diff --git a/app/services/permitted_attributes/product.rb b/app/services/permitted_attributes/product.rb index 1adc8ff7d9..1fd91fcd1a 100644 --- a/app/services/permitted_attributes/product.rb +++ b/app/services/permitted_attributes/product.rb @@ -4,7 +4,7 @@ module PermittedAttributes class Product def self.attributes [ - :id, :name, :description, :supplier_id, :price, + :id, :name, :description, :price, :variant_unit, :variant_unit_scale, :variant_unit_with_scale, :unit_value, :unit_description, :variant_unit_name, :display_as, :sku, :group_buy, :group_buy_unit_size, diff --git a/app/services/permitted_attributes/variant.rb b/app/services/permitted_attributes/variant.rb index 21f0f997b8..4d4fdcea38 100644 --- a/app/services/permitted_attributes/variant.rb +++ b/app/services/permitted_attributes/variant.rb @@ -7,7 +7,8 @@ module PermittedAttributes :id, :sku, :on_hand, :on_demand, :shipping_category_id, :price, :unit_value, :unit_description, :display_name, :display_as, :tax_category_id, - :weight, :height, :width, :depth, :taxon_ids, :primary_taxon_id + :weight, :height, :width, :depth, :taxon_ids, :primary_taxon_id, + :supplier_id ] end end diff --git a/spec/controllers/api/v0/variants_controller_spec.rb b/spec/controllers/api/v0/variants_controller_spec.rb index 496af4d6b4..1f053d0325 100644 --- a/spec/controllers/api/v0/variants_controller_spec.rb +++ b/spec/controllers/api/v0/variants_controller_spec.rb @@ -88,9 +88,9 @@ RSpec.describe Api::V0::VariantsController, type: :controller do context "as an enterprise user" do let(:current_api_user) { create(:user, enterprises: [supplier]) } let(:supplier_other) { create(:supplier_enterprise) } - let!(:product) { create(:product, supplier:) } + let!(:product) { create(:product, supplier_id: supplier.id) } let(:variant) { product.variants.first } - let(:product_other) { create(:product, supplier: supplier_other) } + let(:product_other) { create(:product, supplier_id: supplier_other.id) } let(:variant_other) { product_other.variants.first } context "with a single remaining variant" do @@ -102,7 +102,7 @@ RSpec.describe Api::V0::VariantsController, type: :controller do end context "with more than one variants" do - let(:variant_to_delete) { create(:variant, product:) } + let(:variant_to_delete) { create(:variant, product:, supplier:) } it "deletes a variant" do api_delete :destroy, id: variant_to_delete.id @@ -125,7 +125,7 @@ RSpec.describe Api::V0::VariantsController, type: :controller do context "as an administrator" do let(:current_api_user) { create(:admin_user) } - let(:product) { create(:product) } + let(:product) { create(:product, supplier_id: create(:supplier_enterprise).id) } let(:variant) { product.variants.first } let(:taxon) { create(:taxon) } let!(:variant2) { create(:variant, product:) } @@ -144,8 +144,9 @@ RSpec.describe Api::V0::VariantsController, type: :controller do it "can create a new variant" do original_number_of_variants = variant.product.variants.count - api_post :create, variant: { sku: "12345", unit_value: "1", - unit_description: "L", price: "1", primary_taxon_id: taxon.id }, + api_post :create, variant: { sku: "12345", unit_value: "1", unit_description: "L", + price: "1",primary_taxon_id: taxon.id, + supplier_id: variant.supplier.id}, product_id: variant.product.id expect(attributes.all?{ |attr| json_response.include? attr.to_s }).to eq(true)