Skip to content

Commit

Permalink
Failing spec: Getting a record using find doesn’t cause the associa…
Browse files Browse the repository at this point in the history
…tions to be created.

Illustrates #15
  • Loading branch information
ronen committed Mar 6, 2016
1 parent 10d7b06 commit 58ae6f1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spec/association_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ class Comment < ActiveRecord::Base ; end
expect(comment.post.id).to eq(post.id)
end

it "should create association if record retrieved using 'find'" do
post_id = 99
comment_id = 22
Post.connection.execute("INSERT INTO posts (id) VALUES (#{post_id})")
Comment.connection.execute("INSERT INTO comments (id, post_id) VALUES (#{comment_id}, #{post_id})");
expect(Comment.find(comment_id).posts.first.id).to eq(post_id)
end

it "should create association when creating record" do
post = Post.create
comment = Comment.create(:post => post)
Expand Down

0 comments on commit 58ae6f1

Please sign in to comment.