Commit b2e59b620688129c3a6649c34816221be8f04896
1 parent
ddf8ec9d
Exists in
master
and in
29 other branches
shopping_cart: fix tests
Showing
15 changed files
with
331 additions
and
450 deletions
Show diff stats
plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb
... | ... | @@ -8,39 +8,39 @@ class ShoppingCartPluginController < OrdersPluginController |
8 | 8 | def get |
9 | 9 | config = |
10 | 10 | if cart.nil? |
11 | - { :profile_id => params[:profile_id], | |
12 | - :has_products => false, | |
13 | - :visible => false, | |
14 | - :products => []} | |
11 | + { profile_id: params[:profile_id], | |
12 | + has_products: false, | |
13 | + visible: false, | |
14 | + products: []} | |
15 | 15 | else |
16 | 16 | { |
17 | - :profile_id => cart[:profile_id], | |
18 | - :profile_short_name => cart_profile.short_name, | |
19 | - :has_products => (cart[:items].keys.size > 0), | |
20 | - :visible => visible?, | |
21 | - :products => products, | |
17 | + profile_id: cart[:profile_id], | |
18 | + profile_short_name: cart_profile.short_name, | |
19 | + has_products: (cart[:items].keys.size > 0), | |
20 | + visible: visible?, | |
21 | + products: products, | |
22 | 22 | } |
23 | 23 | end |
24 | 24 | config[:has_previous_orders] = if cart_profile then previous_orders.first.present? else false end |
25 | - render :text => config.to_json | |
25 | + render text: config.to_json | |
26 | 26 | end |
27 | 27 | |
28 | 28 | def add |
29 | 29 | product = find_product(params[:id]) |
30 | 30 | if product && (profile = validate_same_profile(product)) |
31 | - self.cart = { :profile_id => profile.id, :items => {} } if self.cart.nil? | |
31 | + self.cart = { profile_id: profile.id, items: {} } if self.cart.nil? | |
32 | 32 | self.cart[:items][product.id] = 0 if self.cart[:items][product.id].nil? |
33 | 33 | self.cart[:items][product.id] += 1 |
34 | - render :text => { | |
35 | - :ok => true, | |
36 | - :error => {:code => 0}, | |
37 | - :products => [{ | |
38 | - :id => product.id, | |
39 | - :name => product.name, | |
40 | - :price => get_price(product, profile.environment), | |
41 | - :description => product.description, | |
42 | - :picture => product.default_image(:minor), | |
43 | - :quantity => self.cart[:items][product.id] | |
34 | + render text: { | |
35 | + ok: true, | |
36 | + error: {code: 0}, | |
37 | + products: [{ | |
38 | + id: product.id, | |
39 | + name: product.name, | |
40 | + price: get_price(product, profile.environment), | |
41 | + description: product.description, | |
42 | + picture: product.default_image(:minor), | |
43 | + quantity: self.cart[:items][product.id] | |
44 | 44 | }] |
45 | 45 | }.to_json |
46 | 46 | end |
... | ... | @@ -51,20 +51,20 @@ class ShoppingCartPluginController < OrdersPluginController |
51 | 51 | if validate_cart_presence && validate_cart_has_product(id) |
52 | 52 | self.cart[:items].delete(id) |
53 | 53 | self.cart = nil if self.cart[:items].empty? |
54 | - render :text => { | |
55 | - :ok => true, | |
56 | - :error => {:code => 0}, | |
57 | - :product_id => id | |
54 | + render text: { | |
55 | + ok: true, | |
56 | + error: {code: 0}, | |
57 | + product_id: id | |
58 | 58 | }.to_json |
59 | 59 | end |
60 | 60 | end |
61 | 61 | |
62 | 62 | def list |
63 | 63 | if validate_cart_presence |
64 | - render :text => { | |
65 | - :ok => true, | |
66 | - :error => {:code => 0}, | |
67 | - :products => products | |
64 | + render text: { | |
65 | + ok: true, | |
66 | + error: {code: 0}, | |
67 | + products: products | |
68 | 68 | }.to_json |
69 | 69 | end |
70 | 70 | end |
... | ... | @@ -75,20 +75,20 @@ class ShoppingCartPluginController < OrdersPluginController |
75 | 75 | if validate_cart_presence && validate_cart_has_product(id) && validate_item_quantity(quantity) |
76 | 76 | product = Product.find(id) |
77 | 77 | self.cart[:items][product.id] = quantity |
78 | - render :text => { | |
79 | - :ok => true, | |
80 | - :error => {:code => 0}, | |
81 | - :product_id => id, | |
82 | - :quantity => quantity | |
78 | + render text: { | |
79 | + ok: true, | |
80 | + error: {code: 0}, | |
81 | + product_id: id, | |
82 | + quantity: quantity | |
83 | 83 | }.to_json |
84 | 84 | end |
85 | 85 | end |
86 | 86 | |
87 | 87 | def clean |
88 | 88 | self.cart = nil |
89 | - render :text => { | |
90 | - :ok => true, | |
91 | - :error => {:code => 0} | |
89 | + render text: { | |
90 | + ok: true, | |
91 | + error: {code: 0} | |
92 | 92 | }.to_json |
93 | 93 | end |
94 | 94 | |
... | ... | @@ -121,7 +121,7 @@ class ShoppingCartPluginController < OrdersPluginController |
121 | 121 | @profile = cart_profile |
122 | 122 | @order = profile.sales.build consumer: user |
123 | 123 | |
124 | - @order.supplier_delivery = profile.delivery_methods.find session[:cart][:last_delivery_option_id] rescue nil | |
124 | + @order.supplier_delivery = profile.delivery_methods.where(id: session[:cart][:last_delivery_option_id]).first | |
125 | 125 | if repeat_order_id = self.cart[:repeat_order_id] |
126 | 126 | repeat_order = cart_profile.orders.where(id: repeat_order_id).first |
127 | 127 | @order.consumer_delivery_data = repeat_order.consumer_delivery_data if repeat_order |
... | ... | @@ -146,23 +146,23 @@ class ShoppingCartPluginController < OrdersPluginController |
146 | 146 | end |
147 | 147 | |
148 | 148 | def visibility |
149 | - render :text => visible?.to_json | |
149 | + render text: visible?.to_json | |
150 | 150 | end |
151 | 151 | |
152 | 152 | def show |
153 | 153 | begin |
154 | 154 | self.cart[:visibility] = true |
155 | - render :text => { | |
156 | - :ok => true, | |
157 | - :message => _('Basket displayed.'), | |
158 | - :error => {:code => 0} | |
155 | + render text: { | |
156 | + ok: true, | |
157 | + message: _('Basket displayed.'), | |
158 | + error: {code: 0} | |
159 | 159 | }.to_json |
160 | 160 | rescue Exception => exception |
161 | - render :text => { | |
162 | - :ok => false, | |
163 | - :error => { | |
164 | - :code => 7, | |
165 | - :message => exception.message | |
161 | + render text: { | |
162 | + ok: false, | |
163 | + error: { | |
164 | + code: 7, | |
165 | + message: exception.message | |
166 | 166 | } |
167 | 167 | }.to_json |
168 | 168 | end |
... | ... | @@ -171,17 +171,17 @@ class ShoppingCartPluginController < OrdersPluginController |
171 | 171 | def hide |
172 | 172 | begin |
173 | 173 | self.cart[:visibility] = false |
174 | - render :text => { | |
175 | - :ok => true, | |
176 | - :message => _('Basket hidden.'), | |
177 | - :error => {:code => 0} | |
174 | + render text: { | |
175 | + ok: true, | |
176 | + message: _('Basket hidden.'), | |
177 | + error: {code: 0} | |
178 | 178 | }.to_json |
179 | 179 | rescue Exception => exception |
180 | - render :text => { | |
181 | - :ok => false, | |
182 | - :error => { | |
183 | - :code => 8, | |
184 | - :message => exception.message | |
180 | + render text: { | |
181 | + ok: false, | |
182 | + error: { | |
183 | + code: 8, | |
184 | + message: exception.message | |
185 | 185 | } |
186 | 186 | }.to_json |
187 | 187 | end |
... | ... | @@ -189,7 +189,7 @@ class ShoppingCartPluginController < OrdersPluginController |
189 | 189 | |
190 | 190 | def update_supplier_delivery |
191 | 191 | @profile = cart_profile |
192 | - supplier_delivery = @profile.delivery_methods.find params[:order][:supplier_delivery_id] | |
192 | + supplier_delivery = @profile.delivery_methods.where(id: params[:order][:supplier_delivery_id]).first | |
193 | 193 | order = build_order self.cart[:items], supplier_delivery |
194 | 194 | total_price = order.total_price |
195 | 195 | render json: { |
... | ... | @@ -210,11 +210,11 @@ class ShoppingCartPluginController < OrdersPluginController |
210 | 210 | |
211 | 211 | def validate_same_profile(product) |
212 | 212 | if self.cart && self.cart[:profile_id] && product.profile_id != self.cart[:profile_id] |
213 | - render :text => { | |
214 | - :ok => false, | |
215 | - :error => { | |
216 | - :code => 1, | |
217 | - :message => _("Your basket contains items from '%{profile_name}'. Please empty the basket or checkout before adding items from here.") % {profile_name: cart_profile.short_name} | |
213 | + render text: { | |
214 | + ok: false, | |
215 | + error: { | |
216 | + code: 1, | |
217 | + message: _("Your basket contains items from '%{profile_name}'. Please empty the basket or checkout before adding items from here.") % {profile_name: cart_profile.short_name} | |
218 | 218 | } |
219 | 219 | }.to_json |
220 | 220 | return nil |
... | ... | @@ -224,11 +224,11 @@ class ShoppingCartPluginController < OrdersPluginController |
224 | 224 | |
225 | 225 | def validate_cart_presence |
226 | 226 | if self.cart.nil? |
227 | - render :text => { | |
228 | - :ok => false, | |
229 | - :error => { | |
230 | - :code => 2, | |
231 | - :message => _("There is no basket.") | |
227 | + render text: { | |
228 | + ok: false, | |
229 | + error: { | |
230 | + code: 2, | |
231 | + message: _("There is no basket.") | |
232 | 232 | } |
233 | 233 | }.to_json |
234 | 234 | return false |
... | ... | @@ -240,11 +240,11 @@ class ShoppingCartPluginController < OrdersPluginController |
240 | 240 | begin |
241 | 241 | product = Product.find(id) |
242 | 242 | rescue ActiveRecord::RecordNotFound |
243 | - render :text => { | |
244 | - :ok => false, | |
245 | - :error => { | |
246 | - :code => 3, | |
247 | - :message => _("This enterprise doesn't have this product.") | |
243 | + render text: { | |
244 | + ok: false, | |
245 | + error: { | |
246 | + code: 3, | |
247 | + message: _("This enterprise doesn't have this product.") | |
248 | 248 | } |
249 | 249 | }.to_json |
250 | 250 | return nil |
... | ... | @@ -254,11 +254,11 @@ class ShoppingCartPluginController < OrdersPluginController |
254 | 254 | |
255 | 255 | def validate_cart_has_product(id) |
256 | 256 | if !self.cart[:items].has_key?(id) |
257 | - render :text => { | |
258 | - :ok => false, | |
259 | - :error => { | |
260 | - :code => 4, | |
261 | - :message => _("The basket doesn't have this product.") | |
257 | + render text: { | |
258 | + ok: false, | |
259 | + error: { | |
260 | + code: 4, | |
261 | + message: _("The basket doesn't have this product.") | |
262 | 262 | } |
263 | 263 | }.to_json |
264 | 264 | return false |
... | ... | @@ -268,11 +268,11 @@ class ShoppingCartPluginController < OrdersPluginController |
268 | 268 | |
269 | 269 | def validate_item_quantity(quantity) |
270 | 270 | if quantity.to_i < 1 |
271 | - render :text => { | |
272 | - :ok => false, | |
273 | - :error => { | |
274 | - :code => 5, | |
275 | - :message => _("Invalid quantity.") | |
271 | + render text: { | |
272 | + ok: false, | |
273 | + error: { | |
274 | + code: 5, | |
275 | + message: _("Invalid quantity.") | |
276 | 276 | } |
277 | 277 | }.to_json |
278 | 278 | return false |
... | ... | @@ -284,12 +284,12 @@ class ShoppingCartPluginController < OrdersPluginController |
284 | 284 | products_list = {}; items.each do |id, quantity| |
285 | 285 | product = Product.find(id) |
286 | 286 | price = product.price || 0 |
287 | - products_list[id] = {:quantity => quantity, :price => price, :name => product.name} | |
287 | + products_list[id] = {quantity: quantity, price: price, name: product.name} | |
288 | 288 | end |
289 | 289 | |
290 | 290 | order = OrdersPlugin::Sale.new |
291 | 291 | order.profile = environment.profiles.find(cart[:profile_id]) |
292 | - order.supplier_delivery = profile.delivery_methods.find params[:order][:supplier_delivery_id] | |
292 | + order.supplier_delivery = profile.delivery_methods.where(id: params[:order][:supplier_delivery_id]).first | |
293 | 293 | order.session_id = session_id unless user |
294 | 294 | order.consumer = user |
295 | 295 | order.source = 'shopping_cart_plugin' |
... | ... | @@ -330,11 +330,11 @@ class ShoppingCartPluginController < OrdersPluginController |
330 | 330 | after_filter :save_cookie |
331 | 331 | def save_cookie |
332 | 332 | if @cart.nil? |
333 | - cookies.delete(cookie_key, :path => '/plugin/shopping_cart') | |
333 | + cookies.delete(cookie_key, path: '/plugin/shopping_cart') | |
334 | 334 | else |
335 | 335 | cookies[cookie_key] = { |
336 | - :value => Base64.encode64(@cart.to_yaml), | |
337 | - :path => "/plugin/shopping_cart" | |
336 | + value: Base64.encode64(@cart.to_yaml), | |
337 | + path: "/plugin/shopping_cart" | |
338 | 338 | } |
339 | 339 | end |
340 | 340 | end |
... | ... | @@ -351,20 +351,20 @@ class ShoppingCartPluginController < OrdersPluginController |
351 | 351 | self.cart[:items].collect do |id, quantity| |
352 | 352 | product = Product.find_by_id(id) |
353 | 353 | if product |
354 | - { :id => product.id, | |
355 | - :name => product.name, | |
356 | - :price => get_price(product, product.profile.environment), | |
357 | - :description => product.description, | |
358 | - :picture => product.default_image(:minor), | |
359 | - :quantity => quantity | |
354 | + { id: product.id, | |
355 | + name: product.name, | |
356 | + price: get_price(product, product.profile.environment), | |
357 | + description: product.description, | |
358 | + picture: product.default_image(:minor), | |
359 | + quantity: quantity | |
360 | 360 | } |
361 | 361 | else |
362 | - { :id => id, | |
363 | - :name => _('Undefined product'), | |
364 | - :price => 0, | |
365 | - :description => _('Wrong product id'), | |
366 | - :picture => '', | |
367 | - :quantity => quantity | |
362 | + { id: id, | |
363 | + name: _('Undefined product'), | |
364 | + price: 0, | |
365 | + description: _('Wrong product id'), | |
366 | + picture: '', | |
367 | + quantity: quantity | |
368 | 368 | } |
369 | 369 | end |
370 | 370 | end | ... | ... |
plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb
... | ... | @@ -5,13 +5,8 @@ class ShoppingCartPluginMyprofileController < MyProfileController |
5 | 5 | def edit |
6 | 6 | params[:settings] = treat_cart_options(params[:settings]) |
7 | 7 | @settings = profile.shopping_cart_settings params[:settings] || {} |
8 | - respond_to do |format| | |
9 | - format.js do | |
10 | - if request.post? | |
11 | - @success = @settings.save! | |
12 | - end | |
13 | - end | |
14 | - format.html | |
8 | + if request.post? | |
9 | + @success = @settings.save! | |
15 | 10 | end |
16 | 11 | end |
17 | 12 | ... | ... |
plugins/shopping_cart/delivery_admin.feature
... | ... | @@ -1,81 +0,0 @@ |
1 | -Feature: delivery administration | |
2 | - As an enterprise's administrator | |
3 | - I want to create delivery methods | |
4 | - In order to allow my customer to choose which delivery they want | |
5 | - | |
6 | - Background: | |
7 | - Given "ShoppingCart" plugin is enabled | |
8 | - And "Delivery" plugin is enabled | |
9 | - And the following users | |
10 | - | login | name | | |
11 | - | moe | Moe | | |
12 | - And the following enterprise | |
13 | - | identifier | name | owner | | |
14 | - | moes-tavern | Moes Tavern | moe | | |
15 | - And the shopping basket is enabled on "Moes Tavern" | |
16 | - And "Moe" is admin of "Moes Tavern" | |
17 | - And I am logged in as "moe" | |
18 | - And I go to moes-tavern's control panel | |
19 | - | |
20 | - @selenium | |
21 | - Scenario: enable delivery | |
22 | - Given I follow "Shopping basket" | |
23 | - When I check "Enable shopping basket" | |
24 | - Then I should see "Deliveries or pickups" | |
25 | - | |
26 | - @selenium | |
27 | - Scenario: disable delivery | |
28 | - Given I follow "Shopping basket" | |
29 | - When I uncheck "Enable shopping basket" | |
30 | - Then I should not see "Deliveries or pickups" | |
31 | - | |
32 | - @selenium | |
33 | - Scenario: create new deliver | |
34 | - Given I follow "Shopping basket" | |
35 | - And I check "Enable shopping basket" | |
36 | - And I follow "New delivery or pickup" | |
37 | - And I select "Deliver" from "Type" | |
38 | - And I fill in "Name" with "Bike" | |
39 | - And I fill in "Description" with "Beers delivered with my old bike." | |
40 | - And I fill in "Fixed cost" with "8.00" | |
41 | - And I fill in "Order's minimum price for free delivery" with "35.50" | |
42 | - When I press "Add" | |
43 | - Then I should see "Bike" within ".delivery-method" | |
44 | - | |
45 | - @selenium | |
46 | - Scenario: create new pickup | |
47 | - Given I follow "Shopping basket" | |
48 | - And I check "Enable shopping basket" | |
49 | - And I follow "New delivery or pickup" | |
50 | - And I select "Pickup" from "Type" | |
51 | - And I fill in "Name" with "Bar" | |
52 | - And I fill in "Description" with "Come to my bar and pick it yourself." | |
53 | - And I fill in "Fixed cost" with "0.00" | |
54 | - When I press "Add" | |
55 | - Then I should see "Bar" | |
56 | - | |
57 | - @selenium | |
58 | - Scenario: remove delivery | |
59 | - Given I follow "Shopping basket" | |
60 | - And I check "Enable shopping basket" | |
61 | - And I follow "New delivery or pickup" | |
62 | - And I fill in "Name" with "Bike" | |
63 | - When I press "Add" | |
64 | - Then I should see "Bike" | |
65 | - And I follow "Remove" within ".delivery-method" | |
66 | - When I confirm the browser dialog | |
67 | - Then I should see "Bike" | |
68 | - | |
69 | - @selenium | |
70 | - Scenario: edit delivery | |
71 | - Given I follow "Shopping basket" | |
72 | - And I check "Enable shopping basket" | |
73 | - And I follow "New delivery or pickup" | |
74 | - And I fill in "Name" with "Bike" | |
75 | - When I press "Add" | |
76 | - Then I should see "Bike" | |
77 | - And I follow "Edit" within ".delivery-method" | |
78 | - And I fill in "Name" with "Car" | |
79 | - When I press "Save" | |
80 | - Then I should not see "Bike" | |
81 | - Then I should see "Car" |
plugins/shopping_cart/delivery_client.feature
... | ... | @@ -1,77 +0,0 @@ |
1 | -Feature: delivery client | |
2 | - As an enterprise's client | |
3 | - I want to choose the delivery method | |
4 | - In order to receive my procucts properly | |
5 | - | |
6 | - Background: | |
7 | - Given "ShoppingCart" plugin is enabled | |
8 | - And "Delivery" plugin is enabled | |
9 | - And the following users | |
10 | - | login | name | email | | |
11 | - | moe | Moe | moe@springfield.com | | |
12 | - | homer | Homer | homer@springfield.com | | |
13 | - And the following enterprise | |
14 | - | identifier | name | owner | | |
15 | - | moes-tavern | Moes Tavern | moe | | |
16 | - And the shopping basket is enabled on "Moes Tavern" | |
17 | - And the following product_categories | |
18 | - | name | | |
19 | - | Beer | | |
20 | - | Snacks | | |
21 | - And the following products | |
22 | - | owner | category | name | price | | |
23 | - | moes-tavern | beer | Duff | 3.00 | | |
24 | - | moes-tavern | snacks | French fries | 7.00 | | |
25 | - And "moes-tavern" has the following delivery methods | |
26 | - | delivery_type | name | description | fixed_cost | free_over_price | | |
27 | - | deliver | Bike | My good old bike. | 8.00 | 10.00 | | |
28 | - | pickup | Bar | Come to my bar and drink it! | 0.00 | 0.00 | | |
29 | - And feature "products_for_enterprises" is enabled on environment | |
30 | - And I am logged in as "homer" | |
31 | - And I go to moes-tavern's products page | |
32 | - | |
33 | - @selenium | |
34 | - Scenario: choose deliver method for purchase | |
35 | - Given I follow "Add to basket" | |
36 | - And I follow "Add to basket" | |
37 | - And I should see "Show basket" | |
38 | - And I follow "Show basket" | |
39 | - And I follow "Shopping checkout" | |
40 | - And I fill in "Contact phone" with "123456789" | |
41 | - When I select "Bike ($8.00)" from "Option" | |
42 | - Then I should see "My good old bike." within ".instructions" | |
43 | - And I should see "Address" | |
44 | - And I should see "Bike" within "#delivery-name" | |
45 | - And I should see "8.00" within "#delivery-price" | |
46 | - | |
47 | - @selenium | |
48 | - Scenario: choose pickup method for purchase | |
49 | - Given I follow "Add to basket" | |
50 | - And I follow "Add to basket" | |
51 | - And I should see "Show basket" | |
52 | - And I follow "Show basket" | |
53 | - And I follow "Shopping checkout" | |
54 | - And I fill in "Contact phone" with "123456789" | |
55 | - When I select "Bar" from "Option" | |
56 | - Then I should see "Come to my bar and drink it!" within ".instructions" | |
57 | - And I should not see "Address" | |
58 | - And I should see "Bar" within "#delivery-name" | |
59 | - And I should see "0.00" within "#delivery-price" | |
60 | - | |
61 | - @selenium | |
62 | - Scenario: gets free delivery due to free over price | |
63 | - Given I follow "Add to basket" | |
64 | - And I follow "Add to basket" | |
65 | - And I follow "Add to basket" | |
66 | - And I follow "Add to basket" | |
67 | - And I follow "Add to basket" | |
68 | - And I follow "Add to basket" | |
69 | - And I should see "Show basket" | |
70 | - And I follow "Show basket" | |
71 | - And I follow "Shopping checkout" | |
72 | - And I fill in "Contact phone" with "123456789" | |
73 | - When I select "Bike ($8.00)" from "Option" | |
74 | - Then I should see "My good old bike." within ".instructions" | |
75 | - And I should see "Address" | |
76 | - And I should see "Bike" within "#delivery-name" | |
77 | - And I should see "0.00" within "#delivery-price" |
... | ... | @@ -0,0 +1,81 @@ |
1 | +Feature: delivery administration | |
2 | + As an enterprise's administrator | |
3 | + I want to create delivery methods | |
4 | + In order to allow my customer to choose which delivery they want | |
5 | + | |
6 | + Background: | |
7 | + Given "ShoppingCart" plugin is enabled | |
8 | + And "Delivery" plugin is enabled | |
9 | + And the following users | |
10 | + | login | name | | |
11 | + | moe | Moe | | |
12 | + And the following enterprise | |
13 | + | identifier | name | owner | | |
14 | + | moes-tavern | Moes Tavern | moe | | |
15 | + And the shopping basket is enabled on "Moes Tavern" | |
16 | + And "Moe" is admin of "Moes Tavern" | |
17 | + And I am logged in as "moe" | |
18 | + And I go to moes-tavern's control panel | |
19 | + | |
20 | + @selenium | |
21 | + Scenario: enable delivery | |
22 | + Given I follow "Shopping basket" | |
23 | + When I check "Enable shopping basket" | |
24 | + Then I should see "Deliveries or pickups" | |
25 | + | |
26 | + @selenium | |
27 | + Scenario: disable delivery | |
28 | + Given I follow "Shopping basket" | |
29 | + When I uncheck "Enable shopping basket" | |
30 | + Then I should not see "Deliveries or pickups" | |
31 | + | |
32 | + @selenium | |
33 | + Scenario: create new deliver | |
34 | + Given I follow "Shopping basket" | |
35 | + And I check "Enable shopping basket" | |
36 | + And I follow "New delivery or pickup" | |
37 | + And I select "Deliver" from "Type" | |
38 | + And I fill in "Name" with "Bike" | |
39 | + And I fill in "Description" with "Beers delivered with my old bike." | |
40 | + And I fill in "Fixed cost" with "8.00" | |
41 | + And I fill in "Order's minimum price for free delivery" with "35.50" | |
42 | + When I press "Add" | |
43 | + Then I should see "Bike" within ".delivery-method" | |
44 | + | |
45 | + @selenium | |
46 | + Scenario: create new pickup | |
47 | + Given I follow "Shopping basket" | |
48 | + And I check "Enable shopping basket" | |
49 | + And I follow "New delivery or pickup" | |
50 | + And I select "Pickup" from "Type" | |
51 | + And I fill in "Name" with "Bar" | |
52 | + And I fill in "Description" with "Come to my bar and pick it yourself." | |
53 | + And I fill in "Fixed cost" with "0.00" | |
54 | + When I press "Add" | |
55 | + Then I should see "Bar" | |
56 | + | |
57 | + @selenium | |
58 | + Scenario: remove delivery | |
59 | + Given I follow "Shopping basket" | |
60 | + And I check "Enable shopping basket" | |
61 | + And I follow "New delivery or pickup" | |
62 | + And I fill in "Name" with "Bike" | |
63 | + When I press "Add" | |
64 | + Then I should see "Bike" | |
65 | + And I follow "Remove" within ".delivery-method" | |
66 | + When I confirm the browser dialog | |
67 | + Then I should see "Bike" | |
68 | + | |
69 | + @selenium | |
70 | + Scenario: edit delivery | |
71 | + Given I follow "Shopping basket" | |
72 | + And I check "Enable shopping basket" | |
73 | + And I follow "New delivery or pickup" | |
74 | + And I fill in "Name" with "Bike" | |
75 | + When I press "Add" | |
76 | + Then I should see "Bike" | |
77 | + And I follow "Edit" within ".delivery-method" | |
78 | + And I fill in "Name" with "Car" | |
79 | + When I press "Save" | |
80 | + Then I should not see "Bike" | |
81 | + Then I should see "Car" | ... | ... |
... | ... | @@ -0,0 +1,77 @@ |
1 | +Feature: delivery client | |
2 | + As an enterprise's client | |
3 | + I want to choose the delivery method | |
4 | + In order to receive my procucts properly | |
5 | + | |
6 | + Background: | |
7 | + Given "ShoppingCart" plugin is enabled | |
8 | + And "Delivery" plugin is enabled | |
9 | + And the following users | |
10 | + | login | name | email | | |
11 | + | moe | Moe | moe@springfield.com | | |
12 | + | homer | Homer | homer@springfield.com | | |
13 | + And the following enterprise | |
14 | + | identifier | name | owner | | |
15 | + | moes-tavern | Moes Tavern | moe | | |
16 | + And the shopping basket is enabled on "Moes Tavern" | |
17 | + And the following product_categories | |
18 | + | name | | |
19 | + | Beer | | |
20 | + | Snacks | | |
21 | + And the following products | |
22 | + | owner | category | name | price | | |
23 | + | moes-tavern | beer | Duff | 3.00 | | |
24 | + | moes-tavern | snacks | French fries | 7.00 | | |
25 | + And "moes-tavern" has the following delivery methods | |
26 | + | delivery_type | name | description | fixed_cost | free_over_price | | |
27 | + | deliver | Bike | My good old bike. | 8.00 | 10.00 | | |
28 | + | pickup | Bar | Come to my bar and drink it! | 0.00 | 0.00 | | |
29 | + And feature "products_for_enterprises" is enabled on environment | |
30 | + And I am logged in as "homer" | |
31 | + And I go to moes-tavern's products page | |
32 | + | |
33 | + @selenium | |
34 | + Scenario: choose deliver method for purchase | |
35 | + Given I follow "Add to basket" | |
36 | + And I follow "Add to basket" | |
37 | + And I should see "Show basket" | |
38 | + And I follow "Show basket" | |
39 | + And I follow "Shopping checkout" | |
40 | + And I fill in "Contact phone" with "123456789" | |
41 | + When I select "Bike ($8.00)" from "Option" | |
42 | + Then I should see "My good old bike." within ".instructions" | |
43 | + And I should see "Address" | |
44 | + And I should see "Bike" within "#delivery-name" | |
45 | + And I should see "8.00" within "#delivery-price" | |
46 | + | |
47 | + @selenium | |
48 | + Scenario: choose pickup method for purchase | |
49 | + Given I follow "Add to basket" | |
50 | + And I follow "Add to basket" | |
51 | + And I should see "Show basket" | |
52 | + And I follow "Show basket" | |
53 | + And I follow "Shopping checkout" | |
54 | + And I fill in "Contact phone" with "123456789" | |
55 | + When I select "Bar" from "Option" | |
56 | + Then I should see "Come to my bar and drink it!" within ".instructions" | |
57 | + And I should not see "Address" | |
58 | + And I should see "Bar" within "#delivery-name" | |
59 | + And I should see "0.00" within "#delivery-price" | |
60 | + | |
61 | + @selenium | |
62 | + Scenario: gets free delivery due to free over price | |
63 | + Given I follow "Add to basket" | |
64 | + And I follow "Add to basket" | |
65 | + And I follow "Add to basket" | |
66 | + And I follow "Add to basket" | |
67 | + And I follow "Add to basket" | |
68 | + And I follow "Add to basket" | |
69 | + And I should see "Show basket" | |
70 | + And I follow "Show basket" | |
71 | + And I follow "Shopping checkout" | |
72 | + And I fill in "Contact phone" with "123456789" | |
73 | + When I select "Bike ($8.00)" from "Option" | |
74 | + Then I should see "My good old bike." within ".instructions" | |
75 | + And I should see "Address" | |
76 | + And I should see "Bike" within "#delivery-name" | |
77 | + And I should see "0.00" within "#delivery-price" | ... | ... |
plugins/shopping_cart/features/step_definitions/orders_steps.rb
1 | -Given /^"([^""]*)" has the following delivery methods$/ do |name, table| | |
2 | - enterprise = Enterprise.find_by_name(name) || Enterprise[name] | |
3 | - table.hashes.map{|item| item.dup}.each do |item| | |
4 | - delivery_method = enterprise.delivery_methods.build | |
5 | - delivery_method.update_attributes(item) | |
6 | - end | |
7 | -end | |
8 | - | |
9 | 1 | Given /^the following purchase from "([^""]*)" on "([^""]*)" that is "([^""]*)"$/ do |consumer_identifier, enterprise_identifier, status, table| |
10 | 2 | consumer = Person.find_by_name(consumer_identifier) || Person[consumer_identifier] |
11 | 3 | enterprise = Enterprise.find_by_name(enterprise_identifier) || Enterprise[enterprise_identifier] | ... | ... |
plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb
... | ... | @@ -59,7 +59,7 @@ module ShoppingCartPlugin::CartHelper |
59 | 59 | @order |
60 | 60 | end |
61 | 61 | |
62 | - def items_table(items, profile, delivery_method = nil, by_mail = false) | |
62 | + def items_table(items, delivery_method = nil, by_mail = false) | |
63 | 63 | # partial key needed in mailer context |
64 | 64 | render partial: 'shopping_cart_plugin/items', locals: {order: build_order(items, delivery_method), by_mail: by_mail} |
65 | 65 | end | ... | ... |
plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb
1 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
2 | -require File.dirname(__FILE__) + '/../../controllers/shopping_cart_plugin_controller' | |
1 | +require 'test_helper' | |
2 | +require_relative '../../controllers/shopping_cart_plugin_controller' | |
3 | 3 | |
4 | 4 | # Re-raise errors caught by the controller. |
5 | 5 | class ShoppingCartPluginController; def rescue_action(e) raise e end; end |
... | ... | @@ -12,7 +12,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
12 | 12 | @response = ActionController::TestResponse.new |
13 | 13 | @profile = fast_create(Enterprise) |
14 | 14 | @profile.contact_email = 'enterprise@noosfero.org';@profile.save |
15 | - @product = fast_create(Product, :profile_id => @profile.id) | |
15 | + @product = fast_create(Product, profile_id: @profile.id) | |
16 | 16 | end |
17 | 17 | attr_reader :profile |
18 | 18 | attr_reader :product |
... | ... | @@ -23,22 +23,22 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
23 | 23 | end |
24 | 24 | |
25 | 25 | should 'add a new product to cart' do |
26 | - get :add, :id => product.id | |
26 | + get :add, id: product.id | |
27 | 27 | |
28 | 28 | assert product_in_cart?(product) |
29 | 29 | assert_equal 1, product_quantity(product) |
30 | 30 | end |
31 | 31 | |
32 | 32 | should 'grow quantity through add' do |
33 | - get :add, :id => product.id | |
33 | + get :add, id: product.id | |
34 | 34 | assert_equal 1, product_quantity(product) |
35 | 35 | |
36 | - get :add, :id => product.id | |
36 | + get :add, id: product.id | |
37 | 37 | assert_equal 2, product_quantity(product) |
38 | 38 | end |
39 | 39 | |
40 | 40 | should 'not add product to cart if it does not exists' do |
41 | - assert_nothing_raised { get :add, :id => 9999 } | |
41 | + assert_nothing_raised { get :add, id: 9999 } | |
42 | 42 | |
43 | 43 | refute product_in_cart?(product) |
44 | 44 | refute response_ok? |
... | ... | @@ -46,10 +46,10 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
46 | 46 | end |
47 | 47 | |
48 | 48 | should 'remove cart if the product being removed is the last one' do |
49 | - get :add, :id => product.id | |
49 | + get :add, id: product.id | |
50 | 50 | assert cart? |
51 | 51 | |
52 | - get :remove, :id => product.id | |
52 | + get :remove, id: product.id | |
53 | 53 | refute cart? |
54 | 54 | end |
55 | 55 | |
... | ... | @@ -57,25 +57,25 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
57 | 57 | instantiate_cart |
58 | 58 | refute cart? |
59 | 59 | |
60 | - assert_nothing_raised { get :remove, :id => 9999 } | |
60 | + assert_nothing_raised { get :remove, id: 9999 } | |
61 | 61 | refute response_ok? |
62 | 62 | assert_equal 2, reponse_error_code |
63 | 63 | end |
64 | 64 | |
65 | 65 | should 'just remove product if there are other products on cart' do |
66 | - another_product = fast_create(Product, :profile_id => profile.id) | |
67 | - get :add, :id => product.id | |
68 | - get :add, :id => another_product.id | |
66 | + another_product = fast_create(Product, profile_id: profile.id) | |
67 | + get :add, id: product.id | |
68 | + get :add, id: another_product.id | |
69 | 69 | |
70 | - get :remove, :id => product.id | |
70 | + get :remove, id: product.id | |
71 | 71 | assert cart? |
72 | 72 | refute product_in_cart?(product) |
73 | 73 | end |
74 | 74 | |
75 | 75 | should 'not try to remove a product that is not in the cart' do |
76 | - get :add, :id => product.id | |
76 | + get :add, id: product.id | |
77 | 77 | assert cart? |
78 | - assert_nothing_raised { get :remove, :id => 9999 } | |
78 | + assert_nothing_raised { get :remove, id: 9999 } | |
79 | 79 | |
80 | 80 | refute response_ok? |
81 | 81 | assert_equal 4, reponse_error_code |
... | ... | @@ -91,17 +91,17 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
91 | 91 | end |
92 | 92 | |
93 | 93 | should 'list products without errors' do |
94 | - get :add, :id => product.id | |
94 | + get :add, id: product.id | |
95 | 95 | |
96 | 96 | assert_nothing_raised { get :list } |
97 | 97 | assert response_ok? |
98 | 98 | end |
99 | 99 | |
100 | 100 | should 'update the quantity of a product' do |
101 | - get :add, :id => product.id | |
101 | + get :add, id: product.id | |
102 | 102 | assert_equal 1, product_quantity(product) |
103 | 103 | |
104 | - get :update_quantity, :id => product.id, :quantity => 3 | |
104 | + get :update_quantity, id: product.id, quantity: 3 | |
105 | 105 | assert_equal 3, product_quantity(product) |
106 | 106 | end |
107 | 107 | |
... | ... | @@ -109,36 +109,36 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
109 | 109 | instantiate_cart |
110 | 110 | refute cart? |
111 | 111 | |
112 | - assert_nothing_raised { get :update_quantity, :id => 9999, :quantity => 3 } | |
112 | + assert_nothing_raised { get :update_quantity, id: 9999, quantity: 3 } | |
113 | 113 | refute response_ok? |
114 | 114 | assert_equal 2, reponse_error_code |
115 | 115 | end |
116 | 116 | |
117 | 117 | should 'not try to update the quantity of a product that is not in the cart' do |
118 | - get :add, :id => product.id | |
118 | + get :add, id: product.id | |
119 | 119 | assert cart? |
120 | - assert_nothing_raised { get :update_quantity, :id => 9999, :quantity => 3 } | |
120 | + assert_nothing_raised { get :update_quantity, id: 9999, quantity: 3 } | |
121 | 121 | |
122 | 122 | refute response_ok? |
123 | 123 | assert_equal 4, reponse_error_code |
124 | 124 | end |
125 | 125 | |
126 | 126 | should 'not update the quantity of a product with a invalid value' do |
127 | - get :add, :id => product.id | |
127 | + get :add, id: product.id | |
128 | 128 | |
129 | - assert_nothing_raised { get :update_quantity, :id => product.id, :quantity => -1} | |
129 | + assert_nothing_raised { get :update_quantity, id: product.id, quantity: -1} | |
130 | 130 | refute response_ok? |
131 | 131 | assert_equal 5, reponse_error_code |
132 | 132 | |
133 | - assert_nothing_raised { get :update_quantity, :id => product.id, :quantity => 'asdf'} | |
133 | + assert_nothing_raised { get :update_quantity, id: product.id, quantity: 'asdf'} | |
134 | 134 | refute response_ok? |
135 | 135 | assert_equal 5, reponse_error_code |
136 | 136 | end |
137 | 137 | |
138 | 138 | should 'clean the cart' do |
139 | - another_product = fast_create(Product, :profile_id => profile.id) | |
140 | - get :add, :id => product.id | |
141 | - get :add, :id => another_product.id | |
139 | + another_product = fast_create(Product, profile_id: profile.id) | |
140 | + get :add, id: product.id | |
141 | + get :add, id: another_product.id | |
142 | 142 | |
143 | 143 | assert_nothing_raised { get :clean } |
144 | 144 | refute cart? |
... | ... | @@ -151,12 +151,11 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
151 | 151 | end |
152 | 152 | |
153 | 153 | should 'register order on send request' do |
154 | - product1 = fast_create(Product, :profile_id => profile.id, :price => 1.99) | |
155 | - product2 = fast_create(Product, :profile_id => profile.id, :price => 2.23) | |
156 | - @controller.stubs(:cart).returns({ :profile_id => profile.id, :items => {product1.id => 1, product2.id => 2}}) | |
154 | + product1 = fast_create(Product, profile_id: profile.id, price: 1.99) | |
155 | + product2 = fast_create(Product, profile_id: profile.id, price: 2.23) | |
156 | + @controller.stubs(:cart).returns({ profile_id: profile.id, items: {product1.id => 1, product2.id => 2}}) | |
157 | 157 | assert_difference 'OrdersPlugin::Order.count', 1 do |
158 | - post :send_request, | |
159 | - :customer => {:name => "Manuel", :email => "manuel@ceu.com"} | |
158 | + xhr :post, :send_request, order: {consumer_data: {name: "Manuel", email: "manuel@ceu.com"}} | |
160 | 159 | end |
161 | 160 | |
162 | 161 | order = OrdersPlugin::Order.last |
... | ... | @@ -165,15 +164,14 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
165 | 164 | assert_equal 1, order.products_list[product1.id][:quantity] |
166 | 165 | assert_equal 2.23, order.products_list[product2.id][:price] |
167 | 166 | assert_equal 2, order.products_list[product2.id][:quantity] |
168 | - assert_equal 'confirmed', order.status | |
167 | + assert_equal 'ordered', order.status | |
169 | 168 | end |
170 | 169 | |
171 | 170 | should 'register order on send request and not crash if product is not defined' do |
172 | - product1 = fast_create(Product, :profile_id => profile.id) | |
173 | - @controller.stubs(:cart).returns({ :profile_id => profile.id, :items => {product1.id => 1}}) | |
171 | + product1 = fast_create(Product, profile_id: profile.id) | |
172 | + @controller.stubs(:cart).returns({ profile_id: profile.id, items: {product1.id => 1}}) | |
174 | 173 | assert_difference 'OrdersPlugin::Order.count', 1 do |
175 | - post :send_request, | |
176 | - :customer => {:name => "Manuel", :email => "manuel@ceu.com"} | |
174 | + xhr :post, :send_request, order: {consumer_data: {name: "Manuel", email: "manuel@ceu.com"}} | |
177 | 175 | end |
178 | 176 | |
179 | 177 | order = OrdersPlugin::Order.last |
... | ... | @@ -182,16 +180,15 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
182 | 180 | end |
183 | 181 | |
184 | 182 | should 'clean the cart after placing the order' do |
185 | - product1 = fast_create(Product, :profile_id => profile.id) | |
186 | - post :add, :id => product1.id | |
187 | - post :send_request, :customer => { :name => "Manuel", :email => "manuel@ceu.com" } | |
183 | + product1 = fast_create(Product, profile_id: profile.id) | |
184 | + post :add, id: product1.id | |
185 | + xhr :post, :send_request, order: {consumer_data: {name: "Manuel", email: "manuel@ceu.com"}} | |
188 | 186 | refute cart?, "cart expected to be empty!" |
189 | 187 | end |
190 | 188 | |
191 | 189 | should 'not allow buy without any cart' do |
192 | 190 | get :buy |
193 | - refute json_response[:ok] | |
194 | - assert_equal 2, json_response['error']['code'] | |
191 | + assert_response :redirect | |
195 | 192 | end |
196 | 193 | |
197 | 194 | private |
... | ... | @@ -225,8 +222,8 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase |
225 | 222 | # temporary hack...if I don't do this the session stays as an Array instead |
226 | 223 | # of a TestSession |
227 | 224 | def instantiate_cart |
228 | - get :add, :id => product.id | |
229 | - get :remove, :id => product.id | |
225 | + get :add, id: product.id | |
226 | + get :remove, id: product.id | |
230 | 227 | end |
231 | 228 | |
232 | 229 | end | ... | ... |
plugins/shopping_cart/test/functional/shopping_cart_plugin_myprofile_controller_test.rb
1 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
1 | +require 'test_helper' | |
2 | 2 | |
3 | 3 | class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase |
4 | 4 | |
5 | - TIME_FORMAT = '%Y-%m-%d' | |
6 | - | |
7 | 5 | def setup |
8 | 6 | @profile = fast_create(Enterprise) |
9 | 7 | @admin = create_user('admin').person |
... | ... | @@ -13,115 +11,23 @@ class ShoppingCartPluginMyprofileControllerTest < ActionController::TestCase |
13 | 11 | attr_reader :profile |
14 | 12 | |
15 | 13 | should 'be able to enable shopping cart' do |
16 | - settings.enabled = false | |
17 | - settings.save! | |
18 | - post :edit, :profile => profile.identifier, :settings => {:enabled => '1'} | |
19 | - | |
20 | - assert settings.enabled | |
21 | - end | |
22 | - | |
23 | - should 'be able to disable shopping cart' do | |
24 | - settings.enabled = true | |
25 | - settings.save! | |
26 | - post :edit, :profile => profile.identifier, :settings => {:enabled => '0'} | |
27 | - | |
28 | - refute settings.enabled | |
29 | - end | |
14 | + profile.shopping_cart_settings.enabled = false | |
15 | + profile.shopping_cart_settings.save! | |
30 | 16 | |
31 | - should 'be able to enable shopping cart delivery' do | |
32 | - settings.delivery = false | |
33 | - settings.save! | |
34 | - post :edit, :profile => profile.identifier, :settings => {:delivery => '1'} | |
17 | + post :edit, profile: profile.identifier, settings: {enabled: '1'} | |
18 | + profile.reload | |
35 | 19 | |
36 | - assert settings.delivery | |
20 | + assert profile.shopping_cart_settings.enabled | |
37 | 21 | end |
38 | 22 | |
39 | - should 'be able to disable shopping cart delivery' do | |
40 | - settings.delivery = true | |
41 | - settings.save! | |
42 | - post :edit, :profile => profile.identifier, :settings => {:delivery => '0'} | |
43 | - | |
44 | - refute settings.delivery | |
45 | - end | |
46 | - | |
47 | - should 'be able to choose the delivery price' do | |
48 | - price = 4.35 | |
49 | - post :edit, :profile => profile.identifier, :settings => {:delivery_price => price} | |
50 | - | |
51 | - assert settings.delivery_price == price.to_s | |
52 | - end | |
53 | - | |
54 | - # FIXME | |
55 | - should 'be able to choose delivery_options' do | |
56 | - delivery_options = {:options => ['car', 'bike'], :prices => ['20', '5']} | |
57 | - post :edit, :profile => profile.identifier, :settings => {:delivery_options => delivery_options} | |
58 | - | |
59 | - assert_equal '20', settings.delivery_options['car'] | |
60 | - assert_equal '5', settings.delivery_options['bike'] | |
61 | - end | |
62 | - | |
63 | - should 'filter the reports correctly' do | |
64 | - another_profile = fast_create(Enterprise) | |
65 | - po1 = OrdersPlugin::Sale.create! :profile => profile, :status => 'confirmed' | |
66 | - po2 = OrdersPlugin::Sale.create! :profile => profile, :status => 'shipped' | |
67 | - po3 = OrdersPlugin::Sale.create! :profile => profile, :status => 'confirmed' | |
68 | - po3.created_at = 1.year.ago | |
69 | - po3.save! | |
70 | - po4 = OrdersPlugin::Sale.create! :profile => another_profile, :status => 'confirmed' | |
71 | - | |
72 | - post :reports, | |
73 | - :profile => profile.identifier, | |
74 | - :from => (Time.now - 1.day).strftime(TIME_FORMAT), | |
75 | - :to => (Time.now + 1.day).strftime(TIME_FORMAT), | |
76 | - :filter_status => 'confirmed' | |
77 | - | |
78 | - assert_includes assigns(:orders), po1 | |
79 | - assert_not_includes assigns(:orders), po2 | |
80 | - assert_not_includes assigns(:orders), po3 | |
81 | - assert_not_includes assigns(:orders), po4 | |
82 | - end | |
83 | - | |
84 | - should 'group filtered orders products and quantities' do | |
85 | - p1 = fast_create(Product, :profile_id => profile.id, :price => 1, :name => 'p1') | |
86 | - p2 = fast_create(Product, :profile_id => profile.id, :price => 2, :name => 'p2') | |
87 | - p3 = fast_create(Product, :profile_id => profile.id, :price => 3) | |
88 | - po1_products = {p1.id => {:quantity => 1, :price => p1.price, :name => p1.name}, p2.id => {:quantity => 2, :price => p2.price, :name => p2.name }} | |
89 | - po2_products = {p2.id => {:quantity => 1, :price => p2.price, :name => p2.name }, p3.id => {:quantity => 2, :price => p3.price, :name => p3.name}} | |
90 | - po1 = OrdersPlugin::Sale.create! :profile => profile, :products_list => po1_products, :status => 'confirmed' | |
91 | - po2 = OrdersPlugin::Sale.create! :profile => profile, :products_list => po2_products, :status => 'confirmed' | |
92 | - | |
93 | - post :reports, | |
94 | - :profile => profile.identifier, | |
95 | - :from => (Time.now - 1.day).strftime(TIME_FORMAT), | |
96 | - :to => (Time.now + 1.day).strftime(TIME_FORMAT), | |
97 | - :filter_status => 'confirmed' | |
98 | - | |
99 | - lineitem1 = ShoppingCartPlugin::LineItem.new(p1.id, p1.name) | |
100 | - lineitem1.quantity = 1 | |
101 | - lineitem2 = ShoppingCartPlugin::LineItem.new(p2.id, p2.name) | |
102 | - lineitem2.quantity = 3 | |
103 | - lineitem3 = ShoppingCartPlugin::LineItem.new(p3.id, p3.name) | |
104 | - lineitem3.quantity = 2 | |
105 | - hash = {p1.id => lineitem1, p2.id => lineitem2, p3.id => lineitem3} | |
106 | - | |
107 | - assert_equal hash, assigns(:products) | |
108 | - end | |
23 | + should 'be able to disable shopping cart' do | |
24 | + profile.shopping_cart_settings.enabled = true | |
25 | + profile.shopping_cart_settings.save! | |
109 | 26 | |
110 | - should 'be able to update the order status' do | |
111 | - po = OrdersPlugin::Sale.create!(:profile => profile, :status => 'confirmed') | |
27 | + post :edit, profile: profile.identifier, settings: {enabled: '0'} | |
28 | + profile.reload | |
112 | 29 | |
113 | - post :update_order_status, | |
114 | - :profile => profile.identifier, | |
115 | - :order_id => po.id, | |
116 | - :order_status => 'confirmed' | |
117 | - po.reload | |
118 | - assert_equal 'confirmed', po.status | |
30 | + refute profile.shopping_cart_settings.enabled | |
119 | 31 | end |
120 | 32 | |
121 | - private | |
122 | - | |
123 | - def settings | |
124 | - @profile.reload | |
125 | - profile.shopping_cart_settings | |
126 | - end | |
127 | 33 | end | ... | ... |
plugins/shopping_cart/test/unit/shopping_cart_plugin/cart_helper_test.rb
1 | -require File.dirname(__FILE__) + '/../../../../../test/test_helper' | |
1 | +require 'test_helper' | |
2 | 2 | |
3 | 3 | class ShoppingCartPlugin::CartHelperTest < ActiveSupport::TestCase |
4 | 4 | |
... | ... | @@ -41,19 +41,4 @@ class ShoppingCartPlugin::CartHelperTest < ActiveSupport::TestCase |
41 | 41 | assert_equal "#{environment.currency_unit}13#{environment.currency_separator}70", float_to_currency_cart(value,environment) |
42 | 42 | end |
43 | 43 | |
44 | - should 'return a table of items' do | |
45 | - enterprise = Enterprise.new(name: "Test Enterprise", identifier: "test-enterprise") | |
46 | - enterprise.environment = Environment.default | |
47 | - enterprise.save! | |
48 | - | |
49 | - product_category = fast_create(ProductCategory, :name => 'Products') | |
50 | - product = fast_create(Product, :name => 'test product1', :product_category_id => product_category.id, :profile_id => enterprise.id) | |
51 | - setting = Noosfero::Plugin::Settings.new(enterprise, ShoppingCartPlugin) | |
52 | - setting.delivery = true | |
53 | - setting.save! | |
54 | - | |
55 | - assert_match 'table id="cart-items-table"', items_table([product], enterprise) | |
56 | - assert_match '<td>test product1</td>', items_table([product], enterprise) | |
57 | - end | |
58 | - | |
59 | 44 | end | ... | ... |
plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb
... | ... | @@ -39,7 +39,7 @@ |
39 | 39 | <fieldset> |
40 | 40 | <legend><%=s_('Your Order')%></legend> |
41 | 41 | <% supplier_delivery = @order.supplier_delivery || profile.delivery_methods.first %> |
42 | - <%= items_table @cart[:items], @profile, supplier_delivery %> | |
42 | + <%= items_table @cart[:items], supplier_delivery %> | |
43 | 43 | </fieldset> |
44 | 44 | </div> |
45 | 45 | ... | ... |
plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb
... | ... | @@ -18,9 +18,11 @@ |
18 | 18 | <li><b><%= c_('Email') %>: </b><%= @order.consumer_data[:email] %></li> |
19 | 19 | <li><b><%= _('Phone number') %>: </b><%= @order.consumer_data[:contact_phone] %></li> |
20 | 20 | |
21 | - <li><b><%= _("Payment's method") %>: </b><%= _ OrdersPlugin::Order::PaymentMethods[@order.payment_data[:method].to_sym].call %></li> | |
22 | - <% if @order.payment_data[:method] == 'money' %> | |
23 | - <li><b><%= s_('shopping_cart|Change') %>: </b><%= @order.payment_data[:change] %></li> | |
21 | + <% if @order.payment_data[:method] %> | |
22 | + <li><b><%= _("Payment's method") %>: </b><%= _ OrdersPlugin::Order::PaymentMethods[@order.payment_data[:method].to_sym].call %></li> | |
23 | + <% if @order.payment_data[:method] == 'money' %> | |
24 | + <li><b><%= s_('shopping_cart|Change') %>: </b><%= @order.payment_data[:change] %></li> | |
25 | + <% end %> | |
24 | 26 | <% end %> |
25 | 27 | |
26 | 28 | <li><b><%= _('Delivery or pickup') %>:</b></li> |
... | ... | @@ -59,7 +61,7 @@ |
59 | 61 | </ul> |
60 | 62 | |
61 | 63 | <p><%=_('Here are the products you bought:')%></p> |
62 | - <%= items_table(@items, @order.profile, @order.supplier_delivery, true) %> | |
64 | + <%= items_table(@items, @order.supplier_delivery, true) %> | |
63 | 65 | <p> |
64 | 66 | --<br/> |
65 | 67 | <%=_('Thanks for buying with us!')%><br/> | ... | ... |
plugins/shopping_cart/views/shopping_cart_plugin/mailer/supplier_notification.html.erb
... | ... | @@ -16,9 +16,11 @@ |
16 | 16 | <li><b><%= c_('Email') %>: </b><%= @order.consumer_data[:email] %></li> |
17 | 17 | <li><b><%= _('Phone number') %>: </b><%= @order.consumer_data[:contact_phone] %></li> |
18 | 18 | |
19 | - <li><b><%= _('Payment') %>: </b><%= OrdersPlugin::Order::PaymentMethods[@order.payment_data[:method].to_sym].call %></li> | |
20 | - <% if @order.payment_data[:method] == 'money' %> | |
21 | - <li><b><%= s_('shopping_cart|Change') %>: </b><%= @order.payment_data[:change] %></li> | |
19 | + <% if @order.payment_data[:method] %> | |
20 | + <li><b><%= _('Payment') %>: </b><%= OrdersPlugin::Order::PaymentMethods[@order.payment_data[:method].to_sym].call %></li> | |
21 | + <% if @order.payment_data[:method] == 'money' %> | |
22 | + <li><b><%= s_('shopping_cart|Change') %>: </b><%= @order.payment_data[:change] %></li> | |
23 | + <% end %> | |
22 | 24 | <% end %> |
23 | 25 | |
24 | 26 | <% if !@order.consumer_delivery_data[:address].blank? || !@order.consumer_delivery_data[:city].blank? || !@order.consumer_delivery_data[:zip_code].blank? || !@order.consumer_delivery_data[:district].blank? || !@order.consumer_delivery_data[:address_reference].blank? %> |
... | ... | @@ -51,7 +53,7 @@ |
51 | 53 | </ul> |
52 | 54 | |
53 | 55 | <p><%=_('And here are the items bought by this customer:')%></p> |
54 | - <%= items_table(@items, @order.profile, @order.supplier_delivery, true) %> | |
56 | + <%= items_table(@items, @order.supplier_delivery, true) %> | |
55 | 57 | <p> |
56 | 58 | --<br/> |
57 | 59 | <%=_('If there are any problems with this email contact the admin of %s.') % @environment.name %> | ... | ... |
test/fixtures/environments.yml
... | ... | @@ -3,6 +3,7 @@ colivre_net: |
3 | 3 | id: 1 |
4 | 4 | name: 'Colivre.net' |
5 | 5 | contact_email: 'colivre@localhost.localdomain' |
6 | + noreply_email: 'noreply@localhost.localdomain' | |
6 | 7 | is_default: true |
7 | 8 | theme: 'noosfero' |
8 | 9 | anhetegua_net: |
... | ... | @@ -10,3 +11,4 @@ anhetegua_net: |
10 | 11 | name: 'Anheteguá' |
11 | 12 | is_default: false |
12 | 13 | contact_email: 'anhetegua@localhost.localdomain' |
14 | + noreply_email: 'noreply@localhost.localdomain' | ... | ... |