spree_backend 3.2.1 → 3.2.2

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.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/app/views/spree/admin/products/_form.html.erb +8 -8
  3. data/spree_backend.gemspec +2 -2
  4. metadata +9 -100
  5. data/spec/controllers/spree/admin/base_controller_spec.rb +0 -46
  6. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +0 -185
  7. data/spec/controllers/spree/admin/general_settings_controller_spec.rb +0 -41
  8. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +0 -18
  9. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +0 -197
  10. data/spec/controllers/spree/admin/orders_controller_spec.rb +0 -296
  11. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +0 -64
  12. data/spec/controllers/spree/admin/payments_controller_spec.rb +0 -97
  13. data/spec/controllers/spree/admin/products_controller_spec.rb +0 -99
  14. data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +0 -21
  15. data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +0 -21
  16. data/spec/controllers/spree/admin/promotions_controller_spec.rb +0 -44
  17. data/spec/controllers/spree/admin/refunds_controller_spec.rb +0 -32
  18. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +0 -74
  19. data/spec/controllers/spree/admin/reports_controller_spec.rb +0 -42
  20. data/spec/controllers/spree/admin/resource_controller_spec.rb +0 -252
  21. data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +0 -225
  22. data/spec/controllers/spree/admin/return_index_controller_spec.rb +0 -37
  23. data/spec/controllers/spree/admin/return_items_controller_spec.rb +0 -27
  24. data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +0 -14
  25. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +0 -19
  26. data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +0 -41
  27. data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +0 -41
  28. data/spec/controllers/spree/admin/tax_categories_controller_spec.rb +0 -34
  29. data/spec/controllers/spree/admin/users_controller_spec.rb +0 -161
  30. data/spec/controllers/spree/admin/variants_controller_spec.rb +0 -32
  31. data/spec/features/admin/configuration/analytics_tracker_spec.rb +0 -47
  32. data/spec/features/admin/configuration/countries_spec.rb +0 -24
  33. data/spec/features/admin/configuration/general_settings_spec.rb +0 -44
  34. data/spec/features/admin/configuration/payment_methods_spec.rb +0 -63
  35. data/spec/features/admin/configuration/roles_spec.rb +0 -47
  36. data/spec/features/admin/configuration/shipping_methods_spec.rb +0 -62
  37. data/spec/features/admin/configuration/states_spec.rb +0 -68
  38. data/spec/features/admin/configuration/stock_locations_spec.rb +0 -48
  39. data/spec/features/admin/configuration/store_credit_categories_spec.rb +0 -50
  40. data/spec/features/admin/configuration/tax_categories_spec.rb +0 -56
  41. data/spec/features/admin/configuration/tax_rates_spec.rb +0 -18
  42. data/spec/features/admin/configuration/zones_spec.rb +0 -39
  43. data/spec/features/admin/homepage_spec.rb +0 -89
  44. data/spec/features/admin/locale_spec.rb +0 -31
  45. data/spec/features/admin/orders/adjustments_promotions_spec.rb +0 -53
  46. data/spec/features/admin/orders/adjustments_spec.rb +0 -130
  47. data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +0 -47
  48. data/spec/features/admin/orders/customer_details_spec.rb +0 -154
  49. data/spec/features/admin/orders/line_items_spec.rb +0 -51
  50. data/spec/features/admin/orders/listing_spec.rb +0 -224
  51. data/spec/features/admin/orders/log_entries_spec.rb +0 -55
  52. data/spec/features/admin/orders/new_order_spec.rb +0 -186
  53. data/spec/features/admin/orders/order_details_spec.rb +0 -662
  54. data/spec/features/admin/orders/payments_spec.rb +0 -231
  55. data/spec/features/admin/orders/risk_analysis_spec.rb +0 -48
  56. data/spec/features/admin/orders/shipments_spec.rb +0 -64
  57. data/spec/features/admin/orders/state_changes_spec.rb +0 -21
  58. data/spec/features/admin/products/edit/images_spec.rb +0 -86
  59. data/spec/features/admin/products/edit/products_spec.rb +0 -64
  60. data/spec/features/admin/products/edit/taxons_spec.rb +0 -41
  61. data/spec/features/admin/products/edit/variants_spec.rb +0 -56
  62. data/spec/features/admin/products/option_types_spec.rb +0 -114
  63. data/spec/features/admin/products/products_spec.rb +0 -445
  64. data/spec/features/admin/products/properties_spec.rb +0 -147
  65. data/spec/features/admin/products/prototypes_spec.rb +0 -112
  66. data/spec/features/admin/products/stock_management_spec.rb +0 -124
  67. data/spec/features/admin/products/taxonomies_spec.rb +0 -52
  68. data/spec/features/admin/products/variant_spec.rb +0 -50
  69. data/spec/features/admin/promotions/adjustments_spec.rb +0 -258
  70. data/spec/features/admin/promotions/option_value_rule_spec.rb +0 -70
  71. data/spec/features/admin/promotions/tiered_calculator_spec.rb +0 -70
  72. data/spec/features/admin/refund_reasons/refund_reasons_spec.rb +0 -57
  73. data/spec/features/admin/reimbursement_type/edit_reimbursement_type_spec.rb +0 -36
  74. data/spec/features/admin/reimbursement_type/new_reimbursement_type_spec.rb +0 -62
  75. data/spec/features/admin/reports_spec.rb +0 -61
  76. data/spec/features/admin/return_authorization_reasons/return_authorization_reasons_spec.rb +0 -63
  77. data/spec/features/admin/returns/customer_returns_spec.rb +0 -80
  78. data/spec/features/admin/returns/return_authorizations_spec.rb +0 -152
  79. data/spec/features/admin/stock_transfer_spec.rb +0 -75
  80. data/spec/features/admin/store_credits_spec.rb +0 -93
  81. data/spec/features/admin/taxons_spec.rb +0 -47
  82. data/spec/features/admin/users_spec.rb +0 -286
  83. data/spec/helpers/admin/base_helper_spec.rb +0 -30
  84. data/spec/helpers/admin/navigation_helper_spec.rb +0 -111
  85. data/spec/helpers/admin/promotion_rules_helper_spec.rb +0 -12
  86. data/spec/helpers/admin/stock_movements_helper_spec.rb +0 -30
  87. data/spec/models/spree/resource_spec.rb +0 -48
  88. data/spec/routing/admin_path_spec.rb +0 -22
  89. data/spec/spec_helper.rb +0 -144
  90. data/spec/support/appear_before_matcher.rb +0 -8
  91. data/spec/support/ror_ringer.jpeg +0 -0
  92. data/spec/test_views/spree/admin/submodule/posts/edit.html.erb +0 -1
  93. data/spec/test_views/spree/admin/submodule/posts/new.html.erb +0 -1
  94. data/spec/test_views/spree/admin/widgets/edit.html.erb +0 -1
  95. data/spec/test_views/spree/admin/widgets/new.html.erb +0 -1
@@ -1,197 +0,0 @@
1
- require "spec_helper"
2
- require "cancan"
3
- require "spree/testing_support/bar_ability"
4
-
5
- describe Spree::Admin::Orders::CustomerDetailsController, type: :controller do
6
-
7
- context "with authorization" do
8
- stub_authorization!
9
-
10
- let(:order) do
11
- mock_model(
12
- Spree::Order,
13
- total: 100,
14
- number: "R123456789",
15
- billing_address: mock_model(Spree::Address)
16
- )
17
- end
18
-
19
- before do
20
- allow(Spree::Order).to receive_message_chain(:friendly, :find).and_return(order)
21
- end
22
-
23
- describe '#update' do
24
- let(:attributes) do
25
- {
26
- order_id: order.number,
27
- order: {
28
- email: "",
29
- use_billing: "",
30
- bill_address_attributes: { firstname: 'john' },
31
- ship_address_attributes: { firstname: 'john' }
32
- },
33
- guest_checkout: 'true'
34
- }
35
- end
36
-
37
- def send_request(params = {})
38
- spree_put :update, params
39
- end
40
-
41
- context 'using guest checkout' do
42
- context 'having valid parameters' do
43
- before do
44
- allow(order).to receive_messages(update_attributes: true)
45
- allow(order).to receive_messages(next: false)
46
- allow(order).to receive_messages(complete?: true)
47
- allow(order).to receive_messages(refresh_shipment_rates: true)
48
- end
49
-
50
- context 'having successful response' do
51
- before { send_request(attributes) }
52
- it { expect(response).to have_http_status(302) }
53
- it { expect(response).to redirect_to(edit_admin_order_url(order)) }
54
- end
55
-
56
- context 'with correct method flow' do
57
- it { expect(order).to receive(:update_attributes).with(ActionController::Parameters.new(attributes[:order]).permit(permitted_order_attributes)) }
58
- it { expect(order).to_not receive(:next) }
59
- it { expect(order).to receive(:complete?) }
60
- it 'does refresh the shipment rates with all shipping methods' do
61
- expect(order).to receive(:refresh_shipment_rates).
62
- with(Spree::ShippingMethod::DISPLAY_ON_FRONT_AND_BACK_END)
63
- end
64
- it { expect(controller).to receive(:load_order).and_call_original }
65
- it { expect(controller).to receive(:guest_checkout?).twice.and_call_original }
66
- it { expect(controller).to_not receive(:load_user).and_call_original }
67
- after { send_request(attributes) }
68
- end
69
- end
70
-
71
- context 'having invalid parameters' do
72
- before do
73
- allow(order).to receive_messages(update_attributes: false)
74
- end
75
-
76
- context 'having failure response' do
77
- before { send_request(attributes) }
78
- it { expect(response).to render_template(:edit) }
79
- end
80
-
81
- context 'with correct method flow' do
82
- it { expect(order).to receive(:update_attributes).with(ActionController::Parameters.new(attributes[:order]).permit(permitted_order_attributes)) }
83
- it { expect(controller).to receive(:load_order).and_call_original }
84
- it { expect(controller).to receive(:guest_checkout?).and_call_original }
85
- it { expect(controller).to_not receive(:load_user).and_call_original }
86
- after { send_request(attributes) }
87
- end
88
- end
89
- end
90
-
91
- context 'without using guest checkout' do
92
- let(:user) { mock_model(Spree.user_class) }
93
- let(:changed_attributes) { attributes.merge(guest_checkout: 'false', user_id: user.id) }
94
-
95
- context 'having valid parameters' do
96
- before do
97
- allow(Spree.user_class).to receive(:find_by).and_return(user)
98
- allow(order).to receive_messages(update_attributes: true)
99
- allow(order).to receive_messages(next: false)
100
- allow(order).to receive_messages(complete?: true)
101
- allow(order).to receive_messages(refresh_shipment_rates: true)
102
- allow(order).to receive_messages(associate_user!: true)
103
- allow(controller).to receive(:guest_checkout?).and_return(false)
104
- allow(order).to receive(:associate_user!)
105
- end
106
-
107
- context 'having successful response' do
108
- before { send_request(changed_attributes) }
109
- it { expect(response).to have_http_status(302) }
110
- it { expect(response).to redirect_to(edit_admin_order_url(order)) }
111
- end
112
-
113
- context 'with correct method flow' do
114
- it { expect(order).to receive(:update_attributes).with(ActionController::Parameters.new(attributes[:order]).permit(permitted_order_attributes)) }
115
- it { expect(order).to receive(:associate_user!).with(user, order.email.blank?) }
116
- it { expect(order).to_not receive(:next) }
117
- it { expect(order).to receive(:complete?) }
118
- it 'does refresh the shipment rates with all shipping methods' do
119
- expect(order).to receive(:refresh_shipment_rates).
120
- with(Spree::ShippingMethod::DISPLAY_ON_FRONT_AND_BACK_END)
121
- end
122
- it { expect(controller).to receive(:load_order).and_call_original }
123
- it { expect(controller).to receive(:guest_checkout?).twice.and_call_original }
124
- it { expect(controller).to receive(:load_user).and_call_original }
125
- after { send_request(changed_attributes) }
126
- end
127
- end
128
-
129
- context 'having invalid parameters' do
130
- before do
131
- allow(Spree.user_class).to receive(:find_by).and_return(false)
132
- allow(controller).to receive(:guest_checkout?).and_return(false)
133
- end
134
-
135
- context 'having failure response' do
136
- before { send_request(changed_attributes) }
137
- it { expect(response).to render_template(:edit) }
138
- end
139
-
140
- context 'with correct method flow' do
141
- it { expect(order).to_not receive(:update_attributes).with(ActionController::Parameters.new(attributes[:order]).permit(permitted_order_attributes)) }
142
- it { expect(controller).to receive(:load_order).and_call_original }
143
- it { expect(controller).to receive(:guest_checkout?).and_call_original }
144
- it { expect(controller).to receive(:load_user).and_call_original }
145
- after { send_request(changed_attributes) }
146
- end
147
- end
148
-
149
- describe '#load_user' do
150
- context 'having valid parameters' do
151
- before do
152
- allow(Spree.user_class).to receive(:find_by).and_return(user)
153
- allow(order).to receive_messages(update_attributes: true)
154
- allow(order).to receive_messages(next: false)
155
- allow(order).to receive_messages(complete?: true)
156
- allow(order).to receive_messages(refresh_shipment_rates: true)
157
- allow(order).to receive_messages(associate_user!: true)
158
- allow(controller).to receive(:guest_checkout?).and_return(false)
159
- allow(order).to receive(:associate_user!)
160
- end
161
-
162
- it "expects to assign user" do
163
- send_request(changed_attributes)
164
- expect(assigns[:user]).to eq(user)
165
- end
166
-
167
- context 'with correct method flow' do
168
- it { expect(Spree.user_class).to receive(:find_by).with(id: user.id.to_s).and_return(user) }
169
- after { send_request(changed_attributes) }
170
- end
171
- end
172
-
173
- context 'with invalid parameters' do
174
- before do
175
- allow(Spree.user_class).to receive(:find_by).and_return(nil)
176
- allow(controller).to receive(:guest_checkout?).and_return(false)
177
- end
178
-
179
- it "expects to not assign user" do
180
- send_request(changed_attributes)
181
- expect(assigns[:user]).to_not eq(user)
182
- end
183
-
184
- context 'with correct method flow' do
185
- it { expect(Spree.user_class).to receive(:find_by).with(id: user.id.to_s).and_return(nil) }
186
- it "expects user class to receive find_by with email" do
187
- expect(Spree.user_class).to receive(:find_by).
188
- with(email: changed_attributes[:order][:email]).and_return(nil)
189
- end
190
- after { send_request(changed_attributes) }
191
- end
192
- end
193
- end
194
- end
195
- end
196
- end
197
- end
@@ -1,296 +0,0 @@
1
- require 'spec_helper'
2
- require 'cancan'
3
- require 'spree/testing_support/bar_ability'
4
-
5
- # Ability to test access to specific model instances
6
- class OrderSpecificAbility
7
- include CanCan::Ability
8
-
9
- def initialize(user)
10
- can [:admin, :manage], Spree::Order, number: 'R987654321'
11
- end
12
- end
13
-
14
- describe Spree::Admin::OrdersController, type: :controller do
15
-
16
- context "with authorization" do
17
- stub_authorization!
18
-
19
- before do
20
- request.env["HTTP_REFERER"] = "http://localhost:3000"
21
-
22
- # ensure no respond_overrides are in effect
23
- if Spree::BaseController.spree_responders[:OrdersController].present?
24
- Spree::BaseController.spree_responders[:OrdersController].clear
25
- end
26
- end
27
-
28
- let(:order) do
29
- mock_model(
30
- Spree::Order,
31
- completed?: true,
32
- total: 100,
33
- number: 'R123456789',
34
- all_adjustments: adjustments,
35
- billing_address: mock_model(Spree::Address)
36
- )
37
- end
38
-
39
- let(:adjustments) { double('adjustments') }
40
-
41
- before do
42
- allow(Spree::Order).to receive_message_chain(:friendly, :find).and_return(order)
43
- end
44
-
45
- context "#approve" do
46
- it "approves an order" do
47
- expect(order).to receive(:approved_by).with(controller.try_spree_current_user)
48
- spree_put :approve, id: order.number
49
- expect(flash[:success]).to eq Spree.t(:order_approved)
50
- end
51
- end
52
-
53
- context "#cancel" do
54
- it "cancels an order" do
55
- expect(order).to receive(:canceled_by).with(controller.try_spree_current_user)
56
- spree_put :cancel, id: order.number
57
- expect(flash[:success]).to eq Spree.t(:order_canceled)
58
- end
59
- end
60
-
61
- context "#resume" do
62
- it "resumes an order" do
63
- expect(order).to receive(:resume!)
64
- spree_put :resume, id: order.number
65
- expect(flash[:success]).to eq Spree.t(:order_resumed)
66
- end
67
- end
68
-
69
- context "pagination" do
70
- it "can page through the orders" do
71
- spree_get :index, page: 2, per_page: 10
72
- expect(assigns[:orders].offset_value).to eq(10)
73
- expect(assigns[:orders].limit_value).to eq(10)
74
- end
75
- end
76
-
77
- # Test for #3346
78
- context "#new" do
79
- it "a new order has the current user assigned as a creator" do
80
- spree_get :new
81
- expect(assigns[:order].created_by).to eq(controller.try_spree_current_user)
82
- end
83
- end
84
-
85
- # Regression test for #3684
86
- describe "#edit" do
87
- let(:display_value) { Spree::ShippingMethod::DISPLAY_ON_FRONT_AND_BACK_END }
88
-
89
- before do
90
- allow(controller).to receive(:can_not_transition_without_customer_info)
91
- allow(order).to receive(:refresh_shipment_rates).with(display_value).and_return(true)
92
- end
93
-
94
- after do
95
- spree_get :edit, id: order.number
96
- end
97
-
98
- it { expect(controller).to receive(:can_not_transition_without_customer_info) }
99
- it { expect(order).to receive(:refresh_shipment_rates).with(display_value).and_return(true) }
100
- end
101
-
102
- # Test for #3919
103
- context "search" do
104
- let(:user) { create(:user) }
105
-
106
- before do
107
- allow(controller).to receive_messages spree_current_user: user
108
- user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
109
-
110
- create(:completed_order_with_totals)
111
- expect(Spree::Order.count).to eq 1
112
- end
113
-
114
- def send_request
115
- spree_get :index, q: {
116
- line_items_variant_id_in: Spree::Order.first.variants.map(&:id)
117
- }
118
- end
119
-
120
- it 'does not display duplicate results' do
121
- send_request
122
- expect(assigns[:orders].map { |o| o.number }.count).to eq 1
123
- end
124
-
125
- it 'preloads users' do
126
- expect(Spree::Order).to receive(:preload).with(:user).and_return(Spree::Order.all)
127
- send_request
128
- end
129
- end
130
-
131
- context "#open_adjustments" do
132
- let(:closed) { double('closed_adjustments') }
133
-
134
- before do
135
- allow(adjustments).to receive(:closed).and_return(closed)
136
- allow(closed).to receive(:update_all)
137
- end
138
-
139
- it "changes all the closed adjustments to open" do
140
- expect(adjustments).to receive(:closed).and_return(closed)
141
- expect(closed).to receive(:update_all).with(state: 'open')
142
- spree_post :open_adjustments, id: order.number
143
- end
144
-
145
- it "sets the flash success message" do
146
- spree_post :open_adjustments, id: order.number
147
- expect(flash[:success]).to eql('All adjustments successfully opened!')
148
- end
149
-
150
- context 'when referer' do
151
- before(:each) do
152
- request.env['HTTP_REFERER'] = root_url
153
- end
154
-
155
- it "redirects back" do
156
- spree_post :open_adjustments, id: order.number
157
- expect(response).to redirect_to(root_url)
158
- end
159
- end
160
-
161
- context 'when no referer' do
162
- before(:each) do
163
- request.env['HTTP_REFERER'] = nil
164
- end
165
-
166
- it 'refirects to fallback location' do
167
- spree_post :open_adjustments, id: order.number
168
- expect(response).to redirect_to(admin_order_adjustments_url(order))
169
- end
170
- end
171
- end
172
-
173
- context "#close_adjustments" do
174
- let(:open) { double('open_adjustments') }
175
-
176
- before do
177
- allow(adjustments).to receive(:open).and_return(open)
178
- allow(open).to receive(:update_all)
179
- end
180
-
181
- it "changes all the open adjustments to closed" do
182
- expect(adjustments).to receive(:open).and_return(open)
183
- expect(open).to receive(:update_all).with(state: 'closed')
184
- spree_post :close_adjustments, id: order.number
185
- end
186
-
187
- it "sets the flash success message" do
188
- spree_post :close_adjustments, id: order.number
189
- expect(flash[:success]).to eql('All adjustments successfully closed!')
190
- end
191
-
192
- context 'when referer' do
193
- before(:each) do
194
- request.env['HTTP_REFERER'] = root_url
195
- end
196
-
197
- it "redirects back" do
198
- spree_post :close_adjustments, id: order.number
199
- expect(response).to redirect_to(root_url)
200
- end
201
- end
202
-
203
- context 'when no referer' do
204
- before(:each) do
205
- request.env['HTTP_REFERER'] = nil
206
- end
207
-
208
- it 'refirects to fallback location' do
209
- spree_post :close_adjustments, id: order.number
210
- expect(response).to redirect_to(admin_order_adjustments_url(order))
211
- end
212
- end
213
- end
214
- end
215
-
216
- context '#authorize_admin' do
217
- let(:user) { create(:user) }
218
- let(:order) { create(:completed_order_with_totals, number: 'R987654321') }
219
-
220
- def with_ability(ability)
221
- Spree::Ability.register_ability(ability)
222
- yield
223
- ensure
224
- Spree::Ability.remove_ability(ability)
225
- end
226
-
227
- before do
228
- allow(Spree::Order).to receive_messages find: order
229
- allow(controller).to receive_messages spree_current_user: user
230
- end
231
-
232
- it 'should grant access to users with an admin role' do
233
- user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
234
- spree_post :index
235
- expect(response).to render_template :index
236
- end
237
-
238
- it 'should grant access to users with an bar role' do
239
- with_ability(BarAbility) do
240
- user.spree_roles << Spree::Role.find_or_create_by(name: 'bar')
241
- spree_post :index
242
- expect(response).to render_template :index
243
- end
244
- end
245
-
246
- it 'should deny access to users with an bar role' do
247
- with_ability(BarAbility) do
248
- allow(order).to receive(:update_attributes).and_return true
249
- allow(order).to receive(:user).and_return Spree.user_class.new
250
- allow(order).to receive(:token).and_return nil
251
- user.spree_roles.clear
252
- user.spree_roles << Spree::Role.find_or_create_by(name: 'bar')
253
- spree_put :update, id: order.number
254
- expect(response).to redirect_to(spree.forbidden_path)
255
- end
256
- end
257
-
258
- it 'should deny access to users without an admin role' do
259
- allow(user).to receive_messages has_spree_role?: false
260
- spree_post :index
261
- expect(response).to redirect_to(spree.forbidden_path)
262
- end
263
-
264
- it 'should deny access to not signed in users' do
265
- allow(controller).to receive_messages spree_current_user: nil
266
- spree_get :index
267
- expect(response).to redirect_to(spree.root_path)
268
- end
269
-
270
- it 'should restrict returned order(s) on index when using OrderSpecificAbility' do
271
- number = order.number
272
-
273
- 3.times { create(:completed_order_with_totals) }
274
- expect(Spree::Order.complete.count).to eq 4
275
-
276
- with_ability(OrderSpecificAbility) do
277
- allow(user).to receive_messages has_spree_role?: false
278
- spree_get :index
279
- expect(response).to render_template :index
280
- expect(assigns['orders'].size).to eq 1
281
- expect(assigns['orders'].first.number).to eq number
282
- expect(Spree::Order.accessible_by(Spree::Ability.new(user), :index).pluck(:number)).to eq [number]
283
- end
284
- end
285
- end
286
-
287
- context "order number not given" do
288
- stub_authorization!
289
-
290
- it "raise active record not found" do
291
- expect {
292
- spree_get :edit, id: 99999999
293
- }.to raise_error ActiveRecord::RecordNotFound
294
- end
295
- end
296
- end
@@ -1,64 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- class GatewayWithPassword < PaymentMethod
5
- preference :password, :string, default: "password"
6
- end
7
-
8
- describe Admin::PaymentMethodsController, type: :controller do
9
- stub_authorization!
10
-
11
- let(:payment_method) { GatewayWithPassword.create!(name: "Bogus", preferred_password: "haxme") }
12
-
13
- # regression test for #2094
14
- it "does not clear password on update" do
15
- expect(payment_method.preferred_password).to eq("haxme")
16
- spree_put :update, id: payment_method.id, payment_method: { type: payment_method.class.to_s, preferred_password: "" }
17
- expect(response).to redirect_to(spree.edit_admin_payment_method_path(payment_method))
18
-
19
- payment_method.reload
20
- expect(payment_method.preferred_password).to eq("haxme")
21
- end
22
-
23
- it 'saves payment method preferences on update' do
24
- spree_put :update,
25
- id: payment_method.id,
26
- payment_method: {
27
- type: payment_method.class.to_s,
28
- name: 'Bogus'
29
- },
30
- gateway_with_password: {
31
- preferred_password: "abc"
32
- }
33
-
34
- payment_method.reload
35
- expect(payment_method.preferred_password).to eq("abc")
36
- end
37
-
38
- context "tries to save invalid payment" do
39
- it "doesn't break, responds nicely" do
40
- expect {
41
- spree_post :create, payment_method: { name: "", type: "Spree::Gateway::Bogus" }
42
- }.not_to raise_error
43
- end
44
- end
45
-
46
- it "can create a payment method of a valid type" do
47
- expect {
48
- spree_post :create, payment_method: { name: "Test Method", type: "Spree::Gateway::Bogus" }
49
- }.to change(Spree::PaymentMethod, :count).by(1)
50
-
51
- expect(response).to be_redirect
52
- expect(response).to redirect_to spree.edit_admin_payment_method_path(assigns(:payment_method))
53
- end
54
-
55
- it "can not create a payment method of an invalid type" do
56
- expect {
57
- spree_post :create, payment_method: { name: "Invalid Payment Method", type: "Spree::InvalidType" }
58
- }.to change(Spree::PaymentMethod, :count).by(0)
59
-
60
- expect(response).to be_redirect
61
- expect(response).to redirect_to spree.new_admin_payment_method_path
62
- end
63
- end
64
- end
@@ -1,97 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- module Admin
5
- describe PaymentsController, type: :controller do
6
- stub_authorization!
7
-
8
- let(:order) { create(:order) }
9
-
10
- context "with a valid credit card" do
11
- let(:order) { create(:order_with_line_items, state: "payment") }
12
- let(:payment_method) { create(:credit_card_payment_method, display_on: "back_end") }
13
-
14
- before do
15
- attributes = {
16
- order_id: order.number,
17
- card: "new",
18
- payment: {
19
- amount: order.total,
20
- payment_method_id: payment_method.id.to_s,
21
- source_attributes: {
22
- name: "Test User",
23
- number: "4111 1111 1111 1111",
24
- expiry: "09 / #{Time.current.year + 1}",
25
- verification_value: "123"
26
- }
27
- }
28
- }
29
- spree_post :create, attributes
30
- end
31
-
32
- it "should process payment correctly" do
33
- expect(order.payments.count).to eq(1)
34
- expect(response).to redirect_to(spree.admin_order_payments_path(order))
35
- expect(order.reload.state).to eq('complete')
36
- end
37
-
38
- # Regression for #4768
39
- it "doesnt process the same payment twice" do
40
- expect(Spree::LogEntry.where(source: order.payments.first).count).to eq(1)
41
- end
42
- end
43
-
44
- # Regression test for #3233
45
- context "with a backend payment method" do
46
- before do
47
- @payment_method = create(:check_payment_method, display_on: "back_end")
48
- end
49
-
50
- it "loads backend payment methods" do
51
- spree_get :new, order_id: order.number
52
- expect(response.status).to eq(200)
53
- expect(assigns[:payment_methods]).to include(@payment_method)
54
- end
55
- end
56
-
57
- context "order has billing address" do
58
- before do
59
- order.bill_address = create(:address)
60
- order.save!
61
- end
62
-
63
- context "order does not have payments" do
64
- it "redirect to new payments page" do
65
- spree_get :index, { amount: 100, order_id: order.number }
66
- expect(response).to redirect_to(spree.new_admin_order_payment_path(order))
67
- end
68
- end
69
-
70
- context "order has payments" do
71
- before do
72
- order.payments << create(:payment, amount: order.total, order: order, state: 'completed')
73
- end
74
-
75
- it "shows the payments page" do
76
- spree_get :index, { amount: 100, order_id: order.number }
77
- expect(response.code).to eq "200"
78
- end
79
- end
80
-
81
- end
82
-
83
- context "order does not have a billing address" do
84
- before do
85
- order.bill_address = nil
86
- order.save
87
- end
88
-
89
- it "should redirect to the customer details page" do
90
- spree_get :index, { amount: 100, order_id: order.number }
91
- expect(response).to redirect_to(spree.edit_admin_order_customer_path(order))
92
- end
93
- end
94
-
95
- end
96
- end
97
- end