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

Move controller specs #96

Merged
merged 4 commits into from
Jan 9, 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
4 changes: 1 addition & 3 deletions spec/controllers/cloud_network_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require Rails.root.join('spec/shared/controllers/shared_examples_for_cloud_network_controller')

describe CloudNetworkController do
include_examples :shared_examples_for_cloud_network_controller, %w(openstack azure google)
include_examples :shared_examples_for_cloud_network_controller, %w(openstack azure google amazon)

context "#button" do
before(:each) do
Expand Down
4 changes: 1 addition & 3 deletions spec/controllers/cloud_subnet_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require Rails.root.join('spec/shared/controllers/shared_examples_for_cloud_subnet_controller')

describe CloudSubnetController do
include_examples :shared_examples_for_cloud_subnet_controller, %w(openstack azure google)
include_examples :shared_examples_for_cloud_subnet_controller, %w(openstack azure google amazon)

context "#button" do
before(:each) do
Expand Down
2 changes: 0 additions & 2 deletions spec/controllers/ems_block_storage_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require Rails.root.join('spec/shared/controllers/shared_examples_for_ems_block_storage_controller')

describe EmsBlockStorageController do
include_examples :shared_examples_for_ems_block_storage_controller, %w(openstack)
end
4 changes: 1 addition & 3 deletions spec/controllers/ems_network_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require Rails.root.join('spec/shared/controllers/shared_examples_for_ems_network_controller')

describe EmsNetworkController do
include_examples :shared_examples_for_ems_network_controller, %w(openstack azure google)
include_examples :shared_examples_for_ems_network_controller, %w(openstack azure google amazon)
end
2 changes: 0 additions & 2 deletions spec/controllers/ems_object_storage_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require Rails.root.join('spec/shared/controllers/shared_examples_for_ems_object_storage_controller')

describe EmsObjectStorageController do
include_examples :shared_examples_for_ems_object_storage_controller, %w(openstack)
end
2 changes: 0 additions & 2 deletions spec/controllers/ems_storage_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require Rails.root.join('spec/shared/controllers/shared_examples_for_ems_storage_controller')

describe EmsStorageController do
include_examples :shared_examples_for_ems_storage_controller, %w(openstack)
end
4 changes: 1 addition & 3 deletions spec/controllers/floating_ip_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require Rails.root.join('spec/shared/controllers/shared_examples_for_floating_ip_controller')

describe FloatingIpController do
include_examples :shared_examples_for_floating_ip_controller, %w(openstack azure google)
include_examples :shared_examples_for_floating_ip_controller, %w(openstack azure google amazon)

context "#button" do
before(:each) do
Expand Down
4 changes: 1 addition & 3 deletions spec/controllers/load_balancer_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require Rails.root.join('spec/shared/controllers/shared_examples_for_load_balancer_controller')

describe LoadBalancerController do
include_examples :shared_examples_for_load_balancer_controller, %w()
include_examples :shared_examples_for_load_balancer_controller, %w(amazon)
end
4 changes: 1 addition & 3 deletions spec/controllers/network_port_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require Rails.root.join('spec/shared/controllers/shared_examples_for_network_port_controller')

describe NetworkPortController do
include_examples :shared_examples_for_network_port_controller, %w(openstack azure google)
include_examples :shared_examples_for_network_port_controller, %w(openstack azure google amazon)
end
4 changes: 1 addition & 3 deletions spec/controllers/network_router_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require Rails.root.join('spec/shared/controllers/shared_examples_for_network_router_controller')

describe NetworkRouterController do
include_examples :shared_examples_for_network_router_controller, %w(openstack azure google)
include_examples :shared_examples_for_network_router_controller, %w(openstack azure google amazon)

context "#button" do
before(:each) do
Expand Down
4 changes: 1 addition & 3 deletions spec/controllers/security_group_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require Rails.root.join('spec/shared/controllers/shared_examples_for_security_group_controller')

describe SecurityGroupController do
include_examples :shared_examples_for_security_group_controller, %w(openstack azure google)
include_examples :shared_examples_for_security_group_controller, %w(openstack azure google amazon)

context "#button" do
before(:each) do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
require_relative 'shared_network_manager_context'

shared_examples :shared_examples_for_cloud_network_controller do |providers|
include CompressedIds

render_views
before :each do
stub_user(:features => :all)
setup_zone
end

providers.each do |t|
context "for #{t}" do
include_context :shared_network_manager_context, t

describe "#show_list" do
it "renders index" do
get :index
expect(response.status).to eq(302)
expect(response).to redirect_to(:action => 'show_list')
end

it "renders show_list" do
# TODO(lsmola) figure out why I have to mock pdf available here, but not in other Manager's lists
allow(PdfGenerator).to receive_messages(:available? => false)
session[:settings] = {:default_search => 'foo',
:views => {},
:perpage => {:list => 10}}
get :show_list
expect(response.status).to eq(200)
expect(response.body).to_not be_empty
end
end

describe "#show" do
it "renders show screen" do
get :show, :params => {:id => @cloud_network.id}
expect(response.status).to eq(200)
expect(response.body).to_not be_empty
expect(assigns(:breadcrumbs)).to eq([{:name => "Cloud Networks",
:url => "/cloud_network/show_list?page=&refresh=y"},
{:name => "Cloud Network (Summary)",
:url => "/cloud_network/show/#{@cloud_network.id}"}])

is_expected.to render_template(:partial => "layouts/listnav/_cloud_network")
end

it "show associated cloud_subnets" do
assert_nested_list(@cloud_network, [@cloud_subnet], 'cloud_subnets', 'All Cloud Subnets')
end

it "show associated network routers" do
assert_nested_list(@cloud_network, [@network_router], 'network_routers', 'All Network Routers')
end

it "show associated instances" do
assert_nested_list(@cloud_network, [@vm], 'instances', 'All Instances', :child_path => 'vm_cloud')
end
end

describe "#test_toolbars" do
it 'edit Cloud Network tags' do
post :button, :params => {:miq_grid_checks => to_cid(@cloud_network.id), :pressed => "cloud_network_tag"}
expect(response.status).to eq(200)
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require_relative 'shared_network_manager_context'

shared_examples :shared_examples_for_cloud_subnet_controller do |providers|
include CompressedIds

render_views
before :each do
stub_user(:features => :all)
setup_zone
end

providers.each do |t|
context "for #{t}" do
include_context :shared_network_manager_context, t

describe "#show_list" do
it "renders index" do
get :index
expect(response.status).to eq(302)
expect(response).to redirect_to(:action => 'show_list')
end

it "renders show_list" do
# TODO(lsmola) figure out why I have to mock pdf available here, but not in other Manager's lists
allow(PdfGenerator).to receive_messages(:available? => false)
session[:settings] = {:default_search => 'foo',
:views => {},
:perpage => {:list => 10}}
get :show_list
expect(response.status).to eq(200)
expect(response.body).to_not be_empty
end
end

describe "#show" do
it "renders show screen" do
get :show, :params => {:id => @cloud_subnet.id}
expect(response.status).to eq(200)
expect(response.body).to_not be_empty
expect(assigns(:breadcrumbs)).to eq([{:name => "Cloud Subnets",
:url => "/cloud_subnet/show_list?page=&refresh=y"},
{:name => "Cloud Subnet (Summary)",
:url => "/cloud_subnet/show/#{@cloud_subnet.id}"}])

is_expected.to render_template(:partial => "layouts/listnav/_cloud_subnet")
end

it "show associated cloud_subnets" do
assert_nested_list(@cloud_subnet, [@child_subnet], 'cloud_subnets', 'All Cloud Subnets')
end

it "show associated instances" do
assert_nested_list(@cloud_subnet, [@vm], 'instances', 'All Instances', :child_path => 'vm_cloud')
end
end

describe "#test_toolbars" do
it 'edit cloud subnet tags' do
post :button, :params => {:miq_grid_checks => to_cid(@cloud_subnet.id), :pressed => "cloud_subnet_tag"}
expect(response.status).to eq(200)
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require_relative 'shared_storage_manager_context'

shared_examples :shared_examples_for_ems_block_storage_controller do |providers|
include CompressedIds
render_views
before :each do
stub_user(:features => :all)
setup_zone
end

providers.each do |t|
context "for #{t}" do
include_context :shared_storage_manager_context, t

describe "#show_list" do
it "renders index" do
get :index
expect(response.status).to eq(302)
expect(response).to redirect_to(:action => 'show_list')
end

it "renders show_list" do
# TODO(lsmola) figure out why I have to mock pdf available here, but not in other Manager's lists
allow(PdfGenerator).to receive_messages(:available? => false)
session[:settings] = {:default_search => 'foo',
:views => {},
:perpage => {:list => 10}}
get :show_list
expect(response.status).to eq(200)
expect(response.body).to_not be_empty
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
require_relative 'shared_network_manager_context'

shared_examples :shared_examples_for_ems_network_controller do |providers|
include CompressedIds
render_views
before :each do
stub_user(:features => :all)
setup_zone
end

providers.each do |t|
context "for #{t}" do
include_context :shared_network_manager_context, t

describe "#show_list" do
it "renders index" do
get :index
expect(response.status).to eq(302)
expect(response).to redirect_to(:action => 'show_list')
end

it "renders show_list" do
# TODO(lsmola) figure out why I have to mock pdf available here, but not in other Manager's lists
allow(PdfGenerator).to receive_messages(:available? => false)
session[:settings] = {:default_search => 'foo',
:views => {},
:perpage => {:list => 10}}
get :show_list
expect(response.status).to eq(200)
expect(response.body).to_not be_empty
end
end

describe "#show" do
it "renders show screen" do
get :show, :params => {:id => @ems.id}
expect(response.status).to eq(200)
expect(response.body).to_not be_empty
expect(assigns(:breadcrumbs)).to eq([{:name => "Network Providers",
:url => "/ems_network/show_list?page=&refresh=y"},
{:name => "Cloud Manager Network Manager (Summary)",
:url => "/ems_network/#{@ems.id}"}])

is_expected.to render_template(:partial => "layouts/listnav/_ems_network")
end

it "show associated cloud_networks" do
assert_nested_list(@ems, [@cloud_network], 'cloud_networks', 'All Cloud Networks')
end

it "show associated cloud_subnets" do
assert_nested_list(@ems, [@cloud_subnet], 'cloud_subnets', 'All Cloud Subnets')
end

it "show associated network routers" do
assert_nested_list(@ems, [@network_router], 'network_routers', 'All Network Routers')
end

it "show associated security_groups" do
assert_nested_list(@ems, [@security_group], 'security_groups', 'All Security Groups')
end

it "show associated floating_ips" do
assert_nested_list(@ems, [@floating_ip], 'floating_ips', 'All Floating IPs')
end

it "show associated network_ports" do
assert_nested_list(@ems, [@network_port], 'network_ports', 'All Network Ports')
end

it "show associated load balancers" do
# TODO: add more cloud providers as the LBaaS is implemented
skip unless %w(amazon).include? t
assert_nested_list(@ems, [@load_balancer], 'load_balancers', 'All Load Balancers')
end
end

describe "#ems_network_form_fields" do
it "renders ems_network_form_fields json" do
get :ems_network_form_fields, :params => {:id => @ems.id}
expect(response.status).to eq(200)
expect(response.body).to_not be_empty
end
end

describe "#create" do
it "adds a new provider" do
controller.instance_variable_set(:@breadcrumbs, [])
get :new
expect(response.status).to eq(200)
expect(allow(controller).to(receive(:edit))).to_not be_nil
end
end

describe "#test_toolbars" do
it "refresh relationships and power states" do
post :button, :params => {:id => @ems.id, :pressed => "ems_network_refresh"}
expect(response.status).to eq(200)
end

it 'edit selected network provider' do
post :button, :params => {:miq_grid_checks => to_cid(@ems.id), :pressed => "ems_network_edit"}
expect(response.status).to eq(200)
end

it 'edit network provider tags' do
post :button, :params => {:miq_grid_checks => to_cid(@ems.id), :pressed => "ems_network_tag"}
expect(response.status).to eq(200)
end

it 'manage network provider policies' do
allow(controller).to receive(:protect_build_tree).and_return(nil)
controller.instance_variable_set(:@protect_tree, OpenStruct.new(:name => "name"))

post :button, :params => {:miq_grid_checks => to_cid(@ems.id), :pressed => "ems_network_protect"}
expect(response.status).to eq(200)

get :protect
expect(response.status).to eq(200)
expect(response).to render_template('shared/views/protect')
end

it 'edit network provider timeline' do
get :show, :params => {:display => "timeline", :id => @ems.id}
expect(response.status).to eq(200)
end

it 'edit network providers' do
post :button, :params => {:miq_grid_checks => to_cid(@ems.id), :pressed => "ems_network_edit"}
expect(response.status).to eq(200)
end
end
end
end
end
Loading