forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarget_spec.rb
158 lines (138 loc) · 4.76 KB
/
target_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
describe ManagerRefresh::Target do
before(:each) do
@zone = FactoryGirl.create(:zone)
@ems = FactoryGirl.create(:ems_cloud, :zone => @zone)
@vm_1 = FactoryGirl.create(
:vm_cloud,
:ext_management_system => @ems,
:ems_ref => "vm_1"
)
@vm_2 = FactoryGirl.create(
:vm_cloud,
:ext_management_system => @ems,
:ems_ref => "vm_2"
)
end
context ".load" do
it "intializes correct ManagerRefresh::Target.object with a :manager_id" do
target_1 = ManagerRefresh::Target.load(
:manager_id => @ems.id,
:association => :vms,
:manager_ref => {:ems_ref => @vm_1.ems_ref},
:options => {:opt1 => "opt1", :opt2 => "opt2"}
)
expect(target_1).to(
have_attributes(
:manager => @ems,
:manager_id => @ems.id,
:association => :vms,
:manager_ref => {:ems_ref => @vm_1.ems_ref},
:options => {:opt1 => "opt1", :opt2 => "opt2"}
)
)
end
it "intializes correct ManagerRefresh::Target.object with a :manager " do
target_1 = ManagerRefresh::Target.load(
:manager => @ems,
:association => :vms,
:manager_ref => {:ems_ref => @vm_1.ems_ref},
:options => {:opt1 => "opt1", :opt2 => "opt2"}
)
expect(target_1).to(
have_attributes(
:manager => @ems,
:manager_id => @ems.id,
:association => :vms,
:manager_ref => {:ems_ref => @vm_1.ems_ref},
:options => {:opt1 => "opt1", :opt2 => "opt2"}
)
)
end
it "raises exception when manager not provided in any form" do
data = {
:association => :vms,
:manager_ref => {:ems_ref => @vm_1.ems_ref},
:options => {:opt1 => "opt1", :opt2 => "opt2"}
}
expect { ManagerRefresh::Target.load(data) }.to raise_error("Provide either :manager or :manager_id argument")
end
context ".dump" do
it "intializes correct ManagerRefresh::Target.object with a :manager_id" do
target_1 = ManagerRefresh::Target.load(
:manager_id => @ems.id,
:association => :vms,
:manager_ref => {:ems_ref => @vm_1.ems_ref},
:options => {:opt1 => "opt1", :opt2 => "opt2"}
)
expect(target_1.dump).to(
eq(
:manager_id => @ems.id,
:event_id => nil,
:association => :vms,
:manager_ref => {:ems_ref => @vm_1.ems_ref},
:options => {:opt1 => "opt1", :opt2 => "opt2"}
)
)
end
it "intializes correct ManagerRefresh::Target.object with a :manager " do
target_1 = ManagerRefresh::Target.load(
:manager => @ems,
:association => :vms,
:manager_ref => {:ems_ref => @vm_1.ems_ref},
:options => {:opt1 => "opt1", :opt2 => "opt2"}
)
expect(target_1.dump).to(
eq(
:manager_id => @ems.id,
:event_id => nil,
:association => :vms,
:manager_ref => {:ems_ref => @vm_1.ems_ref},
:options => {:opt1 => "opt1", :opt2 => "opt2"}
)
)
end
it "class method .dump returns the same as an instance method .dump " do
target_1 = ManagerRefresh::Target.load(
:manager => @ems,
:association => :vms,
:manager_ref => {:ems_ref => @vm_1.ems_ref},
:options => {:opt1 => "opt1", :opt2 => "opt2"}
)
expect(target_1.dump).to eq ManagerRefresh::Target.dump(target_1)
end
end
context ".load_from_db" do
it "loads ManagerRefresh::Target from the db" do
target_1 = ManagerRefresh::Target.load(
:manager => @ems,
:association => :vms,
:manager_ref => {:ems_ref => @vm_1.ems_ref},
:options => {:opt1 => "opt1", :opt2 => "opt2"}
)
expect(target_1.load_from_db).to eq @vm_1
end
end
context ".id" do
it "checks that .id is an alias for .dump" do
target_1 = ManagerRefresh::Target.load(
:manager => @ems,
:association => :vms,
:manager_ref => {:ems_ref => @vm_1.ems_ref},
:options => {:opt1 => "opt1", :opt2 => "opt2"}
)
expect(target_1.dump).to eq target_1.id
end
end
context ".name" do
it "checks that .name is an alias for .association" do
target_1 = ManagerRefresh::Target.load(
:manager => @ems,
:association => :vms,
:manager_ref => {:ems_ref => @vm_1.ems_ref},
:options => {:opt1 => "opt1", :opt2 => "opt2"}
)
expect(target_1.name).to eq target_1.manager_ref
end
end
end
end