spree_backend 3.0.5 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -0
  3. data/Gemfile +6 -0
  4. data/Rakefile +29 -0
  5. data/app/assets/javascripts/spree/backend/admin.js +26 -0
  6. data/app/controllers/spree/admin/resource_controller.rb +4 -2
  7. data/app/helpers/spree/admin/navigation_helper.rb +10 -1
  8. data/app/views/spree/admin/images/new.html.erb +1 -1
  9. data/app/views/spree/admin/payments/_list.html.erb +1 -1
  10. data/app/views/spree/admin/products/_form.html.erb +1 -1
  11. data/app/views/spree/admin/shared/_index_table_options.html.erb +1 -11
  12. data/app/views/spree/admin/shared/sub_menu/_product.html.erb +1 -1
  13. data/script/rails +9 -0
  14. data/spec/controllers/spree/admin/base_controller_spec.rb +46 -0
  15. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +185 -0
  16. data/spec/controllers/spree/admin/general_settings_controller_spec.rb +41 -0
  17. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +18 -0
  18. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +42 -0
  19. data/spec/controllers/spree/admin/orders_controller_spec.rb +247 -0
  20. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +49 -0
  21. data/spec/controllers/spree/admin/payments_controller_spec.rb +97 -0
  22. data/spec/controllers/spree/admin/products_controller_spec.rb +53 -0
  23. data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +21 -0
  24. data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +21 -0
  25. data/spec/controllers/spree/admin/promotions_controller_spec.rb +44 -0
  26. data/spec/controllers/spree/admin/refunds_controller_spec.rb +32 -0
  27. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +74 -0
  28. data/spec/controllers/spree/admin/reports_controller_spec.rb +42 -0
  29. data/spec/controllers/spree/admin/resource_controller_spec.rb +276 -0
  30. data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +225 -0
  31. data/spec/controllers/spree/admin/return_items_controller_spec.rb +27 -0
  32. data/spec/controllers/spree/admin/root_controller_spec.rb +35 -0
  33. data/spec/controllers/spree/admin/search_controller_spec.rb +56 -0
  34. data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +14 -0
  35. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +19 -0
  36. data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +41 -0
  37. data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +41 -0
  38. data/spec/controllers/spree/admin/tax_categories_controller_spec.rb +34 -0
  39. data/spec/controllers/spree/admin/users_controller_spec.rb +161 -0
  40. data/spec/controllers/spree/admin/variants_controller_spec.rb +32 -0
  41. data/spec/features/admin/configuration/analytics_tracker_spec.rb +46 -0
  42. data/spec/features/admin/configuration/countries_spec.rb +24 -0
  43. data/spec/features/admin/configuration/general_settings_spec.rb +43 -0
  44. data/spec/features/admin/configuration/payment_methods_spec.rb +63 -0
  45. data/spec/features/admin/configuration/roles_spec.rb +47 -0
  46. data/spec/features/admin/configuration/shipping_methods_spec.rb +62 -0
  47. data/spec/features/admin/configuration/states_spec.rb +68 -0
  48. data/spec/features/admin/configuration/stock_locations_spec.rb +48 -0
  49. data/spec/features/admin/configuration/tax_categories_spec.rb +56 -0
  50. data/spec/features/admin/configuration/tax_rates_spec.rb +18 -0
  51. data/spec/features/admin/configuration/zones_spec.rb +39 -0
  52. data/spec/features/admin/homepage_spec.rb +81 -0
  53. data/spec/features/admin/locale_spec.rb +31 -0
  54. data/spec/features/admin/orders/adjustments_promotions_spec.rb +53 -0
  55. data/spec/features/admin/orders/adjustments_spec.rb +129 -0
  56. data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +47 -0
  57. data/spec/features/admin/orders/customer_details_spec.rb +182 -0
  58. data/spec/features/admin/orders/line_items_spec.rb +51 -0
  59. data/spec/features/admin/orders/listing_spec.rb +225 -0
  60. data/spec/features/admin/orders/log_entries_spec.rb +55 -0
  61. data/spec/features/admin/orders/new_order_spec.rb +161 -0
  62. data/spec/features/admin/orders/order_details_spec.rb +620 -0
  63. data/spec/features/admin/orders/payments_spec.rb +229 -0
  64. data/spec/features/admin/orders/risk_analysis_spec.rb +48 -0
  65. data/spec/features/admin/orders/shipments_spec.rb +64 -0
  66. data/spec/features/admin/orders/state_changes_spec.rb +21 -0
  67. data/spec/features/admin/products/edit/images_spec.rb +86 -0
  68. data/spec/features/admin/products/edit/products_spec.rb +64 -0
  69. data/spec/features/admin/products/edit/taxons_spec.rb +41 -0
  70. data/spec/features/admin/products/edit/variants_spec.rb +56 -0
  71. data/spec/features/admin/products/option_types_spec.rb +113 -0
  72. data/spec/features/admin/products/products_spec.rb +394 -0
  73. data/spec/features/admin/products/properties_spec.rb +140 -0
  74. data/spec/features/admin/products/prototypes_spec.rb +112 -0
  75. data/spec/features/admin/products/stock_management_spec.rb +123 -0
  76. data/spec/features/admin/products/taxonomies_spec.rb +52 -0
  77. data/spec/features/admin/products/variant_spec.rb +50 -0
  78. data/spec/features/admin/promotions/adjustments_spec.rb +255 -0
  79. data/spec/features/admin/promotions/option_value_rule_spec.rb +70 -0
  80. data/spec/features/admin/promotions/tiered_calculator_spec.rb +70 -0
  81. data/spec/features/admin/reports_spec.rb +61 -0
  82. data/spec/features/admin/stock_transfer_spec.rb +75 -0
  83. data/spec/features/admin/taxons_spec.rb +47 -0
  84. data/spec/features/admin/users_spec.rb +284 -0
  85. data/spec/helpers/admin/base_helper_spec.rb +24 -0
  86. data/spec/helpers/admin/navigation_helper_spec.rb +106 -0
  87. data/spec/helpers/admin/stock_movements_helper_spec.rb +30 -0
  88. data/spec/helpers/promotion_rules_helper_spec.rb +12 -0
  89. data/spec/models/spree/resource_spec.rb +48 -0
  90. data/spec/spec_helper.rb +133 -0
  91. data/spec/support/appear_before_matcher.rb +8 -0
  92. data/spec/support/ror_ringer.jpeg +0 -0
  93. data/spec/test_views/spree/admin/submodule/posts/edit.html.erb +1 -0
  94. data/spec/test_views/spree/admin/submodule/posts/new.html.erb +1 -0
  95. data/spec/test_views/spree/admin/widgets/edit.html.erb +1 -0
  96. data/spec/test_views/spree/admin/widgets/new.html.erb +1 -0
  97. data/spree_backend.gemspec +29 -0
  98. metadata +101 -14
@@ -0,0 +1,229 @@
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
+ capture_amount = order.outstanding_balance/2 * 100
54
+ payment.capture!(capture_amount)
55
+
56
+ visit spree.admin_order_payment_path(order, payment)
57
+ expect(page).to have_content 'Capture events'
58
+ within '#capture_events' do
59
+ within_row(1) do
60
+ expect(page).to have_content(capture_amount / 100)
61
+ end
62
+ end
63
+ end
64
+
65
+ it 'lists and create payments for an order', js: true do
66
+ within_row(1) do
67
+ expect(column_text(3)).to eq('$150.00')
68
+ expect(column_text(4)).to eq('Credit Card')
69
+ expect(column_text(6)).to eq('checkout')
70
+ end
71
+
72
+ click_icon :void
73
+ expect(find('#payment_status').text).to eq('balance due')
74
+ expect(page).to have_content('Payment Updated')
75
+
76
+ within_row(1) do
77
+ expect(column_text(3)).to eq('$150.00')
78
+ expect(column_text(4)).to eq('Credit Card')
79
+ expect(column_text(6)).to eq('void')
80
+ end
81
+
82
+ click_on 'New Payment'
83
+ expect(page).to have_content('New Payment')
84
+ click_button 'Update'
85
+ expect(page).to have_content('successfully created!')
86
+
87
+ click_icon(:capture)
88
+ expect(find('#payment_status').text).to eq('paid')
89
+
90
+ expect(page).not_to have_selector('#new_payment_section')
91
+ end
92
+
93
+ # Regression test for #1269
94
+ it 'cannot create a payment for an order with no payment methods' do
95
+ Spree::PaymentMethod.delete_all
96
+ order.payments.delete_all
97
+
98
+ click_on 'New Payment'
99
+ expect(page).to have_content('You cannot create a payment for an order without any payment methods defined.')
100
+ expect(page).to have_content('Please define some payment methods first.')
101
+ end
102
+
103
+ %w[checkout pending].each do |state|
104
+ context "payment is #{state.inspect}", js: true do
105
+ let(:state) { state }
106
+
107
+ it 'allows the amount to be edited by clicking on the edit button then saving' do
108
+ within_row(1) do
109
+ click_icon(:edit)
110
+ fill_in('amount', with: '$1')
111
+ click_icon(:save)
112
+ expect(page).to have_selector('td.amount span', text: '$1.00')
113
+ expect(payment.reload.amount).to eq(1.00)
114
+ end
115
+ end
116
+
117
+ it 'allows the amount to be edited by clicking on the amount then saving' do
118
+ within_row(1) do
119
+ find('td.amount span').click
120
+ fill_in('amount', with: '$1.01')
121
+ click_icon(:save)
122
+ expect(page).to have_selector('td.amount span', text: '$1.01')
123
+ expect(payment.reload.amount).to eq(1.01)
124
+ end
125
+ end
126
+
127
+ it 'allows the amount change to be cancelled by clicking on the cancel button' do
128
+ within_row(1) do
129
+ click_icon(:edit)
130
+
131
+ # Can't use fill_in here, as under poltergeist that will unfocus (and
132
+ # thus submit) the field under poltergeist
133
+ find('td.amount input').click
134
+ page.execute_script("$('td.amount input').val('$1')")
135
+
136
+ click_icon(:cancel)
137
+ expect(page).to have_selector('td.amount span', text: '$150.00')
138
+ expect(payment.reload.amount).to eq(150.00)
139
+ end
140
+ end
141
+
142
+ it 'displays an error when the amount is invalid' do
143
+ within_row(1) do
144
+ click_icon(:edit)
145
+ fill_in('amount', with: 'invalid')
146
+ click_icon(:save)
147
+ expect(find('td.amount input').value).to eq('invalid')
148
+ expect(payment.reload.amount).to eq(150.00)
149
+ end
150
+ expect(page).to have_selector('.alert-error', text: 'Invalid resource. Please fix errors and try again.')
151
+ end
152
+ end
153
+ end
154
+
155
+ context 'payment is completed' do
156
+ let(:state) { 'completed' }
157
+
158
+ it 'does not allow the amount to be edited' do
159
+ within_row(1) do
160
+ expect(page).not_to have_selector('.fa-edit')
161
+ expect(page).not_to have_selector('td.amount span')
162
+ end
163
+ end
164
+ end
165
+ end
166
+
167
+ context "with no prior payments" do
168
+ let(:order) { create(:order_with_line_items, line_items_count: 1) }
169
+ let!(:payment_method) { create(:credit_card_payment_method) }
170
+
171
+ # Regression tests for #4129
172
+ context "with a credit card payment method" do
173
+ before do
174
+ visit spree.admin_order_payments_path(order)
175
+ end
176
+
177
+ it "is able to create a new credit card payment with valid information" do
178
+ fill_in "Card Number", with: "4111 1111 1111 1111"
179
+ fill_in "Name", with: "Test User"
180
+ fill_in "Expiration", with: "09 / #{Time.now.year + 1}"
181
+ fill_in "Card Code", with: "007"
182
+ # Regression test for #4277
183
+ sleep(1)
184
+ expect(find('.ccType', visible: false).value).to eq('visa')
185
+ click_button "Continue"
186
+ expect(page).to have_content("Payment has been successfully created!")
187
+ end
188
+
189
+ it "is unable to create a new payment with invalid information" do
190
+ click_button "Continue"
191
+ expect(page).to have_content("Payment could not be created.")
192
+ expect(page).to have_content("Number can't be blank")
193
+ expect(page).to have_content("Name can't be blank")
194
+ expect(page).to have_content("Verification Value can't be blank")
195
+ expect(page).to have_content("Month is not a number")
196
+ expect(page).to have_content("Year is not a number")
197
+ end
198
+ end
199
+
200
+ context "user existing card" do
201
+ let!(:cc) do
202
+ create(:credit_card, user_id: order.user_id, payment_method: payment_method, gateway_customer_profile_id: "BGS-RFRE")
203
+ end
204
+
205
+ before { visit spree.admin_order_payments_path(order) }
206
+
207
+ it "is able to reuse customer payment source" do
208
+ expect(find("#card_#{cc.id}")).to be_checked
209
+ click_button "Continue"
210
+ expect(page).to have_content("Payment has been successfully created!")
211
+ end
212
+ end
213
+
214
+ context "with a check" do
215
+ let!(:payment_method) { create(:check_payment_method) }
216
+
217
+ before do
218
+ visit spree.admin_order_payments_path(order.reload)
219
+ end
220
+
221
+ it "can successfully be created and captured" do
222
+ click_on 'Continue'
223
+ expect(page).to have_content("Payment has been successfully created!")
224
+ click_icon(:capture)
225
+ expect(page).to have_content("Payment Updated")
226
+ end
227
+ end
228
+ end
229
+ 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" 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" 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