Sha256: 916d93166d31795f926d04704ff9a72379c25b8ce15c37bf172cd869314ba377

Contents?: true

Size: 1.68 KB

Versions: 11

Compression:

Stored size: 1.68 KB

Contents

require File.expand_path("../test_helper", __FILE__)

class IntegerTest < SearchCop::TestCase
  def test_anywhere
    product = create(:product, :stock => 1)

    assert_includes Product.search("1"), product
    refute_includes Product.search("0"), product
  end

  def test_includes
    product = create(:product, :stock => 1)

    assert_includes Product.search("stock: 1"), product
    refute_includes Product.search("stock: 10"), product
  end

  def test_equals
    product = create(:product, :stock => 1)

    assert_includes Product.search("stock = 1"), product
    refute_includes Product.search("stock = 0"), product
  end

  def test_equals_not
    product = create(:product, :stock => 1)

    assert_includes Product.search("stock != 0"), product
    refute_includes Product.search("stock != 1"), product
  end

  def test_greater
    product = create(:product, :stock => 1)

    assert_includes Product.search("stock > 0"), product
    refute_includes Product.search("stock < 1"), product
  end

  def test_greater_equals
    product = create(:product, :stock => 1)

    assert_includes Product.search("stock >= 1"), product
    refute_includes Product.search("stock >= 2"), product
  end

  def test_less
    product = create(:product, :stock => 1)

    assert_includes Product.search("stock < 2"), product
    refute_includes Product.search("stock < 1"), product
  end

  def test_less_equals
    product = create(:product, :stock => 1)

    assert_includes Product.search("stock <= 1"), product
    refute_includes Product.search("stock <= 0"), product
  end

  def test_incompatible_datatype
    assert_raises SearchCop::IncompatibleDatatype do
      Product.unsafe_search "stock: Value"
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
search_cop-1.1.0 test/integer_test.rb
search_cop-1.0.9 test/integer_test.rb
search_cop-1.0.8 test/integer_test.rb
search_cop-1.0.7 test/integer_test.rb
search_cop-1.0.6 test/integer_test.rb
search_cop-1.0.5 test/integer_test.rb
search_cop-1.0.4 test/integer_test.rb
search_cop-1.0.3 test/integer_test.rb
search_cop-1.0.2 test/integer_test.rb
search_cop-1.0.1 test/integer_test.rb
search_cop-1.0.0 test/integer_test.rb