Skip to content

Commit

Permalink
Merge pull request ManageIQ#9153 from kbrock/supports_unsupports
Browse files Browse the repository at this point in the history
stub_supports uses specific class
  • Loading branch information
Fryguy authored Apr 5, 2024
2 parents a791d15 + ed68bfc commit 5d9bb09
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions spec/controllers/application_controller/ci_processing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -644,22 +644,22 @@
before { controller.instance_variable_set(:@reconfigitems, [vm]) }

context "when vm supports reconfiguring disks" do
before { stub_supports(Vm, :reconfigure_disks) }
before { stub_supports(vm.class, :reconfigure_disks) }
it "enables reconfigure disks" do
expect(controller.send(:item_supports?, :reconfigure_disks)).to be_truthy
end
end

context "when vm does not supports reconfiguring disks" do
before { stub_supports_not(Vm, :reconfigure_disks) }
before { stub_supports_not(vm.class, :reconfigure_disks) }
it "disables reconfigure disks" do
expect(controller.send(:item_supports?, :reconfigure_disks)).to be_falsey
end
end
end

context "when multiple vms selected" do
before { stub_supports(Vm, :reconfigure_disks) }
before { stub_supports(vm.class, :reconfigure_disks) }
let(:vm1) { FactoryBot.create(:vm_redhat) }

it "disables reconfigure disks" do
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/cloud_object_store_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
end

it "delete shows expected flash" do
stub_supports(CloudObjectStoreObject, :delete)
stub_supports(object.class, :delete)

post :button, :params => {
:pressed => "cloud_object_store_object_delete", :format => :js, :id => object.id
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/storage_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@
host = FactoryBot.create(:host)
command = button.split('_', 2)[1]

stub_supports_all_others(Host)
stub_supports(Host, command)
stub_supports_all_others(host.class)
stub_supports(host.class, command)

controller.params = {:pressed => button, :miq_grid_checks => host.id.to_s}
controller.instance_variable_set(:@lastaction, "show_list")
Expand Down
5 changes: 2 additions & 3 deletions spec/controllers/vm_infra_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,8 @@
end

it 'can set retirement date' do
# allow the other supports (from other buttons) to still work:
allow_any_instance_of(Vm).to receive(:supports?).and_call_original
stub_supports(Vm, :retire)
stub_supports_all_others(vm_vmware.class)
stub_supports(vm_vmware.class, :retire)
get :show, :params => {:id => vm_vmware.id}
expect(response).to redirect_to(:action => 'explorer')

Expand Down
4 changes: 2 additions & 2 deletions spec/helpers/application_helper/buttons/vm_retire_now_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
context "when record is retireable" do
before do
@record = FactoryBot.create(:vm_vmware)
stub_supports(Vm, :retire)
stub_supports(@record.class, :retire)
end

it_behaves_like "will not be skipped for this record"
Expand All @@ -12,7 +12,7 @@
context "when record is not retiretable" do
before do
@record = FactoryBot.create(:vm_vmware)
stub_supports_not(Vm, :retire)
stub_supports_not(@record.class, :retire)
end

it_behaves_like "will be skipped for this record"
Expand Down
4 changes: 2 additions & 2 deletions spec/helpers/application_helper/buttons/vm_retire_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
context "when record is retireable" do
before do
@record = FactoryBot.create(:vm_vmware)
stub_supports(Vm, :retire)
stub_supports(@record.class, :retire)
end

it_behaves_like "will not be skipped for this record"
Expand All @@ -12,7 +12,7 @@
context "when record is not retiretable" do
before do
@record = FactoryBot.create(:vm_vmware)
stub_supports_not(Vm, :retire)
stub_supports_not(@record.class, :retire)
end

it_behaves_like "will be skipped for this record"
Expand Down
11 changes: 6 additions & 5 deletions spec/helpers/application_helper/buttons/volume_detach_spec.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
describe ApplicationHelper::Button::VolumeDetach do
let(:record) { CloudVolume.new }
let(:button) do
described_class.new(
setup_view_context_with_sandbox({}), {}, {"record" => CloudVolume.new}, {}
setup_view_context_with_sandbox({}), {}, {"record" => record}, {}
)
end

describe '#disabled?' do
it "when the detach action is supported, then the button is enabled" do
stub_supports(CloudVolume, :detach)
stub_supports(record.class, :detach)
expect(button.disabled?).to be false
end

it "when the detach action is not supported, then the button is disabled" do
stub_supports_not(CloudVolume, :detach, "unavailable")
stub_supports_not(record.class, :detach, "unavailable")
expect(button.disabled?).to be true
end
end

describe '#calculate_properties' do
it "when the detach action is not supported, then the button has the error in the title" do
stub_supports_not(CloudVolume, :detach, "unavailable")
stub_supports_not(record.class, :detach, "unavailable")
button.calculate_properties
expect(button[:title]).to eq("unavailable")
end

it "when the detach action is not supported, the button has no error in the title" do
stub_supports(CloudVolume, :detach)
stub_supports(record.class, :detach)
button.calculate_properties
expect(button[:title]).to be nil
end
Expand Down

0 comments on commit 5d9bb09

Please sign in to comment.