spree_backend 3.2.9 → 3.3.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/spree/backend/admin.js +16 -15
  3. data/app/assets/javascripts/spree/backend/checkouts/edit.js +25 -26
  4. data/app/assets/javascripts/spree/backend/general_settings.js.coffee +10 -12
  5. data/app/assets/javascripts/spree/backend/payments/edit.js.coffee +4 -6
  6. data/app/assets/javascripts/spree/backend/returns/return_item_selection.js +7 -1
  7. data/app/assets/javascripts/spree/backend/stock_transfer.js.coffee +4 -1
  8. data/app/assets/javascripts/spree/backend/user_picker.js +3 -1
  9. data/app/assets/javascripts/spree/backend.js +3 -3
  10. data/app/controllers/spree/admin/countries_controller.rb +1 -0
  11. data/app/controllers/spree/admin/log_entries_controller.rb +2 -2
  12. data/app/controllers/spree/admin/orders/customer_details_controller.rb +5 -6
  13. data/app/controllers/spree/admin/orders_controller.rb +4 -4
  14. data/app/controllers/spree/admin/payments_controller.rb +21 -10
  15. data/app/controllers/spree/admin/products_controller.rb +5 -0
  16. data/app/controllers/spree/admin/promotion_rules_controller.rb +11 -7
  17. data/app/controllers/spree/admin/stock_transfers_controller.rb +1 -1
  18. data/app/controllers/spree/admin/taxons_controller.rb +31 -23
  19. data/app/helpers/spree/admin/base_helper.rb +1 -1
  20. data/app/helpers/spree/admin/navigation_helper.rb +10 -4
  21. data/app/views/spree/admin/adjustments/_adjustments_table.html.erb +2 -2
  22. data/app/views/spree/admin/general_settings/edit.html.erb +8 -8
  23. data/app/views/spree/admin/images/_form.html.erb +2 -2
  24. data/app/views/spree/admin/images/edit.html.erb +2 -2
  25. data/app/views/spree/admin/images/new.html.erb +1 -1
  26. data/app/views/spree/admin/option_types/_form.html.erb +2 -2
  27. data/app/views/spree/admin/option_types/index.html.erb +4 -4
  28. data/app/views/spree/admin/orders/_line_items.html.erb +40 -38
  29. data/app/views/spree/admin/orders/_shipment.html.erb +77 -76
  30. data/app/views/spree/admin/orders/customer_details/_form.html.erb +5 -5
  31. data/app/views/spree/admin/orders/index.html.erb +16 -16
  32. data/app/views/spree/admin/payment_methods/_form.html.erb +2 -2
  33. data/app/views/spree/admin/payments/_list.html.erb +1 -1
  34. data/app/views/spree/admin/products/_add_stock_form.html.erb +3 -3
  35. data/app/views/spree/admin/products/_form.html.erb +16 -16
  36. data/app/views/spree/admin/products/index.html.erb +4 -4
  37. data/app/views/spree/admin/products/new.html.erb +8 -8
  38. data/app/views/spree/admin/promotion_categories/index.html.erb +3 -3
  39. data/app/views/spree/admin/promotions/_form.html.erb +3 -3
  40. data/app/views/spree/admin/promotions/_promotion_rule.html.erb +1 -1
  41. data/app/views/spree/admin/promotions/actions/_create_adjustment.html.erb +2 -2
  42. data/app/views/spree/admin/promotions/actions/_create_item_adjustments.html.erb +2 -2
  43. data/app/views/spree/admin/promotions/actions/_create_line_items.html.erb +2 -4
  44. data/app/views/spree/admin/promotions/edit.html.erb +3 -3
  45. data/app/views/spree/admin/promotions/index.html.erb +6 -6
  46. data/app/views/spree/admin/promotions/rules/_item_total.html.erb +2 -2
  47. data/app/views/spree/admin/promotions/rules/_option_value.html.erb +4 -4
  48. data/app/views/spree/admin/properties/_form.html.erb +2 -2
  49. data/app/views/spree/admin/properties/index.html.erb +6 -6
  50. data/app/views/spree/admin/prototypes/index.html.erb +4 -4
  51. data/app/views/spree/admin/reimbursement_types/_form.html.erb +4 -4
  52. data/app/views/spree/admin/reimbursements/edit.html.erb +1 -1
  53. data/app/views/spree/admin/return_authorizations/_form.html.erb +13 -1
  54. data/app/views/spree/admin/return_index/customer_returns.html.erb +2 -2
  55. data/app/views/spree/admin/return_index/return_authorizations.html.erb +5 -5
  56. data/app/views/spree/admin/shared/_content_header.html.erb +2 -2
  57. data/app/views/spree/admin/shared/_header.html.erb +2 -2
  58. data/app/views/spree/admin/shared/_index_table_options.html.erb +2 -2
  59. data/app/views/spree/admin/shared/_order_summary.html.erb +1 -1
  60. data/app/views/spree/admin/shared/_table_filter.html.erb +1 -1
  61. data/app/views/spree/admin/shared/_translations.html.erb +0 -1
  62. data/app/views/spree/admin/shared/_update_order_state.js.erb +1 -1
  63. data/app/views/spree/admin/shipping_methods/_form.html.erb +10 -10
  64. data/app/views/spree/admin/state_changes/index.html.erb +3 -3
  65. data/app/views/spree/admin/states/_form.html.erb +2 -2
  66. data/app/views/spree/admin/stock_locations/_form.html.erb +2 -2
  67. data/app/views/spree/admin/stock_locations/_transfer_stock_form.html.erb +4 -4
  68. data/app/views/spree/admin/stock_transfers/index.html.erb +3 -3
  69. data/app/views/spree/admin/stock_transfers/new.html.erb +2 -2
  70. data/app/views/spree/admin/store_credits/index.html.erb +1 -1
  71. data/app/views/spree/admin/tax_rates/_form.html.erb +2 -2
  72. data/app/views/spree/admin/taxonomies/_list.html.erb +2 -2
  73. data/app/views/spree/admin/taxonomies/{edit.erb → edit.html.erb} +0 -0
  74. data/app/views/spree/admin/taxonomies/index.html.erb +2 -2
  75. data/app/views/spree/admin/taxons/_form.html.erb +5 -5
  76. data/app/views/spree/admin/taxons/edit.html.erb +3 -0
  77. data/app/views/spree/admin/trackers/_form.html.erb +2 -2
  78. data/app/views/spree/admin/users/_addresses_form.html.erb +2 -2
  79. data/app/views/spree/admin/users/_form.html.erb +2 -2
  80. data/app/views/spree/admin/users/_user_page_actions.html.erb +1 -1
  81. data/app/views/spree/admin/users/index.html.erb +5 -5
  82. data/app/views/spree/admin/users/items.html.erb +1 -1
  83. data/app/views/spree/admin/users/orders.html.erb +1 -1
  84. data/app/views/spree/admin/variants/_form.html.erb +2 -2
  85. data/app/views/spree/admin/zones/_form.html.erb +2 -2
  86. data/app/views/spree/layouts/admin.html.erb +3 -3
  87. data/config/initializers/assets.rb +1 -1
  88. data/lib/spree/backend/engine.rb +0 -1
  89. data/spec/controllers/spree/admin/base_controller_spec.rb +46 -0
  90. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +185 -0
  91. data/spec/controllers/spree/admin/general_settings_controller_spec.rb +41 -0
  92. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +18 -0
  93. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +199 -0
  94. data/spec/controllers/spree/admin/orders_controller_spec.rb +296 -0
  95. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +64 -0
  96. data/spec/controllers/spree/admin/payments_controller_spec.rb +97 -0
  97. data/spec/controllers/spree/admin/products_controller_spec.rb +137 -0
  98. data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +21 -0
  99. data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +21 -0
  100. data/spec/controllers/spree/admin/promotions_controller_spec.rb +44 -0
  101. data/spec/controllers/spree/admin/refunds_controller_spec.rb +32 -0
  102. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +74 -0
  103. data/spec/controllers/spree/admin/reports_controller_spec.rb +42 -0
  104. data/spec/controllers/spree/admin/resource_controller_spec.rb +252 -0
  105. data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +225 -0
  106. data/spec/controllers/spree/admin/return_index_controller_spec.rb +37 -0
  107. data/spec/controllers/spree/admin/return_items_controller_spec.rb +27 -0
  108. data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +14 -0
  109. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +19 -0
  110. data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +41 -0
  111. data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +41 -0
  112. data/spec/controllers/spree/admin/tax_categories_controller_spec.rb +34 -0
  113. data/spec/controllers/spree/admin/users_controller_spec.rb +161 -0
  114. data/spec/controllers/spree/admin/variants_controller_spec.rb +32 -0
  115. data/spec/features/admin/configuration/analytics_tracker_spec.rb +47 -0
  116. data/spec/features/admin/configuration/countries_spec.rb +24 -0
  117. data/spec/features/admin/configuration/general_settings_spec.rb +44 -0
  118. data/spec/features/admin/configuration/payment_methods_spec.rb +63 -0
  119. data/spec/features/admin/configuration/roles_spec.rb +47 -0
  120. data/spec/features/admin/configuration/shipping_methods_spec.rb +62 -0
  121. data/spec/features/admin/configuration/states_spec.rb +68 -0
  122. data/spec/features/admin/configuration/stock_locations_spec.rb +48 -0
  123. data/spec/features/admin/configuration/store_credit_categories_spec.rb +50 -0
  124. data/spec/features/admin/configuration/tax_categories_spec.rb +56 -0
  125. data/spec/features/admin/configuration/tax_rates_spec.rb +18 -0
  126. data/spec/features/admin/configuration/zones_spec.rb +39 -0
  127. data/spec/features/admin/homepage_spec.rb +89 -0
  128. data/spec/features/admin/locale_spec.rb +31 -0
  129. data/spec/features/admin/orders/adjustments_promotions_spec.rb +53 -0
  130. data/spec/features/admin/orders/adjustments_spec.rb +124 -0
  131. data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +47 -0
  132. data/spec/features/admin/orders/customer_details_spec.rb +154 -0
  133. data/spec/features/admin/orders/line_items_spec.rb +51 -0
  134. data/spec/features/admin/orders/listing_spec.rb +224 -0
  135. data/spec/features/admin/orders/log_entries_spec.rb +55 -0
  136. data/spec/features/admin/orders/new_order_spec.rb +186 -0
  137. data/spec/features/admin/orders/order_details_spec.rb +660 -0
  138. data/spec/features/admin/orders/payments_spec.rb +244 -0
  139. data/spec/features/admin/orders/risk_analysis_spec.rb +48 -0
  140. data/spec/features/admin/orders/shipments_spec.rb +64 -0
  141. data/spec/features/admin/orders/state_changes_spec.rb +21 -0
  142. data/spec/features/admin/products/edit/images_spec.rb +86 -0
  143. data/spec/features/admin/products/edit/products_spec.rb +56 -0
  144. data/spec/features/admin/products/edit/taxons_spec.rb +41 -0
  145. data/spec/features/admin/products/edit/variants_spec.rb +56 -0
  146. data/spec/features/admin/products/option_types_spec.rb +114 -0
  147. data/spec/features/admin/products/products_spec.rb +445 -0
  148. data/spec/features/admin/products/properties_spec.rb +147 -0
  149. data/spec/features/admin/products/prototypes_spec.rb +112 -0
  150. data/spec/features/admin/products/stock_management_spec.rb +124 -0
  151. data/spec/features/admin/products/taxonomies_spec.rb +52 -0
  152. data/spec/features/admin/products/variant_spec.rb +50 -0
  153. data/spec/features/admin/promotions/adjustments_spec.rb +258 -0
  154. data/spec/features/admin/promotions/option_value_rule_spec.rb +70 -0
  155. data/spec/features/admin/promotions/tiered_calculator_spec.rb +70 -0
  156. data/spec/features/admin/refund_reasons/refund_reasons_spec.rb +57 -0
  157. data/spec/features/admin/reimbursement_type/edit_reimbursement_type_spec.rb +36 -0
  158. data/spec/features/admin/reimbursement_type/new_reimbursement_type_spec.rb +62 -0
  159. data/spec/features/admin/reports_spec.rb +61 -0
  160. data/spec/features/admin/return_authorization_reasons/return_authorization_reasons_spec.rb +63 -0
  161. data/spec/features/admin/returns/customer_returns_spec.rb +80 -0
  162. data/spec/features/admin/returns/return_authorizations_spec.rb +152 -0
  163. data/spec/features/admin/stock_transfer_spec.rb +91 -0
  164. data/spec/features/admin/store_credits_spec.rb +93 -0
  165. data/spec/features/admin/taxons_spec.rb +53 -0
  166. data/spec/features/admin/users_spec.rb +286 -0
  167. data/spec/helpers/admin/base_helper_spec.rb +30 -0
  168. data/spec/helpers/admin/navigation_helper_spec.rb +111 -0
  169. data/spec/helpers/admin/promotion_rules_helper_spec.rb +12 -0
  170. data/spec/helpers/admin/stock_movements_helper_spec.rb +30 -0
  171. data/spec/models/spree/resource_spec.rb +48 -0
  172. data/spec/routing/admin_path_spec.rb +22 -0
  173. data/spec/spec_helper.rb +144 -0
  174. data/spec/support/appear_before_matcher.rb +8 -0
  175. data/spec/support/ror_ringer.jpeg +0 -0
  176. data/spec/test_views/spree/admin/submodule/posts/edit.html.erb +1 -0
  177. data/spec/test_views/spree/admin/submodule/posts/new.html.erb +1 -0
  178. data/spec/test_views/spree/admin/widgets/edit.html.erb +1 -0
  179. data/spec/test_views/spree/admin/widgets/new.html.erb +1 -0
  180. data/spree_backend.gemspec +4 -4
  181. data/vendor/assets/javascripts/jquery.jstree/jquery.jstree.js +130 -154
  182. metadata +106 -29
  183. data/vendor/assets/images/jquery-ui/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  184. data/vendor/assets/images/jquery-ui/ui-bg_flat_0_eeeeee_40x100.png +0 -0
  185. data/vendor/assets/images/jquery-ui/ui-bg_flat_55_ffffff_40x100.png +0 -0
  186. data/vendor/assets/images/jquery-ui/ui-bg_flat_75_ffffff_40x100.png +0 -0
  187. data/vendor/assets/images/jquery-ui/ui-bg_glass_65_ffffff_1x400.png +0 -0
  188. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_100_f6f6f6_1x100.png +0 -0
  189. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_25_0073ea_1x100.png +0 -0
  190. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_50_dddddd_1x100.png +0 -0
  191. data/vendor/assets/images/jquery-ui/ui-icons_0073ea_256x240.png +0 -0
  192. data/vendor/assets/images/jquery-ui/ui-icons_454545_256x240.png +0 -0
  193. data/vendor/assets/images/jquery-ui/ui-icons_666666_256x240.png +0 -0
  194. data/vendor/assets/images/jquery-ui/ui-icons_ff0084_256x240.png +0 -0
  195. data/vendor/assets/images/jquery-ui/ui-icons_ffffff_256x240.png +0 -0
  196. data/vendor/assets/stylesheets/jquery-ui.datepicker.css.erb +0 -357
@@ -0,0 +1,244 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Payments', type: :feature, js: true do
4
+ stub_authorization!
5
+
6
+ context "with a pre-existing payment" do
7
+
8
+ let!(:payment) do
9
+ create(:payment,
10
+ order: order,
11
+ amount: order.outstanding_balance,
12
+ payment_method: create(:credit_card_payment_method),
13
+ state: state
14
+ )
15
+ end
16
+
17
+ let(:order) { create(:completed_order_with_totals, number: 'R100', line_items_count: 5) }
18
+ let(:state) { 'checkout' }
19
+
20
+ before do
21
+ visit spree.edit_admin_order_path(order)
22
+ click_link 'Payments'
23
+ end
24
+
25
+ def refresh_page
26
+ visit current_path
27
+ end
28
+
29
+ # Regression tests for #1453
30
+ context 'with a check payment' do
31
+ let(:order) { create(:completed_order_with_totals, number: 'R100') }
32
+ let!(:payment) do
33
+ create(:payment,
34
+ order: order,
35
+ amount: order.outstanding_balance,
36
+ payment_method: create(:check_payment_method) # Check
37
+ )
38
+ end
39
+
40
+ it 'capturing a check payment from a new order' do
41
+ click_icon(:capture)
42
+ expect(page).not_to have_content('Cannot perform requested operation')
43
+ expect(page).to have_content('Payment Updated')
44
+ end
45
+
46
+ it 'voids a check payment from a new order' do
47
+ click_icon(:void)
48
+ expect(page).to have_content('Payment Updated')
49
+ end
50
+ end
51
+
52
+ it 'should list all captures for a payment' do
53
+ Spree::ShippingMethod.delete_all
54
+ capture_amount = order.outstanding_balance/2 * 100
55
+ payment.capture!(capture_amount)
56
+
57
+ visit spree.admin_order_payment_path(order, payment)
58
+ expect(page).to have_content 'Capture events'
59
+ within '#capture_events' do
60
+ within_row(1) do
61
+ expect(page).to have_content(capture_amount / 100)
62
+ end
63
+ end
64
+ end
65
+
66
+ it 'lists and create payments for an order' do
67
+ within_row(1) do
68
+ expect(column_text(3)).to eq('$150.00')
69
+ expect(column_text(4)).to eq('Credit Card')
70
+ expect(column_text(6)).to eq('checkout')
71
+ end
72
+
73
+ click_icon :void
74
+ expect(find('#payment_status').text).to eq('balance due')
75
+ expect(page).to have_content('Payment Updated')
76
+
77
+ within_row(1) do
78
+ expect(column_text(3)).to eq('$150.00')
79
+ expect(column_text(4)).to eq('Credit Card')
80
+ expect(column_text(6)).to eq('void')
81
+ end
82
+
83
+ click_on 'New Payment'
84
+ expect(page).to have_content('New Payment')
85
+ click_button 'Update'
86
+ expect(page).to have_content('successfully created!')
87
+
88
+ click_icon(:capture)
89
+ wait_for_ajax
90
+ expect(find('#payment_status').text).to eq('paid')
91
+
92
+ expect(page).not_to have_selector('#new_payment_section')
93
+ end
94
+
95
+ # Regression test for #1269
96
+ it 'cannot create a payment for an order with no payment methods', js: false do
97
+ Spree::PaymentMethod.delete_all
98
+ order.payments.delete_all
99
+
100
+ click_on 'New Payment'
101
+ expect(page).to have_content('You cannot create a payment for an order without any payment methods defined.')
102
+ expect(page).to have_content('Please define some payment methods first.')
103
+ end
104
+
105
+ %w[checkout pending].each do |state|
106
+ context "payment is #{state.inspect}" do
107
+ let(:state) { state }
108
+
109
+ it 'allows the amount to be edited by clicking on the edit button then saving' do
110
+ within_row(1) do
111
+ click_icon(:edit)
112
+ fill_in('amount', with: '$1')
113
+ click_icon(:save)
114
+ expect(page).to have_selector('td.amount span', text: '$1.00')
115
+ expect(payment.reload.amount).to eq(1.00)
116
+ end
117
+ end
118
+
119
+ it 'allows the amount to be edited by clicking on the amount then saving' do
120
+ within_row(1) do
121
+ find('td.amount span').click
122
+ fill_in('amount', with: '$1.01')
123
+ click_icon(:save)
124
+ expect(page).to have_selector('td.amount span', text: '$1.01')
125
+ expect(payment.reload.amount).to eq(1.01)
126
+ end
127
+ end
128
+
129
+ it 'allows the amount change to be cancelled by clicking on the cancel button' do
130
+ within_row(1) do
131
+ click_icon(:edit)
132
+
133
+ # Can't use fill_in here, as under poltergeist that will unfocus (and
134
+ # thus submit) the field under poltergeist
135
+ find('td.amount input').click
136
+ page.execute_script("$('td.amount input').val('$1')")
137
+
138
+ click_icon(:cancel)
139
+ expect(page).to have_selector('td.amount span', text: '$150.00')
140
+ expect(payment.reload.amount).to eq(150.00)
141
+ end
142
+ end
143
+
144
+ it 'displays an error when the amount is invalid' do
145
+ within_row(1) do
146
+ click_icon(:edit)
147
+ fill_in('amount', with: 'invalid')
148
+ click_icon(:save)
149
+ expect(find('td.amount input').value).to eq('invalid')
150
+ expect(payment.reload.amount).to eq(150.00)
151
+ end
152
+ expect(page).to have_selector('.alert-error', text: 'Invalid resource. Please fix errors and try again.')
153
+ end
154
+ end
155
+ end
156
+
157
+ context 'payment is completed', js: false do
158
+ let(:state) { 'completed' }
159
+
160
+ it 'does not allow the amount to be edited' do
161
+ within_row(1) do
162
+ expect(page).not_to have_selector('td.amount span')
163
+ end
164
+ end
165
+ end
166
+ end
167
+
168
+ context "with no prior payments" do
169
+ let(:order) { create(:order_with_line_items, line_items_count: 1) }
170
+ let!(:payment_method) { create(:credit_card_payment_method) }
171
+
172
+ # Regression tests for #4129
173
+ context "with a credit card payment method" do
174
+ before do
175
+ visit spree.admin_order_payments_path(order)
176
+ end
177
+
178
+ it "is able to create a new credit card payment with valid information" do
179
+ fill_in "Card Number", with: "4111 1111 1111 1111"
180
+ fill_in "Name", with: "Test User"
181
+ fill_in "Expiration", with: "09 / #{Time.current.year + 1}"
182
+ fill_in "Card Code", with: "007"
183
+ # Regression test for #4277
184
+ sleep(1)
185
+ expect(find('.ccType', visible: false).value).to eq('visa')
186
+ click_button "Continue"
187
+ expect(page).to have_content("Payment has been successfully created!")
188
+ end
189
+
190
+ it "is unable to create a new payment with invalid information" do
191
+ click_button "Continue"
192
+ expect(page).to have_content("Payment could not be created.")
193
+ expect(page).to have_content("Number can't be blank")
194
+ expect(page).to have_content("Name can't be blank")
195
+ expect(page).to have_content("Verification Value can't be blank")
196
+ expect(page).to have_content("Month is not a number")
197
+ expect(page).to have_content("Year is not a number")
198
+ end
199
+ end
200
+
201
+ context "user existing card" do
202
+ let!(:cc) do
203
+ create(:credit_card, user_id: order.user_id, payment_method: payment_method, gateway_customer_profile_id: "BGS-RFRE")
204
+ end
205
+
206
+ before { visit spree.admin_order_payments_path(order) }
207
+
208
+ it "is able to reuse customer payment source", js: false do
209
+ expect(find("#card_#{cc.id}")).to be_checked
210
+ click_button "Continue"
211
+ expect(page).to have_content("Payment has been successfully created!")
212
+ end
213
+ end
214
+
215
+ context "with a check" do
216
+ let!(:payment_method) { create(:check_payment_method) }
217
+
218
+ before do
219
+ visit spree.admin_order_payments_path(order.reload)
220
+ end
221
+
222
+ it "can successfully be created and captured" do
223
+ click_on 'Continue'
224
+ expect(page).to have_content("Payment has been successfully created!")
225
+ click_icon(:capture)
226
+ expect(page).to have_content("Payment Updated")
227
+ end
228
+ end
229
+
230
+ context 'store_credit payment' do
231
+ let!(:payment_method) { create(:store_credit_payment_method) }
232
+ let!(:category) { create(:store_credit_category, name: 'Default') }
233
+ let!(:store_credit) { create(:store_credit, user: order.user, category: category, amount: 500) }
234
+
235
+ before do
236
+ visit spree.new_admin_order_payment_path(order.reload)
237
+ choose("payment_payment_method_id_#{payment_method.id}")
238
+ click_button 'Continue'
239
+ end
240
+
241
+ it { expect(page).to have_content('successfully created') }
242
+ end
243
+ end
244
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Order Risk Analysis', type: :feature do
4
+ stub_authorization!
5
+
6
+ let!(:order) do
7
+ create(:completed_order_with_pending_payment)
8
+ end
9
+
10
+ def visit_order
11
+ visit spree.admin_path
12
+ click_link 'Orders'
13
+ within_row(1) do
14
+ click_link order.number
15
+ end
16
+ end
17
+
18
+ context "the order is considered risky" do
19
+ before do
20
+ allow_any_instance_of(Spree::Admin::BaseController).to receive_messages try_spree_current_user: create(:user)
21
+
22
+ order.payments.first.update_column(:avs_response, 'X')
23
+ order.considered_risky!
24
+ visit_order
25
+ end
26
+
27
+ it "displays 'Risk Analysis' box" do
28
+ expect(page).to have_content 'Risk Analysis'
29
+ end
30
+
31
+ it "can be approved" do
32
+ click_button('Approve')
33
+ expect(page).to have_content 'Approver'
34
+ expect(page).to have_content 'Approved at'
35
+ expect(page).to have_content 'Status: complete'
36
+ end
37
+ end
38
+
39
+ context "the order is not considered risky" do
40
+ before do
41
+ visit_order
42
+ end
43
+
44
+ it "does not display 'Risk Analysis' box" do
45
+ expect(page).to_not have_content 'Risk Analysis'
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Shipments", type: :feature do
4
+ stub_authorization!
5
+
6
+ let!(:order) { create(:order_ready_to_ship, number: "R100", state: "complete", line_items_count: 5) }
7
+
8
+ # Regression test for #4025
9
+ context "a shipment without a shipping method" do
10
+ before do
11
+ order.shipments.each do |s|
12
+ # Deleting the shipping rates causes there to be no shipping methods
13
+ s.shipping_rates.delete_all
14
+ end
15
+ end
16
+
17
+ it "can still be displayed" do
18
+ expect { visit spree.edit_admin_order_path(order) }.not_to raise_error
19
+ end
20
+ end
21
+
22
+ context "shipping an order", js: true do
23
+ before(:each) do
24
+ visit spree.admin_orders_path
25
+ within_row(1) do
26
+ click_link "R100"
27
+ end
28
+ end
29
+
30
+ it "can ship a completed order" do
31
+ click_on "Ship"
32
+ wait_for_ajax
33
+
34
+ expect(page).to have_content("shipped package")
35
+ expect(order.reload.shipment_state).to eq("shipped")
36
+ end
37
+ end
38
+
39
+ context "moving variants between shipments", js: true do
40
+ let!(:la) { create(:stock_location, name: "LA") }
41
+ before(:each) do
42
+ visit spree.admin_orders_path
43
+ within_row(1) do
44
+ click_link "R100"
45
+ end
46
+ end
47
+
48
+ it "can move a variant to a new and to an existing shipment" do
49
+ expect(order.shipments.count).to eq(1)
50
+
51
+ within_row(1) { click_icon :split }
52
+ targetted_select2 'LA', from: '#s2id_item_stock_location'
53
+ click_icon :save
54
+ wait_for_ajax
55
+ expect(page.find("#shipment_#{order.shipments.first.id}")).to be_present
56
+
57
+ within_row(2) { click_icon :split }
58
+ targetted_select2 "LA(#{order.reload.shipments.last.number})", from: '#s2id_item_stock_location'
59
+ click_icon :save
60
+ wait_for_ajax
61
+ expect(page.find("#shipment_#{order.reload.shipments.last.id}")).to be_present
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Order - State Changes", type: :feature do
4
+ stub_authorization!
5
+
6
+ let!(:order) { create(:order_with_line_items) }
7
+
8
+ context "for completed order" do
9
+ before do
10
+ order.next!
11
+ visit spree.admin_order_state_changes_path(order)
12
+ end
13
+ it 'are viewable' do
14
+ within_row(1) do
15
+ within('td:nth-child(1)') { expect(page).to have_content('Order') }
16
+ within('td:nth-child(2)') { expect(page).to have_content('cart') }
17
+ within('td:nth-child(3)') { expect(page).to have_content('address') }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Product Images", type: :feature, js: true do
4
+ stub_authorization!
5
+
6
+ let(:file_path) { Rails.root + "../../spec/support/ror_ringer.jpeg" }
7
+
8
+ before do
9
+ # Ensure attachment style keys are symbolized before running all tests
10
+ # Otherwise this would result in this error:
11
+ # undefined method `processors' for \"48x48>\
12
+ Spree::Image.attachment_definitions[:attachment][:styles].symbolize_keys!
13
+ end
14
+
15
+ context "uploading, editing, and deleting an image" do
16
+ it "should allow an admin to upload and edit an image for a product" do
17
+ Spree::Image.attachment_definitions[:attachment].delete :storage
18
+
19
+ create(:product)
20
+
21
+ visit spree.admin_products_path
22
+ click_icon(:edit)
23
+ click_link "Images"
24
+ click_link "new_image_link"
25
+ attach_file('image_attachment', file_path)
26
+ click_button "Create"
27
+ expect(page).to have_content("successfully created!")
28
+
29
+ click_icon(:edit)
30
+ fill_in "image_alt", with: "ruby on rails t-shirt"
31
+ click_button "Update"
32
+ expect(page).to have_content("successfully updated!")
33
+ expect(page).to have_content("ruby on rails t-shirt")
34
+
35
+ accept_alert do
36
+ click_icon :delete
37
+ end
38
+ expect(page).not_to have_content("ruby on rails t-shirt")
39
+ end
40
+ end
41
+
42
+ # Regression test for #2228
43
+ it "should see variant images", js: false do
44
+ variant = create(:variant)
45
+ variant.images.create!(attachment: File.open(file_path))
46
+ visit spree.admin_product_images_path(variant.product)
47
+
48
+ expect(page).not_to have_content("No Images Found.")
49
+ within("table.table") do
50
+ expect(page).to have_content(variant.options_text)
51
+
52
+ #ensure no duplicate images are displayed
53
+ expect(page).to have_css("tbody tr", count: 1)
54
+
55
+ #ensure variant header is displayed
56
+ within("thead") do
57
+ expect(page.body).to have_content("Variant")
58
+ end
59
+
60
+ #ensure variant header is displayed
61
+ within("tbody") do
62
+ expect(page).to have_content("Size: S")
63
+ end
64
+ end
65
+ end
66
+
67
+ it "should not see variant column when product has no variants", js: false do
68
+ product = create(:product)
69
+ product.images.create!(attachment: File.open(file_path))
70
+ visit spree.admin_product_images_path(product)
71
+
72
+ expect(page).not_to have_content("No Images Found.")
73
+ within("table.table") do
74
+ #ensure no duplicate images are displayed
75
+ expect(page).to have_css("tbody tr", count: 1)
76
+
77
+ #ensure variant header is not displayed
78
+ within("thead") do
79
+ expect(page).not_to have_content("Variant")
80
+ end
81
+
82
+ #ensure correct cell count
83
+ expect(page).to have_css("thead th", count: 3)
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,56 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe 'Product Details', type: :feature, js: true do
5
+ stub_authorization!
6
+
7
+ context 'editing a product' do
8
+ it 'should list the product details' do
9
+ create(:product, name: 'Bún thịt nướng', sku: 'A100',
10
+ description: 'lorem ipsum', available_on: '2013-08-14 01:02:03')
11
+
12
+ visit spree.admin_products_path
13
+ within_row(1) { click_icon :edit }
14
+
15
+ click_link 'Details'
16
+
17
+ expect(find('.content-header h1').text.strip).to eq('Products / Bún thịt nướng')
18
+ expect(find('input#product_name').value).to eq('Bún thịt nướng')
19
+ expect(find('input#product_slug').value).to eq('bun-th-t-n-ng')
20
+ expect(find('textarea#product_description').text.strip).to eq('lorem ipsum')
21
+ expect(find('input#product_price').value).to eq('19.99')
22
+ expect(find('input#product_cost_price').value).to eq('17.00')
23
+ expect(find('input#product_available_on').value).to eq("2013/08/14")
24
+ expect(find('input#product_sku').value).to eq('A100')
25
+ end
26
+
27
+ it "should handle slug changes" do
28
+ create(:product, name: 'Bún thịt nướng', sku: 'A100',
29
+ description: 'lorem ipsum', available_on: '2011-01-01 01:01:01')
30
+
31
+ visit spree.admin_products_path
32
+ within('table.table tbody tr:nth-child(1)') do
33
+ click_icon(:edit)
34
+ end
35
+
36
+ fill_in "product_slug", with: 'random-slug-value'
37
+ click_button "Update"
38
+ expect(page).to have_content("successfully updated!")
39
+ end
40
+ end
41
+
42
+ # Regression test for #3385
43
+ context "deleting a product" do
44
+ it "is still able to find the master variant" do
45
+ create(:product)
46
+
47
+ visit spree.admin_products_path
48
+ within_row(1) do
49
+ accept_alert do
50
+ click_icon :delete
51
+ end
52
+ end
53
+ wait_for_ajax
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Product Taxons", type: :feature, js: true do
4
+ stub_authorization!
5
+
6
+ after do
7
+ Capybara.ignore_hidden_elements = true
8
+ end
9
+
10
+ before do
11
+ Capybara.ignore_hidden_elements = false
12
+ end
13
+
14
+ context "managing taxons" do
15
+ def selected_taxons
16
+ find("#product_taxon_ids").value.split(',').map(&:to_i).uniq
17
+ end
18
+
19
+ it "should allow an admin to manage taxons" do
20
+ taxon_1 = create(:taxon)
21
+ taxon_2 = create(:taxon, name: 'Clothing')
22
+ product = create(:product)
23
+ product.taxons << taxon_1
24
+
25
+ visit spree.admin_products_path
26
+ within_row(1) { click_icon :edit }
27
+
28
+ expect(find(".select2-search-choice").text).to eq(taxon_1.name)
29
+ expect(selected_taxons).to match_array([taxon_1.id])
30
+
31
+ select2_search "Clothing", from: "Taxons"
32
+ click_button "Update"
33
+ expect(selected_taxons).to match_array([taxon_1.id, taxon_2.id])
34
+
35
+ # Regression test for #2139
36
+ sleep(1)
37
+ expect(first(".select2-search-choice", text: taxon_1.name)).to be_present
38
+ expect(first(".select2-search-choice", text: taxon_2.name)).to be_present
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Product Variants", type: :feature, js: true do
4
+ stub_authorization!
5
+
6
+ let!(:product) { create(:product) }
7
+
8
+ before(:each) do
9
+ visit spree.admin_products_path
10
+ end
11
+
12
+ context "editing variant option types" do
13
+ it "should allow an admin to create option types for a variant" do
14
+ within_row(1) { click_icon :edit }
15
+
16
+ within('#sidebar') { click_link "Variants" }
17
+ expect(page).to have_content("To add variants, you must first define")
18
+ end
19
+
20
+ it "allows admin to create a variant if there are option types" do
21
+ click_link "Products"
22
+ click_link "Option Types"
23
+ click_link "new_option_type_link"
24
+ fill_in "option_type_name", with: "shirt colors"
25
+ fill_in "option_type_presentation", with: "colors"
26
+ click_button "Create"
27
+ expect(page).to have_content("successfully created!")
28
+
29
+ page.find('#option_type_option_values_attributes_0_name').set('color')
30
+ page.find('#option_type_option_values_attributes_0_presentation').set('black')
31
+ click_button "Update"
32
+ expect(page).to have_content("successfully updated!")
33
+
34
+ visit spree.admin_products_path
35
+ within_row(1) { click_icon :edit }
36
+
37
+ select2_search "shirt", from: "Option Types"
38
+ click_button "Update"
39
+ expect(page).to have_content("successfully updated!")
40
+
41
+ within('#sidebar') { click_link "Variants" }
42
+ click_link "New Variant"
43
+
44
+ targetted_select2 "black", from: "#s2id_variant_option_value_ids"
45
+ fill_in "variant_sku", with: "A100"
46
+ click_button "Create"
47
+ expect(page).to have_content("successfully created!")
48
+
49
+ within(".table") do
50
+ expect(page).to have_content("19.99")
51
+ expect(page).to have_content("black")
52
+ expect(page).to have_content("A100")
53
+ end
54
+ end
55
+ end
56
+ end