Permalink
Browse files

Added test for has_many associations

  • Loading branch information...
1 parent cc1543a commit f4b134bd92c3d9b674a961190aac8e9653b56662 @lawrencepit lawrencepit committed Jun 17, 2008
Showing with 15 additions and 0 deletions.
  1. +7 −0 spec/models.rb
  2. +8 −0 spec/stub_spec.rb
View
@@ -77,6 +77,7 @@ def set_attribute(key, value)
User = Class.new BlankModel
Post = Class.new BlankModel
+ Tag = Class.new BlankModel
module Foo
Bar = Class.new BlankModel
end
@@ -94,13 +95,19 @@ module Foo
end
define_models do
+ model Tag do
+ stub :foo, :name => "foo"
+ stub :bar, :name => "bar"
+ end
+
model User do
stub :admin, :admin => true # inherits from default fixture
end
model Post do
# uses admin user fixture above
stub :title => 'initial', :user => all_stubs(:admin_model_stubbing_user), :published_at => current_time + 5.days
+ stub :nice_one, :title => 'nice one', :tags => [all_stubs(:foo_model_stubbing_tag), all_stubs(:bar_model_stubbing_tag)]
end
end
View
@@ -201,8 +201,12 @@ module ModelStubbing
@definition = ModelStubbing.definitions[:default]
@users = @definition.models[:model_stubbing_users]
@posts = @definition.models[:model_stubbing_posts]
+ @tags = @definition.models[:model_stubbing_tags]
@user = @users.stubs[:admin]
@post = @posts.default
+ @nice_one = @posts.stubs[:nice_one]
+ @tag_foo = @tags.stubs[:foo]
+ @tag_bar = @tags.stubs[:bar]
end
before do
@@ -213,5 +217,9 @@ module ModelStubbing
it "stubs associated records" do
@post.record.user.should == @user.record
end
+
+ it "stubs has_many associated records" do
+ @nice_one.record.tags.should == [@tag_foo.record, @tag_bar.record]
+ end
end
end

0 comments on commit f4b134b

Please sign in to comment.