Sha256: 0aea23bbd77bd87d60be1591a65c90d1e7b62d1e77b57699d2d3c959c0ef2147

Contents?: true

Size: 821 Bytes

Versions: 11

Compression:

Stored size: 821 Bytes

Contents

require "spec_helper"

describe "Simple::SQL.record" do
  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

11 entries across 11 versions & 1 rubygems

Version Path
simple-sql-0.3.7 spec/simple/sql_record_spec.rb
simple-sql-0.3.6 spec/simple/sql_record_spec.rb
simple-sql-0.3.5 spec/simple/sql_record_spec.rb
simple-sql-0.3.4 spec/simple/sql_record_spec.rb
simple-sql-0.3.3 spec/simple/sql_record_spec.rb
simple-sql-0.2.10 spec/simple/sql_record_spec.rb
simple-sql-0.3.2 spec/simple/sql_record_spec.rb
simple-sql-0.2.9 spec/simple/sql_record_spec.rb
simple-sql-0.3.1 spec/simple/sql_record_spec.rb
simple-sql-0.2.8 spec/simple/sql_record_spec.rb
simple-sql-0.3.0 spec/simple/sql_record_spec.rb