From 231d7676f72947bae765b9bd885b134aaf949921 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Sun, 9 May 2010 12:24:25 +0300 Subject: corrected AR find_each and find_in_batches to raise when the user uses select but does not specify the primary key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activerecord/test/cases/batches_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/batches_test.rb b/activerecord/test/cases/batches_test.rb index 83deabb5b7..dcc49e12ca 100644 --- a/activerecord/test/cases/batches_test.rb +++ b/activerecord/test/cases/batches_test.rb @@ -17,6 +17,20 @@ class EachTest < ActiveRecord::TestCase end end + def test_each_should_raise_if_select_is_set_without_id + assert_raise(RuntimeError) do + Post.find_each(:select => :title, :batch_size => 1) { |post| post } + end + end + + def test_each_should_execute_if_id_is_in_select + assert_queries(4) do + Post.find_each(:select => "id, title, type", :batch_size => 2) do |post| + assert_kind_of Post, post + end + end + end + def test_each_should_raise_if_the_order_is_set assert_raise(RuntimeError) do Post.find_each(:order => "title") { |post| post } -- cgit v1.2.3 From 8d2f6c16e381f5fff6d3f24f5c73a443577a1488 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sun, 9 May 2010 12:42:48 +0100 Subject: Revert "Revert "Add index length support for MySQL [#1852 state:open]"" This reverts commit 6626833db13a69786f9f6cd56b9f53c4017c3e39. --- activerecord/test/cases/active_schema_test_mysql.rb | 17 +++++++++++++++++ activerecord/test/cases/migration_test.rb | 8 ++++++++ 2 files changed, 25 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/active_schema_test_mysql.rb b/activerecord/test/cases/active_schema_test_mysql.rb index 9aff538ce9..f4d123be15 100644 --- a/activerecord/test/cases/active_schema_test_mysql.rb +++ b/activerecord/test/cases/active_schema_test_mysql.rb @@ -15,6 +15,23 @@ class ActiveSchemaTest < ActiveRecord::TestCase end end + def test_add_index + expected = "CREATE INDEX `index_people_on_last_name` ON `people` (`last_name`)" + assert_equal expected, add_index(:people, :last_name, :length => nil) + + expected = "CREATE INDEX `index_people_on_last_name` ON `people` (`last_name`(10))" + assert_equal expected, add_index(:people, :last_name, :length => 10) + + expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`(15))" + assert_equal expected, add_index(:people, [:last_name, :first_name], :length => 15) + + expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`)" + assert_equal expected, add_index(:people, [:last_name, :first_name], :length => {:last_name => 15}) + + expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`(10))" + assert_equal expected, add_index(:people, [:last_name, :first_name], :length => {:last_name => 15, :first_name => 10}) + end + def test_drop_table assert_equal "DROP TABLE `people`", drop_table(:people) end diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index a3d1ceaa1f..f67344445a 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -92,6 +92,14 @@ if ActiveRecord::Base.connection.supports_migrations? assert_nothing_raised { Person.connection.remove_index("people", "last_name_and_first_name") } assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) } assert_nothing_raised { Person.connection.remove_index("people", ["last_name", "first_name"]) } + assert_nothing_raised { Person.connection.add_index("people", ["last_name"], :length => 10) } + assert_nothing_raised { Person.connection.remove_index("people", "last_name") } + assert_nothing_raised { Person.connection.add_index("people", ["last_name"], :length => {:last_name => 10}) } + assert_nothing_raised { Person.connection.remove_index("people", ["last_name"]) } + assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"], :length => 10) } + assert_nothing_raised { Person.connection.remove_index("people", ["last_name", "first_name"]) } + assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"], :length => {:last_name => 10, :first_name => 20}) } + assert_nothing_raised { Person.connection.remove_index("people", ["last_name", "first_name"]) } end # quoting -- cgit v1.2.3 From 5c245b91d2dbc0b300e8193310b3f950d0cf6c4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 10 May 2010 12:28:38 +0300 Subject: Make sure valid? preceives the context as in ActiveModel API (ht: Carlos Antonio) --- activerecord/test/cases/validations_test.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index e1fb911cc9..b873babc36 100644 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -62,6 +62,23 @@ class ValidationsTest < ActiveRecord::TestCase assert_equal ["is Wrong Update"], r.errors[:title], "A reply with a bad content should contain an error" end + def test_error_on_given_context + r = WrongReply.new + assert !r.valid?(:special_case) + assert "Invalid", r.errors[:title].join + + r.title = "secret" + r.content = "Good" + assert r.valid?(:special_case) + + r.title = nil + assert !r.save(:context => :special_case) + assert "Invalid", r.errors[:title].join + + r.title = "secret" + assert r.save(:context => :special_case) + end + def test_invalid_record_exception assert_raise(ActiveRecord::RecordInvalid) { WrongReply.create! } assert_raise(ActiveRecord::RecordInvalid) { WrongReply.new.save! } -- cgit v1.2.3 From 88b4a8fcafc7c52ad7deaa4fee9ee0fabf68940c Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Tue, 11 May 2010 15:39:29 +0100 Subject: Remove undocumented save_without_validation! --- activerecord/test/cases/validations_test.rb | 6 ------ 1 file changed, 6 deletions(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index b873babc36..3a34df2426 100644 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -152,12 +152,6 @@ class ValidationsTest < ActiveRecord::TestCase end end - def test_create_without_validation_bang - count = WrongReply.count - assert_nothing_raised { WrongReply.new.save_without_validation! } - assert count+1, WrongReply.count - end - def test_validates_acceptance_of_with_non_existant_table Object.const_set :IncorporealModel, Class.new(ActiveRecord::Base) -- cgit v1.2.3 From 5f3bd55726703e08ba595555e1cf428c57832603 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 12 May 2010 01:47:58 -0300 Subject: type_cast_calculated_value refactor: value is never a Fixnum here. Fix test since SQLite returns Float. [#4514 state:committed] Signed-off-by: Jeremy Kemper --- activerecord/test/cases/calculations_test.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index 28a1ae5feb..8473150338 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -20,8 +20,7 @@ class CalculationsTest < ActiveRecord::TestCase def test_should_average_field value = Account.average(:credit_limit) - assert_kind_of BigDecimal, value - assert_equal BigDecimal.new('53.0'), value + assert_equal 53.0, value end def test_should_return_nil_as_average -- cgit v1.2.3 From 35a114a8941cb22d29a536f1215a23a8cf7c4756 Mon Sep 17 00:00:00 2001 From: David Chelimsky + Brian Tatnall Date: Fri, 14 May 2010 16:30:12 -0500 Subject: Modified default_scope to merge with any pre-existing default_scope and added AR::Base::clear_default_scope MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - clear_default_scope provides users who rely on the old behaviour of each call to default_scope overwriting any previous default scopes an opportunity to maintain that behaviour. [#4583 state:resolved] Signed-off-by: José Valim --- activerecord/test/cases/method_scoping_test.rb | 31 ++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/method_scoping_test.rb b/activerecord/test/cases/method_scoping_test.rb index a3b496a0e6..3a6354ec6d 100644 --- a/activerecord/test/cases/method_scoping_test.rb +++ b/activerecord/test/cases/method_scoping_test.rb @@ -587,6 +587,18 @@ class HasAndBelongsToManyScopingTest< ActiveRecord::TestCase end end +class ClearDefaultScopeTest < ActiveRecord::TestCase + fixtures :developers + + def test_should_clear_default_scope + klass = Class.new(DeveloperCalledDavid) + klass.__send__ :clear_default_scope + expected = Developer.all.collect { |dev| dev.name } + actual = klass.all.collect { |dev| dev.name } + assert_equal expected, actual + end +end + class DefaultScopingTest < ActiveRecord::TestCase fixtures :developers, :posts @@ -615,15 +627,30 @@ class DefaultScopingTest < ActiveRecord::TestCase def test_default_scoping_with_inheritance # Inherit a class having a default scope and define a new default scope klass = Class.new(DeveloperOrderedBySalary) - klass.send :default_scope, {} + klass.send :default_scope, :limit => 1 # Scopes added on children should append to parent scope - assert klass.scoped.order_values.blank? + assert_equal 1, klass.scoped.limit_value + assert_equal ['salary DESC'], klass.scoped.order_values # Parent should still have the original scope + assert_equal nil, DeveloperOrderedBySalary.scoped.limit_value assert_equal ['salary DESC'], DeveloperOrderedBySalary.scoped.order_values end + def test_default_scope_called_twice_merges_conditions + Developer.destroy_all + Developer.create!(:name => "David", :salary => 80000) + Developer.create!(:name => "David", :salary => 100000) + Developer.create!(:name => "Brian", :salary => 100000) + + klass = Class.new(Developer) + klass.__send__ :default_scope, :conditions => { :name => "David" } + klass.__send__ :default_scope, :conditions => { :salary => 100000 } + assert_equal 1, klass.count + assert_equal "David", klass.first.name + assert_equal 100000, klass.first.salary + end def test_method_scope expected = Developer.find(:all, :order => 'name DESC').collect { |dev| dev.salary } received = DeveloperOrderedBySalary.all_ordered_by_name.collect { |dev| dev.salary } -- cgit v1.2.3 From 58adc6737126242d189274d83c50bcade098800a Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Mon, 3 May 2010 12:18:25 -0400 Subject: STI should not ignore type condition while applying scopes from parent class scopes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#4507 state:resolved] Signed-off-by: José Valim --- activerecord/test/cases/named_scope_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index e4cafad11e..9db0e7c143 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -142,6 +142,11 @@ class NamedScopeTest < ActiveRecord::TestCase assert_equal authors(:david).posts & Post.containing_the_letter_a, authors(:david).posts.containing_the_letter_a end + def test_named_scope_with_STI + assert_equal 3,Post.containing_the_letter_a.count + assert_equal 1,SpecialPost.containing_the_letter_a.count + end + def test_has_many_through_associations_have_access_to_named_scopes assert_not_equal Comment.containing_the_letter_e, authors(:david).comments assert !Comment.containing_the_letter_e.empty? -- cgit v1.2.3 From 3436fdfc12d58925e3d981e0afa61084ea34736c Mon Sep 17 00:00:00 2001 From: Diego Algorta Date: Sat, 15 May 2010 12:33:18 -0300 Subject: Fix for get_ids when including a belongs_to association on a has_many association [#2896 state:resolved] Signed-off-by: Pratik Naik --- activerecord/test/cases/associations/has_many_associations_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index b55b08bf9d..6e47967696 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -900,6 +900,10 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert !company.clients.loaded? end + def test_get_ids_ignores_include_option + assert_equal [readers(:michael_welcome).id], posts(:welcome).readers_with_person_ids + end + def test_get_ids_for_unloaded_finder_sql_associations_loads_them company = companies(:first_firm) assert !company.clients_using_sql.loaded? -- cgit v1.2.3 From 47c9a355062888feb2c7ea7c794e914a9b78f50c Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 15 May 2010 18:53:47 +0100 Subject: Reset quoted_table_name after set_table_name [#4568 state:resolved] Signed-off-by: Pratik Naik --- activerecord/test/cases/base_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index bbc4e543d5..b7ae619787 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1793,6 +1793,18 @@ class BasicsTest < ActiveRecord::TestCase assert_equal "bar", k.table_name end + def test_quoted_table_name_after_set_table_name + klass = Class.new(ActiveRecord::Base) + + klass.set_table_name "foo" + assert_equal "foo", klass.table_name + assert_equal klass.connection.quote_table_name("foo"), klass.quoted_table_name + + klass.set_table_name "bar" + assert_equal "bar", klass.table_name + assert_equal klass.connection.quote_table_name("bar"), klass.quoted_table_name + end + def test_set_table_name_with_block k = Class.new( ActiveRecord::Base ) k.set_table_name { "ks" } -- cgit v1.2.3 From bc1c8d58ec45593acba614d1d0fecb49adef08ff Mon Sep 17 00:00:00 2001 From: Jeroen van Dijk Date: Sat, 15 May 2010 19:43:45 +0200 Subject: Make ActiveModel::Errors#add_on_blank and #add_on_empty accept an options hash and make various Validators pass their (filtered) options. This makes it possible to pass additional options through Validators to message generation. E.g. plugin authors want to add validates_presence_of :foo, :format => "some format". Also, cleanup the :default vs :message options confusion in ActiveModel validation message generation. Also, deprecate ActiveModel::Errors#add_on_blank(attributes, custom_message) in favor of ActiveModel::Errors#add_on_blank(attributes, options). Original patch by Sven Fuchs, some minor changes and has been changed to be applicable to master again [#4057 state:committed] Signed-off-by: Jeremy Kemper --- .../validations/i18n_generate_message_validation_test.rb | 12 ++++++------ activerecord/test/cases/validations/i18n_validation_test.rb | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb b/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb index 8ee2a5868c..454e42ed37 100644 --- a/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb +++ b/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb @@ -9,22 +9,22 @@ class I18nGenerateMessageValidationTest < ActiveRecord::TestCase I18n.backend = I18n::Backend::Simple.new end - # validates_associated: generate_message(attr_name, :invalid, :default => configuration[:message], :value => value) + # validates_associated: generate_message(attr_name, :invalid, :message => custom_message, :value => value) def test_generate_message_invalid_with_default_message - assert_equal 'is invalid', @topic.errors.generate_message(:title, :invalid, :default => nil, :value => 'title') + assert_equal 'is invalid', @topic.errors.generate_message(:title, :invalid, :value => 'title') end def test_generate_message_invalid_with_custom_message - assert_equal 'custom message title', @topic.errors.generate_message(:title, :invalid, :default => 'custom message %{value}', :value => 'title') + assert_equal 'custom message title', @topic.errors.generate_message(:title, :invalid, :message => 'custom message %{value}', :value => 'title') end - # validates_uniqueness_of: generate_message(attr_name, :taken, :default => configuration[:message]) + # validates_uniqueness_of: generate_message(attr_name, :taken, :message => custom_message) def test_generate_message_taken_with_default_message - assert_equal "has already been taken", @topic.errors.generate_message(:title, :taken, :default => nil, :value => 'title') + assert_equal "has already been taken", @topic.errors.generate_message(:title, :taken, :value => 'title') end def test_generate_message_taken_with_custom_message - assert_equal 'custom message title', @topic.errors.generate_message(:title, :taken, :default => 'custom message %{value}', :value => 'title') + assert_equal 'custom message title', @topic.errors.generate_message(:title, :taken, :message => 'custom message %{value}', :value => 'title') end # ActiveRecord#RecordInvalid exception diff --git a/activerecord/test/cases/validations/i18n_validation_test.rb b/activerecord/test/cases/validations/i18n_validation_test.rb index 38fa2b821d..79f32e48ae 100644 --- a/activerecord/test/cases/validations/i18n_validation_test.rb +++ b/activerecord/test/cases/validations/i18n_validation_test.rb @@ -36,14 +36,14 @@ class I18nValidationTest < ActiveRecord::TestCase def test_validates_uniqueness_of_generates_message Topic.validates_uniqueness_of :title @topic.title = unique_topic.title - @topic.errors.expects(:generate_message).with(:title, :taken, {:default => nil, :value => 'unique!'}) + @topic.errors.expects(:generate_message).with(:title, :taken, {:value => 'unique!'}) @topic.valid? end def test_validates_uniqueness_of_generates_message_with_custom_default_message Topic.validates_uniqueness_of :title, :message => 'custom' @topic.title = unique_topic.title - @topic.errors.expects(:generate_message).with(:title, :taken, {:default => 'custom', :value => 'unique!'}) + @topic.errors.expects(:generate_message).with(:title, :taken, {:message => 'custom', :value => 'unique!'}) @topic.valid? end @@ -51,13 +51,13 @@ class I18nValidationTest < ActiveRecord::TestCase def test_validates_associated_generates_message Topic.validates_associated :replies - replied_topic.errors.expects(:generate_message).with(:replies, :invalid, {:value => replied_topic.replies, :default => nil}) + replied_topic.errors.expects(:generate_message).with(:replies, :invalid, {:value => replied_topic.replies}) replied_topic.valid? end def test_validates_associated_generates_message_with_custom_default_message Topic.validates_associated :replies - replied_topic.errors.expects(:generate_message).with(:replies, :invalid, {:value => replied_topic.replies, :default => nil}) + replied_topic.errors.expects(:generate_message).with(:replies, :invalid, {:value => replied_topic.replies}) replied_topic.valid? end -- cgit v1.2.3 From d6cbb27e7b260c970bf7d07dc0b0591ed82cee2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 15 May 2010 21:55:16 +0200 Subject: Revert "Make ActiveModel::Errors#add_on_blank and #add_on_empty accept an options hash and make various Validators pass their (filtered) options." Having a huge array to whitelist options is not the proper way to handle this case. This means that the ActiveModel::Errors object should know about the options given in *all* validators and break the extensibility added by the validators itself. If the intent is to whitelist options before sending them to I18n, each validator should clean its respective options instead of throwing the responsibility to the Errors object. This reverts commit bc1c8d58ec45593acba614d1d0fecb49adef08ff. --- .../validations/i18n_generate_message_validation_test.rb | 12 ++++++------ activerecord/test/cases/validations/i18n_validation_test.rb | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb b/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb index 454e42ed37..8ee2a5868c 100644 --- a/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb +++ b/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb @@ -9,22 +9,22 @@ class I18nGenerateMessageValidationTest < ActiveRecord::TestCase I18n.backend = I18n::Backend::Simple.new end - # validates_associated: generate_message(attr_name, :invalid, :message => custom_message, :value => value) + # validates_associated: generate_message(attr_name, :invalid, :default => configuration[:message], :value => value) def test_generate_message_invalid_with_default_message - assert_equal 'is invalid', @topic.errors.generate_message(:title, :invalid, :value => 'title') + assert_equal 'is invalid', @topic.errors.generate_message(:title, :invalid, :default => nil, :value => 'title') end def test_generate_message_invalid_with_custom_message - assert_equal 'custom message title', @topic.errors.generate_message(:title, :invalid, :message => 'custom message %{value}', :value => 'title') + assert_equal 'custom message title', @topic.errors.generate_message(:title, :invalid, :default => 'custom message %{value}', :value => 'title') end - # validates_uniqueness_of: generate_message(attr_name, :taken, :message => custom_message) + # validates_uniqueness_of: generate_message(attr_name, :taken, :default => configuration[:message]) def test_generate_message_taken_with_default_message - assert_equal "has already been taken", @topic.errors.generate_message(:title, :taken, :value => 'title') + assert_equal "has already been taken", @topic.errors.generate_message(:title, :taken, :default => nil, :value => 'title') end def test_generate_message_taken_with_custom_message - assert_equal 'custom message title', @topic.errors.generate_message(:title, :taken, :message => 'custom message %{value}', :value => 'title') + assert_equal 'custom message title', @topic.errors.generate_message(:title, :taken, :default => 'custom message %{value}', :value => 'title') end # ActiveRecord#RecordInvalid exception diff --git a/activerecord/test/cases/validations/i18n_validation_test.rb b/activerecord/test/cases/validations/i18n_validation_test.rb index 79f32e48ae..38fa2b821d 100644 --- a/activerecord/test/cases/validations/i18n_validation_test.rb +++ b/activerecord/test/cases/validations/i18n_validation_test.rb @@ -36,14 +36,14 @@ class I18nValidationTest < ActiveRecord::TestCase def test_validates_uniqueness_of_generates_message Topic.validates_uniqueness_of :title @topic.title = unique_topic.title - @topic.errors.expects(:generate_message).with(:title, :taken, {:value => 'unique!'}) + @topic.errors.expects(:generate_message).with(:title, :taken, {:default => nil, :value => 'unique!'}) @topic.valid? end def test_validates_uniqueness_of_generates_message_with_custom_default_message Topic.validates_uniqueness_of :title, :message => 'custom' @topic.title = unique_topic.title - @topic.errors.expects(:generate_message).with(:title, :taken, {:message => 'custom', :value => 'unique!'}) + @topic.errors.expects(:generate_message).with(:title, :taken, {:default => 'custom', :value => 'unique!'}) @topic.valid? end @@ -51,13 +51,13 @@ class I18nValidationTest < ActiveRecord::TestCase def test_validates_associated_generates_message Topic.validates_associated :replies - replied_topic.errors.expects(:generate_message).with(:replies, :invalid, {:value => replied_topic.replies}) + replied_topic.errors.expects(:generate_message).with(:replies, :invalid, {:value => replied_topic.replies, :default => nil}) replied_topic.valid? end def test_validates_associated_generates_message_with_custom_default_message Topic.validates_associated :replies - replied_topic.errors.expects(:generate_message).with(:replies, :invalid, {:value => replied_topic.replies}) + replied_topic.errors.expects(:generate_message).with(:replies, :invalid, {:value => replied_topic.replies, :default => nil}) replied_topic.valid? end -- cgit v1.2.3 From edec1afe25014749f0e2df86d27477b45586a9e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elomar=20Fran=C3=A7a?= Date: Sun, 27 Sep 2009 13:42:13 -0300 Subject: Don't carry default value when changing column for a binary type on MySQL [#3234 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activerecord/test/cases/migration_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index f67344445a..41e27bd281 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -860,6 +860,16 @@ if ActiveRecord::Base.connection.supports_migrations? assert_equal "Tester", Person.new.first_name end + def test_change_column_type_default_should_change + old_columns = Person.connection.columns(Person.table_name, "#{name} Columns") + assert !old_columns.find { |c| c.name == 'data' } + + assert_nothing_raised do + Person.connection.add_column "people", "data", :string, :default => '' + Person.connection.change_column "people", "data", :binary + end + end + def test_change_column_quotes_column_names Person.connection.create_table :testings do |t| t.column :select, :string -- cgit v1.2.3 From d7a3e65c50c5e8c0a7a37a59d6244c0e91fda629 Mon Sep 17 00:00:00 2001 From: Wijnand Wiersma Date: Sun, 16 May 2010 14:49:40 +0200 Subject: Postgresql doesn't allow to change a string type column to a binary type. Skip this test for postgresql for now. [#4616 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activerecord/test/cases/migration_test.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 41e27bd281..768a44f6df 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -860,13 +860,15 @@ if ActiveRecord::Base.connection.supports_migrations? assert_equal "Tester", Person.new.first_name end - def test_change_column_type_default_should_change - old_columns = Person.connection.columns(Person.table_name, "#{name} Columns") - assert !old_columns.find { |c| c.name == 'data' } - - assert_nothing_raised do - Person.connection.add_column "people", "data", :string, :default => '' - Person.connection.change_column "people", "data", :binary + unless current_adapter?(:PostgreSQLAdapter) + def test_change_column_type_default_should_change + old_columns = Person.connection.columns(Person.table_name, "#{name} Columns") + assert !old_columns.find { |c| c.name == 'data' } + + assert_nothing_raised do + Person.connection.add_column "people", "data", :string, :default => '' + Person.connection.change_column "people", "data", :binary + end end end -- cgit v1.2.3 From fdfebb7782a399839ac9a9e63d5153565d6f88f4 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 16 May 2010 10:37:57 -0300 Subject: Make use of assert_equal to test equallity between object assert expects and object and a message of error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#4611 state:committed] Signed-off-by: José Valim --- activerecord/test/cases/associations/join_model_test.rb | 2 +- activerecord/test/cases/autosave_association_test.rb | 4 ++-- activerecord/test/cases/finder_test.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb index 8bdf8bcd55..dca72be4fd 100644 --- a/activerecord/test/cases/associations/join_model_test.rb +++ b/activerecord/test/cases/associations/join_model_test.rb @@ -289,7 +289,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase end def test_has_many_array_methods_called_by_method_missing - assert true, authors(:david).categories.any? { |category| category.name == 'General' } + assert authors(:david).categories.any? { |category| category.name == 'General' } assert_nothing_raised { authors(:david).categories.sort } end diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb index 2995cc6f72..5cc5dff633 100644 --- a/activerecord/test/cases/autosave_association_test.rb +++ b/activerecord/test/cases/autosave_association_test.rb @@ -765,7 +765,7 @@ class TestAutosaveAssociationOnAHasOneAssociation < ActiveRecord::TestCase @ship.destroy @pirate.reload.catchphrase = "Arr" @pirate.save - assert 'Arr', @pirate.reload.catchphrase + assert_equal 'Arr', @pirate.reload.catchphrase end def test_should_automatically_save_the_associated_model @@ -885,7 +885,7 @@ class TestAutosaveAssociationOnABelongsToAssociation < ActiveRecord::TestCase @pirate.destroy @ship.reload.name = "The Vile Insanity" @ship.save - assert 'The Vile Insanity', @ship.reload.name + assert_equal 'The Vile Insanity', @ship.reload.name end def test_should_automatically_save_the_associated_model diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index e78db8969d..c73ad50a71 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -722,10 +722,10 @@ class FinderTest < ActiveRecord::TestCase def test_find_all_by_one_attribute_with_options topics = Topic.find_all_by_content("Have a nice day", :order => "id DESC") - assert topics(:first), topics.last + assert_equal topics(:first), topics.last topics = Topic.find_all_by_content("Have a nice day", :order => "id") - assert topics(:first), topics.first + assert_equal topics(:first), topics.first end def test_find_all_by_array_attribute -- cgit v1.2.3 From 5d0afe75ebd7d88f982a57af84dba1ef62b14c0c Mon Sep 17 00:00:00 2001 From: Nobuhiro IMAI Date: Sun, 16 May 2010 16:12:13 +0200 Subject: prevent to run fixture accessor (e.g. test_foos for TestFoo model) as a test case [#2992 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Wijnand Wiersma Signed-off-by: José Valim --- activerecord/test/cases/fixtures_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb index 3ce23209cc..8008b86f81 100644 --- a/activerecord/test/cases/fixtures_test.rb +++ b/activerecord/test/cases/fixtures_test.rb @@ -256,6 +256,11 @@ class FixturesWithoutInstantiationTest < ActiveRecord::TestCase def test_fixtures_from_root_yml_without_instantiation assert !defined?(@unknown), "@unknown is not defined" end + + def test_visibility_of_accessor_method + assert_equal false, respond_to?(:topics, false), "should be private method" + assert_equal true, respond_to?(:topics, true), "confirm to respond surely" + end def test_accessor_methods assert_equal "The First Topic", topics(:first).title -- cgit v1.2.3 From 821e15e5f2d9ef2aa43918a16cbd00f40c221e95 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 16 May 2010 15:20:52 -0300 Subject: Change on Array extension from rand => random_element [#4555 state:committed] Signed-off-by: Xavier Noria --- .../cases/associations/eager_load_nested_include_test.rb | 14 +++++++------- activerecord/test/cases/named_scope_test.rb | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'activerecord/test/cases') 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 e8db6d5dab..2beb3f8365 100644 --- a/activerecord/test/cases/associations/eager_load_nested_include_test.rb +++ b/activerecord/test/cases/associations/eager_load_nested_include_test.rb @@ -17,7 +17,7 @@ module Remembered module ClassMethods def remembered; @@remembered ||= []; end - def rand; @@remembered.rand; end + def random_element; @@remembered.random_element; end end end @@ -79,14 +79,14 @@ class EagerLoadPolyAssocsTest < ActiveRecord::TestCase [Circle, Square, Triangle, NonPolyOne, NonPolyTwo].map(&:create!) end 1.upto(NUM_SIMPLE_OBJS) do - PaintColor.create!(:non_poly_one_id => NonPolyOne.rand.id) - PaintTexture.create!(:non_poly_two_id => NonPolyTwo.rand.id) + PaintColor.create!(:non_poly_one_id => NonPolyOne.random_element.id) + PaintTexture.create!(:non_poly_two_id => NonPolyTwo.random_element.id) end 1.upto(NUM_SHAPE_EXPRESSIONS) do - shape_type = [Circle, Square, Triangle].rand - paint_type = [PaintColor, PaintTexture].rand - ShapeExpression.create!(:shape_type => shape_type.to_s, :shape_id => shape_type.rand.id, - :paint_type => paint_type.to_s, :paint_id => paint_type.rand.id) + shape_type = [Circle, Square, Triangle].random_element + paint_type = [PaintColor, PaintTexture].random_element + ShapeExpression.create!(:shape_type => shape_type.to_s, :shape_id => shape_type.random_element.id, + :paint_type => paint_type.to_s, :paint_id => paint_type.random_element.id) end end diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index 9db0e7c143..2007f5492f 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -301,7 +301,7 @@ class NamedScopeTest < ActiveRecord::TestCase end def test_rand_should_select_a_random_object_from_proxy - assert_kind_of Topic, Topic.approved.rand + assert_kind_of Topic, Topic.approved.random_element end def test_should_use_where_in_query_for_named_scope -- cgit v1.2.3 From 6b4e0cc526f55b5532cf99292c94f0a4db53b16f Mon Sep 17 00:00:00 2001 From: Federico Brubacher Date: Sun, 16 May 2010 07:24:41 -0300 Subject: a cloned object no longer mimics changed flags from creator , plus a test case [#4614 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activerecord/test/cases/dirty_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb index 7a17ef1ee0..3ea2948f62 100644 --- a/activerecord/test/cases/dirty_test.rb +++ b/activerecord/test/cases/dirty_test.rb @@ -338,6 +338,15 @@ class DirtyTest < ActiveRecord::TestCase assert !pirate.changed? end + def test_cloned_objects_should_not_copy_dirty_flag_from_creator + pirate = Pirate.create!(:catchphrase => "shiver me timbers") + pirate_clone = pirate.clone + pirate_clone.reset_catchphrase! + pirate.catchphrase = "I love Rum" + assert pirate.catchphrase_changed? + assert !pirate_clone.catchphrase_changed? + end + def test_reverted_changes_are_not_dirty phrase = "shiver me timbers" pirate = Pirate.create!(:catchphrase => phrase) -- cgit v1.2.3