Sha256: 398cc7e245851ee1783816a36647730e5421499628ab065187d18a5dcd16e49a
Contents?: true
Size: 1.44 KB
Versions: 3
Compression:
Stored size: 1.44 KB
Contents
require 'test_helper' class FirstAfterCreatedAtTest < ActiveSupport::TestCase test 'returns nil if no object exists' do assert_nil HasTimestamp.first_after_created_at(Time.now) end test 'returns nil if no object meets criteria' do HasTimestamp.create assert_nil HasTimestamp.first_after_created_at(1.hour.from_now) end test 'can return the first object' do obj = HasTimestamp.create HasTimestamp.create assert_equal obj, HasTimestamp.first_after_created_at(1.hour.ago) end test "will ignore first object if it's out of scope" do HasTimestamp.create obj = HasTimestamp.create(created_at: 2.hours.from_now) assert_equal obj, HasTimestamp.first_after_created_at(1.hour.from_now) end test 'given two objects with same created at, returns one with min id' do obj = HasTimestamp.create HasTimestamp.create(created_at: obj.created_at) assert_equal obj, HasTimestamp.first_after_created_at(1.hour.ago) end test 'can return the middle object' do objs = Array.new(3) do |n| HasTimestamp.create(created_at: n.hours.from_now) end middle = objs[1] assert_equal middle, HasTimestamp.first_after_created_at(middle.created_at) end test 'can join to another table' do obj = HasTimestamp.create found_with_join = HasTimestamp.joins('INNER JOIN has_timestamps h ON h.id = has_timestamps.id').first_after_created_at(obj.created_at) assert_equal obj, found_with_join end end
Version data entries
3 entries across 3 versions & 1 rubygems