diff --git a/spec/helpers/application_helper/buttons/generic_feature_button_with_disable_spec.rb b/spec/helpers/application_helper/buttons/generic_feature_button_with_disable_spec.rb index cb4662ffcf2..dd596787294 100644 --- a/spec/helpers/application_helper/buttons/generic_feature_button_with_disable_spec.rb +++ b/spec/helpers/application_helper/buttons/generic_feature_button_with_disable_spec.rb @@ -1,50 +1,31 @@ describe ApplicationHelper::Button::GenericFeatureButtonWithDisable do - [:start, :stop, :suspend, :reset, :reboot_guest, - :collect_running_processes, :shutdown_guest].each do |feature| - describe '#visible?' do - context "when vm supports feature #{feature}" do - before do - @record = FactoryGirl.create(:vm_vmware) - if @record.respond_to?("supports_#{feature}?") - allow(@record).to receive("supports_#{feature}?").and_return(true) - else - allow(@record).to receive(:is_available?).with(feature).and_return(true) - end - end - - it "will not be skipped for this vm" do - view_context = setup_view_context_with_sandbox({}) - button = described_class.new(view_context, {}, {'record' => @record}, {:options => {:feature => feature}}) - expect(button.visible?).to be_truthy - end + describe '#disabled?' do + context "when record has an error message" do + it "disables the button and returns the stop error message" do + record = double + message = "xx stop message" + allow(record).to receive(:feature_known?).with(:some_feature).and_return(true) + allow(record).to receive(:supports?).with(:some_feature).and_return(false) + allow(record).to receive(:unsupported_reason).with(:some_feature).and_return(message) + view_context = setup_view_context_with_sandbox({}) + button = described_class.new(view_context, {}, {'record' => record}, {:options => {:feature => :some_feature}}) + expect(button.disabled?).to be_truthy + button.calculate_properties + expect(button[:title]).to eq(message) end - context "when instance does not support feature #{feature}" do - before do - @record = FactoryGirl.create(:vm_vmware) - allow(@record).to receive(:is_available?).with(feature).and_return(false) - end - - it "will be skipped for this vm" do - view_context = setup_view_context_with_sandbox({}) - button = described_class.new(view_context, {}, {'record' => @record}, {:options => {:feature => feature}}) - expect(button.visible?).to be_falsey - end - end - end - describe '#disabled?' do - context "when record has an error message" do - before do - @record = FactoryGirl.create(:vm_vmware) - message = "xx stop message" - allow(@record).to receive(:is_available_now_error_message).with(feature).and_return(message) - end - - it "disables the button and returns the stop error message" do - view_context = setup_view_context_with_sandbox({}) - button = described_class.new(view_context, {}, {'record' => @record}, {:options => {:feature => feature}}) - expect(button.disabled?).to be_truthy - end + it "disables the button and returns the stop error message" do + # TODO: remove with deleting AvailabilityMixin module + record = double + message = "xx stop message" + allow(record).to receive(:feature_known?).with(:some_feature).and_return(false) + allow(record).to receive(:is_available?).with(:some_feature).and_return(false) + allow(record).to receive(:is_available_now_error_message).with(:some_feature).and_return(message) + view_context = setup_view_context_with_sandbox({}) + button = described_class.new(view_context, {}, {'record' => record}, {:options => {:feature => :some_feature}}) + expect(button.disabled?).to be_truthy + button.calculate_properties + expect(button[:title]).to eq(message) end end end