diff options
Diffstat (limited to 'activerecord/test')
25 files changed, 281 insertions, 159 deletions
diff --git a/activerecord/test/cases/adapters/mysql/connection_test.rb b/activerecord/test/cases/adapters/mysql/connection_test.rb index 534dc2c2df..ffd6904aec 100644 --- a/activerecord/test/cases/adapters/mysql/connection_test.rb +++ b/activerecord/test/cases/adapters/mysql/connection_test.rb @@ -137,6 +137,23 @@ class MysqlConnectionTest < ActiveRecord::TestCase end end + def test_mysql_set_session_variable + run_without_connection do |orig_connection| + ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:default_week_format => 3}})) + session_mode = ActiveRecord::Base.connection.exec_query "SELECT @@SESSION.DEFAULT_WEEK_FORMAT" + assert_equal 3, session_mode.rows.first.first.to_i + end + end + + def test_mysql_set_session_variable_to_default + run_without_connection do |orig_connection| + ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:default_week_format => :default}})) + global_mode = ActiveRecord::Base.connection.exec_query "SELECT @@GLOBAL.DEFAULT_WEEK_FORMAT" + session_mode = ActiveRecord::Base.connection.exec_query "SELECT @@SESSION.DEFAULT_WEEK_FORMAT" + assert_equal global_mode.rows, session_mode.rows + end + end + private def run_without_connection diff --git a/activerecord/test/cases/adapters/mysql2/connection_test.rb b/activerecord/test/cases/adapters/mysql2/connection_test.rb index 14c22d2519..1265cb927e 100644 --- a/activerecord/test/cases/adapters/mysql2/connection_test.rb +++ b/activerecord/test/cases/adapters/mysql2/connection_test.rb @@ -53,6 +53,23 @@ class MysqlConnectionTest < ActiveRecord::TestCase end end + def test_mysql_set_session_variable + run_without_connection do |orig_connection| + ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:default_week_format => 3}})) + session_mode = ActiveRecord::Base.connection.exec_query "SELECT @@SESSION.DEFAULT_WEEK_FORMAT" + assert_equal 3, session_mode.rows.first.first.to_i + end + end + + def test_mysql_set_session_variable_to_default + run_without_connection do |orig_connection| + ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:default_week_format => :default}})) + global_mode = ActiveRecord::Base.connection.exec_query "SELECT @@GLOBAL.DEFAULT_WEEK_FORMAT" + session_mode = ActiveRecord::Base.connection.exec_query "SELECT @@SESSION.DEFAULT_WEEK_FORMAT" + assert_equal global_mode.rows, session_mode.rows + end + end + def test_logs_name_structure_dump @connection.structure_dump assert_equal "SCHEMA", @connection.logged[0][1] diff --git a/activerecord/test/cases/adapters/postgresql/connection_test.rb b/activerecord/test/cases/adapters/postgresql/connection_test.rb index 1ff307c735..fa8f339f00 100644 --- a/activerecord/test/cases/adapters/postgresql/connection_test.rb +++ b/activerecord/test/cases/adapters/postgresql/connection_test.rb @@ -154,5 +154,46 @@ module ActiveRecord end end + def test_set_session_variable_true + run_without_connection do |orig_connection| + ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:debug_print_plan => true}})) + set_true = ActiveRecord::Base.connection.exec_query "SHOW DEBUG_PRINT_PLAN" + assert_equal set_true.rows, [["on"]] + end + end + + def test_set_session_variable_false + run_without_connection do |orig_connection| + ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:debug_print_plan => false}})) + set_false = ActiveRecord::Base.connection.exec_query "SHOW DEBUG_PRINT_PLAN" + assert_equal set_false.rows, [["off"]] + end + end + + def test_set_session_variable_nil + run_without_connection do |orig_connection| + # This should be a no-op that does not raise an error + ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:debug_print_plan => nil}})) + end + end + + def test_set_session_variable_default + run_without_connection do |orig_connection| + # This should execute a query that does not raise an error + ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:debug_print_plan => :default}})) + end + end + + private + + def run_without_connection + original_connection = ActiveRecord::Base.remove_connection + begin + yield original_connection + ensure + ActiveRecord::Base.establish_connection(original_connection) + end + end + end end diff --git a/activerecord/test/cases/ar_schema_test.rb b/activerecord/test/cases/ar_schema_test.rb index bd47ba8741..b2eac0349b 100644 --- a/activerecord/test/cases/ar_schema_test.rb +++ b/activerecord/test/cases/ar_schema_test.rb @@ -46,55 +46,4 @@ if ActiveRecord::Base.connection.supports_migrations? end end - class ActiveRecordSchemaMigrationsTest < ActiveRecordSchemaTest - def setup - super - ActiveRecord::SchemaMigration.delete_all - end - - def test_migration_adds_row_to_migrations_table - schema = ActiveRecord::Schema.new - schema.migration(1001, "", "") - schema.migration(1002, "123456789012345678901234567890ab", "add_magic_power_to_unicorns") - - migrations = ActiveRecord::SchemaMigration.all.to_a - assert_equal 2, migrations.length - - assert_equal 1001, migrations[0].version - assert_match %r{^2\d\d\d-}, migrations[0].migrated_at.to_s(:db) - assert_equal "", migrations[0].fingerprint - assert_equal "", migrations[0].name - - assert_equal 1002, migrations[1].version - assert_match %r{^2\d\d\d-}, migrations[1].migrated_at.to_s(:db) - assert_equal "123456789012345678901234567890ab", migrations[1].fingerprint - assert_equal "add_magic_power_to_unicorns", migrations[1].name - end - - def test_define_clears_schema_migrations - assert_nothing_raised do - ActiveRecord::Schema.define do - migrations do - migration(123001, "", "") - end - end - ActiveRecord::Schema.define do - migrations do - migration(123001, "", "") - end - end - end - end - - def test_define_raises_if_both_version_and_explicit_migrations - assert_raise(ArgumentError) do - ActiveRecord::Schema.define(version: 123001) do - migrations do - migration(123001, "", "") - end - end - end - end - end - end diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index d25aca760f..7e6c7d5862 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -298,12 +298,6 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal 2, Firm.order(:id).find{|f| f.id > 0}.clients.length end - def test_find_with_blank_conditions - [[], {}, nil, ""].each do |blank| - assert_equal 2, Firm.all.merge!(:order => "id").first.clients.where(blank).to_a.size - end - end - def test_find_many_with_merged_options assert_equal 1, companies(:first_firm).limited_clients.size assert_equal 1, companies(:first_firm).limited_clients.to_a.size diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index 8e52ce1d91..2b96b42032 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -330,6 +330,17 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase end end + def test_update_counter_caches_on_replace_association + post = posts(:welcome) + tag = post.tags.create!(:name => 'doomed') + tag.tagged_posts << posts(:thinking) + + tag.tagged_posts = [] + post.reload + + assert_equal(post.taggings.count, post.taggings_count) + end + def test_replace_association assert_queries(4){posts(:welcome);people(:david);people(:michael); posts(:welcome).people(true)} diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 8644f2f496..d326ed7863 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -23,6 +23,8 @@ require 'models/edge' require 'models/joke' require 'models/bulb' require 'models/bird' +require 'models/car' +require 'models/bulb' require 'rexml/document' require 'active_support/core_ext/exception' @@ -1442,6 +1444,21 @@ class BasicsTest < ActiveRecord::TestCase assert_equal "developers/#{dev.id}-#{dev.updated_at.utc.to_s(:nsec)}", dev.cache_key end + def test_cache_key_format_for_existing_record_with_updated_at_and_custom_cache_timestamp_format + dev = CachedDeveloper.first + assert_equal "cached_developers/#{dev.id}-#{dev.updated_at.utc.to_s(:number)}", dev.cache_key + end + + def test_cache_key_changes_when_child_touched + car = Car.create + Bulb.create(car: car) + + key = car.cache_key + car.bulb.touch + car.reload + assert_not_equal key, car.cache_key + end + def test_cache_key_format_for_existing_record_with_nil_updated_at dev = Developer.first dev.update_columns(updated_at: nil) diff --git a/activerecord/test/cases/date_time_test.rb b/activerecord/test/cases/date_time_test.rb index 3deb0dac99..427076bd80 100644 --- a/activerecord/test/cases/date_time_test.rb +++ b/activerecord/test/cases/date_time_test.rb @@ -8,15 +8,15 @@ class DateTimeTest < ActiveRecord::TestCase with_active_record_default_timezone :utc do time_values = [1807, 2, 10, 15, 30, 45] # create DateTime value with local time zone offset - local_offset = Rational(Time.local_time(*time_values).utc_offset, 86400) + local_offset = Rational(Time.local(*time_values).utc_offset, 86400) now = DateTime.civil(*(time_values + [local_offset])) task = Task.new task.starting = now task.save! - # check against Time.local_time, since some platforms will return a Time instead of a DateTime - assert_equal Time.local_time(*time_values), Task.find(task.id).starting + # check against Time.local, since some platforms will return a Time instead of a DateTime + assert_equal Time.local(*time_values), Task.find(task.id).starting end end end diff --git a/activerecord/test/cases/log_subscriber_test.rb b/activerecord/test/cases/log_subscriber_test.rb index 70d00aecf9..9fee219753 100644 --- a/activerecord/test/cases/log_subscriber_test.rb +++ b/activerecord/test/cases/log_subscriber_test.rb @@ -1,4 +1,5 @@ require "cases/helper" +require "models/binary" require "models/developer" require "models/post" require "active_support/log_subscriber/test_helper" @@ -100,4 +101,13 @@ class LogSubscriberTest < ActiveRecord::TestCase def test_initializes_runtime Thread.new { assert_equal 0, ActiveRecord::LogSubscriber.runtime }.join end + + def test_binary_data_is_not_logged + skip if current_adapter?(:Mysql2Adapter) + + Binary.create(:data => 'some binary data') + wait + assert_equal 3, @logger.logged(:debug).size + assert_match(/<16 bytes of binary data>/, @logger.logged(:debug)[-2]) + end end diff --git a/activerecord/test/cases/migration/logger_test.rb b/activerecord/test/cases/migration/logger_test.rb index 6e62c1fcbe..ee0c20747e 100644 --- a/activerecord/test/cases/migration/logger_test.rb +++ b/activerecord/test/cases/migration/logger_test.rb @@ -6,12 +6,10 @@ module ActiveRecord # mysql can't roll back ddl changes self.use_transactional_fixtures = false - Migration = Struct.new(:name, :version, :filename, :fingerprint) do + Migration = Struct.new(:name, :version) do def migrate direction # do nothing end - def filename; "anon.rb"; end - def fingerprint; "123456789012345678901234567890ab"; end end def setup diff --git a/activerecord/test/cases/migration/table_and_index_test.rb b/activerecord/test/cases/migration/table_and_index_test.rb new file mode 100644 index 0000000000..8fd770abd1 --- /dev/null +++ b/activerecord/test/cases/migration/table_and_index_test.rb @@ -0,0 +1,24 @@ +require "cases/helper" + +module ActiveRecord + class Migration + class TableAndIndexTest < ActiveRecord::TestCase + def test_add_schema_info_respects_prefix_and_suffix + conn = ActiveRecord::Base.connection + + 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.initialize_schema_migrations_table + + 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 + end + end +end diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 60e5a29965..c155f29973 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -59,21 +59,12 @@ class MigrationTest < ActiveRecord::TestCase def test_migrator_versions migrations_path = MIGRATIONS_ROOT + "/valid" ActiveRecord::Migrator.migrations_paths = migrations_path - m0_path = File.join(migrations_path, "1_valid_people_have_last_names.rb") - m0_fingerprint = Digest::MD5.hexdigest(File.read(m0_path)) ActiveRecord::Migrator.up(migrations_path) assert_equal 3, ActiveRecord::Migrator.current_version assert_equal 3, ActiveRecord::Migrator.last_version assert_equal false, ActiveRecord::Migrator.needs_migration? - rows = connection.select_all("SELECT * FROM #{connection.quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name)}") - assert_equal m0_fingerprint, rows[0]["fingerprint"] - assert_equal "valid_people_have_last_names", rows[0]["name"] - rows.each do |row| - assert_match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/, row["migrated_at"], "missing migrated_at") - end - ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid") assert_equal 0, ActiveRecord::Migrator.current_version assert_equal 3, ActiveRecord::Migrator.last_version @@ -346,7 +337,7 @@ class MigrationTest < ActiveRecord::TestCase assert_nothing_raised { Person.connection.create_table :binary_testings do |t| - t.column :data, :binary, :null => false + t.column "data", :binary, :null => false end } diff --git a/activerecord/test/cases/migrator_test.rb b/activerecord/test/cases/migrator_test.rb index 0f0384382f..199d0c584b 100644 --- a/activerecord/test/cases/migrator_test.rb +++ b/activerecord/test/cases/migrator_test.rb @@ -18,9 +18,6 @@ module ActiveRecord def up; @went_up = true; end def down; @went_down = true; end - # also used in place of a MigrationProxy - def filename; "anon.rb"; end - def fingerprint; "123456789012345678901234567890ab"; end end def setup @@ -87,6 +84,12 @@ module ActiveRecord end end + def test_finds_migrations_in_numbered_directory + migrations = ActiveRecord::Migrator.migrations [MIGRATIONS_ROOT + '/10_urban'] + assert_equal 9, migrations[0].version + assert_equal 'AddExpressions', migrations[0].name + end + def test_deprecated_constructor assert_deprecated do ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/valid") @@ -105,7 +108,7 @@ module ActiveRecord end def test_finds_pending_migrations - ActiveRecord::SchemaMigration.create!(:version => '1', :name => "anon", :migrated_at => Time.now) + ActiveRecord::SchemaMigration.create!(:version => '1') migration_list = [ Migration.new('foo', 1), Migration.new('bar', 3) ] migrations = ActiveRecord::Migrator.new(:up, migration_list).pending_migrations @@ -155,7 +158,7 @@ module ActiveRecord end def test_current_version - ActiveRecord::SchemaMigration.create!(:version => '1000', :name => "anon", :migrated_at => Time.now) + ActiveRecord::SchemaMigration.create!(:version => '1000') assert_equal 1000, ActiveRecord::Migrator.current_version end @@ -323,7 +326,7 @@ module ActiveRecord def test_only_loads_pending_migrations # migrate up to 1 - ActiveRecord::SchemaMigration.create!(:version => '1', :name => "anon", :migrated_at => Time.now) + ActiveRecord::SchemaMigration.create!(:version => '1') calls, migrator = migrator_class(3) migrator.migrate("valid", nil) diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index 02034c87b4..9e0423ab52 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -512,6 +512,14 @@ class PersistencesTest < ActiveRecord::TestCase assert_equal 'super_title', t.title end + def test_update_column_with_default_scope + developer = DeveloperCalledDavid.first + developer.name = 'John' + developer.save! + + assert developer.update_column(:name, 'Will'), 'did not update record due to default scope' + end + def test_update_columns topic = Topic.find(1) topic.update_columns({ "approved" => true, title: "Sebastian Topic" }) @@ -616,6 +624,14 @@ class PersistencesTest < ActiveRecord::TestCase assert_equal true, topic.update_columns(title: "New title") end + def test_update_columns_with_default_scope + developer = DeveloperCalledDavid.first + developer.name = 'John' + developer.save! + + assert developer.update_columns(name: 'Will'), 'did not update record due to default scope' + end + def test_update_attributes topic = Topic.find(1) assert !topic.approved? diff --git a/activerecord/test/cases/relation/where_chain_test.rb b/activerecord/test/cases/relation/where_chain_test.rb new file mode 100644 index 0000000000..8ce44636b4 --- /dev/null +++ b/activerecord/test/cases/relation/where_chain_test.rb @@ -0,0 +1,75 @@ +require 'cases/helper' +require 'models/post' +require 'models/comment' + +module ActiveRecord + class WhereChainTest < ActiveRecord::TestCase + fixtures :posts + + def test_not_eq + expected = Arel::Nodes::NotEqual.new(Post.arel_table[:title], 'hello') + relation = Post.where.not(title: 'hello') + assert_equal([expected], relation.where_values) + end + + def test_not_null + expected = Arel::Nodes::NotEqual.new(Post.arel_table[:title], nil) + relation = Post.where.not(title: nil) + assert_equal([expected], relation.where_values) + end + + def test_not_in + expected = Arel::Nodes::NotIn.new(Post.arel_table[:title], %w[hello goodbye]) + relation = Post.where.not(title: %w[hello goodbye]) + assert_equal([expected], relation.where_values) + end + + def test_association_not_eq + expected = Arel::Nodes::NotEqual.new(Comment.arel_table[:title], 'hello') + relation = Post.joins(:comments).where.not(comments: {title: 'hello'}) + assert_equal(expected.to_sql, relation.where_values.first.to_sql) + end + + def test_not_eq_with_preceding_where + relation = Post.where(title: 'hello').where.not(title: 'world') + + expected = Arel::Nodes::Equality.new(Post.arel_table[:title], 'hello') + assert_equal(expected, relation.where_values.first) + + expected = Arel::Nodes::NotEqual.new(Post.arel_table[:title], 'world') + assert_equal(expected, relation.where_values.last) + end + + def test_not_eq_with_succeeding_where + relation = Post.where.not(title: 'hello').where(title: 'world') + + expected = Arel::Nodes::NotEqual.new(Post.arel_table[:title], 'hello') + assert_equal(expected, relation.where_values.first) + + expected = Arel::Nodes::Equality.new(Post.arel_table[:title], 'world') + assert_equal(expected, relation.where_values.last) + end + + def test_not_eq_with_string_parameter + expected = Arel::Nodes::Not.new("title = 'hello'") + relation = Post.where.not("title = 'hello'") + assert_equal([expected], relation.where_values) + end + + def test_not_eq_with_array_parameter + expected = Arel::Nodes::Not.new("title = 'hello'") + relation = Post.where.not(['title = ?', 'hello']) + assert_equal([expected], relation.where_values) + end + + def test_chaining_multiple + relation = Post.where.not(author_id: [1, 2]).where.not(title: 'ruby on rails') + + expected = Arel::Nodes::NotIn.new(Post.arel_table[:author_id], [1, 2]) + assert_equal(expected, relation.where_values[0]) + + expected = Arel::Nodes::NotEqual.new(Post.arel_table[:title], 'ruby on rails') + assert_equal(expected, relation.where_values[1]) + end + end +end diff --git a/activerecord/test/cases/relation/where_test.rb b/activerecord/test/cases/relation/where_test.rb index 9c0b139dbf..297e865308 100644 --- a/activerecord/test/cases/relation/where_test.rb +++ b/activerecord/test/cases/relation/where_test.rb @@ -85,5 +85,11 @@ module ActiveRecord def test_where_with_empty_hash_and_no_foreign_key assert_equal 0, Edge.where(:sink => {}).count end + + def test_where_with_blank_conditions + [[], {}, nil, ""].each do |blank| + assert_equal 4, Edge.where(blank).order("sink_id").to_a.size + end + end end end diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb index 9056b92d65..7ff0044bd4 100644 --- a/activerecord/test/cases/schema_dumper_test.rb +++ b/activerecord/test/cases/schema_dumper_test.rb @@ -1,5 +1,6 @@ require "cases/helper" + class SchemaDumperTest < ActiveRecord::TestCase def setup super @@ -17,15 +18,11 @@ class SchemaDumperTest < ActiveRecord::TestCase def test_dump_schema_information_outputs_lexically_ordered_versions versions = %w{ 20100101010101 20100201010101 20100301010101 } versions.reverse.each do |v| - ActiveRecord::SchemaMigration.create!( - :version => v, :migrated_at => Time.now, - :fingerprint => "123456789012345678901234567890ab", :name => "anon") + ActiveRecord::SchemaMigration.create!(:version => v) end schema_info = ActiveRecord::Base.connection.dump_schema_information assert_match(/20100201010101.*20100301010101/m, schema_info) - target_line = %q{INSERT INTO schema_migrations (version, migrated_at, fingerprint, name) VALUES ('20100101010101',LOCALTIMESTAMP,'123456789012345678901234567890ab','anon');} - assert_match target_line, schema_info end def test_magic_comment @@ -39,16 +36,6 @@ class SchemaDumperTest < ActiveRecord::TestCase assert_no_match %r{create_table "schema_migrations"}, output end - def test_schema_dump_includes_migrations - ActiveRecord::SchemaMigration.delete_all - ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/always_safe") - - output = standard_dump - assert_match %r{migrations do}, output, "Missing migrations block" - assert_match %r{migration 1001, "[0-9a-f]{32}", "always_safe"}, output, "Missing migration line" - assert_match %r{migration 1002, "[0-9a-f]{32}", "still_safe"}, output, "Missing migration line" - end - def test_schema_dump_excludes_sqlite_sequence output = standard_dump assert_no_match %r{create_table "sqlite_sequence"}, output diff --git a/activerecord/test/cases/schema_migration_test.rb b/activerecord/test/cases/schema_migration_test.rb deleted file mode 100644 index 34b9fa520a..0000000000 --- a/activerecord/test/cases/schema_migration_test.rb +++ /dev/null @@ -1,54 +0,0 @@ -require "cases/helper" - -class SchemaMigrationTest < ActiveRecord::TestCase - def sm_table_name - ActiveRecord::SchemaMigration.table_name - end - - def connection - ActiveRecord::Base.connection - end - - def test_add_schema_info_respects_prefix_and_suffix - connection.drop_table(sm_table_name) if connection.table_exists?(sm_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' - connection.drop_table(sm_table_name) if connection.table_exists?(sm_table_name) - - ActiveRecord::SchemaMigration.create_table - - assert_equal "p_unique_schema_migrations_s", connection.indexes(sm_table_name)[0][:name] - ensure - ActiveRecord::Base.table_name_prefix = "" - ActiveRecord::Base.table_name_suffix = "" - end - - def test_add_metadata_columns_to_exisiting_schema_migrations - # creates the old table schema from pre-Rails4.0, so we can test adding to it below - if connection.table_exists?(sm_table_name) - connection.drop_table(sm_table_name) - end - connection.create_table(sm_table_name, :id => false) do |schema_migrations_table| - schema_migrations_table.column("version", :string, :null => false) - end - - connection.insert "INSERT INTO #{connection.quote_table_name(sm_table_name)} (version) VALUES (100)" - connection.insert "INSERT INTO #{connection.quote_table_name(sm_table_name)} (version) VALUES (200)" - - ActiveRecord::SchemaMigration.create_table - - rows = connection.select_all("SELECT * FROM #{connection.quote_table_name(sm_table_name)}") - assert rows[0].has_key?("migrated_at"), "missing column `migrated_at`" - assert_match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/, rows[0]["migrated_at"]) - assert rows[0].has_key?("fingerprint"), "missing column `fingerprint`" - assert rows[0].has_key?("name"), "missing column `name`" - end - - def test_schema_migrations_columns - ActiveRecord::SchemaMigration.create_table - - columns = connection.columns(sm_table_name).collect(&:name) - %w[version migrated_at fingerprint name].each { |col| assert columns.include?(col), "missing column `#{col}`" } - end -end diff --git a/activerecord/test/cases/serialized_attribute_test.rb b/activerecord/test/cases/serialized_attribute_test.rb index 068f3cf3cd..6962da298e 100644 --- a/activerecord/test/cases/serialized_attribute_test.rb +++ b/activerecord/test/cases/serialized_attribute_test.rb @@ -212,4 +212,17 @@ class SerializedAttributeTest < ActiveRecord::TestCase assert_kind_of BCrypt::Password, topic.content assert_equal(true, topic.content == password, 'password should equal') end + + def test_serialize_attribute_via_select_method_when_time_zone_available + ActiveRecord::Base.time_zone_aware_attributes = true + Topic.serialize(:content, MyObject) + + myobj = MyObject.new('value1', 'value2') + topic = Topic.create(content: myobj) + + assert_equal(myobj, Topic.select(:content).find(topic.id).content) + assert_raise(ActiveModel::MissingAttributeError) { Topic.select(:id).find(topic.id).content } + ensure + ActiveRecord::Base.time_zone_aware_attributes = false + end end diff --git a/activerecord/test/migrations/10_urban/9_add_expressions.rb b/activerecord/test/migrations/10_urban/9_add_expressions.rb new file mode 100644 index 0000000000..79a342e574 --- /dev/null +++ b/activerecord/test/migrations/10_urban/9_add_expressions.rb @@ -0,0 +1,11 @@ +class AddExpressions < ActiveRecord::Migration + def self.up + create_table("expressions") do |t| + t.column :expression, :string + end + end + + def self.down + drop_table "expressions" + end +end diff --git a/activerecord/test/migrations/always_safe/1001_always_safe.rb b/activerecord/test/migrations/always_safe/1001_always_safe.rb deleted file mode 100644 index 454b972507..0000000000 --- a/activerecord/test/migrations/always_safe/1001_always_safe.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AlwaysSafe < ActiveRecord::Migration - def change - # do nothing to avoid side-effect conflicts from running multiple times - end -end diff --git a/activerecord/test/migrations/always_safe/1002_still_safe.rb b/activerecord/test/migrations/always_safe/1002_still_safe.rb deleted file mode 100644 index 7398ae27a2..0000000000 --- a/activerecord/test/migrations/always_safe/1002_still_safe.rb +++ /dev/null @@ -1,5 +0,0 @@ -class StillSafe < ActiveRecord::Migration - def change - # do nothing to avoid side-effect conflicts from running multiple times - end -end diff --git a/activerecord/test/models/bulb.rb b/activerecord/test/models/bulb.rb index e4c0278c0d..0109ef4f83 100644 --- a/activerecord/test/models/bulb.rb +++ b/activerecord/test/models/bulb.rb @@ -1,6 +1,6 @@ class Bulb < ActiveRecord::Base default_scope { where(:name => 'defaulty') } - belongs_to :car + belongs_to :car, :touch => true attr_reader :scope_after_initialize, :attributes_after_initialize diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb index 1c048bb6b4..683cb54a10 100644 --- a/activerecord/test/models/developer.rb +++ b/activerecord/test/models/developer.rb @@ -234,3 +234,8 @@ class ThreadsafeDeveloper < ActiveRecord::Base limit(1) end end + +class CachedDeveloper < ActiveRecord::Base + self.table_name = "developers" + self.cache_timestamp_format = :number +end diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 35778d008a..af14bc7bd5 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -115,6 +115,7 @@ ActiveRecord::Schema.define do t.integer :engines_count t.integer :wheels_count t.column :lock_version, :integer, :null => false, :default => 0 + t.timestamps end create_table :categories, :force => true do |t| |