Changeset 317
- Timestamp:
- 2007-02-28 12:04:25 (2 years ago)
- Files:
-
- trunk/app/controllers/application.rb (modified) (3 diffs)
- trunk/app/controllers/main_controller.rb (modified) (1 diff)
- trunk/app/models/document.rb (modified) (5 diffs)
- trunk/app/models/document_content.rb (modified) (4 diffs)
- trunk/app/models/document_version.rb (modified) (1 diff)
- trunk/app/models/node.rb (modified) (2 diffs)
- trunk/app/models/skin.rb (modified) (2 diffs)
- trunk/app/models/template.rb (modified) (2 diffs)
- trunk/app/models/text_document.rb (modified) (1 diff)
- trunk/app/models/version.rb (modified) (3 diffs)
- trunk/app/views/templates (modified) (1 prop)
- trunk/app/views/templates/compiled (deleted)
- trunk/lib/parser/lib/parser.rb (modified) (2 diffs)
- trunk/lib/parser/lib/rules/zena.rb (modified) (1 diff)
- trunk/lib/parser/test/testhelp.rb (modified) (1 diff)
- trunk/test/helpers/testhelp.rb (modified) (1 diff)
- trunk/test/unit/document_test.rb (modified) (2 diffs)
- trunk/test/unit/node_test.rb (modified) (7 diffs)
- trunk/test/unit/skin_test.rb (modified) (1 diff)
- trunk/test/unit/template_test.rb (modified) (1 diff)
- trunk/test/unit/text_document_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/application.rb
r315 r317 26 26 end 27 27 28 # TODO: test 28 29 def template_url(opts={}) 29 30 skin = opts[:skin] || 'default' … … 94 95 end 95 96 97 # TODO: test 96 98 def template_text_for_url(url) 97 99 url = url[1..-1] # strip leading '/' … … 102 104 end 103 105 skin ||= secure(Skin) { Skin.find_by_name(skin_name) } 104 template = skin.template_for_path(url )105 template .version.text106 template = skin.template_for_path(url.join('/')) 107 template ? template.version.text : nil 106 108 rescue 107 109 return nil 108 110 end 109 111 112 # TODO: implement 110 113 def template_url_for_asset(type,url) 111 return "/#{url}" # TODO IMPLEMENT 112 # current_template = @current_template || "/" 113 # we assume current_template is /projects/cleanWater for testing 114 current_template = 'projects/cleanWater' 115 path = current_template.split('/') + url.split('/') 116 doc = secure(Document) { Document.find_by_path(path)} 117 url = url_for(data_url(doc)) 118 if url =~ %r{http://test.host(.*)} 119 $1 120 else 121 url 122 end 123 end 124 114 # 1. find in current skin ? 115 # 2. find in corresponding public directory ? 116 case type 117 when :stylesheet 118 when :link 119 when :script 120 end 121 # 3. find in site ? 122 end 123 124 # TODO: implement 125 125 def save_erb_to_url(template, template_url) 126 126 "save '#{template_url}':[#{template}]" 127 127 end 128 129 130 131 132 133 134 135 136 137 138 139 128 140 129 def page_not_found trunk/app/controllers/main_controller.rb
r304 r317 17 17 def show 18 18 path = params[:path].dup 19 ref = path.pop 20 if ref =~ /[a-zA-Z\-_]+([0-9]+)(\.|$)/ 19 if path[-1..-1] =~ /[a-zA-Z\-_]+([0-9]+)(\.|$)/ 21 20 @node = secure(Node) { Node.find($1.to_i) } 22 21 else 23 path << ref # unpop ref 24 @node = secure(Node) { Node.find_by_path(path) } 22 @node = secure(Node) { Node.find_by_path(path.join('/')) } 25 23 end 26 if path == @node.basepath(true) .split('/')24 if path == @node.basepath(true) 27 25 render_and_cache 28 26 else trunk/app/models/document.rb
r316 r317 3 3 =end 4 4 class Document < Page 5 before_validation :set_name 6 before_save :update_content_name 5 before_validation :prepare_before_validation 7 6 8 7 class << self … … 12 11 13 12 alias o_create create 14 15 # TODO: test more (Templates and Skin tested without files)16 13 def create(hash) 17 14 scope = self.scoped_methods[0] || {} … … 19 16 if hash[:c_file] 20 17 content_type = hash[:c_file].content_type 21 if Image.accept_content_type?(content_type) 22 klass = Image 23 elsif Template.accept_content_type?(content_type) 24 if hash[:parent_id] && Node.find(hash[:parent_id]).kind_of?(Skin) 25 klass = Template 26 else 27 klass = Skin 28 end 29 elsif TextDocument.accept_content_type?(content_type) 30 klass = TextDocument 31 else 32 klass = Document 33 end 34 elsif hash[:name] =~ /\.html$/ 18 elsif hash[:c_content_type] 19 content_type = hash[:c_content_type] 20 elsif hash[:name] =~ /^.*\.(\w+)$/ && types = EXT_TO_TYPE[$1] 21 content_type = types[0] 22 else 23 content_type = 'text/plain' 24 end 25 if Image.accept_content_type?(content_type) 26 klass = Image 27 elsif Template.accept_content_type?(content_type) 35 28 if hash[:parent_id] && Node.find(hash[:parent_id]).kind_of?(Skin) 36 29 klass = Template 37 else 30 else 38 31 klass = Skin 39 32 end 33 elsif TextDocument.accept_content_type?(content_type) 34 klass = TextDocument 40 35 else 41 klass = TextDocument36 klass = Document 42 37 end 43 38 klass.with_scope(scope) { klass.o_create(hash) } … … 47 42 def c_file=(file) 48 43 @file = file 49 # we call 'method missing' to do normal file setting on content50 method_missing(:c_file=,file)51 44 end 52 45 … … 66 59 67 60 # Set name from filename 68 def set_name 69 return true unless new_record? 70 if self[:name] && self[:name] != "" 71 base = self[:name] 72 elsif @file 73 base = @file.original_filename 61 def prepare_before_validation 62 content = version.content 63 if new_record? 64 if self[:name] && self[:name] != "" 65 base = self[:name] 66 elsif @file 67 base = @file.original_filename 68 end 69 if base =~ /\./ 70 self[:name] = base.split('.')[0..-2].join('.') 71 ext = base.split('.').last 72 end 73 content[:name] = self[:name] 74 content[:ext] = self[:ext] 74 75 else 75 errors.add('name', 'cannot be empty') 76 return false 76 # when cannot use 'old' here as this record is not secured when spreading inheritance 77 if self[:name] != self.class.find(self[:id])[:name] && self[:name] && self[:name] != '' 78 # update all content names : 79 versions.each do |v| 80 content = v.content 81 content.name = self[:name] 82 content.save 83 end 84 end 77 85 end 78 if base =~ /\./79 self[:name] = base.split('.')[0..-2].join('.')80 c_ext = base.split('.').last81 c _name = self[:name]86 87 if @file 88 # set file 89 content.file = @file 82 90 end 83 return true84 91 end 85 92 86 def update_content_name87 # when cannot use 'old' here as this record is not secured when spreading inheritance88 if !new_record? && (self[:name] != self.class.find(self[:id])[:name])89 # update all content names :90 versions.each do |v|91 content = v.content92 content.name = self[:name]93 content.save94 end95 end96 end97 93 # This is a callback from acts_as_multiversioned 98 94 def version_class trunk/app/models/document_content.rb
r266 r317 2 2 class DocumentContent < ActiveRecord::Base 3 3 belongs_to :version 4 5 before_validation :prepare_filename 4 6 5 validate :valid_file 7 6 validates_presence_of :ext … … 41 40 end 42 41 42 def size=(s) 43 raise StandardError, "Size cannot be set. It is defined by the file size." 44 end 45 43 46 def file=(aFile) 44 47 @file = aFile 48 45 49 self[:content_type] = @file.content_type.chomp 46 50 if @file.kind_of?(StringIO) … … 49 53 self[:size] = @file.stat.size 50 54 end 51 end 52 53 def size=(s) 54 raise StandardError, "Size cannot be set. It is defined by the file size." 55 extension = self[:ext] || @file.original_filename.split('.').last 56 # is this extension valid ? 57 extensions = TYPE_TO_EXT[content_type] 58 if extensions 59 self[:ext] = extensions.include?(extension) ? extension : extensions[0] 60 else 61 self[:ext] = "???" 62 end 55 63 end 56 64 … … 89 97 90 98 private 91 92 def prepare_filename93 if new_record?94 self[:name] = version.node.name95 if @file96 # set extension97 ext = self[:ext] || @file.original_filename.split('.').last98 # is this extension valid ?99 extensions = TYPE_TO_EXT[self[:content_type]]100 if extensions101 self[:ext] = extensions.include?(ext) ? ext : extensions[0]102 else103 self[:ext] = "???"104 end105 106 true107 end108 end109 end110 99 111 100 def valid_file trunk/app/models/document_version.rb
r62 r317 2 2 # is created, both the new and the old #DocumentVersion refer to the same file (#DocumentContent) 3 3 class DocumentVersion < Version 4 before_validation_on_create :get_content5 4 validates_presence_of :content 6 5 def content_class 7 6 DocumentContent 8 7 end 9 10 private11 12 def get_content13 redaction_content unless content14 end15 8 end trunk/app/models/node.rb
r316 r317 73 73 # Find an node by it's full path. Cache 'fullpath' if found. 74 74 def find_by_path(path) 75 node = self.find_by_fullpath(path .join('/'))75 node = self.find_by_fullpath(path) 76 76 if node.nil? 77 path = path.split('/') 77 78 last = path.pop 78 79 Node.with_exclusive_scope do … … 146 147 # Same as fullpath, but the path includes the root node. 147 148 def rootpath 148 ZENA_ENV[:site_name] + "/" + fullpath149 ZENA_ENV[:site_name] + (fullpath != "" ? "/#{fullpath}" : "") 149 150 end 150 151 trunk/app/models/skin.rb
r315 r317 2 2 # of a site. 3 3 class Skin < Template 4 # opts can be :mode and :klass4 5 5 def template_url_for_name(template_name, helper) 6 6 if template_name == 'any' … … 23 23 24 24 def template_for_path(path) 25 Skin.logger.info "[#{name}] GET (#{path.inspect})"26 25 current = self 27 if path == ['any']26 if path == 'any' 28 27 return current 29 else 28 else 29 path = path.split('/') 30 30 while path != [] 31 31 template_name = path.shift 32 Skin.logger.info "[#{name}] GET ('parent_id = #{current[:id]} AND name = '#{template_name}')" 33 begin 34 current = secure(Template) { Template.find(:first, :conditions=>["parent_id = ? AND name = ?", current[:id], template_name])} 35 Skin.logger.info "OK" 36 rescue ActiveRecord::RecordNotFound 37 Skin.logger.info "NOT FOUND" 38 break 39 end 32 current = secure(Template) { Template.find(:first, :conditions=>["parent_id = ? AND name = ?", current[:id], template_name])} 40 33 end 41 if path == [] 42 current 43 else 44 nil 45 end 34 current 46 35 end 47 36 rescue ActiveRecord::RecordNotFound trunk/app/models/template.rb
r316 r317 1 1 class Template < TextDocument 2 before_validation :set_content_type 2 class << self 3 def accept_content_type?(content_type) 4 content_type == 'text/html' 5 end 6 end 7 3 8 # TODO: test 4 9 def sweep_cache … … 19 24 private 20 25 21 # TODO: test22 def set_content_type23 version.redaction_content.content_type = 'text/html'24 version.content.ext = 'html'25 version.content.name = name26 def prepare_before_validation 27 super 28 content = version.content 29 content[:content_type] = 'text/html' 30 content[:ext] = 'html' 26 31 end 27 32 end trunk/app/models/text_document.rb
r266 r317 24 24 25 25 private 26 27 def prepare_before_validation 28 super 29 content = version.content 30 content[:content_type] ||= 'text/plain' 31 content[:ext] ||= 'txt' 32 end 26 33 # This is a callback from acts_as_multiversioned 27 34 def version_class trunk/app/models/version.rb
r256 r317 71 71 @content = content_class.find_by_version_id(self[:content_id]) 72 72 else 73 content_class.find_by_version_id(self[:id]) 73 @content = content_class.find_by_version_id(self[:id]) 74 end 75 if @content 76 @content 77 else 78 # create new content 79 @content = content_class.new 80 @content.version = self 81 self[:content_id] = nil 82 @redaction_content = @content 74 83 end 75 84 end … … 83 92 @redaction_content = @content 84 93 elsif @content 94 # copy current content 85 95 @content = content.clone 86 96 @content.version = self … … 88 98 @redaction_content = @content 89 99 else 100 # create new content 90 101 @content = content_class.new 91 102 @content.version = self trunk/app/views/templates
- Property svn:ignore set to compiled
trunk/lib/parser/lib/parser.rb
r315 r317 3 3 require File.join(File.dirname(__FILE__) , 'rules', file) 4 4 end 5 module ParserModule 6 class DummyHelper 7 def initialize(strings = {}) 8 @strings = strings 9 end 10 11 def template_text_for_url(url) 12 url = url[1..-1] # strip leading '/' 13 url = url.gsub('/','_') 14 if test = @strings[url] 15 test['src'] 16 else 17 nil 18 end 19 end 20 21 def template_url_for_asset(type,url) 22 "/test_#{type}/#{url}" 23 end 24 25 def method_missing(sym, *args) 26 arguments = args.map do |arg| 27 if arg.kind_of?(Hash) 28 res = [] 29 arg.each do |k,v| 30 unless v.nil? 31 res << "#{k}:#{v.inspect.gsub(/'|"/, "|")}" 32 end 33 end 34 res.sort.join(' ') 35 else 36 arg.inspect.gsub(/'|"/, "|") 37 end 38 end 39 res = "[#{sym} #{arguments.join(' ')}]" 40 end 41 end 42 end 43 5 44 class Parser 6 45 attr_accessor :text, :method … … 16 55 end 17 56 def new_with_url(url, opts={}) 18 helper = opts[:helper] || Zafu::DummyHelper57 helper = opts[:helper] || ParserModule::DummyHelper.new 19 58 text, absolute_url = self.find_template_text(url,helper) 20 59 current_folder = absolute_url ? absolute_url.split('/')[0..-2].join('/') : '/' trunk/lib/parser/lib/rules/zena.rb
r315 r317 424 424 else 425 425 select = select[1..-1] if select[0..0] == '/' 426 do_var("secure(Node) { Node.find_by_path(#{select. split('/').inspect})} rescue nil")426 do_var("secure(Node) { Node.find_by_path(#{select.inspect})} rescue nil") 427 427 end 428 428 end trunk/lib/parser/test/testhelp.rb
r313 r317 2 2 require 'yaml' 3 3 require File.join(File.dirname(__FILE__) , '..', 'lib', 'parser') 4 5 class DummyHelper6 def initialize(strings = {})7 @strings = strings8 end9 10 def template_text_for_url(url)11 url = url[1..-1] # strip leading '/'12 url = url.gsub('/','_')13 if test = @strings[url]14 test['src']15 else16 nil17 end18 end19 20 def template_url_for_asset(type,url)21 "/test_#{type}/#{url}"22 end23 24 def method_missing(sym, *args)25 arguments = args.map do |arg|26 if arg.kind_of?(Hash)27 res = []28 arg.each do |k,v|29 unless v.nil?30 res << "#{k}:#{v.inspect.gsub(/'|"/, "|")}"31 end32 end33 res.sort.join(' ')34 else35 arg.inspect.gsub(/'|"/, "|")36 end37 end38 res = "[#{sym} #{arguments.join(' ')}]"39 end40 end41 4 42 5 class Test::Unit::TestCase trunk/test/helpers/testhelp.rb
r282 r317 60 60 end 61 61 end 62 63 def template_url_for_asset(type,url)64 # current_template = @current_template || "/"65 # we assume current_template is /projects/cleanWater for testing66 current_template = 'projects/cleanWater'67 path = current_template.split('/') + url.split('/')68 doc = secure(Document) { Document.find_by_path(path)}69 url = url_for(data_url(doc))70 if url =~ %r{http://test.host(.*)}71 $172 else73 url74 end75 end76 62 77 def save_erb_to_url(template, template_url)78 return ''79 "save '#{template_url}':[#{template}]"80 end81 63 end 82 64 trunk/test/unit/document_test.rb
r140 r317 8 8 assert Document.read_inheritable_attribute(:validate_on_create).include?(:node_on_create) 9 9 assert Document.read_inheritable_attribute(:validate_on_update).include?(:node_on_update) 10 assert Document.read_inheritable_attribute(:before_validation).include?(:set_name) 11 assert Document.read_inheritable_attribute(:before_save).include?(:update_content_name) 10 assert Document.read_inheritable_attribute(:before_validation).include?(:prepare_before_validation) 12 11 end 13 12 … … 77 76 def get_with_full_path 78 77 test_visitor(:tiger) 79 doc = secure(Document) { Document.find_by_path( visitor_id, visitor_groups, lang,"/projects/cleanWater/water.pdf") }78 doc = secure(Document) { Document.find_by_path("/projects/cleanWater/water.pdf") } 80 79 assert_kind_of Document, doc 81 80 assert_equal "/projects/cleanWater/water.pdf", doc.fullpath trunk/test/unit/node_test.rb
r299 r317 17 17 node = nodes(:wiki) 18 18 assert_nil node[:fullpath] 19 node = secure(Node) { Node.find_by_path( ['projects', 'wiki']) }19 node = secure(Node) { Node.find_by_path('projects/wiki') } 20 20 assert_equal 'projects/wiki', node.fullpath 21 node = secure(Node) { Node.find_by_path( ['projects', 'wiki']) }21 node = secure(Node) { Node.find_by_path('projects/wiki') } 22 22 assert_equal 'projects/wiki', node[:fullpath] 23 23 end … … 42 42 assert_nothing_raised { node = secure(Node) { nodes(:status) } } 43 43 assert_kind_of Node, node 44 assert_raises (ActiveRecord::RecordNotFound) { node = secure(Node) { Node.find_by_path( ['people', 'ant']) } }45 assert_nothing_raised { node = secure(Node) { Node.find_by_path( ['people', 'ant', 'status'])}}44 assert_raises (ActiveRecord::RecordNotFound) { node = secure(Node) { Node.find_by_path('people/ant') } } 45 assert_nothing_raised { node = secure(Node) { Node.find_by_path('people/ant/status')}} 46 46 end 47 47 … … 49 49 test_visitor(:ant) 50 50 node = secure(Node) { nodes(:status) } 51 assert_equal ['zena', 'projects', 'cleanWater', 'status'], node.rootpath51 assert_equal 'zena/projects/cleanWater/status', node.rootpath 52 52 node = secure(Node) { nodes(:zena) } 53 assert_equal ['zena'], node.rootpath53 assert_equal 'zena', node.rootpath 54 54 end 55 55 … … 285 285 286 286 def test_project 287 assert_equal nodes(:zena).id, secure(Node) { nodes(: wiki) }.project.id287 assert_equal nodes(:zena).id, secure(Node) { nodes(:people) }.project.id 288 288 end 289 289 … … 355 355 def test_secure_find_by_path 356 356 test_visitor(:tiger) 357 node = secure(Node) { Node.find_by_path( ['projects', 'secret']) }357 node = secure(Node) { Node.find_by_path('projects/secret') } 358 358 assert_kind_of Node, node 359 359 test_visitor(:ant) 360 assert_raise(ActiveRecord::RecordNotFound) { node = secure(Node) { Node.find_by_path( ['projects', 'secret']) }}360 assert_raise(ActiveRecord::RecordNotFound) { node = secure(Node) { Node.find_by_path('projects/secret') }} 361 361 end 362 362 … … 696 696 assert_equal 1, node.comments.size 697 697 ZENA_ENV[:allow_anonymous_comments] = false 698 assert node.can_comment?, "Anonymous cannot comment."698 assert !node.can_comment?, "Anonymous cannot comment." 699 699 ZENA_ENV[:allow_anonymous_comments] = true 700 700 assert node.can_comment?, "Anonymous can comment." … … 729 729 test_visitor(:ant) 730 730 node = secure(Node) { nodes(:status) } 731 res = {:conditions=>[" project_id = ? AND kpath NOT LIKE 'NPDI%'", 11], :order=>"name ASC"}731 res = {:conditions=>["(project_id = ?) AND (kpath NOT LIKE 'NPDI%')", 11], :order=>"name ASC"} 732 732 assert_equal res, node.relation_options({:from=>'project'}, "kpath NOT LIKE 'NPDI%'") 733 res = {:conditions=>[" parent_id = ? AND kpath NOT LIKE 'NPDI%'", 12], :order=>"name ASC"}733 res = {:conditions=>["(parent_id = ?) AND (kpath NOT LIKE 'NPDI%')", 12], :order=>"name ASC"} 734 734 assert_equal res, node.relation_options({}, "kpath NOT LIKE 'NPDI%'") 735 735 end trunk/test/unit/skin_test.rb
r280 r317 4 4 include ZenaTestUnit 5 5 6 # Replace this with your real tests. 7 def test_truth 8 assert true 6 def test_template_url_for_name 7 without_files('app/views/templates/compiled') do 8 skin = secure(Skin) { Skin.find_by_name('wiki')} 9 assert_kind_of Skin, skin 10 path = File.join(RAILS_ROOT, 'app', 'views', 'templates', 'compiled', 'wiki', 'any_en.rhtml') 11 assert !File.exist?(path), "File does not exist" 12 assert_equal "/templates/compiled/wiki/any_en", skin.template_url_for_name('any', nil) 13 assert File.exist?(path), "File exists" 14 path = File.join(RAILS_ROOT, 'app', 'views', 'templates', 'compiled', 'wiki', 'layout_en.rhtml') 15 assert !File.exist?(path), "File does not exist" 16 assert_equal "/templates/compiled/wiki/layout_en", skin.template_url_for_name('layout', nil) 17 assert File.exist?(path), "File exists" 18 assert_equal nil, skin.template_url_for_name('bad', nil) 19 end 20 end 21 22 def test_template_for_path 23 skin = secure(Skin) { Skin.find_by_name('wiki')} 24 assert_kind_of Skin, skin 25 tmpl = skin.template_for_path('any') 26 assert_equal tmpl, skin 27 tmpl = skin.template_for_path('layout') 28 assert_equal nodes_id(:wiki_layout), tmpl[:id] 29 tmpl = skin.template_for_path('bad') 30 assert_nil tmpl 9 31 end 10 32 end trunk/test/unit/template_test.rb
r313 r317 2 2 3 3 class TemplateTest < Test::Unit::TestCase 4 5 # Replace this with your real tests. 6 def test_truth 7 assert true 4 include ZenaTestUnit 5 6 def test_create_simplest 7 test_visitor(:tiger) 8 doc = secure(Document) { Document.create(:parent_id=>nodes_id(:cleanWater), :name=>'skiny.html')} 9 assert_kind_of Skin, doc 10 assert !doc.new_record?, "Not a new record" 11 assert_equal 'text/html', doc.c_content_type 12 assert_equal 'html', doc.c_ext 13 sub = secure(Document) { Document.create(:parent_id=>doc[:id], :name=>'sub', :c_content_type=>'text/html')} 14 assert_kind_of Template, sub 15 assert !sub.kind_of?(Skin) 16 assert !sub.new_record?, "Not a new record" 17 end 18 19 def test_create_with_file 20 test_visitor(:tiger) 21 doc = secure(Document) { Document.create(:parent_id=>nodes_id(:cleanWater), :name=>'skiny', 22 :c_file=>uploaded_file('some.txt', content_type="text/html", 'smoke'))} 23 assert_kind_of Skin, doc 24 assert !doc.new_record?, "Not a new record" 25 assert_equal 'text/html', doc.c_content_type 26 assert_equal 'html', doc.c_ext 27 assert_equal 'skiny.html', doc.c_filename 28 sub = secure(Document) { Document.create(:parent_id=>doc[:id], :name=>'sub.html')} 29 assert_kind_of Template, sub 30 assert !sub.kind_of?(Skin) 31 assert !sub.new_record?, "Not a new record" 8 32 end 9 33 end trunk/test/unit/text_document_test.rb
r316 r317 3 3 class TextDocumentTest < Test::Unit::TestCase 4 4 include ZenaTestUnit 5 6 # Replace this with your real tests. 5 6 def test_callbacks_for_documents 7 assert Node.read_inheritable_attribute(:before_validation).include?(:secure_before_validation) 8 assert TextDocument.read_inheritable_attribute(:validate_on_create).include?(:node_on_create) 9 assert TextDocument.read_inheritable_attribute(:validate_on_update).include?(:node_on_update) 10 assert TextDocument.read_inheritable_attribute(:before_validation).include?(:prepare_before_validation) 11 end 12 7 13 def test_create_simplest 8 14 test_visitor(:tiger) 9 15 doc = secure(Document) { Document.create(:parent_id=>nodes_id(:cleanWater), :name=>'skiny')} 10 assert_kind_of TextDocument, doc 16 assert_equal TextDocument, doc.class 17 err doc 11 18 assert !doc.new_record?, "Not a new record" 12 19 end 13 20 14 def test_create_template 15 test_visitor(:tiger) 16 doc = secure(Document) { Document.create(:parent_id=>nodes_id(:cleanWater), :name=>'skiny.html')} 17 assert_kind_of Skin, doc 18 assert !doc.new_record?, "Not a new record" 19 assert_equal 'text/html', doc.c_content_type 20 assert_equal 'html', doc.c_ext 21 sub = secure(Document) { Document.create(:parent_id=>doc[:id], :name=>'sub.html')} 22 assert_kind_of Template, sub 23 assert !sub.kind_of?(Skin) 24 assert !sub.new_record?, "Not a new record" 21 def test_create_with_file 22 next_id = Version.find(:first, :order=>"id DESC")[:id] + 1 23 doc = secure(Document) { Document.create( :parent_id=>nodes_id(:cleanWater), 24 :v_title => 'My new project', 25 :c_file => uploaded_text('some.txt', 'stupid.jpg') ) } 26 assert_equal TextDocument, doc.class 27 assert !File.exist?(doc.c_filepath), "No file created" 28 assert_equal 'txt', doc.c_ext 29 assert_equal 'text/plain', doc.c_content_type 30 assert_equal 'stupid.txt', doc.c_filename 31 end 32 33 def test_content_lang 34 doc = secure(Document) { Document.create( :parent_id=>nodes_id(:cleanWater), :v_title => 'super script', 35 :c_content_type => 'text/x-ruby-script')} 36 assert_equal TextDocument, doc.class 37 assert_equal 'ruby', doc.content_lang 38 39 doc = secure(Document) { Document.create( :parent_id=>nodes_id(:cleanWater), :v_title => 'super script', 40 :c_content_type => 'text/html')} 41 assert_equal Skin, doc.class 42 assert_equal 'zafu', doc.content_lang 25 43 end 26 44 end
