2024-02-25 12:15:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "test_helper"
|
2017-12-17 17:58:34 -05:00
|
|
|
|
|
|
|
class ApplicationRecordTest < ActiveSupport::TestCase
|
|
|
|
setup do
|
2022-11-25 15:06:54 -05:00
|
|
|
@tags = create_list(:tag, 3, post_count: 1)
|
2017-12-17 17:58:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "ApplicationRecord#search" do
|
|
|
|
should "support the id param" do
|
|
|
|
assert_equal([@tags.first], Tag.search(id: @tags.first.id))
|
|
|
|
end
|
|
|
|
|
|
|
|
should "support ranges in the id param" do
|
|
|
|
assert_equal(@tags.reverse, Tag.search(id: ">=1"))
|
|
|
|
assert_equal(@tags.reverse, Tag.search(id: "#{@tags[0].id}..#{@tags[2].id}"))
|
|
|
|
assert_equal(@tags.reverse, Tag.search(id: @tags.map(&:id).join(",")))
|
|
|
|
end
|
2017-12-17 18:31:07 -05:00
|
|
|
|
|
|
|
should "support the created_at and updated_at params" do
|
|
|
|
assert_equal(@tags.reverse, Tag.search(created_at: ">=#{@tags.first.created_at}"))
|
|
|
|
assert_equal(@tags.reverse, Tag.search(updated_at: ">=#{@tags.first.updated_at}"))
|
|
|
|
end
|
2017-12-17 17:58:34 -05:00
|
|
|
end
|
|
|
|
end
|