Skip to content
Browse files

prevent `svc.load_property` from mutating the obj's uri

  • Loading branch information...
1 parent d41ab24 commit c9ed8a9608c7bb599f4ddbbe068d7bde0e4342af @sillylogger sillylogger committed with Feb 19, 2013
Showing with 14 additions and 5 deletions.
  1. +4 −4 lib/ruby_odata/service.rb
  2. +10 −1 spec/service_spec.rb
View
8 lib/ruby_odata/service.rb
@@ -474,13 +474,13 @@ def build_save_uri(operation)
uri
end
def build_add_link_uri(operation)
- uri = "#{operation.klass.send(:__metadata)[:uri]}"
+ uri = operation.klass.send(:__metadata)[:uri].dup
uri << "/$links/#{operation.klass_name}"
uri << "?#{@additional_params.to_query}" unless @additional_params.empty?
uri
end
def build_resource_uri(operation)
- uri = operation.klass.send(:__metadata)[:uri]
+ uri = operation.klass.send(:__metadata)[:uri].dup
uri << "?#{@additional_params.to_query}" unless @additional_params.empty?
uri
end
@@ -490,7 +490,7 @@ def build_batch_uri
uri
end
def build_load_property_uri(obj, property)
- uri = obj.__metadata[:uri]
+ uri = obj.__metadata[:uri].dup
uri << "/#{property}"
uri
end
@@ -766,4 +766,4 @@ def singular?(value)
end
end
-end # module OData
+end # module OData
View
11 spec/service_spec.rb
@@ -483,6 +483,15 @@ module OData
category.Products[0].Id.should eq 1
category.Products[1].Id.should eq 2
end
+
+ it "should not mutate the object's metadata" do
+ svc = OData::Service.new "http://test.com/test.svc/"
+ svc.Products(1)
+ product = svc.execute.first
+ original_metadata = product.__metadata.to_json
+ svc.load_property(product, "Category")
+ product.__metadata.to_json.should == original_metadata
+ end
end
describe "find, create, add, update, and delete" do
@@ -746,4 +755,4 @@ module OData
end
end
end
-end
+end

0 comments on commit c9ed8a9

Please sign in to comment.
Something went wrong with that request. Please try again.