Commit 955fb392ebe66f5c23111d3cc82ffab906e32a5f
1 parent
fbcb1e60
Exists in
proposal_response
Marks a proposal or topic like 'replied'
Showing
5 changed files
with
35 additions
and
4 deletions
Show diff stats
lib/ext/entities.rb
lib/proposals_discussion_plugin/proposal.rb
lib/proposals_discussion_plugin/response.rb
| ... | ... | @@ -4,6 +4,15 @@ class ProposalsDiscussionPlugin::Response < TinyMceArticle |
| 4 | 4 | |
| 5 | 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 | 16 | def self.short_description |
| 8 | 17 | _("Proposal Response") |
| 9 | 18 | end | ... | ... |
lib/proposals_discussion_plugin/topic.rb
| ... | ... | @@ -5,6 +5,7 @@ class ProposalsDiscussionPlugin::Topic < ProposalsDiscussionPlugin::ProposalsHo |
| 5 | 5 | has_many :proposals_comments, :class_name => 'Comment', :through => :children, :source => :comments |
| 6 | 6 | |
| 7 | 7 | settings_items :color, :type => :string |
| 8 | + settings_items :replied, :type => :boolean, :default => false | |
| 8 | 9 | |
| 9 | 10 | attr_accessible :color |
| 10 | 11 | ... | ... |
test/unit/api_test.rb
| ... | ... | @@ -51,11 +51,11 @@ class APITest < ActiveSupport::TestCase |
| 51 | 51 | |
| 52 | 52 | should 'sanitize proposal' do |
| 53 | 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 | 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 | 59 | :body => "This is a malicious body <iMg SrC=x OnErRoR=document.documentElement.innerHTML=1>SearchParam"} |
| 60 | 60 | assert_difference "ProposalsDiscussionPlugin::ProposalTask.count" do |
| 61 | 61 | post "/api/v1/proposals_discussion_plugin/#{topic.id}/propose?#{params.to_query}" |
| ... | ... | @@ -79,4 +79,20 @@ class APITest < ActiveSupport::TestCase |
| 79 | 79 | assert_includes json["articles"].map { |a| a["ranking_position"] }, 1 |
| 80 | 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 | 98 | end | ... | ... |