Leave a distributor

This commit is contained in:
Rohan Mitchell
2012-06-23 12:33:38 +10:00
parent 2cdf32590c
commit 5e6c4de34b
4 changed files with 23 additions and 1 deletions

View File

@@ -18,5 +18,13 @@ module Spree
redirect_back_or_default(root_path)
end
def deselect
order = current_order(true)
order.distributor = nil
order.save!
redirect_back_or_default(root_path)
end
end
end

View File

@@ -8,3 +8,5 @@
%ul.filter_choices
- @distributors.each do |distributor|
%li.nowrap= link_to distributor.name, select_distributor_path(distributor)
- if current_distributor
%li.nowrap= link_to 'Leave distributor', deselect_distributors_path

View File

@@ -8,6 +8,7 @@ Spree::Core::Engine.routes.prepend do
resources :suppliers
resources :distributors do
get :select, :on => :member
get :deselect, :on => :collection
end
namespace :admin do

View File

@@ -39,7 +39,18 @@ feature %q{
it "splits the product listing by local/remote distributor"
it "allows the user to leave the distributor"
it "allows the user to leave the distributor" do
# Given a distributor
d = create(:distributor, :name => 'Melb Uni Co-op')
# When I select the distributor and then leave it
visit spree.root_path
click_link d.name
click_link 'Leave distributor'
# 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" do
it "provides a choice of distributor when adding to cart" # Test product at remote distributor