From aa85d20173137ac57056c22fe7fdb591f1efe039 Mon Sep 17 00:00:00 2001 From: vagrant Date: Wed, 22 May 2013 13:06:24 +1000 Subject: [PATCH 01/22] add suppliers scope, limit by 5, test --- config/database.yml | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 config/database.yml diff --git a/config/database.yml b/config/database.yml deleted file mode 100644 index 9633824f0f..0000000000 --- a/config/database.yml +++ /dev/null @@ -1,24 +0,0 @@ -development: - adapter: postgresql - encoding: unicode - database: open_food_web_dev - pool: 5 - username: ofw - password: f00d - -test: - adapter: postgresql - encoding: unicode - database: open_food_web_test - pool: 5 - username: ofw - password: f00d - -#not used with heroku -production: - adapter: postgresql - encoding: unicode - database: open_food_web_prod - pool: 5 - username: ofw - password: f00d \ No newline at end of file From 4e7f96642911e690d7731c34dc974e2db081dbec Mon Sep 17 00:00:00 2001 From: vagrant Date: Wed, 22 May 2013 13:07:30 +1000 Subject: [PATCH 02/22] add suppliers scope, limit by 5, test --- .gitignore | 1 + app/controllers/application_controller.rb | 6 ++++-- app/models/enterprise.rb | 1 + .../spree/products/_source_sidebar.html.haml | 20 ++++++++++++------- db/schema.rb | 1 + spec/models/enterprises_spec.rb | 12 +++++++++++ 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 6cb7536f07..d3e283ca3a 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ config/abr.yml config/heroku_env.rb NERD_tree* coverage +config/database.yml diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b3ef2dff28..30c59f30cb 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,8 +10,10 @@ class ApplicationController < ActionController::Base end def load_data_for_sidebar - @suppliers = Enterprise.is_primary_producer - @distributors = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name + @suppliers = Enterprise.is_primary_producer.with_supplied_active_products_on_hand.limit(5) + @supplier_count = Enterprise.is_primary_producer.with_supplied_active_products_on_hand.count + @distributors = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name.limit(5) + @distributor_count = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name.count end # All render calls within the block will be performed with the specified format diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 17c9380097..6b7d133970 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -17,6 +17,7 @@ class Enterprise < ActiveRecord::Base scope :by_name, order('name') scope :is_primary_producer, where(:is_primary_producer => true) scope :is_distributor, where(:is_distributor => true) + scope :with_supplied_active_products_on_hand, lambda { joins(:supplied_products).where('spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0', Time.now).select('distinct(enterprises.*)') } scope :with_distributed_active_products_on_hand, lambda { joins(:distributed_products).where('spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0', Time.now).select('distinct(enterprises.*)') } diff --git a/app/views/spree/products/_source_sidebar.html.haml b/app/views/spree/products/_source_sidebar.html.haml index 03fc78ac84..11f62f90cb 100644 --- a/app/views/spree/products/_source_sidebar.html.haml +++ b/app/views/spree/products/_source_sidebar.html.haml @@ -1,11 +1,4 @@ %nav#filters - %h6.filter_name Shop by Supplier - %ul.filter_choices - - @suppliers.each do |supplier| - - if supplier.has_supplied_products_on_hand? - %li.nowrap= link_to supplier.name, [main_app, supplier] - = button_to 'Browse All Suppliers', main_app.suppliers_enterprises_path, :method => :get - %h6.filter_name Shop by Distributor %ul.filter_choices - order = current_order(false) @@ -18,5 +11,18 @@ = link_to distributor.name, [main_app, distributor] - else %abbr(title="One or more of the products in your cart is not available from this distributor")= distributor.name + - if @distributor_count > @distributors.count + - distributors_more = @distributors.count - @distributor_count + = "#{distributors_more} more..." - if current_distributor && validator.can_change_distributor? = button_to 'Browse All Distributors', deselect_distributor_orders_path, :method => :get + + %h6.filter_name Shop by Supplier + %ul.filter_choices + - @suppliers.each do |supplier| + -# - if supplier.has_supplied_products_on_hand? -#d.cook: this is filtered in the controller now + %li.nowrap= link_to supplier.name, [main_app, supplier] + - if @supplier_count > @suppliers.count + - suppliers_more = @suppliers.count - @supplier_count + = "#{suppliers_more} more..." + = button_to 'Browse All Suppliers', main_app.suppliers_enterprises_path, :method => :get diff --git a/db/schema.rb b/db/schema.rb index a35dd39545..b99bd0a260 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -422,6 +422,7 @@ ActiveRecord::Schema.define(:version => 20130207043555) do t.string "email" t.text "special_instructions" t.integer "distributor_id" + t.integer "order_cycle_id" t.string "currency" t.string "last_ip_address" end diff --git a/spec/models/enterprises_spec.rb b/spec/models/enterprises_spec.rb index 051533144e..30a518b8b7 100644 --- a/spec/models/enterprises_spec.rb +++ b/spec/models/enterprises_spec.rb @@ -29,6 +29,18 @@ describe Enterprise do Enterprise.with_distributed_active_products_on_hand.sort.should == [d1, d2] end + + it "returns suppliers with products in stock" do + d1 = create(:supplier_enterprise) + d2 = create(:supplier_enterprise) + d3 = create(:supplier_enterprise) + d4 = create(:supplier_enterprise) + create(:product, :supplier => d1, :on_hand => 5) + create(:product, :supplier => d2, :on_hand => 5, :available_on => 1.week.from_now) + create(:product, :supplier => d3, :on_hand => 0) + # supplier with no products, supplier with product out of stock, suplier with product thats unavailable, supplier with active product on hand + Enterprise.with_supplied_active_products_on_hand.sort.should == [d1] + end end context "has_supplied_products_on_hand?" do From 423bd52fd63db58b30c78b818888ef9345069a7a Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 22 May 2013 14:03:51 +1000 Subject: [PATCH 03/22] rename _count vars to _total --- .gitignore | 1 - app/controllers/application_controller.rb | 4 +-- .../spree/products/_source_sidebar.html.haml | 9 +++--- config/database.yml | 29 +++++++++++++++++++ 4 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 config/database.yml diff --git a/.gitignore b/.gitignore index d3e283ca3a..6cb7536f07 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,3 @@ config/abr.yml config/heroku_env.rb NERD_tree* coverage -config/database.yml diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 30c59f30cb..1ce9866eb3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -11,9 +11,9 @@ class ApplicationController < ActionController::Base def load_data_for_sidebar @suppliers = Enterprise.is_primary_producer.with_supplied_active_products_on_hand.limit(5) - @supplier_count = Enterprise.is_primary_producer.with_supplied_active_products_on_hand.count + @supplier_total = Enterprise.is_primary_producer.with_supplied_active_products_on_hand.count @distributors = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name.limit(5) - @distributor_count = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name.count + @distributor_total = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name.count end # All render calls within the block will be performed with the specified format diff --git a/app/views/spree/products/_source_sidebar.html.haml b/app/views/spree/products/_source_sidebar.html.haml index 11f62f90cb..918d89206b 100644 --- a/app/views/spree/products/_source_sidebar.html.haml +++ b/app/views/spree/products/_source_sidebar.html.haml @@ -11,8 +11,8 @@ = link_to distributor.name, [main_app, distributor] - else %abbr(title="One or more of the products in your cart is not available from this distributor")= distributor.name - - if @distributor_count > @distributors.count - - distributors_more = @distributors.count - @distributor_count + - if @distributor_total > @distributors.count + - distributors_more = @distributors.count - @distributor_total = "#{distributors_more} more..." - if current_distributor && validator.can_change_distributor? = button_to 'Browse All Distributors', deselect_distributor_orders_path, :method => :get @@ -20,9 +20,8 @@ %h6.filter_name Shop by Supplier %ul.filter_choices - @suppliers.each do |supplier| - -# - if supplier.has_supplied_products_on_hand? -#d.cook: this is filtered in the controller now %li.nowrap= link_to supplier.name, [main_app, supplier] - - if @supplier_count > @suppliers.count - - suppliers_more = @suppliers.count - @supplier_count + - if @supplier_total > @suppliers.count + - suppliers_more = @suppliers.count - @supplier_total = "#{suppliers_more} more..." = button_to 'Browse All Suppliers', main_app.suppliers_enterprises_path, :method => :get diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000000..40ffe445f7 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,29 @@ +development: + adapter: postgresql + encoding: unicode + #template: template0 + #collate: en_US.UTF8 + #ctype: en_US.UTF8 + database: open_food_web_dev + pool: 5 + host: localhost + username: ofw + password: f00d + +test: + adapter: postgresql + encoding: unicode + database: open_food_web_test + pool: 5 + host: localhost + username: ofw + password: f00d + +#not used with heroku +production: + adapter: postgresql + encoding: unicode + database: open_food_web_prod + pool: 5 + username: ofw + password: f00d From 26c3b80e87d5aace83c75ccd96654c9335167593 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 14 Jun 2013 11:05:56 +1000 Subject: [PATCH 04/22] Reverse unintentional changes to database.yml and db/schema.rb --- config/database.yml | 7 +------ db/schema.rb | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/config/database.yml b/config/database.yml index 40ffe445f7..9633824f0f 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,12 +1,8 @@ development: adapter: postgresql encoding: unicode - #template: template0 - #collate: en_US.UTF8 - #ctype: en_US.UTF8 database: open_food_web_dev pool: 5 - host: localhost username: ofw password: f00d @@ -15,7 +11,6 @@ test: encoding: unicode database: open_food_web_test pool: 5 - host: localhost username: ofw password: f00d @@ -26,4 +21,4 @@ production: database: open_food_web_prod pool: 5 username: ofw - password: f00d + password: f00d \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index b99bd0a260..a35dd39545 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -422,7 +422,6 @@ ActiveRecord::Schema.define(:version => 20130207043555) do t.string "email" t.text "special_instructions" t.integer "distributor_id" - t.integer "order_cycle_id" t.string "currency" t.string "last_ip_address" end From 1abc0dac68529db8e678b3a7af7af15fed7edb38 Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 14 Jun 2013 17:36:38 +1000 Subject: [PATCH 05/22] rename vars again --- app/controllers/application_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1ce9866eb3..a563988ff3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -11,9 +11,9 @@ class ApplicationController < ActionController::Base def load_data_for_sidebar @suppliers = Enterprise.is_primary_producer.with_supplied_active_products_on_hand.limit(5) - @supplier_total = Enterprise.is_primary_producer.with_supplied_active_products_on_hand.count + @total_suppliers = Enterprise.is_primary_producer.with_supplied_active_products_on_hand.count @distributors = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name.limit(5) - @distributor_total = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name.count + @total_distributors = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name.count end # All render calls within the block will be performed with the specified format From 7ce7107c6ce951139421c00527a79db7eb5dae0e Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 14 Jun 2013 17:37:44 +1000 Subject: [PATCH 06/22] Add meaningfull ids and classnames --- .../spree/products/_source_sidebar.html.haml | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/app/views/spree/products/_source_sidebar.html.haml b/app/views/spree/products/_source_sidebar.html.haml index 918d89206b..c5d2da82ba 100644 --- a/app/views/spree/products/_source_sidebar.html.haml +++ b/app/views/spree/products/_source_sidebar.html.haml @@ -1,27 +1,30 @@ %nav#filters - %h6.filter_name Shop by Distributor - %ul.filter_choices - - order = current_order(false) - - validator = DistributorChangeValidator.new(order) - - @distributors.each do |distributor| - %li.nowrap - - if order.nil? || validator.can_change_to_distributor?(distributor) - = link_to distributor.name, [main_app, distributor] - - elsif order.distributor == distributor - = link_to distributor.name, [main_app, distributor] - - else - %abbr(title="One or more of the products in your cart is not available from this distributor")= distributor.name - - if @distributor_total > @distributors.count - - distributors_more = @distributors.count - @distributor_total - = "#{distributors_more} more..." - - if current_distributor && validator.can_change_distributor? - = button_to 'Browse All Distributors', deselect_distributor_orders_path, :method => :get - - %h6.filter_name Shop by Supplier - %ul.filter_choices - - @suppliers.each do |supplier| - %li.nowrap= link_to supplier.name, [main_app, supplier] - - if @supplier_total > @suppliers.count - - suppliers_more = @suppliers.count - @supplier_total - = "#{suppliers_more} more..." + %div#distributor_filter + %h6.filter_name Shop by Distributor + %ul.filter_choices + - order = current_order(false) + - validator = DistributorChangeValidator.new(order) + - @distributors.each do |distributor| + %li.nowrap + - if order.nil? || validator.can_change_to_distributor?(distributor) + = link_to distributor.name, [main_app, distributor] + - elsif order.distributor == distributor + = link_to distributor.name, [main_app, distributor] + - else + %abbr(title="One or more of the products in your cart is not available from this distributor")= distributor.name + - if @total_distributors > @distributors.count + - distributors_more = @total_distributors - @distributors.count + %span.filter_more + = "#{distributors_more} more..." + = button_to 'Browse All Distributors', main_app.distributors_enterprises_path, :method => :get + + %div#supplier_filter + %h6.filter_name Shop by Supplier + %ul.filter_choices + - @suppliers.each do |supplier| + %li.nowrap= link_to supplier.name, [main_app, supplier] + - if @total_suppliers > @suppliers.count + - suppliers_more = @total_suppliers - @suppliers.count + %span.filter_more + = "#{suppliers_more} more..." = button_to 'Browse All Suppliers', main_app.suppliers_enterprises_path, :method => :get From 7933dea611604af1a3c8c28e85b423ca6b692972 Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 14 Jun 2013 17:38:51 +1000 Subject: [PATCH 07/22] WIP: add more tests --- spec/features/consumer/distributors_spec.rb | 95 +++++++++++++++++---- spec/features/consumer/suppliers_spec.rb | 49 +++++++++-- 2 files changed, 124 insertions(+), 20 deletions(-) diff --git a/spec/features/consumer/distributors_spec.rb b/spec/features/consumer/distributors_spec.rb index 4a747e5c0f..8d738120c2 100644 --- a/spec/features/consumer/distributors_spec.rb +++ b/spec/features/consumer/distributors_spec.rb @@ -8,7 +8,7 @@ feature %q{ include AuthenticationWorkflow include WebHelper - scenario "viewing a list of distributors" do + scenario "viewing a list of distributors in the sidebar" do # Given some distributors d1 = create(:distributor_enterprise) d2 = create(:distributor_enterprise) @@ -26,6 +26,85 @@ feature %q{ page.should_not have_selector 'a', :text => d3.name end +scenario "viewing a list of distributors (with active products) in the sidebar when there's 5 or fewer" do + # Given some distributors + d1 = create(:distributor_enterprise) + d2 = create(:distributor_enterprise) + d3 = create(:distributor_enterprise) + d4 = create(:distributor_enterprise) + d5 = create(:distributor_enterprise) + d6 = create(:distributor_enterprise) + + # And some of those distributors have a product + create(:product, :distributors => [d1]) + create(:product, :distributors => [d3], :on_hand => 0) + + # When I go to the home page + visit spree.root_path + + # Then I should see a list containing all the distributors that have active products in stock + page.should have_selector 'a', :text => d1.name + page.should_not have_selector 'a', :text => d2.name #has no products + page.should_not have_selector 'a', :text => d3.name #has no products on hand + + # And I shouldn't see 'xx more' + page.should_not have_selector '#distributor_filter span.filter_more', :text => 'more' + + # And I shouldn't see a browse distributors button + page.should have_selector "#distributor_filter input[value='Browse All Distributors']" + end + + scenario "viewing a list of distributors (with active products) in the sidebar when there's more than 5" do + # Given some distributors + d1 = create(:distributor_enterprise) + d2 = create(:distributor_enterprise) + d3 = create(:distributor_enterprise) + d4 = create(:distributor_enterprise) + d5 = create(:distributor_enterprise) + d6 = create(:distributor_enterprise) + + # And at least 5 of those distributors have a product + create(:product, :distributors => [d1]) + create(:product, :distributors => [d2]) + create(:product, :distributors => [d3]) + create(:product, :distributors => [d4]) + create(:product, :distributors => [d5]) + create(:product, :distributors => [d6]) + + # When I go to the home page + visit spree.root_path + + # Then I should see a list containing 5 distributors that have products in stock + page.should have_selector '#distributor_filter li a', :count => 5 + + # And I should see 'xx more' + page.should have_selector '#distributor_filter span.filter_more', :text => 'more' + + # And I should see a browse distributors button + page.should have_selector "#distributor_filter input[value='Browse All Distributors']" + end + + scenario "viewing a list of all distributors" do + # Given some distributors + d1 = create(:distributor_enterprise) + d2 = create(:distributor_enterprise) + d3 = create(:distributor_enterprise) + + # And some of those distributors have a product + create(:product, :distributors => [d1]) + create(:product, :distributors => [d3]) + + # When I go to the distributors listing page + visit spree.root_path + click_button 'Browse All Distributors' + + # Then I should see a list containing all the distributors + page.should have_selector '#content a', :text => d1.name + page.should have_selector '#content a', :text => d2.name + page.should have_selector '#content a', :text => d3.name + end + + scenario "viewing a distributor" do # Given some distributors with products d1 = create(:distributor_enterprise, :long_description => "

Hello, world!

") @@ -107,20 +186,6 @@ feature %q{ end end - it "allows the user to leave the distributor" do - # Given a distributor with a product - d = create(:distributor_enterprise, :name => 'Melb Uni Co-op') - p1 = create(:product, :distributors => [d]) - - # When I select the distributor and then leave it - visit spree.select_distributor_order_path(d) - visit spree.root_path - click_button 'Browse All Distributors' - - # Then I should have left the distributor - page.should_not have_selector '#current-distributor', :text => 'You are shopping at Melb Uni Co-op' - end - context "viewing a product, it provides a choice of distributor when adding to cart" do it "works when no distributor is chosen" do # Given a distributor and a product under it diff --git a/spec/features/consumer/suppliers_spec.rb b/spec/features/consumer/suppliers_spec.rb index c52e3c6f86..ff7b2caecb 100644 --- a/spec/features/consumer/suppliers_spec.rb +++ b/spec/features/consumer/suppliers_spec.rb @@ -8,23 +8,62 @@ feature %q{ include AuthenticationWorkflow include WebHelper - scenario "viewing a list of suppliers in the sidebar" do + scenario "viewing a list of suppliers (with active products) in the sidebar when there's 5 or fewer" do # Given some suppliers s1 = create(:supplier_enterprise) s2 = create(:supplier_enterprise) s3 = create(:supplier_enterprise) + s4 = create(:supplier_enterprise) + s5 = create(:supplier_enterprise) + s6 = create(:supplier_enterprise) # And some of those suppliers have a product create(:product, :supplier => s1) - create(:product, :supplier => s3) + create(:product, :supplier => s3, :on_hand => 0) # When I go to the home page visit spree.root_path - # Then I should see a list containing all the suppliers that have products in stock + # Then I should see a list containing all the suppliers that have active products in stock page.should have_selector 'a', :text => s1.name - page.should have_selector 'a', :text => s3.name - page.should_not have_selector 'a', :text => s2.name + page.should_not have_selector 'a', :text => s2.name #has no products + page.should_not have_selector 'a', :text => s3.name #has no products on hand + + # And I shouldn't see 'xx more' + page.should_not have_selector '#supplier_filter span.filter_more', :text => 'more' + + # And I shouldn't see a browse suppliers button + page.should have_selector "#supplier_filter input[value='Browse All Suppliers']" + end + + scenario "viewing a list of suppliers (with active products) in the sidebar when there's more than 5" do + # Given some suppliers + s1 = create(:supplier_enterprise) + s2 = create(:supplier_enterprise) + s3 = create(:supplier_enterprise) + s4 = create(:supplier_enterprise) + s5 = create(:supplier_enterprise) + s6 = create(:supplier_enterprise) + + # And at least 5 of those suppliers have a product + create(:product, :supplier => s1) + create(:product, :supplier => s2) + create(:product, :supplier => s3) + create(:product, :supplier => s4) + create(:product, :supplier => s5) + create(:product, :supplier => s6) + + # When I go to the home page + visit spree.root_path + + # Then I should see a list containing 5 suppliers that have products in stock + page.should have_selector '#supplier_filter li a', :count => 5 + + # And I should see 'xx more' + page.should have_selector '#supplier_filter span.filter_more', :text => 'more' + + # And I should see a browse suppliers button + page.should have_selector "#supplier_filter input[value='Browse All Suppliers']" end scenario "viewing a list of all suppliers" do From b0e4bef75ed55fccba538580df8e1a0054942743 Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 21 Jun 2013 10:42:42 +1000 Subject: [PATCH 08/22] rename sidebar collection variables to avoid clash, fix count to be distinct --- app/controllers/application_controller.rb | 10 ++++++---- .../spree/products/_source_sidebar.html.haml | 16 ++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a563988ff3..0e9badab42 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,10 +10,12 @@ class ApplicationController < ActionController::Base end def load_data_for_sidebar - @suppliers = Enterprise.is_primary_producer.with_supplied_active_products_on_hand.limit(5) - @total_suppliers = Enterprise.is_primary_producer.with_supplied_active_products_on_hand.count - @distributors = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name.limit(5) - @total_distributors = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name.count + sidebar_distributors_limit = 5 #set false to disable TODO: move to app config + sidebar_suppliers_limit = 5 + @sidebar_distributors = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name.limit(sidebar_distributors_limit) + @total_distributors = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name.count(:distinct => true) + @sidebar_suppliers = Enterprise.is_primary_producer.with_supplied_active_products_on_hand.limit(sidebar_suppliers_limit) + @total_suppliers = Enterprise.is_primary_producer.with_supplied_active_products_on_hand.count(:distinct => true) end # All render calls within the block will be performed with the specified format diff --git a/app/views/spree/products/_source_sidebar.html.haml b/app/views/spree/products/_source_sidebar.html.haml index c5d2da82ba..8f36430536 100644 --- a/app/views/spree/products/_source_sidebar.html.haml +++ b/app/views/spree/products/_source_sidebar.html.haml @@ -4,7 +4,7 @@ %ul.filter_choices - order = current_order(false) - validator = DistributorChangeValidator.new(order) - - @distributors.each do |distributor| + - @sidebar_distributors.each do |distributor| %li.nowrap - if order.nil? || validator.can_change_to_distributor?(distributor) = link_to distributor.name, [main_app, distributor] @@ -12,19 +12,19 @@ = link_to distributor.name, [main_app, distributor] - else %abbr(title="One or more of the products in your cart is not available from this distributor")= distributor.name - - if @total_distributors > @distributors.count - - distributors_more = @total_distributors - @distributors.count + - if @total_distributors > @sidebar_distributors.count + - distributors_more = @total_distributors - @sidebar_distributors.count %span.filter_more = "#{distributors_more} more..." - = button_to 'Browse All Distributors', main_app.distributors_enterprises_path, :method => :get + = button_to 'Browse All Distributors', main_app.distributors_enterprises_path, :method => :get, :style => "margin-top: -15px; margin-bottom: 15px;" %div#supplier_filter %h6.filter_name Shop by Supplier %ul.filter_choices - - @suppliers.each do |supplier| + - @sidebar_suppliers.each do |supplier| %li.nowrap= link_to supplier.name, [main_app, supplier] - - if @total_suppliers > @suppliers.count - - suppliers_more = @total_suppliers - @suppliers.count + - if @total_suppliers > @sidebar_suppliers.count + - suppliers_more = @total_suppliers - @sidebar_suppliers.count %span.filter_more = "#{suppliers_more} more..." - = button_to 'Browse All Suppliers', main_app.suppliers_enterprises_path, :method => :get + = button_to 'Browse All Suppliers', main_app.suppliers_enterprises_path, :method => :get, :style => "margin-top: -15px; margin-bottom: 15px;" From d95903a82d6b8e68fd51f88048c38f533ce86b6e Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 21 Jun 2013 10:44:16 +1000 Subject: [PATCH 09/22] add html output format for all distributors --- app/controllers/enterprises_controller.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index a582d0e6c0..75c90eeae6 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -17,6 +17,9 @@ class EnterprisesController < BaseController format.js do @distributor_details = Hash[@distributors.map { |d| [d.id, render_to_string(:partial => 'enterprises/distributor_details', :locals => {:distributor => d})] }] end + format.html do + @distributors + end end end From 2d64e257ffa73bc9baf6dc2938253ba35c21c81e Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 21 Jun 2013 10:45:11 +1000 Subject: [PATCH 10/22] break long lines into two; no functional change --- app/models/enterprise.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 6b7d133970..29002444f7 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -17,8 +17,10 @@ class Enterprise < ActiveRecord::Base scope :by_name, order('name') scope :is_primary_producer, where(:is_primary_producer => true) scope :is_distributor, where(:is_distributor => true) - scope :with_supplied_active_products_on_hand, lambda { joins(:supplied_products).where('spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0', Time.now).select('distinct(enterprises.*)') } - scope :with_distributed_active_products_on_hand, lambda { joins(:distributed_products).where('spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0', Time.now).select('distinct(enterprises.*)') } + scope :with_supplied_active_products_on_hand, lambda { + joins(:supplied_products).where('spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0', Time.now).select('distinct(enterprises.*)') } + scope :with_distributed_active_products_on_hand, lambda { + joins(:distributed_products).where('spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0', Time.now).select('distinct(enterprises.*)') } def has_supplied_products_on_hand? From 38c0552362e52844ddf17ea88e9e0fa6f223850e Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 21 Jun 2013 10:47:04 +1000 Subject: [PATCH 11/22] test 'more' count --- spec/features/consumer/distributors_spec.rb | 4 ++-- spec/features/consumer/suppliers_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/features/consumer/distributors_spec.rb b/spec/features/consumer/distributors_spec.rb index 8d738120c2..0f0ce829ea 100644 --- a/spec/features/consumer/distributors_spec.rb +++ b/spec/features/consumer/distributors_spec.rb @@ -77,8 +77,8 @@ scenario "viewing a list of distributors (with active products) in the sidebar w # Then I should see a list containing 5 distributors that have products in stock page.should have_selector '#distributor_filter li a', :count => 5 - # And I should see 'xx more' - page.should have_selector '#distributor_filter span.filter_more', :text => 'more' + # And I should see '1 more' + page.should have_selector '#distributor_filter span.filter_more', :text => '1 more' # And I should see a browse distributors button page.should have_selector "#distributor_filter input[value='Browse All Distributors']" diff --git a/spec/features/consumer/suppliers_spec.rb b/spec/features/consumer/suppliers_spec.rb index ff7b2caecb..6abc642aac 100644 --- a/spec/features/consumer/suppliers_spec.rb +++ b/spec/features/consumer/suppliers_spec.rb @@ -59,8 +59,8 @@ feature %q{ # Then I should see a list containing 5 suppliers that have products in stock page.should have_selector '#supplier_filter li a', :count => 5 - # And I should see 'xx more' - page.should have_selector '#supplier_filter span.filter_more', :text => 'more' + # And I should see '1 more' + page.should have_selector '#supplier_filter span.filter_more', :text => '1 more' # And I should see a browse suppliers button page.should have_selector "#supplier_filter input[value='Browse All Suppliers']" From 2e6387ac60e3cab3b55b014797336e784dda5503 Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 21 Jun 2013 10:52:15 +1000 Subject: [PATCH 12/22] test available_on for distributors --- spec/models/enterprises_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/models/enterprises_spec.rb b/spec/models/enterprises_spec.rb index 30a518b8b7..41e02327d4 100644 --- a/spec/models/enterprises_spec.rb +++ b/spec/models/enterprises_spec.rb @@ -24,7 +24,8 @@ describe Enterprise do d3 = create(:distributor_enterprise) d4 = create(:distributor_enterprise) create(:product, :distributors => [d1, d2], :on_hand => 5) - create(:product, :distributors => [d1], :on_hand => 5) + create(:product, :distributors => [d1], :on_hand => 5, :available_on => 1.week.from_now) + create(:product, :distributors => [d2], :on_hand => 5) create(:product, :distributors => [d3], :on_hand => 0) Enterprise.with_distributed_active_products_on_hand.sort.should == [d1, d2] @@ -38,7 +39,7 @@ describe Enterprise do create(:product, :supplier => d1, :on_hand => 5) create(:product, :supplier => d2, :on_hand => 5, :available_on => 1.week.from_now) create(:product, :supplier => d3, :on_hand => 0) - # supplier with no products, supplier with product out of stock, suplier with product thats unavailable, supplier with active product on hand + # supplier with no products, supplier with product out of stock, supplier with product thats unavailable, supplier with active product on hand Enterprise.with_supplied_active_products_on_hand.sort.should == [d1] end end From 7121860416282f8bd0c34982dda5db045ae147cb Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 21 Jun 2013 10:53:24 +1000 Subject: [PATCH 13/22] new view to display all distributors --- app/views/enterprises/distributors.html.haml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 app/views/enterprises/distributors.html.haml diff --git a/app/views/enterprises/distributors.html.haml b/app/views/enterprises/distributors.html.haml new file mode 100644 index 0000000000..941b65237b --- /dev/null +++ b/app/views/enterprises/distributors.html.haml @@ -0,0 +1,12 @@ +- content_for :sidebar do + %div{'data-hook' => "homepage_sidebar_navigation"} + = render 'spree/sidebar' + + +%h1 Distributors + += cms_page_content(:content, Cms::Page.find_by_full_path('/enterprises/distributors')) + +%ul.enterprises + - @distributors.each do |distributor| + %li= link_to distributor.name, distributor From 250e76c281e58d62b92aee66bc414854d25a50da Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 21 Jun 2013 15:10:21 +1000 Subject: [PATCH 14/22] Fix incorrect count of enterprises (due to bug in rails issue #5554) --- app/controllers/application_controller.rb | 4 ++-- app/models/enterprise.rb | 8 ++++++-- spec/models/enterprises_spec.rb | 3 +++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0e9badab42..0d8f209ce2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -13,9 +13,9 @@ class ApplicationController < ActionController::Base sidebar_distributors_limit = 5 #set false to disable TODO: move to app config sidebar_suppliers_limit = 5 @sidebar_distributors = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name.limit(sidebar_distributors_limit) - @total_distributors = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name.count(:distinct => true) + @total_distributors = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name.distinct_count @sidebar_suppliers = Enterprise.is_primary_producer.with_supplied_active_products_on_hand.limit(sidebar_suppliers_limit) - @total_suppliers = Enterprise.is_primary_producer.with_supplied_active_products_on_hand.count(:distinct => true) + @total_suppliers = Enterprise.is_primary_producer.with_supplied_active_products_on_hand.distinct_count end # All render calls within the block will be performed with the specified format diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 29002444f7..0ea6afa580 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -18,10 +18,14 @@ class Enterprise < ActiveRecord::Base scope :is_primary_producer, where(:is_primary_producer => true) scope :is_distributor, where(:is_distributor => true) scope :with_supplied_active_products_on_hand, lambda { - joins(:supplied_products).where('spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0', Time.now).select('distinct(enterprises.*)') } + joins(:supplied_products).where('spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0', Time.now).uniq } scope :with_distributed_active_products_on_hand, lambda { - joins(:distributed_products).where('spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0', Time.now).select('distinct(enterprises.*)') } + joins(:distributed_products).where('spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0', Time.now).uniq } + # Force a distinct count to work around relation count issue https://github.com/rails/rails/issues/5554 + def self.distinct_count + count(distinct: true) + end def has_supplied_products_on_hand? self.supplied_products.where('count_on_hand > 0').present? diff --git a/spec/models/enterprises_spec.rb b/spec/models/enterprises_spec.rb index 41e02327d4..8e8ce97dad 100644 --- a/spec/models/enterprises_spec.rb +++ b/spec/models/enterprises_spec.rb @@ -29,6 +29,7 @@ describe Enterprise do create(:product, :distributors => [d3], :on_hand => 0) Enterprise.with_distributed_active_products_on_hand.sort.should == [d1, d2] + Enterprise.with_distributed_active_products_on_hand.distinct_count.should == 2 end it "returns suppliers with products in stock" do @@ -37,10 +38,12 @@ describe Enterprise do d3 = create(:supplier_enterprise) d4 = create(:supplier_enterprise) create(:product, :supplier => d1, :on_hand => 5) + create(:product, :supplier => d1, :on_hand => 5) create(:product, :supplier => d2, :on_hand => 5, :available_on => 1.week.from_now) create(:product, :supplier => d3, :on_hand => 0) # supplier with no products, supplier with product out of stock, supplier with product thats unavailable, supplier with active product on hand Enterprise.with_supplied_active_products_on_hand.sort.should == [d1] + Enterprise.with_supplied_active_products_on_hand.distinct_count.should == 1 end end From 0525abb084d6accf97916665fd95865d61bdac89 Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 21 Jun 2013 15:53:12 +1000 Subject: [PATCH 15/22] Test that scopes don't return deleted products --- spec/models/enterprises_spec.rb | 43 +++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/spec/models/enterprises_spec.rb b/spec/models/enterprises_spec.rb index 8e8ce97dad..9d645f24d0 100644 --- a/spec/models/enterprises_spec.rb +++ b/spec/models/enterprises_spec.rb @@ -18,32 +18,39 @@ describe Enterprise do end describe "scopes" do - it "returns distributors with products in stock" do - d1 = create(:distributor_enterprise) - d2 = create(:distributor_enterprise) - d3 = create(:distributor_enterprise) - d4 = create(:distributor_enterprise) + it "returns distributors with available products in stock" do + d1 = create(:distributor_enterprise) # two products on hand + d2 = create(:distributor_enterprise) # one product on hand + d3 = create(:distributor_enterprise) # product on hand but not yet available + d4 = create(:distributor_enterprise) # no products on hand + d5 = create(:distributor_enterprise) # deleted product + d6 = create(:distributor_enterprise) # no products create(:product, :distributors => [d1, d2], :on_hand => 5) - create(:product, :distributors => [d1], :on_hand => 5, :available_on => 1.week.from_now) - create(:product, :distributors => [d2], :on_hand => 5) - create(:product, :distributors => [d3], :on_hand => 0) + create(:product, :distributors => [d1], :on_hand => 5) + create(:product, :distributors => [d3], :on_hand => 5, :available_on => 1.week.from_now) + create(:product, :distributors => [d4], :on_hand => 0) + create(:product, :distributors => [d5]).delete Enterprise.with_distributed_active_products_on_hand.sort.should == [d1, d2] Enterprise.with_distributed_active_products_on_hand.distinct_count.should == 2 end - it "returns suppliers with products in stock" do - d1 = create(:supplier_enterprise) - d2 = create(:supplier_enterprise) - d3 = create(:supplier_enterprise) - d4 = create(:supplier_enterprise) + it "returns suppliers with available products in stock" do + d1 = create(:supplier_enterprise) # two products on hand + d2 = create(:supplier_enterprise) # one product on hand + d3 = create(:supplier_enterprise) # product on hand but not yet available + d4 = create(:supplier_enterprise) # no products on hand + d5 = create(:supplier_enterprise) # deleted product + d6 = create(:supplier_enterprise) # no products create(:product, :supplier => d1, :on_hand => 5) create(:product, :supplier => d1, :on_hand => 5) - create(:product, :supplier => d2, :on_hand => 5, :available_on => 1.week.from_now) - create(:product, :supplier => d3, :on_hand => 0) - # supplier with no products, supplier with product out of stock, supplier with product thats unavailable, supplier with active product on hand - Enterprise.with_supplied_active_products_on_hand.sort.should == [d1] - Enterprise.with_supplied_active_products_on_hand.distinct_count.should == 1 + create(:product, :supplier => d2, :on_hand => 5) + create(:product, :supplier => d3, :on_hand => 5, :available_on => 1.week.from_now) + create(:product, :supplier => d4, :on_hand => 0) + create(:product, :supplier => d5).delete + + Enterprise.with_supplied_active_products_on_hand.sort.should == [d1, d2] + Enterprise.with_supplied_active_products_on_hand.distinct_count.should == 2 end end From a63b8908bb983f05e8df1775ab00fa400dcaec33 Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 21 Jun 2013 16:12:56 +1000 Subject: [PATCH 16/22] Moved inline style to stylesheet --- app/assets/stylesheets/store/openfoodweb.css.scss | 6 +++++- app/views/spree/products/_source_sidebar.html.haml | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/store/openfoodweb.css.scss b/app/assets/stylesheets/store/openfoodweb.css.scss index bf08508f82..3daef60040 100644 --- a/app/assets/stylesheets/store/openfoodweb.css.scss +++ b/app/assets/stylesheets/store/openfoodweb.css.scss @@ -48,7 +48,7 @@ nav#filters { .filter_choices { padding-left: 20px; - margin-bottom: 20px; + margin-bottom: 5px; list-style: disc outside; li { @@ -60,6 +60,10 @@ nav#filters { } } } + + input[type=submit] { + margin-bottom: 15px; + } } diff --git a/app/views/spree/products/_source_sidebar.html.haml b/app/views/spree/products/_source_sidebar.html.haml index 8f36430536..9f49ebe8e9 100644 --- a/app/views/spree/products/_source_sidebar.html.haml +++ b/app/views/spree/products/_source_sidebar.html.haml @@ -16,7 +16,7 @@ - distributors_more = @total_distributors - @sidebar_distributors.count %span.filter_more = "#{distributors_more} more..." - = button_to 'Browse All Distributors', main_app.distributors_enterprises_path, :method => :get, :style => "margin-top: -15px; margin-bottom: 15px;" + = button_to 'Browse All Distributors', main_app.distributors_enterprises_path, :method => :get %div#supplier_filter %h6.filter_name Shop by Supplier @@ -27,4 +27,4 @@ - suppliers_more = @total_suppliers - @sidebar_suppliers.count %span.filter_more = "#{suppliers_more} more..." - = button_to 'Browse All Suppliers', main_app.suppliers_enterprises_path, :method => :get, :style => "margin-top: -15px; margin-bottom: 15px;" + = button_to 'Browse All Suppliers', main_app.suppliers_enterprises_path, :method => :get From 3007549aa5f7d857e03c20604a6a3ce3d9669fbd Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 28 Jun 2013 17:02:26 +1000 Subject: [PATCH 17/22] use .length instead of .count which produced unexpected results --- app/views/spree/products/_source_sidebar.html.haml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/spree/products/_source_sidebar.html.haml b/app/views/spree/products/_source_sidebar.html.haml index 9f49ebe8e9..827bdbcf1d 100644 --- a/app/views/spree/products/_source_sidebar.html.haml +++ b/app/views/spree/products/_source_sidebar.html.haml @@ -12,8 +12,8 @@ = link_to distributor.name, [main_app, distributor] - else %abbr(title="One or more of the products in your cart is not available from this distributor")= distributor.name - - if @total_distributors > @sidebar_distributors.count - - distributors_more = @total_distributors - @sidebar_distributors.count + - if @total_distributors > @sidebar_distributors.length + - distributors_more = @total_distributors - @sidebar_distributors.length %span.filter_more = "#{distributors_more} more..." = button_to 'Browse All Distributors', main_app.distributors_enterprises_path, :method => :get @@ -23,8 +23,8 @@ %ul.filter_choices - @sidebar_suppliers.each do |supplier| %li.nowrap= link_to supplier.name, [main_app, supplier] - - if @total_suppliers > @sidebar_suppliers.count - - suppliers_more = @total_suppliers - @sidebar_suppliers.count + - if @total_suppliers > @sidebar_suppliers.length + - suppliers_more = @total_suppliers - @sidebar_suppliers.length %span.filter_more = "#{suppliers_more} more..." = button_to 'Browse All Suppliers', main_app.suppliers_enterprises_path, :method => :get From 5b58351b73d7b1d18d9a48c58e9f4b7eab2ecd26 Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 28 Jun 2013 17:04:58 +1000 Subject: [PATCH 18/22] minor changes --- app/controllers/application_controller.rb | 2 +- spec/features/consumer/distributors_spec.rb | 2 +- spec/features/consumer/suppliers_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0d8f209ce2..d04bbcc8d8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -13,7 +13,7 @@ class ApplicationController < ActionController::Base sidebar_distributors_limit = 5 #set false to disable TODO: move to app config sidebar_suppliers_limit = 5 @sidebar_distributors = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name.limit(sidebar_distributors_limit) - @total_distributors = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name.distinct_count + @total_distributors = Enterprise.is_distributor.with_distributed_active_products_on_hand.distinct_count @sidebar_suppliers = Enterprise.is_primary_producer.with_supplied_active_products_on_hand.limit(sidebar_suppliers_limit) @total_suppliers = Enterprise.is_primary_producer.with_supplied_active_products_on_hand.distinct_count end diff --git a/spec/features/consumer/distributors_spec.rb b/spec/features/consumer/distributors_spec.rb index 0f0ce829ea..4a75a8d8cc 100644 --- a/spec/features/consumer/distributors_spec.rb +++ b/spec/features/consumer/distributors_spec.rb @@ -48,7 +48,7 @@ scenario "viewing a list of distributors (with active products) in the sidebar w page.should_not have_selector 'a', :text => d3.name #has no products on hand # And I shouldn't see 'xx more' - page.should_not have_selector '#distributor_filter span.filter_more', :text => 'more' + page.should_not have_selector '#distributor_filter span.filter_more' # And I shouldn't see a browse distributors button page.should have_selector "#distributor_filter input[value='Browse All Distributors']" diff --git a/spec/features/consumer/suppliers_spec.rb b/spec/features/consumer/suppliers_spec.rb index 6abc642aac..c48cae9d13 100644 --- a/spec/features/consumer/suppliers_spec.rb +++ b/spec/features/consumer/suppliers_spec.rb @@ -30,7 +30,7 @@ feature %q{ page.should_not have_selector 'a', :text => s3.name #has no products on hand # And I shouldn't see 'xx more' - page.should_not have_selector '#supplier_filter span.filter_more', :text => 'more' + page.should_not have_selector '#supplier_filter span.filter_more' # And I shouldn't see a browse suppliers button page.should have_selector "#supplier_filter input[value='Browse All Suppliers']" From 66d345d360fc7a7d188a4ca46c2963268c34fa43 Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 22 Jul 2013 14:53:08 +1000 Subject: [PATCH 19/22] fix 'x more' count, disable sidebar limit (config for this to be implemented later) --- app/controllers/application_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d04bbcc8d8..bc71cf464d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,12 +10,12 @@ class ApplicationController < ActionController::Base end def load_data_for_sidebar - sidebar_distributors_limit = 5 #set false to disable TODO: move to app config - sidebar_suppliers_limit = 5 + sidebar_distributors_limit = false # TODO: move to app config + sidebar_suppliers_limit = false @sidebar_distributors = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name.limit(sidebar_distributors_limit) - @total_distributors = Enterprise.is_distributor.with_distributed_active_products_on_hand.distinct_count + @total_distributors = Enterprise.is_distributor.distinct_count @sidebar_suppliers = Enterprise.is_primary_producer.with_supplied_active_products_on_hand.limit(sidebar_suppliers_limit) - @total_suppliers = Enterprise.is_primary_producer.with_supplied_active_products_on_hand.distinct_count + @total_suppliers = Enterprise.is_primary_producer.distinct_count end # All render calls within the block will be performed with the specified format From 55277e2f0a05c261e9909c197c716f183fe66d2d Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 22 Jul 2013 14:55:46 +1000 Subject: [PATCH 20/22] test for inactive enterprises being counted in 'x more' on sidebar, disable limit test --- spec/features/consumer/distributors_spec.rb | 14 ++++++++++---- spec/features/consumer/suppliers_spec.rb | 12 +++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/spec/features/consumer/distributors_spec.rb b/spec/features/consumer/distributors_spec.rb index 4a75a8d8cc..549acca3f1 100644 --- a/spec/features/consumer/distributors_spec.rb +++ b/spec/features/consumer/distributors_spec.rb @@ -26,7 +26,7 @@ feature %q{ page.should_not have_selector 'a', :text => d3.name end -scenario "viewing a list of distributors (with active products) in the sidebar when there's 5 or fewer" do +scenario "viewing a list of distributors (with active products) in the sidebar when there's some inactive distributors" do # Given some distributors d1 = create(:distributor_enterprise) d2 = create(:distributor_enterprise) @@ -39,6 +39,9 @@ scenario "viewing a list of distributors (with active products) in the sidebar w create(:product, :distributors => [d1]) create(:product, :distributors => [d3], :on_hand => 0) + # And no limit set for the sidebar + sidebar_distributors_limit = false + # When I go to the home page visit spree.root_path @@ -47,13 +50,15 @@ scenario "viewing a list of distributors (with active products) in the sidebar w page.should_not have_selector 'a', :text => d2.name #has no products page.should_not have_selector 'a', :text => d3.name #has no products on hand - # And I shouldn't see 'xx more' - page.should_not have_selector '#distributor_filter span.filter_more' + # And I should see '5 more' + distributors_more = Enterprise.is_distributor.distinct_count - Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name.limit(sidebar_distributors_limit).length + page.should have_selector '#distributor_filter span.filter_more', :text => "#{distributors_more} more" - # And I shouldn't see a browse distributors button + # And I should (always) see a browse distributors button page.should have_selector "#distributor_filter input[value='Browse All Distributors']" end +=begin scenario "viewing a list of distributors (with active products) in the sidebar when there's more than 5" do # Given some distributors d1 = create(:distributor_enterprise) @@ -83,6 +88,7 @@ scenario "viewing a list of distributors (with active products) in the sidebar w # And I should see a browse distributors button page.should have_selector "#distributor_filter input[value='Browse All Distributors']" end +=end scenario "viewing a list of all distributors" do # Given some distributors diff --git a/spec/features/consumer/suppliers_spec.rb b/spec/features/consumer/suppliers_spec.rb index c48cae9d13..f960a6e444 100644 --- a/spec/features/consumer/suppliers_spec.rb +++ b/spec/features/consumer/suppliers_spec.rb @@ -21,6 +21,9 @@ feature %q{ create(:product, :supplier => s1) create(:product, :supplier => s3, :on_hand => 0) + # And no limit set for the sidebar + sidebar_suppliers_limit = false + # When I go to the home page visit spree.root_path @@ -29,13 +32,15 @@ feature %q{ page.should_not have_selector 'a', :text => s2.name #has no products page.should_not have_selector 'a', :text => s3.name #has no products on hand - # And I shouldn't see 'xx more' - page.should_not have_selector '#supplier_filter span.filter_more' + # And I should see '5 more' + suppliers_more = Enterprise.is_primary_producer.distinct_count - Enterprise.is_primary_producer.with_supplied_active_products_on_hand.limit(sidebar_suppliers_limit).length + page.should have_selector '#supplier_filter span.filter_more', :text => "#{suppliers_more} more" - # And I shouldn't see a browse suppliers button + # And I should (always) see a browse suppliers button page.should have_selector "#supplier_filter input[value='Browse All Suppliers']" end +=begin scenario "viewing a list of suppliers (with active products) in the sidebar when there's more than 5" do # Given some suppliers s1 = create(:supplier_enterprise) @@ -65,6 +70,7 @@ feature %q{ # And I should see a browse suppliers button page.should have_selector "#supplier_filter input[value='Browse All Suppliers']" end +=end scenario "viewing a list of all suppliers" do # Given some suppliers From 6265dfc80d7cc6aac0e6cd74d5e8f686f77d2e6c Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 29 Jul 2013 09:29:23 +1000 Subject: [PATCH 21/22] remove block commented code --- spec/features/consumer/distributors_spec.rb | 32 --------------------- 1 file changed, 32 deletions(-) diff --git a/spec/features/consumer/distributors_spec.rb b/spec/features/consumer/distributors_spec.rb index 549acca3f1..348d7fc35c 100644 --- a/spec/features/consumer/distributors_spec.rb +++ b/spec/features/consumer/distributors_spec.rb @@ -58,38 +58,6 @@ scenario "viewing a list of distributors (with active products) in the sidebar w page.should have_selector "#distributor_filter input[value='Browse All Distributors']" end -=begin - scenario "viewing a list of distributors (with active products) in the sidebar when there's more than 5" do - # Given some distributors - d1 = create(:distributor_enterprise) - d2 = create(:distributor_enterprise) - d3 = create(:distributor_enterprise) - d4 = create(:distributor_enterprise) - d5 = create(:distributor_enterprise) - d6 = create(:distributor_enterprise) - - # And at least 5 of those distributors have a product - create(:product, :distributors => [d1]) - create(:product, :distributors => [d2]) - create(:product, :distributors => [d3]) - create(:product, :distributors => [d4]) - create(:product, :distributors => [d5]) - create(:product, :distributors => [d6]) - - # When I go to the home page - visit spree.root_path - - # Then I should see a list containing 5 distributors that have products in stock - page.should have_selector '#distributor_filter li a', :count => 5 - - # And I should see '1 more' - page.should have_selector '#distributor_filter span.filter_more', :text => '1 more' - - # And I should see a browse distributors button - page.should have_selector "#distributor_filter input[value='Browse All Distributors']" - end -=end - scenario "viewing a list of all distributors" do # Given some distributors d1 = create(:distributor_enterprise) From 863236b8271b1116ea2fca8d721b9dc9001ac219 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Mon, 29 Jul 2013 09:47:28 +1000 Subject: [PATCH 22/22] Remove speculative test --- spec/features/consumer/suppliers_spec.rb | 32 ------------------------ 1 file changed, 32 deletions(-) diff --git a/spec/features/consumer/suppliers_spec.rb b/spec/features/consumer/suppliers_spec.rb index f960a6e444..2dee0f1a5f 100644 --- a/spec/features/consumer/suppliers_spec.rb +++ b/spec/features/consumer/suppliers_spec.rb @@ -40,38 +40,6 @@ feature %q{ page.should have_selector "#supplier_filter input[value='Browse All Suppliers']" end -=begin - scenario "viewing a list of suppliers (with active products) in the sidebar when there's more than 5" do - # Given some suppliers - s1 = create(:supplier_enterprise) - s2 = create(:supplier_enterprise) - s3 = create(:supplier_enterprise) - s4 = create(:supplier_enterprise) - s5 = create(:supplier_enterprise) - s6 = create(:supplier_enterprise) - - # And at least 5 of those suppliers have a product - create(:product, :supplier => s1) - create(:product, :supplier => s2) - create(:product, :supplier => s3) - create(:product, :supplier => s4) - create(:product, :supplier => s5) - create(:product, :supplier => s6) - - # When I go to the home page - visit spree.root_path - - # Then I should see a list containing 5 suppliers that have products in stock - page.should have_selector '#supplier_filter li a', :count => 5 - - # And I should see '1 more' - page.should have_selector '#supplier_filter span.filter_more', :text => '1 more' - - # And I should see a browse suppliers button - page.should have_selector "#supplier_filter input[value='Browse All Suppliers']" - end -=end - scenario "viewing a list of all suppliers" do # Given some suppliers s1 = create(:supplier_enterprise)