Skip to content

Commit

Permalink
Adds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Nov 6, 2017
1 parent a318ce6 commit 00a99de
Showing 1 changed file with 303 additions and 0 deletions.
303 changes: 303 additions & 0 deletions spec/requests/custom_actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,307 @@ def expect_result_to_have_custom_actions_hash
expect(response.parsed_body).to include(expected)
end
end

def define_custom_button1(resource)
dialog1 = FactoryGirl.create(:dialog, :label => "dialog1")
resource_action1 = FactoryGirl.create(:resource_action, :dialog_id => dialog1.id)
FactoryGirl.create(:custom_button, :name => "button1", :applies_to => resource, :userid => @user.userid, :resource_action => resource_action1)
end

describe "Availability Zones" do
before(:each) do
@resource = FactoryGirl.create(:availability_zone)
define_custom_button1(@resource)
end

it "queries return custom actions defined" do
api_basic_authorize(action_identifier(:availability_zones, :read, :resource_actions, :get))

get api_availability_zone_url(nil, @resource)

expect(response.parsed_body).to include(
"id" => @resource.id.to_s,
"href" => api_availability_zone_url(nil, @resource),
"actions" => a_collection_including(a_hash_including("name" => "button1"))
)
end

it "accept custom actions" do
api_basic_authorize

post api_availability_zone_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1")

expect_single_action_result(:success => true, :message => /.*/, :href => api_availability_zone_url(nil, @resource))
end
end

describe "CloudSubnet" do
before(:each) do
@resource = FactoryGirl.create(:cloud_subnet)
define_custom_button1(@resource)
end

it "queries return custom actions defined" do
api_basic_authorize(action_identifier(:cloud_subnets, :read, :resource_actions, :get))

get api_cloud_subnet_url(nil, @resource)

expect(response.parsed_body).to include(
"id" => @resource.id.to_s,
"href" => api_cloud_subnet_url(nil, @resource),
"actions" => a_collection_including(a_hash_including("name" => "button1"))
)
end

it "accept custom actions" do
api_basic_authorize

post api_cloud_subnet_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1")

expect_single_action_result(:success => true, :message => /.*/, :href => api_cloud_subnet_url(nil, @resource))
end
end

describe "CloudTenant" do
before(:each) do
@resource = FactoryGirl.create(:cloud_tenant)
define_custom_button1(@resource)
end

it "queries return custom actions defined" do
api_basic_authorize(action_identifier(:cloud_tenants, :read, :resource_actions, :get))

get api_cloud_tenant_url(nil, @resource)

expect(response.parsed_body).to include(
"id" => @resource.id.to_s,
"href" => api_cloud_tenant_url(nil, @resource),
"actions" => a_collection_including(a_hash_including("name" => "button1"))
)
end

it "accept custom actions" do
api_basic_authorize

post api_cloud_tenant_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1")

expect_single_action_result(:success => true, :message => /.*/, :href => api_cloud_tenant_url(nil, @resource))
end
end

describe "CloudVolume" do
before(:each) do
@resource = FactoryGirl.create(:cloud_volume)
define_custom_button1(@resource)
end

it "queries return custom actions defined" do
api_basic_authorize(action_identifier(:cloud_volumes, :read, :resource_actions, :get))

get api_cloud_volume_url(nil, @resource)

expect(response.parsed_body).to include(
"id" => @resource.id.to_s,
"href" => api_cloud_volume_url(nil, @resource),
"actions" => a_collection_including(a_hash_including("name" => "button1"))
)
end

it "accept custom actions" do
api_basic_authorize

post api_cloud_volume_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1")

expect_single_action_result(:success => true, :message => /.*/, :href => api_cloud_volume_url(nil, @resource))
end
end

describe "ContainerNode" do
before(:each) do
@resource = FactoryGirl.create(:container_node)
define_custom_button1(@resource)
end

it "queries return custom actions defined" do
api_basic_authorize(action_identifier(:container_nodes, :read, :resource_actions, :get))

get api_container_node_url(nil, @resource)

expect(response.parsed_body).to include(
"id" => @resource.id.to_s,
"href" => api_container_node_url(nil, @resource),
"actions" => a_collection_including(a_hash_including("name" => "button1"))
)
end

it "accept custom actions" do
api_basic_authorize

post api_container_node_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1")

expect_single_action_result(:success => true, :message => /.*/, :href => api_container_node_url(nil, @resource))
end
end

describe "Host" do
before(:each) do
@resource = FactoryGirl.create(:host)
define_custom_button1(@resource)
end

it "queries return custom actions defined" do
api_basic_authorize(action_identifier(:hosts, :read, :resource_actions, :get))

get api_host_url(nil, @resource)

expect(response.parsed_body).to include(
"id" => @resource.id.to_s,
"href" => api_host_url(nil, @resource),
"actions" => a_collection_including(a_hash_including("name" => "button1"))
)
end

it "accept custom actions" do
api_basic_authorize

post api_host_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1")

expect_single_action_result(:success => true, :message => /.*/, :href => api_host_url(nil, @resource))
end
end

describe "LoadBalancer" do
before(:each) do
@resource = FactoryGirl.create(:load_balancer)
define_custom_button1(@resource)
end

it "queries return custom actions defined" do
api_basic_authorize(action_identifier(:load_balancers, :read, :resource_actions, :get))

get api_load_balancer_url(nil, @resource)

expect(response.parsed_body).to include(
"id" => @resource.id.to_s,
"href" => api_load_balancer_url(nil, @resource),
"actions" => a_collection_including(a_hash_including("name" => "button1"))
)
end

it "accept custom actions" do
api_basic_authorize

post api_load_balancer_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1")

expect_single_action_result(:success => true, :message => /.*/, :href => api_load_balancer_url(nil, @resource))
end
end

describe "NetworkRouter" do
before(:each) do
@resource = FactoryGirl.create(:network_router)
define_custom_button1(@resource)
end

it "queries return custom actions defined" do
api_basic_authorize(action_identifier(:network_routers, :read, :resource_actions, :get))

get api_network_router_url(nil, @resource)

expect(response.parsed_body).to include(
"id" => @resource.id.to_s,
"href" => api_network_router_url(nil, @resource),
"actions" => a_collection_including(a_hash_including("name" => "button1"))
)
end

it "accept custom actions" do
api_basic_authorize

post api_network_router_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1")

expect_single_action_result(:success => true, :message => /.*/, :href => api_network_router_url(nil, @resource))
end
end

describe "Tenant" do
before(:each) do
@resource = FactoryGirl.create(:tenant)
define_custom_button1(@resource)
end

it "queries return custom actions defined" do
api_basic_authorize(action_identifier(:tenants, :read, :resource_actions, :get))

get api_tenant_url(nil, @resource)

expect(response.parsed_body).to include(
"id" => @resource.id.to_s,
"href" => api_tenant_url(nil, @resource),
"actions" => a_collection_including(a_hash_including("name" => "button1"))
)
end

it "accept custom actions" do
api_basic_authorize

post api_tenant_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1")

expect_single_action_result(:success => true, :message => /.*/, :href => api_tenant_url(nil, @resource))
end
end

describe "User" do
before(:each) do
@resource = FactoryGirl.create(:user)
define_custom_button1(@resource)
end

it "queries return custom actions defined" do
api_basic_authorize(action_identifier(:users, :read, :resource_actions, :get))

get api_user_url(nil, @resource)

expect(response.parsed_body).to include(
"id" => @resource.id.to_s,
"href" => api_user_url(nil, @resource),
"actions" => a_collection_including(a_hash_including("name" => "button1"))
)
end

it "accept custom actions" do
api_basic_authorize

post api_user_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1")

expect_single_action_result(:success => true, :message => /.*/, :href => api_user_url(nil, @resource))
end
end

describe "Vms" do
before(:each) do
@resource = FactoryGirl.create(:vm)
define_custom_button1(@resource)
end

it "queries return custom actions defined" do
api_basic_authorize(action_identifier(:vms, :read, :resource_actions, :get))

get api_vm_url(nil, @resource)

expect(response.parsed_body).to include(
"id" => @resource.id.to_s,
"href" => api_vm_url(nil, @resource),
"actions" => a_collection_including(a_hash_including("name" => "button1"))
)
end

it "accept custom actions" do
api_basic_authorize

post api_vm_url(nil, @resource), :params => gen_request(:button1, "key1" => "value1")

expect_single_action_result(:success => true, :message => /.*/, :href => api_vm_url(nil, @resource))
end
end
end

0 comments on commit 00a99de

Please sign in to comment.