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,112 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Prototypes", type: :feature, js: true do
4
+ stub_authorization!
5
+
6
+ context "listing prototypes" do
7
+ it "should be able to list existing prototypes" do
8
+ create(:property, name: "model", presentation: "Model")
9
+ create(:property, name: "brand", presentation: "Brand")
10
+ create(:property, name: "shirt_fabric", presentation: "Fabric")
11
+ create(:property, name: "shirt_sleeve_length", presentation: "Sleeve")
12
+ create(:property, name: "mug_type", presentation: "Type")
13
+ create(:property, name: "bag_type", presentation: "Type")
14
+ create(:property, name: "manufacturer", presentation: "Manufacturer")
15
+ create(:property, name: "bag_size", presentation: "Size")
16
+ create(:property, name: "mug_size", presentation: "Size")
17
+ create(:property, name: "gender", presentation: "Gender")
18
+ create(:property, name: "shirt_fit", presentation: "Fit")
19
+ create(:property, name: "bag_material", presentation: "Material")
20
+ create(:property, name: "shirt_type", presentation: "Type")
21
+ p = create(:prototype, name: "Shirt")
22
+ %w( brand gender manufacturer model shirt_fabric shirt_fit shirt_sleeve_length shirt_type ).each do |prop|
23
+ p.properties << Spree::Property.find_by_name(prop)
24
+ end
25
+ p = create(:prototype, name: "Mug")
26
+ %w( mug_size mug_type ).each do |prop|
27
+ p.properties << Spree::Property.find_by_name(prop)
28
+ end
29
+ p = create(:prototype, name: "Bag")
30
+ %w( bag_type bag_material ).each do |prop|
31
+ p.properties << Spree::Property.find_by_name(prop)
32
+ end
33
+
34
+ visit spree.admin_path
35
+ click_link "Products"
36
+ click_link "Prototypes"
37
+
38
+ within_row(1) { expect(column_text(1)).to eq "Shirt" }
39
+ within_row(2) { expect(column_text(1)).to eq "Mug" }
40
+ within_row(3) { expect(column_text(1)).to eq "Bag" }
41
+ end
42
+ end
43
+
44
+ context "creating a prototype" do
45
+ it "should allow an admin to create a new product prototype" do
46
+ visit spree.admin_path
47
+ click_link "Products"
48
+ click_link "Prototypes"
49
+
50
+ click_link "new_prototype_link"
51
+ within('.content-header') do
52
+ expect(page).to have_content("New Prototype")
53
+ end
54
+ fill_in "prototype_name", with: "male shirts"
55
+ click_button "Create"
56
+ expect(page).to have_content("successfully created!")
57
+ click_link "Products"
58
+ click_link "Prototypes"
59
+ within_row(1) { click_icon :edit }
60
+ fill_in "prototype_name", with: "Shirt 99"
61
+ click_button "Update"
62
+ expect(page).to have_content("successfully updated!")
63
+ expect(page).to have_content("Shirt 99")
64
+ end
65
+ end
66
+
67
+ context "editing a prototype" do
68
+ it "should allow to empty its properties" do
69
+ model_property = create(:property, name: "model", presentation: "Model")
70
+ brand_property = create(:property, name: "brand", presentation: "Brand")
71
+
72
+ shirt_prototype = create(:prototype, name: "Shirt", properties: [])
73
+ %w( brand model ).each do |prop|
74
+ shirt_prototype.properties << Spree::Property.find_by_name(prop)
75
+ end
76
+
77
+ visit spree.admin_path
78
+ click_link "Products"
79
+ click_link "Prototypes"
80
+
81
+ click_icon :edit
82
+ property_ids = find_field("prototype_property_ids").value.map(&:to_i)
83
+ expect(property_ids).to match_array [model_property.id, brand_property.id]
84
+
85
+ unselect "Brand", from: "prototype_property_ids"
86
+ unselect "Model", from: "prototype_property_ids"
87
+
88
+ click_button 'Update'
89
+
90
+ click_icon :edit
91
+
92
+ expect(find_field("prototype_property_ids").value).to be_empty
93
+ end
94
+ end
95
+
96
+ it 'should be deletable' do
97
+ shirt_prototype = create(:prototype, name: "Shirt", properties: [])
98
+ shirt_prototype.taxons << create(:taxon)
99
+
100
+ visit spree.admin_path
101
+ click_link "Products"
102
+ click_link "Prototypes"
103
+
104
+ within("#spree_prototype_#{shirt_prototype.id}") do
105
+ page.find('.delete-resource').click
106
+ end
107
+
108
+ accept_alert do
109
+ expect(page).to have_content("Prototype \"#{shirt_prototype.name}\" has been successfully removed!")
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Stock Management", type: :feature, js: true do
4
+ stub_authorization!
5
+
6
+ context "given a product with a variant and a stock location" do
7
+ let!(:stock_location) { create(:stock_location, name: 'Default') }
8
+ let!(:product) { create(:product, name: 'apache baseball cap', price: 10) }
9
+ let!(:variant) { product.master }
10
+
11
+ before do
12
+ stock_location.stock_item(variant).update_column(:count_on_hand, 10)
13
+ visit spree.stock_admin_product_path(product)
14
+ end
15
+
16
+ context "toggle backorderable for a variant's stock item" do
17
+ let(:backorderable) { find ".stock_item_backorderable" }
18
+
19
+ before do
20
+ expect(backorderable).to be_checked
21
+ backorderable.set(false)
22
+ wait_for_ajax
23
+ end
24
+
25
+ it "persists the value when page reload" do
26
+ visit current_path
27
+ expect(backorderable).not_to be_checked
28
+ end
29
+ end
30
+
31
+ context "toggle track inventory for a variant's stock item" do
32
+ let(:track_inventory) { find ".track_inventory_checkbox" }
33
+
34
+ before do
35
+ expect(track_inventory).to be_checked
36
+ track_inventory.set(false)
37
+ wait_for_ajax
38
+ end
39
+
40
+ it "persists the value when page reloaded" do
41
+ visit current_path
42
+ expect(track_inventory).not_to be_checked
43
+ end
44
+ end
45
+
46
+ # Regression test for #2896
47
+ # The regression was that unchecking the last checkbox caused a redirect
48
+ # to happen. By ensuring that we're still on an /admin/products URL, we
49
+ # assert that the redirect is *not* happening.
50
+ it "can toggle backorderable for the second variant stock item" do
51
+ new_location = create(:stock_location, name: "Another Location")
52
+ visit current_url
53
+
54
+ new_location_backorderable = find "#stock_item_backorderable_#{new_location.id}"
55
+ new_location_backorderable.set(false)
56
+ wait_for_ajax
57
+
58
+ expect(page.current_url).to include("/admin/products")
59
+ end
60
+
61
+ it "can create a new stock movement" do
62
+ fill_in "stock_movement_quantity", with: 5
63
+ select2 "default", from: "Stock Location"
64
+ click_button "Add Stock"
65
+
66
+ expect(page).to have_content('successfully created')
67
+
68
+ within(:css, '.stock_location_info table') do
69
+ expect(column_text(2)).to eq '15'
70
+ end
71
+ end
72
+
73
+ it "can create a new negative stock movement" do
74
+ fill_in "stock_movement_quantity", with: -5
75
+ select2 "default", from: "Stock Location"
76
+ click_button "Add Stock"
77
+
78
+ expect(page).to have_content('successfully created')
79
+
80
+ within(:css, '.stock_location_info table') do
81
+ expect(column_text(2)).to eq '5'
82
+ end
83
+ end
84
+
85
+ context "with multiple variants" do
86
+ let!(:variant) { create(:variant, product: product, sku: 'SPREEC') }
87
+ before do
88
+ variant.stock_items.first.update_column(:count_on_hand, 30)
89
+ visit current_url
90
+ end
91
+
92
+ it "can create a new stock movement for the specified variant" do
93
+ fill_in "stock_movement_quantity", with: 10
94
+ select2 "SPREEC", from: "Variant"
95
+ click_button "Add Stock"
96
+
97
+ expect(page).to have_content('successfully created')
98
+
99
+ within("#listing_product_stock tr", text: "SPREEC") do
100
+ within("table") do
101
+ expect(column_text(2)).to eq '40'
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ # Regression test for #3304
108
+ context "with no stock location" do
109
+ let(:product) { create(:product, name: 'apache baseball cap', price: 10) }
110
+ let(:variant) { create(:variant, product: product, sku: 'FOOBAR') }
111
+
112
+ before do
113
+ Spree::StockLocation.delete_all
114
+
115
+ visit spree.stock_admin_product_path(product)
116
+ end
117
+
118
+ it "redirects to stock locations page", js: false do
119
+ expect(page).to have_content(Spree.t(:stock_management_requires_a_stock_location))
120
+ expect(page.current_url).to include("admin/stock_locations")
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Taxonomies", type: :feature, js: true do
4
+ stub_authorization!
5
+
6
+ before(:each) do
7
+ visit spree.admin_path
8
+ click_link "Products"
9
+ end
10
+
11
+ context "show" do
12
+ it 'should display existing taxonomies' do
13
+ create(:taxonomy, name: 'Brand')
14
+ create(:taxonomy, name: 'Categories')
15
+ visit spree.admin_taxonomies_path
16
+ within_row(1) { expect(page).to have_content('Brand') }
17
+ within_row(2) { expect(page).to have_content('Categories') }
18
+ end
19
+ end
20
+
21
+ context "create" do
22
+ before(:each) do
23
+ click_link "Taxonomies"
24
+ click_link "admin_new_taxonomy_link"
25
+ end
26
+
27
+ it "should allow an admin to create a new taxonomy" do
28
+ expect(page).to have_content("New Taxonomy")
29
+ fill_in "taxonomy_name", with: "sports"
30
+ click_button "Create"
31
+ expect(page).to have_content("successfully created!")
32
+ end
33
+
34
+ it "should display validation errors" do
35
+ fill_in "taxonomy_name", with: ""
36
+ click_button "Create"
37
+ expect(page).to have_content("can't be blank")
38
+ end
39
+ end
40
+
41
+ context "edit" do
42
+ it "should allow an admin to update an existing taxonomy" do
43
+ create(:taxonomy)
44
+ click_link "Taxonomies"
45
+ within_row(1) { click_icon :edit }
46
+ fill_in "taxonomy_name", with: "sports 99"
47
+ click_button "Update"
48
+ expect(page).to have_content("successfully updated!")
49
+ expect(page).to have_content("sports 99")
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe "Variants", type: :feature do
5
+ stub_authorization!
6
+
7
+ let(:product) { create(:product_with_option_types, price: "1.99", cost_price: "1.00", weight: "2.5", height: "3.0", width: "1.0", depth: "1.5") }
8
+
9
+ context "creating a new variant" do
10
+ it "should allow an admin to create a new variant", js: true do
11
+ product.options.each do |option|
12
+ create(:option_value, option_type: option.option_type)
13
+ end
14
+
15
+ visit spree.admin_products_path
16
+ within_row(1) { click_icon :edit }
17
+ click_link "Variants"
18
+ click_on "Add One"
19
+ expect(find('input#variant_price').value).to eq("1.99")
20
+ expect(find('input#variant_cost_price').value).to eq("1.00")
21
+ expect(find('input#variant_weight').value).to eq("2.50")
22
+ expect(find('input#variant_height').value).to eq("3.00")
23
+ expect(find('input#variant_width').value).to eq("1.00")
24
+ expect(find('input#variant_depth').value).to eq("1.50")
25
+ expect(page).to have_select('variant[tax_category_id]')
26
+ end
27
+ end
28
+
29
+ context "listing variants" do
30
+ context "currency displaying" do
31
+ context "using Russian Rubles" do
32
+ before do
33
+ Spree::Config[:currency] = "RUB"
34
+ end
35
+
36
+ let!(:variant) do
37
+ create(:variant, product: product, price: 19.99)
38
+ end
39
+
40
+ # Regression test for #2737
41
+ context "uses руб as the currency symbol" do
42
+ it "on the products listing page" do
43
+ visit spree.admin_product_variants_path(product)
44
+ within_row(1) { expect(page).to have_content("19.99 ₽") }
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,258 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Promotion Adjustments", type: :feature, js: true do
4
+ stub_authorization!
5
+
6
+ context "coupon promotions" do
7
+ before(:each) do
8
+ visit spree.admin_promotions_path
9
+ click_on "New Promotion"
10
+ end
11
+
12
+ it "should allow an admin to create a flat rate discount coupon promo" do
13
+ fill_in "Name", with: "Promotion"
14
+ fill_in "Code", with: "order"
15
+ click_button "Create"
16
+ promotion = Spree::Promotion.find_by_name("Promotion")
17
+ expect(page).to have_content(promotion.name)
18
+
19
+ select2 "Item total", from: "Add rule of type"
20
+ within('#rule_fields') { click_button "Add" }
21
+
22
+ eventually_fill_in "promotion_promotion_rules_attributes_#{Spree::Promotion.count}_preferred_amount_min", with: 30
23
+ eventually_fill_in "promotion_promotion_rules_attributes_#{Spree::Promotion.count}_preferred_amount_max", with: 60
24
+ within('#rule_fields') { click_button "Update" }
25
+
26
+ select2 "Create whole-order adjustment", from: "Add action of type"
27
+ within('#action_fields') { click_button "Add" }
28
+ select2 "Flat Rate", from: "Calculator"
29
+ within('#actions_container') { click_button "Update" }
30
+
31
+ within('.calculator-fields') { fill_in "Amount", with: 5 }
32
+ within('#actions_container') { click_button "Update" }
33
+
34
+ expect(promotion.code).to eq("order")
35
+
36
+ first_rule = promotion.rules.first
37
+ expect(first_rule.class).to eq(Spree::Promotion::Rules::ItemTotal)
38
+ expect(first_rule.preferred_amount_min).to eq(30)
39
+ expect(first_rule.preferred_amount_max).to eq(60)
40
+
41
+ first_action = promotion.actions.first
42
+ expect(first_action.class).to eq(Spree::Promotion::Actions::CreateAdjustment)
43
+ first_action_calculator = first_action.calculator
44
+ expect(first_action_calculator.class).to eq(Spree::Calculator::FlatRate)
45
+ expect(first_action_calculator.preferred_amount).to eq(5)
46
+ end
47
+
48
+ it "should allow an admin to create a single user coupon promo with flat rate discount" do
49
+ fill_in "Name", with: "Promotion"
50
+ fill_in "Usage Limit", with: "1"
51
+ fill_in "Code", with: "single_use"
52
+ click_button "Create"
53
+ promotion = Spree::Promotion.find_by_name("Promotion")
54
+ expect(page).to have_content(promotion.name)
55
+
56
+ select2 "Create whole-order adjustment", from: "Add action of type"
57
+ within('#action_fields') { click_button "Add" }
58
+ select2 "Flat Rate", from: "Calculator"
59
+ within('#actions_container') { click_button "Update" }
60
+ within('#action_fields') { fill_in "Amount", with: "5" }
61
+ within('#actions_container') { click_button "Update" }
62
+
63
+ expect(promotion.usage_limit).to eq(1)
64
+ expect(promotion.code).to eq("single_use")
65
+
66
+ first_action = promotion.actions.first
67
+ expect(first_action.class).to eq(Spree::Promotion::Actions::CreateAdjustment)
68
+ first_action_calculator = first_action.calculator
69
+ expect(first_action_calculator.class).to eq(Spree::Calculator::FlatRate)
70
+ expect(first_action_calculator.preferred_amount).to eq(5)
71
+ end
72
+
73
+ it "should allow an admin to create an automatic promo with flat percent discount" do
74
+ fill_in "Name", with: "Promotion"
75
+ click_button "Create"
76
+ promotion = Spree::Promotion.find_by_name("Promotion")
77
+
78
+ expect(page).to have_content(promotion.name)
79
+
80
+ select2 "Item total", from: "Add rule of type"
81
+ within('#rule_fields') { click_button "Add" }
82
+
83
+ eventually_fill_in "promotion_promotion_rules_attributes_1_preferred_amount_min", with: 30
84
+ eventually_fill_in "promotion_promotion_rules_attributes_1_preferred_amount_max", with: 60
85
+ within('#rule_fields') { click_button "Update" }
86
+
87
+ select2 "Create whole-order adjustment", from: "Add action of type"
88
+ within('#action_fields') { click_button "Add" }
89
+ select2 "Flat Percent", from: "Calculator"
90
+ within('#actions_container') { click_button "Update" }
91
+ within('.calculator-fields') { fill_in "Flat Percent", with: "10" }
92
+ within('#actions_container') { click_button "Update" }
93
+
94
+ expect(promotion.code).to be_blank
95
+
96
+ first_rule = promotion.rules.first
97
+ expect(first_rule.class).to eq(Spree::Promotion::Rules::ItemTotal)
98
+ expect(first_rule.preferred_amount_min).to eq(30)
99
+ expect(first_rule.preferred_amount_max).to eq(60)
100
+
101
+ first_action = promotion.actions.first
102
+ expect(first_action.class).to eq(Spree::Promotion::Actions::CreateAdjustment)
103
+ first_action_calculator = first_action.calculator
104
+ expect(first_action_calculator.class).to eq(Spree::Calculator::FlatPercentItemTotal)
105
+ expect(first_action_calculator.preferred_flat_percent).to eq(10)
106
+ end
107
+
108
+ it "should allow an admin to create an product promo with percent per item discount" do
109
+ create(:product, name: "RoR Mug")
110
+
111
+ fill_in "Name", with: "Promotion"
112
+ click_button "Create"
113
+ promotion = Spree::Promotion.find_by_name("Promotion")
114
+
115
+ expect(page).to have_content(promotion.name)
116
+
117
+ select2 "Product(s)", from: "Add rule of type"
118
+ within("#rule_fields") { click_button "Add" }
119
+ select2_search "RoR Mug", from: "Choose products"
120
+ within('#rule_fields') { click_button "Update" }
121
+
122
+ select2 "Create per-line-item adjustment", from: "Add action of type"
123
+ within('#action_fields') { click_button "Add" }
124
+ select2 "Percent Per Item", from: "Calculator"
125
+ within('#actions_container') { click_button "Update" }
126
+ within('.calculator-fields') { fill_in "Percent", with: "10" }
127
+ within('#actions_container') { click_button "Update" }
128
+
129
+ expect(promotion.code).to be_blank
130
+
131
+ first_rule = promotion.rules.first
132
+ expect(first_rule.class).to eq(Spree::Promotion::Rules::Product)
133
+ expect(first_rule.products.map(&:name)).to include("RoR Mug")
134
+
135
+ first_action = promotion.actions.first
136
+ expect(first_action.class).to eq(Spree::Promotion::Actions::CreateItemAdjustments)
137
+ first_action_calculator = first_action.calculator
138
+ expect(first_action_calculator.class).to eq(Spree::Calculator::PercentOnLineItem)
139
+ expect(first_action_calculator.preferred_percent).to eq(10)
140
+ end
141
+
142
+ it "should allow an admin to create an automatic promotion with free shipping (no code)" do
143
+ fill_in "Name", with: "Promotion"
144
+ click_button "Create"
145
+
146
+ promotion = Spree::Promotion.find_by_name("Promotion")
147
+ expect(page).to have_content(promotion.name)
148
+
149
+ select2 "Item total", from: "Add rule of type"
150
+ within('#rule_fields') { click_button "Add" }
151
+ eventually_fill_in "promotion_promotion_rules_attributes_1_preferred_amount_min", with: "50"
152
+ eventually_fill_in "promotion_promotion_rules_attributes_1_preferred_amount_max", with: "150"
153
+ within('#rule_fields') { click_button "Update" }
154
+
155
+ select2 "Free shipping", from: "Add action of type"
156
+ within('#action_fields') { click_button "Add" }
157
+ expect(page).to have_content("Makes all shipments for the order free")
158
+
159
+ expect(promotion.code).to be_blank
160
+
161
+ first_rule = promotion.rules.first
162
+ expect(first_rule.class).to eq(Spree::Promotion::Rules::ItemTotal)
163
+
164
+ first_action = promotion.actions.first
165
+ expect(first_action.class).to eq(Spree::Promotion::Actions::FreeShipping)
166
+ end
167
+
168
+ it "should allow an admin to create an automatic promo requiring a landing page to be visited" do
169
+ fill_in "Name", with: "Promotion"
170
+ fill_in "Path", with: "content/cvv"
171
+ click_button "Create"
172
+ promotion = Spree::Promotion.find_by_name("Promotion")
173
+
174
+ expect(page).to have_content(promotion.name)
175
+
176
+ select2 "Create whole-order adjustment", from: "Add action of type"
177
+ within('#action_fields') { click_button "Add" }
178
+ select2 "Flat Rate", from: "Calculator"
179
+ within('#actions_container') { click_button "Update" }
180
+ within('.calculator-fields') { fill_in "Amount", with: "4" }
181
+ within('#actions_container') { click_button "Update" }
182
+
183
+ expect(promotion.path).to eq("content/cvv")
184
+ expect(promotion.code).to be_blank
185
+ expect(promotion.rules).to be_blank
186
+
187
+ first_action = promotion.actions.first
188
+ expect(first_action.class).to eq(Spree::Promotion::Actions::CreateAdjustment)
189
+ first_action_calculator = first_action.calculator
190
+ expect(first_action_calculator.class).to eq(Spree::Calculator::FlatRate)
191
+ expect(first_action_calculator.preferred_amount).to eq(4)
192
+ end
193
+
194
+ it "should allow an admin to create a promotion that adds a 'free' item to the cart" do
195
+ create(:product, name: "RoR Mug")
196
+ fill_in "Name", with: "Promotion"
197
+ fill_in "Code", with: "complex"
198
+ click_button "Create"
199
+ promotion = Spree::Promotion.find_by_name("Promotion")
200
+
201
+ expect(page).to have_content(promotion.name)
202
+
203
+ select2 "Create line items", from: "Add action of type"
204
+
205
+ within('#action_fields') { click_button "Add" }
206
+
207
+ page.find('.create_line_items .select2-choice').click
208
+ page.find('.select2-input').set('RoR Mug')
209
+ page.find('.select2-highlighted').click
210
+
211
+ within('#actions_container') { click_button "Update" }
212
+
213
+ select2 "Create whole-order adjustment", from: "Add action of type"
214
+ within('#new_promotion_action_form') { click_button "Add" }
215
+ select2 "Flat Rate", from: "Calculator"
216
+ within('#actions_container') { click_button "Update" }
217
+ within('.create_adjustment .calculator-fields') { fill_in "Amount", with: "40.00" }
218
+ within('#actions_container') { click_button "Update" }
219
+
220
+ expect(promotion.code).to eq("complex")
221
+
222
+ first_action = promotion.actions.first
223
+ expect(first_action.class).to eq(Spree::Promotion::Actions::CreateLineItems)
224
+ line_item = expect(first_action.promotion_action_line_items).not_to be_empty
225
+ end
226
+
227
+ it "ceasing to be eligible for a promotion with item total rule then becoming eligible again" do
228
+ fill_in "Name", with: "Promotion"
229
+ click_button "Create"
230
+ promotion = Spree::Promotion.find_by_name("Promotion")
231
+
232
+ expect(page).to have_content(promotion.name)
233
+
234
+ select2 "Item total", from: "Add rule of type"
235
+ within('#rule_fields') { click_button "Add" }
236
+ eventually_fill_in "promotion_promotion_rules_attributes_1_preferred_amount_min", with: "50"
237
+ eventually_fill_in "promotion_promotion_rules_attributes_1_preferred_amount_max", with: "150"
238
+ within('#rule_fields') { click_button "Update" }
239
+
240
+ select2 "Create whole-order adjustment", from: "Add action of type"
241
+ within('#action_fields') { click_button "Add" }
242
+ select2 "Flat Rate", from: "Calculator"
243
+ within('#actions_container') { click_button "Update" }
244
+ within('.calculator-fields') { fill_in "Amount", with: "5" }
245
+ within('#actions_container') { click_button "Update" }
246
+
247
+ first_rule = promotion.rules.first
248
+ expect(first_rule.class).to eq(Spree::Promotion::Rules::ItemTotal)
249
+ expect(first_rule.preferred_amount_min).to eq(50)
250
+ expect(first_rule.preferred_amount_max).to eq(150)
251
+
252
+ first_action = promotion.actions.first
253
+ expect(first_action.class).to eq(Spree::Promotion::Actions::CreateAdjustment)
254
+ expect(first_action.calculator.class).to eq(Spree::Calculator::FlatRate)
255
+ expect(first_action.calculator.preferred_amount).to eq(5)
256
+ end
257
+ end
258
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'Promotion with option value rule' do
4
+ stub_authorization!
5
+
6
+ given(:variant) { create :variant }
7
+ given!(:product) { variant.product }
8
+ given!(:option_value) { variant.option_values.first }
9
+
10
+ given(:promotion) { create :promotion }
11
+
12
+ background do
13
+ visit spree.edit_admin_promotion_path(promotion)
14
+ end
15
+
16
+ scenario "adding an option value rule", js: true do
17
+ select2 "Option Value(s)", from: "Add rule of type"
18
+ within("#rule_fields") { click_button "Add" }
19
+
20
+ within("#rules .promotion-block") do
21
+ click_button "Add"
22
+
23
+ expect(page.body).to have_content("Product")
24
+ expect(page.body).to have_content("Option Values")
25
+ end
26
+
27
+ within('.promo-rule-option-value') do
28
+ targetted_select2_search product.name, from: '.js-promo-rule-option-value-product-select'
29
+ targetted_select2_search(
30
+ option_value.name,
31
+ from: '.js-promo-rule-option-value-option-values-select'
32
+ )
33
+ end
34
+
35
+ within('#rules_container') { click_button "Update" }
36
+
37
+ first_rule = promotion.rules.reload.first
38
+ expect(first_rule.class).to eq Spree::Promotion::Rules::OptionValue
39
+ expect(first_rule.preferred_eligible_values).to eq Hash[product.id => [option_value.id]]
40
+ end
41
+
42
+ context "with an existing option value rule" do
43
+ given(:variant1) { create :variant }
44
+ given(:variant2) { create :variant }
45
+ background do
46
+ rule = Spree::Promotion::Rules::OptionValue.new
47
+ rule.promotion = promotion
48
+ rule.preferred_eligible_values = Hash[
49
+ variant1.product_id => variant1.option_values.pluck(:id),
50
+ variant2.product_id => variant2.option_values.pluck(:id)
51
+ ]
52
+ rule.save!
53
+
54
+ visit spree.edit_admin_promotion_path(promotion)
55
+ end
56
+
57
+ scenario "deleting a product", js: true do
58
+ within(".promo-rule-option-value:last-child") do
59
+ find(".delete").click
60
+ end
61
+
62
+ within('#rule_fields') { click_button "Update" }
63
+
64
+ first_rule = promotion.rules.reload.first
65
+ expect(first_rule.preferred_eligible_values).to eq(
66
+ Hash[variant1.product_id => variant1.option_values.pluck(:id)]
67
+ )
68
+ end
69
+ end
70
+ end