Sha256: ac78edb8888a36bcd52312fa47f791232fc88ca4818eefdc7155cf317adad413

Contents?: true

Size: 1.22 KB

Versions: 15

Compression:

Stored size: 1.22 KB

Contents

require 'test_helper'

class TimestampTest < ActiveSupport::TestCase

  setup do
    PaperTrail.timestamp_field = :custom_created_at
    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

  teardown do
    PaperTrail.timestamp_field = :created_at
    restore_schema
  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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
paper_trail-4.2.0 test/unit/timestamp_test.rb
paper_trail-4.1.0 test/unit/timestamp_test.rb
paper_trail-4.0.2 test/unit/timestamp_test.rb
paper_trail-4.0.1 test/unit/timestamp_test.rb
paper_trail-3.0.9 test/unit/timestamp_test.rb
paper_trail-4.0.0 test/unit/timestamp_test.rb
paper_trail-4.0.0.rc2 test/unit/timestamp_test.rb
paper_trail-4.0.0.rc1 test/unit/timestamp_test.rb
paper_trail-3.0.8 test/unit/timestamp_test.rb
paper_trail-3.0.7 test/unit/timestamp_test.rb
paper_trail-4.0.0.beta2 test/unit/timestamp_test.rb
paper_trail-4.0.0.beta1 test/unit/timestamp_test.rb
paper_trail-3.0.6 test/unit/timestamp_test.rb
paper_trail-3.0.5 test/unit/timestamp_test.rb
paper_trail-3.0.2 test/unit/timestamp_test.rb