Sha256: 76d799d8b5d044e499d10eb77a7415b141138b6284f771dec3529192a5f1e4ea

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

describe ActiveHashRelation do
  include Helpers

  context 'NULL' do
    context "one where clause" do
      it "is null" do
        hash = {admin: {null: true}}

        query = HelperClass.new.apply_filters(User.all, hash).to_sql
        expected_query = q(
          "SELECT users.* FROM users",
          "WHERE (users.admin IS NULL)"
        )

        expect(strip(query)).to eq expected_query.to_s
      end

      it "is not null" do
        hash = {admin: {null: false}}

        query = HelperClass.new.apply_filters(User.all, hash).to_sql
        expected_query = q(
          "SELECT users.* FROM users",
          "WHERE (users.admin IS NOT NULL)"
        )

        expect(strip(query)).to eq expected_query.to_s
      end
    end

    it "multi where clauses" do
      hash = {admin: {null: true}, verified: {null: false}}

      query = HelperClass.new.apply_filters(User.all, hash).to_sql
      expected_query = q(
        "SELECT users.* FROM users",
        "WHERE (users.admin IS NULL)",
        "AND (users.verified IS NOT NULL)"
      )

      expect(strip(query)).to eq expected_query.to_s
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
active_hash_relation-1.4.1 spec/tests/null_spec.rb
active_hash_relation-1.4.0 spec/tests/null_spec.rb
active_hash_relation-1.2.0 spec/tests/null_spec.rb