Commit bb03159988747ffeb89587cd2f0c727569ba664b

Authored by Rodrigo Souto
1 parent 6b037511

shopping_cart: avoid crash on buy if there is no cart

(ActionItem2808)
plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb
... ... @@ -94,10 +94,12 @@ class ShoppingCartPluginController < PublicController
94 94 end
95 95  
96 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 103 end
102 104  
103 105 def send_request
... ...
plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb
... ... @@ -187,6 +187,12 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase
187 187 assert !cart?, "cart expected to be empty!"
188 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 196 private
191 197  
192 198 def json_response
... ...