Sha256: 4e07f96f78236a5271f70a60e9174d0120c1e438439dc5d20bb43bde8ffd5ee6

Contents?: true

Size: 1.52 KB

Versions: 11

Compression:

Stored size: 1.52 KB

Contents

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

class BooleanTest < SearchCop::TestCase
  def test_mapping
    product = create(:product, :available => true)

    assert_includes Product.search("available: 1"), product
    assert_includes Product.search("available: true"), product
    assert_includes Product.search("available: yes"), product

    product = create(:product, :available => false)

    assert_includes Product.search("available: 0"), product
    assert_includes Product.search("available: false"), product
    assert_includes Product.search("available: no"), product
  end

  def test_anywhere
    product = create(:product, :available => true)

    assert_includes Product.search("true"), product
    refute_includes Product.search("false"), product
  end

  def test_includes
    product = create(:product, :available => true)

    assert_includes Product.search("available: true"), product
    refute_includes Product.search("available: false"), product
  end

  def test_equals
    product = create(:product, :available => true)

    assert_includes Product.search("available = true"), product
    refute_includes Product.search("available = false"), product
  end

  def test_equals_not
    product = create(:product, :available => false)

    assert_includes Product.search("available != true"), product
    refute_includes Product.search("available != false"), product
  end

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

Version data entries

11 entries across 11 versions & 1 rubygems

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