Skip to content

Commit

Permalink
Merge pull request #3724 from cnorm35/disallow-empty-action-type-and-…
Browse files Browse the repository at this point in the history
…discount-rule

[Admin] Disallow promotions with empty action type and discount rule
  • Loading branch information
spaghetticode authored Aug 7, 2020
2 parents 7c76993 + 5eadf8c commit 1a4f85c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/app/views/spree/admin/promotions/_actions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="field">
<%= label_tag :action_type, t('spree.adjustment_type')%>
<%= admin_hint t('spree.adjustment_type'), t(:promotions, scope: [:spree, :hints, "spree/calculator"]) %>
<%= select_tag 'action_type', options, include_blank: t(:choose_promotion_action, scope: 'spree'), class: 'custom-select fullwidth' %>
<%= select_tag 'action_type', options, include_blank: t(:choose_promotion_action, scope: 'spree'), class: 'custom-select fullwidth', required: true %>
</div>
<div class="filter-actions actions">
<%= button_tag t('spree.actions.add'), class: 'btn btn-primary' %>
Expand Down
2 changes: 1 addition & 1 deletion backend/app/views/spree/admin/promotions/_rules.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<% if can?(:update, @promotion) %>
<div class="field">
<%= label_tag :promotion_rule_type, t('spree.discount_rules') %>
<%= select_tag('promotion_rule[type]', options_for_promotion_rule_types(@promotion), include_blank: t(:choose_promotion_rule, scope: 'spree'), class: 'custom-select fullwidth') %>
<%= select_tag('promotion_rule[type]', options_for_promotion_rule_types(@promotion), include_blank: t(:choose_promotion_rule, scope: 'spree'), class: 'custom-select fullwidth', required: true) %>
</div>
<div class="filter-actions actions">
<%= button_tag t('spree.actions.add'), class: 'btn btn-primary' %>
Expand Down
21 changes: 21 additions & 0 deletions backend/spec/features/admin/promotion_adjustments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,27 @@
expect(first_action.calculator.preferred_amount).to eq(5)
end

context 'creating a promotion with discount rules and adjustments' do
before do
fill_in "Name", with: "SAVE SAVE SAVE"
choose "Apply to all orders"
click_button "Create"
expect(page).to have_title("SAVE SAVE SAVE - Promotions")
end

it "should not allow an Discount Rule to be added without selecting an option" do
within('#rule_fields') { click_button "Add" }
message = page.find("#promotion_rule_type").native.attribute("validationMessage")
expect(message).to eq "Please select an item in the list."
end

it "should not allow an Adjusment type to be added without selecting an option" do
within('#action_fields') { click_button "Add" }
message = page.find("#action_type").native.attribute("validationMessage")
expect(message).to eq "Please select an item in the list."
end
end

context 'creating a promotion with promotion action that has a calculator with complex preferences' do
before do
class ComplexCalculator < Spree::Calculator
Expand Down

0 comments on commit 1a4f85c

Please sign in to comment.