From 324bfab7e9654ba43995b3031c900eaa3d39ee06 Mon Sep 17 00:00:00 2001 From: Alberto Bellotti Date: Tue, 20 Mar 2018 15:17:47 -0400 Subject: [PATCH] Completing the Enterprise story, adding an enterprise_href in the server_info section in the API entrypoint. Followup to https://github.com/ManageIQ/manageiq-api/pull/346 --- app/controllers/api/api_controller.rb | 15 ++++++++------- spec/requests/enterprises_spec.rb | 2 +- spec/requests/entrypoint_spec.rb | 15 ++++++++------- spec/support/api/helpers.rb | 1 + 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index 67df8dd6cb..90b1635921 100644 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -58,13 +58,14 @@ def entrypoint_collections def server_info { - :version => Vmdb::Appliance.VERSION, - :build => Vmdb::Appliance.BUILD, - :appliance => MiqServer.my_server.name, - :time => Time.now.utc.iso8601, - :server_href => "#{@req.api_prefix}/servers/#{MiqServer.my_server.id}", - :zone_href => "#{@req.api_prefix}/zones/#{MiqServer.my_server.zone.id}", - :region_href => "#{@req.api_prefix}/regions/#{MiqRegion.my_region.id}" + :version => Vmdb::Appliance.VERSION, + :build => Vmdb::Appliance.BUILD, + :appliance => MiqServer.my_server.name, + :time => Time.now.utc.iso8601, + :server_href => "#{@req.api_prefix}/servers/#{MiqServer.my_server.id}", + :zone_href => "#{@req.api_prefix}/zones/#{MiqServer.my_server.zone.id}", + :region_href => "#{@req.api_prefix}/regions/#{MiqRegion.my_region.id}", + :enterprise_href => "#{@req.api_prefix}/enterprises/#{MiqEnterprise.my_enterprise.id}" } end diff --git a/spec/requests/enterprises_spec.rb b/spec/requests/enterprises_spec.rb index 7812008e03..e44a256ca3 100644 --- a/spec/requests/enterprises_spec.rb +++ b/spec/requests/enterprises_spec.rb @@ -1,7 +1,7 @@ describe "Enterprises API" do context "GET /api/enterprises" do it "returns the enterprises" do - enterprise = FactoryGirl.create(:miq_enterprise) + enterprise = MiqEnterprise.first api_basic_authorize get(api_enterprises_url) diff --git a/spec/requests/entrypoint_spec.rb b/spec/requests/entrypoint_spec.rb index 0fbcad9382..84a4a4b20c 100644 --- a/spec/requests/entrypoint_spec.rb +++ b/spec/requests/entrypoint_spec.rb @@ -45,13 +45,14 @@ expect(response.parsed_body).to include( "server_info" => a_hash_including( - "version" => Vmdb::Appliance.VERSION, - "build" => Vmdb::Appliance.BUILD, - "appliance" => MiqServer.my_server.name, - "time" => "2018-01-01T00:00:00Z", - "server_href" => api_server_url(nil, MiqServer.my_server), - "zone_href" => api_zone_url(nil, MiqServer.my_server.zone), - "region_href" => api_region_url(nil, MiqRegion.my_region) + "version" => Vmdb::Appliance.VERSION, + "build" => Vmdb::Appliance.BUILD, + "appliance" => MiqServer.my_server.name, + "time" => "2018-01-01T00:00:00Z", + "server_href" => api_server_url(nil, MiqServer.my_server), + "zone_href" => api_zone_url(nil, MiqServer.my_server.zone), + "region_href" => api_region_url(nil, MiqRegion.my_region), + "enterprise_href" => api_enterprise_url(nil, MiqEnterprise.my_enterprise) ) ) end diff --git a/spec/support/api/helpers.rb b/spec/support/api/helpers.rb index 6f6f7c3a81..6d6a41f631 100644 --- a/spec/support/api/helpers.rb +++ b/spec/support/api/helpers.rb @@ -7,6 +7,7 @@ module Support module Api module Helpers def init_api_spec_env + @enterprise = FactoryGirl.create(:miq_enterprise) @guid, @server, @zone = EvmSpecHelper.create_guid_miq_server_zone @region = FactoryGirl.create(:miq_region, :region => ApplicationRecord.my_region_number) @role = FactoryGirl.create(:miq_user_role, :name => "Api User Role")