aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/public_body_controller_spec.rb14
-rw-r--r--spec/integration/cookie_stripping_spec.rb12
-rw-r--r--spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb56
-rw-r--r--spec/models/info_request_spec.rb27
4 files changed, 81 insertions, 28 deletions
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index 6800765f2..2663f2a75 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -273,6 +273,20 @@ describe PublicBodyController, "when showing JSON version for API" do
end
+describe PublicBodyController, "when asked to export public bodies as CSV" do
+
+ it "should return a valid CSV file with the right number of rows" do
+ get :list_all_csv
+ all_data = CSV.parse response.body
+ all_data.length.should == 8
+ # Check that the header has the right number of columns:
+ all_data[0].length.should == 11
+ # And an actual line of data:
+ all_data[1].length.should == 11
+ end
+
+end
+
describe PublicBodyController, "when showing public body statistics" do
it "should render the right template with the right data" do
diff --git a/spec/integration/cookie_stripping_spec.rb b/spec/integration/cookie_stripping_spec.rb
new file mode 100644
index 000000000..897899fd5
--- /dev/null
+++ b/spec/integration/cookie_stripping_spec.rb
@@ -0,0 +1,12 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl')
+
+describe 'when making stripping cookies' do
+
+ it 'should not set a cookie when no significant session data is set' do
+ get 'country_message'
+ response.headers['Set-Cookie'].should be_blank
+ 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
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index 64ad1972e..cf4dda62c 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -550,6 +550,33 @@ describe InfoRequest do
end
+ describe 'when an instance is asked if all can view it' do
+
+ before do
+ @info_request = InfoRequest.new
+ end
+
+ it 'should return true if its prominence is normal' do
+ @info_request.prominence = 'normal'
+ @info_request.all_can_view?.should == true
+ end
+
+ it 'should return true if its prominence is backpage' do
+ @info_request.prominence = 'backpage'
+ @info_request.all_can_view?.should == true
+ end
+
+ it 'should return false if its prominence is hidden' do
+ @info_request.prominence = 'hidden'
+ @info_request.all_can_view?.should == false
+ end
+
+ it 'should return false if its prominence is requester_only' do
+ @info_request.prominence = 'requester_only'
+ @info_request.all_can_view?.should == false
+ end
+ end
+
describe 'when applying censor rules' do
before do