Commit 3d117fad44f744eecd5a549d1e222569f6635af8

Authored by Victor Costa
2 parents 53e18b8a 78a02ddc

Merge branch 'AI3220_proposals' into stable

lib/feed_writer.rb
@@ -19,7 +19,7 @@ class FeedWriter @@ -19,7 +19,7 @@ class FeedWriter
19 for article in articles 19 for article in articles
20 xml.item do 20 xml.item do
21 xml.title(article.name) 21 xml.title(article.name)
22 - xml.description(article.to_html) 22 + xml.description(article.to_html(:feed => true))
23 if article.created_at 23 if article.created_at
24 # rfc822 24 # rfc822
25 xml.pubDate(article.created_at.rfc2822) 25 xml.pubDate(article.created_at.rfc2822)
plugins/proposals_discussion/lib/proposals_discussion_plugin/discussion.rb
1 class ProposalsDiscussionPlugin::Discussion < Folder 1 class ProposalsDiscussionPlugin::Discussion < Folder
2 2
  3 + acts_as_having_posts
  4 +
3 has_many :topics, :class_name => 'ProposalsDiscussionPlugin::Topic', :foreign_key => 'parent_id' 5 has_many :topics, :class_name => 'ProposalsDiscussionPlugin::Topic', :foreign_key => 'parent_id'
4 has_many :proposals, :class_name => 'ProposalsDiscussionPlugin::Proposal', :through => :children, :source => :children 6 has_many :proposals, :class_name => 'ProposalsDiscussionPlugin::Proposal', :through => :children, :source => :children
5 7
@@ -26,4 +28,9 @@ class ProposalsDiscussionPlugin::Discussion &lt; Folder @@ -26,4 +28,9 @@ class ProposalsDiscussionPlugin::Discussion &lt; Folder
26 end 28 end
27 alias_method_chain :cache_key, :person 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 end 36 end
plugins/proposals_discussion/lib/proposals_discussion_plugin/proposal.rb
1 class ProposalsDiscussionPlugin::Proposal < TinyMceArticle 1 class ProposalsDiscussionPlugin::Proposal < TinyMceArticle
2 2
3 scope :private, lambda {|user| {:conditions => {:last_changed_by_id => user.id, :published => false}}} 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 alias :topic :parent 6 alias :topic :parent
6 7
@@ -16,8 +17,12 @@ class ProposalsDiscussionPlugin::Proposal &lt; TinyMceArticle @@ -16,8 +17,12 @@ class ProposalsDiscussionPlugin::Proposal &lt; TinyMceArticle
16 17
17 18
18 def to_html(options = {}) 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 end 26 end
22 end 27 end
23 28
plugins/proposals_discussion/public/proposals_list.js
@@ -34,6 +34,9 @@ jQuery(document).ready(function($) { @@ -34,6 +34,9 @@ jQuery(document).ready(function($) {
34 $(window).resize(function() { 34 $(window).resize(function() {
35 $('.topics').masonry(); 35 $('.topics').masonry();
36 }); 36 });
  37 + $(window).bind('toggleFullwidth', function() {
  38 + $('.topics').masonry();
  39 + });
37 }); 40 });
38 41
39 function loadSocialButtons() { 42 function loadSocialButtons() {
plugins/proposals_discussion/test/unit/proposal_test.rb
@@ -29,4 +29,26 @@ class ProposalTest &lt; ActiveSupport::TestCase @@ -29,4 +29,26 @@ class ProposalTest &lt; ActiveSupport::TestCase
29 assert !proposal.allow_edit?(fast_create(Person)) 29 assert !proposal.allow_edit?(fast_create(Person))
30 end 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 end 54 end
plugins/proposals_discussion/views/content_viewer/discussion.html.erb
1 <%= javascript_include_tag 'plugins/proposals_discussion/proposals_list.js' %> 1 <%= javascript_include_tag 'plugins/proposals_discussion/proposals_list.js' %>
2 2
  3 +<%= add_rss_feed_to_head(@page.name, @page.feed.url) if @page.feed %>
  4 +
3 <div class="description"> 5 <div class="description">
4 <%= @page.body %> 6 <%= @page.body %>
5 </div> 7 </div>
plugins/proposals_discussion/views/select_topic.html.erb
@@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
16 <h3><%= _('Select topic') %></h3> 16 <h3><%= _('Select topic') %></h3>
17 <div id="topics"> 17 <div id="topics">
18 18
19 - <% @discussion.children.each do |topic| %> 19 + <% @discussion.topics.each do |topic| %>
20 <h4> 20 <h4>
21 <%= radio_button_tag('discussion[topic]', topic.id) %> 21 <%= radio_button_tag('discussion[topic]', topic.id) %>
22 <%= topic.title %> 22 <%= topic.title %>