Changeset 1103
- Timestamp:
- 2008-07-17 22:29:08 (6 months ago)
- Files:
-
- trunk/app/controllers/links_controller.rb (modified) (2 diffs)
- trunk/app/models/link.rb (modified) (2 diffs)
- trunk/app/models/node.rb (modified) (1 diff)
- trunk/app/models/relation_proxy.rb (modified) (8 diffs)
- trunk/app/views/links/_form.rhtml (modified) (3 diffs)
- trunk/app/views/links/_li.rhtml (modified) (1 diff)
- trunk/app/views/links/show.rjs (modified) (1 diff)
- trunk/config/awstats.conf.rhtml (modified) (1 diff)
- trunk/lib/has_relations.rb (modified) (7 diffs)
- trunk/lib/multiversion.rb (modified) (1 diff)
- trunk/lib/node_query.rb (modified) (1 diff)
- trunk/lib/parser/lib/rules/zena.rb (modified) (2 diffs)
- trunk/public/stylesheets/popup.css (modified) (1 diff)
- trunk/test/functional/links_controller_test.rb (modified) (1 diff)
- trunk/test/helpers/node_query_test.rb (modified) (1 diff)
- trunk/test/unit/link_test.rb (modified) (3 diffs)
- trunk/test/unit/node_test.rb (modified) (1 diff)
- trunk/test/unit/relation_proxy_test.rb (modified) (7 diffs)
- trunk/test/zena_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/links_controller.rb
r1048 r1103 47 47 @node.errors.add('base', 'you do not have the rights to do this') 48 48 else 49 @link_id = params [:link_id]49 @link_id = params.link_id 50 50 @node.remove_link(@link_id) 51 51 @node.save … … 57 57 58 58 def destroy 59 @node.remove_link(@link [:id])59 @node.remove_link(@link) 60 60 @node.save 61 61 trunk/app/models/link.rb
r1101 r1103 1 1 class Link < ActiveRecord::Base 2 2 attr_reader :relation 3 attr_accessor :start, :side 3 4 4 5 class << self 5 6 def find_through(node, link_id) 6 7 return nil unless link = Link.find(:first, :conditions => ['(source_id = ? OR target_id = ?) AND id = ?', node[:id], node[:id], link_id]) 7 link.set_caller(node) 8 link.start = node 9 node.link = link 8 10 link 9 11 end … … 11 13 12 14 def update_attributes_with_transformations(attrs) 13 attributes = attrs.dup 14 keys = attributes.keys 15 ['role', 'status', 'comment', 'other_zip'].each do |k| 16 if keys.include?(k) 17 self[k] = attributes[k] = attrs[k].blank? ? nil : attrs[k] 15 return false unless @node 16 17 if attrs['role'] 18 # TODO: destroy this link and create a new one ? 19 end 20 21 rel = @node.relation_proxy_from_link(self) 22 rel.other_link = self 23 24 ['status', 'comment'].each do |k| 25 rel.send("other_#{k}=", attrs[k]) if attrs.has_key?(k) 26 self[k] = attrs[k] 27 end 28 29 if attrs['other_zip'] 30 other_id = secure(Node) { Node.translate_pseudo_id(attrs['other_zip']) } 31 rel.other_id = other_id 32 if @side == :source 33 self[:target_id] = other_id 34 @target = nil 18 35 else 19 attributes[k] = self[k] 36 self[:source_id] = other_id 37 @source = nil 20 38 end 21 39 end 22 debugger23 if attributes['other_zip']24 other_id = secure(Node) { Node.translate_pseudo_id(attributes['other_zip']) }25 else26 other_id = @other[:id]27 end28 40 29 # ALL THIS IS BAD. Bad design lead to bad hacky code. PLEASE rewrite links !30 @node.update_link(attributes['role'], :id => other_id, :status => attributes['status'], :comment => attributes['comment'])31 41 @node.save 32 if @other == @target 33 self[:target_id] = other_id 34 self[:id] = Link.find(:first, :conditions => ['target_id = ? AND relation_id = ?', other_id, relation_id])[:id] 35 @target = nil 36 else 37 self[:source_id] = other_id 38 self[:id] = Link.find(:first, :conditions => ['source_id = ? AND relation_id = ?', other_id, relation_id])[:id] 39 @source = nil 40 end 41 sync_node 42 @node.link = self 42 43 @errors = @node.errors 44 return errors.empty? 43 45 end 44 46 45 47 def target 46 @target ||= secure!(Node) { Node.find(target_id) } 48 @target ||= begin 49 node = secure!(Node) { Node.find(target_id) } 50 node.link = self 51 node 52 end 47 53 end 48 54 49 55 def source 50 @source ||= secure!(Node) { Node.find(source_id) } 56 @source ||= begin 57 node = secure!(Node) { Node.find(source_id) } 58 node.link = self 59 node 60 end 51 61 end 52 62 53 def s et_caller(node)63 def start=(node) 54 64 @node = node 55 @relation = @node.relation_proxy(:link => self) 56 self['role'] = @relation.other_role 57 sync_node 65 if @node[:id] == self[:source_id] 66 @side = :source 67 @source = @node 68 else 69 @side = :target 70 @target = @node 71 end 58 72 end 59 73 60 74 def other 61 @other 75 @side == :source ? target : source 76 end 77 78 def this 79 @side == :source ? source : target 62 80 end 63 81 64 82 def other_zip 65 self['other_zip']83 other[:zip] 66 84 end 67 85 68 def node_zip69 self['node_zip']86 def this_zip 87 this[:zip] 70 88 end 71 89 72 private 73 def sync_node 74 if source_id == @node[:id] 75 @other = target 90 def relation_proxy(node=nil) 91 return @relation_proxy if defined?(@relation_proxy) 92 rel = RelationProxy.find(self[:relation_id]) 93 @node = node if node 94 if @node 95 if self[:source_id] == @node[:id] 96 rel.side = :source 76 97 else 77 @other = source98 rel.side = :target 78 99 end 79 self['node_zip'] = @node[:zip] 80 self['other_zip'] = @other.zip 81 @other.link = self # used to get l_status, l_comment after save 82 @node.link = self 100 rel.start = @node 83 101 end 102 @relation_proxy = rel 103 end 104 105 def role 106 relation_proxy.other_role 107 end 84 108 end trunk/app/models/node.rb
r1096 r1103 603 603 false 604 604 else 605 relation = Relation .find_by_role(rel.singularize)605 relation = RelationProxy.find_by_role(rel.singularize) 606 606 return rel =~ /s$/ unless relation 607 607 relation.target_role == rel.singularize ? !relation.target_unique : !relation.source_unique trunk/app/models/relation_proxy.rb
r1102 r1103 1 1 class RelationProxy < Relation 2 attr_accessor :side, :link_errors, :start, : link2 attr_accessor :side, :link_errors, :start, :other_link 3 3 4 4 class << self … … 71 71 end 72 72 73 # When a ...-to-many node is loaded and we modify it, focus on this specific node. For example: 74 # calendar_status does not make sense (there can be many calendars). But if we focus on a specific 75 # calendar, we then get the status for this particular link. 76 def other_link=(link) 77 return unless link[:relation_id] == self[:id] 78 @other_link = link 79 end 80 73 81 # get 74 82 … … 121 129 def other_ids=(v) 122 130 self.other_id = v 131 end 132 133 def remove_link(link) 134 @links_to_delete ||= [] 135 @links_to_delete << link 123 136 end 124 137 … … 148 161 # 2. can write in new target 149 162 def attributes_to_update_valid? 150 return true unless @attributes_to_update 151 152 unless @attributes_to_update[:id] 153 # try to find current id/ids 154 if unique? 155 if other_id 156 @attributes_to_update[:id] = other_id 157 else 158 @link_errors = ["Cannot set attributes #{@attributes_to_update.keys.join(', ')} without a target (missing id)."] 159 end 160 else 161 # error: cannot set other attributes (status/comment) on multiple nodes 162 @link_errors = ["Cannot set attributes #{@attributes_to_update.keys.join(', ')} in #{as_unique? ? 'one' : 'many'}-to-many relation '#{this_role}'."] 163 end 164 end 165 166 if @attributes_to_update[:id].kind_of?(Array) 167 if unique? 168 @link_errors = ["Cannot set multiple targets on #{as_unique? ? 'one' : 'many'}-to-one relation '#{this_role}'."] 169 elsif @attributes_to_update.keys.include?(:status) || @attributes_to_update.keys.include?(:comment) 170 keys = @attributes_to_update.keys 171 keys.delete(:id) 172 @link_errors = ["Cannot set attributes #{keys.join(', ')} on multiple targets."] 173 end 174 end 175 176 return false if @link_errors 163 debugger if $debbbb 164 return true unless @attributes_to_update || @links_to_delete 165 177 166 @link_errors = [] 178 167 @add_links = [] … … 180 169 @update_links = [] 181 170 182 # 1. find what changed 183 if @attributes_to_update[:id].kind_of?(Array) 184 # ..-to-many 185 # define all links 171 if @links_to_delete 172 # only removing links 173 @del_links = @links_to_delete 174 @attributes_to_update = {} 175 else 176 # check if we have an update/create 177 unless @attributes_to_update[:id] 178 # try to find current id/ids 179 if @other_link 180 @attributes_to_update[:id] = @other_link[other_side] 181 elsif link_id = @start.link_id 182 @other_link = Link.find(link_id) 183 @attributes_to_update[:id] = @other_link[other_side] 184 elsif unique? 185 if other_id 186 @attributes_to_update[:id] = other_id 187 else 188 @link_errors << "invalid target" 189 end 190 else 191 # error: cannot set other attributes (status/comment) on multiple nodes 192 @link_errors << "invalid target" 193 end 194 end 195 196 if @attributes_to_update[:id].kind_of?(Array) 197 if unique? 198 @link_errors << "Cannot set multiple targets on #{as_unique? ? 'one' : 'many'}-to-one relation '#{this_role}'." 199 elsif @attributes_to_update.has_key?(:status) || @attributes_to_update.has_key?(:comment) 200 keys = @attributes_to_update.keys 201 keys.delete(:id) 202 @link_errors << "Cannot set attributes #{keys.join(', ')} on multiple targets." 203 end 204 end 205 206 return false if @link_errors != [] 207 208 # 1. find what changed 209 if @attributes_to_update[:id].kind_of?(Array) 210 # ..-to-many 211 # define all links 186 212 187 # list of link ids set188 add_link_ids = @attributes_to_update[:id]213 # list of link ids set 214 add_link_ids = @attributes_to_update[:id] 189 215 190 # find all current links 191 other_links.each do |link| 192 obj_id = link[other_side] 193 if add_link_ids.include?(obj_id) 194 # ignore existing links 195 add_link_ids.delete(obj_id) 216 # find all current links 217 other_links.each do |link| 218 obj_id = link[other_side] 219 if add_link_ids.include?(obj_id) 220 # ignore existing links 221 add_link_ids.delete(obj_id) 222 else 223 # remove unused links 224 @del_links << link 225 end 226 end 227 @add_links = add_link_ids.map {|obj_id| Hash[:id,obj_id] } 228 elsif unique? 229 # ..-to-one 230 # define/update link 231 if other_id == @attributes_to_update[:id] 232 # same target: update 233 @update_links << changed_link(other_link, @attributes_to_update) 196 234 else 197 # remove unused links 198 @del_links << link 199 end 200 end 201 @add_links = add_link_ids.map {|obj_id| Hash[:id,obj_id] } 202 elsif unique? 203 # ..-to-one 204 # define/update link 205 if other_id == @attributes_to_update[:id] 206 # same target: update 207 @update_links << changed_link(other_link, @attributes_to_update) 208 else 209 # other target: replace 210 @del_links = [other_link] 211 @add_links << @attributes_to_update 212 end 213 else 214 # ..-to-many 215 # add/update a link 216 if other_ids.include?(@attributes_to_update[:id]) 217 # update 218 if @attributes_to_update.keys.include?(:status) || @attributes_to_update.keys.include?(:comment) 219 other_links.each do |link| 220 if link[other_side] == @attributes_to_update[:id] 221 @update_links << changed_link(link, @attributes_to_update) 222 break 235 # other target: replace 236 @del_links = [other_link] if other_link 237 @add_links << @attributes_to_update 238 end 239 else 240 # ..-to-many 241 # add/update a link 242 if other_ids.include?(@attributes_to_update[:id]) 243 # update 244 if @attributes_to_update.has_key?(:status) || @attributes_to_update.has_key?(:comment) 245 other_links.each do |link| 246 if link[other_side] == @attributes_to_update[:id] 247 @update_links << changed_link(link, @attributes_to_update) 248 break 249 end 223 250 end 224 251 end 225 e nd226 else227 # add228 @add_links << @attributes_to_update229 end 230 end 252 else 253 # add 254 @add_links << @attributes_to_update 255 end 256 end 257 end 231 258 232 259 # 2. can write in new target ? (and remove targets previous link) … … 243 270 end 244 271 end 245 272 246 273 # 1. can remove old link ? 247 274 @del_links.each do |link| … … 255 282 end 256 283 284 # Return updated link if changed or nil when nothing changed 257 285 def changed_link(link, attrs) 258 286 changed = false 259 287 [:status, :comment].each do |sym| 260 next unless attrs. keys.include?(sym)288 next unless attrs.has_key?(sym) 261 289 if attrs[sym] != link[sym] 262 290 changed = true … … 280 308 end 281 309 Link.connection.execute "INSERT INTO links (`relation_id`,`#{link_side}`,`#{other_side}`,`status`,`comment`) VALUES #{list.join(',')}" 282 remove_instance_variable(:@attributes_to_update) 310 @attributes_to_update = nil 311 @links_to_delete = nil 283 312 remove_instance_variable(:@records) if defined?(@records) 284 313 remove_instance_variable(:@record) if defined?(@record) trunk/app/views/links/_form.rhtml
r1048 r1103 1 1 <td class='inline_form' colspan='5'> 2 2 <% if @link %> 3 <%= form_remote_tag(:url=> node_link_path(:node_id => @link ['node_zip'], :id => @link[:id])) %>3 <%= form_remote_tag(:url=> node_link_path(:node_id => @link.this_zip, :id => @link[:id])) %> 4 4 <input type='hidden' name='_method' value ='put'/> 5 5 <% else %> … … 10 10 <div class='add'> 11 11 <%= if @link 12 link_to_remote _('btn_x'), :url => node_link_path(:node_id => @link ['node_zip'], :id => @link[:id]), :method => :get12 link_to_remote _('btn_x'), :url => node_link_path(:node_id => @link.this_zip, :id => @link[:id]), :method => :get 13 13 else 14 14 link_to_function _('btn_x'), "['add_link', 'add_link_form'].each(Element.toggle);" … … 21 21 roles.unshift ['tag', 'tags'] 22 22 end -%> 23 <% if !@link || @link.new_record? -%> 23 24 <li> 24 <% if !@link || @link.new_record? -%> 25 <%= select('link', 'role', roles, :selected => @link ? @link['role'] : '') %> 26 <% else -%> 27 <input type='hidden' name='link[role]' value='<%= @link['role'] %>'/> 28 <b><%= @link['role'] %></b> 29 <% end -%> 25 <%= select('link', 'role', roles, :selected => @link ? @link.role : '') %> 30 26 <%= select_id('link', 'other_zip') %> 31 27 </li> 32 <li><label for='link_comment'><%= _('status')%></label><%= text_field('link', 'status', :size=>15 ) %></li> 28 <% else -%> 29 <li> 30 <label for='link_role'><%= @link.role %></label> 31 <%= select_id('link', 'other_zip') %> 32 </li> 33 <% end -%> 34 <li><label for='link_status'><%= _('status')%></label><%= text_field('link', 'status', :size=>15 ) %></li> 33 35 <li><label for='link_comment'><%= _('comment')%></label><%= text_field('link', 'comment', :size=>15 ) %></li> 34 36 <li><input type="submit" class="btn_validate" value='<%= _('set') %>'/></li> trunk/app/views/links/_li.rhtml
r980 r1103 1 <tr id='link<%= li [:link_id]%>'>2 <td class="box"><%= link_to_remote( relation.other_icon.blank? ? _('img_link') : relation.other_icon, :update=>"link#{li [:link_id]}", :url=>node_edit_link_path(:node_id => @node[:zip], :id => li[:link_id]), :method=>:get) %></td>1 <tr id='link<%= li.link_id %>'> 2 <td class="box"><%= link_to_remote( relation.other_icon.blank? ? _('img_link') : relation.other_icon, :update=>"link#{li.link_id}", :url=>node_edit_link_path(:node_id => @node[:zip], :id => li.link_id), :method=>:get) %></td> 3 3 <td class="path" ><%= link_to( li.rootpath, zen_path(li), :popup=>true ) %></td> 4 4 <td class="status" ><%= li.l_status %></td> 5 5 <td class="comment" ><%= li.l_comment %></td> 6 <td class="actions"> <%= link_to_remote(_('btn_tiny_del'), :url => node_link_path(:node_id => @node[:zip],:id => li [:link_id]), :method => :delete) %> </td>6 <td class="actions"> <%= link_to_remote(_('btn_tiny_del'), :url => node_link_path(:node_id => @node[:zip],:id => li.link_id), :method => :delete) %> </td> 7 7 </tr> trunk/app/views/links/show.rjs
r1048 r1103 1 1 if @node.errors.empty? 2 page.replace "link#{params[:id]}", :partial=>'links/li', :collection=>[@link.other], :locals => {:relation => @link.relation }2 page.replace "link#{params[:id]}", :partial=>'links/li', :collection=>[@link.other], :locals => {:relation => @link.relation_proxy } 3 3 else 4 4 page.replace_html 'link_errors', :inline=> @errors ? render_errors : error_messages_for(@node) trunk/config/awstats.conf.rhtml
r1098 r1103 554 554 # Default: "" 555 555 # 556 OnlyFiles="REGEX[^\/([^o][^o]\/|[^o].\/|.[^o]\/)]" 556 OnlyFiles="REGEX[^\/([^o].(\/|$)|.[^o](\/|$))]" 557 557 558 558 559 trunk/lib/has_relations.rb
r1102 r1103 47 47 module InstanceMethods 48 48 49 # status defined through loading link 50 def l_status 51 val = @link ? @link[:status] : self['l_status'] 52 val ? val.to_i : nil 53 end 54 55 # comment defined through loading link 56 def l_comment 57 @link ? @link[:comment] : self['l_comment'] 58 end 59 60 def link_id 61 @link ? @link[:id] : self[:link_id] 62 end 63 64 def link_id=(v) 65 if @link && @link[:id].to_i != v.to_i 66 @link = nil 67 end 68 self[:link_id] = v.to_i 69 if @link_attributes_to_update 70 if rel = relation_proxy_from_link 71 @link_attributes_to_update.each do |k,v| 72 rel.send("other_#{k}=",v) 73 end 74 end 75 end 76 end 77 78 def add_link(role, hash) 79 if rel = relation_proxy(role) 80 [:status, :comment, :id].each do |k| 81 rel.send("other_#{k}=", hash[k]) if hash.has_key?(k) 82 end 83 else 84 errors.add(role, 'invalid relation') 85 end 86 end 87 88 def remove_link(link) 89 if link[:source_id] != self[:id] && link[:target_id] != self[:id] 90 errors.add('link', "not related to this node") 91 return false 92 end 93 # find proxy 94 if rel = relation_proxy_from_link(link) 95 rel.remove_link(link) 96 else 97 errors.add('link', "cannot remove (relation proxy not found).") 98 end 99 end 100 101 def l_comment=(v) 102 if rel = relation_proxy_from_link 103 rel.other_comment = v.blank? ? nil : v 104 else 105 @l_comment = v.blank? ? nil : v 106 end 107 end 108 109 def l_status=(v) 110 if rel = relation_proxy_from_link 111 rel.other_status = v.blank? ? nil : v 112 else 113 @l_status = v.blank? ? nil : v 114 end 115 end 116 49 117 def all_relations 50 118 @all_relations ||= self.vclass.all_relations(self) … … 73 141 return @relation_proxies[role] if @relation_proxies.has_key?(role) 74 142 @relation_proxies[role] = RelationProxy.get_proxy(self, role.singularize.underscore) 143 end 144 145 def relation_proxy_from_link(link = nil) 146 unless link 147 if @link 148 link = @link 149 elsif self.link_id 150 link = @link = Link.find_through(self, self.link_id) 151 end 152 return nil unless link 153 end 154 @relation_proxies ||= {} 155 return @relation_proxies[link.role] if @relation_proxies.has_key?(link.role) 156 @relation_proxies[link.role] = link.relation_proxy(self) 157 end 158 159 def remove_link(link) 160 if link[:source_id] != self[:id] && link[:target_id] != self[:id] 161 errors.add('link', "not related to this node") 162 return false 163 end 164 # find proxy 165 if rel = relation_proxy_from_link(link) 166 rel.remove_link(link) 167 else 168 errors.add('link', "cannot remove (relation proxy not found).") 169 end 75 170 end 76 171 … … 107 202 # not used to set relations (must use 'translate_attributes' to chagen zip into id before call) 108 203 raise err 109 when 'id', 'ids', 'zip', 'zips'110 if field[-1..-1] == 's'111 # plural112 raise err if rel.unique?113 else114 # singular115 raise err if !rel.unique?116 end117 else118 # comment, status: must be singular119 raise err if !rel.unique?120 204 end 121 205 # set value … … 123 207 else 124 208 # get 125 case field 126 when 'id', 'ids', 'zip', 'zips' 127 if field[-1..-1] == 's' 128 # plural 129 raise err if rel.unique? 209 if field != 'ids' && field != 'zips' && !rel.unique? 210 # ask for a single value in a ..-to-many relation 211 # 1. try to use focus 212 if @link 213 rel.other_link = @link 214 elsif self.link_id 215 @link = Link.find_through(self, self.link_id) 216 rel.other_link = @link 130 217 else 131 # singular 132 raise err if !rel.unique? 218 return nil 133 219 end 134 else135 # comment, status: must be singular136 raise err if !rel.unique?137 220 end 138 221 rel.send("other_#{field}") … … 292 375 alias update_link set_relation 293 376 294 def remove_link(link_id) 295 @relations_to_update ||= [] 296 @relations_to_update << [:remove, link_id] 297 end 298 299 def add_link(role, value) 300 @relations_to_update ||= [] 301 @relations_to_update << [:add, [role, value]] 302 end 377 303 378 304 379 def all_relations … … 331 406 if role = opts[:role] 332 407 if opts[:ignore_source] 333 rel = Relation .find_by_role(role.singularize.underscore)408 rel = RelationProxy.find_by_role(role.singularize.underscore) 334 409 else 335 410 rel = Relation.get_proxy(self, role.singularize.underscore) … … 352 427 end 353 428 354 # status defined through loading link355 def l_status356 val = @link ? @link[:status] : self['l_status']357 val ? val.to_i : nil358 end359 360 # comment defined through loading link361 def l_comment362 @link ? @link[:comment] : self['l_comment']363 end364 365 429 # ALL THIS IS HORRIBLE CODE. NEED MORE TIME TO REWRITE THIS BIG MESS... 366 def l_status=(v) 367 self[:l_status] = v 368 @link_to_update ||= {} 369 @link_to_update[:status] = v 370 end 371 372 def l_comment=(v) 373 self[:l_comment] = v 374 @link_to_update ||= {} 375 @link_to_update[:comment] = v 376 end 377 378 def link_id 379 @link ? @link[:id] : self[:link_id] 380 end 381 382 def link_id=(v) 383 if @link && @link[:id].to_i != v.to_i 384 @link = nil 385 end 386 self[:link_id] = v.to_i 387 @link_to_update ||= {} 388 @link_to_update[:id] = v.to_i 389 end 430 390 431 391 432 private trunk/lib/multiversion.rb
r1097 r1103 335 335 next 336 336 end 337 current_value = self.send(k) rescue nil # remove rescue when link is fixed337 current_value = self.send(k) rescue nil 338 338 case current_value.class.to_s 339 339 when 'NilClass' trunk/lib/node_query.rb
r1102 r1103 258 258 if type == 'RELATION_ID' 259 259 role = value 260 if rel = Relation .find_by_role(role.singularize)260 if rel = RelationProxy.find_by_role(role.singularize) 261 261 rel[:id] 262 262 else trunk/lib/parser/lib/rules/zena.rb
r1102 r1103 101 101 def self.zafu_readable?(sym) 102 102 if sym.to_s =~ /(.*)_zips?$/ 103 return true if self.ancestors.include?(Node) && Relation .find_by_role($1.singularize)103 return true if self.ancestors.include?(Node) && RelationProxy.find_by_role($1.singularize) 104 104 end 105 105 self.zafu_readable_attributes.include?(sym.to_s) … … 1838 1838 # plural 1839 1839 do_list( build_finder_for(count, method, @params) ) 1840 # elsif count == :count 1841 # "<%= #{build_finder_for(count, method, @params)} %>" 1840 1842 else 1841 1843 # singular trunk/public/stylesheets/popup.css
r1094 r1103 168 168 169 169 .inline_form ul { list-style:none; text-align:left;} 170 # add_link_form label, #add_link_formselect {float:left; width:70px; margin-right:5px;}170 #links label, #links select {float:left; width:70px; margin-right:5px;} 171 171 172 172 trunk/test/functional/links_controller_test.rb
r970 r1103 15 15 def test_create 16 16 login(:lion) 17 node = secure!(Node) { nodes(: people) }18 assert_nil node.find(:first, ' icon')19 post 'create', 'node_id' => nodes_zip(: people), 'link' => {'other_zip' => 'bird', 'role' => 'icon', 'comment' => 'super icon'}17 node = secure!(Node) { nodes(:letter) } 18 assert_nil node.find(:first, 'calendar') 19 post 'create', 'node_id' => nodes_zip(:letter), 'link' => {'other_zip' => nodes_zip(:zena).to_s, 'role' => 'calendar', 'comment' => 'super icon'} 20 20 assert_response :success 21 node = secure!(Node) { nodes(:people) } 22 assert icon = node.find(:first, 'icon') 23 assert_equal nodes_id(:bird_jpg), icon[:id] 24 assert_equal 'super icon', icon.l_comment 25 assert_nil icon.l_status 21 node = assigns(:node) 22 puts node.errors.inspect 23 node = secure!(Node) { nodes(:letter) } 24 assert calendar = node.find(:first, 'calendar') 25 assert_equal nodes_id(:zena), calendar[:id] 26 assert_equal 'super icon', calendar.l_comment 27 assert_nil calendar.l_status 28 end 29 30 def test_show 31 login(:lion) 32 get 'show', 'id'=>links_id(:opening_in_art), 'node_id'=>nodes_zip(:art) 33 assert_response :success 26 34 end 27 35 end trunk/test/helpers/node_query_test.rb
r1042 r1103 44 44 45 45 end 46 47 def test_find_new_record 48 login(:tiger) 49 node = secure!(Node) { Node.new } 50 assert_equal nil, node.find(:all,'set_tags') 51 node = secure!(Node) { Node.get_class('Tag').new_instance } 52 assert_equal nil, node.find(:all,'tagged') 53 end 54 55 def test_do_find_in_new_node 56 login(:tiger) 57 assert var1_new = secure!(Node) { Node.get_class("Post").new } 58 assert_nil var1_new.do_find(:all, eval("\"#{Node.build_find(:all, 'posts in site', :node_name => 'self')}\"")) 59 end 60 61 def test_link_id 62 login(:tiger) 63 page = secure!(Node) { nodes(:cleanWater) } 64 pages = page.find(:all, 'pages') 65 assert_nil pages[0].link_id 66 tags = page.find(:all, 'set_tags') 67 assert_equal [links_id(:cleanWater_in_art).to_s], tags.map{|r| r.link_id} 68 end 69 70 def test_do_find_bad_relation 71 login(:lion) 72 node = secure!(Node) { nodes(:status) } 73 assert_nil node.find(:first, 'blah') 74 end 75 76 def test_l_status 77 login(:lion) 78 node = secure!(Node) { nodes(:art) } 79 tagged = node.find(:all, 'tagged') 80 # cleanWater, opening 81 assert_equal [10, 5], tagged.map{|t| t.l_status} 82 end 83 84 def test_l_comment 85 login(:lion) 86 node = secure!(Node) { nodes(:opening) } 87 tagged = node.find(:all, 'set_tags') 88 # art, news 89 assert_equal ["cold", "hot"], tagged.map{|t| t.l_comment} 90 end 91 92 def test_l_comment_empty 93 login(:lion) 94 node = secure!(Node) { nodes(:art) } 95 tagged = node.find(:all, 'tagged') 96 # cleanWater, opening 97 assert_equal [nil, "cold"], tagged.map{|t| t.l_comment} 98 end 46 99 47 100 make_tests trunk/test/unit/link_test.rb
r1048 r1103 6 6 node = secure!(Node) { nodes(:cleanWater) } 7 7 link = Link.find_through(node, links_id(:status_hot_for_cleanWater)) 8 assert_equal 'hot', link ['role']8 assert_equal 'hot', link.role 9 9 end 10 10 … … 15 15 link = Link.find_through(node, links_id(:status_hot_for_cleanWater)) 16 16 link.update_attributes_with_transformations('role' => 'hot', 'other_zip' => nodes_zip(:lake), 'comment' => 'pop') 17 assert_equal 'hot', link ['role']18 assert_equal nodes_zip(:lake), link ['other_zip']19 # change propagated to caller node. Yes, this is ugly, please rewrite...17 assert_equal 'hot', link.role 18 assert_equal nodes_zip(:lake), link.other_zip 19 # change propagated to caller node. 20 20 assert_equal 'pop', node.l_comment 21 21 node = secure!(Node) { nodes(:cleanWater) } … … 27 27 node = secure!(Node) { nodes(:zena) } 28 28 assert link = Link.find_through(node, links_id(:opening_in_zena)) 29 assert_equal nodes_zip(:zena), link ['node_zip']30 assert_equal nodes_zip(:opening), link ['other_zip']29 assert_equal nodes_zip(:zena), link.this_zip 30 assert_equal nodes_zip(:opening), link.other_zip 31 31 end 32 32 end trunk/test/unit/node_test.rb
r1094 r1103 1301 1301 end 1302 1302 1303 def test_translate_pseudo_id 1304 login(:lion) 1305 { '11' => nodes_id(:zena), 1306 'bird' => nodes_id(:bird_jpg), 1307 nodes_zip(:cleanWater).to_i => nodes_id(:cleanWater), 1308 nodes_zip(:status) => nodes_id(:status), 1309 'statu' => nodes_id(:status), 1310 }.each do |k,v| 1311 assert_equal v, secure(Node) { Node.translate_pseudo_id(k) }, "'#{k}' should translate to '#{v}'" 1312 end 1313 end 1314 1303 1315 # FIXME: write test 1304 1316 def test_assets trunk/test/unit/relation_proxy_test.rb
r1102 r1103 123 123 end 124 124 125 def test_ destroy_links125 def test_remove_link 126 126 login(:tiger) 127 127 node = secure!(Node) { nodes(:cleanWater) } 128 128 assert_equal nodes_id(:art), node.find(:first, 'set_tags')[:id] 129 assert node.remove_link(links _id(:cleanWater_in_art))129 assert node.remove_link(links(:cleanWater_in_art)) 130 130 assert node.save 131 131 assert_nil node.find(:first, 'set_tags') 132 132 end 133 133 134 def test_relation_new_record135 login(:tiger)136 node = secure!(Node) { Node.new }137 assert_equal nil, node.find(:all,'set_tags')138 node = secure!(Node) { Node.get_class('Tag').new_instance }139 assert_equal nil, node.find(:all,'tagged')140 end141 142 def test_link_id143 login(:tiger)144 page = secure!(Node) { nodes(:cleanWater) }145 pages = page.find(:all, 'pages')146 assert_nil pages[0][:link_id]147 tags = page.find(:all, 'set_tags')148 assert_equal [links_id(:cleanWater_in_art).to_s], tags.map{|r| r[:link_id]}149 end150 151 def test_do_find_in_new_node152 login(:tiger)153 assert var1_new = secure!(Node) { Node.get_class("Post").new }154 assert_nil var1_new.do_find(:all, eval("\"#{Node.build_find(:all, 'posts in site', :node_name => 'self')}\""))155 end156 157 134 def test_update_attributes_empty_value 158 135 login(:lion) … … 161 138 end 162 139 163 def test_do_find_bad_relation 164 login(:lion) 165 node = secure!(Node) { nodes(:status) } 166 assert_nil node.find(:first, 'blah') 167 end 168 169 def test_l_status 170 login(:lion) 171 node = secure!(Node) { nodes(:art) } 172 tagged = node.find(:all, 'tagged') 173 # cleanWater, opening 174 assert_equal [10, 5], tagged.map{|t| t.l_status} 175 end 176 177 def test_l
