Skip to content

Commit

Permalink
Refactored test to not hit the DB
Browse files Browse the repository at this point in the history
  • Loading branch information
romanblanco committed Sep 30, 2016
1 parent 682f363 commit bc2f2cb
Showing 1 changed file with 25 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit bc2f2cb

Please sign in to comment.