Skip to content

Commit

Permalink
Add test to column alias in exists? SQL.
Browse files Browse the repository at this point in the history
This behavior was added in be4ecdc.

Closes #1139.

Fixes #2553, #1141, #1623 and #2062.
  • Loading branch information
rafaelfranca committed Jun 10, 2012
1 parent be4ecdc commit 6cc5e9a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/relation/finder_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def first!
# Person.last # returns the last object fetched by SELECT * FROM people
# Person.where(["user_name = ?", user_name]).last
# Person.order("created_on DESC").offset(5).last
# Person.last(3) # returns the last three objects fetched by SELECT * FROM people.
# Person.last(3) # returns the last three objects fetched by SELECT * FROM people.
#
# Take note that in that last case, the results are sorted in ascending order:
#
Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/finder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def test_exists
assert_raise(NoMethodError) { Topic.exists?([1,2]) }
end

def test_exists_does_not_select_columns_without_alias
assert_sql(/SELECT\W+1 AS _one FROM ["`]topics["`]\W+LIMIT 1/) do
Topic.exists?
end
end

def test_exists_returns_true_with_one_record_and_no_args
assert Topic.exists?
end
Expand Down

0 comments on commit 6cc5e9a

Please sign in to comment.