Sha256: 423ac5be55be34d46fc6e561436a2e1ae1efd51d42dc98d1eab7c0b2eca05089

Contents?: true

Size: 812 Bytes

Versions: 3

Compression:

Stored size: 812 Bytes

Contents

describe ActiveHashRelation do
  include Helpers

  context 'limit' do
    it "one where clause" do
      hash = {microposts_count: 10, limit: 10}

      query = HelperClass.new.apply_filters(User.all, hash).to_sql
      expected_query = q(
        "SELECT users.* FROM users WHERE (users.microposts_count = 10) LIMIT 10"
      )

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

    it "multiple where clause" do
      hash = {microposts_count: 3, followers_count: 5, limit: 10}

      query = HelperClass.new.apply_filters(User.all, hash).to_sql
      expected_query = q(
        "SELECT users.* FROM users",
        "WHERE (users.microposts_count = 3)",
        "AND (users.followers_count = 5)",
        "LIMIT 10"
      )

      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/limit_spec.rb
active_hash_relation-1.4.0 spec/tests/limit_spec.rb
active_hash_relation-1.2.0 spec/tests/limit_spec.rb