Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6115 add guid to comments and posts for user export #6185

Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/serializers/export/comment_serializer.rb
@@ -1,6 +1,7 @@
module Export
class CommentSerializer < ActiveModel::Serializer
attributes :text,
attributes :guid,
:text,
:post_guid

def post_guid
Expand Down
3 changes: 2 additions & 1 deletion app/serializers/export/post_serializer.rb
@@ -1,6 +1,7 @@
module Export
class PostSerializer < ActiveModel::Serializer
attributes :text,
attributes :guid,
:text,
:public,
:diaspora_handle,
:type,
Expand Down
10 changes: 10 additions & 0 deletions spec/serializers/comment_serializer_spec.rb
@@ -0,0 +1,10 @@
require "spec_helper"

describe Export::CommentSerializer do
let(:comment) { create(:comment) }
subject(:json_output) { Export::CommentSerializer.new(comment).to_json }

it { is_expected.to include("\"guid\":\"#{comment.guid}\"") }
Copy link
Member

Choose a reason for hiding this comment

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

Actually it would be good to use percent literals for all these to avoid all the escaping:

it { is_expected.to include %("guid":"#{comment.guid}") }

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 wasn't aware of this! Thank you!

it { is_expected.to include("\"post_guid\":\"#{comment.post.guid}\"") }
it { is_expected.to include("\"text\":\"#{comment.text}\"") }
end
20 changes: 20 additions & 0 deletions spec/serializers/post_serializer_spec
@@ -0,0 +1,20 @@
require "spec_helper"

describe Export::PostSerializer do
let(:post) { create(:status_message_with_photo) }
subject(:json_output) { Export::PostSerializer.new(post).to_json }
subject(:json_output) { Export::PostSerializer.new(post).to_json }

it { is_expected.to include("\"guid\":\"#{post.guid}\"") }
it { is_expected.to include("\"text\":\"#{post.text}\"") }
it { is_expected.to include("\"public\":#{post.public}") }
it { is_expected.to include("\"diaspora_handle\":\"#{post.diaspora_handle}\"") }
it { is_expected.to include("\"type\":\"#{post.type}\"") }
it { is_expected.to include("\"image_url\":#{post.image_url}") }
it { is_expected.to include("\"image_height\":#{post.image_height}") }
it { is_expected.to include("\"image_width\":#{post.image_width}") }
it { is_expected.to include("\"likes_count\":#{post.likes_count}") }
it { is_expected.to include("\"comments_count\":#{post.comments_count}") }
it { is_expected.to include("\"reshares_count\":#{post.reshares_count}") }
it { is_expected.to include("\"created_at\":\"#{post.created_at.to_s[0, 4]}") }
Copy link
Member

Choose a reason for hiding this comment

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

What do you mean by mess up? That the format doesn't match post.created_at.to_s? That would be correct, just get the same format with post.created_at.strftime("...") with ... being the right format of course.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

post.created_at.to_s is perfect but Export::PostSerializer.new(post).to_json results in:

expected "{\"post\":{\"guid\":\"15b5e700096d0133dc4548d705df9e7b\",\"text\":\"There are 10 ninjas in this photo.\",\"public\":false,\"diaspora_handle\":\"bob-person-1044ae13@example.net\",\"type\":\"StatusMessage\",\"image_url\":null,\"image_height\":null,\"image_width\":null,\"likes_count\":0,\"comments_count\":0,\"reshares_count\":0,\"created_at\":\"2015-07-10T20:06:33.300Z\"}}" to include "\"created_at\":\"2015-07-10 20:06:33 UTC\""

=> created_at\":\"2015-07-10T20:06:33.300Z\"

Copy link
Member

Choose a reason for hiding this comment

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

That's simply ISO 8601:

[107] pry(main)> Time.now.utc.iso8601(3)                                                                                                                                
=> "2015-07-10T20:22:00.833Z"

end
Copy link
Member

Choose a reason for hiding this comment

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

This file lacks the .rb extension ;)