Skip to content

Commit

Permalink
Just convert test to ActiveSupport::TestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspth committed Dec 23, 2023
1 parent d5db1b1 commit b17a486
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions test/active_record/associated_object_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
require "test_helper"

class ActiveRecord::AssociatedObjectTest < ActiveSupport::TestCase
include ActiveJob::TestHelper # TODO: Switch back to Minitest::Test, but need to fix `tagged_logger` NoMethodError.
include ActiveJob::TestHelper

def setup
super
setup do
@post = Post.first
@publisher = @post.publisher

Expand All @@ -17,15 +16,15 @@ def setup
@rating = @comment.rating
end

def test_associated_object_alias
test "associated object alias" do
assert_equal @post, @publisher.post
assert_equal @publisher.post, @publisher.record

assert_equal @comment, @rating.comment
assert_equal @rating.comment, @rating.record
end

def test_associated_object_method_missing_extraction
test "associated object method missing extraction" do
assert_equal @publisher, Post::Publisher.first
assert_equal @publisher, Post::Publisher.last
assert_equal @publisher, Post::Publisher.find(1)
Expand All @@ -43,7 +42,7 @@ def test_associated_object_method_missing_extraction
assert_equal [ @rating ], Post::Comment::Rating.where(Post::Comment::Rating.primary_key => [[@post.id, @author.id]])
end

def test_introspection
test "introspection" do
assert_equal Post, @publisher.record_klass
assert_equal Post, Post::Publisher.record_klass

Expand All @@ -63,22 +62,22 @@ def test_introspection
assert_equal :rating, Post::Comment::Rating.attribute_name
end

def test_unscoped_passthrough
test "unscoped passthrough" do
# TODO: lol what's this actually supposed to do? Need to look more into GlobalID.
# https://github.com/rails/globalid/blob/3ddb0f87fd5c22b3330ab2b4e5c41a85953ac886/lib/global_id/locator.rb#L164
assert_equal [ @post ], @publisher.class.unscoped
end

def test_transaction_passthrough
test "transaction passthrough" do
assert_equal @post, Post::Publisher.transaction { Post.first }
assert_equal @post, @publisher.transaction { Post.first }
end

def test_primary_key_passthrough
test "primary_key passthrough" do
assert_equal Post.primary_key, Post::Publisher.primary_key
end

def test_callback_passing
test "callback forwarding" do
@post.update title: "Updated title"
assert_equal "Updated title", @publisher.captured_title

Expand All @@ -87,7 +86,7 @@ def test_callback_passing
refute_empty Post.all
end

def test_kredis_integration
test "kredis integration" do
Time.new(2022, 4, 20, 1).tap do |publish_at|
@publisher.publish_at.value = publish_at

Expand All @@ -100,7 +99,7 @@ def test_kredis_integration
assert @rating.moderated?
end

def test_global_id_integration
test "global_id integration" do
assert_equal "gid://test/Post::Publisher/1", @publisher.to_gid.to_s
assert_equal @publisher, GlobalID.find(@publisher.to_gid.to_s)

Expand All @@ -117,7 +116,7 @@ def test_global_id_integration
assert_equal [ @rating ], GlobalID::Locator.locate_many([ @rating.to_gid.to_s, missing_rating.to_gid.to_s ], ignore_missing: true)
end

def test_active_job_integration
test "Active Job integration" do
@publisher.performed = false

assert_performed_with job: Post::Publisher::PublishJob, args: [ @publisher ], queue: "important" do
Expand All @@ -127,11 +126,11 @@ def test_active_job_integration
assert @publisher.performed
end

def test_calling_method
test "calling method" do
assert @rating.great?
end

def test_record_klass_extension
test "record_klass extension" do
assert_predicate Post::Comment.great.first, :rated_great?
assert_match /test\/boot\/associated_object/, Post::Comment.instance_method(:rated_great?).source_location.first
end
Expand Down

0 comments on commit b17a486

Please sign in to comment.