On 8.4.2008, at 23.17, Giuseppe Bertini wrote:
Hi Glenn, thanks for the response.I would do something like this: user = mock_model(User, :operator => true) controller.stub!(:current_user).and_return(user)OK, so, :operator is not a User attribute. Rather, a user is an operator, so to speak, if a habtm relationship exists between the user and the role titled 'operator'. If I modify your code like this: role = mock_model(Role, :title => 'operator') user = mock_model(User, :roles => [role]) controller.stub!(:current_user).and_return(user) things appear to be working well. Thank you again for your help!
You might want to take that one step further and create a method such as has_role?(:operator) for the user class. That way you don't have to stub arrays like roles in your specs, you just stub that method to return true or false and you're done. That way you make your code more easily "speccable":
def has_role?(role) roles.map(&:title).include?(role.to_s) end //jarkko
Giuseppe -- Posted via http://www.ruby-forum.com/. _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
-- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users