Permalink
Browse files

Fix handling of database queries

SQLite `Select` queries return an Array for each column, not a Hash.
  • Loading branch information...
ychatz committed Apr 15, 2012
1 parent b3b5443 commit 045a5f9127144564fd3c3041c929f59dba3ef81f
Showing with 8 additions and 3 deletions.
  1. +1 −1 lib/database.rb
  2. +5 −0 lib/preferences.rb
  3. +2 −2 spec/lib/database_spec.rb
View
@@ -24,7 +24,7 @@ def load(table)
{}.tap do |result|
rows.each do |row|
- result[row["key"].to_sym] = row["value"]
+ result[row[0].to_sym] = row[1]
end
end
end
View
@@ -11,6 +11,11 @@ def initialize
end
def method_missing(meth, *args, &blk)
+ if meth == :[] || meth == :[]=
+ #convert hash key to symbol
+ args[0] = args[0].to_sym
+ end
+
@target.send(meth, *args, &blk)
end
@@ -11,9 +11,9 @@
context ".load" do
it "returns a proper hash" do
- db = HH::Database.new(double(:execute => [{"key" => "key", "value" => "value"}]))
+ db = HH::Database.new(double(:execute => [ ["key1", "value1"], ["key2", "value2"] ]))
- db.load("names").should eql({:key => "value"})
+ db.load("names").should eql({:key1 => "value1", :key2 => "value2"})
end
end
end

0 comments on commit 045a5f9

Please sign in to comment.