diff options
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/mail_handler/mail_handler_spec.rb | 8 | ||||
-rw-r--r-- | spec/lib/sendmail_return_path_spec.rb | 88 | ||||
-rw-r--r-- | spec/lib/theme_spec.rb | 25 | ||||
-rw-r--r-- | spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb | 56 |
4 files changed, 60 insertions, 117 deletions
diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index aa351bd94..49a65dade 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -235,7 +235,7 @@ describe 'when deriving a name, email and formatted address from a message from it 'should quote a name with quotes in it' do should_render_from_address('"FOI \" Person" <foiperson@localhost>', - ['FOI \" Person', + ['FOI " Person', 'foiperson@localhost', '"FOI \" Person" <foiperson@localhost>']) end @@ -409,6 +409,12 @@ describe 'when getting attachment attributes' do attributes[1][:body].length.should == 7769 end + it 'should treat a document/pdf attachment as application/pdf' do + mail = get_fixture_mail('document-pdf.email') + attributes = MailHandler.get_attachment_attributes(mail) + attributes[1][:content_type].should == "application/pdf" + end + it 'should produce a consistent set of url_part_numbers, content_types, within_rfc822_subjects and filenames from an example mail with lots of attachments' do mail = get_fixture_mail('many-attachments-date-header.email') diff --git a/spec/lib/sendmail_return_path_spec.rb b/spec/lib/sendmail_return_path_spec.rb deleted file mode 100644 index 83436c2bd..000000000 --- a/spec/lib/sendmail_return_path_spec.rb +++ /dev/null @@ -1,88 +0,0 @@ -# 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 - before(:each) { ActionMailer::Base.deliveries = [] } - - it "should default to delivery method test" do - ActionMailer::Base.delivery_method.should == :test - end - - it "should let the helper change the method" do - with_delivery_method :smtp do - ActionMailer::Base.delivery_method.should == :smtp - end - ActionMailer::Base.delivery_method.should == :test - end - - # Documentation for fancy mock functions: http://rspec.info/documentation/mocks/message_expectations.html - it "should set the return path when sending email using SMTP" do - mock_smtp = mock("smtp") - mock_smtp_session = mock("smtp_session") - - mock_smtp.should_receive(:start).once.and_yield(mock_smtp_session) - # the second parameter to the SMTP session is the sender (return path) - mock_smtp_session.should_receive(:sendmail).once.with(anything(), "test@localhost", anything()) - - Net::SMTP.stub!(:new).and_return(mock_smtp) - - with_delivery_method :smtp do - ContactMailer.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 - ).deliver - end - - deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 0 - end - - 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" postmaster@localhost', "w+") - with_delivery_method :sendmail do - ContactMailer.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 - ).deliver - end - end - - deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 0 - end - - - protected - # Change the way Rails delivers memory, just for current scope - def with_delivery_method(new_delivery_method) - old_delivery_method, ActionMailer::Base.delivery_method = ActionMailer::Base.delivery_method, new_delivery_method - yield - ensure - ActionMailer::Base.delivery_method = old_delivery_method - end - - # By default, we can't stub popen, presumably because it is a builtin written in C. - # Replace it entirely with a normal method that just calls the C one, so we can stub it - - # this leaves IO working afterwards (for other tests that run in the same instance). - def with_stub_popen() - IO.class_eval "@orig_popen = self.method(:popen); def self.popen(a, b, &c); @orig_popen.call(a, b, &c); end" - begin - yield - ensure - # in theory would undo the popen alterations and return IO to a pristine state, but - # don't know how to (much fiddling with alias bind and the like didn't help). It - # doesn't matter - the new popen should behave just the same. - end - end - - -end - - diff --git a/spec/lib/theme_spec.rb b/spec/lib/theme_spec.rb new file mode 100644 index 000000000..829c1a269 --- /dev/null +++ b/spec/lib/theme_spec.rb @@ -0,0 +1,25 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe "theme_url_to_theme_name" do + + it "should deal with a typical bare repo URL" do + url = 'git://wherever/blah-theme.git' + theme_url_to_theme_name(url).should == 'blah-theme' + end + + it "should deal with a typical bare repo URL with trailing slashes" do + url = 'ssh://wherever/blah-theme.git//' + theme_url_to_theme_name(url).should == 'blah-theme' + end + + it "should deal with a typical non-bare repo URL" do + url = '/home/whoever/themes/blah-theme' + theme_url_to_theme_name(url).should == 'blah-theme' + end + + it "should deal with a typical non-bare repo URL with a trailing slash" do + url = '/home/whoever/themes/blah-theme/' + theme_url_to_theme_name(url).should == 'blah-theme' + end + +end diff --git a/spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb b/spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb index 9bd5ccb93..fcd729b48 100644 --- a/spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb +++ b/spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb @@ -1,71 +1,71 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe WhatDoTheyKnow::StripEmptySessions do - + def make_response(session_data, response_headers) app = lambda do |env| env['rack.session'] = session_data - return [200, response_headers, ['content']] + return [200, response_headers, ['content']] end strip_empty_sessions = WhatDoTheyKnow::StripEmptySessions app = strip_empty_sessions.new(app, {:key => 'mykey', :path => '', :httponly => true}) response = Rack::MockRequest.new(app).get('/', 'HTTP_ACCEPT' => 'text/html') end - - it 'should not prevent a cookie being set if there is data in the session' do - session_data = { :some_real_data => 'important', - :session_id => 'my_session_id', - :_csrf_token => 'hi_there' } - application_response_headers = { 'Content-Type' => 'text/html', + + it 'should not prevent a cookie being set if there is data in the session' do + session_data = { 'some_real_data' => 'important', + 'session_id' => 'my_session_id', + '_csrf_token' => 'hi_there' } + application_response_headers = { 'Content-Type' => 'text/html', 'Set-Cookie' => 'mykey=f274c61a35320c52d45e9f8d7d4e2649; path=/; HttpOnly'} response = make_response(session_data, application_response_headers) response.headers['Set-Cookie'].should == 'mykey=f274c61a35320c52d45e9f8d7d4e2649; path=/; HttpOnly' end - describe 'if there is no meaningful data in the session' do + describe 'if there is no meaningful data in the session' do - before do - @session_data = { :session_id => 'my_session_id', - :_csrf_token => 'hi_there' } + before do + @session_data = { 'session_id' => 'my_session_id', + '_csrf_token' => 'hi_there' } end - - it 'should not strip any other header' do + + it 'should not strip any other header' do application_response_headers = { 'Content-Type' => 'text/html', 'Set-Cookie' => 'mykey=f274c61a35320c52d45e9f8d7d4e2649; path=/; HttpOnly'} response = make_response(@session_data, application_response_headers) response.headers['Content-Type'].should == 'text/html' end - - it 'should strip the session cookie setting header ' do - application_response_headers = { 'Content-Type' => 'text/html', + + it 'should strip the session cookie setting header ' do + application_response_headers = { 'Content-Type' => 'text/html', 'Set-Cookie' => 'mykey=f274c61a35320c52d45e9f8d7d4e2649; path=/; HttpOnly'} response = make_response(@session_data, application_response_headers) response.headers['Set-Cookie'].should == "" end - - it 'should strip the session cookie setting header even with a locale' do - @session_data[:locale] = 'en' - application_response_headers = { 'Content-Type' => 'text/html', + + it 'should strip the session cookie setting header even with a locale' do + @session_data['locale'] = 'en' + application_response_headers = { 'Content-Type' => 'text/html', 'Set-Cookie' => 'mykey=f274c61a35320c52d45e9f8d7d4e2649; path=/; HttpOnly'} response = make_response(@session_data, application_response_headers) response.headers['Set-Cookie'].should == "" end - it 'should not strip the session cookie setting for admins' do - @session_data[:using_admin] = 1 - application_response_headers = { 'Content-Type' => 'text/html', + it 'should not strip the session cookie setting for admins' do + @session_data['using_admin'] = 1 + application_response_headers = { 'Content-Type' => 'text/html', 'Set-Cookie' => 'mykey=f274c61a35320c52d45e9f8d7d4e2649; path=/; HttpOnly'} response = make_response(@session_data, application_response_headers) response.headers['Set-Cookie'].should == "mykey=f274c61a35320c52d45e9f8d7d4e2649; path=/; HttpOnly" end - - it 'should strip the session cookie setting header (but no other cookie setting header) if there is more than one' do - application_response_headers = { 'Content-Type' => 'text/html', + + it 'should strip the session cookie setting header (but no other cookie setting header) if there is more than one' do + application_response_headers = { 'Content-Type' => 'text/html', 'Set-Cookie' => ['mykey=f274c61a35320c52d45e9f8d7d4e2649; path=/; HttpOnly', 'other=mydata']} response = make_response(@session_data, application_response_headers) response.headers['Set-Cookie'].should == ['other=mydata'] end - + end end |