diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2015-02-20 10:19:33 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2015-02-20 10:26:06 +0900 |
commit | cddc298deaf58a51dfa1938fba7b64052594bbe7 (patch) | |
tree | 4d7505317f064ab4f2e40a9353c97a68a7352c1f /activerecord/test/cases | |
parent | a088ee96918a938159cbeee1a3fe822f0bb46b5d (diff) | |
download | rails-cddc298deaf58a51dfa1938fba7b64052594bbe7.tar.gz rails-cddc298deaf58a51dfa1938fba7b64052594bbe7.tar.bz2 rails-cddc298deaf58a51dfa1938fba7b64052594bbe7.zip |
Add schema dumping tests for datetime and time precision
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/date_time_precision_test.rb | 11 | ||||
-rw-r--r-- | activerecord/test/cases/schema_dumper_test.rb | 7 | ||||
-rw-r--r-- | activerecord/test/cases/time_precision_test.rb | 24 |
3 files changed, 34 insertions, 8 deletions
diff --git a/activerecord/test/cases/date_time_precision_test.rb b/activerecord/test/cases/date_time_precision_test.rb index 720f10a9d3..6a4e64b22c 100644 --- a/activerecord/test/cases/date_time_precision_test.rb +++ b/activerecord/test/cases/date_time_precision_test.rb @@ -71,9 +71,18 @@ class DateTimePrecisionTest < ActiveRecord::TestCase assert_equal 999900, foo.updated_at.usec end + def test_schema_dump_includes_datetime_precision + @connection.create_table(:foos, force: true) do |t| + t.timestamps precision: 6 + end + output = dump_table_schema("foos") + assert_match %r{t\.datetime\s+"created_at",\s+precision: 6,\s+null: false$}, output + assert_match %r{t\.datetime\s+"updated_at",\s+precision: 6,\s+null: false$}, output + end + if current_adapter?(:PostgreSQLAdapter) def test_datetime_precision_with_zero_should_be_dumped - @connection.create_table(:foos) do |t| + @connection.create_table(:foos, force: true) do |t| t.timestamps precision: 0 end output = dump_table_schema("foos") diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb index 0413984729..7d8d6421a9 100644 --- a/activerecord/test/cases/schema_dumper_test.rb +++ b/activerecord/test/cases/schema_dumper_test.rb @@ -232,13 +232,6 @@ class SchemaDumperTest < ActiveRecord::TestCase end end - if mysql_56? - def test_schema_dump_includes_datetime_precision - output = standard_dump - assert_match %r{t\.datetime\s+"written_on",\s+precision: 6$}, output - end - end - def test_schema_dump_includes_decimal_options output = dump_all_table_schema([/^[^n]/]) assert_match %r{precision: 3,[[:space:]]+scale: 2,[[:space:]]+default: 2\.78}, output diff --git a/activerecord/test/cases/time_precision_test.rb b/activerecord/test/cases/time_precision_test.rb index c3fb275936..ff4e5ecec5 100644 --- a/activerecord/test/cases/time_precision_test.rb +++ b/activerecord/test/cases/time_precision_test.rb @@ -1,7 +1,9 @@ require 'cases/helper' +require 'support/schema_dumping_helper' if ActiveRecord::Base.connection.supports_datetime_with_precision? class TimePrecisionTest < ActiveRecord::TestCase + include SchemaDumpingHelper self.use_transactional_fixtures = false class Foo < ActiveRecord::Base; end @@ -64,6 +66,28 @@ class TimePrecisionTest < ActiveRecord::TestCase assert_equal 999900, foo.finish.usec end + def test_schema_dump_includes_time_precision + @connection.create_table(:foos, force: true) do |t| + t.time :start, precision: 4 + t.time :finish, precision: 6 + end + output = dump_table_schema("foos") + assert_match %r{t\.time\s+"start",\s+precision: 4$}, output + assert_match %r{t\.time\s+"finish",\s+precision: 6$}, output + end + + if current_adapter?(:PostgreSQLAdapter) + def test_time_precision_with_zero_should_be_dumped + @connection.create_table(:foos, force: true) do |t| + t.time :start, precision: 0 + t.time :finish, precision: 0 + end + output = dump_table_schema("foos") + assert_match %r{t\.time\s+"start",\s+precision: 0$}, output + assert_match %r{t\.time\s+"finish",\s+precision: 0$}, output + end + end + private def database_datetime_precision(table_name, column_name) |