Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.

Changed status to string, make specs compatible with latest common gem #304

Merged
merged 1 commit into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugin "bundler-inject", "~> 1.1"
require File.join(Bundler::Plugin.index.load_paths("bundler-inject")[0], "bundler-inject") rescue nil

gem 'activerecord-virtual_attributes', '~> 1.5'
gem 'insights-api-common', '= 3.8'
gem 'insights-api-common', '~> 4.0'
gem 'jbuilder', '~> 2.0'
gem 'json-schema', '~> 2.8'
gem 'manageiq-loggers', "~> 0.4.0", ">= 0.4.2"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class RootController < ApplicationController
skip_before_action :validate_primary_collection_id

def invalid_url_error
error_document = Insights::API::Common::ErrorDocument.new.add(404, "Invalid URL /#{params[:path]} specified.")
error_document = Insights::API::Common::ErrorDocument.new.add("404", "Invalid URL /#{params[:path]} specified.")
render :json => error_document.to_h, :status => :not_found
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ApplicationController < ActionController::API
around_action :with_current_request

rescue_from ActiveRecord::RecordNotFound do |exception|
error_document = Insights::API::Common::ErrorDocument.new.add(404, "Record not found")
error_document = Insights::API::Common::ErrorDocument.new.add("404", "Record not found")
render :json => error_document.to_h, :status => :not_found
end

Expand All @@ -26,10 +26,10 @@ def with_current_request
ActsAsTenant.without_tenant { yield }
end
rescue KeyError, Insights::API::Common::IdentityError
error_document = Insights::API::Common::ErrorDocument.new.add(401, 'Unauthorized')
error_document = Insights::API::Common::ErrorDocument.new.add('401', 'Unauthorized')
render :json => error_document.to_h, :status => error_document.status
rescue Insights::API::Common::EntitlementError
error_document = Insights::API::Common::ErrorDocument.new.add(403, 'Forbidden')
error_document = Insights::API::Common::ErrorDocument.new.add('403', 'Forbidden')
render :json => error_document.to_h, :status => error_document.status
end
end
Expand Down
14 changes: 7 additions & 7 deletions spec/requests/api/v1.0/filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def expect_failure(query, *errors)

expect(response).to have_attributes(
:parsed_body => {
"errors" => errors.collect { |e| {"detail" => e, "status" => 400} }
"errors" => errors.collect { |e| {"detail" => e, "status" => "400"} }
},
:status => 400,
)
Expand Down Expand Up @@ -131,9 +131,9 @@ def expect_success(query, *results)
it("unknown attribute") { expect_failure("filter[xxx]", "Insights::API::Common::Filter::Error: found unpermitted parameter: xxx") }

context "unsupported comparator" do
it("on an integer") { expect_failure("filter[id][xxx]=4", "Insights::API::Common::Filter::Error: unsupported integer comparator: xxx") }
it("on a string") { expect_failure("filter[name][xxx]=4", "Insights::API::Common::Filter::Error: unsupported string comparator: xxx") }
it("on a timestamp") { expect_failure("filter[created_at][xxx]=4", "Insights::API::Common::Filter::Error: unsupported timestamp comparator: xxx") }
it("on an integer") { expect_failure("filter[id][xxx]=4", "Insights::API::Common::Filter::Error: found unpermitted parameter: id.xxx") }
it("on a string") { expect_failure("filter[name][xxx]=4", "Insights::API::Common::Filter::Error: found unpermitted parameter: name.xxx") }
it("on a timestamp") { expect_failure("filter[created_at][xxx]=4", "Insights::API::Common::Filter::Error: found unpermitted parameter: created_at.xxx") }
end

it "unsupported attribute type" do
Expand All @@ -143,7 +143,7 @@ def expect_success(query, *results)
get("/api/v1.0/vms?filter[mac_addresses]=a", :headers => headers)

expect(response.status).to eq(400)
expect(response.parsed_body["errors"]).to eq([{"detail"=>"Insights::API::Common::Filter::Error: unsupported attribute type for: mac_addresses", "status"=>400}])
expect(response.parsed_body["errors"]).to eq([{"detail"=>"Insights::API::Common::Filter::Error: unsupported attribute type for: mac_addresses", "status"=>"400"}])
end

it "invalid attribute" do
Expand All @@ -153,7 +153,7 @@ def expect_success(query, *results)
get("/api/v1.0/vms?filter[bogus_attribute]=a", :headers => headers)

expect(response.status).to eq(400)
expect(response.parsed_body["errors"]).to eq([{"detail"=>"Insights::API::Common::Filter::Error: found unpermitted parameter: bogus_attribute", "status"=>400}])
expect(response.parsed_body["errors"]).to eq([{"detail"=>"Insights::API::Common::Filter::Error: found unpermitted parameter: bogus_attribute", "status"=>"400"}])
end

it "multiple invalid attributes mixed with a valid attribute" do
Expand All @@ -165,7 +165,7 @@ def expect_success(query, *results)
expect(response.status).to eq(400)
expect(response.parsed_body["errors"]).to eq(
[
{"detail" => "Insights::API::Common::Filter::Error: unsupported attribute type for: mac_addresses, found unpermitted parameter: bogus_attribute", "status" => 400}
{"detail" => "Insights::API::Common::Filter::Error: unsupported attribute type for: mac_addresses, found unpermitted parameter: bogus_attribute", "status" => "400"}
]
)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/api/v1.0/service_offering_icon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def subcollection_path(id)

expect(response).to have_attributes(
:status => 404,
:parsed_body => {"errors"=>[{"detail"=>"Record not found", "status"=>404}]},
:parsed_body => {"errors"=>[{"detail"=>"Record not found", "status"=>"404"}]},
)
end

Expand All @@ -66,7 +66,7 @@ def subcollection_path(id)

expect(response).to have_attributes(
:status => 400,
:parsed_body => {"errors"=>[{"detail"=>"Insights::API::Common::ApplicationControllerMixins::RequestPath::RequestPathError: ID is invalid", "status"=>400}]},
:parsed_body => {"errors"=>[{"detail"=>"Insights::API::Common::ApplicationControllerMixins::RequestPath::RequestPathError: ID is invalid", "status"=>"400"}]},
)
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/requests/api/v1.0/shared_examples_for_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def instance_path(id)

expect(response).to have_attributes(
:status => 404,
:parsed_body => {"errors" => [{"detail" => "Record not found", "status" => 404}]}
:parsed_body => {"errors" => [{"detail" => "Record not found", "status" => "404"}]}
)
end

Expand All @@ -59,7 +59,7 @@ def instance_path(id)

expect(response).to have_attributes(
:status => 400,
:parsed_body => {"errors" => [{"detail" => "Insights::API::Common::ApplicationControllerMixins::RequestPath::RequestPathError: ID is invalid", "status" => 400}]}
:parsed_body => {"errors" => [{"detail" => "Insights::API::Common::ApplicationControllerMixins::RequestPath::RequestPathError: ID is invalid", "status" => "400"}]}
)
end
end
Expand Down Expand Up @@ -95,7 +95,7 @@ def subcollection_path(id)

expect(response).to have_attributes(
:status => 404,
:parsed_body => {"errors" => [{"detail" => "Record not found", "status" => 404}]}
:parsed_body => {"errors" => [{"detail" => "Record not found", "status" => "404"}]}
)
end

Expand All @@ -104,7 +104,7 @@ def subcollection_path(id)

expect(response).to have_attributes(
:status => 400,
:parsed_body => {"errors" => [{"detail" => "Insights::API::Common::ApplicationControllerMixins::RequestPath::RequestPathError: ID is invalid", "status" => 400}]}
:parsed_body => {"errors" => [{"detail" => "Insights::API::Common::ApplicationControllerMixins::RequestPath::RequestPathError: ID is invalid", "status" => "400"}]}
)
end
end
Expand Down
14 changes: 7 additions & 7 deletions spec/requests/api/v2.0/filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def expect_failure(query, *errors)

expect(response).to have_attributes(
:parsed_body => {
"errors" => errors.collect { |e| {"detail" => e, "status" => 400} }
"errors" => errors.collect { |e| {"detail" => e, "status" => "400"} }
},
:status => 400,
)
Expand Down Expand Up @@ -131,9 +131,9 @@ def expect_success(query, *results)
it("unknown attribute") { expect_failure("filter[xxx]", "Insights::API::Common::Filter::Error: found unpermitted parameter: xxx") }

context "unsupported comparator" do
it("on an integer") { expect_failure("filter[id][xxx]=4", "Insights::API::Common::Filter::Error: unsupported integer comparator: xxx") }
it("on a string") { expect_failure("filter[name][xxx]=4", "Insights::API::Common::Filter::Error: unsupported string comparator: xxx") }
it("on a timestamp") { expect_failure("filter[created_at][xxx]=4", "Insights::API::Common::Filter::Error: unsupported timestamp comparator: xxx") }
it("on an integer") { expect_failure("filter[id][xxx]=4", "Insights::API::Common::Filter::Error: found unpermitted parameter: id.xxx") }
it("on a string") { expect_failure("filter[name][xxx]=4", "Insights::API::Common::Filter::Error: found unpermitted parameter: name.xxx") }
it("on a timestamp") { expect_failure("filter[created_at][xxx]=4", "Insights::API::Common::Filter::Error: found unpermitted parameter: created_at.xxx") }
end

it "unsupported attribute type" do
Expand All @@ -143,7 +143,7 @@ def expect_success(query, *results)
get("/api/v2.0/vms?filter[mac_addresses]=a", :headers => headers)

expect(response.status).to eq(400)
expect(response.parsed_body["errors"]).to eq([{"detail"=>"Insights::API::Common::Filter::Error: unsupported attribute type for: mac_addresses", "status"=>400}])
expect(response.parsed_body["errors"]).to eq([{"detail"=>"Insights::API::Common::Filter::Error: unsupported attribute type for: mac_addresses", "status"=>"400"}])
end

it "invalid attribute" do
Expand All @@ -153,7 +153,7 @@ def expect_success(query, *results)
get("/api/v2.0/vms?filter[bogus_attribute]=a", :headers => headers)

expect(response.status).to eq(400)
expect(response.parsed_body["errors"]).to eq([{"detail"=>"Insights::API::Common::Filter::Error: found unpermitted parameter: bogus_attribute", "status"=>400}])
expect(response.parsed_body["errors"]).to eq([{"detail"=>"Insights::API::Common::Filter::Error: found unpermitted parameter: bogus_attribute", "status"=>"400"}])
end

it "multiple invalid attributes mixed with a valid attribute" do
Expand All @@ -165,7 +165,7 @@ def expect_success(query, *results)
expect(response.status).to eq(400)
expect(response.parsed_body["errors"]).to eq(
[
{"detail" => "Insights::API::Common::Filter::Error: unsupported attribute type for: mac_addresses, found unpermitted parameter: bogus_attribute", "status" => 400}
{"detail" => "Insights::API::Common::Filter::Error: unsupported attribute type for: mac_addresses, found unpermitted parameter: bogus_attribute", "status" => "400"}
]
)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/api/v2.0/service_offering_icon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def subcollection_path(id)

expect(response).to have_attributes(
:status => 404,
:parsed_body => {"errors"=>[{"detail"=>"Record not found", "status"=>404}]},
:parsed_body => {"errors"=>[{"detail"=>"Record not found", "status"=>"404"}]},
)
end

Expand All @@ -66,7 +66,7 @@ def subcollection_path(id)

expect(response).to have_attributes(
:status => 400,
:parsed_body => {"errors"=>[{"detail"=>"Insights::API::Common::ApplicationControllerMixins::RequestPath::RequestPathError: ID is invalid", "status"=>400}]},
:parsed_body => {"errors"=>[{"detail"=>"Insights::API::Common::ApplicationControllerMixins::RequestPath::RequestPathError: ID is invalid", "status"=>"400"}]},
)
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/requests/api/v2.0/shared_examples_for_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def instance_path(id)

expect(response).to have_attributes(
:status => 404,
:parsed_body => {"errors" => [{"detail" => "Record not found", "status" => 404}]}
:parsed_body => {"errors" => [{"detail" => "Record not found", "status" => "404"}]}
)
end

Expand All @@ -62,7 +62,7 @@ def instance_path(id)

expect(response).to have_attributes(
:status => 400,
:parsed_body => {"errors" => [{"detail" => "Insights::API::Common::ApplicationControllerMixins::RequestPath::RequestPathError: ID is invalid", "status" => 400}]}
:parsed_body => {"errors" => [{"detail" => "Insights::API::Common::ApplicationControllerMixins::RequestPath::RequestPathError: ID is invalid", "status" => "400"}]}
)
end
end
Expand Down Expand Up @@ -98,7 +98,7 @@ def subcollection_path(id)

expect(response).to have_attributes(
:status => 404,
:parsed_body => {"errors" => [{"detail" => "Record not found", "status" => 404}]}
:parsed_body => {"errors" => [{"detail" => "Record not found", "status" => "404"}]}
)
end

Expand All @@ -107,7 +107,7 @@ def subcollection_path(id)

expect(response).to have_attributes(
:status => 400,
:parsed_body => {"errors" => [{"detail" => "Insights::API::Common::ApplicationControllerMixins::RequestPath::RequestPathError: ID is invalid", "status" => 400}]}
:parsed_body => {"errors" => [{"detail" => "Insights::API::Common::ApplicationControllerMixins::RequestPath::RequestPathError: ID is invalid", "status" => "400"}]}
)
end
end
Expand Down
14 changes: 7 additions & 7 deletions spec/requests/api/v3.0/filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def expect_failure(query, *errors)

expect(response).to have_attributes(
:parsed_body => {
"errors" => errors.collect { |e| {"detail" => e, "status" => 400} }
"errors" => errors.collect { |e| {"detail" => e, "status" => "400"} }
},
:status => 400,
)
Expand Down Expand Up @@ -140,9 +140,9 @@ def expect_tag_success(instance, query, *results)
it("unknown attribute") { expect_failure("filter[xxx]", "Insights::API::Common::Filter::Error: found unpermitted parameter: xxx") }

context "unsupported comparator" do
it("on an integer") { expect_failure("filter[id][xxx]=4", "Insights::API::Common::Filter::Error: unsupported integer comparator: xxx") }
it("on a string") { expect_failure("filter[name][xxx]=4", "Insights::API::Common::Filter::Error: unsupported string comparator: xxx") }
it("on a timestamp") { expect_failure("filter[created_at][xxx]=4", "Insights::API::Common::Filter::Error: unsupported timestamp comparator: xxx") }
it("on an integer") { expect_failure("filter[id][xxx]=4", "Insights::API::Common::Filter::Error: found unpermitted parameter: id.xxx") }
it("on a string") { expect_failure("filter[name][xxx]=4", "Insights::API::Common::Filter::Error: found unpermitted parameter: name.xxx") }
it("on a timestamp") { expect_failure("filter[created_at][xxx]=4", "Insights::API::Common::Filter::Error: found unpermitted parameter: created_at.xxx") }
end

it "unsupported attribute type" do
Expand All @@ -152,7 +152,7 @@ def expect_tag_success(instance, query, *results)
get("/api/v3.0/vms?filter[mac_addresses]=a", :headers => headers)

expect(response.status).to eq(400)
expect(response.parsed_body["errors"]).to eq([{"detail"=>"Insights::API::Common::Filter::Error: unsupported attribute type for: mac_addresses", "status"=>400}])
expect(response.parsed_body["errors"]).to eq([{"detail"=>"Insights::API::Common::Filter::Error: unsupported attribute type for: mac_addresses", "status"=>"400"}])
end

it "invalid attribute" do
Expand All @@ -162,7 +162,7 @@ def expect_tag_success(instance, query, *results)
get("/api/v3.0/vms?filter[bogus_attribute]=a", :headers => headers)

expect(response.status).to eq(400)
expect(response.parsed_body["errors"]).to eq([{"detail"=>"Insights::API::Common::Filter::Error: found unpermitted parameter: bogus_attribute", "status"=>400}])
expect(response.parsed_body["errors"]).to eq([{"detail"=>"Insights::API::Common::Filter::Error: found unpermitted parameter: bogus_attribute", "status"=>"400"}])
end

it "multiple invalid attributes mixed with a valid attribute" do
Expand All @@ -174,7 +174,7 @@ def expect_tag_success(instance, query, *results)
expect(response.status).to eq(400)
expect(response.parsed_body["errors"]).to eq(
[
{"detail" => "Insights::API::Common::Filter::Error: unsupported attribute type for: mac_addresses, found unpermitted parameter: bogus_attribute", "status" => 400}
{"detail" => "Insights::API::Common::Filter::Error: unsupported attribute type for: mac_addresses, found unpermitted parameter: bogus_attribute", "status" => "400"}
]
)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/api/v3.0/service_offering_icon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def subcollection_path(id)

expect(response).to have_attributes(
:status => 404,
:parsed_body => {"errors"=>[{"detail"=>"Record not found", "status"=>404}]},
:parsed_body => {"errors"=>[{"detail"=>"Record not found", "status"=>"404"}]},
)
end

Expand All @@ -66,7 +66,7 @@ def subcollection_path(id)

expect(response).to have_attributes(
:status => 400,
:parsed_body => {"errors"=>[{"detail"=>"Insights::API::Common::ApplicationControllerMixins::RequestPath::RequestPathError: ID is invalid", "status"=>400}]},
:parsed_body => {"errors"=>[{"detail"=>"Insights::API::Common::ApplicationControllerMixins::RequestPath::RequestPathError: ID is invalid", "status"=>"400"}]},
)
end
end
Expand Down
Loading