diff options
-rw-r--r-- | app/controllers/application_controller.rb | 7 | ||||
-rw-r--r-- | spec/controllers/general_controller_spec.rb | 6 | ||||
-rw-r--r-- | spec/controllers/public_body_controller_spec.rb | 5 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 26 | ||||
-rw-r--r-- | spec/fixtures/comments.yml | 9 | ||||
-rw-r--r-- | spec/fixtures/incoming_messages.yml | 7 | ||||
-rw-r--r-- | spec/fixtures/info_request_events.yml | 37 | ||||
-rw-r--r-- | spec/fixtures/info_requests.yml | 15 | ||||
-rw-r--r-- | spec/fixtures/outgoing_messages.yml | 10 | ||||
-rw-r--r-- | spec/fixtures/public_bodies.yml | 13 | ||||
-rw-r--r-- | spec/fixtures/public_body_translations.yml | 11 | ||||
-rw-r--r-- | spec/models/public_body_spec.rb | 1 |
12 files changed, 129 insertions, 18 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8fc6c3792..5a295d3e7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -178,14 +178,13 @@ class ApplicationController < ActionController::Base end def foi_fragment_cache_path(param) - path = foi_fragment_cache_part_path(param) - path = "/views" + path - foi_cache_path = File.join(File.dirname(__FILE__), '../../cache') + path = File.join(RAILS_ROOT, 'cache', 'views', foi_fragment_cache_part_path(param)) max_file_length = 255 - 35 # we subtract 35 because tempfile # adds on a variable number of # characters - return File.join(foi_cache_path, path)[0...max_file_length] + return File.join(File.split(path).map{|x| x[0...max_file_length]}) end + def foi_fragment_cache_all_for_request(info_request) # return stub path so admin can expire it first_three_digits = info_request.id.to_s()[0..2] diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index c4fd46c14..b067707de 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -115,9 +115,11 @@ describe GeneralController, "when searching" do rebuild_xapian_index end - it 'should list the successful request first' do + it 'should list the newest successful request first' do + # Make sure the newest is listed first even if an older one has an even newer comment: + # https://github.com/sebbacon/alaveteli/issues/370 get :frontpage - assigns[:request_events].first.info_request.should == info_requests(:boring_request) + assigns[:request_events].first.info_request.should == info_requests(:another_boring_request) end end diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 4b657849a..bd4e625ca 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -105,11 +105,14 @@ describe PublicBodyController, "when listing bodies" do end it "should list bodies in alphabetical order" do + # Note that they are alphabetised by localised name get :list response.should render_template('list') - assigns[:public_bodies].should == PublicBody.all(:order => "name", :conditions => "id <> #{PublicBody.internal_admin_body.id}") + assigns[:public_bodies].should == PublicBody.all( + :conditions => "id <> #{PublicBody.internal_admin_body.id}", + :order => "(select name from public_body_translations where public_body_id=public_bodies.id and locale='en')") assigns[:tag].should == "all" assigns[:description].should == "" end diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index a77d1ac27..bae1f32e7 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -39,6 +39,7 @@ describe RequestController, "when listing recent requests" do from info_request_events later_events where later_events.created_at > info_request_events.created_at and later_events.info_request_id = info_request_events.info_request_id + and later_events.described_state is not null ) and info_request_events.described_state in ('successful', 'partially_successful') )") @@ -219,9 +220,11 @@ describe RequestController, "when showing one request" do get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' (assigns[:info_request_events].size - size_before).should == 1 ir.reload + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt'] response.content_type.should == "text/plain" response.should have_text(/Second hello/) + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3, :file_name => ['hello.txt'] response.content_type.should == "text/plain" response.should have_text(/First hello/) @@ -350,12 +353,16 @@ describe RequestController, "when showing one request" do censor_rule.last_edit_comment = "none" ir.user.censor_rules << censor_rule - receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) - ir.reload + begin + receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) + ir.reload - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1 - response.content_type.should == "text/plain" - response.should have_text(/xxxxxx hello/) + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1 + response.content_type.should == "text/plain" + response.should have_text(/xxxxxx hello/) + ensure + ir.user.censor_rules.clear + end end it "should censor attachment names" do @@ -386,9 +393,12 @@ describe RequestController, "when showing one request" do censor_rule.last_edit_editor = "unknown" censor_rule.last_edit_comment = "none" ir.censor_rules << censor_rule - - get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' - response.body.should have_tag("p.attachment strong", /goodbye.txt/m) + begin + get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' + response.body.should have_tag("p.attachment strong", /goodbye.txt/m) + ensure + ir.censor_rules.clear + end end it "should make a zipfile available, which has a different URL when it changes" do diff --git a/spec/fixtures/comments.yml b/spec/fixtures/comments.yml index ed1925bfa..b73385a55 100644 --- a/spec/fixtures/comments.yml +++ b/spec/fixtures/comments.yml @@ -8,4 +8,13 @@ silly_comment: user_id: "2" created_at: 2008-08-13 01:25:17.486939 +sensible_comment: + id: 2 + body: This a wise and helpful annotation. + info_request_id: 106 + visible: t + comment_type: request + user_id: 1 + created_at: 2008-08-13 01:25:17.486939 + updated_at: 2008-08-13 01:25:17.486939 diff --git a/spec/fixtures/incoming_messages.yml b/spec/fixtures/incoming_messages.yml index 2a5dd872b..a32052413 100644 --- a/spec/fixtures/incoming_messages.yml +++ b/spec/fixtures/incoming_messages.yml @@ -11,3 +11,10 @@ useful_incoming_message: raw_email_id: 2 created_at: 2012-01-26 10:19:23 updated_at: 2012-01-26 10:19:23 + +another_useful_incoming_message: + id: 3 + info_request_id: 105 + raw_email_id: 2 + created_at: 2007-11-13 18:09:20 + updated_at: 2007-11-13 18:09:20 diff --git a/spec/fixtures/info_request_events.yml b/spec/fixtures/info_request_events.yml index b19845345..ec6abbf57 100644 --- a/spec/fixtures/info_request_events.yml +++ b/spec/fixtures/info_request_events.yml @@ -48,6 +48,8 @@ badger_outgoing_message_event: described_state: waiting_response calculated_state: waiting_response outgoing_message_id: 3 + +# These in chronological order boring_outgoing_message_event: id: 905 params_yaml: "--- \n\ @@ -69,3 +71,38 @@ useful_incoming_message_event: described_state: successful calculated_state: successful +another_boring_outgoing_message_event: + id: 907 + params_yaml: "--- \n\ + :outgoing_message_id: 5\n" + outgoing_message_id: 5 + info_request_id: 106 + event_type: sent + created_at: 2006-01-12 01:56:58.586598 + described_state: waiting_response + calculated_state: waiting_response +another_useful_incoming_message_event: + id: 908 + params_yaml: "--- \n\ + :incoming_message_id: 3\n" + incoming_message_id: 3 + info_request_id: 106 + event_type: response + created_at: 2007-11-13 18:09:20.042061 + described_state: successful + calculated_state: successful + +another_comment_event: + id: 909 + info_request_id: 105 + comment_id: 2 + params_yaml: "--- \n\ + :comment_id: 2\n" + incoming_message_id: + outgoing_message_id: + last_described_at: + described_state: + calculated_state: + event_type: comment + created_at: 2008-08-12 12:05:12.879634 + diff --git a/spec/fixtures/info_requests.yml b/spec/fixtures/info_requests.yml index 9f767e7f3..89c53e9f3 100644 --- a/spec/fixtures/info_requests.yml +++ b/spec/fixtures/info_requests.yml @@ -35,10 +35,21 @@ boring_request: id: 105 title: The cost of boring url_title: the_cost_of_boring - created_at: 2012-01-26 10:19:23 - updated_at: 2012-01-26 10:19:23 + created_at: 2006-01-12 01:56:58.586598 + updated_at: 2008-08-12 12:05:12.879634 public_body_id: 3 user_id: 1 described_state: successful awaiting_description: false idhash: 173fd003 +another_boring_request: + id: 106 + title: The cost of boring + url_title: the_cost_of_boring_2 + created_at: 2006-01-12 01:56:58.586598 + updated_at: 2007-11-13 18:09:20.042061 + public_body_id: 5 + user_id: 1 + described_state: successful + awaiting_description: false + idhash: 173fd003 diff --git a/spec/fixtures/outgoing_messages.yml b/spec/fixtures/outgoing_messages.yml index 3afce92f5..3fb472630 100644 --- a/spec/fixtures/outgoing_messages.yml +++ b/spec/fixtures/outgoing_messages.yml @@ -54,5 +54,15 @@ boring_outgoing_message: created_at: 2012-01-14 01:56:58.586598 what_doing: normal_sort +another_boring_outgoing_message: + id: 5 + info_request_id: 106 + message_type: initial_request + status: sent + body: "How much was spent on boring equipment in the 2010-2011 financial year?" + last_sent_at: 2006-01-12 01:57:58.586598 + created_at: 2006-01-12 01:56:58.586598 + updated_at: 2006-01-12 01:56:58.586598 + what_doing: normal_sort diff --git a/spec/fixtures/public_bodies.yml b/spec/fixtures/public_bodies.yml index 93fd0fb2e..737fe203f 100644 --- a/spec/fixtures/public_bodies.yml +++ b/spec/fixtures/public_bodies.yml @@ -36,3 +36,16 @@ forlorn_public_body: url_name: lonely created_at: 2011-01-26 14:11:02.12345 notes: A very lonely public body that no one has corresponded with +silly_walks_public_body: + id: 5 + version: 1 + name: "Ministry of Silly Walks" + first_letter: M + updated_at: 2007-10-25 10:51:01.161639 + last_edit_comment: Is a comment really required? + request_email: silly-walks-requests@localhost + last_edit_editor: robin + short_name: MSW + url_name: msw + created_at: 2007-10-25 10:51:01.161639 + notes: You know the one. diff --git a/spec/fixtures/public_body_translations.yml b/spec/fixtures/public_body_translations.yml index 08727e45c..b81dd35a3 100644 --- a/spec/fixtures/public_body_translations.yml +++ b/spec/fixtures/public_body_translations.yml @@ -52,3 +52,14 @@ forlorn_en_public_body_translation: url_name: lonely locale: en notes: A very lonely public body that no one has corresponded with + +silly_walks_en_public_body_translation: + id: 6 + public_body_id: 5 + locale: en + name: "Ministry of Silly Walks" + first_letter: M + request_email: silly-walks-requests@localhost + short_name: MSW + url_name: msw + notes: You know the one. diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index 97fa04f93..8d667c395 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -249,7 +249,6 @@ describe PublicBody, " when loading CSV files" do it "should import even if no email is provided" do errors, notes = PublicBody.import_csv("1,aBody", '', 'replace', true, 'someadmin') # true means dry run errors.should == [] - puts "notes = #{notes.inspect}" notes.size.should == 2 notes[0].should == "line 1: creating new authority 'aBody' (locale: en):\n\t{\"name\":\"aBody\"}" notes[1].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/ |