2012-03-12 07:12:27 -04:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class TimestampTest < ActiveSupport::TestCase
|
|
|
|
|
|
|
|
setup do
|
2012-03-12 09:02:47 -04:00
|
|
|
PaperTrail.timestamp_field = :custom_created_at
|
2012-03-12 07:12:27 -04:00
|
|
|
change_schema
|
|
|
|
|
|
|
|
Fluxor.instance_eval <<-END
|
|
|
|
has_paper_trail
|
|
|
|
END
|
|
|
|
|
|
|
|
@fluxor = Fluxor.create :name => 'Some text.'
|
|
|
|
@fluxor.update_attributes :name => 'Some more text.'
|
|
|
|
@fluxor.update_attributes :name => 'Even more text.'
|
|
|
|
end
|
|
|
|
|
2012-03-12 08:23:25 -04:00
|
|
|
teardown do
|
2012-03-12 09:02:47 -04:00
|
|
|
PaperTrail.timestamp_field = :created_at
|
2014-03-14 23:52:35 -04:00
|
|
|
restore_schema
|
2012-03-12 08:23:25 -04:00
|
|
|
end
|
|
|
|
|
2012-03-12 07:12:27 -04:00
|
|
|
test 'versions works with custom timestamp field' do
|
|
|
|
# Normal behaviour
|
|
|
|
assert_equal 3, @fluxor.versions.length
|
|
|
|
assert_nil @fluxor.versions[0].reify
|
|
|
|
assert_equal 'Some text.', @fluxor.versions[1].reify.name
|
|
|
|
assert_equal 'Some more text.', @fluxor.versions[2].reify.name
|
|
|
|
|
|
|
|
# Tinker with custom timestamps.
|
|
|
|
now = Time.now.utc
|
|
|
|
@fluxor.versions.reverse.each_with_index do |version, index|
|
|
|
|
version.update_attribute :custom_created_at, (now + index.seconds)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Test we are ordering by custom timestamps.
|
2016-01-11 22:03:20 -05:00
|
|
|
@fluxor.versions.reload # reload association
|
2012-03-12 07:12:27 -04:00
|
|
|
assert_nil @fluxor.versions[2].reify
|
|
|
|
assert_equal 'Some text.', @fluxor.versions[1].reify.name
|
|
|
|
assert_equal 'Some more text.', @fluxor.versions[0].reify.name
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|