From 87f284dcb6c54047948f39cf5ce58444eae73c1e 2012-07-26 17:41:47 From: Jean-Philippe Lang Date: 2012-07-26 17:41:47 Subject: [PATCH] Repository Identifier should be frozen (#11109). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10081 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/repository.rb b/app/models/repository.rb index c81979a..9a6891a 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -20,6 +20,9 @@ class ScmFetchError < Exception; end class Repository < ActiveRecord::Base include Redmine::Ciphering include Redmine::SafeAttributes + + # Maximum length for repository identifiers + IDENTIFIER_MAX_LENGTH = 255 belongs_to :project has_many :changesets, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC" @@ -34,7 +37,7 @@ class Repository < ActiveRecord::Base before_destroy :clear_changesets validates_length_of :password, :maximum => 255, :allow_nil => true - validates_length_of :identifier, :maximum => 255, :allow_blank => true + validates_length_of :identifier, :maximum => IDENTIFIER_MAX_LENGTH, :allow_blank => true validates_presence_of :identifier, :unless => Proc.new { |r| r.is_default? || r.set_as_default? } validates_uniqueness_of :identifier, :scope => :project_id, :allow_blank => true validates_exclusion_of :identifier, :in => %w(show entry raw changes annotate diff show stats graph) @@ -114,6 +117,14 @@ class Repository < ActiveRecord::Base end end + def identifier=(identifier) + super unless identifier_frozen? + end + + def identifier_frozen? + errors[:identifier].blank? && !(new_record? || identifier.blank?) + end + def identifier_param if is_default? nil diff --git a/app/views/repositories/_form.html.erb b/app/views/repositories/_form.html.erb index 91a19ca..1554eb5 100644 --- a/app/views/repositories/_form.html.erb +++ b/app/views/repositories/_form.html.erb @@ -9,7 +9,10 @@

<%= f.check_box :is_default, :label => :field_repository_is_default %>

-

<%= f.text_field :identifier %>

+

<%= f.text_field :identifier, :disabled => @repository.identifier_frozen? %> +<% unless @repository.identifier_frozen? %> + <%= l(:text_length_between, :min => 1, :max => Repository::IDENTIFIER_MAX_LENGTH) %> <%= l(:text_repository_identifier_info).html_safe %> +<% end %>

<% button_disabled = true %> <% if @repository %> diff --git a/config/locales/ar.yml b/config/locales/ar.yml index f0acf6d..095a3d8 100644 --- a/config/locales/ar.yml +++ b/config/locales/ar.yml @@ -1056,3 +1056,4 @@ ar: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/bg.yml b/config/locales/bg.yml index 374c501..79c1d99 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -1054,3 +1054,4 @@ bg: description_date_range_interval: Изберете диапазон чрез задаване на начална и крайна дати description_date_from: Въведете начална дата description_date_to: Въведете крайна дата + text_repository_identifier_info: 'Позволени са малки букви (a-z), цифри, тирета и _.
Промяна след създаването му не е възможна.' diff --git a/config/locales/bs.yml b/config/locales/bs.yml index 87e4d42..32a0041 100644 --- a/config/locales/bs.yml +++ b/config/locales/bs.yml @@ -1070,3 +1070,4 @@ bs: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/ca.yml b/config/locales/ca.yml index 2bdd472..fee68f7 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -1058,3 +1058,4 @@ ca: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/cs.yml b/config/locales/cs.yml index 1c0edf0..b408bf9 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -1059,3 +1059,4 @@ cs: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/da.yml b/config/locales/da.yml index bbee44a..dcbb8c0 100644 --- a/config/locales/da.yml +++ b/config/locales/da.yml @@ -1073,3 +1073,4 @@ da: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/de.yml b/config/locales/de.yml index f3eb9a7..8bb8a4a 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1074,3 +1074,4 @@ de: label_fields_permissions: Fields permissions label_readonly: Nur-Lese-Zugriff label_required: Erforderlich + text_repository_identifier_info: 'Kleinbuchstaben (a-z), Ziffern, Binde- und Unterstriche erlaubt.
Einmal gespeichert, kann die Kennung nicht mehr geändert werden.' diff --git a/config/locales/el.yml b/config/locales/el.yml index d2cb46e..ef9e44c 100644 --- a/config/locales/el.yml +++ b/config/locales/el.yml @@ -1056,3 +1056,4 @@ el: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/en-GB.yml b/config/locales/en-GB.yml index f9d795f..f61fbfc 100644 --- a/config/locales/en-GB.yml +++ b/config/locales/en-GB.yml @@ -1058,3 +1058,4 @@ en-GB: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: 'Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed.' diff --git a/config/locales/en.yml b/config/locales/en.yml index a381713..a6bbfa1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1053,3 +1053,4 @@ en: description_date_range_interval: Choose range by selecting start and end date description_date_from: Enter start date description_date_to: Enter end date + text_repository_identifier_info: 'Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed.' diff --git a/config/locales/es.yml b/config/locales/es.yml index bdb25a9..ceff24a 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -1093,3 +1093,4 @@ es: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/et.yml b/config/locales/et.yml index c233604..b5595ea 100644 --- a/config/locales/et.yml +++ b/config/locales/et.yml @@ -1069,3 +1069,4 @@ et: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: "Lubatud on ainult väikesed tähed (a-z), numbrid ja kriipsud.
Peale salvestamist ei saa tunnust enam muuta." diff --git a/config/locales/eu.yml b/config/locales/eu.yml index 14e3ba7..f89b190 100644 --- a/config/locales/eu.yml +++ b/config/locales/eu.yml @@ -1059,3 +1059,4 @@ eu: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/fa.yml b/config/locales/fa.yml index 55b99aa..abc6a55 100644 --- a/config/locales/fa.yml +++ b/config/locales/fa.yml @@ -1058,3 +1058,4 @@ fa: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/fi.yml b/config/locales/fi.yml index 37f35c4..549cdb2 100644 --- a/config/locales/fi.yml +++ b/config/locales/fi.yml @@ -1077,3 +1077,4 @@ fi: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/fr.yml b/config/locales/fr.yml index f8f0aa0..007aecc 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -1070,3 +1070,4 @@ fr: error_scm_annotate_big_text_file: Cette entrée ne peut pas être annotée car elle excède la taille maximale. setting_repositories_encodings: Encodages des fichiers et des dépôts label_search_for_watchers: Rechercher des observateurs + text_repository_identifier_info: 'Seuls les lettres minuscules (a-z), chiffres, tirets et underscore sont autorisés.
Un fois sauvegardé, l''identifiant ne pourra plus être modifié.' diff --git a/config/locales/gl.yml b/config/locales/gl.yml index d528ee2..b4b557a 100644 --- a/config/locales/gl.yml +++ b/config/locales/gl.yml @@ -1067,3 +1067,4 @@ gl: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/he.yml b/config/locales/he.yml index ef24f09..6655991 100644 --- a/config/locales/he.yml +++ b/config/locales/he.yml @@ -1061,3 +1061,4 @@ he: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/hr.yml b/config/locales/hr.yml index e7f9eb6..e8805aa 100644 --- a/config/locales/hr.yml +++ b/config/locales/hr.yml @@ -1059,3 +1059,4 @@ hr: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/hu.yml b/config/locales/hu.yml index fc99e47..a42a3c8 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -1075,3 +1075,4 @@ label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/id.yml b/config/locales/id.yml index c50fe27..52ff79a 100644 --- a/config/locales/id.yml +++ b/config/locales/id.yml @@ -1062,3 +1062,4 @@ id: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/it.yml b/config/locales/it.yml index 73c57b0..7ec4982 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -1057,3 +1057,4 @@ it: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/ja.yml b/config/locales/ja.yml index cd59b34..5ef74b3 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -1086,3 +1086,4 @@ ja: label_fields_permissions: フィールドに対する権限 label_readonly: 読み取り専用 label_required: 必須 + text_repository_identifier_info: アルファベット小文字(a-z)・数字・ハイフン・アンダースコアが使えます。
識別子は後で変更することはできません。 diff --git a/config/locales/ko.yml b/config/locales/ko.yml index 8054910..a48c774 100644 --- a/config/locales/ko.yml +++ b/config/locales/ko.yml @@ -1106,3 +1106,4 @@ ko: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: "소문자(a-z),숫자,대쉬(-)와 밑줄(_)만 가능합니다.
식별자는 저장후에는 수정할 수 없습니다." diff --git a/config/locales/lt.yml b/config/locales/lt.yml index 2784e4f..a2fcce9 100644 --- a/config/locales/lt.yml +++ b/config/locales/lt.yml @@ -1116,3 +1116,4 @@ lt: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/lv.yml b/config/locales/lv.yml index 6d7dacb..e9d7e5f 100644 --- a/config/locales/lv.yml +++ b/config/locales/lv.yml @@ -1050,3 +1050,4 @@ lv: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/mk.yml b/config/locales/mk.yml index 6831dd6..3d7f7e8 100644 --- a/config/locales/mk.yml +++ b/config/locales/mk.yml @@ -1056,3 +1056,4 @@ mk: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/mn.yml b/config/locales/mn.yml index dd73bb7..af04632 100644 --- a/config/locales/mn.yml +++ b/config/locales/mn.yml @@ -1058,3 +1058,4 @@ mn: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 35b43ef..b4e0c8d 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -1038,3 +1038,4 @@ nl: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: 'Alleen kleine letter (a-z), cijfers, streepjes en liggende streepjes zijn toegestaan.
Eenmaal opgeslagen kan de identifier niet worden gewijzigd.' diff --git a/config/locales/no.yml b/config/locales/no.yml index b870624..b32df74 100644 --- a/config/locales/no.yml +++ b/config/locales/no.yml @@ -1046,3 +1046,4 @@ label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/pl.yml b/config/locales/pl.yml index d4f31c6..0dc4a91 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -1073,3 +1073,4 @@ pl: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index fc86bad..4c95f35 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -1078,3 +1078,4 @@ pt-BR: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 6b3f0ce..04b3c45 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -1061,3 +1061,4 @@ pt: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/ro.yml b/config/locales/ro.yml index b84d607..8c84883 100644 --- a/config/locales/ro.yml +++ b/config/locales/ro.yml @@ -1053,3 +1053,4 @@ ro: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 17173f1..479be8c 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -1169,3 +1169,4 @@ ru: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Допускаются только строчные латинские буквы (a-z), цифры, тире и подчеркивания.
После сохранения идентификатор изменить нельзя. diff --git a/config/locales/sk.yml b/config/locales/sk.yml index 438294e..8db88bb 100644 --- a/config/locales/sk.yml +++ b/config/locales/sk.yml @@ -1056,3 +1056,4 @@ sk: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/sl.yml b/config/locales/sl.yml index 7709648..8d317d1 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -1056,3 +1056,4 @@ sl: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/sq.yml b/config/locales/sq.yml index be98bdf..5b3d979 100644 --- a/config/locales/sq.yml +++ b/config/locales/sq.yml @@ -1052,3 +1052,4 @@ sq: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: 'Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed.' diff --git a/config/locales/sr-YU.yml b/config/locales/sr-YU.yml index e94b12d..b738d6b 100644 --- a/config/locales/sr-YU.yml +++ b/config/locales/sr-YU.yml @@ -1058,3 +1058,4 @@ sr-YU: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/sr.yml b/config/locales/sr.yml index cd65cdd..7ffbadd 100644 --- a/config/locales/sr.yml +++ b/config/locales/sr.yml @@ -1057,3 +1057,4 @@ sr: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/sv.yml b/config/locales/sv.yml index 784a713..4904b1b 100644 --- a/config/locales/sv.yml +++ b/config/locales/sv.yml @@ -1094,3 +1094,4 @@ sv: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Ändast gemener (a-z), siffror, streck och understreck är tillåtna.
När identifieraren sparats kan den inte ändras. diff --git a/config/locales/th.yml b/config/locales/th.yml index 6dc8c36..bd58ca5 100644 --- a/config/locales/th.yml +++ b/config/locales/th.yml @@ -1053,3 +1053,4 @@ th: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/tr.yml b/config/locales/tr.yml index 8cd8490..14893ae 100644 --- a/config/locales/tr.yml +++ b/config/locales/tr.yml @@ -1075,3 +1075,4 @@ tr: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/uk.yml b/config/locales/uk.yml index 14c1ea6..88b6432 100644 --- a/config/locales/uk.yml +++ b/config/locales/uk.yml @@ -1051,3 +1051,4 @@ uk: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/vi.yml b/config/locales/vi.yml index cbd8081..d074750 100644 --- a/config/locales/vi.yml +++ b/config/locales/vi.yml @@ -1107,3 +1107,4 @@ vi: label_fields_permissions: Fields permissions label_readonly: Read-only label_required: Required + text_repository_identifier_info: Only lower case letters (a-z), numbers, dashes and underscores are allowed.
Once saved, the identifier cannot be changed. diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index 99b49b8..c53c0bd 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -1137,3 +1137,4 @@ description_date_range_interval: 選擇起始與結束日期以設定範圍區間 description_date_from: 輸入起始日期 description_date_to: 輸入結束日期 + text_repository_identifier_info: '僅允許使用小寫英文字母 (a-z), 阿拉伯數字, 虛線與底線。
一旦儲存之後, 代碼便無法再次被更改。' diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 5cd5845..64cdd7f 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1060,3 +1060,4 @@ zh: label_fields_permissions: 字段权限 label_readonly: 只读 label_required: 必填 + text_repository_identifier_info: 仅小写字母(a-z)、数字、破折号(-)和下划线(_)可以使用。
一旦保存,标识无法修改。 diff --git a/test/unit/repository_test.rb b/test/unit/repository_test.rb index f997116..56663c1 100644 --- a/test/unit/repository_test.rb +++ b/test/unit/repository_test.rb @@ -105,6 +105,38 @@ class RepositoryTest < ActiveSupport::TestCase ) assert r.save end + + def test_identifier_should_not_be_frozen_for_a_new_repository + assert_equal false, Repository.new.identifier_frozen? + end + + def test_identifier_should_not_be_frozen_for_a_saved_repository_with_blank_identifier + Repository.update_all(["identifier = ''"], "id = 10") + + assert_equal false, Repository.find(10).identifier_frozen? + end + + def test_identifier_should_be_frozen_for_a_saved_repository_with_valid_identifier + Repository.update_all(["identifier = 'abc123'"], "id = 10") + + assert_equal true, Repository.find(10).identifier_frozen? + end + + def test_identifier_should_not_accept_change_if_frozen + r = Repository.new(:identifier => 'foo') + r.stubs(:identifier_frozen?).returns(true) + + r.identifier = 'bar' + assert_equal 'foo', r.identifier + end + + def test_identifier_should_accept_change_if_not_frozen + r = Repository.new(:identifier => 'foo') + r.stubs(:identifier_frozen?).returns(false) + + r.identifier = 'bar' + assert_equal 'bar', r.identifier + end def test_destroy repository = Repository.find(10)