Skip to content

Commit

Permalink
Using any character to build kpath if no character from the class nam…
Browse files Browse the repository at this point in the history
…e can be used.
  • Loading branch information
gaspard committed Jun 27, 2012
1 parent 72fbc78 commit d479a81
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Added 'ssl_on_auth' option to force https after (and during) login. <=== TODO: Document
* Removing evaluated strings if copy_id is blank.
* Exporting relations by class name instead of kpath (may differ from site to site).
* Using any character to build kpath if no character from the class name can be used.

== 1.2.0, 1.2.1 2012-05-01

Expand Down
5 changes: 3 additions & 2 deletions app/models/virtual_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,9 @@ def index_groups
def rebuild_kpath(superclass)
index = 0
kpath = nil
while index < self[:name].length
try_kpath = superclass.kpath + self[:name][index..index].upcase
try_keys = "#{name}ABCDEFGHIJKLMNOPQRSTUCWXYZ1234567890"
while index < try_keys.length
try_kpath = superclass.kpath + try_keys[index..index].upcase
if found = VirtualClass.find_by_kpath(try_kpath)
if found.id && found.id == self[:id]
kpath = try_kpath
Expand Down
4 changes: 4 additions & 0 deletions test/unit/virtual_class_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ def test_new_conflict_kpath
assert !vclass.new_record?
assert_not_equal Section.kpath, vclass.kpath
assert_equal 'NPU', vclass.kpath
# New class without any free key
vclass = VirtualClass.create(:superclass => 'Page', :name => 'U', :create_group_id => groups_id(:public))
assert !vclass.new_record?
assert_equal 'NPA', vclass.kpath
end

context 'Updating a VirtualClass' do
Expand Down

0 comments on commit d479a81

Please sign in to comment.