Commit da6c280a912b7619a7ca0911f37da7a7672a8af1
1 parent
c553ad10
Exists in
staging
and in
42 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,6 +109,7 @@ class ShoppingCartPluginController < PublicController | ||
109 | enterprise = Enterprise.find(cart[:enterprise_id]) | 109 | enterprise = Enterprise.find(cart[:enterprise_id]) |
110 | ShoppingCartPlugin::Mailer.deliver_customer_notification(params[:customer], enterprise, self.cart[:items]) | 110 | ShoppingCartPlugin::Mailer.deliver_customer_notification(params[:customer], enterprise, self.cart[:items]) |
111 | ShoppingCartPlugin::Mailer.deliver_supplier_notification(params[:customer], enterprise, self.cart[:items]) | 111 | ShoppingCartPlugin::Mailer.deliver_supplier_notification(params[:customer], enterprise, self.cart[:items]) |
112 | + self.cart = nil | ||
112 | render :text => { | 113 | render :text => { |
113 | :ok => true, | 114 | :ok => true, |
114 | :message => _('Request sent successfully. Check your email.'), | 115 | :message => _('Request sent successfully. Check your email.'), |
@@ -279,7 +280,11 @@ class ShoppingCartPluginController < PublicController | @@ -279,7 +280,11 @@ class ShoppingCartPluginController < PublicController | ||
279 | after_filter :save_cookie | 280 | after_filter :save_cookie |
280 | def save_cookie | 281 | def save_cookie |
281 | if @cart.nil? | 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 | else | 288 | else |
284 | cookies[cookie_key] = { | 289 | cookies[cookie_key] = { |
285 | :value => Base64.encode64(@cart.to_yaml), | 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,9 +16,10 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | ||
16 | attr_reader :enterprise | 16 | attr_reader :enterprise |
17 | attr_reader :product | 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 | get :get | 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 | end | 23 | end |
23 | 24 | ||
24 | should 'add a new product to cart' do | 25 | should 'add a new product to cart' do |
@@ -180,6 +181,13 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | @@ -180,6 +181,13 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | ||
180 | assert_equal 0, order.products_list[product1.id][:price] | 181 | assert_equal 0, order.products_list[product1.id][:price] |
181 | end | 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 | private | 191 | private |
184 | 192 | ||
185 | def json_response | 193 | def json_response |