From 362c6e6ce5848036cd186d76f86ae6fc44a40434 Mon Sep 17 00:00:00 2001 From: Sean Yeoh Date: Fri, 13 May 2022 14:16:26 +0800 Subject: [PATCH 1/5] Fix card comment xml --- app/models/card.rb | 8 +++--- spec/features/export/v2/template_spec.rb | 32 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/app/models/card.rb b/app/models/card.rb index 4f044a277..fedcdd181 100644 --- a/app/models/card.rb +++ b/app/models/card.rb @@ -75,9 +75,11 @@ def to_xml(xml_builder, includes: [], version: 3) end if includes.include?(:comments) - card_builder.comments do |comment_builder| - comments.each do |comment| - comment.to_xml(comment_builder) + card_builder.comments do |comments_builder| + comments_builder.comment do |comment_builder| + comments.each do |comment| + comment.to_xml(comment_builder) + end end end end diff --git a/spec/features/export/v2/template_spec.rb b/spec/features/export/v2/template_spec.rb index bb1c0dc4d..3fb883086 100644 --- a/spec/features/export/v2/template_spec.rb +++ b/spec/features/export/v2/template_spec.rb @@ -32,4 +32,36 @@ expect(exporter.export).to include(comment_xml) end end + + context 'card with a comment' do + let(:card) do + board = create(:board, node: current_project.methodology_library, project: current_project) + list = create(:list, board: board) + create(:card, list: list) + end + + let(:comment) do + create(:comment, + content: 'Sample card comment', + commentable: card, + user: @logged_in_as + ) + end + + it 'creates the comment xml' do + export_options = { + plugin: Dradis::Plugins::Projects, + project_id: current_project.id + } + exporter = + Dradis::Plugins::Projects::Export::V3::Template.new(export_options) + + comment_xml = ""\ + ""\ + "#{@logged_in_as.email}"\ + "#{comment.created_at.to_i}"\ + "" + expect(exporter.export).to include(comment_xml) + end + end end From 94b4cedb4e280184d8106cf46369fc7a39d854df Mon Sep 17 00:00:00 2001 From: Sean Yeoh Date: Fri, 13 May 2022 14:17:52 +0800 Subject: [PATCH 2/5] Add specs and changelog --- CHANGELOG | 1 + spec/features/export/v2/template_spec.rb | 32 ------------------------ spec/features/export/v3/template_spec.rb | 32 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2b506af03..4ece2e9df 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,7 @@ - Bugs fixes: - [entity]: - [future tense verb] [bug fix] + - Project export: Fix card comments not exported - Bug tracker items: - [item] - New integrations: diff --git a/spec/features/export/v2/template_spec.rb b/spec/features/export/v2/template_spec.rb index 3fb883086..bb1c0dc4d 100644 --- a/spec/features/export/v2/template_spec.rb +++ b/spec/features/export/v2/template_spec.rb @@ -32,36 +32,4 @@ expect(exporter.export).to include(comment_xml) end end - - context 'card with a comment' do - let(:card) do - board = create(:board, node: current_project.methodology_library, project: current_project) - list = create(:list, board: board) - create(:card, list: list) - end - - let(:comment) do - create(:comment, - content: 'Sample card comment', - commentable: card, - user: @logged_in_as - ) - end - - it 'creates the comment xml' do - export_options = { - plugin: Dradis::Plugins::Projects, - project_id: current_project.id - } - exporter = - Dradis::Plugins::Projects::Export::V3::Template.new(export_options) - - comment_xml = ""\ - ""\ - "#{@logged_in_as.email}"\ - "#{comment.created_at.to_i}"\ - "" - expect(exporter.export).to include(comment_xml) - end - end end diff --git a/spec/features/export/v3/template_spec.rb b/spec/features/export/v3/template_spec.rb index ff27bd021..5ce1905c6 100644 --- a/spec/features/export/v3/template_spec.rb +++ b/spec/features/export/v3/template_spec.rb @@ -38,5 +38,37 @@ expect(@result).to include(node_board_xml) end + + context 'card with a comment' do + let(:card) do + board = create(:board, node: current_project.methodology_library, project: current_project) + list = create(:list, board: board) + create(:card, list: list) + end + + let(:comment) do + create(:comment, + content: 'Sample card comment', + commentable: card, + user: @logged_in_as + ) + end + + it 'creates the comment xml' do + export_options = { + plugin: Dradis::Plugins::Projects, + project_id: current_project.id + } + exporter = + Dradis::Plugins::Projects::Export::V3::Template.new(export_options) + + comment_xml = ""\ + ""\ + "#{@logged_in_as.email}"\ + "#{comment.created_at.to_i}"\ + "" + expect(exporter.export).to include(comment_xml) + end + end end end From f977bdae97198e2311ded7cdb799445c7bac0b6c Mon Sep 17 00:00:00 2001 From: Sean Yeoh Date: Fri, 13 May 2022 16:13:09 +0800 Subject: [PATCH 3/5] Fix comment builder --- app/models/card.rb | 6 ++---- app/models/comment.rb | 10 ++++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/card.rb b/app/models/card.rb index fedcdd181..062325149 100644 --- a/app/models/card.rb +++ b/app/models/card.rb @@ -76,10 +76,8 @@ def to_xml(xml_builder, includes: [], version: 3) if includes.include?(:comments) card_builder.comments do |comments_builder| - comments_builder.comment do |comment_builder| - comments.each do |comment| - comment.to_xml(comment_builder) - end + comments.each do |comment| + comment.to_xml(comments_builder) end end end diff --git a/app/models/comment.rb b/app/models/comment.rb index 366af2806..0f74810d1 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -83,11 +83,13 @@ def self.mentionable_users(resource, extra_scope = nil) end def to_xml(xml_builder, version: 3) - xml_builder.content do - xml_builder.cdata!(content) + xml_builder.comment do |comment_builder| + comment_builder.content do + comment_builder.cdata!(content) + end + comment_builder.author(user.email) + comment_builder.created_at(created_at.to_i) end - xml_builder.author(user.email) - xml_builder.created_at(created_at.to_i) end private From fef722b93059db81841fbf7ba55bcb72ec184911 Mon Sep 17 00:00:00 2001 From: Sean Yeoh Date: Fri, 13 May 2022 16:14:01 +0800 Subject: [PATCH 4/5] Update changelog --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 4ece2e9df..0fab40e8d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,7 +8,7 @@ - Bugs fixes: - [entity]: - [future tense verb] [bug fix] - - Project export: Fix card comments not exported + - Project export: Fix export for comments in cards - Bug tracker items: - [item] - New integrations: From 5f90fe94ceae50c866cdaf95d5cb0142673e03ea Mon Sep 17 00:00:00 2001 From: Sean Yeoh Date: Fri, 13 May 2022 16:19:10 +0800 Subject: [PATCH 5/5] Revert name change --- app/models/card.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/card.rb b/app/models/card.rb index 062325149..4f044a277 100644 --- a/app/models/card.rb +++ b/app/models/card.rb @@ -75,9 +75,9 @@ def to_xml(xml_builder, includes: [], version: 3) end if includes.include?(:comments) - card_builder.comments do |comments_builder| + card_builder.comments do |comment_builder| comments.each do |comment| - comment.to_xml(comments_builder) + comment.to_xml(comment_builder) end end end