Permalink
Browse files

Added the ability to append additional parameters to a query at any time

  • Loading branch information...
1 parent 0bd6352 commit a3c41d0cee9c4fd32d24cfa1169310c200122ecf @visoft committed Aug 26, 2012
Showing with 19 additions and 0 deletions.
  1. +2 −0 lib/ruby_odata/query_builder.rb
  2. +17 −0 spec/query_builder_spec.rb
@@ -6,6 +6,8 @@ module OData
# svc.Categories
# The *Categories* method would return a QueryBuilder
class QueryBuilder
+ attr_accessor :additional_params
+
# Creates a new instance of the QueryBuilder class
#
# @param [String] root entity collection to query against
@@ -88,6 +88,23 @@ module OData
end
end
+ describe "additional_parameters" do
+ it "should be able to be added at any time" do
+ builder = QueryBuilder.new "PollingLocations"
+ builder.filter("Address/Zip eq 45693")
+ builder.expand("Election")
+ builder.additional_params[:foo] = "bar"
+ builder.query.should eq "PollingLocations?$expand=Election&$filter=Address%2FZip+eq+45693&foo=bar"
+ end
+
+ it "should not overwrite what is already there" do
+ builder = QueryBuilder.new "Products", { :x=>1, :y=>2 }
+ builder.top(10)
+ builder.additional_params[:foo] = "bar"
+ builder.query.should eq "Products?$top=10&foo=bar&x=1&y=2"
+ end
+ end
+
describe "#query" do
it "should encode spaces in IDs" do
builder = QueryBuilder.new "Categories('Cool Stuff')"

0 comments on commit a3c41d0

Please sign in to comment.