Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Additional count tests

  • Loading branch information...
commit b369a132ade6aca9bd080da7a25c2f39fe6d2642 1 parent 0068bd5
@visoft authored
Showing with 34 additions and 16 deletions.
  1. +10 −0 features/query_builder.feature
  2. +24 −16 spec/query_builder_spec.rb
View
10 features/query_builder.feature
@@ -169,4 +169,14 @@ Scenario: Count should be able to be used on a root collection
And I run the query
Then the integer result should be 4
+Scenario: Count should be able to be used on with a filter
+ Given the following products exist:
+ | Name |
+ | Product 1 |
+ | Product 2 |
+ When I call "Products" on the service
+ And I filter the query with: "Name eq 'Product 2'"
+ And I ask for the count
+ And I run the query
+ Then the integer result should be 1
View
40 spec/query_builder_spec.rb
@@ -18,23 +18,25 @@ module OData
builder.top(10)
builder.query.should eq "Products?$top=10&x=1&y=2"
end
- it "should properly handle queries for links" do
- builder = QueryBuilder.new "Categories(1)"
- builder.links("Products")
- builder.query.should eq "Categories(1)/$links/Products"
- end
- it "should properly handle queries for links with additional operations" do
- builder = QueryBuilder.new "Categories(1)"
- builder.links("Products")
- builder.top(5)
- builder.query.should eq "Categories(1)/$links/Products?$top=5"
- end
- it "should throw an execption if count was already called on the builder" do
- builder = QueryBuilder.new "Categories(1)"
- builder.count
- lambda { builder.links("Products") }.should raise_error(OData::NotSupportedError, "You cannot call both the `links` method and the `count` method in the same query.")
+ context "#links" do
+ it "should properly handle queries for links" do
+ builder = QueryBuilder.new "Categories(1)"
+ builder.links("Products")
+ builder.query.should eq "Categories(1)/$links/Products"
+ end
+ it "should properly handle queries for links with additional operations" do
+ builder = QueryBuilder.new "Categories(1)"
+ builder.links("Products")
+ builder.top(5)
+ builder.query.should eq "Categories(1)/$links/Products?$top=5"
+ end
+ it "should throw an execption if count was already called on the builder" do
+ builder = QueryBuilder.new "Categories(1)"
+ builder.count
+ lambda { builder.links("Products") }.should raise_error(OData::NotSupportedError, "You cannot call both the `links` method and the `count` method in the same query.")
+ end
end
- context "count" do
+ context "#count" do
it "should accept the count method" do
builder = QueryBuilder.new "Products"
lambda { builder.count }.should_not raise_error
@@ -44,6 +46,12 @@ module OData
builder.count
builder.query.should eq "Products/$count"
end
+ it "should properly handle the count method with additional operators" do
+ builder = QueryBuilder.new "Products"
+ builder.filter("Name eq 'Widget 1'")
+ builder.count
+ builder.query.should eq "Products/$count?$filter=Name+eq+%27Widget+1%27"
+ end
it "should throw an execption if links was already called on the builder" do
builder = QueryBuilder.new "Categories(1)"
builder.links("Products")
Please sign in to comment.
Something went wrong with that request. Please try again.