solidus_frontend 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of solidus_frontend might be problematic. Click here for more details.

Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -0
  3. data/Gemfile +6 -0
  4. data/Rakefile +15 -0
  5. data/script/rails +9 -0
  6. data/solidus_frontend.gemspec +28 -0
  7. data/spec/controllers/controller_extension_spec.rb +126 -0
  8. data/spec/controllers/controller_helpers_spec.rb +26 -0
  9. data/spec/controllers/spree/checkout_controller_spec.rb +401 -0
  10. data/spec/controllers/spree/checkout_controller_with_views_spec.rb +36 -0
  11. data/spec/controllers/spree/content_controller_spec.rb +7 -0
  12. data/spec/controllers/spree/current_order_tracking_spec.rb +44 -0
  13. data/spec/controllers/spree/home_controller_spec.rb +27 -0
  14. data/spec/controllers/spree/orders_controller_ability_spec.rb +104 -0
  15. data/spec/controllers/spree/orders_controller_spec.rb +134 -0
  16. data/spec/controllers/spree/orders_controller_transitions_spec.rb +31 -0
  17. data/spec/controllers/spree/products_controller_spec.rb +36 -0
  18. data/spec/controllers/spree/taxons_controller_spec.rb +12 -0
  19. data/spec/features/address_spec.rb +76 -0
  20. data/spec/features/automatic_promotion_adjustments_spec.rb +47 -0
  21. data/spec/features/caching/products_spec.rb +55 -0
  22. data/spec/features/caching/taxons_spec.rb +22 -0
  23. data/spec/features/cart_spec.rb +81 -0
  24. data/spec/features/checkout_spec.rb +477 -0
  25. data/spec/features/checkout_unshippable_spec.rb +35 -0
  26. data/spec/features/coupon_code_spec.rb +227 -0
  27. data/spec/features/currency_spec.rb +18 -0
  28. data/spec/features/free_shipping_promotions_spec.rb +59 -0
  29. data/spec/features/locale_spec.rb +60 -0
  30. data/spec/features/order_spec.rb +73 -0
  31. data/spec/features/products_spec.rb +260 -0
  32. data/spec/features/promotion_code_invalidation_spec.rb +51 -0
  33. data/spec/features/quantity_promotions_spec.rb +128 -0
  34. data/spec/features/taxons_spec.rb +135 -0
  35. data/spec/features/template_rendering_spec.rb +19 -0
  36. data/spec/fixtures/thinking-cat.jpg +0 -0
  37. data/spec/helpers/base_helper_spec.rb +11 -0
  38. data/spec/spec_helper.rb +121 -0
  39. data/spec/support/shared_contexts/checkout_setup.rb +9 -0
  40. data/spec/support/shared_contexts/custom_products.rb +25 -0
  41. data/spec/support/shared_contexts/product_prototypes.rb +30 -0
  42. data/spec/views/spree/checkout/_summary_spec.rb +11 -0
  43. metadata +47 -6
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe "checkout with unshippable items", type: :feature, inaccessible: true do
4
+ let!(:stock_location) { create(:stock_location) }
5
+ let(:order) { OrderWalkthrough.up_to(:address) }
6
+
7
+ before do
8
+ OrderWalkthrough.add_line_item!(order)
9
+ line_item = order.line_items.last
10
+ stock_item = stock_location.stock_item(line_item.variant)
11
+ stock_item.adjust_count_on_hand -999
12
+ stock_item.backorderable = false
13
+ stock_item.save!
14
+
15
+ user = create(:user)
16
+ order.user = user
17
+ order.update!
18
+
19
+ allow_any_instance_of(Spree::CheckoutController).to receive_messages(:current_order => order)
20
+ allow_any_instance_of(Spree::CheckoutController).to receive_messages(:try_spree_current_user => user)
21
+ allow_any_instance_of(Spree::CheckoutController).to receive_messages(:skip_state_validation? => true)
22
+ allow_any_instance_of(Spree::CheckoutController).to receive_messages(:ensure_sufficient_stock_lines => true)
23
+ end
24
+
25
+ it 'displays and removes' do
26
+ visit spree.checkout_state_path(:delivery)
27
+ expect(page).to have_content('Unshippable Items')
28
+
29
+ click_button "Save and Continue"
30
+
31
+ order.reload
32
+ expect(order.line_items.count).to eq 1
33
+ end
34
+ end
35
+
@@ -0,0 +1,227 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Coupon code promotions", type: :feature, js: true do
4
+ let!(:country) { create(:country, :name => "United States of America", :states_required => true) }
5
+ let!(:state) { create(:state, :name => "Alabama", :country => country) }
6
+ let!(:zone) { create(:zone) }
7
+ let!(:shipping_method) { create(:shipping_method) }
8
+ let!(:payment_method) { create(:check_payment_method) }
9
+ let!(:product) { create(:product, :name => "RoR Mug", :price => 20) }
10
+
11
+ context "visitor makes checkout as guest without registration" do
12
+ def create_basic_coupon_promotion(code)
13
+ promotion = create(
14
+ :promotion,
15
+ name: code.titleize,
16
+ code: code,
17
+ starts_at: 1.day.ago,
18
+ expires_at: 1.day.from_now,
19
+ )
20
+
21
+ calculator = Spree::Calculator::FlatRate.new
22
+ calculator.preferred_amount = 10
23
+
24
+ action = Spree::Promotion::Actions::CreateItemAdjustments.new
25
+ action.calculator = calculator
26
+ action.promotion = promotion
27
+ action.save
28
+
29
+ promotion.reload # so that promotion.actions is available
30
+ end
31
+
32
+ let!(:promotion) { create_basic_coupon_promotion("onetwo") }
33
+
34
+ # OrdersController
35
+ context "on the payment page" do
36
+ before do
37
+
38
+ visit spree.root_path
39
+ click_link "RoR Mug"
40
+ click_button "add-to-cart-button"
41
+ click_button "Checkout"
42
+ fill_in "order_email", :with => "spree@example.com"
43
+ fill_in "First Name", :with => "John"
44
+ fill_in "Last Name", :with => "Smith"
45
+ fill_in "Street Address", :with => "1 John Street"
46
+ fill_in "City", :with => "City of John"
47
+ fill_in "Zip", :with => "01337"
48
+ select country.name, :from => "Country"
49
+ select state.name, :from => "order[bill_address_attributes][state_id]"
50
+ fill_in "Phone", :with => "555-555-5555"
51
+
52
+ # To shipping method screen
53
+ click_button "Save and Continue"
54
+ # To payment screen
55
+ click_button "Save and Continue"
56
+ end
57
+
58
+ it "informs about an invalid coupon code" do
59
+ fill_in "order_coupon_code", :with => "coupon_codes_rule_man"
60
+ click_button "Save and Continue"
61
+ expect(page).to have_content(Spree.t(:coupon_code_not_found))
62
+ end
63
+
64
+ it "can enter an invalid coupon code, then a real one" do
65
+ fill_in "order_coupon_code", :with => "coupon_codes_rule_man"
66
+ click_button "Save and Continue"
67
+ expect(page).to have_content(Spree.t(:coupon_code_not_found))
68
+ fill_in "order_coupon_code", :with => "onetwo"
69
+ click_button "Save and Continue"
70
+ expect(page).to have_content("Promotion (Onetwo) -$10.00")
71
+ end
72
+
73
+ context "with a promotion" do
74
+ it "applies a promotion to an order" do
75
+ fill_in "order_coupon_code", :with => "onetwo"
76
+ click_button "Save and Continue"
77
+ expect(page).to have_content("Promotion (Onetwo) -$10.00")
78
+ end
79
+ end
80
+ end
81
+
82
+ # CheckoutController
83
+ context "on the cart page" do
84
+
85
+ before do
86
+ visit spree.root_path
87
+ click_link "RoR Mug"
88
+ click_button "add-to-cart-button"
89
+ end
90
+
91
+ it "can enter a coupon code and receives success notification" do
92
+ fill_in "order_coupon_code", :with => "onetwo"
93
+ click_button "Update"
94
+ expect(page).to have_content(Spree.t(:coupon_code_applied))
95
+ end
96
+
97
+ it "can enter a promotion code with both upper and lower case letters" do
98
+ fill_in "order_coupon_code", :with => "ONETwO"
99
+ click_button "Update"
100
+ expect(page).to have_content(Spree.t(:coupon_code_applied))
101
+ end
102
+
103
+ it "informs the user about a coupon code which has exceeded its usage" do
104
+ expect_any_instance_of(Spree::Promotion).to receive(:usage_limit_exceeded?).and_return(true)
105
+
106
+ fill_in "order_coupon_code", :with => "onetwo"
107
+ click_button "Update"
108
+ expect(page).to have_content(Spree.t(:coupon_code_max_usage))
109
+ end
110
+
111
+ context "informs the user if the coupon code is not eligible" do
112
+ before do
113
+ rule = Spree::Promotion::Rules::ItemTotal.new
114
+ rule.promotion = promotion
115
+ rule.preferred_amount = 100
116
+ rule.save
117
+ end
118
+
119
+ specify do
120
+ visit spree.cart_path
121
+
122
+ fill_in "order_coupon_code", :with => "onetwo"
123
+ click_button "Update"
124
+ expect(page).to have_content(Spree.t(:item_total_less_than_or_equal, scope: [:eligibility_errors, :messages], amount: "$100.00"))
125
+ end
126
+ end
127
+
128
+ it "informs the user if the coupon is expired" do
129
+ promotion.expires_at = Date.today.beginning_of_week
130
+ promotion.starts_at = Date.today.beginning_of_week.advance(:day => 3)
131
+ promotion.save!
132
+ fill_in "order_coupon_code", :with => "onetwo"
133
+ click_button "Update"
134
+ expect(page).to have_content(Spree.t(:coupon_code_expired))
135
+ end
136
+
137
+ context "calculates the correct amount of money saved with flat percent promotions" do
138
+ before do
139
+ calculator = Spree::Calculator::FlatPercentItemTotal.new
140
+ calculator.preferred_flat_percent = 20
141
+ promotion.actions.first.calculator = calculator
142
+ promotion.save
143
+
144
+ create(:product, :name => "Spree Mug", :price => 10)
145
+ end
146
+
147
+ specify do
148
+ visit spree.root_path
149
+ click_link "Spree Mug"
150
+ click_button "add-to-cart-button"
151
+
152
+ visit spree.cart_path
153
+ fill_in "order_coupon_code", :with => "onetwo"
154
+ click_button "Update"
155
+
156
+ fill_in "order_line_items_attributes_0_quantity", :with => 2
157
+ fill_in "order_line_items_attributes_1_quantity", :with => 2
158
+ click_button "Update"
159
+
160
+
161
+ within '#cart_adjustments' do
162
+ # 20% of $40 = 8
163
+ # 20% of $20 = 4
164
+ # Therefore: promotion discount amount is $12.
165
+ expect(page).to have_content("Promotion (Onetwo) -$12.00")
166
+ end
167
+
168
+ within '.cart-total' do
169
+ expect(page).to have_content("$48.00")
170
+ end
171
+ end
172
+ end
173
+
174
+ context "calculates the correct amount of money saved with flat 100% promotions on the whole order" do
175
+ before do
176
+ calculator = Spree::Calculator::FlatPercentItemTotal.new
177
+ calculator.preferred_flat_percent = 100
178
+
179
+ action = Spree::Promotion::Actions::CreateAdjustment.new
180
+ action.calculator = calculator
181
+ action.promotion = promotion
182
+ action.save
183
+
184
+ promotion.promotion_actions = [action]
185
+ promotion.save
186
+
187
+ create(:product, name: "Spree Mug", price: 10)
188
+ end
189
+
190
+ specify do
191
+ visit spree.root_path
192
+ click_link "Spree Mug"
193
+ click_button "add-to-cart-button"
194
+
195
+ visit spree.cart_path
196
+
197
+ within '.cart-total' do
198
+ expect(page).to have_content("$30.00")
199
+ end
200
+
201
+ fill_in "order_coupon_code", with: "onetwo"
202
+ click_button "Update"
203
+
204
+ within '#cart_adjustments' do
205
+ expect(page).to have_content("Promotion (Onetwo) -$30.00")
206
+ end
207
+
208
+ within '.cart-total' do
209
+ expect(page).to have_content("$0.00")
210
+ end
211
+
212
+ fill_in "order_line_items_attributes_0_quantity", with: 2
213
+ fill_in "order_line_items_attributes_1_quantity", with: 2
214
+ click_button "Update"
215
+
216
+ within '#cart_adjustments' do
217
+ expect(page).to have_content("Promotion (Onetwo) -$60.00")
218
+ end
219
+
220
+ within '.cart-total' do
221
+ expect(page).to have_content("$0.00")
222
+ end
223
+ end
224
+ end
225
+ end
226
+ end
227
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Switching currencies in backend", :type => :feature do
4
+ before do
5
+ create(:base_product, :name => "RoR Mug")
6
+ end
7
+
8
+ # Regression test for #2340
9
+ it "does not cause current_order to become nil", inaccessible: true do
10
+ visit spree.root_path
11
+ click_link "RoR Mug"
12
+ click_button "Add To Cart"
13
+ # Now that we have an order...
14
+ Spree::Config[:currency] = "AUD"
15
+ expect { visit spree.root_path }.not_to raise_error
16
+ end
17
+
18
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Free shipping promotions", :type => :feature, :js => true do
4
+ let!(:country) { create(:country, :name => "United States of America", :states_required => true) }
5
+ let!(:state) { create(:state, :name => "Alabama", :country => country) }
6
+ let!(:zone) { create(:zone) }
7
+ let!(:shipping_method) do
8
+ sm = create(:shipping_method)
9
+ sm.calculator.preferred_amount = 10
10
+ sm.calculator.save
11
+ sm
12
+ end
13
+
14
+ let!(:payment_method) { create(:check_payment_method) }
15
+ let!(:product) { create(:product, :name => "RoR Mug", :price => 20) }
16
+ let!(:promotion) do
17
+ promotion = Spree::Promotion.create!(:name => "Free Shipping",
18
+ :starts_at => 1.day.ago,
19
+ :expires_at => 1.day.from_now)
20
+
21
+ action = Spree::Promotion::Actions::FreeShipping.new
22
+ action.promotion = promotion
23
+ action.save
24
+
25
+ promotion.reload # so that promotion.actions is available
26
+ end
27
+
28
+ context "free shipping promotion automatically applied" do
29
+ before do
30
+
31
+ visit spree.root_path
32
+ click_link "RoR Mug"
33
+ click_button "add-to-cart-button"
34
+ click_button "Checkout"
35
+ fill_in "order_email", :with => "spree@example.com"
36
+ fill_in "First Name", :with => "John"
37
+ fill_in "Last Name", :with => "Smith"
38
+ fill_in "Street Address", :with => "1 John Street"
39
+ fill_in "City", :with => "City of John"
40
+ fill_in "Zip", :with => "01337"
41
+ select country.name, :from => "Country"
42
+ select state.name, :from => "order[bill_address_attributes][state_id]"
43
+ fill_in "Phone", :with => "555-555-5555"
44
+
45
+ # To shipping method screen
46
+ click_button "Save and Continue"
47
+ # To payment screen
48
+ click_button "Save and Continue"
49
+ end
50
+
51
+ # Regression test for #4428
52
+ it "applies the free shipping promotion" do
53
+ within("#checkout-summary") do
54
+ expect(page).to have_content("Shipping total: $10.00")
55
+ expect(page).to have_content("Promotion (Free Shipping): -$10.00")
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'setting locale', :type => :feature do
4
+ def with_locale(locale)
5
+ I18n.locale = locale
6
+ Spree::Frontend::Config[:locale] = locale
7
+ yield
8
+ I18n.locale = I18n.default_locale
9
+ Spree::Frontend::Config[:locale] = 'en'
10
+ end
11
+
12
+ context 'shopping cart link and page' do
13
+ before do
14
+ I18n.backend.store_translations(:fr,
15
+ :spree => {
16
+ :cart => 'Panier',
17
+ :shopping_cart => 'Panier'
18
+ })
19
+ end
20
+
21
+ it 'should be in french' do
22
+ with_locale('fr') do
23
+ visit spree.root_path
24
+ click_link 'Panier'
25
+ expect(page).to have_content('Panier')
26
+ end
27
+ end
28
+ end
29
+
30
+ context 'checkout form validation messages' do
31
+ include_context 'checkout setup'
32
+
33
+ let(:error_messages) do
34
+ {
35
+ 'en' => 'This field is required.',
36
+ 'fr' => 'Ce champ est obligatoire.',
37
+ 'de' => 'Dieses Feld ist ein Pflichtfeld.',
38
+ }
39
+ end
40
+
41
+ def check_error_text(text)
42
+ %w(firstname lastname address1 city).each do |attr|
43
+ expect(find(".field#b#{attr} label.error").text).to eq(text)
44
+ end
45
+ end
46
+
47
+ it 'shows translated jquery.validate error messages', js: true do
48
+ visit spree.root_path
49
+ click_link mug.name
50
+ click_button 'add-to-cart-button'
51
+ error_messages.each do |locale, message|
52
+ with_locale(locale) do
53
+ visit '/checkout/address'
54
+ find('.form-buttons input[type=submit]').click
55
+ check_error_text message
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'orders', :type => :feature do
4
+ let(:order) { OrderWalkthrough.up_to(:complete) }
5
+ let(:user) { create(:user) }
6
+
7
+ before do
8
+ order.update_attribute(:user_id, user.id)
9
+ allow_any_instance_of(Spree::OrdersController).to receive_messages(:try_spree_current_user => user)
10
+ end
11
+
12
+ it "can visit an order" do
13
+ # Regression test for current_user call on orders/show
14
+ expect { visit spree.order_path(order) }.not_to raise_error
15
+ end
16
+
17
+ it "should display line item price" do
18
+ # Regression test for #2772
19
+ line_item = order.line_items.first
20
+ line_item.target_shipment = create(:shipment)
21
+ line_item.price = 19.00
22
+ line_item.save!
23
+
24
+ visit spree.order_path(order)
25
+
26
+ # Tests view spree/shared/_order_details
27
+ within 'td.price' do
28
+ expect(page).to have_content "19.00"
29
+ end
30
+ end
31
+
32
+ it "should have credit card info if paid with credit card" do
33
+ create(:payment, :order => order)
34
+ visit spree.order_path(order)
35
+ within '.payment-info' do
36
+ expect(page).to have_content "Ending in 1111"
37
+ end
38
+ end
39
+
40
+ it "should have payment method name visible if not paid with credit card" do
41
+ create(:check_payment, :order => order)
42
+ visit spree.order_path(order)
43
+ within '.payment-info' do
44
+ expect(page).to have_content "Check"
45
+ end
46
+ end
47
+
48
+ # Regression test for #2282
49
+ context "can support a credit card with blank information" do
50
+ before do
51
+ credit_card = create(:credit_card)
52
+ credit_card.update_column(:cc_type, '')
53
+ payment = order.payments.first
54
+ payment.source = credit_card
55
+ payment.save!
56
+ end
57
+
58
+ specify do
59
+ visit spree.order_path(order)
60
+ within '.payment-info' do
61
+ expect { find("img") }.to raise_error(Capybara::ElementNotFound)
62
+ end
63
+ end
64
+ end
65
+
66
+ it "should return the correct title when displaying a completed order" do
67
+ visit spree.order_path(order)
68
+
69
+ within '#order_summary' do
70
+ expect(page).to have_content("#{Spree.t(:order)} #{order.number}")
71
+ end
72
+ end
73
+ end