Changeset 468
- Timestamp:
- 2007-05-01 16:18:54 (2 years ago)
- Files:
-
- trunk/app/controllers/application.rb (modified) (7 diffs)
- trunk/app/controllers/nodes_controller.rb (modified) (2 diffs)
- trunk/app/controllers/session_controller.rb (modified) (1 diff)
- trunk/app/models/node.rb (modified) (15 diffs)
- trunk/app/models/page.rb (modified) (1 diff)
- trunk/app/models/site.rb (modified) (1 diff)
- trunk/app/models/template.rb (modified) (1 diff)
- trunk/db/init/default.tgz (modified) (previous)
- trunk/lib/multiversion.rb (modified) (3 diffs)
- trunk/lib/parser/lib/parser.rb (modified) (5 diffs)
- trunk/lib/parser/lib/rules/zafu.rb (modified) (2 diffs)
- trunk/lib/parser/test/parser_test.rb (modified) (1 diff)
- trunk/lib/parser/test/zafu_asset.yml (modified) (1 diff)
- trunk/test/functional/application_controller_test.rb (modified) (1 diff)
- trunk/test/helpers/testhelp.rb (modified) (3 diffs)
- trunk/test/unit/node_test.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/application.rb
r466 r468 3 3 class ApplicationController < ActionController::Base 4 4 helper_method :prefix, :zen_path, :zen_url, :data_path, :node_url, :notes, :error_messages_for, :render_errors, :processing_error 5 helper_method : template_text_for_url, :template_url_for_asset, :save_erb_to_url, :lang, :visitor, :fullpath_from_template_url5 helper_method :get_template_text, :template_url_for_asset, :save_erb_to_url, :lang, :visitor, :fullpath_from_template_url 6 6 helper 'main' 7 7 before_filter :check_env … … 132 132 @skin_name = @skin_name.gsub(/[^a-zA-Z]/,'') # security 133 133 mode = opts[:mode] || params[:mode] 134 puts mode.inspect 134 135 format = opts[:format] || params[:format] || 'html' 135 136 klass = @node.class … … 142 143 :conditions => ["tkpath IN (?) AND format = ? AND mode #{mode ? '=' : 'IS'} ? AND template_contents.node_id = nodes.id", klasses, format, mode], 143 144 :from => "nodes, template_contents", 144 :select => "nodes.*, template_contents. *, (template_contents.skin_name = #{@skin_name}) AS skin_ok",145 :select => "nodes.*, template_contents.skin_name, template_contents.klass, (template_contents.skin_name = #{@skin_name.inspect}) AS skin_ok", 145 146 :order => "length(tkpath) DESC, skin_ok DESC" 146 147 )} … … 154 155 skin_path = "/#{template[:skin_name]}/#{template[:klass]}#{mode}.#{format}" 155 156 main_path = "/#{visitor.lang}/main.erb" 156 url = "#{skin_root}/zafu.compiled#{skin_path}#{main_path}" 157 158 if File.exists?(url) 159 # FIXME: use CachedPage to store the compiled template instead of this File.stat test 160 if File.stat(url).mtime < template.v_updated_at 161 # template changed, render 162 FileUtils.rmtree("#{skin_root}/zafu.compiled#{skin_path}") 163 response.template.instance_variable_set(:@session, session) 164 skin_helper = response.template 165 res = ZafuParser.new_with_url(skin_path, :helper => skin_helper).render 166 FileUtils::mkpath(File.dirname(url)) unless File.exists?(File.dirname(url)) 167 File.open(url, "wb") { |f| f.syswrite(res) } 168 end 157 url = "#{skin_root}/zafu#{skin_path}#{main_path}" 158 159 # FIXME: use CachedPage to store the compiled template instead of this File.stat test 160 if true #!File.exists?(url) || (File.stat(url).mtime < template.v_updated_at) 161 # template changed, render 162 FileUtils.rmtree("#{skin_root}/zafu#{skin_path}") 163 response.template.instance_variable_set(:@session, session) 164 skin_helper = response.template 165 res = ZafuParser.new_with_url(skin_path, :helper => skin_helper).render 166 FileUtils::mkpath(File.dirname(url)) unless File.exists?(File.dirname(url)) 167 File.open(url, "wb") { |f| f.syswrite(res) } 169 168 end 170 169 … … 176 175 # start with a '/' we use the full url directly. 177 176 # tested in MainControllerTest 178 def template_text_for_url(url) 179 @skin ||= {} 180 if url =~ /^\// 181 url = url[1..-1].split('/') 182 skin_names = [url.shift] 183 else 184 url = url.split('/') 185 skin_names = [@skin_name, url.shift] 186 end 187 188 partial = nil 189 skin_names.each do |skin_name| 190 skin = @skin[skin_name] ||= secure(Skin) { Skin.find_by_name(skin_name) } 191 path = (skin.fullpath.split('/') + url).join('/') 192 break if partial = secure(TextDocument) { TextDocument.find_by_path(path) } 193 end 194 partial ? partial.version.text : nil 177 def get_template_text(opts) 178 return nil unless doc = find_template_document(opts) 179 doc.version.text 195 180 end 196 181 197 182 # TODO: implement 198 183 def template_url_for_asset(opts) 199 200 # 1. find in current skin ? 201 url = opts[:current_template][1..-1].split('/') + opts[:src].split('/') 202 url.compact! 203 skin_name = url.shift 204 if @skin_obj && @skin_obj[:name] == skin_name 205 skin = @skin_obj 206 end 207 skin ||= secure(Skin) { Skin.find_by_name(skin_name) } 208 asset = skin.asset_for_path(url.join('/'), Document) 209 asset ? node_url(asset) : nil 184 return nil unless asset = find_template_document(opts) 185 asset ? data_path(asset, :prefix=>lang) : nil 210 186 rescue ActiveRecord::RecordNotFound 211 187 return nil 188 end 189 190 # opts should contain :current_template and :src 191 def find_template_document(opts) 192 src = opts[:src].split('.') 193 mode = src.pop 194 src = src.join('.') 195 folder = (opts[:current_folder] && opts[:current_folder] != '') ? opts[:current_folder].split('/') : [] 196 @skin ||= {} 197 198 if src =~ /^\// 199 # /default /fun/layout.html 200 # look in fun --> layout.html 201 url = src[1..-1].split('/') 202 skin_names = [url.shift] 203 else 204 # /default default.css 205 # look in @skin_name, default --> default.css 206 url = folder + src.split('/') 207 skin_names = [@skin_name] 208 skin_names << url.shift if url.size > 1 209 end 210 211 document = nil 212 skin_names.each do |skin_name| 213 next unless skin = @skin[skin_name] ||= secure(Skin) { Skin.find_by_name(skin_name) } 214 path = (skin.fullpath.split('/') + url).join('/') 215 break if document = secure(TextDocument) { TextDocument.find_by_path(path) } 216 end 217 document 212 218 end 213 219 … … 230 236 231 237 if template_url[0] == 'default' 232 "#{SITES_ROOT}/shared/zafu .compiled#{path}"233 else 234 "#{SITES_ROOT}/#{visitor.site.host}/zafu .compiled#{path}"238 "#{SITES_ROOT}/shared/zafu#{path}" 239 else 240 "#{SITES_ROOT}/#{visitor.site.host}/zafu#{path}" 235 241 end 236 242 end … … 356 362 # /////// The following methods are common to controllers and views //////////// # 357 363 358 def data_path(obj )359 zen_path(obj, :format => obj.c_ext)364 def data_path(obj, opts={}) 365 zen_path(obj, {:format => obj.c_ext}.merge(opts)) 360 366 end 361 367 trunk/app/controllers/nodes_controller.rb
r467 r468 24 24 def index 25 25 @node = site.root_node 26 params[:mode] = 'index' 27 respond_to do |format| 28 format.html { render_and_cache } 26 respond_to do |format| 27 format.html { render_and_cache(:mode => 'index') } 29 28 format.xml { render :xml => @node.to_xml } 30 29 end … … 33 32 def not_found 34 33 @node = site.root_node 35 params[:mode] = 'not_found' 36 respond_to do |format| 37 format.html { render_and_cache } 34 respond_to do |format| 35 format.html { render_and_cache(:mode => 'not_found') } 38 36 format.all { render :nothing => true } 39 37 end trunk/app/controllers/session_controller.rb
r455 r468 15 15 def destroy 16 16 reset_session 17 redirect_to :controller=>'node ', :action=>'index', :prefix=>(visitor.site.monolingual? ? '' : visitor.lang)17 redirect_to :controller=>'nodes', :action=>'index', :prefix=>(visitor.site.monolingual? ? '' : visitor.lang) 18 18 end 19 19 trunk/app/models/node.rb
r467 r468 128 128 after_save :spread_project_and_section 129 129 before_destroy :node_on_destroy 130 attr_protected :site_id, :zip, :id, :section_id, :project_id, :publish_from, :max_status 130 attr_protected :site_id, :zip, :id, :section_id, :project_id, :publish_from, :max_status, :v_status 131 131 acts_as_secure_node 132 132 acts_as_multiversioned … … 140 140 141 141 # TODO: cleanup and rename with something indicating the attrs cleanup that this method does. 142 def create_node(attrs) 142 def create_node(new_attributes) 143 attributes = new_attributes.stringify_keys 144 publish = (attributes.delete('v_status').to_i == Zena::Status[:pub]) 145 klass = attributes.delete('class') || attributes.delete('klass')|| self.to_s 146 143 147 scope = self.scoped_methods[0] || {} 144 148 visitor = scope[:create][:visitor] 145 klass = attrs.delete('class') || attrs.delete('klass') || attrs.delete(:class) || attrs.delete(:klass) || self.to_s146 149 147 if parent_id = attr s.delete(:_parent_id)148 attr s.delete('parent_id')150 if parent_id = attributes.delete('_parent_id') 151 attributes.delete('parent_id') 149 152 else 150 p = attr s['parent_id']153 p = attributes['parent_id'] 151 154 if p && p.to_i.to_s != p.to_s.strip 152 155 # find by name 153 156 parent_id = Node.with_exclusive_scope(scope) { Node.find_by_name(p) }[:id] 154 attr s.delete('parent_id')155 end 156 end 157 158 attr s.keys.each do |key|159 if key .to_s =~ /^(\w+)_id$/ && ! ['rgroup_id', 'wgroup_id', 'pgroup_id', 'user_id'].include?(key.to_s)160 attr s[key] = Node.connection.execute( "SELECT id FROM nodes WHERE site_id = #{visitor.site[:id]} AND zip = '#{attrs[key].to_i}'" ).fetch_row[0]161 end 162 end 163 164 attr s['parent_id'] = parent_id if parent_id165 166 attr s.delete('file') if attrs['file'] == ''157 attributes.delete('parent_id') 158 end 159 end 160 161 attributes.keys.each do |key| 162 if key =~ /^(\w+)_id$/ && ! ['rgroup_id', 'wgroup_id', 'pgroup_id', 'user_id'].include?(key) 163 attributes[key] = Node.connection.execute( "SELECT id FROM nodes WHERE site_id = #{visitor.site[:id]} AND zip = '#{attributes[key].to_i}'" ).fetch_row[0] 164 end 165 end 166 167 attributes['parent_id'] = parent_id if parent_id 168 169 attributes.delete('file') if attributes['file'] == '' 167 170 168 171 klass = Module::const_get(klass.to_sym) 169 172 raise NameError unless klass.ancestors.include?(Node) 170 if klass != self 171 klass.with_exclusive_scope(scope) { klass.create(attrs) } 173 174 node = if klass != self 175 klass.with_exclusive_scope(scope) { klass.create(attributes) } 172 176 else 173 self.create(attrs) 174 end 177 self.create(attributes) 178 end 179 node.publish if publish 180 node 175 181 rescue NameError => err 176 182 node = self.new 177 node.instance_eval { @attributes = attr s }183 node.instance_eval { @attributes = attributes } 178 184 node.errors.add('klass', 'invalid') 179 185 # This is to show the klass in the form seizure … … 183 189 end 184 190 185 191 # Create new nodes from the data in a folder or archive. 186 192 def create_nodes_from_folder(opts) 193 # TODO: all this method needs cleaning, it's a mess. 187 194 return nil unless (opts[:folder] || opts[:archive]) && (opts[:parent] || opts[:parent_id]) 188 195 scope = self.scoped_methods[0] || {} 189 196 parent_id = opts[:parent_id] || opts[:parent][:id] 190 197 folder = opts[:folder] 191 defaults = opts[:defaults] || {} 198 defaults = (opts[:defaults] || {}).stringify_keys 199 res = [] 192 200 193 201 # create from archive … … 205 213 # FIXME: is there a security risk here ? 206 214 system "tar -C '#{folder}' -xz < '#{archive.path}'" 207 res = create_nodes_from_folder(:folder => folder, :parent_id => parent_id, :defaults => defaults)215 res += create_nodes_from_folder(:folder => folder, :parent_id => parent_id, :defaults => defaults) 208 216 ensure 209 217 FileUtils::rmtree(folder) … … 232 240 attrs['v_lang'] ||= lang 233 241 current_obj = create_node(attrs) 242 res << current_obj 234 243 else 235 244 # document … … 253 262 current_obj.remove if current_obj.v_lang == attrs['v_lang'] 254 263 current_obj.edit!(attrs['v_lang']) 264 255 265 # FIXME: This should pass through the 'attrs' cleanup... 256 266 current_obj.update_attributes(attrs.merge(:parent_id => parent_id)) 267 current_obj.publish if attrs['v_status'].to_i == Zena::Status[:pub] 257 268 elsif document 258 269 # processing a document … … 265 276 end 266 277 current_obj = create_node(attrs.merge(:c_file => file, :klass => 'Document', :_parent_id => parent_id)) 278 res << current_obj 267 279 end 268 280 document = nil … … 270 282 # processing a folder 271 283 current_obj = create_node(attrs.merge(:_parent_id => parent_id)) 284 res << current_obj 272 285 end 273 286 index += 1 … … 277 290 if sub_folder 278 291 # create minimal object to store the children 279 current_obj ||= Page.with_exclusive_scope(scope) { Page.create( defaults.merge(:parent_id => parent_id, :name => filename.split('.').first) )} 280 create_nodes_from_folder(:folder => sub_folder, :parent_id => current_obj[:id], :defaults => defaults) 292 unless current_obj 293 current_obj = Page.with_exclusive_scope(scope) { Page.create( defaults.merge(:parent_id => parent_id, :name => filename.split('.').first) )} 294 current_obj.publish if defaults['v_status'].to_i == Zena::Status[:pub] 295 res << current_obj 296 end 297 res += create_nodes_from_folder(:folder => sub_folder, :parent_id => current_obj[:id], :defaults => defaults) 281 298 elsif document && !current_obj 282 299 # processing a document … … 290 307 end 291 308 current_obj = Document.with_exclusive_scope(scope) { Document.create(defaults.merge(:c_file => file, :parent_id => parent_id, :name => filename)) } 309 current_obj.publish if defaults['v_status'].to_i == Zena::Status[:pub] 310 res << current_obj 292 311 end 293 312 end 294 313 end 295 current_obj314 res 296 315 end 297 316 … … 874 893 unless all_children.size == 0 875 894 errors.add('base', "contains subpages") 876 return false 895 return false§ 877 896 else 878 897 # expire cache … … 890 909 # Called after an node is 'removed' 891 910 def after_remove 892 if self[:max_status] < Zena::Status[:pub]911 if (self[:max_status] < Zena::Status[:pub]) && !@new_record_before_save 893 912 # not published any more. 'remove' documents 894 913 sync_documents(:remove) … … 900 919 # Called after an node is 'proposed' 901 920 def after_propose 921 return true if @new_record_before_save 902 922 sync_documents(:propose) 903 923 end … … 905 925 # Called after an node is 'refused' 906 926 def after_refuse 927 return true if @new_record_before_save 907 928 sync_documents(:refuse) 908 929 end … … 910 931 # Called after an node is published 911 932 def after_publish(pub_time=nil) 933 return true if @new_record_before_save 912 934 sync_documents(:publish, pub_time) 913 935 end trunk/app/models/page.rb
r463 r468 15 15 Page 16 16 end 17 18 # Find an node by it's full path. Cache 'fullpath' if found. 19 def find_by_path(path) 20 return nil unless scope = scoped_methods[0] 21 return nil unless scope[:create] 22 visitor = scoped_methods[0][:create][:visitor] # use secure scope to get visitor 23 node = self.find_by_fullpath(path) 24 if node.nil? 25 path = path.split('/') 26 last = path.pop 27 Node.with_exclusive_scope do 28 node = Node.find(visitor.site[:root_id]) 29 path.each do |p| 30 raise ActiveRecord::RecordNotFound unless node = Node.find_by_name_and_parent_id(p, node[:id]) 31 end 32 end 33 raise ActiveRecord::RecordNotFound unless node = self.find_by_name_and_parent_id(last, node[:id]) 34 path << last 35 node.fullpath = path.join('/') 36 # bypass callbacks here 37 Node.connection.execute "UPDATE #{Node.table_name} SET fullpath='#{path.join('/').gsub("'",'"')}' WHERE id='#{node[:id]}'" 38 end 39 node 40 end 41 17 42 18 def select_classes 43 19 list = subclasses.inject([]) do |list, k| trunk/app/models/site.rb
r467 r468 132 132 # =========== LOAD INITIAL DATA (default skin) ============= 133 133 134 site.send(:secure,Node) { Node.create_nodes_from_folder(:archive => File.join(RAILS_ROOT, 'db', 'init', 'default.tgz'), :parent_id => root[:id], :defaults => {:rgroup_id => pub[:id], :wgroup_id => sgroup[:id], :pgroup_id => admin[:id] } ) }134 nodes = site.send(:secure,Node) { Node.create_nodes_from_folder(:archive => File.join(RAILS_ROOT, 'db', 'init', 'default.tgz'), :parent_id => root[:id], :defaults => { :v_status => Zena::Status[:pub], :rgroup_id => pub[:id], :wgroup_id => sgroup[:id], :pgroup_id => admin[:id] } ) } 135 135 136 136 trunk/app/models/template.rb
r467 r468 20 20 version.content.format = nil 21 21 end 22 super 22 if str =~ /(.+)\.(.*)/ 23 super($1) 24 else 25 super 26 end 23 27 end 24 28 trunk/lib/multiversion.rb
r465 r468 238 238 end 239 239 240 # Update an node's attributes or the node's version/content attributes. If the hashcontains only241 # :v_... or :c_... keys, then only the version will be saved. If the hashdoes not contain any :v_... or :c_...240 # Update an node's attributes or the node's version/content attributes. If the attributes contains only 241 # :v_... or :c_... keys, then only the version will be saved. If the attributes does not contain any :v_... or :c_... 242 242 # attributes, only the node is saved, without creating a new version. 243 def update_attributes( hash)243 def update_attributes(new_attributes) 244 244 redaction_attr = false 245 245 node_attr = false 246 hash.each do |k,v| 246 247 attributes = new_attributes.stringify_keys 248 attributes = remove_attributes_protected_from_mass_assignment(attributes) 249 attributes.each do |k,v| 247 250 next if k.to_s == 'id' # just ignore 'id' (cannot be set but is often around) 248 251 if k.to_s =~ /^(v_|c_)/ … … 257 260 end 258 261 unless node_attr 259 hash.each do |k,v|262 attributes.each do |k,v| 260 263 next if k.to_s == 'id' # just ignore 'id' (cannot be set but is often around) 261 264 self.send("#{k}=".to_sym, v) … … 311 314 end 312 315 if @version.nil? 313 raise Exception.new(" Node#{self[:id]} does not have any version !!")316 raise Exception.new("#{self.class} #{self[:id]} does not have any version !!") 314 317 end 315 318 end trunk/lib/parser/lib/parser.rb
r463 r468 9 9 end 10 10 11 def template_text_for_url(url) 12 url = url[1..-1] if url[0..0] == '/' # just ignore the 'relative' or 'absolute' tricks. 11 def get_template_text(opts) 12 src = opts[:src] 13 folder = (opts[:current_folder] && opts[:current_folder] != '') ? opts[:current_folder][1..-1].split('/') : [] 14 src = src[1..-1] if src[0..0] == '/' # just ignore the 'relative' or 'absolute' tricks. 15 url = (folder + src.split('/')).join('_') 13 16 14 if test = @strings[url .gsub('/','_')]17 if test = @strings[url] 15 18 test['src'] 16 19 else … … 55 58 def new_with_url(url, opts={}) 56 59 helper = opts[:helper] || ParserModule::DummyHelper.new 57 text, absolute_url = self. find_template_text(url,helper)60 text, absolute_url = self.get_template_text(url,helper) 58 61 current_folder = absolute_url ? absolute_url.split('/')[1..-2].join('/') : nil 59 62 self.new(text, :helper=>helper, :current_folder=>current_folder, :included_history=>[absolute_url]) … … 62 65 # Retrieve the template text in the current folder or as an absolute path. 63 66 # This method is used when 'including' text 64 def find_template_text(url, helper, current_folder=nil)67 def get_template_text(url, helper, current_folder=nil) 65 68 66 69 if (url[0..0] != '/') && current_folder … … 68 71 end 69 72 70 text = helper.send(: template_text_for_url, url) || "<span class='parser_error'>template '#{url}' not found</span>"73 text = helper.send(:get_template_text, :src=>url, :current_folder=>'') || "<span class='parser_error'>template '#{url}' not found</span>" 71 74 url = "/#{url}" unless url[0..0] == '/' # has to be an absolute path 72 75 return [text, url] … … 209 212 @options[:included_history] ||= [] 210 213 211 @text, absolute_url = self.class. find_template_text(@params[:template], @options[:helper], @options[:current_folder])214 @text, absolute_url = self.class.get_template_text(@params[:template], @options[:helper], @options[:current_folder]) 212 215 213 216 if absolute_url trunk/lib/parser/lib/rules/zafu.rb
r463 r468 74 74 def r_rename_asset 75 75 return expand_with unless @html_tag 76 unless @params[:src][0..0] == '/' 77 opts = {:src => @params[:src]} 78 case @html_tag 79 when 'link' 80 if @params[:rel].downcase == 'stylesheet' 81 opts[:type] = :stylesheet 82 else 83 opts[:type] = :link 84 end 85 else 86 opts[:type] = @html_tag.to_sym 87 end 88 opts[:current_template] = @options[:included_history].last 89 @params[:src] = @options[:helper].send(:template_url_for_asset, opts) 90 end 76 opts = {} 77 case @html_tag 78 when 'link' 79 key = :href 80 if @params[:rel].downcase == 'stylesheet' 81 opts[:type] = :stylesheet 82 else 83 opts[:type] = :link 84 end 85 else 86 key = :src 87 opts[:type] = @html_tag.to_sym 88 end 89 90 opts[:src] = @params[key] 91 if opts[:src] && opts[:src][0..0] != '/' 92 opts[:current_folder] = @options[:current_folder] 93 @params[key] = @options[:helper].send(:template_url_for_asset, opts) 94 end 95 91 96 res = "<#{@html_tag}#{params_to_html(@params)}" 92 97 @html_tag_done = true … … 243 248 flush $& 244 249 @end_tag_count += 1 unless $2 == '/' 245 elsif @text =~ /\A<(link|img|script) .*src\s*=/250 elsif @text =~ /\A<(link|img|script)/ 246 251 # puts "HTML:[#{$&}]}" # html 247 252 make(:asset) 248 253 elsif @text =~ /\A[^>]*?>/ 249 254 # html tag 255 # puts "OTHER:[#{$&}]" 250 256 store opts[:space_before] 251 257 flush $& trunk/lib/parser/test/parser_test.rb
r463 r468 33 33 testfile :zafu, :zafu_asset, :zafu_insight, :zazen 34 34 def test_single 35 do_test('zafu ', 'complex_example')35 do_test('zafu_asset', 'change_stylesheet') 36 36 end 37 37 38 def test_zazen_image_no_image 38 39 file = 'zazen' trunk/lib/parser/test/zafu_asset.yml
r279 r468 3 3 res: "this is just <h2 class='any'>a title</h2>" 4 4 5 change_stylesheet _src:6 src: "<link src='local/test.css' rel='stylesheet' type='text/css'/>"7 res: "<link rel='stylesheet' src='/test_stylesheet/local/test.css' type='text/css'/>"5 change_stylesheet: 6 src: "<link href='local/test.css' rel='stylesheet' type='text/css'/>" 7 res: "<link href='/test_stylesheet/local/test.css' rel='stylesheet' type='text/css'/>" 8 8 9 9 ignore_absolute_path: 10 src: "<link rel='stylesheet' type='text/css' src='/absolute/test.css'/>" 11 res: "<link rel='stylesheet' src='/absolute/test.css' type='text/css'/>" 10 src: "<link rel='stylesheet' type='text/css' href='/absolute/test.css'/>" 11 res: "<link href='/absolute/test.css' rel='stylesheet' type='text/css'/>" 12 13 bad_link: 14 src: "<link rel='stylesheet'/>" 15 res: "<link rel='stylesheet'/>" 12 16 13 17 change_img_src: trunk/test/functional/application_controller_test.rb
r455 r468 21 21 # visitor tested in multiple_hosts integration test 22 22 23 def test_find_template_document 24 res = @controller.instance_variable_set(:@skin_name, 'wiki') 25 assert false, "finish test" 26 end 27 23 28 def test_template_url_any_project 24 29 without_files('app/views/templates/compiled') do trunk/test/helpers/testhelp.rb
r455 r468 6 6 7 7 class TestController < ApplicationController 8 helper_method : template_text_for_url, :template_url_for_asset, :save_erb_to_url8 helper_method :get_template_text, :template_url_for_asset, :save_erb_to_url 9 9 before_filter :set_context 10 10 before_filter :authorize … … 34 34 def authorize 35 35 end 36 36 37 def set_env 37 38 end … … 55 56 end 56 57 57 def template_text_for_url(url) 58 url = url[1..-1] # strip leading '/' 59 @current_template = url 60 url = url.gsub('/','_') 61 if test = @@templates[url] 58 def get_template_text(url) 59 src = opts[:src] 60 folder = (opts[:current_folder] && opts[:current_folder] != '') ? opts[:current_folder][1..-1].split('/') : [] 61 src = src[1..-1] if src[0..0] == '/' # just ignore the 'relative' or 'absolute' tricks. 62 url = (folder + src.split('/')).join('_') 63 64 if test = @strings[url] 62 65 test['src'] 63 66 else trunk/test/unit/node_test.rb
r467 r468 109 109 login(:ant) 110 110 test_page = secure(Node) { Node.create(:name=>"yoba", :parent_id => nodes_id(:cleanWater), :inherit=>1 ) } 111 err test_page112 111 assert ! test_page.new_record? , "Not a new record" 113 112 assert_equal nodes_id(:cleanWater), test_page.parent[:id] 113 end 114 115 def test_cannot_update_v_status 116 login(:ant) 117 test_page = secure(Node) { nodes(:status) } 118 assert_equal 2, test_page.v_number 119 test_page.update_attributes( :v_status => Zena::Status[:pub], :v_title => "New funky title") 120 assert_equal 3, test_page.v_number 121 assert_equal Zena::Status[:red], test_page.v_status 114 122 end 115 123 … … 836 844 parent = secure(Project) { Project.create(:name => 'import', :parent_id => nodes_id(:zena)) } 837 845 assert !parent.new_record?, "Not a new record" 838 secure(Node) { Node.create_nodes_from_folder(:folder => File.join(RAILS_ROOT, 'test', 'fixtures', 'import'), :parent_id => parent[:id] )}846 nodes = secure(Node) { Node.create_nodes_from_folder(:folder => File.join(RAILS_ROOT, 'test', 'fixtures', 'import'), :parent_id => parent[:id] )} 839 847 children = parent.children 840 848 assert_equal 2, children.size 841 bird, simple = children 849 assert_equal 2, nodes.size 850 bird, simple = nodes 842 851 843 852 assert_equal 'bird', bird[:name] … … 845 854 assert_equal 'The sky is blue', simple.v_title 846 855 assert_equal 'jpg', bird.c_ext 847 assert_equal 'L ucy in the sky', bird.v_title848 versions = bird.versions856 assert_equal 'Le septiÚme ciel', bird.v_title 857 versions = secure(Node) { Node.find(bird[:id]) }.versions 849 858 assert_equal 2, versions.size 850 859 assert_equal 'fr', versions[0].lang … … 869 878 end 870 879 880 def test_create_nodes_from_folder_with_publish 881 login(:tiger) 882 nodes = secure(Node) { Node.create_nodes_from_folder(:folder => File.join(RAILS_ROOT, 'test', 'fixtures', 'import'), :parent_id => nodes_id(:zena) )} 883 assert_equal Zena::Status[:red], nodes[0].v_status 884 885 nodes = secure(Node) { Node.create_nodes_from_folder(:folder => File.join(RAILS_ROOT, 'test', 'fixtures', 'import'), :parent_id => nodes_id(:cleanWater), :defaults => { :v_status => Zena::Status[:pub] }) } 886 assert_equal Zena::Status[:pub], nodes[0].v_status 887 end 888 871 889 def test_create_nodes_from_archive 872 890 login(:tiger)
