Add assertions to adjust timestamps on MySQL.
Tests were failing on MySQL due to timestamps with differing usec flunking `assert_equal`. Happened because Rails 4.2 added support for fractional seconds precision. Travis, however, doesn't support the required MySQL 5.6 for it. Bend the timestamps to strip out fractional seconds when tests are run with MySQL.
This commit is contained in:
parent
5be48e491e
commit
01837bf374
|
@ -43,6 +43,36 @@ class ActiveSupport::TestCase
|
|||
DatabaseCleaner.clean if using_mysql?
|
||||
Thread.current[:paper_trail] = nil
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assert_attributes_equal(expected, actual)
|
||||
if using_mysql?
|
||||
expected, actual = expected.dup, actual.dup
|
||||
|
||||
# Adjust timestamps for missing fractional seconds precision.
|
||||
%w(created_at updated_at).each do |timestamp|
|
||||
expected[timestamp] = expected[timestamp].change(usec: 0)
|
||||
actual[timestamp] = actual[timestamp].change(usec: 0)
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal expected, actual
|
||||
end
|
||||
|
||||
def assert_changes_equal(expected, actual)
|
||||
if using_mysql?
|
||||
expected, actual = expected.dup, actual.dup
|
||||
|
||||
# Adjust timestamps for missing fractional seconds precision.
|
||||
%w(created_at updated_at).each do |timestamp|
|
||||
expected[timestamp][1] = expected[timestamp][1].change(usec: 0)
|
||||
actual[timestamp][1] = actual[timestamp][1].change(usec: 0)
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal expected, actual
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
|
|
|
@ -229,7 +229,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|||
}
|
||||
|
||||
assert_kind_of Time, @widget.versions.last.changeset['updated_at'][1]
|
||||
assert_equal changes, @widget.versions.last.changeset
|
||||
assert_changes_equal changes, @widget.versions.last.changeset
|
||||
end
|
||||
|
||||
context 'and then updated without any changes' do
|
||||
|
@ -375,7 +375,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|||
|
||||
should 'be available in its previous version' do
|
||||
assert_equal @widget.id, @reified_widget.id
|
||||
assert_equal @widget.attributes, @reified_widget.attributes
|
||||
assert_attributes_equal @widget.attributes, @reified_widget.attributes
|
||||
end
|
||||
|
||||
should 'be re-creatable from its previous version' do
|
||||
|
|
|
@ -38,7 +38,7 @@ class ProtectedAttrsTest < ActiveSupport::TestCase
|
|||
# For some reason this test seems to be broken in JRuby 1.9 mode in the
|
||||
# test env even though it works in the console. WTF?
|
||||
unless ActiveRecord::VERSION::MAJOR >= 4 && defined?(JRUBY_VERSION)
|
||||
assert_equal @widget.previous_version.attributes, @initial_attributes
|
||||
assert_attributes_equal @widget.previous_version.attributes, @initial_attributes
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue