Changeset 1173

Show
Ignore:
Timestamp:
2008-09-19 21:36:54 (4 months ago)
Author:
gaspard
Message:

commit 4b697cca0ce1cfc396cbb9f7db7026a840343211
Author: Gaspard Bucher <gaspard@teti.ch>

Added 'node' context to move into the node from a Comment. Fixed some bugs in queries built from separate parameters like "<r:pages from='projects' in='site' where='...'/>".

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/models/comment.rb

    r1168 r1173  
    88class Comment < ActiveRecord::Base 
    99  zafu_readable      :title, :text, :author_name, :created_at, :updated_at, :status 
    10   zafu_context       :replies => ["Comment"] 
     10  zafu_context       :replies => ["Comment"], :node => "Node" 
    1111  attr_accessible    :title, :text, :author_name, :discussion_id, :reply_to, :status 
    1212   
    1313  belongs_to :discussion 
    14   belongs_to :node #, :through => :discussion (TOO BAD...) 
    1514  validate   :valid_comment 
    1615  before_validation :comment_before_validation 
     
    1918  def author 
    2019    @author ||= secure(User) { User.find(self[:user_id]) } 
     20  end 
     21   
     22  def node 
     23    @node ||= discussion.node 
    2124  end 
    2225   
  • trunk/app/models/discussion.rb

    r1060 r1173  
    5151  end 
    5252   
     53  alias o_node node 
     54   
    5355  def node 
    54     secure!(Node) { Node.find(self[:node_id])
     56    secure!(Node) { o_node
    5557  end 
    5658   
  • trunk/lib/comment_query.rb

    r1172 r1173  
    2121      add_table('users') 
    2222      @where << "#{table('users')}.id = #{field_or_param('author_id')}" 
    23       # should we only move to Users ? 
     23      # should we move on to Contact ? 
     24    when 'node', 'nodes' 
    2425      add_table('discussions') 
    2526      add_table('nodes') 
  • trunk/lib/node_query.rb

    r1172 r1173  
    115115    def parse_change_class(rel, is_last) 
    116116      case rel 
    117       when 'comments' 
     117      when 'comment', 'comments' 
    118118        if is_last 
    119119          # no need to load discussions, versions and all the mess 
  • trunk/lib/parser/lib/rules/zena.rb

    r1168 r1173  
    20712071     
    20722072    # Build pseudo sql from the parameters 
     2073    # comments where ... from ... in ... order ... limit 
    20732074    def make_pseudo_sql(rel, params=@params) 
    20742075      parts   = [rel.dup] 
     
    20902091       
    20912092      if params[:in] 
    2092         parts[0] << " in #{params[:in]}" 
     2093        parts[-1] << " in #{params[:in]}" 
    20932094      end 
    20942095       
    20952096      if group = params[:group] 
    2096         parts[0] << " group by #{group}" unless parts[0] =~ /group by/ 
     2097        parts[-1] << " group by #{group}" unless parts[0] =~ /group by/ 
    20972098      end 
    20982099       
    20992100      if order = params[:order] 
    2100         parts[0] << " order by #{order}" unless parts[0] =~ /order by/ 
     2101        parts[-1] << " order by #{order}" unless parts[0] =~ /order by/ 
    21012102      end 
    21022103       
    21032104      [:limit, :offset].each do |k| 
    21042105        next unless params[k] 
    2105         parts[0] << " #{k} #{params[k]}" unless parts[0] =~ / #{k} / 
     2106        parts[-1] << " #{k} #{params[k]}" unless parts[0] =~ / #{k} / 
    21062107      end 
    21072108       
  • trunk/test/helpers/zena_parser/relations.yml

    r1122 r1173  
    390390  src: "<r:comments><r:each do='{text}'/></r:comments>" 
    391391  tem: "/zazen\(var1.text, :node=>@node\)/" 
     392 
     393comments_in_site_node: 
     394  src: "<r:comment from='nodes in site' order='created_at desc'><r:node do='[name]'/>: <r:show attr='title'/></r:comment>" 
     395  res: "myLife: I want to become queen" 
  • trunk/test/sites/zena/comments.yml

    r1016 r1173  
    7474  text:            Not here... 
    7575 
     76private_comment_fr: 
     77  discussion:      private_discussion_on_myLife 
     78  created_at:      2008-09-18 22:02 
     79  updated_at:      2008-09-18 22:02 
     80  user:            ant 
     81  title:           I want to become queen 
     82  text:            I hate being a worker 
     83   
  • trunk/test/unit/comment_test.rb

    r1061 r1173  
    2929    comment = secure!(Comment) { comments(:lion_says_inside) } 
    3030    assert_equal 'PLV', comment.author.initials 
     31  end 
     32   
     33  def test_node 
     34    login(:anon) 
     35    comment = secure!(Comment) { comments(:lion_says_inside) } 
     36    assert_equal nodes_id(:status), comment.node[:id] 
    3137  end 
    3238