Skip to content

Commit

Permalink
Look up Users' organisation titles from Content Items
Browse files Browse the repository at this point in the history
We currently try to infer the title of a user's organisation by [`titleize`ing][1] their organisation slug. However, this doesn't work in all cases. For example, HMRC has the slug `/hm-revenue-customs`, which titleizes to "Hm Revenue Customs", when the actual title of the organisation is "HM Revenue & Customs" (note the incorrect capitalization of "HM" and the missing ampersand).

This change removes the titleization, and instead explicitly looks up the organisation title from the organisation's Content Item. This is done for both auditors and assignees.

[1]: http://api.rubyonrails.org/v5.1/classes/ActiveSupport/Inflector.html#method-i-titleize
  • Loading branch information
Alec Gibson authored and Alec Gibson committed Oct 23, 2017
1 parent 37e2b2a commit 47ce7df
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 16 deletions.
1 change: 0 additions & 1 deletion app/decorators/audits/audit_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class AuditDecorator < Draper::Decorator

decorates_association :responses
decorates_association :content_item
decorates_association :user

def incomplete?
object.new_record?
Expand Down
2 changes: 1 addition & 1 deletion app/decorators/content/item_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def auditor
end

def auditor_org
allocation.user.organisation_slug.titleize
allocation.user.organisation&.title
end

private
Expand Down
8 changes: 0 additions & 8 deletions app/decorators/user_decorator.rb

This file was deleted.

4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ class User < ApplicationRecord
include GDS::SSO::User

serialize :permissions, Array

def organisation
@organisation ||= Content::Item.find_by(content_id: organisation_content_id)
end
end
2 changes: 1 addition & 1 deletion app/views/audits/audits/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<% else %>
<p><%= audit.last_updated %></p>
<p>by <%= audit.user.name %></p>
<p><%= audit.user.department %></p>
<p><%= audit.user.organisation&.title %></p>
<% end %>
</div>

Expand Down
31 changes: 30 additions & 1 deletion spec/features/audit/audit/audit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,20 @@
)
end

let!(:user) { create(:user) }
let!(:my_organisation) do
create(
:organisation,
title: "YA Authors",
)
end

let!(:me) do
create(
:user,
name: "Garth Nix",
organisation: my_organisation,
)
end

def answer_question(question, answer)
find('p', text: question)
Expand Down Expand Up @@ -136,4 +149,20 @@ def expect_answer(question, answer)
expect(find_field("Where should users be redirected to? (optional)").value).to eq("")
expect(find_field("URLs of similar pages").value).to eq("")
end

context "a content item is assigned to me" do
let!(:sabriel) do
create(
:content_item,
allocated_to: me,
)
end

scenario "my name and organisation are shown on the content item" do
visit content_item_audit_path(sabriel)

expect(page).to have_content("Garth Nix")
expect(page).to have_content("YA Authors")
end
end
end
17 changes: 13 additions & 4 deletions spec/features/audit/audit/metadata_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
RSpec.feature "Audit metadata", type: :feature do
let!(:my_organisation) do
create(
:organisation,
title: "Authors",
)
end

let!(:me) do
create(
:user,
name: "Harper Lee",
organisation: my_organisation,
)
end

Expand Down Expand Up @@ -62,14 +70,15 @@ def create_linked_content(link_type, title)
create_linked_content("topics", "Borders")
create_linked_content("policy_areas", "Borders and Immigration")

user = create(:user, name: "Edd the Duck")
create(:allocation, content_item: content_item, user: user)
cbbc = create(:organisation, title: "CBBC")
edd = create(:user, name: "Edd the Duck", organisation: cbbc)
create(:allocation, content_item: content_item, user: edd)

visit content_item_audit_path(content_item)

within("#metadata") do
allocated_text = "Assigned to Edd the Duck Government Digital Service"
audited_text = "Audited 01/01/17 (less than a minute ago) by Harper Lee Government Digital Service"
allocated_text = "Assigned to Edd the Duck CBBC"
audited_text = "Audited 01/01/17 (less than a minute ago) by Harper Lee Authors"
expect(page).to have_selector("#allocated", text: allocated_text)
expect(page).to have_selector("#audited", text: audited_text)
expect(page).to have_selector("#organisations", text: "Organisations Home office")
Expand Down

0 comments on commit 47ce7df

Please sign in to comment.