Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #16704 - Allow filtering on dashboard
Some filters on the dashboard caused the reports widget to break, specifically searching using free text or on attributes that are not part of the hosts table (such as environment name). This is caused by an issue with Rails that digregards outer joins when a query is used as an inner query for a where clause using hash syntax.
- Loading branch information
Showing
2 changed files
with
89 additions
and
1 deletion.
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,86 @@ | ||
require 'test_helper' | ||
|
||
class DashboardTest < ActiveSupport::TestCase | ||
setup do | ||
@env = FactoryGirl.create(:environment) | ||
@host = FactoryGirl.create(:host, :with_reports, :environment => @env) | ||
end | ||
|
||
test 'hosts returns correct host' do | ||
data = Dashboard::Data.new | ||
|
||
as_admin do | ||
assert_equal 1, data.hosts.length | ||
end | ||
end | ||
|
||
test 'hosts works with environment filter' do | ||
data = Dashboard::Data.new("environment = #{@env.name}") | ||
|
||
as_admin do | ||
assert_equal 1, data.hosts.length | ||
end | ||
end | ||
|
||
test 'hosts works with free text filter' do | ||
data = Dashboard::Data.new(@env.name) | ||
|
||
as_admin do | ||
assert_equal 1, data.hosts.length | ||
end | ||
end | ||
|
||
test 'hosts works with a filter that returns no hosts' do | ||
data = Dashboard::Data.new("name = DoesNotExist") | ||
|
||
as_admin do | ||
assert_equal 0, data.hosts.length | ||
end | ||
end | ||
|
||
test 'latest_events does not return uneventful reports' do | ||
data = Dashboard::Data.new | ||
|
||
as_admin do | ||
assert_equal 0, data.latest_events.length | ||
end | ||
end | ||
|
||
context 'with eventful report' do | ||
setup do | ||
@host.reports.first.update_attribute(:status, 2) | ||
end | ||
|
||
test 'latest_events returns latest events' do | ||
data = Dashboard::Data.new | ||
|
||
as_admin do | ||
assert_equal 1, data.latest_events.length | ||
end | ||
end | ||
|
||
test 'latest_events works with environment filter' do | ||
data = Dashboard::Data.new("environment = #{@env.name}") | ||
|
||
as_admin do | ||
assert_equal 1, data.latest_events.length | ||
end | ||
end | ||
|
||
test 'latest_events works with free text filter' do | ||
data = Dashboard::Data.new(@env.name) | ||
|
||
as_admin do | ||
assert_equal 1, data.latest_events.length | ||
end | ||
end | ||
|
||
test 'latest_events works with a filter that returns no hosts' do | ||
data = Dashboard::Data.new("name = DoesNotExist") | ||
|
||
as_admin do | ||
assert_equal 0, data.latest_events.length | ||
end | ||
end | ||
end | ||
end |