Skip to content

Commit

Permalink
Merge pull request kreynolds#26 from brendan/nil_fetch_hash
Browse files Browse the repository at this point in the history
fixed condition where to_hash called on nil.
  • Loading branch information
Kelley Reynolds committed Aug 30, 2012
2 parents 108b7d3 + 58e3fb0 commit 0f2e696
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 7 additions & 5 deletions lib/cassandra-cql/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ def fetch_hash
end
end
else
if (row = fetch_row).kind_of?(Fixnum)
{row => row}
else
row.to_hash
if row = fetch_row
if row.kind_of?(Fixnum)
{row => row}
else
row.to_hash
end
end
end
end
Expand All @@ -130,4 +132,4 @@ def fetch_array
end
end
end
end
end
7 changes: 6 additions & 1 deletion spec/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@
hash.should be_kind_of(Hash)
hash.should eq(row.to_hash)
end

it "should return nil where there is no row to fetch" do
2.times { @result.fetch }
@result.fetch_hash.should be_nil
end
end

context "fetch_hash_with a block" do
Expand All @@ -170,4 +175,4 @@
counter.should eq(@result.rows)
end
end
end
end

0 comments on commit 0f2e696

Please sign in to comment.