forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud_network_controller_spec.rb
202 lines (181 loc) · 7.25 KB
/
cloud_network_controller_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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)
context "#button" do
before(:each) do
stub_user(:features => :all)
EvmSpecHelper.create_guid_miq_server_zone
ApplicationController.handle_exceptions = true
end
it "when Edit Tag is pressed" do
skip "No ready yet"
expect(controller).to receive(:tag)
post :button, :params => { :pressed => "edit_tag", :format => :js }
expect(controller.send(:flash_errors?)).not_to be_truthy
end
end
context "#tags_edit" do
let!(:user) { stub_user(:features => :all) }
before(:each) do
EvmSpecHelper.create_guid_miq_server_zone
@ct = FactoryGirl.create(:cloud_network, :name => "cloud-network-01")
allow(@ct).to receive(:tagged_with).with(:cat => user.userid).and_return("my tags")
classification = FactoryGirl.create(:classification, :name => "department", :description => "Department")
@tag1 = FactoryGirl.create(:classification_tag,
:name => "tag1",
:parent => classification)
@tag2 = FactoryGirl.create(:classification_tag,
:name => "tag2",
:parent => classification)
allow(Classification).to receive(:find_assigned_entries).with(@ct).and_return([@tag1, @tag2])
session[:tag_db] = "CloudNetwork"
edit = {
:key => "CloudNetwork_edit_tags__#{@ct.id}",
:tagging => "CloudNetwork",
:object_ids => [@ct.id],
:current => {:assignments => []},
:new => {:assignments => [@tag1.id, @tag2.id]}
}
session[:edit] = edit
end
after(:each) do
expect(response.status).to eq(200)
end
it "builds tagging screen" do
post :button, :params => { :pressed => "cloud_network_tag", :format => :js, :id => @ct.id }
expect(assigns(:flash_array)).to be_nil
end
it "cancels tags edit" do
session[:breadcrumbs] = [{:url => "cloud_network/show/#{@ct.id}"}, 'placeholder']
post :tagging_edit, :params => { :button => "cancel", :format => :js, :id => @ct.id }
expect(assigns(:flash_array).first[:message]).to include("was cancelled by the user")
expect(assigns(:edit)).to be_nil
end
it "save tags" do
session[:breadcrumbs] = [{:url => "cloud_network/show/#{@ct.id}"}, 'placeholder']
post :tagging_edit, :params => { :button => "save", :format => :js, :id => @ct.id }
expect(assigns(:flash_array).first[:message]).to include("Tag edits were successfully saved")
expect(assigns(:edit)).to be_nil
end
end
describe "#show" do
before do
EvmSpecHelper.create_guid_miq_server_zone
@network = FactoryGirl.create(:cloud_network)
login_as FactoryGirl.create(:user)
end
subject do
get :show, :params => {:id => @network.id}
end
context "render listnav partial" do
render_views
it do
is_expected.to have_http_status 200
is_expected.to render_template(:partial => "layouts/listnav/_cloud_network")
end
end
end
describe "#create" do
before do
stub_user(:features => :all)
EvmSpecHelper.create_guid_miq_server_zone
@ems = FactoryGirl.create(:ems_openstack).network_manager
@network = FactoryGirl.create(:cloud_network_openstack)
end
context "#create" do
let(:task_options) do
{
:action => "creating Cloud Network for user %{user}" % {:user => controller.current_user.userid},
:userid => controller.current_user.userid
}
end
let(:queue_options) do
{
:class_name => @ems.class.name,
:method_name => 'create_cloud_network',
:instance_id => @ems.id,
:priority => MiqQueue::HIGH_PRIORITY,
:role => 'ems_operations',
:zone => @ems.my_zone,
:args => [{:name => "test", :admin_state_up => false, :shared => false, :external_facing => false}]
}
end
it "builds create screen" do
post :button, :params => { :pressed => "cloud_network_new", :format => :js }
expect(assigns(:flash_array)).to be_nil
end
it "queues the create action" do
expect(MiqTask).to receive(:generic_action_with_callback).with(task_options, queue_options)
post :create, :params => { :button => "add", :format => :js, :name => 'test',
:tenant_id => 'id', :ems_id => @ems.id }
end
end
end
describe "#edit" do
before do
stub_user(:features => :all)
EvmSpecHelper.create_guid_miq_server_zone
@ems = FactoryGirl.create(:ems_openstack).network_manager
@network = FactoryGirl.create(:cloud_network_openstack, :ext_management_system => @ems)
end
context "#edit" do
let(:task_options) do
{
:action => "updating Cloud Network for user %{user}" % {:user => controller.current_user.userid},
:userid => controller.current_user.userid
}
end
let(:queue_options) do
{
:class_name => @network.class.name,
:method_name => 'raw_update_cloud_network',
:instance_id => @network.id,
:priority => MiqQueue::HIGH_PRIORITY,
:role => 'ems_operations',
:zone => @ems.my_zone,
:args => [{:name=>"test2", :admin_state_up => false, :shared => false, :external_facing => false}]
}
end
it "builds edit screen" do
post :button, :params => { :pressed => "cloud_network_edit", :format => :js, :id => @network.id }
expect(assigns(:flash_array)).to be_nil
end
it "queues the update action" do
expect(MiqTask).to receive(:generic_action_with_callback).with(task_options, queue_options)
post :update, :params => { :button => "save", :format => :js, :id => @network.id, :name => "test2" }
end
end
end
describe "#delete" do
before do
stub_user(:features => :all)
EvmSpecHelper.create_guid_miq_server_zone
@ems = FactoryGirl.create(:ems_openstack).network_manager
@network = FactoryGirl.create(:cloud_network_openstack, :ext_management_system => @ems)
session[:cloud_network_lastaction] = 'show'
end
context "#delete" do
let(:task_options) do
{
:action => "deleting Cloud Network for user %{user}" % {:user => controller.current_user.userid},
:userid => controller.current_user.userid
}
end
let(:queue_options) do
{
:class_name => @network.class.name,
:method_name => 'raw_delete_cloud_network',
:instance_id => @network.id,
:priority => MiqQueue::HIGH_PRIORITY,
:role => 'ems_operations',
:zone => @ems.my_zone,
:args => []
}
end
it "queues the delete action" do
expect(MiqTask).to receive(:generic_action_with_callback).with(task_options, queue_options)
post :button, :params => { :id => @network.id, :pressed => "cloud_network_delete", :format => :js }
end
end
end
end