spree_backend 3.0.5 → 3.0.6
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -0
- data/Gemfile +6 -0
- data/Rakefile +29 -0
- data/app/assets/javascripts/spree/backend/admin.js +26 -0
- data/app/controllers/spree/admin/resource_controller.rb +4 -2
- data/app/helpers/spree/admin/navigation_helper.rb +10 -1
- data/app/views/spree/admin/images/new.html.erb +1 -1
- data/app/views/spree/admin/payments/_list.html.erb +1 -1
- data/app/views/spree/admin/products/_form.html.erb +1 -1
- data/app/views/spree/admin/shared/_index_table_options.html.erb +1 -11
- data/app/views/spree/admin/shared/sub_menu/_product.html.erb +1 -1
- data/script/rails +9 -0
- data/spec/controllers/spree/admin/base_controller_spec.rb +46 -0
- data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +185 -0
- data/spec/controllers/spree/admin/general_settings_controller_spec.rb +41 -0
- data/spec/controllers/spree/admin/missing_products_controller_spec.rb +18 -0
- data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +42 -0
- data/spec/controllers/spree/admin/orders_controller_spec.rb +247 -0
- data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +49 -0
- data/spec/controllers/spree/admin/payments_controller_spec.rb +97 -0
- data/spec/controllers/spree/admin/products_controller_spec.rb +53 -0
- data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +21 -0
- data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +21 -0
- data/spec/controllers/spree/admin/promotions_controller_spec.rb +44 -0
- data/spec/controllers/spree/admin/refunds_controller_spec.rb +32 -0
- data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +74 -0
- data/spec/controllers/spree/admin/reports_controller_spec.rb +42 -0
- data/spec/controllers/spree/admin/resource_controller_spec.rb +276 -0
- data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +225 -0
- data/spec/controllers/spree/admin/return_items_controller_spec.rb +27 -0
- data/spec/controllers/spree/admin/root_controller_spec.rb +35 -0
- data/spec/controllers/spree/admin/search_controller_spec.rb +56 -0
- data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +14 -0
- data/spec/controllers/spree/admin/stock_items_controller_spec.rb +19 -0
- data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +41 -0
- data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +41 -0
- data/spec/controllers/spree/admin/tax_categories_controller_spec.rb +34 -0
- data/spec/controllers/spree/admin/users_controller_spec.rb +161 -0
- data/spec/controllers/spree/admin/variants_controller_spec.rb +32 -0
- data/spec/features/admin/configuration/analytics_tracker_spec.rb +46 -0
- data/spec/features/admin/configuration/countries_spec.rb +24 -0
- data/spec/features/admin/configuration/general_settings_spec.rb +43 -0
- data/spec/features/admin/configuration/payment_methods_spec.rb +63 -0
- data/spec/features/admin/configuration/roles_spec.rb +47 -0
- data/spec/features/admin/configuration/shipping_methods_spec.rb +62 -0
- data/spec/features/admin/configuration/states_spec.rb +68 -0
- data/spec/features/admin/configuration/stock_locations_spec.rb +48 -0
- data/spec/features/admin/configuration/tax_categories_spec.rb +56 -0
- data/spec/features/admin/configuration/tax_rates_spec.rb +18 -0
- data/spec/features/admin/configuration/zones_spec.rb +39 -0
- data/spec/features/admin/homepage_spec.rb +81 -0
- data/spec/features/admin/locale_spec.rb +31 -0
- data/spec/features/admin/orders/adjustments_promotions_spec.rb +53 -0
- data/spec/features/admin/orders/adjustments_spec.rb +129 -0
- data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +47 -0
- data/spec/features/admin/orders/customer_details_spec.rb +182 -0
- data/spec/features/admin/orders/line_items_spec.rb +51 -0
- data/spec/features/admin/orders/listing_spec.rb +225 -0
- data/spec/features/admin/orders/log_entries_spec.rb +55 -0
- data/spec/features/admin/orders/new_order_spec.rb +161 -0
- data/spec/features/admin/orders/order_details_spec.rb +620 -0
- data/spec/features/admin/orders/payments_spec.rb +229 -0
- data/spec/features/admin/orders/risk_analysis_spec.rb +48 -0
- data/spec/features/admin/orders/shipments_spec.rb +64 -0
- data/spec/features/admin/orders/state_changes_spec.rb +21 -0
- data/spec/features/admin/products/edit/images_spec.rb +86 -0
- data/spec/features/admin/products/edit/products_spec.rb +64 -0
- data/spec/features/admin/products/edit/taxons_spec.rb +41 -0
- data/spec/features/admin/products/edit/variants_spec.rb +56 -0
- data/spec/features/admin/products/option_types_spec.rb +113 -0
- data/spec/features/admin/products/products_spec.rb +394 -0
- data/spec/features/admin/products/properties_spec.rb +140 -0
- data/spec/features/admin/products/prototypes_spec.rb +112 -0
- data/spec/features/admin/products/stock_management_spec.rb +123 -0
- data/spec/features/admin/products/taxonomies_spec.rb +52 -0
- data/spec/features/admin/products/variant_spec.rb +50 -0
- data/spec/features/admin/promotions/adjustments_spec.rb +255 -0
- data/spec/features/admin/promotions/option_value_rule_spec.rb +70 -0
- data/spec/features/admin/promotions/tiered_calculator_spec.rb +70 -0
- data/spec/features/admin/reports_spec.rb +61 -0
- data/spec/features/admin/stock_transfer_spec.rb +75 -0
- data/spec/features/admin/taxons_spec.rb +47 -0
- data/spec/features/admin/users_spec.rb +284 -0
- data/spec/helpers/admin/base_helper_spec.rb +24 -0
- data/spec/helpers/admin/navigation_helper_spec.rb +106 -0
- data/spec/helpers/admin/stock_movements_helper_spec.rb +30 -0
- data/spec/helpers/promotion_rules_helper_spec.rb +12 -0
- data/spec/models/spree/resource_spec.rb +48 -0
- data/spec/spec_helper.rb +133 -0
- data/spec/support/appear_before_matcher.rb +8 -0
- data/spec/support/ror_ringer.jpeg +0 -0
- data/spec/test_views/spree/admin/submodule/posts/edit.html.erb +1 -0
- data/spec/test_views/spree/admin/submodule/posts/new.html.erb +1 -0
- data/spec/test_views/spree/admin/widgets/edit.html.erb +1 -0
- data/spec/test_views/spree/admin/widgets/new.html.erb +1 -0
- data/spree_backend.gemspec +29 -0
- metadata +101 -14
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Admin::ProductsController, :type => :controller do
|
|
4
|
+
stub_authorization!
|
|
5
|
+
|
|
6
|
+
context "#index" do
|
|
7
|
+
let(:ability_user) { stub_model(Spree::LegacyUser, :has_spree_role? => true) }
|
|
8
|
+
|
|
9
|
+
# Regression test for #1259
|
|
10
|
+
it "can find a product by SKU" do
|
|
11
|
+
product = create(:product, :sku => "ABC123")
|
|
12
|
+
spree_get :index, :q => { :sku_start => "ABC123" }
|
|
13
|
+
expect(assigns[:collection]).not_to be_empty
|
|
14
|
+
expect(assigns[:collection]).to include(product)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# regression test for #1370
|
|
19
|
+
context "adding properties to a product" do
|
|
20
|
+
let!(:product) { create(:product) }
|
|
21
|
+
specify do
|
|
22
|
+
spree_put :update, :id => product.to_param, :product => { :product_properties_attributes => { "1" => { :property_name => "Foo", :value => "bar" } } }
|
|
23
|
+
expect(flash[:success]).to eq("Product #{product.name.inspect} has been successfully updated!")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# regression test for #801
|
|
30
|
+
context "destroying a product" do
|
|
31
|
+
let(:product) do
|
|
32
|
+
product = create(:product)
|
|
33
|
+
create(:variant, :product => product)
|
|
34
|
+
product
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "deletes all the variants (including master) for the product" do
|
|
38
|
+
spree_delete :destroy, :id => product
|
|
39
|
+
expect(product.reload.deleted_at).not_to be_nil
|
|
40
|
+
product.variants_including_master.each do |variant|
|
|
41
|
+
expect(variant.reload.deleted_at).not_to be_nil
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context "stock" do
|
|
47
|
+
let(:product) { create(:product) }
|
|
48
|
+
it "restricts stock location based on accessible attributes" do
|
|
49
|
+
expect(Spree::StockLocation).to receive(:accessible_by).and_return([])
|
|
50
|
+
spree_get :stock, :id => product
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Admin::PromotionActionsController, :type => :controller do
|
|
4
|
+
stub_authorization!
|
|
5
|
+
|
|
6
|
+
let!(:promotion) { create(:promotion) }
|
|
7
|
+
|
|
8
|
+
it "can create a promotion action of a valid type" do
|
|
9
|
+
spree_post :create, :promotion_id => promotion.id, :action_type => "Spree::Promotion::Actions::CreateAdjustment"
|
|
10
|
+
expect(response).to be_redirect
|
|
11
|
+
expect(response).to redirect_to spree.edit_admin_promotion_path(promotion)
|
|
12
|
+
expect(promotion.actions.count).to eq(1)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "can not create a promotion action of an invalid type" do
|
|
16
|
+
spree_post :create, :promotion_id => promotion.id, :action_type => "Spree::InvalidType"
|
|
17
|
+
expect(response).to be_redirect
|
|
18
|
+
expect(response).to redirect_to spree.edit_admin_promotion_path(promotion)
|
|
19
|
+
expect(promotion.rules.count).to eq(0)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Admin::PromotionRulesController, :type => :controller do
|
|
4
|
+
stub_authorization!
|
|
5
|
+
|
|
6
|
+
let!(:promotion) { create(:promotion) }
|
|
7
|
+
|
|
8
|
+
it "can create a promotion rule of a valid type" do
|
|
9
|
+
spree_post :create, :promotion_id => promotion.id, :promotion_rule => { :type => "Spree::Promotion::Rules::Product" }
|
|
10
|
+
expect(response).to be_redirect
|
|
11
|
+
expect(response).to redirect_to spree.edit_admin_promotion_path(promotion)
|
|
12
|
+
expect(promotion.rules.count).to eq(1)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "can not create a promotion rule of an invalid type" do
|
|
16
|
+
spree_post :create, :promotion_id => promotion.id, :promotion_rule => { :type => "Spree::InvalidType" }
|
|
17
|
+
expect(response).to be_redirect
|
|
18
|
+
expect(response).to redirect_to spree.edit_admin_promotion_path(promotion)
|
|
19
|
+
expect(promotion.rules.count).to eq(0)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Admin::PromotionsController, :type => :controller do
|
|
4
|
+
stub_authorization!
|
|
5
|
+
|
|
6
|
+
let!(:promotion1) { create(:promotion, name: "name1", code: "code1", path: "path1") }
|
|
7
|
+
let!(:promotion2) { create(:promotion, name: "name2", code: "code2", path: "path2") }
|
|
8
|
+
let!(:category) { create :promotion_category }
|
|
9
|
+
|
|
10
|
+
context "#index" do
|
|
11
|
+
it "succeeds" do
|
|
12
|
+
spree_get :index
|
|
13
|
+
expect(assigns[:promotions]).to match_array [promotion2, promotion1]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "assigns promotion categories" do
|
|
17
|
+
spree_get :index
|
|
18
|
+
expect(assigns[:promotion_categories]).to match_array [category]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context "search" do
|
|
22
|
+
it "pages results" do
|
|
23
|
+
spree_get :index, per_page: '1'
|
|
24
|
+
expect(assigns[:promotions]).to eq [promotion2]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "filters by name" do
|
|
28
|
+
spree_get :index, q: {name_cont: promotion1.name}
|
|
29
|
+
expect(assigns[:promotions]).to eq [promotion1]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "filters by code" do
|
|
33
|
+
spree_get :index, q: {code_cont: promotion1.code}
|
|
34
|
+
expect(assigns[:promotions]).to eq [promotion1]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "filters by path" do
|
|
38
|
+
spree_get :index, q: {path_cont: promotion1.path}
|
|
39
|
+
expect(assigns[:promotions]).to eq [promotion1]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Admin::RefundsController do
|
|
4
|
+
stub_authorization!
|
|
5
|
+
|
|
6
|
+
describe "POST create" do
|
|
7
|
+
context "a Spree::Core::GatewayError is raised" do
|
|
8
|
+
|
|
9
|
+
let(:payment) { create(:payment) }
|
|
10
|
+
|
|
11
|
+
subject do
|
|
12
|
+
spree_post :create,
|
|
13
|
+
refund: { amount: "50.0", refund_reason_id: "1" },
|
|
14
|
+
order_id: payment.order.to_param,
|
|
15
|
+
payment_id: payment.to_param
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
before(:each) do
|
|
19
|
+
def controller.create
|
|
20
|
+
raise Spree::Core::GatewayError.new('An error has occurred')
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "sets an error message with the correct text" do
|
|
25
|
+
subject
|
|
26
|
+
expect(flash[:error]).to eq 'An error has occurred'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it { should render_template(:new) }
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Admin::ReimbursementsController, :type => :controller do
|
|
4
|
+
stub_authorization!
|
|
5
|
+
|
|
6
|
+
let!(:default_refund_reason) do
|
|
7
|
+
Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
describe '#create' do
|
|
11
|
+
let(:customer_return) { create(:customer_return, line_items_count: 1) }
|
|
12
|
+
let(:order) { customer_return.order }
|
|
13
|
+
let(:return_item) { customer_return.return_items.first }
|
|
14
|
+
let(:payment) { order.payments.first }
|
|
15
|
+
|
|
16
|
+
subject do
|
|
17
|
+
spree_post :create, order_id: order.to_param, build_from_customer_return_id: customer_return.id
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'creates the reimbursement' do
|
|
21
|
+
expect { subject }.to change { order.reimbursements.count }.by(1)
|
|
22
|
+
expect(assigns(:reimbursement).return_items.to_a).to eq customer_return.return_items.to_a
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'redirects to the edit page' do
|
|
26
|
+
subject
|
|
27
|
+
expect(response).to redirect_to(spree.edit_admin_order_reimbursement_path(order, assigns(:reimbursement)))
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe "#perform" do
|
|
32
|
+
let(:reimbursement) { create(:reimbursement) }
|
|
33
|
+
let(:customer_return) { reimbursement.customer_return }
|
|
34
|
+
let(:order) { reimbursement.order }
|
|
35
|
+
let(:return_items) { reimbursement.return_items }
|
|
36
|
+
let(:payment) { order.payments.first }
|
|
37
|
+
|
|
38
|
+
subject do
|
|
39
|
+
spree_post :perform, order_id: order.to_param, id: reimbursement.to_param
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'redirects to customer return page' do
|
|
43
|
+
subject
|
|
44
|
+
expect(response).to redirect_to spree.admin_order_reimbursement_path(order, reimbursement)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'performs the reimbursement' do
|
|
48
|
+
expect {
|
|
49
|
+
subject
|
|
50
|
+
}.to change { payment.refunds.count }.by(1)
|
|
51
|
+
expect(payment.refunds.last.amount).to be > 0
|
|
52
|
+
expect(payment.refunds.last.amount).to eq return_items.to_a.sum(&:total)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context "a Spree::Core::GatewayError is raised" do
|
|
56
|
+
before(:each) do
|
|
57
|
+
def controller.perform
|
|
58
|
+
raise Spree::Core::GatewayError.new('An error has occurred')
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "sets an error message with the correct text" do
|
|
63
|
+
subject
|
|
64
|
+
expect(flash[:error]).to eq 'An error has occurred'
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it 'redirects to the edit page' do
|
|
68
|
+
subject
|
|
69
|
+
redirect_path = spree.edit_admin_order_reimbursement_path(order, assigns(:reimbursement))
|
|
70
|
+
expect(response).to redirect_to(redirect_path)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Admin::ReportsController, :type => :controller do
|
|
4
|
+
stub_authorization!
|
|
5
|
+
|
|
6
|
+
describe 'ReportsController.available_reports' do
|
|
7
|
+
it 'should contain sales_total' do
|
|
8
|
+
expect(Spree::Admin::ReportsController.available_reports.keys.include?(:sales_total)).to be true
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'should have the proper sales total report description' do
|
|
12
|
+
expect(Spree::Admin::ReportsController.available_reports[:sales_total][:description]).to eql('Sales Total For All Orders')
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe 'ReportsController.add_available_report!' do
|
|
18
|
+
context 'when adding the report name' do
|
|
19
|
+
it 'should contain the report' do
|
|
20
|
+
Spree::Admin::ReportsController.add_available_report!(:some_report)
|
|
21
|
+
expect(Spree::Admin::ReportsController.available_reports.keys.include?(:some_report)).to be true
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe 'GET index' do
|
|
27
|
+
it 'should be ok' do
|
|
28
|
+
spree_get :index
|
|
29
|
+
expect(response).to be_ok
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'should respond to model_class as Spree::AdminReportsController' do
|
|
34
|
+
expect(controller.send(:model_class)).to eql(Spree::Admin::ReportsController)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
after(:each) do
|
|
38
|
+
Spree::Admin::ReportsController.available_reports.delete_if do |key, value|
|
|
39
|
+
key != :sales_total
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Spree
|
|
4
|
+
module Admin
|
|
5
|
+
class WidgetsController < Spree::Admin::ResourceController
|
|
6
|
+
prepend_view_path('spec/test_views')
|
|
7
|
+
|
|
8
|
+
def model_class
|
|
9
|
+
Widget
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe Spree::Admin::WidgetsController, :type => :controller do
|
|
16
|
+
stub_authorization!
|
|
17
|
+
|
|
18
|
+
after(:all) do
|
|
19
|
+
# Spree::Core::Engine.routes.reload_routes!
|
|
20
|
+
Rails.application.reload_routes!
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
with_model 'Widget' do
|
|
24
|
+
table do |t|
|
|
25
|
+
t.string :name
|
|
26
|
+
t.integer :position
|
|
27
|
+
t.timestamps null: false
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
model do
|
|
31
|
+
acts_as_list
|
|
32
|
+
validates :name, presence: true
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
before do
|
|
37
|
+
Spree::Core::Engine.routes.draw do
|
|
38
|
+
namespace :admin do
|
|
39
|
+
resources :widgets do
|
|
40
|
+
post :update_positions, on: :member
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
stub_const('Spree::Widget', Widget)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe '#new' do
|
|
48
|
+
subject do
|
|
49
|
+
spree_get :new
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'succeeds' do
|
|
53
|
+
subject
|
|
54
|
+
expect(response).to be_success
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe '#edit' do
|
|
59
|
+
let(:widget) { Widget.create!(name: 'a widget') }
|
|
60
|
+
|
|
61
|
+
subject do
|
|
62
|
+
spree_get :edit, id: widget.to_param
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'succeeds' do
|
|
66
|
+
subject
|
|
67
|
+
expect(response).to be_success
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe '#create' do
|
|
72
|
+
let(:params) do
|
|
73
|
+
{widget: {name: 'a widget'}}
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
subject { spree_post :create, params }
|
|
77
|
+
|
|
78
|
+
it 'creates the resource' do
|
|
79
|
+
expect { subject }.to change { Widget.count }.by(1)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
context 'failure' do
|
|
83
|
+
let(:params) do
|
|
84
|
+
{widget: {name: ''}} # blank name generates an error
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'sets a flash error' do
|
|
88
|
+
subject
|
|
89
|
+
expect(flash[:error]).to eq assigns(:widget).errors.full_messages.join(', ')
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
context 'without any parameters' do
|
|
94
|
+
let(:params) { {} }
|
|
95
|
+
|
|
96
|
+
before do
|
|
97
|
+
allow_any_instance_of(Widget).to receive(:name).and_return('some name')
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it 'creates the resource' do
|
|
101
|
+
expect { subject }.to change { Widget.count }.by(1)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
describe '#update' do
|
|
107
|
+
let(:widget) { Widget.create!(name: 'a widget') }
|
|
108
|
+
|
|
109
|
+
let(:params) do
|
|
110
|
+
{
|
|
111
|
+
id: widget.to_param,
|
|
112
|
+
widget: {name: 'widget renamed'},
|
|
113
|
+
}
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
subject { spree_put :update, params }
|
|
117
|
+
|
|
118
|
+
it 'updates the resource' do
|
|
119
|
+
expect { subject }.to change { widget.reload.name }.from('a widget').to('widget renamed')
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
context 'failure' do
|
|
123
|
+
let(:params) do
|
|
124
|
+
{
|
|
125
|
+
id: widget.to_param,
|
|
126
|
+
widget: {name: ''}, # a blank name will trigger a validation error
|
|
127
|
+
}
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it 'sets a flash error' do
|
|
131
|
+
subject
|
|
132
|
+
expect(flash[:error]).to eq assigns(:widget).errors.full_messages.join(', ')
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
describe '#destroy' do
|
|
138
|
+
let!(:widget) { Widget.create!(name: 'a widget') }
|
|
139
|
+
let(:params) { {id: widget.id} }
|
|
140
|
+
|
|
141
|
+
subject {
|
|
142
|
+
spree_delete :destroy, params
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
it 'destroys the resource' do
|
|
146
|
+
expect { subject }.to change { Widget.count }.from(1).to(0)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
describe '#update_positions' do
|
|
151
|
+
let(:widget_1) { Widget.create!(name: 'widget 1', position: 1) }
|
|
152
|
+
let(:widget_2) { Widget.create!(name: 'widget 2', position: 2) }
|
|
153
|
+
|
|
154
|
+
subject do
|
|
155
|
+
spree_post :update_positions, id: widget_1.to_param,
|
|
156
|
+
positions: { widget_1.id => '2', widget_2.id => '1' }, format: 'js'
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
it 'updates the position of widget 1' do
|
|
160
|
+
expect { subject }.to change { widget_1.reload.position }.from(1).to(2)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
it 'updates the position of widget 2' do
|
|
164
|
+
expect { subject }.to change { widget_2.reload.position }.from(2).to(1)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it 'touches updated_at' do
|
|
168
|
+
expect { subject }.to change { widget_1.reload.updated_at }
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
module Spree
|
|
174
|
+
module Submodule
|
|
175
|
+
class Post < Spree::Base
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
module Admin
|
|
179
|
+
module Submodule
|
|
180
|
+
class PostsController < Spree::Admin::ResourceController
|
|
181
|
+
prepend_view_path('spec/test_views')
|
|
182
|
+
|
|
183
|
+
def model_class
|
|
184
|
+
Spree::Submodule::Post
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
describe Spree::Admin::Submodule::PostsController, type: :controller do
|
|
192
|
+
stub_authorization!
|
|
193
|
+
|
|
194
|
+
after(:all) do
|
|
195
|
+
# Spree::Core::Engine.routes.reload_routes!
|
|
196
|
+
Rails.application.reload_routes!
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
with_table 'spree_posts' do |t|
|
|
200
|
+
t.string :name
|
|
201
|
+
t.integer :position
|
|
202
|
+
t.timestamps null: false
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
before do
|
|
206
|
+
Spree::Core::Engine.routes.draw do
|
|
207
|
+
namespace :admin do
|
|
208
|
+
namespace :submodule do
|
|
209
|
+
resources :posts
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
describe '#new' do
|
|
216
|
+
subject do
|
|
217
|
+
spree_get :new
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
it 'succeeds' do
|
|
221
|
+
subject
|
|
222
|
+
expect(response).to be_success
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
describe '#edit' do
|
|
227
|
+
let(:submodule_post) { Spree::Submodule::Post.create!(name: 'a post') }
|
|
228
|
+
|
|
229
|
+
subject do
|
|
230
|
+
spree_get :edit, id: submodule_post.to_param
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
it 'succeeds' do
|
|
234
|
+
subject
|
|
235
|
+
expect(response).to be_success
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
describe '#create' do
|
|
240
|
+
let(:params) do
|
|
241
|
+
{ submodule_post: { name: 'a post' } }
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
subject { spree_post :create, params }
|
|
245
|
+
|
|
246
|
+
it 'creates the resource' do
|
|
247
|
+
expect { subject }.to change { Spree::Submodule::Post.count }.by(1)
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
describe '#update' do
|
|
252
|
+
let(:post) { Spree::Submodule::Post.create!(name: 'a post') }
|
|
253
|
+
|
|
254
|
+
let(:params) do
|
|
255
|
+
{ id: post.to_param, submodule_post: { name: 'post renamed' } }
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
subject { spree_put :update, params }
|
|
259
|
+
|
|
260
|
+
it 'updates the resource' do
|
|
261
|
+
expect { subject }.to change { post.reload.name }.from('a post').to('post renamed')
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
describe '#destroy' do
|
|
266
|
+
let!(:post) { Spree::Submodule::Post.create!(name: 'a post') }
|
|
267
|
+
let(:params) { { id: post.id } }
|
|
268
|
+
|
|
269
|
+
subject { spree_delete :destroy, params }
|
|
270
|
+
|
|
271
|
+
it 'destroys the resource' do
|
|
272
|
+
expect { subject }.to change { Spree::Submodule::Post.count }.from(1).to(0)
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
|