-
Notifications
You must be signed in to change notification settings - Fork 896
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 #11715 from romanblanco/toolbar_button_refactoring…
…_server_role Toolbar button refactoring server role
- Loading branch information
Showing
14 changed files
with
408 additions
and
159 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
app/helpers/application_helper/button/role_power_options.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,10 @@ | ||
class ApplicationHelper::Button::RolePowerOptions < ApplicationHelper::Button::Basic | ||
needs :@record, :@sb | ||
|
||
def visible? | ||
@view_context.x_active_tree == :diagnostics_tree && | ||
%w(diagnostics_roles_servers diagnostics_servers_roles).include?(@sb[:active_tab]) && | ||
@record.class == AssignedServerRole && | ||
@record.miq_server.started? | ||
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class ApplicationHelper::Button::RoleStart < ApplicationHelper::Button::RolePowerOptions | ||
needs :@record, :@sb | ||
|
||
def calculate_properties | ||
super | ||
self[:title] = @error_message if disabled? | ||
end | ||
|
||
def disabled? | ||
@error_message = if @record.class == AssignedServerRole | ||
if @record.active | ||
N_("This Role is already active on this Server") | ||
elsif !@record.miq_server.started? | ||
N_("Only available Roles on active Servers can be started") | ||
elsif @view_context.x_node != "root" && @record.server_role.regional_role? | ||
N_("This role can only be managed at the Region level") | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class ApplicationHelper::Button::RoleSuspend < ApplicationHelper::Button::RolePowerOptions | ||
needs :@record, :@sb | ||
|
||
def calculate_properties | ||
super | ||
self[:title] = @error_message if disabled? | ||
end | ||
|
||
def disabled? | ||
@error_message = if @view_context.x_node != "root" && @record.server_role.regional_role? | ||
N_("This role can only be managed at the Region level") | ||
else | ||
if @record.active | ||
unless @record.server_role.max_concurrent != 1 | ||
N_("Activate the %{server_role_description} Role on another Server to suspend it on %{server_name} [%{server_id}]") % | ||
{:server_role_description => @record.server_role.description, | ||
:server_name => @record.miq_server.name, | ||
:server_id => @record.miq_server.id} | ||
end | ||
else | ||
N_("Only active Roles on active Servers can be suspended") | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class ApplicationHelper::Button::ServerDemote < ApplicationHelper::Button::ServerLevelOptions | ||
needs :@record, :@sb | ||
|
||
def calculate_properties | ||
super | ||
self[:title] = @error_message if disabled? | ||
end | ||
|
||
def disabled? | ||
@error_message = if @record.master_supported? | ||
if @record.priority == 1 || @record.priority == 2 | ||
if @view_context.x_node != "root" && @record.server_role.regional_role? | ||
N_("This role can only be managed at the Region level") | ||
end | ||
end | ||
end | ||
@error_message.present? | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
app/helpers/application_helper/button/server_level_options.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,10 @@ | ||
class ApplicationHelper::Button::ServerLevelOptions < ApplicationHelper::Button::Basic | ||
needs :@record, :@sb | ||
|
||
def visible? | ||
@view_context.x_active_tree == :diagnostics_tree && | ||
%w(diagnostics_roles_servers diagnostics_servers_roles).include?(@sb[:active_tab]) && | ||
@record.class == AssignedServerRole && | ||
@record.master_supported? | ||
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class ApplicationHelper::Button::ServerPromote < ApplicationHelper::Button::ServerLevelOptions | ||
needs :@record, :@sb | ||
|
||
def calculate_properties | ||
super | ||
self[:title] = @error_message if disabled? | ||
end | ||
|
||
def disabled? | ||
@error_message = if @record.master_supported? | ||
if (@record.priority != 1 && @record.priority != 2) || @record.priority == 2 | ||
if @view_context.x_node != "root" && @record.server_role.regional_role? | ||
N_("This role can only be managed at the Region level") | ||
end | ||
end | ||
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
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
110 changes: 110 additions & 0 deletions
110
spec/helpers/application_helper/buttons/role_start_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,110 @@ | ||
describe ApplicationHelper::Button::RoleStart do | ||
describe '#visible?' do | ||
context "record is assigned server role and miq server is started" do | ||
before do | ||
@record = FactoryGirl.create( | ||
:assigned_server_role, | ||
:miq_server => FactoryGirl.create(:miq_server) | ||
) | ||
allow(@record.miq_server).to receive(:started?).and_return(true) | ||
end | ||
|
||
it "will not be skipped for this record" do | ||
view_context = setup_view_context_with_sandbox({}) | ||
button = described_class.new(view_context, {}, {'record' => @record}, {}) | ||
button.instance_variable_set(:@sb, {:active_tab => "diagnostics_roles_servers"}) | ||
allow(view_context).to receive(:x_active_tree).and_return(:diagnostics_tree) | ||
expect(button.visible?).to be_truthy | ||
end | ||
end | ||
|
||
context "record is server role" do | ||
before do | ||
@record = FactoryGirl.create(:server_role, :name => "biggus_dickus") | ||
end | ||
|
||
it "will be skipped for this record" do | ||
view_context = setup_view_context_with_sandbox({}) | ||
button = described_class.new(view_context, {}, {'record' => @record}, {}) | ||
button.instance_variable_set(:@sb, {:active_tab => "diagnostics_roles_servers"}) | ||
allow(view_context).to receive(:x_active_tree).and_return(:diagnostics_tree) | ||
expect(button.visible?).to be_falsey | ||
end | ||
end | ||
|
||
context "record is miq server" do | ||
before do | ||
@record = FactoryGirl.create(:miq_server) | ||
end | ||
|
||
it "will be skipped for this record" do | ||
view_context = setup_view_context_with_sandbox({}) | ||
button = described_class.new(view_context, {}, {'record' => @record}, {}) | ||
button.instance_variable_set(:@sb, {:active_tab => "diagnostics_roles_servers"}) | ||
allow(view_context).to receive(:x_active_tree).and_return(:diagnostics_tree) | ||
expect(button.visible?).to be_falsey | ||
end | ||
end | ||
end | ||
|
||
describe '#disabled?' do | ||
context "record is active assigned server role" do | ||
before do | ||
@record = FactoryGirl.create(:assigned_server_role) | ||
allow(@record).to receive(:active?).and_return(true) | ||
end | ||
|
||
it "disables the button and returns the error message" do | ||
view_context = setup_view_context_with_sandbox({}) | ||
button = described_class.new(view_context, {}, {'record' => @record}, {}) | ||
expect(button.disabled?).to be_truthy | ||
button.calculate_properties | ||
expect(button[:title]).to eq("This Role is already active on this Server") | ||
end | ||
end | ||
|
||
context "record is inactive assigned server role" do | ||
before do | ||
@record = FactoryGirl.create( | ||
:assigned_server_role, | ||
:active => false, | ||
:miq_server => FactoryGirl.create(:miq_server) | ||
) | ||
allow(@record.miq_server).to receive(:started?).and_return(false) | ||
end | ||
|
||
it "disables the button and returns the error message" do | ||
view_context = setup_view_context_with_sandbox({}) | ||
button = described_class.new(view_context, {}, {'record' => @record}, {}) | ||
expect(button.disabled?).to be_truthy | ||
button.calculate_properties | ||
expect(button[:title]).to eq("Only available Roles on active Servers can be started") | ||
end | ||
end | ||
|
||
context "record is inactive assigned server role" do | ||
before do | ||
@record = FactoryGirl.create( | ||
:assigned_server_role, | ||
:active => false, | ||
:miq_server => FactoryGirl.create(:miq_server), | ||
:server_role => FactoryGirl.create( | ||
:server_role, | ||
:name => "dr_fetus" | ||
) | ||
) | ||
allow(@record.server_role).to receive(:regional_role?).and_return(true) | ||
allow(@record.miq_server).to receive(:started?).and_return(true) | ||
end | ||
|
||
it "disables the button and returns the error message" do | ||
view_context = setup_view_context_with_sandbox({}) | ||
button = described_class.new(view_context, {}, {'record' => @record}, {}) | ||
allow(view_context).to receive(:x_node).and_return('z-1r23') | ||
expect(button.disabled?).to be_truthy | ||
button.calculate_properties | ||
expect(button[:title]).to eq("This role can only be managed at the Region level") | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.