diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 14 | ||||
-rw-r--r-- | spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb | 55 | ||||
-rw-r--r-- | spec/models/outgoing_mailer_spec.rb | 17 | ||||
-rw-r--r-- | spec/spec_helper.rb | 16 |
4 files changed, 71 insertions, 31 deletions
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 8232a7398..9d91bf8c2 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -376,20 +376,6 @@ describe RequestController, "when creating a new request" do response.should render_template('new') end - it "should give an error if the same request is submitted twice with extra whitespace in the body" do - # This only works for PostgreSQL databases which have regexp_replace - - # see model method InfoRequest.find_by_existing_request for more info - if ActiveRecord::Base.connection.adapter_name == "PostgreSQL" - session[:user_id] = @user.id - - post :new, :info_request => { :public_body_id => info_requests(:fancy_dog_request).public_body_id, - :title => info_requests(:fancy_dog_request).title }, - :outgoing_message => { :body => "\n" + info_requests(:fancy_dog_request).outgoing_messages[0].body + " "}, - :submitted_new_request => 1, :preview => 0, :mouse_house => 1 - response.should render_template('new') - end - end - it "should let you submit another request with the same title" do session[:user_id] = @user.id diff --git a/spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb b/spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb new file mode 100644 index 000000000..cbe1feea6 --- /dev/null +++ b/spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb @@ -0,0 +1,55 @@ +require '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']] + 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', + '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 + + before do + @session_data = { :session_id => 'my_session_id', + :_csrf_token => 'hi_there' } + end + + 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', + '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 (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 diff --git a/spec/models/outgoing_mailer_spec.rb b/spec/models/outgoing_mailer_spec.rb index 83da7a553..24143fc9b 100644 --- a/spec/models/outgoing_mailer_spec.rb +++ b/spec/models/outgoing_mailer_spec.rb @@ -6,23 +6,6 @@ describe OutgoingMailer, " when working out follow up addresses" do # mocks. Put parts of the tests in spec/lib/tmail_extensions.rb fixtures :info_requests, :incoming_messages, :raw_emails, :public_bodies, :public_body_translations - before do - # XXX this is a hack around the fact that our raw_email model - # is in transition to something that doesn't actually live in - # the database at all. The raw_email fixture saves to the - # model, the model then needs to be told to save itself on the - # filesystem. - raw_email = raw_emails(:useless_raw_email) - raw_email.data=raw_email.dbdata - end - - after do - # And this is a hack around the fact that Rails fixtures don't - # have teardowns happen on them; we need to ensure no emails - # are left lying around - raw_emails(:useless_raw_email).destroy_file_representation! - end - it "should parse them right" do ir = info_requests(:fancy_dog_request) im = ir.incoming_messages[0] diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bbcc9aa23..086def32a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -30,6 +30,22 @@ Spec::Runner.configure do |config| # in your config/boot.rb config.fixture_path = RAILS_ROOT + '/spec/fixtures/' + + config.before(:each) do + # XXX this is a hack around the fact that our raw_email model + # is in transition to something that doesn't actually live in + # the database at all. The raw_email *fixture* saves to the + # model, the model then needs to be told to save itself on the + # filesystem. + begin + raw_email = raw_emails(:useless_raw_email) + raw_email.data=raw_email.dbdata + rescue NoMethodError + # only do it in tests with raw_emails fixtures + end + end + + # == Fixtures # # You can declare fixtures for each example_group like this: |