From 28896a9f4ae0830726619bc479f69263acb80e4b Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Sun, 28 Nov 2010 20:07:59 -0800 Subject: test case on has_one :through after a destroy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#6037 state:resolved] Signed-off-by: José Valim --- .../associations/has_one_through_associations_test.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (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 5d153147f5..ac43e571cb 100644 --- a/activerecord/test/cases/associations/has_one_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_through_associations_test.rb @@ -206,6 +206,23 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase end end + def test_through_belongs_to_after_destroy + @member_detail = MemberDetail.new(:extra_data => 'Extra') + @member.member_detail = @member_detail + @member.save! + + assert_not_nil @member_detail.member_type + @member_detail.destroy + assert_queries(1) do + assert_not_nil @member_detail.member_type(true) + end + + @member_detail.member.destroy + assert_queries(1) do + assert_nil @member_detail.member_type(true) + end + end + def test_value_is_properly_quoted minivan = Minivan.find('m1') assert_nothing_raised do -- cgit v1.2.3 From 9f2e885ce8d5cbf6999b22e274ec245d9007131d Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 29 Nov 2010 13:32:02 -0800 Subject: testing attributes applied by default_scope --- activerecord/test/cases/relation_scoping_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb index dae9721a63..c7f7738248 100644 --- a/activerecord/test/cases/relation_scoping_test.rb +++ b/activerecord/test/cases/relation_scoping_test.rb @@ -464,6 +464,11 @@ class DefaultScopingTest < ActiveRecord::TestCase assert_equal 50000, PoorDeveloperCalledJamis.create!(:name => 'David').salary end + def test_default_scope_attribute + jamis = PoorDeveloperCalledJamis.new(:name => 'David') + assert_equal 50000, jamis.salary + end + def test_scope_composed_by_limit_and_then_offset_is_equal_to_scope_composed_by_offset_and_then_limit posts_limit_offset = Post.limit(3).offset(2) posts_offset_limit = Post.offset(2).limit(3) -- cgit v1.2.3 From 76a15dd0599779f86bda063bb545bba68c6ff17b Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 29 Nov 2010 16:41:02 -0800 Subject: adding more tests surrounding where values hash --- activerecord/test/cases/relation_scoping_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb index c7f7738248..1678e631e5 100644 --- a/activerecord/test/cases/relation_scoping_test.rb +++ b/activerecord/test/cases/relation_scoping_test.rb @@ -469,6 +469,17 @@ class DefaultScopingTest < ActiveRecord::TestCase assert_equal 50000, jamis.salary end + def test_where_attribute + aaron = PoorDeveloperCalledJamis.where(:salary => 20).new(:name => 'Aaron') + assert_equal 20, aaron.salary + assert_equal 'Aaron', aaron.name + end + + def test_where_attribute_merge + aaron = PoorDeveloperCalledJamis.where(:name => 'foo').new(:name => 'Aaron') + assert_equal 'Aaron', aaron.name + end + def test_scope_composed_by_limit_and_then_offset_is_equal_to_scope_composed_by_offset_and_then_limit posts_limit_offset = Post.limit(3).offset(2) posts_offset_limit = Post.offset(2).limit(3) -- cgit v1.2.3 From b7a9890d7765a0a6edc1161f58304386266bdf2e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 30 Nov 2010 13:38:48 -0800 Subject: fix whitespace errors --- activerecord/test/cases/connection_pool_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb index f0ec5c751c..2e18117895 100644 --- a/activerecord/test/cases/connection_pool_test.rb +++ b/activerecord/test/cases/connection_pool_test.rb @@ -38,9 +38,9 @@ module ActiveRecord assert_not_nil connection end end - + threads.each {|t| t.join} - + Thread.new do threads.each do |t| thread_ids = pool.instance_variable_get(:@reserved_connections).keys -- cgit v1.2.3 From bfc398cb7083c41becf6e4938c0a80a6659a1caa Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 30 Nov 2010 14:10:55 -0800 Subject: adding a test for ActiveRecord::Relation --- activerecord/test/cases/relation_test.rb | 56 ++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 activerecord/test/cases/relation_test.rb (limited to 'activerecord/test') diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb new file mode 100644 index 0000000000..96856ac22b --- /dev/null +++ b/activerecord/test/cases/relation_test.rb @@ -0,0 +1,56 @@ +require "cases/helper" + +module ActiveRecord + class RelationTest < ActiveRecord::TestCase + def test_construction + relation = nil + assert_nothing_raised do + relation = Relation.new :a, :b + end + assert_equal :a, relation.klass + assert_equal :b, relation.table + assert !relation.loaded, 'relation is not loaded' + end + + def test_single_values + assert_equal [:limit, :offset, :lock, :readonly, :create_with, :from].sort, + Relation::SINGLE_VALUE_METHODS.sort + end + + def test_initialize_single_values + relation = Relation.new :a, :b + Relation::SINGLE_VALUE_METHODS.each do |method| + assert_nil relation.send("#{method}_value"), method.to_s + end + end + + def test_association_methods + assert_equal [:includes, :eager_load, :preload].sort, + Relation::ASSOCIATION_METHODS.sort + end + + def test_initialize_association_methods + relation = Relation.new :a, :b + Relation::ASSOCIATION_METHODS.each do |method| + assert_equal [], relation.send("#{method}_values"), method.to_s + end + end + + def test_multi_value_methods + assert_equal [:select, :group, :order, :joins, :where, :having, :bind].sort, + Relation::MULTI_VALUE_METHODS.sort + end + + def test_multi_value_initialize + relation = Relation.new :a, :b + Relation::MULTI_VALUE_METHODS.each do |method| + assert_equal [], relation.send("#{method}_values"), method.to_s + end + end + + def test_extensions + relation = Relation.new :a, :b + assert_equal [], relation.extensions + end + end +end -- cgit v1.2.3 From 6c32290bac460ce53ea2d29b50047248f9f0de92 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 30 Nov 2010 14:29:35 -0800 Subject: testing Relation#table_name --- activerecord/test/cases/relation_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 96856ac22b..3629f6f806 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -2,6 +2,9 @@ require "cases/helper" module ActiveRecord class RelationTest < ActiveRecord::TestCase + class FakeTable < Struct.new(:table_name) + end + def test_construction relation = nil assert_nothing_raised do @@ -52,5 +55,23 @@ module ActiveRecord relation = Relation.new :a, :b assert_equal [], relation.extensions end + + def test_where_values_hash + relation = Relation.new :a, :b + assert_equal({}, relation.where_values_hash) + + relation.where_values << :hello + assert_equal({}, relation.where_values_hash) + end + + def test_table_name_delegates_to_klass + relation = Relation.new FakeTable.new('foo'), :b + assert_equal 'foo', relation.table_name + end + + def test_scope_for_create + relation = Relation.new :a, :b + assert_equal({}, relation.scope_for_create) + end end end -- cgit v1.2.3 From 795dc3d15fee02c9ccc9da08c8fcee0830a4962a Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 30 Nov 2010 14:47:55 -0800 Subject: adding more tests surrounding where_values_hash --- activerecord/test/cases/relation_test.rb | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 3629f6f806..cc2c2c1446 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -1,8 +1,12 @@ require "cases/helper" +require 'models/post' +require 'models/comment' module ActiveRecord class RelationTest < ActiveRecord::TestCase - class FakeTable < Struct.new(:table_name) + fixtures :posts, :comments + + class FakeKlass < Struct.new(:table_name) end def test_construction @@ -56,7 +60,7 @@ module ActiveRecord assert_equal [], relation.extensions end - def test_where_values_hash + def test_empty_where_values_hash relation = Relation.new :a, :b assert_equal({}, relation.where_values_hash) @@ -64,8 +68,20 @@ module ActiveRecord assert_equal({}, relation.where_values_hash) end + def test_has_values + relation = Relation.new Post, Post.arel_table + relation.where_values << relation.table[:id].eq(10) + assert_equal({:id => 10}, relation.where_values_hash) + end + + def test_values_wrong_table + relation = Relation.new Post, Post.arel_table + relation.where_values << Comment.arel_table[:id].eq(10) + assert_equal({}, relation.where_values_hash) + end + def test_table_name_delegates_to_klass - relation = Relation.new FakeTable.new('foo'), :b + relation = Relation.new FakeKlass.new('foo'), :b assert_equal 'foo', relation.table_name end -- cgit v1.2.3 From 3ad0779e566067f26422a74f108d81ac458e4333 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 30 Nov 2010 14:56:32 -0800 Subject: testing combined nodes are not traversed --- activerecord/test/cases/relation_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index cc2c2c1446..a9244ae65e 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -80,6 +80,15 @@ module ActiveRecord assert_equal({}, relation.where_values_hash) end + def test_tree_is_not_traversed + relation = Relation.new Post, Post.arel_table + left = relation.table[:id].eq(10) + right = relation.table[:id].eq(10) + combine = left.and right + relation.where_values << combine + assert_equal({}, relation.where_values_hash) + end + def test_table_name_delegates_to_klass relation = Relation.new FakeKlass.new('foo'), :b assert_equal 'foo', relation.table_name -- cgit v1.2.3 From dccf624b643398afdf1b0e048e57f04cb182c55e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 30 Nov 2010 15:20:27 -0800 Subject: Ruby 1.8, how does it work? --- activerecord/test/cases/relation_test.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index a9244ae65e..02de0398aa 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -20,8 +20,8 @@ module ActiveRecord end def test_single_values - assert_equal [:limit, :offset, :lock, :readonly, :create_with, :from].sort, - Relation::SINGLE_VALUE_METHODS.sort + assert_equal [:limit, :offset, :lock, :readonly, :create_with, :from].map(&:to_s).sort, + Relation::SINGLE_VALUE_METHODS.map(&:to_s).sort end def test_initialize_single_values @@ -32,8 +32,8 @@ module ActiveRecord end def test_association_methods - assert_equal [:includes, :eager_load, :preload].sort, - Relation::ASSOCIATION_METHODS.sort + assert_equal [:includes, :eager_load, :preload].map(&:to_s).sort, + Relation::ASSOCIATION_METHODS.map(&:to_s).sort end def test_initialize_association_methods @@ -44,8 +44,8 @@ module ActiveRecord end def test_multi_value_methods - assert_equal [:select, :group, :order, :joins, :where, :having, :bind].sort, - Relation::MULTI_VALUE_METHODS.sort + assert_equal [:select, :group, :order, :joins, :where, :having, :bind].map(&:to_s).sort, + Relation::MULTI_VALUE_METHODS.map(&:to_s).sort end def test_multi_value_initialize -- cgit v1.2.3 From b2e7d1e41ec1d40c35aeb201720dfec413c8f95a Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 30 Nov 2010 15:44:30 -0800 Subject: surrounding scope_for_create behavior --- activerecord/test/cases/relation_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 02de0398aa..31d2020acd 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -98,5 +98,19 @@ module ActiveRecord relation = Relation.new :a, :b assert_equal({}, relation.scope_for_create) end + + def test_create_with_value + relation = Relation.new Post, Post.arel_table + hash = { :hello => 'world' } + relation.create_with_value = hash + assert_equal hash, relation.scope_for_create + end + + def test_create_with_value_with_wheres + relation = Relation.new Post, Post.arel_table + relation.where_values << relation.table[:id].eq(10) + relation.create_with_value = {:hello => 'world'} + assert_equal({:hello => 'world', :id => 10}, relation.scope_for_create) + end end end -- cgit v1.2.3 From b293ab7c618f65e06371e9ae7b00fe2a65082209 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 30 Nov 2010 15:45:32 -0800 Subject: making sure scope_for_create value is cached --- activerecord/test/cases/relation_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 31d2020acd..3cc31b3db0 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -112,5 +112,17 @@ module ActiveRecord relation.create_with_value = {:hello => 'world'} assert_equal({:hello => 'world', :id => 10}, relation.scope_for_create) end + + # FIXME: is this really wanted or expected behavior? + def test_scope_for_create_is_cached + relation = Relation.new Post, Post.arel_table + assert_equal({}, relation.scope_for_create) + + relation.where_values << relation.table[:id].eq(10) + assert_equal({}, relation.scope_for_create) + + relation.create_with_value = {:hello => 'world'} + assert_equal({}, relation.scope_for_create) + end end end -- cgit v1.2.3 From 22b01c52c7cccdaa7f4fbed2a66c38a4c5416c6e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 30 Nov 2010 16:10:49 -0800 Subject: isolating eager_loading? method --- activerecord/test/cases/relation_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 3cc31b3db0..7bdbd773b6 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -124,5 +124,16 @@ module ActiveRecord relation.create_with_value = {:hello => 'world'} assert_equal({}, relation.scope_for_create) end + + def test_empty_eager_loading? + relation = Relation.new :a, :b + assert !relation.eager_loading? + end + + def test_eager_load_values + relation = Relation.new :a, :b + relation.eager_load_values << :b + assert relation.eager_loading? + end end end -- cgit v1.2.3 From 542cb5c327f92d3f6ae6159a54e86949441f095e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 30 Nov 2010 18:46:56 -0800 Subject: fix warnings, stop using global variables --- activerecord/test/cases/nested_attributes_test.rb | 3 +-- activerecord/test/models/pet.rb | 6 +++++- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index fb6a239545..ffcc7a081a 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -848,13 +848,12 @@ class TestNestedAttributesWithNonStandardPrimaryKeys < ActiveRecord::TestCase def test_attr_accessor_of_child_should_be_value_provided_during_update_attributes @owner = owners(:ashley) @pet1 = pets(:chew) - assert_equal nil, $current_user attributes = {:pets_attributes => { "1"=> { :id => @pet1.id, :name => "Foo2", :current_user => "John", :_destroy=>true }}} @owner.update_attributes(attributes) - assert_equal 'John', $after_destroy_callback_output + assert_equal 'John', Pet.after_destroy_output end end diff --git a/activerecord/test/models/pet.rb b/activerecord/test/models/pet.rb index 570db4c8d5..113826756a 100644 --- a/activerecord/test/models/pet.rb +++ b/activerecord/test/models/pet.rb @@ -6,8 +6,12 @@ class Pet < ActiveRecord::Base belongs_to :owner, :touch => true has_many :toys + class << self + attr_accessor :after_destroy_output + end + after_destroy do |record| - $after_destroy_callback_output = record.current_user + Pet.after_destroy_output = record.current_user end end -- cgit v1.2.3 From c283cdd63cafdb04784cfcc5094da41c9268c20c Mon Sep 17 00:00:00 2001 From: Josh Susser Date: Mon, 15 Mar 2010 00:53:57 -0700 Subject: Add migrated_at column to schema_migrations table. --- activerecord/test/cases/migration_test.rb | 36 +++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 3037d73a1b..55a24a94f3 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -27,22 +27,46 @@ if ActiveRecord::Base.connection.supports_migrations? end class MigrationTableAndIndexTest < ActiveRecord::TestCase - def test_add_schema_info_respects_prefix_and_suffix - conn = ActiveRecord::Base.connection + def setup + @conn = ActiveRecord::Base.connection + @conn.drop_table(ActiveRecord::Migrator.schema_migrations_table_name) if @conn.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name) + end - conn.drop_table(ActiveRecord::Migrator.schema_migrations_table_name) if conn.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name) + def test_add_schema_migrations_respects_prefix_and_suffix # Use shorter prefix and suffix as in Oracle database identifier cannot be larger than 30 characters ActiveRecord::Base.table_name_prefix = 'p_' ActiveRecord::Base.table_name_suffix = '_s' - conn.drop_table(ActiveRecord::Migrator.schema_migrations_table_name) if conn.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name) + @conn.drop_table(ActiveRecord::Migrator.schema_migrations_table_name) if @conn.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name) - conn.initialize_schema_migrations_table + @conn.initialize_schema_migrations_table - assert_equal "p_unique_schema_migrations_s", conn.indexes(ActiveRecord::Migrator.schema_migrations_table_name)[0][:name] + assert_equal "p_unique_schema_migrations_s", @conn.indexes(ActiveRecord::Migrator.schema_migrations_table_name)[0][:name] ensure ActiveRecord::Base.table_name_prefix = "" ActiveRecord::Base.table_name_suffix = "" end + + def test_schema_migrations_columns + @conn.initialize_schema_migrations_table + + columns = @conn.columns(ActiveRecord::Migrator.schema_migrations_table_name).collect(&:name) + %w[version migrated_at].each { |col| assert columns.include?(col) } + end + + def test_add_migrated_at_to_exisiting_schema_migrations + sm_table = ActiveRecord::Migrator.schema_migrations_table_name + @conn.create_table(sm_table, :id => false) do |schema_migrations_table| + schema_migrations_table.column :version, :string, :null => false + end + @conn.insert "INSERT INTO #{@conn.quote_table_name(sm_table)} (version) VALUES (100)" + @conn.insert "INSERT INTO #{@conn.quote_table_name(sm_table)} (version) VALUES (200)" + + @conn.initialize_schema_migrations_table + + m_ats = @conn.select_values("SELECT migrated_at FROM #{@conn.quote_table_name(sm_table)}") + assert_equal 2, m_ats.length + assert_equal 2, m_ats.compact.length + end end class MigrationTest < ActiveRecord::TestCase -- cgit v1.2.3 From 4e4e9ad48a222ac94a904c62ae684c609bd8e177 Mon Sep 17 00:00:00 2001 From: Josh Susser Date: Tue, 16 Mar 2010 23:02:03 -0700 Subject: record migration timestamp when migrations run --- activerecord/test/cases/migration_test.rb | 49 ++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 55a24a94f3..e76097d42d 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -445,6 +445,43 @@ if ActiveRecord::Base.connection.supports_migrations? Person.connection.drop_table table_name rescue nil end + def test_create_table_with_custom_sequence_name + return unless current_adapter? :OracleAdapter + + # table name is 29 chars, the standard sequence name will + # be 33 chars and fail + assert_raise(ActiveRecord::StatementInvalid) do + begin + Person.connection.create_table :table_with_name_thats_just_ok do |t| + t.column :foo, :string, :null => false + end + ensure + Person.connection.drop_table :table_with_name_thats_just_ok rescue nil + end + end + + # should be all good w/ a custom sequence name + assert_nothing_raised do + begin + Person.connection.create_table :table_with_name_thats_just_ok, + :sequence_name => 'suitably_short_seq' do |t| + t.column :foo, :string, :null => false + end + + Person.connection.execute("select suitably_short_seq.nextval from dual") + + ensure + Person.connection.drop_table :table_with_name_thats_just_ok, + :sequence_name => 'suitably_short_seq' rescue nil + end + end + + # confirm the custom sequence got dropped + assert_raise(ActiveRecord::StatementInvalid) do + Person.connection.execute("select suitably_short_seq.nextval from dual") + end + end + # Sybase, and SQLite3 will not allow you to add a NOT NULL # column to a table without a default value. unless current_adapter?(:SybaseAdapter, :SQLite3Adapter) @@ -1462,6 +1499,17 @@ if ActiveRecord::Base.connection.supports_migrations? ActiveRecord::Base.table_name_suffix = "" end + def test_migration_row_includes_timestamp + conn = ActiveRecord::Base.connection + sm_table = ActiveRecord::Migrator.schema_migrations_table_name + + ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid") + + conn.select_all("SELECT * FROM #{conn.quote_table_name(sm_table)}").each do |row| + assert_match /^2\d\d\d-/, row["migrated_at"], "missing migrated_at" + end + end + def test_proper_table_name assert_equal "table", ActiveRecord::Migrator.proper_table_name('table') assert_equal "table", ActiveRecord::Migrator.proper_table_name(:table) @@ -2117,4 +2165,3 @@ if ActiveRecord::Base.connection.supports_migrations? end end end - -- cgit v1.2.3 From 7139aa878ceea8dd17a60955cd4d07f5f68980d9 Mon Sep 17 00:00:00 2001 From: Josh Susser Date: Sat, 20 Mar 2010 18:26:12 -0700 Subject: name in schema_migrations, migrations in schema dump --- activerecord/test/cases/ar_schema_test.rb | 23 +++++++++++++++++++++++ activerecord/test/cases/migration_test.rb | 20 ++++++++++++-------- activerecord/test/cases/schema_dumper_test.rb | 15 +++++++++++++++ 3 files changed, 50 insertions(+), 8 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/ar_schema_test.rb b/activerecord/test/cases/ar_schema_test.rb index 588adc38e3..e7f3907ff5 100644 --- a/activerecord/test/cases/ar_schema_test.rb +++ b/activerecord/test/cases/ar_schema_test.rb @@ -39,4 +39,27 @@ if ActiveRecord::Base.connection.supports_migrations? end end + class ActiveRecordSchemaMigrationsTest < ActiveRecordSchemaTest + def setup + super + @sm_table = ActiveRecord::Migrator.schema_migrations_table_name + @connection.execute "DELETE FROM #{@connection.quote_table_name(@sm_table)}" + end + + def test_migration_adds_row_to_migrations_table + ActiveRecord::Schema.migration("123001") + ActiveRecord::Schema.migration("123002", "add_magic_power_to_unicorns") + rows = @connection.select_all("SELECT * FROM #{@connection.quote_table_name(@sm_table)}") + assert_equal 2, rows.length + + assert_equal "123001", rows[0]["version"] + assert_equal "", rows[0]["name"] + assert_match /^2\d\d\d-/, rows[0]["migrated_at"] + + assert_equal "123002", rows[1]["version"] + assert_equal "add_magic_power_to_unicorns", rows[1]["name"] + assert_match /^2\d\d\d-/, rows[1]["migrated_at"] + end + end + end diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index e76097d42d..497391e713 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -50,10 +50,10 @@ if ActiveRecord::Base.connection.supports_migrations? @conn.initialize_schema_migrations_table columns = @conn.columns(ActiveRecord::Migrator.schema_migrations_table_name).collect(&:name) - %w[version migrated_at].each { |col| assert columns.include?(col) } + %w[version name migrated_at].each { |col| assert columns.include?(col) } end - def test_add_migrated_at_to_exisiting_schema_migrations + def test_add_name_and_migrated_at_to_exisiting_schema_migrations sm_table = ActiveRecord::Migrator.schema_migrations_table_name @conn.create_table(sm_table, :id => false) do |schema_migrations_table| schema_migrations_table.column :version, :string, :null => false @@ -63,9 +63,9 @@ if ActiveRecord::Base.connection.supports_migrations? @conn.initialize_schema_migrations_table - m_ats = @conn.select_values("SELECT migrated_at FROM #{@conn.quote_table_name(sm_table)}") - assert_equal 2, m_ats.length - assert_equal 2, m_ats.compact.length + rows = @conn.select_all("SELECT * FROM #{@conn.quote_table_name(sm_table)}") + assert rows[0].has_key?("name") + assert rows[0].has_key?("migrated_at") end end @@ -1499,15 +1499,19 @@ if ActiveRecord::Base.connection.supports_migrations? ActiveRecord::Base.table_name_suffix = "" end - def test_migration_row_includes_timestamp + def test_migration_row_includes_name_and_timestamp conn = ActiveRecord::Base.connection sm_table = ActiveRecord::Migrator.schema_migrations_table_name ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid") - conn.select_all("SELECT * FROM #{conn.quote_table_name(sm_table)}").each do |row| - assert_match /^2\d\d\d-/, row["migrated_at"], "missing migrated_at" + rows = conn.select_all("SELECT * FROM #{conn.quote_table_name(sm_table)}") + rows.each do |row| + assert_match( /^2\d\d\d-/, row["migrated_at"], "missing migrated_at" ) end + assert_equal "people_have_last_names", rows[0]["name"] + assert_equal "we_need_reminders", rows[1]["name"] + assert_equal "innocent_jointable", rows[2]["name"] end def test_proper_table_name diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb index 9b2c7c00df..fdcf1b5cd4 100644 --- a/activerecord/test/cases/schema_dumper_test.rb +++ b/activerecord/test/cases/schema_dumper_test.rb @@ -17,6 +17,21 @@ class SchemaDumperTest < ActiveRecord::TestCase assert_no_match %r{create_table "schema_migrations"}, output end + def test_schema_dump_includes_migrations + conn = ActiveRecord::Base.connection + sm_table = ActiveRecord::Migrator.schema_migrations_table_name + conn.execute "DELETE FROM #{conn.quote_table_name(sm_table)}" + conn.remove_column "people", "last_name" rescue nil + conn.drop_table "reminders" rescue nil + conn.drop_table "people_reminders" rescue nil + ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid") + + output = standard_dump + assert_match %r{migration "1", "people_have_last_names"}, output + assert_match %r{migration "2", "we_need_reminders"}, output + assert_match %r{migration "3", "innocent_jointable"}, output + end + def test_schema_dump_excludes_sqlite_sequence output = standard_dump assert_no_match %r{create_table "sqlite_sequence"}, output -- cgit v1.2.3 From b07c2c0fd3130bb69cf8d846e46762a7c3972107 Mon Sep 17 00:00:00 2001 From: Josh Susser Date: Sat, 20 Mar 2010 19:46:17 -0700 Subject: clear schema_migrations in Schema.define --- activerecord/test/cases/ar_schema_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/ar_schema_test.rb b/activerecord/test/cases/ar_schema_test.rb index e7f3907ff5..930a57330d 100644 --- a/activerecord/test/cases/ar_schema_test.rb +++ b/activerecord/test/cases/ar_schema_test.rb @@ -60,6 +60,17 @@ if ActiveRecord::Base.connection.supports_migrations? assert_equal "add_magic_power_to_unicorns", rows[1]["name"] assert_match /^2\d\d\d-/, rows[1]["migrated_at"] end + + def test_define_clears_schema_migrations + assert_nothing_raised do + ActiveRecord::Schema.define do + migration("123001") + end + ActiveRecord::Schema.define do + migration("123001") + end + end + end end end -- cgit v1.2.3 From a49de9811ab4cf39fbdb5a6941ee003b1e489184 Mon Sep 17 00:00:00 2001 From: Josh Susser Date: Wed, 1 Dec 2010 11:56:21 -0800 Subject: tests mostly pass adjust to work with instance-based migations migrated_at can't be null why must people have last names? it's killing me! --- activerecord/test/cases/ar_schema_test.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/ar_schema_test.rb b/activerecord/test/cases/ar_schema_test.rb index 930a57330d..28f219e213 100644 --- a/activerecord/test/cases/ar_schema_test.rb +++ b/activerecord/test/cases/ar_schema_test.rb @@ -47,8 +47,9 @@ if ActiveRecord::Base.connection.supports_migrations? end def test_migration_adds_row_to_migrations_table - ActiveRecord::Schema.migration("123001") - ActiveRecord::Schema.migration("123002", "add_magic_power_to_unicorns") + schema = ActiveRecord::Schema.new + schema.migration("123001") + schema.migration("123002", "add_magic_power_to_unicorns") rows = @connection.select_all("SELECT * FROM #{@connection.quote_table_name(@sm_table)}") assert_equal 2, rows.length -- cgit v1.2.3 From c266a6bf0f219f211979b67396750fc9071b0391 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 1 Dec 2010 14:33:59 -0800 Subject: fixing tests and warnings --- activerecord/test/cases/ar_schema_test.rb | 4 ++-- activerecord/test/cases/schema_dumper_test.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/ar_schema_test.rb b/activerecord/test/cases/ar_schema_test.rb index 28f219e213..e007c12c33 100644 --- a/activerecord/test/cases/ar_schema_test.rb +++ b/activerecord/test/cases/ar_schema_test.rb @@ -55,11 +55,11 @@ if ActiveRecord::Base.connection.supports_migrations? assert_equal "123001", rows[0]["version"] assert_equal "", rows[0]["name"] - assert_match /^2\d\d\d-/, rows[0]["migrated_at"] + assert_match(/^2\d\d\d-/, rows[0]["migrated_at"]) assert_equal "123002", rows[1]["version"] assert_equal "add_magic_power_to_unicorns", rows[1]["name"] - assert_match /^2\d\d\d-/, rows[1]["migrated_at"] + assert_match(/^2\d\d\d-/, rows[1]["migrated_at"]) end def test_define_clears_schema_migrations diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb index fdcf1b5cd4..7914ee0a6f 100644 --- a/activerecord/test/cases/schema_dumper_test.rb +++ b/activerecord/test/cases/schema_dumper_test.rb @@ -18,6 +18,10 @@ class SchemaDumperTest < ActiveRecord::TestCase end def test_schema_dump_includes_migrations + $".delete_if do |fname| + fname == (MIGRATIONS_ROOT + "/valid/1_people_have_last_names.rb") + end + conn = ActiveRecord::Base.connection sm_table = ActiveRecord::Migrator.schema_migrations_table_name conn.execute "DELETE FROM #{conn.quote_table_name(sm_table)}" -- cgit v1.2.3 From 7d2179608c21f1a36a3d0392f251b1ef7a2cf377 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 1 Dec 2010 14:59:17 -0800 Subject: not all databases return dates as strings --- activerecord/test/cases/ar_schema_test.rb | 4 ++-- activerecord/test/cases/migration_test.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/ar_schema_test.rb b/activerecord/test/cases/ar_schema_test.rb index e007c12c33..cab27167b7 100644 --- a/activerecord/test/cases/ar_schema_test.rb +++ b/activerecord/test/cases/ar_schema_test.rb @@ -55,11 +55,11 @@ if ActiveRecord::Base.connection.supports_migrations? assert_equal "123001", rows[0]["version"] assert_equal "", rows[0]["name"] - assert_match(/^2\d\d\d-/, rows[0]["migrated_at"]) + assert_match(/^2\d\d\d-/, rows[0]["migrated_at"].to_s) assert_equal "123002", rows[1]["version"] assert_equal "add_magic_power_to_unicorns", rows[1]["name"] - assert_match(/^2\d\d\d-/, rows[1]["migrated_at"]) + assert_match(/^2\d\d\d-/, rows[1]["migrated_at"].to_s) end def test_define_clears_schema_migrations diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 497391e713..37b2fea275 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1507,7 +1507,7 @@ if ActiveRecord::Base.connection.supports_migrations? rows = conn.select_all("SELECT * FROM #{conn.quote_table_name(sm_table)}") rows.each do |row| - assert_match( /^2\d\d\d-/, row["migrated_at"], "missing migrated_at" ) + assert_match(/^2\d\d\d-/, row["migrated_at"].to_s, "missing migrated_at") end assert_equal "people_have_last_names", rows[0]["name"] assert_equal "we_need_reminders", rows[1]["name"] -- cgit v1.2.3 From 4232454289ec12f8b21a22f764848263acd7af26 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 1 Dec 2010 15:07:44 -0800 Subject: make sure we have a value in migrated_at --- activerecord/test/cases/migration_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 37b2fea275..eed35e83f1 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1507,7 +1507,7 @@ if ActiveRecord::Base.connection.supports_migrations? rows = conn.select_all("SELECT * FROM #{conn.quote_table_name(sm_table)}") rows.each do |row| - assert_match(/^2\d\d\d-/, row["migrated_at"].to_s, "missing migrated_at") + assert_not_nil(row["migrated_at"], "missing migrated_at") end assert_equal "people_have_last_names", rows[0]["name"] assert_equal "we_need_reminders", rows[1]["name"] -- cgit v1.2.3 From 85a5318c2b03bd4a9b5e7ce096207a3a9f052419 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 1 Dec 2010 15:14:10 -0800 Subject: should not to_s the possibly nil value --- activerecord/test/cases/ar_schema_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/ar_schema_test.rb b/activerecord/test/cases/ar_schema_test.rb index cab27167b7..df51a6e4ba 100644 --- a/activerecord/test/cases/ar_schema_test.rb +++ b/activerecord/test/cases/ar_schema_test.rb @@ -55,11 +55,11 @@ if ActiveRecord::Base.connection.supports_migrations? assert_equal "123001", rows[0]["version"] assert_equal "", rows[0]["name"] - assert_match(/^2\d\d\d-/, rows[0]["migrated_at"].to_s) + assert_not_nil(rows[0]["migrated_at"]) assert_equal "123002", rows[1]["version"] assert_equal "add_magic_power_to_unicorns", rows[1]["name"] - assert_match(/^2\d\d\d-/, rows[1]["migrated_at"].to_s) + assert_not_nil(rows[1]["migrated_at"]) end def test_define_clears_schema_migrations -- cgit v1.2.3 From c15c14563e6604aab232336b16e14f1f235cc19d Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 1 Dec 2010 15:14:56 -0800 Subject: removing duplicate test --- activerecord/test/cases/migration_test.rb | 37 ------------------------------- 1 file changed, 37 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index eed35e83f1..b698a5a3cf 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -445,43 +445,6 @@ if ActiveRecord::Base.connection.supports_migrations? Person.connection.drop_table table_name rescue nil end - def test_create_table_with_custom_sequence_name - return unless current_adapter? :OracleAdapter - - # table name is 29 chars, the standard sequence name will - # be 33 chars and fail - assert_raise(ActiveRecord::StatementInvalid) do - begin - Person.connection.create_table :table_with_name_thats_just_ok do |t| - t.column :foo, :string, :null => false - end - ensure - Person.connection.drop_table :table_with_name_thats_just_ok rescue nil - end - end - - # should be all good w/ a custom sequence name - assert_nothing_raised do - begin - Person.connection.create_table :table_with_name_thats_just_ok, - :sequence_name => 'suitably_short_seq' do |t| - t.column :foo, :string, :null => false - end - - Person.connection.execute("select suitably_short_seq.nextval from dual") - - ensure - Person.connection.drop_table :table_with_name_thats_just_ok, - :sequence_name => 'suitably_short_seq' rescue nil - end - end - - # confirm the custom sequence got dropped - assert_raise(ActiveRecord::StatementInvalid) do - Person.connection.execute("select suitably_short_seq.nextval from dual") - end - end - # Sybase, and SQLite3 will not allow you to add a NOT NULL # column to a table without a default value. unless current_adapter?(:SybaseAdapter, :SQLite3Adapter) -- cgit v1.2.3 From 3ec212e3c9c815e9993cbea409c60774ea75cd30 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 1 Dec 2010 17:08:01 -0800 Subject: rolling out migrated_at until I can fix the build --- activerecord/test/cases/ar_schema_test.rb | 35 ------------------ activerecord/test/cases/migration_test.rb | 52 ++++----------------------- activerecord/test/cases/schema_dumper_test.rb | 19 ---------- 3 files changed, 7 insertions(+), 99 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/ar_schema_test.rb b/activerecord/test/cases/ar_schema_test.rb index df51a6e4ba..588adc38e3 100644 --- a/activerecord/test/cases/ar_schema_test.rb +++ b/activerecord/test/cases/ar_schema_test.rb @@ -39,39 +39,4 @@ if ActiveRecord::Base.connection.supports_migrations? end end - class ActiveRecordSchemaMigrationsTest < ActiveRecordSchemaTest - def setup - super - @sm_table = ActiveRecord::Migrator.schema_migrations_table_name - @connection.execute "DELETE FROM #{@connection.quote_table_name(@sm_table)}" - end - - def test_migration_adds_row_to_migrations_table - schema = ActiveRecord::Schema.new - schema.migration("123001") - schema.migration("123002", "add_magic_power_to_unicorns") - rows = @connection.select_all("SELECT * FROM #{@connection.quote_table_name(@sm_table)}") - assert_equal 2, rows.length - - assert_equal "123001", rows[0]["version"] - assert_equal "", rows[0]["name"] - assert_not_nil(rows[0]["migrated_at"]) - - assert_equal "123002", rows[1]["version"] - assert_equal "add_magic_power_to_unicorns", rows[1]["name"] - assert_not_nil(rows[1]["migrated_at"]) - end - - def test_define_clears_schema_migrations - assert_nothing_raised do - ActiveRecord::Schema.define do - migration("123001") - end - ActiveRecord::Schema.define do - migration("123001") - end - end - end - end - end diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index b698a5a3cf..3037d73a1b 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -27,46 +27,22 @@ if ActiveRecord::Base.connection.supports_migrations? end class MigrationTableAndIndexTest < ActiveRecord::TestCase - def setup - @conn = ActiveRecord::Base.connection - @conn.drop_table(ActiveRecord::Migrator.schema_migrations_table_name) if @conn.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name) - end + def test_add_schema_info_respects_prefix_and_suffix + conn = ActiveRecord::Base.connection - def test_add_schema_migrations_respects_prefix_and_suffix + conn.drop_table(ActiveRecord::Migrator.schema_migrations_table_name) if conn.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name) # Use shorter prefix and suffix as in Oracle database identifier cannot be larger than 30 characters ActiveRecord::Base.table_name_prefix = 'p_' ActiveRecord::Base.table_name_suffix = '_s' - @conn.drop_table(ActiveRecord::Migrator.schema_migrations_table_name) if @conn.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name) + conn.drop_table(ActiveRecord::Migrator.schema_migrations_table_name) if conn.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name) - @conn.initialize_schema_migrations_table + conn.initialize_schema_migrations_table - assert_equal "p_unique_schema_migrations_s", @conn.indexes(ActiveRecord::Migrator.schema_migrations_table_name)[0][:name] + assert_equal "p_unique_schema_migrations_s", conn.indexes(ActiveRecord::Migrator.schema_migrations_table_name)[0][:name] ensure ActiveRecord::Base.table_name_prefix = "" ActiveRecord::Base.table_name_suffix = "" end - - def test_schema_migrations_columns - @conn.initialize_schema_migrations_table - - columns = @conn.columns(ActiveRecord::Migrator.schema_migrations_table_name).collect(&:name) - %w[version name migrated_at].each { |col| assert columns.include?(col) } - end - - def test_add_name_and_migrated_at_to_exisiting_schema_migrations - sm_table = ActiveRecord::Migrator.schema_migrations_table_name - @conn.create_table(sm_table, :id => false) do |schema_migrations_table| - schema_migrations_table.column :version, :string, :null => false - end - @conn.insert "INSERT INTO #{@conn.quote_table_name(sm_table)} (version) VALUES (100)" - @conn.insert "INSERT INTO #{@conn.quote_table_name(sm_table)} (version) VALUES (200)" - - @conn.initialize_schema_migrations_table - - rows = @conn.select_all("SELECT * FROM #{@conn.quote_table_name(sm_table)}") - assert rows[0].has_key?("name") - assert rows[0].has_key?("migrated_at") - end end class MigrationTest < ActiveRecord::TestCase @@ -1462,21 +1438,6 @@ if ActiveRecord::Base.connection.supports_migrations? ActiveRecord::Base.table_name_suffix = "" end - def test_migration_row_includes_name_and_timestamp - conn = ActiveRecord::Base.connection - sm_table = ActiveRecord::Migrator.schema_migrations_table_name - - ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid") - - rows = conn.select_all("SELECT * FROM #{conn.quote_table_name(sm_table)}") - rows.each do |row| - assert_not_nil(row["migrated_at"], "missing migrated_at") - end - assert_equal "people_have_last_names", rows[0]["name"] - assert_equal "we_need_reminders", rows[1]["name"] - assert_equal "innocent_jointable", rows[2]["name"] - end - def test_proper_table_name assert_equal "table", ActiveRecord::Migrator.proper_table_name('table') assert_equal "table", ActiveRecord::Migrator.proper_table_name(:table) @@ -2132,3 +2093,4 @@ if ActiveRecord::Base.connection.supports_migrations? end end end + diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb index 7914ee0a6f..9b2c7c00df 100644 --- a/activerecord/test/cases/schema_dumper_test.rb +++ b/activerecord/test/cases/schema_dumper_test.rb @@ -17,25 +17,6 @@ class SchemaDumperTest < ActiveRecord::TestCase assert_no_match %r{create_table "schema_migrations"}, output end - def test_schema_dump_includes_migrations - $".delete_if do |fname| - fname == (MIGRATIONS_ROOT + "/valid/1_people_have_last_names.rb") - end - - conn = ActiveRecord::Base.connection - sm_table = ActiveRecord::Migrator.schema_migrations_table_name - conn.execute "DELETE FROM #{conn.quote_table_name(sm_table)}" - conn.remove_column "people", "last_name" rescue nil - conn.drop_table "reminders" rescue nil - conn.drop_table "people_reminders" rescue nil - ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid") - - output = standard_dump - assert_match %r{migration "1", "people_have_last_names"}, output - assert_match %r{migration "2", "we_need_reminders"}, output - assert_match %r{migration "3", "innocent_jointable"}, output - end - def test_schema_dump_excludes_sqlite_sequence output = standard_dump assert_no_match %r{create_table "sqlite_sequence"}, output -- cgit v1.2.3 From 96eec090dfd50326146b2f690408fefec50c5111 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Thu, 2 Dec 2010 15:36:05 +1300 Subject: Work around a strange piece of Syck behaviour where it checks Model#respond_to? before initializing the object. Things like YAML.load(YAML.dump(@post)) won't work without this. --- activerecord/test/cases/attribute_methods_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index bb0166a60c..3df8197e0d 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -85,6 +85,17 @@ class AttributeMethodsTest < ActiveRecord::TestCase assert !topic.respond_to?("nothingness") assert !topic.respond_to?(:nothingness) end + + + # Syck calls respond_to? before actually calling initialize + def test_respond_to_with_allocated_object + topic = Topic.allocate + assert !topic.respond_to?("nothingness") + assert !topic.respond_to?(:nothingness) + assert_respond_to topic, "title" + assert_respond_to topic, :title + end + def test_array_content topic = Topic.new -- cgit v1.2.3 From da6ce2e2532a5209a224201a08f805f62dff8d72 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 2 Dec 2010 08:44:31 -0800 Subject: adding a test for YAML round trip --- activerecord/test/cases/yaml_serialization_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/yaml_serialization_test.rb b/activerecord/test/cases/yaml_serialization_test.rb index f221def6b6..0fc9918744 100644 --- a/activerecord/test/cases/yaml_serialization_test.rb +++ b/activerecord/test/cases/yaml_serialization_test.rb @@ -2,10 +2,19 @@ require "cases/helper" require 'models/topic' class YamlSerializationTest < ActiveRecord::TestCase + fixtures :topics + def test_to_yaml_with_time_with_zone_should_not_raise_exception Time.zone = ActiveSupport::TimeZone["Pacific Time (US & Canada)"] ActiveRecord::Base.time_zone_aware_attributes = true topic = Topic.new(:written_on => DateTime.now) assert_nothing_raised { topic.to_yaml } end + + def test_roundtrip + topic = Topic.first + assert topic + t = YAML.load YAML.dump topic + assert_equal topic, t + end end -- cgit v1.2.3 From 077ec5a0ed3459816a4666364c722bb512c09bc7 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 2 Dec 2010 08:41:54 -0800 Subject: fixing space errors --- activerecord/test/cases/attribute_methods_test.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 3df8197e0d..8214815bde 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -85,8 +85,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase assert !topic.respond_to?("nothingness") assert !topic.respond_to?(:nothingness) end - - + # Syck calls respond_to? before actually calling initialize def test_respond_to_with_allocated_object topic = Topic.allocate @@ -95,7 +94,6 @@ class AttributeMethodsTest < ActiveRecord::TestCase assert_respond_to topic, "title" assert_respond_to topic, :title end - def test_array_content topic = Topic.new -- cgit v1.2.3 From 42c51b8527e49ae2d7a0f6cc009e53865b7910c1 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 2 Dec 2010 17:59:55 -0200 Subject: Doesn't need to sort, lets users of attribute_names sort them if they want --- activerecord/test/cases/reflection_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb index 3b9e4f42a6..389ca9eae6 100644 --- a/activerecord/test/cases/reflection_test.rb +++ b/activerecord/test/cases/reflection_test.rb @@ -25,7 +25,7 @@ class ReflectionTest < ActiveRecord::TestCase def test_read_attribute_names assert_equal( %w( id title author_name author_email_address bonus_time written_on last_read content group approved replies_count parent_id parent_title type created_at updated_at ).sort, - @first.attribute_names + @first.attribute_names.sort ) end -- cgit v1.2.3 From 47737681fdfe4986dc7426b174f81d2b8daca991 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 3 Dec 2010 11:44:11 -0800 Subject: in the middle of refactoring --- activerecord/test/cases/migration_test.rb | 80 ++++++++-------------- .../interleaved/pass_1/3_innocent_jointable.rb | 12 ---- .../pass_1/3_interleaved_innocent_jointable.rb | 12 ++++ .../pass_2/1_interleaved_people_have_last_names.rb | 9 +++ .../interleaved/pass_2/1_people_have_last_names.rb | 9 --- .../interleaved/pass_2/3_innocent_jointable.rb | 12 ---- .../pass_2/3_interleaved_innocent_jointable.rb | 12 ++++ .../pass_3/1_interleaved_people_have_last_names.rb | 9 +++ .../interleaved/pass_3/1_people_have_last_names.rb | 9 --- .../interleaved/pass_3/2_i_raise_on_down.rb | 8 --- .../pass_3/2_interleaved_i_raise_on_down.rb | 8 +++ .../interleaved/pass_3/3_innocent_jointable.rb | 12 ---- .../pass_3/3_interleaved_innocent_jointable.rb | 12 ++++ .../migrations/valid/1_people_have_last_names.rb | 9 --- .../valid/1_valid_people_have_last_names.rb | 9 +++ .../20100101010101_people_have_last_names.rb | 9 --- ...valid_with_timestamps_people_have_last_names.rb | 9 +++ ...0101_valid_with_timestamps_we_need_reminders.rb | 12 ++++ .../20100201010101_we_need_reminders.rb | 12 ---- .../20100301010101_innocent_jointable.rb | 12 ---- ...101_valid_with_timestamps_innocent_jointable.rb | 12 ++++ 21 files changed, 134 insertions(+), 154 deletions(-) delete mode 100644 activerecord/test/migrations/interleaved/pass_1/3_innocent_jointable.rb create mode 100644 activerecord/test/migrations/interleaved/pass_1/3_interleaved_innocent_jointable.rb create mode 100644 activerecord/test/migrations/interleaved/pass_2/1_interleaved_people_have_last_names.rb delete mode 100644 activerecord/test/migrations/interleaved/pass_2/1_people_have_last_names.rb delete mode 100644 activerecord/test/migrations/interleaved/pass_2/3_innocent_jointable.rb create mode 100644 activerecord/test/migrations/interleaved/pass_2/3_interleaved_innocent_jointable.rb create mode 100644 activerecord/test/migrations/interleaved/pass_3/1_interleaved_people_have_last_names.rb delete mode 100644 activerecord/test/migrations/interleaved/pass_3/1_people_have_last_names.rb delete mode 100644 activerecord/test/migrations/interleaved/pass_3/2_i_raise_on_down.rb create mode 100644 activerecord/test/migrations/interleaved/pass_3/2_interleaved_i_raise_on_down.rb delete mode 100644 activerecord/test/migrations/interleaved/pass_3/3_innocent_jointable.rb create mode 100644 activerecord/test/migrations/interleaved/pass_3/3_interleaved_innocent_jointable.rb delete mode 100644 activerecord/test/migrations/valid/1_people_have_last_names.rb create mode 100644 activerecord/test/migrations/valid/1_valid_people_have_last_names.rb delete mode 100644 activerecord/test/migrations/valid_with_timestamps/20100101010101_people_have_last_names.rb create mode 100644 activerecord/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb create mode 100644 activerecord/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb delete mode 100644 activerecord/test/migrations/valid_with_timestamps/20100201010101_we_need_reminders.rb delete mode 100644 activerecord/test/migrations/valid_with_timestamps/20100301010101_innocent_jointable.rb create mode 100644 activerecord/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb (limited to 'activerecord/test') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 3037d73a1b..d7ff3e68d9 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -5,10 +5,8 @@ require 'models/person' require 'models/topic' require 'models/developer' -require MIGRATIONS_ROOT + "/valid/1_people_have_last_names" require MIGRATIONS_ROOT + "/valid/2_we_need_reminders" require MIGRATIONS_ROOT + "/decimal/1_give_me_big_numbers" -require MIGRATIONS_ROOT + "/interleaved/pass_3/2_i_raise_on_down" if ActiveRecord::Base.connection.supports_migrations? class BigNumber < ActiveRecord::Base; end @@ -21,8 +19,8 @@ if ActiveRecord::Base.connection.supports_migrations? end def puts(text="") - self.class.message_count ||= 0 - self.class.message_count += 1 + ActiveRecord::Migration.message_count ||= 0 + ActiveRecord::Migration.message_count += 1 end end @@ -52,7 +50,7 @@ if ActiveRecord::Base.connection.supports_migrations? def setup ActiveRecord::Migration.verbose = true - PeopleHaveLastNames.message_count = 0 + ActiveRecord::Migration.message_count = 0 end def teardown @@ -1271,7 +1269,7 @@ if ActiveRecord::Base.connection.supports_migrations? def test_finds_migrations migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/valid").migrations - [[1, 'PeopleHaveLastNames'], [2, 'WeNeedReminders'], [3, 'InnocentJointable']].each_with_index do |pair, i| + [[1, 'ValidPeopleHaveLastNames'], [2, 'WeNeedReminders'], [3, 'InnocentJointable']].each_with_index do |pair, i| assert_equal migrations[i].version, pair.first assert_equal migrations[i].name, pair.last end @@ -1283,39 +1281,30 @@ if ActiveRecord::Base.connection.supports_migrations? assert_equal 1, migrations.size assert_equal migrations[0].version, 3 - assert_equal migrations[0].name, 'InnocentJointable' + assert_equal migrations[0].name, 'InterleavedInnocentJointable' end def test_relative_migrations - $".delete_if do |fname| - fname == (MIGRATIONS_ROOT + "/valid/1_people_have_last_names.rb") - end - Object.send(:remove_const, :PeopleHaveLastNames) - - Dir.chdir(MIGRATIONS_ROOT) do + list = Dir.chdir(MIGRATIONS_ROOT) do ActiveRecord::Migrator.up("valid/", 1) end - assert defined?(PeopleHaveLastNames) + migration_proxy = list.find { |item| + item.name == 'ValidPeopleHaveLastNames' + } + assert migration_proxy, 'should find pending migration' end def test_only_loads_pending_migrations # migrate up to 1 ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1) - # now unload the migrations that have been defined - Object.send(:remove_const, :PeopleHaveLastNames) - - ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", nil) + proxies = ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", nil) - assert !defined? PeopleHaveLastNames - - %w(WeNeedReminders, InnocentJointable).each do |migration| - assert defined? migration - end - - ensure - load(MIGRATIONS_ROOT + "/valid/1_people_have_last_names.rb") + names = proxies.map(&:name) + assert !names.include?('ValidPeopleHaveLastNames') + assert names.include?('WeNeedReminders') + assert names.include?('InnocentJointable') end def test_target_version_zero_should_run_only_once @@ -1325,16 +1314,9 @@ if ActiveRecord::Base.connection.supports_migrations? # migrate down to 0 ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 0) - # now unload the migrations that have been defined - PeopleHaveLastNames.unloadable - ActiveSupport::Dependencies.remove_unloadable_constants! - # migrate down to 0 again - ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 0) - - assert !defined? PeopleHaveLastNames - ensure - load(MIGRATIONS_ROOT + "/valid/1_people_have_last_names.rb") + proxies = ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 0) + assert_equal [], proxies end def test_migrator_db_has_no_schema_migrations_table @@ -1351,20 +1333,20 @@ if ActiveRecord::Base.connection.supports_migrations? def test_migrator_verbosity ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1) - assert_operator PeopleHaveLastNames.message_count, :>, 0 - PeopleHaveLastNames.message_count = 0 + assert_not_equal 0, ActiveRecord::Migration.message_count + ActiveRecord::Migration.message_count = 0 ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", 0) - assert_operator PeopleHaveLastNames.message_count, :>, 0 - PeopleHaveLastNames.message_count = 0 + assert_not_equal 0, ActiveRecord::Migration.message_count + ActiveRecord::Migration.message_count = 0 end def test_migrator_verbosity_off - PeopleHaveLastNames.verbose = false + ActiveRecord::Migration.verbose = false ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1) - assert_equal 0, PeopleHaveLastNames.message_count + assert_equal 0, ActiveRecord::Migration.message_count ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", 0) - assert_equal 0, PeopleHaveLastNames.message_count + assert_equal 0, ActiveRecord::Migration.message_count end def test_migrator_going_down_due_to_version_target @@ -1658,10 +1640,6 @@ if ActiveRecord::Base.connection.supports_migrations? end # SexyMigrationsTest class MigrationLoggerTest < ActiveRecord::TestCase - def setup - Object.send(:remove_const, :InnocentJointable) - end - def test_migration_should_be_run_without_logger previous_logger = ActiveRecord::Base.logger ActiveRecord::Base.logger = nil @@ -1675,7 +1653,7 @@ if ActiveRecord::Base.connection.supports_migrations? class InterleavedMigrationsTest < ActiveRecord::TestCase def setup - Object.send(:remove_const, :PeopleHaveLastNames) + #Object.send(:remove_const, :PeopleHaveLastNames) end def test_migrator_interleaved_migrations @@ -1688,10 +1666,12 @@ if ActiveRecord::Base.connection.supports_migrations? Person.reset_column_information assert Person.column_methods_hash.include?(:last_name) - Object.send(:remove_const, :PeopleHaveLastNames) - Object.send(:remove_const, :InnocentJointable) assert_nothing_raised do - ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/interleaved/pass_3") + proxies = ActiveRecord::Migrator.down( + MIGRATIONS_ROOT + "/interleaved/pass_3") + names = proxies.map(&:name) + assert names.include?('InterleavedPeopleHaveLastNames') + assert names.include?('InterleavedInnocentJointable') end end end diff --git a/activerecord/test/migrations/interleaved/pass_1/3_innocent_jointable.rb b/activerecord/test/migrations/interleaved/pass_1/3_innocent_jointable.rb deleted file mode 100644 index 21c9ca5328..0000000000 --- a/activerecord/test/migrations/interleaved/pass_1/3_innocent_jointable.rb +++ /dev/null @@ -1,12 +0,0 @@ -class InnocentJointable < ActiveRecord::Migration - def self.up - create_table("people_reminders", :id => false) do |t| - t.column :reminder_id, :integer - t.column :person_id, :integer - end - end - - def self.down - drop_table "people_reminders" - end -end \ No newline at end of file diff --git a/activerecord/test/migrations/interleaved/pass_1/3_interleaved_innocent_jointable.rb b/activerecord/test/migrations/interleaved/pass_1/3_interleaved_innocent_jointable.rb new file mode 100644 index 0000000000..bf912fbfc8 --- /dev/null +++ b/activerecord/test/migrations/interleaved/pass_1/3_interleaved_innocent_jointable.rb @@ -0,0 +1,12 @@ +class InterleavedInnocentJointable < ActiveRecord::Migration + def self.up + create_table("people_reminders", :id => false) do |t| + t.column :reminder_id, :integer + t.column :person_id, :integer + end + end + + def self.down + drop_table "people_reminders" + end +end diff --git a/activerecord/test/migrations/interleaved/pass_2/1_interleaved_people_have_last_names.rb b/activerecord/test/migrations/interleaved/pass_2/1_interleaved_people_have_last_names.rb new file mode 100644 index 0000000000..c6c94213a0 --- /dev/null +++ b/activerecord/test/migrations/interleaved/pass_2/1_interleaved_people_have_last_names.rb @@ -0,0 +1,9 @@ +class InterleavedPeopleHaveLastNames < ActiveRecord::Migration + def self.up + add_column "people", "last_name", :string + end + + def self.down + remove_column "people", "last_name" + end +end diff --git a/activerecord/test/migrations/interleaved/pass_2/1_people_have_last_names.rb b/activerecord/test/migrations/interleaved/pass_2/1_people_have_last_names.rb deleted file mode 100644 index 81af5fef5e..0000000000 --- a/activerecord/test/migrations/interleaved/pass_2/1_people_have_last_names.rb +++ /dev/null @@ -1,9 +0,0 @@ -class PeopleHaveLastNames < ActiveRecord::Migration - def self.up - add_column "people", "last_name", :string - end - - def self.down - remove_column "people", "last_name" - end -end \ No newline at end of file diff --git a/activerecord/test/migrations/interleaved/pass_2/3_innocent_jointable.rb b/activerecord/test/migrations/interleaved/pass_2/3_innocent_jointable.rb deleted file mode 100644 index 21c9ca5328..0000000000 --- a/activerecord/test/migrations/interleaved/pass_2/3_innocent_jointable.rb +++ /dev/null @@ -1,12 +0,0 @@ -class InnocentJointable < ActiveRecord::Migration - def self.up - create_table("people_reminders", :id => false) do |t| - t.column :reminder_id, :integer - t.column :person_id, :integer - end - end - - def self.down - drop_table "people_reminders" - end -end \ No newline at end of file diff --git a/activerecord/test/migrations/interleaved/pass_2/3_interleaved_innocent_jointable.rb b/activerecord/test/migrations/interleaved/pass_2/3_interleaved_innocent_jointable.rb new file mode 100644 index 0000000000..bf912fbfc8 --- /dev/null +++ b/activerecord/test/migrations/interleaved/pass_2/3_interleaved_innocent_jointable.rb @@ -0,0 +1,12 @@ +class InterleavedInnocentJointable < ActiveRecord::Migration + def self.up + create_table("people_reminders", :id => false) do |t| + t.column :reminder_id, :integer + t.column :person_id, :integer + end + end + + def self.down + drop_table "people_reminders" + end +end diff --git a/activerecord/test/migrations/interleaved/pass_3/1_interleaved_people_have_last_names.rb b/activerecord/test/migrations/interleaved/pass_3/1_interleaved_people_have_last_names.rb new file mode 100644 index 0000000000..c6c94213a0 --- /dev/null +++ b/activerecord/test/migrations/interleaved/pass_3/1_interleaved_people_have_last_names.rb @@ -0,0 +1,9 @@ +class InterleavedPeopleHaveLastNames < ActiveRecord::Migration + def self.up + add_column "people", "last_name", :string + end + + def self.down + remove_column "people", "last_name" + end +end diff --git a/activerecord/test/migrations/interleaved/pass_3/1_people_have_last_names.rb b/activerecord/test/migrations/interleaved/pass_3/1_people_have_last_names.rb deleted file mode 100644 index 81af5fef5e..0000000000 --- a/activerecord/test/migrations/interleaved/pass_3/1_people_have_last_names.rb +++ /dev/null @@ -1,9 +0,0 @@ -class PeopleHaveLastNames < ActiveRecord::Migration - def self.up - add_column "people", "last_name", :string - end - - def self.down - remove_column "people", "last_name" - end -end \ No newline at end of file diff --git a/activerecord/test/migrations/interleaved/pass_3/2_i_raise_on_down.rb b/activerecord/test/migrations/interleaved/pass_3/2_i_raise_on_down.rb deleted file mode 100644 index 9b1ce9f017..0000000000 --- a/activerecord/test/migrations/interleaved/pass_3/2_i_raise_on_down.rb +++ /dev/null @@ -1,8 +0,0 @@ -class IRaiseOnDown < ActiveRecord::Migration - def self.up - end - - def self.down - raise - end -end \ No newline at end of file diff --git a/activerecord/test/migrations/interleaved/pass_3/2_interleaved_i_raise_on_down.rb b/activerecord/test/migrations/interleaved/pass_3/2_interleaved_i_raise_on_down.rb new file mode 100644 index 0000000000..6849995f5e --- /dev/null +++ b/activerecord/test/migrations/interleaved/pass_3/2_interleaved_i_raise_on_down.rb @@ -0,0 +1,8 @@ +class InterleavedIRaiseOnDown < ActiveRecord::Migration + def self.up + end + + def self.down + raise + end +end diff --git a/activerecord/test/migrations/interleaved/pass_3/3_innocent_jointable.rb b/activerecord/test/migrations/interleaved/pass_3/3_innocent_jointable.rb deleted file mode 100644 index 21c9ca5328..0000000000 --- a/activerecord/test/migrations/interleaved/pass_3/3_innocent_jointable.rb +++ /dev/null @@ -1,12 +0,0 @@ -class InnocentJointable < ActiveRecord::Migration - def self.up - create_table("people_reminders", :id => false) do |t| - t.column :reminder_id, :integer - t.column :person_id, :integer - end - end - - def self.down - drop_table "people_reminders" - end -end \ No newline at end of file diff --git a/activerecord/test/migrations/interleaved/pass_3/3_interleaved_innocent_jointable.rb b/activerecord/test/migrations/interleaved/pass_3/3_interleaved_innocent_jointable.rb new file mode 100644 index 0000000000..bf912fbfc8 --- /dev/null +++ b/activerecord/test/migrations/interleaved/pass_3/3_interleaved_innocent_jointable.rb @@ -0,0 +1,12 @@ +class InterleavedInnocentJointable < ActiveRecord::Migration + def self.up + create_table("people_reminders", :id => false) do |t| + t.column :reminder_id, :integer + t.column :person_id, :integer + end + end + + def self.down + drop_table "people_reminders" + end +end diff --git a/activerecord/test/migrations/valid/1_people_have_last_names.rb b/activerecord/test/migrations/valid/1_people_have_last_names.rb deleted file mode 100644 index 81af5fef5e..0000000000 --- a/activerecord/test/migrations/valid/1_people_have_last_names.rb +++ /dev/null @@ -1,9 +0,0 @@ -class PeopleHaveLastNames < ActiveRecord::Migration - def self.up - add_column "people", "last_name", :string - end - - def self.down - remove_column "people", "last_name" - end -end \ No newline at end of file diff --git a/activerecord/test/migrations/valid/1_valid_people_have_last_names.rb b/activerecord/test/migrations/valid/1_valid_people_have_last_names.rb new file mode 100644 index 0000000000..06cb911117 --- /dev/null +++ b/activerecord/test/migrations/valid/1_valid_people_have_last_names.rb @@ -0,0 +1,9 @@ +class ValidPeopleHaveLastNames < ActiveRecord::Migration + def self.up + add_column "people", "last_name", :string + end + + def self.down + remove_column "people", "last_name" + end +end diff --git a/activerecord/test/migrations/valid_with_timestamps/20100101010101_people_have_last_names.rb b/activerecord/test/migrations/valid_with_timestamps/20100101010101_people_have_last_names.rb deleted file mode 100644 index 81af5fef5e..0000000000 --- a/activerecord/test/migrations/valid_with_timestamps/20100101010101_people_have_last_names.rb +++ /dev/null @@ -1,9 +0,0 @@ -class PeopleHaveLastNames < ActiveRecord::Migration - def self.up - add_column "people", "last_name", :string - end - - def self.down - remove_column "people", "last_name" - end -end \ No newline at end of file diff --git a/activerecord/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb b/activerecord/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb new file mode 100644 index 0000000000..1da99ceaba --- /dev/null +++ b/activerecord/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb @@ -0,0 +1,9 @@ +class ValidWithTimestampsPeopleHaveLastNames < ActiveRecord::Migration + def self.up + add_column "people", "last_name", :string + end + + def self.down + remove_column "people", "last_name" + end +end diff --git a/activerecord/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb b/activerecord/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb new file mode 100644 index 0000000000..cb6d735c8b --- /dev/null +++ b/activerecord/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb @@ -0,0 +1,12 @@ +class ValidWithTimestampsWeNeedReminders < ActiveRecord::Migration + def self.up + create_table("reminders") do |t| + t.column :content, :text + t.column :remind_at, :datetime + end + end + + def self.down + drop_table "reminders" + end +end diff --git a/activerecord/test/migrations/valid_with_timestamps/20100201010101_we_need_reminders.rb b/activerecord/test/migrations/valid_with_timestamps/20100201010101_we_need_reminders.rb deleted file mode 100644 index d5e71ce8ef..0000000000 --- a/activerecord/test/migrations/valid_with_timestamps/20100201010101_we_need_reminders.rb +++ /dev/null @@ -1,12 +0,0 @@ -class WeNeedReminders < ActiveRecord::Migration - def self.up - create_table("reminders") do |t| - t.column :content, :text - t.column :remind_at, :datetime - end - end - - def self.down - drop_table "reminders" - end -end \ No newline at end of file diff --git a/activerecord/test/migrations/valid_with_timestamps/20100301010101_innocent_jointable.rb b/activerecord/test/migrations/valid_with_timestamps/20100301010101_innocent_jointable.rb deleted file mode 100644 index 21c9ca5328..0000000000 --- a/activerecord/test/migrations/valid_with_timestamps/20100301010101_innocent_jointable.rb +++ /dev/null @@ -1,12 +0,0 @@ -class InnocentJointable < ActiveRecord::Migration - def self.up - create_table("people_reminders", :id => false) do |t| - t.column :reminder_id, :integer - t.column :person_id, :integer - end - end - - def self.down - drop_table "people_reminders" - end -end \ No newline at end of file diff --git a/activerecord/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb b/activerecord/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb new file mode 100644 index 0000000000..4bd4b4714d --- /dev/null +++ b/activerecord/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb @@ -0,0 +1,12 @@ +class ValidWithTimestampsInnocentJointable < ActiveRecord::Migration + def self.up + create_table("people_reminders", :id => false) do |t| + t.column :reminder_id, :integer + t.column :person_id, :integer + end + end + + def self.down + drop_table "people_reminders" + end +end -- cgit v1.2.3 From 399730bdd2f133e9fecac501e2f2333be5f29aa2 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 3 Dec 2010 11:51:33 -0800 Subject: removing unused setup --- activerecord/test/cases/migration_test.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index d7ff3e68d9..96da3be655 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1652,10 +1652,6 @@ if ActiveRecord::Base.connection.supports_migrations? end class InterleavedMigrationsTest < ActiveRecord::TestCase - def setup - #Object.send(:remove_const, :PeopleHaveLastNames) - end - def test_migrator_interleaved_migrations ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/interleaved/pass_1") -- cgit v1.2.3 From a299fcaef90741090c5719d0569715c209149a59 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 3 Dec 2010 16:22:42 -0800 Subject: not a responsibility for rails to test --- activerecord/test/cases/associations/join_model_test.rb | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb index 1ece961d2e..4581cb1acd 100644 --- a/activerecord/test/cases/associations/join_model_test.rb +++ b/activerecord/test/cases/associations/join_model_test.rb @@ -44,16 +44,6 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase assert !authors(:mary).unique_categorized_posts.loaded? end - def test_column_caching - # pre-heat our cache - Post.arel_table.columns - Comment.columns - - Post.connection.column_calls = 0 - 2.times { Post.joins(:comments).to_a } - assert_equal 0, Post.connection.column_calls - end - def test_has_many_uniq_through_find assert_equal 1, authors(:mary).unique_categorized_posts.find(:all).size end -- cgit v1.2.3 From d0467e08e54a84fc4672c508716615aa0177994a Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 3 Dec 2010 13:12:59 +0100 Subject: Allow to run migrations from more than one directory --- activerecord/test/cases/migration_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 96da3be655..95b7ce9f34 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1275,6 +1275,18 @@ if ActiveRecord::Base.connection.supports_migrations? end end + def test_finds_migrations_from_two_directories + directories = [MIGRATIONS_ROOT + '/valid_with_timestamps', MIGRATIONS_ROOT + '/to_copy_with_timestamps'] + migrations = ActiveRecord::Migrator.new(:up, directories).migrations + + [[20090101010101, "PeopleHaveHobbies"], [20090101010202, "PeopleHaveDescriptions"], + [20100101010101, "PeopleHaveLastNames"], [20100201010101, "WeNeedReminders"], + [20100301010101, "InnocentJointable"]].each_with_index do |pair, i| + assert_equal migrations[i].version, pair.first + assert_equal migrations[i].name, pair.last + end + end + def test_finds_pending_migrations ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/interleaved/pass_2", 1) migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/interleaved/pass_2").pending_migrations -- cgit v1.2.3 From 7ecee054a322e214e4f285b1a8327751bd79a418 Mon Sep 17 00:00:00 2001 From: Jeff Dean Date: Fri, 3 Dec 2010 23:16:45 -0700 Subject: Setting the id of a belongs_to object updates all referenced objects [#2989 state:resolved] --- .../associations/belongs_to_associations_test.rb | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 1b0c00bd5a..1820f95261 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -486,4 +486,41 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase new_firm = accounts(:signals37).build_firm(:name => 'Apple') assert_equal new_firm.name, "Apple" end + + def test_reassigning_the_parent_id_updates_the_object + original_parent = Firm.create! :name => "original" + updated_parent = Firm.create! :name => "updated" + + client = Client.new("client_of" => original_parent.id) + assert_equal original_parent, client.firm + assert_equal original_parent, client.firm_with_condition + assert_equal original_parent, client.firm_with_other_name + + client.client_of = updated_parent.id + assert_equal updated_parent, client.firm + assert_equal updated_parent, client.firm_with_condition + assert_equal updated_parent, client.firm_with_other_name + end + + def test_polymorphic_reassignment_of_associated_id_updates_the_object + member1 = Member.create! + member2 = Member.create! + + sponsor = Sponsor.new("sponsorable_type" => "Member", "sponsorable_id" => member1.id) + assert_equal member1, sponsor.sponsorable + + sponsor.sponsorable_id = member2.id + assert_equal member2, sponsor.sponsorable + end + + def test_polymorphic_reassignment_of_associated_type_updates_the_object + member1 = Member.create! + + sponsor = Sponsor.new("sponsorable_type" => "Member", "sponsorable_id" => member1.id) + assert_equal member1, sponsor.sponsorable + + sponsor.sponsorable_type = "Firm" + assert_not_equal member1, sponsor.sponsorable + end + end -- cgit v1.2.3 From 7a237d56aa38c51987af0fd52d001989c4f3da07 Mon Sep 17 00:00:00 2001 From: Aditya Sanghi Date: Mon, 29 Nov 2010 18:13:17 +0530 Subject: Ensure that boolean false is properly serialized [#6079 state:resolved] --- activerecord/test/cases/base_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index c3ba1f0c35..86d4a90fc4 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -997,6 +997,22 @@ class BasicsTest < ActiveRecord::TestCase Topic.serialize(:content) end + def test_serialized_boolean_value_true + Topic.serialize(:content) + topic = Topic.new(:content => true) + assert topic.save + topic = topic.reload + assert_equal topic.content, true + end + + def test_serialized_boolean_value_false + Topic.serialize(:content) + topic = Topic.new(:content => false) + assert topic.save + topic = topic.reload + assert_equal topic.content, false + end + def test_quote author_name = "\\ \001 ' \n \\n \"" topic = Topic.create('author_name' => author_name) -- cgit v1.2.3 From f572a02b94ce85bb8db64e838aa159cf3ef4b1fa Mon Sep 17 00:00:00 2001 From: Mike Dvorkin Date: Wed, 8 Dec 2010 20:39:46 -0800 Subject: Take into account current time zone when serializing datetime values [#6096 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/xml_serialization_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/xml_serialization_test.rb b/activerecord/test/cases/xml_serialization_test.rb index b11b340e94..2003e25e35 100644 --- a/activerecord/test/cases/xml_serialization_test.rb +++ b/activerecord/test/cases/xml_serialization_test.rb @@ -4,6 +4,7 @@ require 'models/post' require 'models/author' require 'models/comment' require 'models/company_in_module' +require 'models/toy' class XmlSerializationTest < ActiveRecord::TestCase def test_should_serialize_default_root @@ -83,6 +84,26 @@ class DefaultXmlSerializationTest < ActiveRecord::TestCase end end +class DefaultXmlSerializationTimezoneTest < ActiveRecord::TestCase + def test_should_serialize_datetime_with_timezone + timezone, Time.zone = Time.zone, "Pacific Time (US & Canada)" + + toy = Toy.create(:name => 'Mickey', :updated_at => Time.utc(2006, 8, 1)) + assert_match %r{2006-07-31T17:00:00-07:00}, toy.to_xml + ensure + Time.zone = timezone + end + + def test_should_serialize_datetime_with_timezone_reloaded + timezone, Time.zone = Time.zone, "Pacific Time (US & Canada)" + + toy = Toy.create(:name => 'Minnie', :updated_at => Time.utc(2006, 8, 1)).reload + assert_match %r{2006-07-31T17:00:00-07:00}, toy.to_xml + ensure + Time.zone = timezone + end +end + class NilXmlSerializationTest < ActiveRecord::TestCase def setup @xml = Contact.new.to_xml(:root => 'xml_contact') -- cgit v1.2.3 From 6f8958277b4ba96dc6185a476a7a00a6c1d99892 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 9 Dec 2010 18:02:09 +0100 Subject: Fix test on finding migrations from 2 paths 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 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 95b7ce9f34..1a65045ded 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1279,11 +1279,13 @@ if ActiveRecord::Base.connection.supports_migrations? directories = [MIGRATIONS_ROOT + '/valid_with_timestamps', MIGRATIONS_ROOT + '/to_copy_with_timestamps'] migrations = ActiveRecord::Migrator.new(:up, directories).migrations - [[20090101010101, "PeopleHaveHobbies"], [20090101010202, "PeopleHaveDescriptions"], - [20100101010101, "PeopleHaveLastNames"], [20100201010101, "WeNeedReminders"], - [20100301010101, "InnocentJointable"]].each_with_index do |pair, i| - assert_equal migrations[i].version, pair.first - assert_equal migrations[i].name, pair.last + [[20090101010101, "PeopleHaveHobbies"], + [20090101010202, "PeopleHaveDescriptions"], + [20100101010101, "ValidWithTimestampsPeopleHaveLastNames"], + [20100201010101, "ValidWithTimestampsWeNeedReminders"], + [20100301010101, "ValidWithTimestampsInnocentJointable"]].each_with_index do |pair, i| + assert_equal pair.first, migrations[i].version + assert_equal pair.last, migrations[i].name end end -- cgit v1.2.3 From bba3dacc3dc6ac379209f2eda0da5d2dd93d6b04 Mon Sep 17 00:00:00 2001 From: "Robert Pankowecki (Gavdi)" Date: Fri, 26 Nov 2010 19:16:13 +0100 Subject: Simplifies observer implementation [#6065 state:resolved] --- activerecord/test/cases/lifecycle_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/lifecycle_test.rb b/activerecord/test/cases/lifecycle_test.rb index 233338498f..b8c3ffb9cb 100644 --- a/activerecord/test/cases/lifecycle_test.rb +++ b/activerecord/test/cases/lifecycle_test.rb @@ -9,10 +9,19 @@ class SpecialDeveloper < Developer; end class SalaryChecker < ActiveRecord::Observer observe :special_developer + attr_accessor :last_saved def before_save(developer) return developer.salary > 80000 end + + module Implementation + def after_save(developer) + self.last_saved = developer + end + end + include Implementation + end class TopicaAuditor < ActiveRecord::Observer @@ -179,4 +188,11 @@ class LifecycleTest < ActiveRecord::TestCase developer = SpecialDeveloper.new :name => 'Rookie', :salary => 50000 assert !developer.save, "allowed to save a developer with too low salary" end + + test "able to call methods defined with included module" do # https://rails.lighthouseapp.com/projects/8994/tickets/6065-activerecordobserver-is-not-aware-of-method-added-by-including-modules + SalaryChecker.instance # activate + developer = SpecialDeveloper.create! :name => 'Roger', :salary => 100000 + assert_equal developer, SalaryChecker.instance.last_saved + end + end -- cgit v1.2.3 From 3e7c351b486356757631de9a89ea775c9bed658f Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 9 Dec 2010 15:12:48 -0800 Subject: preheating cache so that tests can run in isolation --- activerecord/test/cases/associations/eager_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index ea86ac29d0..c96ca90750 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -24,6 +24,11 @@ class EagerAssociationTest < ActiveRecord::TestCase :owners, :pets, :author_favorites, :jobs, :references, :subscribers, :subscriptions, :books, :developers, :projects, :developers_projects + def setup + # preheat table existence caches + Comment.find_by_id(1) + end + def test_loading_with_one_association posts = Post.find(:all, :include => :comments) post = posts.find { |p| p.id == 1 } -- cgit v1.2.3