spec/database_spec.rb in motion-sqlite3-0.5.0 vs spec/database_spec.rb in motion-sqlite3-0.5.1
- old
+ new
@@ -22,11 +22,11 @@
it "allows parameters to be passed in as a Hash" do
@db.execute("CREATE TABLE test (name TEXT, address TEXT)")
@db.execute("INSERT INTO test VALUES(:name, :address)", { name: "matt", address: "123 main st" })
@db.execute_scalar("SELECT changes()").should == 1
- end
+ end
it "returns rows if no block is provided" do
@db.execute("CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER)")
@db.execute("INSERT INTO test (name, age) VALUES (?, ?)", ["brad", 28])
@db.execute("INSERT INTO test (name, age) VALUES (?, ?)", ["sparky", 24])
@@ -49,9 +49,22 @@
rows.should == [
{ id: 1, name: "brad", age: 28 },
{ id: 2, name: "sparky", age: 24 }
]
+ end
+
+ it "handles results where the first row has a nil column correctly" do
+ @db.execute 'create virtual table fts_1 using fts4 (col_1, col_2)'
+ @db.execute "insert into fts_1 (col_1) values ('hello')"
+ @db.execute "insert into fts_1 (col_2) values ('hello')"
+
+ rows = @db.execute("select col_1, col_2 from fts_1 where fts_1 match 'hello' order by rowid")
+ rows.size.should == 2
+ one, two = rows
+
+ one.should == { col_1: 'hello', col_2: nil }
+ two.should == { col_1: nil, col_2: 'hello' }
end
end
describe "#execute_scalar" do
it "returns the first value of the first column" do