Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make sure #size, #length, and #count work. #37

Merged
merged 1 commit into from

2 participants

John Nunemaker Kelley Reynolds
John Nunemaker

Since you mentioned being ok with this, I created a separate pull request. Feel free to pull this one and we can continue to talk about the other one. Last pull request for tonight. :P

Kelley Reynolds kreynolds merged commit a47d154 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 8, 2012
  1. John Nunemaker
This page is out of date. Refresh to see the latest.
Showing with 33 additions and 17 deletions.
  1. +9 −5 lib/cassandra-cql/result.rb
  2. +24 −12 spec/result_spec.rb
14 lib/cassandra-cql/result.rb
View
@@ -35,7 +35,7 @@ def initialize(schema)
}
end
end
-
+
class Result
attr_reader :result, :schema, :cursor
@@ -44,11 +44,11 @@ def initialize(result)
@schema = ResultSchema.new(result.schema) if rows?
@cursor = 0
end
-
+
def void?
@result.type == CassandraCQL::Thrift::CqlResultType::VOID
end
-
+
def int?
@result.type == CassandraCQL::Thrift::CqlResultType::INT
end
@@ -61,12 +61,16 @@ def rows
@result.rows.size
end
+ alias_method :size, :rows
+ alias_method :count, :rows
+ alias_method :length, :rows
+
def cursor=(cursor)
@cursor = cursor.to_i
rescue Exception => e
raise Error::InvalidCursor, e.to_s
end
-
+
def fetch_row
case @result.type
when CassandraCQL::Thrift::CqlResultType::ROWS
@@ -113,7 +117,7 @@ def fetch_hash
end
end
end
-
+
def fetch_array
if block_given?
while row = fetch_row
36 spec/result_spec.rb
View
@@ -57,30 +57,42 @@
it "should have two rows" do
@result.rows.should eq(2)
end
-
+
+ it "should know size of rows" do
+ @result.size.should eq(2)
+ end
+
+ it "should know count of rows" do
+ @result.count.should eq(2)
+ end
+
+ it "should know length of rows" do
+ @result.length.should eq(2)
+ end
+
context "initialize" do
it "should have a cursor set to 0" do
@result.instance_variable_get(:@cursor).should eq(0)
end
-
+
it "should have a result" do
@result.instance_variable_get(:@result).should be_kind_of(CassandraCQL::Thrift::CqlResult)
end
end
-
+
context "setting the cursor" do
it "should set the cursor" do
expect {
@result.cursor = 15
}.to_not raise_error
@result.instance_variable_get(:@cursor).should eq(15)
- end
+ end
it "should not set the cursor" do
expect {
@result.cursor = Object
}.to raise_error(CassandraCQL::Error::InvalidCursor)
- end
+ end
end
context "fetching a single row" do
@@ -90,12 +102,12 @@
@result.fetch_row.should be_kind_of(Row)
@result.instance_variable_get(:@cursor).should eq(2)
-
+
@result.fetch_row.should be_nil
@result.instance_variable_get(:@cursor).should eq(2)
end
end
-
+
context "resetting cursor should fetch the same row" do
it "should return the same row" do
@result.instance_variable_get(:@cursor).should eq(0)
@@ -104,7 +116,7 @@
arr.should eq(@result.fetch_array)
end
end
-
+
context "fetch without a block" do
it "should return a row twice then nil" do
@result.fetch.should be_kind_of(Row)
@@ -112,12 +124,12 @@
@result.fetch.should be_kind_of(Row)
@result.instance_variable_get(:@cursor).should eq(2)
-
+
@result.fetch.should be_nil
@result.instance_variable_get(:@cursor).should eq(2)
end
end
-
+
context "fetch with a block" do
it "fetched count should equal the number of rows" do
counter = 0
@@ -138,7 +150,7 @@
arr.should eq(row.column_values)
end
end
-
+
context "fetch_array_with a block" do
it "fetched count should equal the number of rows" do
counter = 0
@@ -164,7 +176,7 @@
@result.fetch_hash.should be_nil
end
end
-
+
context "fetch_hash_with a block" do
it "should iterate rows() times and return hashes" do
counter = 0
Something went wrong with that request. Please try again.