aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/public_body.rb3
-rw-r--r--spec/fixtures/files/fake-authority-type-with-field-names.csv8
-rw-r--r--spec/models/public_body_spec.rb32
3 files changed, 31 insertions, 12 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 9e85fb44b..8c34f9e27 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -395,7 +395,7 @@ class PublicBody < ActiveRecord::Base
next
end
- field_list = ['name', 'short_name', 'request_email', 'notes', 'publication_scheme', 'home_page']
+ field_list = ['name', 'short_name', 'request_email', 'notes', 'publication_scheme', 'home_page', 'tag_string']
if public_body = bodies_by_name[name] # Existing public body
available_locales.each do |locale|
@@ -435,7 +435,6 @@ class PublicBody < ActiveRecord::Base
unless changed.empty?
notes.push "line #{line.to_s}: creating new authority '#{name}' (locale: #{locale}):\n\t#{changed.to_json}"
public_body.publication_scheme = public_body.publication_scheme || ""
- public_body.tag_string = tag
public_body.last_edit_editor = editor
public_body.last_edit_comment = 'Created from spreadsheet'
public_body.save!
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 9e82308fb..a4247dced 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,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
+#id,request_email,name,name.es,tag_string,home_page
+,north_west_foi@localhost,North West Fake Authority,Autoridad del Nordeste,,http://northwest.org
+,scottish_foi@localhost,Scottish Fake Authority,Autoridad Escocesa,scottish,http://scottish.org
+,ni_foi@localhost,Fake Authority of Northern Ireland,Autoridad Irlandesa,fake aTag
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 67f1cc069..9833179a7 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -290,12 +290,32 @@ describe PublicBody, " when loading CSV files" do
notes.size.should == 3
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\"\}"
+ "line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"tag_string\":\"scottish\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\"\}",
+ "line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"tag_string\":\"fake aTag\",\"request_email\":\"ni_foi@localhost\"\}"
]
PublicBody.count.should == original_count
end
+
+ it "should import tags successfully when no the import tag is not set" do
+ csv_contents = load_file_fixture("fake-authority-type-with-field-names.csv")
+ errors, notes = PublicBody.import_csv(csv_contents, '', false, 'someadmin') # false means real run
+
+ PublicBody.find_by_name('North West Fake Authority').tag_array_for_search.should == []
+ PublicBody.find_by_name('Scottish Fake Authority').tag_array_for_search.should == ['scottish']
+ PublicBody.find_by_name('Fake Authority of Northern Ireland').tag_array_for_search.should == ['fake', 'aTag']
+ end
+
+ it "should import tags successfully when no the import tag is set" do
+ csv_contents = load_file_fixture("fake-authority-type-with-field-names.csv")
+ errors, notes = PublicBody.import_csv(csv_contents, 'fake', false, 'someadmin') # false means real run
+ # XXX: when a 'tag' is set for the import, do we want to add it to the tag string for all bodies?
+ # The tests below assume we don't
+
+ PublicBody.find_by_name('North West Fake Authority').tag_array_for_search.should == []
+ PublicBody.find_by_name('Scottish Fake Authority').tag_array_for_search.should == ['scottish']
+ PublicBody.find_by_name('Fake Authority of Northern Ireland').tag_array_for_search.should == ['fake', 'aTag']
+ end
it "should create bodies with names in multiple locales" do
original_count = PublicBody.count
@@ -307,9 +327,9 @@ describe PublicBody, " when loading CSV files" do
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 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: en):\n\t{\"tag_string\":\"scottish\",\"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: en):\n\t{\"tag_string\":\"fake aTag\",\"request_email\":\"ni_foi@localhost\"}",
"line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: es):\n\t{\"name\":\"Autoridad Irlandesa\"}"
]
@@ -331,8 +351,8 @@ describe PublicBody, " when loading CSV files" do
notes.size.should == 3
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\"}"
+ "line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t{\"tag_string\":\"scottish\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\"}",
+ "line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t{\"tag_string\":\"fake aTag\",\"request_email\":\"ni_foi@localhost\"}"
]
PublicBody.count.should == original_count