Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect tasks subcollection to request_tasks #15357

Merged
merged 2 commits into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@

Array(collection.subcollections).each do |subcollection_name|
Api::ApiConfig.collections[subcollection_name].verbs.each do |verb|
if subcollection_name == :tasks && verb == :get
get "/:c_id/#{subcollection_name}", :to => redirect { |path_params, _req| "/api/#{collection_name}/#{path_params[:c_id]}/request_tasks" }
get "/:c_id/#{subcollection_name}/:s_id", :to => redirect { |path_params, _req| "/api/#{collection_name}/#{path_params[:c_id]}/request_tasks/#{path_params[:s_id]}" }
end

case verb
when :get
get "/:c_id/#{subcollection_name}", :action => :index
Expand Down
36 changes: 36 additions & 0 deletions spec/requests/api/automation_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,40 @@
expect(response).to have_http_status(:ok)
end
end

context 'Tasks subcollection' do
let(:automation_request) { FactoryGirl.create(:automation_request) }

it 'redirects to request_tasks subcollection' do
task = FactoryGirl.create(:miq_request_task, :miq_request_id => automation_request.id)
api_basic_authorize

run_get("#{automation_requests_url(automation_request.id)}/tasks")

expect(response).to have_http_status(:moved_permanently)
expect(response.redirect?).to be_truthy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this expectation is redundant - the one above checks that it is a 301, this one checks that it is in the set of many redirect codes

expect(response.redirect_url).to include("#{automation_requests_url(automation_request.id)}/request_tasks")

run_get response.redirect_url, :expand => :resources
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I like the idea of testing the whole flow of being redirected in this test, on the flip side this could also be a test duplication. I think we could assume that this subsequent request will do the right thing, especially if it is tested elsewhere (assuming it is). So I'm not sure this extra check is necessary. WDYT?


expect(response).to have_http_status(:ok)
expect(response.parsed_body['resources'].first['id']).to eq(task.id)
end

it 'redirects to request_tasks subresources' do
task = FactoryGirl.create(:miq_request_task, :miq_request_id => automation_request.id)
api_basic_authorize

run_get("#{automation_requests_url(automation_request.id)}/tasks/#{task.id}")

expect(response).to have_http_status(:moved_permanently)
expect(response.redirect?).to be_truthy
expect(response.redirect_url).to include("#{automation_requests_url(automation_request.id)}/request_tasks/#{task.id}")

run_get response.redirect_url

expect(response).to have_http_status(:ok)
expect(response.parsed_body['id']).to eq(task.id)
end
end
end
34 changes: 34 additions & 0 deletions spec/requests/api/service_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -574,4 +574,38 @@ def expect_result_to_have_user_email(email)
expect(response.parsed_body).to include(expected)
end
end

context 'Tasks subcollection' do
it 'redirects to request_tasks subcollection' do
task = FactoryGirl.create(:miq_request_task, :miq_request_id => service_request.id)
api_basic_authorize collection_action_identifier(:service_requests, :read, :get)

run_get("#{service_requests_url(service_request.id)}/tasks")

expect(response).to have_http_status(:moved_permanently)
expect(response.redirect?).to be_truthy
expect(response.redirect_url).to include("#{service_requests_url(service_request.id)}/request_tasks")

run_get response.redirect_url, :expand => :resources

expect(response).to have_http_status(:ok)
expect(response.parsed_body["resources"].first["id"]).to eq(task.id)
end

it 'redirects to request_tasks subresources' do
task = FactoryGirl.create(:miq_request_task, :miq_request_id => service_request.id)
api_basic_authorize action_identifier(:services, :read, :resource_actions, :get)

run_get("#{service_requests_url(service_request.id)}/tasks/#{task.id}")

expect(response).to have_http_status(:moved_permanently)
expect(response.redirect?).to be_truthy
expect(response.redirect_url).to include("#{service_requests_url(service_request.id)}/request_tasks/#{task.id}")

run_get response.redirect_url

expect(response).to have_http_status(:ok)
expect(response.parsed_body['id']).to eq(task.id)
end
end
end