Skip to content
Browse files

make usage of #as_summary_json more consistent

Change-Id: I05146f0dc9382c4b9a9de987cc8f5d27f63aae53
  • Loading branch information...
1 parent 959fa58 commit 9b66f538292ab5c0d659ab7ef4b96809078703c0 Dennis Schmidt & Roberto Ostinelli committed with Bob Nugmanov and Dmitriy Kalinin Jan 14, 2013
View
22 lib/cloud_controller/api/app_summary.rb
@@ -23,9 +23,7 @@ def summary(id)
:framework => app.framework.to_hash.merge(:guid => app.framework.guid),
:runtime => app.runtime.to_hash.merge(:guid => app.runtime.guid),
:running_instances => app.running_instances,
- :services => app.service_instances.map do |instance|
- service_instance_summary(instance)
- end,
+ :services => app.service_instances.map(&:as_summary_json),
:available_domains => app.space.domains.map(&:as_summary_json)
}.merge(app.to_hash)
@@ -34,24 +32,6 @@ def summary(id)
private
- def service_instance_summary(instance)
- {
- :guid => instance.guid,
- :name => instance.name,
- :bound_app_count => instance.service_bindings_dataset.count,
- :service_plan => {
- :guid => instance.service_plan.guid,
- :name => instance.service_plan.name,
- :service => {
- :guid => instance.service_plan.service.guid,
- :label => instance.service_plan.service.label,
- :provider => instance.service_plan.service.provider,
- :version => instance.service_plan.service.version,
- }
- }
- }
- end
-
get "#{path_id}/summary", :summary
end
end
View
18 lib/cloud_controller/models/service_instance.rb
@@ -61,6 +61,24 @@ def validate_service_binding(service_binding)
end
end
+ def as_summary_json
+ {
+ :guid => guid,
+ :name => name,
+ :bound_app_count => service_bindings_dataset.count,
+ :service_plan => {
+ :guid => service_plan.guid,
+ :name => service_plan.name,
+ :service => {
+ :guid => service_plan.service.guid,
+ :label => service_plan.service.label,
+ :provider => service_plan.service.provider,
+ :version => service_plan.service.version,
+ }
+ }
+ }
+ end
+
def check_quota
if space
if !space.organization.service_instance_quota_remaining?
View
22 spec/models/service_instance_spec.rb
@@ -123,6 +123,28 @@ module VCAP::CloudController
end
end
+ describe "#as_summary_json" do
+ subject { Models::ServiceInstance.make }
+
+ it "returns detailed summary" do
+ subject.as_summary_json.should == {
+ :guid => subject.guid,
+ :name => subject.name,
+ :bound_app_count => 0,
+ :service_plan => {
+ :guid => subject.service_plan.guid,
+ :name => subject.service_plan.name,
+ :service => {
+ :guid => subject.service_plan.service.guid,
+ :label => subject.service_plan.service.label,
+ :provider => subject.service_plan.service.provider,
+ :version => subject.service_plan.service.version,
+ }
+ }
+ }
+ end
+ end
+
context "quota" do
let(:free_plan) { Models::ServicePlan.make(:free => true)}
let(:paid_plan) { Models::ServicePlan.make(:free => false)}

0 comments on commit 9b66f53

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