spree_backend 3.3.0.rc1 → 3.3.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/spree/backend/general_settings.js.coffee +12 -10
- data/app/controllers/spree/admin/orders_controller.rb +3 -4
- data/app/controllers/spree/admin/payments_controller.rb +2 -2
- data/app/controllers/spree/admin/products_controller.rb +3 -3
- data/app/controllers/spree/admin/return_authorizations_controller.rb +1 -1
- data/app/helpers/spree/admin/base_helper.rb +4 -1
- data/app/helpers/spree/admin/navigation_helper.rb +1 -1
- data/app/views/spree/admin/products/_form.html.erb +8 -8
- data/app/views/spree/admin/promotions/actions/_create_line_items.html.erb +4 -2
- data/app/views/spree/admin/shared/_translations.html.erb +1 -0
- data/spree_backend.gemspec +1 -1
- metadata +7 -98
- data/spec/controllers/spree/admin/base_controller_spec.rb +0 -46
- data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +0 -185
- data/spec/controllers/spree/admin/general_settings_controller_spec.rb +0 -41
- data/spec/controllers/spree/admin/missing_products_controller_spec.rb +0 -18
- data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +0 -199
- data/spec/controllers/spree/admin/orders_controller_spec.rb +0 -296
- data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +0 -64
- data/spec/controllers/spree/admin/payments_controller_spec.rb +0 -97
- data/spec/controllers/spree/admin/products_controller_spec.rb +0 -137
- data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +0 -21
- data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +0 -21
- data/spec/controllers/spree/admin/promotions_controller_spec.rb +0 -44
- data/spec/controllers/spree/admin/refunds_controller_spec.rb +0 -32
- data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +0 -74
- data/spec/controllers/spree/admin/reports_controller_spec.rb +0 -42
- data/spec/controllers/spree/admin/resource_controller_spec.rb +0 -252
- data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +0 -225
- data/spec/controllers/spree/admin/return_index_controller_spec.rb +0 -37
- data/spec/controllers/spree/admin/return_items_controller_spec.rb +0 -27
- data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +0 -14
- data/spec/controllers/spree/admin/stock_items_controller_spec.rb +0 -19
- data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +0 -41
- data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +0 -41
- data/spec/controllers/spree/admin/tax_categories_controller_spec.rb +0 -34
- data/spec/controllers/spree/admin/users_controller_spec.rb +0 -161
- data/spec/controllers/spree/admin/variants_controller_spec.rb +0 -32
- data/spec/features/admin/configuration/analytics_tracker_spec.rb +0 -47
- data/spec/features/admin/configuration/countries_spec.rb +0 -24
- data/spec/features/admin/configuration/general_settings_spec.rb +0 -44
- data/spec/features/admin/configuration/payment_methods_spec.rb +0 -63
- data/spec/features/admin/configuration/roles_spec.rb +0 -47
- data/spec/features/admin/configuration/shipping_methods_spec.rb +0 -62
- data/spec/features/admin/configuration/states_spec.rb +0 -68
- data/spec/features/admin/configuration/stock_locations_spec.rb +0 -48
- data/spec/features/admin/configuration/store_credit_categories_spec.rb +0 -50
- data/spec/features/admin/configuration/tax_categories_spec.rb +0 -56
- data/spec/features/admin/configuration/tax_rates_spec.rb +0 -18
- data/spec/features/admin/configuration/zones_spec.rb +0 -39
- data/spec/features/admin/homepage_spec.rb +0 -89
- data/spec/features/admin/locale_spec.rb +0 -31
- data/spec/features/admin/orders/adjustments_promotions_spec.rb +0 -53
- data/spec/features/admin/orders/adjustments_spec.rb +0 -124
- data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +0 -47
- data/spec/features/admin/orders/customer_details_spec.rb +0 -154
- data/spec/features/admin/orders/line_items_spec.rb +0 -51
- data/spec/features/admin/orders/listing_spec.rb +0 -224
- data/spec/features/admin/orders/log_entries_spec.rb +0 -55
- data/spec/features/admin/orders/new_order_spec.rb +0 -186
- data/spec/features/admin/orders/order_details_spec.rb +0 -660
- data/spec/features/admin/orders/payments_spec.rb +0 -244
- data/spec/features/admin/orders/risk_analysis_spec.rb +0 -48
- data/spec/features/admin/orders/shipments_spec.rb +0 -64
- data/spec/features/admin/orders/state_changes_spec.rb +0 -21
- data/spec/features/admin/products/edit/images_spec.rb +0 -86
- data/spec/features/admin/products/edit/products_spec.rb +0 -56
- data/spec/features/admin/products/edit/taxons_spec.rb +0 -41
- data/spec/features/admin/products/edit/variants_spec.rb +0 -56
- data/spec/features/admin/products/option_types_spec.rb +0 -114
- data/spec/features/admin/products/products_spec.rb +0 -445
- data/spec/features/admin/products/properties_spec.rb +0 -147
- data/spec/features/admin/products/prototypes_spec.rb +0 -112
- data/spec/features/admin/products/stock_management_spec.rb +0 -124
- data/spec/features/admin/products/taxonomies_spec.rb +0 -52
- data/spec/features/admin/products/variant_spec.rb +0 -50
- data/spec/features/admin/promotions/adjustments_spec.rb +0 -258
- data/spec/features/admin/promotions/option_value_rule_spec.rb +0 -70
- data/spec/features/admin/promotions/tiered_calculator_spec.rb +0 -70
- data/spec/features/admin/refund_reasons/refund_reasons_spec.rb +0 -57
- data/spec/features/admin/reimbursement_type/edit_reimbursement_type_spec.rb +0 -36
- data/spec/features/admin/reimbursement_type/new_reimbursement_type_spec.rb +0 -62
- data/spec/features/admin/reports_spec.rb +0 -61
- data/spec/features/admin/return_authorization_reasons/return_authorization_reasons_spec.rb +0 -63
- data/spec/features/admin/returns/customer_returns_spec.rb +0 -80
- data/spec/features/admin/returns/return_authorizations_spec.rb +0 -152
- data/spec/features/admin/stock_transfer_spec.rb +0 -91
- data/spec/features/admin/store_credits_spec.rb +0 -93
- data/spec/features/admin/taxons_spec.rb +0 -53
- data/spec/features/admin/users_spec.rb +0 -286
- data/spec/helpers/admin/base_helper_spec.rb +0 -30
- data/spec/helpers/admin/navigation_helper_spec.rb +0 -111
- data/spec/helpers/admin/promotion_rules_helper_spec.rb +0 -12
- data/spec/helpers/admin/stock_movements_helper_spec.rb +0 -30
- data/spec/models/spree/resource_spec.rb +0 -48
- data/spec/routing/admin_path_spec.rb +0 -22
- data/spec/spec_helper.rb +0 -144
- data/spec/support/appear_before_matcher.rb +0 -8
- data/spec/support/ror_ringer.jpeg +0 -0
- data/spec/test_views/spree/admin/submodule/posts/edit.html.erb +0 -1
- data/spec/test_views/spree/admin/submodule/posts/new.html.erb +0 -1
- data/spec/test_views/spree/admin/widgets/edit.html.erb +0 -1
- data/spec/test_views/spree/admin/widgets/new.html.erb +0 -1
@@ -1,199 +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(:user) { mock_model(Spree.user_class) }
|
11
|
-
|
12
|
-
let(:order) do
|
13
|
-
mock_model(
|
14
|
-
Spree::Order,
|
15
|
-
total: 100,
|
16
|
-
number: "R123456789",
|
17
|
-
billing_address: mock_model(Spree::Address)
|
18
|
-
)
|
19
|
-
end
|
20
|
-
|
21
|
-
before do
|
22
|
-
allow(Spree::Order).to receive_message_chain(:includes, find_by!: order)
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '#update' do
|
26
|
-
let(:attributes) do
|
27
|
-
{
|
28
|
-
order_id: order.number,
|
29
|
-
order: {
|
30
|
-
email: "",
|
31
|
-
use_billing: "",
|
32
|
-
bill_address_attributes: { firstname: 'john' },
|
33
|
-
ship_address_attributes: { firstname: 'john' },
|
34
|
-
user_id: user.id.to_s
|
35
|
-
},
|
36
|
-
guest_checkout: 'true'
|
37
|
-
}
|
38
|
-
end
|
39
|
-
|
40
|
-
def send_request(params = {})
|
41
|
-
spree_put :update, params
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'using guest checkout' do
|
45
|
-
context 'having valid parameters' do
|
46
|
-
before do
|
47
|
-
allow(order).to receive_messages(update_attributes: true)
|
48
|
-
allow(order).to receive_messages(next: false)
|
49
|
-
allow(order).to receive_messages(address?: false)
|
50
|
-
allow(order).to receive_messages(refresh_shipment_rates: true)
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'having successful response' do
|
54
|
-
before { send_request(attributes) }
|
55
|
-
it { expect(response).to have_http_status(302) }
|
56
|
-
it { expect(response).to redirect_to(edit_admin_order_url(order)) }
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'with correct method flow' do
|
60
|
-
it { expect(order).to receive(:update_attributes).with(ActionController::Parameters.new(attributes[:order]).permit(permitted_order_attributes)) }
|
61
|
-
it { expect(order).to_not receive(:next) }
|
62
|
-
it { expect(order).to receive(:address?) }
|
63
|
-
it 'does refresh the shipment rates with all shipping methods' do
|
64
|
-
expect(order).to receive(:refresh_shipment_rates).
|
65
|
-
with(Spree::ShippingMethod::DISPLAY_ON_BACK_END)
|
66
|
-
end
|
67
|
-
it { expect(controller).to receive(:load_order).and_call_original }
|
68
|
-
it { expect(controller).to receive(:guest_checkout?).twice.and_call_original }
|
69
|
-
it { expect(controller).to_not receive(:load_user).and_call_original }
|
70
|
-
after { send_request(attributes) }
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'having invalid parameters' do
|
75
|
-
before do
|
76
|
-
allow(order).to receive_messages(update_attributes: false)
|
77
|
-
end
|
78
|
-
|
79
|
-
context 'having failure response' do
|
80
|
-
before { send_request(attributes) }
|
81
|
-
it { expect(response).to render_template(:edit) }
|
82
|
-
end
|
83
|
-
|
84
|
-
context 'with correct method flow' do
|
85
|
-
it { expect(order).to receive(:update_attributes).with(ActionController::Parameters.new(attributes[:order]).permit(permitted_order_attributes)) }
|
86
|
-
it { expect(controller).to receive(:load_order).and_call_original }
|
87
|
-
it { expect(controller).to receive(:guest_checkout?).and_call_original }
|
88
|
-
it { expect(controller).to_not receive(:load_user).and_call_original }
|
89
|
-
after { send_request(attributes) }
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context 'without using guest checkout' do
|
95
|
-
let(:changed_attributes) { attributes.merge(guest_checkout: 'false') }
|
96
|
-
|
97
|
-
context 'having valid parameters' do
|
98
|
-
before do
|
99
|
-
allow(Spree.user_class).to receive(:find_by).and_return(user)
|
100
|
-
allow(order).to receive_messages(update_attributes: true)
|
101
|
-
allow(order).to receive_messages(next: false)
|
102
|
-
allow(order).to receive_messages(address?: false)
|
103
|
-
allow(order).to receive_messages(refresh_shipment_rates: true)
|
104
|
-
allow(order).to receive_messages(associate_user!: true)
|
105
|
-
allow(controller).to receive(:guest_checkout?).and_return(false)
|
106
|
-
allow(order).to receive(:associate_user!)
|
107
|
-
end
|
108
|
-
|
109
|
-
context 'having successful response' do
|
110
|
-
before { send_request(changed_attributes) }
|
111
|
-
it { expect(response).to have_http_status(302) }
|
112
|
-
it { expect(response).to redirect_to(edit_admin_order_url(order)) }
|
113
|
-
end
|
114
|
-
|
115
|
-
context 'with correct method flow' do
|
116
|
-
it { expect(order).to receive(:update_attributes).with(ActionController::Parameters.new(attributes[:order]).permit(permitted_order_attributes)) }
|
117
|
-
it { expect(order).to receive(:associate_user!).with(user, order.email.blank?) }
|
118
|
-
it { expect(order).to_not receive(:next) }
|
119
|
-
it { expect(order).to receive(:address?) }
|
120
|
-
it 'does refresh the shipment rates with all shipping methods' do
|
121
|
-
expect(order).to receive(:refresh_shipment_rates).
|
122
|
-
with(Spree::ShippingMethod::DISPLAY_ON_BACK_END)
|
123
|
-
end
|
124
|
-
it { expect(controller).to receive(:load_order).and_call_original }
|
125
|
-
it { expect(controller).to receive(:guest_checkout?).twice.and_call_original }
|
126
|
-
it { expect(controller).to receive(:load_user).and_call_original }
|
127
|
-
after { send_request(changed_attributes) }
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
context 'having invalid parameters' do
|
132
|
-
before do
|
133
|
-
allow(Spree.user_class).to receive(:find_by).and_return(false)
|
134
|
-
allow(controller).to receive(:guest_checkout?).and_return(false)
|
135
|
-
end
|
136
|
-
|
137
|
-
context 'having failure response' do
|
138
|
-
before { send_request(changed_attributes) }
|
139
|
-
it { expect(response).to render_template(:edit) }
|
140
|
-
end
|
141
|
-
|
142
|
-
context 'with correct method flow' do
|
143
|
-
it { expect(order).to_not receive(:update_attributes).with(ActionController::Parameters.new(attributes[:order]).permit(permitted_order_attributes)) }
|
144
|
-
it { expect(controller).to receive(:load_order).and_call_original }
|
145
|
-
it { expect(controller).to receive(:guest_checkout?).and_call_original }
|
146
|
-
it { expect(controller).to receive(:load_user).and_call_original }
|
147
|
-
after { send_request(changed_attributes) }
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe '#load_user' do
|
152
|
-
context 'having valid parameters' do
|
153
|
-
before do
|
154
|
-
allow(Spree.user_class).to receive(:find_by).and_return(user)
|
155
|
-
allow(order).to receive_messages(update_attributes: true)
|
156
|
-
allow(order).to receive_messages(next: false)
|
157
|
-
allow(order).to receive_messages(address?: false)
|
158
|
-
allow(order).to receive_messages(refresh_shipment_rates: true)
|
159
|
-
allow(order).to receive_messages(associate_user!: true)
|
160
|
-
allow(controller).to receive(:guest_checkout?).and_return(false)
|
161
|
-
allow(order).to receive(:associate_user!)
|
162
|
-
end
|
163
|
-
|
164
|
-
it "expects to assign user" do
|
165
|
-
send_request(changed_attributes)
|
166
|
-
expect(assigns[:user]).to eq(user)
|
167
|
-
end
|
168
|
-
|
169
|
-
context 'with correct method flow' do
|
170
|
-
it { expect(Spree.user_class).to receive(:find_by).with(id: user.id.to_s).and_return(user) }
|
171
|
-
after { send_request(changed_attributes) }
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
context 'with invalid parameters' do
|
176
|
-
before do
|
177
|
-
allow(Spree.user_class).to receive(:find_by).and_return(nil)
|
178
|
-
allow(controller).to receive(:guest_checkout?).and_return(false)
|
179
|
-
end
|
180
|
-
|
181
|
-
it "expects to not assign user" do
|
182
|
-
send_request(changed_attributes)
|
183
|
-
expect(assigns[:user]).to_not eq(user)
|
184
|
-
end
|
185
|
-
|
186
|
-
context 'with correct method flow' do
|
187
|
-
it { expect(Spree.user_class).to receive(:find_by).with(id: user.id.to_s).and_return(nil) }
|
188
|
-
it "expects user class to receive find_by with email" do
|
189
|
-
expect(Spree.user_class).to receive(:find_by).
|
190
|
-
with(email: changed_attributes[:order][:email]).and_return(nil)
|
191
|
-
end
|
192
|
-
after { send_request(changed_attributes) }
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
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(:includes, find_by!: 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_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'].distinct(false).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
|