Add conversation presenter
This commit is contained in:
parent
604075c570
commit
40d42f4b58
2 changed files with 29 additions and 0 deletions
17
app/presenters/conversation_presenter.rb
Normal file
17
app/presenters/conversation_presenter.rb
Normal 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
|
||||
12
spec/presenters/conversation_presenter.rb
Normal file
12
spec/presenters/conversation_presenter.rb
Normal 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
|
||||
Loading…
Reference in a new issue