[feat] Happening now JSON endpoint contains rendered abstract of event; Add corresponding tests

This commit is contained in:
Jimmy 2021-03-31 17:35:25 +08:00
parent 7b3d97fdbb
commit c3167a3503
3 changed files with 21 additions and 1 deletions

View file

@ -33,6 +33,8 @@
class Event < ApplicationRecord
include ActiveRecord::Transitions
include RevisionCount
include FormatHelper
has_paper_trail on: [:create, :update], ignore: [:updated_at, :guid, :week], meta: { conference_id: :conference_id }
acts_as_commentable
@ -337,6 +339,10 @@ class Event < ApplicationRecord
time <=> other.time
end
def serializable_hash(options = {})
super(options).merge('rendered_abstract' => markdown(abstract))
end
private
##

View file

@ -34,7 +34,7 @@ describe SchedulesController do
let!(:selected_schedule) { create(:schedule, program: program) }
let!(:scheduled_event1) do
program.update_attributes!(selected_schedule: selected_schedule)
create(:event, program: program, state: 'confirmed')
create(:event, program: program, state: 'confirmed', abstract: '`markdown`')
end
let!(:event_schedule1) { create(:event_schedule, event: scheduled_event1, schedule: selected_schedule, start_time: Time.now.in_time_zone(conference2.timezone).strftime('%a, %d %b %Y %H:%M:%S')) }
let!(:scheduled_event2) do
@ -66,6 +66,10 @@ describe SchedulesController do
expect(response.body).to include(event_schedule1.to_json(include: :event))
expect(response.body).not_to include(event_schedule2.to_json(include: :event))
end
it 'contains the rendered markdown in HTML of events that are happening now' do
expect(response.body).to include('code')
end
end
end
end

View file

@ -448,4 +448,14 @@ describe Event do
end
end
end
describe '#serializable_hash' do
let(:event2) { create(:event, program: conference.program, abstract: '`markdown`') }
context 'serializes event correctly' do
it 'contains rendered markdown in HTML' do
expect(event2.serializable_hash['rendered_abstract']).to include('<code>markdown</code>')
end
end
end
end