From 58ae6f1b8dcc3710b5c1b7c5b0cfbc6b4a2af5a5 Mon Sep 17 00:00:00 2001 From: ronen barzel Date: Sat, 5 Mar 2016 22:17:22 -0500 Subject: [PATCH] =?UTF-8?q?Failing=20spec:=20=20Getting=20a=20record=20usi?= =?UTF-8?q?ng=20`find`=20doesn=E2=80=99t=20cause=20the=20associations=20to?= =?UTF-8?q?=20be=20created.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Illustrates #15 --- spec/association_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) 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)