diff --git a/app/controllers/api/base_controller/action.rb b/app/controllers/api/base_controller/action.rb index cc86641578b..c86806558f0 100644 --- a/app/controllers/api/base_controller/action.rb +++ b/app/controllers/api/base_controller/action.rb @@ -8,7 +8,7 @@ def api_action(type, id, options = {}) result = yield(klass) if block_given? - add_href_to_result(result, type, id) unless options[:skip_href] + add_href_to_result(result, type, compress_if_numeric_id(id)) unless options[:skip_href] log_result(result) result end diff --git a/app/controllers/api/base_controller/generic.rb b/app/controllers/api/base_controller/generic.rb index 1c096e1f01b..b890e0e8d12 100644 --- a/app/controllers/api/base_controller/generic.rb +++ b/app/controllers/api/base_controller/generic.rb @@ -187,7 +187,7 @@ def delete_resource_action(klass, type, id) rescue => err action_result(false, "#{err} - #{resource.errors.full_messages.join(', ')}") end - add_href_to_result(result, type, id) + add_href_to_result(result, type, ApplicationRecord.compress_id(id)) log_result(result) result end @@ -204,7 +204,7 @@ def invoke_custom_action(type, resource, action, data) rescue => err action_result(false, err.to_s) end - add_href_to_result(result, type, resource.id) + add_href_to_result(result, type, resource.compressed_id) log_result(result) result end @@ -218,7 +218,7 @@ def invoke_custom_action_with_dialog(type, resource, action, data, custom_button rescue => err action_result(false, err.to_s) end - add_href_to_result(result, type, resource.id) + add_href_to_result(result, type, resource.compressed_id) log_result(result) result end diff --git a/app/controllers/api/base_controller/normalizer.rb b/app/controllers/api/base_controller/normalizer.rb index 70fb8549277..84a73952d50 100644 --- a/app/controllers/api/base_controller/normalizer.rb +++ b/app/controllers/api/base_controller/normalizer.rb @@ -10,7 +10,7 @@ def normalize_hash(type, obj, opts = {}) attrs = normalize_select_attributes(obj, opts) result = {} - href = new_href(type, obj["id"], obj["href"]) + href = new_href(compress_path(type), compress_if_numeric_id(obj["id"]), obj["href"]) if href.present? result["href"] = href attrs -= ["href"] @@ -78,7 +78,7 @@ def normalize_href(type, value) end def subcollection_href(type, value) - normalize_url("#{@req.collection}/#{@req.c_id}/#{type}/#{value}") + normalize_url("#{@req.collection}/#{ApplicationRecord.compress_id(@req.c_id)}/#{type}/#{value}") end def collection_href(type, value) diff --git a/app/controllers/api/base_controller/renderer.rb b/app/controllers/api/base_controller/renderer.rb index 2017b5c87e2..d0d5ea6b618 100644 --- a/app/controllers/api/base_controller/renderer.rb +++ b/app/controllers/api/base_controller/renderer.rb @@ -46,7 +46,7 @@ def collection_to_jbuilder(type, reftype, resources, opts = {}) if opts[:expand_resources] add_hash json, resource_to_jbuilder(type, reftype, resource, opts).attributes! else - json.href normalize_href(reftype, resource["id"]) + json.href normalize_href(compress_path(reftype), ApplicationRecord.compress_id(resource["id"])) end end end @@ -398,7 +398,7 @@ def expand_subcollection(json, sc, sctype, subresources) if @req.expand?(sc) || scr["id"].nil? add_child js, normalize_hash(sctype, scr) else - js.child! { |jsc| jsc.href normalize_href(sctype, scr["id"]) } + js.child! { |jsc| jsc.href normalize_href(sctype, ApplicationRecord.compress_id(scr["id"])) } end end end @@ -475,6 +475,22 @@ def render_options(resource, data = {}) klass = collection_class(resource) render :json => OptionsSerializer.new(klass, data).serialize end + + def compress_path(path) + if path.to_s.split("/").size > 1 + path.to_s.split("/").tap { |e| e[1] = ApplicationRecord.compress_id(e[1]) if e[1] =~ /\A[0-9]+\z/ }.join("/") + else + path + end + end + + def compress_if_numeric_id(id) + if id.to_s =~ /\A[0-9]+\z/ + ApplicationRecord.compress_id(id) + else + id + end + end end end end diff --git a/app/controllers/api/base_controller/results.rb b/app/controllers/api/base_controller/results.rb index f35f2d10566..4022ccd3aa5 100644 --- a/app/controllers/api/base_controller/results.rb +++ b/app/controllers/api/base_controller/results.rb @@ -9,7 +9,7 @@ def action_result(success, message = nil, options = {}) res[:result] = options[:result] unless options[:result].nil? add_task_to_result(res, options[:task_id]) if options[:task_id].present? add_tasks_to_result(res, options[:task_ids]) if options[:task_ids].present? - add_parent_href_to_result(res, options[:parent_id]) if options[:parent_id].present? + add_parent_href_to_result(res, ApplicationRecord.compress_id(options[:parent_id])) if options[:parent_id].present? res end @@ -20,27 +20,27 @@ def add_href_to_result(hash, type, id) def add_parent_href_to_result(hash, parent_id = nil) return if hash[:href].present? - hash[:href] = "#{@req.api_prefix}/#{@req.collection}/#{parent_id ? parent_id : @req.c_id}" + hash[:href] = "#{@req.api_prefix}/#{@req.collection}/#{parent_id ? parent_id : ApplicationRecord.compress_id(@req.c_id)}" hash end def add_task_to_result(hash, task_id) hash[:task_id] = ApplicationRecord.compress_id(task_id) - hash[:task_href] = task_href(task_id) + hash[:task_href] = task_href(ApplicationRecord.compress_id(task_id)) hash end def add_tasks_to_result(hash, task_ids) add_task_to_result(hash, task_ids.first) hash[:tasks] = task_ids.collect do |task_id| - { :id => ApplicationRecord.compress_id(task_id), :href => task_href(task_id) } + { :id => ApplicationRecord.compress_id(task_id), :href => task_href(ApplicationRecord.compress_id(task_id)) } end end def add_tag_to_result(hash, tag_spec) hash[:tag_category] = tag_spec[:category] if tag_spec[:category].present? hash[:tag_name] = tag_spec[:name] if tag_spec[:name].present? - hash[:tag_href] = "#{@req.api_prefix}/tags/#{tag_spec[:id]}" if tag_spec[:id].present? + hash[:tag_href] = "#{@req.api_prefix}/tags/#{ApplicationRecord.compress_id(tag_spec[:id])}" if tag_spec[:id].present? hash end @@ -52,7 +52,7 @@ def add_subcollection_resource_to_result(hash, ctype, object) return hash if object.blank? ctype_pref = ctype.to_s.singularize hash["#{ctype_pref}_id".to_sym] = object.id - hash["#{ctype_pref}_href".to_sym] = "#{@req.api_prefix}/#{ctype}/#{object.id}" + hash["#{ctype_pref}_href".to_sym] = "#{@req.api_prefix}/#{ctype}/#{object.compressed_id}" hash end diff --git a/app/controllers/api/reports_controller.rb b/app/controllers/api/reports_controller.rb index 1476d376345..d359d68a7ce 100644 --- a/app/controllers/api/reports_controller.rb +++ b/app/controllers/api/reports_controller.rb @@ -30,7 +30,7 @@ def run_report_result(success, message = nil, options = {}) res = {:success => success} res[:message] = message if message.present? add_parent_href_to_result(res) - add_report_result_to_result(res, options[:report_result_id]) if options[:report_result_id].present? + add_report_result_to_result(res, ApplicationRecord.compress_id(options[:report_result_id])) if options[:report_result_id].present? add_task_to_result(res, options[:task_id]) if options[:task_id].present? res end @@ -60,8 +60,8 @@ def schedule_reports(report, type, id, data) desc = "scheduling of report #{report.id}" schedule = report.add_schedule fetch_schedule_data(data) res = action_result(true, desc) - add_report_schedule_to_result(res, schedule.id, report.id) - add_href_to_result(res, type, id) + add_report_schedule_to_result(res, schedule.compressed_id, report.compressed_id) + add_href_to_result(res, type, ApplicationRecord.compress_id(id)) res rescue => err action_result(false, err.to_s) diff --git a/app/controllers/api/services_controller.rb b/app/controllers/api/services_controller.rb index 0db3d80f120..9dbb7a05c28 100644 --- a/app/controllers/api/services_controller.rb +++ b/app/controllers/api/services_controller.rb @@ -194,7 +194,7 @@ def invoke_reconfigure_dialog(type, svc, data = {}) rescue => err action_result(false, err.to_s) end - add_href_to_result(result, type, svc.id) + add_href_to_result(result, type, svc.compressed_id) log_result(result) result end diff --git a/lib/api/utils.rb b/lib/api/utils.rb index a07159364b3..d8c6fd215c0 100644 --- a/lib/api/utils.rb +++ b/lib/api/utils.rb @@ -3,7 +3,7 @@ module Utils def self.build_href_slug(klass, id) return unless id collection = Api::CollectionConfig.new.name_for_subclass(klass) - "#{collection}/#{id}" if collection + "#{collection}/#{ApplicationRecord.compress_id(id)}" if collection end def self.resource_search_by_href_slug(href_slug, user = User.current_user) @@ -16,7 +16,7 @@ def self.resource_search_by_href_slug(href_slug, user = User.current_user) raise _("User must be defined") unless user klass = collection_config.klass(collection) - Rbac.filtered_object(klass.find(id), :user => user, :class => klass) + Rbac.filtered_object(klass.find(ApplicationRecord.uncompress_id(id)), :user => user, :class => klass) end end end diff --git a/spec/lib/api/utils_spec.rb b/spec/lib/api/utils_spec.rb index 95723f0e888..e60fdc7a8c3 100644 --- a/spec/lib/api/utils_spec.rb +++ b/spec/lib/api/utils_spec.rb @@ -100,5 +100,16 @@ expect(actual).to eq(nil) end + + it "can interpret slugs with compressed ids" do + owner_tenant = FactoryGirl.create(:tenant) + owner_group = FactoryGirl.create(:miq_group, :tenant => owner_tenant) + owner = FactoryGirl.create(:user, :miq_groups => [owner_group]) + vm = FactoryGirl.create(:vm_vmware, :tenant => owner_tenant) + + actual = described_class.resource_search_by_href_slug("vms/#{vm.compressed_id}", owner) + + expect(actual).to eq(vm) + end end end diff --git a/spec/requests/api/alert_definitions_spec.rb b/spec/requests/api/alert_definitions_spec.rb index 3094d7a6a0d..3f72aa6c41a 100644 --- a/spec/requests/api/alert_definitions_spec.rb +++ b/spec/requests/api/alert_definitions_spec.rb @@ -24,10 +24,10 @@ "subcount" => 2, "resources" => a_collection_containing_exactly( { - "href" => a_string_matching(alert_definitions_url(alert_definitions[0].id)) + "href" => a_string_matching(alert_definitions_url(alert_definitions[0].compressed_id)) }, { - "href" => a_string_matching(alert_definitions_url(alert_definitions[1].id)) + "href" => a_string_matching(alert_definitions_url(alert_definitions[1].compressed_id)) } ) ) @@ -46,7 +46,7 @@ run_get(alert_definitions_url(alert_definition.id)) expect(response).to have_http_status(:ok) expect(response.parsed_body).to include( - "href" => a_string_matching(alert_definitions_url(alert_definition.id)), + "href" => a_string_matching(alert_definitions_url(alert_definition.compressed_id)), "id" => alert_definition.compressed_id, "description" => alert_definition.description, "guid" => alert_definition.guid @@ -94,7 +94,7 @@ expect(response).to have_http_status(:ok) expect_single_action_result(:success => true, :message => "alert_definitions id: #{alert_definition.id} deleting", - :href => alert_definitions_url(alert_definition.id)) + :href => alert_definitions_url(alert_definition.compressed_id)) end it "deletes an alert definition via DELETE" do @@ -168,9 +168,11 @@ expect(response).to have_http_status(:ok) expect_query_result(:alert_definition_profiles, 2, 2) - expect_result_resources_to_include_hrefs("resources", - [alert_definition_profiles_url(alert_definition_profiles.first.id), - alert_definition_profiles_url(alert_definition_profiles.second.id)]) + expect_result_resources_to_include_hrefs( + "resources", + [alert_definition_profiles_url(alert_definition_profiles.first.compressed_id), + alert_definition_profiles_url(alert_definition_profiles.second.compressed_id)] + ) end it "reads an alert definition profile as a resource" do @@ -180,7 +182,7 @@ expect(response).to have_http_status(:ok) expect(response.parsed_body).to include( - "href" => a_string_matching(alert_definition_profiles_url(alert_definition_profile.id)), + "href" => a_string_matching(alert_definition_profiles_url(alert_definition_profile.compressed_id)), "description" => alert_definition_profile.description, "guid" => alert_definition_profile.guid ) @@ -196,8 +198,8 @@ expect(response).to have_http_status(:ok) expect_result_resources_to_include_hrefs( "resources", - ["#{alert_definition_profiles_url}/#{alert_definition_profile.id}/alert_definitions/#{alert_definitions.first.id}", - "#{alert_definition_profiles_url}/#{alert_definition_profile.id}/alert_definitions/#{alert_definitions.first.id}"] + ["#{alert_definition_profiles_url}/#{alert_definition_profile.compressed_id}/alert_definitions/#{alert_definitions.first.compressed_id}", + "#{alert_definition_profiles_url}/#{alert_definition_profile.compressed_id}/alert_definitions/#{alert_definitions.first.compressed_id}"] ) end @@ -244,7 +246,7 @@ expect(response).to have_http_status(:ok) expect_single_action_result(:success => true, :message => "alert_definition_profiles id: #{alert_definition_profile.id} deleting", - :href => alert_definition_profiles_url(alert_definition_profile.id)) + :href => alert_definition_profiles_url(alert_definition_profile.compressed_id)) end it "deletes an alert definition profile via DELETE" do diff --git a/spec/requests/api/alerts_spec.rb b/spec/requests/api/alerts_spec.rb index cefb66f4ac7..02214025773 100644 --- a/spec/requests/api/alerts_spec.rb +++ b/spec/requests/api/alerts_spec.rb @@ -16,10 +16,10 @@ "subcount" => 2, "resources" => [ { - "href" => a_string_matching(alerts_url(alert_statuses[0].id)) + "href" => a_string_matching(alerts_url(alert_statuses[0].compressed_id)) }, { - "href" => a_string_matching(alerts_url(alert_statuses[1].id)) + "href" => a_string_matching(alerts_url(alert_statuses[1].compressed_id)) } ] ) @@ -38,7 +38,7 @@ run_get(alerts_url(alert_status.id)) expect(response).to have_http_status(:ok) expect(response.parsed_body).to include( - "href" => a_string_matching(alerts_url(alert_status.id)), + "href" => a_string_matching(alerts_url(alert_status.compressed_id)), "id" => alert_status.compressed_id ) end @@ -81,7 +81,7 @@ "subcount" => 1, "resources" => [ { - "href" => a_string_matching("#{alerts_url(alert.id)}/alert_actions/#{alert_action.id}") + "href" => a_string_matching("#{alerts_url(alert.compressed_id)}/alert_actions/#{alert_action.compressed_id}") } ] ) @@ -146,7 +146,7 @@ it "create an assignment alert action reference by href" do attributes = { "action_type" => "assign", - "assignee" => { "href" => users_url(assignee.id) } + "assignee" => { "href" => users_url(assignee.compressed_id) } } api_basic_authorize subcollection_action_identifier(:alerts, :alert_actions, :create, :post) run_post(actions_subcollection_url, attributes) @@ -177,7 +177,7 @@ run_get("#{actions_subcollection_url}/#{alert_action.id}") expect(response).to have_http_status(:ok) expect(response.parsed_body).to include( - "href" => a_string_matching("#{alerts_url(alert.id)}/alert_actions/#{alert_action.id}"), + "href" => a_string_matching("#{alerts_url(alert.compressed_id)}/alert_actions/#{alert_action.compressed_id}"), "id" => alert_action.compressed_id, "action_type" => alert_action.action_type, "user_id" => user.compressed_id, diff --git a/spec/requests/api/authentications_spec.rb b/spec/requests/api/authentications_spec.rb index 5f8dcf85184..463e047baeb 100644 --- a/spec/requests/api/authentications_spec.rb +++ b/spec/requests/api/authentications_spec.rb @@ -14,7 +14,7 @@ 'count' => 1, 'subcount' => 1, 'name' => 'authentications', - 'resources' => [hash_including('href' => a_string_matching(authentications_url(auth.id)))] + 'resources' => [hash_including('href' => a_string_matching(authentications_url(auth.compressed_id)))] } expect(response.parsed_body).to include(expected) expect(response).to have_http_status(:ok) @@ -36,7 +36,7 @@ run_get(authentications_url(auth.id)) expected = { - 'href' => a_string_matching(authentications_url(auth.id)) + 'href' => a_string_matching(authentications_url(auth.compressed_id)) } expect(response.parsed_body).to include(expected) expect(response).to have_http_status(:ok) diff --git a/spec/requests/api/automate_domains_spec.rb b/spec/requests/api/automate_domains_spec.rb index b3e33a9e795..0353688baa1 100644 --- a/spec/requests/api/automate_domains_spec.rb +++ b/spec/requests/api/automate_domains_spec.rb @@ -45,7 +45,7 @@ expect_single_action_result( :success => true, :message => a_string_matching(/Refreshing Automate Domain .* from git repository/), - :href => automate_domains_url(git_domain.id) + :href => automate_domains_url(git_domain.compressed_id) ) end diff --git a/spec/requests/api/automation_requests_spec.rb b/spec/requests/api/automation_requests_spec.rb index 64decc99895..f97691b4768 100644 --- a/spec/requests/api/automation_requests_spec.rb +++ b/spec/requests/api/automation_requests_spec.rb @@ -38,7 +38,7 @@ "count" => 2, "subcount" => 1, "resources" => a_collection_containing_exactly( - "href" => a_string_matching(automation_requests_url(automation_request2.id)), + "href" => a_string_matching(automation_requests_url(automation_request2.compressed_id)), ) } expect(response).to have_http_status(:ok) @@ -58,8 +58,8 @@ "count" => 2, "subcount" => 2, "resources" => a_collection_containing_exactly( - {"href" => a_string_matching(automation_requests_url(automation_request1.id))}, - {"href" => a_string_matching(automation_requests_url(automation_request2.id))}, + {"href" => a_string_matching(automation_requests_url(automation_request1.compressed_id))}, + {"href" => a_string_matching(automation_requests_url(automation_request2.compressed_id))}, ) } expect(response).to have_http_status(:ok) @@ -86,7 +86,7 @@ expected = { "id" => automation_request.compressed_id, - "href" => a_string_matching(automation_requests_url(automation_request.id)) + "href" => a_string_matching(automation_requests_url(automation_request.compressed_id)) } expect(response).to have_http_status(:ok) expect(response.parsed_body).to include(expected) @@ -198,7 +198,7 @@ run_post(request1_url, gen_request(:approve, :reason => "approve reason")) expected_msg = "Automation request #{request1.id} approved" - expect_single_action_result(:success => true, :message => expected_msg, :href => request1_url) + expect_single_action_result(:success => true, :message => expected_msg, :href => automation_requests_url(request1.compressed_id)) end it "supports denying a request" do @@ -207,7 +207,7 @@ run_post(request2_url, gen_request(:deny, :reason => "deny reason")) expected_msg = "Automation request #{request2.id} denied" - expect_single_action_result(:success => true, :message => expected_msg, :href => request2_url) + expect_single_action_result(:success => true, :message => expected_msg, :href => automation_requests_url(request2.compressed_id)) end it "supports approving multiple requests" do @@ -221,12 +221,12 @@ { "message" => a_string_matching(/Automation request #{request1.id} approved/i), "success" => true, - "href" => a_string_matching(request1_url) + "href" => a_string_matching(automation_requests_url(request1.compressed_id)) }, { "message" => a_string_matching(/Automation request #{request2.id} approved/i), "success" => true, - "href" => a_string_matching(request2_url) + "href" => a_string_matching(automation_requests_url(request2.compressed_id)) } ) } @@ -245,12 +245,12 @@ { "message" => a_string_matching(/Automation request #{request1.id} denied/i,), "success" => true, - "href" => a_string_matching(request1_url) + "href" => a_string_matching(automation_requests_url(request1.compressed_id)) }, { "message" => a_string_matching(/Automation request #{request2.id} denied/i), "success" => true, - "href" => a_string_matching(request2_url) + "href" => a_string_matching(automation_requests_url(request2.compressed_id)) } ) } diff --git a/spec/requests/api/blueprints_spec.rb b/spec/requests/api/blueprints_spec.rb index 0c3cd3262ba..f953dcea1f0 100644 --- a/spec/requests/api/blueprints_spec.rb +++ b/spec/requests/api/blueprints_spec.rb @@ -11,7 +11,7 @@ "subcount" => 1, "name" => "blueprints", "resources" => [ - hash_including("href" => a_string_matching(blueprints_url(blueprint.id))) + hash_including("href" => a_string_matching(blueprints_url(blueprint.compressed_id))) ] } expect(response.parsed_body).to include(expected) @@ -35,7 +35,7 @@ run_get(blueprints_url(blueprint.id)) - expect(response.parsed_body).to include("href" => a_string_matching(blueprints_url(blueprint.id))) + expect(response.parsed_body).to include("href" => a_string_matching(blueprints_url(blueprint.compressed_id))) expect(response).to have_http_status(:ok) end diff --git a/spec/requests/api/categories_spec.rb b/spec/requests/api/categories_spec.rb index ed01838f7be..4b672f5908c 100644 --- a/spec/requests/api/categories_spec.rb +++ b/spec/requests/api/categories_spec.rb @@ -7,7 +7,7 @@ expect_result_resources_to_include_hrefs( "resources", - categories.map { |category| categories_url(category.id) } + categories.map { |category| categories_url(category.compressed_id) } ) expect(response).to have_http_status(:ok) end @@ -20,7 +20,7 @@ run_get categories_url, :filter => ["name=foo"] expect_query_result(:categories, 1, 2) - expect_result_resources_to_include_hrefs("resources", [categories_url(category_1.id)]) + expect_result_resources_to_include_hrefs("resources", [categories_url(category_1.compressed_id)]) end it "will return a bad request error if the filter name is invalid" do @@ -40,7 +40,7 @@ expect_result_to_match_hash( response.parsed_body, "description" => category.description, - "href" => categories_url(category.id), + "href" => categories_url(category.compressed_id), "id" => category.compressed_id ) expect(response).to have_http_status(:ok) @@ -67,7 +67,7 @@ expect_result_resources_to_include_hrefs( "resources", - ["#{categories_url(category.id)}/tags/#{tag.id}"] + ["#{categories_url(category.compressed_id)}/tags/#{tag.compressed_id}"] ) expect(response).to have_http_status(:ok) end diff --git a/spec/requests/api/chargebacks_spec.rb b/spec/requests/api/chargebacks_spec.rb index 9c0884c0232..73b4c96bf3b 100644 --- a/spec/requests/api/chargebacks_spec.rb +++ b/spec/requests/api/chargebacks_spec.rb @@ -8,7 +8,7 @@ run_get chargebacks_url expect_result_resources_to_include_hrefs( - "resources", [chargebacks_url(chargeback_rate.id)] + "resources", [chargebacks_url(chargeback_rate.compressed_id)] ) expect_result_to_match_hash(response.parsed_body, "count" => 1) expect(response).to have_http_status(:ok) @@ -25,7 +25,7 @@ "description" => chargeback_rate.description, "guid" => chargeback_rate.guid, "id" => chargeback_rate.compressed_id, - "href" => chargebacks_url(chargeback_rate.id) + "href" => chargebacks_url(chargeback_rate.compressed_id) ) expect(response).to have_http_status(:ok) end @@ -45,7 +45,7 @@ expect_query_result(:rates, 1, 1) expect_result_resources_to_include_hrefs( "resources", - ["#{chargebacks_url(chargeback_rate.id)}/rates/#{chargeback_rate_detail.to_param}"] + ["#{chargebacks_url(chargeback_rate.compressed_id)}/rates/#{chargeback_rate_detail.compressed_id}"] ) end @@ -64,7 +64,7 @@ expect_result_to_match_hash( response.parsed_body, "chargeback_rate_id" => chargeback_rate.compressed_id, - "href" => "#{chargebacks_url(chargeback_rate.id)}/rates/#{chargeback_rate_detail.to_param}", + "href" => "#{chargebacks_url(chargeback_rate.compressed_id)}/rates/#{chargeback_rate_detail.compressed_id}", "id" => chargeback_rate_detail.compressed_id, "description" => "rate_1" ) @@ -78,7 +78,7 @@ run_get '/api/currencies' expect_result_resources_to_include_hrefs( - "resources", ["/api/currencies/#{currency.id}"] + "resources", ["/api/currencies/#{currency.compressed_id}"] ) expect_result_to_match_hash(response.parsed_body, "count" => 1) expect(response).to have_http_status(:ok) @@ -94,7 +94,7 @@ response.parsed_body, "name" => currency.name, "id" => currency.compressed_id, - "href" => "/api/currencies/#{currency.id}" + "href" => "/api/currencies/#{currency.compressed_id}" ) expect(response).to have_http_status(:ok) end @@ -106,7 +106,7 @@ run_get '/api/measures' expect_result_resources_to_include_hrefs( - "resources", ["/api/measures/#{measure.id}"] + "resources", ["/api/measures/#{measure.compressed_id}"] ) expect_result_to_match_hash(response.parsed_body, "count" => 1) expect(response).to have_http_status(:ok) @@ -122,7 +122,7 @@ response.parsed_body, "name" => measure.name, "id" => measure.compressed_id, - "href" => "/api/measures/#{measure.id}", + "href" => "/api/measures/#{measure.compressed_id}", ) expect(response).to have_http_status(:ok) end diff --git a/spec/requests/api/cloud_subnets_spec.rb b/spec/requests/api/cloud_subnets_spec.rb index 576a8bc7a76..e4848d1d7ef 100644 --- a/spec/requests/api/cloud_subnets_spec.rb +++ b/spec/requests/api/cloud_subnets_spec.rb @@ -10,7 +10,7 @@ 'subcount' => 1, 'name' => 'cloud_subnets', 'resources' => [ - hash_including('href' => a_string_matching(cloud_subnets_url(cloud_subnet.id))) + hash_including('href' => a_string_matching(cloud_subnets_url(cloud_subnet.compressed_id))) ] } expect(response).to have_http_status(:ok) @@ -33,7 +33,7 @@ run_get(cloud_subnets_url(cloud_subnet.id)) - expect(response.parsed_body).to include('href' => a_string_matching(cloud_subnets_url(cloud_subnet.id))) + expect(response.parsed_body).to include('href' => a_string_matching(cloud_subnets_url(cloud_subnet.compressed_id))) expect(response).to have_http_status(:ok) end diff --git a/spec/requests/api/cloud_tenants_spec.rb b/spec/requests/api/cloud_tenants_spec.rb index 557e0108ecd..8775ee256af 100644 --- a/spec/requests/api/cloud_tenants_spec.rb +++ b/spec/requests/api/cloud_tenants_spec.rb @@ -10,7 +10,7 @@ 'subcount' => 1, 'name' => 'cloud_tenants', 'resources' => [ - hash_including('href' => a_string_matching(cloud_tenants_url(cloud_tenant.id))) + hash_including('href' => a_string_matching(cloud_tenants_url(cloud_tenant.compressed_id))) ] } expect(response).to have_http_status(:ok) @@ -33,7 +33,7 @@ run_get(cloud_tenants_url(cloud_tenant.id)) - expect(response.parsed_body).to include('href' => a_string_matching(cloud_tenants_url(cloud_tenant.id))) + expect(response.parsed_body).to include('href' => a_string_matching(cloud_tenants_url(cloud_tenant.compressed_id))) expect(response).to have_http_status(:ok) end diff --git a/spec/requests/api/cloud_volumes_spec.rb b/spec/requests/api/cloud_volumes_spec.rb index f60f2f98dd1..5178973d58f 100644 --- a/spec/requests/api/cloud_volumes_spec.rb +++ b/spec/requests/api/cloud_volumes_spec.rb @@ -36,7 +36,7 @@ expect(response).to have_http_status(:ok) expect(response.parsed_body).to include( - "href" => a_string_matching(cloud_volumes_url(cloud_volume.id)), + "href" => a_string_matching(cloud_volumes_url(cloud_volume.compressed_id)), "id" => cloud_volume.compressed_id ) end diff --git a/spec/requests/api/collections_spec.rb b/spec/requests/api/collections_spec.rb index 410d4d6c53b..590ae9c1ae4 100644 --- a/spec/requests/api/collections_spec.rb +++ b/spec/requests/api/collections_spec.rb @@ -26,7 +26,7 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil) api_basic_authorize collection_action_identifier(collection, :query) obj = id.nil? ? klass.first : klass.find(id) - url = send("#{collection}_url", obj.id) + url = send("#{collection}_url", obj.compressed_id) attr_list = String(Api::ApiConfig.collections[collection].identifying_attrs).split(",") attr_list |= %w(guid) if klass.attribute_method?(:guid) resources = [{"id" => obj.compressed_id}, {"href" => url}] @@ -537,7 +537,8 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil) vm = FactoryGirl.create(:vm_vmware) api_basic_authorize(collection_action_identifier(:vms, :query), action_identifier(:vms, :start)) - run_post(vms_url, gen_request(:query, [{"id" => vm.id, "href" => vms_url(vm.id)}])) + # HMMM + run_post(vms_url, gen_request(:query, [{"id" => vm.id}])) expected = { "results" => [ @@ -546,7 +547,7 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil) a_hash_including( "name" => "start", "method" => "post", - "href" => a_string_matching(vms_url(vm.id)) + "href" => a_string_matching(vms_url(vm.compressed_id)) ) ] ) diff --git a/spec/requests/api/conditions_spec.rb b/spec/requests/api/conditions_spec.rb index 148881ce539..6e1950e5c04 100644 --- a/spec/requests/api/conditions_spec.rb +++ b/spec/requests/api/conditions_spec.rb @@ -162,8 +162,10 @@ def assign_conditions_to(resource) run_get conditions_url expect_query_result(:conditions, 3, 3) - expect_result_resources_to_include_hrefs("resources", - Condition.pluck(:id).collect { |id| /^.*#{conditions_url(id)}$/ }) + expect_result_resources_to_include_hrefs( + "resources", + Condition.select(:id).collect { |c| /^.*#{conditions_url(c.compressed_id)}$/ } + ) end it "query conditions in expanded form" do diff --git a/spec/requests/api/configuration_script_payloads_spec.rb b/spec/requests/api/configuration_script_payloads_spec.rb index 6ade23e09d3..54f1683fecd 100644 --- a/spec/requests/api/configuration_script_payloads_spec.rb +++ b/spec/requests/api/configuration_script_payloads_spec.rb @@ -11,7 +11,7 @@ 'subcount' => 1, 'name' => 'configuration_script_payloads', 'resources' => [ - hash_including('href' => a_string_matching(configuration_script_payloads_url(script_payload.id))) + hash_including('href' => a_string_matching(configuration_script_payloads_url(script_payload.compressed_id))) ] } expect(response.parsed_body).to include(expected) @@ -35,7 +35,7 @@ run_get(configuration_script_payloads_url(script_payload.id)) expect(response.parsed_body) - .to include('href' => a_string_matching(configuration_script_payloads_url(script_payload.id))) + .to include('href' => a_string_matching(configuration_script_payloads_url(script_payload.compressed_id))) expect(response).to have_http_status(:ok) end diff --git a/spec/requests/api/configuration_script_sources_spec.rb b/spec/requests/api/configuration_script_sources_spec.rb index f612e487a47..5934da3706c 100644 --- a/spec/requests/api/configuration_script_sources_spec.rb +++ b/spec/requests/api/configuration_script_sources_spec.rb @@ -16,7 +16,7 @@ 'count' => 1, 'subcount' => 1, 'name' => 'configuration_script_sources', - 'resources' => [hash_including('href' => a_string_matching(configuration_script_sources_url(repository.id)))] + 'resources' => [hash_including('href' => a_string_matching(configuration_script_sources_url(repository.compressed_id)))] } expect(response.parsed_body).to include(expected) expect(response).to have_http_status(:ok) @@ -39,7 +39,7 @@ run_get(configuration_script_sources_url(repository.id)) expected = { - 'href' => a_string_matching(configuration_script_sources_url(repository.id)) + 'href' => a_string_matching(configuration_script_sources_url(repository.compressed_id)) } expect(response.parsed_body).to include(expected) expect(response).to have_http_status(:ok) @@ -455,7 +455,9 @@ run_get(url) expected = { - 'resources' => [{'href' => a_string_including("#{url}/#{payload.id}")}] + 'resources' => [ + {'href' => a_string_including("#{configuration_script_sources_url(config_script_src.compressed_id)}/configuration_script_payloads/#{payload.compressed_id}")} + ] } expect(response).to have_http_status(:ok) expect(response.parsed_body).to include(expected) @@ -468,7 +470,9 @@ expected = { 'subcount' => 1, - 'resources' => [{'href' => a_string_including("#{url}/#{payload.id}")}] + 'resources' => [ + {'href' => a_string_including("#{configuration_script_sources_url(config_script_src.compressed_id)}/configuration_script_payloads/#{payload.compressed_id}")} + ] } expect(response).to have_http_status(:ok) expect(response.parsed_body).to include(expected) diff --git a/spec/requests/api/custom_actions_spec.rb b/spec/requests/api/custom_actions_spec.rb index 7f12448692b..9d67167724a 100644 --- a/spec/requests/api/custom_actions_spec.rb +++ b/spec/requests/api/custom_actions_spec.rb @@ -162,7 +162,7 @@ def expect_result_to_have_custom_actions_hash run_post(services_url(svc1.id), gen_request(:button1, "button_key1" => "value", "button_key2" => "value")) - expect_single_action_result(:success => true, :message => /.*/, :href => services_url(svc1.id)) + expect_single_action_result(:success => true, :message => /.*/, :href => services_url(svc1.compressed_id)) end it "accepts a custom action as case insensitive" do @@ -170,7 +170,7 @@ def expect_result_to_have_custom_actions_hash run_post(services_url(svc1.id), gen_request(:BuTtOn1, "button_key1" => "value", "button_key2" => "value")) - expect_single_action_result(:success => true, :message => /.*/, :href => services_url(svc1.id)) + expect_single_action_result(:success => true, :message => /.*/, :href => services_url(svc1.compressed_id)) end end diff --git a/spec/requests/api/custom_attributes_spec.rb b/spec/requests/api/custom_attributes_spec.rb index a0cf84c522d..ccdf8f66ec2 100644 --- a/spec/requests/api/custom_attributes_spec.rb +++ b/spec/requests/api/custom_attributes_spec.rb @@ -39,6 +39,6 @@ run_post(url, :action => :edit, :name => 'name1') expect(response).to have_http_status(:ok) - expect(response.parsed_body['href']).to include(url) + expect(response.parsed_body['href']).to include("#{providers_url(provider.compressed_id)}/custom_attributes/#{custom_attribute.compressed_id}") end end diff --git a/spec/requests/api/events_spec.rb b/spec/requests/api/events_spec.rb index 333eac8c682..57443ab8720 100644 --- a/spec/requests/api/events_spec.rb +++ b/spec/requests/api/events_spec.rb @@ -38,8 +38,10 @@ def create_events(count) run_get events_url expect_query_result(:events, 3, 3) - expect_result_resources_to_include_hrefs("resources", - MiqEventDefinition.pluck(:id).collect { |id| /^.*#{events_url(id)}$/ }) + expect_result_resources_to_include_hrefs( + "resources", + MiqEventDefinition.select(:id).collect { |med| /^.*#{events_url(med.compressed_id)}$/ } + ) end it "query events in expanded form" do diff --git a/spec/requests/api/floating_ips_spec.rb b/spec/requests/api/floating_ips_spec.rb index fe87b77fcca..ca900bbe3ef 100644 --- a/spec/requests/api/floating_ips_spec.rb +++ b/spec/requests/api/floating_ips_spec.rb @@ -10,7 +10,7 @@ 'subcount' => 1, 'name' => 'floating_ips', 'resources' => [ - hash_including('href' => a_string_matching(floating_ips_url(floating_ip.id))) + hash_including('href' => a_string_matching(floating_ips_url(floating_ip.compressed_id))) ] } expect(response).to have_http_status(:ok) @@ -33,7 +33,7 @@ run_get(floating_ips_url(floating_ip.id)) - expect(response.parsed_body).to include('href' => a_string_matching(floating_ips_url(floating_ip.id))) + expect(response.parsed_body).to include('href' => a_string_matching(floating_ips_url(floating_ip.compressed_id))) expect(response).to have_http_status(:ok) end diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb index 5d157e2702f..e5f289675e8 100644 --- a/spec/requests/api/groups_spec.rb +++ b/spec/requests/api/groups_spec.rb @@ -241,7 +241,7 @@ run_post(g1_url, gen_request(:delete)) - expect_single_action_result(:success => true, :message => "deleting", :href => g1_url) + expect_single_action_result(:success => true, :message => "deleting", :href => groups_url(group1.compressed_id)) expect(MiqGroup.exists?(g1_id)).to be_falsey end @@ -254,7 +254,7 @@ run_post(groups_url, gen_request(:delete, [{"href" => g1_url}, {"href" => g2_url}])) expect_multiple_action_result(2) - expect_result_resources_to_include_hrefs("results", [g1_url, g2_url]) + expect_result_resources_to_include_hrefs("results", [groups_url(group1.compressed_id), groups_url(group2.compressed_id)]) expect(MiqGroup.exists?(g1_id)).to be_falsey expect(MiqGroup.exists?(g2_id)).to be_falsey end diff --git a/spec/requests/api/instances_spec.rb b/spec/requests/api/instances_spec.rb index 3887f8921db..e8bd3a4c1b6 100644 --- a/spec/requests/api/instances_spec.rb +++ b/spec/requests/api/instances_spec.rb @@ -24,7 +24,7 @@ def update_raw_power_state(state, *instances) run_get(instances_url) expect_query_result(:instances, 1, 1) - expect_result_resources_to_include_hrefs("resources", [instances_url(instance.id)]) + expect_result_resources_to_include_hrefs("resources", [instances_url(instance.compressed_id)]) end end @@ -53,7 +53,7 @@ def update_raw_power_state(state, *instances) expect_single_action_result( :success => true, :message => /#{instance.id}.* terminating/i, - :href => instance_url + :href => instances_url(instance.compressed_id) ) end @@ -67,12 +67,12 @@ def update_raw_power_state(state, *instances) a_hash_including( "message" => a_string_matching(/#{instance1.id}.* terminating/i), "success" => true, - "href" => a_string_matching(instance1_url) + "href" => a_string_matching(instances_url(instance1.compressed_id)) ), a_hash_including( "message" => a_string_matching(/#{instance2.id}.* terminating/i), "success" => true, - "href" => a_string_matching(instance2_url) + "href" => a_string_matching(instances_url(instance2.compressed_id)) ) ) } @@ -104,7 +104,7 @@ def update_raw_power_state(state, *instances) run_post(instance_url, gen_request(:stop)) - expect_single_action_result(:success => false, :message => "is not powered on", :href => instance_url) + expect_single_action_result(:success => false, :message => "is not powered on", :href => instances_url(instance.compressed_id)) end it "stops a valid instance" do @@ -112,7 +112,7 @@ def update_raw_power_state(state, *instances) run_post(instance_url, gen_request(:stop)) - expect_single_action_result(:success => true, :message => "stopping", :href => instance_url, :task => true) + expect_single_action_result(:success => true, :message => "stopping", :href => instances_url(instance.compressed_id), :task => true) end it "stops multiple valid instances" do @@ -121,7 +121,7 @@ def update_raw_power_state(state, *instances) run_post(instances_url, gen_request(:stop, nil, instance1_url, instance2_url)) expect_multiple_action_result(2, :task => true) - expect_result_resources_to_include_hrefs("results", instances_list) + expect_result_resources_to_include_hrefs("results", [instances_url(instance1.compressed_id), instances_url(instance2.compressed_id)]) end end @@ -147,7 +147,7 @@ def update_raw_power_state(state, *instances) run_post(instance_url, gen_request(:start)) - expect_single_action_result(:success => false, :message => "is powered on", :href => instance_url) + expect_single_action_result(:success => false, :message => "is powered on", :href => instances_url(instance.compressed_id)) end it "starts an instance" do @@ -156,7 +156,7 @@ def update_raw_power_state(state, *instances) run_post(instance_url, gen_request(:start)) - expect_single_action_result(:success => true, :message => "starting", :href => instance_url, :task => true) + expect_single_action_result(:success => true, :message => "starting", :href => instances_url(instance.compressed_id), :task => true) end it "starts multiple instances" do @@ -166,7 +166,7 @@ def update_raw_power_state(state, *instances) run_post(instances_url, gen_request(:start, nil, instance1_url, instance2_url)) expect_multiple_action_result(2, :task => true) - expect_result_resources_to_include_hrefs("results", instances_list) + expect_result_resources_to_include_hrefs("results", [instances_url(instance1.compressed_id), instances_url(instance2.compressed_id)]) end end @@ -193,7 +193,7 @@ def update_raw_power_state(state, *instances) run_post(instance_url, gen_request(:pause)) - expect_single_action_result(:success => false, :message => "is not powered on", :href => instance_url) + expect_single_action_result(:success => false, :message => "is not powered on", :href => instances_url(instance.compressed_id)) end it "fails to pause a paused instance" do @@ -202,7 +202,7 @@ def update_raw_power_state(state, *instances) run_post(instance_url, gen_request(:pause)) - expect_single_action_result(:success => false, :message => "is not powered on", :href => instance_url) + expect_single_action_result(:success => false, :message => "is not powered on", :href => instances_url(instance.compressed_id)) end it "pauses an instance" do @@ -210,7 +210,7 @@ def update_raw_power_state(state, *instances) run_post(instance_url, gen_request(:pause)) - expect_single_action_result(:success => true, :message => "pausing", :href => instance_url, :task => true) + expect_single_action_result(:success => true, :message => "pausing", :href => instances_url(instance.compressed_id), :task => true) end it "pauses multiple instances" do @@ -219,7 +219,7 @@ def update_raw_power_state(state, *instances) run_post(instances_url, gen_request(:pause, nil, instance1_url, instance2_url)) expect_multiple_action_result(2, :task => true) - expect_result_resources_to_include_hrefs("results", instances_list) + expect_result_resources_to_include_hrefs("results", [instances_url(instance1.compressed_id), instances_url(instance2.compressed_id)]) end end @@ -246,7 +246,7 @@ def update_raw_power_state(state, *instances) run_post(instance_url, gen_request(:suspend)) - expect_single_action_result(:success => false, :message => "is not powered on", :href => instance_url) + expect_single_action_result(:success => false, :message => "is not powered on", :href => instances_url(instance.compressed_id)) end it "cannot suspend a suspended instance" do @@ -255,7 +255,7 @@ def update_raw_power_state(state, *instances) run_post(instance_url, gen_request(:suspend)) - expect_single_action_result(:success => false, :message => "is not powered on", :href => instance_url) + expect_single_action_result(:success => false, :message => "is not powered on", :href => instances_url(instance.compressed_id)) end it "suspends an instance" do @@ -263,7 +263,7 @@ def update_raw_power_state(state, *instances) run_post(instance_url, gen_request(:suspend)) - expect_single_action_result(:success => true, :message => "suspending", :href => instance_url, :task => true) + expect_single_action_result(:success => true, :message => "suspending", :href => instances_url(instance.compressed_id), :task => true) end it "suspends multiple instances" do @@ -272,7 +272,7 @@ def update_raw_power_state(state, *instances) run_post(instances_url, gen_request(:suspend, nil, instance1_url, instance2_url)) expect_multiple_action_result(2, :task => true) - expect_result_resources_to_include_hrefs("results", instances_list) + expect_result_resources_to_include_hrefs("results", [instances_url(instance1.compressed_id), instances_url(instance2.compressed_id)]) end end @@ -299,7 +299,7 @@ def update_raw_power_state(state, *instances) run_post(instance_url, gen_request(:shelve)) - expect_single_action_result(:success => true, :message => 'shelving', :href => instance_url) + expect_single_action_result(:success => true, :message => 'shelving', :href => instances_url(instance.compressed_id)) end it "shelves a suspended instance" do @@ -308,7 +308,7 @@ def update_raw_power_state(state, *instances) run_post(instance_url, gen_request(:shelve)) - expect_single_action_result(:success => true, :message => 'shelving', :href => instance_url) + expect_single_action_result(:success => true, :message => 'shelving', :href => instances_url(instance.compressed_id)) end it "shelves a paused instance" do @@ -317,7 +317,7 @@ def update_raw_power_state(state, *instances) run_post(instance_url, gen_request(:shelve)) - expect_single_action_result(:success => true, :message => 'shelving', :href => instance_url) + expect_single_action_result(:success => true, :message => 'shelving', :href => instances_url(instance.compressed_id)) end it "cannot shelve a shelved instance" do @@ -329,7 +329,7 @@ def update_raw_power_state(state, *instances) expect_single_action_result( :success => false, :message => "The VM can't be shelved, current state has to be powered on, off, suspended or paused", - :href => instance_url + :href => instances_url(instance.compressed_id) ) end @@ -340,7 +340,7 @@ def update_raw_power_state(state, *instances) expect_single_action_result(:success => true, :message => "shelving", - :href => instance_url, + :href => instances_url(instance.compressed_id), :task => true) end @@ -350,7 +350,7 @@ def update_raw_power_state(state, *instances) run_post(instances_url, gen_request(:shelve, nil, instance1_url, instance2_url)) expect_multiple_action_result(2, :task => true) - expect_result_resources_to_include_hrefs("results", instances_list) + expect_result_resources_to_include_hrefs("results", [instances_url(instance1.compressed_id), instances_url(instance2.compressed_id)]) end end @@ -377,7 +377,7 @@ def update_raw_power_state(state, *instances) run_post(instance_url, gen_request(:reboot_guest)) - expect_single_action_result(:success => false, :message => "is not powered on", :href => instance_url) + expect_single_action_result(:success => false, :message => "is not powered on", :href => instances_url(instance.compressed_id)) end it "reboots a valid instance" do @@ -385,7 +385,7 @@ def update_raw_power_state(state, *instances) run_post(instance_url, gen_request(:reboot_guest)) - expect_single_action_result(:success => true, :message => "rebooting", :href => instance_url, :task => true) + expect_single_action_result(:success => true, :message => "rebooting", :href => instances_url(instance.compressed_id), :task => true) end it "reboots multiple valid instances" do @@ -394,7 +394,7 @@ def update_raw_power_state(state, *instances) run_post(instances_url, gen_request(:reboot_guest, nil, instance1_url, instance2_url)) expect_multiple_action_result(2, :task => true) - expect_result_resources_to_include_hrefs("results", instances_list) + expect_result_resources_to_include_hrefs("results", [instances_url(instance1.compressed_id), instances_url(instance2.compressed_id)]) end end @@ -421,7 +421,7 @@ def update_raw_power_state(state, *instances) run_post(instance_url, gen_request(:reset)) - expect_single_action_result(:success => false, :message => "is not powered on", :href => instance_url) + expect_single_action_result(:success => false, :message => "is not powered on", :href => instances_url(instance.compressed_id)) end it "resets a valid instance" do @@ -429,7 +429,7 @@ def update_raw_power_state(state, *instances) run_post(instance_url, gen_request(:reset)) - expect_single_action_result(:success => true, :message => "resetting", :href => instance_url, :task => true) + expect_single_action_result(:success => true, :message => "resetting", :href => instances_url(instance.compressed_id), :task => true) end it "resets multiple valid instances" do @@ -438,7 +438,7 @@ def update_raw_power_state(state, *instances) run_post(instances_url, gen_request(:reset, nil, instance1_url, instance2_url)) expect_multiple_action_result(2, :task => true) - expect_result_resources_to_include_hrefs("results", instances_list) + expect_result_resources_to_include_hrefs("results", [instances_url(instance1.compressed_id), instances_url(instance2.compressed_id)]) end end @@ -460,7 +460,7 @@ def update_raw_power_state(state, *instances) expected = { 'name' => 'load_balancers', 'resources' => [ - { 'href' => a_string_matching("#{instances_url(@vm.id)}/load_balancers/#{@load_balancer.id}") } + { 'href' => a_string_matching("#{instances_url(@vm.compressed_id)}/load_balancers/#{@load_balancer.compressed_id}") } ] } run_get("#{instances_url(@vm.id)}/load_balancers") diff --git a/spec/requests/api/load_balancers_spec.rb b/spec/requests/api/load_balancers_spec.rb index 5e67acf0f3d..f4e32d7539d 100644 --- a/spec/requests/api/load_balancers_spec.rb +++ b/spec/requests/api/load_balancers_spec.rb @@ -9,7 +9,7 @@ 'subcount' => 1, 'name' => 'load_balancers', 'resources' => [ - hash_including('href' => a_string_matching(load_balancers_url(load_balancer.id))) + hash_including('href' => a_string_matching(load_balancers_url(load_balancer.compressed_id))) ] } run_get(load_balancers_url) @@ -34,7 +34,7 @@ run_get(load_balancers_url(load_balancer.id)) - expect(response.parsed_body).to include('href' => a_string_matching(load_balancers_url(load_balancer.id))) + expect(response.parsed_body).to include('href' => a_string_matching(load_balancers_url(load_balancer.compressed_id))) expect(response).to have_http_status(:ok) end diff --git a/spec/requests/api/network_routers_spec.rb b/spec/requests/api/network_routers_spec.rb index 4f3e8f65186..8611f2f4f9a 100644 --- a/spec/requests/api/network_routers_spec.rb +++ b/spec/requests/api/network_routers_spec.rb @@ -10,7 +10,7 @@ 'subcount' => 1, 'name' => 'network_routers', 'resources' => [ - hash_including('href' => a_string_matching(network_routers_url(network_router.id))) + hash_including('href' => a_string_matching(network_routers_url(network_router.compressed_id))) ] } expect(response).to have_http_status(:ok) @@ -29,7 +29,7 @@ network_router = FactoryGirl.create(:network_router) api_basic_authorize action_identifier(:network_routers, :read, :resource_actions, :get) run_get(network_routers_url(network_router.id)) - expect(response.parsed_body).to include('href' => a_string_matching(network_routers_url(network_router.id))) + expect(response.parsed_body).to include('href' => a_string_matching(network_routers_url(network_router.compressed_id))) expect(response).to have_http_status(:ok) end diff --git a/spec/requests/api/notifications_spec.rb b/spec/requests/api/notifications_spec.rb index 896ce260e06..1a892b01b91 100644 --- a/spec/requests/api/notifications_spec.rb +++ b/spec/requests/api/notifications_spec.rb @@ -48,7 +48,7 @@ run_post(notification_url, gen_request(:delete)) expect(response).to have_http_status(:ok) - expect_single_action_result(:success => true, :href => notification_url) + expect_single_action_result(:success => true, :href => notifications_url(notification_recipient.compressed_id)) expect { notification_recipient.reload }.to raise_error(ActiveRecord::RecordNotFound) end @@ -74,7 +74,8 @@ run_post(notifications_url, gen_request(:delete, :href => notification_url)) expect(response).to have_http_status(:ok) - expect_results_to_match_hash('results', [{'success' => true, 'href' => notification_url}]) + expect_results_to_match_hash('results', [{'success' => true, + 'href' => notifications_url(notification_recipient.compressed_id)}]) expect { notification_recipient.reload }.to raise_error(ActiveRecord::RecordNotFound) end @@ -121,7 +122,7 @@ expect(notification_recipient.seen).to be_falsey run_post(notification_url, gen_request(:mark_as_seen)) - expect_single_action_result(:success => true, :href => notification_url) + expect_single_action_result(:success => true, :href => notifications_url(notification_recipient.compressed_id)) expect(notification_recipient.reload.seen).to be_truthy end end diff --git a/spec/requests/api/policies_assignment_spec.rb b/spec/requests/api/policies_assignment_spec.rb index fcf46149269..5bef8c456ab 100644 --- a/spec/requests/api/policies_assignment_spec.rb +++ b/spec/requests/api/policies_assignment_spec.rb @@ -81,7 +81,7 @@ def test_assign_multiple_policies(object_url, object_policies_url, collection, s expect_multiple_action_result(policies.size) sc_prefix = subcollection.to_s.singularize results_hash = policies.collect do |policy| - {"success" => true, "href" => object_url, "#{sc_prefix}_href" => %r{/api/#{subcollection}/#{policy.id}}} + {"success" => true, "href" => object_url, "#{sc_prefix}_href" => %r{/api/#{subcollection}/#{policy.compressed_id}}} end expect_results_to_match_hash("results", results_hash) expect(object.get_policies.size).to eq(policies.size) @@ -144,7 +144,7 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc let(:policy_profile_policies_url) { "#{policy_profile_url}/policies" } it "adds Policies to a Policy Profile" do - test_assign_multiple_policies(policy_profile_url, + test_assign_multiple_policies(policy_profiles_url(ps2.compressed_id), policy_profile_policies_url, :policy_profiles, :policies, @@ -171,11 +171,11 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "assign Provider policy with invalid guid" do - test_policy_assign_invalid_policy_guid(provider_url, provider_policies_url, :providers, :policies) + test_policy_assign_invalid_policy_guid(providers_url(provider.compressed_id), provider_policies_url, :providers, :policies) end it "assign Provider multiple policies" do - test_assign_multiple_policies(provider_url, + test_assign_multiple_policies(providers_url(provider.compressed_id), provider_policies_url, :providers, :policies, @@ -192,7 +192,7 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "unassign Provider policy with invalid guid" do - test_policy_unassign_invalid_policy_guid(provider_url, provider_policies_url, :providers, :policies) + test_policy_unassign_invalid_policy_guid(providers_url(provider.compressed_id), provider_policies_url, :providers, :policies) end it "unassign Provider multiple policies" do @@ -214,11 +214,11 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "assign Provider policy profile with invalid guid" do - test_policy_assign_invalid_policy_guid(provider_url, provider_policy_profiles_url, :providers, :policy_profiles) + test_policy_assign_invalid_policy_guid(providers_url(provider.compressed_id), provider_policy_profiles_url, :providers, :policy_profiles) end it "assign Provider multiple policy profiles" do - test_assign_multiple_policies(provider_url, + test_assign_multiple_policies(providers_url(provider.compressed_id), provider_policy_profiles_url, :providers, :policy_profiles, @@ -235,7 +235,7 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "unassign Provider policy profile with invalid guid" do - test_policy_unassign_invalid_policy_guid(provider_url, + test_policy_unassign_invalid_policy_guid(providers_url(provider.compressed_id), provider_policy_profiles_url, :providers, :policy_profiles) @@ -263,11 +263,11 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "assign Host policy with invalid guid" do - test_policy_assign_invalid_policy_guid(host_url, host_policies_url, :hosts, :policies) + test_policy_assign_invalid_policy_guid(hosts_url(host.compressed_id), host_policies_url, :hosts, :policies) end it "assign Host multiple policies" do - test_assign_multiple_policies(host_url, + test_assign_multiple_policies(hosts_url(host.compressed_id), host_policies_url, :hosts, :policies, @@ -284,7 +284,7 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "unassign Host policy with invalid guid" do - test_policy_unassign_invalid_policy_guid(host_url, host_policies_url, :hosts, :policies) + test_policy_unassign_invalid_policy_guid(hosts_url(host.compressed_id), host_policies_url, :hosts, :policies) end it "unassign Host multiple policies" do @@ -306,11 +306,11 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "assign Host policy profile with invalid guid" do - test_policy_assign_invalid_policy_guid(host_url, host_policy_profiles_url, :hosts, :policy_profiles) + test_policy_assign_invalid_policy_guid(hosts_url(host.compressed_id), host_policy_profiles_url, :hosts, :policy_profiles) end it "assign Host multiple policy profiles" do - test_assign_multiple_policies(host_url, + test_assign_multiple_policies(hosts_url(host.compressed_id), host_policy_profiles_url, :hosts, :policy_profiles, @@ -327,7 +327,7 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "unassign Host policy profile with invalid guid" do - test_policy_unassign_invalid_policy_guid(host_url, + test_policy_unassign_invalid_policy_guid(hosts_url(host.compressed_id), host_policy_profiles_url, :hosts, :policy_profiles) @@ -355,11 +355,11 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "assign Resource Pool policy with invalid guid" do - test_policy_assign_invalid_policy_guid(rp_url, rp_policies_url, :resource_pools, :policies) + test_policy_assign_invalid_policy_guid(resource_pools_url(rp.compressed_id), rp_policies_url, :resource_pools, :policies) end it "assign Resource Pool multiple policies" do - test_assign_multiple_policies(rp_url, + test_assign_multiple_policies(resource_pools_url(rp.compressed_id), rp_policies_url, :resource_pools, :policies, @@ -376,7 +376,7 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "unassign Resource Pool policy with invalid guid" do - test_policy_unassign_invalid_policy_guid(rp_url, rp_policies_url, :resource_pools, :policies) + test_policy_unassign_invalid_policy_guid(resource_pools_url(rp.compressed_id), rp_policies_url, :resource_pools, :policies) end it "unassign Resource Pool multiple policies" do @@ -398,11 +398,11 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "assign Resource Pool policy profile with invalid guid" do - test_policy_assign_invalid_policy_guid(rp_url, rp_policy_profiles_url, :resource_pools, :policy_profiles) + test_policy_assign_invalid_policy_guid(resource_pools_url(rp.compressed_id), rp_policy_profiles_url, :resource_pools, :policy_profiles) end it "assign Resource Pool multiple policy profiles" do - test_assign_multiple_policies(rp_url, + test_assign_multiple_policies(resource_pools_url(rp.compressed_id), rp_policy_profiles_url, :resource_pools, :policy_profiles, @@ -419,7 +419,7 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "unassign Resource Pool policy profile with invalid guid" do - test_policy_unassign_invalid_policy_guid(rp_url, + test_policy_unassign_invalid_policy_guid(resource_pools_url(rp.compressed_id), rp_policy_profiles_url, :resource_pools, :policy_profiles) @@ -447,11 +447,11 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "assign Cluster policy with invalid guid" do - test_policy_assign_invalid_policy_guid(cluster_url, cluster_policies_url, :clusters, :policies) + test_policy_assign_invalid_policy_guid(clusters_url(cluster.compressed_id), cluster_policies_url, :clusters, :policies) end it "assign Cluster multiple policies" do - test_assign_multiple_policies(cluster_url, + test_assign_multiple_policies(clusters_url(cluster.compressed_id), cluster_policies_url, :clusters, :policies, @@ -468,7 +468,7 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "unassign Cluster policy with invalid guid" do - test_policy_unassign_invalid_policy_guid(cluster_url, cluster_policies_url, :clusters, :policies) + test_policy_unassign_invalid_policy_guid(clusters_url(cluster.compressed_id), cluster_policies_url, :clusters, :policies) end it "unassign Cluster multiple policies" do @@ -490,11 +490,11 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "assign Cluster policy profile with invalid guid" do - test_policy_assign_invalid_policy_guid(cluster_url, cluster_policy_profiles_url, :clusters, :policy_profiles) + test_policy_assign_invalid_policy_guid(clusters_url(cluster.compressed_id), cluster_policy_profiles_url, :clusters, :policy_profiles) end it "assign Cluster multiple policy profiles" do - test_assign_multiple_policies(cluster_url, + test_assign_multiple_policies(clusters_url(cluster.compressed_id), cluster_policy_profiles_url, :clusters, :policy_profiles, @@ -511,7 +511,7 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "unassign Cluster policy profile with invalid guid" do - test_policy_unassign_invalid_policy_guid(cluster_url, + test_policy_unassign_invalid_policy_guid(clusters_url(cluster.compressed_id), cluster_policy_profiles_url, :clusters, :policy_profiles) @@ -539,11 +539,11 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "assign Vm policy with invalid guid" do - test_policy_assign_invalid_policy_guid(vm_url, vm_policies_url, :vms, :policies) + test_policy_assign_invalid_policy_guid(vms_url(vm.compressed_id), vm_policies_url, :vms, :policies) end it "assign Vm multiple policies" do - test_assign_multiple_policies(vm_url, + test_assign_multiple_policies(vms_url(vm.compressed_id), vm_policies_url, :vms, :policies, @@ -560,7 +560,7 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "unassign Vm policy with invalid guid" do - test_policy_unassign_invalid_policy_guid(vm_url, vm_policies_url, :vms, :policies) + test_policy_unassign_invalid_policy_guid(vms_url(vm.compressed_id), vm_policies_url, :vms, :policies) end it "unassign Vm multiple policies" do @@ -582,11 +582,11 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "assign Vm policy profile with invalid guid" do - test_policy_assign_invalid_policy_guid(vm_url, vm_policy_profiles_url, :vms, :policy_profiles) + test_policy_assign_invalid_policy_guid(vms_url(vm.compressed_id), vm_policy_profiles_url, :vms, :policy_profiles) end it "assign Vm multiple policy profiles" do - test_assign_multiple_policies(vm_url, + test_assign_multiple_policies(vms_url(vm.compressed_id), vm_policy_profiles_url, :vms, :policy_profiles, @@ -603,7 +603,7 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "unassign Vm policy profile with invalid guid" do - test_policy_unassign_invalid_policy_guid(vm_url, + test_policy_unassign_invalid_policy_guid(vms_url(vm.compressed_id), vm_policy_profiles_url, :vms, :policy_profiles) @@ -631,11 +631,11 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "assign Template policy with invalid guid" do - test_policy_assign_invalid_policy_guid(template_url, template_policies_url, :templates, :policies) + test_policy_assign_invalid_policy_guid(templates_url(template.compressed_id), template_policies_url, :templates, :policies) end it "assign Template multiple policies" do - test_assign_multiple_policies(template_url, + test_assign_multiple_policies(templates_url(template.compressed_id), template_policies_url, :templates, :policies, @@ -652,7 +652,7 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "unassign Template policy with invalid guid" do - test_policy_unassign_invalid_policy_guid(template_url, template_policies_url, :templates, :policies) + test_policy_unassign_invalid_policy_guid(templates_url(template.compressed_id), template_policies_url, :templates, :policies) end it "unassign Template multiple policies" do @@ -674,11 +674,11 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "assign Template policy profile with invalid guid" do - test_policy_assign_invalid_policy_guid(template_url, template_policy_profiles_url, :templates, :policy_profiles) + test_policy_assign_invalid_policy_guid(templates_url(template.compressed_id), template_policy_profiles_url, :templates, :policy_profiles) end it "assign Template multiple policy profiles" do - test_assign_multiple_policies(template_url, + test_assign_multiple_policies(templates_url(template.compressed_id), template_policy_profiles_url, :templates, :policy_profiles, @@ -695,7 +695,7 @@ def test_unassign_multiple_policy_profiles(object_policies_url, collection, subc end it "unassign Template policy profile with invalid guid" do - test_policy_unassign_invalid_policy_guid(template_url, + test_policy_unassign_invalid_policy_guid(templates_url(template.compressed_id), template_policy_profiles_url, :templates, :policy_profiles) diff --git a/spec/requests/api/policies_spec.rb b/spec/requests/api/policies_spec.rb index 18482835d65..300534a090f 100644 --- a/spec/requests/api/policies_spec.rb +++ b/spec/requests/api/policies_spec.rb @@ -113,8 +113,10 @@ def test_policy_profile_query(object, object_policy_profiles_url) run_get policies_url expect_query_result(:policies, 3, 3) - expect_result_resources_to_include_hrefs("resources", - [policies_url(p1.id), policies_url(p2.id), policies_url(p3.id)]) + expect_result_resources_to_include_hrefs( + "resources", + [policies_url(p1.compressed_id), policies_url(p2.compressed_id), policies_url(p3.compressed_id)] + ) end it "query policies in expanded form" do @@ -145,8 +147,10 @@ def test_policy_profile_query(object, object_policy_profiles_url) run_get policy_profiles_url expect_query_result(:policy_profiles, 2, 2) - expect_result_resources_to_include_hrefs("resources", - [policy_profiles_url(ps1.id), policy_profiles_url(ps2.id)]) + expect_result_resources_to_include_hrefs( + "resources", + [policy_profiles_url(ps1.compressed_id), policy_profiles_url(ps2.compressed_id)] + ) end it "query individual Policy Profile" do diff --git a/spec/requests/api/policy_actions_spec.rb b/spec/requests/api/policy_actions_spec.rb index d8931c5c03b..79e090506ae 100644 --- a/spec/requests/api/policy_actions_spec.rb +++ b/spec/requests/api/policy_actions_spec.rb @@ -40,8 +40,10 @@ def create_actions(count) run_get policy_actions_url expect_query_result(:policy_actions, 4, 4) - expect_result_resources_to_include_hrefs("resources", - MiqAction.pluck(:id).collect { |id| /^.*#{policy_actions_url(id)}$/ }) + expect_result_resources_to_include_hrefs( + "resources", + MiqAction.select(:id).collect { |ma| /^.*#{policy_actions_url(ma.compressed_id)}$/ } + ) end it "query policy actions in expanded form" do diff --git a/spec/requests/api/providers_spec.rb b/spec/requests/api/providers_spec.rb index f4b9725070f..f34b15757c0 100644 --- a/spec/requests/api/providers_spec.rb +++ b/spec/requests/api/providers_spec.rb @@ -210,7 +210,9 @@ def define_user expect_query_result(:custom_attributes, 2) - expect_result_resources_to_include_hrefs("resources", provider_ca_url_list) + expect_result_resources_to_include_hrefs("resources", + ["#{providers_url(provider.compressed_id)}/custom_attributes/#{ca1.compressed_id}", + "#{providers_url(provider.compressed_id)}/custom_attributes/#{ca2.compressed_id}"]) end it "getting custom_attributes from a provider in expanded form" do @@ -372,7 +374,9 @@ def define_user run_get providers_url, :provider_class => 'provider' expected = { - 'resources' => [{'href' => a_string_including("/api/providers/#{provider.id}?provider_class=provider")}], + 'resources' => [ + {'href' => a_string_including("/api/providers/#{provider.compressed_id}?provider_class=provider")} + ], 'actions' => [a_hash_including('href' => a_string_including('?provider_class=provider'))] } expect(response).to have_http_status(:ok) @@ -387,9 +391,9 @@ def define_user run_get providers_url(provider.id), :provider_class => :provider expected = { - 'href' => a_string_including("/api/providers/#{provider.id}?provider_class=provider"), + 'href' => a_string_including("/api/providers/#{provider.compressed_id}?provider_class=provider"), 'actions' => [ - a_hash_including('href' => a_string_including("/api/providers/#{provider.id}?provider_class=provider")) + a_hash_including('href' => a_string_including("/api/providers/#{provider.compressed_id}?provider_class=provider")) ] } expect(response).to have_http_status(:ok) @@ -760,7 +764,7 @@ def token(connection) expect_single_action_result(:success => true, :message => "deleting", - :href => providers_url(provider.id), + :href => providers_url(provider.compressed_id), :task => true) end @@ -775,7 +779,7 @@ def token(connection) {"href" => providers_url(p2.id)}])) expect_multiple_action_result(2, :task => true) - expect_result_resources_to_include_hrefs("results", [providers_url(p1.id), providers_url(p2.id)]) + expect_result_resources_to_include_hrefs("results", [providers_url(p1.compressed_id), providers_url(p2.compressed_id)]) end end @@ -800,7 +804,7 @@ def failed_auth_action(id) run_post(providers_url(provider.id), gen_request(:refresh)) - expect_single_action_result(failed_auth_action(provider.id).symbolize_keys) + expect_single_action_result(failed_auth_action(provider.compressed_id).symbolize_keys) end it "supports multiple provider refreshes" do @@ -815,7 +819,7 @@ def failed_auth_action(id) run_post(providers_url, gen_request(:refresh, [{"href" => providers_url(p1.id)}, {"href" => providers_url(p2.id)}])) expect(response).to have_http_status(:ok) - expect_results_to_match_hash("results", [failed_auth_action(p1.id), failed_auth_action(p2.id)]) + expect_results_to_match_hash("results", [failed_auth_action(p1.compressed_id), failed_auth_action(p2.compressed_id)]) end it "provider refresh are created with a task" do @@ -829,7 +833,7 @@ def failed_auth_action(id) expect_single_action_result(:success => true, :message => a_string_matching("Provider .* refreshing"), - :href => providers_url(provider.id), + :href => providers_url(provider.compressed_id), :task => true) end @@ -844,7 +848,7 @@ def failed_auth_action(id) expect_single_action_result(:success => true, :message => a_string_matching("Provider .* refreshing"), - :href => providers_url(provider.id), + :href => providers_url(provider.compressed_id), :task => true) end @@ -860,7 +864,7 @@ def failed_auth_action(id) expected = { "success" => true, "message" => a_string_matching("Provider .* refreshing"), - "href" => a_string_matching(providers_url(provider.id)), + "href" => a_string_matching(providers_url(provider.compressed_id)), "task_id" => a_kind_of(String), "task_href" => a_string_matching(tasks_url), "tasks" => [a_hash_including("id" => a_kind_of(String), "href" => a_string_matching(tasks_url)), @@ -958,7 +962,9 @@ def gen_import_request api_basic_authorize subcollection_action_identifier(:providers, :load_balancers, :read, :get) expected = { 'resources' => [ - { 'href' => a_string_matching("#{providers_url(@provider.id)}/load_balancers/#{@load_balancer.id}") } + { + 'href' => a_string_matching("#{providers_url(@provider.compressed_id)}/load_balancers/#{@load_balancer.compressed_id}") + } ] } @@ -1007,7 +1013,7 @@ def gen_import_request expected = { 'resources' => [ - { 'href' => a_string_matching("#{providers_url(@provider.id)}/cloud_subnets/#{@cloud_subnet.id}") } + { 'href' => a_string_matching("#{providers_url(@provider.compressed_id)}/cloud_subnets/#{@cloud_subnet.compressed_id}") } ] } @@ -1054,7 +1060,7 @@ def gen_import_request expected = { 'resources' => [ - { 'href' => a_string_matching("#{providers_url(@provider.id)}/cloud_tenants/#{@cloud_tenant.id}") } + { 'href' => a_string_matching("#{providers_url(@provider.compressed_id)}/cloud_tenants/#{@cloud_tenant.compressed_id}") } ] } diff --git a/spec/requests/api/provision_requests_spec.rb b/spec/requests/api/provision_requests_spec.rb index 7c466f0bd2a..497017aa650 100644 --- a/spec/requests/api/provision_requests_spec.rb +++ b/spec/requests/api/provision_requests_spec.rb @@ -54,7 +54,7 @@ "count" => 2, "subcount" => 1, "resources" => a_collection_containing_exactly( - "href" => a_string_matching(provision_requests_url(provision_request2.id)), + "href" => a_string_matching(provision_requests_url(provision_request2.compressed_id)), ) } expect(response).to have_http_status(:ok) @@ -74,8 +74,8 @@ "count" => 2, "subcount" => 2, "resources" => a_collection_containing_exactly( - {"href" => a_string_matching(provision_requests_url(provision_request1.id))}, - {"href" => a_string_matching(provision_requests_url(provision_request2.id))}, + {"href" => a_string_matching(provision_requests_url(provision_request1.compressed_id))}, + {"href" => a_string_matching(provision_requests_url(provision_request2.compressed_id))}, ) } expect(response).to have_http_status(:ok) @@ -102,7 +102,7 @@ expected = { "id" => provision_request.compressed_id, - "href" => a_string_matching(provision_requests_url(provision_request.id)) + "href" => a_string_matching(provision_requests_url(provision_request.compressed_id)) } expect(response).to have_http_status(:ok) expect(response.parsed_body).to include(expected) @@ -230,7 +230,7 @@ run_post(provreq1_url, gen_request(:approve)) expected_msg = "Provision request #{provreq1.id} approved" - expect_single_action_result(:success => true, :message => expected_msg, :href => provreq1_url) + expect_single_action_result(:success => true, :message => expected_msg, :href => provision_requests_url(provreq1.compressed_id)) end it "supports denying a request" do @@ -239,7 +239,7 @@ run_post(provreq2_url, gen_request(:deny)) expected_msg = "Provision request #{provreq2.id} denied" - expect_single_action_result(:success => true, :message => expected_msg, :href => provreq2_url) + expect_single_action_result(:success => true, :message => expected_msg, :href => provision_requests_url(provreq2.compressed_id)) end it "supports approving multiple requests" do @@ -252,12 +252,12 @@ { "message" => a_string_matching(/Provision request #{provreq1.id} approved/i), "success" => true, - "href" => a_string_matching(provreq1_url) + "href" => a_string_matching(provision_requests_url(provreq1.compressed_id)) }, { "message" => a_string_matching(/Provision request #{provreq2.id} approved/i), "success" => true, - "href" => a_string_matching(provreq2_url) + "href" => a_string_matching(provision_requests_url(provreq2.compressed_id)) } ) } @@ -275,12 +275,12 @@ { "message" => a_string_matching(/Provision request #{provreq1.id} denied/i), "success" => true, - "href" => a_string_matching(provreq1_url) + "href" => a_string_matching(provision_requests_url(provreq1.compressed_id)) }, { "message" => a_string_matching(/Provision request #{provreq2.id} denied/i), "success" => true, - "href" => a_string_matching(provreq2_url) + "href" => a_string_matching(provision_requests_url(provreq2.compressed_id)) } ) } diff --git a/spec/requests/api/queries_spec.rb b/spec/requests/api/queries_spec.rb index 0ac41e62800..05611fc7c39 100644 --- a/spec/requests/api/queries_spec.rb +++ b/spec/requests/api/queries_spec.rb @@ -9,7 +9,7 @@ let(:vm1) { FactoryGirl.create(:vm_vmware, :host => host, :ems_id => ems.id, :raw_power_state => "poweredOn") } let(:vm1_url) { vms_url(vm1.id) } - let(:vm_href_pattern) { %r{^http://.*/api/vms/[0-9]+$} } + let(:vm_href_pattern) { %r{^http://.*/api/vms/[0-9r]+$} } def create_vms(count) count.times { FactoryGirl.create(:vm_vmware) } @@ -48,7 +48,7 @@ def create_vms(count) run_get vms_url, :expand => "resources", :attributes => "guid" expect_query_result(:vms, 1, 1) - expect_result_resources_to_match_hash([{"id" => vm1.compressed_id, "href" => vm1_url, "guid" => vm1.guid}]) + expect_result_resources_to_match_hash([{"id" => vm1.compressed_id, "href" => vms_url(vm1.compressed_id), "guid" => vm1.guid}]) end end @@ -59,7 +59,7 @@ def create_vms(count) run_get vm1_url - expect_single_resource_query("id" => vm1.compressed_id, "href" => vm1_url, "guid" => vm1.guid) + expect_single_resource_query("id" => vm1.compressed_id, "href" => vms_url(vm1.compressed_id), "guid" => vm1.guid) end it 'supports compressed ids' do @@ -67,7 +67,7 @@ def create_vms(count) run_get vms_url(ApplicationRecord.compress_id(vm1.id)) - expect_single_resource_query("id" => vm1.compressed_id, "href" => vm1_url, "guid" => vm1.guid) + expect_single_resource_query("id" => vm1.compressed_id, "href" => vms_url(vm1.compressed_id), "guid" => vm1.guid) end it 'returns 404 on url with trailing garbage' do @@ -97,7 +97,9 @@ def create_vms(count) run_get vm1_accounts_url expect_query_result(:accounts, 2) - expect_result_resources_to_include_hrefs("resources", vm1_accounts_url_list) + expect_result_resources_to_include_hrefs("resources", + ["#{vms_url(vm1.compressed_id)}/accounts/#{acct1.compressed_id}", + "#{vms_url(vm1.compressed_id)}/accounts/#{acct2.compressed_id}"]) end it "includes both id and href when getting a single resource" do @@ -105,7 +107,11 @@ def create_vms(count) run_get acct1_url - expect_single_resource_query("id" => acct1.compressed_id, "href" => acct1_url, "name" => acct1.name) + expect_single_resource_query( + "id" => acct1.compressed_id, + "href" => "#{vms_url(vm1.compressed_id)}/accounts/#{acct1.compressed_id}", + "name" => acct1.name + ) end it "includes both id and href when expanded" do @@ -118,7 +124,9 @@ def create_vms(count) expect_query_result(:accounts, 2) expect_result_resources_to_include_keys("resources", %w(id href)) - expect_result_resources_to_include_hrefs("resources", vm1_accounts_url_list) + expect_result_resources_to_include_hrefs("resources", + ["#{vms_url(vm1.compressed_id)}/accounts/#{acct1.compressed_id}", + "#{vms_url(vm1.compressed_id)}/accounts/#{acct2.compressed_id}"]) expect_result_resources_to_include_data("resources", "id" => [acct1.compressed_id, acct2.compressed_id]) end @@ -127,7 +135,7 @@ def create_vms(count) run_get vms_url(ApplicationRecord.compress_id(vm1.id)) + "/accounts/#{acct1.id}" - expect_single_resource_query("id" => acct1.compressed_id, "href" => acct1_url, "name" => acct1.name) + expect_single_resource_query("id" => acct1.compressed_id, "href" => vms_url(vm1.compressed_id) + "/accounts/#{acct1.compressed_id}", "name" => acct1.name) end it 'returns 404 on url with trailing garbage' do diff --git a/spec/requests/api/querying_spec.rb b/spec/requests/api/querying_spec.rb index 12d38a16e10..4999680ac2a 100644 --- a/spec/requests/api/querying_spec.rb +++ b/spec/requests/api/querying_spec.rb @@ -486,7 +486,7 @@ def create_vms_by_name(names) run_get(vms_url, :filter => ["retires_on = 2016-01-02", "vendor_display = VMware"]) - expected = {"resources" => [{"href" => a_string_matching(vms_url(vm_2.id))}]} + expected = {"resources" => [{"href" => a_string_matching(vms_url(vm_2.compressed_id))}]} expect(response.parsed_body).to include(expected) expect(response).to have_http_status(:ok) end @@ -498,7 +498,7 @@ def create_vms_by_name(names) run_get(vms_url, :filter => ["retires_on > 2016-01-01", "vendor_display = VMware"]) - expected = {"resources" => [{"href" => a_string_matching(vms_url(vm_2.id))}]} + expected = {"resources" => [{"href" => a_string_matching(vms_url(vm_2.compressed_id))}]} expect(response.parsed_body).to include(expected) expect(response).to have_http_status(:ok) end @@ -510,7 +510,7 @@ def create_vms_by_name(names) run_get(vms_url, :filter => ["last_scan_on > 2016-01-01T07:59:59Z", "vendor_display = VMware"]) - expected = {"resources" => [{"href" => a_string_matching(vms_url(vm_2.id))}]} + expected = {"resources" => [{"href" => a_string_matching(vms_url(vm_2.compressed_id))}]} expect(response.parsed_body).to include(expected) expect(response).to have_http_status(:ok) end @@ -522,7 +522,7 @@ def create_vms_by_name(names) run_get(vms_url, :filter => ["retires_on < 2016-01-03", "vendor_display = VMware"]) - expected = {"resources" => [{"href" => a_string_matching(vms_url(vm_2.id))}]} + expected = {"resources" => [{"href" => a_string_matching(vms_url(vm_2.compressed_id))}]} expect(response.parsed_body).to include(expected) expect(response).to have_http_status(:ok) end @@ -534,7 +534,7 @@ def create_vms_by_name(names) run_get(vms_url, :filter => ["last_scan_on < 2016-01-01T08:00:00Z", "vendor_display = VMware"]) - expected = {"resources" => [{"href" => a_string_matching(vms_url(vm_2.id))}]} + expected = {"resources" => [{"href" => a_string_matching(vms_url(vm_2.compressed_id))}]} expect(response.parsed_body).to include(expected) expect(response).to have_http_status(:ok) end @@ -588,7 +588,7 @@ def create_vms_by_name(names) expected = { "count" => 2, "subcount" => 1, - "resources" => [{"href" => a_string_matching(tags_url(tag_1.id))}] + "resources" => [{"href" => a_string_matching(tags_url(tag_1.compressed_id))}] } expect(response.parsed_body).to include(expected) expect(response).to have_http_status(:ok) @@ -664,8 +664,8 @@ def create_vms_by_name(names) "resources" => [ { "id" => vm.compressed_id, - "href" => a_string_matching(vms_url(vm.id)), - "href_slug" => "vms/#{vm.id}", + "href" => a_string_matching(vms_url(vm.compressed_id)), + "href_slug" => "vms/#{vm.compressed_id}", "name" => "aa", "vendor" => anything } diff --git a/spec/requests/api/regions_spec.rb b/spec/requests/api/regions_spec.rb index 56010867122..53e8d80bad5 100644 --- a/spec/requests/api/regions_spec.rb +++ b/spec/requests/api/regions_spec.rb @@ -36,7 +36,7 @@ expect(response).to have_http_status(:ok) expect(response.parsed_body).to include( - "href" => a_string_matching(regions_url(region.id)), + "href" => a_string_matching(regions_url(region.compressed_id)), "id" => region.compressed_id ) end diff --git a/spec/requests/api/reports_spec.rb b/spec/requests/api/reports_spec.rb index f27d6a7271c..b1890e20b16 100644 --- a/spec/requests/api/reports_spec.rb +++ b/spec/requests/api/reports_spec.rb @@ -9,8 +9,8 @@ expect_result_resources_to_include_hrefs( "resources", [ - reports_url(report_1.id), - reports_url(report_2.id) + reports_url(report_1.compressed_id), + reports_url(report_2.compressed_id) ] ) expect_result_to_match_hash(response.parsed_body, "count" => 2, "name" => "reports") @@ -35,7 +35,7 @@ expect_result_to_match_hash( response.parsed_body, - "href" => reports_url(report.id), + "href" => reports_url(report.compressed_id), "id" => report.compressed_id, "name" => report.name, "title" => report.title @@ -60,7 +60,7 @@ expect_result_resources_to_include_hrefs( "resources", [ - "#{reports_url(report.id)}/results/#{report_result.to_param}" + "#{reports_url(report.compressed_id)}/results/#{report_result.compressed_id}" ] ) expect(response.parsed_body["resources"]).not_to be_any { |resource| resource.key?("result_set") } @@ -92,7 +92,7 @@ expect_result_resources_to_include_hrefs( "resources", [ - results_url(result.id).to_s + results_url(result.compressed_id).to_s ] ) expect(response).to have_http_status(:ok) @@ -152,8 +152,8 @@ expect_result_resources_to_include_hrefs( "resources", [ - "/api/reports/#{report.id}/schedules/#{schedule_1.id}", - "/api/reports/#{report.id}/schedules/#{schedule_2.id}", + "/api/reports/#{report.compressed_id}/schedules/#{schedule_1.compressed_id}", + "/api/reports/#{report.compressed_id}/schedules/#{schedule_2.compressed_id}", ] ) expect(response).to have_http_status(:ok) @@ -184,7 +184,7 @@ expect_result_to_match_hash( response.parsed_body, - "href" => "/api/reports/#{report.id}/schedules/#{schedule.id}", + "href" => "/api/reports/#{report.compressed_id}/schedules/#{schedule.compressed_id}", "id" => schedule.compressed_id, "name" => 'unit_test' ) @@ -211,7 +211,7 @@ run_post reports_url(report.id).to_s, :action => "run" end.to change(MiqReportResult, :count).by(1) expect_single_action_result( - :href => reports_url(report.id), + :href => reports_url(report.compressed_id), :success => true, :message => "running report #{report.id}" ) @@ -232,7 +232,7 @@ :time_zone => 'UTC' end.to change(MiqSchedule, :count).by(1) expect_single_action_result( - :href => reports_url(report.id), + :href => reports_url(report.compressed_id), :success => true, :message => "scheduling of report #{report.id}" ) diff --git a/spec/requests/api/requests_spec.rb b/spec/requests/api/requests_spec.rb index 42d8045e541..48b1b85281f 100644 --- a/spec/requests/api/requests_spec.rb +++ b/spec/requests/api/requests_spec.rb @@ -67,7 +67,7 @@ expect(response).to have_http_status(:ok) expect(response.parsed_body).to include("id" => service_request.compressed_id, - "href" => a_string_matching(requests_url(service_request.id))) + "href" => a_string_matching(requests_url(service_request.compressed_id))) end it "lists all the service requests if you are admin" do @@ -89,8 +89,8 @@ "count" => 2, "subcount" => 2, "resources" => a_collection_containing_exactly( - {"href" => a_string_matching(requests_url(service_request_1.id))}, - {"href" => a_string_matching(requests_url(service_request_2.id))}, + {"href" => a_string_matching(requests_url(service_request_1.compressed_id))}, + {"href" => a_string_matching(requests_url(service_request_2.compressed_id))}, ) } expect(response).to have_http_status(:ok) @@ -110,7 +110,7 @@ expected = { "id" => service_request.compressed_id, - "href" => a_string_matching(requests_url(service_request.id)) + "href" => a_string_matching(requests_url(service_request.compressed_id)) } expect(response).to have_http_status(:ok) expect(response.parsed_body).to include(expected) @@ -378,7 +378,7 @@ run_post(request1_url, gen_request(:approve, :reason => "approval reason")) expected_msg = "Request #{request1.id} approved" - expect_single_action_result(:success => true, :message => expected_msg, :href => request1_url) + expect_single_action_result(:success => true, :message => expected_msg, :href => requests_url(request1.compressed_id)) end it "fails approving a request if the reason is missing" do @@ -396,7 +396,7 @@ run_post(request1_url, gen_request(:deny, :reason => "denial reason")) expected_msg = "Request #{request1.id} denied" - expect_single_action_result(:success => true, :message => expected_msg, :href => request1_url) + expect_single_action_result(:success => true, :message => expected_msg, :href => requests_url(request1.compressed_id)) end it "fails denying a request if the reason is missing" do @@ -419,12 +419,12 @@ { "message" => a_string_matching(/Request #{request1.id} approved/i), "success" => true, - "href" => a_string_matching(request1_url) + "href" => a_string_matching(requests_url(request1.compressed_id)) }, { "message" => a_string_matching(/Request #{request2.id} approved/i), "success" => true, - "href" => a_string_matching(request2_url) + "href" => a_string_matching(requests_url(request2.compressed_id)) } ) } @@ -443,12 +443,12 @@ { "message" => a_string_matching(/Request #{request1.id} denied/i), "success" => true, - "href" => a_string_matching(request1_url) + "href" => a_string_matching(requests_url(request1.compressed_id)) }, { "message" => a_string_matching(/Request #{request2.id} denied/i), "success" => true, - "href" => a_string_matching(request2_url) + "href" => a_string_matching(requests_url(request2.compressed_id)) } ) } @@ -466,8 +466,8 @@ run_get requests_url, :expand => :resources expected = [ - a_hash_including('href' => a_string_including(requests_url(provision_request.id))), - a_hash_including('href' => a_string_including(requests_url(automation_request.id))) + a_hash_including('href' => a_string_including(requests_url(provision_request.compressed_id))), + a_hash_including('href' => a_string_including(requests_url(automation_request.compressed_id))) ] expect(response).to have_http_status(:ok) expect(response.parsed_body['resources']).to match_array(expected) diff --git a/spec/requests/api/roles_spec.rb b/spec/requests/api/roles_spec.rb index 5b477b63362..dbef9e3e0a0 100644 --- a/spec/requests/api/roles_spec.rb +++ b/spec/requests/api/roles_spec.rb @@ -170,7 +170,7 @@ def test_features_query(role, role_url, klass, attr = :id) it "rejects role edits without appropriate role" do role = FactoryGirl.create(:miq_user_role) api_basic_authorize - run_post(roles_url, gen_request(:edit, "name" => "role name", "href" => roles_url(role.id))) + run_post(roles_url, gen_request(:edit, "name" => "role name", "href" => roles_url(role.compressed_id))) expect(response).to have_http_status(:forbidden) end diff --git a/spec/requests/api/service_catalogs_spec.rb b/spec/requests/api/service_catalogs_spec.rb index 15cb5e25e4a..a67ba883def 100644 --- a/spec/requests/api/service_catalogs_spec.rb +++ b/spec/requests/api/service_catalogs_spec.rb @@ -253,7 +253,7 @@ def sc_templates_url(id, st_id = nil) run_post(service_catalogs_url(sc.id), gen_request(:delete)) - expect_single_action_result(:success => true, :message => "deleting", :href => service_catalogs_url(sc.id)) + expect_single_action_result(:success => true, :message => "deleting", :href => service_catalogs_url(sc.compressed_id)) expect { sc.reload }.to raise_error(ActiveRecord::RecordNotFound) end @@ -267,7 +267,7 @@ def sc_templates_url(id, st_id = nil) [{"href" => service_catalogs_url(sc1.id)}, {"href" => service_catalogs_url(sc2.id)}])) expect_multiple_action_result(2) - expect_result_resources_to_include_hrefs("results", [service_catalogs_url(sc1.id), service_catalogs_url(sc2.id)]) + expect_result_resources_to_include_hrefs("results", [service_catalogs_url(sc1.compressed_id), service_catalogs_url(sc2.compressed_id)]) expect { sc1.reload }.to raise_error(ActiveRecord::RecordNotFound) expect { sc2.reload }.to raise_error(ActiveRecord::RecordNotFound) @@ -299,7 +299,7 @@ def sc_templates_url(id, st_id = nil) run_post(sc_templates_url(sc.id), gen_request(:assign, "href" => service_templates_url(999_999))) expect(response).to have_http_status(:ok) - expect_results_to_match_hash("results", [{"success" => false, "href" => service_catalogs_url(sc.id)}]) + expect_results_to_match_hash("results", [{"success" => false, "href" => service_catalogs_url(sc.compressed_id)}]) end it "supports assign requests" do @@ -308,14 +308,15 @@ def sc_templates_url(id, st_id = nil) sc = FactoryGirl.create(:service_template_catalog, :name => "sc", :description => "sc description") st = FactoryGirl.create(:service_template) - run_post(sc_templates_url(sc.id), gen_request(:assign, "href" => service_templates_url(st.id))) + run_post(sc_templates_url(sc.id), gen_request(:assign, "href" => service_templates_url(st.compressed_id))) expect(response).to have_http_status(:ok) - expect_results_to_match_hash("results", [{"success" => true, - "href" => service_catalogs_url(sc.id), - "service_template_id" => st.compressed_id, - "service_template_href" => /^.*#{service_templates_url(st.id)}$/, - "message" => /assigning/i}]) + expect_results_to_match_hash("results", + [{"success" => true, + "href" => service_catalogs_url(sc.compressed_id), + "service_template_id" => st.compressed_id, + "service_template_href" => /^.*#{service_templates_url(st.compressed_id)}$/, + "message" => /assigning/i}]) expect(sc.reload.service_templates.pluck(:id)).to eq([st.id]) end @@ -330,11 +331,12 @@ def sc_templates_url(id, st_id = nil) run_post(sc_templates_url(sc.id), gen_request(:unassign, "href" => service_templates_url(st1.id))) expect(response).to have_http_status(:ok) - expect_results_to_match_hash("results", [{"success" => true, - "href" => service_catalogs_url(sc.id), - "service_template_id" => st1.compressed_id, - "service_template_href" => /^.*#{service_templates_url(st1.id)}$/, - "message" => /unassigning/i}]) + expect_results_to_match_hash("results", + [{"success" => true, + "href" => service_catalogs_url(sc.compressed_id), + "service_template_id" => st1.compressed_id, + "service_template_href" => /^.*#{service_templates_url(st1.compressed_id)}$/, + "message" => /unassigning/i}]) expect(sc.reload.service_templates.pluck(:id)).to eq([st2.id]) end end diff --git a/spec/requests/api/service_dialogs_spec.rb b/spec/requests/api/service_dialogs_spec.rb index ce403c4605a..986b38b9907 100644 --- a/spec/requests/api/service_dialogs_spec.rb +++ b/spec/requests/api/service_dialogs_spec.rb @@ -44,7 +44,7 @@ expect_single_resource_query( "id" => dialog1.compressed_id, - "href" => service_dialogs_url(dialog1.id), + "href" => service_dialogs_url(dialog1.compressed_id), "label" => dialog1.label ) expect_result_to_have_keys(%w(content)) @@ -137,7 +137,7 @@ } expected = { - 'href' => a_string_including(service_dialogs_url(dialog.id)), + 'href' => a_string_including(service_dialogs_url(dialog.compressed_id)), 'id' => dialog.compressed_id, 'label' => 'updated label' } @@ -326,7 +326,7 @@ def init_dialog expect(response.parsed_body).to include( "success" => true, "message" => a_string_matching(/refreshing dialog fields/i), - "href" => a_string_matching(service_dialogs_url(dialog1.id)), + "href" => a_string_matching(service_dialogs_url(dialog1.compressed_id)), "result" => hash_including("text1") ) end diff --git a/spec/requests/api/service_orders_spec.rb b/spec/requests/api/service_orders_spec.rb index 9c1a364bfb4..02fc556694d 100644 --- a/spec/requests/api/service_orders_spec.rb +++ b/spec/requests/api/service_orders_spec.rb @@ -6,7 +6,7 @@ run_get service_orders_url expect(response).to have_http_status(:ok) - expect_result_resources_to_include_hrefs("resources", [service_orders_url(service_order.id)]) + expect_result_resources_to_include_hrefs("resources", [service_orders_url(service_order.compressed_id)]) end it "won't show another user's service orders" do @@ -19,7 +19,7 @@ expected = { "count" => 2, "subcount" => 1, - "resources" => [{"href" => a_string_matching(service_orders_url(shopping_cart_for_user.id))}] + "resources" => [{"href" => a_string_matching(service_orders_url(shopping_cart_for_user.compressed_id))}] } expect(response).to have_http_status(:ok) expect(response.parsed_body).to include(expected) @@ -84,7 +84,7 @@ expect(response).to have_http_status(:ok) expect(response.parsed_body).to include("id" => shopping_cart.compressed_id, - "href" => a_string_matching(service_orders_url(shopping_cart.id))) + "href" => a_string_matching(service_orders_url(shopping_cart.compressed_id))) end it "returns an empty response when there is no shopping cart" do @@ -163,7 +163,7 @@ url = "#{service_orders_url("cart")}/service_requests" run_get url - expected_href = a_string_matching("#{url}/#{service_request.id}") + expected_href = a_string_matching("#{url}/#{service_request.compressed_id}") expect(response).to have_http_status(:ok) expect(response.parsed_body).to include("count" => 1, "name" => "service_requests", @@ -179,8 +179,12 @@ url = "#{service_orders_url("cart")}/service_requests/#{service_request.id}" run_get url + expected = { + "id" => service_request.compressed_id, + "href" => a_string_matching("#{service_orders_url("cart")}/service_requests/#{service_request.compressed_id}") + } expect(response).to have_http_status(:ok) - expect(response.parsed_body).to include("id" => service_request.compressed_id, "href" => a_string_matching(url)) + expect(response.parsed_body).to include(expected) end it "can add a service request to a shopping cart" do @@ -205,7 +209,7 @@ "success" => true, "message" => /Adding service_request/, "service_request_id" => actual_requests.first.compressed_id, - "service_request_href" => a_string_matching(service_requests_url(actual_requests.first.id)) + "service_request_href" => a_string_matching(service_requests_url(actual_requests.first.compressed_id)) ) ] } @@ -245,13 +249,13 @@ "success" => true, "message" => /Adding service_request/, "service_request_id" => actual_requests.first.compressed_id, - "service_request_href" => a_string_matching(service_requests_url(actual_requests.first.id)) + "service_request_href" => a_string_matching(service_requests_url(actual_requests.first.compressed_id)) ), a_hash_including( "success" => true, "message" => /Adding service_request/, "service_request_id" => actual_requests.second.compressed_id, - "service_request_href" => a_string_matching(service_requests_url(actual_requests.second.id)) + "service_request_href" => a_string_matching(service_requests_url(actual_requests.second.compressed_id)) ) ) } @@ -269,7 +273,7 @@ expected = { "success" => true, "message" => a_string_starting_with("Removing Service Request id:#{service_request.id}"), - "service_request_href" => a_string_matching(service_requests_url(service_request.id)), + "service_request_href" => a_string_matching(service_requests_url(service_request.compressed_id)), "service_request_id" => service_request.compressed_id } expect(response).to have_http_status(:ok) @@ -300,13 +304,13 @@ a_hash_including( "success" => true, "message" => a_string_starting_with("Removing Service Request id:#{service_request_1.id}"), - "service_request_href" => a_string_matching(service_requests_url(service_request_1.id)), + "service_request_href" => a_string_matching(service_requests_url(service_request_1.compressed_id)), "service_request_id" => service_request_1.compressed_id ), a_hash_including( "success" => true, "message" => a_string_starting_with("Removing Service Request id:#{service_request_2.id}"), - "service_request_href" => a_string_matching(service_requests_url(service_request_2.id)), + "service_request_href" => a_string_matching(service_requests_url(service_request_2.compressed_id)), "service_request_id" => service_request_2.compressed_id ) ) @@ -339,13 +343,13 @@ a_hash_including( "success" => true, "message" => a_string_starting_with("Removing Service Request id:#{service_request_1.id}"), - "service_request_href" => a_string_matching(service_requests_url(service_request_1.id)), + "service_request_href" => a_string_matching(service_requests_url(service_request_1.compressed_id)), "service_request_id" => service_request_1.compressed_id ), a_hash_including( "success" => true, "message" => a_string_starting_with("Removing Service Request id:#{service_request_2.id}"), - "service_request_href" => a_string_matching(service_requests_url(service_request_2.id)), + "service_request_href" => a_string_matching(service_requests_url(service_request_2.compressed_id)), "service_request_id" => service_request_2.compressed_id ) ) @@ -367,7 +371,7 @@ run_post service_orders_url("cart"), :action => :clear expected = { - "href" => a_string_matching(service_orders_url(shopping_cart.id)), + "href" => a_string_matching(service_orders_url(shopping_cart.compressed_id)), "id" => shopping_cart.compressed_id } expect(response).to have_http_status(:ok) diff --git a/spec/requests/api/service_requests_spec.rb b/spec/requests/api/service_requests_spec.rb index 2e6619bfca2..07af3ff97a7 100644 --- a/spec/requests/api/service_requests_spec.rb +++ b/spec/requests/api/service_requests_spec.rb @@ -102,7 +102,7 @@ def expect_result_to_have_user_email(email) run_post(svcreq1_url, gen_request(:approve, :reason => "approve reason")) expected_msg = "Service request #{svcreq1.id} approved" - expect_single_action_result(:success => true, :message => expected_msg, :href => svcreq1_url) + expect_single_action_result(:success => true, :message => expected_msg, :href => service_requests_url(svcreq1.compressed_id)) end it "supports denying a request" do @@ -111,7 +111,7 @@ def expect_result_to_have_user_email(email) run_post(svcreq2_url, gen_request(:deny, :reason => "deny reason")) expected_msg = "Service request #{svcreq2.id} denied" - expect_single_action_result(:success => true, :message => expected_msg, :href => svcreq2_url) + expect_single_action_result(:success => true, :message => expected_msg, :href => service_requests_url(svcreq2.compressed_id)) end it "supports approving multiple requests" do @@ -125,12 +125,12 @@ def expect_result_to_have_user_email(email) { "message" => a_string_matching(/Service request #{svcreq1.id} approved/i), "success" => true, - "href" => a_string_matching(svcreq1_url) + "href" => a_string_matching(service_requests_url(svcreq1.compressed_id)) }, { "message" => a_string_matching(/Service request #{svcreq2.id} approved/i), "success" => true, - "href" => a_string_matching(svcreq2_url) + "href" => a_string_matching(service_requests_url(svcreq2.compressed_id)) } ) } @@ -149,12 +149,12 @@ def expect_result_to_have_user_email(email) { "message" => a_string_matching(/Service request #{svcreq1.id} denied/i), "success" => true, - "href" => a_string_matching(svcreq1_url) + "href" => a_string_matching(service_requests_url(svcreq1.compressed_id)) }, { "message" => a_string_matching(/Service request #{svcreq2.id} denied/i), "success" => true, - "href" => a_string_matching(svcreq2_url) + "href" => a_string_matching(service_requests_url(svcreq2.compressed_id)) } ) } @@ -229,7 +229,7 @@ def expect_result_to_have_user_email(email) expect(response).to have_http_status(:ok) expect(response.parsed_body).to include("id" => service_request.compressed_id, - "href" => a_string_matching(service_requests_url(service_request.id))) + "href" => a_string_matching(service_requests_url(service_request.compressed_id))) end it "lists all the service requests if you are admin" do @@ -251,8 +251,8 @@ def expect_result_to_have_user_email(email) "count" => 2, "subcount" => 2, "resources" => a_collection_containing_exactly( - {"href" => a_string_matching(service_requests_url(service_request_1.id))}, - {"href" => a_string_matching(service_requests_url(service_request_2.id))}, + {"href" => a_string_matching(service_requests_url(service_request_1.compressed_id))}, + {"href" => a_string_matching(service_requests_url(service_request_2.compressed_id))}, ) } expect(response).to have_http_status(:ok) @@ -272,7 +272,7 @@ def expect_result_to_have_user_email(email) expected = { "id" => service_request.compressed_id, - "href" => a_string_matching(service_requests_url(service_request.id)) + "href" => a_string_matching(service_requests_url(service_request.compressed_id)) } expect(response).to have_http_status(:ok) expect(response.parsed_body).to include(expected) diff --git a/spec/requests/api/service_templates_spec.rb b/spec/requests/api/service_templates_spec.rb index d6db9463a93..70cbfba91ca 100644 --- a/spec/requests/api/service_templates_spec.rb +++ b/spec/requests/api/service_templates_spec.rb @@ -49,7 +49,7 @@ run_get service_templates_url(template.id), :attributes => "picture" expect_result_to_have_keys(%w(id href picture)) - expected = {"id" => template.compressed_id, "href" => service_templates_url(template.id)} + expected = {"id" => template.compressed_id, "href" => service_templates_url(template.compressed_id)} expect_result_to_match_hash(response.parsed_body, expected) end @@ -134,7 +134,7 @@ st = FactoryGirl.create(:service_template, :name => "st1") run_post(service_templates_url(st.id), gen_request(:edit, updated_catalog_item_options)) - expect_single_resource_query("id" => st.compressed_id, "href" => service_templates_url(st.id), "name" => "Updated Template Name") + expect_single_resource_query("id" => st.compressed_id, "href" => service_templates_url(st.compressed_id), "name" => "Updated Template Name") expect(st.reload.name).to eq("Updated Template Name") end @@ -215,7 +215,7 @@ end.to change(ServiceTemplate, :count).by(-1) expected = { - "href" => a_string_matching(service_templates_url(service_template.id)), + "href" => a_string_matching(service_templates_url(service_template.compressed_id)), "message" => "service_templates id: #{service_template.id} deleting", "success" => true } @@ -245,7 +245,7 @@ {"href" => service_templates_url(st2.id)}])) expect_multiple_action_result(2) expect_result_resources_to_include_hrefs("results", - [service_templates_url(st1.id), service_templates_url(st2.id)]) + [service_templates_url(st1.compressed_id), service_templates_url(st2.compressed_id)]) expect { st1.reload }.to raise_error(ActiveRecord::RecordNotFound) expect { st2.reload }.to raise_error(ActiveRecord::RecordNotFound) @@ -281,7 +281,7 @@ "resources" => [ { "href" => a_string_matching( - "#{service_templates_url(service_template.id)}/service_requests/#{service_request.id}" + "#{service_templates_url(service_template.compressed_id)}/service_requests/#{service_request.compressed_id}" ) } ] diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb index 21d88a1d99a..85dcd027597 100644 --- a/spec/requests/api/services_spec.rb +++ b/spec/requests/api/services_spec.rb @@ -74,8 +74,8 @@ 'type' => 'ServiceOrchestration', 'name' => 'svc_new', 'parent_service' => { 'href' => services_url(svc1.id)}, - 'orchestration_template' => { 'href' => orchestration_templates_url(orchestration_template.id) }, - 'orchestration_manager' => { 'href' => providers_url(ems.id) } + 'orchestration_template' => { 'href' => orchestration_templates_url(orchestration_template.compressed_id) }, + 'orchestration_manager' => { 'href' => providers_url(ems.compressed_id) } } } expect do @@ -120,7 +120,7 @@ run_post(services_url(svc.id), gen_request(:edit, "name" => "updated svc1")) - expect_single_resource_query("id" => svc.compressed_id, "href" => services_url(svc.id), "name" => "updated svc1") + expect_single_resource_query("id" => svc.compressed_id, "href" => services_url(svc.compressed_id), "name" => "updated svc1") expect(svc.reload.name).to eq("updated svc1") end @@ -131,8 +131,8 @@ 'action' => 'edit', 'resource' => { 'parent_service' => { 'href' => services_url(svc1.id) }, - 'orchestration_template' => { 'href' => orchestration_templates_url(orchestration_template.id) }, - 'orchestration_manager' => { 'href' => providers_url(ems.id) } + 'orchestration_template' => { 'href' => orchestration_templates_url(orchestration_template.compressed_id) }, + 'orchestration_manager' => { 'href' => providers_url(ems.compressed_id) } } } run_post(services_url(svc_orchestration.id), resource) @@ -177,7 +177,7 @@ run_put(services_url(svc.id), "name" => "updated svc1") - expect_single_resource_query("id" => svc.compressed_id, "href" => services_url(svc.id), "name" => "updated svc1") + expect_single_resource_query("id" => svc.compressed_id, "href" => services_url(svc.compressed_id), "name" => "updated svc1") expect(svc.reload.name).to eq("updated svc1") end @@ -255,7 +255,7 @@ expected = { "success" => true, "message" => "services id: #{service.id} deleting", - "href" => a_string_matching(services_url(service.id)) + "href" => a_string_matching(services_url(service.compressed_id)) } expect(response.parsed_body).to include(expected) expect(response).to have_http_status(:ok) @@ -280,7 +280,7 @@ {"href" => services_url(svc2.id)}])) expect_multiple_action_result(2) expect_result_resources_to_include_hrefs("results", - [services_url(svc1.id), services_url(svc2.id)]) + [services_url(svc1.compressed_id), services_url(svc2.compressed_id)]) expect { svc1.reload }.to raise_error(ActiveRecord::RecordNotFound) expect { svc2.reload }.to raise_error(ActiveRecord::RecordNotFound) end @@ -314,7 +314,7 @@ def format_retirement_date(time) run_post(services_url(svc.id), gen_request(:retire)) - expect_single_resource_query("id" => svc.compressed_id, "href" => services_url(svc.id)) + expect_single_resource_query("id" => svc.compressed_id, "href" => services_url(svc.compressed_id)) end it "supports single service retirement in future" do @@ -412,7 +412,7 @@ def format_retirement_date(time) run_post(services_url(svc1.id), gen_request(:reconfigure, "text1" => "updated_text")) - expect_single_action_result(:success => true, :message => /reconfiguring/i, :href => services_url(svc1.id)) + expect_single_action_result(:success => true, :message => /reconfiguring/i, :href => services_url(svc1.compressed_id)) end end @@ -429,20 +429,21 @@ def format_retirement_date(time) svc1 << vm1 svc1 << vm2 svc1.save - - @svc1_vm_list = ["#{services_url(svc1.id)}/vms/#{vm1.id}", "#{services_url(svc1.id)}/vms/#{vm2.id}"] end def expect_svc_with_vms - expect_single_resource_query("href" => services_url(svc1.id)) - expect_result_resources_to_include_hrefs("vms", @svc1_vm_list) + expect_single_resource_query("href" => services_url(svc1.compressed_id)) + expect_result_resources_to_include_hrefs("vms", + ["#{services_url(svc1.compressed_id)}/vms/#{vm1.compressed_id}", "#{services_url(svc1.compressed_id)}/vms/#{vm2.compressed_id}"]) end it "can query vms as subcollection" do run_get "#{services_url(svc1.id)}/vms" expect_query_result(:vms, 2, 2) - expect_result_resources_to_include_hrefs("resources", @svc1_vm_list) + expect_result_resources_to_include_hrefs("resources", + ["#{services_url(svc1.compressed_id)}/vms/#{vm1.compressed_id}", + "#{services_url(svc1.compressed_id)}/vms/#{vm2.compressed_id}"]) end it "supports expansion of virtual attributes" do @@ -495,7 +496,7 @@ def expect_svc_with_vms run_post(services_url(service.id), :action => "start") expected = { - "href" => a_string_matching(services_url(service.id)), + "href" => a_string_matching(services_url(service.compressed_id)), "success" => true, "message" => a_string_matching("starting") } @@ -515,12 +516,12 @@ def expect_svc_with_vms "message" => a_string_matching("starting"), "task_id" => anything, "task_href" => anything, - "href" => a_string_matching(services_url(service_1.id))), + "href" => a_string_matching(services_url(service_1.compressed_id))), a_hash_including("success" => true, "message" => a_string_matching("starting"), "task_id" => anything, "task_href" => anything, - "href" => a_string_matching(services_url(service_2.id))), + "href" => a_string_matching(services_url(service_2.compressed_id))), ) } expect(response.parsed_body).to include(expected) @@ -545,7 +546,7 @@ def expect_svc_with_vms run_post(services_url(service.id), :action => "stop") expected = { - "href" => a_string_matching(services_url(service.id)), + "href" => a_string_matching(services_url(service.compressed_id)), "success" => true, "message" => a_string_matching("stopping") } @@ -565,12 +566,12 @@ def expect_svc_with_vms "message" => a_string_matching("stopping"), "task_id" => anything, "task_href" => anything, - "href" => a_string_matching(services_url(service_1.id))), + "href" => a_string_matching(services_url(service_1.compressed_id))), a_hash_including("success" => true, "message" => a_string_matching("stopping"), "task_id" => anything, "task_href" => anything, - "href" => a_string_matching(services_url(service_2.id))), + "href" => a_string_matching(services_url(service_2.compressed_id))), ) } expect(response.parsed_body).to include(expected) @@ -595,7 +596,7 @@ def expect_svc_with_vms run_post(services_url(service.id), :action => "suspend") expected = { - "href" => a_string_matching(services_url(service.id)), + "href" => a_string_matching(services_url(service.compressed_id)), "success" => true, "message" => a_string_matching("suspending") } @@ -615,12 +616,12 @@ def expect_svc_with_vms "message" => a_string_matching("suspending"), "task_id" => anything, "task_href" => anything, - "href" => a_string_matching(services_url(service_1.id))), + "href" => a_string_matching(services_url(service_1.compressed_id))), a_hash_including("success" => true, "message" => a_string_matching("suspending"), "task_id" => anything, "task_href" => anything, - "href" => a_string_matching(services_url(service_2.id))), + "href" => a_string_matching(services_url(service_2.compressed_id))), ) } expect(response.parsed_body).to include(expected) @@ -715,7 +716,7 @@ def expect_svc_with_vms request = { 'action' => 'add_resource', 'resources' => [ - { 'href' => services_url(svc.id), 'resource' => {'href' => vms_url(vm1.id)} }, + { 'href' => services_url(svc.compressed_id), 'resource' => {'href' => vms_url(vm1.id)} }, { 'href' => services_url(svc1.id), 'resource' => {'href' => vms_url(vm2.id)} } ] } @@ -741,8 +742,8 @@ def expect_svc_with_vms request = { 'action' => 'add_resource', 'resources' => [ - { 'href' => services_url(svc.id), 'resource' => {'href' => vms_url(vm1.id)} }, - { 'href' => services_url(svc1.id), 'resource' => {'href' => users_url(user.id)} } + { 'href' => services_url(svc.compressed_id), 'resource' => {'href' => vms_url(vm1.id)} }, + { 'href' => services_url(svc1.id), 'resource' => {'href' => users_url(user.compressed_id)} } ] } @@ -780,7 +781,7 @@ def expect_svc_with_vms api_basic_authorize(collection_action_identifier(:services, :add_resource)) request = { 'action' => 'add_resource', - 'resource' => { 'resource' => { 'href' => users_url(user.id) } } + 'resource' => { 'resource' => { 'href' => users_url(user.compressed_id) } } } run_post(services_url(svc.id), request) @@ -853,7 +854,7 @@ def expect_svc_with_vms request = { 'action' => 'remove_resource', 'resources' => [ - { 'href' => services_url(svc.id), 'resource' => { 'href' => vms_url(vm1.id)} }, + { 'href' => services_url(svc.compressed_id), 'resource' => { 'href' => vms_url(vm1.id)} }, { 'href' => services_url(svc1.id), 'resource' => { 'href' => vms_url(vm2.id)} } ] } @@ -897,7 +898,7 @@ def expect_svc_with_vms request = { 'action' => 'remove_resource', 'resources' => [ - { 'href' => services_url(svc.id), 'resource' => {} } + { 'href' => services_url(svc.compressed_id), 'resource' => {} } ] } @@ -963,7 +964,7 @@ def expect_svc_with_vms request = { 'action' => 'remove_all_resources', 'resources' => [ - { 'href' => services_url(svc.id) }, + { 'href' => services_url(svc.compressed_id) }, { 'href' => services_url(svc1.id) } ] } diff --git a/spec/requests/api/set_ownership_spec.rb b/spec/requests/api/set_ownership_spec.rb index 2472a83ce41..20d6e210f95 100644 --- a/spec/requests/api/set_ownership_spec.rb +++ b/spec/requests/api/set_ownership_spec.rb @@ -45,7 +45,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(services_url(svc.id), gen_request(:set_ownership, "owner" => {"id" => 999_999})) - expect_single_action_result(:success => false, :message => /.*/, :href => services_url(svc.id)) + expect_single_action_result(:success => false, :message => /.*/, :href => services_url(svc.compressed_id)) end it "to a service" do @@ -53,7 +53,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(services_url(svc.id), gen_request(:set_ownership, "owner" => {"userid" => api_config(:user)})) - expect_set_ownership_success(svc, services_url(svc.id), @user) + expect_set_ownership_success(svc, services_url(svc.compressed_id), @user) end it "by owner name to a service" do @@ -61,7 +61,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(services_url(svc.id), gen_request(:set_ownership, "owner" => {"name" => @user.name})) - expect_set_ownership_success(svc, services_url(svc.id), @user) + expect_set_ownership_success(svc, services_url(svc.compressed_id), @user) end it "by owner href to a service" do @@ -69,7 +69,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(services_url(svc.id), gen_request(:set_ownership, "owner" => {"href" => users_url(@user.id)})) - expect_set_ownership_success(svc, services_url(svc.id), @user) + expect_set_ownership_success(svc, services_url(svc.compressed_id), @user) end it "by owner id to a service" do @@ -77,7 +77,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(services_url(svc.id), gen_request(:set_ownership, "owner" => {"id" => @user.id})) - expect_set_ownership_success(svc, services_url(svc.id), @user) + expect_set_ownership_success(svc, services_url(svc.compressed_id), @user) end it "by group id to a service" do @@ -85,7 +85,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(services_url(svc.id), gen_request(:set_ownership, "group" => {"id" => @group.id})) - expect_set_ownership_success(svc, services_url(svc.id), nil, @group) + expect_set_ownership_success(svc, services_url(svc.compressed_id), nil, @group) end it "by group description to a service" do @@ -93,7 +93,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(services_url(svc.id), gen_request(:set_ownership, "group" => {"description" => @group.description})) - expect_set_ownership_success(svc, services_url(svc.id), nil, @group) + expect_set_ownership_success(svc, services_url(svc.compressed_id), nil, @group) end it "with owner and group to a service" do @@ -101,7 +101,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(services_url(svc.id), gen_request(:set_ownership, "owner" => {"userid" => api_config(:user)})) - expect_set_ownership_success(svc, services_url(svc.id), @user) + expect_set_ownership_success(svc, services_url(svc.compressed_id), @user) end it "to multiple services" do @@ -114,7 +114,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(services_url, gen_request(:set_ownership, {"owner" => {"userid" => api_config(:user)}}, *svc_urls)) expect_multiple_action_result(2) - expect_result_resources_to_include_hrefs("results", svc_urls) + expect_result_resources_to_include_hrefs("results", [services_url(svc1.compressed_id), services_url(svc2.compressed_id)]) expect(svc1.reload.evm_owner).to eq(@user) expect(svc2.reload.evm_owner).to eq(@user) end @@ -152,7 +152,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(vms_url(vm.id), gen_request(:set_ownership, "owner" => {"id" => 999_999})) - expect_single_action_result(:success => false, :message => /.*/, :href => vms_url(vm.id)) + expect_single_action_result(:success => false, :message => /.*/, :href => vms_url(vm.compressed_id)) end it "to a vm" do @@ -160,7 +160,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(vms_url(vm.id), gen_request(:set_ownership, "owner" => {"userid" => api_config(:user)})) - expect_set_ownership_success(vm, vms_url(vm.id), @user) + expect_set_ownership_success(vm, vms_url(vm.compressed_id), @user) end it "by owner name to a vm" do @@ -168,7 +168,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(vms_url(vm.id), gen_request(:set_ownership, "owner" => {"name" => @user.name})) - expect_set_ownership_success(vm, vms_url(vm.id), @user) + expect_set_ownership_success(vm, vms_url(vm.compressed_id), @user) end it "by owner href to a vm" do @@ -176,7 +176,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(vms_url(vm.id), gen_request(:set_ownership, "owner" => {"href" => users_url(@user.id)})) - expect_set_ownership_success(vm, vms_url(vm.id), @user) + expect_set_ownership_success(vm, vms_url(vm.compressed_id), @user) end it "by owner id to a vm" do @@ -184,7 +184,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(vms_url(vm.id), gen_request(:set_ownership, "owner" => {"id" => @user.id})) - expect_set_ownership_success(vm, vms_url(vm.id), @user) + expect_set_ownership_success(vm, vms_url(vm.compressed_id), @user) end it "by group id to a vm" do @@ -192,7 +192,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(vms_url(vm.id), gen_request(:set_ownership, "group" => {"id" => @group.id})) - expect_set_ownership_success(vm, vms_url(vm.id), nil, @group) + expect_set_ownership_success(vm, vms_url(vm.compressed_id), nil, @group) end it "by group description to a vm" do @@ -200,7 +200,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(vms_url(vm.id), gen_request(:set_ownership, "group" => {"description" => @group.description})) - expect_set_ownership_success(vm, vms_url(vm.id), nil, @group) + expect_set_ownership_success(vm, vms_url(vm.compressed_id), nil, @group) end it "with owner and group to a vm" do @@ -208,7 +208,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(vms_url(vm.id), gen_request(:set_ownership, "owner" => {"userid" => api_config(:user)})) - expect_set_ownership_success(vm, vms_url(vm.id), @user) + expect_set_ownership_success(vm, vms_url(vm.compressed_id), @user) end it "to multiple vms" do @@ -221,7 +221,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(vms_url, gen_request(:set_ownership, {"owner" => {"userid" => api_config(:user)}}, *vm_urls)) expect_multiple_action_result(2) - expect_result_resources_to_include_hrefs("results", vm_urls) + expect_result_resources_to_include_hrefs("results", [vms_url(vm1.compressed_id), vms_url(vm2.compressed_id)]) expect(vm1.reload.evm_owner).to eq(@user) expect(vm2.reload.evm_owner).to eq(@user) end @@ -259,7 +259,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(templates_url(template.id), gen_request(:set_ownership, "owner" => {"id" => 999_999})) - expect_single_action_result(:success => false, :message => /.*/, :href => templates_url(template.id)) + expect_single_action_result(:success => false, :message => /.*/, :href => templates_url(template.compressed_id)) end it "to a template" do @@ -267,7 +267,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(templates_url(template.id), gen_request(:set_ownership, "owner" => {"userid" => api_config(:user)})) - expect_set_ownership_success(template, templates_url(template.id), @user) + expect_set_ownership_success(template, templates_url(template.compressed_id), @user) end it "by owner name to a template" do @@ -275,7 +275,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(templates_url(template.id), gen_request(:set_ownership, "owner" => {"name" => @user.name})) - expect_set_ownership_success(template, templates_url(template.id), @user) + expect_set_ownership_success(template, templates_url(template.compressed_id), @user) end it "by owner href to a template" do @@ -283,7 +283,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(templates_url(template.id), gen_request(:set_ownership, "owner" => {"href" => users_url(@user.id)})) - expect_set_ownership_success(template, templates_url(template.id), @user) + expect_set_ownership_success(template, templates_url(template.compressed_id), @user) end it "by owner id to a template" do @@ -291,7 +291,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(templates_url(template.id), gen_request(:set_ownership, "owner" => {"id" => @user.id})) - expect_set_ownership_success(template, templates_url(template.id), @user) + expect_set_ownership_success(template, templates_url(template.compressed_id), @user) end it "by group id to a template" do @@ -299,7 +299,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(templates_url(template.id), gen_request(:set_ownership, "group" => {"id" => @group.id})) - expect_set_ownership_success(template, templates_url(template.id), nil, @group) + expect_set_ownership_success(template, templates_url(template.compressed_id), nil, @group) end it "by group description to a template" do @@ -308,7 +308,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(templates_url(template.id), gen_request(:set_ownership, "group" => {"description" => @group.description})) - expect_set_ownership_success(template, templates_url(template.id), nil, @group) + expect_set_ownership_success(template, templates_url(template.compressed_id), nil, @group) end it "with owner and group to a template" do @@ -316,7 +316,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(templates_url(template.id), gen_request(:set_ownership, "owner" => {"userid" => api_config(:user)})) - expect_set_ownership_success(template, templates_url(template.id), @user) + expect_set_ownership_success(template, templates_url(template.compressed_id), @user) end it "to multiple templates" do @@ -329,7 +329,7 @@ def expect_set_ownership_success(object, href, user = nil, group = nil) run_post(templates_url, gen_request(:set_ownership, {"owner" => {"userid" => api_config(:user)}}, *template_urls)) expect_multiple_action_result(2) - expect_result_resources_to_include_hrefs("results", template_urls) + expect_result_resources_to_include_hrefs("results", [templates_url(template1.compressed_id), templates_url(template2.compressed_id)]) expect(template1.reload.evm_owner).to eq(@user) expect(template2.reload.evm_owner).to eq(@user) end diff --git a/spec/requests/api/snapshots_spec.rb b/spec/requests/api/snapshots_spec.rb index d253824b23a..4bbddf571c0 100644 --- a/spec/requests/api/snapshots_spec.rb +++ b/spec/requests/api/snapshots_spec.rb @@ -14,7 +14,7 @@ "name" => "snapshots", "subcount" => 1, "resources" => [ - {"href" => a_string_matching("#{vms_url(vm.id)}/snapshots/#{snapshot.id}")} + {"href" => a_string_matching("#{vms_url(vm.compressed_id)}/snapshots/#{snapshot.compressed_id}")} ] } expect(response.parsed_body).to include(expected) @@ -43,7 +43,7 @@ expected = { "create_time" => create_time.iso8601, - "href" => a_string_matching("#{vms_url(vm.id)}/snapshots/#{snapshot.id}"), + "href" => a_string_matching("#{vms_url(vm.compressed_id)}/snapshots/#{snapshot.compressed_id}"), "id" => snapshot.compressed_id, "vm_or_template_id" => vm.compressed_id } @@ -359,7 +359,7 @@ "name" => "snapshots", "subcount" => 1, "resources" => [ - {"href" => a_string_matching("#{instances_url(instance.id)}/snapshots/#{snapshot.id}")} + {"href" => a_string_matching("#{instances_url(instance.compressed_id)}/snapshots/#{snapshot.compressed_id}")} ] } expect(response.parsed_body).to include(expected) @@ -388,7 +388,7 @@ expected = { "create_time" => create_time.iso8601, - "href" => a_string_matching("#{instances_url(instance.id)}/snapshots/#{snapshot.id}"), + "href" => a_string_matching("#{instances_url(instance.compressed_id)}/snapshots/#{snapshot.compressed_id}"), "id" => snapshot.compressed_id, "vm_or_template_id" => instance.compressed_id } diff --git a/spec/requests/api/tag_collections_spec.rb b/spec/requests/api/tag_collections_spec.rb index 06efd94e850..e48cbc06f37 100644 --- a/spec/requests/api/tag_collections_spec.rb +++ b/spec/requests/api/tag_collections_spec.rb @@ -58,7 +58,7 @@ def expect_resource_has_tags(resource, tag_names) run_post(provider_tags_url, gen_request(:assign, :category => tag1[:category], :name => tag1[:name])) - expect_tagging_result(tag1_results(provider_url)) + expect_tagging_result(tag1_results(providers_url(provider.compressed_id))) end it "does not unassign a tag from a Provider without appropriate role" do @@ -75,7 +75,7 @@ def expect_resource_has_tags(resource, tag_names) run_post(provider_tags_url, gen_request(:unassign, :category => tag1[:category], :name => tag1[:name])) - expect_tagging_result(tag1_results(provider_url)) + expect_tagging_result(tag1_results(providers_url(provider.compressed_id))) expect_resource_has_tags(provider, tag2[:path]) end end @@ -107,7 +107,7 @@ def expect_resource_has_tags(resource, tag_names) run_post(host_tags_url, gen_request(:assign, :category => tag1[:category], :name => tag1[:name])) - expect_tagging_result(tag1_results(host_url)) + expect_tagging_result(tag1_results(hosts_url(host.compressed_id))) end it "does not unassign a tag from a Host without appropriate role" do @@ -124,7 +124,7 @@ def expect_resource_has_tags(resource, tag_names) run_post(host_tags_url, gen_request(:unassign, :category => tag1[:category], :name => tag1[:name])) - expect_tagging_result(tag1_results(host_url)) + expect_tagging_result(tag1_results(hosts_url(host.compressed_id))) expect_resource_has_tags(host, tag2[:path]) end end @@ -157,7 +157,7 @@ def expect_resource_has_tags(resource, tag_names) run_post(ds_tags_url, gen_request(:assign, :category => tag1[:category], :name => tag1[:name])) - expect_tagging_result(tag1_results(ds_url)) + expect_tagging_result(tag1_results(data_stores_url(ds.compressed_id))) end it "does not unassign a tag from a Data Store without appropriate role" do @@ -174,7 +174,7 @@ def expect_resource_has_tags(resource, tag_names) run_post(ds_tags_url, gen_request(:unassign, :category => tag1[:category], :name => tag1[:name])) - expect_tagging_result(tag1_results(ds_url)) + expect_tagging_result(tag1_results(data_stores_url(ds.compressed_id))) expect_resource_has_tags(ds, tag2[:path]) end end @@ -207,7 +207,7 @@ def expect_resource_has_tags(resource, tag_names) run_post(rp_tags_url, gen_request(:assign, :category => tag1[:category], :name => tag1[:name])) - expect_tagging_result(tag1_results(rp_url)) + expect_tagging_result(tag1_results(resource_pools_url(rp.compressed_id))) end it "does not unassign a tag from a Resource Pool without appropriate role" do @@ -224,7 +224,7 @@ def expect_resource_has_tags(resource, tag_names) run_post(rp_tags_url, gen_request(:unassign, :category => tag1[:category], :name => tag1[:name])) - expect_tagging_result(tag1_results(rp_url)) + expect_tagging_result(tag1_results(resource_pools_url(rp.compressed_id))) expect_resource_has_tags(rp, tag2[:path]) end end @@ -264,7 +264,7 @@ def expect_resource_has_tags(resource, tag_names) run_post(cluster_tags_url, gen_request(:assign, :category => tag1[:category], :name => tag1[:name])) - expect_tagging_result(tag1_results(cluster_url)) + expect_tagging_result(tag1_results(clusters_url(cluster.compressed_id))) end it "does not unassign a tag from a Cluster without appropriate role" do @@ -281,7 +281,7 @@ def expect_resource_has_tags(resource, tag_names) run_post(cluster_tags_url, gen_request(:unassign, :category => tag1[:category], :name => tag1[:name])) - expect_tagging_result(tag1_results(cluster_url)) + expect_tagging_result(tag1_results(clusters_url(cluster.compressed_id))) expect_resource_has_tags(cluster, tag2[:path]) end end @@ -314,7 +314,7 @@ def expect_resource_has_tags(resource, tag_names) run_post(service_tags_url, gen_request(:assign, :category => tag1[:category], :name => tag1[:name])) - expect_tagging_result(tag1_results(service_url)) + expect_tagging_result(tag1_results(services_url(service.compressed_id))) end it "does not unassign a tag from a Service without appropriate role" do @@ -331,7 +331,7 @@ def expect_resource_has_tags(resource, tag_names) run_post(service_tags_url, gen_request(:unassign, :category => tag1[:category], :name => tag1[:name])) - expect_tagging_result(tag1_results(service_url)) + expect_tagging_result(tag1_results(services_url(service.compressed_id))) expect_resource_has_tags(service, tag2[:path]) end end @@ -364,7 +364,7 @@ def expect_resource_has_tags(resource, tag_names) run_post(service_template_tags_url, gen_request(:assign, :category => tag1[:category], :name => tag1[:name])) - expect_tagging_result(tag1_results(service_template_url)) + expect_tagging_result(tag1_results(service_templates_url(service_template.compressed_id))) end it "does not unassign a tag from a Service Template without appropriate role" do @@ -381,7 +381,7 @@ def expect_resource_has_tags(resource, tag_names) run_post(service_template_tags_url, gen_request(:unassign, :category => tag1[:category], :name => tag1[:name])) - expect_tagging_result(tag1_results(service_template_url)) + expect_tagging_result(tag1_results(service_templates_url(service_template.compressed_id))) expect_resource_has_tags(service_template, tag2[:path]) end end @@ -414,7 +414,7 @@ def expect_resource_has_tags(resource, tag_names) run_post(tenant_tags_url, gen_request(:assign, :category => tag1[:category], :name => tag1[:name])) - expect_tagging_result(tag1_results(tenant_url)) + expect_tagging_result(tag1_results(tenants_url(tenant.compressed_id))) end it "does not unassign a tag from a Tenant without appropriate role" do @@ -431,7 +431,7 @@ def expect_resource_has_tags(resource, tag_names) run_post(tenant_tags_url, gen_request(:unassign, :category => tag1[:category], :name => tag1[:name])) - expect_tagging_result(tag1_results(tenant_url)) + expect_tagging_result(tag1_results(tenants_url(tenant.compressed_id))) expect_resource_has_tags(tenant, tag2[:path]) end end @@ -543,11 +543,11 @@ def expect_resource_has_tags(resource, tag_names) expected = { 'results' => [ a_hash_including('success' => true, - 'href' => a_string_including(vms_url(vm1.id)), + 'href' => a_string_including(vms_url(vm1.compressed_id)), 'tag_category' => tag1[:category], 'tag_name' => tag1[:name]), a_hash_including('success' => true, - 'href' => a_string_including(vms_url(vm2.id)), + 'href' => a_string_including(vms_url(vm2.compressed_id)), 'tag_category' => tag2[:category], 'tag_name' => tag2[:name]) ] @@ -575,11 +575,11 @@ def expect_resource_has_tags(resource, tag_names) 'results' => [ a_hash_including('success' => false, 'message' => a_string_including("Couldn't find Vm")), a_hash_including('success' => false, - 'href' => a_string_including(vms_url(vm2.id)), + 'href' => a_string_including(vms_url(vm2.compressed_id)), 'tag_category' => bad_tag[:category], 'tag_name' => bad_tag[:name]), a_hash_including('success' => true, - 'href' => a_string_including(vms_url(vm2.id)), + 'href' => a_string_including(vms_url(vm2.compressed_id)), 'tag_category' => tag1[:category], 'tag_name' => tag1[:name]) ] @@ -611,11 +611,11 @@ def expect_resource_has_tags(resource, tag_names) expected = { 'results' => [ a_hash_including('success' => true, - 'href' => a_string_including(vms_url(vm1.id)), + 'href' => a_string_including(vms_url(vm1.compressed_id)), 'tag_category' => tag1[:category], 'tag_name' => tag1[:name]), a_hash_including('success' => true, - 'href' => a_string_including(vms_url(vm2.id)), + 'href' => a_string_including(vms_url(vm2.compressed_id)), 'tag_category' => tag2[:category], 'tag_name' => tag2[:name]) ] @@ -824,11 +824,11 @@ def expect_resource_has_tags(resource, tag_names) expected = { 'results' => [ a_hash_including('success' => true, - 'href' => a_string_including(services_url(service1.id)), + 'href' => a_string_including(services_url(service1.compressed_id)), 'tag_category' => tag1[:category], 'tag_name' => tag1[:name]), a_hash_including('success' => true, - 'href' => a_string_including(services_url(service2.id)), + 'href' => a_string_including(services_url(service2.compressed_id)), 'tag_category' => tag2[:category], 'tag_name' => tag2[:name]) ] @@ -852,11 +852,11 @@ def expect_resource_has_tags(resource, tag_names) expected = { 'results' => [ a_hash_including('success' => true, - 'href' => a_string_including(services_url(service1.id)), + 'href' => a_string_including(services_url(service1.compressed_id)), 'tag_category' => tag1[:category], 'tag_name' => tag1[:name]), a_hash_including('success' => true, - 'href' => a_string_including(services_url(service2.id)), + 'href' => a_string_including(services_url(service2.compressed_id)), 'tag_category' => tag2[:category], 'tag_name' => tag2[:name]) ] diff --git a/spec/requests/api/tags_spec.rb b/spec/requests/api/tags_spec.rb index d594412a101..14a13dabd93 100644 --- a/spec/requests/api/tags_spec.rb +++ b/spec/requests/api/tags_spec.rb @@ -32,7 +32,7 @@ tag = Tag.find(ApplicationRecord.uncompress_id(result["id"])) tag_category = Category.find(tag.category.id) expect(tag_category).to eq(category) - expect(result["href"]).to include(tags_url(tag.id)) + expect(result["href"]).to include(tags_url(tag.compressed_id)) expect(response).to have_http_status(:ok) end @@ -270,7 +270,7 @@ run_get tags_url(tag.id), :attributes => attr_list expect_single_resource_query( - "href" => tags_url(tag.id), + "href" => tags_url(tag.compressed_id), "id" => tag.compressed_id, "name" => tag.name, "category" => {"name" => tag.category.name, "description" => tag.category.description}, @@ -285,7 +285,7 @@ run_get tags_url(tag.id), :attributes => "categorization" expect_single_resource_query( - "href" => tags_url(tag.id), + "href" => tags_url(tag.compressed_id), "id" => tag.compressed_id, "name" => tag.name, "categorization" => { diff --git a/spec/requests/api/templates_spec.rb b/spec/requests/api/templates_spec.rb index 87e808244a1..de140e4d0d5 100644 --- a/spec/requests/api/templates_spec.rb +++ b/spec/requests/api/templates_spec.rb @@ -9,7 +9,7 @@ end.to change(MiqTemplate, :count).by(-1) expected = { - "href" => a_string_matching(templates_url(template.id)), + "href" => a_string_matching(templates_url(template.compressed_id)), "message" => "templates id: #{template.id} deleting", "success" => true } diff --git a/spec/requests/api/tenant_quotas_spec.rb b/spec/requests/api/tenant_quotas_spec.rb index ec92216edca..a889cf5acb3 100644 --- a/spec/requests/api/tenant_quotas_spec.rb +++ b/spec/requests/api/tenant_quotas_spec.rb @@ -13,8 +13,8 @@ expect_result_resources_to_include_hrefs( "resources", [ - "/api/tenants/#{tenant.id}/quotas/#{quota_1.id}", - "/api/tenants/#{tenant.id}/quotas/#{quota_2.id}", + "/api/tenants/#{tenant.compressed_id}/quotas/#{quota_1.compressed_id}", + "/api/tenants/#{tenant.compressed_id}/quotas/#{quota_2.compressed_id}", ] ) @@ -30,7 +30,7 @@ expect_result_to_match_hash( response.parsed_body, - "href" => "/api/tenants/#{tenant.id}/quotas/#{quota.id}", + "href" => "/api/tenants/#{tenant.compressed_id}/quotas/#{quota.compressed_id}", "id" => quota.compressed_id, "tenant_id" => tenant.compressed_id, "name" => "cpu_allocated", @@ -45,7 +45,7 @@ expected = { 'results' => [ - a_hash_including('href' => a_string_including("#{tenants_url(tenant.id)}/quotas/")) + a_hash_including('href' => a_string_including("#{tenants_url(tenant.compressed_id)}/quotas/")) ] } expect do @@ -81,7 +81,7 @@ expect(response).to have_http_status(:ok) quota.reload expect(quota.value).to eq(5) - expect(response.parsed_body).to include('href' => a_string_including("tenants/#{tenant.id}/quotas/#{quota.id}")) + expect(response.parsed_body).to include('href' => a_string_including("tenants/#{tenant.compressed_id}/quotas/#{quota.compressed_id}")) end it "can update multiple quotas from a tenant with POST" do diff --git a/spec/requests/api/tenants_spec.rb b/spec/requests/api/tenants_spec.rb index 820175ff342..fe2dfdae392 100644 --- a/spec/requests/api/tenants_spec.rb +++ b/spec/requests/api/tenants_spec.rb @@ -11,9 +11,9 @@ expect_result_resources_to_include_hrefs( "resources", [ - tenants_url(root_tenant.id), - tenants_url(tenant_1.id), - tenants_url(tenant_2.id) + tenants_url(root_tenant.compressed_id), + tenants_url(tenant_1.compressed_id), + tenants_url(tenant_2.compressed_id) ] ) @@ -33,7 +33,7 @@ expect_result_to_match_hash( response.parsed_body, - "href" => tenants_url(tenant.id), + "href" => tenants_url(tenant.compressed_id), "id" => tenant.compressed_id, "name" => "Test Tenant", "description" => "Tenant for this test" @@ -111,7 +111,7 @@ run_get tenants_url(root_tenant.id) expect_result_to_match_hash(response.parsed_body, - "href" => tenants_url(root_tenant.id), + "href" => tenants_url(root_tenant.compressed_id), "id" => root_tenant.compressed_id, "name" => ::Settings.server.company, ) diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index 9cf93e40ce2..9886ddd6842 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -299,7 +299,7 @@ run_post(user1_url, gen_request(:delete)) - expect_single_action_result(:success => true, :message => "deleting", :href => user1_url) + expect_single_action_result(:success => true, :message => "deleting", :href => users_url(user1.compressed_id)) expect(User.exists?(user1_id)).to be_falsey end @@ -312,7 +312,7 @@ run_post(users_url, gen_request(:delete, [{"href" => user1_url}, {"href" => user2_url}])) expect_multiple_action_result(2) - expect_result_resources_to_include_hrefs("results", [user1_url, user2_url]) + expect_result_resources_to_include_hrefs("results", [users_url(user1.compressed_id), users_url(user2.compressed_id)]) expect(User.exists?(user1_id)).to be_falsey expect(User.exists?(user2_id)).to be_falsey end diff --git a/spec/requests/api/vms_spec.rb b/spec/requests/api/vms_spec.rb index 08eeb2c2218..926c840ab44 100644 --- a/spec/requests/api/vms_spec.rb +++ b/spec/requests/api/vms_spec.rb @@ -47,7 +47,7 @@ def update_raw_power_state(state, *vms) it 'can edit a VM with an appropriate role' do api_basic_authorize collection_action_identifier(:vms, :edit) children = new_vms.collect do |vm| - { 'href' => vms_url(vm.id) } + { 'href' => vms_url(vm.compressed_id) } end run_post(vms_url(vm.id), :action => 'edit', @@ -120,7 +120,6 @@ def update_raw_power_state(state, *vms) let(:vm_accounts_url) { "#{vms_url(vm.id)}/accounts" } let(:acct1_url) { "#{vm_accounts_url}/#{acct1.id}" } let(:acct2_url) { "#{vm_accounts_url}/#{acct2.id}" } - let(:vm_accounts_url_list) { [acct1_url, acct2_url] } it "query VM accounts subcollection with no related accounts" do api_basic_authorize @@ -139,7 +138,9 @@ def update_raw_power_state(state, *vms) run_get vm_accounts_url expect_query_result(:accounts, 2) - expect_result_resources_to_include_hrefs("resources", vm_accounts_url_list) + expect_result_resources_to_include_hrefs("resources", + ["#{vms_url(vm.compressed_id)}/accounts/#{acct1.compressed_id}", + "#{vms_url(vm.compressed_id)}/accounts/#{acct2.compressed_id}"]) end it "query VM accounts subcollection with a valid Account Id" do @@ -167,7 +168,9 @@ def update_raw_power_state(state, *vms) run_get vm_url, :expand => "accounts" expect_single_resource_query("guid" => vm_guid) - expect_result_resources_to_include_hrefs("accounts", vm_accounts_url_list) + expect_result_resources_to_include_hrefs("accounts", + ["#{vms_url(vm.compressed_id)}/accounts/#{acct1.compressed_id}", + "#{vms_url(vm.compressed_id)}/accounts/#{acct2.compressed_id}"]) end end @@ -177,7 +180,6 @@ def update_raw_power_state(state, *vms) let(:vm_software_url) { "#{vms_url(vm.id)}/software" } let(:sw1_url) { "#{vm_software_url}/#{sw1.id}" } let(:sw2_url) { "#{vm_software_url}/#{sw2.id}" } - let(:vm_software_url_list) { [sw1_url, sw2_url] } it "query VM software subcollection with no related software" do api_basic_authorize @@ -196,7 +198,9 @@ def update_raw_power_state(state, *vms) run_get vm_software_url expect_query_result(:software, 2) - expect_result_resources_to_include_hrefs("resources", vm_software_url_list) + expect_result_resources_to_include_hrefs("resources", + ["#{vms_url(vm.compressed_id)}/software/#{sw1.compressed_id}", + "#{vms_url(vm.compressed_id)}/software/#{sw2.compressed_id}"]) end it "query VM software subcollection with a valid Software Id" do @@ -224,7 +228,9 @@ def update_raw_power_state(state, *vms) run_get vms_url(vm.id), :expand => "software" expect_single_resource_query("guid" => vm_guid) - expect_result_resources_to_include_hrefs("software", vm_software_url_list) + expect_result_resources_to_include_hrefs("software", + ["#{vms_url(vm.compressed_id)}/software/#{sw1.compressed_id}", + "#{vms_url(vm.compressed_id)}/software/#{sw2.compressed_id}"]) end end @@ -250,7 +256,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:start)) - expect_single_action_result(:success => false, :message => "is powered on", :href => vm_url) + expect_single_action_result(:success => false, :message => "is powered on", :href => vms_url(vm.compressed_id)) end it "starts a vm" do @@ -259,7 +265,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:start)) - expect_single_action_result(:success => true, :message => "starting", :href => vm_url, :task => true) + expect_single_action_result(:success => true, :message => "starting", :href => vms_url(vm.compressed_id), :task => true) end it "starting a vm queues it properly" do @@ -268,7 +274,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:start)) - expect_single_action_result(:success => true, :message => "starting", :href => vm_url, :task => true) + expect_single_action_result(:success => true, :message => "starting", :href => vms_url(vm.compressed_id), :task => true) expect(MiqQueue.where(:class_name => vm.class.name, :instance_id => vm.id, :method_name => "start", @@ -282,7 +288,7 @@ def update_raw_power_state(state, *vms) run_post(vms_url, gen_request(:start, nil, vm1_url, vm2_url)) expect_multiple_action_result(2, :task => true) - expect_result_resources_to_include_hrefs("results", vms_list) + expect_result_resources_to_include_hrefs("results", [vms_url(vm1.compressed_id), vms_url(vm2.compressed_id)]) end end @@ -309,7 +315,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:stop)) - expect_single_action_result(:success => false, :message => "is not powered on", :href => vm_url) + expect_single_action_result(:success => false, :message => "is not powered on", :href => vms_url(vm.compressed_id)) end it "stops a vm" do @@ -317,7 +323,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:stop)) - expect_single_action_result(:success => true, :message => "stopping", :href => vm_url, :task => true) + expect_single_action_result(:success => true, :message => "stopping", :href => vms_url(vm.compressed_id), :task => true) end it "stops multiple vms" do @@ -326,7 +332,7 @@ def update_raw_power_state(state, *vms) run_post(vms_url, gen_request(:stop, nil, vm1_url, vm2_url)) expect_multiple_action_result(2, :task => true) - expect_result_resources_to_include_hrefs("results", vms_list) + expect_result_resources_to_include_hrefs("results", [vms_url(vm1.compressed_id), vms_url(vm2.compressed_id)]) end end @@ -353,7 +359,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:suspend)) - expect_single_action_result(:success => false, :message => "is not powered on", :href => vm_url) + expect_single_action_result(:success => false, :message => "is not powered on", :href => vms_url(vm.compressed_id)) end it "suspends a suspended vm" do @@ -362,7 +368,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:suspend)) - expect_single_action_result(:success => false, :message => "is not powered on", :href => vm_url) + expect_single_action_result(:success => false, :message => "is not powered on", :href => vms_url(vm.compressed_id)) end it "suspends a vm" do @@ -370,7 +376,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:suspend)) - expect_single_action_result(:success => true, :message => "suspending", :href => vm_url, :task => true) + expect_single_action_result(:success => true, :message => "suspending", :href => vms_url(vm.compressed_id), :task => true) end it "suspends multiple vms" do @@ -379,7 +385,7 @@ def update_raw_power_state(state, *vms) run_post(vms_url, gen_request(:suspend, nil, vm1_url, vm2_url)) expect_multiple_action_result(2, :task => true) - expect_result_resources_to_include_hrefs("results", vms_list) + expect_result_resources_to_include_hrefs("results", [vms_url(vm1.compressed_id), vms_url(vm2.compressed_id)]) end end @@ -406,7 +412,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:pause)) - expect_single_action_result(:success => false, :message => "is not powered on", :href => vm_url) + expect_single_action_result(:success => false, :message => "is not powered on", :href => vms_url(vm.compressed_id)) end it "pauses a pauseed vm" do @@ -415,7 +421,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:pause)) - expect_single_action_result(:success => false, :message => "is not powered on", :href => vm_url) + expect_single_action_result(:success => false, :message => "is not powered on", :href => vms_url(vm.compressed_id)) end it "pauses a vm" do @@ -423,7 +429,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:pause)) - expect_single_action_result(:success => true, :message => "pausing", :href => vm_url, :task => true) + expect_single_action_result(:success => true, :message => "pausing", :href => vms_url(vm.compressed_id), :task => true) end it "pauses multiple vms" do @@ -432,7 +438,7 @@ def update_raw_power_state(state, *vms) run_post(vms_url, gen_request(:pause, nil, vm1_url, vm2_url)) expect_multiple_action_result(2, :task => true) - expect_result_resources_to_include_hrefs("results", vms_list) + expect_result_resources_to_include_hrefs("results", [vms_url(vm1.compressed_id), vms_url(vm2.compressed_id)]) end end @@ -459,7 +465,7 @@ def update_raw_power_state(state, *vms) run_post(vm_openstack_url, gen_request(:shelve)) - expect_single_action_result(:success => true, :message => 'shelving', :href => vm_openstack_url) + expect_single_action_result(:success => true, :message => 'shelving', :href => vms_url(vm_openstack.compressed_id)) end it "shelves a suspended vm" do @@ -468,7 +474,7 @@ def update_raw_power_state(state, *vms) run_post(vm_openstack_url, gen_request(:shelve)) - expect_single_action_result(:success => true, :message => 'shelving', :href => vm_openstack_url) + expect_single_action_result(:success => true, :message => 'shelving', :href => vms_url(vm_openstack.compressed_id)) end it "shelves a paused off vm" do @@ -477,7 +483,7 @@ def update_raw_power_state(state, *vms) run_post(vm_openstack_url, gen_request(:shelve)) - expect_single_action_result(:success => true, :message => 'shelving', :href => vm_openstack_url) + expect_single_action_result(:success => true, :message => 'shelving', :href => vms_url(vm_openstack.compressed_id)) end it "shelves a shelveed vm" do @@ -488,7 +494,7 @@ def update_raw_power_state(state, *vms) expect_single_action_result(:success => false, :message => "The VM can't be shelved, current state has to be powered on, off, suspended or paused", - :href => vm_openstack_url) + :href => vms_url(vm_openstack.compressed_id)) end it "shelves a vm" do @@ -496,7 +502,7 @@ def update_raw_power_state(state, *vms) run_post(vm_openstack_url, gen_request(:shelve)) - expect_single_action_result(:success => true, :message => "shelving", :href => vm_openstack_url, :task => true) + expect_single_action_result(:success => true, :message => "shelving", :href => vms_url(vm_openstack.compressed_id), :task => true) end it "shelve for a VMWare vm is not supported" do @@ -506,7 +512,7 @@ def update_raw_power_state(state, *vms) expect_single_action_result(:success => false, :message => "Shelve Operation is not available for Vmware VM.", - :href => vm_url, + :href => vms_url(vm.compressed_id), :task => false) end @@ -516,7 +522,7 @@ def update_raw_power_state(state, *vms) run_post(vms_url, gen_request(:shelve, nil, vm_openstack1_url, vm_openstack2_url)) expect_multiple_action_result(2, :task => true) - expect_result_resources_to_include_hrefs("results", vms_openstack_list) + expect_result_resources_to_include_hrefs("results", [vms_url(vm_openstack1.compressed_id), vms_url(vm_openstack2.compressed_id)]) end end @@ -544,7 +550,7 @@ def update_raw_power_state(state, *vms) expect_single_action_result(:success => false, :message => "The VM can't be shelved offload, current state has to be shelved", - :href => vm_openstack_url) + :href => vms_url(vm_openstack.compressed_id)) end it "shelve_offloads a powered off vm" do @@ -555,7 +561,7 @@ def update_raw_power_state(state, *vms) expect_single_action_result(:success => false, :message => "The VM can't be shelved offload, current state has to be shelved", - :href => vm_openstack_url) + :href => vms_url(vm_openstack.compressed_id)) end it "shelve_offloads a suspended vm" do @@ -566,7 +572,7 @@ def update_raw_power_state(state, *vms) expect_single_action_result(:success => false, :message => "The VM can't be shelved offload, current state has to be shelved", - :href => vm_openstack_url) + :href => vms_url(vm_openstack.compressed_id)) end it "shelve_offloads a paused off vm" do @@ -577,7 +583,7 @@ def update_raw_power_state(state, *vms) expect_single_action_result(:success => false, :message => "The VM can't be shelved offload, current state has to be shelved", - :href => vm_openstack_url) + :href => vms_url(vm_openstack.compressed_id)) end it "shelve_offloads a shelve_offloaded vm" do @@ -588,7 +594,7 @@ def update_raw_power_state(state, *vms) expect_single_action_result(:success => false, :message => "The VM can't be shelved offload, current state has to be shelved", - :href => vm_openstack_url) + :href => vms_url(vm_openstack.compressed_id)) end it "shelve_offloads a shelved vm" do @@ -599,7 +605,7 @@ def update_raw_power_state(state, *vms) expect_single_action_result(:success => true, :message => "shelve-offloading", - :href => vm_openstack_url) + :href => vms_url(vm_openstack.compressed_id)) end it "shelve_offload for a VMWare vm is not supported" do @@ -609,7 +615,7 @@ def update_raw_power_state(state, *vms) expect_single_action_result(:success => false, :message => "Shelve Offload Operation is not available for Vmware VM.", - :href => vm_url, + :href => vms_url(vm.compressed_id), :task => false) end @@ -622,7 +628,7 @@ def update_raw_power_state(state, *vms) run_post(vms_url, gen_request(:shelve_offload, nil, vm_openstack1_url, vm_openstack2_url)) expect_multiple_action_result(2, :task => true) - expect_result_resources_to_include_hrefs("results", vms_openstack_list) + expect_result_resources_to_include_hrefs("results", [vms_url(vm_openstack1.compressed_id), vms_url(vm_openstack2.compressed_id)]) end end @@ -656,7 +662,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:delete)) - expect_single_action_result(:success => true, :message => "deleting", :href => vm_url, :task => true) + expect_single_action_result(:success => true, :message => "deleting", :href => vms_url(vm.compressed_id), :task => true) end it "deletes a vm via a resource DELETE" do @@ -706,7 +712,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:set_owner, "owner" => "bad_user")) - expect_single_action_result(:success => false, :message => /.*/, :href => vm_url) + expect_single_action_result(:success => false, :message => /.*/, :href => vms_url(vm.compressed_id)) end it "set_owner to a vm" do @@ -714,7 +720,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:set_owner, "owner" => api_config(:user))) - expect_single_action_result(:success => true, :message => "setting owner", :href => vm_url) + expect_single_action_result(:success => true, :message => "setting owner", :href => vms_url(vm.compressed_id)) expect(vm.reload.evm_owner).to eq(@user) end @@ -724,7 +730,7 @@ def update_raw_power_state(state, *vms) run_post(vms_url, gen_request(:set_owner, {"owner" => api_config(:user)}, vm1_url, vm2_url)) expect_multiple_action_result(2) - expect_result_resources_to_include_hrefs("results", vms_list) + expect_result_resources_to_include_hrefs("results", [vms_url(vm1.compressed_id), vms_url(vm2.compressed_id)]) expect(vm1.reload.evm_owner).to eq(@user) expect(vm2.reload.evm_owner).to eq(@user) end @@ -736,7 +742,6 @@ def update_raw_power_state(state, *vms) let(:vm_ca_url) { "#{vm_url}/custom_attributes" } let(:ca1_url) { "#{vm_ca_url}/#{ca1.id}" } let(:ca2_url) { "#{vm_ca_url}/#{ca2.id}" } - let(:vm_ca_url_list) { [ca1_url, ca2_url] } it "getting custom_attributes from a vm with no custom_attributes" do api_basic_authorize @@ -753,7 +758,9 @@ def update_raw_power_state(state, *vms) run_get vm_ca_url expect_query_result(:custom_attributes, 2) - expect_result_resources_to_include_hrefs("resources", vm_ca_url_list) + expect_result_resources_to_include_hrefs("resources", + ["#{vms_url(vm.compressed_id)}/custom_attributes/#{ca1.compressed_id}", + "#{vms_url(vm.compressed_id)}/custom_attributes/#{ca2.compressed_id}"]) end it "getting custom_attributes from a vm in expanded form" do @@ -878,7 +885,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:add_lifecycle_event, events[0])) - expect_single_action_result(:success => true, :message => /adding lifecycle event/i, :href => vm_url) + expect_single_action_result(:success => true, :message => /adding lifecycle event/i, :href => vms_url(vm.compressed_id)) expect(vm.lifecycle_events.size).to eq(1) expect(vm.lifecycle_events.first.event).to eq(events[0][:event]) end @@ -917,7 +924,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:scan)) - expect_single_action_result(:success => true, :message => "scanning", :href => vm_url, :task => true) + expect_single_action_result(:success => true, :message => "scanning", :href => vms_url(vm.compressed_id), :task => true) end it "scan multiple Vms" do @@ -926,7 +933,7 @@ def update_raw_power_state(state, *vms) run_post(vms_url, gen_request(:scan, nil, vm1_url, vm2_url)) expect_multiple_action_result(2, :task => true) - expect_result_resources_to_include_hrefs("results", vms_list) + expect_result_resources_to_include_hrefs("results", [vms_url(vm1.compressed_id), vms_url(vm2.compressed_id)]) end end @@ -952,7 +959,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:add_event, :event_type => "special", :event_message => "message")) - expect_single_action_result(:success => true, :message => /adding event/i, :href => vm_url) + expect_single_action_result(:success => true, :message => /adding event/i, :href => vms_url(vm.compressed_id)) end it "to multiple Vms" do @@ -968,12 +975,12 @@ def update_raw_power_state(state, *vms) { "message" => a_string_matching(/adding event .*etype1/i), "success" => true, - "href" => a_string_matching(vm1_url) + "href" => a_string_matching(vms_url(vm1.compressed_id)) }, { "message" => a_string_matching(/adding event .*etype2/i), "success" => true, - "href" => a_string_matching(vm2_url) + "href" => a_string_matching(vms_url(vm2.compressed_id)) } ) } @@ -1004,7 +1011,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:retire)) - expect_single_action_result(:success => true, :message => /#{vm.id}.* retiring/i, :href => vm_url) + expect_single_action_result(:success => true, :message => /#{vm.id}.* retiring/i, :href => vms_url(vm.compressed_id)) end it "to multiple Vms" do @@ -1017,12 +1024,12 @@ def update_raw_power_state(state, *vms) { "message" => a_string_matching(/#{vm1.id}.* retiring/i), "success" => true, - "href" => a_string_matching(vm1_url) + "href" => a_string_matching(vms_url(vm1.compressed_id)) }, { "message" => a_string_matching(/#{vm2.id}.* retiring/ii), "success" => true, - "href" => a_string_matching(vm2_url) + "href" => a_string_matching(vms_url(vm2.compressed_id)) } ) } @@ -1035,7 +1042,7 @@ def update_raw_power_state(state, *vms) date = 2.weeks.from_now run_post(vm_url, gen_request(:retire, :date => date.iso8601)) - expect_single_action_result(:success => true, :message => /#{vm.id}.* retiring/i, :href => vm_url) + expect_single_action_result(:success => true, :message => /#{vm.id}.* retiring/i, :href => vms_url(vm.compressed_id)) end end @@ -1061,7 +1068,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:reset)) - expect_single_action_result(:success => true, :message => /#{vm.id}.* resetting/i, :href => vm_url) + expect_single_action_result(:success => true, :message => /#{vm.id}.* resetting/i, :href => vms_url(vm.compressed_id)) end it "to multiple Vms" do @@ -1074,12 +1081,12 @@ def update_raw_power_state(state, *vms) a_hash_including( "message" => a_string_matching(/#{vm1.id}.* resetting/i), "success" => true, - "href" => a_string_matching(vm1_url) + "href" => a_string_matching(vms_url(vm1.compressed_id)) ), a_hash_including( "message" => a_string_matching(/#{vm2.id}.* resetting/i), "success" => true, - "href" => a_string_matching(vm2_url) + "href" => a_string_matching(vms_url(vm2.compressed_id)) ) ) } @@ -1110,7 +1117,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:shutdown_guest)) - expect_single_action_result(:success => true, :message => /#{vm.id}.* shutting down/i, :href => vm_url) + expect_single_action_result(:success => true, :message => /#{vm.id}.* shutting down/i, :href => vms_url(vm.compressed_id)) end it "to multiple Vms" do @@ -1123,12 +1130,12 @@ def update_raw_power_state(state, *vms) a_hash_including( "message" => a_string_matching(/#{vm1.id}.* shutting down/i), "success" => true, - "href" => a_string_matching(vm1_url) + "href" => a_string_matching(vms_url(vm1.compressed_id)) ), a_hash_including( "message" => a_string_matching(/#{vm2.id}.* shutting down/i), "success" => true, - "href" => a_string_matching(vm2_url) + "href" => a_string_matching(vms_url(vm2.compressed_id)) ) ) } @@ -1159,7 +1166,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:refresh)) - expect_single_action_result(:success => true, :message => /#{vm.id}.* refreshing/i, :href => vm_url) + expect_single_action_result(:success => true, :message => /#{vm.id}.* refreshing/i, :href => vms_url(vm.compressed_id)) end it "to multiple Vms" do @@ -1172,12 +1179,12 @@ def update_raw_power_state(state, *vms) a_hash_including( "message" => a_string_matching(/#{vm1.id}.* refreshing/i), "success" => true, - "href" => a_string_matching(vm1_url) + "href" => a_string_matching(vms_url(vm1.compressed_id)) ), a_hash_including( "message" => a_string_matching(/#{vm2.id}.* refreshing/i), "success" => true, - "href" => a_string_matching(vm2_url) + "href" => a_string_matching(vms_url(vm2.compressed_id)) ) ) } @@ -1208,7 +1215,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:reboot_guest)) - expect_single_action_result(:success => true, :message => /#{vm.id}.* rebooting/i, :href => vm_url) + expect_single_action_result(:success => true, :message => /#{vm.id}.* rebooting/i, :href => vms_url(vm.compressed_id)) end it "to multiple Vms" do @@ -1221,12 +1228,12 @@ def update_raw_power_state(state, *vms) a_hash_including( "message" => a_string_matching(/#{vm1.id}.* rebooting/i,), "success" => true, - "href" => a_string_matching(vm1_url) + "href" => a_string_matching(vms_url(vm1.compressed_id)) ), a_hash_including( "message" => a_string_matching(/#{vm2.id}.* rebooting/i), "success" => true, - "href" => a_string_matching(vm2_url) + "href" => a_string_matching(vms_url(vm2.compressed_id)) ) ) } @@ -1257,7 +1264,7 @@ def update_raw_power_state(state, *vms) run_post(vm_url, gen_request(:request_console)) - expect_single_action_result(:success => true, :message => /#{vm.id}.* requesting console/i, :href => vm_url) + expect_single_action_result(:success => true, :message => /#{vm.id}.* requesting console/i, :href => vms_url(vm.compressed_id)) end end @@ -1316,7 +1323,7 @@ def update_raw_power_state(state, *vms) run_get vms_url, :expand => "resources", :filter => ["tags.name='#{tag2[:path]}'"] expect_query_result(:vms, 1, 2) - expect_result_resources_to_include_hrefs("resources", [vm2_url]) + expect_result_resources_to_include_hrefs("resources", [vms_url(vm2.compressed_id)]) end it "assigns a tag to a Vm without appropriate role" do @@ -1333,7 +1340,7 @@ def update_raw_power_state(state, *vms) run_post(vm1_tags_url, gen_request(:assign, :category => tag1[:category], :name => tag1[:name])) expect_tagging_result( - [{:success => true, :href => vm1_url, :tag_category => tag1[:category], :tag_name => tag1[:name]}] + [{:success => true, :href => vms_url(vm1.compressed_id), :tag_category => tag1[:category], :tag_name => tag1[:name]}] ) end @@ -1343,7 +1350,7 @@ def update_raw_power_state(state, *vms) run_post(vm1_tags_url, gen_request(:assign, :name => tag1[:path])) expect_tagging_result( - [{:success => true, :href => vm1_url, :tag_category => tag1[:category], :tag_name => tag1[:name]}] + [{:success => true, :href => vms_url(vm1.compressed_id), :tag_category => tag1[:category], :tag_name => tag1[:name]}] ) end @@ -1353,7 +1360,7 @@ def update_raw_power_state(state, *vms) run_post(vm1_tags_url, gen_request(:assign, :href => tags_url(Tag.find_by(:name => tag1[:path]).id))) expect_tagging_result( - [{:success => true, :href => vm1_url, :tag_category => tag1[:category], :tag_name => tag1[:name]}] + [{:success => true, :href => vms_url(vm1.compressed_id), :tag_category => tag1[:category], :tag_name => tag1[:name]}] ) end @@ -1371,7 +1378,7 @@ def update_raw_power_state(state, *vms) run_post(vm1_tags_url, gen_request(:assign, :name => "/managed/bad_category/bad_name")) expect_tagging_result( - [{:success => false, :href => vm1_url, :tag_category => "bad_category", :tag_name => "bad_name"}] + [{:success => false, :href => vms_url(vm1.compressed_id), :tag_category => "bad_category", :tag_name => "bad_name"}] ) end @@ -1381,8 +1388,8 @@ def update_raw_power_state(state, *vms) run_post(vm1_tags_url, gen_request(:assign, [{:name => tag1[:path]}, {:name => tag2[:path]}])) expect_tagging_result( - [{:success => true, :href => vm1_url, :tag_category => tag1[:category], :tag_name => tag1[:name]}, - {:success => true, :href => vm1_url, :tag_category => tag2[:category], :tag_name => tag2[:name]}] + [{:success => true, :href => vms_url(vm1.compressed_id), :tag_category => tag1[:category], :tag_name => tag1[:name]}, + {:success => true, :href => vms_url(vm1.compressed_id), :tag_category => tag2[:category], :tag_name => tag2[:name]}] ) end @@ -1393,8 +1400,8 @@ def update_raw_power_state(state, *vms) run_post(vm1_tags_url, gen_request(:assign, [{:name => tag1[:path]}, {:href => tags_url(tag.id)}])) expect_tagging_result( - [{:success => true, :href => vm1_url, :tag_category => tag1[:category], :tag_name => tag1[:name]}, - {:success => true, :href => vm1_url, :tag_category => tag2[:category], :tag_name => tag2[:name]}] + [{:success => true, :href => vms_url(vm1.compressed_id), :tag_category => tag1[:category], :tag_name => tag1[:name]}, + {:success => true, :href => vms_url(vm1.compressed_id), :tag_category => tag2[:category], :tag_name => tag2[:name]}] ) end @@ -1412,7 +1419,7 @@ def update_raw_power_state(state, *vms) run_post(vm2_tags_url, gen_request(:unassign, :category => tag1[:category], :name => tag1[:name])) expect_tagging_result( - [{:success => true, :href => vm2_url, :tag_category => tag1[:category], :tag_name => tag1[:name]}] + [{:success => true, :href => vms_url(vm2.compressed_id), :tag_category => tag1[:category], :tag_name => tag1[:name]}] ) expect(vm2.tags.count).to eq(1) expect(vm2.tags.first.name).to eq(tag2[:path]) @@ -1425,8 +1432,8 @@ def update_raw_power_state(state, *vms) run_post(vm2_tags_url, gen_request(:unassign, [{:name => tag1[:path]}, {:href => tags_url(tag.id)}])) expect_tagging_result( - [{:success => true, :href => vm2_url, :tag_category => tag1[:category], :tag_name => tag1[:name]}, - {:success => true, :href => vm2_url, :tag_category => tag2[:category], :tag_name => tag2[:name]}] + [{:success => true, :href => vms_url(vm2.compressed_id), :tag_category => tag1[:category], :tag_name => tag1[:name]}, + {:success => true, :href => vms_url(vm2.compressed_id), :tag_category => tag2[:category], :tag_name => tag2[:name]}] ) expect(vm2.tags.count).to eq(0) end @@ -1515,7 +1522,7 @@ def update_raw_power_state(state, *vms) expected = { "success" => true, "message" => "Invoked custom action test button for vms id: #{vm.id}", - "href" => a_string_matching(vms_url(vm.id)) + "href" => a_string_matching(vms_url(vm.compressed_id)) } expect(response.parsed_body).to include(expected) end