diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 0d7f0b1..2bd4be2 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -191,6 +191,17 @@ class RelationTest < ActiveRecord::TestCase assert_equal companies(:rails_core), firms.first end + def test_limit_with_joins + comments = Comment.joins(:post).where(:posts => {:author_id => 1}).limit(2) + assert_equal 2, comments.count, "we limit to 2 so we expect our count to be 2" + end + + #this is how we can work around the join + limit bug in the mean time, but it is ugly + def test_limit_with_joins_workaround + comments = Comment.find_by_sql(Comment.joins(:post).where(:posts => {:author_id => 1}).limit(2).to_sql) + assert_equal 2, comments.count + end + def test_find_all_with_join developers_on_project_one = Developer.joins('LEFT JOIN developers_projects ON developers.id = developers_projects.developer_id'). where('project_id=1').to_a