Sha256: 757f078d442974775a1250d17417f95b4e70a248164817c024684156f55bbea2

Contents?: true

Size: 929 Bytes

Versions: 1

Compression:

Stored size: 929 Bytes

Contents

require "spec_helper"

describe "Simple::SQL.record" do
  def expects(expected_result, sql, *args)
    expect(SQL.record(sql, *args)).to eq(expected_result)
  end

  let!(:users) { 1.upto(USER_COUNT).map { create(:user) } }

  it "calls the database" do
    r = SQL.record("SELECT COUNT(*) AS count FROM users")
    expect(r).to eq({count: 2}) 
  end

  it "returns nil when there is no record" do
    r = SQL.record("SELECT * FROM users WHERE FALSE", into: OpenStruct)
    expect(r).to be_nil
  end

  it "supports the into: option" do
    r = SQL.record("SELECT COUNT(*) AS count FROM users", into: OpenStruct)
    expect(r).to be_a(OpenStruct)
    expect(r).to eq(OpenStruct.new(count: 2))
  end

  it "supports the into: option even with parameters" do
    r = SQL.record("SELECT $1::integer AS count FROM users", 2, into: OpenStruct)
    expect(r).to be_a(OpenStruct)
    expect(r).to eq(OpenStruct.new(count: 2))
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple-sql-0.2.7 spec/simple/sql_record_spec.rb