Guest User

Untitled

a guest
Jun 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. describe Letter do
  2. before(:each) do
  3. @john = mock("John")
  4. @john.stub!(:id).and_return(5)
  5. @john.stub!(:class).and_return(Person) # is this ok?
  6. @john.stub!(:name).and_return("John F.")
  7. Person.stub!(:find).and_return(@john)
  8. end
  9. it.should "have a valid #to field" do
  10. letter = Letter.create!(:to=>@john, :content => "Hello John")
  11. letter.to_type.should == @john.class.name
  12. letter.to_id.should == @john.id
  13. end
  14. [...]
  15. end
  16.  
  17. class Letter < ActiveRecord::Base
  18. belongs_to :to, :polymorphic => true
  19. [...]
  20. end
  21.  
  22. before(:each) do
  23. @john = mock_model(Person, :name => "John F.")
  24. Person.stub!(:find).and_return(@john)
  25. end
  26.  
  27. describe Letter
  28. should_belong_to :to, :polymorphic => true
  29. end
Add Comment
Please, Sign In to add comment