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/fixtures/files/fake-authority-type-with-field-names.csv6
-rw-r--r--spec/models/public_body_spec.rb49
3 files changed, 104 insertions, 41 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/fixtures/files/fake-authority-type-with-field-names.csv b/spec/fixtures/files/fake-authority-type-with-field-names.csv
index 93ce00a25..9e82308fb 100644
--- a/spec/fixtures/files/fake-authority-type-with-field-names.csv
+++ b/spec/fixtures/files/fake-authority-type-with-field-names.csv
@@ -1,4 +1,4 @@
-#id,email,name,name.es
-,north_west_foi@localhost,North West Fake Authority,Autoridad del Nordeste
-,scottish_foi@localhost,Scottish Fake Authority,Autoridad Escocesa
+#id,request_email,name,name.es,home_page
+,north_west_foi@localhost,North West Fake Authority,Autoridad del Nordeste,http://northwest.org
+,scottish_foi@localhost,Scottish Fake Authority,Autoridad Escocesa,http://scottish.org
,ni_foi@localhost,Fake Authority of Northern Ireland,Autoridad Irlandesa
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 3d00d37fb..3902e3662 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -234,9 +234,11 @@ describe PublicBody, " when loading CSV files" do
errors, notes = PublicBody.import_csv(csv_contents, 'fake', true, 'someadmin') # true means dry run
errors.should == []
notes.size.should == 3
- notes.should == ["line 1: new authority 'North West Fake Authority' with email north_west_foi@localhost",
- "line 2: new authority 'Scottish Fake Authority' with email scottish_foi@localhost",
- "line 3: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost"]
+ notes.should == [
+ "line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"request_email\":\"north_west_foi@localhost\"\}",
+ "line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"request_email\":\"scottish_foi@localhost\"\}",
+ "line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"request_email\":\"ni_foi@localhost\"\}"
+ ]
PublicBody.count.should == original_count
end
@@ -248,9 +250,11 @@ describe PublicBody, " when loading CSV files" do
errors, notes = PublicBody.import_csv(csv_contents, 'fake', false, 'someadmin') # false means real run
errors.should == []
notes.size.should == 3
- notes.should == ["line 1: new authority 'North West Fake Authority' with email north_west_foi@localhost",
- "line 2: new authority 'Scottish Fake Authority' with email scottish_foi@localhost",
- "line 3: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost"]
+ notes.should == [
+ "line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"request_email\":\"north_west_foi@localhost\"\}",
+ "line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"request_email\":\"scottish_foi@localhost\"\}",
+ "line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"request_email\":\"ni_foi@localhost\"\}"
+ ]
PublicBody.count.should == original_count + 3
end
@@ -262,9 +266,11 @@ describe PublicBody, " when loading CSV files" do
errors, notes = PublicBody.import_csv(csv_contents, 'fake', true, 'someadmin') # true means dry run
errors.should == []
notes.size.should == 3
- notes.should == ["line 2: new authority 'North West Fake Authority' with email north_west_foi@localhost",
- "line 3: new authority 'Scottish Fake Authority' with email scottish_foi@localhost",
- "line 4: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost"]
+ notes.should == [
+ "line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"\}",
+ "line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\"\}",
+ "line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"request_email\":\"ni_foi@localhost\"\}"
+ ]
PublicBody.count.should == original_count
end
@@ -273,16 +279,17 @@ describe PublicBody, " when loading CSV files" do
original_count = PublicBody.count
csv_contents = load_file_fixture("fake-authority-type-with-field-names.csv")
- errors, notes = PublicBody.import_csv(csv_contents, 'fake', false, 'someadmin', ['es'])
+ errors, notes = PublicBody.import_csv(csv_contents, 'fake', false, 'someadmin', [:en, :es])
errors.should == []
notes.size.should == 6
notes.should == [
- "line 2: new authority 'North West Fake Authority' with email north_west_foi@localhost",
- "line 2: (aka 'Autoridad del Nordeste' in locale es)",
- "line 3: new authority 'Scottish Fake Authority' with email scottish_foi@localhost",
- "line 3: (aka 'Autoridad Escocesa' in locale es)",
- "line 4: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost",
- "line 4: (aka 'Autoridad Irlandesa' in locale es)"]
+ "line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t{\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"}",
+ "line 2: creating new authority 'North West Fake Authority' (locale: es):\n\t{\"name\":\"Autoridad del Nordeste\"}",
+ "line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t{\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\"}",
+ "line 3: creating new authority 'Scottish Fake Authority' (locale: es):\n\t{\"name\":\"Autoridad Escocesa\"}",
+ "line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t{\"request_email\":\"ni_foi@localhost\"}",
+ "line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: es):\n\t{\"name\":\"Autoridad Irlandesa\"}"
+ ]
PublicBody.count.should == original_count + 3
@@ -297,12 +304,14 @@ describe PublicBody, " when loading CSV files" do
original_count = PublicBody.count
csv_contents = load_file_fixture("fake-authority-type-with-field-names.csv")
- errors, notes = PublicBody.import_csv(csv_contents, 'fake', true, 'someadmin', ['xx']) # true means dry run
+ errors, notes = PublicBody.import_csv(csv_contents, 'fake', true, 'someadmin', [:en, :xx]) # true means dry run
errors.should == []
notes.size.should == 3
- notes.should == ["line 2: new authority 'North West Fake Authority' with email north_west_foi@localhost",
- "line 3: new authority 'Scottish Fake Authority' with email scottish_foi@localhost",
- "line 4: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost"]
+ notes.should == [
+ "line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t{\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"}",
+ "line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t{\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\"}",
+ "line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t{\"request_email\":\"ni_foi@localhost\"}"
+ ]
PublicBody.count.should == original_count
end