Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conditional validation not working in models that inherit and set collection #588

Open
cpmurphy opened this issue Oct 30, 2014 · 0 comments

Comments

@cpmurphy
Copy link

A model should be able to add a conditional validation to a key defined in a parent model, even if it uses its own collection. This was working in mongomapper 0.11.1 but it doesn't work in master currently. Instead the conditional on the validation is apparently ignored, i.e. the validation is applied when it shouldn't be.

Here's a test case:

    # add this to spec/functional/validations_spec.rb
    context "conditional validation" do
      it "should do conditional validation in child classes" do
        parent_class = Doc do
          key :name, String
        end
        class ChildDoc < parent_class
          validate :never_valid, :if => lambda { false }
          set_collection_name 'anything'

          def never_valid
            errors.add(:name, 'not valid, sorry')
          end
        end
        ChildDoc.new.should be_valid
      end
    end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant