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

Use wrapped Rails request helpers instead of custom ones #51

Merged
merged 7 commits into from
Sep 14, 2017
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
28 changes: 14 additions & 14 deletions spec/requests/actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
action
api_basic_authorize

run_get(api_actions_url)
get(api_actions_url)

expect(response).to have_http_status(:forbidden)
end

it "creates new action" do
api_basic_authorize collection_action_identifier(:actions, :create)
run_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)
run_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 @@ -44,7 +44,7 @@
it "reads all actions" do
api_basic_authorize collection_action_identifier(:actions, :read, :get)
FactoryGirl.create(:miq_action)
run_get(api_actions_url)
get(api_actions_url)
expect(response).to have_http_status(:ok)

actions_amount = response.parsed_body["count"]
Expand All @@ -54,7 +54,7 @@

it "deletes action" do
api_basic_authorize collection_action_identifier(:actions, :delete)
run_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)
run_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 @@ -76,15 +76,15 @@
it "deletes action via DELETE" do
api_basic_authorize collection_action_identifier(:actions, :delete)

run_delete(api_action_url(nil, action))
delete(api_action_url(nil, action))

expect(response).to have_http_status(:no_content)
expect(MiqAction.exists?(action.id)).to be_falsey
end

it "edits new action" do
api_basic_authorize collection_action_identifier(:actions, :edit)
run_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)
run_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
73 changes: 40 additions & 33 deletions spec/requests/alert_definitions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
describe "Alerts Definitions API" do
it "forbids access to alert definitions list without an appropriate role" do
api_basic_authorize
run_get(api_alert_definitions_url)
get(api_alert_definitions_url)
expect(response).to have_http_status(:forbidden)
end

it "reads 2 alert definitions as a collection" do
api_basic_authorize collection_action_identifier(:alert_definitions, :read, :get)
alert_definitions = FactoryGirl.create_list(:miq_alert, 2)
run_get(api_alert_definitions_url)
get(api_alert_definitions_url)
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(
"name" => "alert_definitions",
Expand All @@ -36,7 +36,7 @@
it "forbids access to an alert definition resource without an appropriate role" do
api_basic_authorize
alert_definition = FactoryGirl.create(:miq_alert)
run_get(api_alert_definition_url(nil, alert_definition))
get(api_alert_definition_url(nil, alert_definition))
expect(response).to have_http_status(:forbidden)
end

Expand All @@ -46,7 +46,7 @@
:miq_alert,
:miq_expression => MiqExpression.new("=" => {"field" => "Vm-name", "value" => "foo"})
)
run_get(api_alert_definition_url(nil, alert_definition))
get(api_alert_definition_url(nil, alert_definition))
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(
"href" => api_alert_definition_url(nil, alert_definition.compressed_id),
Expand All @@ -63,7 +63,7 @@
"description" => "Test Alert Definition",
"db" => "ContainerNode"
}
run_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)
run_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)
run_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 @@ -104,16 +104,16 @@
it "deletes an alert definition via DELETE" do
api_basic_authorize action_identifier(:alert_definitions, :delete, :resource_actions, :delete)
alert_definition = FactoryGirl.create(:miq_alert)
run_delete(api_alert_definition_url(nil, alert_definition))
delete(api_alert_definition_url(nil, alert_definition))
expect(response).to have_http_status(:no_content)
expect(MiqAlert.exists?(alert_definition.id)).to be_falsey
end

it "deletes alert definitions" do
api_basic_authorize collection_action_identifier(:alert_definitions, :delete)
alert_definitions = FactoryGirl.create_list(:miq_alert, 2)
run_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 @@ -126,10 +126,17 @@
:options => { :notifications => {:delay_next_evaluation => 0, :evm_event => {} } }
)

run_post(
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)
run_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 All @@ -167,23 +174,23 @@
describe "Alerts Definition Profiles API" do
it "forbids access to alert definition profiles list without an appropriate role" do
api_basic_authorize
run_get(api_alert_definition_profiles_url)
get(api_alert_definition_profiles_url)

expect(response).to have_http_status(:forbidden)
end

it "forbids access to an alert definition profile without an appropriate role" do
api_basic_authorize
alert_definition_profile = FactoryGirl.create(:miq_alert_set)
run_get(api_alert_definition_profile_url(nil, alert_definition_profile))
get(api_alert_definition_profile_url(nil, alert_definition_profile))

expect(response).to have_http_status(:forbidden)
end

it "reads 2 alert definition profiles as a collection" do
api_basic_authorize collection_action_identifier(:alert_definition_profiles, :read, :get)
alert_definition_profiles = FactoryGirl.create_list(:miq_alert_set, 2)
run_get(api_alert_definition_profiles_url)
get(api_alert_definition_profiles_url)

expect(response).to have_http_status(:ok)
expect_query_result(:alert_definition_profiles, 2, 2)
Expand All @@ -197,7 +204,7 @@
it "reads an alert definition profile as a resource" do
api_basic_authorize action_identifier(:alert_definition_profiles, :read, :resource_actions, :get)
alert_definition_profile = FactoryGirl.create(:miq_alert_set)
run_get(api_alert_definition_profile_url(nil, alert_definition_profile))
get(api_alert_definition_profile_url(nil, alert_definition_profile))

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(
Expand All @@ -212,7 +219,7 @@

alert_definitions = FactoryGirl.create_list(:miq_alert, 2)
alert_definition_profile = FactoryGirl.create(:miq_alert_set, :alerts => alert_definitions)
run_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])
run_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)
run_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)
run_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 @@ -271,7 +278,7 @@
it "deletes an alert definition profile via DELETE" do
api_basic_authorize action_identifier(:alert_definition_profiles, :delete, :resource_actions, :delete)
alert_definition_profile = FactoryGirl.create(:miq_alert_set)
run_delete(api_alert_definition_profile_url(nil, alert_definition_profile))
delete(api_alert_definition_profile_url(nil, alert_definition_profile))

expect(response).to have_http_status(:no_content)
expect(MiqAlertSet.exists?(alert_definition_profile.id)).to be_falsey
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)
run_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)
run_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
Loading