bricestacey
I am writing a validation for a MongoMapper embedded document. It looks something like so: ``` if _root_document.settings.select { |s| s.feature_id == feature_id && s.name == name }.size > 1 errors.add(:name, 'is not unique') end ``` If I then try to test this using valid_attribute like so: ``` describe Setting do before do @feature = FactoryGirl.create(:feature) @feature.settings << subject end context 'given a setting with the name limit already exists' do before { @feature.settings << FactoryGirl.build(:setting, name: 'limit') } it { should_not have_valid(:name).when('limit') } end end ``` It will fail even though it actually doesn't. The problem seems to stem from how valid_attribute clones the subject and then performs validations. At that point, the feature's embedded settings do not contain a reference to the cloned subject, but to the actual subject and so valid_attribute wrongly believes the setting is valid. I've worked around this by emulating the behavior of valid_attribute without cloning and it works. It's an obvious edge-case, not sure if it's worth working around, but wanted to let you know.