From a686a820d9212119e136572d9efc17ec41228dfe Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 11 Oct 2012 10:11:09 +1100 Subject: [PATCH] Add distributor show page, redirect here after selecting distributor --- .../stylesheets/store/openfoodweb.css.scss | 7 ++++++ .../spree/distributors_controller.rb | 7 ++++-- app/views/spree/distributors/show.html.haml | 7 ++++++ .../spree/products/_source_sidebar.html.haml | 2 +- spec/factories.rb | 1 + spec/requests/consumer/distributors_spec.rb | 24 ++++++++++++++++--- 6 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 app/views/spree/distributors/show.html.haml diff --git a/app/assets/stylesheets/store/openfoodweb.css.scss b/app/assets/stylesheets/store/openfoodweb.css.scss index e44ec5f66f..a3cb0a29f1 100644 --- a/app/assets/stylesheets/store/openfoodweb.css.scss +++ b/app/assets/stylesheets/store/openfoodweb.css.scss @@ -128,6 +128,13 @@ ul.product-listing { } +/* Supplier and distributor description */ +.supplier-description, .distributor-description { + margin-bottom: 2em; +} + + + /* Highlight local products in distributor-split product listings */ #products-local ul { margin-bottom: 1em; diff --git a/app/controllers/spree/distributors_controller.rb b/app/controllers/spree/distributors_controller.rb index 98ac1930a8..ecce2dfd6b 100644 --- a/app/controllers/spree/distributors_controller.rb +++ b/app/controllers/spree/distributors_controller.rb @@ -1,12 +1,15 @@ module Spree class DistributorsController < BaseController + helper 'spree/products' + def show options = {:distributor_id => params[:id]} options.merge(params.reject { |k,v| k == :id }) + @distributor = Distributor.find params[:id] + @searcher = Config.searcher_class.new(options) @products = @searcher.retrieve_products - render :template => 'spree/products/index' end def select @@ -19,7 +22,7 @@ module Spree order.save! end - redirect_to root_path + redirect_to distributor end def deselect diff --git a/app/views/spree/distributors/show.html.haml b/app/views/spree/distributors/show.html.haml new file mode 100644 index 0000000000..da898156e1 --- /dev/null +++ b/app/views/spree/distributors/show.html.haml @@ -0,0 +1,7 @@ +%h2= @distributor.name + +.distributor-description= @distributor.long_description.andand.html_safe + +%h3 Available Now + += render :template => 'spree/products/index' diff --git a/app/views/spree/products/_source_sidebar.html.haml b/app/views/spree/products/_source_sidebar.html.haml index 90f7337e6a..da178106da 100644 --- a/app/views/spree/products/_source_sidebar.html.haml +++ b/app/views/spree/products/_source_sidebar.html.haml @@ -12,7 +12,7 @@ - if order.nil? || order.can_change_distributor? = link_to distributor.name, select_distributor_path(distributor) - elsif order.distributor == distributor - = link_to distributor.name, root_path + = link_to distributor.name, distributor - else %span.inactive= distributor.name - if current_distributor && order.can_change_distributor? diff --git a/spec/factories.rb b/spec/factories.rb index a85929f972..a227cef574 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -15,6 +15,7 @@ FactoryGirl.define do contact 'Mr Turing' phone '1000100100' description 'The creator' + long_description '

Hello, world!

This is a paragraph.

' email 'alan@somewhere.com' url 'http://example.com' pickup_times "Whenever you're free" diff --git a/spec/requests/consumer/distributors_spec.rb b/spec/requests/consumer/distributors_spec.rb index eb5e7dc216..1139ace1cd 100644 --- a/spec/requests/consumer/distributors_spec.rb +++ b/spec/requests/consumer/distributors_spec.rb @@ -26,19 +26,36 @@ feature %q{ page.should_not have_selector 'a', :text => d3.name end - context "when a distributor is selected" do - it "displays the distributor's name" do + it "displays the distributor's details" do # Given a distributor with a product - d = create(:distributor, :name => 'Melb Uni Co-op') + d = create(:distributor, :name => 'Melb Uni Co-op', :description => '

Hello, world!

') create(:product, :distributors => [d]) # When I select the distributor visit spree.root_path click_link d.name + # Then I should see the name of the distributor that I've selected + page.should have_selector 'h2', :text => 'Melb Uni Co-op' + + # And I should see the distributor's long description + page.should have_selector 'div.distributor-description', :text => 'Hello, world!' + end + + it "displays the distributor's name on the home page" do + # Given a distributor with a product + d = create(:distributor, :name => 'Melb Uni Co-op', :description => '

Hello, world!

') + create(:product, :distributors => [d]) + + # When I select the distributor + visit spree.root_path + click_link d.name + visit spree.root_path + # Then I should see the name of the distributor that I've selected page.should have_content 'You are shopping at Melb Uni Co-op' + page.should_not have_selector 'div.distributor-description' end it "splits the product listing by local/remote distributor" do @@ -54,6 +71,7 @@ feature %q{ # When I select the first distributor visit spree.root_path click_link d1.name + visit spree.root_path # Then I should see products split by local/remote distributor # on the home page, the products page, the search results page and the taxon page