diff options
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/admin_helper_spec.rb | 21 | ||||
-rw-r--r-- | spec/helpers/application_helper_spec.rb | 34 | ||||
-rw-r--r-- | spec/helpers/link_to_helper_spec.rb | 40 | ||||
-rw-r--r-- | spec/helpers/track_helper_spec.rb | 204 |
4 files changed, 297 insertions, 2 deletions
diff --git a/spec/helpers/admin_helper_spec.rb b/spec/helpers/admin_helper_spec.rb new file mode 100644 index 000000000..804fcc7fd --- /dev/null +++ b/spec/helpers/admin_helper_spec.rb @@ -0,0 +1,21 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe AdminHelper do + + include AdminHelper + + describe :comment_visibility do + + it 'shows the status of a visible comment' do + comment = Factory.build(:visible_comment) + comment_visibility(comment).should == 'Visible' + end + + it 'shows the status of a hidden comment' do + comment = Factory.build(:hidden_comment) + comment_visibility(comment).should == 'Hidden' + end + + end + +end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb new file mode 100644 index 000000000..6407eaf3a --- /dev/null +++ b/spec/helpers/application_helper_spec.rb @@ -0,0 +1,34 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe ApplicationHelper do + + include ApplicationHelper + include LinkToHelper + + describe 'when creating an event description' do + + it 'should generate a description for a request' do + @info_request = FactoryGirl.create(:info_request) + @sent_event = @info_request.get_last_event + expected = "Request sent to #{public_body_link_absolute(@info_request.public_body)} by #{request_user_link_absolute(@info_request)}" + event_description(@sent_event).should match(expected) + + end + + it 'should generate a description for a response' do + @info_request_with_incoming = FactoryGirl.create(:info_request_with_incoming) + @response_event = @info_request_with_incoming.get_last_event + expected = "Response by #{public_body_link_absolute(@info_request_with_incoming.public_body)} to #{request_user_link_absolute(@info_request_with_incoming)}" + event_description(@response_event).should match(expected) + end + + it 'should generate a description for a request where an internal review has been requested' do + @info_request_with_internal_review_request = FactoryGirl.create(:info_request_with_internal_review_request) + @response_event = @info_request_with_internal_review_request.get_last_event + expected = "Internal review request sent to #{public_body_link_absolute(@info_request_with_internal_review_request.public_body)} by #{request_user_link_absolute(@info_request_with_internal_review_request)}" + event_description(@response_event).should match(expected) + end + + end + +end diff --git a/spec/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb index 2259db6c2..4a01ec683 100644 --- a/spec/helpers/link_to_helper_spec.rb +++ b/spec/helpers/link_to_helper_spec.rb @@ -70,14 +70,50 @@ describe LinkToHelper do end describe 'simple_date' do + + it 'formats a date in html by default' do + time = Time.utc(2012, 11, 07, 21, 30, 26) + self.should_receive(:simple_date_html).with(time) + simple_date(time) + end + + it 'formats a date in the specified format' do + time = Time.utc(2012, 11, 07, 21, 30, 26) + self.should_receive(:simple_date_text).with(time) + simple_date(time, :format => :text) + end + + it 'raises an argument error if given an unrecognized format' do + time = Time.utc(2012, 11, 07, 21, 30, 26) + expect { simple_date(time, :format => :unknown) }.to raise_error(ArgumentError) + end + + end + + describe 'simple_date_html' do + + it 'formats a date in a time tag' do + Time.use_zone('London') do + time = Time.utc(2012, 11, 07, 21, 30, 26) + expected = "<time datetime=\"2012-11-07T21:30:26+00:00\" title=\"2012-11-07 21:30:26 +0000\">November 07, 2012</time>" + simple_date_html(time).should == expected + end + end + + end + + describe 'simple_date_text' do + it 'should respect time zones' do Time.use_zone('Australia/Sydney') do - simple_date(Time.utc(2012, 11, 07, 21, 30, 26)).should == 'November 08, 2012' + simple_date_text(Time.utc(2012, 11, 07, 21, 30, 26)).should == 'November 08, 2012' end end it 'should handle Date objects' do - simple_date(Date.new(2012, 11, 21)).should == 'November 21, 2012' + simple_date_text(Date.new(2012, 11, 21)).should == 'November 21, 2012' end + end + end diff --git a/spec/helpers/track_helper_spec.rb b/spec/helpers/track_helper_spec.rb new file mode 100644 index 000000000..b6252ab39 --- /dev/null +++ b/spec/helpers/track_helper_spec.rb @@ -0,0 +1,204 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe TrackHelper do + + include TrackHelper + include LinkToHelper + + describe 'when displaying notices for a search track' do + + before do + @track_thing = FactoryGirl.build(:search_track) + end + + it 'should create an already subscribed_notice' do + expected = %Q(You are already subscribed to <a href="/search/Example%20Query/newest/advanced">this search</a>.) + already_subscribed_notice(@track_thing).should == expected + end + + it 'should create an email subscription notice' do + expected = %Q(You will now be emailed updates about <a href="/search/Example%20Query/newest/advanced">this search</a>.) + subscribe_email_notice(@track_thing).should == expected + end + + it 'should create a following subscription notice' do + expected = %Q(You are now <a href="#{show_user_wall_path(:url_name => @track_thing.tracking_user.url_name)}">following</a> updates about <a href="/search/Example%20Query/newest/advanced">this search</a>.) + subscribe_follow_notice(@track_thing).should == expected + end + + it 'should create an unsubscribe notice' do + expected = %Q(You are no longer following <a href="/search/Example%20Query/newest/advanced">this search</a>.) + unsubscribe_notice(@track_thing).should == expected + end + + it 'should create a description of the track' do + expected = %Q(<a href="/search/Example%20Query/newest/advanced">anything matching text 'Example Query'</a>) + track_description(@track_thing).should == expected + end + + end + + describe 'when displaying notices for a user track' do + + before do + @track_thing = FactoryGirl.build(:user_track) + end + + it 'should create an already subscribed_notice' do + expected = %Q(You are already subscribed to '#{user_link(@track_thing.tracked_user)}', a person.) + already_subscribed_notice(@track_thing).should == expected + end + + it 'should create an email subscription notice' do + expected = %Q(You will now be emailed updates about '#{user_link(@track_thing.tracked_user)}', a person.) + subscribe_email_notice(@track_thing).should == expected + end + + it 'should create a following subscription notice' do + expected = %Q(You are now <a href="#{show_user_wall_path(:url_name => @track_thing.tracking_user.url_name)}">following</a> updates about '#{user_link(@track_thing.tracked_user)}', a person.) + subscribe_follow_notice(@track_thing).should == expected + end + + it 'should create an unsubscribe notice' do + expected = %Q(You are no longer following '#{user_link(@track_thing.tracked_user)}', a person.) + unsubscribe_notice(@track_thing).should == expected + end + + it 'should create a description of the track' do + expected = %Q('#{user_link(@track_thing.tracked_user)}', a person) + track_description(@track_thing).should == expected + end + + end + + describe 'when displaying notices for a public body track' do + + before do + @track_thing = FactoryGirl.build(:public_body_track) + end + + it 'should create an already subscribed_notice' do + expected = %Q(You are already subscribed to '#{public_body_link(@track_thing.public_body)}', a public authority.) + already_subscribed_notice(@track_thing).should == expected + end + + it 'should create an email subscription notice' do + expected = %Q(You will now be emailed updates about '#{public_body_link(@track_thing.public_body)}', a public authority.) + subscribe_email_notice(@track_thing).should == expected + end + + it 'should create a following subscription notice' do + expected = %Q(You are now <a href="#{show_user_wall_path(:url_name => @track_thing.tracking_user.url_name)}">following</a> updates about '#{public_body_link(@track_thing.public_body)}', a public authority.) + subscribe_follow_notice(@track_thing).should == expected + end + + it 'should create an unsubscribe notice' do + expected = %Q(You are no longer following '#{public_body_link(@track_thing.public_body)}', a public authority.) + unsubscribe_notice(@track_thing).should == expected + end + + it 'should create a description of the track' do + expected = %Q('#{public_body_link(@track_thing.public_body)}', a public authority) + track_description(@track_thing).should == expected + end + end + + describe 'when displaying notices for a successful request track' do + + before do + @track_thing = FactoryGirl.build(:successful_request_track) + end + + it 'should create an already subscribed_notice' do + expected = %Q(You are already subscribed to any <a href="/list/successful">successful requests</a>.) + already_subscribed_notice(@track_thing).should == expected + end + + it 'should create an email subscription notice' do + expected = %Q(You will now be emailed updates about <a href="/list/successful">successful requests</a>.) + subscribe_email_notice(@track_thing).should == expected + end + + it 'should create a following subscription notice' do + expected = %Q(You are now <a href="#{show_user_wall_path(:url_name => @track_thing.tracking_user.url_name)}">following</a> updates about <a href="/list/successful">successful requests</a>.) + subscribe_follow_notice(@track_thing).should == expected + end + + it 'should create an unsubscribe notice' do + expected = %Q(You are no longer following <a href="/list/successful">successful requests</a>.) + unsubscribe_notice(@track_thing).should == expected + end + + it 'should create a description of the track' do + expected = %Q(<a href="/list/successful">successful requests</a>) + track_description(@track_thing).should == expected + end + end + + describe 'when displaying notices for a new request track' do + + before do + @track_thing = FactoryGirl.build(:new_request_track) + end + + it 'should create an already subscribed_notice' do + expected = %Q(You are already subscribed to any <a href="/list">new requests</a>.) + already_subscribed_notice(@track_thing).should == expected + end + + it 'should create an email subscription notice' do + expected = %Q(You will now be emailed updates about any <a href="/list">new requests</a>.) + subscribe_email_notice(@track_thing).should == expected + end + + it 'should create a following subscription notice' do + expected = %Q(You are now <a href="#{show_user_wall_path(:url_name => @track_thing.tracking_user.url_name)}">following</a> updates about <a href="/list">new requests</a>.) + subscribe_follow_notice(@track_thing).should == expected + end + + it 'should create an unsubscribe notice' do + expected = %Q(You are no longer following <a href="/list">new requests</a>.) + unsubscribe_notice(@track_thing).should == expected + end + + it 'should create a description of the track' do + expected = %Q(<a href="/list">new requests</a>) + track_description(@track_thing).should == expected + end + + end + + describe 'when displaying notices for a request update track' do + + before do + @track_thing = FactoryGirl.build(:request_update_track) + end + + it 'should create an already subscribed_notice' do + expected = %Q(You are already subscribed to '#{request_link(@track_thing.info_request)}', a request.) + already_subscribed_notice(@track_thing).should == expected + end + + it 'should create an email subscription notice' do + expected = %Q(You will now be emailed updates about '#{request_link(@track_thing.info_request)}', a request.) + subscribe_email_notice(@track_thing).should == expected + end + + it 'should create a following subscription notice' do + expected = %Q(You are now <a href="#{show_user_wall_path(:url_name => @track_thing.tracking_user.url_name)}">following</a> updates about '#{request_link(@track_thing.info_request)}', a request.) + subscribe_follow_notice(@track_thing).should == expected + end + + it 'should create an unsubscribe notice' do + expected = %Q(You are no longer following '#{request_link(@track_thing.info_request)}', a request.) + unsubscribe_notice(@track_thing).should == expected + end + + it 'should create a description of the track' do + expected = %Q('#{request_link(@track_thing.info_request)}', a request) + track_description(@track_thing).should == expected + end + + end + +end |