Add conversation presenter

This commit is contained in:
Frank Rousseau 2017-05-21 00:31:30 +02:00
parent 604075c570
commit 40d42f4b58
2 changed files with 29 additions and 0 deletions

View file

@ -0,0 +1,17 @@
class ConversationPresenter < BasePresenter
def initialize(conversation)
@conversation = conversation
end
def as_json
{
id: @conversation.id,
guid: @conversation.guid,
created_at: @conversation.created_at,
subject: @conversation.subject,
messages: @conversation.messages.map {|x| x.as_json["message"] },
author: @conversation.author,
participants: @conversation.participants
}
end
end

View file

@ -0,0 +1,12 @@
describe ConversationPresenter do
before do
@conversation = FactoryGirl.create(:conversation)
@presenter = ConversationPresenter.new(@conversation)
end
describe "#as_json" do
it "works" do
expect(@presenter.as_json).to be_a Hash
end
end
end