Skip to content

Instantly share code, notes, and snippets.

@dpickett
Created October 16, 2008 20:54
Show Gist options
  • Save dpickett/17259 to your computer and use it in GitHub Desktop.
Save dpickett/17259 to your computer and use it in GitHub Desktop.
require File.dirname(__FILE__) + '/../spec_helper'
class Message
has_many :copies
has_many :recipients, :through => :copies
end
class MessageCopy
belongs_to :recipient
belongs_to :message
end
#todo: rename this file to message_spec
describe Message do
def message_factory(attrs = {})
Message.create!({
:subject => "Test Message",
:body => "Testing 1 2 3",
:recipients => [User.find(:first)],
:sender => Factory(:user, :login => "sender"),
}.merge(attrs))
end
#passes
it "should have a copy for a single recipient" do
user = Factory(:user)
@message = message_factory
end
#fails
it "should using factory girl" do
@message = Factory(:message, :recipients => [Factory(:user, :login => "recipient")])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment