Skip to content

Commit

Permalink
Properly implement the top minsterial role.
Browse files Browse the repository at this point in the history
We can use whether or not they attempt cabinet to measure their 'seniority'.
  • Loading branch information
lazyatom committed Feb 2, 2012
1 parent 1d98495 commit 10e6760
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/organisation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def search_link
end

def top_ministerial_role
ministerial_roles.first
ministerial_roles.order(MinisterialRole.arel_table[:cabinet_member].desc).first
end

private
Expand Down
11 changes: 9 additions & 2 deletions test/unit/organisation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,16 @@ class OrganisationTest < ActiveSupport::TestCase
assert_equal [], organisation.ministerial_roles
end

test "#top_ministerial_role returns a ministerial role" do
test "#top_ministerial_role returns a ministerial role which attends cabinet" do
minister = create(:ministerial_role)
other_minister = create(:ministerial_role)
other_minister = create(:ministerial_role, cabinet_member: true)
organisation = create(:organisation, roles: [minister, other_minister])
assert_equal other_minister, organisation.top_ministerial_role
end

test "#top_ministerial_role returns first ministerial role if none attends cabinet" do
minister = create(:ministerial_role, cabinet_member: false)
other_minister = create(:ministerial_role, cabinet_member: false)
organisation = create(:organisation, roles: [minister, other_minister])
assert_equal minister, organisation.top_ministerial_role
end
Expand Down

0 comments on commit 10e6760

Please sign in to comment.