Sha256: 83bb9f9ab3a533271d3383c1bf2407e389cde43ce62023bbc2c01982ee880490

Contents?: true

Size: 843 Bytes

Versions: 11

Compression:

Stored size: 843 Bytes

Contents

require "spec_helper"

describe "Simple::SQL.ask into: argument" do
  let!(:users) { 1.upto(USER_COUNT).map { create(:user) } }

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

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

  it "returns a OpenStruct with into: OpenStruct" do
    r = SQL.ask("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.ask("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.4.9 spec/simple/sql_ask_into_spec.rb
simple-sql-0.4.8 spec/simple/sql_ask_into_spec.rb
simple-sql-0.4.7 spec/simple/sql_ask_into_spec.rb
simple-sql-0.4.5 spec/simple/sql_ask_into_spec.rb
simple-sql-0.4.4 spec/simple/sql_ask_into_spec.rb
simple-sql-0.4.3 spec/simple/sql_ask_into_spec.rb
simple-sql-0.4.2 spec/simple/sql_ask_into_spec.rb
simple-sql-0.4.1 spec/simple/sql_ask_into_spec.rb
simple-sql-0.4.0 spec/simple/sql_ask_into_spec.rb
simple-sql-0.3.7 spec/simple/sql_ask_into_spec.rb
simple-sql-0.3.6 spec/simple/sql_ask_into_spec.rb