Add test for Version's custom timestamps.
This commit is contained in:
parent
542f600c0c
commit
6015ef748d
|
@ -38,6 +38,7 @@ def change_schema
|
|||
ActiveRecord::Migration.verbose = false
|
||||
ActiveRecord::Schema.define do
|
||||
remove_column :widgets, :sacrificial_column
|
||||
add_column :versions, :custom_created_at, :datetime
|
||||
end
|
||||
ActiveRecord::Migration.verbose = true
|
||||
end
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
require 'test_helper'
|
||||
|
||||
class TimestampTest < ActiveSupport::TestCase
|
||||
|
||||
setup do
|
||||
PaperTrail.config.timestamp_field = :custom_created_at
|
||||
change_schema
|
||||
Version.reset_column_information
|
||||
|
||||
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
|
||||
|
||||
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.
|
||||
@fluxor.versions true # reload association
|
||||
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
|
Loading…
Reference in New Issue