Skip to content

Commit 7436fe5

Browse files
committed
Use let for host tests
2 parents 95ac377 + c5a643a commit 7436fe5

File tree

2 files changed

+40
-42
lines changed
  • app/models/manageiq/providers/vmware/infra_manager/inventory
  • spec/models/manageiq/providers/vmware/infra_manager

2 files changed

+40
-42
lines changed

app/models/manageiq/providers/vmware/infra_manager/inventory/saver.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ def save_inventory(persister)
1818
private
1919

2020
def update_ems_refresh_stats(ems, error: nil)
21-
ems.update(:last_refresh_error => error, :last_refresh_date => Time.now.utc)
21+
refresh_date = Time.now.utc
22+
23+
ems.last_refresh_error = error
24+
ems.last_refresh_date = refresh_date
25+
ems.last_refresh_success_date = refresh_date if error.nil?
26+
ems.save!
2227
end
2328

2429
def post_refresh(ems, save_inventory_start_time)

spec/models/manageiq/providers/vmware/infra_manager/host_spec.rb

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,83 @@
11
describe ManageIQ::Providers::Vmware::InfraManager::Host do
2-
before(:each) do
3-
@host = FactoryBot.create(:host_vmware)
4-
end
2+
let(:ems) { FactoryBot.create(:ems_vmware) }
3+
let(:host) { FactoryBot.create(:host_vmware, :ext_management_system => ems) }
54

65
context "#reserve_next_available_vnc_port" do
76
context "without EMS defaults set" do
8-
before(:each) do
9-
@ems = FactoryBot.create(:ems_vmware, :host_default_vnc_port_start => nil, :host_default_vnc_port_end => nil)
10-
@host.ext_management_system = @ems
11-
end
7+
let(:ems) { FactoryBot.create(:ems_vmware, :host_default_vnc_port_start => nil, :host_default_vnc_port_end => nil) }
128

139
it "normal case" do
14-
@host.update(:next_available_vnc_port => 5901)
10+
host.update(:next_available_vnc_port => 5901)
1511

16-
expect(@host.reserve_next_available_vnc_port).to eq(5901)
17-
expect(@host.next_available_vnc_port).to eq(5902)
12+
expect(host.reserve_next_available_vnc_port).to eq(5901)
13+
expect(host.next_available_vnc_port).to eq(5902)
1814
end
1915

2016
it "with last value of nil" do
21-
@host.update(:next_available_vnc_port => nil)
17+
host.update(:next_available_vnc_port => nil)
2218

23-
expect(@host.reserve_next_available_vnc_port).to eq(5900)
24-
expect(@host.next_available_vnc_port).to eq(5901)
19+
expect(host.reserve_next_available_vnc_port).to eq(5900)
20+
expect(host.next_available_vnc_port).to eq(5901)
2521
end
2622

2723
it "with last value at end of range" do
28-
@host.update(:next_available_vnc_port => 5999)
24+
host.update(:next_available_vnc_port => 5999)
2925

30-
expect(@host.reserve_next_available_vnc_port).to eq(5999)
31-
expect(@host.next_available_vnc_port).to eq(5900)
26+
expect(host.reserve_next_available_vnc_port).to eq(5999)
27+
expect(host.next_available_vnc_port).to eq(5900)
3228
end
3329

3430
it "with last value before start of range" do
35-
@host.update(:next_available_vnc_port => 5899)
31+
host.update(:next_available_vnc_port => 5899)
3632

37-
expect(@host.reserve_next_available_vnc_port).to eq(5900)
38-
expect(@host.next_available_vnc_port).to eq(5901)
33+
expect(host.reserve_next_available_vnc_port).to eq(5900)
34+
expect(host.next_available_vnc_port).to eq(5901)
3935
end
4036

4137
it "with last value after end of range" do
42-
@host.update(:next_available_vnc_port => 6000)
38+
host.update(:next_available_vnc_port => 6000)
4339

44-
expect(@host.reserve_next_available_vnc_port).to eq(5900)
45-
expect(@host.next_available_vnc_port).to eq(5901)
40+
expect(host.reserve_next_available_vnc_port).to eq(5900)
41+
expect(host.next_available_vnc_port).to eq(5901)
4642
end
4743
end
4844

4945
context "with EMS defaults set" do
50-
before(:each) do
51-
@ems = FactoryBot.create(:ems_vmware, :host_default_vnc_port_start => 5925, :host_default_vnc_port_end => 5930)
52-
@host.ext_management_system = @ems
53-
end
46+
let(:ems) { FactoryBot.create(:ems_vmware, :host_default_vnc_port_start => 5925, :host_default_vnc_port_end => 5930) }
5447

5548
it "normal case" do
56-
@host.update(:next_available_vnc_port => 5926)
49+
host.update(:next_available_vnc_port => 5926)
5750

58-
expect(@host.reserve_next_available_vnc_port).to eq(5926)
59-
expect(@host.next_available_vnc_port).to eq(5927)
51+
expect(host.reserve_next_available_vnc_port).to eq(5926)
52+
expect(host.next_available_vnc_port).to eq(5927)
6053
end
6154

6255
it "with last value of nil" do
63-
@host.update(:next_available_vnc_port => nil)
56+
host.update(:next_available_vnc_port => nil)
6457

65-
expect(@host.reserve_next_available_vnc_port).to eq(5925)
66-
expect(@host.next_available_vnc_port).to eq(5926)
58+
expect(host.reserve_next_available_vnc_port).to eq(5925)
59+
expect(host.next_available_vnc_port).to eq(5926)
6760
end
6861

6962
it "with last value at end of range" do
70-
@host.update(:next_available_vnc_port => 5930)
63+
host.update(:next_available_vnc_port => 5930)
7164

72-
expect(@host.reserve_next_available_vnc_port).to eq(5930)
73-
expect(@host.next_available_vnc_port).to eq(5925)
65+
expect(host.reserve_next_available_vnc_port).to eq(5930)
66+
expect(host.next_available_vnc_port).to eq(5925)
7467
end
7568

7669
it "with last value before start of range" do
77-
@host.update(:next_available_vnc_port => 5924)
70+
host.update(:next_available_vnc_port => 5924)
7871

79-
expect(@host.reserve_next_available_vnc_port).to eq(5925)
80-
expect(@host.next_available_vnc_port).to eq(5926)
72+
expect(host.reserve_next_available_vnc_port).to eq(5925)
73+
expect(host.next_available_vnc_port).to eq(5926)
8174
end
8275

8376
it "with last value after end of range" do
84-
@host.update(:next_available_vnc_port => 5931)
77+
host.update(:next_available_vnc_port => 5931)
8578

86-
expect(@host.reserve_next_available_vnc_port).to eq(5925)
87-
expect(@host.next_available_vnc_port).to eq(5926)
79+
expect(host.reserve_next_available_vnc_port).to eq(5925)
80+
expect(host.next_available_vnc_port).to eq(5926)
8881
end
8982
end
9083
end

0 commit comments

Comments
 (0)