aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2013-08-14 14:56:21 +0100
committerLouise Crow <louise.crow@gmail.com>2013-09-16 12:41:44 +0100
commita9363f6c3926d5a8cba8db79176c1b76bc4118e7 (patch)
tree65e15026bd3d1619fa775eeb71d4574106be534e
parent5104b1323ee8901c46aa76893b160ab5c7972fbb (diff)
Rewrite download spec
Make it an integration spec so we don't need to touch the internals so much.
-rw-r--r--spec/controllers/request_controller_spec.rb48
-rw-r--r--spec/factories.rb15
-rw-r--r--spec/integration/download_request_spec.rb60
3 files changed, 76 insertions, 47 deletions
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 7e26d0ada..8f8e3afa0 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -191,7 +191,6 @@ describe RequestController, "when showing one request" do
before(:each) do
load_raw_emails_data
- FileUtils.rm_rf File.join(File.dirname(__FILE__), "../../cache/zips")
end
it "should be successful" do
@@ -768,49 +767,7 @@ describe RequestController, "when showing one request" do
end
end
- describe 'when making a zipfile available' do
- it "should have a different zipfile URL when the request changes" do
- title = 'why_do_you_have_such_a_fancy_dog'
- ir = info_requests(:fancy_dog_request)
- session[:user_id] = ir.user.id # bob_smith_user
- get :download_entire_request, :url_title => title
- assigns[:url_path].should contain /#{title}.zip$/
- old_path = assigns[:url_path]
- response.location.should contain /#{assigns[:url_path]}$/
- zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", old_path)) { |zipfile|
- zipfile.count.should == 1 # just the message
- }
- receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
- get :download_entire_request, :url_title => title
- assigns[:url_path].should contain /#{title}.zip$/
- old_path = assigns[:url_path]
- response.location.should contain /#{assigns[:url_path]}$/
- zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", old_path)) { |zipfile|
- zipfile.count.should == 3 # the message plus two "hello-world.txt" files
- }
-
- # The path of the zip file is based on the hash of the timestamp of the last request
- # in the thread, so we wait for a second to make sure this one will have a different
- # timestamp than the previous.
- sleep 1
- receive_incoming_mail('incoming-request-attachment-unknown-extension.email', ir.incoming_email)
- get :download_entire_request, :url_title => title
- assigns[:url_path].should contain /#{title}.zip$/
- assigns[:url_path].should_not == old_path
- response.location.should contain assigns[:url_path]
- zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", assigns[:url_path])) { |zipfile|
- zipfile.count.should == 4 # the message, two hello-world.txt plus the unknown attachment
- }
- end
-
- it 'should successfully make a zipfile for an external request' do
- info_request = info_requests(:external_request)
- get :download_entire_request, { :url_title => info_request.url_title },
- { :user_id => users(:bob_smith_user) }
- response.location.should contain /#{assigns[:url_path]}$/
- end
- end
end
end
@@ -825,7 +782,7 @@ describe RequestController, "when handling prominence" do
context 'when the request is hidden' do
before(:each) do
- @info_request = FactoryGirl.create(:info_request_with_attachments,
+ @info_request = FactoryGirl.create(:info_request_with_incoming_attachments,
prominence: 'hidden')
end
@@ -879,7 +836,7 @@ describe RequestController, "when handling prominence" do
context 'when the request is requester_only' do
before(:each) do
- @info_request = FactoryGirl.create(:info_request_with_attachments, prominence: 'requester_only')
+ @info_request = FactoryGirl.create(:info_request_with_incoming_attachments, prominence: 'requester_only')
end
it "should not show request if you're not logged in" do
@@ -975,6 +932,7 @@ describe RequestController, "when handling prominence" do
:part => 2,
:file_name => 'interesting.pdf'
end
+
end
context 'when the incoming message has prominence requester_only' do
diff --git a/spec/factories.rb b/spec/factories.rb
index fe93815f5..36f89037a 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -57,11 +57,22 @@ FactoryGirl.define do
FactoryGirl.create(:initial_request, info_request: info_request)
end
- factory :info_request_with_attachments do
+ factory :info_request_with_incoming do
+ after(:create) do |info_request, evaluator|
+ FactoryGirl.create(:incoming_message, info_request: info_request)
+ end
+ end
+
+ factory :info_request_with_incoming_attachments do
after(:create) do |info_request, evaluator|
FactoryGirl.create(:incoming_message_with_attachments, info_request: info_request)
end
+ end
+ factory :external_request do
+ user nil
+ external_user_name 'External User'
+ external_url 'http://www.example.org/request/external'
end
end
@@ -71,7 +82,7 @@ FactoryGirl.define do
email
salt "-6116981980.392287733335677"
hashed_password '6b7cd45a5f35fd83febc0452a799530398bfb6e8' # jonespassword
-
+ email_confirmed true
factory :admin_user do
name 'Admin User'
admin_level 'super'
diff --git a/spec/integration/download_request_spec.rb b/spec/integration/download_request_spec.rb
new file mode 100644
index 000000000..563efbf50
--- /dev/null
+++ b/spec/integration/download_request_spec.rb
@@ -0,0 +1,60 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl')
+
+describe 'when making a zipfile available' do
+
+ def inspect_zip_download(session, info_request)
+ session.get_via_redirect "request/#{info_request.url_title}/download"
+ session.response.should be_success
+ Tempfile.open('download') do |f|
+ f.binmode
+ f.write(session.response.body)
+ f.flush
+ Zip::ZipFile::open(f) do |zip|
+ yield zip
+ end
+ end
+ end
+
+ def sleep_and_receive_mail(name, info_request)
+ # The path of the zip file is based on the hash of the timestamp of the last request
+ # in the thread, so we wait for a second to make sure this one will have a different
+ # timestamp than the previous.
+ sleep 1
+ receive_incoming_mail(name, info_request.incoming_email)
+ end
+
+ it "should update the contents of the zipfile when the request changes" do
+
+ info_request = FactoryGirl.create(:info_request_with_incoming)
+ request_owner = login(info_request.user)
+ inspect_zip_download(request_owner, info_request) do |zip|
+ zip.count.should == 1 # just the message
+ expected = 'This is a plain-text version of the Freedom of Information request "Example Title"'
+ zip.read('correspondence.txt').should match expected
+ end
+
+ sleep_and_receive_mail('incoming-request-two-same-name.email', info_request)
+
+ inspect_zip_download(request_owner, info_request) do |zip|
+ zip.count.should == 3 # the message plus two "hello-world.txt" files
+ zip.read('2_hello world.txt').should match('Second hello')
+ zip.read('3_hello world.txt').should match('First hello')
+ end
+
+ sleep_and_receive_mail('incoming-request-attachment-unknown-extension.email', info_request)
+
+ inspect_zip_download(request_owner, info_request) do |zip|
+ zip.count.should == 4 # the message plus two "hello-world.txt" files, and the new attachment
+ zip.read('2_hello.qwglhm').should match('This is an unusual')
+ end
+ end
+
+
+ it 'should successfully make a zipfile for an external request' do
+ info_request = info_requests(:external_request)
+ get_via_redirect "request/#{info_request.url_title}/download"
+ response.should be_success
+ end
+
+end