Skip to content

Commit 8524c07

Browse files
committed
Refactor test a bit
1 parent 4f47114 commit 8524c07

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

test/active_record/associated_object_test.rb

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,34 @@ class ActiveRecord::AssociatedObjectTest < ActiveSupport::TestCase
2525
end
2626

2727
test "associated object method missing extraction" do
28-
assert_equal @publisher, Post::Publisher.first
29-
assert_equal @publisher, Post::Publisher.last
30-
assert_equal @publisher, Post::Publisher.find(1)
31-
assert_equal @publisher, Post::Publisher.find_by(id: 1)
32-
assert_equal @publisher, Post::Publisher.find_by(title: Post.first.title)
33-
assert_equal @publisher, Post::Publisher.find_by(author: Author.first)
34-
assert_equal @publisher, Post::Publisher.find_by!(id: 1)
35-
assert_equal @publisher, Post::Publisher.find_by!(title: Post.first.title)
36-
assert_equal @publisher, Post::Publisher.find_by!(author: Author.first)
37-
assert_equal [ @publisher ], Post::Publisher.where(id: 1)
38-
39-
assert_equal @rating, Post::Comment::Rating.first
40-
assert_equal @rating, Post::Comment::Rating.last
41-
assert_equal @rating, Post::Comment::Rating.find([@post, @author])
42-
assert_equal @rating, Post::Comment::Rating.find_by(Post::Comment::Rating.primary_key => [[@post.id, @author.id]])
43-
assert_equal @rating, Post::Comment::Rating.find_by(body: "First!!!!")
44-
assert_equal @rating, Post::Comment::Rating.find_by(author: Author.first)
45-
assert_equal @rating, Post::Comment::Rating.find_by!(Post::Comment::Rating.primary_key => [[@post.id, @author.id]])
46-
assert_equal @rating, Post::Comment::Rating.find_by!(body: "First!!!!")
47-
assert_equal @rating, Post::Comment::Rating.find_by!(author: Author.first)
48-
assert_equal [ @rating ], Post::Comment::Rating.where(Post::Comment::Rating.primary_key => [[@post.id, @author.id]])
28+
[1, @post.title, @author].tap do |id, title, author|
29+
assert_equal @publisher, Post::Publisher.first
30+
assert_equal @publisher, Post::Publisher.last
31+
assert_equal @publisher, Post::Publisher.find(id)
32+
assert_equal @publisher, Post::Publisher.find_by(id:)
33+
assert_equal @publisher, Post::Publisher.find_by(title:)
34+
assert_equal @publisher, Post::Publisher.find_by(author:)
35+
assert_equal @publisher, Post::Publisher.find_by!(id:)
36+
assert_equal @publisher, Post::Publisher.find_by!(title:)
37+
assert_equal @publisher, Post::Publisher.find_by!(author:)
38+
assert_equal [@publisher], Post::Publisher.where(id:)
39+
end
40+
41+
[[@post, @author], @comment.body, @author].tap do |id, body, author|
42+
assert_equal @rating, Post::Comment::Rating.first
43+
assert_equal @rating, Post::Comment::Rating.last
44+
assert_equal @rating, Post::Comment::Rating.find(id)
45+
assert_equal @rating, Post::Comment::Rating.find_by(body:)
46+
assert_equal @rating, Post::Comment::Rating.find_by(author:)
47+
assert_equal @rating, Post::Comment::Rating.find_by!(body:)
48+
assert_equal @rating, Post::Comment::Rating.find_by!(author:)
49+
end
50+
51+
{ Post::Comment::Rating.primary_key => [[@post.id, @author.id]] }.tap do
52+
assert_equal @rating, Post::Comment::Rating.find_by(_1)
53+
assert_equal @rating, Post::Comment::Rating.find_by!(_1)
54+
assert_equal [@rating], Post::Comment::Rating.where(_1)
55+
end
4956
end
5057

5158
test "associated object method missing extraction omittances" do

0 commit comments

Comments
 (0)