Skip to content

Commit

Permalink
Merge pull request #11564 from h-kataria/vm_compliance_history_link_fix
Browse files Browse the repository at this point in the history
Vm compliance history link fix
(cherry picked from commit 3a73026)

https://bugzilla.redhat.com/show_bug.cgi?id=1382847
  • Loading branch information
Dan Clarizio authored and chessbyte committed Oct 8, 2016
1 parent ece9bf2 commit e89af64
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/helpers/compliance_summary_helper.rb
Expand Up @@ -19,7 +19,7 @@ def textual_compliance_status
{:time => time_ago_in_words(date.in_time_zone(Time.zone)).titleize}
end
h[:title] = _("Show Details of Compliance Check on %{date}") % {:date => format_timezone(date)}
h[:explorer] = true
h[:explorer] = true if @explorer
h[:link] = url_for(
:controller => controller.controller_name,
:action => 'show',
Expand All @@ -39,6 +39,7 @@ def textual_compliance_history(options_if_available = {})
h[:value] = _("Available")
h[:title] = _("Show Compliance History of this %{model} (Last 10 Checks)") %
{:model => ui_lookup(:model => controller.class.model.name)}
h[:explorer] = true if @explorer
h[:link] = url_for(
:controller => controller.controller_name,
:action => 'show',
Expand Down
64 changes: 64 additions & 0 deletions spec/helpers/compliance_summary_helper_spec.rb
@@ -0,0 +1,64 @@
describe ComplianceSummaryHelper do
before do
server = FactoryGirl.build(:miq_server, :id => 0)
@record = FactoryGirl.build(:vm_vmware, :miq_server => server)
@compliance1 = FactoryGirl.build(:compliance)
@compliance2 = FactoryGirl.build(:compliance)
allow_any_instance_of(described_class).to receive(:role_allows?).and_return(true)
end

context "when @explorer is set" do
before do
allow(controller).to receive(:controller_name).and_return("vm_infra")
allow(controller.class).to receive(:model).and_return(VmOrTemplate)
@explorer = true
end

it "#textual_compliance_status" do
@record.compliances = [@compliance1]
date = @compliance1.timestamp
expect(helper.textual_compliance_status).to eq(:label => "Status",
:image => "check",
:value => "Compliant as of #{time_ago_in_words(date.in_time_zone(Time.zone)).titleize} Ago",
:title => "Show Details of Compliance Check on #{format_timezone(date)}",
:explorer => true,
:link => "/vm_infra/show?count=1&display=compliance_history")
end

it "#textual_compliance_history" do
@record.compliances = [@compliance1, @compliance2]
expect(helper.textual_compliance_history).to eq(:label => "History",
:image => "compliance",
:value => "Available",
:explorer => true,
:title => "Show Compliance History of this VM or Template (Last 10 Checks)",
:link => "/vm_infra/show?display=compliance_history")
end
end

context "for classic screens when @explorer is not set" do
before do
allow(controller).to receive(:controller_name).and_return("host")
allow(controller.class).to receive(:model).and_return(Host)
end

it "#textual_compliance_status" do
@record.compliances = [@compliance1]
date = @compliance1.timestamp
expect(helper.textual_compliance_status).to eq(:label => "Status",
:image => "check",
:value => "Compliant as of #{time_ago_in_words(date.in_time_zone(Time.zone)).titleize} Ago",
:title => "Show Details of Compliance Check on #{format_timezone(date)}",
:link => "/host/show?count=1&display=compliance_history")
end

it "#textual_compliance_history" do
@record.compliances = [@compliance1, @compliance2]
expect(helper.textual_compliance_history).to eq(:label => "History",
:image => "compliance",
:value => "Available",
:title => "Show Compliance History of this Host / Node (Last 10 Checks)",
:link => "/host/show?display=compliance_history")
end
end
end

0 comments on commit e89af64

Please sign in to comment.