solidus_backend 1.0.2 → 1.0.3

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.

Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -0
  3. data/Gemfile +6 -0
  4. data/Rakefile +15 -0
  5. data/script/rails +9 -0
  6. data/solidus_backend.gemspec +28 -0
  7. data/spec/controllers/spree/admin/base_controller_spec.rb +24 -0
  8. data/spec/controllers/spree/admin/cancellations_controller_spec.rb +77 -0
  9. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +234 -0
  10. data/spec/controllers/spree/admin/general_settings_controller_spec.rb +41 -0
  11. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +18 -0
  12. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +80 -0
  13. data/spec/controllers/spree/admin/orders_controller_spec.rb +472 -0
  14. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +49 -0
  15. data/spec/controllers/spree/admin/payments_controller_spec.rb +175 -0
  16. data/spec/controllers/spree/admin/products_controller_spec.rb +45 -0
  17. data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +21 -0
  18. data/spec/controllers/spree/admin/promotion_codes_controller_spec.rb +18 -0
  19. data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +21 -0
  20. data/spec/controllers/spree/admin/promotions_controller_spec.rb +122 -0
  21. data/spec/controllers/spree/admin/refunds_controller_spec.rb +32 -0
  22. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +75 -0
  23. data/spec/controllers/spree/admin/reports_controller_spec.rb +134 -0
  24. data/spec/controllers/spree/admin/resource_controller_spec.rb +166 -0
  25. data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +226 -0
  26. data/spec/controllers/spree/admin/return_items_controller_spec.rb +27 -0
  27. data/spec/controllers/spree/admin/root_controller_spec.rb +41 -0
  28. data/spec/controllers/spree/admin/search_controller_spec.rb +104 -0
  29. data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +14 -0
  30. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +50 -0
  31. data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +41 -0
  32. data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +331 -0
  33. data/spec/controllers/spree/admin/store_credits_controller_spec.rb +309 -0
  34. data/spec/controllers/spree/admin/users_controller_spec.rb +236 -0
  35. data/spec/controllers/spree/admin/variants_controller_spec.rb +32 -0
  36. data/spec/features/admin/configuration/analytics_tracker_spec.rb +54 -0
  37. data/spec/features/admin/configuration/countries_spec.rb +22 -0
  38. data/spec/features/admin/configuration/general_settings_spec.rb +45 -0
  39. data/spec/features/admin/configuration/payment_methods_spec.rb +125 -0
  40. data/spec/features/admin/configuration/shipping_methods_spec.rb +64 -0
  41. data/spec/features/admin/configuration/states_spec.rb +64 -0
  42. data/spec/features/admin/configuration/stock_locations_spec.rb +50 -0
  43. data/spec/features/admin/configuration/tax_categories_spec.rb +56 -0
  44. data/spec/features/admin/configuration/tax_rates_spec.rb +30 -0
  45. data/spec/features/admin/configuration/taxonomies_spec.rb +52 -0
  46. data/spec/features/admin/configuration/zones_spec.rb +39 -0
  47. data/spec/features/admin/homepage_spec.rb +78 -0
  48. data/spec/features/admin/locale_spec.rb +30 -0
  49. data/spec/features/admin/orders/adjustments_promotions_spec.rb +53 -0
  50. data/spec/features/admin/orders/adjustments_spec.rb +126 -0
  51. data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +48 -0
  52. data/spec/features/admin/orders/cancelling_inventory_spec.rb +48 -0
  53. data/spec/features/admin/orders/customer_details_spec.rb +163 -0
  54. data/spec/features/admin/orders/line_items_spec.rb +50 -0
  55. data/spec/features/admin/orders/listing_spec.rb +130 -0
  56. data/spec/features/admin/orders/log_entries_spec.rb +55 -0
  57. data/spec/features/admin/orders/new_order_spec.rb +185 -0
  58. data/spec/features/admin/orders/order_details_spec.rb +533 -0
  59. data/spec/features/admin/orders/payments_spec.rb +228 -0
  60. data/spec/features/admin/orders/risk_analysis_spec.rb +47 -0
  61. data/spec/features/admin/orders/shipments_spec.rb +65 -0
  62. data/spec/features/admin/payments/store_credits_spec.rb +21 -0
  63. data/spec/features/admin/products/edit/images_spec.rb +87 -0
  64. data/spec/features/admin/products/edit/products_spec.rb +66 -0
  65. data/spec/features/admin/products/edit/taxons_spec.rb +43 -0
  66. data/spec/features/admin/products/edit/variants_spec.rb +61 -0
  67. data/spec/features/admin/products/option_types_spec.rb +114 -0
  68. data/spec/features/admin/products/products_spec.rb +392 -0
  69. data/spec/features/admin/products/properties_spec.rb +139 -0
  70. data/spec/features/admin/products/prototypes_spec.rb +110 -0
  71. data/spec/features/admin/products/stock_management_spec.rb +82 -0
  72. data/spec/features/admin/products/variant_spec.rb +51 -0
  73. data/spec/features/admin/promotion_adjustments_spec.rb +220 -0
  74. data/spec/features/admin/promotions/tiered_calculator_spec.rb +69 -0
  75. data/spec/features/admin/reports_spec.rb +61 -0
  76. data/spec/features/admin/stock_transfer_spec.rb +86 -0
  77. data/spec/features/admin/store_credits_spec.rb +82 -0
  78. data/spec/features/admin/taxons_spec.rb +31 -0
  79. data/spec/features/admin/users_spec.rb +270 -0
  80. data/spec/helpers/admin/base_helper_spec.rb +24 -0
  81. data/spec/helpers/admin/navigation_helper_spec.rb +73 -0
  82. data/spec/helpers/admin/reimbursements_helper_spec.rb +34 -0
  83. data/spec/helpers/admin/stock_movements_helper_spec.rb +29 -0
  84. data/spec/helpers/admin/store_credit_events_helper_spec.rb +95 -0
  85. data/spec/helpers/promotion_rules_helper_spec.rb +12 -0
  86. data/spec/spec_helper.rb +108 -0
  87. data/spec/support/appear_before_matcher.rb +8 -0
  88. data/spec/support/ror_ringer.jpeg +0 -0
  89. data/spec/test_views/spree/admin/widgets/edit.html.erb +1 -0
  90. data/spec/test_views/spree/admin/widgets/new.html.erb +1 -0
  91. metadata +95 -6
@@ -0,0 +1,49 @@
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
+ context "tries to save invalid payment" do
24
+ it "doesn't break, responds nicely" do
25
+ expect {
26
+ spree_post :create, :payment_method => { :name => "", :type => "Spree::Gateway::Bogus" }
27
+ }.not_to raise_error
28
+ end
29
+ end
30
+
31
+ it "can create a payment method of a valid type" do
32
+ expect {
33
+ spree_post :create, :payment_method => { :name => "Test Method", :type => "Spree::Gateway::Bogus" }
34
+ }.to change(Spree::PaymentMethod, :count).by(1)
35
+
36
+ expect(response).to be_redirect
37
+ expect(response).to redirect_to spree.edit_admin_payment_method_path(assigns(:payment_method))
38
+ end
39
+
40
+ it "can not create a payment method of an invalid type" do
41
+ expect {
42
+ spree_post :create, :payment_method => { :name => "Invalid Payment Method", :type => "Spree::InvalidType" }
43
+ }.to change(Spree::PaymentMethod, :count).by(0)
44
+
45
+ expect(response).to be_redirect
46
+ expect(response).to redirect_to spree.new_admin_payment_method_path
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,175 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ module Admin
5
+ describe PaymentsController, :type => :controller do
6
+ before do
7
+ allow(controller).to receive_messages :spree_current_user => user
8
+ end
9
+
10
+ let(:user) { create(:admin_user) }
11
+ let(:order) { create(:order) }
12
+
13
+ context "with a valid credit card" do
14
+ let(:order) { create(:order_with_line_items, :state => "payment") }
15
+ let(:payment_method) { create(:credit_card_payment_method, :display_on => "back_end") }
16
+ let(:attributes) do
17
+ {
18
+ :order_id => order.number,
19
+ :card => "new",
20
+ :payment => {
21
+ :amount => order.total,
22
+ :payment_method_id => payment_method.id.to_s,
23
+ :source_attributes => {
24
+ :name => "Test User",
25
+ :number => "4111 1111 1111 1111",
26
+ :expiry => "09 / #{Time.now.year + 1}",
27
+ :verification_value => "123"
28
+ }
29
+ }
30
+ }
31
+ end
32
+
33
+ before do
34
+ spree_post :create, attributes
35
+ end
36
+
37
+ it "should process payment correctly" do
38
+ expect(order.payments.count).to eq(1)
39
+ expect(order.payments.last.state).to eq 'checkout'
40
+ expect(response).to redirect_to(spree.admin_order_payments_path(order))
41
+ expect(order.reload.state).to eq('confirm')
42
+ end
43
+
44
+ context 'with credit card address fields' do
45
+ let(:address) { build(:address) }
46
+
47
+ let(:attributes) do
48
+ attrs = super()
49
+ attrs[:payment][:source_attributes][:address_attributes] = address_attributes
50
+ attrs
51
+ end
52
+
53
+ let(:address_attributes) do
54
+ {
55
+ 'firstname' => address.firstname,
56
+ 'lastname' => address.lastname,
57
+ 'address1' => address.address1,
58
+ 'city' => address.city,
59
+ 'country_id' => address.country_id,
60
+ 'state_id' => address.state_id,
61
+ 'zipcode' => address.zipcode,
62
+ 'phone' => address.phone,
63
+ }
64
+ end
65
+
66
+ it 'associates the address' do
67
+ expect(order.payments.count).to eq(1)
68
+ credit_card = order.payments.last.source
69
+ expect(credit_card.address.attributes).to include(address_attributes)
70
+ end
71
+ end
72
+ end
73
+
74
+ # Regression test for #3233
75
+ context "with a backend payment method" do
76
+ before do
77
+ @payment_method = create(:check_payment_method, :display_on => "back_end")
78
+ end
79
+
80
+ it "loads backend payment methods" do
81
+ spree_get :new, :order_id => order.number
82
+ expect(response.status).to eq(200)
83
+ expect(assigns[:payment_methods]).to include(@payment_method)
84
+ end
85
+ end
86
+
87
+ context "order has billing address" do
88
+ before do
89
+ order.bill_address = create(:address)
90
+ order.save!
91
+ end
92
+
93
+ context "order does not have payments" do
94
+ it "redirect to new payments page" do
95
+ spree_get :index, { amount: 100, order_id: order.number }
96
+ expect(response).to redirect_to(spree.new_admin_order_payment_path(order))
97
+ end
98
+ end
99
+
100
+ context "order has payments" do
101
+ before do
102
+ order.payments << create(:payment, amount: order.total, order: order, state: 'completed')
103
+ end
104
+
105
+ it "shows the payments page" do
106
+ spree_get :index, { amount: 100, order_id: order.number }
107
+ expect(response.code).to eq "200"
108
+ end
109
+ end
110
+
111
+ end
112
+
113
+ context "order does not have a billing address" do
114
+ before do
115
+ order.bill_address = nil
116
+ order.save
117
+ end
118
+
119
+ it "should redirect to the customer details page" do
120
+ spree_get :index, { amount: 100, order_id: order.number }
121
+ expect(response).to redirect_to(spree.edit_admin_order_customer_path(order))
122
+ end
123
+ end
124
+
125
+ describe 'fire' do
126
+ describe 'authorization' do
127
+ let(:payment) { create(:payment, state: 'checkout') }
128
+ let(:order) { payment.order }
129
+
130
+ context 'the user is authorized' do
131
+ class CaptureAllowedAbility
132
+ include CanCan::Ability
133
+
134
+ def initialize(user)
135
+ can :capture, Spree::Payment
136
+ end
137
+ end
138
+
139
+ before do
140
+ Spree::Ability.register_ability(CaptureAllowedAbility)
141
+ end
142
+
143
+ it 'allows the action' do
144
+ expect {
145
+ spree_post(:fire, id: payment.to_param, e: 'capture', order_id: order.to_param)
146
+ }.to change { payment.reload.state }.from('checkout').to('completed')
147
+ end
148
+ end
149
+
150
+ context 'the user is not authorized' do
151
+ class CaptureNotAllowedAbility
152
+ include CanCan::Ability
153
+
154
+ def initialize(user)
155
+ cannot :capture, Spree::Payment
156
+ end
157
+ end
158
+
159
+ before do
160
+ Spree::Ability.register_ability(CaptureNotAllowedAbility)
161
+ end
162
+
163
+ it 'does not allow the action' do
164
+ expect {
165
+ spree_post(:fire, id: payment.to_param, e: 'capture', order_id: order.to_param)
166
+ }.to_not change { payment.reload.state }
167
+ expect(flash[:error]).to eq('Authorization Failure')
168
+ end
169
+ end
170
+ end
171
+ end
172
+
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,45 @@
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
+ 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,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Admin::PromotionCodesController do
4
+ stub_authorization!
5
+ render_views
6
+
7
+ let!(:promotion) { create(:promotion) }
8
+ let!(:code1) { create(:promotion_code, promotion: promotion) }
9
+ let!(:code2) { create(:promotion_code, promotion: promotion) }
10
+ let!(:code3) { create(:promotion_code, promotion: promotion) }
11
+
12
+ it "can create a promotion rule of a valid type" do
13
+ spree_get :index, promotion_id: promotion.id, format: 'csv'
14
+ expect(response).to be_success
15
+ parsed = CSV.parse(response.body, headers: true)
16
+ expect(parsed.entries.map(&:to_h)).to eq([{"Code" => code1.value}, {"Code" => code2.value}, {"Code" => code3.value}])
17
+ end
18
+ 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,122 @@
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
+ describe "#index" do
11
+
12
+ it "succeeds" do
13
+ spree_get :index
14
+ expect(assigns[:promotions]).to match_array [promotion2, promotion1]
15
+ end
16
+
17
+ it "assigns promotion categories" do
18
+ spree_get :index
19
+ expect(assigns[:promotion_categories]).to match_array [category]
20
+ end
21
+
22
+ context "search" do
23
+ it "pages results" do
24
+ spree_get :index, per_page: '1'
25
+ expect(assigns[:promotions]).to eq [promotion2]
26
+ end
27
+
28
+ it "filters by name" do
29
+ spree_get :index, q: {name_cont: promotion1.name}
30
+ expect(assigns[:promotions]).to eq [promotion1]
31
+ end
32
+
33
+ it "filters by code" do
34
+ spree_get :index, q: {codes_value_cont: promotion1.codes.first.value }
35
+ expect(assigns[:promotions]).to eq [promotion1]
36
+ end
37
+
38
+ it "filters by path" do
39
+ spree_get :index, q: {path_cont: promotion1.path}
40
+ expect(assigns[:promotions]).to eq [promotion1]
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "#create" do
46
+ subject { spree_post :create, params }
47
+ let(:params) { {promotion: {name: 'some promo'}} }
48
+
49
+ context "it succeeds" do
50
+ it "creates a promotion" do
51
+ expect { subject }.to change { Spree::Promotion.count }.by(1)
52
+ end
53
+
54
+ it "sets the flash message" do
55
+ subject
56
+ expect(flash[:success]).to eq "Promotion has been successfully created!"
57
+ end
58
+
59
+ it "redirects to promotion edit" do
60
+ subject
61
+ expect(response).to redirect_to "http://test.host/admin/promotions/#{assigns(:promotion).id}/edit"
62
+ end
63
+
64
+ context "with one promo codes" do
65
+ let(:params) do
66
+ super().merge(promotion_builder: { base_code: 'abc', number_of_codes: 1 })
67
+ end
68
+
69
+ it "succeeds and creates one code" do
70
+ expect {
71
+ expect {
72
+ subject
73
+ }.to change { Spree::Promotion.count }.by(1)
74
+ }.to change { Spree::PromotionCode.count }.by(1)
75
+
76
+ expect(assigns(:promotion).codes.first.value).to eq ('abc')
77
+ end
78
+ end
79
+
80
+ context "with multiple promo codes" do
81
+ let(:params) do
82
+ super().merge(promotion_builder: { base_code: 'abc', number_of_codes: 2 })
83
+ end
84
+
85
+ it "succeeds and creates multiple codes" do
86
+ expect {
87
+ expect {
88
+ subject
89
+ }.to change { Spree::Promotion.count }.by(1)
90
+ }.to change { Spree::PromotionCode.count }.by(2)
91
+
92
+ codes = assigns(:promotion).codes.map(&:value).sort
93
+ expect(codes.length).to be 2
94
+ expect(codes[0]).to match(/abc_[a-z]{6}/)
95
+ expect(codes[1]).to match(/abc_[a-z]{6}/)
96
+ end
97
+ end
98
+ end
99
+
100
+ context "it fails" do
101
+ let(:params) { {} }
102
+
103
+ it "does not create a promotion" do
104
+ expect {
105
+ subject
106
+ }.not_to change { Spree::Promotion.count }
107
+ end
108
+
109
+ it "sets the flash error" do
110
+ subject
111
+ expect(flash[:error]).to eq "Name can't be blank"
112
+ end
113
+
114
+ it "renders new" do
115
+ subject
116
+ expect(response).to render_template :new
117
+ end
118
+ end
119
+
120
+ end
121
+
122
+ end