Need help testing a module behavior with RSpec

I have a resource_security.rb file that includes instance and class
method definitions. At the end of the file I mix these into
ActiveRecord::Base.

ActiveRecord::Base.class_eval { include
ResourceSecurity::InstanceMethods }
ActiveRecord::Base.class_eval { extend ResourceSecurity::ClassMethods }

I’ve had limited success testing using the following approach

@resource = mock("ActiveRecord::Base")
@resource.class.class_eval { extend ResourceSecurity::ClassMethods }
@resource.class.class_eval { include 

ResourceSecurity::InstanceMethods }

The problem is that I want to test the behavior of a security related
instance method using different assumptions about the value of
access_hash (a class method). Any suggestions on how to best test
this?

Its also possible that my actual code solution is less then ideal.
The basic concept is that you can have statements like this in your
model:

allow :show, %w{admin team_lead}

Each model is in charge of evaluating whether or not the current user
has access (which is why I was thinking in terms of a class level
access hash.)

Anyways, any suggestions on how to test this would be greatly
appreciated.

TIA,

Sean

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs