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

Already on GitHub? Sign in to your account

using devise twice in model has side effect : validators are duplicated #765

Closed
thenrio opened this Issue Jan 10, 2011 · 1 comment

Comments

Projects
None yet
2 participants

thenrio commented Jan 10, 2011

Description

Given the following model

class TwoCalls
  include Mongoid::Document
  field :email

  devise :validatable
  devise :database_authenticatable
end

Then validating blank "Sign up" form will show 1 errors for email (presence)

Actually, there is 2 errors for email (presence)

Red?

require 'test_helper'

class TwoCallsTest < ActiveSupport::TestCase
  test 'has 1 presence validator' do
    assert_equal 1, 
      TwoCalls.validators_on(:email).grep(ActiveModel::Validations::PresenceValidator).size
  end
end

Green?

Work around is straight, merge devise calls in model

devise :validatable, :database_authenticatable

It might not need code, but documentation on this validation behavior ?

Thoughts?

Owner

josevalim commented Jan 11, 2011

It is not a validation behavior, it is rather a bug on calling Devise several times. This needs to be fixed. Thanks for the report!

@josevalim josevalim closed this in 8f3539c Apr 16, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment