Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Refactor comments to support markup types (#707) #717

Merged
merged 3 commits into from Feb 7, 2017

Conversation

xcoulon
Copy link
Contributor

@xcoulon xcoulon commented Feb 2, 2017

Added a markup column in the comments table using
a migration script.
When creating or updating a comment, the default markup
is used if none was provided.
When showing comments, the default markup is also returned
if none was found in the database (ie, for older comments).

Fixes #707

@xcoulon
Copy link
Contributor Author

xcoulon commented Feb 2, 2017

Marked as WIP since this PR is based on a commit for issue #714 whose PR (#716) is still pending

@xcoulon xcoulon self-assigned this Feb 7, 2017
Added a `markup` column in the `comments` table using
a migration script.
When creating or updating a comment, the default markup
is used if none was provided.
When showing comments, the default markup is also returned
if none was found in the database (ie, for older comments).

Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
@codecov-io
Copy link

codecov-io commented Feb 7, 2017

Codecov Report

Merging #717 into master will increase coverage by 0.03%.

@@            Coverage Diff             @@
##           master     #717      +/-   ##
==========================================
+ Coverage   71.12%   71.16%   +0.03%     
==========================================
  Files          80       80              
  Lines        4603     4616      +13     
==========================================
+ Hits         3274     3285      +11     
- Misses       1013     1016       +3     
+ Partials      316      315       -1
Impacted Files Coverage Δ
comment/comment.go 72.28% <ø> (ø)
account/user.go 45.61% <ø> (ø)
migration/migration.go 50% <100%> (+0.22%)
work-item-comments.go 73.01% <100%> (-2.43%)
rendering/markup_content.go 86.11% <100%> (+1.73%)
comments.go 77.33% <100%> (+1.99%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 741a7a0...e7b8de4. Read the comment docs.

@xcoulon xcoulon changed the title WIP - Refactor comments to support markup types (#707) Refactor comments to support markup types (#707) Feb 7, 2017
@@ -44,6 +47,9 @@ var createCommentAttributes = a.Type("CreateCommentAttributes", func() {
a.MinLength(1) // Empty comment not allowed
a.Example("This is really interesting")
})
a.Attribute("markup", d.String, "The comment markup associated with the body", func() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to have this attribute outsourced because you define it tiwce?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is outsourced twice just as body is, because it is used in the types associated with the create and update operations

@@ -45,6 +46,10 @@ func (s *CommentsSuite) TearDownTest() {
s.clean()
}

var markdownMarkup = rendering.SystemMarkupMarkdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it is a code convention but you could also define it like this:

var (
  markdownMarkup = rendering.SystemMarkupMarkdown
  plaintextMarkup = rendering.SystemMarkupPlainText
  defaultMarkup = rendering.SystemMarkupDefault
)
You type less characters :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok ;-)

// when
result := NilSafeGetMarkup(nil)
// then
require.NotNil(t, result)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure you need this nil check because the assert.Equal below just compares values and it is safe to compare nil values as long as you don't dereference a nil value. Right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, correct, I can probably remove that

// when
result := NilSafeGetMarkup(&markup)
// then
require.NotNil(t, result)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure you need this nil check because the assert.Equal below just compares values and it is safe to compare nil values as long as you don't dereference a nil value. Right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

// when
result := NilSafeGetMarkup(&markup)
// then
require.NotNil(t, result)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure you need this nil check because the assert.Equal below just compares values and it is safe to compare nil values as long as you don't dereference a nil value. Right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

import "github.com/stretchr/testify/assert"
import "github.com/stretchr/testify/require"

func TestGetDefaultMarkupFromNil(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the functions TestGetDefaultMarkupFromNil, TestGetMarkupFromValue, and TestGetMarkupFromEmptyValue can be merged into one test function, don't you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kwk why would I do that ? I want short unit tests that follow as much as possible the "given/when/then" pattern, which is why I have 3 tests here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, agreed. they just seemed so small, tiny, and cozy. Those poor little tests looked like they should be sleeping under a shared blanket. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kwk I've had enough of co-sleeping in the past ;-)

reqComment := ctx.Payload.Data

fmt.Println(fmt.Sprintf("Processing markup value: '%v'", reqComment.Attributes.Markup))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove print.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@@ -181,6 +193,7 @@ func assertComment(t *testing.T, c *app.Comment) {
assert.Equal(t, "comments", c.Type)
assert.NotNil(t, c.ID)
assert.NotNil(t, c.Attributes.Body)
assert.NotNil(t, c.Attributes.Markup)
assert.NotNil(t, c.Attributes.CreatedAt)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be require.NotNil because you dereference the value one line below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@@ -181,6 +193,7 @@ func assertComment(t *testing.T, c *app.Comment) {
assert.Equal(t, "comments", c.Type)
assert.NotNil(t, c.ID)
assert.NotNil(t, c.Attributes.Body)
assert.NotNil(t, c.Attributes.Markup)
assert.NotNil(t, c.Attributes.CreatedAt)
assert.WithinDuration(t, time.Now(), *c.Attributes.CreatedAt, 2*time.Second)
assert.NotNil(t, c.Relationships)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be require.NotNil because you dereference the value one line below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Taking review comments into account

Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
@kwk kwk merged commit e28a1b7 into fabric8-services:master Feb 7, 2017
@@ -0,0 +1,2 @@
-- add a 'markup' column in the 'comments' table
alter table comments add column markup text;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add PlainText to the existing ones?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can provide an SQL script for that, indeed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, that I didn't notice that.

newComment := comment.Comment{
ParentID: ctx.ID,
Body: reqComment.Attributes.Body,
Markup: markup,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

htmlescape?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be addressed in #724, actually

@xcoulon xcoulon deleted the Issue707_Comment_markup branch February 9, 2017 14:29
AdamJ pushed a commit to AdamJ/almighty-core that referenced this pull request Mar 7, 2017
…ric8-services#717)

* Refactor comments to support markup types (fabric8-services#707)

Added a `markup` column in the `comments` table using
a migration script.
When creating or updating a comment, the default markup
is used if none was provided.
When showing comments, the default markup is also returned
if none was found in the database (ie, for older comments).

Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants