lib/cc_api_stub/helper.rb in cfoundry-4.3.5.rc1 vs lib/cc_api_stub/helper.rb in cfoundry-4.3.5
- old
+ new
@@ -89,20 +89,20 @@
def response(code, body=nil)
CcApiStub::Helper.response(code, body)
end
def succeed_to_load(options={})
- response_body = options[:response] || CcApiStub::Helper.load_fixtures(options.delete(:fixture) || "fake_cc_#{object_name}", options)
+ response_body = response_from_options(options.reverse_merge!({:fixture => "fake_cc_#{object_name}"}))
stub_get(object_endpoint(options[:id]), {}, response(200, response_body))
end
def fail_to_load(options = {})
stub_get(object_endpoint(options[:id]), {}, response(500))
end
def succeed_to_load_many(options={})
- response_body = options[:response] || CcApiStub::Helper.load_fixtures(options.delete(:fixture) || "fake_cc_#{object_name.pluralize}", options)
+ response_body = response_from_options(options.reverse_merge!({:fixture => "fake_cc_#{object_name.pluralize}"}))
stub_get(collection_endpoint, {}, response(200, response_body))
end
def succeed_to_load_empty(options = {})
root = options[:root] || object_name.pluralize
@@ -117,11 +117,11 @@
response_body = {object_name.to_sym => {:id => "#{object_name.gsub("_", "-")}-id-1"}}
stub_post(collection_endpoint, {}, response(201, response_body))
end
def succeed_to_update(options = {})
- stub_put(object_endpoint(options[:id]), nil, response(200, {}))
+ stub_put(object_endpoint(options[:id]), nil, response(200, response_from_options(options)))
end
def fail_to_update(options = {})
stub_put(object_endpoint(options[:id]), nil, response(500, {}))
end
@@ -132,8 +132,17 @@
alias_method :succeed_to_leave, :succeed_to_delete
def fixture_prefix
"_cc"
+ end
+
+ private
+
+ def response_from_options(options)
+ fixture = options.delete(:fixture)
+ return options[:response] if options[:response]
+ return CcApiStub::Helper.load_fixtures(fixture, options) if fixture
+ {}
end
end
end