From 0947b1445ce4e6ac73e2a7a1536ab4aac775f6a6 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 26 Feb 2015 16:27:04 +0000 Subject: Use routing helper to generate localised urls. --- spec/helpers/public_body_helper_spec.rb | 93 ++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) (limited to 'spec/helpers') diff --git a/spec/helpers/public_body_helper_spec.rb b/spec/helpers/public_body_helper_spec.rb index 89a4d0641..0bf55abb4 100644 --- a/spec/helpers/public_body_helper_spec.rb +++ b/spec/helpers/public_body_helper_spec.rb @@ -1,3 +1,4 @@ +# encoding: UTF-8 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe PublicBodyHelper do @@ -23,7 +24,7 @@ describe PublicBodyHelper do @body.tag_string = 'defunct' msg = 'This authority no longer exists, so you cannot make a request to it.' expect(public_body_not_requestable_reasons(@body)).to include(msg) - end + end it 'links to the request page if the body has no contact email' do @body.request_email = '' @@ -47,4 +48,94 @@ describe PublicBodyHelper do end + + describe :type_of_authority do + + it 'falls back to "A public authority"' do + public_body = FactoryGirl.build(:public_body) + expect(type_of_authority(public_body)).to eq('A public authority') + end + + it 'handles Unicode' do + category = FactoryGirl.create(:public_body_category, :category_tag => 'spec', + :description => 'ünicode category') + heading = FactoryGirl.create(:public_body_heading) + heading.add_category(category) + public_body = FactoryGirl.create(:public_body, :tag_string => 'spec') + + + expect(type_of_authority(public_body)).to eq('Ünicode category') + end + + it 'constructs the correct string if there are tags which are not categories' 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_2 unknown') + expected = 'Spec category 0 and spec category 2' + expect(type_of_authority(public_body)).to eq(expected) + end + + + 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', + :description => 'spec category') + heading = FactoryGirl.create(:public_body_heading) + heading.add_category(category) + public_body = FactoryGirl.create(:public_body, :tag_string => 'spec') + + anchor = %Q(Spec category) + expect(type_of_authority(public_body)).to eq(anchor) + 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 = [ + %Q(Spec category 0), + ', ', + %Q(spec category 1), + ' and ', + %Q(spec category 2) + ].join('') + + expect(type_of_authority(public_body)).to eq(description) + end + + end + + context 'when in a non-default locale' do + + it 'creates the anchor href in the correct locale' do + # Activate the routing filter, normally turned off for helper tests + RoutingFilter.active = true + 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') + + anchor = %Q(Spec category) + I18n.with_locale(:es) { expect(type_of_authority(public_body) +).to eq(anchor) } + end + + end + + end + end -- cgit v1.2.3