Rails3: model: Member: errors must be set on existing attributes

On Rails 3.0, test fails with following error.

<pre>
Error:
test_validate(MemberTest):
NoMethodError: undefined method `role' for #<Member:0x7f73caf8cd08>
    app/models/member.rb:87:in `validate_role'
    test/unit/member_test.rb:76:in `test_validate'
</pre>

Contributed by Sylvain Utard.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8124 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2011-12-08 11:13:24 +00:00
parent c585d224d8
commit d9699adce5
2 changed files with 2 additions and 1 deletions

View File

@ -84,7 +84,7 @@ class Member < ActiveRecord::Base
protected
def validate_role
errors.add_on_empty :role if member_roles.empty? && roles.empty?
errors.add_on_empty :roles if member_roles.empty? && roles.empty?
end
private

View File

@ -74,6 +74,7 @@ class MemberTest < ActiveSupport::TestCase
assert user.save
member = Member.new(:project_id => 1, :user_id => user.id, :role_ids => [])
assert !member.save
assert_equal I18n.translate('activerecord.errors.messages.empty'), member.errors[:roles].to_s
end
def test_validate_member_role