aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/request_controller_spec.rb27
-rw-r--r--spec/lib/i18n_interpolation.rb38
-rw-r--r--spec/lib/sendmail_return_path_spec.rb4
-rw-r--r--spec/lib/timezone_fixes_spec.rb21
-rw-r--r--spec/models/foi_attachment_spec.rb13
-rw-r--r--spec/models/incoming_message_spec.rb7
-rw-r--r--spec/models/request_mailer_spec.rb2
-rw-r--r--spec/script/mailin_spec.rb (renamed from spec/script/mailin-spec.rb)0
-rw-r--r--spec/views/request/list.rhtml_spec.rb2
9 files changed, 75 insertions, 39 deletions
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 148e4327d..6f25b605a 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -59,19 +59,6 @@ describe RequestController, "when listing recent requests" do
:conditions => "id in (select info_request_id from info_request_events where created_at between '2007-10-13'::date and '2007-11-01'::date)")
end
- it "should make a sane-sized cache tag" do
- get :list, :view => 'all', :request_date_after => '13/10/2007', :request_date_before => '01/11/2007'
- assigns[:cache_tag].size.should <= 32
- end
-
- it "should vary the cache tag with locale" do
- get :list, :view => 'all', :request_date_after => '13/10/2007', :request_date_before => '01/11/2007'
- en_tag = assigns[:cache_tag]
- session[:locale] = :es
- get :list, :view => 'all', :request_date_after => '13/10/2007', :request_date_before => '01/11/2007'
- assigns[:cache_tag].should_not == en_tag
- end
-
it "should list internal_review requests as unresolved ones" do
get :list, :view => 'awaiting'
@@ -1044,7 +1031,7 @@ describe RequestController, "when creating a new request" do
mail = deliveries[0]
mail.body.should =~ /This is a silly letter. It is too short to be interesting./
- response.should redirect_to(:action => 'show', :url_title => ir.url_title)
+ response.should redirect_to show_new_request_url(:url_title => ir.url_title)
# This test uses an explicit path because it's relied in
# Google Analytics goals:
response.redirected_to.should =~ /request\/why_is_your_quango_called_gerald\/new$/
@@ -1082,7 +1069,7 @@ describe RequestController, "when creating a new request" do
ir.url_title.should_not == ir2.url_title
- response.should redirect_to(:action => 'show', :url_title => ir2.url_title)
+ response.should redirect_to show_new_request_url(:url_title => ir2.url_title)
end
it 'should respect the rate limit' do
@@ -1094,14 +1081,14 @@ describe RequestController, "when creating a new request" do
:title => "What is the answer to the ultimate question?", :tag_string => "" },
:outgoing_message => { :body => "Please supply the answer from your files." },
:submitted_new_request => 1, :preview => 0
- response.should redirect_to(:action => 'show', :url_title => 'what_is_the_answer_to_the_ultima')
+ response.should redirect_to show_new_request_url(:url_title => 'what_is_the_answer_to_the_ultima')
post :new, :info_request => { :public_body_id => @body.id,
:title => "Why did the chicken cross the road?", :tag_string => "" },
:outgoing_message => { :body => "Please send me all the relevant documents you hold." },
:submitted_new_request => 1, :preview => 0
- response.should redirect_to(:action => 'show', :url_title => 'why_did_the_chicken_cross_the_ro')
+ response.should redirect_to show_new_request_url(:url_title => 'why_did_the_chicken_cross_the_ro')
post :new, :info_request => { :public_body_id => @body.id,
:title => "What's black and white and red all over?", :tag_string => "" },
@@ -1121,20 +1108,20 @@ describe RequestController, "when creating a new request" do
:title => "What is the answer to the ultimate question?", :tag_string => "" },
:outgoing_message => { :body => "Please supply the answer from your files." },
:submitted_new_request => 1, :preview => 0
- response.should redirect_to(:action => 'show', :url_title => 'what_is_the_answer_to_the_ultima')
+ response.should redirect_to show_new_request_url(:url_title => 'what_is_the_answer_to_the_ultima')
post :new, :info_request => { :public_body_id => @body.id,
:title => "Why did the chicken cross the road?", :tag_string => "" },
:outgoing_message => { :body => "Please send me all the relevant documents you hold." },
:submitted_new_request => 1, :preview => 0
- response.should redirect_to(:action => 'show', :url_title => 'why_did_the_chicken_cross_the_ro')
+ response.should redirect_to show_new_request_url(:url_title => 'why_did_the_chicken_cross_the_ro')
post :new, :info_request => { :public_body_id => @body.id,
:title => "What's black and white and red all over?", :tag_string => "" },
:outgoing_message => { :body => "Please send all minutes of meetings and email records that address this question." },
:submitted_new_request => 1, :preview => 0
- response.should redirect_to(:action => 'show', :url_title => 'whats_black_and_white_and_red_al')
+ response.should redirect_to show_new_request_url(:url_title => 'whats_black_and_white_and_red_al')
end
end
diff --git a/spec/lib/i18n_interpolation.rb b/spec/lib/i18n_interpolation.rb
index 6b745059c..e8d046757 100644
--- a/spec/lib/i18n_interpolation.rb
+++ b/spec/lib/i18n_interpolation.rb
@@ -8,5 +8,43 @@ describe "when using i18n" do
result = _('Hello {{dip}}', :dip => 'hummus')
result.should == 'Hello hummus'
end
+
+ it "should assume that simple translations are always html safe" do
+ _("Hello").should be_html_safe
+ end
+
end
+describe "gettext_interpolate" do
+ context "html unsafe string" do
+ let(:string) { "Hello {{a}}" }
+
+ it "should give an unsafe result" do
+ result = gettext_interpolate(string, :a => "foo")
+ result.should == "Hello foo"
+ result.should_not be_html_safe
+ end
+
+ it "should give an unsafe result" do
+ result = gettext_interpolate(string, :a => "foo".html_safe)
+ result.should == "Hello foo"
+ result.should_not be_html_safe
+ end
+ end
+
+ context "html safe string" do
+ let(:string) { "Hello {{a}}".html_safe }
+
+ it "should quote the input if it's unsafe" do
+ result = gettext_interpolate(string, :a => "foo&")
+ result.should == "Hello foo&amp;"
+ result.should be_html_safe
+ end
+
+ it "should not quote the input if it's safe" do
+ result = gettext_interpolate(string, :a => "foo&".html_safe)
+ result.should == "Hello foo&"
+ result.should be_html_safe
+ end
+ end
+end
diff --git a/spec/lib/sendmail_return_path_spec.rb b/spec/lib/sendmail_return_path_spec.rb
index 7708edb35..137869b6e 100644
--- a/spec/lib/sendmail_return_path_spec.rb
+++ b/spec/lib/sendmail_return_path_spec.rb
@@ -28,7 +28,7 @@ describe "when sending email with an altered return path" do
Net::SMTP.stub!(:new).and_return(mock_smtp)
with_delivery_method :smtp do
- ContactMailer.deliver_message(
+ ContactMailer.deliver_to_admin_message(
"Mr. Test", "test@localhost", "Test script spec/lib/sendmail_return_path_spec.rb",
"This is just a test for a test script", nil, nil, nil
)
@@ -42,7 +42,7 @@ describe "when sending email with an altered return path" do
with_stub_popen do
IO.should_receive(:popen).once.with('/usr/sbin/sendmail -i -t -f "test@localhost"', "w+")
with_delivery_method :sendmail do
- ContactMailer.deliver_message(
+ ContactMailer.deliver_to_admin_message(
"Mr. Test", "test@localhost", "Test script spec/lib/sendmail_return_path_spec.rb",
"This is just a test for a test script", nil, nil, nil
)
diff --git a/spec/lib/timezone_fixes_spec.rb b/spec/lib/timezone_fixes_spec.rb
index 525bd7561..9d6ade526 100644
--- a/spec/lib/timezone_fixes_spec.rb
+++ b/spec/lib/timezone_fixes_spec.rb
@@ -11,14 +11,13 @@ describe "when doing things with timezones" do
with_active_record_default_timezone :utc do
time = Time.local(2000)
mail_server_log_done = MailServerLogDone.create('last_stat' => time, 'filename' => 'dummy')
- raw_saved_time = MailServerLogDone.find(mail_server_log_done.id).read_attribute(:last_stat)
+ raw_saved_time = MailServerLogDone.find(mail_server_log_done.id).attributes_before_type_cast["last_stat"]
saved_time = MailServerLogDone.find(mail_server_log_done.id).last_stat
assert_equal time, saved_time
- assert_equal saved_time, raw_saved_time
# Time is created in EST by local method (using ENV['TZ'])
assert_equal [0, 0, 0, 1, 1, 2000, 6, 1, false, "EST"], time.to_a
# Due to :utc active_record_default_timezone, everything saved as UTC
- assert_equal [0, 0, 5, 1, 1, 2000, 6, 1, false, "UTC"], raw_saved_time.to_a
+ assert_equal "2000-01-01 05:00:00", raw_saved_time
# As config.time_zone is UTC (from config default), times returned in UTC
assert_equal [0, 0, 5, 1, 1, 2000, 6, 1, false, "UTC"], saved_time.to_a
end
@@ -33,14 +32,12 @@ describe "when doing things with timezones" do
Time.use_zone 'Central Time (US & Canada)' do
time = Time.zone.local(2000)
mail_server_log_done = MailServerLogDone.create('last_stat' => time, 'filename' => 'dummy')
- raw_saved_time = MailServerLogDone.find(mail_server_log_done.id).read_attribute(:last_stat)
+ raw_saved_time = MailServerLogDone.find(mail_server_log_done.id).attributes_before_type_cast["last_stat"]
saved_time = MailServerLogDone.find(mail_server_log_done.id).last_stat
- assert_equal time, saved_time
- assert_equal saved_time, raw_saved_time
# Time is created in CST by Time.local (as Time.zone has been set)
assert_equal [0, 0, 0, 1, 1, 2000, 6, 1, false, "CST"], time.to_a
# Due to :utc active_record_default_timezone, everything saved as UTC
- assert_equal [0, 0, 6, 1, 1, 2000, 6, 1, false, "UTC"], raw_saved_time.to_a
+ assert_equal "2000-01-01 06:00:00", raw_saved_time
# Times returned in CST due to Time.use_zone and ActiveRecord::time_zone_aware_attributes
# being true
assert_equal [0, 0, 0, 1, 1, 2000, 6, 1, false, "CST"], saved_time.to_a
@@ -55,14 +52,13 @@ describe "when doing things with timezones" do
with_active_record_default_timezone :local do
time = Time.utc(2000)
mail_server_log_done = MailServerLogDone.create('last_stat' => time, 'filename' => 'dummy')
- raw_saved_time = MailServerLogDone.find(mail_server_log_done.id).read_attribute(:last_stat)
+ raw_saved_time = MailServerLogDone.find(mail_server_log_done.id).attributes_before_type_cast["last_stat"]
saved_time = MailServerLogDone.find(mail_server_log_done.id).last_stat
assert_equal time, saved_time
- assert_equal saved_time, raw_saved_time
# Time is created in UTC by Time.utc method
assert_equal [0, 0, 0, 1, 1, 2000, 6, 1, false, "UTC"], time.to_a
# Due to :local active_record_default_timezone, saved as EST
- assert_equal [0, 0, 19, 31, 12, 1999, 5, 365, false, "EST"], raw_saved_time.to_a
+ assert_equal "1999-12-31 19:00:00", raw_saved_time
# As config.time_zone is UTC (from config default), times returned in UTC
assert_equal [0, 0, 0, 1, 1, 2000, 6, 1, false, "UTC"], saved_time.to_a
end
@@ -76,14 +72,13 @@ describe "when doing things with timezones" do
Time.use_zone 'Central Time (US & Canada)' do
time = Time.zone.local(2000)
mail_server_log_done = MailServerLogDone.create('last_stat' => time, 'filename' => 'dummy')
- raw_saved_time = MailServerLogDone.find(mail_server_log_done.id).read_attribute(:last_stat)
+ raw_saved_time = MailServerLogDone.find(mail_server_log_done.id).attributes_before_type_cast["last_stat"]
saved_time = MailServerLogDone.find(mail_server_log_done.id).last_stat
assert_equal time, saved_time
- assert_equal saved_time, raw_saved_time
# Time is created in CST by Time.zone.local
assert_equal [0, 0, 0, 1, 1, 2000, 6, 1, false, "CST"], time.to_a
# Due to :local active_record_default_timezone, saved as EST
- assert_equal [0, 0, 1, 1, 1, 2000, 6, 1, false, "EST"], raw_saved_time.to_a
+ assert_equal "2000-01-01 01:00:00", raw_saved_time
# Due to Time.use_zone, and ActiveRecord::time_zone_aware_attributes
# being true, time returned in CST
assert_equal [0, 0, 0, 1, 1, 2000, 6, 1, false, "CST"], saved_time.to_a
diff --git a/spec/models/foi_attachment_spec.rb b/spec/models/foi_attachment_spec.rb
index 9d44957e4..537a3363c 100644
--- a/spec/models/foi_attachment_spec.rb
+++ b/spec/models/foi_attachment_spec.rb
@@ -30,6 +30,17 @@ describe FoiAttachment, " when calculating due date" do
main.delete_cached_file!
main = im.get_main_body_text_part
main.body.should == orig_body
-
+
end
end
+
+describe FoiAttachment, "when ensuring a filename is present" do
+
+ it 'should create a filename for an instance with a blank filename' do
+ attachment = FoiAttachment.new
+ attachment.filename = ''
+ attachment.ensure_filename!
+ attachment.filename.should == 'attachment.bin'
+ end
+
+end
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index 6fc0ff3cc..f53a5856a 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -148,6 +148,13 @@ describe IncomingMessage, " folding quoted parts of emails" do
@incoming_message.remove_lotus_quoting(text).should match(/FOLDED_QUOTED_SECTION/)
end
+ it 'should not error when trying to fold lotus notes quoted parts on a request with no user_name' do
+ text = "hello"
+ @incoming_message = IncomingMessage.new()
+ @incoming_message.stub_chain(:info_request, :user_name).and_return(nil)
+ @incoming_message.remove_lotus_quoting(text).should == 'hello'
+ end
+
it "cope with [ in user names properly" do
@incoming_message = IncomingMessage.new()
@incoming_message.stub_chain(:info_request, :user_name).and_return("Sir [ Bobble")
diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb
index 0f09e6926..5edc8edb6 100644
--- a/spec/models/request_mailer_spec.rb
+++ b/spec/models/request_mailer_spec.rb
@@ -98,7 +98,7 @@ describe RequestMailer, " when receiving incoming mail" do
mail.multipart?.should == true
mail.parts.size.should == 2
message_part = mail.parts[0].to_s
- bounced_mail = MailHandler.mail_from_raw_email(mail.parts[1].body, decode=false)
+ bounced_mail = MailHandler.mail_from_raw_email(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").should be_true
diff --git a/spec/script/mailin-spec.rb b/spec/script/mailin_spec.rb
index d80789635..d80789635 100644
--- a/spec/script/mailin-spec.rb
+++ b/spec/script/mailin_spec.rb
diff --git a/spec/views/request/list.rhtml_spec.rb b/spec/views/request/list.rhtml_spec.rb
index 94ece5e76..137bc359d 100644
--- a/spec/views/request/list.rhtml_spec.rb
+++ b/spec/views/request/list.rhtml_spec.rb
@@ -7,8 +7,6 @@ describe "when listing recent requests" do
assigns[:per_page] = 10
# work round a bug in ActionController::TestRequest; allows request.query_string to work in the template
request.env["REQUEST_URI"] = ""
- # we're not testing the interlock plugin's cache
- template.stub!(:view_cache).and_yield
end
def make_mock_event