Skip to content

Commit

Permalink
Fixed a bug in 'is_ancestry?' where it would be confused by similar ids.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Jun 7, 2011
1 parent 3e136a4 commit 3e07763
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ vendor/plugins/rubyless
vendor/plugins/versions
vendor/plugins/yamltest
vendor/plugins/zafu
send.sftp
1 change: 1 addition & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Improved capistrano tasks on site rename.
* Fixed a bug where cached_role_ids would not be recalculated on rebuild rebuild.
* Fixed type_cast bug on Time value.
* Fixed a bug in 'is_ancestor?' where it would be confused by similar ids.

== 1.0.0.rc3 2011-05-26

Expand Down
15 changes: 9 additions & 6 deletions bricks/zena/zena/migrate/03_zerox1_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,15 @@ def validate

def migrate_base
# migrate content to version properties
prop['custom_a'] = node.custom_a unless node.custom_a.nil?
prop['custom_b'] = node.custom_b unless node.custom_b.nil?
prop['title'] = idx_text_high
prop['summary'] = idx_text_medium
prop['text'] = idx_text_low
prop['ext'] = 'zafu' if node.kpath =~ /\ANDTT/
prop['custom_a'] = node.custom_a unless node.custom_a.nil?
prop['custom_b'] = node.custom_b unless node.custom_b.nil?
prop['title'] = idx_text_high unless idx_text_high.blank?
prop['summary'] = idx_text_medium unless idx_text_medium.blank?
prop['text'] = idx_text_low unless idx_text_low.blank?
if node.kpath =~ /\ANDTT/
prop['ext'] = 'zafu'
prop['content_type'] = 'text/zafu'
end
end

def migrate_contact
Expand Down
4 changes: 3 additions & 1 deletion lib/zena/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ def rename_prop(list, old_key, new_key)
end
list.each do |rec|
prop = rec.prop
if value = prop.delete(old_key)
value = prop.delete(old_key)
if !value.blank?
prop[new_key] = value
Zena::Db.execute "UPDATE #{rec.class.table_name} SET properties=#{Zena::Db.quote(rec.class.encode_properties(prop))} WHERE id=#{rec[:id]}"
end
end
true
end

def field_to_prop(list, native_key, prop_key)
Expand Down
11 changes: 8 additions & 3 deletions lib/zena/use/ancestry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,20 @@ def z_ancestors

# Return true if the current node is an ancestor for the given child
def is_ancestor?(child)
child.fullpath =~ %r{\A#{fullpath}}
# self is it's own ancestor
child.id == id ||
# parent
child.fullpath =~ %r{\A#{fullpath}/} ||
# root
id == current_site.root_id
end

# Return the list of ancestors (without self): [root, obj, obj]
# ancestors to which the visitor has no access are removed from the list
def ancestors(start=[])
if self[:id] == current_site[:root_id]
if id == current_site.root_id
[]
elsif self[:parent_id].nil?
elsif parent_id.nil?
[]
else
path = fullpath.split('/')[0..-2]
Expand Down
25 changes: 25 additions & 0 deletions test/unit/zena/use/ancestry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,32 @@ class AncestryTest < Zena::Unit::TestCase
should 'return list of ancestors on ancestors' do
assert_equal nodes_zip(:zena, :projects), subject.ancestors.map(&:zip)
end

should 'return true on is_ancestor in parent' do
assert nodes(:projects).is_ancestor?(subject)
assert nodes(:zena).is_ancestor?(subject)
end

should 'return true on is_ancestor in self' do
assert subject.is_ancestor?(subject)
end

context 'with a zip starting like subject' do
setup do
subject.fullpath = '22'
@node = secure(Node) { nodes(:people) }
@node.fullpath = '2234'
end

should 'not return true on is_ancestor' do
assert !subject.is_ancestor?(@node)
end
end # with an zip starting like subject

should 'not return true on is_ancestor in foreign' do
assert subject.is_ancestor?(subject)
end

context 'with a secret parent' do
subject do
secure(Node) { nodes(:talk) }
Expand Down

0 comments on commit 3e07763

Please sign in to comment.