-----BEGIN PGP SIGNED MESSAGE-----
I’ve run into a bit of a problem that I can’t seem to figure out. I
have a model class User which includes our acts_as_role_context
library. This lib acts like most other acts_as libs, evaluating
class and instance methods at runtime. When I try to stub methods
that are defined in acts_as_role_context, I get strange behavior.
Perhaps it’s just me. I am a bit under the weather, and the Nyquil
could be clouding my thinking.
Here is my spec. It’s pretty simple, I just want to ensure that the
correct redirect happens when it should. For the record, the
controller works as expected outside of rspec.
require File.dirname(FILE) + ‘/…/spec_helper’
describe MemberNetworkController do
describe “on GET to add_as_friend” do
it “should redirect to /network/friends” do
get :add_as_friend, :key => logged_in_user.key
The line in question is logged_in_user.stub!(:add_user_to_role).
User#add_user_to_role is defined in acts_as_role_context.rb. I’ll
not paste the entire file unless requested. It’s fairly large. the
instance method #add_user_to_role looks like this.
def add_user_to_role(user, role_or_key) role = self.class.sanitize_role( role_or_key ) binding = role_bindings.find( :first, :conditions=>
[ ‘role_id=? AND user_id=?’, role.id, user.id ] )
if ( binding.nil? )
( :context=>self, :user=>user, :role=>role )
When #add_user_to_role is called in the controller during my spec,
the method is run, rather than being a stub as I would expect. Is
this expected and/or known behavior? Any comments and direction are
very much appreciated.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
-----END PGP SIGNATURE-----