On 8/12/07, David Parker &lt;<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:nemo7467@gmail.com">nemo7467@gmail.com</a>&gt; wrote:<br>&gt; Hello all, I&#39;m currently having an issue with some specs, specifically scope
<br>&gt; issues (probably more of a scope issue than a spec issue at this point)...<br>&gt; Here&#39;s the error:<br>&gt; ActiveRecord::AssociationTypeM<div style="direction: ltr;">ismatch in &#39;A new User should<br>&gt; know what role it has&#39;
<br>&gt; Role expected, got NilClass<br>&gt; D:/ruby/projects/restful_authentication_test/config/../app/models/role.rb:5:in<br>&gt; `add&#39;<br>&gt; ./spec/models/user_spec.rb:62:<br>&gt; script/spec:4:<br>&gt;<br>&gt; Here&#39;s the 
user.rb<br>&gt; &nbsp;<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://pastie.caboo.se/87029" target="_blank">http://pastie.caboo.se/87029</a><br>&gt;<br>&gt; role.rb<br>&gt; <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://pastie.caboo.se/87030" target="_blank">
http://pastie.caboo.se/87030</a><br>&gt;<br>&gt; user_spec.rb<br>&gt; &nbsp;<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://pastie.caboo.se/87032" target="_blank">http://pastie.caboo.se/87032</a><br>&gt;
<br>&gt; The code is based off of RESTful authentication +<br>&gt; Ben Curtis&#39; user roles in Rails Application:<br>&gt; <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.bencurtis.com/archives/2007/06/user-roles-in-rails-applications/" target="_blank">
http://www.bencurtis.com/archives/2007/06/user-roles-in-rails-applications/</a><br>&gt;<br>users.roles is an AssociationProxy, not the Role class, where you have<br>defined the method add(user, role). You should be able to eliminate
<br>that method in the Role class and just pass the role on line 62 of<br>your spec:<br><br>users.roles.add(role)<br>____________<br>I went ahead an eliminated the add method in the role class, and now, with the same spec as above these are the results I get, depending on what I have for line 62...
<br><br>Users.roles.add(role):<br>NameError in &#39;A new User should know what role it has&#39;<br>uninitialized constant Users<br><br>User.roles.add(role):<br>NoMethodError in &#39;A new User should know what role it has&#39;
<br>undefined method `roles&#39; for User:Class<br><br>user.roles.add(role):<br>NoMethodError in &#39;A new User should know what role it has&#39;<br>undefined method `add&#39; for Role:Class<br><br>users.roles.add(role):
<br>
NameError in &#39;A new User should know what role it has&#39;<br>
undefined local variable or method `users&#39; <br><br>If I go ahead and do something like:<br>users = User.find(:all)<br>before doing users.roles.add(role), then I get:<br>NoMethodError in &#39;A new User should know what role it has&#39;
<br>undefined method `roles&#39; <br><br>are my associations somehow not registering?<br><br>&gt;<br>&gt; Thanks for your help!<br>&gt; --<br>&gt; dp<br>&gt; _______________________________________________<br>&gt; rspec-users mailing list
<br>&gt; <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br>&gt; <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank">
http://rubyforge.org/mailman/listinfo/rspec-users</a><br>&gt;<br></div><br clear="all"><br>-- <br><br>dp