From a7ccc7c79fa69cea3b7d19bcaa4df3c2932238d8 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 12 May 2009 17:58:37 -0700 Subject: Remove support for deprecated validation message interpolation format --- activerecord/test/cases/validations_i18n_test.rb | 34 ++++++------------------ 1 file changed, 8 insertions(+), 26 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/validations_i18n_test.rb b/activerecord/test/cases/validations_i18n_test.rb index 66982346e9..20d1369a64 100644 --- a/activerecord/test/cases/validations_i18n_test.rb +++ b/activerecord/test/cases/validations_i18n_test.rb @@ -38,35 +38,17 @@ class ActiveRecordValidationsI18nTests < ActiveSupport::TestCase end end - def test_default_error_messages_is_deprecated - assert_deprecated('ActiveRecord::Errors.default_error_messages') do - ActiveRecord::Errors.default_error_messages + def test_percent_s_interpolation_syntax_in_error_messages_was_deprecated + assert_not_deprecated do + default = "%s interpolation syntax was deprecated" + assert_equal default, I18n.t(:does_not_exist, :default => default, :value => 'this') end end - def test_percent_s_interpolation_syntax_in_error_messages_still_works - ActiveSupport::Deprecation.silence do - result = I18n.t :does_not_exist, :default => "%s interpolation syntax is deprecated", :value => 'this' - assert_equal result, "this interpolation syntax is deprecated" - end - end - - def test_percent_s_interpolation_syntax_in_error_messages_is_deprecated - assert_deprecated('using %s in messages') do - I18n.t :does_not_exist, :default => "%s interpolation syntax is deprected", :value => 'this' - end - end - - def test_percent_d_interpolation_syntax_in_error_messages_still_works - ActiveSupport::Deprecation.silence do - result = I18n.t :does_not_exist, :default => "%d interpolation syntaxes are deprecated", :count => 2 - assert_equal result, "2 interpolation syntaxes are deprecated" - end - end - - def test_percent_d_interpolation_syntax_in_error_messages_is_deprecated - assert_deprecated('using %d in messages') do - I18n.t :does_not_exist, :default => "%d interpolation syntaxes are deprected", :count => 2 + def test_percent_d_interpolation_syntax_in_error_messages_was_deprecated + assert_not_deprecated do + default = "%d interpolation syntaxes are deprecated" + assert_equal default, I18n.t(:does_not_exist, :default => default, :count => 2) end end -- cgit v1.2.3 From e8550ee0329586b32de425e905c7af7e65bc78a8 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 13 May 2009 01:10:37 -0700 Subject: Cherry-pick core extensions --- activerecord/test/cases/aggregations_test.rb | 1 + .../test/cases/associations/eager_load_nested_include_test.rb | 1 + .../cases/associations/has_and_belongs_to_many_associations_test.rb | 1 + activerecord/test/cases/base_test.rb | 1 + activerecord/test/cases/finder_test.rb | 5 +++-- activerecord/test/cases/helper.rb | 5 +++++ activerecord/test/cases/named_scope_test.rb | 3 ++- activerecord/test/cases/nested_attributes_test.rb | 1 + activerecord/test/models/company_in_module.rb | 2 ++ 9 files changed, 17 insertions(+), 3 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/aggregations_test.rb b/activerecord/test/cases/aggregations_test.rb index 4e0e1c7f15..8b6ec04018 100644 --- a/activerecord/test/cases/aggregations_test.rb +++ b/activerecord/test/cases/aggregations_test.rb @@ -1,5 +1,6 @@ require "cases/helper" require 'models/customer' +require 'active_support/core_ext/exception' class AggregationsTest < ActiveRecord::TestCase fixtures :customers diff --git a/activerecord/test/cases/associations/eager_load_nested_include_test.rb b/activerecord/test/cases/associations/eager_load_nested_include_test.rb index 5f824f9c74..cb7fe9698b 100644 --- a/activerecord/test/cases/associations/eager_load_nested_include_test.rb +++ b/activerecord/test/cases/associations/eager_load_nested_include_test.rb @@ -4,6 +4,7 @@ require 'models/author' require 'models/comment' require 'models/category' require 'models/categorization' +require 'active_support/core_ext/array/random_access' module Remembered extend ActiveSupport::DependencyModule 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 5e8b2cadfc..8dc95806b9 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 @@ -24,6 +24,7 @@ require 'models/club' require 'models/member' require 'models/membership' require 'models/sponsor' +require 'active_support/core_ext/string/conversions' class ProjectWithAfterCreateHook < ActiveRecord::Base set_table_name 'projects' diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 7ca2807f7e..59aa6953e3 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -18,6 +18,7 @@ require 'models/minimalistic' require 'models/warehouse_thing' require 'models/parrot' require 'rexml/document' +require 'active_support/core_ext/exception' class Category < ActiveRecord::Base; end class Categorization < ActiveRecord::Base; end diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 28eb311618..ad4588db69 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -485,8 +485,9 @@ class FinderTest < ActiveRecord::TestCase assert_equal "foo in (#{quoted_nil})", bind('foo in (?)', []) end - def test_bind_string - assert_equal ActiveRecord::Base.connection.quote(''), bind('?', '') + def test_bind_empty_string + quoted_empty = ActiveRecord::Base.connection.quote('') + assert_equal quoted_empty, bind('?', '') end def test_bind_chars diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb index 1ec52ac24d..05e92433cd 100644 --- a/activerecord/test/cases/helper.rb +++ b/activerecord/test/cases/helper.rb @@ -15,6 +15,11 @@ require 'connection' require 'cases/repair_helper' +begin + require 'ruby-debug' +rescue LoadError +end + # Show backtraces for deprecated behavior for quicker cleanup. ActiveSupport::Deprecation.debug = true diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index ae6a54a5bd..7dcea6d42e 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -1,4 +1,5 @@ require "cases/helper" +require 'active_support/core_ext/array/random_access' require 'models/post' require 'models/topic' require 'models/comment' @@ -265,7 +266,7 @@ class NamedScopeTest < ActiveRecord::TestCase end def test_rand_should_select_a_random_object_from_proxy - assert Topic.approved.rand.is_a?(Topic) + assert_kind_of Topic, Topic.approved.rand end def test_should_use_where_in_query_for_named_scope diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index f1741ed54d..f31275163d 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -4,6 +4,7 @@ require "models/ship" require "models/bird" require "models/parrot" require "models/treasure" +require 'active_support/hash_with_indifferent_access' module AssertRaiseWithMessage def assert_raise_with_message(expected_exception, expected_message) diff --git a/activerecord/test/models/company_in_module.rb b/activerecord/test/models/company_in_module.rb index 7f02403d5a..3c34efbe16 100644 --- a/activerecord/test/models/company_in_module.rb +++ b/activerecord/test/models/company_in_module.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/object/misc' + module MyApplication module Business class Company < ActiveRecord::Base -- cgit v1.2.3 From afcbdfc15f919a470e4cfca97fb0084eebd2ab1f Mon Sep 17 00:00:00 2001 From: Peter Marklund Date: Thu, 14 May 2009 09:30:16 +0200 Subject: Changed ActiveRecord::Base#exists? to invoke find_initial so that it is compatible with, and doesn't lose, :include scopes (references to eager loaded tables) Signed-off-by: Michael Koziarski [#2543 state:committed] --- activerecord/test/cases/finder_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index ad4588db69..d0d7094e30 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -119,6 +119,12 @@ class FinderTest < ActiveRecord::TestCase Address.new(existing_address.street + "1", existing_address.city, existing_address.country)) end + def test_exists_with_scoped_include + Developer.with_scope(:find => { :include => :projects, :order => "projects.name" }) do + assert Developer.exists? + end + end + def test_find_by_array_of_one_id assert_kind_of(Array, Topic.find([ 1 ])) assert_equal(1, Topic.find([ 1 ]).length) -- cgit v1.2.3 From 25724eede9b5a62c74b3b78245944638f1cfcef4 Mon Sep 17 00:00:00 2001 From: Daniel Guettler Date: Sun, 17 May 2009 14:48:20 +0200 Subject: has_one :through should not create a new association when assigned nil [#698 state:resolved] Signed-off-by: Pratik Naik --- .../test/cases/associations/has_one_through_associations_test.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/associations/has_one_through_associations_test.rb b/activerecord/test/cases/associations/has_one_through_associations_test.rb index 12c598751b..ab6e6d20fc 100644 --- a/activerecord/test/cases/associations/has_one_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_through_associations_test.rb @@ -43,7 +43,14 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase @member.reload end end - + + def test_set_record_to_nil_should_delete_association + @member.club = nil + @member.reload + assert_equal nil, @member.current_membership + assert_nil @member.club + end + def test_has_one_through_polymorphic assert_equal clubs(:moustache_club), @member.sponsor_club end -- cgit v1.2.3 From 4e8c36a7417e5d447c9b15d5c61df0c014ee6d3b Mon Sep 17 00:00:00 2001 From: Chris Kampmeier Date: Mon, 16 Mar 2009 05:56:32 -0700 Subject: Implement #many? for NamedScope and AssociationCollection using #size [#1500 state:resolved] Signed-off-by: Pratik Naik --- .../associations/has_many_associations_test.rb | 39 ++++++++++++++++++++++ activerecord/test/cases/named_scope_test.rb | 34 +++++++++++++++++++ 2 files changed, 73 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 5df74fcdcd..d99424f9cd 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1023,6 +1023,45 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert firm.clients.loaded? end + def test_calling_many_should_count_instead_of_loading_association + firm = companies(:first_firm) + assert_queries(1) do + firm.clients.many? # use count query + end + assert !firm.clients.loaded? + end + + def test_calling_many_on_loaded_association_should_not_use_query + firm = companies(:first_firm) + firm.clients.collect # force load + assert_no_queries { assert firm.clients.many? } + end + + def test_calling_many_should_defer_to_collection_if_using_a_block + firm = companies(:first_firm) + assert_queries(1) do + firm.clients.expects(:size).never + firm.clients.many? { true } + end + assert firm.clients.loaded? + end + + def test_calling_many_should_return_false_if_none_or_one + firm = companies(:another_firm) + assert !firm.clients_like_ms.many? + assert_equal 0, firm.clients_like_ms.size + + firm = companies(:first_firm) + assert !firm.limited_clients.many? + assert_equal 1, firm.limited_clients.size + end + + def test_calling_many_should_return_true_if_more_than_one + firm = companies(:first_firm) + assert firm.clients.many? + assert_equal 2, firm.clients.size + end + def test_joins_with_namespaced_model_should_use_correct_type old = ActiveRecord::Base.store_full_sti_class ActiveRecord::Base.store_full_sti_class = true diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index 7dcea6d42e..69d01d5c2a 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -235,6 +235,40 @@ class NamedScopeTest < ActiveRecord::TestCase assert_no_queries { assert topics.any? } end + def test_many_should_not_load_results + topics = Topic.base + assert_queries(2) do + topics.many? # use count query + topics.collect # force load + topics.many? # use loaded (no query) + end + end + + def test_many_should_call_proxy_found_if_using_a_block + topics = Topic.base + assert_queries(1) do + topics.expects(:size).never + topics.many? { true } + end + end + + def test_many_should_not_fire_query_if_named_scope_loaded + topics = Topic.base + topics.collect # force load + assert_no_queries { assert topics.many? } + end + + def test_many_should_return_false_if_none_or_one + topics = Topic.base.scoped(:conditions => {:id => 0}) + assert !topics.many? + topics = Topic.base.scoped(:conditions => {:id => 1}) + assert !topics.many? + end + + def test_many_should_return_true_if_more_than_one + assert Topic.base.many? + end + def test_should_build_with_proxy_options topic = Topic.approved.build({}) assert topic.approved -- cgit v1.2.3 From b33c0d98329b97f8f540ba455d419d5046e6bb39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sun, 17 May 2009 13:51:35 -0500 Subject: replace the aaa_create_tables_test hack with loading test database schema in the test helper [#2663 state:resolved] Signed-off-by: Joshua Peek --- activerecord/test/cases/aaa_create_tables_test.rb | 24 ----------------------- activerecord/test/cases/helper.rb | 18 +++++++++++++++++ activerecord/test/schema/schema.rb | 5 ++++- activerecord/test/schema/schema2.rb | 6 ------ 4 files changed, 22 insertions(+), 31 deletions(-) delete mode 100644 activerecord/test/cases/aaa_create_tables_test.rb delete mode 100644 activerecord/test/schema/schema2.rb (limited to 'activerecord/test') diff --git a/activerecord/test/cases/aaa_create_tables_test.rb b/activerecord/test/cases/aaa_create_tables_test.rb deleted file mode 100644 index 3911afac49..0000000000 --- a/activerecord/test/cases/aaa_create_tables_test.rb +++ /dev/null @@ -1,24 +0,0 @@ -# The filename begins with "aaa" to ensure this is the first test. -require "cases/helper" - -class AAACreateTablesTest < ActiveRecord::TestCase - self.use_transactional_fixtures = false - - def test_load_schema - eval(File.read(SCHEMA_ROOT + "/schema.rb")) - if File.exists?(adapter_specific_schema_file) - eval(File.read(adapter_specific_schema_file)) - end - assert true - end - - def test_drop_and_create_courses_table - eval(File.read(SCHEMA_ROOT + "/schema2.rb")) - assert true - end - - private - def adapter_specific_schema_file - SCHEMA_ROOT + '/' + ActiveRecord::Base.connection.adapter_name.downcase + '_specific_schema.rb' - end -end diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb index 05e92433cd..f82784836e 100644 --- a/activerecord/test/cases/helper.rb +++ b/activerecord/test/cases/helper.rb @@ -5,6 +5,7 @@ require 'config' require 'rubygems' require 'test/unit' +require 'stringio' gem 'mocha', '>= 0.9.5' require 'mocha' @@ -72,3 +73,20 @@ class ActiveSupport::TestCase Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names, {}, &block) end end + +# silence verbose schema loading +original_stdout = $stdout +$stdout = StringIO.new + +begin + adapter_name = ActiveRecord::Base.connection.adapter_name.downcase + adapter_specific_schema_file = SCHEMA_ROOT + "/#{adapter_name}_specific_schema.rb" + + load SCHEMA_ROOT + "/schema.rb" + + if File.exists?(adapter_specific_schema_file) + load adapter_specific_schema_file + end +ensure + $stdout = original_stdout +end diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index a776cd974b..4ee0ffe132 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -1,4 +1,3 @@ - ActiveRecord::Schema.define do def except(adapter_names_to_exclude) unless [adapter_names_to_exclude].flatten.include?(adapter_name) @@ -500,3 +499,7 @@ ActiveRecord::Schema.define do execute "ALTER TABLE fk_test_has_fk ADD CONSTRAINT fk_name FOREIGN KEY (#{quote_column_name 'fk_id'}) REFERENCES #{quote_table_name 'fk_test_has_pk'} (#{quote_column_name 'id'})" end end + +Course.connection.create_table :courses, :force => true do |t| + t.column :name, :string, :null => false +end diff --git a/activerecord/test/schema/schema2.rb b/activerecord/test/schema/schema2.rb deleted file mode 100644 index 8527f7ba8f..0000000000 --- a/activerecord/test/schema/schema2.rb +++ /dev/null @@ -1,6 +0,0 @@ -ActiveRecord::Schema.define do - - Course.connection.create_table :courses, :force => true do |t| - t.column :name, :string, :null => false - end -end -- cgit v1.2.3 From 27de7f150b57a18d4ccdd274f6f8b621b58108c6 Mon Sep 17 00:00:00 2001 From: Benjamin Floering Date: Sun, 17 May 2009 23:35:47 -0700 Subject: Fixed limited eager loading associations with numbers in the name [#2668 state:resolved] Signed-off-by: Pratik Naik --- activerecord/test/cases/associations/eager_test.rb | 4 ++++ activerecord/test/fixtures/people.yml | 5 ++++- activerecord/test/models/person.rb | 1 + activerecord/test/schema/schema.rb | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index d23f86b700..65049c4f87 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -589,6 +589,10 @@ class EagerAssociationTest < ActiveRecord::TestCase assert_equal posts(:sti_post_and_comments, :sti_comments), Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title) DESC, posts.id', :limit => 2, :offset => 1) end + def test_limited_eager_with_numeric_in_association + assert_equal people(:david, :susan), Person.find(:all, :include => [:readers, :primary_contact, :number1_fan], :conditions => "number1_fans_people.first_name like 'M%'", :order => 'readers.id', :limit => 2, :offset => 0) + end + def test_preload_with_interpolation assert_equal [comments(:greetings)], Post.find(posts(:welcome).id, :include => :comments_with_interpolated_conditions).comments_with_interpolated_conditions end diff --git a/activerecord/test/fixtures/people.yml b/activerecord/test/fixtures/people.yml index 3babb1fe59..123673a2af 100644 --- a/activerecord/test/fixtures/people.yml +++ b/activerecord/test/fixtures/people.yml @@ -2,14 +2,17 @@ michael: id: 1 first_name: Michael primary_contact_id: 2 + number1_fan_id: 3 gender: M david: id: 2 first_name: David primary_contact_id: 3 + number1_fan_id: 1 gender: M susan: id: 3 first_name: Susan primary_contact_id: 2 - gender: F \ No newline at end of file + number1_fan_id: 1 + gender: F diff --git a/activerecord/test/models/person.rb b/activerecord/test/models/person.rb index ec2f684a6e..57fa6418f1 100644 --- a/activerecord/test/models/person.rb +++ b/activerecord/test/models/person.rb @@ -10,6 +10,7 @@ class Person < ActiveRecord::Base belongs_to :primary_contact, :class_name => 'Person' has_many :agents, :class_name => 'Person', :foreign_key => 'primary_contact_id' + belongs_to :number1_fan, :class_name => 'Person' named_scope :males, :conditions => { :gender => 'M' } named_scope :females, :conditions => { :gender => 'F' } diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 4ee0ffe132..6e8813d8ab 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -324,6 +324,7 @@ ActiveRecord::Schema.define do t.string :first_name, :null => false t.references :primary_contact t.string :gender, :limit => 1 + t.references :number1_fan t.integer :lock_version, :null => false, :default => 0 end -- cgit v1.2.3