Skip to content

Commit

Permalink
Add test case for the #5153's default order contract
Browse files Browse the repository at this point in the history
  • Loading branch information
kamipo committed Jul 31, 2018
1 parent 40ac706 commit 673cf4f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions activerecord/test/cases/finder_test.rb
Expand Up @@ -463,6 +463,7 @@ def test_first_have_primary_key_order_by_default
expected = topics(:first)
expected.touch # PostgreSQL changes the default order if no order clause is used
assert_equal expected, Topic.first
assert_equal expected, Topic.limit(5).first
end

def test_model_class_responds_to_first_bang
Expand All @@ -485,6 +486,7 @@ def test_second_have_primary_key_order_by_default
expected = topics(:second)
expected.touch # PostgreSQL changes the default order if no order clause is used
assert_equal expected, Topic.second
assert_equal expected, Topic.limit(5).second
end

def test_model_class_responds_to_second_bang
Expand All @@ -507,6 +509,7 @@ def test_third_have_primary_key_order_by_default
expected = topics(:third)
expected.touch # PostgreSQL changes the default order if no order clause is used
assert_equal expected, Topic.third
assert_equal expected, Topic.limit(5).third
end

def test_model_class_responds_to_third_bang
Expand All @@ -529,6 +532,7 @@ def test_fourth_have_primary_key_order_by_default
expected = topics(:fourth)
expected.touch # PostgreSQL changes the default order if no order clause is used
assert_equal expected, Topic.fourth
assert_equal expected, Topic.limit(5).fourth
end

def test_model_class_responds_to_fourth_bang
Expand All @@ -551,6 +555,7 @@ def test_fifth_have_primary_key_order_by_default
expected = topics(:fifth)
expected.touch # PostgreSQL changes the default order if no order clause is used
assert_equal expected, Topic.fifth
assert_equal expected, Topic.limit(5).fifth
end

def test_model_class_responds_to_fifth_bang
Expand Down Expand Up @@ -713,6 +718,14 @@ def test_first_on_relation_with_limit_and_offset
assert_equal comments.limit(2).to_a.first(3), comments.limit(2).first(3)
end

def test_first_have_determined_order_by_default
expected = [companies(:second_client), companies(:another_client)]
clients = Client.where(name: expected.map(&:name))

assert_equal expected, clients.first(2)
assert_equal expected, clients.limit(5).first(2)
end

def test_take_and_first_and_last_with_integer_should_return_an_array
assert_kind_of Array, Topic.take(5)
assert_kind_of Array, Topic.first(5)
Expand Down

0 comments on commit 673cf4f

Please sign in to comment.