Commit da6c280a912b7619a7ca0911f37da7a7672a8af1
1 parent
c553ad10
Exists in
master
and in
22 other branches
Fix cart cleaning with path-specific cookie
Showing
2 changed files
with
16 additions
and
3 deletions
Show diff stats
plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb
... | ... | @@ -109,6 +109,7 @@ class ShoppingCartPluginController < PublicController |
109 | 109 | enterprise = Enterprise.find(cart[:enterprise_id]) |
110 | 110 | ShoppingCartPlugin::Mailer.deliver_customer_notification(params[:customer], enterprise, self.cart[:items]) |
111 | 111 | ShoppingCartPlugin::Mailer.deliver_supplier_notification(params[:customer], enterprise, self.cart[:items]) |
112 | + self.cart = nil | |
112 | 113 | render :text => { |
113 | 114 | :ok => true, |
114 | 115 | :message => _('Request sent successfully. Check your email.'), |
... | ... | @@ -279,7 +280,11 @@ class ShoppingCartPluginController < PublicController |
279 | 280 | after_filter :save_cookie |
280 | 281 | def save_cookie |
281 | 282 | if @cart.nil? |
282 | - cookies.delete(cookie_key) | |
283 | + cookies[cookie_key] = { | |
284 | + :value => '', | |
285 | + :path => '/plugin/shopping_cart', | |
286 | + :expires => 1.year.ago, | |
287 | + } | |
283 | 288 | else |
284 | 289 | cookies[cookie_key] = { |
285 | 290 | :value => Base64.encode64(@cart.to_yaml), | ... | ... |
plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb
... | ... | @@ -16,9 +16,10 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
16 | 16 | attr_reader :enterprise |
17 | 17 | attr_reader :product |
18 | 18 | |
19 | - should 'return no cookie for an empty cart' do | |
19 | + should 'force cookie expiration with explicit path for an empty cart' do | |
20 | 20 | get :get |
21 | - assert_nil @response.cookies[:_noosfero_plugin_shopping_cart] | |
21 | + last_year = 1.year.ago.year | |
22 | + assert @response.headers['Set-Cookie'].any? { |c| c =~ /_noosfero_plugin_shopping_cart=; path=\/plugin\/shopping_cart; expires=.*-#{last_year}/} | |
22 | 23 | end |
23 | 24 | |
24 | 25 | should 'add a new product to cart' do |
... | ... | @@ -180,6 +181,13 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
180 | 181 | assert_equal 0, order.products_list[product1.id][:price] |
181 | 182 | end |
182 | 183 | |
184 | + should 'clean the cart after placing the order' do | |
185 | + product1 = fast_create(Product, :enterprise_id => enterprise.id) | |
186 | + post :add, :id => product1.id | |
187 | + post :send_request, :customer => { :name => "Manuel", :email => "manuel@ceu.com" } | |
188 | + assert !cart?, "cart expected to be empty!" | |
189 | + end | |
190 | + | |
183 | 191 | private |
184 | 192 | |
185 | 193 | def json_response | ... | ... |