-
Notifications
You must be signed in to change notification settings - Fork 898
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13437 from mansam/backport-openstack-volume-attac…
…h-detachment-ux-improvements [EUWE] Backport UX improvements for attaching Openstack cloud volumes to instances
- Loading branch information
Showing
6 changed files
with
66 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class ApplicationHelper::Button::InstanceAttach < ApplicationHelper::Button::Basic | ||
def calculate_properties | ||
super | ||
self[:title] = @error_message if disabled? | ||
end | ||
|
||
def disabled? | ||
if @record.cloud_tenant.cloud_volumes.where(:status => 'available').count.zero? | ||
@error_message = _("There are no Cloud Volumes available to attach to this Instance.") | ||
end | ||
@error_message.present? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
class ApplicationHelper::Button::InstanceDetach < ApplicationHelper::Button::Basic | ||
def calculate_properties | ||
super | ||
if @record.number_of(:cloud_volumes) == 0 | ||
self[:title] = _("%{model} \"%{name}\" has no attached %{volumes}") % { | ||
:model => ui_lookup(:table => 'vm_cloud'), | ||
:name => @record.name, | ||
:volumes => ui_lookup(:tables => 'cloud_volumes') | ||
} | ||
end | ||
self[:title] = @error_message if disabled? | ||
end | ||
|
||
def disabled? | ||
@record.number_of(:cloud_volumes) == 0 | ||
if @record.number_of(:cloud_volumes).zero? | ||
@error_message = _("This Instance has no attached Cloud Volumes.") | ||
end | ||
@error_message.present? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
spec/helpers/application_helper/buttons/instance_attach_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
describe ApplicationHelper::Button::InstanceAttach do | ||
describe '#disabled?' do | ||
it "when there are available volumes, then the button is enabled" do | ||
view_context = setup_view_context_with_sandbox({}) | ||
|
||
tenant = FactoryGirl.create(:cloud_tenant_openstack) | ||
volume = FactoryGirl.create(:cloud_volume_openstack, :cloud_tenant => tenant, :status => 'available') | ||
record = FactoryGirl.create(:vm_openstack, :cloud_tenant => tenant) | ||
button = described_class.new(view_context, {}, {"record" => record}, {}) | ||
expect(button.disabled?).to be false | ||
end | ||
|
||
it "when there are no available volumes then the button is disabled" do | ||
view_context = setup_view_context_with_sandbox({}) | ||
tenant = FactoryGirl.create(:cloud_tenant_openstack) | ||
volume = FactoryGirl.create(:cloud_volume_openstack, :cloud_tenant => tenant, :status => 'in-use') | ||
record = FactoryGirl.create(:vm_openstack, :cloud_tenant => tenant) | ||
button = described_class.new(view_context, {}, {"record" => record}, {}) | ||
expect(button.disabled?).to be true | ||
end | ||
end | ||
|
||
describe '#calculate_properties' do | ||
it "when there are no available volumes then the button has the error in the title" do | ||
view_context = setup_view_context_with_sandbox({}) | ||
tenant = FactoryGirl.create(:cloud_tenant_openstack) | ||
volume = FactoryGirl.create(:cloud_volume_openstack, :cloud_tenant => tenant, :status => 'in-use') | ||
record = FactoryGirl.create(:vm_openstack, :cloud_tenant => tenant) | ||
button = described_class.new(view_context, {}, {"record" => record}, {}) | ||
button.calculate_properties | ||
expect(button[:title]).to eq(_("There are no Cloud Volumes available to attach to this Instance.")) | ||
end | ||
|
||
it "when there are available volumes, the button has no error in the title" do | ||
view_context = setup_view_context_with_sandbox({}) | ||
tenant = FactoryGirl.create(:cloud_tenant_openstack) | ||
volume = FactoryGirl.create(:cloud_volume_openstack, :cloud_tenant => tenant, :status => 'available') | ||
record = FactoryGirl.create(:vm_openstack, :cloud_tenant => tenant) | ||
button = described_class.new(view_context, {}, {"record" => record}, {}) | ||
button.calculate_properties | ||
expect(button[:title]).to be nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters