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.

Better tests for Product Stores editing

Damian Legawiec6b1226a3398a
diff --git a/backend/app/controllers/spree/admin/products_controller.rb b/backend/app/controllers/spree/admin/products_controller.rb
index 470b3d9e43..1e92f5bd1d 100644
--- a/backend/app/controllers/spree/admin/products_controller.rb
+++ b/backend/app/controllers/spree/admin/products_controller.rb
@@ -97,7 +97,7 @@ module Spree
end
def find_resource
- current_store.products.with_deleted.friendly.find(params[:id])
+ scope.with_deleted.friendly.find(params[:id])
end
def location_after_save
diff --git a/backend/app/views/spree/admin/products/_form.html.erb b/backend/app/views/spree/admin/products/_form.html.erb
index 01d1d1ff0e..9da9867979 100644
--- a/backend/app/views/spree/admin/products/_form.html.erb
+++ b/backend/app/views/spree/admin/products/_form.html.erb
@@ -261,8 +261,8 @@
<p data-hook="admin_product_form_stores" class="omega two columns">
<%= f.field_container :stores, class: ['form-group'] do %>
- <%= f.label :store_ids, Spree.t(:stores) %>
- <%= f.select :store_ids, @stores.pluck(:name, :id), { include_blank: true }, { class: 'select2', multiple: true, "data-placeholder" => Spree.t(:select_stores) } %>
+ <%= f.label :product_stores, Spree.t(:stores) %>
+ <%= collection_select(:product, :store_ids, @stores, :id, :unique_name, {}, { multiple: true, class: 'select2' }) %>
<% end %>
</p>
diff --git a/backend/spec/features/admin/products/edit/stores_spec.rb b/backend/spec/features/admin/products/edit/stores_spec.rb
index 3b8ea66256..a0f4a57aa3 100644
--- a/backend/spec/features/admin/products/edit/stores_spec.rb
+++ b/backend/spec/features/admin/products/edit/stores_spec.rb
@@ -1,27 +1,24 @@
require 'spec_helper'
-describe 'Product Stores', type: :feature, js: true do
+describe 'Edit Product Stores', type: :feature, js: true do
stub_authorization!
- before do
- create(:product, stores: Spree::Store.all)
- create(:store, name: 'First store', code: 'first')
- create(:store, name: 'Second store', code: 'second')
-
- visit spree.admin_products_path
+ let(:store) { Spree::Store.default }
+ let(:product) { create(:product, stores: [store]) }
+ let!(:store_2) { create(:store) }
+ let!(:store_3) { create(:store) }
- within_row(1) { click_icon :edit }
+ before do
+ visit spree.edit_admin_product_path(product)
end
- it 'allows assigning products' do
- select2 'First store', from: 'Stores'
- select2 'Second store', from: 'Stores'
+ it 'allows assigning multiple stores' do
+ select2 store_3.unique_name, from: 'Stores'
click_button 'Update'
expect(page).to have_content('successfully updated')
- expect(page).to have_content('First store')
- expect(page).to have_content('Second store')
+ expect(product.reload.stores).to contain_exactly(store, store_3)
end
end
diff --git a/backend/spec/features/admin/products/products_spec.rb b/backend/spec/features/admin/products/products_spec.rb
index 99226e342a..9d5b1f92c3 100644
--- a/backend/spec/features/admin/products/products_spec.rb
+++ b/backend/spec/features/admin/products/products_spec.rb
@@ -243,6 +243,8 @@ describe 'Products', type: :feature do
end
end
+ let(:product) { Spree::Product.last }
+
it 'allows an admin to create a new product' do
fill_in 'product_name', with: 'Baseball Cap'
fill_in 'product_sku', with: 'B100'
@@ -250,11 +252,14 @@ describe 'Products', type: :feature do
fill_in 'product_available_on', with: '2012/01/24'
select @shipping_category.name, from: 'product_shipping_category_id'
click_button 'Create'
+
expect(page).to have_content('successfully created!')
expect(page).to have_field('product_price', with: '100.00')
- expect(page).to have_select('product_store_ids', selected: store.name)
expect(page).to have_select('product_cost_currency', selected: 'Euro (EUR)')
- expect(Spree::Product.last.master.prices.last.currency).to eq('EUR')
+
+ expect(product.master.prices.last.currency).to eq('EUR')
+ expect(product.stores).to eq([store])
+
click_button 'Update'
expect(page).to have_content('successfully updated!')
end