diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/help_controller_spec.rb | 91 | ||||
-rw-r--r-- | spec/controllers/track_controller_spec.rb | 6 | ||||
-rw-r--r-- | spec/factories.rb | 196 | ||||
-rw-r--r-- | spec/factories/comments.rb | 19 | ||||
-rw-r--r-- | spec/factories/foi_attchments.rb | 15 | ||||
-rw-r--r-- | spec/factories/incoming_messages.rb | 46 | ||||
-rw-r--r-- | spec/factories/info_request_batches.rb | 9 | ||||
-rw-r--r-- | spec/factories/info_requests.rb | 47 | ||||
-rw-r--r-- | spec/factories/outgoing_messages.rb | 29 | ||||
-rw-r--r-- | spec/factories/public_bodies.rb | 12 | ||||
-rw-r--r-- | spec/factories/public_body_change_requests.rb | 16 | ||||
-rw-r--r-- | spec/factories/raw_emails.rb | 5 | ||||
-rw-r--r-- | spec/factories/track_things.rb | 30 | ||||
-rw-r--r-- | spec/factories/users.rb | 16 | ||||
-rw-r--r-- | spec/helpers/track_helper_spec.rb | 204 | ||||
-rw-r--r-- | spec/integration/errors_spec.rb | 7 | ||||
-rw-r--r-- | spec/models/contact_validator_spec.rb | 49 | ||||
-rw-r--r-- | spec/models/track_thing_spec.rb | 9 |
18 files changed, 572 insertions, 234 deletions
diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb index cc024f840..f92323f50 100644 --- a/spec/controllers/help_controller_spec.rb +++ b/spec/controllers/help_controller_spec.rb @@ -1,48 +1,81 @@ # -*- coding: utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') -describe HelpController, "when using help" do +describe HelpController do render_views - it "shows the about page" do - get :about - end + describe :about do - it "shows contact form" do - get :contact - end + it 'shows the about page' do + get :about + response.should be_success + response.should render_template('help/about') + end - it "sends a contact message" do - post :contact, { :contact => { - :name => "Vinny Vanilli", - :email => "vinny@localhost", - :subject => "Why do I have such an ace name?", - :message => "You really should know!!!\n\nVinny", - }, :submitted_contact_form => 1 - } - response.should redirect_to(:controller => 'general', :action => 'frontpage') - - deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 1 - deliveries[0].body.should include("really should know") - deliveries.clear end - describe 'when requesting a page in a supported locale ' do + describe 'GET contact' do - before do - # Prepend our fixture templates - fixture_theme_path = File.join(Rails.root, 'spec', 'fixtures', 'theme_views', 'theme_one') - controller.prepend_view_path fixture_theme_path + it 'shows contact form' do + get :contact + response.should be_success + response.should render_template('help/contact') end - it 'should render the locale-specific template if available' do - get :contact, {:locale => 'es'} - response.body.should match('contáctenos theme one') + describe 'when requesting a page in a supported locale' do + + before do + # Prepend our fixture templates + fixture_theme_path = File.join(Rails.root, 'spec', 'fixtures', 'theme_views', 'theme_one') + controller.prepend_view_path fixture_theme_path + end + + it 'should render the locale-specific template if available' do + get :contact, {:locale => 'es'} + response.body.should match('contáctenos theme one') + end + end end + describe 'POST contact' do + + it 'sends a contact message' do + post :contact, { :contact => { + :name => 'Vinny Vanilli', + :email => 'vinny@localhost', + :subject => 'Why do I have such an ace name?', + :comment => '', + :message => "You really should know!!!\n\nVinny", + }, :submitted_contact_form => 1 + } + response.should redirect_to(frontpage_path) + + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + deliveries[0].body.should include('really should know') + deliveries.clear + end + + it 'has rudimentary spam protection' do + post :contact, { :contact => { + :name => 'Vinny Vanilli', + :email => 'vinny@localhost', + :subject => 'Why do I have such an ace name?', + :comment => 'I AM A SPAMBOT', + :message => "You really should know!!!\n\nVinny", + }, :submitted_contact_form => 1 + } + + response.should redirect_to(frontpage_path) + + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 0 + deliveries.clear + end + + end end diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index 40865d2b9..d2b45b6bf 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -5,7 +5,7 @@ describe TrackController, "when making a new track on a request" do @ir = mock_model(InfoRequest, :url_title => 'myrequest', :title => 'My request') @track_thing = mock_model(TrackThing, :save! => true, - :params => {:list_description => 'list description'}, + :params => {}, :track_medium= => nil, :tracking_user_id= => nil) TrackThing.stub!(:create_track_for_request).and_return(@track_thing) @@ -58,7 +58,7 @@ end describe TrackController, "when unsubscribing from a track" do before do - @track_thing = FactoryGirl.create(:track_thing) + @track_thing = FactoryGirl.create(:search_track) end it 'should destroy the track thing' do @@ -78,7 +78,7 @@ describe TrackController, "when unsubscribing from a track" do end it 'should not redirect to a url on another site' do - track_thing = FactoryGirl.create(:track_thing) + track_thing = FactoryGirl.create(:search_track) get :update, {:track_id => @track_thing.id, :track_medium => 'delete', :r => 'http://example.com/'}, diff --git a/spec/factories.rb b/spec/factories.rb deleted file mode 100644 index e3990977e..000000000 --- a/spec/factories.rb +++ /dev/null @@ -1,196 +0,0 @@ -FactoryGirl.define do - - sequence(:email) { |n| "person#{n}@example.com" } - sequence(:name) { |n| "Example Public Body #{n}" } - sequence(:short_name) { |n| "Example Body #{n}" } - - factory :foi_attachment do - factory :body_text do - content_type 'text/plain' - body { 'hereisthetext' } - end - factory :pdf_attachment do - content_type 'application/pdf' - filename 'interesting.pdf' - body { load_file_fixture('interesting.pdf') } - end - end - - factory :incoming_message do - info_request - raw_email - last_parsed { 1.week.ago } - sent_at { 1.week.ago } - - after_create do |incoming_message, evaluator| - FactoryGirl.create(:body_text, - :incoming_message => incoming_message, - :url_part_number => 1) - end - - factory :plain_incoming_message do - last_parsed { nil } - sent_at { nil } - after_create do |incoming_message, evaluator| - data = load_file_fixture('incoming-request-plain.email') - data.gsub!('EMAIL_FROM', 'Bob Responder <bob@example.com>') - incoming_message.raw_email.data = data - incoming_message.raw_email.save! - end - end - - factory :incoming_message_with_attachments do - # foi_attachments_count is declared as an ignored attribute and available in - # attributes on the factory, as well as the callback via the evaluator - ignore do - foi_attachments_count 2 - end - - # the after(:create) yields two values; the incoming_message instance itself and the - # evaluator, which stores all values from the factory, including ignored - # attributes; - after_create do |incoming_message, evaluator| - evaluator.foi_attachments_count.times do |count| - FactoryGirl.create(:pdf_attachment, - :incoming_message => incoming_message, - :url_part_number => count+2) - end - end - end - end - - factory :raw_email - - factory :outgoing_message do - factory :initial_request do - ignore do - status 'ready' - message_type 'initial_request' - body 'Some information please' - what_doing 'normal_sort' - end - end - factory :internal_review_request do - ignore do - status 'ready' - message_type 'followup' - body 'I want a review' - what_doing 'internal_review' - end - end - initialize_with { OutgoingMessage.new({ :status => status, - :message_type => message_type, - :body => body, - :what_doing => what_doing }) } - after_create do |outgoing_message| - outgoing_message.send_message - end - end - - factory :info_request do - title "Example Title" - public_body - user - - after_create do |info_request, evaluator| - FactoryGirl.create(:initial_request, :info_request => info_request) - end - - factory :info_request_with_incoming do - after_create do |info_request, evaluator| - incoming_message = FactoryGirl.create(:incoming_message, :info_request => info_request) - info_request.log_event("response", {:incoming_message_id => incoming_message.id}) - end - end - - factory :info_request_with_plain_incoming do - after_create do |info_request, evaluator| - incoming_message = FactoryGirl.create(:plain_incoming_message, :info_request => info_request) - info_request.log_event("response", {:incoming_message_id => incoming_message.id}) - end - end - - factory :info_request_with_incoming_attachments do - after_create do |info_request, evaluator| - incoming_message = FactoryGirl.create(:incoming_message_with_attachments, :info_request => info_request) - info_request.log_event("response", {:incoming_message_id => incoming_message.id}) - end - end - - factory :info_request_with_internal_review_request do - after_create do |info_request, evaluator| - outgoing_message = FactoryGirl.create(:internal_review_request, :info_request => info_request) - end - end - - factory :external_request do - user nil - external_user_name 'External User' - external_url 'http://www.example.org/request/external' - end - - end - - factory :user do - name 'Example User' - email - salt "-6116981980.392287733335677" - hashed_password '6b7cd45a5f35fd83febc0452a799530398bfb6e8' # jonespassword - email_confirmed true - ban_text "" - factory :admin_user do - name 'Admin User' - admin_level 'super' - end - end - - factory :public_body do - name - short_name - request_email 'request@example.com' - last_edit_editor "admin user" - last_edit_comment "Making an edit" - end - - factory :track_thing do - association :tracking_user, :factory => :user - track_medium 'email_daily' - track_type 'search_query' - track_query 'Example Query' - end - - factory :public_body_change_request do - user - source_url 'http://www.example.com' - notes 'Please' - public_body_email 'new@example.com' - factory :add_body_request do - public_body_name 'A New Body' - end - factory :update_body_request do - public_body - end - end - factory :info_request_batch do - title "Example title" - user - body "Some text" - end - - factory :comment do - user - info_request - - body 'This a wise and helpful annotation.' - comment_type 'request' - - factory :visible_comment do - visible true - end - - factory :hidden_comment do - visible false - end - end - -end diff --git a/spec/factories/comments.rb b/spec/factories/comments.rb new file mode 100644 index 000000000..1e0861dad --- /dev/null +++ b/spec/factories/comments.rb @@ -0,0 +1,19 @@ +FactoryGirl.define do + + factory :comment do + user + info_request + + body 'This a wise and helpful annotation.' + comment_type 'request' + + factory :visible_comment do + visible true + end + + factory :hidden_comment do + visible false + end + end + +end diff --git a/spec/factories/foi_attchments.rb b/spec/factories/foi_attchments.rb new file mode 100644 index 000000000..d7a90efb8 --- /dev/null +++ b/spec/factories/foi_attchments.rb @@ -0,0 +1,15 @@ +FactoryGirl.define do + + factory :foi_attachment do + factory :body_text do + content_type 'text/plain' + body { 'hereisthetext' } + end + factory :pdf_attachment do + content_type 'application/pdf' + filename 'interesting.pdf' + body { load_file_fixture('interesting.pdf') } + end + end + +end diff --git a/spec/factories/incoming_messages.rb b/spec/factories/incoming_messages.rb new file mode 100644 index 000000000..38ad98394 --- /dev/null +++ b/spec/factories/incoming_messages.rb @@ -0,0 +1,46 @@ +FactoryGirl.define do + + factory :incoming_message do + info_request + raw_email + last_parsed { 1.week.ago } + sent_at { 1.week.ago } + + after_create do |incoming_message, evaluator| + FactoryGirl.create(:body_text, + :incoming_message => incoming_message, + :url_part_number => 1) + end + + factory :plain_incoming_message do + last_parsed { nil } + sent_at { nil } + after_create do |incoming_message, evaluator| + data = load_file_fixture('incoming-request-plain.email') + data.gsub!('EMAIL_FROM', 'Bob Responder <bob@example.com>') + incoming_message.raw_email.data = data + incoming_message.raw_email.save! + end + end + + factory :incoming_message_with_attachments do + # foi_attachments_count is declared as an ignored attribute and available in + # attributes on the factory, as well as the callback via the evaluator + ignore do + foi_attachments_count 2 + end + + # the after(:create) yields two values; the incoming_message instance itself and the + # evaluator, which stores all values from the factory, including ignored + # attributes; + after_create do |incoming_message, evaluator| + evaluator.foi_attachments_count.times do |count| + FactoryGirl.create(:pdf_attachment, + :incoming_message => incoming_message, + :url_part_number => count+2) + end + end + end + end + +end diff --git a/spec/factories/info_request_batches.rb b/spec/factories/info_request_batches.rb new file mode 100644 index 000000000..960db6ec5 --- /dev/null +++ b/spec/factories/info_request_batches.rb @@ -0,0 +1,9 @@ +FactoryGirl.define do + + factory :info_request_batch do + title "Example title" + user + body "Some text" + end + +end diff --git a/spec/factories/info_requests.rb b/spec/factories/info_requests.rb new file mode 100644 index 000000000..8052625cd --- /dev/null +++ b/spec/factories/info_requests.rb @@ -0,0 +1,47 @@ +FactoryGirl.define do + + factory :info_request do + title "Example Title" + public_body + user + + after_create do |info_request, evaluator| + FactoryGirl.create(:initial_request, :info_request => info_request) + end + + factory :info_request_with_incoming do + after_create do |info_request, evaluator| + incoming_message = FactoryGirl.create(:incoming_message, :info_request => info_request) + info_request.log_event("response", {:incoming_message_id => incoming_message.id}) + end + end + + factory :info_request_with_plain_incoming do + after_create do |info_request, evaluator| + incoming_message = FactoryGirl.create(:plain_incoming_message, :info_request => info_request) + info_request.log_event("response", {:incoming_message_id => incoming_message.id}) + end + end + + factory :info_request_with_incoming_attachments do + after_create do |info_request, evaluator| + incoming_message = FactoryGirl.create(:incoming_message_with_attachments, :info_request => info_request) + info_request.log_event("response", {:incoming_message_id => incoming_message.id}) + end + end + + factory :info_request_with_internal_review_request do + after_create do |info_request, evaluator| + outgoing_message = FactoryGirl.create(:internal_review_request, :info_request => info_request) + end + end + + factory :external_request do + user nil + external_user_name 'External User' + external_url 'http://www.example.org/request/external' + end + + end + +end diff --git a/spec/factories/outgoing_messages.rb b/spec/factories/outgoing_messages.rb new file mode 100644 index 000000000..d1ed25093 --- /dev/null +++ b/spec/factories/outgoing_messages.rb @@ -0,0 +1,29 @@ +FactoryGirl.define do + + factory :outgoing_message do + factory :initial_request do + ignore do + status 'ready' + message_type 'initial_request' + body 'Some information please' + what_doing 'normal_sort' + end + end + factory :internal_review_request do + ignore do + status 'ready' + message_type 'followup' + body 'I want a review' + what_doing 'internal_review' + end + end + initialize_with { OutgoingMessage.new({ :status => status, + :message_type => message_type, + :body => body, + :what_doing => what_doing }) } + after_create do |outgoing_message| + outgoing_message.send_message + end + end + +end diff --git a/spec/factories/public_bodies.rb b/spec/factories/public_bodies.rb new file mode 100644 index 000000000..44769f7c2 --- /dev/null +++ b/spec/factories/public_bodies.rb @@ -0,0 +1,12 @@ +FactoryGirl.define do + + factory :public_body do + sequence(:name) { |n| "Example Public Body #{n}" } + sequence(:short_name) { |n| "Example Body #{n}" } + request_email 'request@example.com' + last_edit_editor "admin user" + last_edit_comment "Making an edit" + end + + +end diff --git a/spec/factories/public_body_change_requests.rb b/spec/factories/public_body_change_requests.rb new file mode 100644 index 000000000..2bacb9b9b --- /dev/null +++ b/spec/factories/public_body_change_requests.rb @@ -0,0 +1,16 @@ +FactoryGirl.define do + + factory :public_body_change_request do + user + source_url 'http://www.example.com' + notes 'Please' + public_body_email 'new@example.com' + factory :add_body_request do + public_body_name 'A New Body' + end + factory :update_body_request do + public_body + end + end + +end diff --git a/spec/factories/raw_emails.rb b/spec/factories/raw_emails.rb new file mode 100644 index 000000000..30fb24c37 --- /dev/null +++ b/spec/factories/raw_emails.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + + factory :raw_email + +end diff --git a/spec/factories/track_things.rb b/spec/factories/track_things.rb new file mode 100644 index 000000000..cf76b00b3 --- /dev/null +++ b/spec/factories/track_things.rb @@ -0,0 +1,30 @@ +FactoryGirl.define do + + factory :track_thing do + association :tracking_user, :factory => :user + factory :search_track do + track_medium 'email_daily' + track_type 'search_query' + track_query 'Example Query' + end + factory :user_track do + association :tracked_user, :factory => :user + track_type 'user_updates' + end + factory :public_body_track do + association :public_body, :factory => :public_body + track_type 'public_body_updates' + end + factory :request_update_track do + association :info_request, :factory => :info_request + track_type 'request_updates' + end + factory :successful_request_track do + track_type 'all_successful_requests' + end + factory :new_request_track do + track_type 'all_new_requests' + end + end + +end diff --git a/spec/factories/users.rb b/spec/factories/users.rb new file mode 100644 index 000000000..ab782fbf7 --- /dev/null +++ b/spec/factories/users.rb @@ -0,0 +1,16 @@ +FactoryGirl.define do + + factory :user do + name 'Example User' + sequence(:email) { |n| "person#{n}@example.com" } + salt "-6116981980.392287733335677" + hashed_password '6b7cd45a5f35fd83febc0452a799530398bfb6e8' # jonespassword + email_confirmed true + ban_text "" + factory :admin_user do + name 'Admin User' + admin_level 'super' + 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..80857067b --- /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 diff --git a/spec/integration/errors_spec.rb b/spec/integration/errors_spec.rb index 17a0153c2..3ff3edb53 100644 --- a/spec/integration/errors_spec.rb +++ b/spec/integration/errors_spec.rb @@ -54,6 +54,13 @@ describe "When errors occur" do end end + it 'should url encode params' do + get ('/%d3') + response.should render_template('general/exception_caught') + response.code.should == '404' + response.body.should match("Sorry, we couldn't find that page") + end + it "should render a 500 for general errors using the general/exception_caught template" do InfoRequest.stub!(:find_by_url_title!).and_raise("An example error") get("/request/example") diff --git a/spec/models/contact_validator_spec.rb b/spec/models/contact_validator_spec.rb index 9ea0fac49..0f5403967 100644 --- a/spec/models/contact_validator_spec.rb +++ b/spec/models/contact_validator_spec.rb @@ -1,8 +1,53 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') -describe ContactValidator, " when blah" do - before do +describe ContactValidator do + + describe :new do + + let(:valid_params) do + { :name => "Vinny Vanilli", + :email => "vinny@localhost", + :subject => "Why do I have such an ace name?", + :message => "You really should know!!!\n\nVinny" } + end + + it 'validates specified attributes' do + ContactValidator.new(valid_params).should be_valid + end + + it 'validates name is present' do + valid_params.except!(:name) + validator = ContactValidator.new(valid_params) + expect(validator).to have(1).error_on(:name) + end + + it 'validates email is present' do + valid_params.except!(:email) + validator = ContactValidator.new(valid_params) + # We have 2 errors on email because of the format validator + expect(validator).to have(2).errors_on(:email) + end + + it 'validates email format' do + valid_params.merge!({:email => 'not-an-email'}) + validator = ContactValidator.new(valid_params) + expect(validator.errors_on(:email)).to include("Email doesn't look like a valid address") + end + + it 'validates subject is present' do + valid_params.except!(:subject) + validator = ContactValidator.new(valid_params) + expect(validator).to have(1).error_on(:subject) + end + + it 'validates message is present' do + valid_params.except!(:message) + validator = ContactValidator.new(valid_params) + expect(validator).to have(1).error_on(:message) + end + end + end diff --git a/spec/models/track_thing_spec.rb b/spec/models/track_thing_spec.rb index 1c582564b..3edf2d1ad 100644 --- a/spec/models/track_thing_spec.rb +++ b/spec/models/track_thing_spec.rb @@ -51,10 +51,11 @@ describe TrackThing, "when tracking changes" do end it "will make some sane descriptions of search-based tracks" do - tests = { 'bob variety:user' => "users matching text 'bob'", - 'bob (variety:sent OR variety:followup_sent OR variety:response OR variety:comment) (latest_status:successful OR latest_status:partially_successful OR latest_status:rejected OR latest_status:not_held)' => "comments or requests which are successful or unsuccessful matching text 'bob'", - '(latest_status:waiting_response OR latest_status:waiting_clarification OR waiting_classification:true)' => 'requests which are awaiting a response', - ' (variety:sent OR variety:followup_sent OR variety:response OR variety:comment)' => 'all requests or comments' } + tests = { ' (variety:sent OR variety:followup_sent OR variety:response OR variety:comment)' => 'all requests or comments', + 'bob (variety:sent OR variety:followup_sent OR variety:response OR variety:comment)' => "all requests or comments matching text 'bob'", + 'bob (latest_status:successful OR latest_status:partially_successful)' => "requests which are successful matching text 'bob'", + '(latest_status:successful OR latest_status:partially_successful)' => 'requests which are successful', + 'bob' => "anything matching text 'bob'" } tests.each do |query, description| track_thing = TrackThing.create_track_for_search_query(query) track_thing.track_query_description.should == description |