diff --git a/TODO_ZENA_1_0 b/TODO_ZENA_1_0 index ce5a4eee..4c3b25bb 100644 --- a/TODO_ZENA_1_0 +++ b/TODO_ZENA_1_0 @@ -7,3 +7,4 @@ TODO 3. Rename virtual_classes_controller to roles_controller 4. kill node_name +10. secure XML API (get cookie: do not send login each time) \ No newline at end of file diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index aa36c864..ed78607e 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb @@ -227,7 +227,7 @@ def edit respond_to do |format| format.html do - @title_for_layout = @node.rootpath + @title_for_layout = @node.title end format.js do @@ -366,7 +366,7 @@ def update if @node.errors.empty? render :xml => @node.to_xml, :status => :ok, :location => node_url(@node) else - render :xml => @page.errors, :status => :unprocessable_entity + render :xml => @node.errors, :status => :unprocessable_entity end end # xml end @@ -389,6 +389,9 @@ def attribute node_id = secure!(Node) { Node.translate_pseudo_id(id_query, :id, @node)} @node = secure!(Node) { Node.find(node_id) } elsif name_query = params[:name] + # ???? + raise Exception.new "Attribute by name should be fixed or removed" + if name_query =~ /^(.*)\.[a-z]{2,3}$/ name_query = $1 end @@ -400,7 +403,7 @@ def attribute conditions << "#{kpath}%" end - conditions[0] << "node_name LIKE ?" + conditions[0] << "title LIKE ?" # ??? conditions << "#{name_query}%" conditions[0] = conditions[0].join(' AND ') @@ -484,7 +487,7 @@ def clear_order # archive ---> fullpath def find_node if path = params[:path] - if path.last =~ /\A(([a-zA-Z]+)([0-9]+)|([a-zA-Z0-9\-\*]+))(_[a-zA-Z]+|)(\..+|)\Z/ + if path.last =~ Zena::Use::Urls::ALLOWED_REGEXP zip = $3 name = $4 params[:mode] = $5 == '' ? nil : $5[1..-1] @@ -499,7 +502,7 @@ def find_node if name =~ /^\d+$/ @node = secure!(Node) { Node.find_by_zip(name) } elsif name - basepath = (path[0..-2] + [name]).join('/') + basepath = (path[0..-2] + [name]).map! {|p| String.from_url_name(p) }.join('/') @node = secure!(Node) { Node.find_by_path(basepath) } else @node = secure!(Node) { Node.find_by_zip(zip) } @@ -516,7 +519,7 @@ def find_node @link = Link.find_through(@node, params[:link_id]) end - @title_for_layout = @node.rootpath if @node + @title_for_layout = @node.title if @node end def set_format(format) diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index 78011bb7..1662475e 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -63,7 +63,7 @@ def edit end render :action=>'update' else - @title_for_layout = @node.rootpath + @title_for_layout = @node.title if @node.kind_of?(TextDocument) if params['parse_assets'] @node.text = @node.parse_assets(@node.text, self, 'text') diff --git a/app/models/cache.rb b/app/models/cache.rb index 2adfcbef..ce9d6c97 100644 --- a/app/models/cache.rb +++ b/app/models/cache.rb @@ -4,44 +4,49 @@ class Cache < ActiveRecord::Base cattr_accessor :perform_caching before_save :set_site_id + # The code is here too bad to be kept. + # TODO: Rewrite class << self def with(visitor_id, visitor_groups, kpath, *context) - return yield unless perform_caching - if cached = self.find(:first, :conditions => ["visitor_id = ? AND site_id = ? AND context = ?", visitor_id, visitor.site.id, context.join('.').hash.abs]) - cached[:content] - else - content = yield - self.create(:visitor_id=>visitor_id, :visitor_groups=>".#{visitor_groups.join('.')}.", :kpath=>kpath, - :context=>context.join('.').hash.abs, :content=>content ) - content - end + yield + + # return yield unless perform_caching + # if cached = self.find(:first, :conditions => ["visitor_id = ? AND site_id = ? AND context = ?", visitor_id, visitor.site.id, context.join('.').hash.abs]) + # cached[:content] + # else + # content = yield + # self.create(:visitor_id=>visitor_id, :visitor_groups=>".#{visitor_groups.join('.')}.", :kpath=>kpath, + # :context=>context.join('.').hash.abs, :content=>content ) + # content + # end end # We can provide a kpath selector for sweeping. If the kpath is in the cached scope, the cache is removed. def sweep(hash) - if kpath = hash[:kpath] - klasses = [] - kpath.split(//).each_index { |i| klasses << kpath[0..i] } - kpath_selector = " AND kpath IN (#{klasses.map{|k| connection.quote(k)}.join(',')})" - else - kpath_selector = "" - end - if hash[:visitor_id] - self.connection.execute "DELETE FROM #{self.table_name} WHERE visitor_id = '#{hash[:visitor_id]}'" + kpath_selector - end - if hash[:visitor_groups] - hash[:visitor_groups].each do |g| - self.connection.execute "DELETE FROM #{self.table_name} WHERE visitor_groups LIKE '%.#{g}.%'" + kpath_selector - end - end - if hash[:context] - context = [hash[:context]].flatten.join('.').hash.abs - self.connection.execute "DELETE FROM #{self.table_name} WHERE context = '#{context}'" + kpath_selector - end - if hash[:older_than] - self.connection.execute "DELETE FROM #{self.table_name} WHERE updated_at < '#{hash[:older_than]}'" + kpath_selector - end + return + # if kpath = hash[:kpath] + # klasses = [] + # kpath.split(//).each_index { |i| klasses << kpath[0..i] } + # kpath_selector = " AND kpath IN (#{klasses.map{|k| connection.quote(k)}.join(',')})" + # else + # kpath_selector = "" + # end + # if hash[:visitor_id] + # self.connection.execute "DELETE FROM #{self.table_name} WHERE visitor_id = '#{hash[:visitor_id]}'" + kpath_selector + # end + # if hash[:visitor_groups] + # hash[:visitor_groups].each do |g| + # self.connection.execute "DELETE FROM #{self.table_name} WHERE visitor_groups LIKE '%.#{g}.%'" + kpath_selector + # end + # end + # if hash[:context] + # context = [hash[:context]].flatten.join('.').hash.abs + # self.connection.execute "DELETE FROM #{self.table_name} WHERE context = '#{context}'" + kpath_selector + # end + # if hash[:older_than] + # self.connection.execute "DELETE FROM #{self.table_name} WHERE updated_at < '#{hash[:older_than]}'" + kpath_selector + # end end end diff --git a/app/models/document.rb b/app/models/document.rb index 8630b3c5..7460d19f 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -46,9 +46,10 @@ class Document < Node safe_property :size, :content_type, :ext safe_method :filename => String, :file => File, :filepath => String - validate :valid_file - validate :valid_content_type - after_save :clear_new_file + validate :make_unique_title + validate :valid_file + validate :valid_content_type + after_save :clear_new_file class << self @@ -71,8 +72,6 @@ def new(attrs = {}) content_type = file.content_type elsif ct = attrs['content_type'] content_type = ct - elsif attrs['node_name'] =~ /^.*\.(\w+)$/ && types = Zena::EXT_TO_TYPE[$1.downcase] - content_type = types[0] elsif attrs['title'] =~ /^.*\.(\w+)$/ && types = Zena::EXT_TO_TYPE[$1.downcase] content_type = types[0] end @@ -144,6 +143,7 @@ def image? end # Get the document's public filename using the name and the file extension. + # FIXME: shouldn't we use title here ? def filename version.attachment.filename end @@ -153,11 +153,6 @@ def filepath(format=nil) version.attachment.filepath(format) end - # Get the node's rootpath with the file's extention. - def rootpath - super + ".#{prop['ext']}" - end - protected def set_defaults set_defaults_from_file @@ -168,10 +163,6 @@ def set_defaults self.title = $1 end - if node_name.to_s =~ /\A(.*)\.#{self.ext}$/i - self.node_name = $1 - end - super set_attachment_filename @@ -224,20 +215,14 @@ def set_defaults_from_file return unless @new_file self.content_type = @new_file.content_type unless prop.content_type_changed? - if base = node_name || title || @new_file.original_filename - if base =~ /(.*)\.(\w+)$/ - self.node_name = $1 if new_record? - else - self.node_name = base if new_record? - end + if base = @new_file.original_filename + self.title = base if title.blank? end end - # Make sure node_name is unique. This should be run after sync_node_name, this is why we - # hack around the name and use super. - def sync_node_name - super - get_unique_node_name_in_scope('ND%') + # Make sure title is unique. This should be run after prop_eval. + def make_unique_title + get_unique_title_in_scope('ND') end def get_extension diff --git a/app/models/node.rb b/app/models/node.rb index 38433d44..198a77bd 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -40,7 +40,7 @@ Base attributes: zip:: unique id (incremented in each site's scope). -node_name:: used to build the node's url when 'custom_base' is set. +_id:: cached title (used to identify nodes in DB: not used in Zena) site_id:: site to which this node belongs to. parent_id:: parent node (every node except root is inserted in a unique place through this attribute). user_id:: creator of the node. @@ -62,7 +62,7 @@ Attributes used internally: publish_from:: earliest publication date from all published versions. kpath:: inheritance hierarchy. For example an Image has 'NPDI' (Node, Page, Document, Image), a Letter would have 'NNTL' (Node, Note, Task. Letter). This is used to optimize sql queries. -fullpath:: cached full path made of ancestors' node_names (//). +fullpath:: cached full path made of ancestors' zip (//). basepath:: cached base path (the base path is used to build the url depending on the 'custom_base' flag). === Node url @@ -94,6 +94,9 @@ Setting 'custom_base' on a node should be done with caution as the node's zip is on longer in the url and when you move the node around, there is no way to find the new location from the old url. Custom_base should therefore only be used for nodes that are not going to move. =end class Node < ActiveRecord::Base + # Only store partial class name in 'type' field (Page instead of ::Page) + self.store_full_sti_class = false + extend Zena::Use::Upload::UploadedFile extend Zena::Use::Search::NodeClassMethods @@ -106,7 +109,7 @@ class Node < ActiveRecord::Base property do |p| # Multilingual string index on 'title' - p.string 'title', :index => Proc.new {|r| {'title' => r.version.idx_text_high}}, :index_group => :ml_string + p.string 'title', :index => :ml_string p.string 'text' p.string 'summary' @@ -130,7 +133,7 @@ class Node < ActiveRecord::Base belongs_to :skin before_validation :set_defaults before_validation :node_before_validation - validates_presence_of :node_name + validates_presence_of :title validate :validate_node before_create :node_before_create before_save :change_klass @@ -165,8 +168,7 @@ def self.author_proc safe_node_context :parent => 'Node', :project => 'Project', :section => 'Section', :real_project => 'Project', :real_section => 'Section' - safe_context :ancestors => {:class => ['Node'], :method => 'z_ancestors'}, - :custom_a => Number, :custom_b => Number, #, :score => Number + safe_context :custom_a => Number, :custom_b => Number, #, :score => Number :comments => ['Comment'], # Code language for syntax highlighting :content_lang => String, @@ -178,10 +180,10 @@ def self.author_proc :traductions => ['Version'], :discussion => 'Discussion' # we use safe_method because the columns can be null, but the values are never null - safe_method :node_name => String, :kpath => String, :user_zip => Number, + safe_method :kpath => String, :user_zip => Number, :parent_zip => Number, :project_zip => Number, :section_zip => Number, - :skin => String, :ref_lang => String, :fullpath => String, - :rootpath => String, :position => Number, :rgroup_id => Number, + :skin => String, :ref_lang => String, + :position => Number, :rgroup_id => Number, :wgroup_id => Number, :dgroup_id => Number, :custom_base => Boolean, :klass => String, :m_text => String, :m_title => String, :m_author => String, @@ -206,18 +208,20 @@ def self.author_proc has_multiple :versions, :inverse => 'node' include Zena::Use::Workflow - include Zena::Use::NodeName # must be included after Workflow - include Zena::Use::VersionHash + include Zena::Use::Ancestry::ModelMethods # to_xml - include Zena::Acts::Serializable::NodeMethods + include Zena::Acts::Serializable::ModelMethods - # fulltext indices - include Zena::Use::Fulltext::ModelMethods + # compute vhash (must come before Fulltext) + include Zena::Use::VersionHash::ModelMethods # computed properties (vclass prop_eval) include Zena::Use::PropEval::ModelMethods + # fulltext indices (must come after PropEval) + include Zena::Use::Fulltext::ModelMethods + # List of version attributes that should be accessed as proxies 'v_lang', 'v_status', etc VERSION_ATTRIBUTES = %w{status lang publish_from backup} @@ -278,6 +282,42 @@ def inherited(child) end end + def find_by_parent_title_and_kpath(parent_id, title, kpath = nil, opts = {}) + if cond = opts[:conditions] + cond[0] = Array(cond[0]) + else + cond = opts[:conditions] = [[]] + end + + if kpath + cond[0] << "kpath like ?" + cond << "#{kpath}%" + end + cond[0] << "site_id = ? AND parent_id = ?" + cond << current_site.id << parent_id + + find_by_title(title, opts) + end + + # Find node by the indexed title. + def find_by_title(title, opts = {}) + if cond = opts[:conditions] + cond[0] = Array(cond[0]) + else + cond = opts[:conditions] = [[]] + end + + cond[0] << "id1.value = ?" + cond << title + + cond[0] = cond[0].join(' AND ') + + opts[:joins] = Node.title_join + opts[:select] = 'nodes.*' + + Node.find(:first, opts) + end + # Return the list of (kpath,subclasses) for the current class. def native_classes # this is to make sure subclasses are loaded before the first call @@ -396,11 +436,32 @@ def find_node_by_pseudo(id, base_node = nil) elsif str =~ /\A:?([0-9a-zA-Z ]+)(\+*)\Z/ offset = $2.to_s.size Node.search_records($1.gsub('-',' '), :offset => offset, :limit => 1).first - elsif path = str[/\A\(([^\)]*)\)\Z/,1] + elsif path = str[/\A\(([^\)]+)\)\Z/,1] if path[0..0] == '/' - find_by_path(path[1..-1]) + path = path[1..-1].split('/').map {|p| String.from_filename(p) } + find_by_path(path) elsif base_node - find_by_path(path.abs_path(base_node.fullpath)) + # transform ../../foo and 45/32/61/72 ==> 'foo' and 45/32 + path = path.split('/') + root = base_node.fullpath.split('/') + while path[0] == '..' + root.pop + path.shift + end + + path = path.map {|p| String.from_filename(p) } + + if base_node.zip == root.last.to_i + find_by_path(path, base_node.id) + elsif root.last + if base = find_by_zip(root.last) + find_by_path(path, base.id) + else + nil + end + else + find_by_path(path) + end else # do not use (path) pseudo when there is no base_node (during create_or_update_node for example). # FIXME: path pseudo is needed for links... and it should be done here (egg and hen problem) @@ -418,9 +479,9 @@ def find_node_by_pseudo(id, base_node = nil) def create_or_update_node(new_attributes) attributes = transform_attributes(new_attributes) - unless attributes['node_name'] && attributes['parent_id'] + unless attributes['title'] && attributes['parent_id'] node = Node.new - node.errors.add('node_name', "can't be blank") unless attributes['node_name'] + node.errors.add('title', "can't be blank") unless attributes['title'] node.errors.add('parent_id', "can't be blank") unless attributes['parent_id'] return node end @@ -434,7 +495,7 @@ def create_or_update_node(new_attributes) # FIXME: remove 'with_exclusive_scope' once scopes are clarified and removed from 'secure' node = klass.send(:with_exclusive_scope) do - Zena::Db.insensitive_find(klass, :first, :site_id => current_site[:id], :parent_id => attributes['parent_id'], :node_name => attributes['node_name'].url_name) + find_by_parent_title_and_kpath(attributes['parent_id'], attributes['title'], nil) end if node @@ -451,7 +512,7 @@ def create_or_update_node(new_attributes) node[:create_or_update] = 'same' end else - node = create_node(new_attributes) + node = create_node(attributes, false) node[:create_or_update] = 'new' end @@ -459,14 +520,14 @@ def create_or_update_node(new_attributes) end # TODO: cleanup and rename with something indicating the attrs cleanup that this method does. - def create_node(new_attributes) - attributes = transform_attributes(new_attributes) + def create_node(new_attributes, transform = true) + attributes = transform ? transform_attributes(new_attributes) : new_attributes # TODO: replace this hack with a proper class method 'secure' behaving like the # instance method. It would get the visitor and scope from the same hack below. scope = self.scoped_methods[0] || {} - klass_name = attributes.delete('class') || attributes.delete('klass') || 'Page' + klass_name = attributes.delete('class') || attributes.delete('klass') || 'Page' unless klass = get_class(klass_name, :create => true) node = Node.new node.instance_eval { @attributes = attributes } @@ -496,7 +557,7 @@ def create_nodes_from_folder(opts) parent_id = opts[:parent_id] || opts[:parent][:id] folder = opts[:folder] defaults = (opts[:defaults] || {}).stringify_keys - klass = opts[:klass] || "Page" + klass = opts[:class] || opts[:klass] || "Page" res = {} unless folder @@ -509,7 +570,9 @@ def create_nodes_from_folder(opts) return res end - entries = Dir.entries(folder).reject { |f| f =~ /^([\._~]|[^\w])/ }.sort + entries = Dir.entries(folder).reject { |f| f =~ /^([\._~])/ }.map do |filename| + String.from_filename(filename) + end.sort index = 0 @@ -522,24 +585,24 @@ def create_nodes_from_folder(opts) if File.stat(path).directory? type = :folder - node_name = filename + title = filename sub_folder = path attrs = defaults.dup attrs['v_lang'] ||= visitor.lang elsif filename =~ /^(.+?)(\.\w\w|)(\.\d+|)\.zml$/ # bird.jpg.en.zml # node content in yaml type = :node - node_name = "#{$1}#{$4}" + title = "#{$1}#{$4}" lang = $2.blank? ? nil : $2[1..-1] # no need for base_node (this is done after all with parse_assets in the controller) attrs = defaults.merge(get_attributes_from_yaml(path)) - attrs['node_name'] = node_name + attrs['title'] = title attrs['v_lang'] = lang || attrs['v_lang'] || visitor.lang versions << attrs elsif filename =~ /^((.+?)\.(.+?))(\.\w\w|)(\.\d+|)$/ # bird.jpg.en type = :document - node_name = $1 + title = $1 attrs = defaults.dup lang = $4.blank? ? nil : $4[1..-1] attrs['v_lang'] = lang || attrs['v_lang'] || visitor.lang @@ -548,15 +611,15 @@ def create_nodes_from_folder(opts) end index += 1 - while entries[index] =~ /^#{node_name}(\.\w\w|)(\.\d+|)\.zml$/ # bird.jpg.en.zml + while entries[index] =~ /^#{title}(\.\w\w|)(\.\d+|)\.zml$/ # bird.jpg.en.zml lang = $1.blank? ? visitor.lang : $1[1..-1] path = File.join(folder,entries[index]) # we have a zml file. Create a version with this file # no need for base_node (this is done after all with parse_assets in the controller) attrs = defaults.merge(get_attributes_from_yaml(path)) - attrs['node_name'] = node_name - attrs['v_lang'] ||= lang + attrs['title'] ||= title + attrs['v_lang'] ||= lang versions << attrs index += 1 @@ -565,14 +628,14 @@ def create_nodes_from_folder(opts) if versions.empty? if type == :folder # minimal node for a folder - attrs['node_name'] = node_name - attrs['v_lang'] ||= lang - attrs['class'] = klass + attrs['title'] = title + attrs['v_lang'] ||= lang + attrs['class'] = klass versions << attrs elsif type == :document # minimal node for a document - attrs['node_name'] = node_name - attrs['v_lang'] ||= lang + attrs['title'] = title + attrs['v_lang'] ||= lang versions << attrs end end @@ -582,14 +645,14 @@ def create_nodes_from_folder(opts) # FIXME: same lang: remove before update current_obj.remove if current_obj.v_lang == attrs['v_lang'] && current_obj.v_status != Zena::Status[:red] # FIXME: current_obj.publish if attrs['v_status'].to_i == Zena::Status[:pub] if type == :document - attrs['node_name' ] = attrs['node_name'].split('.')[0..-2].join('.') + attrs['title' ] = attrs['title'].split('.')[0..-2].join('.') if document_path attrs['ext'] ||= document_path.split('.').last # file insert_zafu_headings = false - if opts[:parent_class] == 'Skin' && ['html','xhtml'].include?(attrs['ext']) && attrs['node_name'] == 'index' - attrs['ext'] = 'zafu' - attrs['node_name'] = 'Node' + if opts[:parent_class] == 'Skin' && ['html','xhtml'].include?(attrs['ext']) && attrs['title'] == 'index' + attrs['ext'] = 'zafu' + attrs['title'] = 'Node' insert_zafu_headings = true end @@ -678,14 +741,6 @@ def find_by_zip(zip) node end - # Find a node by it's full path. Cache 'fullpath' if found. This is useless now - # that fullpath is properly cached. REMOVE ! - def find_by_path(path) - return nil unless scope = scoped_methods[0] - return nil unless scope[:find] # not secured find. refuse. - Zena::Db.insensitive_find(Node, :first, :fullpath => path) - end - # FIXME: Where is this used ? def class_for_relation(rel) case rel @@ -740,7 +795,7 @@ def transform_attributes(new_attributes, base_node = nil, change_timezone = true res["#{key}_id"] = Group.translate_pseudo_id(value, :id) || value elsif %w{user_id}.include?(key) res[key] = User.translate_pseudo_id(value, :id) || value - elsif %w{create_at updated_at}.include?(key) + elsif %w{id create_at updated_at}.include?(key) # ignore (can be present in xml) elsif %w{log_at event_at v_publish_from date}.include?(key) if value.kind_of?(Time) @@ -837,6 +892,13 @@ def auto_create_discussion end end + # Remove loaded version and properties on reload. + def reload + @version = nil + @properties = nil + super + end + # TODO: remove when :inverse_of works. def versions_with_secure(*args) proxy = versions_without_secure(*args) @@ -908,72 +970,6 @@ def unparse_assets(text, helper, key) ZazenParser.new(text,:helper=>helper).render(:translate_ids => :relative_path, :node=>self) 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=[]) - raise Zena::InvalidRecord, "Infinit loop in 'ancestors' (#{start.inspect} --> #{self[:id]})" if start.include?(self[:id]) - start += [self[:id]] - if self[:id] == current_site[:root_id] - [] - elsif self[:parent_id].nil? - [] - else - parent = @parent || Node.find(self[:parent_id]) - parent.visitor = visitor - if parent.can_read? - parent.ancestors(start) + [parent] - else - parent.ancestors(start) - end - end - end - - # Return the list of ancestors as a Zafu compatible context. - def z_ancestors - anc = ancestors - anc.empty? ? nil : anc - end - - # Return true if the current node is an ancestor for the given child - def ancestor?(child) - child.fullpath =~ %r{\A#{fullpath}} - end - - # url base path. If a node is in 'projects' and projects has custom_base set, the - # node's basepath becomes 'projects', so the url will be 'projects/node34.html'. - # The basepath is cached. If rebuild is set to true, the cache is updated. - def basepath - self[:basepath] - end - - # Same as fullpath, but the path includes the root node. - def rootpath - current_site.name + (fullpath != "" ? "/#{fullpath}" : "") - end - - alias path rootpath - - # Return an array with the node name and the last two parents' names. - def short_path - path = self.rootpath.split('/') - if path.size > 2 - ['..'] + path[-2..-1] - else - path - end - end - - def pseudo_id(root_node, sym) - case sym - when :zip - self.zip - when :relative_path - full = self.fullpath - root = root_node ? root_node.fullpath : '' - "(#{full.rel_path(root)})" - end - end - # Return save path for an asset (element produced by text like a png file from LateX) def asset_path(asset_filename) # It would be nice to move this outside 'self[:id]' so that the same asset can @@ -1110,12 +1106,6 @@ def data end end - # set node_name: remove all accents and camelize - def node_name=(str) - return unless str && str != "" - self[:node_name] = str.url_name - end - # Return current discussion id (used by query_builder) def get_discussion_id (discussion && !discussion.new_record?) ? discussion[:id] : '0' @@ -1316,14 +1306,15 @@ def archive n = 0 while true folder_path = File.join(RAILS_ROOT, 'tmp', sprintf('%s.%d.%d', 'archive', $$, n)) + n += 1 break unless File.exists?(folder_path) end begin FileUtils::mkpath(folder_path) export_to_folder(folder_path) - tempf = Tempfile.new(node_name) - `cd #{folder_path}; tar czf #{tempf.path} *` + tempf = Tempfile.new(title.to_filename) + `cd #{folder_path.inspect}; tar czf #{tempf.path.inspect} *` ensure FileUtils::rmtree(folder_path) end @@ -1334,13 +1325,13 @@ def archive def export_to_folder(path) children = secure(Node) { Node.find(:all, :conditions=>['parent_id = ?', self[:id] ]) } - if kind_of?(Document) && title == node_name && (kind_of?(TextDocument) || text.blank? || text == "!#{zip}!") + if kind_of?(Document) && (kind_of?(TextDocument) || text.blank? || text == "!#{zip}!") # skip zml # TODO: this should better check that version content is really useless - elsif title == node_name && text.blank? && klass == 'Page' && children + elsif text.blank? && klass == 'Page' && children # skip zml else - File.open(File.join(path, node_name + '.zml'), 'wb') do |f| + File.open(File.join(path, title.to_filename + '.zml'), 'wb') do |f| f.puts self.to_yaml end end @@ -1351,8 +1342,10 @@ def export_to_folder(path) end if children - content_folder = File.join(path, node_name) - FileUtils::mkpath(content_folder) + content_folder = File.join(path, title.to_filename) + if !FileUtils::mkpath(content_folder) + puts "Problem..." + end children.each do |child| child.export_to_folder(content_folder) end @@ -1410,6 +1403,7 @@ def safe_send(method) protected # after node is saved, make sure it's children have the correct section set + # FIXME: move this into Ancestry def spread_project_and_section if @spread_section_id || @spread_project_id # update children @@ -1471,9 +1465,6 @@ def sync_section_and_project(section_id, project_id) private def set_defaults - # FIXME: always sync node_name and basta! - self.node_name = self.title if node_name.blank? - self[:custom_base] = false unless kind_of?(Page) true end @@ -1522,11 +1513,6 @@ def node_before_validation # Make sure the node is complete before creating it (check parent and project references) def validate_node - # temporary hack until import/export does not rely on node_name anymore - # FIXME: remove this once 'node_name' is just a sync of title and is not set in import/export and - # such. - self.title = self.node_name if title.blank? - # when creating root node, self[:id] and :root_id are both nil, so it works. if parent_id_changed? && self[:id] == current_site[:root_id] errors.add("parent_id", "root should not have a parent") unless self[:parent_id].blank? @@ -1714,26 +1700,21 @@ def ref_field(for_heirs=false) end end - def get_unique_node_name_in_scope(kpath) - - if node_name_changed? || parent_id_changed? || kpath_changed? + def get_unique_title_in_scope(kpath) + if prop.title_changed? || parent_id_changed? || kpath_changed? Node.send(:with_exclusive_scope) do - if new_record? - cond = ["node_name = ? AND parent_id = ? AND kpath LIKE ?", self[:node_name], self[:parent_id], kpath] + if !new_record? + cond = ['nodes.id != ?', id] else - cond = ["node_name = ? AND parent_id = ? AND kpath LIKE ? AND id != ? ", self[:node_name], self[:parent_id], kpath, self[:id]] + cond = nil end - if taken_name = Node.find(:first, :select => 'node_name', :conditions => cond, :order => "LENGTH(node_name) DESC") - if taken_name =~ /^#{self[:node_name]}-(\d)/ - self[:node_name] = "#{self[:node_name]}-#{$1.to_i + 1}" - i = $1.to_i + 1 + if taken_name = Node.find_by_parent_title_and_kpath(parent_id, title, kpath, :order => "LENGTH(id1.value) DESC", :select => 'id1.value', :conditions => cond) + if taken_name =~ /^#{title}-(\d)/ + self.title = "#{title}-#{$1.to_i + 1}" else - self[:node_name] = "#{self[:node_name]}-1" - i = 1 + self.title = "#{title}-1" end - - self.title = "#{title}-#{i}" unless title.blank? end end end diff --git a/app/models/page.rb b/app/models/page.rb index e53995ba..bb537f86 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -19,16 +19,16 @@ def validate_node # we are in a scope, we cannot just use the normal validates_... # FIXME: remove 'with_exclusive_scope' once scopes are clarified and removed from 'secure' test_same_name = nil - if node_name_changed? || parent_id_changed? || kpath_changed? + if prop.title_changed? || parent_id_changed? || kpath_changed? Node.send(:with_exclusive_scope) do - if new_record? - cond = ["node_name = ? AND parent_id = ? AND kpath LIKE 'NP%'", self[:node_name], self[:parent_id]] + if !new_record? + cond = ['id != ?', id] else - cond = ["node_name = ? AND parent_id = ? AND kpath LIKE 'NP%' AND id != ? ", self[:node_name], self[:parent_id], self[:id]] + cond = nil end - test_same_name = Node.find(:all, :conditions => cond) + test_same_name = Node.find_by_parent_title_and_kpath(parent_id, title, 'NP') end - errors.add("node_name", "has already been taken") unless test_same_name == [] + errors.add("title", "has already been taken") if test_same_name end end diff --git a/app/models/relation_proxy.rb b/app/models/relation_proxy.rb index b8c775d9..9783a4b3 100644 --- a/app/models/relation_proxy.rb +++ b/app/models/relation_proxy.rb @@ -82,11 +82,13 @@ def other_ids end def other_zips + return nil unless @start[:id] return @other_zips if defined?(@other_zips) @other_zips = @records ? @records.map { |r| r.zip} : Zena::Db.fetch_ids("SELECT zip FROM nodes INNER JOIN links ON nodes.id=links.#{other_side} AND links.relation_id = #{self[:id]} AND links.#{link_side} = #{@start[:id]} WHERE #{secure_scope('nodes')} GROUP BY nodes.zip", 'zip') end def records(opts = {}) + return nil unless @start[:id] return @records if defined?(@records) options = { :select => "nodes.*, #{LINK_SELECT}", diff --git a/app/models/role.rb b/app/models/role.rb index 1cb8892c..6f442dcc 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -1,6 +1,9 @@ require 'property/stored_role' class Role < ActiveRecord::Base + # Only store partial class name in 'type' field (not ::Role) + self.store_full_sti_class = false + include Property::StoredRole has_many :stored_columns, :class_name => 'Column', :dependent => :destroy has_and_belongs_to_many :nodes diff --git a/app/models/site.rb b/app/models/site.rb index 246a6424..2bf0e00b 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -122,7 +122,7 @@ def create_for_host(host, su_password, opts={}) # =========== CREATE ROOT NODE ============================ root = site.send(:secure,Project) do - Project.create( :node_name => site.name, :rgroup_id => pub[:id], :wgroup_id => sgroup[:id], :dgroup_id => admin[:id], :title => site.name, :v_status => Zena::Status[:pub]) + Project.create( :title => site.name, :rgroup_id => pub[:id], :wgroup_id => sgroup[:id], :dgroup_id => admin[:id], :title => site.name, :v_status => Zena::Status[:pub]) end raise Exception.new("Could not create root node for site [#{host}] (site#{site[:id]})\n#{root.errors.map{|k,v| "[#{k}] #{v}"}.join("\n")}") if root.new_record? @@ -366,17 +366,20 @@ def rebuild_vhash(nodes = nil, page = nil, page_count = nil) true end - # TODO: replace fullpath defined from names by '/zip/zip/zip' - def rebuild_fullpath(parent_id = nil, parent_fullpath = "", parent_basepath = "") + # Recreates the fullpath ('/zip/zip/zip'). + # TODO: find a way to use SiteWorker (need to remove get_nodes) + def rebuild_fullpath(parent_id = nil, parent_fullpath = "", parent_basepath = "", start=[]) + raise Zena::InvalidRecord, "Infinit loop in 'ancestors' (#{start.inspect} --> #{parent_id})" if start.include?(parent_id) + start += [parent_id] i = 0 batch_size = 100 children = [] while true - rec = Zena::Db.fetch_attributes(['id', 'fullpath', 'basepath', 'custom_base', 'node_name'], 'nodes', "parent_id #{parent_id ? "= #{parent_id}" : "IS NULL"} AND site_id = #{self.id} ORDER BY id ASC LIMIT #{batch_size} OFFSET #{i * batch_size}") + rec = Zena::Db.fetch_attributes(['id', 'fullpath', 'basepath', 'custom_base', 'zip'], 'nodes', "parent_id #{parent_id ? "= #{parent_id}" : "IS NULL"} AND site_id = #{self.id} ORDER BY id ASC LIMIT #{batch_size} OFFSET #{i * batch_size}") break if rec.empty? rec.each do |rec| if parent_id - rec['fullpath'] = parent_fullpath == '' ? rec['node_name'] : "#{parent_fullpath}/#{rec['node_name']}" + rec['fullpath'] = parent_fullpath == '' ? rec['zip'] : "#{parent_fullpath}/#{rec['zip']}" else # root node rec['fullpath'] = '' @@ -389,7 +392,7 @@ def rebuild_fullpath(parent_id = nil, parent_fullpath = "", parent_basepath = "" end id = rec.delete('id') - children << [id, rec['fullpath'], rec['basepath']] + children << [id, rec['fullpath'], rec['basepath'], start] Zena::Db.execute "UPDATE nodes SET #{rec.map {|k,v| "#{Zena::Db.connection.quote_column_name(k)}=#{Zena::Db.quote(v)}"}.join(', ')} WHERE id = #{id}" end # 50 more diff --git a/app/models/template.rb b/app/models/template.rb index 0093724c..22f45749 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -6,11 +6,11 @@ Render ---> Master template --include--> helper template --include--> ... -For master templates, the node_name is build from the different filters (target_klass, mode, format): +For master templates, the title is build from the different filters (target_klass, mode, format): Klass-mode-format. Examples: Node-index, Node--xml, Project-info. Note how the format is omitted when it is 'html'. -Other templates have a node_name built from the given name, just like any other node. +Other templates have a title built from the given name, just like any other node. =end class Template < TextDocument @@ -63,14 +63,14 @@ def set_defaults # Force template content-type to 'text/zafu' self.content_type = 'text/zafu' - if node_name_changed? - if node_name =~ /^([A-Z][a-zA-Z]+?)(-(([a-zA-Z_\+]*)(-([a-zA-Z_]+)|))|)(\.|\Z)/ - # node_name/title changed force update + if prop.title_changed? + if title =~ /^([A-Z][a-zA-Z]+?)(-(([a-zA-Z_\+]*)(-([a-zA-Z_]+)|))|)(\.|\Z)/ + # title changed force update prop['target_klass'] = $1 unless prop.target_klass_changed? prop['mode'] = ($4 || '').url_name unless prop.mode_changed? prop['format'] = ($6 || 'html') unless prop.format_changed? else - # node_name set but it is not a master template name + # title set but it is not a master template name prop['target_klass'] = nil prop['mode'] = nil prop['format'] = nil @@ -78,13 +78,12 @@ def set_defaults end if version.edited? - prop['mode'] = prop['mode'].url_name if prop['mode'] + prop['mode'] = prop['mode'].gsub(/[^a-zA-Z]/, '') if prop['mode'] if !prop['target_klass'].blank? - # update node_name + # update title prop['format'] = 'html' if prop['format'].blank? - self.node_name = node_name_from_mode_and_format - self.title = self.node_name + self.title = title_from_mode_and_format if text.blank? && prop['format'] == 'html' && prop['mode'] != '+edit' # set a default text @@ -121,7 +120,7 @@ def set_defaults end end - def node_name_from_mode_and_format(opts={}) + def title_from_mode_and_format(opts={}) opts[:format] ||= prop['format'] opts[:mode ] ||= prop['mode'] opts[:target_klass ] ||= prop['target_klass'] diff --git a/app/models/text_document.rb b/app/models/text_document.rb index 15ba5bed..c4275d8d 100644 --- a/app/models/text_document.rb +++ b/app/models/text_document.rb @@ -43,8 +43,6 @@ def parse_assets(text, helper, key) return text end - base_path = parent.fullpath - res.gsub!(/url\(\s*(.*?)\s*\)/) do match, src = $&, $1 if src =~ /('|")(.*?)\1/ @@ -71,7 +69,7 @@ def parse_assets(text, helper, key) else if new_src = helper.send(:template_url_for_asset, :src => src, - :base_path => base_path, + :parent => parent, :parse_assets => true ) "url(#{quote}#{new_src}#{quote})" @@ -129,9 +127,10 @@ def unparse_assets(text, helper, key) zip, mode = $1, $2 if asset = secure(Node) { Node.find_by_zip(zip) } if asset.fullpath =~ /\A#{base_path}\/(.+)/ - "url(#{quote}#{$1}#{mode}.#{asset.prop['ext']}#{quote})" + path = fullpath_as_title($1) + "url(#{quote}#{path}#{mode}.#{asset.prop['ext']}#{quote})" else - "url(#{quote}/#{asset.fullpath}#{mode}.#{asset.prop['ext']}#{quote})" + "url(#{quote}/#{asset.fullpath_as_title.map(&:to_filename).join('/')}#{mode}.#{asset.prop['ext']}#{quote})" end else errors.add('asset', '{{zip}} not found', :zip => zip) diff --git a/app/models/user.rb b/app/models/user.rb index 616a19c7..1af0034d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -251,7 +251,7 @@ def tz end def comments_to_publish - secure(Comment) { Comment.find(:all, :select=>'comments.*, nodes.node_name', :from=>'comments, nodes, discussions', + secure(Comment) { Comment.find(:all, :select=>'comments.*', :from=>'comments, nodes, discussions', :conditions => ['comments.status = ? AND discussions.node_id = nodes.id AND comments.discussion_id = discussions.id AND nodes.dgroup_id IN (?)', Zena::Status[:prop], visitor.group_ids]) } end diff --git a/app/views/links/_li.rhtml b/app/views/links/_li.rhtml index 64528cf6..e591cad1 100644 --- a/app/views/links/_li.rhtml +++ b/app/views/links/_li.rhtml @@ -1,6 +1,6 @@ <%= link_to_remote( relation.other_icon.blank? ? _('img_link') : relation.other_icon, :update=>"link#{li.link_id}", :url => edit_node_link_path(:node_id => @node[:zip], :id => li.link_id), :method=>:get) %> - <%= link_to( li.rootpath, zen_path(li), :popup=>true ) %> + <%= link_to( li.short_path, zen_path(li), :popup=>true ) %> <%= li.l_status %> <%= li.l_comment %> <%= link_to_remote(_('btn_tiny_del'), :url => node_link_path(:node_id => @node[:zip],:id => li.link_id), :method => :delete) %> diff --git a/app/views/nodes/_import_results.rhtml b/app/views/nodes/_import_results.rhtml index 22664b60..a91cda32 100644 --- a/app/views/nodes/_import_results.rhtml +++ b/app/views/nodes/_import_results.rhtml @@ -6,7 +6,7 @@ <% @nodes.each do |node| -%> '> <%= img_tag(node, :mode=>'tiny') %> - <%= node.rootpath %> + <%= node.short_path %> <% if node[:create_or_update] == 'same' && node.errors.empty? -%> <%= _('same') %> <% else -%> diff --git a/app/views/nodes/_parent.rhtml b/app/views/nodes/_parent.rhtml index 7a0b09e1..650f7874 100644 --- a/app/views/nodes/_parent.rhtml +++ b/app/views/nodes/_parent.rhtml @@ -5,7 +5,7 @@ <% if @node[:parent_id] %>
  • <%= select_id('node', 'parent_id') %>
  • <% end -%>
  • <%= select('node', 'klass', @node.class.change_to_classes_for_form) %>
  • -
  • <%= text_field('node', 'node_name', :size=>15) %>
  • +
  • <%= text_field('node', 'title', :size=>15) %>
  • <% if @node.kind_of?(Page) -%>
  • <%= check_box('node', 'custom_base') %>
  • <% end -%> diff --git a/app/views/nodes/_results.rhtml b/app/views/nodes/_results.rhtml index e6283740..4ee4b62a 100644 --- a/app/views/nodes/_results.rhtml +++ b/app/views/nodes/_results.rhtml @@ -20,7 +20,7 @@ <%= img_tag(node, :mode=>'mini') %>

    <%= link_to(node.title, zen_path(node), :popup=>true) %> <%= check_lang(node) %>

    <%= node[:zip] %>

    -

    <%= node.rootpath.split('/').join(' / ') %>

    +

    <%= node.short_path %>

    <% end %> diff --git a/app/views/templates/document_create_tabs/_file.rhtml b/app/views/templates/document_create_tabs/_file.rhtml index 6bb16fce..8ebe5545 100644 --- a/app/views/templates/document_create_tabs/_file.rhtml +++ b/app/views/templates/document_create_tabs/_file.rhtml @@ -4,7 +4,7 @@ <%= upload_field %> - + <%= check_exists(:node => @parent, :watch => 'node_title', :kpath => 'ND', :show => 'short_path') %>
    diff --git a/app/views/templates/document_create_tabs/_template.rhtml b/app/views/templates/document_create_tabs/_template.rhtml index 2ec63761..5e036ec8 100644 --- a/app/views/templates/document_create_tabs/_template.rhtml +++ b/app/views/templates/document_create_tabs/_template.rhtml @@ -4,8 +4,8 @@ - -
    + +
    <%= select('node', 'target_klass', Node.classes_for_form, {:include_blank => true} ) %>
    diff --git a/app/views/templates/document_create_tabs/_text_document.rhtml b/app/views/templates/document_create_tabs/_text_document.rhtml index 1bb92cd1..7ad34743 100644 --- a/app/views/templates/document_create_tabs/_text_document.rhtml +++ b/app/views/templates/document_create_tabs/_text_document.rhtml @@ -5,8 +5,8 @@
    - -
    + +

    diff --git a/app/views/templates/edit_tabs/_help.rhtml b/app/views/templates/edit_tabs/_help.rhtml index 9f2b551a..0de0901a 100755 --- a/app/views/templates/edit_tabs/_help.rhtml +++ b/app/views/templates/edit_tabs/_help.rhtml @@ -1,6 +1,6 @@ <%= begin - node = secure!(Node) { Node.find_by_node_name('help') } + node = secure!(Node) { Node.find_by_title('help') } zazen(node.summary) rescue _('help not found') diff --git a/app/views/zafu/default/Node-+search.zafu b/app/views/zafu/default/Node-+search.zafu index ad1920b8..ccb0dbda 100644 --- a/app/views/zafu/default/Node-+search.zafu +++ b/app/views/zafu/default/Node-+search.zafu @@ -11,7 +11,7 @@

    -

    +

    diff --git a/bricks/tags/zena/test/zafu/tags.yml b/bricks/tags/zena/test/zafu/tags.yml index f3cc3f60..58b9f5bd 100644 --- a/bricks/tags/zena/test/zafu/tags.yml +++ b/bricks/tags/zena/test/zafu/tags.yml @@ -16,16 +16,16 @@ listing_no_tags: listing_with_link: src: "" - res: "blue,sky" + res: "blue,sky" tagged_query: context: cat: 'blue' - src: "" - res: "bird, status" + src: "" + res: "bird, status title" images_tagged_blue: - src: "" + src: "" res: "bird" tagged_keys_rubyless: diff --git a/db/init/base/skins/default/Node-+search.zafu b/db/init/base/skins/default/Node-+search.zafu index ad1920b8..ccb0dbda 100644 --- a/db/init/base/skins/default/Node-+search.zafu +++ b/db/init/base/skins/default/Node-+search.zafu @@ -11,7 +11,7 @@

    -

    +

    diff --git a/db/init/base/skins/default/Node-tree.zafu b/db/init/base/skins/default/Node-tree.zafu index a661cedd..d36b2c95 100644 --- a/db/init/base/skins/default/Node-tree.zafu +++ b/db/init/base/skins/default/Node-tree.zafu @@ -5,11 +5,11 @@

    this is the title

    • -
    • -
    • +
    • +
      • - +
    • diff --git a/db/migrate/046_fix_zazen_image_tag.rb b/db/migrate/046_fix_zazen_image_tag.rb index 6a6a2c9b..19a72b5b 100644 --- a/db/migrate/046_fix_zazen_image_tag.rb +++ b/db/migrate/046_fix_zazen_image_tag.rb @@ -1,23 +1,25 @@ class FixZazenImageTag < ActiveRecord::Migration def self.up - # Change all zazen image tags from !34.pv! to !34_pv! for better consistency with 'modes'. - { - Version.table_name => [:text, :summary], - 'dyn_attributes' => [:value], - ContactContent.table_name => [:address], - Comment.table_name => [:text], - DataEntry.table_name => [:text], - }.each do |table_name, keys| - select_all("SELECT id,#{keys.join(',')} FROM #{table_name}", "#{table_name} Load").each do |record| - new_value = {} - keys.each do |k| - next unless record[k.to_s] - value = record[k.to_s].gsub(/\!([^0-9]{0,2}[0-9]+)(\.([^\/\!]+)|)(\/[^\!]*|)\!/) do - "!#{$1}#{$3 ? "_#{$3}" : ''}#{$4}!" + if !$migrating_new_site + # Change all zazen image tags from !34.pv! to !34_pv! for better consistency with 'modes'. + { + Version.table_name => [:text, :summary], + 'dyn_attributes' => [:value], + ContactContent.table_name => [:address], + Comment.table_name => [:text], + DataEntry.table_name => [:text], + }.each do |table_name, keys| + select_all("SELECT id,#{keys.join(',')} FROM #{table_name}", "#{table_name} Load").each do |record| + new_value = {} + keys.each do |k| + next unless record[k.to_s] + value = record[k.to_s].gsub(/\!([^0-9]{0,2}[0-9]+)(\.([^\/\!]+)|)(\/[^\!]*|)\!/) do + "!#{$1}#{$3 ? "_#{$3}" : ''}#{$4}!" + end + new_value[k] = value if value != record[k.to_s] end - new_value[k] = value if value != record[k.to_s] + execute "UPDATE #{table_name} SET #{new_value.map{|k,v| "#{k} = #{quote(v)}"}.join(', ')} WHERE id = #{record['id']}" if new_value != {} end - execute "UPDATE #{table_name} SET #{new_value.map{|k,v| "#{k} = #{quote(v)}"}.join(', ')} WHERE id = #{record['id']}" if new_value != {} end end end diff --git a/db/migrate/20100928185257_add_obvious_idx.rb b/db/migrate/20100928185257_add_obvious_idx.rb index 47e0f310..0898882f 100644 --- a/db/migrate/20100928185257_add_obvious_idx.rb +++ b/db/migrate/20100928185257_add_obvious_idx.rb @@ -8,8 +8,8 @@ class AddObviousIdx < ActiveRecord::Migration :data_entries => DataEntry::NodeLinkSymbolsId, :discussions => %w{node_id}, :groups_users => %w{group_id user_id}, - :idx_nodes_ml_strings => %w{node_id key lang value}, - :idx_nodes_strings => %w{node_id key value}, + :idx_nodes_ml_strings => %w{value}, + :idx_nodes_strings => %w{value}, :idx_templates => %w{tkpath format mode site_id node_id version_id}, # :iformats :links => %w{source_id target_id relation_id status date}, @@ -26,6 +26,8 @@ class AddObviousIdx < ActiveRecord::Migration def self.up add_index(:nodes, [:zip, :site_id]) + add_index(:idx_nodes_ml_strings, [:node_id, :key, :lang]) + add_index(:idx_nodes_strings, [:node_id, :key]) INDICES.each do |table, indices| indices.each do |key| @@ -38,6 +40,9 @@ def self.up def self.down remove_index(:nodes, :column => [:zip, :site_id]) + remove_index(:idx_nodes_ml_strings, :column => [:node_id, :key, :lang]) + remove_index(:idx_nodes_strings, :column => [:node_id, :key]) + INDICES.each do |table, indices| indices.each do |key| remove_index(table, key) diff --git a/db/migrate/20100929143111_remove_node_name.rb b/db/migrate/20100929143111_remove_node_name.rb new file mode 100644 index 00000000..1d935c33 --- /dev/null +++ b/db/migrate/20100929143111_remove_node_name.rb @@ -0,0 +1,11 @@ +class RemoveNodeName < ActiveRecord::Migration + def self.up + remove_column :nodes, :node_name + add_column :nodes, :_id, :string, :limit => 40 + end + + def self.down + remove_column :nodes, :_id + add_column :nodes, :node_name, :text + end +end diff --git a/lib/log_recorder/lib/log_recorder.rb b/lib/log_recorder/lib/log_recorder.rb index 2de61aec..927518bd 100644 --- a/lib/log_recorder/lib/log_recorder.rb +++ b/lib/log_recorder/lib/log_recorder.rb @@ -88,9 +88,9 @@ def test puts parse_date("10/Oct/2000:13:55:36 -0100") puts parse_path("GET /apache_pb.gif HTTP/1.0") puts get_site_id("test.host").inspect - puts find_zip_by_path("projects/cleanWater") + puts find_zip_by_path("projects-list/Clean-Water-project") insert_combined_record('213.3.85.165 - - [29/Feb/2008:11:34:22 +0100] "GET /en/image133_tiny.jpg HTTP/1.1" 200 4039 "http://zenadmin.org/en" "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; fr) AppleWebKit/419.3 (KHTML, like Gecko) Safari/419.3"') - insert_combined_record('213.3.85.165 - - [29/Feb/2008:11:38:09 +0100] "GET /fr/projects/cleanWater.html HTTP/1.1" 200 4760 "http://zenadmin.org/en" "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; fr) AppleWebKit/419.3 (KHTML, like Gecko) Safari/419.3"') + insert_combined_record('213.3.85.165 - - [29/Feb/2008:11:38:09 +0100] "GET /fr/projects-list/Clean-Water-project.html HTTP/1.1" 200 4760 "http://zenadmin.org/en" "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; fr) AppleWebKit/419.3 (KHTML, like Gecko) Safari/419.3"') end private def get_site_id(vhost_name) diff --git a/lib/tasks/zena.rake b/lib/tasks/zena.rake index 18680c90..229ca5f2 100644 --- a/lib/tasks/zena.rake +++ b/lib/tasks/zena.rake @@ -155,7 +155,7 @@ namespace :zena do next if File.exist?("#{host_path}/#{dir}") FileUtils.mkpath("#{host_path}/#{dir}") end - + # FIXME! should not symlink RAILS_ROOT but /home/app_name/app/current ... symlink_assets(RAILS_ROOT, host_path) end end @@ -354,6 +354,17 @@ namespace :zena do end end + desc 'Rebuild fullpath for all sites (without SiteWorker)' + task :rebuild_fullpath => :environment do + include Zena::Acts::Secure + + Site.all.each do |site| + # We avoid SiteWorker because it's async. + Thread.current[:visitor] = User.find_by_login_and_site_id(nil, site.id) + site.rebuild_fullpath + end + end + Rake::RDocTask.new do |rdoc| files = ['README', 'doc/README_FOR_APP', 'CREDITS', 'MIT-LICENSE', 'app/**/*.rb', 'lib/**/*.rb'] diff --git a/lib/zena/acts/secure.rb b/lib/zena/acts/secure.rb index a071400e..ef4fcd7e 100644 --- a/lib/zena/acts/secure.rb +++ b/lib/zena/acts/secure.rb @@ -349,7 +349,7 @@ def nodes(zip_or_name) if zip_or_name.kind_of?(Fixnum) secure(Node) { Node.find_by_zip(zip_or_name) } else - secure(Node) { Node.first(:conditions => ['node_name LIKE ?', "#{zip_or_name}%"]) } + secure(Node) { Node.find_by_title(zip_or_name) } end end end diff --git a/lib/zena/acts/secure_node.rb b/lib/zena/acts/secure_node.rb index 8b1fca8c..35baf7f2 100644 --- a/lib/zena/acts/secure_node.rb +++ b/lib/zena/acts/secure_node.rb @@ -235,7 +235,7 @@ def secure_on_update # Node hasn't been changed (only version edits) return true end - + if !can_drive_was_true? errors.add(:base, 'You do not have the rights to do this.') unless errors[:base] return false diff --git a/lib/zena/acts/serializable.rb b/lib/zena/acts/serializable.rb index 7e2a0c51..a787c296 100644 --- a/lib/zena/acts/serializable.rb +++ b/lib/zena/acts/serializable.rb @@ -75,7 +75,7 @@ def serializable_id_attributes end end - module NodeMethods + module ModelMethods def to_xml(options = {}, &block) options = default_serialization_options.merge(options) serializer = XmlNodeSerializer.new(self, options) @@ -83,7 +83,7 @@ def to_xml(options = {}, &block) end def default_serialization_options - { :only => %w{node_name created_at updated_at log_at event_at kpath ref_lang fullpath position}, + { :only => %w{created_at updated_at log_at event_at kpath ref_lang fullpath position}, :methods => %w{v_status klass}, :properties => export_properties, :ids => export_ids, diff --git a/lib/zena/core_ext/string.rb b/lib/zena/core_ext/string.rb index a26a643b..0f91386a 100644 --- a/lib/zena/core_ext/string.rb +++ b/lib/zena/core_ext/string.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -# FIXME: do we really need to monkey patch String ? +require 'cgi' # Avoid incompatibility with rails 'chars' version in Ruby 1.8.7 unless '1.9'.respond_to?(:force_encoding) @@ -13,29 +13,45 @@ end class String - # could not name this extension 'camelize'. 'camelize' is a Rails core extension to String. + ALLOWED_CHARS_IN_URL = " a-zA-Z0-9_\\." + # in filename, allow '-' because it does not represent a space + ALLOWED_CHARS_IN_FILENAME = "#{ALLOWED_CHARS_IN_URL}\\-" + # Everything apart from a-zA-Z0-9_.-/$ are not allowed in template paths + ALLOWED_CHARS_IN_FILEPATH = "#{ALLOWED_CHARS_IN_FILENAME}+/$" + TO_FILENAME_REGEXP = %r{([^ #{ALLOWED_CHARS_IN_FILENAME}]+)}n + TO_URL_NAME_REGEXP = %r{([^ #{ALLOWED_CHARS_IN_URL}])} + + # Change a title into a valid url name def url_name - dup.url_name! + gsub(TO_URL_NAME_REGEXP) do + '%' + $1.unpack('H2' * $1.size).join('%').upcase + end.tr(' ', '-') + end + + # Retrieve original title from an url_name + def self.from_url_name(str) + CGI.unescape(str.tr('-', ' ')) end - def url_name! - accents = { - ['á', 'à','À','â','Â','ä','Ä','ã','Ã'] => 'a', - ['é','É','è','È','ê','Ê','ë','Ë', ] => 'e', - ['í', 'ì','Ì','î','Î','ï','Ï' ] => 'i', - ['ó', 'ò','Ò','ô','Ô','ö','Ö','õ','Õ'] => 'o', - ['ú', 'ù','Ù','û','Û','ü','Ü' ] => 'u', - ['œ'] => 'oe', - ['ß'] => 'ss', - } - accents.each do |ac,rep| - ac.each do |s| - gsub!(s, rep) - end + # Change a title into a valid filename + def to_filename + gsub(TO_FILENAME_REGEXP) do + '%' + $1.unpack('H2' * $1.size).join('%').upcase end - gsub!(/[^a-zA-Z0-9\.\-\+ ]/,' ') - replace(split.join(' ')) - gsub!(/ (.)/) { $1.upcase } + end + + # Retrieve original title from filename + def self.from_filename(str) + CGI.unescape(str.gsub('+', '%2B')) + end + + def url_name! + replace(url_name) + self + end + + def to_filename! + replace(to_filename) self end diff --git a/lib/zena/deploy.rb b/lib/zena/deploy.rb index 0b73d02a..c0be08bc 100644 --- a/lib/zena/deploy.rb +++ b/lib/zena/deploy.rb @@ -13,7 +13,8 @@ ========== USAGE ========== 1. Copy the file 'deploy_config_example.rb' to 'deploy_config.rb' and edit the entries in this new file. -2. Run => cap initial_setup +2. Run => cap deploy:setup +3. Run => cap deploy 3. Run => cap mksite -s host='example.com' -s pass='secret' -s lang='en' If anything goes wrong, ask the mailing list (lists.zenadmin.org) or read the content of this file to understand what went wrong... diff --git a/lib/zena/deploy/vhost.rhtml b/lib/zena/deploy/vhost.rhtml index ecd7bd93..85b677d9 100644 --- a/lib/zena/deploy/vhost.rhtml +++ b/lib/zena/deploy/vhost.rhtml @@ -63,7 +63,7 @@ RewriteRule ^([^.]+)$ $1.html [QSA] # Redirect all non-static requests to cluster - RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}%{QUERY_STRING} !-f RewriteRule ^/(.*)$ balancer://<%= config[:balancer] %>%{REQUEST_URI} [P,QSA,L] <% elsif config[:app_type] == :passenger %> PassengerAppRoot <%= config[:app_root] %> diff --git a/lib/zena/foxy_parser.rb b/lib/zena/foxy_parser.rb index 16c82750..c3365e25 100644 --- a/lib/zena/foxy_parser.rb +++ b/lib/zena/foxy_parser.rb @@ -349,13 +349,6 @@ def set_defaults add_template(template, name) end - if !node.has_key?('node_name') - node['node_name'] = name - node[:header_keys] << 'node_name' - end - - node['node_name'] = node['node_name'].url_name - if node.keys.include?('title') || node.keys.detect {|k| k =~ /^v_/} # need version defaults @defaults.each do |key,value| @@ -364,6 +357,11 @@ def set_defaults end end + if !node.has_key?('_id') + node['_id'] = name + node[:header_keys] << '_id' + end + # FIXME: better filtering, in a hurry right now prop_field = nil %w{text title summary comment}.each do |k| @@ -426,11 +424,6 @@ def set_defaults end build_inherited_fields - - # build fullpath - elements.each do |k, node| - make_paths(node, k) - end end def make_paths(node, name) @@ -439,7 +432,7 @@ def make_paths(node, name) parent_fullpath = make_paths(parent, node['parent']) # Unquote content if it was an empty quoted string. parent_fullpath = '' if parent_fullpath == "''" - node['fullpath'] = (parent_fullpath.split('/') + [node['node_name'] || name]).join('/') + node['fullpath'] = (parent_fullpath.split('/') + [node['zip']]).join('/') klass = if roles[site] && vc = roles[site][node['class']] vc['real_class'] else @@ -519,7 +512,7 @@ def build_inherited_fields def insert_headers node = elements[name] - # we compute 'zip' here so that the order of the file is kept + # we compute 'zip' here so that the order of the elements in file is kept @zip_counter[site] ||= 0 if node['zip'] if node['zip'] > @zip_counter[site] @@ -530,6 +523,9 @@ def insert_headers node['zip'] = @zip_counter[site] end + # build fullpath + make_paths(node, name) + super end @@ -641,7 +637,7 @@ def set_defaults version['status'] = Zena::Status[version['status'].to_sym] version['prop'] ||= {} - version['prop']['title'] ||= raw_nodes[version['node']]['node_name'] || version['node'] + version['prop']['title'] ||= version['node'] if prop = version.delete('prop') version['properties'] = make_prop(prop) unless prop.blank? diff --git a/lib/zena/parser/zazen_rules.rb b/lib/zena/parser/zazen_rules.rb index d4bf23f5..24be1441 100644 --- a/lib/zena/parser/zazen_rules.rb +++ b/lib/zena/parser/zazen_rules.rb @@ -112,7 +112,7 @@ def scan_exclam else store @helper._('[documents]') end - elsif @text =~ /\A\!([^0-9]{0,2})(#{PSEUDO_ID_REGEXP})(_([^\/\!]+)|)(\/([^\!]*)|)\!(:([^\s]+)|)/m + elsif @text =~ /\A\!([^0-9:]{0,2})(#{PSEUDO_ID_REGEXP})(_([^\/\!]+)|)(\/([^\!]*)|)\!(:([^:\(][^\s]+|#{PSEUDO_ID_REGEXP}(_[a-zA-Z]+|))|)/m # image !<.:art++_pv/blah blah!:12 #puts "SHORCUT IMAGE:#{$~.to_a.inspect}" eat $& @@ -136,7 +136,7 @@ def scan_exclam if node.kind_of?(Document) store @helper.make_image(:style=>style, :id=>node[:zip].to_s, :node=>node, :mode=>mode, :title=>title, :link=>link, :images=>@context[:images]) else - store "[#{node.fullpath} is not a document]" + store "[#{node.fullpath_as_title.join('/')} is not a document]" end end elsif @translate_ids @@ -144,7 +144,7 @@ def scan_exclam else store "[#{id} not found]" end - elsif @text =~ /\A\!([^0-9]{0,2})([0-9]+)(_([^\/\!]+)|)(\/([^\!]*)|)\!(:([^\s]+)|)/m + elsif @text =~ /\A\!([^0-9]{0,2})([0-9]+)(_([^\/\!]+)|)(\/([^\!]*)|)\!(:([^:\(][^\s]+|#{PSEUDO_ID_REGEXP}(_[a-zA-Z]+|))|)/m # image !<.12_pv/blah blah!:12 #puts "IMAGE:[#{$&}]" eat $& @@ -204,9 +204,9 @@ def scan_quote else id = "#{node.zip}#{mode_format}" if format == '.data' - title = "#{node.fullpath}#{mode}.#{node.ext}#{dash}" + title = "#{node.fullpath_as_title.join('/')}#{mode}.#{node.ext}#{dash}" else - title = "#{node.fullpath}#{mode_format}" + title = "#{node.fullpath_as_title.join('/')}#{mode_format}" end if id =~ /(.*?)#(.*)/ id, anchor = $1, $2 diff --git a/lib/zena/parser/zena_rules.rb b/lib/zena/parser/zena_rules.rb index 808e7ae8..b75c2596 100644 --- a/lib/zena/parser/zena_rules.rb +++ b/lib/zena/parser/zena_rules.rb @@ -13,7 +13,7 @@ def start(mode) @method = 'zazen' @params[:attr] = $1 elsif @method =~ /\A(\w+)\s+(\w+)\s+(.+)$/ - # 'pages where node_name ...' + # 'pages where title ...' @params[:select] = @method @method = 'context' end diff --git a/lib/zena/test_controller.rb b/lib/zena/test_controller.rb index ddca9053..2aaa881c 100644 --- a/lib/zena/test_controller.rb +++ b/lib/zena/test_controller.rb @@ -99,11 +99,16 @@ def set_context def get_template_text(path, base_path) folder = base_path.blank? ? [] : base_path[1..-1].split('/') - path = path[1..-1] if path[0..0] == '/' # just ignore the 'relative' or 'absolute' tricks. - url = (folder + path.split('/')[1..-1]).join('_') + if path[0..0] == '/' + # just ignore the 'relative' or 'absolute' tricks. + test_path = path[1..-1] + else + test_path = path + end + url = (folder + test_path.split('/')[1..-1]).join('_') if test = @@templates[url] - [test['src'], path] + [test['src'], test_path] else # 'normal' include @expire_with_nodes = {} diff --git a/lib/zena/use/ancestry.rb b/lib/zena/use/ancestry.rb new file mode 100644 index 00000000..26035653 --- /dev/null +++ b/lib/zena/use/ancestry.rb @@ -0,0 +1,210 @@ +module Zena + module Use + # This module handles the creation and maintenance of a 'fullpath' and cached project/section_id. + module Ancestry + module ClassMethods + def title_join + %Q{INNER JOIN idx_nodes_ml_strings AS id1 ON id1.node_id = nodes.id AND id1.key = 'title' AND id1.lang = '#{visitor.lang}'} + end + + # (slow). Find a node by it's path. This is used during node importation when stored as zml files. + def find_by_path(path, parent_id = current_site.root_id) + res = nil + path = path.split('/') unless path.kind_of?(Array) + last = path.size - 1 + path.each_with_index do |title, i| + klass = i == last ? self : Node + unless p = klass.find(:first, + :select => i == last ? 'nodes.*' : 'nodes.id', + :joins => title_join, + :conditions => ["parent_id = ? AND id1.value = ? AND #{secure_scope('nodes')}", parent_id, title] + ) + # Block as soon as we cannot find an element + return nil + end + parent_id = p['id'] + res = p if i == last + end + res + end + + # (slow). Transform a list of zips into a fullpath. + def fullpath_map(path, sym = :node) + path = path.split('/') unless path.kind_of?(Array) + zips = path.reject{|e| e == '..'} + case sym + when :title + opts = { + :select => 'zip, id1.value AS title', + :joins => title_join, + :conditions => ["zip IN (?) AND #{secure_scope('nodes')}", zips], + } + when :node + opts = { + :conditions => ["zip IN (?) AND #{secure_scope('nodes')}", zips], + } + else + # not supported + raise Exception.new("#{sym} not supported for fullpath_map") + end + + + list = Node.find(:all, opts) + + list = Hash[*(list.map{|e| [e['zip'].to_i, sym == :node ? e : e[sym.to_s]]}).flatten] + + path.map do |zip| + zip == '..' ? '..' : (list[zip.to_i] || (sym == :node ? nil : '*')) + end.compact + end + end # ClassMethods + + module ModelMethods + include RubyLess + safe_context :ancestors => {:class => ['Node'], :method => 'z_ancestors'} + safe_method :fullpath => String, :short_path => String + + def self.included(base) + base.class_eval do + # We do not use before_save to make sure this happens after 'zip' is set in 'node_before_create'. + before_create :rebuild_paths + before_update :rebuild_paths + after_save :rebuild_children_fullpath + extend ClassMethods + end + end + + # Return the list of ancestors as a Zafu compatible context. + def z_ancestors + anc = ancestors + anc.empty? ? nil : anc + end + + # Return true if the current node is an ancestor for the given child + def ancestor?(child) + child.fullpath =~ %r{\A#{fullpath}} + 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] + [] + elsif self[:parent_id].nil? + [] + else + path = fullpath.split('/')[0..-2] + [current_site.root_node].compact + secure(Node) { Node.fullpath_map(path, :node) } + end + end + + # url base path. If a node is in 'projects' and projects has custom_base set, the + # node's basepath becomes 'projects', so the url will be 'projects/node34.html'. + # The basepath is cached. If rebuild is set to true, the cache is updated. + def basepath + self[:basepath] + end + + # (slow). Return an array with the node title and the last two parents' titles. + def short_path + path = fullpath.split('/') + if path.size > 2 + ['..'] + fullpath_as_title(path[-2..-1]) + else + fullpath_as_title(path) + end + end + + def pseudo_id(root_node, sym) + case sym + when :zip + self.zip + when :relative_path + full = self.fullpath + root = root_node ? root_node.fullpath : '' + "(#{fullpath_as_title(full.rel_path(root)).map(&:to_filename).join('/')})" + end + end + + # (slow). Transform a list of zips into a fullpath. + def fullpath_as_title(path = fullpath) + if path == self.fullpath + @fullpath_as_title ||= secure(Node) { Node.fullpath_map(path, :title) } + else + secure(Node) { Node.fullpath_map(path, :title) } + end + end + + private + + def rebuild_paths + # rebuild cached fullpath / basepath + rebuild_fullpath + rebuild_basepath + # we should use a full rebuild when there are corrupt values, + # if fullpath was blank, we have no way to find all children + @need_rebuild_children_fullpath = !new_record? && (fullpath_changed? || basepath_changed?) && !fullpath_was.blank? + + true + end + + def rebuild_fullpath + return unless new_record? || parent_id_changed? || fullpath.nil? + if parent = parent(false) + path = parent.fullpath.split('/') + [zip] + else + path = [] + end + self.fullpath = path.join('/') + end + + def rebuild_basepath + return unless new_record? || parent_id_changed? || custom_base_changed? || basepath.nil? + if custom_base + self[:basepath] = self.fullpath + elsif parent = parent(false) + self[:basepath] = parent.basepath || "" + else + self[:basepath] = "" + end + end + + def rebuild_children_fullpath + return true unless @need_rebuild_children_fullpath + + # Update descendants + fullpath_new = self.fullpath + fullpath_new = "#{fullpath_new}/" if fullpath_was == '' + fullpath_re = fullpath_changed? ? %r{\A#{self.fullpath_was}} : nil + + bases = [self.basepath] + + i = 0 + batch_size = 100 + while true + list = Zena::Db.fetch_attributes(['id', 'fullpath', 'basepath', 'custom_base'], 'nodes', "fullpath LIKE #{Zena::Db.quote("#{fullpath_was}/%")} AND site_id = #{current_site.id} ORDER BY fullpath ASC LIMIT #{batch_size} OFFSET #{i * batch_size}") + + break if list.empty? + list.each do |rec| + rec['fullpath'].sub!(fullpath_re, fullpath_new) if fullpath_re + if rec['custom_base'] == Zena::Db::TRUE_RESULT + rec['basepath'] = rec['fullpath'] + bases << rec['basepath'] + else + while rec['fullpath'].size <= bases.last.size + bases.pop + end + rec['basepath'] = bases.last + end + id = rec.delete('id') + Zena::Db.execute "UPDATE nodes SET #{rec.map {|k,v| "#{Zena::Db.connection.quote_column_name(k)}=#{Zena::Db.quote(v)}"}.join(', ')} WHERE id = #{id}" + end + # 50 more + i += 1 + end + true + end + end # ModelMethods + end # Ancestry + end # Use +end # Zena diff --git a/lib/zena/use/context.rb b/lib/zena/use/context.rb index bfdb7352..8f8363d7 100644 --- a/lib/zena/use/context.rb +++ b/lib/zena/use/context.rb @@ -151,7 +151,7 @@ def r_group return parser_error("cannot be used outside of a list") unless node.list_context? return parser_error("missing 'by' clause") unless key = @params[:by] - #sort_key = @params[:sort] || 'node_name' + #sort_key = @params[:sort] || 'title' # if node.will_be?(DataEntry) && DataEntry::NodeLinkSymbols.include?(key.to_sym) # key = "#{key}_id" # #sort_block = "{|e| (e.#{key} || {})[#{sort_key.to_sym.inspect}]}" diff --git a/lib/zena/use/display.rb b/lib/zena/use/display.rb index e3f42e86..d4b17ea9 100644 --- a/lib/zena/use/display.rb +++ b/lib/zena/use/display.rb @@ -8,7 +8,7 @@ def icon_finder else finder = 'image' end - "#{finder} group by id,l_id order by l_id desc, position asc, node_name asc" + "#{finder} group by id,l_id order by l_id desc, position asc" end end # Common @@ -500,7 +500,7 @@ def r_content_for_layout # Display the page's default title def r_title_for_layout - "<% if @title_for_layout -%><%= @title_for_layout %><% elsif @node && !@node.new_record? -%><%= @node.rootpath %><% elsif @node.parent -%><%= @node.parent.rootpath %><% else -%>" + + "<% if @title_for_layout -%><%= @title_for_layout %><% elsif @node && !@node.new_record? -%><%= @node.title %><% elsif @node.parent -%><%= @node.parent.short_path %><% else -%>" + expand_with + "<% end -%>" end diff --git a/lib/zena/use/fixtures.rb b/lib/zena/use/fixtures.rb index a7d86f5f..ecd173a9 100644 --- a/lib/zena/use/fixtures.rb +++ b/lib/zena/use/fixtures.rb @@ -122,21 +122,24 @@ def self.load_fixtures end end - define_method(table_name + "_id") do |fixture| + define_method(table_name + "_id") do |*fixtures| raise Exception.new("$_test_site is blank!") if $_test_site.blank? - Zena::FoxyParser::id($_test_site, fixture) + res = fixtures.map {|f| Zena::FoxyParser::id($_test_site, f) } + fixtures.size > 1 ? res : res.first end end if table_name == 'nodes' || table_name == 'zips' - define_method(table_name + "_zip") do |fixture| - # needed by additions_test - fixture_name = table_name == 'zips' ? fixture.to_s : "#{$_test_site}_#{fixture}" - if fix = @@loaded_fixtures[table_name][fixture_name] - fix.instance_eval { @fixture['zip'].to_i } - else - raise StandardError, "No fixture with name '#{fixture_name}' found for table '#{table_name}'" + define_method(table_name + "_zip") do |*fixtures| + res = fixtures.map do |fixture| + fixture_name = table_name == 'zips' ? fixture.to_s : "#{$_test_site}_#{fixture}" + if fix = @@loaded_fixtures[table_name][fixture_name] + fix.instance_eval { @fixture['zip'].to_i } + else + raise StandardError, "No fixture with name '#{fixture_name}' found for table '#{table_name}'" + end end + fixtures.size > 1 ? res : res.first end end diff --git a/lib/zena/use/forms.rb b/lib/zena/use/forms.rb index 446cd12b..c857092c 100644 --- a/lib/zena/use/forms.rb +++ b/lib/zena/use/forms.rb @@ -276,7 +276,14 @@ def form_hidden_fields(opts) end else # no ajax - # FIXME + + if node.will_be?(Node) + # Nested contexts: + # 1. @node + # 2. var1 = @node.children + # 3. var1_new = Node.new + hidden_fields['node[parent_id]'] = "<%= #{node.opts[:new_keys] ? "#{node.up}.zip" : "#{node}.parent_zip"} %>" + end cancel = "" # link to normal node ? end diff --git a/lib/zena/use/html_tags.rb b/lib/zena/use/html_tags.rb index c3cacbc6..ede022f3 100644 --- a/lib/zena/use/html_tags.rb +++ b/lib/zena/use/html_tags.rb @@ -14,7 +14,7 @@ def form_groups #TODO: test # Return the list of possible templates def form_skins - @form_skins ||= secure!(Skin) { Skin.find(:all, :order=>'node_name ASC') }.map {|r| [r.title, r.zip]} + @form_skins ||= secure!(Skin) { Skin.find(:all, :order=>'zip ASC') }.map {|r| [r.title, r.zip]} end # Display an input field to select an id. The user can enter an id or a name in the field and the diff --git a/lib/zena/use/i18n.rb b/lib/zena/use/i18n.rb index 8b681c88..8e08ee2f 100644 --- a/lib/zena/use/i18n.rb +++ b/lib/zena/use/i18n.rb @@ -260,6 +260,7 @@ def r_wrong_lang(params = @params) def r_load if dict = @params[:dictionary] + # FIXME: replace @options[:base_path] by @options[:skin_id] dict_content, absolute_url, base_path, doc = @options[:helper].send(:get_template_text, dict, @options[:base_path]) return parser_error("dictionary #{dict.inspect} not found") unless base_path # Lazy dictionary used for literal resolution diff --git a/lib/zena/use/ml_index.rb b/lib/zena/use/ml_index.rb index b7c9addc..57d68b9a 100644 --- a/lib/zena/use/ml_index.rb +++ b/lib/zena/use/ml_index.rb @@ -8,7 +8,7 @@ def self.included(base) def rebuild_index_with_multi_lingual! # We call rebuild_index_without_multi_lingual first with our hack - # to avoid inclusion order probles with fulltext index. + # to avoid inclusion order problems with fulltext index. # Skip multi lingual indices @index_langs = [] @@ -23,7 +23,8 @@ def rebuild_index_with_multi_lingual! self.version = version @properties = version.prop @index_langs = nil # force rebuild - property_index + # Build ml index for each version + rebuild_index_without_multi_lingual! end end @@ -40,11 +41,12 @@ def index_reader(group_name) end private + # Return the list of languages for which the current version is returned. def index_langs @index_langs ||= begin - v_id = version.id + v_id = version.id ref_lang = self.ref_lang - read = vhash['w'].merge(vhash['r']) + read = vhash['w'].merge(vhash['r']) current_site.lang_list.select do |lang| (read[lang] || read[ref_lang] || read.values.first) == v_id end diff --git a/lib/zena/use/node_name.rb b/lib/zena/use/node_name.rb deleted file mode 100644 index 7e9c700c..00000000 --- a/lib/zena/use/node_name.rb +++ /dev/null @@ -1,94 +0,0 @@ -module Zena - module Use - # This module handles the creation and maintenance of a 'node_name' and a path built from - # these node_names (fullpath). - # - # This module has to be included after Workflow so that v_status is properly - # set before 'sync_node_name' is called. - module NodeName - def self.included(base) - base.before_validation :sync_node_name - base.after_save :rebuild_children_fullpath - end - - private - # Store part of the title into the node (used when accessing the database with a - # console). - def sync_node_name - # Sync if we are publishing - if ((full_drive? && v_status == Zena::Status[:pub]) || - (can_drive? && vhash['r'][ref_lang].nil?)) - self.node_name = title - end - - unless node_name.blank? - # rebuild cached fullpath / basepath - rebuild_fullpath - rebuild_basepath - # we should use a full rebuild when there are corrupt values, - # if fullpath was blank, we have no way to find all children - @need_rebuild_children_fullpath = !new_record? && (fullpath_changed? || basepath_changed?) && !fullpath_was.blank? - end - - true - end - - def rebuild_fullpath - return unless new_record? || node_name_changed? || parent_id_changed? || fullpath.nil? - if parent = parent(false) - path = parent.fullpath.split('/') + [node_name] - else - path = [] - end - self[:fullpath] = path.join('/') - end - - def rebuild_basepath - return unless new_record? || node_name_changed? || parent_id_changed? || custom_base_changed? || basepath.nil? - if custom_base - self[:basepath] = self.fullpath - elsif parent = parent(false) - self[:basepath] = parent.basepath || "" - else - self[:basepath] = "" - end - end - - def rebuild_children_fullpath - return true unless @need_rebuild_children_fullpath - - # Update descendants - fullpath_new = self.fullpath - fullpath_new = "#{fullpath_new}/" if fullpath_was == '' - fullpath_re = fullpath_changed? ? %r{\A#{self.fullpath_was}} : nil - - bases = [self.basepath] - - i = 0 - batch_size = 100 - while true - list = Zena::Db.fetch_attributes(['id', 'fullpath', 'basepath', 'custom_base'], 'nodes', "fullpath LIKE #{Zena::Db.quote("#{fullpath_was}/%")} AND site_id = #{current_site.id} ORDER BY fullpath ASC LIMIT #{batch_size} OFFSET #{i * batch_size}") - - break if list.empty? - list.each do |rec| - rec['fullpath'].sub!(fullpath_re, fullpath_new) if fullpath_re - if rec['custom_base'] == Zena::Db::TRUE_RESULT - rec['basepath'] = rec['fullpath'] - bases << rec['basepath'] - else - while rec['fullpath'].size <= bases.last.size - bases.pop - end - rec['basepath'] = bases.last - end - id = rec.delete('id') - Zena::Db.execute "UPDATE nodes SET #{rec.map {|k,v| "#{Zena::Db.connection.quote_column_name(k)}=#{Zena::Db.quote(v)}"}.join(', ')} WHERE id = #{id}" - end - # 50 more - i += 1 - end - true - end - end # NodeName - end # Use -end # Zena diff --git a/lib/zena/use/prop_eval.rb b/lib/zena/use/prop_eval.rb index a6b668a0..d0e4b7e1 100644 --- a/lib/zena/use/prop_eval.rb +++ b/lib/zena/use/prop_eval.rb @@ -40,10 +40,34 @@ module ModelMethods def self.included(base) base.before_validation :merge_prop_eval + base.before_validation :need_set__id + base.before_save :set__id + base.alias_method_chain :rebuild_index!, :prop_eval end - def merge_prop_eval + def rebuild_index_with_prop_eval! + merge_prop_eval(true) + rebuild_index_without_prop_eval! + end + + def need_set__id + # Set DB identifier _id with latest title + # This is not the best place to put this code, but it's hard to make sure it is only executed + # in the correct order (after all properties are evaluated). + + @need_set__id = prop.title_changed? + true + end + + # TODO: decide if we need to keep this (Zena::Remote makes a much better console the MySQL console...) + def set__id + self._id = self.title if @need_set__id + end + + def merge_prop_eval(force_rebuild = false) return unless self[:vclass_id] + return unless prop.changed? || force_rebuild + if code = vclass.prop_eval hash = safe_eval(code) if hash.kind_of?(Hash) @@ -55,6 +79,7 @@ def merge_prop_eval false end end + rescue RubyLess::Error => err errors.add(:base, "Error during evaluation of #{klass} computed properties (#{err.message}).") return false # Will this properly halt the save chain ? diff --git a/lib/zena/use/query_node.rb b/lib/zena/use/query_node.rb index b3359567..3cdd2d0a 100644 --- a/lib/zena/use/query_node.rb +++ b/lib/zena/use/query_node.rb @@ -92,7 +92,7 @@ class Compiler < QueryBuilder::Processor set_main_table 'nodes' set_main_class 'Node' set_default :scope, 'self' - set_default :order, 'position ASC, node_name ASC' + set_default :order, 'position ASC, title ASC' set_default :context, 'self' after_process :insert_links_fields after_process :secure_query @@ -215,14 +215,14 @@ def process_field(field_name) # We use the add_key_value_table rule to avoid inserting the # same index access twice. - tbl = add_key_value_table('idx', index_table, field_name) do |tbl_name| + tbl = add_key_value_table(group_name, index_table, field_name) do |tbl_name| # This block is only executed once add_filter "#{tbl_name}.node_id = #{table}.id" add_filter "#{tbl_name}.key = #{quote(field_name)}" if group_name.to_s =~ /^ml_/ add_filter "#{tbl_name}.lang = #{quote(visitor.lang)}" end - distinct! + # no need for distinct, the new table makes a 1-1 relation end "#{tbl}.value" @@ -278,7 +278,7 @@ def process_function(arg, method) # ******** And maybe overwrite these ********** def parse_custom_query_argument(key, value) return nil unless value - super.gsub(/(RELATION_ID|NODE_ATTR)\(([^)]+)\)|(REF_DATE|NODE_ID)/) do + super.gsub(/(RELATION_ID|NODE_ATTR)\(([^)]+)\)|(REF_DATE|NODE_ID|VISITOR_LANG)/) do type, value = $1, $2 type ||= $3 case type @@ -302,6 +302,8 @@ def parse_custom_query_argument(key, value) context[:ref_date] ? insert_bind(context[:ref_date]) : 'now()' when 'NODE_ID' insert_bind("#{node_name}.id") + when 'VISITOR_LANG' + insert_bind("visitor.lang") end end end diff --git a/lib/zena/use/rendering.rb b/lib/zena/use/rendering.rb index 57ac125f..45a9e7cc 100644 --- a/lib/zena/use/rendering.rb +++ b/lib/zena/use/rendering.rb @@ -161,6 +161,9 @@ def page_cache_file(url = nil) path = ((path.empty? || path == "/") ? "/index" : URI.unescape(path)) ext = params[:format].blank? ? 'html' : params[:format] path << ".#{ext}" unless path =~ /\.#{ext}(\?\d+|)$/ + # + # QUERY_STRING in cached page ? + # # Do not cache filename with query or apache will not see it ! # if cachestamp_format?(params['format']) # path << "?" << make_cachestamp(@node, params['mode']) diff --git a/lib/zena/use/search.rb b/lib/zena/use/search.rb index 4f2a1580..2552f8fe 100644 --- a/lib/zena/use/search.rb +++ b/lib/zena/use/search.rb @@ -8,13 +8,13 @@ def match_query(query, options = {}) if query == '.' && node return options.merge( :conditions => ["parent_id = ?",node[:id]], - :order => 'node_name ASC' ) + :order => 'zip ASC' ) elsif !query.blank? if Zena::Db.adapter == 'mysql' && RAILS_ENV != 'test' - match = sanitize_sql(["MATCH (vs.idx_text_high,vs.idx_text_medium,vs.idx_text_low) AGAINST (?) OR nodes.node_name LIKE ?", query, "#{options[:name_query] || query.url_name}%"]) - select = sanitize_sql(["nodes.*, MATCH (vs.idx_text_high,vs.idx_text_medium,vs.idx_text_low) AGAINST (?) + (5 * (nodes.node_name LIKE ?)) AS score", query, "#{query}%"]) + match = sanitize_sql(["MATCH (vs.idx_text_high,vs.idx_text_medium,vs.idx_text_low) AGAINST (?)", query, "#{options[:name_query] || query.url_name}%"]) + select = sanitize_sql(["nodes.*, MATCH (vs.idx_text_high,vs.idx_text_medium,vs.idx_text_low) AGAINST (?) AS score", query, "#{query}%"]) else - match = sanitize_sql(["nodes.node_name LIKE ?", "#{query}%"]) + match = sanitize_sql(["nodes._id LIKE ?", "#{query}%"]) select = "nodes.*, #{match} AS score" end diff --git a/lib/zena/use/urls.rb b/lib/zena/use/urls.rb index e1f41e6f..20539dc8 100644 --- a/lib/zena/use/urls.rb +++ b/lib/zena/use/urls.rb @@ -1,6 +1,8 @@ module Zena module Use module Urls + ALLOWED_REGEXP = /\A(([a-zA-Z]+)([0-9]+)|([#{String::ALLOWED_CHARS_IN_FILENAME}]+))(_[a-zA-Z]+|)(\..+|)\Z/ + module Common CACHESTAMP_FORMATS = ['jpg', 'png', 'gif', 'css', 'js'] def prefix @@ -80,13 +82,13 @@ def zen_path(node, options={}) "#{abs_url_prefix}/#{pre}" # index page elsif node[:custom_base] "#{abs_url_prefix}/#{pre}/" + - node.basepath + + basepath_as_url(node.basepath) + (mode ? "_#{mode}" : '') + (asset ? ".#{asset}" : '') + (format == 'html' ? '' : ".#{format}") else "#{abs_url_prefix}/#{pre}/" + - ((node.basepath != '' && !node.basepath.nil? )? "#{node.basepath}/" : '') + + (node.basepath.blank? ? '' : "#{basepath_as_url(node.basepath)}/") + (node.klass.downcase ) + (node[:zip].to_s ) + (mode ? "_#{mode}" : '') + @@ -95,6 +97,16 @@ def zen_path(node, options={}) end append_query_params(path, opts) end + + def basepath_as_url(path) + path.split('/').map do |zip| + if n = secure(Node) { Node.find_by_zip(zip) } + n.title.url_name + else + nil + end + end.compact.join('/') + end def append_query_params(path, opts) if opts == {} @@ -421,6 +433,7 @@ def get_anchor_name(anchor_name) elsif node.will_be?(Version) 'version#{node.id}_#{id}' else + # ??? anchor_name # force compilation with Node context. Why ? #node_bak = @context[:node] @@ -449,7 +462,7 @@ def make_href(remote_target = nil, opts = {}) anchor = @params[:anchor] if anchor && !@params[:href] # Link on same page - return ::RubyLess.translate_string(self, "##{get_anchor_name(anchor)}") + return ::RubyLess.translate(self, "%Q{##{get_anchor_name(anchor)}}") end # if opts[:action] == 'edit' && !remote_target diff --git a/lib/zena/use/version_hash.rb b/lib/zena/use/version_hash.rb index 0ee98c7b..83583cdb 100644 --- a/lib/zena/use/version_hash.rb +++ b/lib/zena/use/version_hash.rb @@ -7,148 +7,148 @@ module Use # Technically, the vhash field contains two dictionaries "readonly" and "write". Each of these dictionaries # provide mapping from languages to version id. module VersionHash + def self.cached_values_from_records(records) + r_hash, w_hash = {}, {} + vhash = {'r' => r_hash, 'w' => w_hash} + lang = nil + n_pub = nil + records.each do |record| + if record['lang'] != lang + lang = record['lang'] + # highest status for this lang + if record['status'].to_i == Zena::Status[:pub] + # ok for readers & writers + w_hash[lang] = r_hash[lang] = record['id'].to_i + v_pub = record['publish_from'] - class << self - def cached_values_from_records(records) - r_hash, w_hash = {}, {} - vhash = {'r' => r_hash, 'w' => w_hash} - lang = nil - n_pub = nil - records.each do |record| - if record['lang'] != lang - lang = record['lang'] - # highest status for this lang - if record['status'].to_i == Zena::Status[:pub] - # ok for readers & writers - w_hash[lang] = r_hash[lang] = record['id'].to_i - v_pub = record['publish_from'] - - if v_pub.kind_of?(String) - v_pub = DateTime.parse(record['publish_from']) rescue Time.now - end - - if n_pub.nil? || v_pub < n_pub - n_pub = v_pub - end - else - # too high, only ok for writers - w_hash[lang] = record['id'].to_i + if v_pub.kind_of?(String) + v_pub = DateTime.parse(record['publish_from']) rescue Time.now end - elsif record['status'].to_i == Zena::Status[:pub] - # ok for readers - r_hash[lang] = record['id'].to_i - v_pub = DateTime.parse(record['publish_from']) rescue Time.now + if n_pub.nil? || v_pub < n_pub n_pub = v_pub end + else + # too high, only ok for writers + w_hash[lang] = record['id'].to_i + end + elsif record['status'].to_i == Zena::Status[:pub] + # ok for readers + r_hash[lang] = record['id'].to_i + v_pub = DateTime.parse(record['publish_from']) rescue Time.now + if n_pub.nil? || v_pub < n_pub + n_pub = v_pub end end - {:publish_from => n_pub, :vhash => vhash} end + {:publish_from => n_pub, :vhash => vhash} end - def version - @version ||= begin - if v_id = version_id - version = ::Version.find(v_id) - else - version = ::Version.new + module ModelMethods + def version + @version ||= begin + if v_id = version_id + version = ::Version.find(v_id) + else + version = ::Version.new + end + version.node = self + version end - version.node = self - version end - end - def version_id - access = can_see_redactions? ? vhash['w'] : vhash['r'] - access[visitor.lang] || access[self[:ref_lang]] || access.values.first - end + def version_id + access = can_see_redactions? ? vhash['w'] : vhash['r'] + access[visitor.lang] || access[self[:ref_lang]] || access.values.first + end - # Return the list of versions that are stored in the vhash and could be loaded depending - # on the visitor. - def visible_versions - @visible_versions ||= begin - ids = (vhash['w'].values + vhash['r'].values).uniq - ::Version.find(ids).tap do |list| - list.each do |version| - version.node = self + # Return the list of versions that are stored in the vhash and could be loaded depending + # on the visitor. + def visible_versions + @visible_versions ||= begin + ids = (vhash['w'].values + vhash['r'].values).uniq + ::Version.find(ids).tap do |list| + list.each do |version| + version.node = self + end end end end - end - def vhash - @vhash ||= JSON.parse(self[:vhash] || '{"r":{}, "w":{}}') - end + def vhash + @vhash ||= JSON.parse(self[:vhash] || '{"r":{}, "w":{}}') + end - def rebuild_vhash - cached = VersionHash.cached_values_from_records(connection.select_all("SELECT id,lang,status,publish_from FROM #{Version.table_name} WHERE node_id = #{self.id} ORDER BY lang ASC, status DESC", "Version Load")) - # We also rebuild publish_from here: yes, that's a leak with Workflow. - self[:publish_from] = cached[:publish_from] - self[:vhash] = cached[:vhash].to_json - @vhash = cached[:vhash] - end + def rebuild_vhash + cached = VersionHash.cached_values_from_records(connection.select_all("SELECT id,lang,status,publish_from FROM #{Version.table_name} WHERE node_id = #{self.id} ORDER BY lang ASC, status DESC", "Version Load")) + # We also rebuild publish_from here: yes, that's a leak with Workflow. + self[:publish_from] = cached[:publish_from] + self[:vhash] = cached[:vhash].to_json + @vhash = cached[:vhash] + end - private - def update_vhash - version = self.version + private + def update_vhash + version = self.version - case @current_transition[:name] - when :edit, :redit - vhash['w'][version.lang] = version.id - when :publish, :auto_publish - vhash['r'][version.lang] = vhash['w'][version.lang] = version.id - when :unpublish - vhash['r'].delete(version.lang) - when :remove - if v_id = vhash['r'][version.lang] - vhash['w'][version.lang] = v_id - end - when :destroy_version - v_id = version.id - lang = version.lang - if vhash['w'][lang] == v_id - # Writers were looking at old version - if vhash['r'][lang] && vhash['r'][lang] != v_id - # There is a publication that can be used - vhash['w'][lang] = v_id - else - # Nothing to see here for this lang - vhash['w'].delete(lang) - vhash['r'].delete(lang) + case @current_transition[:name] + when :edit, :redit + vhash['w'][version.lang] = version.id + when :publish, :auto_publish + vhash['r'][version.lang] = vhash['w'][version.lang] = version.id + when :unpublish + vhash['r'].delete(version.lang) + when :remove + if v_id = vhash['r'][version.lang] + vhash['w'][version.lang] = v_id + end + when :destroy_version + v_id = version.id + lang = version.lang + if vhash['w'][lang] == v_id + # Writers were looking at old version + if vhash['r'][lang] && vhash['r'][lang] != v_id + # There is a publication that can be used + vhash['w'][lang] = v_id + else + # Nothing to see here for this lang + vhash['w'].delete(lang) + vhash['r'].delete(lang) + end end - end - if vhash['w'].values == [] - if last = versions.last - # We have a last version (not destroying node) - vhash['w'][last.lang] = last.id + if vhash['w'].values == [] + if last = versions.last + # We have a last version (not destroying node) + vhash['w'][last.lang] = last.id + end end + + # force reload + @version = nil end + self[:vhash] = vhash.to_json + end - # force reload - @version = nil + # Overwrite MultiVersion. This is called before update. + def set_current_version_before_update + super + update_vhash end - self[:vhash] = vhash.to_json - end - # Overwrite MultiVersion. This is called before update. - def set_current_version_before_update - super - update_vhash - end + # Overwrite MultiVersion. This is called after create. + def set_current_version_after_create + update_vhash + Zena::Db.set_attribute(self, :vhash, self[:vhash]) + end - # Overwrite MultiVersion. This is called after create. - def set_current_version_after_create - update_vhash - Zena::Db.set_attribute(self, :vhash, self[:vhash]) - end + # Overwrite MultiVersion. This is called after a version is destroyed. + def version_destroyed + super + rebuild_vhash + end - # Overwrite MultiVersion. This is called after a version is destroyed. - def version_destroyed - super - rebuild_vhash - end - end + end # ModelMethods + end # VersionHash end end \ No newline at end of file diff --git a/lib/zena/use/zafu_safe_definitions.rb b/lib/zena/use/zafu_safe_definitions.rb index dedca4c0..137241d3 100644 --- a/lib/zena/use/zafu_safe_definitions.rb +++ b/lib/zena/use/zafu_safe_definitions.rb @@ -11,12 +11,14 @@ module ViewMethods safe_method :params => ParamsDictionary safe_method :now => {:method => 'Time.now', :class => Time} safe_method_for String, [:gsub, Regexp, String] => {:class => String, :pre_processor => true} - safe_method_for String, :upcase => {:class => String, :pre_processor => true} - safe_method_for Number, :to_s => {:class => String, :pre_processor => true} - safe_method_for Object, :blank? => Boolean + safe_method_for String, :upcase => {:class => String, :pre_processor => true} + safe_method_for String, :strip => {:class => String, :pre_processor => true} + safe_method_for String, :urlencode => {:class => String, :pre_processor => true, :method => :url_name} + safe_method_for Number, :to_s => {:class => String, :pre_processor => true} + safe_method_for Object, :blank? => Boolean - safe_method_for Node, [:kind_of?, String] => {:method => 'kpath_match?', :class => Boolean} - safe_method_for Node, [:kind_of?, Number] => {:method => 'has_role?', :class => Boolean} + safe_method_for Node, [:kind_of?, String] => {:method => 'kpath_match?', :class => Boolean} + safe_method_for Node, [:kind_of?, Number] => {:method => 'has_role?', :class => Boolean} safe_method_for Array, [:index, String] => {:class => Number, :nil => true} end # ViewMethods diff --git a/lib/zena/use/zafu_templates.rb b/lib/zena/use/zafu_templates.rb index 8ce980a1..24a5870a 100644 --- a/lib/zena/use/zafu_templates.rb +++ b/lib/zena/use/zafu_templates.rb @@ -10,25 +10,28 @@ module Common # Return a template's content from an url. If the url does not start with a '/', we try by replacing the # first element with the current skin_name and if it does not work, we try with the full url. If the url # start with a '/' we use the full url directly. - def get_template_text(path, base_path) + def get_template_text(path, section_id = nil) if path =~ DEFAULT_PATH filepath = File.join(DEFAULT_TEMPLATES_PATH, "#{$1}.zafu") text = File.exist?(filepath) ? File.read(filepath) : nil - return text, path, base_path + return text, path, nil elsif @skin.nil? && path == 'Node' filepath = File.join(DEFAULT_TEMPLATES_PATH, "default/#{path}.zafu") text = File.exist?(filepath) ? File.read(filepath) : nil - return text, path, base_path - elsif res = find_document_for_template(path, base_path) - doc, base_path = res - # text, fullpath (for recursion testing), base_path - return doc.text, doc.fullpath, base_path, doc + return text, path, nil else - nil + path = path.split('/').map {|s| String.from_filename(s) } + if doc = find_document_for_template(path, section_id) + # text, fullpath (for recursion testing), base_path + return doc.text, doc.fullpath, doc.section_id, doc + else + nil + end end end - # Return the zen_path ('/en/image34.png') for an asset given its name ('img/footer.png'). + # Return the zen_path ('/en/image34.png') for an asset given its (urlencoded) + # path ('img/footer.png'). # The rule is not the same whether we are rendering a template and find tags # or if we are parsing assets in a CSS file. def template_url_for_asset(opts) @@ -38,8 +41,7 @@ def template_url_for_asset(opts) end if opts[:parse_assets] - base_path = opts[:base_path] || '' - base_path = base_path[1..-1] if base_path[0..0] == '/' + parent_id = opts[:parent].id if source =~ /\A(.*)_(\w+)\Z/ # if the element was not found, maybe it was not a name with underscore but it was an image mode @@ -48,48 +50,55 @@ def template_url_for_asset(opts) paths = [] if source[0..0] == '/' + # ignore parent + parent_id = current_site.root_id paths << source[1..-1] paths << src2[1..-1] if src2 else - paths << (base_path + '/' + source) - paths << (base_path + '/' + src2) if src2 + paths << source + paths << src2 if src2 end - # make sure path elements are url_names + # Retrieve titles from urlencoding paths.map! do |path| - res = [] + res = nil + par_id = parent_id path.split('/').each do |e| if e == '..' + # forces absolute path + par_id = current_site.root_id + res ||= opts[:parent].fullpath_as_title res.pop else - res << e.url_name + res ||= [] + res << String.from_filename(e) end end - res.join('/') + [res, par_id] end - if asset = secure(Document) { Document.find_by_path(paths[0]) } - elsif src2 && (asset = secure(Document) { Document.find_by_path(paths[1]) }) + if asset = secure(Document) { Document.find_by_path(*paths[0]) } + elsif src2 && (asset = secure(Document) { Document.find_by_path(*paths[1]) }) mode = mode2 else return nil end else - src2 = source.split('/').map {|s| s.url_name!}.join('/') + src2 = source.split('/').map {|s| String.from_filename(s) } if source =~ /\A(.*)_(\w+)\Z/ source, mode = $1, $2 end + source = source.split('/').map {|f| String.from_filename(f) } - unless res = find_document_for_template(source, opts[:base_path]) + unless asset = find_document_for_template(source, opts[:base_path]) # '_...' did not mean mode but was an old name. mode = nil - return nil unless res = find_document_for_template(src2, opts[:base_path]) + return nil unless asset = find_document_for_template(src2, opts[:base_path]) end - asset, base_path = res - self.renamed_assets[asset.fullpath] = asset + self.renamed_assets[[asset.section_id, asset.title]] = asset end data_path(asset, :mode => mode) @@ -113,7 +122,7 @@ def fullpath_from_template_url(template_url=params[:t_url]) # Return the template path without '.erb' extension in case we need to append '_form' # from a template's url. The expected url is of the form '/skin/Klass-mode/partial' def template_path_from_template_url(template_url=params[:t_url]) - if template_url =~ /\A\.|[^\w\+\._\-\/\$]/ + if template_url =~ /\A\.|[^ #{String::ALLOWED_CHARS_IN_FILEPATH}]/ raise Zena::AccessViolation.new("'template_url' contains illegal characters : #{template_url.inspect}") end @@ -170,41 +179,35 @@ def default_template_url(opts = {}) # Without a leading slash "special/Node" # 1. Search for a Document with fullpath [current directory]/special/Node # 2. Search anywhere in the master skin for a document named 'Node' - def find_document_for_template(src, base_path = nil) - if src =~ /^\// + def find_document_for_template(src, section_id = nil) + src = src.split('/') unless src.kind_of?(Array) + + if src[0] == '' # Starts with '/' : first part of the path is a Skin - url = src[1..-1].split('/') - else + section_id = nil + # remove blank + src.shift + # get skin + return nil unless skin = get_skin(src.shift) + section_id = skin.id + elsif section_id.nil? && @skin + section_id = @skin.id # does not start with '/' : look in current directory - folder = base_path.blank? ? [] : base_path.split('/') - url = folder + src.split('/') end - skin_name = url.shift - # TODO: can we move this initialization somewhere else ? self.expire_with_nodes ||= {} self.renamed_assets ||= {} - return nil unless skin = get_skin(skin_name) - - fullpath = (skin.fullpath.split('/') + url).join('/') - - unless document = self.expire_with_nodes[fullpath] - unless document = secure(Document) { Document.find_by_path(fullpath) } - document = secure(Document) { Document.first(:conditions => ['node_name = ? AND section_id = ?', url.last, skin.id]) } - self.expire_with_nodes[document.fullpath] = document if document + unless document = self.expire_with_nodes[[section_id, src]] + unless document = secure(Document) { Document.find_by_path(src, section_id) } + # find anywhere in Skin + document = secure(Document) { Document.find_by_title(src.last, :conditions => ['section_id = ?', section_id]) } end - self.expire_with_nodes[fullpath] = document if document + self.expire_with_nodes[[section_id, src]] = document if document end - if document - # Return document and base_path to document - base_path = "#{([skin.node_name] + url[0..-2]).join('/')}" - [document, base_path] - else - nil - end + document end end # Common @@ -241,11 +244,16 @@ def template_url(opts={}) :order => "length(tkpath) DESC" )} - # Path as seen from zafu: - zafu_url = template.fullpath.gsub(/^#{@skin.fullpath}/, @skin.node_name) + path_in_skin = template.fullpath.gsub(/^#{@skin.fullpath}\//, '') + + if path_in_skin == template.zip.to_s + zafu_url = [@skin.title, template.title] + else + zafu_url = [@skin.title] + Node.fullpath_map(path_in_skin, :title) + end - rel_path = current_site.zafu_path + "/#{zafu_url}/#{lang_path}/_main.erb" + rel_path = current_site.zafu_path + "/#{zafu_url.map(&:to_filename).join('/')}/#{lang_path}/_main.erb" path = SITES_ROOT + rel_path if !File.exists?(path) || params[:rebuild] @@ -255,7 +263,7 @@ def template_url(opts={}) nil end - unless rebuild_template(template, opts.merge(:zafu_url => zafu_url, :rel_path => rel_path, :dev_mode => (dev_box?(mode, format)))) + unless rebuild_template(template, opts.merge(:zafu_url => zafu_url.join('/'), :rel_path => rel_path, :dev_mode => (dev_box?(mode, format)))) return default_template_url(opts) end end @@ -314,11 +322,11 @@ def get_skin(skin_name = nil) elsif skin = @skins[skin_name] return skin else - skin =secure(Skin) { Skin.find_by_node_name(skin_name)} + skin =secure(Skin) { Skin.find_by_title(skin_name) } end if skin - @skins[skin.node_name] = skin + @skins[skin.title] = skin end skin @@ -353,13 +361,14 @@ def get_node_context # a filesystem path inside SITES_ROOT where the built template should be compiled. def rebuild_template(template, opts = {}) zafu_url, rel_path, insert_dev = opts[:zafu_url], opts[:rel_path], opts[:dev_mode] + # clear : FileUtils::rmtree(File.dirname(SITES_ROOT + rel_path)) # Cache loaded templates and skins if template self.expire_with_nodes = { - template.fullpath => template + template.fullpath_as_title => template } end @@ -449,7 +458,7 @@ def dev_skin_options [ ['off', nil ], ['any', 0 ], - ] + skins.map {|s| [ s.node_name, s.zip ] } + [ + ] + skins.map {|s| [ s.title, s.zip ] } + [ ['rescue', -1 ], ] end diff --git a/lib/zena/use/zazen.rb b/lib/zena/use/zazen.rb index f5d2b3e2..610fcd03 100644 --- a/lib/zena/use/zazen.rb +++ b/lib/zena/use/zazen.rb @@ -120,7 +120,7 @@ def make_link(opts) if %w{true [id] [zip]}.include?(anchor) anchor_value = "node#{node.zip}" elsif anchor =~ /\[(.+)\]/ - anchor_value = $1 == 'node_name' ? node.node_name : node.prop[$1] + anchor_value = node.prop[$1].url_name else anchor_value = anchor end @@ -208,11 +208,12 @@ def make_image(opts) # Create a gallery from a list of images. See ApplicationHelper#zazen for details. def make_gallery(ids=[], opts={}) + node = opts[:node] || @node if ids == [] - images = secure(Image) { Image.find(:all, :conditions => ["parent_id = ?", (opts[:node] || @node)[:id]], :order => "position ASC, node_name ASC")} + images = node.find(:all, 'images') else ids = ids.map{|i| i.to_i} - images = ids == [] ? nil : secure(Document) { Document.find(:all, :conditions=>"zip IN (#{ids.join(',')})") } + images = secure(Document) { Document.find(:all, :conditions=>"zip IN (#{ids.join(',')})") } # order like ids : images.sort! {|a,b| ids.index(a[:zip].to_i) <=> ids.index(b[:zip].to_i) } if images end @@ -244,7 +245,7 @@ def list_nodes(ids=[], opts={}) docs = node.find(:all, 'images') else ids = ids.map{|i| i.to_i} - docs = ids == [] ? nil : secure!(Document) { Document.find(:all, :order=>'node_name ASC', :conditions=>"zip IN (#{ids.join(',')})") } + docs = ids == [] ? nil : secure!(Document) { Document.find(:all, :conditions=>"zip IN (#{ids.join(',')})") } # order like ids : docs.sort! {|a,b| ids.index(a[:zip].to_i) <=> ids.index(b[:zip].to_i) } if docs end diff --git a/locale/fr/zena.mo b/locale/fr/zena.mo index 1b967646..45102954 100644 Binary files a/locale/fr/zena.mo and b/locale/fr/zena.mo differ diff --git a/locale/fr/zena.po b/locale/fr/zena.po index 32e0c074..2ee9473b 100644 --- a/locale/fr/zena.po +++ b/locale/fr/zena.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: version 0.0.1\n" "POT-Creation-Date: 2010-06-02 16:42+0200\n" -"PO-Revision-Date: 2010-06-02 16:43+0100\n" +"PO-Revision-Date: 2010-09-28 17:41+0100\n" "Last-Translator: Gaspard Bucher \n" "Language-Team: fr \n" "MIME-Version: 1.0\n" @@ -311,7 +311,7 @@ msgstr "modifier la relation" #: app/views/relations/index.erb:1 #: lib/zena/use/display.rb:267 msgid "manage relations" -msgstr "gestion des rôles" +msgstr "gestion des relations" #: app/views/relations/new.erb:1 #, fuzzy diff --git a/public/javascripts/zena.js b/public/javascripts/zena.js index 9ab1044a..f0e1286a 100644 --- a/public/javascripts/zena.js +++ b/public/javascripts/zena.js @@ -602,13 +602,13 @@ Zena.Div_editor.prototype = { Zena.draggable = function(dom_id, drag_handle, revert) { revert = revert == undefined ? true : revert - new Draggable(dom_id, {ghosting:true, revert:revert, handle:drag_handle}); if (drag_handle) { - if ($(dom_id).select('.' + drag_handle) != []) { + if ($(dom_id).select('.' + drag_handle) == []) { // insert span $(dom_id).insert({top: " "}); } } + new Draggable(dom_id, {ghosting:true, revert:revert, handle:drag_handle}); } Zena.select_tab = function(name) { diff --git a/public/stylesheets/admin.css b/public/stylesheets/admin.css index c2296c65..dd854378 100644 --- a/public/stylesheets/admin.css +++ b/public/stylesheets/admin.css @@ -8,8 +8,8 @@ /* ADMIN USERS, GROUPS */ .admin_links { margin:18px; border:1px solid #35462B; background:#ccc; padding:0;} .admin_links li { padding:0;} -#context .admin_links li a { margin:0; border-top:1px solid #35462B; padding:3px; font-size:90%; color:black; display:block;} -#context .admin_links li:first-child a { border:0; } +.admin_links li a { margin:0; border-top:1px solid #35462B; padding:3px; font-size:90%; color:black; display:block;} +.admin_links li:first-child a { border:0; } .admin_links li a:hover { background:#999; } .admin_links li a.on {background:#eee;} .disabled img { opacity:0.4;} diff --git a/public/stylesheets/popup.css b/public/stylesheets/popup.css index d420eac0..809e9b0c 100644 --- a/public/stylesheets/popup.css +++ b/public/stylesheets/popup.css @@ -121,7 +121,7 @@ ul.infos li { padding:0.4em 0.4em; list-style:none; display:block; } .drive ul { list-style:none; padding:5px;} .drive li p { font-weight:normal;} .drive li select { width: 100%;} -.drive li #node_name { width: 95%;} +.drive li #title { width: 95%;} .drive li.submit { text-align:right; padding-top:1em;} .select_id span { margin-left:0.2em;} diff --git a/test/custom_queries/complex.host.yml b/test/custom_queries/complex.host.yml index 5c494430..b77812ea 100644 --- a/test/custom_queries/complex.host.yml +++ b/test/custom_queries/complex.host.yml @@ -77,6 +77,7 @@ Node: # all formations are created inside the course = project. This is why # form.project_id == course_id. - LEFT JOIN (SELECT nodes.project_id AS course_id, flink.target_id AS emp_id, MAX(nodes.event_at) AS last_date FROM nodes INNER JOIN links AS flink ON nodes.id = flink.source_id AND flink.relation_id = RELATION_ID(assigned_formation) AND (flink.status IS NULL OR flink.status = 100) GROUP BY flink.target_id, nodes.project_id) AS form ON courses.id = form.course_id AND form.emp_id = NODE_ID + - INNER JOIN idx_nodes_ml_strings AS _ml1 ON courses.id = _ml1.node_id AND _ml1.key = 'title' AND _ml1.lang = VISITOR_LANG where: # get all assigned jobs (links) - links.source_id = NODE_ID @@ -88,13 +89,12 @@ Node: - li1.relation_id = RELATION_ID(assigned_course) - courses.id = li1.source_id group: courses.id - order: priority DESC, last_date ASC, courses.node_name ASC + order: priority DESC, last_date ASC, _ml1.value ASC course_emp_date: main_table: employees select: - employees.id - - employees.node_name - employees.publish_from - employees.zip - employees.vclass_id @@ -118,11 +118,12 @@ Node: join_tables: employees: - LEFT JOIN (SELECT nodes.project_id AS project_id, flink.target_id AS emp_id, MAX(nodes.event_at) AS last_date FROM nodes INNER JOIN links AS flink ON nodes.id = flink.source_id AND flink.relation_id = RELATION_ID(assigned_formation) AND (flink.status IS NULL OR flink.status = 100) GROUP BY flink.target_id, nodes.project_id) AS form ON form.emp_id = employees.id AND form.project_id = NODE_ID + - INNER JOIN idx_nodes_ml_strings AS _ml1 ON employees.id = _ml1.node_id AND _ml1.key = 'title' AND _ml1.lang = VISITOR_LANG where: - employees.id = li1.source_id AND li1.relation_id = RELATION_ID(assigned_employee) AND li1.target_id = assigned_pages.project_id - assigned_pages.id = links.target_id AND links.relation_id = RELATION_ID(assigned_page) AND links.source_id = NODE_ID group: employees.id - order: employees.node_name ASC, IF(form.last_date,form.last_date,0) ASC + order: _ml1.value ASC, IF(form.last_date,form.last_date,0) ASC all_course_emp_date: @@ -131,7 +132,6 @@ Node: main_table: courses select: - courses.id - - courses.node_name - courses.publish_from - courses.zip - courses.vclass_id diff --git a/test/fixtures/files/Node-test.zafu b/test/fixtures/files/Node-test.zafu index e971e4eb..1f0c1a4d 100644 --- a/test/fixtures/files/Node-test.zafu +++ b/test/fixtures/files/Node-test.zafu @@ -120,7 +120,7 @@ This filter updates the "distant filter block test"

      distant filter block test

      -
      +

      @@ -128,8 +128,8 @@ This filter updates the "distant filter block test"

      filter block test

      - -
      + +
      diff --git a/test/fixtures/files/translations_fr.yml b/test/fixtures/files/translations_fr.yml index 0e888cc2..5e48efe0 100644 --- a/test/fixtures/files/translations_fr.yml +++ b/test/fixtures/files/translations_fr.yml @@ -3,5 +3,5 @@ translations: words: les mots date_format: '[%d.%m]' # used to translate dynamic key - status: statut + 'status title': statut lang_en: anglais \ No newline at end of file diff --git a/test/functional/nodes_controller_commit_test.rb b/test/functional/nodes_controller_commit_test.rb index 268d6740..d4590fe9 100644 --- a/test/functional/nodes_controller_commit_test.rb +++ b/test/functional/nodes_controller_commit_test.rb @@ -29,7 +29,7 @@ def set_visitor node_list = assigns(:nodes) nodes = {} node_list.each do |n| - nodes[n.node_name] = n + nodes[n.title] = n end assert skin = nodes['jet30'] assert_kind_of Skin, skin diff --git a/test/functional/nodes_controller_test.rb b/test/functional/nodes_controller_test.rb index ec62a559..139efff6 100644 --- a/test/functional/nodes_controller_test.rb +++ b/test/functional/nodes_controller_test.rb @@ -445,7 +445,7 @@ def test_cache_xml_format with_caching do assert !File.exist?("#{SITES_ROOT}/test.host/public/fr/#{name}") login(:lion) - doc = secure!(Template) { Template.create('node_name'=>'Node', 'format'=>'xml', 'text' => '</node>', 'parent_id'=>nodes_id(:default))} + doc = secure!(Template) { Template.create('title'=>'Node', 'format'=>'xml', 'text' => '<?xml version="1.0" encoding="utf-8"?><node><title do="title"/></node>', 'parent_id'=>nodes_id(:default))} assert !doc.new_record?, "Not a new record" assert doc.publish login(:anon) @@ -474,7 +474,7 @@ def test_update_l_status def test_ics_format_not_anon preserving_files('test.host/zafu') do login(:lion) - doc = secure!(Template) { Template.create("node_name"=>"Project", "format"=>"ics", "summary"=>"", 'text' => "<r:notes in='site' order='event_at asc'> + doc = secure!(Template) { Template.create("title"=>"Project", "format"=>"ics", "summary"=>"", 'text' => "<r:notes in='site' order='event_at asc'> BEGIN:VCALENDAR VERSION:2.0 PRODID:-//hacksw/handcal//NONSGML v1.0//EN @@ -526,7 +526,7 @@ def test_cache_css_auto_publish def test_create_nodes_from_folder login(:tiger) preserving_files('/test.host/data') do - parent = secure!(Project) { Project.create(:node_name => 'import', :parent_id => nodes_id(:zena)) } + parent = secure!(Project) { Project.create(:title => 'import', :parent_id => nodes_id(:zena)) } assert !parent.new_record?, "Not a new record" nodes = secure!(Node) { Node.create_nodes_from_folder(:folder => File.join(Zena::ROOT, 'test', 'fixtures', 'import'), :parent_id => parent[:id] )}.values @@ -537,14 +537,14 @@ def test_create_nodes_from_folder assert_equal 4, nodes.size bird, doc = nil, nil nodes.each do |n| - bird = n if n.node_name == 'bird' - doc = n if n.node_name == 'document' + bird = n if n.title == 'bird' + doc = n if n.title == 'document' end - simple = secure!(Node) { Node.find_by_node_name_and_parent_id('simple', parent[:id]) } - photos = secure!(Node) { Node.find_by_node_name_and_parent_id('photos', parent[:id]) } + simple = secure!(Node) { Node.find_by_parent_title_and_kpath(parent.id, 'simple') } + photos = secure!(Node) { Node.find_by_parent_title_and_kpath(parent.id, 'Photos !') } - assert_equal 'bird', bird.node_name - assert_equal 'simple', simple.node_name + assert_equal 'bird', bird.title + assert_equal 'simple', simple.title assert_equal 'jpg', bird.ext assert_equal 'Le septième ciel', bird.text versions = secure!(Node) { Node.find(bird[:id]) }.versions @@ -607,7 +607,7 @@ def test_drive_popup get 'edit', :id => nodes_zip(:zena) assert_response :success assert_template 'nodes/edit' - assert_match %r{/default/Node-\+popupLayout/en/_main$}, @response.layout + assert_match %r{/Default skin/Node-%2BpopupLayout/en/_main$}, @response.layout end def test_crop_image @@ -666,7 +666,7 @@ def test_search def test_search_klass login(:anon) - get 'search', 'class' => 'Project', 'title' => 'a wiki with zena' + get 'search', 'class' => 'Project', 'title' => 'a wiki with Zena' assert nodes = assigns(:nodes) assert_equal [nodes_id(:wiki)], nodes.map {|r| r.id} end diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 658c8380..c5143f69 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -28,8 +28,10 @@ class UsersControllerTest < Zena::Controller::TestCase context "with an invalid layout" do setup do login(:lion) - Version.connection.execute "UPDATE #{Version.table_name} SET properties = '{\"data\":{\"text\":\"empty\"},\"json_class\":\"Property::Properties\"}' WHERE id = #{versions_id(:Node_admin_layout_zafu_en)}" + # Make a bad admin layout + Version.connection.execute "UPDATE #{Version.table_name} SET properties = '{\"data\":{\"title\":\"foo\",\"text\":\"empty\"},\"json_class\":\"Property::Properties\"}' WHERE id = #{versions_id(:Node_admin_layout_zafu_en)}" without_files('test.host/zafu') do + get 'index' get 'index' end end diff --git a/test/functional/versions_controller_test.rb b/test/functional/versions_controller_test.rb index ee4a2329..d1b0ef6a 100644 --- a/test/functional/versions_controller_test.rb +++ b/test/functional/versions_controller_test.rb @@ -27,7 +27,7 @@ def version_hash(version_ref, number = nil) should 'get a page rendered with zafu when getting a version' do get 'show', version_hash(:lake_red_en) assert_response :success - assert_match %r{default/Node/fr/_main.erb$}, @response.rendered[:template].to_s + assert_match %r{Default skin/Node/fr/_main.erb$}, @response.rendered[:template].to_s end end @@ -78,7 +78,7 @@ def test_parse_assets start =<<-END_CSS body { font-size:10px; } #header { background:url('bird.jpg') } - #footer { background:url('/projects/wiki/flower.jpg') } + #footer { background:url('/projects list/a wiki with Zena/flower.jpg') } END_CSS assert node.update_attributes(:text => start.dup) diff --git a/test/integration/multiple_hosts_test.rb b/test/integration/multiple_hosts_test.rb index f6e977c6..41e7329f 100644 --- a/test/integration/multiple_hosts_test.rb +++ b/test/integration/multiple_hosts_test.rb @@ -35,21 +35,21 @@ def test_visitor_anon end def test_cache - status_zip = nodes(:zena, :status).zip + node_zip = nodes(:zena, :people).zip without_files('/test.host/public') do with_caching do - path = "/en/projects/cleanWater/page#{status_zip}.html" + path = "/en/section#{node_zip}.html" filepath = "#{RAILS_ROOT}/sites/test.host/public#{path}" assert !File.exist?(filepath) anon.get "http://test.host#{path}" assert_equal 200, anon.status assert File.exist?(filepath), "Cache file created" - node = nodes(:zena, :status) - assert_equal 1, CachedPage.count(:conditions => "path like '%page#{status_zip}%'") + node = nodes(:zena, :people) + assert_equal 1, CachedPage.count(:conditions => "path like '%section#{node_zip}%'") assert_not_equal 0, Zena::Db.fetch_attribute("SELECT COUNT(*) as count_all FROM cached_pages_nodes WHERE node_id = #{node[:id]}").to_i node.visitor = Thread.current[:visitor] node.sweep_cache - assert_equal 0, CachedPage.count(:conditions => "path like '%page#{status_zip}%'") + assert_equal 0, CachedPage.count(:conditions => "path like '%section#{node_zip}%'") assert_equal 0, Zena::Db.fetch_attribute("SELECT COUNT(*) as count_all FROM cached_pages_nodes WHERE node_id = #{node[:id]}").to_i assert !File.exist?(filepath) end diff --git a/test/integration/navigation_test.rb b/test/integration/navigation_test.rb index 70dfc702..25afcbbb 100644 --- a/test/integration/navigation_test.rb +++ b/test/integration/navigation_test.rb @@ -71,8 +71,8 @@ def test_out_of_oo_custom_base_set_lang assert_redirected_to "http://test.host/oo" # 2. navigating out of '/oo' but logged in and format is not data, custom_base url (format not in path) assert_equal 'en', session[:lang] - get 'http://test.host/fr/projects/cleanWater' - assert_redirected_to 'http://test.host/oo/projects/cleanWater' + get 'http://test.host/fr/page18.html' + assert_redirected_to 'http://test.host/oo/page18.html' assert_equal 'fr', session[:lang] follow_redirect! assert_response :success @@ -188,6 +188,11 @@ def test_set_lang_with_login assert_response :success assert_equal 'fr', session[:lang] end + + def test_url_with_custom_base + get 'http://test.host/en/projects-list/Clean-Water-project' + assert_response :success + end def test_nodes_redirect get 'http://test.host/nodes/30' @@ -227,10 +232,10 @@ def test_url_by_zip_without_lang_redirect end def test_url_by_path_without_lang_redirect - get 'http://test.host/projects/wiki' - assert_redirected_to 'http://test.host/en/projects/wiki' + get 'http://test.host/people' + assert_redirected_to 'http://test.host/en/people' follow_redirect! - assert_redirected_to 'http://test.host/en/project29.html' + assert_redirected_to 'http://test.host/en/section12.html' follow_redirect! assert_response :success end diff --git a/test/integration/query_node/basic.yml b/test/integration/query_node/basic.yml index 3fc5ce40..66bea7a1 100644 --- a/test/integration/query_node/basic.yml +++ b/test/integration/query_node/basic.yml @@ -4,39 +4,39 @@ default: node: 'cleanWater' visitor: 'ant' src: "" - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.parent_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id]" - res: "crocodiles, lake, lakeAddress, opening, status, track, water" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.parent_id = ? ORDER BY nodes.zip ASC}, @node.id]" + res: "Etat des travaux, The lake we love, it's a lake, water, crocodiles, super ouverture, Keeping things clean !" nodes: src: "nodes" - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.parent_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id]" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.parent_id = ? ORDER BY nodes.zip ASC}, @node.id]" pages: src: "pages" - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.kpath LIKE 'NP%' AND nodes.parent_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id]" - res: "crocodiles, status, track" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.kpath LIKE 'NP%' AND nodes.parent_id = ? ORDER BY nodes.zip ASC}, @node.id]" + res: "Etat des travaux, crocodiles, Keeping things clean !" letters: src: "letters" - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.kpath LIKE 'NNL%' AND nodes.parent_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id]" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.kpath LIKE 'NNL%' AND nodes.parent_id = ? ORDER BY nodes.zip ASC}, @node.id]" nodes_in_site: - sql: "%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} ORDER BY nodes.position ASC, nodes.node_name ASC}" + sql: "%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} ORDER BY nodes.zip ASC}" pages_in_project: - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.kpath LIKE 'NP%' AND nodes.project_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.get_project_id]" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.kpath LIKE 'NP%' AND nodes.project_id = ? ORDER BY nodes.zip ASC}, @node.get_project_id]" nodes_in_section: - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.section_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.get_section_id]" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.section_id = ? ORDER BY nodes.zip ASC}, @node.get_section_id]" nodes_in_self: - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.parent_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id]" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.parent_id = ? ORDER BY nodes.zip ASC}, @node.id]" nodes_in_parent: - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.parent_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.parent_id]" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.parent_id = ? ORDER BY nodes.zip ASC}, @node.parent_id]" children: - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.parent_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id]" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.parent_id = ? ORDER BY nodes.zip ASC}, @node.id]" # --- fixed up to here @@ -44,80 +44,80 @@ pages_or_letters: context: node: zena src: pages or letters - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND ((nodes.kpath LIKE 'NP%' AND nodes.parent_id = ?) OR (nodes.kpath LIKE 'NNL%' AND nodes.parent_id = ?)) GROUP BY id ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id, @node.id]" - res: "collections, letter, nature, people, projects, skins" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND ((nodes.kpath LIKE 'NP%' AND nodes.parent_id = ?) OR (nodes.kpath LIKE 'NNL%' AND nodes.parent_id = ?)) GROUP BY id ORDER BY nodes.zip ASC}, @node.id, @node.id]" + res: "people, projects list, Collections, Nature, zena enhancements, Skins (layout themes)" project: - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.get_project_id]" - res: 'cleanWater' + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.id = ? ORDER BY nodes.zip ASC}, @node.get_project_id]" + res: 'Clean Water project' many_alternatives: src: tagged in site or images in site or tags in site - sql: "%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes WHERE #{secure_scope('nodes')} AND ((nodes.id = links.source_id AND links.relation_id = _ID(node_has_tags)) OR (nodes.kpath LIKE 'NDI%' AND links.id = 0) OR (nodes.kpath LIKE 'NPT%' AND links.id = 0)) GROUP BY nodes.id ORDER BY nodes.position ASC, nodes.node_name ASC}" -# res: 'art, bird, cleanWater, flower, lake, menu, news, opening, tree' + sql: "%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes WHERE #{secure_scope('nodes')} AND ((nodes.id = links.source_id AND links.relation_id = _ID(node_has_tags)) OR (nodes.kpath LIKE 'NDI%' AND links.id = 0) OR (nodes.kpath LIKE 'NPT%' AND links.id = 0)) GROUP BY nodes.id ORDER BY nodes.zip ASC}" +# res: "art, bird, Clean Water project, flower, it's a lake, menu, news, opening, tree" alternatives_same_join: src: tagged in site or icons - sql: "[%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes WHERE #{secure_scope('nodes')} AND ((nodes.id = links.source_id AND links.relation_id = _ID(node_has_tags)) OR (nodes.id = links.target_id AND links.relation_id = _ID(node_has_an_icon) AND links.source_id = ?)) GROUP BY nodes.id ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id]" - res: "cleanWater, lake, opening" + sql: "[%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes WHERE #{secure_scope('nodes')} AND ((nodes.id = links.source_id AND links.relation_id = _ID(node_has_tags)) OR (nodes.id = links.target_id AND links.relation_id = _ID(node_has_an_icon) AND links.source_id = ?)) GROUP BY nodes.id ORDER BY nodes.zip ASC}, @node.id]" + res: "Clean Water project, it's a lake, super ouverture" same_name_as_class: context: node: 'opening' src: "set_tags" - sql: "[%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes WHERE #{secure_scope('nodes')} AND nodes.id = links.target_id AND links.relation_id = _ID(node_has_tags) AND links.source_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id]" - res: "art, news" + sql: "[%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes WHERE #{secure_scope('nodes')} AND nodes.id = links.target_id AND links.relation_id = _ID(node_has_tags) AND links.source_id = ? ORDER BY nodes.zip ASC}, @node.id]" + res: "Art, News list" notes_in_project: - res: "opening" + res: "super ouverture" vclass_in_project: src: "posts in project" - res: "opening" + res: "super ouverture" vlcass_or_pages: src: "(posts in project) or pages" - res: "crocodiles, opening, status, track" + res: "Etat des travaux, crocodiles, super ouverture, Keeping things clean !" find_relation: context: node: 'ant' class: Contact src: "favorites" - res: "nature" + res: "Nature" root: - res: "zena" + res: "Zena the wild CMS" children_with_order_clause: - src: "children order by node_name ASC" - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.parent_id = ? ORDER BY nodes.node_name ASC}, @node.id]" + src: "children order by position ASC" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.parent_id = ? ORDER BY nodes.position ASC}, @node.id]" notes_or_news: context: class: Project - sql: "[%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes WHERE #{secure_scope('nodes')} AND ((nodes.kpath LIKE 'NN%' AND nodes.parent_id = ? AND links.id = 0) OR (nodes.id = links.source_id AND links.relation_id = _ID(note_has_calendars) AND links.target_id = ?)) GROUP BY nodes.id ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id, @node.id]" + sql: "[%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes WHERE #{secure_scope('nodes')} AND ((nodes.kpath LIKE 'NN%' AND nodes.parent_id = ? AND links.id = 0) OR (nodes.id = links.source_id AND links.relation_id = _ID(note_has_calendars) AND links.target_id = ?)) GROUP BY nodes.id ORDER BY nodes.zip ASC}, @node.id, @node.id]" news_or_notes: context: class: Project - sql: "[%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes WHERE #{secure_scope('nodes')} AND ((nodes.id = links.source_id AND links.relation_id = _ID(note_has_calendars) AND links.target_id = ?) OR (nodes.kpath LIKE 'NN%' AND nodes.parent_id = ? AND links.id = 0)) GROUP BY nodes.id ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id, @node.id]" + sql: "[%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes WHERE #{secure_scope('nodes')} AND ((nodes.id = links.source_id AND links.relation_id = _ID(note_has_calendars) AND links.target_id = ?) OR (nodes.kpath LIKE 'NN%' AND nodes.parent_id = ? AND links.id = 0)) GROUP BY nodes.id ORDER BY nodes.zip ASC}, @node.id, @node.id]" order_l_status: context: node: art class: Tag - src: "tagged order by l_status ASC, node_name ASC" - sql: "[%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes WHERE #{secure_scope('nodes')} AND nodes.id = links.source_id AND links.relation_id = _ID(node_has_tags) AND links.target_id = ? ORDER BY links.status ASC, nodes.node_name ASC}, @node.id]" - res: "opening, cleanWater" + src: "tagged order by l_status ASC, zip ASC" + sql: "[%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes WHERE #{secure_scope('nodes')} AND nodes.id = links.source_id AND links.relation_id = _ID(node_has_tags) AND links.target_id = ? ORDER BY links.status ASC, nodes.zip ASC}, @node.id]" + res: "super ouverture, Clean Water project" paginate_one: src: "nodes in site order by zip limit 2 paginate p" # we sort by zip to avoid collation problems when some DB sort Capital letters first # and others are case-insensitive. sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} ORDER BY nodes.zip LIMIT 2 OFFSET ?}, ((params[:p].to_i > 0 ? params[:p].to_i : 1)-1)*2]" - res: "zena, people" + res: "Zena the wild CMS, people" paginate_two: context: @@ -125,4 +125,4 @@ paginate_two: p: 2 src: "nodes in site order by zip limit 2 paginate p" sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} ORDER BY nodes.zip LIMIT 2 OFFSET ?}, ((params[:p].to_i > 0 ? params[:p].to_i : 1)-1)*2]" - res: "ant, tiger" \ No newline at end of file + res: "Solenopsis Invicta, Panthera Tigris Sumatran" \ No newline at end of file diff --git a/test/integration/query_node/complex.yml b/test/integration/query_node/complex.yml index 620f089e..5098fb08 100644 --- a/test/integration/query_node/complex.yml +++ b/test/integration/query_node/complex.yml @@ -5,8 +5,8 @@ default: visitor: complex_admin site: complex src: "" - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.parent_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id]" - res: "courses, cskin, employees, jobs" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.parent_id = ? ORDER BY nodes.zip ASC}, @node.id]" + res: "cskin, list of employees, jobs, courses list" assigned_jobs: context: @@ -20,27 +20,28 @@ courses_assigned_to_driver_team: node: driver_team class: Page src: assigned_courses - res: "formulateProblems, transmitInformation" + res: "problem formulation, information transmission" all_courses_in_driver: context: node: driver class: Employee src: assigned_courses from pages in project - res: "dangerousTransportations, engine, formulateProblems, transmitInformation" + res: "dangerous transportations, problem formulation, information transmission, engine maintenance" all_courses_for_roger: context: node: roger class: Employee src: assigned_courses from pages in project from assigned_jobs - res: "dangerousTransportations, engine, fiberJunction, formulateProblems, radioUsage, secureASite, transmitInformation, winchUsage" + res: "dangerous transportations, problem formulation, information transmission, engine maintenance, secure a site, how to use the winch, how to use the radio, fiber junction" + all_courses_for_joe: context: node: joe class: Employee src: assigned_courses from pages in project from assigned_jobs - res: "fiberJunction, formulateProblems, radioUsage, secureASite, transmitInformation, winchUsage" + res: "problem formulation, information transmission, secure a site, how to use the winch, how to use the radio, fiber junction" all_courses_for_mike: context: @@ -49,21 +50,21 @@ all_courses_for_mike: src: assigned_courses from pages in project from assigned_jobs # TODO: optimization #sql: "[%Q{SELECT no1.*,li1.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes,nodes AS no1,links AS li1 WHERE no1.id = li1.target_id AND li1.relation_id = 512923747 AND li1.source_id = nodes.id AND nodes.kpath LIKE 'NP%' AND nodes.project_id = links.target_id AND links.relation_id = 813976280 AND links.source_id = \#{@node.id} AND (\#{@node.secure_scope('no1')}) GROUP BY no1.id ORDER BY no1.position ASC, no1.node_name ASC}]" - res: "fiberJunction, formulateProblems, radioUsage, respManagement, secureASite, teamMotivation, transmitInformation, vision, winchUsage" + res: "problem formulation, information transmission, secure a site, how to use the winch, how to use the radio, fiber junction, responsabilities management, motivate your team, our vision" all_achieved_formations_for_roger: context: node: roger class: Employee src: assigned_formations where l_status eq 100 - res: fiber2003, form2006, transm2001, transm2002, transp2004 + res: dtransp 2004, fiber 2003, formprobs 2006, transinfo 2001, transinfo 2002 custom_query_form_date: context: node: roger class: Employee - src: emp_form_dates order by node_name ASC - res: "dangerousTransportations, engine, fiberJunction, formulateProblems, radioUsage, secureASite, transmitInformation, winchUsage" + src: emp_form_dates order by title ASC + res: "dangerous transportations, engine maintenance, fiber junction, how to use the radio, how to use the winch, information transmission, problem formulation, secure a site" custom_query_form_with_where: context: @@ -71,21 +72,21 @@ custom_query_form_with_where: class: Employee date: 2005-03-01 src: "emp_form_dates where last_date is null or (repeat_every is not null and next_date lt #{date} + 6 month)" - res: "secureASite, winchUsage, engine, transmitInformation, fiberJunction, radioUsage" + res: "how to use the winch, secure a site, engine maintenance, information transmission, fiber junction, how to use the radio" find_employees_related_to_a_course__formulate_problems: context: node: transmit_information class: Course src: assigned_employees from jobs:project from assigned_pages - res: 'joe, mike, roger' + res: 'Roger Ubercool, Joe Friendly, Mike Mean' find_employees_related_to_a_course__fiber_junction: context: node: fiber_junction class: Course src: assigned_employees from jobs:project from assigned_pages - res: 'joe, mike, roger' + res: 'Roger Ubercool, Joe Friendly, Mike Mean' find_employees_related_to_a_course__vision: @@ -93,23 +94,23 @@ find_employees_related_to_a_course__vision: node: vision class: Course src: assigned_employees from jobs:project from assigned_pages - res: 'mike' + res: 'Mike Mean' course_emp_date: context: node: transmit_information class: Course src: "course_emp_dates" - res: "joe, mike, roger" + res: "Joe Friendly, Mike Mean, Roger Ubercool" all_course_emp_date: src: "assigned_employees from jobs:project from assigned_pages from courses in site" - res: "joe, mike, roger" + res: "Roger Ubercool, Joe Friendly, Mike Mean" courses_with_rep: - src: "courses where custom_a is not null in site order by node_name ASC" - res: "dangerousTransportations, engine, fiberJunction, radioUsage, respManagement, secureASite, teamMotivation, transmitInformation, vision, winchUsage" + src: "courses where custom_a is not null in site order by title ASC" + res: "dangerous transportations, engine maintenance, fiber junction, how to use the radio, how to use the winch, information transmission, motivate your team, our vision, responsabilities management, secure a site" it_should_use_alias_in_filters: src: "alias_query where event_at < now in site" - sql: "%Q{SELECT (log_at + INTERVAL 6 months) AS event_at FROM nodes WHERE #{secure_scope('nodes')} AND ((log_at + INTERVAL 6 months)) < now() ORDER BY nodes.position ASC, nodes.node_name ASC}" + sql: "%Q{SELECT (log_at + INTERVAL 6 months) AS event_at FROM nodes WHERE #{secure_scope('nodes')} AND ((log_at + INTERVAL 6 months)) < now() ORDER BY nodes.zip ASC}" diff --git a/test/integration/query_node/dates.yml b/test/integration/query_node/dates.yml index 76c7d833..2c355e74 100644 --- a/test/integration/query_node/dates.yml +++ b/test/integration/query_node/dates.yml @@ -7,15 +7,15 @@ default: now: src: "nodes where event_at < now" - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.event_at < now() AND nodes.parent_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id]" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.event_at < now() AND nodes.parent_id = ? ORDER BY nodes.zip ASC}, @node.id]" now_interval: src: "nodes where created_at > now - 4 days" - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.created_at > now() - INTERVAL 4 DAY AND nodes.parent_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id]" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.created_at > now() - INTERVAL 4 DAY AND nodes.parent_id = ? ORDER BY nodes.zip ASC}, @node.id]" year: src: "nodes where event_at.year < now.year" - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND year(nodes.event_at) < year(now()) AND nodes.parent_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id]" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND year(nodes.event_at) < year(now()) AND nodes.parent_id = ? ORDER BY nodes.zip ASC}, @node.id]" year_on_whatever: src: "nodes where id.year < now.year" diff --git a/test/integration/query_node/filters.yml b/test/integration/query_node/filters.yml index 8f5936ce..d7c63ce7 100644 --- a/test/integration/query_node/filters.yml +++ b/test/integration/query_node/filters.yml @@ -4,7 +4,7 @@ default: node: 'cleanWater' visitor: 'ant' src: "nodes where log_at = event_at in site" - sql: "%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.log_at = nodes.event_at ORDER BY nodes.position ASC, nodes.node_name ASC}" + sql: "%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.log_at = nodes.event_at ORDER BY nodes.zip ASC}" id_becomes_zip: src: "nodes where id ne 1" @@ -14,21 +14,21 @@ year_function: context: visitor: 'lion' src: "nodes where updated_at.year = 2007 in project" - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND year(nodes.updated_at) = 2007 AND nodes.project_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.get_project_id]" - sqlite3: "[%Q{SELECT nodes.* FROM nodes,versions WHERE #{secure_scope('nodes')} AND nodes.project_id = ? AND strftime('%Y', versions.updated_at)*1 = 2007 AND nodes.id = versions.node_id GROUP BY nodes.id ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.get_project_id]" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND year(nodes.updated_at) = 2007 AND nodes.project_id = ? ORDER BY nodes.zip ASC}, @node.get_project_id]" + sqlite3: "[%Q{SELECT nodes.* FROM nodes,versions WHERE #{secure_scope('nodes')} AND nodes.project_id = ? AND strftime('%Y', versions.updated_at)*1 = 2007 AND nodes.id = versions.node_id GROUP BY nodes.id ORDER BY nodes.zip ASC}, @node.get_project_id]" res: "crocodiles" two_fields: src: "notes where event_at = log_at in site" - sql: "%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.event_at = nodes.log_at AND nodes.kpath LIKE 'NN%' ORDER BY nodes.position ASC, nodes.node_name ASC}" + sql: "%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.event_at = nodes.log_at AND nodes.kpath LIKE 'NN%' ORDER BY nodes.zip ASC}" filter_l_status: context: node: art class: Tag src: "tagged where l_status > 5" - sql: "[%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes WHERE #{secure_scope('nodes')} AND links.status > 5 AND nodes.id = links.source_id AND links.relation_id = _ID(node_has_tags) AND links.target_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id]" - res: "cleanWater" + sql: "[%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes WHERE #{secure_scope('nodes')} AND links.status > 5 AND nodes.id = links.source_id AND links.relation_id = _ID(node_has_tags) AND links.target_id = ? ORDER BY nodes.zip ASC}, @node.id]" + res: "Clean Water project" param_filter: context: @@ -36,9 +36,8 @@ param_filter: class: Tag params: tag: c - src: 'nodes where node_name like "#{params[:tag]}%" in site' - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.node_name LIKE ? ORDER BY nodes.position ASC, nodes.node_name ASC}, \"#{params[:tag]}%\"]" - res: "cleanWater, collections, crocodiles" + src: 'nodes where zip like "#{params[:tag]}%" in site' + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.zip LIKE ? ORDER BY nodes.zip ASC}, \"#{params[:tag]}%\"]" param_filter_no_string: old_src: "notes where created_at gt REF_DATE - param:f in site" @@ -46,13 +45,13 @@ param_filter_no_string: sql: "/nodes.created_at\ > now\(\) - \? /" filter_literal: - src: "nodes where node_name like 'w%' in site" - sql: "/name LIKE 'w%'/" - res: "water, wiki, wikiSkin" + src: "nodes where kpath like 'NPP%' in site" + sql: "/kpath LIKE 'NPP%'/" + res: "Zena the wild CMS, Clean Water project, a wiki with Zena" filter_literal_first: src: "nodes where #{params[:tag]} = 'two'" - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND ? = 'two' AND nodes.parent_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, params[:tag], @node.id]" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND ? = 'two' AND nodes.parent_id = ? ORDER BY nodes.zip ASC}, params[:tag], @node.id]" links_in_merged_queries: # Some queries have links, others don't. Merging should not mess things up. @@ -61,38 +60,39 @@ links_in_merged_queries: class: Tag params: tag: 'op' - src: "(nodes where node_name like \"%#{params[:tag]}%\" and \"#{params[:tag]}\" ne '' in site) or (tagged where l_status > 5)" - res: "cleanWater, Node-+popupLayout, opening, people" + src: "(nodes where title like \"%#{params[:tag]}%\" and \"#{params[:tag]}\" ne '' in site) or (tagged where l_status > 5)" + # CleanWater is tagged, the rest contains 'op' + res: "people, Solenopsis Invicta, Clean Water project, Top menu, Node-+popupLayout" -pages_group_by_node_name: - src: 'pages group by node_name' - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.kpath LIKE 'NP%' AND nodes.parent_id = ? GROUP BY nodes.node_name ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id]" - res: "crocodiles, status, track" +pages_group_by_zip: + src: 'contacts in site group by zip' + sql: "%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.kpath LIKE 'NRC%' GROUP BY nodes.zip ORDER BY nodes.zip ASC}" + res: "Solenopsis Invicta, Panthera Tigris Sumatran, Panthera Leo Verneyi, The lake we love, Mr nobody" nodes_group_by_year: - src: "nodes in site group by log_at.year order by log_at.year asc, node_name ASC" - sql: "%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} GROUP BY year(nodes.log_at) ORDER BY year(nodes.log_at) ASC, nodes.node_name ASC}" - sqlite3: "%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} GROUP BY strftime('%Y', nodes.log_at)*1 ORDER BY strftime('%Y', nodes.log_at)*1 ASC, nodes.node_name ASC}" + src: "nodes in site group by log_at.year order by log_at.year asc, zip ASC" + sql: "%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} GROUP BY year(nodes.log_at) ORDER BY year(nodes.log_at) ASC, nodes.zip ASC}" + sqlite3: "%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} GROUP BY strftime('%Y', nodes.log_at)*1 ORDER BY strftime('%Y', nodes.log_at)*1 ASC, nodes.zip ASC}" negative_value: src: "notes where custom_a ne -10 in site" - sql: "%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.custom_a <> -10 AND nodes.kpath LIKE 'NN%' ORDER BY nodes.position ASC, nodes.node_name ASC}" + sql: "%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.custom_a <> -10 AND nodes.kpath LIKE 'NN%' ORDER BY nodes.zip ASC}" filter_through_links: src: "nodes where (set_tag_id = 33 and hot_id = 22) in site" sql: "/jn1\.zip = 33 AND jn2\.zip = 22.*nodes.id = links.source_id/" - res: "cleanWater" + res: "Clean Water project" filter_with_fullpath: # Get all objects under a given node (node the '/' to avoid self) src: "nodes where fullpath like \"#{fullpath}/%\" in site order by fullpath" sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.fullpath LIKE ? ORDER BY nodes.fullpath}, \"#{@node.fullpath}/%\"]" - res: 'crocodiles, lake, lakeAddress, opening, status, track, water' + res: "Etat des travaux, The lake we love, it's a lake, water, crocodiles, super ouverture, Keeping things clean !" class_filter: src: "nodes where class like Image or class = Project in site" - sql: "%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND (nodes.kpath LIKE 'NDI%' OR nodes.kpath = 'NPP') GROUP BY id ORDER BY nodes.position ASC, nodes.node_name ASC}" - res: 'bird, cleanWater, flower, lake, tree, wiki, zena' + sql: "%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND (nodes.kpath LIKE 'NDI%' OR nodes.kpath = 'NPP') GROUP BY id ORDER BY nodes.zip ASC}" + res: "Zena the wild CMS, Clean Water project, it's a lake, a wiki with Zena, bird, flower, Autumn Tree" class_filter_with_quotes: src: "nodes where class = 'Project' and title = 'k' in site" @@ -104,8 +104,8 @@ klass_filter: role_filter: src: "nodes where role = Original in site" - sql: "%Q{SELECT nodes.* FROM nodes,nodes_roles WHERE #{secure_scope('nodes')} AND (nodes_roles.node_id = nodes.id AND nodes_roles.role_id = 493147733) ORDER BY nodes.position ASC, nodes.node_name ASC}" - res: 'tree' + sql: "%Q{SELECT nodes.* FROM nodes,nodes_roles WHERE #{secure_scope('nodes')} AND (nodes_roles.node_id = nodes.id AND nodes_roles.role_id = 493147733) ORDER BY nodes.zip ASC}" + res: 'Autumn Tree' role_filter_string: src: "nodes where role = 'Original' in site" @@ -113,18 +113,18 @@ role_filter_string: role_as_relation_filter: src: "originals in site" - sql: "%Q{SELECT nodes.* FROM nodes,nodes_roles WHERE #{secure_scope('nodes')} AND nodes_roles.role_id = 493147733 AND nodes_roles.node_id = nodes.id ORDER BY nodes.position ASC, nodes.node_name ASC}" - res: 'tree' + sql: "%Q{SELECT nodes.* FROM nodes,nodes_roles WHERE #{secure_scope('nodes')} AND nodes_roles.role_id = 493147733 AND nodes_roles.node_id = nodes.id ORDER BY nodes.zip ASC}" + res: 'Autumn Tree' filter_by_parent: src: "nodes where parent_id = 11 in site" # nodes where parent.zip = ... - sql: "%Q{SELECT nodes.* FROM nodes,nodes AS jn1 WHERE #{secure_scope('nodes')} AND jn1.zip = 11 AND jn1.id = nodes.parent_id AND jn1.site_id = nodes.site_id ORDER BY nodes.position ASC, nodes.node_name ASC}" - res: 'collections, letter, nature, people, projects, skins' + sql: "%Q{SELECT nodes.* FROM nodes,nodes AS jn1 WHERE #{secure_scope('nodes')} AND jn1.zip = 11 AND jn1.id = nodes.parent_id AND jn1.site_id = nodes.site_id ORDER BY nodes.zip ASC}" + res: 'people, projects list, Collections, Nature, zena enhancements, Skins (layout themes)' #many_role_filter: # This is not working (or clause on 'indexed' fields is not supported right now) # src: "nodes where role = Original or role = Task in site" -# sql: "%Q{SELECT nodes.* FROM nodes,nodes_roles WHERE #{secure_scope('nodes')} AND ((nodes_roles.node_id = nodes.id AND nodes_roles.role_id = 493147733) OR (nodes_roles.node_id = nodes.id AND nodes_roles.role_id = 1793452896)) ORDER BY nodes.position ASC, nodes.node_name ASC}" +# sql: "%Q{SELECT nodes.* FROM nodes,nodes_roles WHERE #{secure_scope('nodes')} AND ((nodes_roles.node_id = nodes.id AND nodes_roles.role_id = 493147733) OR (nodes_roles.node_id = nodes.id AND nodes_roles.role_id = 1793452896)) ORDER BY nodes.zip ASC}" # res: 'nature' # filters on ml strings are in properties.yml \ No newline at end of file diff --git a/test/integration/query_node/properties.yml b/test/integration/query_node/properties.yml index 8e04d35d..e386424a 100644 --- a/test/integration/query_node/properties.yml +++ b/test/integration/query_node/properties.yml @@ -6,38 +6,38 @@ default: ml_title_where: src: "nodes where title like 'Etat%' in site" - sql: "%Q{SELECT nodes.* FROM idx_nodes_ml_strings AS id1,nodes WHERE #{secure_scope('nodes')} AND id1.value LIKE 'Etat%' AND id1.lang = 'fr' AND id1.key = 'title' AND id1.node_id = nodes.id GROUP BY nodes.id ORDER BY nodes.position ASC, nodes.node_name ASC}" - res: 'status' + sql: "%Q{SELECT nodes.* FROM idx_nodes_ml_strings AS ml1,nodes WHERE #{secure_scope('nodes')} AND ml1.value LIKE 'Etat%' AND ml1.lang = 'fr' AND ml1.key = 'title' AND ml1.node_id = nodes.id ORDER BY nodes.zip ASC}" + res: 'Etat des travaux' ml_title_where_with_or: src: "nodes where title like 'Etat%' or class = Letter in site" - sql: "%Q{SELECT nodes.* FROM idx_nodes_ml_strings AS id1,nodes WHERE #{secure_scope('nodes')} AND ((id1.value LIKE 'Etat%' AND id1.lang = 'fr' AND id1.key = 'title' AND id1.node_id = nodes.id) OR (nodes.kpath = 'NNL' AND id1.node_id = 0)) GROUP BY nodes.id ORDER BY nodes.position ASC, nodes.node_name ASC}" - res: 'letter, status' + sql: "%Q{SELECT nodes.* FROM idx_nodes_ml_strings AS ml1,nodes WHERE #{secure_scope('nodes')} AND ((ml1.value LIKE 'Etat%' AND ml1.lang = 'fr' AND ml1.key = 'title' AND ml1.node_id = nodes.id) OR (nodes.kpath = 'NNL' AND ml1.node_id = 0)) GROUP BY nodes.id ORDER BY nodes.zip ASC}" + res: 'Etat des travaux, zena enhancements' name_where: src: "contacts where name like 'Inv%' in site" - sql: "%Q{SELECT nodes.* FROM idx_nodes_strings AS id1,nodes WHERE #{secure_scope('nodes')} AND id1.value LIKE 'Inv%' AND id1.key = 'name' AND id1.node_id = nodes.id AND nodes.kpath LIKE 'NRC%' GROUP BY nodes.id ORDER BY nodes.position ASC, nodes.node_name ASC}" - res: 'ant' + sql: "%Q{SELECT nodes.* FROM idx_nodes_strings AS st1,nodes WHERE #{secure_scope('nodes')} AND st1.value LIKE 'Inv%' AND st1.key = 'name' AND st1.node_id = nodes.id AND nodes.kpath LIKE 'NRC%' ORDER BY nodes.zip ASC}" + res: 'Solenopsis Invicta' # TODO: Only implement with a proper use case. Ref [#190] # this is really more complex then it seems if we do not want too bad performance. Easiest way: # NOT EXISTS (SELECT 'x' FROM idx_nodes_ml_strings AS im WHERE im.node_id = nodes.id AND im.key = 'title' AND im.lang = 'fr') # indexed_value_is_null: # src: "projects where title is null in site" -# sql: "%Q{SELECT nodes.* FROM idx_nodes_ml_strings,nodes WHERE #{secure_scope('nodes')} AND idx_nodes_ml_strings.value IS NULL AND idx_nodes_ml_strings.key = 'title' AND idx_nodes_ml_strings.node_id = nodes.id AND nodes.kpath LIKE 'NPP%' GROUP BY nodes.id ORDER BY nodes.position ASC, nodes.node_name ASC}" +# sql: "%Q{SELECT nodes.* FROM idx_nodes_ml_strings,nodes WHERE #{secure_scope('nodes')} AND idx_nodes_ml_strings.value IS NULL AND idx_nodes_ml_strings.key = 'title' AND idx_nodes_ml_strings.node_id = nodes.id AND nodes.kpath LIKE 'NPP%' ORDER BY nodes.zip ASC}" # res: "wiki, zena" ml_title_order: context: node: 'cleanWater' src: "pages in site order by title asc limit 7" - sql: "%Q{SELECT nodes.* FROM idx_nodes_ml_strings AS id1,nodes WHERE #{secure_scope('nodes')} AND id1.lang = 'fr' AND id1.key = 'title' AND id1.node_id = nodes.id AND nodes.kpath LIKE 'NP%' GROUP BY nodes.id ORDER BY id1.value ASC LIMIT 7}" - res: "wiki, art, cleanWater, collections, crocodiles, default, status" + sql: "%Q{SELECT nodes.* FROM idx_nodes_ml_strings AS ml1,nodes WHERE #{secure_scope('nodes')} AND ml1.lang = 'fr' AND ml1.key = 'title' AND ml1.node_id = nodes.id AND nodes.kpath LIKE 'NP%' ORDER BY ml1.value ASC LIMIT 7}" + res: "a wiki with Zena, Art, Clean Water project, Collections, crocodiles, Default skin, Etat des travaux" ml_title_filter_in_relation: src: "references where title = 'important'" - sql: "/idx_nodes_ml_strings AS id1.*id1.value = 'important'.*lang = 'fr'.*key = 'title'.*nodes.id = links.target_id.*source_id = \?/" + sql: "/idx_nodes_ml_strings AS ml1.*ml1.value = 'important'.*lang = 'fr'.*key = 'title'.*nodes.id = links.target_id.*source_id = \?/" res: "" @@ -45,16 +45,33 @@ filter_ml_string: context: lang: 'de' src: "nodes where title = 'foo' in site" - sql: "%Q{SELECT nodes.* FROM idx_nodes_ml_strings AS id1,nodes WHERE #{secure_scope('nodes')} AND id1.value = 'foo' AND id1.lang = 'fr' AND id1.key = 'title' AND id1.node_id = nodes.id GROUP BY nodes.id ORDER BY nodes.position ASC, nodes.node_name ASC}" + sql: "%Q{SELECT nodes.* FROM idx_nodes_ml_strings AS ml1,nodes WHERE #{secure_scope('nodes')} AND ml1.value = 'foo' AND ml1.lang = 'fr' AND ml1.key = 'title' AND ml1.node_id = nodes.id ORDER BY nodes.zip ASC}" filter_ml_string_order: context: lang: 'de' src: "nodes where title = 'foo' in site order by title" - sql: "%Q{SELECT nodes.* FROM idx_nodes_ml_strings AS id1,nodes WHERE #{secure_scope('nodes')} AND id1.value = 'foo' AND id1.lang = 'fr' AND id1.key = 'title' AND id1.node_id = nodes.id GROUP BY nodes.id ORDER BY id1.value}" + sql: "%Q{SELECT nodes.* FROM idx_nodes_ml_strings AS ml1,nodes WHERE #{secure_scope('nodes')} AND ml1.value = 'foo' AND ml1.lang = 'fr' AND ml1.key = 'title' AND ml1.node_id = nodes.id ORDER BY ml1.value}" filter_ml_string_twice: context: lang: 'de' src: "nodes where title = 'foo' and title = 'baz' in site" - sql: "%Q{SELECT nodes.* FROM idx_nodes_ml_strings AS id1,nodes WHERE #{secure_scope('nodes')} AND id1.value = 'foo' AND id1.value = 'baz' AND id1.lang = 'fr' AND id1.key = 'title' AND id1.node_id = nodes.id GROUP BY nodes.id ORDER BY nodes.position ASC, nodes.node_name ASC}" \ No newline at end of file + sql: "%Q{SELECT nodes.* FROM idx_nodes_ml_strings AS ml1,nodes WHERE #{secure_scope('nodes')} AND ml1.value = 'foo' AND ml1.value = 'baz' AND ml1.lang = 'fr' AND ml1.key = 'title' AND ml1.node_id = nodes.id ORDER BY nodes.zip ASC}" + + +ml_title_with_name: + src: "contacts where title like '%Invicta%' or name = 'Leo Verneyi' in site" + sql: "/ml1.*st1/" + res: 'Solenopsis Invicta, Panthera Leo Verneyi' + +ml_title_with_name_with_sort: + src: "contacts where title like '%Invicta%' or name = 'Leo Verneyi' in site order by title" + sql: "/ml1.*ml2.*st1/" + res: 'Panthera Leo Verneyi, Solenopsis Invicta' + +# Group by property +group_by_ml_title: + src: 'contacts in site group by title' + sql: "%Q{SELECT nodes.* FROM idx_nodes_ml_strings AS ml1,nodes WHERE #{secure_scope('nodes')} AND ml1.lang = 'fr' AND ml1.key = 'title' AND ml1.node_id = nodes.id AND nodes.kpath LIKE 'NRC%' GROUP BY ml1.value ORDER BY nodes.zip ASC}" + res: "Solenopsis Invicta, Panthera Tigris Sumatran, Panthera Leo Verneyi, The lake we love, Mr nobody" \ No newline at end of file diff --git a/test/integration/query_node/relations.yml b/test/integration/query_node/relations.yml index cf3db636..112133ad 100644 --- a/test/integration/query_node/relations.yml +++ b/test/integration/query_node/relations.yml @@ -4,10 +4,10 @@ default: node: 'cleanWater' visitor: 'ant' src: "" - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.parent_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id]" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.parent_id = ? ORDER BY nodes.zip ASC}, @node.id]" nodes_from_nodes_in_section: - sql: "[%Q{SELECT nodes.* FROM nodes,nodes AS no1 WHERE #{secure_scope('nodes')} AND nodes.parent_id = no1.id AND no1.section_id = ? GROUP BY nodes.id ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.get_section_id]" + sql: "[%Q{SELECT nodes.* FROM nodes,nodes AS no1 WHERE #{secure_scope('nodes')} AND nodes.parent_id = no1.id AND no1.section_id = ? GROUP BY nodes.id ORDER BY nodes.zip ASC}, @node.get_section_id]" bad_relation: src: "categories in site" @@ -15,23 +15,23 @@ bad_relation: overriden_relation: src: 'references' - sql: "[%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes WHERE #{secure_scope('nodes')} AND nodes.id = links.target_id AND links.relation_id = _ID(node_has_references) AND links.source_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id]" + sql: "[%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes WHERE #{secure_scope('nodes')} AND nodes.id = links.target_id AND links.relation_id = _ID(node_has_references) AND links.source_id = ? ORDER BY nodes.zip ASC}, @node.id]" link_selects_in_sub_query: src: "icons or images" - sql: "[%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes WHERE #{secure_scope('nodes')} AND ((nodes.id = links.target_id AND links.relation_id = _ID(node_has_an_icon) AND links.source_id = ?) OR (nodes.kpath LIKE 'NDI%' AND nodes.parent_id = ? AND links.id = 0)) GROUP BY nodes.id ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id, @node.id]" + sql: "[%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes WHERE #{secure_scope('nodes')} AND ((nodes.id = links.target_id AND links.relation_id = _ID(node_has_an_icon) AND links.source_id = ?) OR (nodes.kpath LIKE 'NDI%' AND nodes.parent_id = ? AND links.id = 0)) GROUP BY nodes.id ORDER BY nodes.zip ASC}, @node.id, @node.id]" projects_from_tags: sql: "/nodes.id = no1.project_id AND no1.kpath LIKE 'NPT%' AND no1.parent_id = ?/" projects_in_site: - sql: "%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.kpath LIKE 'NPP%' ORDER BY nodes.position ASC, nodes.node_name ASC}" + sql: "%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.kpath LIKE 'NPP%' ORDER BY nodes.zip ASC}" nodes_in_section: context: node: 'people' - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.section_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.get_section_id]" - res: "anonymous, ant, lion, myLife, tiger" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.section_id = ? ORDER BY nodes.zip ASC}, @node.get_section_id]" + res: "Solenopsis Invicta, Panthera Tigris Sumatran, Panthera Leo Verneyi, My Life, Mr nobody" relation_from_class: src: "hot from projects in site" @@ -45,31 +45,31 @@ same_name_as_class: same_name_as_class_in_site: # Creates pages relation in QueryNodeTest src: 'pages in site' - sql: "%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.kpath LIKE 'NP%' ORDER BY nodes.position ASC, nodes.node_name ASC}" + sql: "%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.kpath LIKE 'NP%' ORDER BY nodes.zip ASC}" same_name_as_class_not_valid: # Creates pages relation in QueryNodeTest src: 'pages' - sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.kpath LIKE 'NP%' AND nodes.parent_id = ? ORDER BY nodes.position ASC, nodes.node_name ASC}, @node.id]" + sql: "[%Q{SELECT nodes.* FROM nodes WHERE #{secure_scope('nodes')} AND nodes.kpath LIKE 'NP%' AND nodes.parent_id = ? ORDER BY nodes.zip ASC}, @node.id]" root_should_be_project: context: # Make sure we do not start query on a Project so that we can tell if 'root' properly sets main_class. node: ant src: 'news from root' - sql: "%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes,nodes AS no1 WHERE #{secure_scope('nodes')} AND nodes.id = links.source_id AND links.relation_id = 488905946 AND links.target_id = no1.id AND no1.id = 850927283 GROUP BY nodes.id ORDER BY nodes.position ASC, nodes.node_name ASC}" + sql: "%Q{SELECT nodes.*,links.id AS link_id,links.status AS l_status,links.comment AS l_comment,links.date AS l_date FROM links,nodes,nodes AS no1 WHERE #{secure_scope('nodes')} AND nodes.id = links.source_id AND links.relation_id = 488905946 AND links.target_id = no1.id AND no1.id = 850927283 GROUP BY nodes.id ORDER BY nodes.zip ASC}" start_as_tag: context: node: art src: "tagged from tag:start" sql: '/no1.site_id = \? AND no1.zip = \?.*current_site.id, start_node_zip/' - res: 'cleanWater, opening' + res: 'Clean Water project, super ouverture' from_visitor: src: 'favorites from visitor' sql: '/visitor.node_id/' - res: 'nature' + res: 'Nature' # l_date_as_date: # src: "select *,if(l_date,l_date,event_at) AS date from (notes or assigned_notes) order by date" \ No newline at end of file diff --git a/test/integration/query_node_test.rb b/test/integration/query_node_test.rb index 16b30d20..03378408 100644 --- a/test/integration/query_node_test.rb +++ b/test/integration/query_node_test.rb @@ -38,6 +38,8 @@ def yt_do_test(file, test) login @context[:visitor].to_sym @context[:rubyless_helper] = self + defaults = (@context[:default] ||= {}) + defaults[:order] ||= 'zip asc' if klass = @context.delete(:class) klass = Node.get_class(klass) @@ -72,11 +74,7 @@ def yt_do_test(file, test) res = node_class.do_find(:all, sql) - if node_class == Comment - res = res ? res.map {|r| r[:title]}.join(', ') : '' - else - res = res ? res.map {|r| r[:node_name]}.join(', ') : '' - end + res = res ? res.map(&:title).join(', ') : '' yt_assert test_res, class_prefix + res else @@ -145,7 +143,7 @@ def test_find_count login(:ant) page = secure!(Node) { nodes(:cleanWater) } - sql = Node.build_query(:all, 'nodes where node_name like "a%" in site').to_s(:count) + sql = Node.build_query(:all, 'nodes where title like "a%" in site').to_s(:count) assert_equal 3, Node.do_find(:count, eval(sql)) end diff --git a/test/integration/zafu_compiler/action.yml b/test/integration/zafu_compiler/action.yml index a35c47a7..7c5b2dc1 100644 --- a/test/integration/zafu_compiler/action.yml +++ b/test/integration/zafu_compiler/action.yml @@ -12,7 +12,7 @@ logout_link: # Forces NodesController type of url and params fake_controller: 'nodes' src: "<r:login_link/>" - res: '<a href="/logout?redirect=%2Fen%2Fprojects%2FcleanWater%2Fpage22.html">logout</a>' + res: '<a href="/logout?redirect=%2Fen%2Fprojects-list%2FClean-Water-project%2Fpage22.html">logout</a>' login_link: context: @@ -20,7 +20,7 @@ login_link: # Forces NodesController type of url and params fake_controller: 'nodes' src: "<r:login_link/>" - res: '<a href="/oo/projects/cleanWater/page22.html">login</a>' + res: '<a href="/oo/projects-list/Clean-Water-project/page22.html">login</a>' logout_link_other_controller: src: "<r:login_link/>" @@ -33,13 +33,13 @@ login_link_other_controller: res: '<a href="/login">login</a>' login_link_with_blocks: - src: "<r:login_link>ONE ONE<r:else do='node_name'/></r:login_link>" - res: "<a href='/logout'>status</a>" + src: "<r:login_link>ONE ONE<r:else do='title'/></r:login_link>" + res: "<a href='/logout'>status title</a>" login_link_with_blocks_not_logged_in: context: visitor: 'anon' - src: "<r:login_link><r:title/><r:else do='node_name'/></r:login_link>" + src: "<r:login_link><r:title/><r:else do='title'/></r:login_link>" res: "<a href='/login'>status title</a>" visitor_link_not_logged_in: diff --git a/test/integration/zafu_compiler/ajax.yml b/test/integration/zafu_compiler/ajax.yml index 64b5482c..21a99837 100644 --- a/test/integration/zafu_compiler/ajax.yml +++ b/test/integration/zafu_compiler/ajax.yml @@ -5,9 +5,9 @@ default: node: 'status' block: - src: "<r:parent><r:block name='foobar' do='node_name'/></r:parent>" - tem: "<% if var1 = @node.parent -%><div id='foobar'><%= var1.node_name %></div><% end -%>" - 'ajax/block/en/foobar.erb': "<div id='foobar'><%= @node.node_name %></div>" + src: "<r:parent><r:block name='foobar' do='title'/></r:parent>" + tem: "<% if var1 = @node.parent -%><div id='foobar'><%= var1.prop['title'] %></div><% end -%>" + 'ajax/block/en/foobar.erb': "<div id='foobar'><%= @node.prop['title'] %></div>" add: src: "<ul id='children' do='nodes'><li do='each' do='link'/><li do='add'/></ul>" @@ -20,8 +20,8 @@ edit_not_each: res: "/<li class='blah'>this is a post <a href='/nodes/22/edit'>edit</a></li>/" add_each_no_form: - src: "<ul do='children' id='things'><li do='each'>I <p do='node_name'>blah</p></li><li do='add'/></ul>" - res: "/<ul><li.*id='things_add'.*li.*class='form' id='things_form'.*form.*I <p><input id=.things_node_name. name=.node\[node_name\]. .*type=.text..*hidden/" + src: "<ul do='children' id='things'><li do='each'>I <p do='title'>blah</p></li><li do='add'/></ul>" + res: "/<ul><li.*id='things_add'.*li.*class='form' id='things_form'.*form.*I <p><input id=.things_title. name=.node\[title\]. .*type=.text..*hidden/" add_each_no_form_date: src: "<ul do='children' id='things'><li do='each'>I <p do='show' date='event_at' tformat='short_date'>blah</p></li><li do='add'/></ul>" @@ -36,7 +36,7 @@ each_add_with_form: node: 'wiki' src: | <ol do='children'> - <li do='each' do='node_name'>blah</li> + <li do='each' do='title'>blah</li> <li do='add'>add new</li> <li do='form'><input name='title'/> this is the form</li> </ol> @@ -48,7 +48,7 @@ each_add_with_form_in_sub_block: src: | <r:children> <ol do='void' name='boo'> - <li do='each' do='node_name'>blah</li> + <li do='each' do='title'>blah</li> <li do='add'>add new</li> <li do='form'><input name='title'/> this is the form</li> </ol> @@ -60,43 +60,43 @@ each_add_with_form_klass_set: node: 'wiki' src: | <r:children> - <li do='each' do='node_name'>blah</li> + <li do='each' do='title'>blah</li> <li do='add'>add new</li> <li do='form'><input name='title'/> <select name='klass' root_class='Note' selected='Post'/> this is the form</li> </r:children> res: "!/hidden.*node\[klass\].*Node.*select.*node\[klass\]/" each_add_with_select: - src: "<r:children><r:each do='node_name'/><r:add/><r:form><select name='icon_id' nodes='images in project' selected='[main.icon_id]_abc'/></r:form></r:children>" + src: "<r:children><r:each do='title'/><r:add/><r:form><select name='icon_id' nodes='images in project' selected='[main.icon_id]_abc'/></r:form></r:children>" 'ajax/each/en/add/with/select/list1_form.erb': '/map.|r| \[r.name, r.zip.to_s\]., \"#.@node.icon_zip._abc\"\)/' tem: "/nodes.kpath LIKE 'NDI%'/" each_edit_with_form: context: node: 'wiki' - src: "<r:children><li do='each'><r:show attr='node_name'>blah</r:show> <r:edit>edit</r:edit></li>\n<r:form><li><form>this is the form</form></li></r:form></r:children>" + src: "<r:children><li do='each'><r:show attr='title'>blah</r:show> <r:edit>edit</r:edit></li>\n<r:form><li><form>this is the form</form></li></r:form></r:children>" res: "/<li id='list1_30'>bird <a href='/nodes/30/edit' onclick='new Ajax.Request\(\"/nodes/30/edit\?.*t_url=ajax%2Feach%2Fedit%2Fwith%2Fform%2Flist1_form/" make_form: - src: "<ul do='children'><li do='each' do='node_name'/><li do='add'/></ul>" + src: "<ul do='children'><li do='each' do='title'/><li do='add'/></ul>" tem: "/<li style='display:none;' class='form' id='list1_form'>.*remote_form_for\(:node, var2_new" - 'ajax/make/en/form/list1.erb': "<li id='<%= ndom_id(@node) %>'><%= @node.node_name %></li>" + 'ajax/make/en/form/list1.erb': "<li id='<%= ndom_id(@node) %>'><%= @node.prop['title'] %></li>" 'ajax/make/en/form/list1_form.erb': "/<li class='form' id='<%= ndom_id\(@node\) %>'>/" each_edit_cannot_write: context: node: 'cleanWater' visitor: 'anon' - src: "<r:children><li do='each'><r:show attr='node_name'>blah</r:show> <r:edit>edit</r:edit></li>\n</r:children>" - res: "/<li id='list1_24'>lake</li>.*/" + src: "<r:children><li do='each'><r:show attr='title'>blah</r:show> <r:edit>edit</r:edit></li>\n</r:children>" + res: "/<li id='list1_24'>it's a lake</li>.*/" add_each_publish: - src: "<ul do='children' id='things'><li do='each'>I <p do='node_name'>blah</p></li><li do='add' publish='true'/></ul>" + src: "<ul do='children' id='things'><li do='each'>I <p do='title'>blah</p></li><li do='add' publish='true'/></ul>" res: "/hidden.*name=.node\[v_status\]. value=.50./" block_edit_form: - src: "<r:block><p do='node_name'/> <r:edit/> <r:form>please enter name: <input name='name'/> <r:input type='submit'/></r:form></r:block>" - res: "/<p>status<\/p>.*edit/" + src: "<r:block><p do='title'/> <r:edit/> <r:form>please enter name: <input name='name'/> <r:input type='submit'/></r:form></r:block>" + res: "/<p>status title<\/p>.*edit/" query_in_block: src: "<r:block><r:tagged where='title like \"%#{params[:tag]}%\"' in='site'/></r:block>" @@ -107,7 +107,7 @@ saved_each_block: 'ajax/saved/en/each/block/list1.erb': "!/var1/" no_recursion_in_saved_block: - src: "<r:void name='grp'><r:show attr='node_name'/><r:pages><r:each><r:include part='grp'/></r:each><r:add/></r:pages></r:void>" + src: "<r:void name='grp'><r:show attr='title'/><r:pages><r:each><r:include part='grp'/></r:each><r:add/></r:pages></r:void>" 'ajax/no/en/recursion/in/saved/block/grp1.erb': "!/no_recursion_in_saved_block_grp/" each_in_each: @@ -122,32 +122,32 @@ default_focus_field: live_filter: context: node: cleanWater - src: "<r:filter live='true'/><r:block><ol do='pages where node_name like \"#{params[:f]}%\"'><li do='each' do='node_name'/></ol></r:block>" - tem: "/nodes.node_name LIKE \?.*, \"#\{params\[:f\]\}%\"/" - 'ajax/live/en/filter/list1.erb': "/<div id='list1.*, \"#\{params\[:f\]\}%\".*var2.node_name/" - res: "/<input type='text' name='f'.*<div id='list1'><ol><li>crocodiles</li><li>status</li><li>track</li></ol></div>/" + src: "<r:filter live='true'/><r:block><ol do='pages where title like \"#{params[:f]}%\"'><li do='each' do='title'/></ol></r:block>" + tem: "/ml1.value LIKE \?.*, \"#\{params\[:f\]\}%\"/" + 'ajax/live/en/filter/list1.erb': "/<div id='list1.*, \"#\{params\[:f\]\}%\".*var2.prop\['title'\]/" + res: "/<input type='text' name='f'.*<div id='list1'><ol><li>crocodiles</li><li>Keeping things clean !</li><li>status title</li></ol></div>/" live_filter_single_element: context: node: cleanWater - src: "<r:filter live='true'/><r:block><r:page where='node_name like \"#{params[:f]}%\"' find='first'><b do='node_name'/></r:page></r:block>" + src: "<r:filter live='true'/><r:block><r:page where='title like \"#{params[:f]}%\"' find='first'><b do='title'/></r:page></r:block>" tem: "/, \"#\{params\[:f\]\}%\"/" - 'ajax/live/en/filter/single/element/list1.erb': "/<div id='list1.*params\[:f\].*var1.node_name/" + 'ajax/live/en/filter/single/element/list1.erb': "/<div id='list1.*params\[:f\].*var1.prop\['title'\]/" res: "/<input type='text' name='f'.*<div id='list1'><b>crocodiles</b></div>/" live_filter_select_options: context: node: cleanWater - src: "<r:filter live='true' do='select' name='f' values='1,2'/><r:block><ol do='pages where node_name like \"#{params[:f]}%\"'><li do='each' do='node_name'/></ol></r:block>" + src: "<r:filter live='true' do='select' name='f' values='1,2'/><r:block><ol do='pages where title like \"#{params[:f]}%\"'><li do='each' do='title'/></ol></r:block>" tem: "/select name=.f.><%= options_for_select\(\[.1., .2.\], params\[:f\].to_s/" 'ajax/live/en/filter/select/options/list1.erb': "/<div id='list1'.*params\[:f\]/" - res: "/<select name='f'.*<div id='list1'><ol><li>crocodiles</li><li>status</li><li>track</li></ol></div>/" + res: "/<select name='f'.*<div id='list1'><ol><li>crocodiles</li><li>Keeping things clean !</li><li>status title</li></ol></div>/" draggable_do_syntax: src: "<r:images in='site' do='each' draggable='all' do='img' mode='pv'/>" tem: "/add_drag_id\(\"list1_#\{var2.zip\}\"/" res: "/id='list1_30'><img src='/en/image30_pv.jpg\?967816914293'/" - js: '/"list1_40"\].each.*Zena.draggable\(item, false\)/' + js: '/"list1_24"\].each.*Zena.draggable\(item, false\)/' draggable_true: # should use 'drag_handle' class @@ -158,7 +158,7 @@ draggable_in_block: # should use 'hooba' class src: "<r:block><r:link draggable='hooba'/></r:block>" tem: "/add_drag_id\(\"list1_\#\{@node.zip\}\", .*hooba/" - res: "<div id='list1'><div class='drag' id='list1_22'><a href='/oo/projects/cleanWater/page22.html'>status title</a></div></div>" + res: "<div id='list1'><div class='drag' id='list1_22'><a href='/oo/projects-list/Clean-Water-project/page22.html'>status title</a></div></div>" js: "/Zena.draggable\(item, \"hooba\"\)/" draggable_with_id_set: @@ -186,7 +186,7 @@ edit_link: node: 'art' class: Tag lang: 'fr' - src: "<r:context select='tagged'><r:each><r:show attr='node_name'/>: <r:show attr='l_status'/> <r:edit/></r:each></r:context>" + src: "<r:context select='tagged'><r:each><r:show attr='title'/>: <r:show attr='l_status'/> <r:edit/></r:each></r:context>" # The link_id should be sent with the url. res: "/link_id.*éditer/" 'ajax/edit/fr/link/list1_form.erb': "/<input type='hidden' name='link_id' value=.<%= @node.link_id %>./>/" @@ -207,7 +207,7 @@ drop_add_link: drop_var_scope: src: "<div do='visitor.node'><div do='drop' add='favorite' change='receiver'><r:favorites>.</r:favorites></div></div>" - tem: "/var2 = Node.do_find.*nodes.node_name ASC\}, var1.id\]\)/" + tem: "/var2 = Node.do_find.*ml1.value ASC\}, var1.id\]\)/" drop_done_remove: src: "<div do='drop' set='reference' done='remove'></div>" @@ -228,8 +228,8 @@ update_target: tem: "/UT: <div id='foo'>...</div> .*Ajax.Request.*:dom_id => \"foo\"/" include_update_target: - src: "IUT: <r:include template='/ajax/update/target'><r:with part='foo'><r:show attr='node_name'/></r:with></r:include>" - tem: "/IUT: UT: <div id='foo'><%= @node.node_name %></div> <a .*zen_path.*onclick='new Ajax.Request/" + src: "IUT: <r:include template='/ajax/update/target'><r:with part='foo'><r:show attr='title'/></r:with></r:include>" + tem: "/IUT: UT: <div id='foo'><%= @node.prop\['title'\] %></div> <a .*zen_path.*onclick='new Ajax.Request/" id_in_each_group_should_be_scoped: src: "<ul do='comments from nodes in site' do='group' by='discussion_id'><li do='each'><r:node do='block' do='title'/></li></ul>" @@ -239,7 +239,7 @@ link_page_next: context: pak: 2 src: "<div id='foo' do='block' do='nodes in site' limit='3' order='zip' paginate='pak'><r:link page='previous'/> | <r:pak/> | <r:link update='foo' page='next'/> || <r:each join=',' do='[id]'/></div>" - res: "/<a href='/oo/projects/cleanWater/page22.html\?pak=1'>1</a> \| 2 \| .*22/zafu\?dom_id=foo.*pak=3.*>3</a>/" + res: "/<a href='/oo/projects-list/Clean-Water-project/page22.html\?pak=1'>1</a> \| 2 \| .*22/zafu\?dom_id=foo.*pak=3.*>3</a>/" link_page_list: context: diff --git a/test/integration/zafu_compiler/apphelper.yml b/test/integration/zafu_compiler/apphelper.yml index af33145b..c3eff483 100644 --- a/test/integration/zafu_compiler/apphelper.yml +++ b/test/integration/zafu_compiler/apphelper.yml @@ -29,7 +29,7 @@ zen_url: context: node: status tem: "<%= zen_url(@node, :mode=>'rss', :format=>'xml') %>" - res: "http://test.host/oo/projects/cleanWater/page22_rss.xml" + res: "http://test.host/oo/projects-list/Clean-Water-project/page22_rss.xml" zen_url_root_mode_format: context: diff --git a/test/integration/zafu_compiler/asset.yml b/test/integration/zafu_compiler/asset.yml index 2e259699..c0bda89a 100644 --- a/test/integration/zafu_compiler/asset.yml +++ b/test/integration/zafu_compiler/asset.yml @@ -9,5 +9,5 @@ default: rename_asset: - src: "<link href='/default/style.css' rel='Stylesheet' type='text/css'/>" + src: "<link href='/Default skin/style.css' rel='Stylesheet' type='text/css'/>" tem: "<link href='/en/textdocument53.css?1144713600' rel='Stylesheet' type='text/css'/>" \ No newline at end of file diff --git a/test/integration/zafu_compiler/basic.yml b/test/integration/zafu_compiler/basic.yml index 849430f4..80264367 100644 --- a/test/integration/zafu_compiler/basic.yml +++ b/test/integration/zafu_compiler/basic.yml @@ -50,50 +50,50 @@ each_traductions_only_list: each_alternate_class: context: node: 'cleanWater' - src: "<ol do='pages'><li do='each' alt_class='blue' do='node_name'/></ol>" - res: "<ol><li class=''>crocodiles</li><li class='blue'>status</li><li class=''>track</li></ol>" + src: "<ol do='pages'><li do='each' alt_class='blue' do='title'/></ol>" + res: "<ol><li class=''>crocodiles</li><li class='blue'>status title</li><li class=''>Keeping things clean !</li></ol>" each_alternate_class_reverse: context: node: 'cleanWater' - src: "<ol do='pages' limit='2'><li do='each' alt_class='blue' alt_reverse='true' do='node_name'/></ol>" - res: "<ol><li class='blue'>crocodiles</li><li class=''>status</li></ol>" + src: "<ol do='pages' limit='2'><li do='each' alt_class='blue' alt_reverse='true' do='title'/></ol>" + res: "<ol><li class='blue'>crocodiles</li><li class=''>status title</li></ol>" each_alternate_class_two: context: node: 'collections' - src: "<ol do='pages'><li class='post' do='each' alt_class='stripe' do='node_name'/></ol>" + src: "<ol do='pages'><li class='post' do='each' alt_class='stripe' do='title'/></ol>" res: "<ol><li class='post '>art</li><li class='post stripe'>menu</li><li class='post '>news</li><li class='post stripe'>wikiSkin</li></ol>" each_alternate_class_ajax: context: node: 'cleanWater' - src: "<ol do='pages' limit='2'><li do='each' alt_class='blue' do='node_name'/><li do='add'/></ol>" + src: "<ol do='pages' limit='2'><li do='each' alt_class='blue' do='title'/><li do='add'/></ol>" res: "/<li>crocodiles<\/li><li class=\"blue\">status/" each_else: context: node: 'opening' - src: "<div do='pages'>has pages (<r:each join=', ' do='node_name'/>)<r:else>no pages</r:else></div>" - tem: "/<% if var1.* -%><div>has pages \(<% var1.each_with_index .* -%><%= var2.node_name %><% end -%>\)</div><% elsif true -%><div>no pages</div><% end -%>/" + src: "<div do='pages'>has pages (<r:each join=', ' do='title'/>)<r:else>no pages</r:else></div>" + tem: "/<% if var1.* -%><div>has pages \(<% var1.each_with_index .* -%><%= var2.prop\['title'\] %><% end -%>\)</div><% elsif true -%><div>no pages</div><% end -%>/" res: "<div>no pages</div>" simple_each: - src: "<r:children><r:each><r:show attr='node_name'/></r:each></r:children>" - tem: "/.*if var1.*each.*var2.node_name/" + src: "<r:children><r:each><r:show attr='title'/></r:each></r:children>" + tem: "/.*if var1.*each.*var2.prop\['title'\]/" res: "" each_join: context: node: 'wiki' - src: "<r:children><r:each join=', '><r:show attr='node_name'/></r:each></r:children>" + src: "<r:children><r:each join=', '><r:show attr='title'/></r:each></r:children>" res: "bird, flower" each_join_if: context: node: 'status' - src: "<r:pages in='site' order='name'><r:each join=', ' join_if='prev.id ne main.id and id ne main.id'><r:show attr='node_name'/></r:each></r:pages>" + src: "<r:pages in='site' order='name'><r:each join=', ' join_if='prev.id ne main.id and id ne main.id'><r:show attr='title'/></r:each></r:pages>" res: "/projects, skinsstatustalk, track/" set_attribute: @@ -114,27 +114,27 @@ set_node_param_main_other_class: res: "<p class='class_22'></p>" set_attribute_with_inner: - src: "<p set_id='node[id]' do='show' attr='node_name' set_class='s[v_status]'>some blah blah</p>" - res: "<p class='s50' id='node22'>status</p>" + src: "<p set_id='node[id]' do='show' attr='title' set_class='s[v_status]'>some blah blah</p>" + res: "<p class='s50' id='node22'>status title</p>" set_in_ztag: - src: "<r:show attr='node_name' set_id='node[id]'/>" - res: "<div id='node22'>status</div>" + src: "<r:show attr='title' set_id='node[id]'/>" + res: "<div id='node22'>status title</div>" set_attribute_stored_node: - src: "<r:void store='foo'><r:parent><p do='node_name' set_id='test_[foo.id]'>hey</p></r:parent></r:void>" - res: "<p id='test_22'>cleanWater</p>" + src: "<r:void store='foo'><r:parent><p do='title' set_id='test_[foo.id]'>hey</p></r:parent></r:void>" + res: "<p id='test_22'>Clean Water project</p>" set_attribute_main_node: - src: "<r:parent><p id='test_#{main.node_name}' do='node_name'>hey</p></r:parent>" - res: "<p id='test_status'>cleanWater</p>" + src: "<r:parent><p id='test_#{main.zip}' do='title'>hey</p></r:parent>" + res: "<p id='test_22'>Clean Water project</p>" set_attribute_in_list: context: node: 'projects' - src: "<div do='pages'><p id='#{node_name}'>...</p></div>" + src: "<div do='pages'><p id='#{id}'>...</p></div>" tem: /var1.first/ - res: "<div><p id='cleanWater'>...</p></div>" + res: "<div><p id='21'>...</p></div>" set_attribute_with_namespace: src: "<entry do='void' set_xml:base='[name]'>..</entry>" @@ -143,13 +143,13 @@ set_attribute_with_namespace: each_join_html: context: node: 'wiki' - src: "<r:children><r:each join='<br/>'><r:show attr='node_name'/></r:each></r:children>" + src: "<r:children><r:each join='<br/>'><r:show attr='title'/></r:each></r:children>" res: "bird<br/>flower" each_join_nasty_erb: context: node: 'wiki' - src: "<r:children><r:each join='<% puts \'nasty\' -%>'><r:show attr='node_name'/></r:each></r:children>" + src: "<r:children><r:each join='<% puts \'nasty\' -%>'><r:show attr='title'/></r:each></r:children>" res: "bird<% puts 'nasty' -%>flower" test_children_plural: @@ -159,7 +159,7 @@ test_children_plural: each_do: context: node: 'wiki' - src: "<r:children><r:each join=', ' do='show' attr='node_name'/></r:children>" + src: "<r:children><r:each join=', ' do='show' attr='title'/></r:children>" res: "bird, flower" parent_do: @@ -177,7 +177,7 @@ do_each: do_with_inner: context: node: 'wiki' - src: "<ul do='children' do='each' tag='li'><r:show attr='node_name'/></ul>" + src: "<ul do='children' do='each' tag='li'><r:show attr='title'/></ul>" res: "<ul><li>bird</li><li>flower</li></ul>" do_each_do: @@ -197,8 +197,8 @@ do_ignore: res: "" name_title: - src: "title: <h1 id='lala' do='show' name='title' attr='node_name'>blah</h1>" - res: "title: <h1 id='lala'>status</h1>" + src: "title: <h1 id='lala' do='show' name='title' attr='title'>blah</h1>" + res: "title: <h1 id='lala'>status title</h1>" include_with: src: "include_with: <r:include template='/basic/name/title'><h1 do='with' part='title' attr='id'/>" @@ -218,11 +218,11 @@ include_named: # this test is a dummy used by include_context context_dummy: - src: "CD: <r:pages in='site' where='name like \"s%\"' node_name='pages'><r:each join=', ' do='node_name'/></r:pages>" + src: "CD: <r:pages in='site' where='title like \"s%\"' name='pages'><r:each join=', ' do='title'/></r:pages>" res: "CD: skins, status" include_context: - src: "IC: <r:include template='/context/dummy'><r:with part='pages'><r:each join=' / ' do='node_name'/></r:with></r:include>" + src: "IC: <r:include template='/context/dummy'><r:with part='pages'><r:each join=' / ' do='title'/></r:with></r:include>" res: "IC: CD: skins / status" content_for_layout: @@ -232,7 +232,7 @@ content_for_layout: title_for_layout: src: "<r:title_for_layout>blah blih</r:title_for_layout>" - res: "zena/projects/cleanWater/status" + res: "zena/projects-list/Clean-Water-project/status" tada: context: @@ -347,12 +347,12 @@ find_count: link_page_next: context: pak: 2 - src: "<r:nodes in='site' limit='3' order='zip' paginate='pak'><r:link page='previous'/> | <r:show var='pak'/> | <r:link page='next'/> || <r:each join=',' do='node_name'/></r:nodes>" - res: "<a href='/oo/projects/cleanWater/page22.html?pak=1'>1</a> | 2 | <a href='/oo/projects/cleanWater/page22.html?pak=3'>3</a> || tiger,lion,myLife" + src: "<r:nodes in='site' limit='3' order='zip' paginate='pak'><r:link page='previous'/> | <r:show var='pak'/> | <r:link page='next'/> || <r:each join=',' do='title'/></r:nodes>" + res: "<a href='/oo/projects-list/Clean-Water-project/page22.html?pak=1'>1</a> | 2 | <a href='/oo/projects-list/Clean-Water-project/page22.html?pak=3'>3</a> || tiger,lion,myLife" link_page_next_with_block: src: "<r:nodes in='site' limit='3' order='zip' paginate='pak'><r:link page='next' do='t'>next</r:link></r:nodes>" - res: "<a href='/oo/projects/cleanWater/page22.html?pak=2'>next</a>" + res: "<a href='/oo/projects-list/Clean-Water-project/page22.html?pak=2'>next</a>" link_page_list: context: @@ -398,7 +398,7 @@ link_page_previous_else_page2: context: pak: 2 src: "<r:nodes in='site' limit='3' order='zip' paginate='pak'><r:link page='previous' do='else'>noprev</r:link></r:nodes>" - res: "<a href='/oo/projects/cleanWater/page22.html?pak=1'>1</a>" + res: "<a href='/oo/projects-list/Clean-Water-project/page22.html?pak=1'>1</a>" link_page_list_else: context: @@ -410,14 +410,14 @@ debug_params: context: foo: 'bar' dev: true - src: "DEBUG: <r:debug title='no idea for a title' show='params'/><r:debug do='node_name'/>" + src: "DEBUG: <r:debug title='no idea for a title' show='params'/><r:debug do='title'/>" tem: "DEBUG: <div class='debug'><p>no idea for a title</p><pre><%= params.inspect %></pre></div><div class='debug'><%= @node.name %></div>" - res: "/DEBUG: <div class='debug'><p>no idea for a title</p><pre>.*\"foo\"=>\"bar\".*</pre></div><div class='debug'>status</div>/" + res: "/DEBUG: <div class='debug'><p>no idea for a title</p><pre>.*\"foo\"=>\"bar\".*</pre></div><div class='debug'>status title</div>/" debug_params_not_in_dev_mode: context: foo: 'bar' - src: "DEBUG: <r:debug show='params'/><r:debug do='node_name'/><r:debug title='help needed'/>" + src: "DEBUG: <r:debug show='params'/><r:debug do='title'/><r:debug title='help needed'/>" tem: 'DEBUG: ' res: 'DEBUG: ' diff --git a/test/integration/zafu_compiler/calendar.yml b/test/integration/zafu_compiler/calendar.yml index 0d437a41..17a77146 100644 --- a/test/integration/zafu_compiler/calendar.yml +++ b/test/integration/zafu_compiler/calendar.yml @@ -9,7 +9,7 @@ calendar: context: ref_date: "2006-03-18" src: "<div do='calendar' select='notes in site'/>" - res: "/<td class='sat ref'><span>18</span><ul><li><a href='/oo/projects/cleanWater/post27.html'>opening</a></li></ul><\/td>/" + res: "/<td class='sat ref'><span>18</span><ul><li><a href='/oo/projects-list/Clean-Water-project/post27.html'>opening</a></li></ul><\/td>/" calendar_default_else: context: @@ -23,7 +23,7 @@ calendar_l_date: ref_date: "2009-7-17" node: 'zena' src: "<div do='calendar' select='added_notes' date='l_date' />" - res: "/<td class='ref'><span>17</span><ul><li><a href='/oo/projects/cleanWater/post27.html'>opening</a></li></ul></td>/" + res: "/<td class='ref'><span>17</span><ul><li><a href='/oo/projects-list/Clean-Water-project/post27.html'>opening</a></li></ul></td>/" calendar_hours: context: @@ -31,5 +31,5 @@ calendar_hours: node: 'zena' # I do not like the way we do this, the 'else' thing is not helping. Maybe we need some # extra zafu tags because it' messy: we have 3 lists (days, hours, nodes) ... - src: "<div do='calendar' select='added_notes' date='l_date' split_hours='12'><r:if test='hour eq 0' do='[current_date]' format='%d'/><div do='void' set_class='hour_[hour]' do='each' do='node_name' join=', '/><r:else><r:if test='hour eq 0' do='[current_date]' format='%d'/><div do='void' set_class='hour_[hour]'></div></r:else></div>" + src: "<div do='calendar' select='added_notes' date='l_date' split_hours='12'><r:if test='hour eq 0' do='[current_date]' format='%d'/><div do='void' set_class='hour_[hour]' do='each' do='title' join=', '/><r:else><r:if test='hour eq 0' do='[current_date]' format='%d'/><div do='void' set_class='hour_[hour]'></div></r:else></div>" res: "/<td class='ref'>17<div class='hour_0'></div><div class='hour_12'>opening</div></td>/" diff --git a/test/integration/zafu_compiler/complex.yml b/test/integration/zafu_compiler/complex.yml index 0ecf8b66..f585cbc1 100644 --- a/test/integration/zafu_compiler/complex.yml +++ b/test/integration/zafu_compiler/complex.yml @@ -60,43 +60,43 @@ default: visitor: complex_admin site: complex ref_date: 2004-09-01 - src: "<r:emp_form_dates where='repeat_every is not null' do='each' join=', '><r:show attr='node_name'/>(<r:show attr='priority'/>, <r:show date='last_date' format='%Y-%m-%d'/>, <r:show date='next_date' format='%Y-%m-%d'/>)</r:emp_form_dates>" + src: "<r:emp_form_dates where='repeat_every is not null' do='each' join=', '><r:show attr='title'/>(<r:show attr='priority'/>, <r:show date='last_date' format='%Y-%m-%d'/>, <r:show date='next_date' format='%Y-%m-%d'/>)</r:emp_form_dates>" res: "secure_a_site(10, , ), winch_usage(10, , ), dangerous_transportations(10, 2004-03-15, 2006-03-15), engine(5, , ), transmit_information(5, 2002-05-05, 2003-05-05), fiber_junction(5, 2003-03-03, 2005-03-03), radio_usage(1, , )" courses_in_the_next_6_months: # custom_a = repetition interval - src: "<r:emp_form_dates where='last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month)' order='last_date asc, node_name ASC' do='each' join=', '><r:show attr='node_name'/>: <r:show date='next_date' format='%Y-%m-%d'/></r:emp_form_dates>" + src: "<r:emp_form_dates where='last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month)' order='last_date asc, title ASC' do='each' join=', '><r:show attr='title'/>: <r:show date='next_date' format='%Y-%m-%d'/></r:emp_form_dates>" res: "engine: , radio_usage: , secure_a_site: , winch_usage: , transmit_information: 2003-05-05" courses_in_the_next_6_months_do_syntax: context: ref_date: 2005-03-01 # before 2005-06-01 - src: "<ol do='emp_form_dates where last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month)' do='group' by='priority'><li set_class='priority[priority]' do='each_group' do='each' join=', '><r:show attr='node_name'/>: <r:show date='next_date' format='%Y-%m-%d'/></li></ol>" + src: "<ol do='emp_form_dates where last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month)' do='group' by='priority'><li set_class='priority[priority]' do='each_group' do='each' join=', '><r:show attr='title'/>: <r:show date='next_date' format='%Y-%m-%d'/></li></ol>" res: "<ol><li class='priority10'>secure_a_site: , winch_usage: </li><li class='priority5'>engine: , transmit_information: 2003-05-05, fiber_junction: 2005-03-03</li><li class='priority1'>radio_usage: </li></ol>" all_formations: - src: "<r:formations in='site' do='each' join=', '><r:show attr='node_name'/>: <r:show date='event_at'/></r:formations>" + src: "<r:formations in='site' do='each' join=', '><r:show attr='title'/>: <r:show date='event_at'/></r:formations>" res: "fiber2002: 2002-02-02, fiber2003: 2003-03-03, form2005: 2005-03-20, form2006: 2006-03-20, transm2001: 2001-06-15, transm2002: 2002-05-05, transm2003: 2003-03-20, transp2004: 2004-03-15, transp2006: 2006-04-21, vision2003: 2003-04-05" all_formations_with_people: - src: "<r:formations in='site' do='each' join=', '><r:show attr='node_name'/>: <r:show date='event_at'/> (<r:formation_for find='all' do='each' join=', ' do='node_name'/>)</r:formations>" + src: "<r:formations in='site' do='each' join=', '><r:show attr='title'/>: <r:show date='event_at'/> (<r:formation_for find='all' do='each' join=', ' do='title'/>)</r:formations>" res: "fiber2002: 2002-02-02 (mike), fiber2003: 2003-03-03 (joe, roger), form2005: 2005-03-20 (roger), form2006: 2006-03-20 (roger), transm2001: 2001-06-15 (roger), transm2002: 2002-05-05 (roger), transm2003: 2003-03-20 (joe), transp2004: 2004-03-15 (roger), transp2006: 2006-04-21 (roger), vision2003: 2003-04-05 (mike)" all_people_related_to_a_course: context: node: transmit_information - src: "<r:course_emp_dates do='each' join=', '><r:show attr='node_name'/> (last:<r:show date='last_date'/>, next:<r:show date='next_date'/>)</r:course_emp_dates>" + src: "<r:course_emp_dates do='each' join=', '><r:show attr='title'/> (last:<r:show date='last_date'/>, next:<r:show date='next_date'/>)</r:course_emp_dates>" res: "joe (last:2003-03-20, next:2004-03-20), mike (last:, next:), roger (last:2002-05-05, next:2003-05-05)" all_people_related_to_a_course_group_by_priority: context: node: transmit_information src: | - <ol do='course_emp_dates' where='last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month)' order='priority desc, last_date asc, node_name ASC' do='group' by='priority'> + <ol do='course_emp_dates' where='last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month)' order='priority desc, last_date asc, title ASC' do='group' by='priority'> <li set_class='priority[priority]' do='each_group'> <ol> - <li do='each'><r:show attr='node_name'/> (last:<r:show date='last_date'/>, next:<r:show date='next_date'/>)</li> + <li do='each'><r:show attr='title'/> (last:<r:show date='last_date'/>, next:<r:show date='next_date'/>)</li> </ol> </li> </ol> @@ -118,16 +118,16 @@ all_people_related_to_a_course_in_6_month: context: node: transmit_information ref_date: 2003-04-04 - src: "<r:course_emp_dates where='last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month)' do='each' join=', '><r:show attr='node_name'/> (last:<r:show date='last_date'/>, next:<r:show date='next_date'/>)</r:course_emp_dates>" + src: "<r:course_emp_dates where='last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month)' do='each' join=', '><r:show attr='title'/> (last:<r:show date='last_date'/>, next:<r:show date='next_date'/>)</r:course_emp_dates>" res: "mike (last:, next:), roger (last:2002-05-05, next:2003-05-05)" all_course_emp_date: src: | - <ol do='all_course_emp_dates order by priority desc, log_at asc, node_name ASC'> + <ol do='all_course_emp_dates order by priority desc, log_at asc, title ASC'> <r:group by='priority'> <li do='each_group' set_class='priority[priority]'> <ol> - <li do='each'><r:if test='min_next_date'><r:show date='min_next_date' tformat='%Y-%m-%d'/><r:else>ASAP</r:else></r:if> <r:show attr='node_name'/> (<r:show attr='emp_count'/>)</li> + <li do='each'><r:if test='min_next_date'><r:show date='min_next_date' tformat='%Y-%m-%d'/><r:else>ASAP</r:else></r:if> <r:show attr='title'/> (<r:show attr='emp_count'/>)</li> </ol> </li> </r:group> @@ -166,11 +166,11 @@ all_course_emp_dates_in_six_months: ref_date: 2003-09-01 # in 6 months = before 2004-03-01 src: | - <ol do='all_course_emp_dates where last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month) order by priority desc, log_at asc, node_name ASC'> + <ol do='all_course_emp_dates where last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month) order by priority desc, log_at asc, title ASC'> <r:group by='priority'> <li do='each_group' set_class='priority[priority]'> <ol> - <li do='each'><r:if test='min_next_date'><r:show date='min_next_date' tformat='%Y-%m-%d'/><r:else>ASAP</r:else></r:if> <r:show attr='node_name'/> (<r:show attr='emp_count'/>)</li> + <li do='each'><r:if test='min_next_date'><r:show date='min_next_date' tformat='%Y-%m-%d'/><r:else>ASAP</r:else></r:if> <r:show attr='title'/> (<r:show attr='emp_count'/>)</li> </ol> </li> </r:group> @@ -206,11 +206,11 @@ all_course_emp_dates_in_six_months_later: ref_date: 2004-03-01 # in 6 months = before 2004-09-01 src: | - <ol do='all_course_emp_dates where last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month) order by priority desc, log_at asc, node_name ASC'> + <ol do='all_course_emp_dates where last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month) order by priority desc, log_at asc, title ASC'> <r:group by='priority'> <li do='each_group' set_class='priority[priority]'> <ol> - <li do='each'><r:if test='min_next_date'><r:show date='min_next_date' tformat='%Y-%m-%d'/><r:else>ASAP</r:else></r:if> <r:show attr='node_name'/> (<r:show attr='emp_count'/>)</li> + <li do='each'><r:if test='min_next_date'><r:show date='min_next_date' tformat='%Y-%m-%d'/><r:else>ASAP</r:else></r:if> <r:show attr='title'/> (<r:show attr='emp_count'/>)</li> </ol> </li> </r:group> @@ -245,5 +245,5 @@ all_course_emp_dates_paginate: context: ref_date: 2004-03-01 # in 6 months = before 2004-09-01 - src: "<r:all_course_emp_dates where='last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month)' order='priority desc, log_at asc, node_name ASC' limit='3' paginate='p'><r:link page='list'/> <r:each join=',' do='node_name'/>" + src: "<r:all_course_emp_dates where='last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month)' order='priority desc, log_at asc, title ASC' limit='3' paginate='p'><r:link page='list'/> <r:each join=',' do='title'/>" res: "/1 <a.*>2</a> <a.*>3</a> <a.*>4</a> resp_management, secure_a_site, team_motivation/" diff --git a/test/integration/zafu_compiler/complex_ok.yml b/test/integration/zafu_compiler/complex_ok.yml index a1ccb383..1141470a 100644 --- a/test/integration/zafu_compiler/complex_ok.yml +++ b/test/integration/zafu_compiler/complex_ok.yml @@ -5,8 +5,8 @@ it_should_compile_custom_select: visitor: complex_admin site: complex ref_date: 2004-09-01 - src: "<r:emp_form_dates do='each' join=', '><r:show attr='node_name'/>(<r:priority/>)</r:emp_form_dates>" - res: 'secureASite(10), winchUsage(10), dangerousTransportations(10), engine(5), transmitInformation(5), fiberJunction(5), formulateProblems(5), radioUsage(1)' + src: "<r:emp_form_dates do='each' join=', '><r:show attr='title'/>(<r:priority/>)</r:emp_form_dates>" + res: 'how to use the winch(10), secure a site(10), dangerous transportations(10), engine maintenance(5), information transmission(5), fiber junction(5), problem formulation(5), how to use the radio(1)' it_should_group_by_custom_select: context: diff --git a/test/integration/zafu_compiler/conditional.yml b/test/integration/zafu_compiler/conditional.yml index 4243462a..27f5d034 100644 --- a/test/integration/zafu_compiler/conditional.yml +++ b/test/integration/zafu_compiler/conditional.yml @@ -84,18 +84,18 @@ do_if: res: "<b>it's false</b>" if_has_discussion: - src: "<r:show attr='node_name'/>:<r:if test='discussion'>yes<r:else>no</r:else></r:if> <r:context select='42'><r:show attr='node_name'/>:<r:if test='discussion'>yes<r:else>no</r:else></r:if></r:context>" - res: "status:yes letter:no" + src: "<r:show attr='title'/>:<r:if test='discussion'>yes<r:else>no</r:else></r:if> <r:context select='42'><r:show attr='title'/>:<r:if test='discussion'>yes<r:else>no</r:else></r:if></r:context>" + res: "status title:yes zena enhancements:no" case_ancestor: - src: "<r:root><r:pages><r:each join=', '><r:case><r:when eval='ancestor?(main)'><b><r:show attr='node_name'/></b></r:when><r:else><r:show attr='node_name'/></r:else></r:case></r:each></r:pages></r:root>" - res: "collections, nature, people, <b>projects</b>, skins" + src: "<r:root><r:pages><r:each join=', '><r:case><r:when eval='ancestor?(main)'><b><r:show attr='title'/></b></r:when><r:else><r:show attr='title'/></r:else></r:case></r:each></r:pages></r:root>" + res: "Collections, Nature, people, <b>projects list</b>, Skins (layout themes)" on_if_ancestor_no_class: - old_src: "<r:root><r:pages><li do='each' on_if_node='ancestor' join=', '><r:show attr='node_name'/></li></r:pages></r:root>" - src: "<r:root><r:pages><li do='each' on_if='ancestor?(main)' join=', '><r:show attr='node_name'/></li></r:pages></r:root>" + old_src: "<r:root><r:pages><li do='each' on_if_node='ancestor' join=', '><r:show attr='title'/></li></r:pages></r:root>" + src: "<r:root><r:pages><li do='each' on_if='ancestor?(main)' join=', '><r:show attr='title'/></li></r:pages></r:root>" tem: '/var3.ancestor\?\(@node\)/' - res: "<li class=''>collections</li>, <li class=''>nature</li>, <li class=''>people</li>, <li class=' on'>projects</li>, <li class=''>skins</li>" + res: "<li class=''>Collections</li>, <li class=''>Nature</li>, <li class=''>people</li>, <li class=' on'>projects list</li>, <li class=''>Skins (layout themes)</li>" multiple_class_conditions: src: "<li class='unknown' do='void' one_if='custom_a == 1' two_if='custom_a == 2'>Agrippina</li>" @@ -108,9 +108,9 @@ multiple_class_conditions_true_in_middle: # var1 = stored 'papa' test_ancestor_with_stored: - src: "<r:parent do='parent' set_papa='this' do='pages'><div do='each' super_if='papa.ancestor?(this)' do='node_name'/></r:parent>" + src: "<r:parent do='parent' set_papa='this' do='pages'><div do='each' super_if='papa.ancestor?(this)' do='title'/></r:parent>" tem: "/\(var1\.ancestor\?\(var4\)\)/" - res: "<div class=' super'>cleanWater</div><div class=''>wiki</div>" + res: "<div class=''>a wiki with Zena</div><div class=' super'>Clean Water project</div>" on_if_kind_of: context: @@ -119,21 +119,21 @@ on_if_kind_of: res: "<b class=' popo'>parc opening</b>" on_if_attribute: - src: "<r:projects in='site'><div do='each' on_if='assigned' do='node_name'/></r:projects>" + src: "<r:projects in='site'><div do='each' on_if='assigned' do='title'/></r:projects>" tem: "/var2.prop\['assigned'\]. \? ' on'/" - res: "<div class=' on'>cleanWater</div><div class=''>wiki</div><div class=''>zena</div>" + res: "<div class=''>a wiki with Zena</div><div class=' on'>Clean Water project</div><div class=''>Zena the wild CMS</div>" on_if_attribute_with_edit: - src: "<r:projects in='site'><div do='each' on_if='assigned'><r:show attr='node_name'/><r:edit/></div></r:projects>" + src: "<r:projects in='site'><div do='each' on_if='assigned'><r:show attr='title'/><r:edit/></div></r:projects>" tem: "/var2.prop\['assigned'\]. \? ' on'/" on_if_node_main: - src: "<r:parent><r:pages><div do='each' on_if='id == main.id' do='node_name'>hello</div></r:pages></r:parent>" - res: "<div class=''>crocodiles</div><div class=' on'>status</div><div class=''>track</div>" + src: "<r:parent><r:pages><div do='each' on_if='id == main.id' do='title'>hello</div></r:pages></r:parent>" + res: "<div class=''>crocodiles</div><div class=''>Keeping things clean !</div><div class=' on'>status title</div>" if_in_tag: - src: "<r:form><p do='if' in='form' do='node_name'/></r:form><i do='if' in='form' do='node_name'/>done." - res: "/<p>status</p>.*</form>done./" + src: "<r:form><p do='if' in='form' do='title'/></r:form><i do='if' in='form' do='title'/>done." + res: "/<p>status title</p>.*</form>done./" if_in_tag_else: src: "<r:if in='form'>in form<r:else>not in form</r:else></r:if>" @@ -155,9 +155,9 @@ if_now: res: "past" on_if_now: - src: "<p do='node_name' on_if='log_at > now'/>" + src: "<p do='title' on_if='log_at > now'/>" tem: "/@node.log_at>Time.now.*' on'/" - res: "<p class=''>status</p>" + res: "<p class=''>status title</p>" visitor_is_anon: context: @@ -168,6 +168,6 @@ visitor_is_anon: test_in_each: context: node: 'cleanWater' - src: "<ul do='pages'><li do='each' on_if='this.node_name == \"track\"' do='node_name'/></ul>" - tem: "/var2.node_name==\"track\"/" - res: "<ul><li class=''>crocodiles</li><li class=''>status</li><li class=' on'>track</li></ul>" + src: "<ul do='pages'><li do='each' on_if='this.title == \"Keeping things clean !\"' do='title'/></ul>" + tem: "/var2.prop\['title'\]==\"Keeping things clean !\"/" + res: "<ul><li class=''>crocodiles</li><li class=' on'>Keeping things clean !</li><li class=''>status title</li></ul>" diff --git a/test/integration/zafu_compiler/data.yml b/test/integration/zafu_compiler/data.yml index 493ec8a1..57f760c5 100644 --- a/test/integration/zafu_compiler/data.yml +++ b/test/integration/zafu_compiler/data.yml @@ -43,15 +43,15 @@ stat_max: res: "56.0" group_stat_sum: - src: "<r:data><r:group by='node_a'><r:each_group><r:node_a do='node_name'/>:<r:stat find='sum'/> </r:each_group></r:group></r:data>" + src: "<r:data><r:group by='node_a'><r:each_group><r:node_a do='title'/>:<r:stat find='sum'/> </r:each_group></r:group></r:data>" res: "cleanWater:27.0 wiki:102.0 " li_each_group: - src: "<r:data><r:group by='node_a'><li set_class='[node_a_id]_class' do='each_group'><r:node_a do='node_name'/>:<r:stat find='sum'/> </li></r:group></r:data>" + src: "<r:data><r:group by='node_a'><li set_class='[node_a_id]_class' do='each_group'><r:node_a do='title'/>:<r:stat find='sum'/> </li></r:group></r:data>" res: "<li class='21_class'>cleanWater:27.0 </li><li class='29_class'>wiki:102.0 </li>" group_stat_sum_join: - src: "<r:data><r:group by='node_b' join=', '><r:node_b><r:show attr='node_name'/><r:else text='undef'/></r:node_b>:<r:stat find='sum'/></r:group></r:data>" + src: "<r:data><r:group by='node_b' join=', '><r:node_b><r:show attr='title'/><r:else text='undef'/></r:node_b>:<r:stat find='sum'/></r:group></r:data>" res: "undef:96.0, cleanWater:33.0" stat_max_no_entries: diff --git a/test/integration/zafu_compiler/dates.yml b/test/integration/zafu_compiler/dates.yml index 56fb2574..6d6a47b0 100644 --- a/test/integration/zafu_compiler/dates.yml +++ b/test/integration/zafu_compiler/dates.yml @@ -12,8 +12,8 @@ date: visitor: ant node: 'letter' lang: 'fr' - src: "<r:void set_date='log_at'>nouvelles <r:show eval='trans(date.strftime(\"%B\"))'/> <r:show eval='date' format='%Y'/>: <r:notes where='log_at.month eq #{date}.month' in='site' do='each' join=', ' do='node_name'/></r:void>" - res: "nouvelles avril 2006: letter" + src: "<r:void set_date='log_at'>nouvelles <r:show eval='trans(date.strftime(\"%B\"))'/> <r:show eval='date' format='%Y'/>: <r:notes where='log_at.month eq #{date}.month' in='site' do='each' join=', ' do='title'/></r:void>" + res: "nouvelles avril 2006: zena enhancements" select_date_attr: src: "<p do='void' set_date='log_at'><span do='show' eval='date.year'/></p>" @@ -80,8 +80,8 @@ date_tz: date_tz_field: context: node: nature - src: "<r:nodes do='each' join=', '><r:show attr='node_name'/>: <r:show date='created_at' format='%H:%M' tz='#{tz || \"Europe/Zurich\"}'/> | <r:show date='created_at' format='%H:%M' tz='UTC'/></r:nodes>" - res: "forest: 01:00 | 00:00, tree: 07:00 | 00:00" + src: "<r:nodes do='each' join=', '><r:show attr='title'/>: <r:show date='created_at' format='%H:%M' tz='#{tz || \"Europe/Zurich\"}'/> | <r:show date='created_at' format='%H:%M' tz='UTC'/></r:nodes>" + res: "Autumn Tree: 07:00 | 00:00, Forest: 01:00 | 00:00" date_fr: context: diff --git a/test/integration/zafu_compiler/display.yml b/test/integration/zafu_compiler/display.yml index 02b4d993..cdc228e9 100644 --- a/test/integration/zafu_compiler/display.yml +++ b/test/integration/zafu_compiler/display.yml @@ -29,9 +29,11 @@ show_title_link_http: res: "<a href='http://example.com'>status title</a>" show_title_link_attribute: + context: + node: 'bird_jpg' old_src: "<r:title link='http://[name].com'/>" - src: "<a href='http://#{node_name}.com' do='title'/>" - res: "<a href='http://status.com'>status title</a>" + src: "<a href='http://#{title}.com' do='title'/>" + res: "<a href='http://bird.com'>bird</a>" show_title_link_id: old_src: "<r:title link='32'/>" @@ -50,12 +52,12 @@ do_title: show_title_link_id_from_stored: # disabled old_src: "<r:parent><r:title link='[main.id]'/></r:parent>" - old_res: "<a href='/oo/projects/cleanWater/page22.html'><span id='title21'>Clean Water project</span></a>" + old_res: "<a href='/oo/projects-list/Clean-Water-project/page22.html'><span id='title21'>Clean Water project</span></a>" show_title_link_id_from_stored_mode_and_format: # disabled old_src: "<r:parent><r:title link='[main.id]_blog.rss'/></r:parent>" - old_res: "<a href='/oo/projects/cleanWater/page22_blog.rss'><span id='_title21'>Clean Water project</span></a>" + old_res: "<a href='/oo/projects-list/Clean-Water-project/page22_blog.rss'><span id='_title21'>Clean Water project</span></a>" show_live_no_tag: src: "<r:show attr='title' live='true'/>" @@ -120,8 +122,8 @@ zazen_code: res: "/<code class='css'><span class=\"tag\">body</span>/" show_name: - src: "my <r:show attr='node_name'/>" - res: "my status" + src: "my <r:show attr='title'/>" + res: "my status title" show_text: old_src: "my <r:show attr='text'/>" @@ -137,9 +139,9 @@ show_width: show_else: old_src: "<r:show attr='comment' else='name'/>" - src: "<r:show eval='origin || node_name'/>" - tem: "<%= (@node.prop['origin'] or @node.node_name) %>" - res: "status" + src: "<r:show eval='origin || title'/>" + tem: "<%= (@node.prop['origin'] or @node.prop['title']) %>" + res: "status title" show_default: old_src: "<r:show attr='d_foo' default='baz'/>" @@ -193,7 +195,7 @@ img_tag_icon: context: node: 'cleanWater' src: "<r:img alt_src='icon'/>" - res: "<img src='/en/projects/cleanWater/image24_std.jpg?929831698949' width='545' height='400' alt='it's a lake' class='std'/>" + res: "<img src='/en/projects-list/Clean-Water-project/image24_std.jpg?929831698949' width='545' height='400' alt='it's a lake' class='std'/>" icon: context: diff --git a/test/integration/zafu_compiler/errors.yml b/test/integration/zafu_compiler/errors.yml index 8c36dbdd..ca8f4305 100644 --- a/test/integration/zafu_compiler/errors.yml +++ b/test/integration/zafu_compiler/errors.yml @@ -20,15 +20,15 @@ bad_query: tem: "<span class='parser_error'><span class='method'>images</span> <span class='message'>Syntax error near \"oo bar baz\".</span></span>" bad_field_in_query: - src: "<r:images where='node_name = baz'>ok</r:images>" + src: "<r:images where='title = baz'>ok</r:images>" res: "<span class='parser_error'><span class='method'>images</span> <span class='message'>Unknown field 'baz'.</span></span>" bad_relation: - src: "<div do='categories in site' do='each' join=', ' do='node_name'/>" + src: "<div do='categories in site' do='each' join=', ' do='title'/>" tem: "<div><span class='parser_error'><span class='method'>categories in site</span> <span class='message'>Unknown relation 'categories'.</span></span></div>" bad_order_clause: - src: "<r:images order='l_status ASC' do='each' join=',' do='node_name'/>" + src: "<r:images order='l_status ASC' do='each' join=',' do='title'/>" res: "/Unknown field 'l_status'./" show_var: @@ -56,7 +56,7 @@ nil_value: res: "" not_finished_block: - src: "<r:if kind_of='Document'><r:link format='data'><r:img mode='tiny'/> <r:show attr='node_name'/>.<r:show attr='ext'/></r:link><r:else do='link'/></r:if>" + src: "<r:if kind_of='Document'><r:link format='data'><r:img mode='tiny'/> <r:show attr='title'/>.<r:show attr='ext'/></r:link><r:else do='link'/></r:if>" missing_template: src: "<r:include template='Foo'/>" diff --git a/test/integration/zafu_compiler/eval.yml b/test/integration/zafu_compiler/eval.yml index ce777953..25d8cc36 100644 --- a/test/integration/zafu_compiler/eval.yml +++ b/test/integration/zafu_compiler/eval.yml @@ -12,7 +12,7 @@ sprintf: res: "<b>22.00</b>" set_var: - src: "<r:set var='foo'>I am <r:show attr='node_name'/></r:set> <p do='show' var='foo'/>" + src: "<r:set var='foo'>I am <r:show attr='title'/></r:set> <p do='show' var='foo'/>" tem: "<% set_foo = capture do %>I am <%= @node.name %><% end -%> <p><%= set_foo %></p>" res: " <p>I am status</p>" @@ -47,7 +47,7 @@ show_var: res: "<b>12345</b>" show_var_overwrites_attribute: - src: "<r:set var='name'>12345</r:set><b do='node_name'/>" + src: "<r:set var='name'>12345</r:set><b do='title'/>" res: "<b>12345</b>" test_var: diff --git a/test/integration/zafu_compiler/forms.yml b/test/integration/zafu_compiler/forms.yml index 677b7489..174e4a6b 100644 --- a/test/integration/zafu_compiler/forms.yml +++ b/test/integration/zafu_compiler/forms.yml @@ -9,7 +9,7 @@ default: add_btn: src: "<table do='pages' in='site' limit='1'> - <tr do='each'><td do='node_name'/></tr> + <tr do='each'><td do='title'/></tr> <tr do='add'><td><b><r:add_btn/></b></td></tr> </table>" res: "/<tr class='btn_add' id='list1_add'><td><b><a href='#' onclick/" @@ -48,10 +48,10 @@ select_class_new_node: select_nodes: src: "<r:form><select nodes='images in site' name='foo'></select></r:form>" - res: "/name='node\[foo\]'><option value=\"\" selected=\"selected\"></option>\n<option value=\"30\">bird</option>\n<option value=\"31\">flower</option>/" + res: "/name='node\[foo\]'><option value=\"\" selected=\"selected\"></option>\n<option value=\"40\">Autumn Tree</option>\n<option value=\"30\">bird</option>/" do_not_set_parent_id_if_form_contains_parent_id: - src: "<r:children><r:each do='node_name'/><r:add/><r:form><r:select name='parent_id' nodes='projects in site'/><input name='title'/></r:form></r:children>" + src: "<r:children><r:each do='title'/><r:add/><r:form><r:select name='parent_id' nodes='projects in site'/><input name='title'/></r:form></r:children>" res: "!/node\[parent_id\].\s+value/" select_nodes_selected: @@ -59,8 +59,8 @@ select_nodes_selected: res: "/option\s* value=.21.\s* selected=.selected.>Clean Water/" select_nodes_in_ajax: - src: "<r:pages><r:each do='node_name'/><r:add/><r:form><r:select nodes='images in site' name='d_ref'/></r:form></r:pages>" - res: "/name=.node\[d_ref\].><option value=\"\" selected=\"selected\"></option>\n<option value=\"30\">bird</option>\n<option value=\"31\">flower</option>/" + src: "<r:pages><r:each do='title'/><r:add/><r:form><r:select nodes='images in site' name='d_ref'/></r:form></r:pages>" + res: "/name=.node\[d_ref\].><option value=\"\" selected=\"selected\"></option>\n<option value=\"40\">Autumn Tree</option>\n<option value=\"30\">bird</option>/" select_nodes_show_attr: src: "<r:form><r:select name='title' nodes='images in site' attr='ext' show='title'/></r:form>" @@ -89,7 +89,7 @@ checkbox_finder: context: node: 'opening' src: "<r:checkbox role='calendar' nodes='projects in site'/>" - res: "/value=.21.*Clean Water.*input type=.checkbox. name=.node\[calendar_ids\]\[\]. value=.29. checked=.checked.*wiki/" + res: "/input type=.checkbox. name=.node\[calendar_ids\]\[\]. value=.29. checked=.checked.*wiki.*value=.21.*Clean Water/" checkbox_checked_value: src: "<r:input type='checkbox' name='tagged[sky]'/>" @@ -140,3 +140,13 @@ show_in_form: src: "<r:form><b do='title'/></r:form>" tem: "/<b><%= @node.prop\['title'\] %></b>/" res: '/<b>status title</b>/' + +set_parent_id: + src: "<r:form></r:form>" + tem: "/node\[parent_id\].*@node.parent_zip/" + res: "/<input type='hidden' name='node\[parent_id\]' value='21'/>/" + +set_parent_id_in_new: + src: "<r:new klass='Page' do='form'></r:new>" + tem: "/node\[parent_id\].*@node.zip/" + res: "/<input type='hidden' name='node\[parent_id\]' value='22'/>/" diff --git a/test/integration/zafu_compiler/i18n.yml b/test/integration/zafu_compiler/i18n.yml index 263780bb..7ebd549f 100644 --- a/test/integration/zafu_compiler/i18n.yml +++ b/test/integration/zafu_compiler/i18n.yml @@ -87,7 +87,7 @@ trans_text_dyn_string: trans_rubyless_dyn_string: context: lang: 'fr' - src: "<r:load dictionary='/default/translations'><p do='t(\"lang_#{ref_lang}\")'/></r:load>" + src: "<r:load dictionary='/Default skin/translations'><p do='t(\"lang_#{ref_lang}\")'/></r:load>" res: "<p>anglais</p>" trans_literal_string: @@ -112,16 +112,16 @@ complex_lang_list: <ul do='site.lang_list'> <li do='each' class='#{this == visitor.lang ? "on" : "off"}' do='zen_path(@node, :lang => this)'/> </ul> - res: "/li class='on'>/oo/projects/cleanWater/page22.html\?lang=en</" + res: "/li class='on'>/oo/projects-list/Clean-Water-project/page22.html\?lang=en</" html_lang_and_dict: - src: "<html xmlns='http://www.w3.org/1999/xhtml' lang='#{v.lang}' do='load' dictionary='/default/translations' xml:lang='en'></html>" + src: "<html xmlns='http://www.w3.org/1999/xhtml' lang='#{v.lang}' do='load' dictionary='/Default skin/translations' xml:lang='en'></html>" res: "<html xmlns='http://www.w3.org/1999/xhtml' lang='en'></html>" dictionary_fr: context: lang: 'fr' - src: "<r:load dictionary='/default/translations'><r:trans>foo</r:trans>: <r:t>I love</r:t> <r:trans>words</r:trans></r:load>" + src: "<r:load dictionary='/Default skin/translations'><r:trans>foo</r:trans>: <r:t>I love</r:t> <r:trans>words</r:trans></r:load>" tem: "<% _zdict = load_dictionary(828931430) -%>foo: j'aime les mots" res: "foo: j'aime les mots" @@ -129,34 +129,34 @@ dynamic_dictionary_eval_fr: context: lang: 'fr' node: status - src: "<r:load dictionary='/default/translations'><r:eval>trans(node_name)</r:eval></r:load>" - tem: "<% _zdict = load_dictionary(828931430) -%><%= _zdict.get(@node.node_name) %>" - res: "statut" + src: "<r:load dictionary='/Default skin/translations'><r:eval>trans(title)</r:eval></r:load>" + tem: "<% _zdict = load_dictionary(828931430) -%><%= _zdict.get(@node.prop['title']) %>" + res: "Etat des travaux" dynamic_dictionary_t_fr: context: lang: 'fr' node: status - src: "<r:load dictionary='/default/translations'><r:t attr='node_name'/></r:load>" - tem: "<% _zdict = load_dictionary(828931430) -%><%= _zdict.get(@node.node_name) %>" - res: "statut" + src: "<r:load dictionary='/Default skin/translations'><r:t attr='title'/></r:load>" + tem: "<% _zdict = load_dictionary(828931430) -%><%= _zdict.get(@node.prop['title']) %>" + res: "Etat des travaux" dynamic_dictionary_literal_fr: context: lang: 'fr' node: status - src: "<r:load dictionary='/default/translations'><r:eval>trans('status')</r:eval></r:load>" + src: "<r:load dictionary='/Default skin/translations'><r:eval>trans('status title')</r:eval></r:load>" tem: "<% _zdict = load_dictionary(828931430) -%>statut" res: "statut" dictionary_de: context: lang: 'de' - src: "<r:load dictionary='/default/translations'><r:trans>foo</r:trans>: <r:trans>I love</r:trans> <r:trans>words</r:trans></r:load>" + src: "<r:load dictionary='/Default skin/translations'><r:trans>foo</r:trans>: <r:trans>I love</r:trans> <r:trans>words</r:trans></r:load>" tem: "<% _zdict = load_dictionary(828931430) -%>foo: Ich liebe Wörter" res: "foo: Ich liebe Wörter" dictionary_tformat: - src: "<r:load dictionary='/default/translations'><r:show date='created_at' tformat='date_format'/></r:load>" + src: "<r:load dictionary='/Default skin/translations'><r:show date='created_at' tformat='date_format'/></r:load>" tem: "<% _zdict = load_dictionary(828931430) -%><%= format_date(@node.created_at, :format => \"[%d.%m]\") %>" res: "[10.03]" \ No newline at end of file diff --git a/test/integration/zafu_compiler/later.yml b/test/integration/zafu_compiler/later.yml index f9495d37..4d214224 100644 --- a/test/integration/zafu_compiler/later.yml +++ b/test/integration/zafu_compiler/later.yml @@ -6,7 +6,7 @@ if_test_param_var: # [zafu_attribute:edit] needs reimplementation with JS rendering (like drag/drop): use data attribute ? class name ? show_edit: - src: "<r:show attr='node_name' edit='true'/>" + src: "<r:show attr='title' edit='true'/>" tem: "<% if @node.can_write? -%><span class='show_edit' id='list1_name'><%= link_to_remote(@node.name, :url => edit_node_path(@node.zip) + \"?attribute=name&dom_id=list1_name\", :method => :get) %></span><% else -%><%= @node.name %><% end -%>" res: "/span class='show_edit' id='list1_name'>.*Ajax\.Request\('/nodes/22/edit\?attribute=name/" @@ -27,17 +27,17 @@ each_in_each_dom_id: # [ajax] zazen edit=true (maybe should implement in zafu_attributes with filter_edit) zazen_edit: - src: "<r:zazen attr='node_name' edit='true'/>" - tem: "<div class='zazen' id='list1_name'><% if @node.can_write? -%><span class='zazen_edit'><%= link_to_remote(\"edit\", :url => edit_node_path(@node.zip) + \"?attribute=name&dom_id=list1_name&zazen=true\", :method => :get) %></span><% end -%><%= zazen(@node.node_name, :node=>@node) %></div>" + src: "<r:zazen attr='title' edit='true'/>" + tem: "<div class='zazen' id='list1_name'><% if @node.can_write? -%><span class='zazen_edit'><%= link_to_remote(\"edit\", :url => edit_node_path(@node.zip) + \"?attribute=name&dom_id=list1_name&zazen=true\", :method => :get) %></span><% end -%><%= zazen(@node.prop['title'], :node=>@node) %></div>" res: "/div class='zazen' id='list1_name'>.*Ajax\.Request\('/nodes/22/edit\?attribute=name/" zazen_edit_publish_force: - src: "<r:zazen attr='node_name' edit='true' publish='force'/>" - tem: "/attribute=node_name&dom_id=.*_node_name&publish=force&zazen=true/" + src: "<r:zazen attr='title' edit='true' publish='force'/>" + tem: "/attribute=title&dom_id=.*_title&publish=force&zazen=true/" zazen_edit_publish_true: - src: "<r:zazen attr='node_name' edit='true' publish='true'/>" - tem: "/attribute=node_name&dom_id=.*_node_name&publish=true&zazen=true/" + src: "<r:zazen attr='title' edit='true' publish='true'/>" + tem: "/attribute=title&dom_id=.*_title&publish=true&zazen=true/" # Update query builder for DataEntry select_nodes_data_list: diff --git a/test/integration/zafu_compiler/off/off.yml b/test/integration/zafu_compiler/off/off.yml index ddb640c3..eac5db2d 100644 --- a/test/integration/zafu_compiler/off/off.yml +++ b/test/integration/zafu_compiler/off/off.yml @@ -1,6 +1,6 @@ cache_part: - src: "<r:cache><r:show attr='node_name'/></r:cache>" + src: "<r:cache><r:show attr='title'/></r:cache>" tem: "<% cache1 = Cache.with(visitor.id, visitor.group_ids, \"NP\", \"en\", \"/cache/part/list1\") do capture do %><%= @node.name %><% end; end %><%= cache1 %>" trans_show: @@ -12,4 +12,4 @@ trans_show: node_path: src: "<r:context select='/projects/wiki'><r:link/></r:context>" - res: "<a href='/en/project29.html'>a wiki with zena</a>" \ No newline at end of file + res: "<a href='/en/project29.html'>a wiki with Zena</a>" \ No newline at end of file diff --git a/test/integration/zafu_compiler/recursion.yml b/test/integration/zafu_compiler/recursion.yml index e600793b..7d794862 100644 --- a/test/integration/zafu_compiler/recursion.yml +++ b/test/integration/zafu_compiler/recursion.yml @@ -5,8 +5,8 @@ default: node: 'status' basic: - src: "<r:void name='grp'><r:show attr='node_name'/><r:parent> -- <r:include part='grp'/></r:parent></r:void>" - res: "status -- cleanWater -- projects -- zena" + src: "<r:void name='grp'><r:show attr='title'/><r:parent> -- <r:include part='grp'/></r:parent></r:void>" + res: "status title -- Clean Water project -- projects list -- Zena the wild CMS" in_each: src: "<ul do='comments'> diff --git a/test/integration/zafu_compiler/relations.yml b/test/integration/zafu_compiler/relations.yml index 97e3d6ef..df4e044c 100644 --- a/test/integration/zafu_compiler/relations.yml +++ b/test/integration/zafu_compiler/relations.yml @@ -5,41 +5,41 @@ default: node: 'status' set_tags: - src: "<r:project><r:show attr='node_name'/>: <r:set_tags><r:each join=', '><r:show attr='node_name'/></r:each></r:set_tags></r:project>" - res: "cleanWater: art" + src: "<r:project><r:show attr='title'/>: <r:set_tags><r:each join=', '><r:show attr='title'/></r:each></r:set_tags></r:project>" + res: "Clean Water project: Art" documents: context: node: 'nature' visitor: ant - src: "<r:documents><r:each join=', '><r:show attr='node_name'/></r:each></r:documents>" - res: "forest, tree" + src: "<r:documents><r:each join=', '><r:show attr='title'/></r:each></r:documents>" + res: "Autumn Tree, Forest" documents_only: context: node: 'nature' visitor: ant - src: "<r:documents where='kpath not like \"NDI%\"'><r:each join=', '><r:show attr='node_name'/></r:each></r:documents>" - res: "forest" + src: "<r:documents where='kpath not like \"NDI%\"'><r:each join=', '><r:show attr='title'/></r:each></r:documents>" + res: "Forest" images: context: node: 'wiki' - src: "<r:images><r:each join=', '><r:show attr='node_name'/></r:each></r:images>" + src: "<r:images><r:each join=', '><r:show attr='title'/></r:each></r:images>" res: "bird, flower" icon: context: node: 'cleanWater' - src: "<r:icon do='node_name'/>" + src: "<r:icon do='title'/>" tem: "/ORDER BY links.id DESC/" - res: "lake" + res: "it's a lake" pages: context: node: 'cleanWater' - src: "<r:pages><r:each join=', '><r:show attr='node_name'/></r:each></r:pages>" - res: "status, track" + src: "<r:pages><r:each join=', '><r:show attr='title'/></r:each></r:pages>" + res: "Keeping things clean !, status title" root: src: "<r:root do='[title]'/>" @@ -48,59 +48,59 @@ root: notes: context: node: 'cleanWater' - src: "<r:notes><r:each join=', '><r:show attr='node_name'/></r:each></r:notes>" - res: "opening" + src: "<r:notes><r:each join=', '><r:show attr='title'/></r:each></r:notes>" + res: "parc opening" blog_with_news: context: node: 'zena' class: Project - src: "<r:notes or='news' do='each' join=', ' do='node_name'/>" - res: "letter, opening" + src: "<r:notes or='news' do='each' join=', ' do='title'/>" + res: "parc opening, zena enhancements" blog_with_bad_relation: context: node: 'zena' - src: "<r:notes or='whatever' do='each' join=', ' do='node_name'/>" + src: "<r:notes or='whatever' do='each' join=', ' do='title'/>" res: "/Unknown relation 'whatever'/" pages_do_syntax: - src: "<ol do='pages where node_name like \"c%\" in site'><li do='each' do='node_name'/></ol>" - res: "<ol><li>cleanWater</li><li>collections</li></ol>" + src: "<ol do='pages where title like \"c%\" in site'><li do='each' do='title'/></ol>" + res: "<ol><li>Clean Water project</li><li>Collections</li></ol>" pages_limit: context: node: 'cleanWater' - src: "<r:pages limit='2' order='node_name DESC'><r:each join=', '><r:show attr='node_name'/></r:each></r:pages>" - res: "track, status" + src: "<r:pages limit='2' order='title DESC'><r:each join=', '><r:show attr='title'/></r:each></r:pages>" + res: "status title, Keeping things clean !" pages_random: context: node: 'cleanWater' - src: "<r:pages limit='3' order='random'><r:each join=', '><r:show attr='node_name'/></r:each></r:pages>" + src: "<r:pages limit='3' order='random'><r:each join=', '><r:show attr='title'/></r:each></r:pages>" tem: "/ORDER BY RAND/" nodes_in_project: - src: "<r:nodes in='project' limit='2'><r:each join=', '><r:show attr='node_name'/></r:each></r:nodes>" - res: "lake, lakeAddress" + src: "<r:nodes in='project' limit='2'><r:each join=', '><r:show attr='title'/></r:each></r:nodes>" + res: "it's a lake, Keeping things clean !" nodes_in_project_stored: - src: "<r:void set_foo='this'><r:node where='id = 29 in site'>from <r:show attr='node_name'/>, look at <r:foo do='node_name'/>: <r:foo do='pages in project' do='each' join=', ' do='node_name'/></r:node></r:void>" - res: "from wiki, look at status: status, track" + src: "<r:void set_foo='this'><r:node where='id = 29 in site'>from <r:show attr='title'/>, look at <r:foo do='title'/>: <r:foo do='pages in project' do='each' join=', ' do='title'/></r:node></r:void>" + res: "from a wiki with Zena, look at status title: Keeping things clean !, status title" nodes_in_site: - src: "<r:nodes in='site' limit='3'><r:each join=', ' do='show' attr='node_name'/></r:nodes>" - res: "anonymous, ant, art" + src: "<r:nodes in='site' limit='3'><r:each join=', ' do='show' attr='title'/></r:nodes>" + res: "a wiki with Zena, Art, bird" context: - src: "<r:context select='nodes' in='site' limit='3'><r:each join=', ' do='show' attr='node_name'/></r:context>" - res: "anonymous, ant, art" + src: "<r:context select='nodes' in='site' limit='3'><r:each join=', ' do='show' attr='title'/></r:context>" + res: "a wiki with Zena, Art, bird" author_visitor: context: visitor: ant - src: "<r:pages in='site' where='user_id = #{visitor.id}' limit='5'><r:each join=', ' do='show' attr='node_name'/></r:pages>" - res: "myLife, nature, status" + src: "<r:pages in='site' where='user_id = #{visitor.id}' limit='5'><r:each join=', ' do='show' attr='title'/></r:pages>" + res: "My Life, Nature, status title" author: src: "my master: <r:author><r:name/> <r:first_name/></r:author> my version master: <r:version do='author'><r:name/> <r:first_name/></r:version>" @@ -121,13 +121,13 @@ public_readable_link_id: tem: '<%= @node.rel["icon"].try(:other_zip) %>' node_id: - old_src: "I (<r:show attr='node_name'/>) know: <r:context select='12'><r:show attr='node_name'/> with <r:children><span do='each' join=', '><r:show attr='node_name'>child</r:show></span></r:children></r:context>" - src: "I (<r:show attr='node_name'/>) know: <r:node where='id = 12 in site'><r:show attr='node_name'/> with <r:children><span do='each' join=', '><r:show attr='node_name'>child</r:show></span></r:children></r:node>" - res: "I (status) know: people with <span>anonymous</span>, <span>ant</span>, <span>lion</span>, <span>tiger</span>" + old_src: "I (<r:show attr='title'/>) know: <r:context select='12'><r:show attr='title'/> with <r:children><span do='each' join=', '><r:show attr='title'>child</r:show></span></r:children></r:context>" + src: "I (<r:show attr='title'/>) know: <r:node where='id = 12 in site'><r:show attr='title'/> with <r:children><span do='each' join=', '><r:show attr='title'>child</r:show></span></r:children></r:node>" + res: "I (status title) know: people with <span>Panthera Leo Verneyi</span>, <span>Panthera Tigris Sumatran</span>, <span>Solenopsis Invicta</span>, <span>Mr nobody</span>" context_root: - src: "<r:context select='root'><r:show attr='node_name'/></r:context>" - res: "zena" + src: "<r:context select='root'><r:show attr='title'/></r:context>" + res: "Zena the wild CMS" parent: src: "<r:parent do='title'/>" @@ -135,7 +135,7 @@ parent: res: "Clean Water project" parent_no_parent: - src: "result=<r:root><r:parent><r:show attr='node_name'/></r:parent></r:root>=" + src: "result=<r:root><r:parent><r:show attr='title'/></r:parent></r:root>=" res: "result==" node_not_found: @@ -157,8 +157,8 @@ children_else_block: res: "I am not tired." each_not_in_list: - src: "<r:each><r:show attr='node_name'/></r:each>" - res: "status" + src: "<r:each><r:show attr='title'/></r:each>" + res: "status title" hot_else_block: context: @@ -174,75 +174,75 @@ hot_not_else_block: res: "I am hot funny" children_else: - src: "<r:children find='first' where='node_name like \"%asdfg\"' else='this'><r:show attr='node_name'/></r:children>" - res: "status" + src: "<r:children find='first' where='title like \"%asdfg\"' else='this'><r:show attr='title'/></r:children>" + res: "status title" hot_else: context: class: Project - src: "<r:hot else='project'><r:show attr='node_name'/></r:hot>" - res: "cleanWater" + src: "<r:hot else='project'><r:show attr='title'/></r:hot>" + res: "Clean Water project" updated_today: # date set in ZafuCompilerTest - src: "<r:pages in='site' updated='today' do='each' join=', ' do='show' attr='node_name'/>" - src: "<r:pages in='site' where='updated_at.day = now.day' do='each' join=', ' do='show' attr='node_name'/>" - res: "art, status" + src: "<r:pages in='site' updated='today' do='each' join=', ' do='show' attr='title'/>" + src: "<r:pages in='site' where='updated_at.day = now.day' do='each' join=', ' do='show' attr='title'/>" + res: "Art, status title" upcoming_events: # date set in ZafuCompilerTest - src: "<r:pages in='site' log='upcoming' do='each' join=', ' do='show' attr='node_name'/>" - src: "<r:pages in='site' where='log_at gt now' do='each' join=', ' do='show' attr='node_name'/>" + src: "<r:pages in='site' log='upcoming' do='each' join=', ' do='show' attr='title'/>" + src: "<r:pages in='site' where='log_at gt now' do='each' join=', ' do='show' attr='title'/>" res: "people" in_7_days: # date set in ZafuCompilerTest - old_src: "<r:pages in='site' log='+7days' do='each' join=', ' do='show' attr='node_name'/>" - src: "<r:pages in='site' where='log_at gt now and log_at lt now + 7 days' do='each' join=', ' do='show' attr='node_name'/>" - res: "cleanWater, projects" + old_src: "<r:pages in='site' log='+7days' do='each' join=', ' do='show' attr='title'/>" + src: "<r:pages in='site' where='log_at gt now and log_at lt now + 7 days' do='each' join=', ' do='show' attr='title'/>" + res: "Clean Water project, projects list" logged_7_days_ago: # date set in ZafuCompilerTest - old_src: "<r:pages in='site' log='-7days' do='each' join=', ' do='show' attr='node_name'/>" - src: "<r:pages in='site' where='log_at gt now - 7 days and log_at lt now' do='each' join=', ' do='show' attr='node_name'/>" - res: "cleanWater, projects" + old_src: "<r:pages in='site' log='-7days' do='each' join=', ' do='show' attr='title'/>" + src: "<r:pages in='site' where='log_at gt now - 7 days and log_at lt now' do='each' join=', ' do='show' attr='title'/>" + res: "Clean Water project, projects list" around_7_days: # date set in ZafuCompilerTest - old_src: "<r:pages in='site' log='7days' do='each' join=', ' do='show' attr='node_name'/>" - src: "<r:pages in='site' where='log_at gt now - 7 days and log_at lt now + 7 days' do='each' join=', ' do='show' attr='node_name'/>" - res: "art, cleanWater, projects, status" + old_src: "<r:pages in='site' log='7days' do='each' join=', ' do='show' attr='title'/>" + src: "<r:pages in='site' where='log_at gt now - 7 days and log_at lt now + 7 days' do='each' join=', ' do='show' attr='title'/>" + res: "Art, Clean Water project, projects list, status title" in_37_hours: # date set in ZafuCompilerTest - old_src: "<r:pages in='site' log='+37hours' do='each' join=', ' do='show' attr='node_name'/>" - src: "<r:pages in='site' where='log_at gt now and log_at lt now + 37 hours' do='each' join=', ' do='show' attr='node_name'/>" - res: "art, cleanWater" + old_src: "<r:pages in='site' log='+37hours' do='each' join=', ' do='show' attr='title'/>" + src: "<r:pages in='site' where='log_at gt now and log_at lt now + 37 hours' do='each' join=', ' do='show' attr='title'/>" + res: "Art, Clean Water project" this_week: # date set in ZafuCompilerTest - old_src: "<r:pages in='site' event='week' do='each' join=', ' do='show' attr='node_name'/>" - src: "<r:pages in='site' where='event_at.week = now.week' do='each' join=', ' do='show' attr='node_name'/>" - res: "art, projects" + old_src: "<r:pages in='site' event='week' do='each' join=', ' do='show' attr='title'/>" + src: "<r:pages in='site' where='event_at.week = now.week' do='each' join=', ' do='show' attr='title'/>" + res: "Art, projects list" this_month: # date set in ZafuCompilerTest - old_src: "<r:pages in='site' event='month' do='each' join=', ' do='show' attr='node_name'/>" - src: "<r:pages in='site' where='event_at.month = now.month' do='each' join=', ' do='show' attr='node_name'/>" - res: "art, projects" + old_src: "<r:pages in='site' event='month' do='each' join=', ' do='show' attr='title'/>" + src: "<r:pages in='site' where='event_at.month = now.month' do='each' join=', ' do='show' attr='title'/>" + res: "Art, projects list" this_year: # date set in ZafuCompilerTest - old_src: "<r:pages in='site' event='year' do='each' join=', ' do='show' attr='node_name'/>" - src: "<r:pages in='site' where='event_at.year = now.year' do='each' join=', ' do='show' attr='node_name'/>" - res: "art, projects" + old_src: "<r:pages in='site' event='year' do='each' join=', ' do='show' attr='title'/>" + src: "<r:pages in='site' where='event_at.year = now.year' do='each' join=', ' do='show' attr='title'/>" + res: "Art, projects list" date_select: context: visitor: tiger - old_src: "<r:date select='2006-04-05'><r:nodes in='site' log='current' do='each' join=', ' do='show' attr='node_name'/>" - src: "<r:void set_strdate='\"2006-04-05\"'><r:nodes where='log_at.day eq #{strdate}' in='site' do='each' join=', ' do='node_name'/></r:void>" - res: "letter, proposition" + old_src: "<r:date select='2006-04-05'><r:nodes in='site' log='current' do='each' join=', ' do='show' attr='title'/>" + src: "<r:void set_strdate='\"2006-04-05\"'><r:nodes where='log_at.day eq #{strdate}' in='site' do='each' join=', ' do='title'/></r:void>" + res: "Proposition, zena enhancements" empty_list: context: @@ -254,27 +254,27 @@ order_limit: context: node: 'zena' src: "<ul do='news' in='site' limit='5' order='updated_at desc'><li do='each'><r:link/></li></ul>" - res: "<ul><li><a href='/en/projects/cleanWater/post27.html'>parc opening</a></li></ul>" + res: "<ul><li><a href='/en/projects-list/Clean-Water-project/post27.html'>parc opening</a></li></ul>" relation_not_in_current_node: src: "<ul do='news' in='site' limit='5' order='updated_at desc'><li do='each'><r:link/></li></ul>" - res: "<ul><li><a href='/en/projects/cleanWater/post27.html'>parc opening</a></li></ul>" + res: "<ul><li><a href='/en/projects-list/Clean-Water-project/post27.html'>parc opening</a></li></ul>" pages_anchor: - src: "<r:pages in='site' limit='3' do='each' join=', '><r:show attr='node_name' anchor='true'/></r:pages>" - res: "<a class='anchor' name='node33'></a>art, <a class='anchor' name='node21'></a>cleanWater, <a class='anchor' name='node32'></a>collections" + src: "<r:pages in='site' limit='3' do='each' join=', '><r:show attr='title' anchor='true'/></r:pages>" + res: "<a class='anchor' name='node29'></a>a wiki with Zena, <a class='anchor' name='node33'></a>Art, <a class='anchor' name='node21'></a>Clean Water project" projects_in_site: - src: "<div class='all_projects' do='projects' in='site'><r:each join=', ' do='show' attr='node_name'/></div>" - res: "<div class='all_projects'>cleanWater, wiki, zena</div>" + src: "<div class='all_projects' do='projects' in='site'><r:each join=', ' do='show' attr='title'/></div>" + res: "<div class='all_projects'>a wiki with Zena, Clean Water project, Zena the wild CMS</div>" projects: - src: "<r:projects in='site'><r:each join=', ' do='show' attr='node_name'/></r:projects>" - res: "cleanWater, wiki, zena" + src: "<r:projects in='site'><r:each join=', ' do='show' attr='title'/></r:projects>" + res: "a wiki with Zena, Clean Water project, Zena the wild CMS" nodes: - src: "<r:nodes in='project'><r:each join=', ' do='show' attr='node_name'/></r:nodes>" - res: "lake, lakeAddress, opening, status, track, water" + src: "<r:nodes in='project'><r:each join=', ' do='show' attr='title'/></r:nodes>" + res: "it's a lake, Keeping things clean !, Lake Tanganyika, parc opening, status title, water" menu_with_favorites: context: @@ -299,60 +299,60 @@ checkbox_unique: res: "/<input type='radio' name='node\[icon_id\]' value='30'/> bird/" direction_both: - src: "<r:references or='reference_for' do='each' join=', ' do='node_name'/>" - res: "art, projects" + src: "<r:references or='reference_for' do='each' join=', ' do='title'/>" + res: "Art, projects list" direction_both_self_auto_ref: - src: "<r:references or='reference_for' do='each' join=', ' do='node_name'/>" - res: "art, projects, status" + src: "<r:references or='reference_for' do='each' join=', ' do='title'/>" + res: "Art, projects list, status title" direction_both_else: - src: "<r:references direction='both' else='[parent]' do='each' join=', ' do='node_name'/>" - res: "cleanWater" + src: "<r:references direction='both' else='[parent]' do='each' join=', ' do='title'/>" + res: "Clean Water project" visitor_node: src: "<r:visitor_node><b do='title'/></r:visitor_node>" res: "<b>Mr nobody</b>" relation_in_site: - src: "<r:tagged in='site' limit='10' do='each' join=',' do='node_name'/>" - res: "cleanWater,opening" + src: "<r:tagged in='site' limit='10' do='each' join=',' do='title'/>" + res: "Clean Water project,parc opening" relation_in_site_find_first: - src: "<r:tagged find='first' in='site' do='node_name'/>" - res: "cleanWater" + src: "<r:tagged find='first' in='site' do='title'/>" + res: "Clean Water project" where: - src: "<r:tagged where=\"node_name ='opening'\" in='site' do='each' join=',' do='node_name'/>" - res: "opening" + src: "<r:tagged where=\"id = 27\" in='site' do='each' join=',' do='id'/>" + res: "27" where_like: - src: "<r:images where='node_name like \"%ke\"' in='site' do='each' join=',' do='node_name'/>" - res: "lake" + src: "<r:images where='title like \"%ke\"' in='site' do='each' join=',' do='title'/>" + res: "it's a lake" else: - src: "<r:nodes where='node_name = 1' in='site' else='[this]' do='each' join=',' do='node_name'/>" + src: "<r:nodes where='id = 1' in='site' else='[this]' do='each' join=',' do='title'/>" tem: "/ false\) || \[@node\]\)/" - res: "status" + res: "status title" incompatible_else: - src: "<r:letters where='node_name = 1' in='site' else='this' do='each' join=',' do='node_name'/>" + src: "<r:letters where='id = 1' in='site' else='this' do='each' join=',' do='title'/>" tem: "/Incompatible.*\(Node\).*finder \(\[Letter\]\)/" where_not: context: node: 'cleanWater' - src: "<r:nodes where='node_name ne \"status\"' do='each' join=',' do='node_name'/>" - res: "lake,lakeAddress,opening,track,water" + src: "<r:nodes where='title ne \"status title\"' do='each' join=',' do='title'/>" + res: "it's a lake,Keeping things clean !,Lake Tanganyika,parc opening,water" where_two_attributes: - src: "<r:nodes where='log_at ne event_at' in='site' do='each' join=', ' do='node_name'/>" + src: "<r:nodes where='log_at ne event_at' in='site' do='each' join=', ' do='title'/>" tem: "/nodes.log_at <> nodes.event_at/" - res: "letter, opening" + res: "parc opening, zena enhancements" many_or: - src: "<r:tagged in='site' or='images in site' or='tags in site' do='each' join=',' do='node_name'/>" - res: "art,bird,cleanWater,flower,lake,menu,news,opening" + src: "<r:tagged in='site' or='images in site' or='tags in site' do='each' join=',' do='title'/>" + res: "Art,bird,Clean Water project,flower,it's a lake,News list,parc opening,Top menu" hot_or_page: context: @@ -361,39 +361,39 @@ hot_or_page: tem: "/:first.*.*links.relation_id = _ID(project_has_a_hot_element).*nodes.kpath LIKE 'NP%' AND nodes.project_id = ?.*LIMIT 1.*@node.get_project_id" node_in_version: - src: "<r:version><r:node do='node_name'/></r:version>" - res: "status" + src: "<r:version><r:node do='title'/></r:version>" + res: "status title" where_with_param: - src: "<r:nodes where='node_name like \"%#{params[:t]}%\"' in='site'/>" - tem: "/node_name LIKE \?.*\"%\#\{params\[:t\]\}%\"/" + src: "<r:nodes where='title like \"%#{params[:t]}%\"' in='site'/>" + tem: "/ml1.value LIKE \?.*\"%\#\{params\[:t\]\}%\"/" group_by_secret_project: context: visitor: ant - src: "<r:pages where='node_name like \"t%\"' in='site' order='node_name ASC' do='group' by='project'><b do='project' do='node_name'/>: <r:each join=',' do='node_name'/></r:pages>" - res: ": talk<b>cleanWater</b>: track" + src: "<r:pages where='title like \"t%\"' in='site' order='title ASC' do='group' by='project'><b do='project' do='title'/>: <r:each join=',' do='title'/></r:pages>" + res: ": Talk<b>Zena the wild CMS</b>: Top menu" group_by_project: context: visitor: lion - src: "<r:notes in='site' order='node_name ASC' do='group' by='project'><b do='project' do='node_name'/>: <r:each join=',' do='node_name'/></r:notes>" - res: "<b>zena</b>: letter<b>cleanWater</b>: opening<b>secret</b>: proposition" - + src: "<r:notes in='site' order='title ASC' do='group' by='project'><b do='project' do='title'/>: <r:each join=',' do='title'/></r:notes>" + res: "<b>Clean Water project</b>: parc opening<b>Secret</b>: Proposition<b>Zena the wild CMS</b>: zena enhancements" + group_by_project_sort_zip: context: visitor: ant - old_src: "<r:images in='site' order='node_name ASC' do='group' by='project' sort='zip'><b do='project' do='node_name'/>: <r:each join=',' do='node_name'/></r:images>" - src: "<r:images in='site' order='zip ASC' do='group' by='project' sort='id'><b do='project' do='node_name'/>: <r:each join=',' do='node_name'/></r:images>" - res: "<b>cleanWater</b>: lake<b>wiki</b>: bird,flower<b>zena</b>: tree" + old_src: "<r:images in='site' order='title ASC' do='group' by='project' sort='zip'><b do='project' do='title'/>: <r:each join=',' do='title'/></r:images>" + src: "<r:images in='site' order='zip ASC' do='group' by='project' sort='id'><b do='project' do='title'/>: <r:each join=',' do='title'/></r:images>" + res: "<b>Clean Water project</b>: it's a lake<b>a wiki with Zena</b>: bird,flower<b>Zena the wild CMS</b>: Autumn Tree" group_by_parent_sort: - src: "<r:images in='site' order='node_name ASC' do='group' by='parent' sort='title'><b do='parent' do='node_name'/>: <r:each join=',' do='node_name'/></r:images>" - res: "<b>wiki</b>: bird,flower<b>cleanWater</b>: lake" + src: "<r:images in='site' order='title ASC' do='group' by='parent' sort='title'><b do='parent' do='title'/>: <r:each join=',' do='title'/></r:images>" + res: "<b>a wiki with Zena</b>: bird,flower<b>Clean Water project</b>: it's a lake" nodes_in_site_group_by_year: - old_src: "<r:nodes in='site' group='log_at:year' order='log_at:year asc, node_name ASC' do='each' join=', '><r:show date='log_at' format='%Y'/></r:nodes>" - src: "<r:nodes in='site' group='log_at.year' order='log_at.year asc, node_name ASC' do='each' join=', '><r:show date='log_at' format='%Y'/></r:nodes>" + old_src: "<r:nodes in='site' group='log_at:year' order='log_at:year asc, title ASC' do='each' join=', '><r:show date='log_at' format='%Y'/></r:nodes>" + src: "<r:nodes in='site' group='log_at.year' order='log_at.year asc, title ASC' do='each' join=', '><r:show date='log_at' format='%Y'/></r:nodes>" res: ", 2006, 2007" comments_order_desc: @@ -419,8 +419,8 @@ comments_previous_node: tem: "/zazen\(var2.text, :node => @node/" comments_in_site_node: - src: "<r:comments from='nodes in site' order='created_at desc' limit='2' do='each' join=', '><r:node do='node_name'/>: <r:show attr='title'/></r:comments>" - res: "status: re: What about rivers ?, status: What about rivers ?" + src: "<r:comments from='nodes in site' order='created_at desc' limit='2' do='each' join=', '><r:node do='title'/>: <r:show attr='title'/></r:comments>" + res: "status title: re: What about rivers ?, status title: What about rivers ?" find_by_zip: src: "<div do='find(30)' do='img'/>" @@ -456,7 +456,7 @@ query: visitor: lion node: cleanWater qb: "nodes where updated_at.year = 2007 in project" - src: "<r:query default='nodes in project' do='each' join=', ' do='node_name'/>" + src: "<r:query default='nodes in project' do='each' join=', ' do='title'/>" tem: "/if var1 = query\('Node', \"@node\", params\[:qb\] \|\| \"nodes in project\"\)/" res: 'crocodiles' @@ -465,8 +465,8 @@ query_with_default: context: visitor: lion node: cleanWater - src: "<r:query default='nodes in project' do='each' join=', ' do='node_name'/>" - res: 'bananas, crocodiles, lake, lakeAddress, opening, status, track, water' + src: "<r:query default='nodes in project' do='each' join=', ' do='title'/>" + res: "crocodiles, it's a lake, Keeping things clean !, The lake we love, Nice Bananas, parc opening, status title, water" query_with_param: # Live compile and query from params @@ -475,7 +475,7 @@ query_with_param: node: cleanWater qb: "nodes where updated_at.year = #{params[:p]} in project" p: 2007 - src: "<r:query default='nodes in project' do='each' join=', ' do='node_name'/>" + src: "<r:query default='nodes in project' do='each' join=', ' do='title'/>" res: 'crocodiles' query_eval: @@ -484,10 +484,10 @@ query_eval: visitor: lion node: cleanWater scope: 'self' - src: "<r:query text='pages in #{params[:scope] || \"project\"}' default='pages in project' do='each' join=', ' do='node_name'/>" - res: 'bananas, crocodiles, status, track' + src: "<r:query text='pages in #{params[:scope] || \"project\"}' default='pages in project' do='each' join=', ' do='title'/>" + res: 'crocodiles, Keeping things clean !, Nice Bananas, status title' count: - src: "<p do='nodes in site' find='count'/>" + src: "<p do='nodes in site order by id' find='count'/>" tem: "<p><%= Node.do_find(:count, %Q{SELECT COUNT(*) FROM nodes WHERE #{secure_scope('nodes')}}) %></p>" res: "<p>42</p>" \ No newline at end of file diff --git a/test/integration/zafu_compiler/rubyless.yml b/test/integration/zafu_compiler/rubyless.yml index 4692bf1a..6d82838e 100644 --- a/test/integration/zafu_compiler/rubyless.yml +++ b/test/integration/zafu_compiler/rubyless.yml @@ -9,16 +9,16 @@ tagged_relation: node: 'art' class: Tag dev: 'true' - src: "<r:context select='tagged'><r:each join=', '><r:show attr='node_name'/></r:each></r:context>" - res: "cleanWater, opening" + src: "<r:context select='tagged'><r:each join=', '><r:show attr='title'/></r:each></r:context>" + res: "Clean Water project, parc opening" tagged_relation: context: node: art class: Tag dev: 'true' - src: "<r:tagged foo='bar'><r:each join=', '><r:show attr='node_name'/></r:each></r:tagged>" - res: "cleanWater, opening" + src: "<r:tagged foo='bar'><r:each join=', '><r:show attr='title'/></r:each></r:tagged>" + res: "Clean Water project, parc opening" tagged_rubyless: context: @@ -70,7 +70,7 @@ ancestors: # used to be implemented with 'show_path' src: "<ul id='path' do='ancestors'><li do='each' do='link'/></ul>" tem: "/if var1 = @node.z_ancestors/" - res: "/<ul id='path'><li>.*Zena.*<li>.*en/page18.html.*<li><.*/projects/cleanWater.*Clean Water project</a></li></ul>/" + res: "/<ul id='path'><li>.*Zena.*<li>.*en/page18.html.*<li><.*/projects-list/Clean-Water-project.*Clean Water project</a></li></ul>/" ancestors_on_root: context: diff --git a/test/integration/zafu_compiler/safe_definitions.yml b/test/integration/zafu_compiler/safe_definitions.yml index 5f0bff1d..cfe70c3a 100644 --- a/test/integration/zafu_compiler/safe_definitions.yml +++ b/test/integration/zafu_compiler/safe_definitions.yml @@ -35,13 +35,23 @@ gsub_newline: src: "<r:Contact do='address.gsub(/\\n/, \"\\\\n\")'/>" res: 'Small Island\nIn the Wild' +upcase: + eval: "title.upcase" + tem: "<%= (@node.prop['title'] ? @node.prop['title'].upcase : nil) %>" + res: "STATUS TITLE" + +strip: + eval: "%Q{ #{id}}.strip" + tem: "<%= \" #{@node.zip}\".strip %>" + res: "22" + blank: eval: 'this.blank?' tem: "<%= @node.blank? %>" blank_on_string: - eval: 'node_name.blank?' - tem: "<%= @node.node_name.blank? %>" + eval: 'id.blank?' + tem: "<%= @node.zip.blank? %>" blank_on_could_be_nil: eval: 'parent.blank?' diff --git a/test/integration/zafu_compiler/urls.yml b/test/integration/zafu_compiler/urls.yml index e7bb8b1b..885840cd 100644 --- a/test/integration/zafu_compiler/urls.yml +++ b/test/integration/zafu_compiler/urls.yml @@ -6,72 +6,72 @@ default: url: src: "<r:url/>" - res: "http://test.host/oo/projects/cleanWater/page22.html" + res: "http://test.host/oo/projects-list/Clean-Water-project/page22.html" use_url_in_attribute: src: "<a href='#{url}'>blah</a>" - res: "<a href='http://test.host/oo/projects/cleanWater/page22.html'>blah</a>" + res: "<a href='http://test.host/oo/projects-list/Clean-Water-project/page22.html'>blah</a>" show_url_in_script: src: "<script type='text/javascript'> digg_url = '<r:url/>'; </script>" - res: "/http://test.host/oo/projects/cleanWater/page22.html/" + res: "/http://test.host/oo/projects-list/Clean-Water-project/page22.html/" url_with_param: src: "<p do='eval'>url(parent)</p>" - res: "<p>http://test.host/oo/projects/cleanWater</p>" + res: "<p>http://test.host/oo/projects-list/Clean-Water-project</p>" path: src: "<a href='#{path}'>blah</a>" - res: "<a href='/oo/projects/cleanWater/page22.html'>blah</a>" + res: "<a href='/oo/projects-list/Clean-Water-project/page22.html'>blah</a>" link: src: "<r:link/>" tem: "<a href='<%= zen_path(@node) %>'><%= @node.prop['title'] %></a>" - res: "<a href='/oo/projects/cleanWater/page22.html'>status title</a>" + res: "<a href='/oo/projects-list/Clean-Water-project/page22.html'>status title</a>" link_not_logged: context: visitor: anon src: "<r:link/>" - res: "<a href='/en/projects/cleanWater/page22.html'>status title</a>" + res: "<a href='/en/projects-list/Clean-Water-project/page22.html'>status title</a>" do_link: src: "<li class='super' do='link'>sample text</li>" - res: "<li class='super'><a href='/oo/projects/cleanWater/page22.html'>status title</a></li>" + res: "<li class='super'><a href='/oo/projects-list/Clean-Water-project/page22.html'>status title</a></li>" do_link_t: src: "<li class='super' do='link' do='t'>blah</li>" - res: "<li class='super'><a href='/oo/projects/cleanWater/page22.html'>blah</a></li>" + res: "<li class='super'><a href='/oo/projects-list/Clean-Water-project/page22.html'>blah</a></li>" a_link: src: "<a class='bob' do='link'>sample text</a> <a id='bar' do='link' do='t'>click here</a>" - res: "<a class='bob' href='/oo/projects/cleanWater/page22.html'>status title</a> <a id='bar' href='/oo/projects/cleanWater/page22.html'>click here</a>" + res: "<a class='bob' href='/oo/projects-list/Clean-Water-project/page22.html'>status title</a> <a id='bar' href='/oo/projects-list/Clean-Water-project/page22.html'>click here</a>" zafu_link_with_blocks: src: "<a id='branding' do='link'><div do='zazen(text)'/></a>" - res: "/<a id='branding' href='/oo/projects/cleanWater/page22.html'>.*zazen.*<\/a>/" + res: "/<a id='branding' href='/oo/projects-list/Clean-Water-project/page22.html'>.*zazen.*<\/a>/" link_class: src: "<r:link class='hello'/>" - res: "<a class='hello' href='/oo/projects/cleanWater/page22.html'>status title</a>" + res: "<a class='hello' href='/oo/projects-list/Clean-Water-project/page22.html'>status title</a>" link_set_class: - src: "<r:link class='#{node_name}_foo'/>" - tem: "<a class='<%= \"#{@node.node_name}_foo\" %>' href='<%= zen_path(@node) %>'><%= @node.prop['title'] %></a>" - res: "<a class='status_foo' href='/oo/projects/cleanWater/page22.html'>status title</a>" + src: "<r:link class='#{title}_foo'/>" + tem: "<a class='<%= \"#{@node.prop['title']}_foo\" %>' href='<%= zen_path(@node) %>'><%= @node.prop['title'] %></a>" + res: "<a class='status title_foo' href='/oo/projects-list/Clean-Water-project/page22.html'>status title</a>" link_attr: src: "<r:link attr='ref_lang'/>" tem: "<a href='<%= zen_path(@node) %>'><%= @node.ref_lang %></a>" - res: "<a href='/oo/projects/cleanWater/page22.html'>en</a>" + res: "<a href='/oo/projects-list/Clean-Water-project/page22.html'>en</a>" link_tattr: old_src: "<r:link tattr='ref_lang'/>" src: "<r:link eval='trans(ref_lang)'/>" tem: "<a href='<%= zen_path(@node) %>'><%= trans(@node.ref_lang) %></a>" - res: "<a href='/oo/projects/cleanWater/page22.html'>english</a>" + res: "<a href='/oo/projects-list/Clean-Water-project/page22.html'>english</a>" link_trans: context: @@ -79,17 +79,17 @@ link_trans: old_src: "<r:link trans='Monday'/>" src: "<r:link do='t' text='Monday'/>" tem: "<a href='<%= zen_path(@node) %>'>lundi</a>" - res: "<a href='/oo/projects/cleanWater/page22.html'>lundi</a>" + res: "<a href='/oo/projects-list/Clean-Water-project/page22.html'>lundi</a>" link_parent: src: "<r:link href='parent' text='click here'/>" tem: "<a href='<%= zen_path(@node.parent) %>'>click here</a>" - res: "<a href='/oo/projects/cleanWater'>click here</a>" + res: "<a href='/oo/projects-list/Clean-Water-project'>click here</a>" link_with_block: - src: "<r:link href='parent'>look at <b do='node_name'>her</b></r:link>" - tem: "<a href='<%= zen_path(@node.parent) %>'>look at <b><%= @node.node_name %></b></a>" - res: "<a href='/oo/projects/cleanWater'>look at <b>status</b></a>" + src: "<r:link href='parent'>look at <b do='title'>her</b></r:link>" + tem: "<a href='<%= zen_path(@node.parent) %>'>look at <b><%= @node.prop['title'] %></b></a>" + res: "<a href='/oo/projects-list/Clean-Water-project'>look at <b>status title</b></a>" link_project: context: @@ -107,24 +107,24 @@ link_anchor: src: "<r:link anchor='true'/>" res: "<a href='#node22'>status title</a>" -link_anchor_name: +link_anchor_title: old_src: "<r:link anchor='[name]'/>" - src: "<r:link anchor='#{node_name}'/>" - res: "<a href='#status'>status title</a>" + src: "<r:link anchor='#{title.urlencode}'/>" + res: "<a href='#status-title'>status title</a>" link_anchor_in: src: "<r:link anchor='true' href='project' mode='tree'/>" - res: "<a href='/oo/projects/cleanWater_tree#node22'>status title</a>" + res: "<a href='/oo/projects-list/Clean-Water-project_tree#node22'>status title</a>" link_anchor_name_in: old_src: "<r:link anchor='[name]' in='parent'/>" - src: "<r:link anchor='#{node_name}' href='parent'/>" - res: "<a href='/oo/projects/cleanWater#status'>status title</a>" + src: "<r:link anchor='#{title.urlencode}' href='parent'/>" + res: "<a href='/oo/projects-list/Clean-Water-project#status-title'>status title</a>" link_stored: - old_src: "<r:void store='foo'><r:parent><r:link href='foo' do='node_name'/></r:parent></r:void>" + old_src: "<r:void store='foo'><r:parent><r:link href='foo' do='title'/></r:parent></r:void>" src: "<r:void set_foo='this'><r:parent><r:link href='foo' do='title'/></r:parent></r:void>" - res: "<a href='/oo/projects/cleanWater/page22.html'>Clean Water project</a>" + res: "<a href='/oo/projects-list/Clean-Water-project/page22.html'>Clean Water project</a>" link_stored_not_a_node: src: "<r:void set_foo='45'><r:parent><r:link href='foo' do='title'/></r:parent></r:void>" @@ -148,27 +148,27 @@ link_date: old_src: "<r:link date='current_date'/>" src: "<r:link date='#{date}'/>" tem: '/:date => "#\{main_date\}"' - res: "<a href='/oo/projects/cleanWater/page22.html?date=2008-06-27T00%3A00%3A00%2B00%3A00'>status title</a>" + res: "<a href='/oo/projects-list/Clean-Water-project/page22.html?date=2008-06-27T00%3A00%3A00%2B00%3A00'>status title</a>" link_url_params: src: "<r:link plob='hopla'/>" - res: "<a href='/oo/projects/cleanWater/page22.html?plob=hopla'>status title</a>" + res: "<a href='/oo/projects-list/Clean-Water-project/page22.html?plob=hopla'>status title</a>" link_url_params_parsed_values: src: "<r:link plob='haha #{title}'/>" - res: "<a href='/oo/projects/cleanWater/page22.html?plob=haha+status+title'>status title</a>" + res: "<a href='/oo/projects-list/Clean-Water-project/page22.html?plob=haha+status+title'>status title</a>" title_link_mode: old_src: "<h2 do='title' link='details'/>" src: "<h2 do='link' mode='details' do='title' live='true'/>" - res: "<h2><a href='/oo/projects/cleanWater/page22_details.html'><span id='_title22'>status title</span></a></h2>" + res: "<h2><a href='/oo/projects-list/Clean-Water-project/page22_details.html'><span id='_title22'>status title</span></a></h2>" link_with_custom_params: context: year: 2010 src: "<r:link class='foo' href='main' y='#{params[:year]}'/>" tem: "<a class='foo' href='<%= zen_path(@node, {:y => \"#{params[:year]}\"}) %>'><%= @node.prop['title'] %></a>" - res: "<a class='foo' href='/oo/projects/cleanWater/page22.html?y=2010'>status title</a>" + res: "<a class='foo' href='/oo/projects-list/Clean-Water-project/page22.html?y=2010'>status title</a>" link_format_data: context: @@ -179,7 +179,7 @@ link_format_data: live_link_format: old_src: "<h2 do='title' link='details.xml'/>" src: "<h2 do='link' live='true' format='xml' mode='details'/>" - res: "<h2><a id='_title22' href='/oo/projects/cleanWater/page22_details.xml'>status title</a></h2>" + res: "<h2><a id='_title22' href='/oo/projects-list/Clean-Water-project/page22_details.xml'>status title</a></h2>" live_link_data_mode: context: diff --git a/test/integration/zafu_compiler/version.yml b/test/integration/zafu_compiler/version.yml index ce0b33c6..e134a366 100644 --- a/test/integration/zafu_compiler/version.yml +++ b/test/integration/zafu_compiler/version.yml @@ -8,7 +8,7 @@ link: context: node: 'opening' src: "<r:traductions><r:each join=', '><r:link eval='trans(lang)'/></r:each></r:traductions>" - res: "<a href='/oo/projects/cleanWater/post27.html?lang=en'>english</a>, <a href='/oo/projects/cleanWater/post27.html?lang=fr'>french</a>" + res: "<a href='/oo/projects-list/Clean-Water-project/post27.html?lang=en'>english</a>, <a href='/oo/projects-list/Clean-Water-project/post27.html?lang=fr'>french</a>" link_not_same_node: # version link where 'up' node is not the version's node @@ -24,13 +24,13 @@ anchor: context: node: 'opening' src: "<r:traductions><r:each join=', '><r:anchor do='link' eval='trans(lang)'/></r:each></r:traductions>" - res: "<a class='anchor' name='version27_2'></a><a href='/oo/projects/cleanWater/post27.html?lang=en'>english</a>, <a class='anchor' name='version27_1'></a><a href='/oo/projects/cleanWater/post27.html?lang=fr'>french</a>" + res: "<a class='anchor' name='version27_2'></a><a href='/oo/projects-list/Clean-Water-project/post27.html?lang=en'>english</a>, <a class='anchor' name='version27_1'></a><a href='/oo/projects-list/Clean-Water-project/post27.html?lang=fr'>french</a>" node: context: node: 'opening' - src: "<r:traductions do='each' join=', '><r:lang/>:<r:eval>node.node_name</r:eval></r:traductions>" - res: "en:opening, fr:opening" + src: "<r:traductions do='each' join=', '><r:lang/>:<r:eval>node.id</r:eval></r:traductions>" + res: "en:27, fr:27" author: context: diff --git a/test/integration/zafu_compiler/zafu_attributes.yml b/test/integration/zafu_compiler/zafu_attributes.yml index e6452627..4c0fe2c0 100644 --- a/test/integration/zafu_compiler/zafu_attributes.yml +++ b/test/integration/zafu_compiler/zafu_attributes.yml @@ -66,36 +66,36 @@ prefix_lang_show: set_attribute: old_src: "<div do='void' set_class='[name]'>hop</div>" - src: "<div class='#{node_name}'>hop</div>" - res: "<div class='status'>hop</div>" + src: "<div class='#{title}'>hop</div>" + res: "<div class='status title'>hop</div>" set_attribute_empty_tag: old_src: "<div do='void' set_class='[name]'>hop</div>" - src: "<div class='#{node_name}'/>" - res: "<div class='status'></div>" + src: "<div class='#{title}'/>" + res: "<div class='status title'></div>" store_node: - src: "<r:void set_baz='this'><r:parent><r:show attr='node_name'/>: <r:baz do='node_name'/> + <r:main do='show' attr='id'/></r:parent></r:void>" - res: "cleanWater: status + 22" + src: "<r:void set_baz='this'><r:parent><r:show attr='title'/>: <r:baz do='title'/> + <r:main do='show' attr='id'/></r:parent></r:void>" + res: "Clean Water project: status title + 22" store_in_block: - src: "<r:block><r:void set_found='this' do='node' where='id = 18 in site' do='page'><r:found do='node_name'/>: <r:show attr='node_name'/></r:void></r:block>" - res: "<div id='list1'>status: cleanWater</div>" - 'zafu_attributes/store/en/in/block/list1.erb': '/<% var3 = @node -%><%= var3.node_name %>:/' + src: "<r:block><r:void set_found='this' do='node' where='id = 18 in site' do='page'><r:found do='title'/>: <r:show attr='title'/></r:void></r:block>" + res: "<div id='list1'>status title: a wiki with Zena</div>" + 'zafu_attributes/store/en/in/block/list1.erb': "/<% var3 = @node -%><%= var3.prop\['title'\] %>:/" set_var_outside_block: - old_src: "<r:node select='18' set_found='this' do='pages'><r:block><r:show attr='node_name'/>: <r:context select='found' do='node_name'/></r:block></r:node>" - src: "<r:void set_found='this' do='pages from node where id = 18 in site' do='each' join=', '><r:block><r:found do='node_name'/>: <r:show attr='node_name'/></r:block></r:void>" - res: "<div id='list1_21'>status: cleanWater</div>, <div id='list1_29'>status: wiki</div>" + old_src: "<r:node select='18' set_found='this' do='pages'><r:block><r:show attr='title'/>: <r:context select='found' do='title'/></r:block></r:node>" + src: "<r:void set_found='this' do='pages from node where id = 18 in site' do='each' join=', '><r:block><r:found do='title'/>: <r:show attr='title'/></r:block></r:void>" + res: "<div id='list1_29'>status title: a wiki with Zena</div>, <div id='list1_21'>status title: Clean Water project</div>" 'zafu_attributes/set/en/var/outside/block/list1.erb': "/unknown method <span class='type'>found\(\)/" store_node_as_relation: - src: "<r:void set_baz='this'><r:parent><r:show attr='node_name'/>: <r:baz do='node_name'/> + <r:main do='show' attr='id'/></r:parent></r:void>" - res: "cleanWater: status + 22" + src: "<r:void set_baz='this'><r:parent><r:show attr='title'/>: <r:baz do='title'/> + <r:main do='show' attr='id'/></r:parent></r:void>" + res: "Clean Water project: status title + 22" store_img: - src: "<r:parent><r:icon set_bob='this'><r:show attr='node_name'/><r:img link='bob'/></r:icon></r:parent>" - tem: "/if var1 = @node.parent.*var2 = Node.do_find.*relation_id = _ID(node_has_an_icon).*LIKE 'NDI%'.*var2.node_name.*zen_path\(var1\).*img_tag\(var2/" + src: "<r:parent><r:icon set_bob='this'><r:show attr='title'/><r:img link='bob'/></r:icon></r:parent>" + tem: "/if var1 = @node.parent.*var2 = Node.do_find.*relation_id = _ID(node_has_an_icon).*LIKE 'NDI%'.*var2.prop\['title'\].*zen_path\(var1\).*img_tag\(var2/" store_var_in_html: src: "<p set_foo='this' do='parent' do='foo' do='title'/>" @@ -106,26 +106,26 @@ stored_in_if_clause: tem: "/var1.zip==@node.zip/" on_if_in_context: - src: "<div do='project' on_if='node_name == \"cleanWater\"' do='node_name'/>" - tem: "/var1.node_name==/" - res: "<div class=' on'>cleanWater</div>" + src: "<div do='project' on_if='title == \"Clean Water project\"' do='title'/>" + tem: "/var1.prop\['title'\]==/" + res: "<div class=' on'>Clean Water project</div>" on_if_with_link: # Make sure we do not insert an 'on_if' param in href src: "<p do='link' on_if='1 == 1'/>" - res: "<p class=' on'><a href='/oo/projects/cleanWater/page22.html'>status title</a></p>" + res: "<p class=' on'><a href='/oo/projects-list/Clean-Water-project/page22.html'>status title</a></p>" on_if_on_each: context: node: cleanWater # We use 'this' to make sure we are not in a list context. - src: "<r:pages><p do='each' on_if='this.node_name == \"status\"' do='node_name'/></r:pages>" - tem: '/var2.node_name==\"status\"/' - res: "<p class=''>crocodiles</p><p class=' on'>status</p><p class=''>track</p>" + src: "<r:pages><p do='each' on_if='this.title == \"status title\"' do='title'/></r:pages>" + tem: "/var2.prop\['title'\]==\"status title\"/" + res: "<p class=''>crocodiles</p><p class=''>Keeping things clean !</p><p class=' on'>status title</p>" on_if_ancestor: - src: "<r:root><r:pages><li do='each' on_if='ancestor?(main)' class='hello' join=', ' do='node_name'/></r:pages></r:root>" - res: "<li class='hello'>collections</li>, <li class='hello'>nature</li>, <li class='hello'>people</li>, <li class='hello on'>projects</li>, <li class='hello'>skins</li>" + src: "<r:root><r:pages><li do='each' on_if='ancestor?(main)' class='hello' join=', ' do='title'/></r:pages></r:root>" + res: "<li class='hello'>Collections</li>, <li class='hello'>Nature</li>, <li class='hello'>people</li>, <li class='hello on'>projects list</li>, <li class='hello'>Skins (layout themes)</li>" on_if_empty: src: "<li do='void' on_if='custom_a.blank?'>hello</li>" @@ -138,24 +138,24 @@ test_negative_value: anchor_attribute: # Use to_s so that the method executed replaces the dummy text. - src: "<p do='id.to_s' anchor='#{node_name}'>hello</p>" - res: "<a class='anchor' name='status'></a><p>22</p>" + src: "<p do='id.to_s' anchor='#{title.urlencode}'>hello</p>" + res: "<a class='anchor' name='status-title'></a><p>22</p>" anchor_true: src: "<r:title live='true' anchor='true'/>" res: "<a class='anchor' name='node22'></a><span id='_title22'>status title</span>" show_attr_anchor: - src: "<r:show attr='node_name' anchor='true'/>" - res: "<a class='anchor' name='node22'></a>status" + src: "<r:show attr='title' anchor='true'/>" + res: "<a class='anchor' name='node22'></a>status title" anchor_in_link: src: "<r:link class='xx' anchor='true'/>" res: "<a class='xx' href='#node22'>status title</a>" anchor_tag: - src: "<r:anchor/> <r:anchor anchor='#{node_name}'/>" - res: "<a class='anchor' name='node22'></a> <a class='anchor' name='status'></a>" + src: "<r:anchor/> <r:anchor anchor='#{title.urlencode}'/>" + res: "<a class='anchor' name='node22'></a> <a class='anchor' name='status-title'></a>" live_with_show: src: "<r:title live='true'/>" @@ -167,4 +167,4 @@ live_with_zazen: live_with_link: src: "<h2 do='link' attr='title' live='true'>super titre</h2>" - res: "<h2><a id='_title22' href='/oo/projects/cleanWater/page22.html'>status title</a></h2>" + res: "<h2><a id='_title22' href='/oo/projects-list/Clean-Water-project/page22.html'>status title</a></h2>" diff --git a/test/integration/zafu_compiler/zazen.yml b/test/integration/zafu_compiler/zazen.yml index 735f705a..cb329739 100644 --- a/test/integration/zafu_compiler/zazen.yml +++ b/test/integration/zafu_compiler/zazen.yml @@ -16,20 +16,20 @@ link_anchor: res: "<p>see <a href=\"#node22\">status title</a></p>" link_anchor_attribute: - tem: "<%= zazen('see \"\":22#[node_name]') %>" - res: "<p>see <a href=\"#status\">status title</a></p>" + tem: "<%= zazen('see \"\":22#[title]') %>" + res: "<p>see <a href=\"#status-title\">status title</a></p>" link_anchor_in: tem: "<%= zazen('see \"\":22#[parent/]') %>" - res: "<p>see <a href=\"/oo/projects/cleanWater#node22\">status title</a></p>" + res: "<p>see <a href=\"/oo/projects-list/Clean-Water-project#node22\">status title</a></p>" link_anchor_in_name: - tem: "<%= zazen('see \"\":22#[parent/node_name]') %>" - res: "<p>see <a href=\"/oo/projects/cleanWater#status\">status title</a></p>" + tem: "<%= zazen('see \"\":22#[parent/title]') %>" + res: "<p>see <a href=\"/oo/projects-list/Clean-Water-project#status-title\">status title</a></p>" complex_link: tem: <%= zazen("p<. !<.31_pv!:22\n\nh4(clear). \"\":22") %> - res: "<p style=\"text-align:left;\"><div class='img_left'><a href=\"/oo/projects/cleanWater/page22.html\"><img src='/en/image31_pv.jpg?967816914293' width='70' height='70' alt='flower' class='pv'/></a></div></p>\n\n\n\t<h4 class=\"clear\"><a href=\"/oo/projects/cleanWater/page22.html\">status title</a></h4>" + res: "<p style=\"text-align:left;\"><div class='img_left'><a href=\"/oo/projects-list/Clean-Water-project/page22.html\"><img src='/en/image31_pv.jpg?967816914293' width='70' height='70' alt='flower' class='pv'/></a></div></p>\n\n\n\t<h4 class=\"clear\"><a href=\"/oo/projects-list/Clean-Water-project/page22.html\">status title</a></h4>" at_code: tem: "<%= zazen(\"Try this: @ruby|puts 'Hello'@ or this @zafu|<r:link/>@\") %>" @@ -45,19 +45,19 @@ line_break_list: zip_shortcut_link: tem: "<%= zazen('Look \"here\"::lake or \"\"::lake+') %>" - res: "/<p>Look <a href.*contact23.html.*projects/cleanWater/lakeAddress.*href=.*image24.html.*projects/cleanWater/lake/" + res: "/<p>Look <a href.*contact23.html.*projects list/Clean Water project/Lake Tanganyika.*href=.*image24.html.*projects list/Clean Water project/it’s a lake/" zip_shortcut_link_with_mode_format: tem: "<%= zazen('Look \"here\"::lake_life.rss, \"\"::lake+_life.data.') %>" - res: "/<p>Look <a href.*contact23_life.rss.*projects/cleanWater/lakeAddress_life.rss</a>, <a href=.*image24_life.jpg.*projects/cleanWater/lake_life.jpg</a>./" + res: "/<p>Look <a href.*contact23_life.rss.*projects list/Clean Water project/Lake Tanganyika_life.rss</a>, <a href=.*image24_life.jpg.*projects list/Clean Water project/it’s a lake_life.jpg</a>./" zip_shortcut_image: tem: "<%= zazen('Look !:lake! or !:lake+!') %>" - res: "/<p>Look \[projects/cleanWater/lakeAddress is not a document\] or <img src=.*image24_std.jpg/" + res: "/<p>Look \[projects list/Clean Water project/Lake Tanganyika is not a document\] or <img src=.*image24_std.jpg/" zip_shortcut_image_with_options: tem: "<%= zazen('Look !<.:lake_med! or !=.:lake+_pv!') %>" - res: "/<p>Look \[projects/cleanWater/lakeAddress is not a document\] or .*center.*<img src=.*image24_pv.jpg/" + res: "/<p>Look \[projects list/Clean Water project/Lake Tanganyika is not a document\] or .*center.*<img src=.*image24_pv.jpg/" zip_shortcut_gallery: tem: "<%= zazen('Look ![30,:lake+]!') %>" diff --git a/test/integration/zafu_compiler_test.rb b/test/integration/zafu_compiler_test.rb index c4a947fc..1112aea6 100644 --- a/test/integration/zafu_compiler_test.rb +++ b/test/integration/zafu_compiler_test.rb @@ -1,6 +1,7 @@ require 'test_helper' class ZafuCompilerTest < Zena::Controller::TestCase + include Zena::Use::Urls::Common OK = [ 'action', 'asset', @@ -80,28 +81,20 @@ def setup def yt_do_test(file, test) # Disable defined tests without loaded files - return unless (@@test_strings[file] || {})[test] + return unless test_data = (@@test_strings[file] || {})[test] - if @@test_strings[file][test].keys.include?('src') + if test_data.keys.include?('src') # we do not want src built from title src = yt_get('src', file, test) elsif src = yt_get('eval', file, test) - src = @@test_strings[file][test]['src'] = "<r:eval>#{src}</r:eval>" + src = test_data['src'] = "<r:eval>#{src}</r:eval>" end - tem = yt_get('tem', file, test) - res = yt_get('res', file, test) - js = yt_get('js', file, test) - - compiled_files = {} - @@test_strings[file][test].each do |k,v| - next if ['src','tem','res','context','eval','js'].include?(k) || k =~ /^old/ - compiled_files[k] = v - end context = yt_get('context', file, test) site = sites(context.delete('site') || 'zena') $_test_site = site.name @request.host = site.host + # set context params = {} #params[:user_id] = users_id(context.delete('visitor').to_sym) @@ -111,6 +104,17 @@ def yt_do_test(file, test) params['date'] = context['ref_date'] ? context.delete('ref_date').to_s : nil params['url'] = "#{file}/#{test.to_s.gsub('_', '/')}" params.merge!(context) # merge the rest of the context as query parameters + + compiled_files = {} + test_data.each do |k,v| + next if ['src','tem','res','context','eval','js'].include?(k) || k =~ /^old/ + compiled_files[k] = v + end + + tem = yt_get('tem', file, test) + res = yt_get('res', file, test) + js = yt_get('js', file, test) + Zena::TestController.templates = @@test_strings[file] if src post 'test_compile', params diff --git a/test/sites/complex/nodes.yml b/test/sites/complex/nodes.yml index 30604875..468e5108 100644 --- a/test/sites/complex/nodes.yml +++ b/test/sites/complex/nodes.yml @@ -24,7 +24,6 @@ cskin: Node_zafu: class: Template parent: cskin - node_name: Node title: Node v_prop: target_klass: Node @@ -106,7 +105,6 @@ chief: class: Job parent: jobs title: chief - node_name: chief chief_motivation: class: Page diff --git a/test/sites/ocean/nodes.yml b/test/sites/ocean/nodes.yml index 0f6f4f42..f224ee5a 100644 --- a/test/sites/ocean/nodes.yml +++ b/test/sites/ocean/nodes.yml @@ -8,7 +8,6 @@ DEFAULTS: ocean: class: Project - node_name: other inherit: no rgroup: public wgroup: masters @@ -22,13 +21,11 @@ incognito: whale: class: Contact - node_name: whale parent: ocean skin: default default: class: Skin - node_name: default parent: ocean Node: diff --git a/test/sites/zena/columns.yml b/test/sites/zena/columns.yml index 2948b67e..624e5a53 100644 --- a/test/sites/zena/columns.yml +++ b/test/sites/zena/columns.yml @@ -12,7 +12,13 @@ Original_weight: Original_tz: -Letter_paper: +Letter_paper: + +Letter_search: + index: ml_string + +Letter_search_mono: + index: string Contact_name: index: string @@ -23,4 +29,5 @@ Contact_email: Contact_address: -Contact_country: \ No newline at end of file +Contact_country: + \ No newline at end of file diff --git a/test/sites/zena/nodes.yml b/test/sites/zena/nodes.yml index 8524b069..fadf4d86 100644 --- a/test/sites/zena/nodes.yml +++ b/test/sites/zena/nodes.yml @@ -1,3 +1,5 @@ +# When creating nodes, parent nodes *MUST* appear before their children or +# the fullpath won't build correctly. DEFAULTS: updated_at: 2006-04-11 created_at: 2006-03-10 @@ -100,21 +102,18 @@ status: lake: zip: 23 class: Contact - node_name: lakeAddress parent: cleanWater user: ant lake_jpg: zip: 24 class: Image - node_name: lake parent: cleanWater user: ant water_pdf: zip: 25 class: Document - node_name: water parent: cleanWater crocodiles: @@ -157,14 +156,12 @@ wiki: bird_jpg: zip: 30 class: Image - node_name: bird parent: wiki user: anon flower_jpg: zip: 31 class: Image - node_name: flower parent: wiki user: anon @@ -225,7 +222,6 @@ nature: tree_jpg: zip: 40 class: Image - node_name: tree parent: nature user: ant roles: zena_Original @@ -233,7 +229,6 @@ tree_jpg: forest_pdf: zip: 41 class: Document - node_name: forest parent: nature user: ant @@ -247,91 +242,72 @@ letter: wikiSkin: zip: 43 class: Skin - node_name: wikiSkin # yes it's not good to have this here but changing it would mess up many tests. parent: collections wiki_Project_changes_xml_zafu: class: Template - node_name: Project-changes-xml parent: wikiSkin wiki_Page_changes_zafu: class: Template - node_name: Page-changes parent: wikiSkin wiki_Node_zafu: class: Template - node_name: Node parent: wikiSkin - - - skins: class: Page parent: zena default: class: Skin - node_name: default parent: skins Node_search_zafu: class: Template - node_name: Node-search parent: default style_css: zip: 53 class: TextDocument - node_name: style parent: default Node_zafu: class: Template - node_name: Node parent: default Node_admin_layout_zafu: class: Template - node_name: Node-+adminLayout parent: default Node_index_zafu: class: Template - node_name: Node-+index parent: default Node_not_found_zafu: class: Template - node_name: Node-+notFound parent: default Node_popup_layout_zafu: class: Template - node_name: Node-+popupLayout parent: default notes_zafu: class: Template - node_name: notes parent: default Node_test_zafu: class: Template - node_name: Node-test parent: default Project_zafu: class: Template - node_name: Project parent: default Node_login_zafu: class: Template - node_name: Node-+login parent: default translations: diff --git a/test/sites/zena/roles.yml b/test/sites/zena/roles.yml index a91c7664..eac8b67a 100644 --- a/test/sites/zena/roles.yml +++ b/test/sites/zena/roles.yml @@ -8,6 +8,9 @@ Letter: real_class: Note prop: idx_text_high: "%Q{#{title} paper:#{paper}}" + # We build a 'search' property that is indexed to do funky searching without + # fulltext + prop_eval: "{'search' => %Q{#{title} paper:#{paper}}, 'search_mono' => %Q{#{paper} mono}}" Post: kpath: NNP diff --git a/test/sites/zena/versions.yml b/test/sites/zena/versions.yml index 9fb9b385..bab60fe7 100644 --- a/test/sites/zena/versions.yml +++ b/test/sites/zena/versions.yml @@ -248,6 +248,8 @@ crocodiles_en: user: ant publish_from: status: red + prop: + title: crocodiles opening_fr: node: opening @@ -270,7 +272,7 @@ wiki_en: node: wiki user: lion prop: - title: a wiki with zena + title: a wiki with Zena bird_jpg_en: node: bird_jpg @@ -477,11 +479,11 @@ wiki_project_changes_xml_en: summary: Layout for the wiki skin. text: | <?xml version="1.0" encoding="UTF-8"?> - <name><r:show attr='node_name'/></name> + <name><r:show attr='title'/></name> <changes do='nodes' in='project' order='updated_at DESC' limit='10'> <node do='each'> <type><r:show attr='type'/></type> - <name><r:show attr='node_name'/></name> + <name><r:show attr='title'/></name> <id><r:show attr='id'/></id> </note> </notes> @@ -526,10 +528,10 @@ wiki_node_en: user: tiger prop: comment: master template for wiki - title: main template + title: Node summary: master template for wiki skin. text: | - <r:include template='/default/Node'> + <r:include template='/Default skin/Node'> <r:with part='main'> WIKI </r:with> @@ -576,6 +578,7 @@ style_css_en: user: tiger prop: text: "[FILE:db/init/base/skins/default/style.css]" + title: style content_type: text/css ext: css size: 5262 @@ -585,6 +588,7 @@ Node_zafu_en: user: tiger prop: text: "[FILE:app/views/zafu/default/Node.zafu]" + title: Node format: html tkpath: N target_klass: Node @@ -594,6 +598,7 @@ Node_admin_layout_zafu_en: user: tiger prop: text: "[FILE:app/views/zafu/default/Node-+adminLayout.zafu]" + title: Node-+adminLayout format: html tkpath: N mode: "+adminLayout" @@ -604,6 +609,7 @@ Node_index_zafu_en: user: tiger prop: text: "[FILE:db/init/base/skins/default/Node-+index.zafu]" + title: Node-+index format: html tkpath: N mode: "+index" @@ -614,6 +620,7 @@ Node_not_found_zafu_en: user: tiger prop: text: "[FILE:app/views/zafu/default/Node-+notFound.zafu]" + title: Node-+notFound format: html tkpath: N mode: "+notFound" @@ -624,6 +631,7 @@ Node_popup_layout_zafu_en: user: tiger prop: text: "[FILE:app/views/zafu/default/Node-+popupLayout.zafu]" + title: Node-+popupLayout format: html tkpath: N mode: "+popupLayout" @@ -634,6 +642,7 @@ Node_test_en: user: tiger prop: text: "[FILE:test/fixtures/files/Node-test.zafu]" + title: Node-test format: html tkpath: N mode: test @@ -644,6 +653,7 @@ notes_zafu_en: user: tiger prop: text: "[FILE:db/init/base/skins/default/notes.zafu]" + title: notes format: html Project_zafu_en: @@ -651,6 +661,7 @@ Project_zafu_en: user: tiger prop: text: "[FILE:db/init/base/skins/default/Project.zafu]" + title: Project format: html tkpath: NPP target_klass: Project @@ -660,6 +671,7 @@ Node_login_zafu_en: user: tiger prop: text: "[FILE:app/views/zafu/default/Node-+login.zafu]" + title: Node-+login format: html tkpath: N mode: "+login" @@ -671,6 +683,7 @@ translations_de: lang: de prop: text: "[FILE:test/fixtures/files/translations_de.yml]" + title: translations content_type: text/yaml ext: yml size: 50 @@ -681,6 +694,7 @@ translations_fr: lang: fr prop: text: "[FILE:test/fixtures/files/translations_fr.yml]" + title: translations content_type: text/yaml ext: yml size: 50 \ No newline at end of file diff --git a/test/unit/after_commit_test.rb b/test/unit/after_commit_test.rb index d470376e..dd7c3b1d 100644 --- a/test/unit/after_commit_test.rb +++ b/test/unit/after_commit_test.rb @@ -9,7 +9,7 @@ class Page < ActiveRecord::Base attr_accessor :actions before_save :do_action after_save :raise_to_rollback - validates_presence_of :node_name + validates_presence_of :custom_a def after_commit_actions @after_commit_actions ||= [] @@ -24,19 +24,19 @@ def do_action end def raise_to_rollback - raise ActiveRecord::Rollback if self[:node_name] == 'raise' + raise ActiveRecord::Rollback if self[:custom_a] == 666 end end def test_after_commit_actions_should_be_executed_after_commit - page = Page.create(:node_name => 'hello') + page = Page.create(:custom_a => 1) assert_equal ['executed'], page.after_commit_actions end def test_after_commit_actions_should_be_executed_after_last_transaction page = nil Page.transaction do - page = Page.create(:node_name => 'hello') + page = Page.create(:custom_a => 1) assert_equal [], page.after_commit_actions end assert_equal ['executed'], page.after_commit_actions @@ -49,7 +49,7 @@ def test_after_commit_actions_should_not_be_executed_on_failure end def test_after_commit_actions_should_not_be_executed_on_raise - page = Page.create(:node_name => 'raise') + page = Page.create(:custom_a => 666) assert_equal [], page.after_commit_actions end @@ -57,7 +57,7 @@ def test_after_commit_actions_should_not_be_executed_if_an_outer_transaction_fai page = nil begin Page.transaction do - page = Page.create(:node_name => 'hello') + page = Page.create(:custom_a => 1) assert_equal [], page.after_commit_actions raise 'Something went bad' end @@ -69,7 +69,7 @@ def test_after_commit_actions_should_not_be_executed_if_an_outer_transaction_fai def test_after_commit_actions_should_not_be_executed_when_a_rollback_is_raised page = nil Page.transaction do - page = Page.create(:node_name => 'hello') + page = Page.create(:custom_a => 1) assert_equal [], page.after_commit_actions raise ActiveRecord::Rollback end diff --git a/test/unit/cache_test.rb b/test/unit/cache_test.rb index 552ff927..0313659b 100644 --- a/test/unit/cache_test.rb +++ b/test/unit/cache_test.rb @@ -1,5 +1,8 @@ require 'test_helper' +# Cache has been thrown to hell. + +=begin class CacheTest < Zena::Unit::TestCase def setup @@ -42,6 +45,34 @@ def test_create_cache assert_equal "content 6", Cache.with(2,[3,8] , 'NP', 'first' , 'test') { "content #{i}" } end + def test_after_all_cache_sweep + login(:lion) + i = 1 + assert_equal "content 1", Cache.with(visitor.id, visitor.group_ids, 'NP', 'pages') { "content #{i}" } + assert_equal "content 1", Cache.with(visitor.id, visitor.group_ids, 'NN', 'notes') { "content #{i}" } + i = 2 + assert_equal "content 1", Cache.with(visitor.id, visitor.group_ids, 'NP', 'pages') { "content #{i}" } + assert_equal "content 1", Cache.with(visitor.id, visitor.group_ids, 'NN', 'notes') { "content #{i}" } + + # do something on a project + node = secure!(Node) { nodes(:wiki) } + assert_equal 'NPP', node.class.kpath + assert node.update_attributes(:title=>'new title'), "Can change attributes" + # sweep only kpath NPP + i = 3 + assert_equal "content 3", Cache.with(visitor.id, visitor.group_ids, 'NP', 'pages') { "content #{i}" } + assert_equal "content 1", Cache.with(visitor.id, visitor.group_ids, 'NN', 'notes') { "content #{i}" } + + # do something on a note + node = secure!(Node) { nodes(:proposition) } + assert_equal 'NNP', node.vclass.kpath + assert node.update_attributes(:log_at => Time.now), "Can change attributes" + # sweep only kpath NN + i = 4 + assert_equal "content 3", Cache.with(visitor.id, visitor.group_ids, 'NP', 'pages') { "content #{i}" } + assert_equal "content 4", Cache.with(visitor.id, visitor.group_ids, 'NN', 'notes') { "content #{i}" } + end + def test_kpath i = 1 assert_equal "content 1", Cache.with(1,[2,3,4], 'NP', 'pages') { "content #{i}" } @@ -60,3 +91,4 @@ def test_kpath assert_equal "content 2", Cache.with(1,[2,3,4], 'NN', 'notes') { "content #{i}" } end end +=end \ No newline at end of file diff --git a/test/unit/cached_page_test.rb b/test/unit/cached_page_test.rb index 5fccdd04..f01eb6c7 100644 --- a/test/unit/cached_page_test.rb +++ b/test/unit/cached_page_test.rb @@ -65,7 +65,7 @@ def test_create_symlink login(:tiger) # edit node only node = secure!(Node) { nodes(:bird_jpg) } - assert node.update_attributes(:node_name => 'hey'), "Can save" + assert node.update_attributes(:title => 'hey'), "Can save" assert !File.exists?(path), "Cache file removed" end end diff --git a/test/unit/core_ext_test.rb b/test/unit/core_ext_test.rb index 54bbdbac..7ed8957f 100644 --- a/test/unit/core_ext_test.rb +++ b/test/unit/core_ext_test.rb @@ -1,10 +1,5 @@ -require 'rubygems' -require 'tzinfo' -require 'test/unit' -require 'fileutils' -require File.join(File.dirname(__FILE__), '../../lib/zena/core_ext/string') -require File.join(File.dirname(__FILE__), '../../lib/zena/core_ext/fixnum') -require File.join(File.dirname(__FILE__), '../../lib/zena/core_ext/dir') +# encoding: utf-8 +require 'test_helper' class StringExtTest < Test::Unit::TestCase def test_abs_rel_path @@ -33,6 +28,21 @@ def test_abs_rel_path assert_equal "/a/b/c", ''.abs_path('/a/b/c') end + + context 'A string with accents' do + subject do + "aïl en août" + end + + should 'remove accents on to_filename' do + assert_equal 'a%C3%AFl en ao%C3%BBt', subject.to_filename + end + + should 'recover original name on from_filename' do + assert_equal subject, String.from_filename(subject.to_filename) + end + end # A string with accents + end class DirExtTest < Test::Unit::TestCase diff --git a/test/unit/document_test.rb b/test/unit/document_test.rb index 8345c0fd..df662f3b 100644 --- a/test/unit/document_test.rb +++ b/test/unit/document_test.rb @@ -47,15 +47,11 @@ class Dummy < Document assert_equal 'pdf', subject.ext end - should 'set node_name from original_filename' do - assert_equal 'life', subject.node_name - end - should 'set title from original_filename' do - assert_equal 'life', subject.node_name + assert_equal 'life', subject.title end - context 'with same node_name' do + context 'with same title' do subject do secure!(Document) { Document.create( :parent_id => nodes_id(:cleanWater), @@ -63,11 +59,10 @@ class Dummy < Document } end - should 'save node_name and title with increment' do - assert_equal 'water-1', subject.node_name + should 'save title with increment' do assert_equal 'water-1', subject.title end - end # with same node_name + end # with same title context 'without a file' do subject do @@ -98,11 +93,11 @@ class Dummy < Document end end # with content_type - context 'with a wrong extension in node_name' do + context 'with a wrong extension in title' do subject do secure!(Document) { Document.create( :parent_id => nodes_id(:cleanWater), - :title => 'stupid', + :title => 'stupid.jpg', :file => uploaded_pdf('water.pdf')) } end @@ -111,11 +106,10 @@ class Dummy < Document err subject assert !subject.new_record? assert_equal 'pdf', subject.ext - assert_equal 'stupid', subject.node_name - assert_equal 'stupid', subject.title - assert_equal 'stupid.pdf', subject.filename + assert_equal 'stupid.jpg', subject.title + assert_equal 'stupid.jpg.pdf', subject.filename end - end # with wrong extension in node_name + end # with wrong extension in title context 'with title ending with dots' do subject do @@ -130,10 +124,6 @@ class Dummy < Document assert_equal 'report...', subject.title end - should 'keep dots in node_name' do - assert_equal 'report...', subject.node_name - end - should 'append extension afert dots' do assert_equal 'report....pdf', subject.filename end @@ -222,13 +212,12 @@ class Dummy < Document end end # with a wrong file type - context 'with existing node_name' do - should 'save node_name and title with increment' do + context 'with existing title' do + should 'save title with increment' do assert subject.update_attributes(:title => 'flower', :v_status => Zena::Status[:pub]) - assert_equal 'flower-1', subject.node_name assert_equal 'flower-1', subject.title end - end # with existing node_name + end # with existing title context 'with a new file' do # All tests relying on commit (filename, size, attachment) have been @@ -270,11 +259,6 @@ class Dummy < Document assert_match /bird\.jpg$/, subject.filepath end - should 'change document node_name on publish' do - subject.update_attributes(:title => 'hopla', :v_status => Zena::Status[:pub]) - assert_equal 'hopla', subject.node_name - end - should 'not alter content_type' do subject.update_attributes(:title => 'New title') assert_equal 'image/jpeg', subject.content_type @@ -299,10 +283,6 @@ class Dummy < Document assert subject.valid? end - should 'get node_name' do - assert_equal 'water', subject.node_name - end - should 'get title' do assert_equal 'water', subject.title end @@ -311,18 +291,10 @@ class Dummy < Document assert_equal 'water.pdf', subject.filename end - should 'get fullpath' do - assert_equal 'projects/cleanWater/water', subject.fullpath - end - should 'get filepath' do assert_match /water.pdf$/, subject.filepath end - should 'get rootpath' do - assert_equal 'zena/projects/cleanWater/water.pdf', subject.rootpath - end - should 'get the file size' do assert_equal 29279, subject.size end @@ -359,7 +331,7 @@ class Dummy < Document end should 'find document by path' do - subject = secure!(Document) { Document.find_by_path("projects/cleanWater/water") } + subject = secure(Document) { Document.find_by_path("projects list/Clean Water project/water") } assert_kind_of Document, subject assert_equal nodes_id(:water_pdf), subject.id end diff --git a/test/unit/node_name_test.rb b/test/unit/node_name_test.rb deleted file mode 100644 index 0f476128..00000000 --- a/test/unit/node_name_test.rb +++ /dev/null @@ -1,137 +0,0 @@ -require 'test_helper' - -class NodeNameTest < Zena::Unit::TestCase - - context 'A visitor with write access' do - setup do - login(:tiger) - end - - context 'on a node' do - subject do - secure!(Node) { nodes(:people) } - end - - should 'sync node_name with title on publish' do - assert subject.update_attributes(:title => 'nice people') - assert subject.publish - assert_equal 'nicePeople', subject.node_name - end - - should 'sync node_name with title if name changed' do - assert subject.update_attributes(:title => 'nice people', :node_name => 'foobar') - assert_equal 'foobar', subject.node_name - assert subject.publish - assert_equal 'nicePeople', subject.node_name - end - - should 'not sync node_name with title on redaction' do - assert subject.update_attributes(:title => 'nice people') - assert_equal 'people', subject.node_name - end - - context 'with another node with same node_name' do - setup do - page = secure!(Page) { Page.create( - :parent_id => subject.parent_id, - :title => 'nice people') # ==> nicePeople - } - end - - should 'not sync node_name with title on redaction' do - assert subject.update_attributes(:title => 'nice people') - assert_equal 'people', subject.node_name - end - - should 'set an error on node_name with title on publish' do - assert subject.update_attributes(:title => 'nice people') - assert !subject.publish - assert_equal subject.errors[:node_name], 'has already been taken' - end - end # with another node with same node_name - end # on a node - end # A visitor with write access - - # TODO: move these tests above - - def test_get_fullpath_rebuild - login(:lion) - node = secure!(Node) { nodes(:lake) } - assert_equal 'projects/cleanWater/lakeAddress', node.fullpath - assert node.update_attributes(:parent_id => nodes_id(:collections)) - assert_equal 'collections/lakeAddress', node.fullpath - end - - def test_fullpath_updated_on_parent_rename - login(:tiger) - node = secure!(Node) { nodes(:tiger) } - assert_equal 'people/tiger', node.fullpath - node = secure!(Node) { nodes(:tiger) } - assert_equal 'people/tiger', node[:fullpath] # make sure fullpath is cached - - node = secure!(Node) { nodes(:people) } - assert node.update_attributes(:title => 'nice people') - assert node.publish - assert_equal 'nicePeople', node.node_name # sync node_name - node = secure!(Node) { nodes(:tiger) } - assert_equal 'nicePeople/tiger', node[:fullpath] - end - - def test_rootpath - login(:ant) - node = secure!(Node) { nodes(:status) } - assert_equal 'zena/projects/cleanWater/status', node.rootpath - node = secure!(Node) { nodes(:zena) } - assert_equal 'zena', node.rootpath - end - - def test_basepath - login(:tiger) - node = secure!(Node) { nodes(:status) } - assert_equal 'projects/cleanWater', node.basepath - node = secure!(Node) { nodes(:projects) } - assert_equal '', node.basepath - node = secure!(Node) { nodes(:proposition) } - assert_equal '', node.basepath - end - - def test_sync_node_name_before_publish_if_single_version - login(:ant) - node = secure!(Node) { Node.create(:title => 'Eve', :parent_id => nodes_id(:people)) } - assert_equal Zena::Status[:red], node.v_status - assert_equal 'Eve', node.node_name - node.update_attributes(:title => 'Lilith') - assert_equal Zena::Status[:red], node.v_status - assert_equal 'Lilith', node.node_name - end - - def test_sync_node_name_on_title_change_auto_pub_no_sync - Site.connection.execute "UPDATE sites set auto_publish = #{Zena::Db::TRUE}, redit_time = 3600 WHERE id = #{sites_id(:zena)}" - Version.connection.execute "UPDATE versions set updated_at = '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}' WHERE node_id IN (#{nodes_id(:status)},#{nodes_id(:people)})" - login(:tiger) - - node = secure!(Node) { nodes(:status) } - assert node.update_attributes(:title => 'simply different') - assert_equal 'simplyDifferent', node.node_name - visitor.lang = 'fr' - # not ref lang - node = secure!(Node) { nodes(:people) } - assert node.update_attributes(:title => 'des gens sympathiques') - assert_equal 'fr', node.v_lang - assert_equal 'desGensSympathiques', node.node_name - end - - def test_sync_node_name_on_title_change_auto_pub - test_site('zena') - Site.connection.execute "UPDATE sites set auto_publish = #{Zena::Db::TRUE}, redit_time = 3600 WHERE id = #{sites_id(:zena)}" - Version.connection.execute "UPDATE versions set updated_at = '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}' WHERE node_id IN (#{nodes_id(:people)})" - login(:tiger) - node = secure!(Node) { nodes(:people) } - # was in sync, correct lang - assert_equal node.node_name, node.title - assert node.update_attributes(:title => 'nice people') - node = secure!(Node) { nodes(:people) } - assert_equal 'nice people', node.title - assert_equal 'nicePeople', node.node_name - end -end \ No newline at end of file diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb index e0d43ff9..8b2542af 100644 --- a/test/unit/node_test.rb +++ b/test/unit/node_test.rb @@ -4,7 +4,7 @@ class NodeTest < Zena::Unit::TestCase NEW_DEFAULT = { - :node_name => 'hello', + :title => 'hello', :rgroup_id => Zena::FoxyParser::id('zena', 'public'), :wgroup_id => Zena::FoxyParser::id('zena', 'workers'), :dgroup_id => Zena::FoxyParser::id('zena', 'managers'), @@ -112,76 +112,14 @@ class NodeTest < Zena::Unit::TestCase end # on a node with write access end # A logged in user - def test_rebuild_fullpath - Node.connection.execute "UPDATE nodes SET fullpath = NULL, basepath = NULL WHERE id = #{nodes_id(:wiki)}" - login(:ant) - node = nodes(:wiki) - assert_nil node[:fullpath] - node.send(:rebuild_fullpath) - assert_equal 'projects/wiki', node.fullpath - end - - def test_rebuild_fullpath_in_custom_base - Node.connection.execute "UPDATE nodes SET fullpath = NULL, basepath = NULL WHERE id = #{nodes_id(:status)}" - login(:ant) - node = nodes(:status) - assert_nil node[:fullpath] - node.send(:rebuild_fullpath) - assert_equal 'projects/cleanWater/status', node.fullpath - end - - def test_find_by_path - login(:ant) - node = secure!(Node) { Node.find_by_path('projects/wiki') } - assert_equal nodes_id(:wiki), node.id - end - + # This is a stupid test because the result is not the same in production... def test_match_query query = Node.match_query('smala') - assert_equal "nodes.node_name LIKE 'smala%'", query[:conditions] + assert_equal "nodes._id LIKE 'smala%'", query[:conditions] query = Node.match_query('.', :node => nodes(:wiki)) assert_equal ["parent_id = ?", nodes_id(:wiki)], query[:conditions] end - def test_ancestors - Node.connection.execute "UPDATE nodes SET parent_id = #{nodes_id(:proposition)} WHERE id = #{nodes_id(:bird_jpg)}" - login(:tiger) - node = secure!(Node) { nodes(:status) } - assert_equal ['zena', 'projects', 'cleanWater'], node.ancestors.map { |a| a[:node_name] } - node = secure!(Node) { nodes(:zena) } - assert_equal [], node.ancestors - node = secure!(Node) { nodes(:bird_jpg) } - prop = secure!(Node) { nodes(:proposition)} - assert_kind_of Node, prop - assert prop.can_read? - assert_equal ['zena', 'projects', 'secret', 'proposition'], node.ancestors.map { |a| a[:node_name] } - end - - def test_ancestors_infinit_loop - Node.connection.execute "UPDATE nodes SET parent_id = #{nodes_id(:status)} WHERE id = #{nodes_id(:cleanWater)}" - login(:ant) - node = secure!(Node) { nodes(:lake_jpg) } - assert_raise(Zena::InvalidRecord) { node.ancestors } - end - - def test_ancestor_in_hidden_project - login(:tiger) - node = secure!(Node) { nodes(:proposition) } - assert_kind_of Node, node - assert_equal ['zena', 'projects', 'secret'], node.ancestors.map { |a| a[:node_name] } # ant can view 'proposition' but not the project proposition is in - end - - def test_create_simplest - login(:ant) - test_page = secure!(Node) { Node.create(:node_name => 'yoba', :parent_id => nodes_id(:cleanWater), :inherit=>1 ) } - assert ! test_page.new_record? , "Not a new record" - assert_equal nodes_id(:cleanWater), test_page.parent[:id] - assert_equal 'projects/cleanWater/yoba', test_page.fullpath - assert_equal 'projects/cleanWater', test_page.basepath - parent = secure!(Node) { nodes(:cleanWater) } - assert_equal 'projects/cleanWater', parent.fullpath - end - def test_new_bad_parent login(:tiger) attrs = NEW_DEFAULT.dup @@ -215,16 +153,16 @@ def test_new_without_parent assert node.save , "Save succeeds" end - def test_page_new_without_node_name + def test_page_new_without_title login(:tiger) node = secure!(Node) { Node.new(:parent_id => nodes_id(:cleanWater)) } assert ! node.save, 'Save fails' - assert_equal 'can\'t be blank', node.errors[:node_name] + assert_equal 'can\'t be blank', node.errors[:title] end def test_new_set_section_id login(:tiger) - node = secure!(Page) { Page.create(:parent_id => nodes_id(:people), :node_name => 'SuperPage')} + node = secure!(Page) { Page.create(:parent_id => nodes_id(:people), :title => 'SuperPage')} assert ! node.new_record?, 'Not a new record' assert_equal nodes_id(:people), node[:section_id] end @@ -263,17 +201,12 @@ def test_update_bad_parent assert node.save , "Save succeeds" end - def test_page_update_without_node_name + def test_page_update_without_title login(:tiger) node = secure!(Node) { nodes(:status) } - node[:node_name] = nil - assert node.save, 'Save succeeds' - assert_equal 'statusTitle', node[:node_name] - node = secure!(Node) { nodes(:status) } - node[:node_name] = nil - node.title = "" - assert !node.save, 'Save fails' - assert_equal 'can\'t be blank', node.errors[:node_name] + node.title = nil + assert !node.save + assert_equal 'can\'t be blank', node.errors[:title] end def test_update_set_section_id @@ -329,11 +262,11 @@ def test_real_section def test_new_child login(:ant) node = secure!(Node) { nodes(:cleanWater) } - child = node.new_child(:node_name => 'status', :class => Page ) + child = node.new_child(:title => 'Etat des travaux', :class => Page ) assert !child.save, "Save fails" - assert child.errors[:node_name].any? + assert child.errors[:title].any? - child = node.new_child(:node_name => 'new_name', :class => Page ) + child = node.new_child(:title => 'new_name', :class => Page ) assert child.save , "Save succeeds" assert_equal Zena::Status[:red], child.v_status assert_equal child[:user_id], users_id(:ant) @@ -345,15 +278,6 @@ def test_new_child assert_equal node[:id], child[:parent_id] end - def test_secure_find_by_path - login(:tiger) - node = secure!(Node) { Node.find_by_path('projects/secret') } - assert_kind_of Node, node - assert_kind_of User, node.instance_variable_get(:@visitor) - login(:ant) - assert_raise(ActiveRecord::RecordNotFound) { node = secure!(Node) { Node.find_by_path('projects/secret') }} - end - def test_author login(:tiger) node = secure!(Node) { nodes(:cleanWater) } @@ -364,22 +288,6 @@ def test_author assert_equal 'Solenopsis Invicta', node.author.title end - def test_set_node_name_with_title - login(:tiger) - node = secure!(Node) { Node.create(NEW_DEFAULT.stringify_keys.merge('node_name' => '', 'title' => 'small bed')) } - assert_kind_of Node, node - assert !node.new_record? - assert_equal 'smallBed', node.node_name - end - - def test_set_node_name - node = nodes(:wiki) - node.node_name = " J'aime l'aïl en août ! " - assert_equal 'JAimeLAilEnAout', node.node_name - node.node_name = "LIEUX" - assert_equal 'LIEUX', node.node_name - end - def test_change_project_to_page login(:tiger) node = secure!(Node) { nodes(:cleanWater) } @@ -415,7 +323,7 @@ def test_change_project_to_page end should 'be allowed to change attributes' do - assert @node.update_attributes(:node_name => 'vodou', :event_at => Time.now) + assert @node.update_attributes(:event_at => Time.now) end should 'not be allowed to set parent' do @@ -578,10 +486,11 @@ def test_all_children end def test_url_name - assert_equal "salutJEcrisAujourdHui", "salut j'écris: Aujourd'hui ".url_name! - assert_equal "a--BabMol", " à,--/ bab* mol".url_name! - assert_equal "07.11.2006-mardiProchain", "07.11.2006-mardi_prochain".url_name! - assert_equal "Node-+login", "Node-+login".url_name! + assert_equal "salut-j%27%C3%A9cris%3A-Aujourd%27hui-", "salut j'écris: Aujourd'hui ".url_name + assert_equal "07.11.2006%2Dmardi_prochain", "07.11.2006-mardi_prochain".url_name + ['avant-hier', 'un ami ', 'èààèüï a', '" à,--/ bab* mol'].each do |l| + assert_equal l, String.from_url_name(l.url_name) + end end def test_tags @@ -593,13 +502,13 @@ def test_tags assert @node.save tags = @node.find(:all, 'set_tags') assert_equal 2, tags.size - assert_equal 'art', tags[0].node_name - assert_equal 'news', tags[1].node_name + assert_equal 'Art', tags[0].title + assert_equal 'News list', tags[1].title @node.rel['set_tag'].other_ids = [nodes_id(:art)] @node.save tags = @node.find(:all, 'set_tags') assert_equal 1, tags.size - assert_equal 'art', tags[0].node_name + assert_equal 'Art', tags[0].title end def test_tag_update @@ -613,36 +522,6 @@ def test_tag_update assert_equal node[:id], peop.find(:first, 'set_tags')[:id] end - def test_after_all_cache_sweep - with_caching do - login(:lion) - i = 1 - assert_equal "content 1", Cache.with(visitor.id, visitor.group_ids, 'NP', 'pages') { "content #{i}" } - assert_equal "content 1", Cache.with(visitor.id, visitor.group_ids, 'NN', 'notes') { "content #{i}" } - i = 2 - assert_equal "content 1", Cache.with(visitor.id, visitor.group_ids, 'NP', 'pages') { "content #{i}" } - assert_equal "content 1", Cache.with(visitor.id, visitor.group_ids, 'NN', 'notes') { "content #{i}" } - - # do something on a project - node = secure!(Node) { nodes(:wiki) } - assert_equal 'NPP', node.class.kpath - assert node.update_attributes(:title=>'new title'), "Can change attributes" - # sweep only kpath NPP - i = 3 - assert_equal "content 3", Cache.with(visitor.id, visitor.group_ids, 'NP', 'pages') { "content #{i}" } - assert_equal "content 1", Cache.with(visitor.id, visitor.group_ids, 'NN', 'notes') { "content #{i}" } - - # do something on a note - node = secure!(Node) { nodes(:proposition) } - assert_equal 'NNP', node.vclass.kpath - assert node.update_attributes(:node_name => 'popo' ), "Can change attributes" - # sweep only kpath NN - i = 4 - assert_equal "content 3", Cache.with(visitor.id, visitor.group_ids, 'NP', 'pages') { "content #{i}" } - assert_equal "content 4", Cache.with(visitor.id, visitor.group_ids, 'NN', 'notes') { "content #{i}" } - end - end - def test_empty_comments login(:tiger) node = secure!(Node) { nodes(:lake) } @@ -666,21 +545,47 @@ def test_discussion_lang assert !discussion.inside? end - def test_closed_discussion - login(:tiger) - node = secure!(Node) { nodes(:status) } - discussion = node.discussion - discussion.update_attributes(:open=>false) - node = secure!(Node) { nodes(:status) } - assert_equal discussions_id(:outside_discussion_on_status_en), node.discussion[:id] - login(:ant) - node = secure!(Node) { nodes(:status) } - assert_nil node.discussion - node.update_attributes( :title=>'test' ) - discussion = node.discussion - assert_kind_of Discussion, discussion - assert discussion.inside? - end + context 'A node with a discussion' do + setup do + login(:tiger) + visitor.lang = 'fr' + subject.update_attributes('title' => 'new publication', :v_status => Zena::Status[:pub]) + subject.reload + end + + subject do + # has an open discussion in 'en' + secure(Node) { nodes(:status) } + end + + context 'visited in another language without discussion' do + setup do + login(:ant) + end + + should 'create an outside discussion' do + assert_kind_of Discussion, subject.discussion + assert !subject.discussion.inside? + end + end # visited in another language + + context 'that is closed' do + setup do + discussions(:outside_discussion_on_status_en).update_attributes(:open => false) + end + + context 'visited in another language without discussion without drive access' do + setup do + login(:ant) + end + + should 'not create a discussion' do + assert_nil subject.discussion + end + end # visited in another language + end # that is closed + + end # A node with a closed discussion def test_inside_discussion login(:tiger) @@ -727,7 +632,7 @@ def test_comments node = secure!(Node) { nodes(:status) } comments = node.comments assert_kind_of Comment, comments[0] - assert_equal 'Nice site', comments[0][:title] + assert_equal 'Nice site', comments[0].title end def test_comments_on_nil @@ -747,14 +652,14 @@ def test_site_id def test_other_site_id login(:whale) - node = secure!(Node) { Node.create(:parent_id => nodes_id(:ocean), :rgroup_id => groups_id(:aqua), :wgroup_id => groups_id(:masters), :dgroup_id => groups_id(:masters), :node_name => "fish") } + node = secure!(Node) { Node.create(:parent_id => nodes_id(:ocean), :rgroup_id => groups_id(:aqua), :wgroup_id => groups_id(:masters), :dgroup_id => groups_id(:masters), :title => "fish") } assert !node.new_record?, "Not a new record" assert_equal sites_id(:ocean), node[:site_id] end def test_other_site_id_fool_id login(:whale) - node = secure!(Node) { Node.create(:parent_id => nodes_id(:ocean), :rgroup_id => groups_id(:aqua), :wgroup_id => groups_id(:masters), :dgroup_id => groups_id(:masters), :node_name => "fish", :site_id => sites_id(:zena)) } + node = secure!(Node) { Node.create(:parent_id => nodes_id(:ocean), :rgroup_id => groups_id(:aqua), :wgroup_id => groups_id(:masters), :dgroup_id => groups_id(:masters), :title => "fish", :site_id => sites_id(:zena)) } assert !node.new_record?, "Not a new record" assert_equal sites_id(:ocean), node[:site_id] end @@ -776,7 +681,7 @@ def test_cannot_set_site_id_with_new_record def test_zip next_zip = Zena::Db.fetch_attribute("SELECT zip FROM zips WHERE site_id = #{sites_id(:zena)}").to_i login(:tiger) - node = secure!(Node) { Node.create(:parent_id=>nodes_id(:zena), :node_name => "fly")} + node = secure!(Node) { Node.create(:parent_id=>nodes_id(:zena), :title => "fly")} assert !node.new_record?, "Not a new record" assert_equal (next_zip + 1), node.zip end @@ -797,7 +702,7 @@ def test_parent_zip def test_create_node login(:ant) - node = secure!(Node) { Node.create_node(:parent_id => nodes_zip(:secret), :node_name => 'funny') } + node = secure!(Node) { Node.create_node(:parent_id => nodes_zip(:secret), :title => 'funny') } assert_equal nodes_id(:secret), node[:parent_id] assert node.new_record?, "Not saved" assert_equal 'invalid reference', node.errors[:parent_id] @@ -805,7 +710,7 @@ def test_create_node def test_create_node_with__parent_id login(:ant) - node = secure!(Node) { Node.create_node(:_parent_id => nodes_id(:secret), :node_name => 'funny') } + node = secure!(Node) { Node.create_node(:_parent_id => nodes_id(:secret), :title => 'funny') } assert_equal nodes_id(:secret), node[:parent_id] assert node.new_record?, "Not saved" assert_equal 'invalid reference', node.errors[:parent_id] @@ -813,36 +718,50 @@ def test_create_node_with__parent_id def test_create_node_ok login(:tiger) - node = secure!(Node) { Node.create_node('parent_id' => nodes_zip(:cleanWater), 'node_name' => 'funny') } + node = secure!(Node) { Node.create_node('parent_id' => nodes_zip(:cleanWater), 'title' => 'funny') } assert_equal nodes_id(:cleanWater), node[:parent_id] - assert_equal 'funny', node[:node_name] + assert_equal 'funny', node.title assert !node.new_record? end + context 'Create or update from parent and title' do + setup do + login(:tiger) + end - def test_create_or_update_node_create - login(:tiger) - node = secure!(Node) { Node.create_or_update_node('parent_id' => nodes_zip(:cleanWater), 'node_name' => 'funny') } - assert_equal nodes_id(:cleanWater), node[:parent_id] - assert_equal 'funny', node[:node_name] - assert !node.new_record?, "Saved" - end + context 'with matching node' do + subject do + secure(Node) { Node.create_or_update_node('parent_id' => nodes_zip(:cleanWater), 'title' => 'crocodiles', 'text' => 'Philippine crocodile') } + end - def test_create_or_update_node_update - login(:tiger) - node = secure!(Node) { Node.create_or_update_node('parent_id' => nodes_zip(:cleanWater), 'node_name' => 'status', 'title'=>"It's all broken") } - assert_equal nodes_id(:cleanWater), node[:parent_id] - assert_equal nodes_id(:status), node[:id] - node = secure!(Node) { nodes(:status) } - assert_equal 'status', node[:node_name] - assert_equal "It's all broken", node.title - end + should 'update found node' do + assert_difference('Node.count', 0) do + assert subject.errors.blank? + assert_equal nodes_id(:crocodiles), subject.id + assert_equal 'Philippine crocodile', subject.prop['text'] + end + end + end # with matching node + + context 'without a matching node' do + subject do + secure(Node) { Node.create_or_update_node('parent_id' => nodes_zip(:cleanWater), 'title' => 'scorpion', 'text' => 'Compsobuthus werneri') } + end + + should 'create a new node' do + assert_difference('Node.count', 1) do + subject + end + end + end # without a matching node + + end # Create or update from parent and title def test_create_with_klass login(:tiger) - node = secure!(Node) { Node.create_node('parent_id' => nodes_zip(:projects), 'node_name' => 'funny', 'klass' => 'TextDocument', 'content_type' => 'application/x-javascript') } + node = secure!(Node) { Node.create_node('parent_id' => nodes_zip(:projects), 'title' => 'funny', 'klass' => 'TextDocument', 'content_type' => 'application/x-javascript') } assert_kind_of TextDocument, node assert_equal nodes_id(:projects), node[:parent_id] - assert_equal 'funny', node[:node_name] + assert_equal 'funny', node.title assert !node.new_record?, "Saved" end @@ -878,7 +797,7 @@ def test_get_attributes_from_yaml def test_create_nodes_from_gzip_file login(:tiger) - parent = secure!(Project) { Project.create(:node_name => 'import', :parent_id => nodes_id(:zena)) } + parent = secure!(Project) { Project.create(:title => 'import', :parent_id => nodes_id(:zena)) } assert !parent.new_record?, "Not a new record" nodes = secure!(Node) { Node.create_nodes_from_folder(:archive => uploaded_archive('simple.zml.gz'), :parent_id => parent[:id] )}.values assert_equal 1, nodes.size @@ -890,25 +809,25 @@ def test_create_nodes_from_gzip_file def test_create_nodes_from_folder_with_defaults login(:tiger) - parent = secure!(Project) { Project.create(:node_name => 'import', :parent_id => nodes_id(:zena), :rgroup_id => groups_id(:managers), :wgroup_id => groups_id(:managers)) } + parent = secure!(Project) { Project.create(:title => 'import', :parent_id => nodes_id(:zena), :rgroup_id => groups_id(:managers), :wgroup_id => groups_id(:managers)) } assert !parent.new_record?, "Not a new record" - result = secure!(Node) { Node.create_nodes_from_folder(:folder => File.join(Zena::ROOT, 'test', 'fixtures', 'import'), :parent_id => parent[:id] )}.values + result = secure!(Node) { Node.create_nodes_from_folder(:folder => File.join(Zena::ROOT, 'test', 'fixtures', 'import'), :parent_id => parent.id )}.values assert_equal 4, result.size - children = parent.find(:all, 'children order by node_name asc') + children = parent.find(:all, 'nodes order by title asc') assert_equal 2, children.size - assert_equal 'Photos', children[0].node_name + assert_equal 'Photos !', children[0].title assert_equal groups_id(:managers), children[0].rgroup_id - assert_equal 'simple', children[1].node_name + assert_equal 'simple', children[1].title assert_equal groups_id(:managers), children[1].rgroup_id # we use children[1] as parent just to use any empty node result = secure!(Node) { Node.create_nodes_from_folder(:folder => File.join(Zena::ROOT, 'test', 'fixtures', 'import'), :parent_id => children[1][:id], :defaults => { :rgroup_id => groups_id(:public) } )}.values assert_equal 4, result.size - children = children[1].find(:all, 'children order by node_name ASC') + children = children[1].find(:all, 'nodes order by title ASC') assert_equal 2, children.size - assert_equal 'Photos', children[0].node_name + assert_equal 'Photos !', children[0].title assert_equal groups_id(:public), children[0].rgroup_id end @@ -923,55 +842,85 @@ def test_create_nodes_from_folder_with_publish def test_create_nodes_from_archive login(:tiger) - res = secure!(Node) { Node.create_nodes_from_folder(:archive => uploaded_archive('import.tgz'), :parent_id => nodes_id(:zena)) }.values - photos = secure!(Section) { Section.find_by_node_name('Photos') } + res = secure(Node) { Node.create_nodes_from_folder(:archive => uploaded_archive('import.tgz'), :parent_id => nodes_id(:zena)) }.values + photos = secure!(Section) { Section.first(:conditions => {:_id => 'Photos !'}) } assert_kind_of Section, photos - bird = secure!(Node) { Node.find_by_parent_id_and_node_name(photos[:id], 'bird') } + bird = secure!(Node) { Node.find_by_parent_id_and__id(photos[:id], 'bird') } assert_kind_of Image, bird assert_equal 56183, bird.size assert_equal 'Lucy in the sky', bird.text visitor.lang = 'fr' - bird = secure!(Node) { Node.find_by_parent_id_and_node_name(photos[:id], 'bird') } + bird = secure!(Node) { Node.find_by_parent_id_and__id(photos[:id], 'bird') } assert_equal 'Le septième ciel', bird.text assert_equal 1, bird[:inherit] assert_equal groups_id(:public), bird[:rgroup_id] assert_equal groups_id(:workers), bird[:wgroup_id] assert_equal groups_id(:managers), bird[:dgroup_id] - simple = secure!(Node) { Node.find_by_parent_id_and_node_name(nodes_id(:zena), 'simple') } + simple = secure!(Node) { Node.find_by_parent_id_and__id(nodes_id(:zena), 'simple') } assert_equal 0, simple[:inherit] assert_equal groups_id(:managers), simple[:rgroup_id] assert_equal groups_id(:managers), simple[:wgroup_id] assert_equal groups_id(:managers), simple[:dgroup_id] end - def test_create_nodes_from_zip_archive - login(:tiger) - res = secure!(Node) { Node.create_nodes_from_folder(:archive => uploaded_zip('letter.zip'), :parent_id => nodes_id(:zena), :class => 'Letter') }.values - res.sort!{|a,b| a.node_name <=> b.node_name} - letter, bird = res[1], res[0] - assert_kind_of Note, letter - assert_equal 'Letter', letter.klass - end - - def test_update_nodes_from_archive - preserving_files('test.host/data') do - bird = node = nil + context 'With an archive' do + setup do login(:tiger) - node = secure!(Page) { Page.create(:parent_id => nodes_id(:status), :title => 'Photos', :text => '![]!') } - assert !node.new_record? - assert_nothing_raised { node = secure!(Node) { Node.find_by_path('projects/cleanWater/status/Photos') } } - assert_raise(ActiveRecord::RecordNotFound) { node = secure!(Node) { Node.find_by_path( 'projects/cleanWater/status/Photos/bird') } } - assert_no_match %r{I took during my last vacations}, node.text - v1_id = node.version.id - secure!(Node) { Node.create_nodes_from_folder(:archive => uploaded_archive('import.tgz'), :parent_id => nodes_id(:status)) } - assert_nothing_raised { node = secure!(Node) { Node.find_by_path('projects/cleanWater/status/Photos') } } - assert_nothing_raised { bird = secure!(Node) { Node.find_by_path('projects/cleanWater/status/Photos/bird') } } - assert_match %r{I took during my last vacations}, node.text - assert_equal v1_id, node.version.id - assert_kind_of Image, bird end - end + + subject do + secure(Node) { Node.create_nodes_from_folder( + :archive => uploaded_archive('import.tgz'), + :parent_id => nodes_id(:status)).values + } + end + + should 'create new entries' do + assert_difference('Node.count', 4) do + subject + end + end + + context 'updating existing pages' do + setup do + @photos = secure!(Page) { Page.create(:parent_id => nodes_id(:status), :title => 'Photos !', :text => '![]!') } + end + + should 'create missing entries' do + assert_difference('Node.count', 3) do + subject + end + end + + should 'create entries of correct type' do + subject + assert_kind_of Image, secure(Node) { Node.find_by_parent_title_and_kpath(@photos.id, 'bird')} + end + + should 'update existing entries' do + subject + assert_match %r{I took during my last vacations}, @photos.reload.text + end + end # updating existing pages + + context 'with specified class' do + subject do + secure(Node) { Node.create_nodes_from_folder( + :archive => uploaded_zip('letter.zip'), + :parent_id => nodes_id(:zena), + :class => 'Letter').values + } + end + + should 'create with correct vclass' do + letter = subject.detect {|n| n.title == 'letter'} + assert_kind_of Note, letter + assert_equal 'Letter', letter.klass + end + end # with instances of vclass + + end # With an archive def test_to_yaml #test_site('zena') @@ -982,7 +931,7 @@ def test_to_yaml assert status.update_attributes_with_transformation(:v_status => Zena::Status[:pub], :text => "This is a \"link\":#{nodes_zip(:projects)}.", :origin => "A picture: !#{nodes_zip(:bird_jpg)}!") yaml = status.to_yaml assert_match %r{text:\s+\"?This is a "link":\(\.\./\.\.\)\.}, yaml - assert_match %r{origin:\s+\"?A picture: !\(\.\./\.\./wiki/bird\)!}, yaml + assert_match %r{origin:\s+\"?A picture: !\(\.\./\.\./a wiki with Zena/bird\)!}, yaml assert_no_match %r{log_at}, yaml end @@ -994,24 +943,26 @@ def test_to_yaml_with_change_log_at assert_equal Time.gm(2008,10,20,7,53), prop.log_at yaml = prop.to_yaml assert_match %r{text:\s+\"?This is a "link":\(\.\./\.\.\)\.}, yaml - assert_match %r{origin:\s+\"?A picture: !\(\.\./\.\./wiki/bird\)!}, yaml + assert_match %r{origin:\s+\"?A picture: !\(\.\./\.\./a wiki with Zena/bird\)!}, yaml assert_match %r{log_at:\s+\"?2008-10-20 14:53:00\"?$}, yaml end def test_order_position login(:tiger) - parent = secure!(Node) { nodes(:cleanWater) } + parent = secure!(Node) { nodes(:collections) } + # default sort is position/title + # ["Art", "News list", "Stranger in the night", "Top menu", "wiki skin"] children = parent.find(:all, 'children') - assert_equal 8, children.size - assert_equal 'bananas', children[0].node_name - assert_equal 'crocodiles', children[1].node_name + assert_equal 5, children.size + assert_equal nodes_id(:art), children[0].id + assert_equal nodes_id(:news), children[1].id - Node.connection.execute "UPDATE nodes SET position = -1.0 WHERE id = #{nodes_id(:water_pdf)}" - Node.connection.execute "UPDATE nodes SET position = -0.5 WHERE id = #{nodes_id(:lake)}" + Node.connection.execute "UPDATE nodes SET position = -1.0 WHERE id = #{nodes_id(:menu)}" + Node.connection.execute "UPDATE nodes SET position = -0.5 WHERE id = #{nodes_id(:strange)}" children = parent.find(:all, 'children') - assert_equal 8, children.size - assert_equal 'water', children[0].node_name - assert_equal 'lakeAddress', children[1].node_name + assert_equal 5, children.size + assert_equal nodes_id(:menu), children[0].id + assert_equal nodes_id(:strange), children[1].id end def test_plural_relation @@ -1133,14 +1084,14 @@ def test_data_d def test_position_on_create login(:lion) - node = secure!(Page) { Page.create(:node_name => "yoba", :parent_id => nodes_id(:cleanWater), :inherit=>1 ) } + node = secure!(Page) { Page.create(:title => "yoba", :parent_id => nodes_id(:cleanWater), :inherit=>1 ) } assert !node.new_record? assert_equal 0.0, node.position assert node.update_attributes(:position => 5.0) assert_equal 5.0, node.position node = secure!(Page) { Page.find_by_id(node.id) } # reload assert_equal 5.0, node.position - node = secure!(Page) { Page.create(:node_name => "babo", :parent_id => nodes_id(:cleanWater), :inherit=>1 ) } + node = secure!(Page) { Page.create(:title => "babo", :parent_id => nodes_id(:cleanWater), :inherit=>1 ) } assert !node.new_record? assert_equal 6.0, node.position @@ -1215,19 +1166,19 @@ def test_export FileUtils::mkpath(export_folder) # Add a page and a text document into 'wiki' assert secure!(Node) { Node.create(:title=>"Hello World!", :text => "Bonjour", :parent_id => nodes_id(:wiki), :inherit=>1 ) } - assert secure!(TextDocument) { TextDocument.create(:node_name => "yoba", :parent_id => nodes_id(:wiki), :text => "#header { color:red; }\n#footer { color:blue; }", :content_type => 'text/css') } + assert secure!(TextDocument) { TextDocument.create(:title => "yoba", :parent_id => nodes_id(:wiki), :text => "#header { color:red; }\n#footer { color:blue; }", :content_type => 'text/css') } wiki = secure!(Node) { nodes(:wiki) } assert_equal 4, wiki.find(:all, "children").size wiki.export_to_folder(export_folder) - assert File.exist?(File.join(export_folder, 'wiki.zml')) - assert File.exist?(File.join(export_folder, 'wiki')) - assert File.exist?(File.join(export_folder, 'wiki', 'bird.jpg')) - assert !File.exist?(File.join(export_folder, 'wiki', 'bird.zml')) - assert File.exist?(File.join(export_folder, 'wiki', 'flower.jpg')) - assert !File.exist?(File.join(export_folder, 'wiki', 'flower.zml')) - assert File.exist?(File.join(export_folder, 'wiki', 'yoba.css')) - assert !File.exist?(File.join(export_folder, 'wiki', 'yoba.zml')) - assert File.exist?(File.join(export_folder, 'wiki', 'HelloWorld.zml')) + assert File.exist?(File.join(export_folder, 'a wiki with Zena.zml')) + assert File.exist?(File.join(export_folder, 'a wiki with Zena')) + assert File.exist?(File.join(export_folder, 'a wiki with Zena', 'bird.jpg')) + assert !File.exist?(File.join(export_folder, 'a wiki with Zena', 'bird.zml')) + assert File.exist?(File.join(export_folder, 'a wiki with Zena', 'flower.jpg')) + assert !File.exist?(File.join(export_folder, 'a wiki with Zena', 'flower.zml')) + assert File.exist?(File.join(export_folder, 'a wiki with Zena', 'yoba.css')) + assert !File.exist?(File.join(export_folder, 'a wiki with Zena', 'yoba.zml')) + assert File.exist?(File.join(export_folder, 'a wiki with Zena', 'Hello World!.zml'.to_filename)) end end @@ -1238,20 +1189,20 @@ def test_archive FileUtils::mkpath(export_folder) # Add a page and a text document into 'wiki' assert secure!(Node) { Node.create(:title=>"Hello World!", :text => "Bonjour", :parent_id => nodes_id(:wiki), :inherit=>1 ) } - assert secure!(TextDocument) { TextDocument.create(:node_name => "yoba", :parent_id => nodes_id(:wiki), :text => "#header { color:red; }\n#footer { color:blue; }", :content_type => 'text/css') } + assert secure!(TextDocument) { TextDocument.create(:title => "yoba", :parent_id => nodes_id(:wiki), :text => "#header { color:red; }\n#footer { color:blue; }", :content_type => 'text/css') } wiki = secure!(Node) { nodes(:wiki) } assert_equal 4, wiki.find(:all, "children").size archive = wiki.archive `tar -C '#{export_folder}' -xz < '#{archive.path}'` - assert File.exist?(File.join(export_folder, 'wiki.zml')) - assert File.exist?(File.join(export_folder, 'wiki')) - assert File.exist?(File.join(export_folder, 'wiki', 'bird.jpg')) - assert !File.exist?(File.join(export_folder, 'wiki', 'bird.zml')) - assert File.exist?(File.join(export_folder, 'wiki', 'flower.jpg')) - assert !File.exist?(File.join(export_folder, 'wiki', 'flower.zml')) - assert File.exist?(File.join(export_folder, 'wiki', 'yoba.css')) - assert !File.exist?(File.join(export_folder, 'wiki', 'yoba.zml')) - assert File.exist?(File.join(export_folder, 'wiki', 'HelloWorld.zml')) + assert File.exist?(File.join(export_folder, 'a wiki with Zena.zml')) + assert File.exist?(File.join(export_folder, 'a wiki with Zena')) + assert File.exist?(File.join(export_folder, 'a wiki with Zena', 'bird.jpg')) + assert !File.exist?(File.join(export_folder, 'a wiki with Zena', 'bird.zml')) + assert File.exist?(File.join(export_folder, 'a wiki with Zena', 'flower.jpg')) + assert !File.exist?(File.join(export_folder, 'a wiki with Zena', 'flower.zml')) + assert File.exist?(File.join(export_folder, 'a wiki with Zena', 'yoba.css')) + assert !File.exist?(File.join(export_folder, 'a wiki with Zena', 'yoba.zml')) + assert File.exist?(File.join(export_folder, 'a wiki with Zena', 'Hello World!.zml'.to_filename)) end end @@ -1267,18 +1218,22 @@ def test_translate_pseudo_id def test_translate_pseudo_id_path login(:lion) - lion = secure!(Node) { nodes(:lion) } - people = secure!(Node) { nodes(:people) } - cleanWater = secure!(Node) { nodes(:cleanWater) } - assert lion.update_attributes(:title => 'status', :v_status => Zena::Status[:pub]) - assert_equal 'people/status', lion.fullpath + art = secure(Node) { nodes(:art) } + collections = secure(Node) { nodes(:collections) } + cleanWater = secure(Node) { nodes(:cleanWater) } + + assert art.update_attributes(:title => 'status title', :v_status => Zena::Status[:pub]) + + assert_equal 'Collections/status title', art.fullpath_as_title.join('/') + # path base_node - { ['(/projects/cleanWater/status)', nil] => nodes_id(:status), - ['(/projects/cleanWater/status)', people] => nodes_id(:status), - ['(status)', people] => nodes_id(:lion), - ['(status)', cleanWater] => nodes_id(:status), - }.each do |k,v| - assert_equal v, secure(Node) { Node.translate_pseudo_id(k[0],:id,k[1]) }, "'#{k.inspect}' should translate to '#{v}'" + { ['(/projects list/Clean Water project/status title)', nil] => nodes_id(:status), + ['(/projects list/Clean Water project/status title)', collections] => nodes_id(:status), + ['(status title)', collections] => nodes_id(:art), + ['(status title)', cleanWater] => nodes_id(:status), + }.each do |k, v| + assert_equal v, secure(Node) { Node.translate_pseudo_id(k[0],:id,k[1]) }, "'#{k[0]}' in '#{k[1] ? k[1].title : 'nil + '}' should translate to '#{v}'" end end @@ -1286,13 +1241,13 @@ def test_unparse_assets login(:lion) @node = secure!(Node) { nodes(:status) } assert @node.update_attributes(:text => "Hello this is \"art\":#{nodes_zip(:art)}. !#{nodes_zip(:bird_jpg)}!") - assert_equal "Hello this is \"art\":(../../../collections/art). !(../../wiki/bird)!", @node.unparse_assets(@node.text, self, 'text') + assert_equal "Hello this is \"art\":(../../../Collections/Art). !(../../a wiki with Zena/bird)!", @node.unparse_assets(@node.text, self, 'text') end def test_parse_assets login(:lion) @node = secure!(Node) { nodes(:status) } - assert @node.update_attributes(:text => "Hello this is \"art\":(../../../collections/art).") + assert @node.update_attributes(:text => "Hello this is \"art\":(../../../Collections/Art).") assert_equal "Hello this is \"art\":#{nodes_zip(:art)}.", @node.parse_assets(@node.text, self, 'text') end diff --git a/test/unit/note_test.rb b/test/unit/note_test.rb index b7b0895c..a4d7671a 100644 --- a/test/unit/note_test.rb +++ b/test/unit/note_test.rb @@ -1,22 +1,14 @@ require 'test_helper' class NoteTest < Zena::Unit::TestCase - + def test_create_simplest login(:ant) - test_page = secure!(Note) { Note.create(:node_name => "yoba", :parent_id => nodes_id(:cleanWater), :inherit=>1 ) } + test_page = secure!(Note) { Note.create(:title => "yoba", :parent_id => nodes_id(:cleanWater), :inherit=>1 ) } assert ! test_page.new_record? , "Not a new record" assert_equal nodes_id(:cleanWater), test_page.parent[:id] - assert_equal 'projects/cleanWater/yoba', test_page.fullpath - assert_equal 'projects/cleanWater', test_page.basepath - end - - def test_create_with_node_name - login(:tiger) - note = nil - assert_nothing_raised { note = secure!(Note) { Note.create(:node_name => "asdf", :parent_id=>nodes_id(:zena), :log_at=>"2006-06-20", :set_tag_ids=>[nodes_id(:news)])} } - assert note , "Note created" - assert ! note.new_record? , "Not a new record" + assert_equal '18/21/64', test_page.fullpath + assert_equal '18/21', test_page.basepath end def test_create_with_title @@ -25,68 +17,68 @@ def test_create_with_title assert_nothing_raised { note = secure!(Note) { Note.create(:title=>"Monday is nice", :parent_id=>nodes_id(:zena), :log_at=>"2006-06-20", :set_tag_ids=>[nodes_id(:news)])} } assert note , "Note created" assert ! note.new_record? , "Not a new record" - assert_equal "MondayIsNice", note[:node_name] + assert_equal "Monday is nice", note.title end - def test_create_same_node_name + def test_create_same_title login(:tiger) note, note2, note3 = nil, nil, nil - assert_nothing_raised { note = secure!(Note) { Note.create(:node_name => "test", :parent_id=>nodes_id(:zena), :log_at=>"2006-06-20", :set_tag_ids=>[nodes_id(:news)])} } + assert_nothing_raised { note = secure!(Note) { Note.create(:title => "test", :parent_id=>nodes_id(:zena), :log_at=>"2006-06-20", :set_tag_ids=>[nodes_id(:news)])} } assert note , "Note created" assert ! note.new_record? , "Not a new record" - assert_equal "test", note[:node_name] + assert_equal "test", note.title - assert_nothing_raised { note2 = secure!(Note) { Note.create(:node_name => "test", :parent_id=>nodes_id(:zena), :log_at=>"2006-06-20", :set_tag_ids=>[nodes_id(:news)])} } - assert ! note2.new_record? , "Not a new record" # same node_name allowed for notes + assert_nothing_raised { note2 = secure!(Note) { Note.create(:title => "test", :parent_id=>nodes_id(:zena), :log_at=>"2006-06-20", :set_tag_ids=>[nodes_id(:news)])} } + assert ! note2.new_record? , "Not a new record" # same title allowed for notes end - def test_create_same_node_name_other_day + def test_create_same_title_other_day login(:tiger) note, note2, note3 = nil, nil, nil - assert_nothing_raised { note = secure!(Note) { Note.create(:node_name => "test", :parent_id=>nodes_id(:zena), :log_at=>"2006-06-20", :set_tag_ids=>[nodes_id(:news)])} } + assert_nothing_raised { note = secure!(Note) { Note.create(:title => "test", :parent_id=>nodes_id(:zena), :log_at=>"2006-06-20", :set_tag_ids=>[nodes_id(:news)])} } assert note , "Note created" assert ! note.new_record? , "Not a new record" - assert_equal "test", note[:node_name] + assert_equal "test", note.title - assert_nothing_raised { note2 = secure!(Note) { Note.create(:node_name => "test", :parent_id=>nodes_id(:zena), :log_at=>"2006-07-20", :set_tag_ids=>[nodes_id(:news)])} } + assert_nothing_raised { note2 = secure!(Note) { Note.create(:title => "test", :parent_id=>nodes_id(:zena), :log_at=>"2006-07-20", :set_tag_ids=>[nodes_id(:news)])} } assert !note2.new_record? , "Not a new record" - assert_equal "test", note2[:node_name] + assert_equal "test", note2.title end - def test_update_same_node_name + def test_update_same_title login(:tiger) note, note2 = nil, nil - assert_nothing_raised { note = secure!(Note) { Note.create(:node_name => "test", :parent_id=>nodes_id(:zena), :log_at=>"2006-06-20", :set_tag_ids=>[nodes_id(:news)])} } + assert_nothing_raised { note = secure!(Note) { Note.create(:title => "test", :parent_id=>nodes_id(:zena), :log_at=>"2006-06-20", :set_tag_ids=>[nodes_id(:news)])} } assert note , "Note created" assert ! note.new_record? , "Not a new record" - assert_equal "test", note[:node_name] + assert_equal "test", note.title - assert_nothing_raised { note2 = secure!(Note) { Note.create(:node_name => "asdf", :parent_id=>nodes_id(:zena), :log_at=>"2006-06-20", :set_tag_ids=>[nodes_id(:news)])} } + assert_nothing_raised { note2 = secure!(Note) { Note.create(:title => "asdf", :parent_id=>nodes_id(:zena), :log_at=>"2006-06-20", :set_tag_ids=>[nodes_id(:news)])} } assert note , "Note created" assert ! note2.new_record? , "Not a new record" - note2.node_name = "test" + note2.title = "test" assert note2.save end def test_default_set_event_at login(:tiger) - note = secure!(Note) { Note.create(:node_name => 'test', :parent_id => nodes_id(:zena), :event_at => '2009-06-15')} + note = secure!(Note) { Note.create(:title => 'test', :parent_id => nodes_id(:zena), :event_at => '2009-06-15')} assert_equal '2009-06-15', note.event_at.strftime('%Y-%m-%d') assert_equal '2009-06-15', note.log_at.strftime('%Y-%m-%d') end def test_default_set_log_at login(:tiger) - note = secure!(Note) { Note.create(:node_name => 'test', :parent_id => nodes_id(:zena), :log_at => '2009-06-15')} + note = secure!(Note) { Note.create(:title => 'test', :parent_id => nodes_id(:zena), :log_at => '2009-06-15')} assert_equal '2009-06-15', note.event_at.strftime('%Y-%m-%d') assert_equal '2009-06-15', note.log_at.strftime('%Y-%m-%d') end def test_default_set_log_at_and_event_at login(:tiger) - note = secure!(Note) { Note.create(:node_name => 'test', :parent_id => nodes_id(:zena), :event_at => '2009-06-15', :log_at => '2009-06-16')} + note = secure!(Note) { Note.create(:title => 'test', :parent_id => nodes_id(:zena), :event_at => '2009-06-15', :log_at => '2009-06-16')} assert_equal '2009-06-15', note.event_at.strftime('%Y-%m-%d') assert_equal '2009-06-16', note.log_at.strftime('%Y-%m-%d') end diff --git a/test/unit/page_test.rb b/test/unit/page_test.rb index 74d7b286..6e16edd8 100644 --- a/test/unit/page_test.rb +++ b/test/unit/page_test.rb @@ -7,60 +7,59 @@ def test_create_just_title node = secure!(Page) { Page.create(:parent_id=>nodes_id(:projects), :title=>'lazy node')} err node assert !node.new_record? - assert_equal 'lazyNode', node.node_name assert_equal 'lazy node', node.title end - def test_create_same_node_name + def test_create_same_title login(:tiger) - node = secure!(Page) { Page.create(:parent_id=>nodes_id(:projects), :node_name =>'wiki')} + node = secure!(Page) { Page.create(:parent_id=>nodes_id(:projects), :title =>'a wiki with Zena')} assert node.new_record? - assert_equal 'has already been taken', node.errors[:node_name] + assert_equal 'has already been taken', node.errors[:title] end - def test_create_same_node_name_other_parent + def test_create_same_title_other_parent login(:tiger) - node = secure!(Page) { Page.create(:parent_id=>nodes_id(:cleanWater), :node_name =>'wiki')} + node = secure!(Page) { Page.create(:parent_id=>nodes_id(:cleanWater), :title =>'a wiki with Zena')} err node assert ! node.new_record?, 'Not a new record' - assert_nil node.errors[:node_name] #.empty? + assert_nil node.errors[:title] #.empty? end - def test_create_same_node_name_other_parent_with_cache + def test_create_same_title_other_parent_with_cache with_caching do login(:tiger) - node = secure!(Page) { Page.create(:parent_id=>nodes_id(:cleanWater), :node_name =>'wiki')} + node = secure!(Page) { Page.create(:parent_id=>nodes_id(:cleanWater), :title =>'a wiki with Zena')} err node assert ! node.new_record?, 'Not a new record' - assert_nil node.errors[:node_name] #.empty? + assert_nil node.errors[:title] #.empty? end end - def test_update_same_node_name + def test_update_same_title login(:tiger) node = secure!(Node) { nodes(:cleanWater) } - # publish so that we change node_name and check uniqueness - assert !node.update_attributes('title' => 'wiki', :v_status => Zena::Status[:pub]) - assert_equal 'has already been taken', node.errors[:node_name] + # publish so that we change title and check uniqueness + assert !node.update_attributes('title' => 'a wiki with Zena', :v_status => Zena::Status[:pub]) + assert_equal 'has already been taken', node.errors[:title] end - def test_update_same_node_name_other_parent + def test_update_same_title_other_parent login(:tiger) node = secure!(Node) { nodes(:cleanWater) } - node.node_name = 'wiki' + node.title = 'a wiki with Zena' node[:parent_id] = nodes_id(:zena) assert node.save - assert_nil node.errors[:node_name] #.empty? + assert_nil node.errors[:title] #.empty? end - def test_update_same_node_name_other_parent_with_cache + def test_update_same_title_other_parent_with_cache with_caching do login(:tiger) node = secure!(Node) { nodes(:cleanWater) } - node.node_name = 'wiki' + node.title = 'a wiki with Zena' node[:parent_id] = nodes_id(:zena) assert node.save - assert_nil node.errors[:node_name] #.empty? + assert_nil node.errors[:title] #.empty? end end @@ -72,8 +71,8 @@ def test_custom_base_path assert_equal '', bird.basepath assert_equal node[:id], bird[:parent_id] assert node.update_attributes(:custom_base => true) - assert_equal 'projects/aWikiWithZena', node.basepath + assert_equal '18/29', node.basepath bird = secure!(Node) { nodes(:bird_jpg)} - assert_equal 'projects/aWikiWithZena', bird.basepath + assert_equal '18/29', bird.basepath end end diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index 2c27f293..5ee044bd 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -5,11 +5,11 @@ class ProjectTest < Zena::Unit::TestCase def test_project_id_on_create login(:tiger) - node = secure!(Project) { Project.create(:parent_id=>nodes_id(:status), :node_name =>'SuperProject') } + node = secure!(Project) { Project.create(:parent_id=>nodes_id(:status), :title =>'SuperProject') } assert ! node.new_record?, 'Not a new record' assert_equal node[:id], node.get_project_id assert_equal nodes_id(:cleanWater), node[:project_id] - child = secure!(Page) { Page.create(:parent_id=>node[:id], :node_name =>'child')} + child = secure!(Page) { Page.create(:parent_id=>node[:id], :title =>'child')} assert ! node.new_record?, "Not a new record" assert_equal node[:id], child[:project_id] end diff --git a/test/unit/relation_proxy_test.rb b/test/unit/relation_proxy_test.rb index 1a7f4d7f..7b44b834 100644 --- a/test/unit/relation_proxy_test.rb +++ b/test/unit/relation_proxy_test.rb @@ -84,6 +84,21 @@ def test_set_tag_ids assert_equal [nodes_zip(:art)], node.set_tag_zips end + context 'On a new node' do + subject do + secure(Node) { Node.new_instance(:class => 'Contact')} + end + + should 'not fail to find node proxy' do + assert_kind_of RelationProxy, subject.rel['icon'] + end + + should 'resolve zip values without query' do + assert_nil subject.rel['icon'].other_zip + end + end # On a new node + + def test_relation_proxy node = secure!(Node) { nodes(:status) } assert node.relation_proxy('hot_for') @@ -117,7 +132,7 @@ def test_bad_attribute_raises def test_relations_for_form login(:tiger) { - Note => ["blog", "calendar", "favorite_for", "home_for", "hot_for", "icon", "reference", "reference_for", "set_tag"], + Note => ["calendar", "favorite_for", "home_for", "hot_for", "icon", "reference", "reference_for", "set_tag"], Image => ["favorite_for", "home_for", "hot_for", "icon", "icon_for", "reference", "reference_for", "set_tag"], Project => ["added_note", "collaborator", "favorite_for", "home", "home_for", "hot", "hot_for", "icon", "news", "reference", "reference_for", "set_tag"], }.each do |klass, roles| diff --git a/test/unit/remote_test.rb b/test/unit/remote_test.rb index 1dbf252e..60bb748b 100644 --- a/test/unit/remote_test.rb +++ b/test/unit/remote_test.rb @@ -29,7 +29,7 @@ class RemoteTest < Zena::Integration::TestCase assert_equal 'Banana', remote.title end end - + should 'respond to new' do node = subject.new(:title => 'Banana', :parent_id => nodes_zip(:cleanWater)) assert_difference('Node.count', 1) do @@ -47,7 +47,7 @@ class RemoteTest < Zena::Integration::TestCase end should 'find with all' do - assert_equal ["Art", "Top menu", "News list"], subject.all.map(&:title) + assert_equal ["Art", "News list", "Top menu"], subject.all.map(&:title) end should 'find with filters' do @@ -223,7 +223,7 @@ class RemoteTest < Zena::Integration::TestCase context 'paginating results' do subject do - @app.all('pages order by node_name asc', :page => 2, :per_page => 3) + @app.all('pages order by title asc', :page => 2, :per_page => 3) end should 'paginate' do @@ -250,18 +250,18 @@ class RemoteTest < Zena::Integration::TestCase should 'map missing attributes as first queries' do assert_equal 'Clean Water project', subject.icon_for.title - assert_equal ["Nice Bananas", "crocodiles", "status title", "Keeping things clean !"], subject.project.pages.map(&:title) + assert_equal ["crocodiles", "Keeping things clean !", "Nice Bananas", "status title"], subject.project.pages.map(&:title) end should 'map missing attributes as queries' do - assert_equal "Nice Bananas", subject.project.page.title - assert_equal ["Nice Bananas", - "crocodiles", + assert_equal "crocodiles", subject.project.page.title + assert_equal ["crocodiles", "it's a lake", + "Keeping things clean !", "The lake we love", + "Nice Bananas", "parc opening", "status title", - "Keeping things clean !", "water"], subject.parent.nodes.map(&:title) end end # and a found remote node @@ -297,8 +297,8 @@ class RemoteTest < Zena::Integration::TestCase subject.set_tag = [tag] subject.save end - - assert_equal subject.id, tag.first("tagged where title = 'Lion'").id + + assert_equal subject.id, tag.first("tagged where title = 'Panthera Leo Verneyi'").id end end # with a new relation diff --git a/test/unit/site_test.rb b/test/unit/site_test.rb index f2f5fef1..c1ed4d94 100644 --- a/test/unit/site_test.rb +++ b/test/unit/site_test.rb @@ -256,19 +256,19 @@ def test_rebuild_fullpath opening = secure(Node) { nodes(:opening) } cleanWater = secure(Node) { nodes(:cleanWater) } art = secure(Node) { nodes(:art) } - assert_equal 'projects/cleanWater/status', status.fullpath - assert_equal 'projects/cleanWater', status.basepath + assert_equal fullpath(:projects, :cleanWater, :status), status.fullpath + assert_equal fullpath(:projects, :cleanWater), status.basepath assert_equal false, status.custom_base - assert_equal 'projects/cleanWater/opening', opening.fullpath - assert_equal 'projects/cleanWater', opening.basepath + assert_equal fullpath(:projects, :cleanWater, :opening), opening.fullpath + assert_equal fullpath(:projects, :cleanWater), opening.basepath assert_equal false, opening.custom_base - assert_equal 'projects/cleanWater', cleanWater.fullpath - assert_equal 'projects/cleanWater', cleanWater.basepath + assert_equal fullpath(:projects, :cleanWater), cleanWater.fullpath + assert_equal fullpath(:projects, :cleanWater), cleanWater.basepath assert_equal true, cleanWater.custom_base - assert_equal 'collections/art', art.fullpath + assert_equal fullpath(:collections, :art), art.fullpath assert_equal '', art.basepath assert_equal false, art.custom_base end @@ -284,10 +284,10 @@ def test_rebuild_fullpath should 'not alter fullpath' do node = secure!(Node) { nodes(:status) } - assert_equal 'projects/cleanWater/status', node.fullpath + assert_equal fullpath(:projects, :cleanWater, :status), node.fullpath subject.clear_cache node = secure!(Node) { nodes(:status) } - assert_equal 'projects/cleanWater/status', node.fullpath + assert_equal fullpath(:projects, :cleanWater, :status), node.fullpath end end @@ -308,7 +308,12 @@ def test_rebuild_fullpath end should 'rebuild visible entries for all objects' do - assert_difference('IdxNodesMlString.count', subject.lang_list.count * Node.count(:conditions => {:site_id => subject.id})) do + assert_difference('IdxNodesMlString.count', + # title index on all nodes + subject.lang_list.count * Node.count(:conditions => {:site_id => subject.id}) + + # search index on Letter nodes + subject.lang_list.count * Node.count(:conditions => ['site_id = ? AND kpath like ?', subject.id, 'NNL%']) + ) do subject.rebuild_index end end @@ -323,4 +328,10 @@ def test_rebuild_fullpath 'en'=>'status title'], ml_indices end end + + + private + def fullpath(*args) + args.map {|sym| nodes_zip(sym).to_s}.join('/') + end end diff --git a/test/unit/template_test.rb b/test/unit/template_test.rb index 6ee8310c..ae4cb929 100644 --- a/test/unit/template_test.rb +++ b/test/unit/template_test.rb @@ -21,8 +21,8 @@ def self.should_set_target_class_mode_and_format assert_equal 'Project', subject.target_klass end - should 'remove extension from node_name' do - assert_equal 'Project-collab-xml', subject.node_name + should 'remove extension from title' do + assert_equal 'Project-collab-xml', subject.title end should 'set extension to zafu' do @@ -53,9 +53,9 @@ def self.should_set_target_class_mode_and_format context 'creating a template' do - context 'with a capitalized node_name' do + context 'with a capitalized title' do subject do - secure(Template) { Template.create(:parent_id => nodes_id(:default), :node_name => 'Project.zafu') } + secure(Template) { Template.create(:parent_id => nodes_id(:default), :title => 'Project.zafu') } end should 'create a new Template' do @@ -70,7 +70,7 @@ def self.should_set_target_class_mode_and_format end end - should 'use node_name as target class' do + should 'use title as target class' do assert_equal 'Project', subject.target_klass end @@ -85,7 +85,7 @@ def self.should_set_target_class_mode_and_format context 'with minimal arguments' do subject do - secure(Document) { Document.create(:parent_id => nodes_id(:default), :node_name => 'foo.zafu') } + secure(Document) { Document.create(:parent_id => nodes_id(:default), :title => 'foo.zafu') } end should 'create a new Template' do @@ -105,15 +105,14 @@ def self.should_set_target_class_mode_and_format assert_equal 'text/zafu', subject.content_type end - should 'remove extension from node_name' do + should 'remove extension from title' do assert_equal 'foo', subject.title - assert_equal 'foo', subject.node_name end end context 'with a blank mode' do subject do - secure(Document) { Document.create(:parent_id => nodes_id(:default), :node_name => 'super.zafu', :mode => '') } + secure(Document) { Document.create(:parent_id => nodes_id(:default), :title => 'super.zafu', :mode => '') } end should 'not complain' do @@ -122,43 +121,35 @@ def self.should_set_target_class_mode_and_format end end # with a blank mode - context 'with a blank node_name' do + context 'with a blank title' do subject do secure(Template) { Template.create(:parent_id=>nodes_id(:default), :target_klass => 'Section') } end - should 'use target_klass as node_name' do + should 'use target_klass as title' do assert !subject.new_record? - assert_equal 'Section', subject.node_name + assert_equal 'Section', subject.title end - end # with a blank node_name + end # with a blank title context 'with a format' do subject do - secure(Template) { Template.create(:parent_id=>nodes_id(:default), :node_name => 'Node-tree', :format => 'xml') } + secure(Template) { Template.create(:parent_id=>nodes_id(:default), :title => 'Node-tree', :format => 'xml') } end - should 'use format in node_name' do + should 'use format in title' do assert !subject.new_record? - assert_equal 'Node-tree-xml', subject.node_name + assert_equal 'Node-tree-xml', subject.title end - end # with a blank node_name + end # with a blank title context 'with class format and mode in title' do subject do secure!(Document) { Document.create(:parent_id => nodes_id(:default), :title => 'Project-collab-xml.zafu')} - end # with class format and mode in title - - should_set_target_class_mode_and_format - end - - context 'with class format and mode in node_name' do - subject do - secure!(Document) { Document.create(:parent_id => nodes_id(:default), :node_name => 'Project-collab-xml.zafu')} end should_set_target_class_mode_and_format - end # with class format and mode in node_name + end # with class format and mode in title context 'with a file' do subject do @@ -173,14 +164,14 @@ def self.should_set_target_class_mode_and_format assert_kind_of Template, subject end - should 'use title for node_name' do - assert_equal 'skiny', subject.node_name + should 'use title for title' do + assert_equal 'skiny', subject.title end end # with a file context 'with an html extension' do subject do - secure!(Document) { Document.create(:parent_id => nodes_id(:default), :node_name => 'sub.html')} + secure!(Document) { Document.create(:parent_id => nodes_id(:default), :title => 'sub.html')} end should 'create a Template' do @@ -191,7 +182,7 @@ def self.should_set_target_class_mode_and_format context 'not in a Skin section' do subject do - secure!(Document) { Document.create(:parent_id => nodes_id(:cleanWater), :node_name => 'super.zafu')} + secure!(Document) { Document.create(:parent_id => nodes_id(:cleanWater), :title => 'super.zafu')} end should 'return an error on parent' do @@ -282,92 +273,92 @@ def self.should_set_target_class_mode_and_format end # A visitor with drive access - def test_set_by_node_name_without_mode + def test_set_by_title_without_mode login(:tiger) - doc = secure!(Document) { Document.create(:parent_id=>nodes_id(:default), :node_name => 'Project--xml.zafu')} + doc = secure!(Document) { Document.create(:parent_id=>nodes_id(:default), :title => 'Project--xml.zafu')} assert_kind_of Template, doc assert !doc.new_record?, "Saved" assert_nil doc.mode assert_equal 'xml', doc.format assert_equal 'NPP', doc.tkpath assert_equal 'Project', doc.target_klass - assert_equal 'Project--xml', doc.node_name + assert_equal 'Project--xml', doc.title end - def test_set_blank_node_name + def test_set_blank_title login(:tiger) - doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), 'mode' => 'collab', 'target_klass' => 'Page', 'node_name' => '', 'format' => '')} + doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), 'mode' => 'collab', 'target_klass' => 'Page', 'title' => '', 'format' => '')} assert_kind_of Template, doc assert !doc.new_record?, "Saved" assert_equal 'collab', doc.mode assert_equal 'html', doc.format assert_equal 'NP', doc.tkpath assert_equal 'Page', doc.target_klass - assert_equal 'Page-collab', doc.node_name + assert_equal 'Page-collab', doc.title end - def test_change_node_name + def test_change_title login(:tiger) - doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), :node_name => 'Project-collab-xml.zafu')} + doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), :title => 'Project-collab-xml.zafu')} assert_kind_of Template, doc assert !doc.new_record?, "Saved" doc = secure!(Node) { Node.find(doc[:id]) } # reload - assert doc.update_attributes(:node_name => "Page-super") + assert doc.update_attributes(:title => "Page-super") assert_equal 'super', doc.mode assert_equal 'html', doc.format assert_equal 'NP', doc.tkpath assert_equal 'Page', doc.target_klass - assert_equal 'Page-super', doc.node_name + assert_equal 'Page-super', doc.title end def test_update_title_blank_mode login(:tiger) - doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), :node_name => 'Project-collab-xml.zafu')} + doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), :title => 'Project-collab-xml.zafu')} assert_kind_of Template, doc assert !doc.new_record?, "Saved" assert doc.update_attributes(:mode => "", :title=> "Project-collab-xml") assert_nil doc.mode assert_equal 'xml', doc.format - assert_equal 'Project--xml', doc.node_name + assert_equal 'Project--xml', doc.title assert_equal 'Project--xml', doc.title end def test_update_blank_mode login(:tiger) - doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), :node_name => 'Project-collab-xml.zafu')} + doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), :title => 'Project-collab-xml.zafu')} assert_kind_of Template, doc assert !doc.new_record?, "Saved" assert_equal 'collab', doc.mode doc = secure!(Node) { Node.find(doc[:id]) } # reload - assert doc.update_attributes(:mode => "", :node_name => "Project-collab-xml") # name does not change, only mode is updated + assert doc.update_attributes(:mode => "", :title => "Project-collab-xml") # name does not change, only mode is updated assert_nil doc.mode assert_equal 'xml', doc.format assert_equal 'Project', doc.target_klass - assert_equal 'Project--xml', doc.node_name + assert_equal 'Project--xml', doc.title assert_equal 'Project--xml', doc.title end - def test_cannot_change_node_name_not_master + def test_cannot_change_title_not_master login(:tiger) - doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), :node_name => 'Project-collab-xml.zafu')} + doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), :title => 'Project-collab-xml.zafu')} assert_kind_of Template, doc assert !doc.new_record?, "Saved" doc = secure!(Node) { Node.find(doc[:id]) } # reload - assert doc.update_attributes(:node_name => "simple-thing", :v_status => Zena::Status[:pub]) + assert doc.update_attributes(:title => "simple-thing", :v_status => Zena::Status[:pub]) assert_nil doc.target_klass assert_nil doc.mode assert_nil doc.format assert_nil doc.tkpath - assert_equal 'Project-collab-xml', doc.node_name + assert_equal 'simple-thing', doc.title end - def test_set_node_name_no_extension + def test_set_title_no_extension login(:tiger) - doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), :node_name => 'Project-collab')} + doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), :title => 'Project-collab')} assert_kind_of Template, doc assert !doc.new_record?, "Saved" - assert_equal 'Project-collab', doc.node_name + assert_equal 'Project-collab', doc.title assert_equal 'collab', doc.mode assert_equal 'html', doc.format assert_equal 'NPP', doc.tkpath @@ -376,58 +367,58 @@ def test_set_node_name_no_extension def test_set_target_klass login(:tiger) - doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), :node_name => 'Spider-man-xml', + doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), :title => 'Spider-man-xml', :target_klass => 'Page', :format => 'ical')} assert_kind_of Template, doc assert !doc.new_record?, "Saved" - assert_equal 'Page-man-ical', doc.node_name + assert_equal 'Page-man-ical', doc.title assert_equal 'man', doc.mode assert_equal 'ical', doc.format assert_equal 'NP', doc.tkpath assert_equal 'Page', doc.target_klass end - def test_set_blank_node_name_not_unique + def test_set_blank_title_not_unique login(:tiger) - doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), 'mode' => '', 'target_klass' => 'Contact', 'node_name' => '', 'format' => '')} + doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), 'mode' => '', 'target_klass' => 'Contact', 'title' => '', 'format' => '')} assert_kind_of Template, doc assert !doc.new_record?, "Saved" assert_nil doc.mode assert_equal 'html', doc.format assert_equal 'NRC', doc.tkpath assert_equal 'Contact', doc.target_klass - assert_equal 'Contact', doc.node_name - doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), 'mode' => '', 'target_klass' => 'Contact', 'node_name' => '', 'format' => 'vcard')} + assert_equal 'Contact', doc.title + doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), 'mode' => '', 'target_klass' => 'Contact', 'title' => '', 'format' => 'vcard')} assert_kind_of Template, doc assert !doc.new_record?, "Saved" assert_nil doc.mode assert_equal 'vcard', doc.format assert_equal 'NRC', doc.tkpath assert_equal 'Contact', doc.target_klass - assert_equal 'Contact--vcard', doc.node_name + assert_equal 'Contact--vcard', doc.title end - def test_update_format_updates_node_name + def test_update_format_updates_title login(:lion) - doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), 'mode' => '', 'target_klass' => 'Contact', 'node_name' => '', 'format' => 'vcard')} + doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), 'mode' => '', 'target_klass' => 'Contact', 'title' => '', 'format' => 'vcard')} assert_kind_of Template, doc assert !doc.new_record?, "Saved" assert_nil doc.mode assert_equal 'vcard', doc.format assert_equal 'NRC', doc.tkpath assert_equal 'Contact', doc.target_klass - assert_equal 'Contact--vcard', doc.node_name + assert_equal 'Contact--vcard', doc.title assert doc.update_attributes(:format => 'vcf') assert_equal 'vcf', doc.format assert_equal 'NRC', doc.tkpath assert_equal 'Contact', doc.target_klass - assert_equal 'Contact--vcf', doc.node_name + assert_equal 'Contact--vcf', doc.title end def test_default_text_Node login(:lion) - doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), 'target_klass' => 'Node', 'node_name' => '')} + doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), 'target_klass' => 'Node', 'title' => '')} assert_kind_of Template, doc assert !doc.new_record?, "Saved" assert_match %r{xmlns.*www\.w3\.org.*body}m, doc.text @@ -435,7 +426,7 @@ def test_default_text_Node def test_default_text_other_format login(:lion) - doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), 'format' => 'vcard', 'target_klass' => 'Node', 'node_name' => '')} + doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), 'format' => 'vcard', 'target_klass' => 'Node', 'title' => '')} assert_kind_of Template, doc assert !doc.new_record?, "Saved" assert doc.text.blank? diff --git a/test/unit/text_document_test.rb b/test/unit/text_document_test.rb index 19256130..b1032ea2 100644 --- a/test/unit/text_document_test.rb +++ b/test/unit/text_document_test.rb @@ -26,7 +26,7 @@ class TextDocumentTest < Zena::Unit::TestCase body { font-size:10px; } #header { background:url('bird.jpg') } #pv { background:url('bird_pv.jpg') } - #footer { background:url('/projects/wiki/flower.jpg') } + #footer { background:url('/projects list/a wiki with Zena/flower.jpg') } #no_stamp { background:url('/en/image30_pv.jpg?100001001345') } END_CSS @@ -48,24 +48,24 @@ class TextDocumentTest < Zena::Unit::TestCase end end # in a folder with an image end # on a css text_document - + context 'creating a text document' do context 'with a content_type' do subject do secure!(TextDocument) { TextDocument.create( - :node_name => "yoba", + :title => "yoba", :parent_id => nodes_id(:wiki), :text => "#header { color:red; }\n#footer { color:blue; }", - :content_type => 'text/css') + :content_type => 'text/css') } end - + should 'create a new TextDocument' do assert_difference('TextDocument.count', 1) do subject end end - + should 'set extension from content_type' do assert_equal 'css', subject.ext end @@ -75,11 +75,11 @@ class TextDocumentTest < Zena::Unit::TestCase def test_create_simplest login(:tiger) - doc = secure!(Document) { Document.create(:parent_id=>nodes_id(:cleanWater), :node_name => 'skiny')} + doc = secure!(Document) { Document.create(:parent_id=>nodes_id(:cleanWater), :title => 'skiny')} assert_equal TextDocument, doc.class assert !doc.new_record?, "Not a new record" assert_equal 0, doc.size - doc = secure!(Document) { Document.create(:parent_id=>nodes_id(:cleanWater), :node_name => 'medium', :text=>"12345678901234567890")} + doc = secure!(Document) { Document.create(:parent_id=>nodes_id(:cleanWater), :title => 'medium', :text=>"12345678901234567890")} assert_equal TextDocument, doc.class assert !doc.new_record?, "Not a new record" assert_equal 20, doc.size @@ -91,6 +91,7 @@ def test_create_with_file file = uploaded_text('some.txt') doc = secure!(Document) { Document.create( :parent_id => nodes_id(:cleanWater), :file => file ) } + assert_equal TextDocument, doc.class # reload doc = secure!(Document) { Document.find(doc[:id])} @@ -127,8 +128,8 @@ def test_parse_assets body { font-size:10px; behavior:url("/stylesheets/csshover2.htc"); } #header { background:url('bird.jpg') } #pv { background:url('bird_pv.jpg') } - #footer { background:url('/projects/wiki/flower.jpg') } - #back { background:url('../../projects/wiki/flower.jpg') } + #footer { background:url('/projects list/a wiki with Zena/flower.jpg') } + #back { background:url('../../projects list/a wiki with Zena/flower.jpg') } #no_stamp { background:url('/en/image30_pv.jpg') } END_CSS node.text = start.dup @@ -154,8 +155,8 @@ def test_parse_assets body { font-size:10px; behavior:url("/stylesheets/csshover2.htc"); } #header { background:url('bird.jpg') } #pv { background:url('bird_pv.jpg') } - #footer { background:url('/projects/wiki/flower.jpg') } - #back { background:url('/projects/wiki/flower.jpg') } + #footer { background:url('/projects list/a wiki with Zena/flower.jpg') } + #back { background:url('/projects list/a wiki with Zena/flower.jpg') } #no_stamp { background:url('bird_pv.jpg') } END_CSS assert_equal unparsed, text @@ -169,13 +170,13 @@ def test_parse_assets_with_underscore bird = secure!(Node) { nodes(:bird_jpg)} b_at = bird.updated_at # We need to publish so that the title is used for fullpath - assert bird.update_attributes(:parent_id => node[:parent_id], :title => "greenBird", :v_status => Zena::Status[:pub]) + assert bird.update_attributes(:parent_id => node[:parent_id], :title => "green_bird", :v_status => Zena::Status[:pub]) Zena::Db.set_attribute(bird, :updated_at, b_at) start =<<-END_CSS body { font-size:10px; } #header { background:url('green_bird.jpg') } #tiny { background:url('green_bird_tiny.jpg') } - #footer { background:url('/projects/wiki/flower.jpg') } + #footer { background:url('/projects list/a wiki with Zena/flower.jpg') } END_CSS node.text = start.dup # dummy controller diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 335b0b5f..aca46a15 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -303,14 +303,14 @@ def test_tz def test_redactions login(:tiger) - assert_equal ['opening'], visitor.redactions.map {|r| r.node.node_name} + assert_equal ['super ouverture'], visitor.redactions.map {|r| r.node.title} node = secure(Page) { Page.create(:title => 'hello', :parent_id => nodes_id(:projects)) } node.propose - assert_equal ['hello'], visitor.to_publish.map {|r| r.node.node_name} - assert_equal ['hello'], visitor.proposed.map {|r| r.node.node_name} + assert_equal ['hello'], visitor.to_publish.map {|r| r.node.title} + assert_equal ['hello'], visitor.proposed.map {|r| r.node.title} login(:lion) - assert_equal ['hello'], visitor.to_publish.map {|r| r.node.node_name} + assert_equal ['hello'], visitor.to_publish.map {|r| r.node.title} end context 'Creating a new user' do diff --git a/test/unit/version_test.rb b/test/unit/version_test.rb index bf8525c1..199dffcf 100644 --- a/test/unit/version_test.rb +++ b/test/unit/version_test.rb @@ -58,7 +58,7 @@ class VersionTest < Zena::Unit::TestCase context 'on node creation' do context 'setting an invalid v_lang' do setup do - @node = secure!(Page) { Page.create(:v_lang => 'io', :parent_id => nodes_id(:status), :node_name => 'hello')} + @node = secure!(Page) { Page.create(:v_lang => 'io', :parent_id => nodes_id(:status), :title => 'hello')} end should 'not create record if lang is not allowed' do @@ -72,7 +72,7 @@ class VersionTest < Zena::Unit::TestCase context 'setting a valid v_lang' do subject do - @node = secure!(Page) { Page.create(:v_lang => 'de', :parent_id => nodes_id(:status), :node_name => 'hello')} + @node = secure!(Page) { Page.create(:v_lang => 'de', :parent_id => nodes_id(:status), :title => 'hello')} end should 'create a single version' do diff --git a/test/unit/workflow_test.rb b/test/unit/workflow_test.rb index e2dba7c7..3479f554 100644 --- a/test/unit/workflow_test.rb +++ b/test/unit/workflow_test.rb @@ -4,7 +4,7 @@ class WorkflowTest < Zena::Unit::TestCase def defaults - { :node_name => 'hello', + { :title => 'hello', :parent_id => nodes_id(:zena) } end @@ -790,7 +790,7 @@ def test_unpublish_all def test_can_man_cannot_publish login(:ant) - node = secure!(Note) { Note.create(:node_name => 'hello', :parent_id=>nodes_id(:cleanWater)) } + node = secure!(Note) { Note.create(:title => 'hello', :parent_id=>nodes_id(:cleanWater)) } assert !node.new_record? assert node.can_drive?, "Can drive" assert node.can_drive?, "Can manage" @@ -815,7 +815,7 @@ def test_can_unpublish_version node = secure!(Node) { nodes(:lion) } pub_version = node.version assert node.can_unpublish? - assert node.update_attributes(:title=>'leopard') + assert node.update_attributes(:name => 'Leopard') assert_equal Zena::Status[:red], node.version.status assert !node.can_unpublish? end diff --git a/test/unit/zena/acts/secure_test.rb b/test/unit/zena/acts/secure_test.rb index f877e34a..294d6863 100644 --- a/test/unit/zena/acts/secure_test.rb +++ b/test/unit/zena/acts/secure_test.rb @@ -6,7 +6,7 @@ def create_simple_note(opts={}) login(opts[:login] || :ant) # create new node attrs = { - :node_name => 'hello', + :title => 'hello', :parent_id => nodes_id(:cleanWater) }.merge(opts[:node] || {}) @@ -293,13 +293,13 @@ def create_simple_note(opts={}) should 'be allowed to drive' do node = secure!(Node) { nodes(:bananas) } assert node.can_drive? - assert node.update_attributes(:node_name => 'NamWa') + assert node.update_attributes(:log_at => Time.now) end end # A visitor in the read and drive groups def defaults - { :node_name => 'hello', + { :title => 'hello', :parent_id => nodes_id(:zena) } end @@ -403,7 +403,7 @@ def defaults end should 'not be allowed to create circular references' do - # status is a child of projects/cleanWater + # status is a child of projects-list/Clean-Water-project node = secure!(Node) { nodes(:projects) } assert !node.update_attributes(:parent_id => nodes_id(:status)) assert_equal 'circular reference', node.errors[:parent_id] @@ -530,12 +530,6 @@ def defaults assert_equal 'You do not have the rights to do this.', @node.errors[:base] end - should 'not be allowed to change node_name' do - @node.node_name = 'slitherin' - assert !@node.save - assert_equal 'You do not have the rights to do this.', @node.errors[:base] - end - should 'not be allowed to change dates' do @node.event_at = Time.now assert !@node.save @@ -821,7 +815,7 @@ def defaults versions_id(:status_en), versions_id(:strange_en_red), versions_id(:ant_en)]], - :order => 'node_name ASC') + :order => 'zip ASC') end context 'with secure' do @@ -856,7 +850,7 @@ def defaults context 'Using clean_options to prepare queries' do should 'remove anything that might disturb ActiveRecord' do - assert_equal Hash[:conditions => ['id = ?', 3], :order => 'node_name ASC'], Node.clean_options(:conditions => ['id = ?', 3], :funky => 'bad', :order => 'node_name ASC', :from => 'users') + assert_equal Hash[:conditions => ['id = ?', 3], :order => 'zip ASC'], Node.clean_options(:conditions => ['id = ?', 3], :funky => 'bad', :order => 'zip ASC', :from => 'users') end end # Using clean_options to prepare queries diff --git a/test/unit/zena/db_test.rb b/test/unit/zena/db_test.rb index 03925a86..4ea06403 100644 --- a/test/unit/zena/db_test.rb +++ b/test/unit/zena/db_test.rb @@ -25,7 +25,7 @@ def test_next_zip end def test_insensitive_find - assert_equal nodes_zip(:status), secure(Node) { Zena::Db.insensitive_find(Node, :first, :node_name => 'sTatuS')}.zip + assert_equal nodes_zip(:status), secure(Node) { Zena::Db.insensitive_find(Node, :first, :_id => 'sTatuS')}.zip end def test_next_zip_rollback @@ -36,16 +36,16 @@ def test_next_zip_rollback end def test_fetch_row - assert_equal "water", Zena::Db.fetch_attribute("SELECT node_name FROM nodes WHERE id = #{nodes_id(:water_pdf)}") - assert_nil Zena::Db.fetch_attribute("SELECT node_name FROM nodes WHERE #{Zena::Db::FALSE}") + assert_equal "water_pdf", Zena::Db.fetch_attribute("SELECT _id FROM nodes WHERE id = #{nodes_id(:water_pdf)}") + assert_nil Zena::Db.fetch_attribute("SELECT _id FROM nodes WHERE #{Zena::Db::FALSE}") end def test_fetch_attributes - assert_equal [{"node_name"=>"secret", "zip"=>"19"}, - {"node_name"=>"status", "zip"=>"22"}, - {"node_name"=>"strange", "zip"=>"36"}, - {"node_name"=>"skins", "zip"=>"51"}, - {"node_name"=>"style", "zip"=>"53"}], Zena::Db.fetch_attributes(['zip','node_name'], 'nodes', "node_name like 's%' and site_id = #{sites_id(:zena)} ORDER BY zip") + assert_equal [{"_id"=>"secret", "zip"=>"19"}, + {"_id"=>"status", "zip"=>"22"}, + {"_id"=>"strange", "zip"=>"36"}, + {"_id"=>"skins", "zip"=>"51"}, + {"_id"=>"style_css", "zip"=>"53"}], Zena::Db.fetch_attributes(['zip','_id'], 'nodes', "_id like 's%' and site_id = #{sites_id(:zena)} ORDER BY zip") end def test_migrated_once @@ -60,25 +60,25 @@ def test_migrated_once should 'not change updated_at date' do old_updated_at = @node.updated_at - Zena::Db.set_attribute(@node, :node_name, 'flop') + Zena::Db.set_attribute(@node, :_id, 'flop') @node = secure!(Node) { nodes(:status) } # reload assert_equal old_updated_at, @node.updated_at end should 'set attribute in node' do - Zena::Db.set_attribute(@node, :node_name, 'flop') - assert_equal 'flop', @node.node_name + Zena::Db.set_attribute(@node, :_id, 'flop') + assert_equal 'flop', @node._id end should 'not mark as dirty' do - Zena::Db.set_attribute(@node, :node_name, 'flop') + Zena::Db.set_attribute(@node, :_id, 'flop') assert !@node.changed? end should 'set attribute in db' do - Zena::Db.set_attribute(@node, :node_name, 'flop') + Zena::Db.set_attribute(@node, :_id, 'flop') @node = secure!(Node) { nodes(:status) } # reload - assert_equal 'flop', @node.node_name + assert_equal 'flop', @node._id end should 'set a time' do diff --git a/test/unit/zena/use/ancestry_test.rb b/test/unit/zena/use/ancestry_test.rb new file mode 100644 index 00000000..be0d7835 --- /dev/null +++ b/test/unit/zena/use/ancestry_test.rb @@ -0,0 +1,198 @@ +require 'test_helper' + +class AncestryTest < Zena::Unit::TestCase + + context 'On an object with a fullpath' do + setup do + login(:ant) + end + + subject do + secure(Node) { nodes(:status) } + end + + context 'on fullpath_as_title' do + should 'return path with titles' do + assert_equal ["projects list", "Clean Water project", "Etat des travaux"], subject.fullpath_as_title + end + + should 'return double dot from rel_path' do + assert_equal '(../Clean Water project/Etat des travaux)', subject.pseudo_id(nodes(:wiki), :relative_path) + end + end # on fullpath_as_title + + context 'on short_path' do + should 'return last two parent titles' do + assert_equal ["..", "Clean Water project", "Etat des travaux"], subject.short_path + end + end # on short_path + + context 'and custom_base set' do + subject do + secure(Node) { nodes(:cleanWater) } + end + + should 'set basepath' do + assert_equal fullpath(:projects, :cleanWater), subject.basepath + end + + should 'set basepath in children' do + assert_equal fullpath(:projects, :cleanWater), nodes(:status).basepath + end + end # and custom_base set + + context 'with a secret parent' do + subject do + secure(Node) { nodes(:talk) } + end + + should 'replace parent by star on fullpath_as_title' do + assert_equal ["projects list", "*", "Talk"], subject.fullpath_as_title + end + + should 'replace parent by star on short_path' do + assert_equal ["..", "*", "Talk"], subject.short_path + end + end # with a secret parent + + end # On an object with a fullpath + + context 'Moving an object' do + setup do + login(:lion) + subject.update_attributes(:parent_id => nodes_id(:lion)) + end + + subject do + secure(Node) { nodes(:secret) } + end + + should 'rebuild fullpath in new parent' do + assert_equal fullpath(:people, :lion, :secret), subject.fullpath + end + + should 'rebuild children fullpath' do + assert_equal fullpath(:people, :lion, :secret, :talk), nodes(:talk).fullpath + assert_equal fullpath(:people, :lion, :secret, :proposition), nodes(:proposition).fullpath + end + + context 'with custom_base set' do + subject do + secure(Node) { nodes(:cleanWater) } + end + + should 'rebuild basepath in new parent' do + assert_equal fullpath(:people, :lion, :cleanWater), subject.basepath + end + + should 'rebuild children basepath' do + assert_equal fullpath(:people, :lion, :cleanWater), nodes(:status).basepath + end + end # with custom_base set + + + end # Moving an object + + context 'Finding an object from a path' do + setup do + login(:lion) + end + + subject do + secure(Node) { Node.find_by_path('projects list/Secret/Talk')} + end + + should 'find object' do + assert_equal nodes_id(:talk), subject.id + end + + context 'without access to secret parent' do + setup do + login(:anon) + end + + should 'not find object' do + assert_nil subject + end + end # without access to secret parent + + context 'without access to the object' do + setup do + login(:anon) + end + + subject do + secure(Node) { Node.find_by_path('projects list/Secret') } + end + + should 'not find object' do + assert_nil subject + end + end # without access to the object + + end # Finding an object + + context 'A node with ancestors' do + subject do + secure(Node) { nodes(:cleanWater) } + end + + should 'return list of ancestors on ancestors' do + assert_equal nodes_zip(:zena, :projects), subject.ancestors.map(&:zip) + end + + context 'with a secret parent' do + subject do + secure(Node) { nodes(:talk) } + end + + should 'skip secret parent in ancestors' do + assert_equal nodes_zip(:zena, :projects), subject.ancestors.map(&:zip) + end + end # with a secret parent + end # A node with ancestors + + context 'A visitor with write access' do + setup do + login(:tiger) + end + + context 'creating a node' do + subject do + secure(Node) { Node.create(:parent_id => nodes_id(:projects), :title => 'Kyma')} + end + + should 'build fullpath' do + assert_equal [nodes_zip(:projects), subject.zip].join('/'), subject.fullpath + end + + should 'build basepath' do + err subject + assert_equal [nodes_zip(:projects), subject.zip].join('/'), subject.fullpath + end + end # creating a node + + end # A visitor with write access + + + context 'A node in an ancestry loop' do + setup do + login(:ant) + Node.connection.execute "UPDATE nodes SET parent_id = #{nodes_id(:status)} WHERE id = #{nodes_id(:cleanWater)}" + end + + subject do + secure(Node) { nodes(:lake_jpg) } + end + + should 'raise Invalid record on site rebuild_fullpath' do + assert_raise(Zena::InvalidRecord) { current_site.rebuild_fullpath(subject.parent_id) } + end + end # A node in an ancestry loop + + + private + def fullpath(*args) + args.map {|sym| nodes_zip(sym).to_s}.join('/') + end +end \ No newline at end of file diff --git a/test/unit/zena/use/calendar_test.rb b/test/unit/zena/use/calendar_test.rb index c025c531..b3b44ba2 100644 --- a/test/unit/zena/use/calendar_test.rb +++ b/test/unit/zena/use/calendar_test.rb @@ -14,15 +14,15 @@ def test_cal_weeks start_date, end_date = cal_start_end(Time.utc(2006,3,18), :month) assert_equal Date.civil(2006,02,26), start_date assert_equal Date.civil(2006,04,01), end_date - secure!(Note) { Note.create(:parent_id => nodes_id(:zena), :node_name => 'foobar', :event_at => Time.utc(2006,03,20))} + secure!(Note) { Note.create(:parent_id => nodes_id(:zena), :title => 'foobar', :event_at => Time.utc(2006,03,20))} nodes = secure!(Note) { Note.find(:all, :conditions => ["nodes.event_at >= ? AND nodes.event_at <= ?", start_date, end_date])} res = cal_weeks('event_at', nodes, start_date, end_date) do |week, hash| weeks << week event_hash = hash end assert_equal ["2006-03-18 00", "2006-03-20 00"], event_hash.keys.sort - assert_equal ['opening'], event_hash["2006-03-18 00"].map{|r| r.node_name} - assert_equal ['foobar'], event_hash["2006-03-20 00"].map{|r| r.node_name} + assert_equal ['parc opening'], event_hash["2006-03-18 00"].map{|r| r.title} + assert_equal ['foobar'], event_hash["2006-03-20 00"].map{|r| r.title} end def test_cal_weeks_hours @@ -34,16 +34,16 @@ def test_cal_weeks_hours start_date, end_date = cal_start_end(Time.utc(2006,3,18), :month) assert_equal Date.civil(2006,02,26), start_date assert_equal Date.civil(2006,04,01), end_date - secure!(Note) { Note.create(:parent_id => nodes_id(:zena), :node_name => 'morning', :event_at => Time.utc(2006,03,20,9))} - secure!(Note) { Note.create(:parent_id => nodes_id(:zena), :node_name => 'afternoon', :event_at => Time.utc(2006,03,20,14))} + secure!(Note) { Note.create(:parent_id => nodes_id(:zena), :title => 'morning', :event_at => Time.utc(2006,03,20,9))} + secure!(Note) { Note.create(:parent_id => nodes_id(:zena), :title => 'afternoon', :event_at => Time.utc(2006,03,20,14))} nodes = secure!(Note) { Note.find(:all, :conditions => ["nodes.event_at >= ? AND nodes.event_at <= ?", start_date, end_date])} res = cal_weeks('event_at', nodes, start_date, end_date, hours) do |week, hash| weeks << week event_hash = hash end assert_equal ["2006-03-18 12", "2006-03-20 00", "2006-03-20 12"], event_hash.keys.sort - assert_equal ['opening'], event_hash["2006-03-18 12"].map{|r| r.node_name} - assert_equal ['morning'], event_hash["2006-03-20 00"].map{|r| r.node_name} - assert_equal ['afternoon'], event_hash["2006-03-20 12"].map{|r| r.node_name} + assert_equal ['parc opening'], event_hash["2006-03-18 12"].map{|r| r.title} + assert_equal ['morning'], event_hash["2006-03-20 00"].map{|r| r.title} + assert_equal ['afternoon'], event_hash["2006-03-20 12"].map{|r| r.title} end end \ No newline at end of file diff --git a/test/unit/zena/use/html_tags_test.rb b/test/unit/zena/use/html_tags_test.rb index c21a546a..0e272c14 100644 --- a/test/unit/zena/use/html_tags_test.rb +++ b/test/unit/zena/use/html_tags_test.rb @@ -218,7 +218,7 @@ def test_img_tag_other def test_alt_with_apos doc = secure!(Node) { nodes(:lake_jpg) } - assert_equal "<img src='/en/projects/cleanWater/image24.jpg?1144713600' width='600' height='440' alt='it's a lake' class='full'/>", img_tag(doc) + assert_equal "<img src='/en/projects-list/Clean-Water-project/image24.jpg?1144713600' width='600' height='440' alt='it's a lake' class='full'/>", img_tag(doc) end def test_select_id diff --git a/test/unit/zena/use/i18n_test.rb b/test/unit/zena/use/i18n_test.rb index e14da7ae..f820ea3d 100644 --- a/test/unit/zena/use/i18n_test.rb +++ b/test/unit/zena/use/i18n_test.rb @@ -27,7 +27,7 @@ class I18nTest < Zena::View::TestCase end should 'change lang with lang param' do - assert_match %r{href=.*/oo/projects/cleanWater\?lang=.*fr.*}, lang_links + assert_match %r{href=.*/oo/projects-list/Clean-Water-project\?lang=.*fr.*}, lang_links end end # on lang_links end # With a logged in user @@ -57,7 +57,7 @@ class I18nTest < Zena::View::TestCase end should 'change lang with prefix' do - assert_match %r{href=.*/fr/projects/cleanWater.*fr.*}, lang_links + assert_match %r{href=.*/fr/projects-list/Clean-Water-project.*fr.*}, lang_links end end # on lang_links end # Without a login diff --git a/test/unit/zena/use/ml_index_test.rb b/test/unit/zena/use/ml_index_test.rb index a76d9d74..5fef8298 100644 --- a/test/unit/zena/use/ml_index_test.rb +++ b/test/unit/zena/use/ml_index_test.rb @@ -51,7 +51,17 @@ class MLIndexTest < Zena::Unit::TestCase subject do secure(Node) { nodes(:news) } end - + + should 'rebuild index for current lang' do + assert_difference('IdxNodesMlString.count', 0) do + subject.update_attributes(:title => 'fabula', :v_status => Zena::Status[:pub]) + end + idx = IdxNodesMlString.find(:first, + :conditions => {:node_id => subject.id, :lang => visitor.lang, :key => 'title'} + ) + assert_equal 'fabula', idx.value + end + context 'with std indices removed' do setup do IdxNodesString.connection.execute 'DELETE from idx_nodes_strings' @@ -77,6 +87,34 @@ class MLIndexTest < Zena::Unit::TestCase end end end # with multi lingual indices removed + + context 'in a class with evaluated properties' do + subject do + secure(Node) { nodes(:ant) } + end + + should 'index commputed value' do + assert subject.update_attributes(:first_name => 'Superman') + assert_equal 'Superman Invicta', subject.title + idx = IdxNodesMlString.find(:first, :conditions => ["lang = ? AND `key` = ? AND node_id = ?", visitor.lang, 'title', subject.id]) + assert_equal 'Superman Invicta', idx.value + end + + context 'with changes overwritten by computed values' do + should 'not touch index' do + assert_difference('IdxNodesMlString.count', 0) do + subject.update_attributes(:title => 'fabula', :v_status => Zena::Status[:pub]) + end + idx = IdxNodesMlString.find(:first, + :conditions => {:node_id => subject.id, :lang => visitor.lang, :key => 'title'} + ) + + assert_equal 'Solenopsis Invicta', idx.value + end + end # with changes overwritten by computed values + + end # in a class with evaluated properties + end # updating a node context 'on a node' do @@ -105,17 +143,17 @@ class MLIndexTest < Zena::Unit::TestCase 'en'=>'status title'], ml_indices end - context 'with idx_text_high defined for vclass' do + context 'with prop_eval defined for vclass' do subject do secure(Node) { nodes(:letter) } end - should 'set title index from idx_text_high' do + should 'set index from computed value' do subject.rebuild_index! - ml_indices = Hash[*IdxNodesMlString.find(:all, :conditions => {:node_id => subject.id, :key => 'title'}).map {|r| [r.lang, r.value]}.flatten] + ml_indices = Hash[*IdxNodesMlString.find(:all, :conditions => {:node_id => subject.id, :key => 'search'}).map {|r| [r.lang, r.value]}.flatten] assert_equal Hash[ - 'de'=>'zena enhancements paper:Kraft', 'fr'=>'zena enhancements paper:Kraft', + 'de'=>'zena enhancements paper:Kraft', 'es'=>'zena enhancements paper:Kraft', 'en'=>'zena enhancements paper:Kraft'], ml_indices end diff --git a/test/unit/zena/use/prop_eval_test.rb b/test/unit/zena/use/prop_eval_test.rb index 3eb8a483..b422ca00 100644 --- a/test/unit/zena/use/prop_eval_test.rb +++ b/test/unit/zena/use/prop_eval_test.rb @@ -45,16 +45,70 @@ class NodesRoles < ActiveRecord::Base login(:lion) end + context 'creating a node from a class with eval prop' do + subject do + secure(Node) { Node.create_node(:class => 'Contact', :name => 'foo', :parent_id => nodes_id(:projects)) } + end + + should 'set evaluated prop on create' do + assert_difference('Node.count', 1) do + node = subject + assert_equal ' foo', node.title + end + end + end # creating a node from a class with eval prop + + + context 'unpublishing a node from a class with eval prop' do + subject do + secure(Node) { nodes(:ant) } + end + + should 'succeed' do + assert subject.unpublish + end + end # unpublishing a node from a class with eval prop + context 'on a node' do context 'from a class with evaluated properties' do subject do - secure(Node) { nodes(:ant) } + secure(Node) { nodes(:ant) }.tap do |n| + n.update_attributes(:first_name => 'Dan', :name => 'Simmons') + end end + + context 'updating attributes' do + should 'update evaluated prop on save' do + assert_equal 'Dan Simmons', subject.title + end - should 'update evaluated prop on save' do - subject.update_attributes(:first_name => 'Dan', :name => 'Simmons') - assert_equal 'Dan Simmons', subject.title - end + should 'use evaluated prop in fulltext indices' do + assert_equal 'Dan Simmons', subject.version.idx_text_high + end + + context 'with property indices' do + subject do + secure(Node) { nodes(:letter) }.tap do |n| + assert n.update_attributes(:paper => 'Origami', :v_status => Zena::Status[:pub]) + end + end + + should 'use evaluated prop in ml prop indices' do + idx = IdxNodesMlString.find(:first, + :conditions => {:node_id => subject.id, :lang => visitor.lang, :key => 'search'} + ) + assert_equal 'zena enhancements paper:Origami', idx.value + end + + should 'use evaluated prop in prop indices' do + idx = IdxNodesString.find(:first, + :conditions => {:node_id => subject.id, :key => 'search_mono'} + ) + assert_equal 'Origami mono', idx.value + end + end # with property indices + + end # updating attributes end # from a class with evaluated properties context 'from a class with eval prop used as default' do diff --git a/test/unit/zena/use/rendering_test.rb b/test/unit/zena/use/rendering_test.rb index 9abd544c..8755ae06 100644 --- a/test/unit/zena/use/rendering_test.rb +++ b/test/unit/zena/use/rendering_test.rb @@ -18,7 +18,7 @@ class RenderingTest < Zena::View::TestCase end should 'return a relative path on admin_layout' do - assert_equal "/test.host/zafu/default/Node-+adminLayout/en/_main.erb", controller.admin_layout + assert_equal "/test.host/zafu/Default skin/Node-%2BadminLayout/en/_main.erb", controller.admin_layout end end # Rendering diff --git a/test/unit/zena/use/urls_test.rb b/test/unit/zena/use/urls_test.rb index 490c5996..49f66e8b 100644 --- a/test/unit/zena/use/urls_test.rb +++ b/test/unit/zena/use/urls_test.rb @@ -18,11 +18,11 @@ def test_zen_path assert_equal '/en/section12_test.html', zen_path(node, :mode=>'test') assert_match %r{/tt/section12_test.jpg}, zen_path(node, :mode=>'test', :prefix=>'tt', :format=>'jpg') node = secure!(Node) { nodes(:cleanWater) } - assert_equal '/en/projects/cleanWater', zen_path(node) - assert_equal '/en/projects/cleanWater_test', zen_path(node, :mode=>'test') + assert_equal '/en/projects-list/Clean-Water-project', zen_path(node) + assert_equal '/en/projects-list/Clean-Water-project_test', zen_path(node, :mode=>'test') node = secure!(Node) { nodes(:status) } - assert_equal '/en/projects/cleanWater/page22.html', zen_path(node) - assert_equal '/en/projects/cleanWater/page22_test.html', zen_path(node, :mode=>'test') + assert_equal '/en/projects-list/Clean-Water-project/page22.html', zen_path(node) + assert_equal '/en/projects-list/Clean-Water-project/page22_test.html', zen_path(node, :mode=>'test') end def test_zen_path_cache_stamp @@ -36,7 +36,7 @@ def test_zen_path_cache_stamp login(:anon) node = secure!(Node) { nodes(:cleanWater) } - assert_equal '/en/projects/cleanWater.jpg', zen_path(node, :format => 'jpg') + assert_equal '/en/projects-list/Clean-Water-project.jpg', zen_path(node, :format => 'jpg') end def test_make_cachestamp @@ -84,9 +84,9 @@ def test_zen_path_asset assert_equal "/en/section12.kls.html", zen_path(node, :asset=>'kls') assert_equal "/tt/section12.foo.jpg?1144713600", zen_path(node, :mode=>'test', :prefix=>'tt', :format=>'jpg', :asset => 'foo') node = secure!(Node) { nodes(:cleanWater) } - assert_equal "/en/projects/cleanWater.kls", zen_path(node, :asset => 'kls') + assert_equal "/en/projects-list/Clean-Water-project.kls", zen_path(node, :asset => 'kls') node = secure!(Node) { nodes(:status) } - assert_equal "/en/projects/cleanWater/page22.abcd.png?1144713600", zen_path(node, :asset => 'abcd', :format => 'png') + assert_equal "/en/projects-list/Clean-Water-project/page22.abcd.png?1144713600", zen_path(node, :asset => 'abcd', :format => 'png') end def test_zen_url @@ -99,15 +99,15 @@ def test_zen_url def test_data_path_for_public_documents login(:ant) node = secure!(Node) { nodes(:water_pdf) } - assert_equal "/en/projects/cleanWater/document25.pdf", data_path(node) + assert_equal "/en/projects-list/Clean-Water-project/document25.pdf", data_path(node) node = secure!(Node) { nodes(:status) } - assert_equal "/oo/projects/cleanWater/page22.html", data_path(node) + assert_equal "/oo/projects-list/Clean-Water-project/page22.html", data_path(node) login(:anon) node = secure!(Node) { nodes(:water_pdf) } - assert_equal "/en/projects/cleanWater/document25.pdf", data_path(node) + assert_equal "/en/projects-list/Clean-Water-project/document25.pdf", data_path(node) node = secure!(Node) { nodes(:status) } - assert_equal "/en/projects/cleanWater/page22.html", data_path(node) + assert_equal "/en/projects-list/Clean-Water-project/page22.html", data_path(node) end def test_data_path_for_non_public_documents @@ -115,9 +115,9 @@ def test_data_path_for_non_public_documents node = secure!(Node) { nodes(:water_pdf) } assert node.update_attributes( :rgroup_id => groups_id(:workers), :inherit => 0 ) assert !node.public? - assert_equal "/oo/projects/cleanWater/document25.pdf", data_path(node) + assert_equal "/oo/projects-list/Clean-Water-project/document25.pdf", data_path(node) node = secure!(Node) { nodes(:status) } - assert_equal "/oo/projects/cleanWater/page22.html", data_path(node) + assert_equal "/oo/projects-list/Clean-Water-project/page22.html", data_path(node) login(:anon) assert_raise(ActiveRecord::RecordNotFound) { secure!(Node) { nodes(:water_pdf) } } diff --git a/test/unit/zena/use/version_hash_test.rb b/test/unit/zena/use/version_hash_test.rb index 7fb9e7dc..159f9a09 100644 --- a/test/unit/zena/use/version_hash_test.rb +++ b/test/unit/zena/use/version_hash_test.rb @@ -41,7 +41,7 @@ class VersionHashTest < Zena::Unit::TestCase setup do login(:tiger) visitor.lang = 'de' - @attributes = {'title' => 'Tigris Tigris'} + @attributes = {'name' => 'Tigris'} end subject do @@ -66,7 +66,7 @@ class VersionHashTest < Zena::Unit::TestCase context 'with auto publish' do setup do - @attributes = {'title' => 'Tigris Tigris', :v_status => Zena::Status[:pub]} + @attributes = {'name' => 'Tigris Tigris', :v_status => Zena::Status[:pub]} end should 'set a readers and writers entry for the current lang' do diff --git a/test/unit/zena/use/zafu_template_test.rb b/test/unit/zena/use/zafu_template_test.rb index 26248c7e..e3fc29b3 100644 --- a/test/unit/zena/use/zafu_template_test.rb +++ b/test/unit/zena/use/zafu_template_test.rb @@ -31,7 +31,7 @@ class ZafuTemplateTest < Zena::View::TestCase end should 'find best template based on class' do - assert_match %r{default/Node}, @controller.send(:template_url) + assert_match %r{Default skin/Node}, @controller.send(:template_url) end context 'with an admin visitor' do @@ -41,7 +41,7 @@ class ZafuTemplateTest < Zena::View::TestCase should 'use visitor chosen dev skin' do visitor.dev_skin_id = nodes_zip(:wikiSkin) - assert_match %r{/wikiSkin/Node}, @controller.send(:template_url) + assert_match %r{/wiki skin/Node}, @controller.send(:template_url) end should 'use rescue skin' do @@ -51,9 +51,9 @@ class ZafuTemplateTest < Zena::View::TestCase should 'use any skin' do visitor.dev_skin_id = User::ANY_SKIN_ID - assert_match %r{/default/Node}, @controller.send(:template_url) + assert_match %r{/Default skin/Node}, @controller.send(:template_url) visiting(:wiki) - assert_match %r{/wikiSkin/Node}, @controller.send(:template_url) + assert_match %r{/wiki skin/Node}, @controller.send(:template_url) end should 'not insert dev_box for non html content' do @@ -74,9 +74,21 @@ class ZafuTemplateTest < Zena::View::TestCase should 'not use visitor skin mode' do visitor.dev_skin_id = nodes_zip(:wikiSkin) - assert_match %r{/default/Node}, @controller.send(:template_url) + assert_match %r{/Default skin/Node}, @controller.send(:template_url) end end # without an admin visitor + + context 'on get_template_text' do + should 'find template' do + assert_match %r{include template='Node'}, get_template_text('Project', nodes_id(:default)).first + end + end # on get_template_text + + context 'on get_template_text with fullpath' do + should 'find template' do + assert_match %r{include template='Node'}, get_template_text('/Default skin/Project').first + end + end # on get_template_text #def test_template_url_virtual_class # without_files('zafu') do # node = @controller.send(:secure,Node) { nodes(:opening) } diff --git a/test/unit/zena/use/zazen_test.rb b/test/unit/zena/use/zazen_test.rb index 7102e204..1b8ec47b 100644 --- a/test/unit/zena/use/zazen_test.rb +++ b/test/unit/zena/use/zazen_test.rb @@ -17,9 +17,9 @@ def test_wiki_link end def test_image_title - assert_match %r{<div class='img_with_title'><img[^>]*><div class='img_title'><p>blah <a href=.*projects/cleanWater.*Clean Water.*/a></p></div></div>}, + assert_match %r{<div class='img_with_title'><img[^>]*><div class='img_title'><p>blah <a href=.*projects-list/Clean-Water-project.*Clean Water.*/a></p></div></div>}, zazen("!30/blah \"\":21!") - assert_match %r{<div class='img_with_title'><img.*class.*pv.*><div class='img_title'><p>blah <a href=.*projects/cleanWater.*Clean Water.*/a></p></div></div>}, + assert_match %r{<div class='img_with_title'><img.*class.*pv.*><div class='img_title'><p>blah <a href=.*projects-list/Clean-Water-project.*Clean Water.*/a></p></div></div>}, zazen("!30_pv/blah \"\":21!") assert_match %r{<div class='img_with_title'><img.*class.*std.*><div class='img_title'><p>Photo taken from.*</p></div></div>}, zazen("!30/!") @@ -27,36 +27,36 @@ def test_image_title def test_make_link # * ["":34] creates a link to node 34 with node's title. - assert_equal '<p><a href="/en/projects/cleanWater">Clean Water project</a></p>', zazen('"":21') + assert_equal '<p><a href="/en/projects-list/Clean-Water-project">Clean Water project</a></p>', zazen('"":21') # * ["title":34] creates a link to node 34 with the given title. - assert_equal '<p><a href="/en/projects/cleanWater">hello</a></p>', zazen('"hello":21') + assert_equal '<p><a href="/en/projects-list/Clean-Water-project">hello</a></p>', zazen('"hello":21') # * ["":034] if the node id starts with '0', creates a popup link. - assert_match %r{/en/projects/cleanWater.*window.open.*hello}, zazen('"hello":021') + assert_match %r{/en/projects-list/Clean-Water-project.*window.open.*hello}, zazen('"hello":021') end def test_make_link_sharp assert_equal '<p><a href="#node34">hello</a></p>', zazen('"hello":34#') assert_equal '<p><a href="#node34">hello</a></p>', zazen('"hello":34#[id]') assert_equal '<p><a href="#node34">hello</a></p>', zazen('"hello":34#[zip]') - assert_equal '<p><a href="#news">hello</a></p>', zazen('"hello":34#[node_name]') + assert_equal '<p><a href="#News-list">hello</a></p>', zazen('"hello":34#[title]') # * ["":34#[parent/]] if the node id starts with '0', creates a popup link. assert_equal '<p><a href="/en/page32.html#node34">hello</a></p>', zazen('"hello":34#[parent/]') assert_equal '<p><a href="/en/page32.html#node34">hello</a></p>', zazen('"hello":34#[parent/id]') assert_equal '<p><a href="/en/page32.html#node34">hello</a></p>', zazen('"hello":34#[parent/zip]') - assert_equal '<p><a href="/en/page32.html#news">hello</a></p>', zazen('"hello":34#[parent/node_name]') + assert_equal '<p><a href="/en/page32.html#News-list">hello</a></p>', zazen('"hello":34#[parent/title]') end def test_make_image # * [!24!] inline image 24. (default format is 'pv' defined in #ImageBuilder). Options are : - assert_equal "<p><img src='/en/projects/cleanWater/image24_std.jpg?929831698949' width='545' height='400' alt='it's a lake' class='std'/></p>", zazen('!24!') + assert_equal "<p><img src='/en/projects-list/Clean-Water-project/image24_std.jpg?929831698949' width='545' height='400' alt='it's a lake' class='std'/></p>", zazen('!24!') # ** [!024!] inline image, default format, link to full image. - assert_equal "<p><a class='popup' href='/en/projects/cleanWater/image24.jpg?1144713600' target='_blank'><img src='/en/projects/cleanWater/image24_std.jpg?929831698949' width='545' height='400' alt='it's a lake' class='std'/></a></p>", zazen('!024!') + assert_equal "<p><a class='popup' href='/en/projects-list/Clean-Water-project/image24.jpg?1144713600' target='_blank'><img src='/en/projects-list/Clean-Water-project/image24_std.jpg?929831698949' width='545' height='400' alt='it's a lake' class='std'/></a></p>", zazen('!024!') end def test_make_image_with_document - assert_match %r{<p><a.*href=.*en/projects/cleanWater/document25\.pdf.*img src='/images/ext/pdf.png' width='32' height='32' alt='pdf document' class='doc'/></a></p>}, zazen('!25!') - assert_match %r{<p><a.*href=.*en/projects/cleanWater/document25\.pdf.*img src='/images/ext/pdf.png' width='32' height='32' alt='pdf document' class='doc'/></a></p>}, zazen('!025!') # same as '!25!' - assert_match %r{<p><a.*href=.*en/projects/cleanWater/document25\.pdf.*img src='/images/ext/pdf_pv.png' width='70' height='70' alt='pdf document' class='doc'/></a></p>}, zazen('!25_pv!') + assert_match %r{<p><a.*href=.*en/projects-list/Clean-Water-project/document25\.pdf.*img src='/images/ext/pdf.png' width='32' height='32' alt='pdf document' class='doc'/></a></p>}, zazen('!25!') + assert_match %r{<p><a.*href=.*en/projects-list/Clean-Water-project/document25\.pdf.*img src='/images/ext/pdf.png' width='32' height='32' alt='pdf document' class='doc'/></a></p>}, zazen('!025!') # same as '!25!' + assert_match %r{<p><a.*href=.*en/projects-list/Clean-Water-project/document25\.pdf.*img src='/images/ext/pdf_pv.png' width='70' height='70' alt='pdf document' class='doc'/></a></p>}, zazen('!25_pv!') end def test_make_bad_image @@ -65,26 +65,26 @@ def test_make_bad_image def test_make_image_align # ** [!<.24!] or [!<24!] inline image surrounded with <p class='float_left'></p> - assert_match %r{class='img_left'.*img.*/en/projects/cleanWater/image24_std.jpg.*class='std'}, zazen('!<.24!') - assert_match %r{class='img_left'.*img.*/en/projects/cleanWater/image24_std.jpg.*class='std'}, zazen('!<24!') + assert_match %r{class='img_left'.*img.*/en/projects-list/Clean-Water-project/image24_std.jpg.*class='std'}, zazen('!<.24!') + assert_match %r{class='img_left'.*img.*/en/projects-list/Clean-Water-project/image24_std.jpg.*class='std'}, zazen('!<24!') # ** [!>.24!] inline image surrounded with <p class='float_right'></p> - assert_match %r{class='img_right'.*img.*/en/projects/cleanWater/image24_std.jpg.*class='std'}, zazen('!>.24!') - assert_match %r{class='img_right'.*img.*/en/projects/cleanWater/image24_std.jpg.*class='std'}, zazen('!>24!') + assert_match %r{class='img_right'.*img.*/en/projects-list/Clean-Water-project/image24_std.jpg.*class='std'}, zazen('!>.24!') + assert_match %r{class='img_right'.*img.*/en/projects-list/Clean-Water-project/image24_std.jpg.*class='std'}, zazen('!>24!') # ** [!=.24!] inline image with <p class='center'></p> - assert_match %r{class='img_center'.*img.*/en/projects/cleanWater/image24_std.jpg.*class='std'}, zazen('!=.24!') - assert_match %r{class='img_center'.*img.*/en/projects/cleanWater/image24_std.jpg.*class='std'}, zazen('!=24!') + assert_match %r{class='img_center'.*img.*/en/projects-list/Clean-Water-project/image24_std.jpg.*class='std'}, zazen('!=.24!') + assert_match %r{class='img_center'.*img.*/en/projects-list/Clean-Water-project/image24_std.jpg.*class='std'}, zazen('!=24!') end def test_make_iformat # ** [!24_pv!] inline image transformed to format 'pv'. Formats are defined in #ImageBuilder. - assert_match %r{.*img.*/en/projects/cleanWater/image24.jpg.*600.*440.*class='full'}, zazen('!24_full!') - assert_match %r{.*img.*/en/projects/cleanWater/image24_tiny.jpg.*16.*16.*class='tiny'}, zazen('!24_tiny!') + assert_match %r{.*img.*/en/projects-list/Clean-Water-project/image24.jpg.*600.*440.*class='full'}, zazen('!24_full!') + assert_match %r{.*img.*/en/projects-list/Clean-Water-project/image24_tiny.jpg.*16.*16.*class='tiny'}, zazen('!24_tiny!') end def test_all_options # ** all the options above can be used together as in [!>.26.std!] : inline image on the right, size 'med'. - assert_match %r{class='img_right'.*img.*/en/projects/cleanWater/image24_mini.jpg.*32.*32.*class='mini'}, zazen('!>24_mini!') - assert_match %r{class='img_right'.*img.*/en/projects/cleanWater/image24_mini.jpg.*32.*32.*class='mini'}, zazen('!>.24_mini!') + assert_match %r{class='img_right'.*img.*/en/projects-list/Clean-Water-project/image24_mini.jpg.*32.*32.*class='mini'}, zazen('!>24_mini!') + assert_match %r{class='img_right'.*img.*/en/projects-list/Clean-Water-project/image24_mini.jpg.*32.*32.*class='mini'}, zazen('!>.24_mini!') end def test_make_gallery @@ -117,13 +117,13 @@ def test_list_nodes def test_image_as_link # * [!26!:37] you can use an image as the source for a link - assert_zazen_match "p a[@href='/en/projects/cleanWater'] img.std[@src='/en/image30_std.jpg?929831698949'][@width='440'][@height='400']", '!30!:21' + assert_zazen_match "p a[@href='/en/projects-list/Clean-Water-project'] img.std[@src='/en/image30_std.jpg?929831698949'][@width='440'][@height='400']", '!30!:21' # * [!26!:www.example.com] use an image for an outgoing link assert_zazen_match "p a[@href='http://www.example.com'] img.std[@src='/en/image30_std.jpg?929831698949']", '!30!:http://www.example.com' end def test_full - assert_zazen_match "div.img_left a[@href='/en/projects/cleanWater'][@onclick*=window.open] img.std[@src='/en/projects/cleanWater/image24_std.jpg?929831698949'][@width='545'][@height='400'][@alt*=lake]", '!<.24_3!:021' + assert_zazen_match "div.img_left a[@href='/en/projects-list/Clean-Water-project'][@onclick*=window.open] img.std[@src='/en/projects-list/Clean-Water-project/image24_std.jpg?929831698949'][@width='545'][@height='400'][@alt*=lake]", '!<.24_3!:021' end def test_empty_image_ref @@ -137,8 +137,8 @@ def test_no_images end def test_pseudo_id - assert_zazen_match "a[@href='/en/contact15.html'][text()='people/lion']", 'This is a "link"::lio.' - assert_zazen_match "a[@href='/en/image30_pv.jpg?967816914293'][text()='projects/wiki/bird_pv.jpg']", 'This is a "link"::bir_pv.data.' + assert_zazen_match "a[@href='/en/contact15.html'][text()='people/Panthera Leo Verneyi']", 'This is a "link"::lio.' + assert_zazen_match "a[@href='/en/image30_pv.jpg?967816914293'][text()='projects list/a wiki with Zena/bird_pv.jpg']", 'This is a "link"::bir_pv.data.' end context 'An absolute pseudo path' do @@ -147,11 +147,11 @@ def test_pseudo_id end subject do - '(/projects/wiki/bird)' + '(/projects list/a wiki with Zena/bird)' end should 'resolve as link without using the current node' do - assert_equal '<p>Read <a href="/en/image30.html">projects/wiki/bird</a></p>', zazen(%Q{Read "":#{subject}}) + assert_equal '<p>Read <a href="/en/image30.html">projects list/a wiki with Zena/bird</a></p>', zazen(%Q{Read "":#{subject}}) end should 'resolve as image without using the current node' do @@ -161,7 +161,7 @@ def test_pseudo_id context 'with mode' do subject do - '(/projects/wiki/bird)_side' + '(/projects list/a wiki with Zena/bird)_side' end should 'resolve with mode in image tag' do @@ -177,7 +177,7 @@ def test_pseudo_id end should 'resolve with mode as link and image tag' do - assert_equal "<p>See <a href=\"/en/image30_side.html\"><img src='/en/image30_side.jpg?100321116926' width='220' height='500' alt='bird' class='side'/></a></p>", zazen(%Q{See !:#{subject}!:#{subject}}) + assert_equal "<p>See <a href=\"/en/image30_side.html\"><img src='/en/image30_side.jpg?100321116926' width='220' height='500' alt='bird' class='side'/></a></p>", zazen(%Q{See !#{subject}!:#{subject}}) end end end # An absolute pseudo path @@ -188,32 +188,32 @@ def test_pseudo_id end subject do - '(status)' + '(status title)' end context 'with different current nodes' do setup do - lion = secure!(Node) { nodes(:lion) } - lion.update_attributes(:title => 'status', :v_status => Zena::Status[:pub]) - @people = secure!(Node) { nodes(:people) } - @cleanWater = secure!(Node) { nodes(:cleanWater) } + art = secure!(Node) { nodes(:art) } + art.update_attributes(:title => 'status title', :v_status => Zena::Status[:pub]) + @collections = secure!(Node) { nodes(:collections) } + @cleanWater = secure!(Node) { nodes(:cleanWater) } end should 'resolve with current node' do @node = @cleanWater - assert_equal '<p>Read <a href="/oo/projects/cleanWater/page22.html">projects/cleanWater/status</a></p>', zazen(%Q{Read "":#{subject}}) - @node = @people - assert_equal '<p>Read <a href="/oo/contact15.html">people/status</a></p>', zazen(%Q{Read "":#{subject}}) + assert_equal '<p>Read <a href="/oo/projects-list/Clean-Water-project/page22.html">projects list/Clean Water project/status title</a></p>', zazen(%Q{Read "":#{subject}}) + @node = @collections + assert_equal '<p>Read <a href="/oo/tag33.html">Collections/status title</a></p>', zazen(%Q{Read "":#{subject}}) end end end # A relative pseudo path def test_pseudo_id_numbers_only login(:lion) - lion = secure!(Node) { nodes(:lion) } - assert lion.update_attributes(:title => '1234', :v_status => Zena::Status[:pub]) + art = secure!(Node) { nodes(:art) } + assert art.update_attributes(:title => '1234', :v_status => Zena::Status[:pub]) login(:anon) - assert_equal '<p>This is a <a href="/en/contact15.html">people/1234</a>.</p>', zazen('This is a "link"::123.') + assert_equal '<p>This is a <a href="/en/tag33.html">Collections/1234</a>.</p>', zazen('This is a "link"::123.') end def test_bad_pseudo_path @@ -229,16 +229,16 @@ def test_translate_ids projects = secure!(Node) { nodes(:projects) } zena = secure!(Node) { nodes(:zena) } assert_equal "This \"is\":33 \"a\":#{nodes_zip(:wiki)} !#{nodes_zip(:bird_jpg)}! \"link\":#{nodes_zip(:lion)}.", - zazen('This "is":33 "a":(projects/wiki) !(projects/wiki/bird)! "link"::lio.', :translate_ids => :zip, :node => zena) + zazen('This "is":33 "a":(projects list/a wiki with Zena) !(projects list/a wiki with Zena/bird)! "link"::lio.', :translate_ids => :zip, :node => zena) - assert_equal 'This "is":(../collections/art) "a":(wiki) !(wiki/bird)! !{(wiki/bird)}! ![(wiki/bird)]! "link":(../people/lion).', - zazen('This "is":33 "a":(/projects/wiki) !30! !{30}! ![30]! "link"::lio.', :translate_ids => :relative_path, :node => projects) + assert_equal 'This "is":(../Collections/Art) "a":(a wiki with Zena) !(a wiki with Zena/bird)! !{(a wiki with Zena/bird)}! ![(a wiki with Zena/bird)]! "link":(../people/Panthera Leo Verneyi).', + zazen('This "is":33 "a":(/projects list/a wiki with Zena) !30! !{30}! ![30]! "link"::lio.', :translate_ids => :relative_path, :node => projects) assert_equal "This \"is\":33 \"a\":#{nodes_zip(:wiki)} !#{nodes_zip(:bird_jpg)}! \"link\":#{nodes_zip(:lion)}.", - zazen('This "is":(../collections/art) "a":(wiki) !(wiki/bird)! "link":(../people/lion).', :translate_ids => :zip, :node => projects) + zazen('This "is":(../Collections/Art) "a":(a wiki with Zena) !(a wiki with Zena/bird)! "link":(../people/Panthera Leo Verneyi).', :translate_ids => :zip, :node => projects) assert_equal "This \"is\":33 \"a\":#{nodes_zip(:wiki)} !#{nodes_zip(:bird_jpg)}! \"link\":#{nodes_zip(:lion)}.", - zazen('This "is":(collections/art) "a":(/projects/wiki) !(/projects/wiki/bird)! "link":(people/lion).', :translate_ids => :zip, :node => zena) + zazen('This "is":(Collections/Art) "a":(/projects list/a wiki with Zena) !(/projects list/a wiki with Zena/bird)! "link":(people/Panthera Leo Verneyi).', :translate_ids => :zip, :node => zena) end def test_table_asset diff --git a/zena.gemspec b/zena.gemspec index 58e96eb6..302be466 100644 --- a/zena.gemspec +++ b/zena.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |s| s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version= s.authors = ["Gaspard Bucher"] - s.date = %q{2010-09-28} + s.date = %q{2010-09-30} s.default_executable = %q{zena} s.description = %q{zena is a Ruby on Rails CMS (content managment system) with a focus on usability, ease of customization and web 2.0 goodness (application like behaviour).} s.email = %q{gaspard@teti.ch} @@ -435,6 +435,8 @@ Gem::Specification.new do |s| "db/migrate/20100923154807_remove_base_contact.rb", "db/migrate/20100926192223_remove_su_user.rb", "db/migrate/20100927141658_add_eval_attributes_to_v_class.rb", + "db/migrate/20100928185257_add_obvious_idx.rb", + "db/migrate/20100929143111_remove_node_name.rb", "doc/README_FOR_APP", "doc/fixtures.graffle", "doc/fixtures.pdf", @@ -525,6 +527,7 @@ Gem::Specification.new do |s| "lib/zena/use.rb", "lib/zena/use/action.rb", "lib/zena/use/ajax.rb", + "lib/zena/use/ancestry.rb", "lib/zena/use/authlogic.rb", "lib/zena/use/calendar.rb", "lib/zena/use/conditional.rb", @@ -542,7 +545,6 @@ Gem::Specification.new do |s| "lib/zena/use/image_builder.rb", "lib/zena/use/ml_index.rb", "lib/zena/use/nested_attributes_alias.rb", - "lib/zena/use/node_name.rb", "lib/zena/use/prop_eval.rb", "lib/zena/use/query_builder.rb", "lib/zena/use/query_comment.rb", @@ -1879,7 +1881,6 @@ Gem::Specification.new do |s| "test/unit/link_test.rb", "test/unit/multi_version_test.rb", "test/unit/multiversion_test.rb", - "test/unit/node_name_test.rb", "test/unit/node_test.rb", "test/unit/note_test.rb", "test/unit/page_test.rb", @@ -1913,6 +1914,7 @@ Gem::Specification.new do |s| "test/unit/zena/parser_test.rb", "test/unit/zena/unit/test_case_test.rb", "test/unit/zena/use/action_test.rb", + "test/unit/zena/use/ancestry_test.rb", "test/unit/zena/use/calendar_test.rb", "test/unit/zena/use/dates_model_methods_test.rb", "test/unit/zena/use/dates_string_methods_test.rb", @@ -2121,7 +2123,6 @@ Gem::Specification.new do |s| "test/unit/link_test.rb", "test/unit/multi_version_test.rb", "test/unit/multiversion_test.rb", - "test/unit/node_name_test.rb", "test/unit/node_test.rb", "test/unit/note_test.rb", "test/unit/page_test.rb", @@ -2150,6 +2151,7 @@ Gem::Specification.new do |s| "test/unit/zena/parser_test.rb", "test/unit/zena/unit/test_case_test.rb", "test/unit/zena/use/action_test.rb", + "test/unit/zena/use/ancestry_test.rb", "test/unit/zena/use/calendar_test.rb", "test/unit/zena/use/dates_model_methods_test.rb", "test/unit/zena/use/dates_string_methods_test.rb",