-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
Minor Change
Uniqueness validation for StringifiedSymbol field in embedded document doesn't work.
The following test fails with Mongoid 7.3.3:
class Band include Mongoid::Document field :name, type: Mongoid::StringifiedSymbol validates_uniqueness_of :name embeds_many :albums end class Album include Mongoid::Document field :name, type: Mongoid::StringifiedSymbol validates_uniqueness_of :name embedded_in :band end describe "Band with multiple albums with same name" do it "should be invalid" do band = Band.new band.albums.build(name: :foo) band.albums.build(name: :foo) expect(band.invalid?).to be true # not ok end end
The test passes if the type of the field is Symbol.
Validation in root document works:
describe "Band with duplicate name" do it "should be invalid" do _band = Band.create(name: :foo) expect(Band.new(name: :foo).invalid?).to be true # ok end end