From d5a43f1aa76c1e0086f08bec9c575d2a41ae9a9b Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Wed, 4 Jul 2012 13:45:29 +0100 Subject: Atom feed of request events We need not only new requests, but new outgoing correspondence of any sort. The idea is that this feed will contain any event that would have triggered an email to be sent to the public body, so can be used as an alternative, equivalent way to stay up-to-date with happenings on WDTK (or the Alaveteli installation of choice). --- spec/controllers/api_controller_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'spec/controllers') diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb index 1f65576b6..39ffae7fc 100644 --- a/spec/controllers/api_controller_spec.rb +++ b/spec/controllers/api_controller_spec.rb @@ -260,4 +260,20 @@ describe ApiController, "when using the API" do # assigns them and changing assignment to an equality # check, which does not really test anything at all. end + + it "should show a feed of new request events" do + get :body_request_events, + :id => public_bodies(:geraldine_public_body).id, + :k => public_bodies(:geraldine_public_body).api_key, + :feed_type => "atom" + + response.should be_success + response.should render_template("api/request_events.atom") + assigns[:events].size.should > 0 + assigns[:events].each do |event| + event.info_request.public_body.should == public_bodies(:geraldine_public_body) + event.outgoing_message.should_not be_nil + event.event_type.should satisfy {|x| ['sent', 'followup_sent', 'resent', 'followup_resent'].include?(x)} + end + end end -- cgit v1.2.3 From d314c21449823f62afdb708b27ad327443162d8c Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Wed, 4 Jul 2012 16:11:08 +0100 Subject: JSON new events feed --- spec/controllers/api_controller_spec.rb | 40 ++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb index 39ffae7fc..98751a93a 100644 --- a/spec/controllers/api_controller_spec.rb +++ b/spec/controllers/api_controller_spec.rb @@ -261,7 +261,7 @@ describe ApiController, "when using the API" do # check, which does not really test anything at all. end - it "should show a feed of new request events" do + it "should show an Atom feed of new request events" do get :body_request_events, :id => public_bodies(:geraldine_public_body).id, :k => public_bodies(:geraldine_public_body).api_key, @@ -276,4 +276,42 @@ describe ApiController, "when using the API" do event.event_type.should satisfy {|x| ['sent', 'followup_sent', 'resent', 'followup_resent'].include?(x)} end end + + it "should show a JSON feed of new request events" do + get :body_request_events, + :id => public_bodies(:geraldine_public_body).id, + :k => public_bodies(:geraldine_public_body).api_key, + :feed_type => "json" + + response.should be_success + assigns[:events].size.should > 0 + assigns[:events].each do |event| + event.info_request.public_body.should == public_bodies(:geraldine_public_body) + event.outgoing_message.should_not be_nil + event.event_type.should satisfy {|x| ['sent', 'followup_sent', 'resent', 'followup_resent'].include?(x)} + end + + assigns[:event_data].size.should == assigns[:events].size + assigns[:event_data].each do |event_record| + event_record[:event_type].should satisfy {|x| ['sent', 'followup_sent', 'resent', 'followup_resent'].include?(x)} + end + end + + it "should honour the since_event_id parameter" do + get :body_request_events, + :id => public_bodies(:geraldine_public_body).id, + :k => public_bodies(:geraldine_public_body).api_key, + :feed_type => "json" + response.should be_success + first_event = assigns[:event_data][0] + second_event_id = assigns[:event_data][1][:event_id] + + get :body_request_events, + :id => public_bodies(:geraldine_public_body).id, + :k => public_bodies(:geraldine_public_body).api_key, + :feed_type => "json", + :since_event_id => second_event_id + response.should be_success + assigns[:event_data].should == [first_event] + end end -- cgit v1.2.3 From 8365808466eb5beb5a0ac64a4b68db3fef39cd43 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Wed, 1 Aug 2012 15:21:31 +0100 Subject: Add before and after methods to isolate any effect these tests have on locale. --- spec/controllers/services_controller_spec.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 2be382258..a701ae247 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -2,8 +2,15 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe ServicesController, "when using web services" do + integrate_views - + + # store and restore the locale in the context of the test suite to isolate + # changes made in these tests + before do + @old_locale = FastGettext.locale() + end + it "should show no alaveteli message when in the deployed country" do config = MySociety::Config.load_default() config['ISO_COUNTRY_CODE'] = "DE" @@ -29,5 +36,8 @@ describe ServicesController, "when using web services" do response.body.should match(/Puede hacer solicitudes de información en España/) end + after do + FastGettext.set_locale(@old_locale) + end -end +end \ No newline at end of file -- cgit v1.2.3 From 19d6e36039318cdb1f9aa9e0c4731b500b3b0aeb Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 20 Aug 2012 16:27:26 +0100 Subject: Rework the temporary storing of a csv file of public body info between a dry run and real load. Use a temp file, not the session for the data. Also fixes #503. --- .../admin_public_body_controller_spec.rb | 116 +++++++++++++++++---- 1 file changed, 98 insertions(+), 18 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 55a6649b2..be33802c5 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -50,7 +50,7 @@ describe AdminPublicBodyController, "when administering public bodies" do response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id => id) PublicBody.count.should == n end - + it "destroys a public body" do n = PublicBody.count post :destroy, { :id => public_bodies(:forlorn_public_body).id } @@ -70,6 +70,86 @@ describe AdminPublicBodyController, "when administering public bodies" do response.should redirect_to(:action=>'list') PublicBody.find_by_tag("department").count.should == n end + + describe 'import_csv' do + + describe 'when handling a GET request' do + + it 'should get the page successfully' do + get :import_csv + response.should be_success + end + + end + + describe 'when handling a POST request' do + + before do + PublicBody.stub!(:import_csv).and_return([[],[]]) + @file_object = mock("a file upload", :read => 'some contents', + :original_filename => 'contents.txt') + end + + it 'should handle a nil csv file param' do + post :import_csv, { :commit => 'Dry run' } + response.should be_success + end + + describe 'if there is a csv file param' do + + it 'should try to get the contents and original name of a csv file param' do + @file_object.should_receive(:read).and_return('some contents') + post :import_csv, { :csv_file => @file_object, + :commit => 'Dry run'} + end + + it 'should assign the original filename to the view' do + post :import_csv, { :csv_file => @file_object, + :commit => 'Dry run'} + assigns[:original_csv_file].should == 'contents.txt' + end + + end + + describe 'if there is no csv file param, but there are temporary_csv_file and + original_csv_file params' do + + it 'should try and get the file contents from a temporary file whose name + is passed as a param' do + @controller.should_receive(:retrieve_csv_data).with('csv_upload-2046-12-31-394') + post :import_csv, { :temporary_csv_file => 'csv_upload-2046-12-31-394', + :original_csv_file => 'original_contents.txt', + :commit => 'Dry run'} + end + + it 'should raise an error on an invalid temp file name' do + params = { :temporary_csv_file => 'bad_name', + :original_csv_file => 'original_contents.txt', + :commit => 'Dry run'} + expected_error = "Invalid filename in upload_csv: bad_name" + lambda{ post :import_csv, params }.should raise_error(expected_error) + end + + it 'should raise an error if the temp file does not exist' do + temp_name = "csv_upload-20461231-394" + params = { :temporary_csv_file => temp_name, + :original_csv_file => 'original_contents.txt', + :commit => 'Dry run'} + expected_error = "Missing file in upload_csv: csv_upload-20461231-394" + lambda{ post :import_csv, params }.should raise_error(expected_error) + end + + it 'should assign the temporary filename to the view' do + post :import_csv, { :csv_file => @file_object, + :commit => 'Dry run'} + temporary_filename = assigns[:temporary_csv_file] + temporary_filename.should match(/csv_upload-#{Time.now.strftime("%Y%m%d")}-\d{1,5}/) + end + + end + + end + end end describe AdminPublicBodyController, "when administering public bodies and paying attention to authentication" do @@ -79,7 +159,7 @@ describe AdminPublicBodyController, "when administering public bodies and paying before do config = MySociety::Config.load_default() config['SKIP_ADMIN_AUTH'] = false - basic_auth_login @request + basic_auth_login @request end after do config = MySociety::Config.load_default() @@ -106,7 +186,7 @@ describe AdminPublicBodyController, "when administering public bodies and paying PublicBody.count.should == n - 1 session[:using_admin].should == 1 end - + it "doesn't let people with bad credentials log in" do config = MySociety::Config.load_default() config['SKIP_ADMIN_AUTH'] = false @@ -159,7 +239,7 @@ end describe AdminPublicBodyController, "when administering public bodies with i18n" do integrate_views - + it "shows the index page" do get :index end @@ -175,7 +255,7 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" it "edits a public body" do get :edit, {:id => 3, :locale => :en} - + # When editing a body, the controller returns all available translations assigns[:public_body].translation("es").name.should == 'El Department for Humpadinking' assigns[:public_body].name.should == 'Department for Humpadinking' @@ -186,20 +266,20 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" PublicBody.with_locale(:es) do pb = PublicBody.find(id=3) pb.name.should == "El Department for Humpadinking" - post :update, { - :id => 3, - :public_body => { - :name => "Department for Humpadinking", - :short_name => "", - :tag_string => "some tags", - :request_email => 'edited@localhost', + post :update, { + :id => 3, + :public_body => { + :name => "Department for Humpadinking", + :short_name => "", + :tag_string => "some tags", + :request_email => 'edited@localhost', :last_edit_comment => 'From test code', :translated_versions => { 3 => {:locale => "es", :name => "Renamed",:short_name => "", :request_email => 'edited@localhost'} } } } - response.flash[:notice].should include('successful') + response.flash[:notice].should include('successful') end pb = PublicBody.find(public_bodies(:humpadink_public_body).id) @@ -221,7 +301,7 @@ end describe AdminPublicBodyController, "when creating public bodies with i18n" do integrate_views - + before do @old_filters = ActionController::Routing::Routes.filters ActionController::Routing::Routes.filters = RoutingFilter::Chain.new @@ -242,14 +322,14 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do it "creates a new public body with multiple locales" do n = PublicBody.count - post :create, { - :public_body => { + post :create, { + :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code', :translated_versions => [{ :locale => "es", :name => "Mi Nuevo Quango", :short_name => "", :request_email => 'newquango@localhost' }] } } PublicBody.count.should == n + 1 - + body = PublicBody.find_by_name("New Quango") body.translations.map {|t| t.locale.to_s}.sort.should == ["en", "es"] PublicBody.with_locale(:en) do @@ -262,7 +342,7 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do body.url_name.should == "mi_nuevo_quango" body.first_letter.should == "M" end - + response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id=>body.id) end end -- cgit v1.2.3