Commit 5d91b5dd569359dc48120a4e20023d5aab1575a4
1 parent
0ae9f1ff
Exists in
staging
and in
4 other branches
proposals_discussion: added rss link to discussion page
Showing
5 changed files
with
39 additions
and
3 deletions
Show diff stats
plugins/proposals_discussion/lib/proposals_discussion_plugin/discussion.rb
1 | 1 | class ProposalsDiscussionPlugin::Discussion < Folder |
2 | 2 | |
3 | + acts_as_having_posts | |
4 | + | |
3 | 5 | has_many :topics, :class_name => 'ProposalsDiscussionPlugin::Topic', :foreign_key => 'parent_id' |
4 | 6 | has_many :proposals, :class_name => 'ProposalsDiscussionPlugin::Proposal', :through => :children, :source => :children |
5 | 7 | |
... | ... | @@ -26,4 +28,9 @@ class ProposalsDiscussionPlugin::Discussion < Folder |
26 | 28 | end |
27 | 29 | alias_method_chain :cache_key, :person |
28 | 30 | |
31 | + def posts | |
32 | + #override posts method to list proposals in feed | |
33 | + ProposalsDiscussionPlugin::Proposal.from_discussion(self) | |
34 | + end | |
35 | + | |
29 | 36 | end | ... | ... |
plugins/proposals_discussion/lib/proposals_discussion_plugin/proposal.rb
1 | 1 | class ProposalsDiscussionPlugin::Proposal < TinyMceArticle |
2 | 2 | |
3 | 3 | scope :private, lambda {|user| {:conditions => {:last_changed_by_id => user.id, :published => false}}} |
4 | + scope :from_discussion, lambda {|discussion| joins(:parent).where(['parents_articles.parent_id = ?', discussion.id])} | |
4 | 5 | |
5 | 6 | alias :topic :parent |
6 | 7 | |
... | ... | @@ -16,8 +17,12 @@ class ProposalsDiscussionPlugin::Proposal < TinyMceArticle |
16 | 17 | |
17 | 18 | |
18 | 19 | def to_html(options = {}) |
19 | - proc do | |
20 | - render :file => 'content_viewer/proposal' | |
20 | + unless options[:feed] | |
21 | + proc do | |
22 | + render :file => 'content_viewer/proposal' | |
23 | + end | |
24 | + else | |
25 | + body | |
21 | 26 | end |
22 | 27 | end |
23 | 28 | ... | ... |
plugins/proposals_discussion/test/unit/proposal_test.rb
... | ... | @@ -29,4 +29,26 @@ class ProposalTest < ActiveSupport::TestCase |
29 | 29 | assert !proposal.allow_edit?(fast_create(Person)) |
30 | 30 | end |
31 | 31 | |
32 | + should 'return body when to_html was called with feed=true' do | |
33 | + assert_equal proposal.body, proposal.to_html(:feed => true) | |
34 | + end | |
35 | + | |
36 | + should 'return a proc when to_html was called with feed=false' do | |
37 | + assert proposal.to_html(:feed => false).kind_of?(Proc) | |
38 | + end | |
39 | + | |
40 | + should 'return a proc when to_html was called with no feed parameter' do | |
41 | + assert proposal.to_html.kind_of?(Proc) | |
42 | + end | |
43 | + | |
44 | + should 'return proposals by discussion' do | |
45 | + discussion = fast_create(ProposalsDiscussionPlugin::Discussion) | |
46 | + topic = fast_create(ProposalsDiscussionPlugin::Topic, :parent_id => discussion.id) | |
47 | + proposal1 = fast_create(ProposalsDiscussionPlugin::Proposal, :parent_id => topic.id) | |
48 | + proposal2 = fast_create(ProposalsDiscussionPlugin::Proposal) | |
49 | + proposal3 = fast_create(ProposalsDiscussionPlugin::Proposal, :parent_id => topic.id) | |
50 | + | |
51 | + assert_equivalent [proposal1, proposal3], ProposalsDiscussionPlugin::Proposal.from_discussion(discussion) | |
52 | + end | |
53 | + | |
32 | 54 | end | ... | ... |
plugins/proposals_discussion/views/content_viewer/discussion.html.erb
plugins/proposals_discussion/views/select_topic.html.erb