spree_backend 3.2.1 → 3.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/app/views/spree/admin/products/_form.html.erb +8 -8
  3. data/spree_backend.gemspec +2 -2
  4. metadata +9 -100
  5. data/spec/controllers/spree/admin/base_controller_spec.rb +0 -46
  6. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +0 -185
  7. data/spec/controllers/spree/admin/general_settings_controller_spec.rb +0 -41
  8. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +0 -18
  9. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +0 -197
  10. data/spec/controllers/spree/admin/orders_controller_spec.rb +0 -296
  11. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +0 -64
  12. data/spec/controllers/spree/admin/payments_controller_spec.rb +0 -97
  13. data/spec/controllers/spree/admin/products_controller_spec.rb +0 -99
  14. data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +0 -21
  15. data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +0 -21
  16. data/spec/controllers/spree/admin/promotions_controller_spec.rb +0 -44
  17. data/spec/controllers/spree/admin/refunds_controller_spec.rb +0 -32
  18. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +0 -74
  19. data/spec/controllers/spree/admin/reports_controller_spec.rb +0 -42
  20. data/spec/controllers/spree/admin/resource_controller_spec.rb +0 -252
  21. data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +0 -225
  22. data/spec/controllers/spree/admin/return_index_controller_spec.rb +0 -37
  23. data/spec/controllers/spree/admin/return_items_controller_spec.rb +0 -27
  24. data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +0 -14
  25. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +0 -19
  26. data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +0 -41
  27. data/spec/controllers/spree/admin/stock_transfers_controller_spec.rb +0 -41
  28. data/spec/controllers/spree/admin/tax_categories_controller_spec.rb +0 -34
  29. data/spec/controllers/spree/admin/users_controller_spec.rb +0 -161
  30. data/spec/controllers/spree/admin/variants_controller_spec.rb +0 -32
  31. data/spec/features/admin/configuration/analytics_tracker_spec.rb +0 -47
  32. data/spec/features/admin/configuration/countries_spec.rb +0 -24
  33. data/spec/features/admin/configuration/general_settings_spec.rb +0 -44
  34. data/spec/features/admin/configuration/payment_methods_spec.rb +0 -63
  35. data/spec/features/admin/configuration/roles_spec.rb +0 -47
  36. data/spec/features/admin/configuration/shipping_methods_spec.rb +0 -62
  37. data/spec/features/admin/configuration/states_spec.rb +0 -68
  38. data/spec/features/admin/configuration/stock_locations_spec.rb +0 -48
  39. data/spec/features/admin/configuration/store_credit_categories_spec.rb +0 -50
  40. data/spec/features/admin/configuration/tax_categories_spec.rb +0 -56
  41. data/spec/features/admin/configuration/tax_rates_spec.rb +0 -18
  42. data/spec/features/admin/configuration/zones_spec.rb +0 -39
  43. data/spec/features/admin/homepage_spec.rb +0 -89
  44. data/spec/features/admin/locale_spec.rb +0 -31
  45. data/spec/features/admin/orders/adjustments_promotions_spec.rb +0 -53
  46. data/spec/features/admin/orders/adjustments_spec.rb +0 -130
  47. data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +0 -47
  48. data/spec/features/admin/orders/customer_details_spec.rb +0 -154
  49. data/spec/features/admin/orders/line_items_spec.rb +0 -51
  50. data/spec/features/admin/orders/listing_spec.rb +0 -224
  51. data/spec/features/admin/orders/log_entries_spec.rb +0 -55
  52. data/spec/features/admin/orders/new_order_spec.rb +0 -186
  53. data/spec/features/admin/orders/order_details_spec.rb +0 -662
  54. data/spec/features/admin/orders/payments_spec.rb +0 -231
  55. data/spec/features/admin/orders/risk_analysis_spec.rb +0 -48
  56. data/spec/features/admin/orders/shipments_spec.rb +0 -64
  57. data/spec/features/admin/orders/state_changes_spec.rb +0 -21
  58. data/spec/features/admin/products/edit/images_spec.rb +0 -86
  59. data/spec/features/admin/products/edit/products_spec.rb +0 -64
  60. data/spec/features/admin/products/edit/taxons_spec.rb +0 -41
  61. data/spec/features/admin/products/edit/variants_spec.rb +0 -56
  62. data/spec/features/admin/products/option_types_spec.rb +0 -114
  63. data/spec/features/admin/products/products_spec.rb +0 -445
  64. data/spec/features/admin/products/properties_spec.rb +0 -147
  65. data/spec/features/admin/products/prototypes_spec.rb +0 -112
  66. data/spec/features/admin/products/stock_management_spec.rb +0 -124
  67. data/spec/features/admin/products/taxonomies_spec.rb +0 -52
  68. data/spec/features/admin/products/variant_spec.rb +0 -50
  69. data/spec/features/admin/promotions/adjustments_spec.rb +0 -258
  70. data/spec/features/admin/promotions/option_value_rule_spec.rb +0 -70
  71. data/spec/features/admin/promotions/tiered_calculator_spec.rb +0 -70
  72. data/spec/features/admin/refund_reasons/refund_reasons_spec.rb +0 -57
  73. data/spec/features/admin/reimbursement_type/edit_reimbursement_type_spec.rb +0 -36
  74. data/spec/features/admin/reimbursement_type/new_reimbursement_type_spec.rb +0 -62
  75. data/spec/features/admin/reports_spec.rb +0 -61
  76. data/spec/features/admin/return_authorization_reasons/return_authorization_reasons_spec.rb +0 -63
  77. data/spec/features/admin/returns/customer_returns_spec.rb +0 -80
  78. data/spec/features/admin/returns/return_authorizations_spec.rb +0 -152
  79. data/spec/features/admin/stock_transfer_spec.rb +0 -75
  80. data/spec/features/admin/store_credits_spec.rb +0 -93
  81. data/spec/features/admin/taxons_spec.rb +0 -47
  82. data/spec/features/admin/users_spec.rb +0 -286
  83. data/spec/helpers/admin/base_helper_spec.rb +0 -30
  84. data/spec/helpers/admin/navigation_helper_spec.rb +0 -111
  85. data/spec/helpers/admin/promotion_rules_helper_spec.rb +0 -12
  86. data/spec/helpers/admin/stock_movements_helper_spec.rb +0 -30
  87. data/spec/models/spree/resource_spec.rb +0 -48
  88. data/spec/routing/admin_path_spec.rb +0 -22
  89. data/spec/spec_helper.rb +0 -144
  90. data/spec/support/appear_before_matcher.rb +0 -8
  91. data/spec/support/ror_ringer.jpeg +0 -0
  92. data/spec/test_views/spree/admin/submodule/posts/edit.html.erb +0 -1
  93. data/spec/test_views/spree/admin/submodule/posts/new.html.erb +0 -1
  94. data/spec/test_views/spree/admin/widgets/edit.html.erb +0 -1
  95. data/spec/test_views/spree/admin/widgets/new.html.erb +0 -1
@@ -1,112 +0,0 @@
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
@@ -1,124 +0,0 @@
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
@@ -1,52 +0,0 @@
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
@@ -1,50 +0,0 @@
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
@@ -1,258 +0,0 @@
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
@@ -1,70 +0,0 @@
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