solidus_backend 1.0.7 → 1.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_backend might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/assets/javascripts/spree/backend.js +3 -0
- data/app/assets/javascripts/spree/backend/admin.js.erb +17 -24
- data/app/assets/javascripts/spree/backend/checkouts/edit.js +3 -5
- data/app/assets/javascripts/spree/backend/flash.coffee +17 -0
- data/app/assets/javascripts/spree/backend/handlebars_extensions.coffee +9 -0
- data/app/assets/javascripts/spree/backend/option_type_autocomplete.js.erb +6 -6
- data/app/assets/javascripts/spree/backend/option_value_picker.js +43 -0
- data/app/assets/javascripts/spree/backend/product_picker.js +10 -8
- data/app/assets/javascripts/spree/backend/promotions.js.coffee +101 -0
- data/app/assets/javascripts/spree/backend/routes.js +2 -1
- data/app/assets/javascripts/spree/backend/shipments.js.erb +1 -1
- data/app/assets/javascripts/spree/backend/stock_management/index_add_forms.coffee +1 -1
- data/app/assets/javascripts/spree/backend/stock_movement.js.coffee +2 -2
- data/app/assets/javascripts/spree/backend/stock_transfers/variant_form.coffee +1 -1
- data/app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb +6 -6
- data/app/assets/javascripts/spree/backend/taxons.js.coffee +6 -7
- data/app/assets/javascripts/spree/backend/templates/orders/customer_details/autocomplete.hbs +17 -0
- data/app/assets/javascripts/spree/backend/templates/products/sortable.hbs +5 -0
- data/app/assets/javascripts/spree/backend/templates/promotions/calculators/fields/tiered_flat_rate.hbs +17 -0
- data/app/assets/javascripts/spree/backend/templates/promotions/calculators/fields/tiered_percent.hbs +17 -0
- data/app/assets/javascripts/spree/backend/templates/promotions/rules/option_values.hbs +10 -0
- data/app/assets/javascripts/spree/backend/templates/promotions/rules/option_values_select.hbs +1 -0
- data/app/assets/javascripts/spree/backend/templates/stock_items/stock_location_stock_item.hbs +19 -0
- data/app/assets/javascripts/spree/backend/templates/stock_transfers/transfer_item.hbs.erb +52 -0
- data/app/assets/javascripts/spree/backend/templates/variants/autocomplete.hbs.erb +23 -0
- data/app/assets/javascripts/spree/backend/templates/variants/autocomplete_stock.hbs +51 -0
- data/app/assets/javascripts/spree/backend/templates/variants/line_items_autocomplete_stock.hbs +67 -0
- data/app/assets/javascripts/spree/backend/templates/variants/split.hbs +27 -0
- data/app/assets/javascripts/spree/backend/user_picker.js +8 -8
- data/app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee.erb +6 -8
- data/app/assets/stylesheets/spree/backend/components/_messages.scss +6 -3
- data/app/assets/stylesheets/spree/backend/sections/_promotions.scss +16 -0
- data/app/controllers/spree/admin/base_controller.rb +1 -1
- data/app/controllers/spree/admin/option_types_controller.rb +1 -3
- data/app/controllers/spree/admin/orders/customer_details_controller.rb +1 -1
- data/app/controllers/spree/admin/orders_controller.rb +6 -11
- data/app/controllers/spree/admin/product_properties_controller.rb +9 -0
- data/app/controllers/spree/admin/products_controller.rb +20 -5
- data/app/controllers/spree/admin/promotions_controller.rb +2 -1
- data/app/controllers/spree/admin/reimbursements_controller.rb +20 -0
- data/app/controllers/spree/admin/resource_controller.rb +1 -1
- data/app/controllers/spree/admin/return_authorizations_controller.rb +5 -0
- data/app/controllers/spree/admin/root_controller.rb +1 -1
- data/app/controllers/spree/admin/search_controller.rb +2 -4
- data/app/controllers/spree/admin/states_controller.rb +1 -1
- data/app/controllers/spree/admin/stock_items_controller.rb +1 -1
- data/app/controllers/spree/admin/stock_transfers_controller.rb +3 -14
- data/app/controllers/spree/admin/users_controller.rb +2 -3
- data/app/controllers/spree/admin/variant_property_rule_values_controller.rb +7 -0
- data/app/controllers/spree/admin/variants_controller.rb +1 -1
- data/app/controllers/spree/admin/zones_controller.rb +1 -1
- data/app/helpers/spree/admin/adjustments_helper.rb +4 -9
- data/app/helpers/spree/admin/base_helper.rb +7 -6
- data/app/helpers/spree/admin/navigation_helper.rb +8 -2
- data/app/helpers/spree/admin/orders_helper.rb +1 -1
- data/app/helpers/spree/admin/products_helper.rb +2 -4
- data/app/helpers/spree/admin/stock_movements_helper.rb +3 -3
- data/app/views/spree/admin/adjustments/_adjustment.html.erb +1 -1
- data/app/views/spree/admin/orders/_add_line_item.html.erb +0 -5
- data/app/views/spree/admin/orders/_add_product.html.erb +0 -3
- data/app/views/spree/admin/orders/_carton.html.erb +0 -1
- data/app/views/spree/admin/orders/_shipment.html.erb +0 -1
- data/app/views/spree/admin/orders/confirm/_shipment.html.erb +0 -1
- data/app/views/spree/admin/orders/customer_details/_form.html.erb +1 -1
- data/app/views/spree/admin/orders/customer_details/edit.html.erb +0 -1
- data/app/views/spree/admin/orders/index.html.erb +1 -2
- data/app/views/spree/admin/payment_methods/_form.html.erb +0 -4
- data/app/views/spree/admin/payment_methods/index.html.erb +0 -2
- data/app/views/spree/admin/payments/source_views/_gateway.html.erb +3 -0
- data/app/views/spree/admin/product_properties/index.html.erb +52 -2
- data/app/views/spree/admin/promotions/_actions.html.erb +14 -10
- data/app/views/spree/admin/promotions/_promotion_action.html.erb +5 -3
- data/app/views/spree/admin/promotions/_promotion_rule.html.erb +5 -3
- data/app/views/spree/admin/promotions/_rules.html.erb +18 -14
- data/app/views/spree/admin/promotions/calculators/tiered_flat_rate/_fields.html.erb +5 -28
- data/app/views/spree/admin/promotions/calculators/tiered_percent/_fields.html.erb +5 -27
- data/app/views/spree/admin/promotions/edit.html.erb +6 -4
- data/app/views/spree/admin/promotions/index.html.erb +1 -1
- data/app/views/spree/admin/promotions/rules/_option_value.html.erb +13 -0
- data/app/views/spree/admin/refund_reasons/index.html.erb +2 -2
- data/app/views/spree/admin/reimbursements/edit.html.erb +1 -1
- data/app/views/spree/admin/return_authorizations/_form.html.erb +2 -2
- data/app/views/spree/admin/search/users.rabl +1 -1
- data/app/views/spree/admin/shared/_order_summary.html.erb +6 -0
- data/app/views/spree/admin/shared/_tabs.html.erb +2 -2
- data/app/views/spree/admin/shared/_translations.html.erb +16 -46
- data/app/views/spree/admin/shared/named_types/_index.html.erb +2 -2
- data/app/views/spree/admin/stock_items/_stock_management.html.erb +0 -2
- data/app/views/spree/admin/stock_movements/_form.html.erb +0 -2
- data/app/views/spree/admin/stock_transfers/edit.html.erb +0 -3
- data/app/views/spree/admin/stock_transfers/receive.html.erb +0 -2
- data/app/views/spree/admin/stock_transfers/show.html.erb +1 -1
- data/app/views/spree/admin/taxons/index.html.erb +0 -1
- data/app/views/spree/admin/users/_addresses_form.html.erb +4 -4
- data/app/views/spree/layouts/admin.html.erb +11 -9
- data/config/routes.rb +5 -0
- data/lib/spree/backend.rb +1 -2
- metadata +41 -139
- data/CHANGELOG.md +0 -1
- data/Gemfile +0 -6
- data/Rakefile +0 -15
- data/app/assets/javascripts/spree/backend/handlebar_extensions.js +0 -9
- data/app/assets/javascripts/spree/backend/promotions.js +0 -73
- data/app/assets/javascripts/spree/backend/stock_transfer.js.coffee +0 -196
- data/app/views/spree/admin/products/_autocomplete.js.erb +0 -14
- data/app/views/spree/admin/products/_sortable.html +0 -7
- data/app/views/spree/admin/stock_items/_stock_location_stock_item_template.html.erb +0 -21
- data/app/views/spree/admin/stock_transfers/_transfer_item_template.html.erb +0 -54
- data/app/views/spree/admin/variants/_autocomplete.js.erb +0 -25
- data/app/views/spree/admin/variants/_autocomplete_line_items_stock.js.erb +0 -69
- data/app/views/spree/admin/variants/_autocomplete_stock.js.erb +0 -53
- data/app/views/spree/admin/variants/_split.js.erb +0 -29
- data/script/rails +0 -9
- data/solidus_backend.gemspec +0 -30
- data/spec/controllers/spree/admin/base_controller_spec.rb +0 -24
- data/spec/controllers/spree/admin/cancellations_controller_spec.rb +0 -77
- data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +0 -234
- 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 -80
- data/spec/controllers/spree/admin/orders_controller_spec.rb +0 -472
- data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +0 -49
- data/spec/controllers/spree/admin/payments_controller_spec.rb +0 -175
- data/spec/controllers/spree/admin/products_controller_spec.rb +0 -45
- data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +0 -21
- data/spec/controllers/spree/admin/promotion_codes_controller_spec.rb +0 -18
- data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +0 -21
- data/spec/controllers/spree/admin/promotions_controller_spec.rb +0 -122
- data/spec/controllers/spree/admin/refunds_controller_spec.rb +0 -32
- data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +0 -75
- data/spec/controllers/spree/admin/reports_controller_spec.rb +0 -134
- data/spec/controllers/spree/admin/resource_controller_spec.rb +0 -166
- data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +0 -226
- data/spec/controllers/spree/admin/return_items_controller_spec.rb +0 -27
- data/spec/controllers/spree/admin/root_controller_spec.rb +0 -41
- data/spec/controllers/spree/admin/search_controller_spec.rb +0 -104
- data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +0 -14
- data/spec/controllers/spree/admin/stock_items_controller_spec.rb +0 -50
- data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +0 -41
- data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +0 -331
- data/spec/controllers/spree/admin/store_credits_controller_spec.rb +0 -309
- data/spec/controllers/spree/admin/users_controller_spec.rb +0 -236
- data/spec/controllers/spree/admin/variants_controller_spec.rb +0 -32
- data/spec/features/admin/configuration/analytics_tracker_spec.rb +0 -54
- data/spec/features/admin/configuration/countries_spec.rb +0 -22
- data/spec/features/admin/configuration/general_settings_spec.rb +0 -45
- data/spec/features/admin/configuration/payment_methods_spec.rb +0 -125
- data/spec/features/admin/configuration/shipping_methods_spec.rb +0 -64
- data/spec/features/admin/configuration/states_spec.rb +0 -64
- data/spec/features/admin/configuration/stock_locations_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 -30
- data/spec/features/admin/configuration/taxonomies_spec.rb +0 -52
- data/spec/features/admin/configuration/zones_spec.rb +0 -39
- data/spec/features/admin/homepage_spec.rb +0 -78
- data/spec/features/admin/locale_spec.rb +0 -30
- data/spec/features/admin/orders/adjustments_promotions_spec.rb +0 -53
- data/spec/features/admin/orders/adjustments_spec.rb +0 -126
- data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +0 -48
- data/spec/features/admin/orders/cancelling_inventory_spec.rb +0 -48
- data/spec/features/admin/orders/customer_details_spec.rb +0 -163
- data/spec/features/admin/orders/line_items_spec.rb +0 -50
- data/spec/features/admin/orders/listing_spec.rb +0 -130
- data/spec/features/admin/orders/log_entries_spec.rb +0 -55
- data/spec/features/admin/orders/new_order_spec.rb +0 -197
- data/spec/features/admin/orders/order_details_spec.rb +0 -533
- data/spec/features/admin/orders/payments_spec.rb +0 -228
- data/spec/features/admin/orders/risk_analysis_spec.rb +0 -47
- data/spec/features/admin/orders/shipments_spec.rb +0 -65
- data/spec/features/admin/payments/store_credits_spec.rb +0 -21
- data/spec/features/admin/products/edit/images_spec.rb +0 -87
- data/spec/features/admin/products/edit/products_spec.rb +0 -66
- data/spec/features/admin/products/edit/taxons_spec.rb +0 -56
- data/spec/features/admin/products/edit/variants_spec.rb +0 -61
- data/spec/features/admin/products/option_types_spec.rb +0 -114
- data/spec/features/admin/products/products_spec.rb +0 -392
- data/spec/features/admin/products/properties_spec.rb +0 -139
- data/spec/features/admin/products/prototypes_spec.rb +0 -110
- data/spec/features/admin/products/stock_management_spec.rb +0 -82
- data/spec/features/admin/products/variant_spec.rb +0 -51
- data/spec/features/admin/promotion_adjustments_spec.rb +0 -220
- data/spec/features/admin/promotions/tiered_calculator_spec.rb +0 -69
- data/spec/features/admin/promotions/user_rule_spec.rb +0 -25
- data/spec/features/admin/reports_spec.rb +0 -61
- data/spec/features/admin/stock_transfer_spec.rb +0 -86
- data/spec/features/admin/store_credits_spec.rb +0 -82
- data/spec/features/admin/taxons_spec.rb +0 -31
- data/spec/features/admin/users_spec.rb +0 -270
- data/spec/helpers/admin/base_helper_spec.rb +0 -24
- data/spec/helpers/admin/navigation_helper_spec.rb +0 -73
- data/spec/helpers/admin/reimbursements_helper_spec.rb +0 -34
- data/spec/helpers/admin/stock_movements_helper_spec.rb +0 -29
- data/spec/helpers/admin/store_credit_events_helper_spec.rb +0 -95
- data/spec/helpers/promotion_rules_helper_spec.rb +0 -12
- data/spec/spec_helper.rb +0 -108
- data/spec/support/appear_before_matcher.rb +0 -8
- data/spec/support/ror_ringer.jpeg +0 -0
- data/spec/test_views/spree/admin/widgets/edit.html.erb +0 -1
- data/spec/test_views/spree/admin/widgets/new.html.erb +0 -1
- data/vendor/assets/javascripts/handlebars.js +0 -2746
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::Admin::GeneralSettingsController, type: :controller do
|
4
|
-
let(:user) { create(:user) }
|
5
|
-
|
6
|
-
before do
|
7
|
-
allow(controller).to receive_messages :spree_current_user => user
|
8
|
-
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
|
9
|
-
end
|
10
|
-
|
11
|
-
describe '#clear_cache' do
|
12
|
-
subject { spree_post :clear_cache }
|
13
|
-
|
14
|
-
shared_examples 'a HTTP 204 response' do
|
15
|
-
it 'grant access to users with an admin role' do
|
16
|
-
subject
|
17
|
-
expect(response.status).to eq(204)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'when no callback' do
|
22
|
-
it_behaves_like 'a HTTP 204 response'
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when callback implemented' do
|
26
|
-
Spree::Admin::GeneralSettingsController.class_eval do
|
27
|
-
custom_callback(:clear_cache).after :foo
|
28
|
-
|
29
|
-
def foo
|
30
|
-
# Make a call to Akamai, CloudFlare, etc invalidation....
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
before do
|
35
|
-
expect(controller).to receive(:foo).once
|
36
|
-
end
|
37
|
-
|
38
|
-
it_behaves_like 'a HTTP 204 response'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
# This test exists in this file because in the standard admin/products_controller spec
|
3
|
-
# There is the stub_authorization call. This call is not triggered for this test because
|
4
|
-
# the load_resource filter in Spree::Admin::ResourceController is prepended to the filter chain
|
5
|
-
# this means this call is triggered before the authorize_admin call and in this case
|
6
|
-
# the load_resource filter halts the request meaning authorize_admin is not called at all.
|
7
|
-
describe Spree::Admin::ProductsController, :type => :controller do
|
8
|
-
stub_authorization!
|
9
|
-
|
10
|
-
# Regression test for GH #538
|
11
|
-
it "cannot find a non-existent product" do
|
12
|
-
spree_get :edit, :id => "non-existent-product"
|
13
|
-
expect(response).to redirect_to(spree.admin_products_path)
|
14
|
-
expect(flash[:error]).to eql("Product is not found")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
|
@@ -1,80 +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) { create(:order, number: "R123456789") }
|
11
|
-
|
12
|
-
before { allow(Spree::Order).to receive(:find_by_number!) { order } }
|
13
|
-
|
14
|
-
context "#update" do
|
15
|
-
it "updates + progresses the order" do
|
16
|
-
expect(order).to receive(:update_attributes) { true }
|
17
|
-
expect(order).to receive(:next) { false }
|
18
|
-
attributes = { order_id: order.number, order: { email: "" } }
|
19
|
-
spree_put :update, attributes
|
20
|
-
end
|
21
|
-
|
22
|
-
it "does refresh the shipment rates with all shipping methods" do
|
23
|
-
expect(order).to receive(:refresh_shipment_rates)
|
24
|
-
attributes = { order_id: order.number, order: { email: "" } }
|
25
|
-
spree_put :update, attributes
|
26
|
-
end
|
27
|
-
|
28
|
-
# Regression spec
|
29
|
-
context 'completed order' do
|
30
|
-
let(:order) { create(:shipped_order) }
|
31
|
-
let(:attributes) do
|
32
|
-
{
|
33
|
-
order_id: order.number,
|
34
|
-
guest_checkout: 'false',
|
35
|
-
user_id: order.user_id,
|
36
|
-
order: { email: "foo@bar.com" }
|
37
|
-
}
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'allows the updating of an email address' do
|
41
|
-
expect { spree_put :update, attributes }.to change { order.reload.email }.to eq 'foo@bar.com'
|
42
|
-
expect(response).to be_redirect
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "false guest checkout param" do
|
47
|
-
let!(:assigned_user){ create :user }
|
48
|
-
it "attempts to associate the user" do
|
49
|
-
attributes = {
|
50
|
-
order_id: order.number,
|
51
|
-
user_id: assigned_user.id,
|
52
|
-
guest_checkout: 'false',
|
53
|
-
order: { email: "" }
|
54
|
-
}
|
55
|
-
|
56
|
-
expect {
|
57
|
-
spree_put :update, attributes
|
58
|
-
}.to change{ order.reload.user }.to(assigned_user)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context "not false guest checkout param" do
|
63
|
-
it "does not attempt to associate the user" do
|
64
|
-
allow(order).to receive_messages(update_attributes: true,
|
65
|
-
next: false,
|
66
|
-
refresh_shipment_rates: true)
|
67
|
-
|
68
|
-
attributes = {
|
69
|
-
order_id: order.number,
|
70
|
-
order: { email: "foo@example.com" }
|
71
|
-
}
|
72
|
-
|
73
|
-
expect {
|
74
|
-
spree_put :update, attributes
|
75
|
-
}.not_to change{ order.reload.user }
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,472 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'cancan'
|
3
|
-
require 'spree/testing_support/bar_ability'
|
4
|
-
|
5
|
-
describe Spree::Admin::OrdersController, :type => :controller do
|
6
|
-
|
7
|
-
context "with authorization" do
|
8
|
-
stub_authorization!
|
9
|
-
|
10
|
-
before do
|
11
|
-
request.env["HTTP_REFERER"] = "http://localhost:3000"
|
12
|
-
|
13
|
-
# ensure no respond_overrides are in effect
|
14
|
-
if Spree::BaseController.spree_responders[:OrdersController].present?
|
15
|
-
Spree::BaseController.spree_responders[:OrdersController].clear
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
let(:order) do
|
20
|
-
mock_model(
|
21
|
-
Spree::Order,
|
22
|
-
completed?: true,
|
23
|
-
total: 100,
|
24
|
-
number: 'R123456789',
|
25
|
-
all_adjustments: adjustments,
|
26
|
-
ship_address: mock_model(Spree::Address),
|
27
|
-
)
|
28
|
-
end
|
29
|
-
|
30
|
-
let(:adjustments) { double('adjustments') }
|
31
|
-
|
32
|
-
before do
|
33
|
-
allow(Spree::Order).to receive_messages(find_by_number!: order)
|
34
|
-
allow(order).to receive_messages(contents: Spree::OrderContents.new(order))
|
35
|
-
end
|
36
|
-
|
37
|
-
context "#approve" do
|
38
|
-
it "approves an order" do
|
39
|
-
expect(order.contents).to receive(:approve).with(user: controller.try_spree_current_user)
|
40
|
-
spree_put :approve, id: order.number
|
41
|
-
expect(flash[:success]).to eq Spree.t(:order_approved)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "#cancel" do
|
46
|
-
it "cancels an order" do
|
47
|
-
expect(order).to receive(:canceled_by).with(controller.try_spree_current_user)
|
48
|
-
spree_put :cancel, id: order.number
|
49
|
-
expect(flash[:success]).to eq Spree.t(:order_canceled)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context "#resume" do
|
54
|
-
it "resumes an order" do
|
55
|
-
expect(order).to receive(:resume!)
|
56
|
-
spree_put :resume, id: order.number
|
57
|
-
expect(flash[:success]).to eq Spree.t(:order_resumed)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "pagination" do
|
62
|
-
it "can page through the orders" do
|
63
|
-
spree_get :index, :page => 2, :per_page => 10
|
64
|
-
expect(assigns[:orders].offset_value).to eq(10)
|
65
|
-
expect(assigns[:orders].limit_value).to eq(10)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# Test for #3346
|
70
|
-
context "#new" do
|
71
|
-
let(:user) { create(:user) }
|
72
|
-
before do
|
73
|
-
allow(controller).to receive_messages :spree_current_user => user
|
74
|
-
end
|
75
|
-
|
76
|
-
it "imports a new order and sets the current user as a creator" do
|
77
|
-
expect(Spree::Core::Importer::Order).to receive(:import)
|
78
|
-
.with(nil, hash_including(created_by_id: controller.try_spree_current_user.id))
|
79
|
-
.and_return(order)
|
80
|
-
spree_get :new
|
81
|
-
end
|
82
|
-
|
83
|
-
it "sets frontend_viewable to false" do
|
84
|
-
expect(Spree::Core::Importer::Order).to receive(:import)
|
85
|
-
.with(nil, hash_including(frontend_viewable: false ))
|
86
|
-
.and_return(order)
|
87
|
-
spree_get :new
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should associate the order with a store" do
|
91
|
-
expect(Spree::Core::Importer::Order).to receive(:import)
|
92
|
-
.with(user, hash_including(store_id: controller.current_store.id))
|
93
|
-
.and_return(order)
|
94
|
-
spree_get :new, { user_id: user.id }
|
95
|
-
end
|
96
|
-
|
97
|
-
context "when a user_id is passed as a parameter" do
|
98
|
-
let(:user) { mock_model(Spree.user_class) }
|
99
|
-
before { allow(Spree.user_class).to receive_messages :find_by_id => user }
|
100
|
-
|
101
|
-
it "imports a new order and assigns the user to the order" do
|
102
|
-
expect(Spree::Core::Importer::Order).to receive(:import)
|
103
|
-
.with(user, hash_including(created_by_id: controller.try_spree_current_user.id))
|
104
|
-
.and_return(order)
|
105
|
-
spree_get :new, { user_id: user.id }
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should redirect to cart" do
|
110
|
-
spree_get :new
|
111
|
-
expect(response).to redirect_to(spree.cart_admin_order_path(Spree::Order.last))
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# Regression test for #3684
|
116
|
-
context "#edit" do
|
117
|
-
it "does not refresh rates if the order is completed" do
|
118
|
-
allow(order).to receive_messages :completed? => true
|
119
|
-
expect(order).not_to receive :refresh_shipment_rates
|
120
|
-
spree_get :edit, :id => order.number
|
121
|
-
end
|
122
|
-
|
123
|
-
it "does refresh the rates if the order is incomplete" do
|
124
|
-
allow(order).to receive_messages :completed? => false
|
125
|
-
expect(order).to receive :refresh_shipment_rates
|
126
|
-
spree_get :edit, :id => order.number
|
127
|
-
end
|
128
|
-
|
129
|
-
context "when order does not have a ship address" do
|
130
|
-
before do
|
131
|
-
allow(order).to receive_messages :ship_address => nil
|
132
|
-
end
|
133
|
-
|
134
|
-
context 'when order_bill_address_used is true' do
|
135
|
-
before { Spree::Config[:order_bill_address_used] = true }
|
136
|
-
|
137
|
-
it "should redirect to the customer details page" do
|
138
|
-
spree_get :edit, :id => order.number
|
139
|
-
expect(response).to redirect_to(spree.edit_admin_order_customer_path(order))
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
context 'when order_bill_address_used is false' do
|
144
|
-
before { Spree::Config[:order_bill_address_used] = false }
|
145
|
-
|
146
|
-
it "should redirect to the customer details page" do
|
147
|
-
spree_get :edit, :id => order.number
|
148
|
-
expect(response).to redirect_to(spree.edit_admin_order_customer_path(order))
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
describe '#advance' do
|
155
|
-
subject do
|
156
|
-
spree_put :advance, id: order.number
|
157
|
-
end
|
158
|
-
|
159
|
-
context 'when incomplete' do
|
160
|
-
before do
|
161
|
-
allow(order).to receive(:completed?).and_return(false, true)
|
162
|
-
allow(order).to receive(:next).and_return(true, false)
|
163
|
-
end
|
164
|
-
|
165
|
-
context 'when successful' do
|
166
|
-
before { allow(order).to receive(:confirm?).and_return(true) }
|
167
|
-
|
168
|
-
it 'messages and redirects' do
|
169
|
-
subject
|
170
|
-
expect(flash[:success]).to eq Spree.t('order_ready_for_confirm')
|
171
|
-
expect(response).to redirect_to(spree.confirm_admin_order_path(order))
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
context 'when unsuccessful' do
|
176
|
-
before do
|
177
|
-
allow(order).to receive(:confirm?).and_return(false)
|
178
|
-
allow(order).to receive(:errors).and_return(double(full_messages: ['failed']))
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'messages and redirects' do
|
182
|
-
subject
|
183
|
-
expect(flash[:error]) == order.errors.full_messages
|
184
|
-
expect(response).to redirect_to(spree.confirm_admin_order_path(order))
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
context 'when already completed' do
|
190
|
-
before { allow(order).to receive_messages :completed? => true }
|
191
|
-
|
192
|
-
it 'messages and redirects' do
|
193
|
-
subject
|
194
|
-
expect(flash[:notice]).to eq Spree.t('order_already_completed')
|
195
|
-
expect(response).to redirect_to(spree.edit_admin_order_path(order))
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
context '#confirm' do
|
201
|
-
subject do
|
202
|
-
spree_get :confirm, id: order.number
|
203
|
-
end
|
204
|
-
|
205
|
-
context 'when in confirm' do
|
206
|
-
before { allow(order).to receive_messages completed?: false, confirm?: true }
|
207
|
-
|
208
|
-
it 'renders the confirm page' do
|
209
|
-
subject
|
210
|
-
expect(response.status).to eq 200
|
211
|
-
expect(response).to render_template(:confirm)
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
context 'when before confirm' do
|
216
|
-
before { order.stub completed?: false, confirm?: false }
|
217
|
-
|
218
|
-
it 'renders the confirm_advance template (to allow refreshing of the order)' do
|
219
|
-
subject
|
220
|
-
expect(response.status).to eq 200
|
221
|
-
expect(response).to render_template(:confirm_advance)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
context 'when already completed' do
|
226
|
-
before { allow(order).to receive_messages completed?: true }
|
227
|
-
|
228
|
-
it 'redirects to edit' do
|
229
|
-
subject
|
230
|
-
expect(response).to redirect_to(spree.edit_admin_order_path(order))
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
context "#complete" do
|
236
|
-
subject do
|
237
|
-
spree_put :complete, id: order.number
|
238
|
-
end
|
239
|
-
|
240
|
-
context 'when successful' do
|
241
|
-
before { allow(order).to receive(:complete!) }
|
242
|
-
|
243
|
-
it 'completes the order' do
|
244
|
-
expect(order).to receive(:complete!)
|
245
|
-
subject
|
246
|
-
end
|
247
|
-
|
248
|
-
it 'messages and redirects' do
|
249
|
-
subject
|
250
|
-
expect(flash[:success]).to eq Spree.t(:order_completed)
|
251
|
-
expect(response).to redirect_to(spree.edit_admin_order_path(order))
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
context 'with an StateMachines::InvalidTransition error' do
|
256
|
-
let(:order) { create(:order) }
|
257
|
-
|
258
|
-
it 'messages and redirects' do
|
259
|
-
subject
|
260
|
-
expect(response).to redirect_to(spree.confirm_admin_order_path(order))
|
261
|
-
expect(flash[:error].to_s).to include("Cannot transition state via :complete from :cart")
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
context 'insufficient stock to complete the order' do
|
266
|
-
before do
|
267
|
-
expect(order).to receive(:complete!).and_raise Spree::Order::InsufficientStock
|
268
|
-
end
|
269
|
-
|
270
|
-
it 'messages and redirects' do
|
271
|
-
subject
|
272
|
-
expect(response).to redirect_to(spree.cart_admin_order_path(order))
|
273
|
-
expect(flash[:error].to_s).to eq Spree.t(:insufficient_stock_for_order)
|
274
|
-
end
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
# Test for #3919
|
279
|
-
context "search" do
|
280
|
-
let(:user) { create(:user) }
|
281
|
-
|
282
|
-
before do
|
283
|
-
allow(controller).to receive_messages :spree_current_user => user
|
284
|
-
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
|
285
|
-
|
286
|
-
create(:completed_order_with_totals)
|
287
|
-
expect(Spree::Order.count).to eq 1
|
288
|
-
end
|
289
|
-
|
290
|
-
it "does not display duplicated results" do
|
291
|
-
spree_get :index, q: {
|
292
|
-
line_items_variant_id_in: Spree::Order.first.variants.map(&:id)
|
293
|
-
}
|
294
|
-
expect(assigns[:orders].map { |o| o.number }.count).to eq 1
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
context "#open_adjustments" do
|
299
|
-
let(:closed) { double('closed_adjustments') }
|
300
|
-
|
301
|
-
before do
|
302
|
-
allow(adjustments).to receive(:where).and_return(closed)
|
303
|
-
allow(closed).to receive(:update_all)
|
304
|
-
end
|
305
|
-
|
306
|
-
it "changes all the closed adjustments to open" do
|
307
|
-
expect(adjustments).to receive(:where).with(state: 'closed')
|
308
|
-
.and_return(closed)
|
309
|
-
expect(closed).to receive(:update_all).with(state: 'open')
|
310
|
-
spree_post :open_adjustments, id: order.number
|
311
|
-
end
|
312
|
-
|
313
|
-
it "sets the flash success message" do
|
314
|
-
spree_post :open_adjustments, id: order.number
|
315
|
-
expect(flash[:success]).to eql('All adjustments successfully opened!')
|
316
|
-
end
|
317
|
-
|
318
|
-
it "redirects back" do
|
319
|
-
spree_post :open_adjustments, id: order.number
|
320
|
-
expect(response).to redirect_to(:back)
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
context "#close_adjustments" do
|
325
|
-
let(:open) { double('open_adjustments') }
|
326
|
-
|
327
|
-
before do
|
328
|
-
allow(adjustments).to receive(:where).and_return(open)
|
329
|
-
allow(open).to receive(:update_all)
|
330
|
-
end
|
331
|
-
|
332
|
-
it "changes all the open adjustments to closed" do
|
333
|
-
expect(adjustments).to receive(:where).with(state: 'open')
|
334
|
-
.and_return(open)
|
335
|
-
expect(open).to receive(:update_all).with(state: 'closed')
|
336
|
-
spree_post :close_adjustments, id: order.number
|
337
|
-
end
|
338
|
-
|
339
|
-
it "sets the flash success message" do
|
340
|
-
spree_post :close_adjustments, id: order.number
|
341
|
-
expect(flash[:success]).to eql('All adjustments successfully closed!')
|
342
|
-
end
|
343
|
-
|
344
|
-
it "redirects back" do
|
345
|
-
spree_post :close_adjustments, id: order.number
|
346
|
-
expect(response).to redirect_to(:back)
|
347
|
-
end
|
348
|
-
end
|
349
|
-
end
|
350
|
-
|
351
|
-
context '#authorize_admin' do
|
352
|
-
let(:user) { create(:user) }
|
353
|
-
let(:order) { create(:completed_order_with_totals, :number => 'R987654321') }
|
354
|
-
|
355
|
-
before do
|
356
|
-
allow(Spree::Order).to receive_messages :find_by_number! => order
|
357
|
-
allow(controller).to receive_messages :spree_current_user => user
|
358
|
-
end
|
359
|
-
|
360
|
-
it 'should grant access to users with an admin role' do
|
361
|
-
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
|
362
|
-
spree_post :index
|
363
|
-
expect(response).to render_template :index
|
364
|
-
end
|
365
|
-
|
366
|
-
it 'should grant access to users with an bar role' do
|
367
|
-
user.spree_roles << Spree::Role.find_or_create_by(name: 'bar')
|
368
|
-
Spree::Ability.register_ability(BarAbility)
|
369
|
-
spree_post :index
|
370
|
-
expect(response).to render_template :index
|
371
|
-
Spree::Ability.remove_ability(BarAbility)
|
372
|
-
end
|
373
|
-
|
374
|
-
it 'should deny access to users with an bar role' do
|
375
|
-
allow(order).to receive(:update_attributes).and_return true
|
376
|
-
allow(order).to receive(:user).and_return Spree.user_class.new
|
377
|
-
allow(order).to receive(:token).and_return nil
|
378
|
-
user.spree_roles.clear
|
379
|
-
user.spree_roles << Spree::Role.find_or_create_by(name: 'bar')
|
380
|
-
Spree::Ability.register_ability(BarAbility)
|
381
|
-
spree_put :update, { :id => 'R123' }
|
382
|
-
expect(response).to redirect_to('/unauthorized')
|
383
|
-
Spree::Ability.remove_ability(BarAbility)
|
384
|
-
end
|
385
|
-
|
386
|
-
it 'should deny access to users without an admin role' do
|
387
|
-
allow(user).to receive_messages :has_spree_role? => false
|
388
|
-
spree_post :index
|
389
|
-
expect(response).to redirect_to('/unauthorized')
|
390
|
-
end
|
391
|
-
|
392
|
-
context 'with only permissions on Order' do
|
393
|
-
stub_authorization! do |ability|
|
394
|
-
can [:admin, :manage], Spree::Order, :number => 'R987654321'
|
395
|
-
end
|
396
|
-
|
397
|
-
it 'should restrict returned order(s) on index when using OrderSpecificAbility' do
|
398
|
-
number = order.number
|
399
|
-
|
400
|
-
3.times { create(:completed_order_with_totals) }
|
401
|
-
expect(Spree::Order.complete.count).to eq 4
|
402
|
-
|
403
|
-
allow(user).to receive_messages :has_spree_role? => false
|
404
|
-
spree_get :index
|
405
|
-
expect(response).to render_template :index
|
406
|
-
expect(assigns['orders'].size).to eq 1
|
407
|
-
expect(assigns['orders'].first.number).to eq number
|
408
|
-
end
|
409
|
-
end
|
410
|
-
end
|
411
|
-
|
412
|
-
context "order number not given" do
|
413
|
-
stub_authorization!
|
414
|
-
|
415
|
-
it "raise active record not found" do
|
416
|
-
expect {
|
417
|
-
spree_get :edit, id: 0
|
418
|
-
}.to raise_error ActiveRecord::RecordNotFound
|
419
|
-
end
|
420
|
-
end
|
421
|
-
|
422
|
-
describe "#update" do
|
423
|
-
stub_authorization!
|
424
|
-
|
425
|
-
let(:order) { create(:order) }
|
426
|
-
let(:payload) do
|
427
|
-
{
|
428
|
-
id: order.number,
|
429
|
-
order: { email: "foo@bar.com" }
|
430
|
-
}
|
431
|
-
end
|
432
|
-
|
433
|
-
before do
|
434
|
-
allow(order.contents).to receive(:update_cart)
|
435
|
-
expect(Spree::Order).to receive(:find_by_number!) { order }
|
436
|
-
end
|
437
|
-
subject { spree_put :update, payload }
|
438
|
-
|
439
|
-
it "attempts to update the order" do
|
440
|
-
expect(order.contents).to receive(:update_cart).with(payload[:order])
|
441
|
-
subject
|
442
|
-
end
|
443
|
-
|
444
|
-
context "the order is already completed" do
|
445
|
-
before { allow(order).to receive(:completed?) { true } }
|
446
|
-
|
447
|
-
it "renders the edit route" do
|
448
|
-
subject
|
449
|
-
expect(response).to render_template(:edit)
|
450
|
-
end
|
451
|
-
end
|
452
|
-
|
453
|
-
context "the order is not completed" do
|
454
|
-
before { allow(order).to receive(:completed?) { false } }
|
455
|
-
|
456
|
-
it "redirects to the customer path" do
|
457
|
-
subject
|
458
|
-
expect(response).to redirect_to(spree.admin_order_customer_path(order))
|
459
|
-
end
|
460
|
-
end
|
461
|
-
|
462
|
-
context "the order has no line items" do
|
463
|
-
let(:order) { Spree::Order.new(:number => "1234") }
|
464
|
-
|
465
|
-
it "includes an error on the order" do
|
466
|
-
subject
|
467
|
-
expect(order.errors[:line_items]).to include Spree.t('errors.messages.blank')
|
468
|
-
end
|
469
|
-
end
|
470
|
-
|
471
|
-
end
|
472
|
-
end
|