aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/public_body.rb10
-rw-r--r--app/views/public_body/show.html.erb2
-rw-r--r--spec/models/public_body_spec.rb51
3 files changed, 12 insertions, 51 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index c023b436c..b9519c1aa 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -347,7 +347,7 @@ class PublicBody < ActiveRecord::Base
# Use tags to describe what type of thing this is
- def type_of_authority(html = false)
+ def type_of_authority
types = tags.each_with_index.map do |tag, index|
if PublicBodyCategory.get().by_tag().include?(tag.name)
desc = PublicBodyCategory.get().singular_by_tag()[tag.name]
@@ -355,12 +355,8 @@ class PublicBody < ActiveRecord::Base
if index.zero?
desc = desc.sub(/\S/) { |m| Unicode.upcase(m) }
end
-
- if html
- # TODO: this should call proper route helpers, but is in model sigh
- desc = '<a href="/body/list/' + tag.name + '">' + desc + '</a>'
- end
-
+ # TODO: this should call proper route helpers, but is in model sigh
+ desc = '<a href="/body/list/' + tag.name + '">' + desc + '</a>'
desc
end
end
diff --git a/app/views/public_body/show.html.erb b/app/views/public_body/show.html.erb
index e7c5fa2b6..bce396cd8 100644
--- a/app/views/public_body/show.html.erb
+++ b/app/views/public_body/show.html.erb
@@ -32,7 +32,7 @@
<h1><%=h(@public_body.name)%></h1>
<p class="subtitle">
- <%=@public_body.type_of_authority(true)%><% if not @public_body.short_name.empty? %>,
+ <%= @public_body.type_of_authority %><% if not @public_body.short_name.empty? %>,
<%= _('also called {{public_body_short_name}}', :public_body_short_name => h(@public_body.short_name))%><% end %>
<% if !@user.nil? && @user.admin_page_links? %>
(<%= link_to _("admin"), admin_body_path(@public_body) %>)
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index b90696c25..f90e61848 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -45,7 +45,7 @@ describe PublicBody do
public_body = FactoryGirl.create(:public_body, :tag_string => 'spec')
- expect(public_body.type_of_authority).to eq('Ünicode category')
+ expect(public_body.type_of_authority).to eq('<a href="/body/list/spec">Ünicode category</a>')
end
it 'constructs the correct string if there are tags which are not categories' do
@@ -56,44 +56,12 @@ describe PublicBody do
heading.add_category(category)
end
public_body = FactoryGirl.create(:public_body, :tag_string => 'spec_0 spec_2 unknown')
-
- expect(public_body.type_of_authority).to eq('Spec category 0 and spec category 2')
+ expected = '<a href="/body/list/spec_0">Spec category 0</a> and <a href="/body/list/spec_2">spec category 2</a>'
+ expect(public_body.type_of_authority).to eq(expected)
end
- context 'when associated with one category' do
-
- it 'returns the capitalised category description' do
- category = FactoryGirl.create(:public_body_category, :category_tag => 'spec',
- :description => 'spec category')
- heading = FactoryGirl.create(:public_body_heading)
- heading.add_category(category)
- public_body = FactoryGirl.create(:public_body, :tag_string => 'spec')
-
- expect(public_body.type_of_authority).to eq('Spec category')
- end
-
- end
- context 'when associated with several categories' do
-
- it 'joins the category descriptions and capitalizes the first letter' do
- heading = FactoryGirl.create(:public_body_heading)
- 3.times do |i|
- category = FactoryGirl.create(:public_body_category, :category_tag => "spec_#{i}",
- :description => "spec category #{i}")
- heading.add_category(category)
- end
- public_body = FactoryGirl.create(:public_body, :tag_string => 'spec_0 spec_1 spec_2')
-
- description = 'Spec category 0, spec category 1 and spec category 2'
- expect(public_body.type_of_authority).to eq(description)
- end
-
- end
-
- context 'when the html parameter is true' do
-
- context 'when associated with one category' do
+ context 'when associated with one category' do
it 'returns the description wrapped in an anchor tag' do
category = FactoryGirl.create(:public_body_category, :category_tag => 'spec',
@@ -103,12 +71,11 @@ describe PublicBody do
public_body = FactoryGirl.create(:public_body, :tag_string => 'spec')
anchor = %Q(<a href="/body/list/spec">Spec category</a>)
- expect(public_body.type_of_authority(true)).to eq(anchor)
+ expect(public_body.type_of_authority).to eq(anchor)
end
+ end
- end
-
- context 'when associated with several categories' do
+ context 'when associated with several categories' do
it 'joins the category descriptions and capitalizes the first letter' do
heading = FactoryGirl.create(:public_body_heading)
@@ -127,11 +94,9 @@ describe PublicBody do
%Q(<a href="/body/list/spec_2">spec category 2</a>)
].join('')
- expect(public_body.type_of_authority(true)).to eq(description)
+ expect(public_body.type_of_authority).to eq(description)
end
- end
-
end
end