diff options
| -rw-r--r-- | spec/models/public_body_spec.rb | 87 | 
1 files changed, 87 insertions, 0 deletions
| diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index 225958cac..db38e3a15 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -28,6 +28,93 @@  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +describe PublicBody do + +  describe :type_of_authority do + +    it 'falls back to "A public authority"' do +      public_body = FactoryGirl.build(:public_body) +      expect(public_body.type_of_authority).to eq('A public authority') +    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 + +        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(<a href="/body/list/spec">Spec category</a>) +          expect(public_body.type_of_authority(true)).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(<a href="/body/list/spec_0">Spec category 0</a>), +            ', ', +            %Q(<a href="/body/list/spec_1">spec category 1</a>), +            ' and ', +            %Q(<a href="/body/list/spec_2">spec category 2</a>) +          ].join('') + +          expect(public_body.type_of_authority(true)).to eq(description) +        end + +      end + +    end + +  end + +end +  describe PublicBody, " using tags" do      before do          @public_body = PublicBody.new(:name => 'Aardvark Monitoring Service', | 
