spree_backend 3.2.9 → 3.3.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/spree/backend/admin.js +16 -15
  3. data/app/assets/javascripts/spree/backend/checkouts/edit.js +25 -26
  4. data/app/assets/javascripts/spree/backend/general_settings.js.coffee +10 -12
  5. data/app/assets/javascripts/spree/backend/payments/edit.js.coffee +4 -6
  6. data/app/assets/javascripts/spree/backend/returns/return_item_selection.js +7 -1
  7. data/app/assets/javascripts/spree/backend/stock_transfer.js.coffee +4 -1
  8. data/app/assets/javascripts/spree/backend/user_picker.js +3 -1
  9. data/app/assets/javascripts/spree/backend.js +3 -3
  10. data/app/controllers/spree/admin/countries_controller.rb +1 -0
  11. data/app/controllers/spree/admin/log_entries_controller.rb +2 -2
  12. data/app/controllers/spree/admin/orders/customer_details_controller.rb +5 -6
  13. data/app/controllers/spree/admin/orders_controller.rb +4 -4
  14. data/app/controllers/spree/admin/payments_controller.rb +21 -10
  15. data/app/controllers/spree/admin/products_controller.rb +5 -0
  16. data/app/controllers/spree/admin/promotion_rules_controller.rb +11 -7
  17. data/app/controllers/spree/admin/stock_transfers_controller.rb +1 -1
  18. data/app/controllers/spree/admin/taxons_controller.rb +31 -23
  19. data/app/helpers/spree/admin/base_helper.rb +1 -1
  20. data/app/helpers/spree/admin/navigation_helper.rb +10 -4
  21. data/app/views/spree/admin/adjustments/_adjustments_table.html.erb +2 -2
  22. data/app/views/spree/admin/general_settings/edit.html.erb +8 -8
  23. data/app/views/spree/admin/images/_form.html.erb +2 -2
  24. data/app/views/spree/admin/images/edit.html.erb +2 -2
  25. data/app/views/spree/admin/images/new.html.erb +1 -1
  26. data/app/views/spree/admin/option_types/_form.html.erb +2 -2
  27. data/app/views/spree/admin/option_types/index.html.erb +4 -4
  28. data/app/views/spree/admin/orders/_line_items.html.erb +40 -38
  29. data/app/views/spree/admin/orders/_shipment.html.erb +77 -76
  30. data/app/views/spree/admin/orders/customer_details/_form.html.erb +5 -5
  31. data/app/views/spree/admin/orders/index.html.erb +16 -16
  32. data/app/views/spree/admin/payment_methods/_form.html.erb +2 -2
  33. data/app/views/spree/admin/payments/_list.html.erb +1 -1
  34. data/app/views/spree/admin/products/_add_stock_form.html.erb +3 -3
  35. data/app/views/spree/admin/products/_form.html.erb +16 -16
  36. data/app/views/spree/admin/products/index.html.erb +4 -4
  37. data/app/views/spree/admin/products/new.html.erb +8 -8
  38. data/app/views/spree/admin/promotion_categories/index.html.erb +3 -3
  39. data/app/views/spree/admin/promotions/_form.html.erb +3 -3
  40. data/app/views/spree/admin/promotions/_promotion_rule.html.erb +1 -1
  41. data/app/views/spree/admin/promotions/actions/_create_adjustment.html.erb +2 -2
  42. data/app/views/spree/admin/promotions/actions/_create_item_adjustments.html.erb +2 -2
  43. data/app/views/spree/admin/promotions/actions/_create_line_items.html.erb +2 -4
  44. data/app/views/spree/admin/promotions/edit.html.erb +3 -3
  45. data/app/views/spree/admin/promotions/index.html.erb +6 -6
  46. data/app/views/spree/admin/promotions/rules/_item_total.html.erb +2 -2
  47. data/app/views/spree/admin/promotions/rules/_option_value.html.erb +4 -4
  48. data/app/views/spree/admin/properties/_form.html.erb +2 -2
  49. data/app/views/spree/admin/properties/index.html.erb +6 -6
  50. data/app/views/spree/admin/prototypes/index.html.erb +4 -4
  51. data/app/views/spree/admin/reimbursement_types/_form.html.erb +4 -4
  52. data/app/views/spree/admin/reimbursements/edit.html.erb +1 -1
  53. data/app/views/spree/admin/return_authorizations/_form.html.erb +13 -1
  54. data/app/views/spree/admin/return_index/customer_returns.html.erb +2 -2
  55. data/app/views/spree/admin/return_index/return_authorizations.html.erb +5 -5
  56. data/app/views/spree/admin/shared/_content_header.html.erb +2 -2
  57. data/app/views/spree/admin/shared/_header.html.erb +2 -2
  58. data/app/views/spree/admin/shared/_index_table_options.html.erb +2 -2
  59. data/app/views/spree/admin/shared/_order_summary.html.erb +1 -1
  60. data/app/views/spree/admin/shared/_table_filter.html.erb +1 -1
  61. data/app/views/spree/admin/shared/_translations.html.erb +0 -1
  62. data/app/views/spree/admin/shared/_update_order_state.js.erb +1 -1
  63. data/app/views/spree/admin/shipping_methods/_form.html.erb +10 -10
  64. data/app/views/spree/admin/state_changes/index.html.erb +3 -3
  65. data/app/views/spree/admin/states/_form.html.erb +2 -2
  66. data/app/views/spree/admin/stock_locations/_form.html.erb +2 -2
  67. data/app/views/spree/admin/stock_locations/_transfer_stock_form.html.erb +4 -4
  68. data/app/views/spree/admin/stock_transfers/index.html.erb +3 -3
  69. data/app/views/spree/admin/stock_transfers/new.html.erb +2 -2
  70. data/app/views/spree/admin/store_credits/index.html.erb +1 -1
  71. data/app/views/spree/admin/tax_rates/_form.html.erb +2 -2
  72. data/app/views/spree/admin/taxonomies/_list.html.erb +2 -2
  73. data/app/views/spree/admin/taxonomies/{edit.erb → edit.html.erb} +0 -0
  74. data/app/views/spree/admin/taxonomies/index.html.erb +2 -2
  75. data/app/views/spree/admin/taxons/_form.html.erb +5 -5
  76. data/app/views/spree/admin/taxons/edit.html.erb +3 -0
  77. data/app/views/spree/admin/trackers/_form.html.erb +2 -2
  78. data/app/views/spree/admin/users/_addresses_form.html.erb +2 -2
  79. data/app/views/spree/admin/users/_form.html.erb +2 -2
  80. data/app/views/spree/admin/users/_user_page_actions.html.erb +1 -1
  81. data/app/views/spree/admin/users/index.html.erb +5 -5
  82. data/app/views/spree/admin/users/items.html.erb +1 -1
  83. data/app/views/spree/admin/users/orders.html.erb +1 -1
  84. data/app/views/spree/admin/variants/_form.html.erb +2 -2
  85. data/app/views/spree/admin/zones/_form.html.erb +2 -2
  86. data/app/views/spree/layouts/admin.html.erb +3 -3
  87. data/config/initializers/assets.rb +1 -1
  88. data/lib/spree/backend/engine.rb +0 -1
  89. data/spec/controllers/spree/admin/base_controller_spec.rb +46 -0
  90. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +185 -0
  91. data/spec/controllers/spree/admin/general_settings_controller_spec.rb +41 -0
  92. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +18 -0
  93. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +199 -0
  94. data/spec/controllers/spree/admin/orders_controller_spec.rb +296 -0
  95. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +64 -0
  96. data/spec/controllers/spree/admin/payments_controller_spec.rb +97 -0
  97. data/spec/controllers/spree/admin/products_controller_spec.rb +137 -0
  98. data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +21 -0
  99. data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +21 -0
  100. data/spec/controllers/spree/admin/promotions_controller_spec.rb +44 -0
  101. data/spec/controllers/spree/admin/refunds_controller_spec.rb +32 -0
  102. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +74 -0
  103. data/spec/controllers/spree/admin/reports_controller_spec.rb +42 -0
  104. data/spec/controllers/spree/admin/resource_controller_spec.rb +252 -0
  105. data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +225 -0
  106. data/spec/controllers/spree/admin/return_index_controller_spec.rb +37 -0
  107. data/spec/controllers/spree/admin/return_items_controller_spec.rb +27 -0
  108. data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +14 -0
  109. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +19 -0
  110. data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +41 -0
  111. data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +41 -0
  112. data/spec/controllers/spree/admin/tax_categories_controller_spec.rb +34 -0
  113. data/spec/controllers/spree/admin/users_controller_spec.rb +161 -0
  114. data/spec/controllers/spree/admin/variants_controller_spec.rb +32 -0
  115. data/spec/features/admin/configuration/analytics_tracker_spec.rb +47 -0
  116. data/spec/features/admin/configuration/countries_spec.rb +24 -0
  117. data/spec/features/admin/configuration/general_settings_spec.rb +44 -0
  118. data/spec/features/admin/configuration/payment_methods_spec.rb +63 -0
  119. data/spec/features/admin/configuration/roles_spec.rb +47 -0
  120. data/spec/features/admin/configuration/shipping_methods_spec.rb +62 -0
  121. data/spec/features/admin/configuration/states_spec.rb +68 -0
  122. data/spec/features/admin/configuration/stock_locations_spec.rb +48 -0
  123. data/spec/features/admin/configuration/store_credit_categories_spec.rb +50 -0
  124. data/spec/features/admin/configuration/tax_categories_spec.rb +56 -0
  125. data/spec/features/admin/configuration/tax_rates_spec.rb +18 -0
  126. data/spec/features/admin/configuration/zones_spec.rb +39 -0
  127. data/spec/features/admin/homepage_spec.rb +89 -0
  128. data/spec/features/admin/locale_spec.rb +31 -0
  129. data/spec/features/admin/orders/adjustments_promotions_spec.rb +53 -0
  130. data/spec/features/admin/orders/adjustments_spec.rb +124 -0
  131. data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +47 -0
  132. data/spec/features/admin/orders/customer_details_spec.rb +154 -0
  133. data/spec/features/admin/orders/line_items_spec.rb +51 -0
  134. data/spec/features/admin/orders/listing_spec.rb +224 -0
  135. data/spec/features/admin/orders/log_entries_spec.rb +55 -0
  136. data/spec/features/admin/orders/new_order_spec.rb +186 -0
  137. data/spec/features/admin/orders/order_details_spec.rb +660 -0
  138. data/spec/features/admin/orders/payments_spec.rb +244 -0
  139. data/spec/features/admin/orders/risk_analysis_spec.rb +48 -0
  140. data/spec/features/admin/orders/shipments_spec.rb +64 -0
  141. data/spec/features/admin/orders/state_changes_spec.rb +21 -0
  142. data/spec/features/admin/products/edit/images_spec.rb +86 -0
  143. data/spec/features/admin/products/edit/products_spec.rb +56 -0
  144. data/spec/features/admin/products/edit/taxons_spec.rb +41 -0
  145. data/spec/features/admin/products/edit/variants_spec.rb +56 -0
  146. data/spec/features/admin/products/option_types_spec.rb +114 -0
  147. data/spec/features/admin/products/products_spec.rb +445 -0
  148. data/spec/features/admin/products/properties_spec.rb +147 -0
  149. data/spec/features/admin/products/prototypes_spec.rb +112 -0
  150. data/spec/features/admin/products/stock_management_spec.rb +124 -0
  151. data/spec/features/admin/products/taxonomies_spec.rb +52 -0
  152. data/spec/features/admin/products/variant_spec.rb +50 -0
  153. data/spec/features/admin/promotions/adjustments_spec.rb +258 -0
  154. data/spec/features/admin/promotions/option_value_rule_spec.rb +70 -0
  155. data/spec/features/admin/promotions/tiered_calculator_spec.rb +70 -0
  156. data/spec/features/admin/refund_reasons/refund_reasons_spec.rb +57 -0
  157. data/spec/features/admin/reimbursement_type/edit_reimbursement_type_spec.rb +36 -0
  158. data/spec/features/admin/reimbursement_type/new_reimbursement_type_spec.rb +62 -0
  159. data/spec/features/admin/reports_spec.rb +61 -0
  160. data/spec/features/admin/return_authorization_reasons/return_authorization_reasons_spec.rb +63 -0
  161. data/spec/features/admin/returns/customer_returns_spec.rb +80 -0
  162. data/spec/features/admin/returns/return_authorizations_spec.rb +152 -0
  163. data/spec/features/admin/stock_transfer_spec.rb +91 -0
  164. data/spec/features/admin/store_credits_spec.rb +93 -0
  165. data/spec/features/admin/taxons_spec.rb +53 -0
  166. data/spec/features/admin/users_spec.rb +286 -0
  167. data/spec/helpers/admin/base_helper_spec.rb +30 -0
  168. data/spec/helpers/admin/navigation_helper_spec.rb +111 -0
  169. data/spec/helpers/admin/promotion_rules_helper_spec.rb +12 -0
  170. data/spec/helpers/admin/stock_movements_helper_spec.rb +30 -0
  171. data/spec/models/spree/resource_spec.rb +48 -0
  172. data/spec/routing/admin_path_spec.rb +22 -0
  173. data/spec/spec_helper.rb +144 -0
  174. data/spec/support/appear_before_matcher.rb +8 -0
  175. data/spec/support/ror_ringer.jpeg +0 -0
  176. data/spec/test_views/spree/admin/submodule/posts/edit.html.erb +1 -0
  177. data/spec/test_views/spree/admin/submodule/posts/new.html.erb +1 -0
  178. data/spec/test_views/spree/admin/widgets/edit.html.erb +1 -0
  179. data/spec/test_views/spree/admin/widgets/new.html.erb +1 -0
  180. data/spree_backend.gemspec +4 -4
  181. data/vendor/assets/javascripts/jquery.jstree/jquery.jstree.js +130 -154
  182. metadata +106 -29
  183. data/vendor/assets/images/jquery-ui/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  184. data/vendor/assets/images/jquery-ui/ui-bg_flat_0_eeeeee_40x100.png +0 -0
  185. data/vendor/assets/images/jquery-ui/ui-bg_flat_55_ffffff_40x100.png +0 -0
  186. data/vendor/assets/images/jquery-ui/ui-bg_flat_75_ffffff_40x100.png +0 -0
  187. data/vendor/assets/images/jquery-ui/ui-bg_glass_65_ffffff_1x400.png +0 -0
  188. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_100_f6f6f6_1x100.png +0 -0
  189. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_25_0073ea_1x100.png +0 -0
  190. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_50_dddddd_1x100.png +0 -0
  191. data/vendor/assets/images/jquery-ui/ui-icons_0073ea_256x240.png +0 -0
  192. data/vendor/assets/images/jquery-ui/ui-icons_454545_256x240.png +0 -0
  193. data/vendor/assets/images/jquery-ui/ui-icons_666666_256x240.png +0 -0
  194. data/vendor/assets/images/jquery-ui/ui-icons_ff0084_256x240.png +0 -0
  195. data/vendor/assets/images/jquery-ui/ui-icons_ffffff_256x240.png +0 -0
  196. data/vendor/assets/stylesheets/jquery-ui.datepicker.css.erb +0 -357
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ module Admin
5
+ describe StockItemsController, type: :controller do
6
+ stub_authorization!
7
+
8
+ context "formats" do
9
+ let!(:stock_item) { create(:variant).stock_items.first }
10
+
11
+ it "destroy stock item via js" do
12
+ expect {
13
+ spree_delete :destroy, format: :js, id: stock_item
14
+ }.to change{ StockItem.count }.by(-1)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ module Admin
5
+ describe StockLocationsController, type: :controller do
6
+ stub_authorization!
7
+
8
+ # Regression for #4272
9
+ context "with no countries present" do
10
+ it "cannot create a new stock location" do
11
+ spree_get :new
12
+ expect(flash[:error]).to eq(Spree.t(:stock_locations_need_a_default_country))
13
+ expect(response).to redirect_to(spree.admin_stock_locations_path)
14
+ end
15
+ end
16
+
17
+ context "with a default country present" do
18
+ before do
19
+ country = FactoryGirl.create(:country)
20
+ Spree::Config[:default_country_id] = country.id
21
+ end
22
+
23
+ it "can create a new stock location" do
24
+ spree_get :new
25
+ expect(response).to be_success
26
+ end
27
+ end
28
+
29
+ context "with a country with the ISO code of 'US' existing" do
30
+ before do
31
+ FactoryGirl.create(:country, iso: 'US')
32
+ end
33
+
34
+ it "can create a new stock location" do
35
+ spree_get :new
36
+ expect(response).to be_success
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ describe Admin::StockTransfersController, type: :controller do
5
+ stub_authorization!
6
+
7
+ let!(:stock_transfer1) {
8
+ StockTransfer.create do |transfer|
9
+ transfer.source_location_id = 1
10
+ transfer.destination_location_id = 2
11
+ transfer.reference = 'PO 666'
12
+ end }
13
+
14
+ let!(:stock_transfer2) {
15
+ StockTransfer.create do |transfer|
16
+ transfer.source_location_id = 3
17
+ transfer.destination_location_id = 4
18
+ transfer.reference = 'PO 666'
19
+ end }
20
+
21
+
22
+ context "#index" do
23
+ it "gets all transfers without search criteria" do
24
+ spree_get :index
25
+ expect(assigns[:stock_transfers].count).to eq 2
26
+ end
27
+
28
+ it "searches by source location" do
29
+ spree_get :index, q: { source_location_id_eq: 1 }
30
+ expect(assigns[:stock_transfers].count).to eq 1
31
+ expect(assigns[:stock_transfers]).to include(stock_transfer1)
32
+ end
33
+
34
+ it "searches by destination location" do
35
+ spree_get :index, q: { destination_location_id_eq: 4 }
36
+ expect(assigns[:stock_transfers].count).to eq 1
37
+ expect(assigns[:stock_transfers]).to include(stock_transfer2)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ module Admin
5
+ describe TaxCategoriesController, type: :controller do
6
+ stub_authorization!
7
+
8
+ describe 'GET #index' do
9
+ subject { spree_get :index }
10
+
11
+ it 'should be successful' do
12
+ expect(subject).to be_success
13
+ end
14
+ end
15
+
16
+ describe 'PUT #update' do
17
+ let(:tax_category) { create :tax_category }
18
+
19
+ subject { spree_put :update, {id: tax_category.id, tax_category: { name: 'Foo', tax_code: 'Bar' }}}
20
+
21
+ it 'should redirect' do
22
+ expect(subject).to be_redirect
23
+ end
24
+
25
+ it 'should update' do
26
+ subject
27
+ tax_category.reload
28
+ expect(tax_category.name).to eq('Foo')
29
+ expect(tax_category.tax_code).to eq('Bar')
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,161 @@
1
+ require 'spec_helper'
2
+ require 'spree/testing_support/bar_ability'
3
+
4
+ describe Spree::Admin::UsersController, type: :controller do
5
+ let(:user) { create(:user) }
6
+ let(:mock_user) { mock_model Spree.user_class }
7
+
8
+ before do
9
+ allow(controller).to receive_messages spree_current_user: user
10
+ user.spree_roles.clear
11
+ stub_const('Spree::User', user.class)
12
+ end
13
+
14
+ context "#show" do
15
+ before do
16
+ user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
17
+ end
18
+
19
+ it "redirects to edit" do
20
+ spree_get :show, id: user.id
21
+ expect(response).to redirect_to spree.edit_admin_user_path(user)
22
+ end
23
+ end
24
+
25
+ context '#authorize_admin' do
26
+ before { use_mock_user }
27
+
28
+ it 'grant access to users with an admin role' do
29
+ user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
30
+ spree_post :index
31
+ expect(response).to render_template :index
32
+ end
33
+
34
+ it "allows admins to update a user's API key" do
35
+ user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
36
+ expect(mock_user).to receive(:generate_spree_api_key!).and_return(true)
37
+ spree_put :generate_api_key, id: mock_user.id
38
+ expect(response).to redirect_to(spree.edit_admin_user_path(mock_user))
39
+ end
40
+
41
+ it "allows admins to clear a user's API key" do
42
+ user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
43
+ expect(mock_user).to receive(:clear_spree_api_key!).and_return(true)
44
+ spree_put :clear_api_key, id: mock_user.id
45
+ expect(response).to redirect_to(spree.edit_admin_user_path(mock_user))
46
+ end
47
+
48
+ it 'deny access to users with an bar role' do
49
+ user.spree_roles << Spree::Role.find_or_create_by(name: 'bar')
50
+ Spree::Ability.register_ability(BarAbility)
51
+ spree_post :index
52
+ expect(response).to redirect_to(spree.forbidden_path)
53
+ end
54
+
55
+ it 'deny access to users with an bar role' do
56
+ user.spree_roles << Spree::Role.find_or_create_by(name: 'bar')
57
+ Spree::Ability.register_ability(BarAbility)
58
+ spree_post :update, { id: '9' }
59
+ expect(response).to redirect_to(spree.forbidden_path)
60
+ end
61
+
62
+ it 'deny access to users without an admin role' do
63
+ allow(user).to receive_messages has_spree_role?: false
64
+ spree_post :index
65
+ expect(response).to redirect_to(spree.forbidden_path)
66
+ end
67
+ end
68
+
69
+ describe "#create" do
70
+ before do
71
+ use_mock_user
72
+ user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
73
+ end
74
+
75
+ it "can create a shipping_address" do
76
+ expect(Spree.user_class).to receive(:new).with(ActionController::Parameters.new(
77
+ "ship_address_attributes" => { "city" => "New York" }
78
+ ).permit(ship_address_attributes: permitted_address_attributes))
79
+ spree_post :create, user: { ship_address_attributes: { city: "New York" } }
80
+ end
81
+
82
+ it "can create a billing_address" do
83
+ expect(Spree.user_class).to receive(:new).with(ActionController::Parameters.new(
84
+ "bill_address_attributes" => { "city" => "New York" }
85
+ ).permit(bill_address_attributes: permitted_address_attributes))
86
+ spree_post :create, user: { bill_address_attributes: { city: "New York" } }
87
+ end
88
+ end
89
+
90
+ describe "#update" do
91
+ before do
92
+ use_mock_user
93
+ user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
94
+ end
95
+
96
+ it "allows shipping address attributes through" do
97
+ expect(mock_user).to receive(:update_attributes).with(ActionController::Parameters.new(
98
+ "ship_address_attributes" => { "city" => "New York" }
99
+ ).permit(ship_address_attributes: permitted_address_attributes))
100
+ spree_put :update, id: mock_user.id, user: { ship_address_attributes: { city: "New York" } }
101
+ end
102
+
103
+ it "allows billing address attributes through" do
104
+ expect(mock_user).to receive(:update_attributes).with(ActionController::Parameters.new(
105
+ "bill_address_attributes" => { "city" => "New York" }
106
+ ).permit(bill_address_attributes: permitted_address_attributes))
107
+ spree_put :update, id: mock_user.id, user: { bill_address_attributes: { city: "New York" } }
108
+ end
109
+
110
+ it "allows updating without password resetting" do
111
+ expect(mock_user).to receive(:update_attributes).with(hash_not_including(password: '', password_confirmation: ''))
112
+ spree_put :update, id: mock_user.id, user: { password: '', password_confirmation: '', email: 'spree@example.com' }
113
+ end
114
+ end
115
+
116
+ describe "#orders" do
117
+ let(:order) { create(:order) }
118
+ before do
119
+ user.orders << order
120
+ user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
121
+ end
122
+
123
+ it "assigns a list of the users orders" do
124
+ spree_get :orders, { id: user.id }
125
+ expect(assigns[:orders].count).to eq 1
126
+ expect(assigns[:orders].first).to eq order
127
+ end
128
+
129
+ it "assigns a ransack search for Spree::Order" do
130
+ spree_get :orders, { id: user.id }
131
+ expect(assigns[:search]).to be_a Ransack::Search
132
+ expect(assigns[:search].klass).to eq Spree::Order
133
+ end
134
+ end
135
+
136
+ describe "#items" do
137
+ let(:order) { create(:order) }
138
+ before do
139
+ user.orders << order
140
+ user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
141
+ end
142
+
143
+ it "assigns a list of the users orders" do
144
+ spree_get :items, { id: user.id }
145
+ expect(assigns[:orders].count).to eq 1
146
+ expect(assigns[:orders].first).to eq order
147
+ end
148
+
149
+ it "assigns a ransack search for Spree::Order" do
150
+ spree_get :items, { id: user.id }
151
+ expect(assigns[:search]).to be_a Ransack::Search
152
+ expect(assigns[:search].klass).to eq Spree::Order
153
+ end
154
+ end
155
+ end
156
+
157
+ def use_mock_user
158
+ allow(mock_user).to receive(:save).and_return(true)
159
+ allow(Spree.user_class).to receive(:find).with(mock_user.id.to_s).and_return(mock_user)
160
+ allow(Spree.user_class).to receive(:new).and_return(mock_user)
161
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ module Admin
5
+ describe VariantsController, type: :controller do
6
+ stub_authorization!
7
+
8
+ describe "#index" do
9
+ let(:product) { create(:product) }
10
+ let!(:variant_1) { create(:variant, product: product) }
11
+ let!(:variant_2) { create(:variant, product: product) }
12
+
13
+ context "deleted is not requested" do
14
+ it "assigns the variants for a requested product" do
15
+ spree_get :index, product_id: product.slug
16
+ expect(assigns(:collection)).to include variant_1
17
+ expect(assigns(:collection)).to include variant_2
18
+ end
19
+ end
20
+
21
+ context "deleted is requested" do
22
+ before { variant_2.destroy }
23
+ it "assigns only deleted variants for a requested product" do
24
+ spree_get :index, product_id: product.slug, deleted: "on"
25
+ expect(assigns(:collection)).not_to include variant_1
26
+ expect(assigns(:collection)).to include variant_2
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Analytics Tracker", type: :feature do
4
+ stub_authorization!
5
+
6
+ context "index" do
7
+ before(:each) do
8
+ create(:tracker)
9
+ create(:tracker, analytics_id: 'A200')
10
+ visit spree.admin_trackers_path
11
+ end
12
+
13
+ it "should have the right content" do
14
+ expect(page).to have_content("Analytics Trackers")
15
+ end
16
+
17
+ it "should have the right tabular values displayed" do
18
+ within_row(1) do
19
+ expect(column_text(1)).to eq("A100")
20
+ expect(column_text(2)).to eq("Yes")
21
+ end
22
+
23
+ within_row(2) do
24
+ expect(column_text(1)).to eq("A200")
25
+ expect(column_text(2)).to eq("Yes")
26
+ end
27
+ end
28
+ end
29
+
30
+ context "create" do
31
+ before(:each) do
32
+ visit spree.admin_trackers_path
33
+ end
34
+
35
+ it "should be able to create a new analytics tracker" do
36
+ click_link "admin_new_tracker_link"
37
+ fill_in "tracker_analytics_id", with: "A100"
38
+ click_button "Create"
39
+
40
+ expect(page).to have_content("successfully created!")
41
+ within_row(1) do
42
+ expect(column_text(1)).to eq("A100")
43
+ expect(column_text(2)).to eq("Yes")
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ describe "Countries", type: :feature do
5
+ stub_authorization!
6
+
7
+ it "deletes a state", js: true do
8
+ visit spree.admin_countries_path
9
+ click_link "New Country"
10
+
11
+ fill_in "Name", with: "Brazil"
12
+ fill_in "Iso Name", with: "BRL"
13
+ click_button "Create"
14
+
15
+ accept_alert do
16
+ click_icon :delete
17
+ end
18
+
19
+ wait_for_ajax
20
+
21
+ expect { Country.find(country.id) }.to raise_error(StandardError)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe "General Settings", type: :feature do
4
+ stub_authorization!
5
+
6
+ before(:each) do
7
+ store = create(:store, name: 'Test Store', url: 'test.example.org',
8
+ mail_from_address: 'test@example.org')
9
+ visit spree.edit_admin_general_settings_path
10
+ end
11
+
12
+ context "visiting general settings (admin)" do
13
+ it "should have the right content" do
14
+ expect(page).to have_content("General Settings")
15
+ expect(find("#store_name").value).to eq("Test Store")
16
+ expect(find("#store_url").value).to eq("test.example.org")
17
+ expect(find("#store_mail_from_address").value).to eq("test@example.org")
18
+ expect(page).to_not have_content(Spree.t(:security_settings))
19
+ end
20
+ end
21
+
22
+ context "editing general settings (admin)" do
23
+ it "should be able to update the site name" do
24
+ fill_in "store_name", with: "Spree Demo Site99"
25
+ fill_in "store_mail_from_address", with: "spree@example.org"
26
+ click_button "Update"
27
+
28
+ assert_successful_update_message(:general_settings)
29
+ expect(find("#store_name").value).to eq("Spree Demo Site99")
30
+ expect(find("#store_mail_from_address").value).to eq("spree@example.org")
31
+ end
32
+ end
33
+
34
+ context "clearing the cache", js: true do
35
+ it "should clear the cache" do
36
+ expect(page).to_not have_content(Spree.t(:clear_cache_ok))
37
+ expect(page).to have_content(Spree.t(:clear_cache_warning))
38
+
39
+ click_button "Clear Cache"
40
+
41
+ expect(page).to have_content(Spree.t(:clear_cache_ok))
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Payment Methods", type: :feature do
4
+ stub_authorization!
5
+
6
+ before(:each) do
7
+ visit spree.admin_payment_methods_path
8
+ end
9
+
10
+ context "admin visiting payment methods listing page" do
11
+ it "should display existing payment methods" do
12
+ create(:check_payment_method)
13
+ visit current_path
14
+
15
+ within("table#listing_payment_methods") do
16
+ expect(all("th")[1].text).to eq("Name")
17
+ expect(all("th")[2].text).to eq("Provider")
18
+ expect(all("th")[3].text).to eq("Display")
19
+ expect(all("th")[4].text).to eq("Active")
20
+ end
21
+
22
+ within('table#listing_payment_methods') do
23
+ expect(page).to have_content("Spree::PaymentMethod::Check")
24
+ end
25
+ end
26
+ end
27
+
28
+ context "admin creating a new payment method" do
29
+ it "should be able to create a new payment method" do
30
+ click_link "admin_new_payment_methods_link"
31
+ expect(page).to have_content("New Payment Method")
32
+ fill_in "payment_method_name", with: "check90"
33
+ fill_in "payment_method_description", with: "check90 desc"
34
+ select "PaymentMethod::Check", from: "gtwy-type"
35
+ click_button "Create"
36
+ expect(page).to have_content("successfully created!")
37
+ end
38
+ end
39
+
40
+ context "admin editing a payment method", js: true do
41
+ before(:each) do
42
+ create(:check_payment_method)
43
+ visit current_path
44
+
45
+ within("table#listing_payment_methods") do
46
+ click_icon(:edit)
47
+ end
48
+ end
49
+
50
+ it "should be able to edit an existing payment method" do
51
+ fill_in "payment_method_name", with: "Payment 99"
52
+ click_button "Update"
53
+ expect(page).to have_content("successfully updated!")
54
+ expect(find_field("payment_method_name").value).to eq("Payment 99")
55
+ end
56
+
57
+ it "should display validation errors" do
58
+ fill_in "payment_method_name", with: ""
59
+ click_button "Update"
60
+ expect(page).to have_content("Name can't be blank")
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Roles", type: :feature do
4
+ stub_authorization!
5
+
6
+ before(:each) do
7
+ create(:role, name: "admin")
8
+ create(:role, name: "user")
9
+ visit spree.admin_path
10
+ click_link "Configuration"
11
+ # Crap workaround for animation to finish expanding so click doesn't hit ReimbursementTypes.
12
+ sleep 1
13
+ click_link "Roles"
14
+ end
15
+
16
+ context "show" do
17
+ it "should display existing roles" do
18
+ within_row(1) { expect(page).to have_content("admin") }
19
+ within_row(2) { expect(page).to have_content("user") }
20
+ end
21
+ end
22
+
23
+ context "create" do
24
+ it "should be able to create a new role" do
25
+ click_link "admin_new_role_link"
26
+ expect(page).to have_content("New Role")
27
+ fill_in "role_name", with: "blogger"
28
+ click_button "Create"
29
+ expect(page).to have_content("successfully created!")
30
+ end
31
+ end
32
+
33
+ context "edit" do
34
+ it "should not be able to edit the admin role" do
35
+ within_row(1) do
36
+ expect(find("td:nth-child(2)")).not_to have_selector(:css, "span.icon-edit")
37
+ expect(find("td:nth-child(2)")).not_to have_selector(:css, "span.icon-delete")
38
+ end
39
+ end
40
+ it "should be able to edit the user role" do
41
+ within_row(2) do
42
+ expect(find("td:nth-child(2)")).to have_selector(:css, "span.icon-edit")
43
+ expect(find("td:nth-child(2)")).to have_selector(:css, "span.icon-delete")
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Shipping Methods", type: :feature do
4
+ stub_authorization!
5
+ let!(:zone) { create(:global_zone) }
6
+ let!(:shipping_method) { create(:shipping_method, zones: [zone]) }
7
+
8
+ after do
9
+ Capybara.ignore_hidden_elements = true
10
+ end
11
+
12
+ before do
13
+ Capybara.ignore_hidden_elements = false
14
+ # HACK: To work around no email prompting on check out
15
+ allow_any_instance_of(Spree::Order).to receive_messages(require_email: false)
16
+ create(:check_payment_method)
17
+
18
+ visit spree.admin_shipping_methods_path
19
+ end
20
+
21
+ context "show" do
22
+ it "should display existing shipping methods" do
23
+ within_row(1) do
24
+ expect(column_text(1)).to eq(shipping_method.name)
25
+ expect(column_text(2)).to eq(zone.name)
26
+ expect(column_text(3)).to eq("Flat rate")
27
+ expect(column_text(4)).to eq("Both")
28
+ end
29
+ end
30
+ end
31
+
32
+ context "create" do
33
+ it "should be able to create a new shipping method" do
34
+ click_link "New Shipping Method"
35
+
36
+ fill_in "shipping_method_name", with: "bullock cart"
37
+
38
+ within("#shipping_method_categories_field") do
39
+ check first("input[type='checkbox']")["name"]
40
+ end
41
+
42
+ click_on "Create"
43
+ expect(current_path).to eql(spree.edit_admin_shipping_method_path(Spree::ShippingMethod.last))
44
+ end
45
+ end
46
+
47
+ # Regression test for #1331
48
+ context "update" do
49
+ it "can change the calculator", js: true do
50
+ within("#listing_shipping_methods") do
51
+ click_icon :edit
52
+ end
53
+
54
+ expect(find(:css, ".calculator-settings-warning")).not_to be_visible
55
+ select2_search('Flexible Rate', from: 'Calculator')
56
+ expect(find(:css, ".calculator-settings-warning")).to be_visible
57
+
58
+ click_button "Update"
59
+ expect(page).not_to have_content("Shipping method is not found")
60
+ end
61
+ end
62
+ end