diff --git a/spec/association_spec.rb b/spec/association_spec.rb index 9d3ee1d..0973bb8 100644 --- a/spec/association_spec.rb +++ b/spec/association_spec.rb @@ -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)