test/unit/version_test.rb in paper_trail-3.0.1 vs test/unit/version_test.rb in paper_trail-3.0.2

- old
+ new

@@ -5,10 +5,16 @@ change_schema @animal = Animal.create assert PaperTrail::Version.creates.present? end + teardown do + restore_schema + Animal.connection.schema_cache.clear! + Animal.reset_column_information + end + context "PaperTrail::Version.creates" do should "return only create events" do PaperTrail::Version.creates.each do |version| assert_equal "create", version.event end @@ -57,47 +63,39 @@ context "PaperTrail::Version.subsequent" do setup { 2.times { @animal.update_attributes(:name => Faker::Lorem.word) } } context "receiving a TimeStamp" do - should "return all versions that were created before the Timestamp; descendingly by order of the `PaperTrail.timestamp_field`" do - value = PaperTrail::Version.subsequent(1.hour.ago) + should "return all versions that were created before the Timestamp" do + value = PaperTrail::Version.subsequent(1.hour.ago, true) assert_equal value, @animal.versions.to_a - assert_not_nil value.to_sql.match(/ORDER BY versions.created_at ASC\z/) + assert_not_nil value.to_sql.match(/ORDER BY versions.created_at ASC/) end end context "receiving a `PaperTrail::Version`" do should "grab the Timestamp from the version and use that as the value" do value = PaperTrail::Version.subsequent(@animal.versions.first) assert_equal value, @animal.versions.to_a.tap { |assoc| assoc.shift } - # This asssertion can't pass in Ruby18 because the `strftime` method doesn't accept the %6 (milliseconds) command - if RUBY_VERSION.to_f >= 1.9 and not defined?(JRUBY_VERSION) - assert_not_nil value.to_sql.match(/WHERE \(versions.created_at > '#{@animal.versions.first.send(PaperTrail.timestamp_field).strftime("%F %T.%6N")}'\)/) - end end end end context "PaperTrail::Version.preceding" do setup { 2.times { @animal.update_attributes(:name => Faker::Lorem.word) } } context "receiving a TimeStamp" do - should "return all versions that were created before the Timestamp; descendingly by order of the `PaperTrail.timestamp_field`" do - value = PaperTrail::Version.preceding(Time.now) + should "return all versions that were created before the Timestamp" do + value = PaperTrail::Version.preceding(5.seconds.from_now, true) assert_equal value, @animal.versions.reverse - assert_not_nil value.to_sql.match(/ORDER BY versions.created_at DESC\z/) + assert_not_nil value.to_sql.match(/ORDER BY versions.created_at DESC/) end end context "receiving a `PaperTrail::Version`" do should "grab the Timestamp from the version and use that as the value" do value = PaperTrail::Version.preceding(@animal.versions.last) assert_equal value, @animal.versions.to_a.tap { |assoc| assoc.pop }.reverse - # This asssertion can't pass in Ruby18 because the `strftime` method doesn't accept the %6 (milliseconds) command - if RUBY_VERSION.to_f >= 1.9 and not defined?(JRUBY_VERSION) - assert_not_nil value.to_sql.match(/WHERE \(versions.created_at < '#{@animal.versions.last.send(PaperTrail.timestamp_field).strftime("%F %T.%6N")}'\)/) - end end end end end