aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin_public_body_controller_spec.rb90
-rw-r--r--spec/controllers/general_controller_spec.rb1
-rw-r--r--spec/controllers/request_controller_spec.rb9
-rw-r--r--spec/integration/search_request_spec.rb9
-rw-r--r--spec/lib/i18n_interpolation.rb15
-rw-r--r--spec/models/incoming_message_spec.rb14
-rw-r--r--spec/models/outgoing_message_spec.rb7
-rw-r--r--spec/models/public_body_spec.rb14
8 files changed, 140 insertions, 19 deletions
diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb
index 357564211..53db4f412 100644
--- a/spec/controllers/admin_public_body_controller_spec.rb
+++ b/spec/controllers/admin_public_body_controller_spec.rb
@@ -109,28 +109,34 @@ describe AdminPublicBodyController, "when administering public bodies with i18n"
get :show, {:id => 2, :locale => "es" }
end
- it "creates a new public body" do
- I18n.default_locale = :es
- PublicBody.count.should == 2
- post :create, { :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' } }
- PublicBody.count.should == 3
- I18n.default_locale = :en
- end
-
it "edits a public body" do
- I18n.default_locale = :es
- get :edit, {:id => 3, :locale => :es}
- response.body.should include('Baguette')
- I18n.default_locale = :en
+ 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'
+ response.should render_template('edit')
end
it "saves edits to a public body" do
- I18n.default_locale = :es
- pb = PublicBody.find(id=3)
- pb.name.should == "El Department for Humpadinking"
- post :update, { :id => 3, :public_body => { :name => "Renamed", :short_name => "", :tag_string => "some tags", :request_email => 'edited@localhost', :last_edit_comment => 'From test code' }}
- response.flash[:notice].should include('successful')
- I18n.default_locale = :en
+ 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',
+ :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')
+ end
pb = PublicBody.find(public_bodies(:humpadink_public_body).id)
PublicBody.with_locale(:es) do
@@ -148,3 +154,51 @@ describe AdminPublicBodyController, "when administering public bodies with i18n"
end
end
+
+describe AdminPublicBodyController, "when creating public bodies with i18n" do
+ integrate_views
+ fixtures :public_bodies, :public_body_translations
+
+ before do
+ username = MySociety::Config.get('ADMIN_USERNAME', '')
+ password = MySociety::Config.get('ADMIN_PASSWORD', '')
+ basic_auth_login @request
+
+ ActionController::Routing::Routes.filters.clear # don't auto-insert locale, complicates assertions
+ end
+
+ it "creates a new public body in one locale" do
+ PublicBody.count.should == 2
+ post :create, { :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' } }
+ PublicBody.count.should == 3
+
+ body = PublicBody.find_by_name("New Quango")
+ response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id=>body.id)
+ end
+
+ it "creates a new public body with multiple locales" do
+ PublicBody.count.should == 2
+ 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 == 3
+
+ body = PublicBody.find_by_name("New Quango")
+ body.translations.map {|t| t.locale.to_s}.sort.should == ["en", "es"]
+ PublicBody.with_locale(:en) do
+ body.name.should == "New Quango"
+ body.url_name.should == "new_quango"
+ body.first_letter.should == "N"
+ end
+ PublicBody.with_locale(:es) do
+ body.name.should == "Mi Nuevo Quango"
+ 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
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index 76e1bb5e6..3640a8148 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -62,7 +62,6 @@ describe GeneralController, "when searching" do
response.should be_success
end
-
it "should redirect from search query URL to pretty URL" do
post :search_redirect, :query => "mouse" # query hidden in POST parameters
response.should redirect_to(:action => 'search', :combined => "mouse") # URL /search/:query
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 500a30bd0..caca03d58 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -308,6 +308,13 @@ describe RequestController, "when creating a new request" do
response.should redirect_to(:controller => 'general', :action => 'frontpage')
end
+ it "should redirect 'bad request' page when a body has no email address" do
+ @body.request_email = ""
+ @body.save!
+ get :new, :public_body_id => @body.id
+ response.should render_template('new_bad_contact')
+ end
+
it "should accept a public body parameter" do
get :new, :public_body_id => @body.id
assigns[:info_request].public_body.should == @body
@@ -779,6 +786,8 @@ describe RequestController, "when classifying an information request" do
@dog_request.stub!(:date_very_overdue_after).and_return(Time.now.to_date-1)
expect_redirect('waiting_response', unhappy_url)
flash[:notice].should match(/is long overdue/)
+ flash[:notice].should match(/by more than 40 working days/)
+ flash[:notice].should match(/within 20 working days/)
end
it 'should redirect to the "request url" when status is updated to "not held"' do
diff --git a/spec/integration/search_request_spec.rb b/spec/integration/search_request_spec.rb
new file mode 100644
index 000000000..9398519b7
--- /dev/null
+++ b/spec/integration/search_request_spec.rb
@@ -0,0 +1,9 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe "When searching" do
+ it "should not strip quotes from quoted query" do
+ request_via_redirect("post", "/search", :query => '"mouse stilton"')
+ response.body.should include(""mouse stilton"")
+ end
+end
+
diff --git a/spec/lib/i18n_interpolation.rb b/spec/lib/i18n_interpolation.rb
new file mode 100644
index 000000000..8c86413ad
--- /dev/null
+++ b/spec/lib/i18n_interpolation.rb
@@ -0,0 +1,15 @@
+# This is a test of the set_content_type monkey patch in
+# lib/tmail_extensions.rb
+
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe "when using i18n" do
+
+ it "should not complain if we're missing variables from the string" do
+ result = _('Hello', :dip => 'hummus')
+ result.should == 'Hello'
+ result = _('Hello {{dip}}', :dip => 'hummus')
+ result.should == 'Hello hummus'
+ end
+end
+
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index 5fcc534ca..183a258af 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -19,6 +19,13 @@ describe IncomingMessage, " when dealing with incoming mail" do
end
+describe IncomingMessage, "when parsing HTML mail" do
+ it "should display UTF-8 characters in the plain text version correctly" do
+ html = "<html><b>foo</b> është"
+ plain_text = IncomingMessage._get_attachment_text_internal_one_file('text/html', html)
+ plain_text.should match(/është/)
+ end
+end
describe IncomingMessage, "when getting the attachment text" do
@@ -201,6 +208,13 @@ describe IncomingMessage, " when censoring data" do
data.should == "There was a mouse called Jarlsberg, he wished that he was yellow."
end
+ it "should apply hard-coded privacy rules to HTML files" do
+ domain = MySociety::Config.get('DOMAIN')
+ data = "http://#{domain}/c/cheese"
+ @im.html_mask_stuff!(data)
+ data.should == "[WDTK login link]"
+ end
+
it "should apply censor rules to From: addresses" do
mock_mail = mock('Email object')
mock_mail.stub!(:from_name_if_present).and_return("Stilton Mouse")
diff --git a/spec/models/outgoing_message_spec.rb b/spec/models/outgoing_message_spec.rb
index a9ef57b4f..1956c4d73 100644
--- a/spec/models/outgoing_message_spec.rb
+++ b/spec/models/outgoing_message_spec.rb
@@ -1,7 +1,10 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe OutgoingMessage, " when making an outgoing message" do
+ fixtures :outgoing_messages, :info_requests, :incoming_messages, :public_bodies, :public_body_translations
+
before do
+ @om = outgoing_messages(:useless_outgoing_message)
@outgoing_message = OutgoingMessage.new({
:status => 'ready',
:message_type => 'initial_request',
@@ -27,6 +30,10 @@ describe OutgoingMessage, " when making an outgoing message" do
it "should include email addresses in outgoing messages" do
@outgoing_message.body.should include("foo@bar.com")
end
+
+ it "should work out a salutation" do
+ @om.get_salutation.should == "Dear Geraldine Quango,"
+ end
end
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index ec84cbe65..3d00d37fb 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -210,6 +210,20 @@ describe PublicBody, "when searching" do
body.id.should == 3
body.class.to_s.should == 'PublicBody'
end
+
+ it "should cope with same url_name across multiple locales" do
+ PublicBody.with_locale(:es) do
+ # use the unique spanish name to retrieve and edit
+ body = PublicBody.find_by_url_name_with_historic('etgq')
+ body.short_name = 'tgq' # Same as english version
+ body.save!
+
+ # now try to retrieve it
+ body = PublicBody.find_by_url_name_with_historic('tgq')
+ body.id.should == public_bodies(:geraldine_public_body).id
+ body.name.should == "El A Geraldine Quango"
+ end
+ end
end
describe PublicBody, " when loading CSV files" do