Commit 955fb392ebe66f5c23111d3cc82ffab906e32a5f

Authored by Michel Felipe
1 parent fbcb1e60
Exists in proposal_response

Marks a proposal or topic like 'replied'

lib/ext/entities.rb
@@ -13,6 +13,9 @@ module Noosfero @@ -13,6 +13,9 @@ module Noosfero
13 expose :amount_of_children do |article, options| 13 expose :amount_of_children do |article, options|
14 article.children.count 14 article.children.count
15 end 15 end
  16 + expose :replied do |article, options|
  17 + article.setting[:replied]
  18 + end
16 end 19 end
17 20
18 end 21 end
lib/proposals_discussion_plugin/proposal.rb
@@ -9,6 +9,8 @@ class ProposalsDiscussionPlugin::Proposal < TinyMceArticle @@ -9,6 +9,8 @@ class ProposalsDiscussionPlugin::Proposal < TinyMceArticle
9 9
10 has_one :ranking_item 10 has_one :ranking_item
11 11
  12 + settings_items :replied, :type => :boolean, :default => false
  13 +
12 def self.short_description 14 def self.short_description
13 _("Proposal") 15 _("Proposal")
14 end 16 end
lib/proposals_discussion_plugin/response.rb
@@ -4,6 +4,15 @@ class ProposalsDiscussionPlugin::Response < TinyMceArticle @@ -4,6 +4,15 @@ class ProposalsDiscussionPlugin::Response < TinyMceArticle
4 4
5 validate :check_parent_type 5 validate :check_parent_type
6 6
  7 + before_save do |article|
  8 +
  9 + article.parent.setting[:replied] = true
  10 + article.parent.save!
  11 +
  12 + article.parent.parent.setting[:replied] = true
  13 + article.parent.parent.save!
  14 + end
  15 +
7 def self.short_description 16 def self.short_description
8 _("Proposal Response") 17 _("Proposal Response")
9 end 18 end
lib/proposals_discussion_plugin/topic.rb
@@ -5,6 +5,7 @@ class ProposalsDiscussionPlugin::Topic < ProposalsDiscussionPlugin::ProposalsHo @@ -5,6 +5,7 @@ class ProposalsDiscussionPlugin::Topic < ProposalsDiscussionPlugin::ProposalsHo
5 has_many :proposals_comments, :class_name => 'Comment', :through => :children, :source => :comments 5 has_many :proposals_comments, :class_name => 'Comment', :through => :children, :source => :comments
6 6
7 settings_items :color, :type => :string 7 settings_items :color, :type => :string
  8 + settings_items :replied, :type => :boolean, :default => false
8 9
9 attr_accessible :color 10 attr_accessible :color
10 11
test/unit/api_test.rb
@@ -51,11 +51,11 @@ class APITest < ActiveSupport::TestCase @@ -51,11 +51,11 @@ class APITest < ActiveSupport::TestCase
51 51
52 should 'sanitize proposal' do 52 should 'sanitize proposal' do
53 discussion = fast_create(ProposalsDiscussionPlugin::Discussion, :profile_id => user.person.id) 53 discussion = fast_create(ProposalsDiscussionPlugin::Discussion, :profile_id => user.person.id)
54 - topic = fast_create(ProposalsDiscussionPlugin::Topic,  
55 - :profile_id => user.person.id, 54 + topic = fast_create(ProposalsDiscussionPlugin::Topic,
  55 + :profile_id => user.person.id,
56 :parent_id => discussion.id) 56 :parent_id => discussion.id)
57 - params[:article] = {:name => "Proposal name", :abstract => "Proposal <iframe>Test</iframe> abstract",  
58 - :type => 'ProposalsDiscussionPlugin::Proposal', 57 + params[:article] = {:name => "Proposal name", :abstract => "Proposal <iframe>Test</iframe> abstract",
  58 + :type => 'ProposalsDiscussionPlugin::Proposal',
59 :body => "This is a malicious body <iMg SrC=x OnErRoR=document.documentElement.innerHTML=1>SearchParam"} 59 :body => "This is a malicious body <iMg SrC=x OnErRoR=document.documentElement.innerHTML=1>SearchParam"}
60 assert_difference "ProposalsDiscussionPlugin::ProposalTask.count" do 60 assert_difference "ProposalsDiscussionPlugin::ProposalTask.count" do
61 post "/api/v1/proposals_discussion_plugin/#{topic.id}/propose?#{params.to_query}" 61 post "/api/v1/proposals_discussion_plugin/#{topic.id}/propose?#{params.to_query}"
@@ -79,4 +79,20 @@ class APITest &lt; ActiveSupport::TestCase @@ -79,4 +79,20 @@ class APITest &lt; ActiveSupport::TestCase
79 assert_includes json["articles"].map { |a| a["ranking_position"] }, 1 79 assert_includes json["articles"].map { |a| a["ranking_position"] }, 1
80 end 80 end
81 81
  82 + should 'check if a proposal and their topic was replied' do
  83 + discussion = create(ProposalsDiscussionPlugin::Discussion, :name => 'Discussion', :profile_id => user.person.id)
  84 + topic = create(ProposalsDiscussionPlugin::Topic, :name => 'Topic', :profile_id => user.person.id, :parent_id => discussion.id)
  85 + proposal = create(ProposalsDiscussionPlugin::Proposal, :name => 'Proposal', :abstract => 'This is a proposal', :body => 'test', :profile_id => user.person.id, :parent_id => topic.id)
  86 + response = create(ProposalsDiscussionPlugin::Response, :name => 'Response', :body => 'test response', :profile_id => user.person.id, :parent_id => proposal.id)
  87 + get "/api/v1/articles/#{topic.id}?#{params.to_query}"
  88 + json = JSON.parse(last_response.body)
  89 +
  90 + assert json["article"]["replied"]
  91 +
  92 + get "/api/v1/articles/#{topic.id}/children/#{proposal.id}?#{params.to_query}"
  93 + json = JSON.parse(last_response.body)
  94 +
  95 + assert json["article"]["replied"]
  96 + end
  97 +
82 end 98 end