Skip to content

Commit

Permalink
Fix broken spec, replace it with two correct specs—which pass
Browse files Browse the repository at this point in the history
  • Loading branch information
ronen committed Mar 6, 2016
1 parent 864a043 commit fe7ba03
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions spec/association_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,20 @@ class Comment < ActiveRecord::Base ; end
expect(comment.post.id).to eq(post.id)
end

it "should create association if record retrieved using 'find'" do
it "should create direct 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)
expect(Comment.find(comment_id).post.id).to eq(post_id)
end

it "should create reverse 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(Post.find(post_id).comments.first.id).to eq(comment_id)
end

it "should create association when creating record" do
Expand Down

0 comments on commit fe7ba03

Please sign in to comment.