Created
September 18, 2009 02:23
-
-
Save maxim/188843 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context "with associations" do | |
setup do | |
fake_association = Struct.new(:macro, :name, :object) | |
klass_with_associations = proc{|associations| | |
Class.new do | |
self.class.send(:define_method, :reflect_on_all_associations) do | |
associations | |
end | |
define_method(:method_missing) do |meth| | |
association = associations.find{|a| a.name == meth.to_sym} | |
association && association.object | |
end | |
define_method(:respond_to?) do |meth| | |
associations.find{|a| a.name == meth.to_sym} | |
end | |
end | |
} | |
associations = [] | |
associations << fake_association.new(:belongs_to, :user, @instance) | |
post_klass = klass_with_associations.call(associations) | |
@post = post_klass.new | |
end | |
should "have has_role? method using association if association exists" do | |
assert @instance.has_role?(:user, @post) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment