diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/helpers/public_body_helper_spec.rb | 50 | ||||
-rw-r--r-- | spec/models/public_body_spec.rb | 125 | ||||
-rw-r--r-- | spec/views/public_body/show.html.erb_spec.rb | 21 |
3 files changed, 186 insertions, 10 deletions
diff --git a/spec/helpers/public_body_helper_spec.rb b/spec/helpers/public_body_helper_spec.rb new file mode 100644 index 000000000..89a4d0641 --- /dev/null +++ b/spec/helpers/public_body_helper_spec.rb @@ -0,0 +1,50 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe PublicBodyHelper do + include PublicBodyHelper + + describe :public_body_not_requestable_reasons do + + before do + @body = FactoryGirl.build(:public_body) + end + + it 'returns an empty array if there are no reasons' do + expect(public_body_not_requestable_reasons(@body)).to eq([]) + end + + it 'includes a reason if the law does not apply to the authority' do + @body.tag_string = 'not_apply' + msg = 'Freedom of Information law does not apply to this authority, so you cannot make a request to it.' + expect(public_body_not_requestable_reasons(@body)).to include(msg) + end + + it 'includes a reason if the body no longer exists' 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 + + it 'links to the request page if the body has no contact email' do + @body.request_email = '' + msg = %Q(<a href="/new/#{ @body.url_name }" + class="link_button_green">Make + a request to this authority</a>).squish + + expect(public_body_not_requestable_reasons(@body)).to include(msg) + end + + it 'returns the reasons in order of importance' do + @body.tag_string = 'defunct not_apply' + @body.request_email = '' + + reasons = public_body_not_requestable_reasons(@body) + + expect(reasons[0]).to match(/no longer exists/) + expect(reasons[1]).to match(/does not apply/) + expect(reasons[2]).to match(/Make a request/) + end + + end + +end diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index a9e801bfd..7d48fa169 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -868,6 +868,53 @@ describe PublicBody do end + describe :has_request_email? do + + before do + @body = PublicBody.new(:request_email => 'test@example.com') + end + + it 'should return false if request_email is nil' do + @body.request_email = nil + @body.has_request_email?.should == false + end + + it 'should return false if the request email is "blank"' do + @body.request_email = 'blank' + @body.has_request_email?.should == false + end + + it 'should return false if the request email is an empty string' do + @body.request_email = '' + @body.has_request_email?.should == false + end + + it 'should return true if the request email is an email address' do + @body.has_request_email?.should == true + end + end + + describe :special_not_requestable_reason do + + before do + @body = PublicBody.new + end + + it 'should return true if the body is defunct' do + @body.stub!(:defunct?).and_return(true) + @body.special_not_requestable_reason?.should == true + end + + it 'should return true if FOI does not apply' do + @body.stub!(:not_apply?).and_return(true) + @body.special_not_requestable_reason?.should == true + end + + it 'should return false if the body is not defunct and FOI applies' do + @body.special_not_requestable_reason?.should == false + end + end + end describe PublicBody, " when override all public body request emails set" do @@ -960,3 +1007,81 @@ describe PublicBody, 'when asked for popular bodies' do end end + +describe PublicBody do + + describe :is_requestable? do + + before do + @body = PublicBody.new(:request_email => 'test@example.com') + end + + it 'should return false if the body is defunct' do + @body.stub!(:defunct?).and_return true + @body.is_requestable?.should == false + end + + it 'should return false if FOI does not apply' do + @body.stub!(:not_apply?).and_return true + @body.is_requestable?.should == false + end + + it 'should return false there is no request_email' do + @body.stub!(:has_request_email?).and_return false + @body.is_requestable?.should == false + end + + it 'should return true if the request email is an email address' do + @body.is_requestable?.should == true + end + + end + + describe :is_followupable? do + + before do + @body = PublicBody.new(:request_email => 'test@example.com') + end + + it 'should return false there is no request_email' do + @body.stub!(:has_request_email?).and_return false + @body.is_followupable?.should == false + end + + it 'should return true if the request email is an email address' do + @body.is_followupable?.should == true + end + + end + + describe :not_requestable_reason do + + before do + @body = PublicBody.new(:request_email => 'test@example.com') + end + + it 'should return "defunct" if the body is defunct' do + @body.stub!(:defunct?).and_return true + @body.not_requestable_reason.should == 'defunct' + end + + it 'should return "not_apply" if FOI does not apply' do + @body.stub!(:not_apply?).and_return true + @body.not_requestable_reason.should == 'not_apply' + end + + + it 'should return "bad_contact" there is no request_email' do + @body.stub!(:has_request_email?).and_return false + @body.not_requestable_reason.should == 'bad_contact' + end + + it 'should raise an error if the body is not defunct, FOI applies and has an email address' do + expected_error = "not_requestable_reason called with type that has no reason" + lambda{ @body.not_requestable_reason }.should raise_error(expected_error) + end + + end + +end + diff --git a/spec/views/public_body/show.html.erb_spec.rb b/spec/views/public_body/show.html.erb_spec.rb index 0559fc8ef..917c0c793 100644 --- a/spec/views/public_body/show.html.erb_spec.rb +++ b/spec/views/public_body/show.html.erb_spec.rb @@ -2,10 +2,10 @@ require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) describe "public_body/show" do before do - @pb = mock_model(PublicBody, - :name => 'Test Quango', + @pb = mock_model(PublicBody, + :name => 'Test Quango', :short_name => 'tq', - :url_name => 'testquango', + :url_name => 'testquango', :notes => '', :type_of_authority => 'A public body', :eir_only? => nil, @@ -15,6 +15,7 @@ describe "public_body/show" do :calculated_home_page => '') @pb.stub!(:override_request_email).and_return(nil) @pb.stub!(:is_requestable?).and_return(true) + @pb.stub!(:special_not_requestable_reason?).and_return(false) @pb.stub!(:has_notes?).and_return(false) @pb.stub!(:has_tag?).and_return(false) @xap = mock(ActsAsXapian::Search, :matches_estimated => 2) @@ -69,7 +70,7 @@ describe "public_body/show" do response.should have_selector("div#header_right") do have_selector "a", :href => /www.charity-commission.gov.uk.*RegisteredCharityNumber=12345$/ end - end + end it "should link to Scottish Charity Regulator site if we have an SC number" do @pb.stub!(:has_tag?).and_return(true) @@ -79,7 +80,7 @@ describe "public_body/show" do response.should have_selector("div#header_right") do have_selector "a", :href => /www.oscr.org.uk.*id=SC1234$/ end - end + end it "should not link to Charity Commission site if we don't have number" do @@ -87,15 +88,15 @@ describe "public_body/show" do response.should have_selector("div#header_right") do have_selector "a", :href => /charity-commission.gov.uk/ end - end + end end -def mock_event - return mock_model(InfoRequestEvent, - :info_request => mock_model(InfoRequest, - :title => 'Title', +def mock_event + return mock_model(InfoRequestEvent, + :info_request => mock_model(InfoRequest, + :title => 'Title', :url_title => 'title', :display_status => 'waiting_response', :calculate_status => 'waiting_response', |