Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix taxon promotion rule form

Tsuyoshi Hoshino444cd03c8883
diff --git a/backend/app/views/spree/admin/promotions/rules/_taxon.html.erb b/backend/app/views/spree/admin/promotions/rules/_taxon.html.erb
index 83f857a241..7ff5ef31ee 100644
--- a/backend/app/views/spree/admin/promotions/rules/_taxon.html.erb
+++ b/backend/app/views/spree/admin/promotions/rules/_taxon.html.erb
@@ -1,7 +1,7 @@
<div class="card-body">
<div class="form-group taxons_rule_taxons">
- <%= label_tag "#{param_prefix}_taxon_ids_string", Spree.t('taxon_rule.choose_taxons') %>
- <%= select_tag "#{param_prefix}[taxon_ids_string]", nil, class: 'taxon_picker d-block w-100', id: :product_taxon_ids %>
+ <%= label_tag "#{param_prefix}_taxon_ids", Spree.t('taxon_rule.choose_taxons') %>
+ <%= select_tag "#{param_prefix}[taxon_ids]", options_from_collection_for_select(promotion_rule.taxons, :id, :pretty_name, promotion_rule.taxon_ids), class: 'taxon_picker d-block w-100', multiple: true, id: :product_taxon_ids %>
</div>
<div class="form-group mb-0">
<%= label_tag Spree.t('taxon_rule.label') %>
diff --git a/backend/spec/features/admin/promotions/taxon_rule_spec.rb b/backend/spec/features/admin/promotions/taxon_rule_spec.rb
new file mode 100644
index 0000000000..a7a0475bab
--- /dev/null
+++ b/backend/spec/features/admin/promotions/taxon_rule_spec.rb
@@ -0,0 +1,50 @@
+require 'spec_helper'
+
+describe 'Promotion with taxon rule', type: :feature do
+ stub_authorization!
+
+ let!(:taxons) { create_list(:taxon, 2) }
+ let!(:taxon1) { taxons.first }
+ let!(:taxon2) { taxons.second }
+
+ let!(:promotion) { create :promotion }
+
+ before do
+ visit spree.edit_admin_promotion_path(promotion)
+ end
+
+ context 'when there are no taxon rules' do
+ it 'adding a taxon rule', js: true do
+ select2 'Taxon(s)', from: 'Add rule of type'
+ within('#rule_fields') { click_button 'Add' }
+
+ within('.promotion_rule') do
+ select2 taxon1.name, css: '.taxons_rule_taxons', search: true
+ select2 taxon2.name, css: '.taxons_rule_taxons', search: true
+ end
+
+ within('#rules_container') { click_button 'Update' }
+
+ first_rule = promotion.rules.reload.first
+ expect(first_rule.class).to eq Spree::Promotion::Rules::Taxon
+ expect(first_rule.taxons).to contain_exactly(taxon1, taxon2)
+ end
+ end
+
+ context 'when there is a taxon rule' do
+ before do
+ rule = Spree::Promotion::Rules::Taxon.new(promotion: promotion)
+ rule.save!
+ rule.update!(taxons: taxons)
+
+ visit spree.edit_admin_promotion_path(promotion)
+ end
+
+ it 'displays taxon names', js: true do
+ within('.promotion_rule') do
+ expect(page).to have_content(taxon1.name)
+ expect(page).to have_content(taxon2.name)
+ end
+ end
+ end
+end