aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/comment_controller_spec.rb11
-rw-r--r--spec/controllers/request_controller_spec.rb16
-rw-r--r--spec/fixtures/info_requests.yml11
-rw-r--r--spec/models/application_mailer_spec.rb157
-rw-r--r--spec/models/customstates.rb4
-rw-r--r--spec/models/holiday_spec.rb99
-rw-r--r--spec/models/request_mailer_spec.rb5
-rw-r--r--spec/views/request/_after_actions.rhtml_spec.rb71
8 files changed, 302 insertions, 72 deletions
diff --git a/spec/controllers/comment_controller_spec.rb b/spec/controllers/comment_controller_spec.rb
index b71bc0aea..4a7acee23 100644
--- a/spec/controllers/comment_controller_spec.rb
+++ b/spec/controllers/comment_controller_spec.rb
@@ -53,6 +53,17 @@ 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")
+
+ end
describe 'when commenting on an external request' do
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 95737a250..77f43b618 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -238,6 +238,22 @@ describe RequestController, "when showing one request" do
response.should have_tag('div#owner_actions')
end
+ describe 'when the request does allow comments' do
+ it 'should have a comment link' do
+ get :show, { :url_title => 'why_do_you_have_such_a_fancy_dog' },
+ { :user_id => users(:admin_user).id }
+ response.should have_tag('#anyone_actions', /Add an annotation/)
+ end
+ end
+
+ describe 'when the request does not allow comments' do
+ it 'should not have a comment link' do
+ get :show, { :url_title => 'spam_1' },
+ { :user_id => users(:admin_user).id }
+ response.should_not have_tag('#anyone_actions', /Add an annotation/)
+ end
+ end
+
describe 'when the request is being viewed by an admin' do
describe 'if the request is awaiting description' do
diff --git a/spec/fixtures/info_requests.yml b/spec/fixtures/info_requests.yml
index 079a44cd0..9361ec486 100644
--- a/spec/fixtures/info_requests.yml
+++ b/spec/fixtures/info_requests.yml
@@ -8,6 +8,7 @@ fancy_dog_request:
user_id: 1
described_state: waiting_response
awaiting_description: true
+ comments_allowed: true
idhash: 50929748
naughty_chicken_request:
id: 103
@@ -19,6 +20,7 @@ naughty_chicken_request:
user_id: 1
described_state: waiting_response
awaiting_description: false
+ comments_allowed: true
idhash: e8d18c84
badger_request:
id: 104
@@ -30,6 +32,7 @@ badger_request:
user_id: 1
described_state: waiting_response
awaiting_description: false
+ comments_allowed: true
idhash: e8d18c84
boring_request:
id: 105
@@ -41,6 +44,7 @@ boring_request:
user_id: 1
described_state: successful
awaiting_description: false
+ comments_allowed: true
idhash: 173fd003
another_boring_request:
id: 106
@@ -52,6 +56,7 @@ another_boring_request:
user_id: 1
described_state: successful
awaiting_description: false
+ comments_allowed: true
idhash: 173fd004
# A pair of identical requests (with url_title differing only in the numeric suffix)
@@ -66,6 +71,7 @@ spam_1_request:
user_id: 5
described_state: successful
awaiting_description: false
+ comments_allowed: false
idhash: 173fd005
spam_2_request:
id: 108
@@ -77,6 +83,7 @@ spam_2_request:
user_id: 5
described_state: successful
awaiting_description: false
+ comments_allowed: true
idhash: 173fd005
external_request:
id: 109
@@ -87,6 +94,7 @@ external_request:
public_body_id: 2
described_state: waiting_response
awaiting_description: false
+ comments_allowed: true
idhash: a1234567
anonymous_external_request:
id: 110
@@ -97,4 +105,5 @@ anonymous_external_request:
public_body_id: 2
described_state: waiting_response
awaiting_description: false
- idhash: 7654321a \ No newline at end of file
+ comments_allowed: true
+ idhash: 7654321a
diff --git a/spec/models/application_mailer_spec.rb b/spec/models/application_mailer_spec.rb
index 12527c6e8..11fdd2889 100644
--- a/spec/models/application_mailer_spec.rb
+++ b/spec/models/application_mailer_spec.rb
@@ -1,8 +1,161 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-describe ApplicationMailer, " when blah" do
- before do
+
+describe ApplicationMailer do
+
+ context 'when using plugins' do
+
+ def set_base_views
+ ApplicationMailer.class_eval do
+ @previous_view_paths = self.view_paths.dup
+ self.view_paths.clear
+ self.view_paths << File.join(Rails.root, 'spec', 'fixtures', 'theme_views', 'core')
+ end
+ end
+
+ def add_mail_methods(method_names)
+ method_names.each{ |method_name| ApplicationMailer.send(:define_method, method_name){} }
+ end
+
+ def remove_mail_methods(method_names)
+ method_names.each do |method_name|
+ if ApplicationMailer.respond_to?(method_name)
+ ApplicationMailer.send(:remove_method, method_name)
+ end
+ end
+ end
+
+ def prepend_theme_views(theme_name)
+ ApplicationMailer.class_eval do
+ view_paths.unshift File.join(Rails.root, 'spec', 'fixtures', 'theme_views', theme_name)
+ end
+ end
+
+ def append_theme_views(theme_name)
+ ApplicationMailer.class_eval do
+ view_paths << File.join(Rails.root, 'spec', 'fixtures', 'theme_views', theme_name)
+ end
+ end
+
+ def reset_views
+ ApplicationMailer.class_eval do
+ self.view_paths = @previous_view_paths
+ end
+ end
+
+ def create_multipart_method(method_name)
+ ApplicationMailer.send(:define_method, method_name) do
+ puts "in multipart"
+ attachment :content_type => 'message/rfc822',
+ :body => 'xxx',
+ :filename => "original.eml",
+ :transfer_encoding => '7bit',
+ :content_disposition => 'inline'
+ end
+ end
+
+ before do
+ set_base_views
+ add_mail_methods(['simple', 'theme_only', 'core_only', 'neither'])
+ end
+
+ describe 'when a plugin prepends its mail templates to the view paths' do
+
+ it 'should render a theme template in preference to a core template' do
+ prepend_theme_views('theme_one')
+ @mail = ApplicationMailer.create_simple()
+ @mail.body.should match('Theme simple')
+ end
+
+ it 'should render the template provided by the theme if no template is available in core' do
+ prepend_theme_views('theme_one')
+ @mail = ApplicationMailer.create_theme_only()
+ @mail.body.should match('Theme only')
+ end
+
+ it 'should render the template provided by core if there is no theme template' do
+ prepend_theme_views('theme_one')
+ @mail = ApplicationMailer.create_core_only()
+ @mail.body.should match('Core only')
+ end
+
+ it 'should raise an error if the template is in neither core nor theme' do
+ prepend_theme_views('theme_one')
+ lambda{ ApplicationMailer.create_neither() }.should raise_error('Missing template application_mailer/neither.erb in view path spec/fixtures/theme_views/theme_one:spec/fixtures/theme_views/core')
+ end
+
+ it 'should render a multipart email using a theme template' do
+ prepend_theme_views('theme_one')
+ create_multipart_method('multipart_theme_only')
+ @mail = ApplicationMailer.create_multipart_theme_only()
+ @mail.parts.size.should == 2
+ message_part = @mail.parts[0].to_s
+ message_part.should match("Theme multipart")
+ end
+
+ it 'should render a multipart email using a core template' do
+ prepend_theme_views('theme_one')
+ create_multipart_method('multipart_core_only')
+ @mail = ApplicationMailer.create_multipart_core_only()
+ @mail.parts.size.should == 2
+ message_part = @mail.parts[0].to_s
+ message_part.should match("Core multipart")
+ end
+
+ end
+
+ describe 'when a plugin appends its mail templates to the view paths' do
+
+ it 'should render a core template in preference to a theme template' do
+ append_theme_views('theme_one')
+ @mail = ApplicationMailer.create_simple()
+ @mail.body.should match('Core simple')
+ end
+
+ it 'should render the template provided by the theme if no template is available in core' do
+ append_theme_views('theme_one')
+ @mail = ApplicationMailer.create_theme_only()
+ @mail.body.should match('Theme only')
+ end
+
+ it 'should render the template provided by core if there is no theme template' do
+ append_theme_views('theme_one')
+ @mail = ApplicationMailer.create_core_only()
+ @mail.body.should match('Core only')
+ end
+
+ it 'should raise an error if the template is in neither core nor theme' do
+ append_theme_views('theme_one')
+ lambda{ ApplicationMailer.create_neither() }.should raise_error('Missing template application_mailer/neither.erb in view path spec/fixtures/theme_views/core:spec/fixtures/theme_views/theme_one')
+ end
+
+ it 'should render a multipart email using a core template' do
+ append_theme_views('theme_one')
+ create_multipart_method('multipart_core_only')
+ @mail = ApplicationMailer.create_multipart_core_only()
+ @mail.parts.size.should == 2
+ message_part = @mail.parts[0].to_s
+ message_part.should match("Core multipart")
+ end
+
+ it 'should render a multipart email using a theme template' do
+ append_theme_views('theme_one')
+ create_multipart_method('multipart_theme_only')
+ @mail = ApplicationMailer.create_multipart_theme_only()
+ @mail.parts.size.should == 2
+ message_part = @mail.parts[0].to_s
+ message_part.should match("Theme multipart")
+ end
+
+ end
+
+ after do
+ reset_views
+ remove_mail_methods(['simple', 'theme_only', 'core_only', 'neither', 'multipart'])
+ end
end
+
end
+
diff --git a/spec/models/customstates.rb b/spec/models/customstates.rb
index 3488e6730..bffbe86fb 100644
--- a/spec/models/customstates.rb
+++ b/spec/models/customstates.rb
@@ -13,7 +13,7 @@ module InfoRequestCustomStates
return 'deadline_extended' if
Time.now.strftime("%Y-%m-%d") < self.date_deadline_extended.strftime("%Y-%m-%d")
return 'waiting_response_very_overdue' if
- Time.now.strftime("%Y-%m-%d") > Holiday.due_date_from(self.date_deadline_extended, 15).strftime("%Y-%m-%d")
+ Time.now.strftime("%Y-%m-%d") > Holiday.due_date_from_working_days(self.date_deadline_extended, 15).strftime("%Y-%m-%d")
return 'waiting_response_overdue'
end
return 'waiting_response_very_overdue' if
@@ -27,7 +27,7 @@ module InfoRequestCustomStates
# XXX shouldn't this be 15 days after the date the status was
# changed to "deadline extended"? Or perhaps 15 days ater the
# initial request due date?
- return Holiday.due_date_from(self.date_response_required_by, 15)
+ return Holiday.due_date_from_working_days(self.date_response_required_by, 15)
end
module ClassMethods
diff --git a/spec/models/holiday_spec.rb b/spec/models/holiday_spec.rb
index 00ebc7279..5d3f76d24 100644
--- a/spec/models/holiday_spec.rb
+++ b/spec/models/holiday_spec.rb
@@ -3,47 +3,84 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Holiday, " when calculating due date" do
def due_date(ymd)
- return Holiday.due_date_from(Date.strptime(ymd), 20).strftime("%F")
+ return Holiday.due_date_from_working_days(Date.strptime(ymd), 20).strftime("%F")
end
- it "handles no holidays" do
- due_date('2008-10-01').should == '2008-10-29'
- end
+ context "in working days" do
+ it "handles no holidays" do
+ due_date('2008-10-01').should == '2008-10-29'
+ end
- it "handles non leap years" do
- due_date('2007-02-01').should == '2007-03-01'
- end
+ it "handles non leap years" do
+ due_date('2007-02-01').should == '2007-03-01'
+ end
- it "handles leap years" do
- due_date('2008-02-01').should == '2008-02-29'
- end
+ it "handles leap years" do
+ due_date('2008-02-01').should == '2008-02-29'
+ end
- it "handles Thursday start" do
- due_date('2009-03-12').should == '2009-04-14'
- end
+ it "handles Thursday start" do
+ due_date('2009-03-12').should == '2009-04-14'
+ end
- it "handles Friday start" do
- due_date('2009-03-13').should == '2009-04-15'
- end
+ it "handles Friday start" do
+ due_date('2009-03-13').should == '2009-04-15'
+ end
- # Delivery at the weekend ends up the same due day as if it had arrived on
- # the Friday before. This is because the next working day (Monday) counts
- # as day 1.
- # See http://www.whatdotheyknow.com/help/officers#days
- it "handles Saturday start" do
- due_date('2009-03-14').should == '2009-04-15'
- end
- it "handles Sunday start" do
- due_date('2009-03-15').should == '2009-04-15'
- end
+ # Delivery at the weekend ends up the same due day as if it had arrived on
+ # the Friday before. This is because the next working day (Monday) counts
+ # as day 1.
+ # See http://www.whatdotheyknow.com/help/officers#days
+ it "handles Saturday start" do
+ due_date('2009-03-14').should == '2009-04-15'
+ end
+ it "handles Sunday start" do
+ due_date('2009-03-15').should == '2009-04-15'
+ end
- it "handles Monday start" do
- due_date('2009-03-16').should == '2009-04-16'
- end
+ it "handles Monday start" do
+ due_date('2009-03-16').should == '2009-04-16'
+ end
- it "handles Time objects" do
- Holiday.due_date_from(Time.utc(2009, 03, 16, 12, 0, 0), 20).strftime('%F').should == '2009-04-16'
+ it "handles Time objects" do
+ Holiday.due_date_from_working_days(Time.utc(2009, 03, 16, 12, 0, 0), 20).strftime('%F').should == '2009-04-16'
+ end
end
+ context "in calendar days" do
+ it "handles no holidays" do
+ Holiday.due_date_from_calendar_days(Date.new(2008, 10, 1), 20).should == Date.new(2008, 10, 21)
+ end
+
+ it "handles the due date falling on a Friday" do
+ Holiday.due_date_from_calendar_days(Date.new(2008, 10, 4), 20).should == Date.new(2008, 10, 24)
+ end
+
+ # If the due date would fall on a Saturday it should in fact fall on the next day that isn't a weekend
+ # or a holiday
+ it "handles the due date falling on a Saturday" do
+ Holiday.due_date_from_calendar_days(Date.new(2008, 10, 5), 20).should == Date.new(2008, 10, 27)
+ end
+
+ it "handles the due date falling on a Sunday" do
+ Holiday.due_date_from_calendar_days(Date.new(2008, 10, 6), 20).should == Date.new(2008, 10, 27)
+ end
+
+ it "handles the due date falling on a Monday" do
+ Holiday.due_date_from_calendar_days(Date.new(2008, 10, 7), 20).should == Date.new(2008, 10, 27)
+ end
+
+ it "handles the due date falling on a day before a Holiday" do
+ Holiday.due_date_from_calendar_days(Date.new(2008, 12, 4), 20).should == Date.new(2008, 12, 24)
+ end
+
+ it "handles the due date falling on a Holiday" do
+ Holiday.due_date_from_calendar_days(Date.new(2008, 12, 5), 20).should == Date.new(2008, 12, 29)
+ end
+
+ it "handles Time objects" do
+ Holiday.due_date_from_calendar_days(Time.utc(2009, 03, 17, 12, 0, 0), 20).should == Date.new(2009, 4, 6)
+ end
+ end
end
diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb
index 98681a9e9..eec362ad3 100644
--- a/spec/models/request_mailer_spec.rb
+++ b/spec/models/request_mailer_spec.rb
@@ -97,10 +97,12 @@ describe RequestMailer, " when receiving incoming mail" do
# check attached bounce is good copy of incoming-request-plain.email
mail.multipart?.should == true
mail.parts.size.should == 2
+ message_part = mail.parts[0].to_s
bounced_mail = TMail::Mail.parse(mail.parts[1].body)
bounced_mail.to.should == [ ir.incoming_email ]
bounced_mail.from.should == [ 'geraldinequango@localhost' ]
- bounced_mail.body.include?("That's so totally a rubbish question")
+ bounced_mail.body.include?("That's so totally a rubbish question").should be_true
+ message_part.include?("marked to no longer receive responses").should be_true
deliveries.clear
end
@@ -324,3 +326,4 @@ describe RequestMailer, 'when sending mail when someone has updated an old uncla
end
end
+
diff --git a/spec/views/request/_after_actions.rhtml_spec.rb b/spec/views/request/_after_actions.rhtml_spec.rb
index d04db3fc2..5b4734c52 100644
--- a/spec/views/request/_after_actions.rhtml_spec.rb
+++ b/spec/views/request/_after_actions.rhtml_spec.rb
@@ -1,85 +1,86 @@
require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__)
-describe 'when displaying actions that can be taken with regard to a request' do
-
- before do
- @mock_body = mock_model(PublicBody, :name => 'test public body',
+describe 'when displaying actions that can be taken with regard to a request' do
+
+ before do
+ @mock_body = mock_model(PublicBody, :name => 'test public body',
:url_name => 'test_public_body')
- @mock_user = mock_model(User, :name => 'test user',
+ @mock_user = mock_model(User, :name => 'test user',
:url_name => 'test_user')
- @mock_request = mock_model(InfoRequest, :title => 'test request',
- :user => @mock_user,
- :user_name => @mock_user.name,
+ @mock_request = mock_model(InfoRequest, :title => 'test request',
+ :user => @mock_user,
+ :user_name => @mock_user.name,
:is_external? => false,
- :public_body => @mock_body,
+ :public_body => @mock_body,
+ :comments_allowed? => true,
:url_title => 'test_request')
assigns[:info_request] = @mock_request
end
-
+
def do_render
render :partial => 'request/after_actions'
end
-
+
def expect_owner_div
do_render
response.should have_tag('div#owner_actions'){ yield }
end
-
+
def expect_anyone_div
do_render
response.should have_tag('div#anyone_actions'){ yield }
end
-
+
def expect_owner_link(text)
expect_owner_div{ with_tag('a', :text => text) }
end
-
+
def expect_no_owner_link(text)
expect_owner_div{ without_tag('a', :text => text) }
end
-
+
def expect_anyone_link(text)
expect_anyone_div{ with_tag('a', :text => text) }
end
-
+
def expect_no_anyone_link(text)
expect_anyone_div{ without_tag('a', :text => text) }
end
-
- describe 'if the request is old and unclassified' do
-
- before do
+
+ describe 'if the request is old and unclassified' do
+
+ before do
assigns[:old_unclassified] = true
end
-
- it 'should not display a link for the request owner to update the status of the request' do
+
+ it 'should not display a link for the request owner to update the status of the request' do
expect_no_owner_link('Update the status of this request')
end
-
- it 'should display a link for anyone to update the status of the request' do
+
+ it 'should display a link for anyone to update the status of the request' do
expect_anyone_link('Update the status of this request')
end
-
+
end
-
- describe 'if the request is not old and unclassified' do
-
- before do
+
+ describe 'if the request is not old and unclassified' do
+
+ before do
assigns[:old_unclassified] = false
end
-
- it 'should display a link for the request owner to update the status of the request' do
+
+ it 'should display a link for the request owner to update the status of the request' do
expect_owner_link('Update the status of this request')
end
-
- it 'should not display a link for anyone to update the status of the request' do
+
+ it 'should not display a link for anyone to update the status of the request' do
expect_no_anyone_link('Update the status of this request')
end
-
+
end
it 'should display a link for the request owner to request a review' do
expect_owner_link('Request an internal review')
end
-
+
end