Sha256: 1c1b550529dcc0b0cb62078b3c2727890b0f0f0ed0f0b82ce600245e128accfb
Contents?: true
Size: 947 Bytes
Versions: 1
Compression:
Stored size: 947 Bytes
Contents
require "spec_helper" describe "Simple::SQL.record" do USER_COUNT = 2 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.6 | spec/simple/sql_record_spec.rb |