Commit bb03159988747ffeb89587cd2f0c727569ba664b
1 parent
6b037511
Exists in
master
and in
29 other branches
shopping_cart: avoid crash on buy if there is no cart
(ActionItem2808)
Showing
2 changed files
with
12 additions
and
4 deletions
Show diff stats
plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb
@@ -94,10 +94,12 @@ class ShoppingCartPluginController < PublicController | @@ -94,10 +94,12 @@ class ShoppingCartPluginController < PublicController | ||
94 | end | 94 | end |
95 | 95 | ||
96 | def buy | 96 | def buy |
97 | - @cart = cart | ||
98 | - @enterprise = environment.enterprises.find(cart[:enterprise_id]) | ||
99 | - @settings = Noosfero::Plugin::Settings.new(@enterprise, ShoppingCartPlugin) | ||
100 | - render :layout => false | 97 | + if validate_cart_presence |
98 | + @cart = cart | ||
99 | + @enterprise = environment.enterprises.find(cart[:enterprise_id]) | ||
100 | + @settings = Noosfero::Plugin::Settings.new(@enterprise, ShoppingCartPlugin) | ||
101 | + render :layout => false | ||
102 | + end | ||
101 | end | 103 | end |
102 | 104 | ||
103 | def send_request | 105 | def send_request |
plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb
@@ -187,6 +187,12 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | @@ -187,6 +187,12 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | ||
187 | assert !cart?, "cart expected to be empty!" | 187 | assert !cart?, "cart expected to be empty!" |
188 | end | 188 | end |
189 | 189 | ||
190 | + should 'not allow buy without any cart' do | ||
191 | + get :buy | ||
192 | + assert !json_response[:ok] | ||
193 | + assert_equal 2, json_response['error']['code'] | ||
194 | + end | ||
195 | + | ||
190 | private | 196 | private |
191 | 197 | ||
192 | def json_response | 198 | def json_response |