Commit 80163119fa7ffe603b2d44235edd99fca1a66719
1 parent
abde28a7
Exists in
master
and in
29 other branches
Fix shopping cart tests
Showing
5 changed files
with
55 additions
and
47 deletions
Show diff stats
plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb
... | ... | @@ -107,8 +107,8 @@ class ShoppingCartPluginController < PublicController |
107 | 107 | register_order(params[:customer], self.cart[:items]) |
108 | 108 | begin |
109 | 109 | enterprise = environment.enterprises.find(cart[:profile_id]) |
110 | - ShoppingCartPlugin::Mailer.deliver_customer_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option]) | |
111 | - ShoppingCartPlugin::Mailer.deliver_supplier_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option]) | |
110 | + ShoppingCartPlugin::Mailer.customer_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option]).deliver | |
111 | + ShoppingCartPlugin::Mailer.supplier_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option]).deliver | |
112 | 112 | self.cart = nil |
113 | 113 | render :text => { |
114 | 114 | :ok => true, |
... | ... | @@ -268,22 +268,22 @@ class ShoppingCartPluginController < PublicController |
268 | 268 | price = product.price || 0 |
269 | 269 | new_items[id] = {:quantity => quantity, :price => price, :name => product.name} |
270 | 270 | end |
271 | - ShoppingCartPlugin::PurchaseOrder.create!( | |
272 | - :seller => Enterprise.find(cart[:profile_id]), | |
273 | - :customer => user, | |
274 | - :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED, | |
275 | - :products_list => new_items, | |
276 | - :customer_delivery_option => params[:delivery_option], | |
277 | - :customer_payment => params[:customer][:payment], | |
278 | - :customer_change => params[:customer][:change], | |
279 | - :customer_name => params[:customer][:name], | |
280 | - :customer_email => params[:customer][:email], | |
281 | - :customer_contact_phone => params[:customer][:contact_phone], | |
282 | - :customer_address => params[:customer][:address], | |
283 | - :customer_district => params[:customer][:district], | |
284 | - :customer_city => params[:customer][:city], | |
285 | - :customer_zip_code => params[:customer][:zip_code] | |
286 | - ) | |
271 | + purchase_order = ShoppingCartPlugin::PurchaseOrder.new | |
272 | + purchase_order.seller = Enterprise.find(cart[:profile_id]) | |
273 | + purchase_order.customer = user | |
274 | + purchase_order.status = ShoppingCartPlugin::PurchaseOrder::Status::OPENED | |
275 | + purchase_order.products_list = new_items | |
276 | + purchase_order.customer_delivery_option = params[:delivery_option] | |
277 | + purchase_order.customer_payment = params[:customer][:payment] | |
278 | + purchase_order.customer_change = params[:customer][:change] | |
279 | + purchase_order.customer_name = params[:customer][:name] | |
280 | + purchase_order.customer_email = params[:customer][:email] | |
281 | + purchase_order.customer_contact_phone = params[:customer][:contact_phone] | |
282 | + purchase_order.customer_address = params[:customer][:address] | |
283 | + purchase_order.customer_district = params[:customer][:district] | |
284 | + purchase_order.customer_city = params[:customer][:city] | |
285 | + purchase_order.customer_zip_code = params[:customer][:zip_code] | |
286 | + purchase_order.save! | |
287 | 287 | end |
288 | 288 | |
289 | 289 | protected | ... | ... |
plugins/shopping_cart/lib/shopping_cart_plugin/mailer.rb
... | ... | @@ -4,31 +4,37 @@ class ShoppingCartPlugin::Mailer < Noosfero::Plugin::MailerBase |
4 | 4 | |
5 | 5 | def customer_notification(customer, supplier, items, delivery_option) |
6 | 6 | domain = supplier.hostname || supplier.environment.default_hostname |
7 | - recipients customer[:email] | |
8 | - from 'no-reply@' + domain | |
9 | - reply_to supplier.contact_email | |
10 | - subject _("[%s] Your buy request was performed successfully.") % supplier[:name] | |
11 | - content_type 'text/html' | |
12 | - body :customer => customer, | |
13 | - :supplier => supplier, | |
14 | - :items => items, | |
15 | - :environment => supplier.environment, | |
16 | - :helper => self, | |
17 | - :delivery_option => delivery_option | |
7 | + @customer = customer | |
8 | + @supplier = supplier | |
9 | + @items = items | |
10 | + @environment = supplier.environment | |
11 | + @helper = self | |
12 | + @delivery_option = delivery_option | |
13 | + | |
14 | + mail( | |
15 | + to: customer[:email], | |
16 | + from: 'no-reply@' + domain, | |
17 | + reply_to: supplier.contact_email, | |
18 | + subject: _("[%s] Your buy request was performed successfully.") % supplier[:name], | |
19 | + content_type: 'text/html' | |
20 | + ) | |
18 | 21 | end |
19 | 22 | |
20 | 23 | def supplier_notification(customer, supplier, items, delivery_option) |
21 | 24 | domain = supplier.environment.default_hostname |
22 | - recipients supplier.contact_email | |
23 | - from 'no-reply@' + domain | |
24 | - reply_to customer[:email] | |
25 | - subject _("[%s] You have a new buy request from %s.") % [supplier.environment.name, customer[:name]] | |
26 | - content_type 'text/html' | |
27 | - body :customer => customer, | |
28 | - :supplier => supplier, | |
29 | - :items => items, | |
30 | - :environment => supplier.environment, | |
31 | - :helper => self, | |
32 | - :delivery_option => delivery_option | |
25 | + @customer = customer | |
26 | + @supplier = supplier | |
27 | + @items = items | |
28 | + @environment = supplier.environment | |
29 | + @helper = self | |
30 | + @delivery_option = delivery_option | |
31 | + | |
32 | + mail( | |
33 | + to: supplier.contact_email, | |
34 | + from: 'no-reply@' + domain, | |
35 | + reply_to: customer[:email], | |
36 | + subject: _("[%s] You have a new buy request from %s.") % [supplier.environment.name, customer[:name]], | |
37 | + content_type: 'text/html' | |
38 | + ) | |
33 | 39 | end |
34 | 40 | end | ... | ... |
plugins/shopping_cart/lib/shopping_cart_plugin/purchase_order.rb
... | ... | @@ -5,6 +5,8 @@ class ShoppingCartPlugin::PurchaseOrder < Noosfero::Plugin::ActiveRecord |
5 | 5 | |
6 | 6 | validates_presence_of :status, :seller |
7 | 7 | |
8 | + attr_accessible :seller, :status, :products_list | |
9 | + | |
8 | 10 | acts_as_having_settings :field => :data |
9 | 11 | |
10 | 12 | settings_items :products_list, :type => Array, :default => {} | ... | ... |
plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb
... | ... | @@ -18,7 +18,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
18 | 18 | |
19 | 19 | should 'force cookie expiration with explicit path for an empty cart' do |
20 | 20 | get :get |
21 | - assert @response.headers['Set-Cookie'].any? { |c| c =~ /_noosfero_plugin_shopping_cart=; path=\/plugin\/shopping_cart; expires=.*-1970/} | |
21 | + assert @response.headers['Set-Cookie'] =~ /_noosfero_plugin_shopping_cart=; path=\/plugin\/shopping_cart; expires=.*-1970/ | |
22 | 22 | end |
23 | 23 | |
24 | 24 | should 'add a new product to cart' do |
... | ... | @@ -41,7 +41,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
41 | 41 | |
42 | 42 | assert !product_in_cart?(product) |
43 | 43 | assert !response_ok? |
44 | - assert 3, reponse_error_code | |
44 | + assert_equal 3, reponse_error_code | |
45 | 45 | end |
46 | 46 | |
47 | 47 | should 'remove cart if the product being removed is the last one' do |
... | ... | @@ -98,10 +98,10 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
98 | 98 | |
99 | 99 | should 'update the quantity of a product' do |
100 | 100 | get :add, :id => product.id |
101 | - assert 1, product_quantity(product) | |
101 | + assert_equal 1, product_quantity(product) | |
102 | 102 | |
103 | 103 | get :update_quantity, :id => product.id, :quantity => 3 |
104 | - assert 3, product_quantity(product) | |
104 | + assert_equal 3, product_quantity(product) | |
105 | 105 | end |
106 | 106 | |
107 | 107 | should 'not try to update quantity the quantity of a product if there is no cart' do |
... | ... | @@ -153,7 +153,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
153 | 153 | product1 = fast_create(Product, :profile_id => enterprise.id, :price => 1.99) |
154 | 154 | product2 = fast_create(Product, :profile_id => enterprise.id, :price => 2.23) |
155 | 155 | @controller.stubs(:cart).returns({ :profile_id => enterprise.id, :items => {product1.id => 1, product2.id => 2}}) |
156 | - assert_difference ShoppingCartPlugin::PurchaseOrder, :count, 1 do | |
156 | + assert_difference 'ShoppingCartPlugin::PurchaseOrder.count', 1 do | |
157 | 157 | post :send_request, |
158 | 158 | :customer => {:name => "Manuel", :email => "manuel@ceu.com"} |
159 | 159 | end |
... | ... | @@ -170,7 +170,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
170 | 170 | should 'register order on send request and not crash if product is not defined' do |
171 | 171 | product1 = fast_create(Product, :profile_id => enterprise.id) |
172 | 172 | @controller.stubs(:cart).returns({ :profile_id => enterprise.id, :items => {product1.id => 1}}) |
173 | - assert_difference ShoppingCartPlugin::PurchaseOrder, :count, 1 do | |
173 | + assert_difference 'ShoppingCartPlugin::PurchaseOrder.count', 1 do | |
174 | 174 | post :send_request, |
175 | 175 | :customer => {:name => "Manuel", :email => "manuel@ceu.com"} |
176 | 176 | end | ... | ... |
plugins/shopping_cart/test/functional/shopping_cart_plugin_myprofile_controller_test.rb
... | ... | @@ -48,7 +48,7 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase |
48 | 48 | price = 4.35 |
49 | 49 | post :edit, :profile => enterprise.identifier, :settings => {:delivery_price => price} |
50 | 50 | |
51 | - assert settings.delivery_price == price | |
51 | + assert settings.delivery_price == price.to_s | |
52 | 52 | end |
53 | 53 | |
54 | 54 | should 'be able to choose delivery_options' do | ... | ... |