Changeset 1173
- Timestamp:
- 2008-09-19 21:36:54 (4 months ago)
- Files:
-
- trunk/app/models/comment.rb (modified) (2 diffs)
- trunk/app/models/discussion.rb (modified) (1 diff)
- trunk/lib/comment_query.rb (modified) (1 diff)
- trunk/lib/node_query.rb (modified) (1 diff)
- trunk/lib/parser/lib/rules/zena.rb (modified) (2 diffs)
- trunk/test/helpers/zena_parser/relations.yml (modified) (1 diff)
- trunk/test/sites/zena/comments.yml (modified) (1 diff)
- trunk/test/unit/comment_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/models/comment.rb
r1168 r1173 8 8 class Comment < ActiveRecord::Base 9 9 zafu_readable :title, :text, :author_name, :created_at, :updated_at, :status 10 zafu_context :replies => ["Comment"] 10 zafu_context :replies => ["Comment"], :node => "Node" 11 11 attr_accessible :title, :text, :author_name, :discussion_id, :reply_to, :status 12 12 13 13 belongs_to :discussion 14 belongs_to :node #, :through => :discussion (TOO BAD...)15 14 validate :valid_comment 16 15 before_validation :comment_before_validation … … 19 18 def author 20 19 @author ||= secure(User) { User.find(self[:user_id]) } 20 end 21 22 def node 23 @node ||= discussion.node 21 24 end 22 25 trunk/app/models/discussion.rb
r1060 r1173 51 51 end 52 52 53 alias o_node node 54 53 55 def node 54 secure!(Node) { Node.find(self[:node_id])}56 secure!(Node) { o_node } 55 57 end 56 58 trunk/lib/comment_query.rb
r1172 r1173 21 21 add_table('users') 22 22 @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' 24 25 add_table('discussions') 25 26 add_table('nodes') trunk/lib/node_query.rb
r1172 r1173 115 115 def parse_change_class(rel, is_last) 116 116 case rel 117 when 'comment s'117 when 'comment', 'comments' 118 118 if is_last 119 119 # no need to load discussions, versions and all the mess trunk/lib/parser/lib/rules/zena.rb
r1168 r1173 2071 2071 2072 2072 # Build pseudo sql from the parameters 2073 # comments where ... from ... in ... order ... limit 2073 2074 def make_pseudo_sql(rel, params=@params) 2074 2075 parts = [rel.dup] … … 2090 2091 2091 2092 if params[:in] 2092 parts[ 0] << " in #{params[:in]}"2093 parts[-1] << " in #{params[:in]}" 2093 2094 end 2094 2095 2095 2096 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/ 2097 2098 end 2098 2099 2099 2100 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/ 2101 2102 end 2102 2103 2103 2104 [:limit, :offset].each do |k| 2104 2105 next unless params[k] 2105 parts[ 0] << " #{k} #{params[k]}" unless parts[0] =~ / #{k} /2106 parts[-1] << " #{k} #{params[k]}" unless parts[0] =~ / #{k} / 2106 2107 end 2107 2108 trunk/test/helpers/zena_parser/relations.yml
r1122 r1173 390 390 src: "<r:comments><r:each do='{text}'/></r:comments>" 391 391 tem: "/zazen\(var1.text, :node=>@node\)/" 392 393 comments_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 74 74 text: Not here... 75 75 76 private_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 29 29 comment = secure!(Comment) { comments(:lion_says_inside) } 30 30 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] 31 37 end 32 38
