mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Make method naming more explanatory
This commit is contained in:
@@ -11,7 +11,7 @@ class ShopController < BaseController
|
||||
|
||||
def products
|
||||
begin
|
||||
products_json = OpenFoodNetwork::ProductsRenderer.new(current_distributor, current_order_cycle).products
|
||||
products_json = OpenFoodNetwork::ProductsRenderer.new(current_distributor, current_order_cycle).products_json
|
||||
|
||||
render json: products_json
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ module OpenFoodNetwork
|
||||
@order_cycle = order_cycle
|
||||
end
|
||||
|
||||
def products
|
||||
products = products_for_shop
|
||||
def products_json
|
||||
products = load_products
|
||||
|
||||
if products
|
||||
enterprise_fee_calculator = EnterpriseFeeCalculator.new @distributor, @order_cycle
|
||||
@@ -31,7 +31,7 @@ module OpenFoodNetwork
|
||||
|
||||
private
|
||||
|
||||
def products_for_shop
|
||||
def load_products
|
||||
if @order_cycle
|
||||
scoper = ScopeProductToHub.new(@distributor)
|
||||
|
||||
|
||||
@@ -25,13 +25,13 @@ module OpenFoodNetwork
|
||||
|
||||
it "sorts products by the distributor's preferred taxon list" do
|
||||
distributor.stub(:preferred_shopfront_taxon_order) {"#{t1.id},#{t2.id}"}
|
||||
products = pr.send(:products_for_shop)
|
||||
products = pr.send(:load_products)
|
||||
products.should == [p2, p4, p1, p3]
|
||||
end
|
||||
|
||||
it "alphabetizes products by name when taxon list is not set" do
|
||||
distributor.stub(:preferred_shopfront_taxon_order) {""}
|
||||
products = pr.send(:products_for_shop)
|
||||
products = pr.send(:load_products)
|
||||
products.should == [p1, p2, p3, p4]
|
||||
end
|
||||
end
|
||||
@@ -45,17 +45,17 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
it "only returns products for the current order cycle" do
|
||||
pr.products.should include product.name
|
||||
pr.products_json.should include product.name
|
||||
end
|
||||
|
||||
it "doesn't return products not in stock" do
|
||||
variant.update_attribute(:count_on_hand, 0)
|
||||
pr.products.should_not include product.name
|
||||
pr.products_json.should_not include product.name
|
||||
end
|
||||
|
||||
it "strips html from description" do
|
||||
product.update_attribute(:description, "<a href='44'>turtles</a> frogs")
|
||||
json = pr.products
|
||||
json = pr.products_json
|
||||
json.should include "frogs"
|
||||
json.should_not include "<a href"
|
||||
end
|
||||
@@ -65,13 +65,13 @@ module OpenFoodNetwork
|
||||
OpenFoodNetwork::EnterpriseFeeCalculator.any_instance.
|
||||
stub(:indexed_fees_for).and_return 978.01
|
||||
|
||||
pr.products.should include "998.0"
|
||||
pr.products_json.should include "998.0"
|
||||
end
|
||||
|
||||
it "includes the primary taxon" do
|
||||
taxon = create(:taxon)
|
||||
Spree::Product.any_instance.stub(:primary_taxon).and_return taxon
|
||||
pr.products.should include taxon.name
|
||||
pr.products_json.should include taxon.name
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user