Skip to content

Instantly share code, notes, and snippets.

@maxim
Created September 18, 2009 02:23
Show Gist options
  • Save maxim/188843 to your computer and use it in GitHub Desktop.
Save maxim/188843 to your computer and use it in GitHub Desktop.
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