mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-05 07:19:14 +00:00
Require ProductDistribution to be unique on [product, distributor]
This commit is contained in:
@@ -5,5 +5,7 @@ module Spree
|
||||
belongs_to :product
|
||||
belongs_to :distributor
|
||||
belongs_to :shipping_method
|
||||
|
||||
validates_uniqueness_of :product_id, :scope => :distributor_id
|
||||
end
|
||||
end
|
||||
|
||||
23
spec/models/product_distribution_spec.rb
Normal file
23
spec/models/product_distribution_spec.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::ProductDistribution do
|
||||
it "is unique for scope [product, distributor]" do
|
||||
pd1 = create(:product_distribution)
|
||||
pd1.should be_valid
|
||||
|
||||
new_product = create(:product)
|
||||
new_distributor = create(:distributor)
|
||||
|
||||
pd2 = build(:product_distribution, :product => pd1.product, :distributor => pd1.distributor)
|
||||
pd2.should_not be_valid
|
||||
|
||||
pd2 = build(:product_distribution, :product => pd1.product, :distributor => new_distributor)
|
||||
pd2.should be_valid
|
||||
|
||||
pd2 = build(:product_distribution, :product => new_product, :distributor => pd1.distributor)
|
||||
pd2.should be_valid
|
||||
|
||||
pd2 = build(:product_distribution, :product => new_product, :distributor => new_distributor)
|
||||
pd2.should be_valid
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user