diff options
-rw-r--r-- | app/models/info_request_batch.rb | 7 | ||||
-rw-r--r-- | app/models/public_body.rb | 15 | ||||
-rw-r--r-- | app/models/request_classification.rb | 4 | ||||
-rw-r--r-- | app/models/spam_address.rb | 10 | ||||
-rw-r--r-- | app/models/user.rb | 37 | ||||
-rw-r--r-- | app/views/admin_public_body/import_csv.html.erb | 38 | ||||
-rw-r--r-- | db/migrate/20140408145616_add_default_short_name_to_public_bodies.rb | 11 | ||||
-rw-r--r-- | spec/fixtures/info_requests.yml | 1 | ||||
-rw-r--r-- | spec/fixtures/public_bodies.yml | 2 | ||||
-rw-r--r-- | spec/fixtures/users.yml | 37 | ||||
-rw-r--r-- | spec/models/info_request_batch_spec.rb | 13 | ||||
-rw-r--r-- | spec/models/info_request_spec.rb | 1 | ||||
-rw-r--r-- | spec/models/public_body_spec.rb | 21 | ||||
-rw-r--r-- | spec/models/spam_address_spec.rb | 10 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 37 |
15 files changed, 166 insertions, 78 deletions
diff --git a/app/models/info_request_batch.rb b/app/models/info_request_batch.rb index 498ab4951..d7c5eb9af 100644 --- a/app/models/info_request_batch.rb +++ b/app/models/info_request_batch.rb @@ -1,13 +1,14 @@ # == Schema Information -# Schema version: 20131024114346 # # Table name: info_request_batches # # id :integer not null, primary key # title :text not null # user_id :integer not null -# created_at :datetime -# updated_at :datetime +# created_at :datetime not null +# updated_at :datetime not null +# body :text +# sent_at :datetime # class InfoRequestBatch < ActiveRecord::Base diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 7b1ded820..9cb344f14 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -6,7 +6,7 @@ # # id :integer not null, primary key # name :text not null -# short_name :text not null +# short_name :text default(""), not null # request_email :text not null # version :integer not null # last_edit_editor :string(255) not null @@ -37,7 +37,8 @@ class PublicBody < ActiveRecord::Base validates_presence_of :name, :message => N_("Name can't be blank") validates_presence_of :url_name, :message => N_("URL name can't be blank") - validates_uniqueness_of :short_name, :message => N_("Short name is already taken"), :if => Proc.new { |pb| pb.short_name != "" } + validates_uniqueness_of :short_name, :message => N_("Short name is already taken"), :allow_blank => true + validates_uniqueness_of :url_name, :message => N_("URL name is already taken") validates_uniqueness_of :name, :message => N_("Name is already taken") validate :request_email_if_requestable @@ -505,7 +506,15 @@ class PublicBody < ActiveRecord::Base public_body.publication_scheme = public_body.publication_scheme || "" public_body.last_edit_editor = editor public_body.last_edit_comment = 'Created from spreadsheet' - public_body.save! + + begin + public_body.save! + rescue ActiveRecord::RecordInvalid + public_body.errors.full_messages.each do |msg| + errors.push "error: line #{ line }: #{ msg } for authority '#{ name }'" + end + next + end end end end diff --git a/app/models/request_classification.rb b/app/models/request_classification.rb index 6873d468b..478a543d3 100644 --- a/app/models/request_classification.rb +++ b/app/models/request_classification.rb @@ -5,8 +5,8 @@ # id :integer not null, primary key # user_id :integer # info_request_event_id :integer -# created_at :datetime -# updated_at :datetime +# created_at :datetime not null +# updated_at :datetime not null # class RequestClassification < ActiveRecord::Base diff --git a/app/models/spam_address.rb b/app/models/spam_address.rb index 15c9d1ab8..b3ad329d8 100644 --- a/app/models/spam_address.rb +++ b/app/models/spam_address.rb @@ -1,3 +1,13 @@ +# == Schema Information +# +# Table name: spam_addresses +# +# id :integer not null, primary key +# email :string(255) not null +# created_at :datetime not null +# updated_at :datetime not null +# + class SpamAddress < ActiveRecord::Base attr_accessible :email diff --git a/app/models/user.rb b/app/models/user.rb index e63ce8129..d75622b37 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,26 +1,25 @@ # == Schema Information -# Schema version: 20131024114346 # # Table name: users # -# id :integer not null, primary key -# email :string(255) not null -# name :string(255) not null -# hashed_password :string(255) not null -# salt :string(255) not null -# created_at :datetime not null -# updated_at :datetime not null -# email_confirmed :boolean default(FALSE), not null -# url_name :text not null -# last_daily_track_email :datetime default(2000-01-01 00:00:00 UTC) -# admin_level :string(255) default("none"), not null -# ban_text :text default(""), not null -# about_me :text default(""), not null -# locale :string(255) -# email_bounced_at :datetime -# email_bounce_message :text default(""), not null -# no_limit :boolean default(FALSE), not null -# receive_email_alerts :boolean default(TRUE), not null +# id :integer not null, primary key +# email :string(255) not null +# name :string(255) not null +# hashed_password :string(255) not null +# salt :string(255) not null +# created_at :datetime not null +# updated_at :datetime not null +# email_confirmed :boolean default(FALSE), not null +# url_name :text not null +# last_daily_track_email :datetime default(Sat Jan 01 00:00:00 UTC 2000) +# admin_level :string(255) default("none"), not null +# ban_text :text default(""), not null +# about_me :text default(""), not null +# locale :string(255) +# email_bounced_at :datetime +# email_bounce_message :text default(""), not null +# no_limit :boolean default(FALSE), not null +# receive_email_alerts :boolean default(TRUE), not null # can_make_batch_requests :boolean default(FALSE), not null # diff --git a/app/views/admin_public_body/import_csv.html.erb b/app/views/admin_public_body/import_csv.html.erb index 18341ecf1..d15ef1791 100644 --- a/app/views/admin_public_body/import_csv.html.erb +++ b/app/views/admin_public_body/import_csv.html.erb @@ -36,23 +36,35 @@ %> </p> - <p><strong>CSV file format:</strong>The first row should be a list - of fields, starting with '#'. The fields 'name' and - 'request_email' are required; additionally, translated values are + <p><strong>CSV file format:</strong> The first row should be a list + of fields, starting with <code>#</code>. The fields <code>name</code> and + <code>request_email</code> are required; additionally, translated values are supported by adding the locale name to the field name, - e.g. 'name.es', 'name.de'... Example: + e.g. <code>name.es</code>, <code>name.de</code>…<br /> + <strong>Example:</strong> </p> - <blockquote> - <p> - #id,name,request_email,name.es,tag_string<br/> - 1,An Authority,a@example.com,Un organismo,a_tag another_tag<br/> - 2,Another One,another@example.com,Otro organismo,a_tag<br/> - <p> - </blockquote> + <pre> +#name,request_email,name.es,tag_string +An Authority,a@example.com,Un organismo,a_tag another_tag +Another One,another@example.com,Otro organismo,a_tag + </pre> - <p>Supported fields: name (i18n), short_name (i18n), request_email (i18n), notes (i18n), - publication_scheme (i18n), disclosure_log (i18n), home_page, tag_string (tags separated by spaces).</p> + <p><strong>Supported fields:</strong> + <ul> + <li> + <code>name</code> (i18n) + <strong>Existing records cannot be renamed</strong> + </li> + <li><code>short_name</code> (i18n)</li> + <li><code>request_email</code> (i18n)</li> + <li><code>notes</code> (i18n)</li> + <li><code>publication_scheme</code> (i18n)</li> + <li><code>disclosure_log</code> (i18n)</li> + <li><code>home_page</code></li> + <li><code>tag_string</code> (tags separated by spaces)</li> + </ul> + </p> <p><strong>Note:</strong> Choose <strong>dry run</strong> to test, without actually altering the database. Choose <strong>upload</strong> to actually diff --git a/db/migrate/20140408145616_add_default_short_name_to_public_bodies.rb b/db/migrate/20140408145616_add_default_short_name_to_public_bodies.rb new file mode 100644 index 000000000..5fb239ebd --- /dev/null +++ b/db/migrate/20140408145616_add_default_short_name_to_public_bodies.rb @@ -0,0 +1,11 @@ +class AddDefaultShortNameToPublicBodies < ActiveRecord::Migration + + def up + change_column_default(:public_bodies, :short_name, '') + end + + def down + change_column_default(:public_bodies, :short_name, nil) + end + +end diff --git a/spec/fixtures/info_requests.yml b/spec/fixtures/info_requests.yml index d64807a49..d523236b5 100644 --- a/spec/fixtures/info_requests.yml +++ b/spec/fixtures/info_requests.yml @@ -20,6 +20,7 @@ # external_url :string(255) # attention_requested :boolean default(FALSE) # comments_allowed :boolean default(TRUE), not null +# info_request_batch_id :integer # fancy_dog_request: diff --git a/spec/fixtures/public_bodies.yml b/spec/fixtures/public_bodies.yml index d0eb572b3..16c12d9e2 100644 --- a/spec/fixtures/public_bodies.yml +++ b/spec/fixtures/public_bodies.yml @@ -4,7 +4,7 @@ # # id :integer not null, primary key # name :text not null -# short_name :text not null +# short_name :text default(""), not null # request_email :text not null # version :integer not null # last_edit_editor :string(255) not null diff --git a/spec/fixtures/users.yml b/spec/fixtures/users.yml index 9eb91ee9c..fb0414ff2 100644 --- a/spec/fixtures/users.yml +++ b/spec/fixtures/users.yml @@ -2,24 +2,25 @@ # # Table name: users # -# id :integer not null, primary key -# email :string(255) not null -# name :string(255) not null -# hashed_password :string(255) not null -# salt :string(255) not null -# created_at :datetime not null -# updated_at :datetime not null -# email_confirmed :boolean default(FALSE), not null -# url_name :text not null -# last_daily_track_email :datetime default(2000-01-01 00:00:00 UTC) -# admin_level :string(255) default("none"), not null -# ban_text :text default(""), not null -# about_me :text default(""), not null -# locale :string(255) -# email_bounced_at :datetime -# email_bounce_message :text default(""), not null -# no_limit :boolean default(FALSE), not null -# receive_email_alerts :boolean default(TRUE), not null +# id :integer not null, primary key +# email :string(255) not null +# name :string(255) not null +# hashed_password :string(255) not null +# salt :string(255) not null +# created_at :datetime not null +# updated_at :datetime not null +# email_confirmed :boolean default(FALSE), not null +# url_name :text not null +# last_daily_track_email :datetime default(Sat Jan 01 00:00:00 UTC 2000) +# admin_level :string(255) default("none"), not null +# ban_text :text default(""), not null +# about_me :text default(""), not null +# locale :string(255) +# email_bounced_at :datetime +# email_bounce_message :text default(""), not null +# no_limit :boolean default(FALSE), not null +# receive_email_alerts :boolean default(TRUE), not null +# can_make_batch_requests :boolean default(FALSE), not null # bob_smith_user: diff --git a/spec/models/info_request_batch_spec.rb b/spec/models/info_request_batch_spec.rb index 53158ebe2..2881e7745 100644 --- a/spec/models/info_request_batch_spec.rb +++ b/spec/models/info_request_batch_spec.rb @@ -1,3 +1,16 @@ +# == Schema Information +# +# Table name: info_request_batches +# +# id :integer not null, primary key +# title :text not null +# user_id :integer not null +# created_at :datetime not null +# updated_at :datetime not null +# body :text +# sent_at :datetime +# + require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe InfoRequestBatch, "when validating" do diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index 9766f928f..12499f50a 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -21,6 +21,7 @@ # external_url :string(255) # attention_requested :boolean default(FALSE) # comments_allowed :boolean default(TRUE), not null +# info_request_batch_id :integer # require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index dc09bdfa6..38e31783d 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -5,7 +5,7 @@ # # id :integer not null, primary key # name :text not null -# short_name :text not null +# short_name :text default(""), not null # request_email :text not null # version :integer not null # last_edit_editor :string(255) not null @@ -205,6 +205,12 @@ describe PublicBody, " when saving" do pb.first_letter.should == 'Å' end + it "should not save if the url_name is already taken" do + existing = FactoryGirl.create(:public_body) + pb = PublicBody.new(existing.attributes) + pb.should have(1).errors_on(:url_name) + end + it "should save the name when renaming an existing public body" do public_body = public_bodies(:geraldine_public_body) public_body.name = "Mark's Public Body" @@ -527,6 +533,19 @@ describe PublicBody, " when loading CSV files" do PublicBody.count.should == original_count + 3 end + it "should handle active record validation errors" do + csv = <<-CSV +#name,request_email,short_name +Foobar,a@example.com,foobar +Foobar Test,b@example.com,foobar +CSV + + csv_contents = normalize_string_to_utf8(csv) + errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', true, 'someadmin') # true means dry run + + errors.should include("error: line 3: Url name URL name is already taken for authority 'Foobar Test'") + end + end describe PublicBody do diff --git a/spec/models/spam_address_spec.rb b/spec/models/spam_address_spec.rb index 79a1afd11..f28440121 100644 --- a/spec/models/spam_address_spec.rb +++ b/spec/models/spam_address_spec.rb @@ -1,3 +1,13 @@ +# == Schema Information +# +# Table name: spam_addresses +# +# id :integer not null, primary key +# email :string(255) not null +# created_at :datetime not null +# updated_at :datetime not null +# + require 'spec_helper' describe SpamAddress do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index b6f48dad3..c54043092 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -2,24 +2,25 @@ # # Table name: users # -# id :integer not null, primary key -# email :string(255) not null -# name :string(255) not null -# hashed_password :string(255) not null -# salt :string(255) not null -# created_at :datetime not null -# updated_at :datetime not null -# email_confirmed :boolean default(FALSE), not null -# url_name :text not null -# last_daily_track_email :datetime default(2000-01-01 00:00:00 UTC) -# admin_level :string(255) default("none"), not null -# ban_text :text default(""), not null -# about_me :text default(""), not null -# locale :string(255) -# email_bounced_at :datetime -# email_bounce_message :text default(""), not null -# no_limit :boolean default(FALSE), not null -# receive_email_alerts :boolean default(TRUE), not null +# id :integer not null, primary key +# email :string(255) not null +# name :string(255) not null +# hashed_password :string(255) not null +# salt :string(255) not null +# created_at :datetime not null +# updated_at :datetime not null +# email_confirmed :boolean default(FALSE), not null +# url_name :text not null +# last_daily_track_email :datetime default(Sat Jan 01 00:00:00 UTC 2000) +# admin_level :string(255) default("none"), not null +# ban_text :text default(""), not null +# about_me :text default(""), not null +# locale :string(255) +# email_bounced_at :datetime +# email_bounce_message :text default(""), not null +# no_limit :boolean default(FALSE), not null +# receive_email_alerts :boolean default(TRUE), not null +# can_make_batch_requests :boolean default(FALSE), not null # require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') |