aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin_user_controller_spec.rb69
-rw-r--r--spec/controllers/comment_controller_spec.rb32
-rw-r--r--spec/controllers/help_controller_spec.rb91
-rw-r--r--spec/factories.rb185
-rw-r--r--spec/factories/comments.rb19
-rw-r--r--spec/factories/foi_attchments.rb15
-rw-r--r--spec/factories/incoming_messages.rb46
-rw-r--r--spec/factories/info_request_batches.rb9
-rw-r--r--spec/factories/info_requests.rb47
-rw-r--r--spec/factories/outgoing_messages.rb29
-rw-r--r--spec/factories/public_bodies.rb12
-rw-r--r--spec/factories/public_body_change_requests.rb16
-rw-r--r--spec/factories/raw_emails.rb5
-rw-r--r--spec/factories/track_things.rb30
-rw-r--r--spec/factories/users.rb16
-rw-r--r--spec/helpers/admin_helper_spec.rb21
-rw-r--r--spec/helpers/application_helper_spec.rb34
-rw-r--r--spec/helpers/link_to_helper_spec.rb40
-rw-r--r--spec/lib/alaveteli_external_command_spec.rb (renamed from spec/lib/alaveteli_external_command.rb)0
-rw-r--r--spec/lib/basic_encoding_spec.rb (renamed from spec/lib/basic_encoding_tests.rb)20
-rw-r--r--spec/lib/confidence_intervals_spec.rb (renamed from spec/lib/confidence_intervals.rb)0
-rw-r--r--spec/lib/i18n_interpolation_spec.rb (renamed from spec/lib/i18n_interpolation.rb)1
-rw-r--r--spec/mailers/info_request_batch_mailer_spec.rb (renamed from spec/mailers/info_request_batch_mailer.rb)0
-rw-r--r--spec/models/contact_validator_spec.rb49
24 files changed, 549 insertions, 237 deletions
diff --git a/spec/controllers/admin_user_controller_spec.rb b/spec/controllers/admin_user_controller_spec.rb
index 99894a414..8b89506f9 100644
--- a/spec/controllers/admin_user_controller_spec.rb
+++ b/spec/controllers/admin_user_controller_spec.rb
@@ -44,3 +44,72 @@ describe AdminUserController, "when updating a user" do
end
end
+
+describe AdminUserController do
+
+ describe :modify_comment_visibility do
+
+ before(:each) do
+ @user = FactoryGirl.create(:user)
+ request.env["HTTP_REFERER"] = admin_user_show_path(@user)
+ end
+
+ it 'redirects to the page the admin was previously on' do
+ comment = FactoryGirl.create(:visible_comment, :user => @user)
+
+ post :modify_comment_visibility, { :id => @user.id,
+ :comment_ids => comment.id,
+ :hide_selected => 'hidden' }
+
+ response.should redirect_to(admin_user_show_path(@user))
+ end
+
+ it 'sets the given comments visibility to hidden' do
+ comments = FactoryGirl.create_list(:visible_comment, 3, :user => @user)
+ comment_ids = comments.map(&:id)
+
+ post :modify_comment_visibility, { :id => @user.id,
+ :comment_ids => comment_ids,
+ :hide_selected => 'hidden' }
+
+ Comment.find(comment_ids).each { |comment| comment.should_not be_visible }
+ end
+
+ it 'sets the given comments visibility to visible' do
+ comments = FactoryGirl.create_list(:hidden_comment, 3, :user => @user)
+ comment_ids = comments.map(&:id)
+
+ post :modify_comment_visibility, { :id => @user.id,
+ :comment_ids => comment_ids,
+ :unhide_selected => 'visible' }
+
+ Comment.find(comment_ids).each { |comment| comment.should be_visible }
+ end
+
+ it 'only modifes the given list of comments' do
+ unaffected_comment = FactoryGirl.create(:hidden_comment, :user => @user)
+ affected_comment = FactoryGirl.create(:hidden_comment, :user => @user)
+
+ post :modify_comment_visibility, { :id => @user.id,
+ :comment_ids => affected_comment.id,
+ :unhide_selected => 'visible' }
+
+ Comment.find(unaffected_comment).should_not be_visible
+ Comment.find(affected_comment).should be_visible
+ end
+
+ it 'preserves the visibility if a comment is already of the requested visibility' do
+ hidden_comment = FactoryGirl.create(:hidden_comment, :user => @user)
+ visible_comment = FactoryGirl.create(:visible_comment, :user => @user)
+ comment_ids = [hidden_comment.id, visible_comment.id]
+
+ post :modify_comment_visibility, { :id => @user.id,
+ :comment_ids => comment_ids,
+ :unhide_selected => 'visible' }
+
+ Comment.find(comment_ids).each { |c| c.should be_visible }
+ end
+
+ end
+
+end
diff --git a/spec/controllers/comment_controller_spec.rb b/spec/controllers/comment_controller_spec.rb
index c03615ce2..5e250f689 100644
--- a/spec/controllers/comment_controller_spec.rb
+++ b/spec/controllers/comment_controller_spec.rb
@@ -53,16 +53,30 @@ describe CommentController, "when commenting on a request" do
response.should render_template('new')
end
-
+
it "should not allow comments if comments are not allowed" do
- session[:user_id] = users(:silly_name_user).id
-
- expect {
- post :new, :url_title => info_requests(:spam_1_request).url_title,
- :comment => { :body => "I demand to be heard!" },
- :type => 'request', :submitted_comment => 1, :preview => 0
- }.to raise_error("Comments are not allowed on this request")
-
+ session[:user_id] = users(:silly_name_user).id
+ info_request = info_requests(:spam_1_request)
+
+ post :new, :url_title => info_request.url_title,
+ :comment => { :body => "I demand to be heard!" },
+ :type => 'request', :submitted_comment => 1, :preview => 0
+
+ response.should redirect_to(show_request_path(info_request.url_title))
+ flash[:notice].should == 'Comments are not allowed on this request'
+ end
+
+ it "should not allow comments from banned users" do
+ User.any_instance.stub(:ban_text).and_return('Banned from commenting')
+
+ user = users(:silly_name_user)
+ session[:user_id] = user.id
+
+ post :new, :url_title => info_requests(:fancy_dog_request).url_title,
+ :comment => { :body => comments(:silly_comment).body },
+ :type => 'request', :submitted_comment => 1, :preview => 0
+
+ response.should render_template('user/banned')
end
describe 'when commenting on an external request' do
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/factories.rb b/spec/factories.rb
deleted file mode 100644
index 7e6f0da99..000000000
--- a/spec/factories.rb
+++ /dev/null
@@ -1,185 +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
- 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
-
- 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 :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
- 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
-
- 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
-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/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/lib/alaveteli_external_command.rb b/spec/lib/alaveteli_external_command_spec.rb
index 18afeda33..18afeda33 100644
--- a/spec/lib/alaveteli_external_command.rb
+++ b/spec/lib/alaveteli_external_command_spec.rb
diff --git a/spec/lib/basic_encoding_tests.rb b/spec/lib/basic_encoding_spec.rb
index 35d35fd4a..43a65eab9 100644
--- a/spec/lib/basic_encoding_tests.rb
+++ b/spec/lib/basic_encoding_spec.rb
@@ -4,8 +4,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
def bytes_to_binary_string( bytes, claimed_encoding = nil )
claimed_encoding ||= 'ASCII-8BIT'
bytes_string = bytes.pack('c*')
- if RUBY_VERSION.to_f >= 1.9
- bytes_string.force_encoding! claimed_encoding
+ if String.method_defined?(:force_encoding)
+ bytes_string.force_encoding claimed_encoding
end
bytes_string
end
@@ -110,15 +110,15 @@ describe "convert_string_to_utf8_or_binary" do
converted = convert_string_to_utf8_or_binary random_string
converted.should == random_string
- if RUBY_VERSION.to_f >= 1.9
- converted.encoding.should == 'ASCII-8BIT'
+ if String.method_defined?(:encode)
+ converted.encoding.to_s.should == 'ASCII-8BIT'
end
converted = convert_string_to_utf8_or_binary random_string,'UTF-8'
converted.should == random_string
- if RUBY_VERSION.to_f >= 1.9
- converted.encoding.should == 'ASCII-8BIT'
+ if String.method_defined?(:encode)
+ converted.encoding.to_s.should == 'ASCII-8BIT'
end
end
@@ -132,8 +132,8 @@ describe "convert_string_to_utf8_or_binary" do
converted.should == "DASH – DASH"
- if RUBY_VERSION.to_f >= 1.9
- converted.encoding.should == 'UTF-8'
+ if String.method_defined?(:encode)
+ converted.encoding.to_s.should == 'UTF-8'
end
end
@@ -147,8 +147,8 @@ describe "convert_string_to_utf8_or_binary" do
converted.should start_with("贵公司负责人")
- if RUBY_VERSION.to_f >= 1.9
- converted.encoding.should == 'UTF-8'
+ if String.method_defined?(:encode)
+ converted.encoding.to_s.should == 'UTF-8'
end
end
diff --git a/spec/lib/confidence_intervals.rb b/spec/lib/confidence_intervals_spec.rb
index cb8717f3d..cb8717f3d 100644
--- a/spec/lib/confidence_intervals.rb
+++ b/spec/lib/confidence_intervals_spec.rb
diff --git a/spec/lib/i18n_interpolation.rb b/spec/lib/i18n_interpolation_spec.rb
index b07cf1e9a..47037ecdb 100644
--- a/spec/lib/i18n_interpolation.rb
+++ b/spec/lib/i18n_interpolation_spec.rb
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe "when using i18n" do
diff --git a/spec/mailers/info_request_batch_mailer.rb b/spec/mailers/info_request_batch_mailer_spec.rb
index 19791e163..19791e163 100644
--- a/spec/mailers/info_request_batch_mailer.rb
+++ b/spec/mailers/info_request_batch_mailer_spec.rb
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