Skip to content

Commit

Permalink
Run rubocop --only Rails/HttpPositionalArguments --auto-correct
Browse files Browse the repository at this point in the history
  • Loading branch information
imtayadeway committed Sep 13, 2017
1 parent bb5e606 commit f79513c
Show file tree
Hide file tree
Showing 58 changed files with 1,578 additions and 1,317 deletions.
22 changes: 11 additions & 11 deletions spec/requests/actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

it "creates new action" do
api_basic_authorize collection_action_identifier(:actions, :create)
post(api_actions_url, sample_action)
post(api_actions_url, :params => sample_action)

expect(response).to have_http_status(:ok)

Expand All @@ -34,8 +34,8 @@

it "creates new actions" do
api_basic_authorize collection_action_identifier(:actions, :create)
post(api_actions_url, gen_request(:create, [sample_action,
sample_action.merge(:name => "foo", :description => "bar")]))
post(api_actions_url, :params => gen_request(:create, [sample_action,
sample_action.merge(:name => "foo", :description => "bar")]))
expect(response).to have_http_status(:ok)

expect(response.parsed_body["results"].count).to eq(2)
Expand All @@ -54,7 +54,7 @@

it "deletes action" do
api_basic_authorize collection_action_identifier(:actions, :delete)
post(api_actions_url, gen_request(:delete, "name" => action.name, "href" => action_url))
post(api_actions_url, :params => gen_request(:delete, "name" => action.name, "href" => action_url))

expect(response).to have_http_status(:ok)

Expand All @@ -63,10 +63,10 @@

it "deletes actions" do
api_basic_authorize collection_action_identifier(:actions, :delete)
post(api_actions_url, gen_request(:delete, [{"name" => actions.first.name,
"href" => api_action_url(nil, actions.first)},
{"name" => actions.second.name,
"href" => api_action_url(nil, actions.second)}]))
post(api_actions_url, :params => gen_request(:delete, [{"name" => actions.first.name,
"href" => api_action_url(nil, actions.first)},
{"name" => actions.second.name,
"href" => api_action_url(nil, actions.second)}]))

expect(response).to have_http_status(:ok)

Expand All @@ -84,7 +84,7 @@

it "edits new action" do
api_basic_authorize collection_action_identifier(:actions, :edit)
post(action_url, gen_request(:edit, "description" => "change"))
post(action_url, :params => gen_request(:edit, "description" => "change"))

expect(response).to have_http_status(:ok)

Expand All @@ -93,8 +93,8 @@

it "edits new actions" do
api_basic_authorize collection_action_identifier(:actions, :edit)
post(api_actions_url, gen_request(:edit, [{"id" => actions.first.id, "description" => "change"},
{"id" => actions.second.id, "description" => "change2"}]))
post(api_actions_url, :params => gen_request(:edit, [{"id" => actions.first.id, "description" => "change"},
{"id" => actions.second.id, "description" => "change2"}]))
expect(response).to have_http_status(:ok)

expect(response.parsed_body["results"].count).to eq(2)
Expand Down
51 changes: 29 additions & 22 deletions spec/requests/alert_definitions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"description" => "Test Alert Definition",
"db" => "ContainerNode"
}
post(api_alert_definitions_url, alert_definition)
post(api_alert_definitions_url, :params => alert_definition)
expect(response).to have_http_status(:forbidden)
end

Expand All @@ -76,7 +76,7 @@
"enabled" => true
}
api_basic_authorize collection_action_identifier(:alert_definitions, :create)
post(api_alert_definitions_url, sample_alert_definition)
post(api_alert_definitions_url, :params => sample_alert_definition)
expect(response).to have_http_status(:ok)
alert_definition = MiqAlert.find(ApplicationRecord.uncompress_id(response.parsed_body["results"].first["id"]))
expect(alert_definition).to be_truthy
Expand All @@ -94,7 +94,7 @@
it "deletes an alert definition via POST" do
api_basic_authorize action_identifier(:alert_definitions, :delete, :resource_actions, :post)
alert_definition = FactoryGirl.create(:miq_alert)
post(api_alert_definition_url(nil, alert_definition), gen_request(:delete))
post(api_alert_definition_url(nil, alert_definition), :params => gen_request(:delete))
expect(response).to have_http_status(:ok)
expect_single_action_result(:success => true,
:message => "alert_definitions id: #{alert_definition.id} deleting",
Expand All @@ -112,8 +112,8 @@
it "deletes alert definitions" do
api_basic_authorize collection_action_identifier(:alert_definitions, :delete)
alert_definitions = FactoryGirl.create_list(:miq_alert, 2)
post(api_alert_definitions_url, gen_request(:delete, [{"id" => alert_definitions.first.id},
{"id" => alert_definitions.second.id}]))
post(api_alert_definitions_url, :params => gen_request(:delete, [{"id" => alert_definitions.first.id},
{"id" => alert_definitions.second.id}]))
expect(response).to have_http_status(:ok)
expect(response.parsed_body["results"].count).to eq(2)
end
Expand All @@ -128,8 +128,15 @@

post(
api_alert_definition_url(nil, alert_definition),
:action => "edit",
:options => { :notifications => {:delay_next_evaluation => 60, :evm_event => {} } }
:params => {
:action => "edit",
:options => {
:notifications => {
:delay_next_evaluation => 60,
:evm_event => {}
}
}
}
)

expected = {
Expand All @@ -152,10 +159,10 @@
it "edits alert definitions" do
api_basic_authorize collection_action_identifier(:alert_definitions, :edit)
alert_definitions = FactoryGirl.create_list(:miq_alert, 2)
post(api_alert_definitions_url, gen_request(:edit, [{"id" => alert_definitions.first.id,
"description" => "Updated Test Alert 1"},
{"id" => alert_definitions.second.id,
"description" => "Updated Test Alert 2"}]))
post(api_alert_definitions_url, :params => gen_request(:edit, [{"id" => alert_definitions.first.id,
"description" => "Updated Test Alert 1"},
{"id" => alert_definitions.second.id,
"description" => "Updated Test Alert 2"}]))

expect(response).to have_http_status(:ok)
expect(response.parsed_body["results"].count).to eq(2)
Expand Down Expand Up @@ -212,7 +219,7 @@

alert_definitions = FactoryGirl.create_list(:miq_alert, 2)
alert_definition_profile = FactoryGirl.create(:miq_alert_set, :alerts => alert_definitions)
get(api_alert_definition_profile_alert_definitions_url(nil, alert_definition_profile), :expand => "resources")
get(api_alert_definition_profile_alert_definitions_url(nil, alert_definition_profile), :params => { :expand => "resources" })

expect(response).to have_http_status(:ok)
expect_result_resources_to_include_hrefs(
Expand All @@ -227,7 +234,7 @@

alert_definition = FactoryGirl.create(:miq_alert)
alert_definition_profile = FactoryGirl.create(:miq_alert_set, :alerts => [alert_definition])
get(api_alert_definition_profile_url(nil, alert_definition_profile), :expand => "alert_definitions")
get(api_alert_definition_profile_url(nil, alert_definition_profile), :params => { :expand => "alert_definitions" })

expect(response).to have_http_status(:ok)
expect_single_resource_query(
Expand All @@ -245,7 +252,7 @@
"mode" => "ContainerNode",
}
api_basic_authorize collection_action_identifier(:alert_definition_profiles, :create)
post(api_alert_definition_profiles_url, sample_alert_definition_profile)
post(api_alert_definition_profiles_url, :params => sample_alert_definition_profile)

expect(response).to have_http_status(:ok)
id = ApplicationRecord.uncompress_id(response.parsed_body["results"].first["id"])
Expand All @@ -260,7 +267,7 @@
it "deletes an alert definition profile via POST" do
api_basic_authorize action_identifier(:alert_definition_profiles, :delete, :resource_actions, :post)
alert_definition_profile = FactoryGirl.create(:miq_alert_set)
post(api_alert_definition_profile_url(nil, alert_definition_profile), gen_request(:delete))
post(api_alert_definition_profile_url(nil, alert_definition_profile), :params => gen_request(:delete))

expect(response).to have_http_status(:ok)
expect_single_action_result(:success => true,
Expand All @@ -280,20 +287,20 @@
it "deletes alert definition profiles" do
api_basic_authorize collection_action_identifier(:alert_definition_profiles, :delete)
alert_definition_profiles = FactoryGirl.create_list(:miq_alert_set, 2)
post(api_alert_definition_profiles_url, gen_request(:delete, [{"id" => alert_definition_profiles.first.id},
{"id" => alert_definition_profiles.second.id}]))
post(api_alert_definition_profiles_url, :params => gen_request(:delete, [{"id" => alert_definition_profiles.first.id},
{"id" => alert_definition_profiles.second.id}]))
expect(response).to have_http_status(:ok)
expect(response.parsed_body["results"].count).to eq(2)
end

it "edits alert definition profiles" do
api_basic_authorize action_identifier(:alert_definition_profiles, :edit, :resource_actions, :post)
alert_definition_profiles = FactoryGirl.create_list(:miq_alert_set, 2)
post(api_alert_definition_profiles_url, gen_request(:edit,
[{"id" => alert_definition_profiles.first.id,
"description" => "Updated Test Alert Profile 1"},
{"id" => alert_definition_profiles.second.id,
"description" => "Updated Test Alert Profile 2"}]))
post(api_alert_definition_profiles_url, :params => gen_request(:edit,
[{"id" => alert_definition_profiles.first.id,
"description" => "Updated Test Alert Profile 1"},
{"id" => alert_definition_profiles.second.id,
"description" => "Updated Test Alert Profile 2"}]))
expect(response).to have_http_status(:ok)
expect(response.parsed_body["results"].count).to eq(2)
expect(alert_definition_profiles.first.reload.description).to eq("Updated Test Alert Profile 1")
Expand Down
16 changes: 9 additions & 7 deletions spec/requests/alerts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@
api_basic_authorize
post(
api_alert_alert_actions_url(nil, alert),
"action_type" => "comment",
"comment" => "comment text",
:params => {
"action_type" => "comment",
"comment" => "comment text"
}
)
expect(response).to have_http_status(:forbidden)
end
Expand All @@ -102,7 +104,7 @@
"comment" => "comment text",
}
api_basic_authorize subcollection_action_identifier(:alerts, :alert_actions, :create, :post)
post(api_alert_alert_actions_url(nil, alert), attributes)
post(api_alert_alert_actions_url(nil, alert), :params => attributes)
expect(response).to have_http_status(:ok)
expected = {
"results" => [
Expand All @@ -120,7 +122,7 @@
"user_id" => user.id # should be ignored
}
api_basic_authorize subcollection_action_identifier(:alerts, :alert_actions, :create, :post)
post(api_alert_alert_actions_url(nil, alert), attributes)
post(api_alert_alert_actions_url(nil, alert), :params => attributes)
expect(response).to have_http_status(:ok)
expected = {
"results" => [
Expand All @@ -137,7 +139,7 @@
"assignee" => { "id" => assignee.compressed_id }
}
api_basic_authorize subcollection_action_identifier(:alerts, :alert_actions, :create, :post)
post(api_alert_alert_actions_url(nil, alert), attributes)
post(api_alert_alert_actions_url(nil, alert), :params => attributes)
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected_assignee)
end
Expand All @@ -148,7 +150,7 @@
"assignee" => { "href" => api_user_url(nil, assignee.compressed_id) }
}
api_basic_authorize subcollection_action_identifier(:alerts, :alert_actions, :create, :post)
post(api_alert_alert_actions_url(nil, alert), attributes)
post(api_alert_alert_actions_url(nil, alert), :params => attributes)
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected_assignee)
end
Expand All @@ -157,7 +159,7 @@
api_basic_authorize subcollection_action_identifier(:alerts, :alert_actions, :create, :post)
post(
api_alert_alert_actions_url(nil, alert),
"action_type" => "assign",
:params => { "action_type" => "assign"}
)
expect(response).to have_http_status(:bad_request)
expect(response.parsed_body).to include_error_with_message(
Expand Down
25 changes: 14 additions & 11 deletions spec/requests/authentication_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
it "querying user's authorization" do
api_basic_authorize

get api_entrypoint_url, :attributes => "authorization"
get api_entrypoint_url, :params => { :attributes => "authorization" }

expect(response).to have_http_status(:ok)
expected = {"authorization" => hash_including("product_features")}
Expand Down Expand Up @@ -191,15 +191,15 @@
it "gets a token based identifier with an invalid requester_type" do
api_basic_authorize

get api_auth_url, :requester_type => "bogus_type"
get api_auth_url, :params => { :requester_type => "bogus_type" }

expect_bad_request(/invalid requester_type/i)
end

it "gets a token based identifier with a UI based token_ttl" do
api_basic_authorize

get api_auth_url, :requester_type => "ui"
get api_auth_url, :params => { :requester_type => "ui" }

expect(response).to have_http_status(:ok)
expect_result_to_have_keys(%w(auth_token token_ttl expires_on))
Expand All @@ -221,15 +221,15 @@
it 'gets a UI based token_ttl when requesting token for web sockets' do
api_basic_authorize

get api_auth_url, :requester_type => 'ws'
get api_auth_url, :params => { :requester_type => 'ws' }
expect(response).to have_http_status(:ok)
expect_result_to_have_keys(%w(auth_token token_ttl expires_on))
expect(response.parsed_body["token_ttl"]).to eq(::Settings.session.timeout.to_i_with_method)
end

it 'cannot authorize user to api based on token that is dedicated for web sockets' do
api_basic_authorize
get api_auth_url, :requester_type => 'ws'
get api_auth_url, :params => { :requester_type => 'ws' }
ws_token = response.parsed_body["auth_token"]

get api_entrypoint_url, :headers => {Api::HttpHeaders::AUTH_TOKEN => ws_token}
Expand All @@ -249,8 +249,7 @@ def systoken(server_guid, userid, timestamp)
end

it "authentication using a bad token" do
get api_entrypoint_url,
:headers => {Api::HttpHeaders::MIQ_TOKEN => "badtoken"}
get api_entrypoint_url, :headers => {Api::HttpHeaders::MIQ_TOKEN => "badtoken"}

expect(response).to have_http_status(:unauthorized)
expect(response.parsed_body).to include(
Expand All @@ -259,8 +258,10 @@ def systoken(server_guid, userid, timestamp)
end

it "authentication using a token with a bad server guid" do
get api_entrypoint_url,
:headers => {Api::HttpHeaders::MIQ_TOKEN => systoken("bad_server_guid", api_config(:user), Time.now.utc)}
get(
api_entrypoint_url,
:headers => {Api::HttpHeaders::MIQ_TOKEN => systoken("bad_server_guid", api_config(:user), Time.now.utc)}
)

expect(response).to have_http_status(:unauthorized)
expect(response.parsed_body).to include(
Expand All @@ -269,8 +270,10 @@ def systoken(server_guid, userid, timestamp)
end

it "authentication using a token with bad user" do
get api_entrypoint_url,
:headers => {Api::HttpHeaders::MIQ_TOKEN => systoken(MiqServer.first.guid, "bad_user_id", Time.now.utc)}
get(
api_entrypoint_url,
:headers => {Api::HttpHeaders::MIQ_TOKEN => systoken(MiqServer.first.guid, "bad_user_id", Time.now.utc)}
)

expect(response).to have_http_status(:unauthorized)
expect(response.parsed_body).to include(
Expand Down
Loading

0 comments on commit f79513c

Please sign in to comment.