aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb12
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb5
-rw-r--r--activerecord/test/cases/finder_test.rb6
-rw-r--r--activerecord/test/cases/reflection_test.rb4
-rw-r--r--activerecord/test/models/category.rb3
-rw-r--r--activerecord/test/models/company.rb2
6 files changed, 30 insertions, 2 deletions
diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
index edca3c622b..9981f4c5d5 100644
--- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -636,6 +636,18 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
assert_equal 3, Developer.find(:all, :include => {:projects => :developers}, :conditions => 'developers_projects_join.joined_on IS NOT NULL', :group => group.join(",")).size
end
+ def test_find_grouped
+ all_posts_from_category1 = Post.find(:all, :conditions => "category_id = 1", :joins => :categories)
+ grouped_posts_of_category1 = Post.find(:all, :conditions => "category_id = 1", :group => "author_id", :select => 'count(posts.id) as posts_count', :joins => :categories)
+ assert_equal 4, all_posts_from_category1.size
+ assert_equal 1, grouped_posts_of_category1.size
+ end
+
+ def test_find_scoped_grouped
+ assert_equal 4, categories(:general).posts_gruoped_by_title.size
+ assert_equal 1, categories(:technology).posts_gruoped_by_title.size
+ end
+
def test_get_ids
assert_equal projects(:active_record, :action_controller).map(&:id).sort, developers(:david).project_ids.sort
assert_equal [projects(:active_record).id], developers(:jamis).project_ids
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index feac4b002b..5bcbc5eb5b 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -248,6 +248,11 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal 1, grouped_clients_of_firm1.size
end
+ def test_find_scoped_grouped
+ assert_equal 1, companies(:first_firm).clients_grouped_by_firm_id.length
+ assert_equal 2, companies(:first_firm).clients_grouped_by_name.length
+ end
+
def test_adding
force_signal37_to_load_all_clients_of_firm
natural = Client.new("name" => "Natural Company")
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index aede8a6393..ddfebaec08 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -169,6 +169,12 @@ class FinderTest < ActiveRecord::TestCase
assert_equal("fixture_3", developers.first.name)
end
+ def test_find_with_group
+ developers = Developer.find(:all, :group => "salary")
+ assert_equal 4, developers.size
+ assert_equal 4, developers.uniq(&:salary).size
+ end
+
def test_find_with_entire_select_statement
topics = Topic.find_by_sql "SELECT * FROM topics WHERE author_name = 'Mary'"
diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb
index 4b86e32dbf..e339ef41ab 100644
--- a/activerecord/test/cases/reflection_test.rb
+++ b/activerecord/test/cases/reflection_test.rb
@@ -160,8 +160,8 @@ class ReflectionTest < ActiveRecord::TestCase
def test_reflection_of_all_associations
# FIXME these assertions bust a lot
- assert_equal 24, Firm.reflect_on_all_associations.size
- assert_equal 18, Firm.reflect_on_all_associations(:has_many).size
+ assert_equal 26, Firm.reflect_on_all_associations.size
+ assert_equal 20, Firm.reflect_on_all_associations(:has_many).size
assert_equal 6, Firm.reflect_on_all_associations(:has_one).size
assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size
end
diff --git a/activerecord/test/models/category.rb b/activerecord/test/models/category.rb
index 1660c61682..a06dd78011 100644
--- a/activerecord/test/models/category.rb
+++ b/activerecord/test/models/category.rb
@@ -13,6 +13,9 @@ class Category < ActiveRecord::Base
has_and_belongs_to_many :post_with_conditions,
:class_name => 'Post',
:conditions => { :title => 'Yet Another Testing Title' }
+
+ has_and_belongs_to_many :posts_gruoped_by_title, :class_name => "Post", :group => "title"
+
def self.what_are_you
'a category...'
end
diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb
index cd435948a1..1abf3f3918 100644
--- a/activerecord/test/models/company.rb
+++ b/activerecord/test/models/company.rb
@@ -55,6 +55,8 @@ class Firm < Company
has_many :readonly_clients, :class_name => 'Client', :readonly => true
has_many :clients_using_primary_key, :class_name => 'Client',
:primary_key => 'name', :foreign_key => 'firm_name'
+ has_many :clients_grouped_by_firm_id, :class_name => "Client", :group => "firm_id"
+ has_many :clients_grouped_by_name, :class_name => "Client", :group => "name"
has_one :account, :foreign_key => "firm_id", :dependent => :destroy, :validate => true
has_one :unvalidated_account, :foreign_key => "firm_id", :class_name => 'Account', :validate => false