-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new participant attributes to the session json export
- Loading branch information
1 parent
e662dc3
commit b821bf7
Showing
7 changed files
with
108 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class SessionsJsonBuilder | ||
|
||
def to_hash(session) | ||
s = session | ||
{ id: s.id, | ||
participant_id: s.participant.id, | ||
presenter_name: s.participant.name, | ||
presenter_twitter_handle: s.participant.twitter_handle, | ||
presenter_github_username: s.participant.github_profile_username, | ||
presenter_github_og_image: s.participant.github_og_image, | ||
session_title: s.title, | ||
summary: s.summary, | ||
description: s.description, | ||
room_name: s.room_name, | ||
panel: s.panel, | ||
projector: s.projector, | ||
starts_at: s.starts_at, | ||
level_name: s.level_name, | ||
categories: s.categories.map(&:name), | ||
other_presenter_names: s.other_presenter_names, | ||
other_presenter_ids: s.other_presenters.map(&:id), | ||
attendance_count: s.attendances.count, | ||
created_at: s.created_at.utc, | ||
updated_at: s.updated_at.utc | ||
} | ||
end | ||
|
||
def to_json(sessions) | ||
require 'json' | ||
JSON.pretty_generate(sessions.map(&:to_h)) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require "spec_helper" | ||
|
||
describe SessionsJsonBuilder do | ||
let(:event) { create(:event) } | ||
let(:session) { create(:session, event: event) } | ||
|
||
describe "to_hash" do | ||
subject { SessionsJsonBuilder.new } | ||
it "should have all the attributes" do | ||
h = subject.to_hash(session) | ||
|
||
expect(h[:id]).to be session.id | ||
expect(h[:participant_id]).to be session.participant_id | ||
|
||
expect(h[:presenter_name]).to be session.participant.name | ||
expect(h[:presenter_twitter_handle]).to be session.participant.twitter_handle | ||
expect(h[:presenter_github_username]).to be session.participant.github_profile_username | ||
expect(h[:presenter_github_og_image]).to be session.participant.github_og_image | ||
expect(h[:session_title]).to be session.title | ||
expect(h[:summary]).to be session.summary | ||
expect(h[:description]).to be session.description | ||
expect(h[:room_name]).to be session.room_name | ||
expect(h[:panel]).to be session.panel | ||
expect(h[:projector]).to be session.projector | ||
expect(h[:starts_at]).to be session.starts_at | ||
expect(h[:level_name]).to be session.level_name | ||
expect(h[:categories]).to match_array session.categories.map(&:name) | ||
expect(h[:other_presenter_names]).to match_array session.other_presenter_names | ||
expect(h[:other_presenter_ids]).to match_array session.other_presenters.map(&:id) | ||
expect(h[:attendance_count]).to be session.attendances.count | ||
expect(h[:created_at]).to be session.created_at.utc | ||
expect(h[:updated_at]).to be session.updated_at.utc | ||
|
||
end | ||
end | ||
end |