From 40d42f4b58ddc909a4addf3172f4645ecc26e6d0 Mon Sep 17 00:00:00 2001 From: Frank Rousseau Date: Sun, 21 May 2017 00:31:30 +0200 Subject: [PATCH] Add conversation presenter --- app/presenters/conversation_presenter.rb | 17 +++++++++++++++++ spec/presenters/conversation_presenter.rb | 12 ++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 app/presenters/conversation_presenter.rb create mode 100644 spec/presenters/conversation_presenter.rb diff --git a/app/presenters/conversation_presenter.rb b/app/presenters/conversation_presenter.rb new file mode 100644 index 000000000..65abd1f2b --- /dev/null +++ b/app/presenters/conversation_presenter.rb @@ -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 diff --git a/spec/presenters/conversation_presenter.rb b/spec/presenters/conversation_presenter.rb new file mode 100644 index 000000000..f78a236d6 --- /dev/null +++ b/spec/presenters/conversation_presenter.rb @@ -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