On 8/12/07, David Parker <[EMAIL PROTECTED]> wrote:
> Hello all, I'm currently having an issue with some specs, specifically scope
> issues (probably more of a scope issue than a spec issue at this point)...
> Here's the error:
> ActiveRecord::AssociationTypeMismatch in 'A new User should
> know what role it has'
> Role expected, got NilClass
> D:/ruby/projects/restful_authentication_test/config/../app/models/role.rb:5:in
> `add'
> ./spec/models/user_spec.rb:62:
> script/spec:4:
>
> Here's the user.rb
>  http://pastie.caboo.se/87029
>
> role.rb
> http://pastie.caboo.se/87030
>
> user_spec.rb
>  http://pastie.caboo.se/87032
>
> The code is based off of RESTful authentication +
> Ben Curtis' user roles in Rails Application:
> http://www.bencurtis.com/archives/2007/06/user-roles-in-rails-applications/

users.roles is an AssociationProxy, not the Role class, where you have
defined the method add(user, role). You should be able to eliminate
that method in the Role class and just pass the role on line 62 of
your spec:

users.roles.add(role)

>
> Thanks for your help!
> --
> dp
> _______________________________________________
> rspec-users mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to