diff options
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/i18n_interpolation.rb | 38 | ||||
-rw-r--r-- | spec/lib/mail_handler/mail_handler_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/sendmail_return_path_spec.rb | 11 | ||||
-rw-r--r-- | spec/lib/timezone_fixes_spec.rb | 26 |
4 files changed, 60 insertions, 17 deletions
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&" + 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/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index 48c32e2bc..79b779687 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -22,7 +22,7 @@ describe 'when creating a mail object from raw data' do it 'should convert an iso8859 email to utf8' do mail = get_fixture_mail('iso8859_2_raw_email.email') - mail.subject.should have_text(/gjatë/u) + mail.subject.should match /gjatë/u MailHandler.get_part_body(mail).is_utf8?.should == true end diff --git a/spec/lib/sendmail_return_path_spec.rb b/spec/lib/sendmail_return_path_spec.rb index 7708edb35..b4bdda12c 100644 --- a/spec/lib/sendmail_return_path_spec.rb +++ b/spec/lib/sendmail_return_path_spec.rb @@ -1,5 +1,10 @@ # This is a test of the monkey patches in sendmail_return_path.rb +# In Rails 3 the monkeypatches are not needed anymore because sendmail now has the "-f" flag +# set correctly. So, strictly these tests are testing the Rails internals. So, that means we really +# should delete them. Let's do that later when things have settled down. For the time being leave +# them in + require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe "when sending email with an altered return path" do @@ -28,7 +33,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 ) @@ -40,9 +45,9 @@ describe "when sending email with an altered return path" do it "should set the return path when sending email using sendmail" do with_stub_popen do - IO.should_receive(:popen).once.with('/usr/sbin/sendmail -i -t -f "test@localhost"', "w+") + IO.should_receive(:popen).once.with('/usr/sbin/sendmail -i -t -f "test@localhost" postmaster@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..8a9a3bf31 100644 --- a/spec/lib/timezone_fixes_spec.rb +++ b/spec/lib/timezone_fixes_spec.rb @@ -3,6 +3,11 @@ # We use MailServerLogDone here just as a totally random model that has a datetime type. require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +# In Rails 3 the monkeypatch that these tests are testing is not necessary. So, +# since these tests are testing the Rails internals you could argue that they shouldn't +# be here. Well, you're right. But let's leave them in for the time being until the upgrade is finished. +# Then, we should probably delete this whole file + describe "when doing things with timezones" do it "should preserve time objects with local time conversion to default timezone UTC @@ -11,14 +16,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 +37,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 +57,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 +77,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 |