mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Merge pull request #944 from sonalkr132/serializers-test
Serializers test
This commit is contained in:
commit
ad77bea1db
7 changed files with 225 additions and 18 deletions
|
|
@ -7,7 +7,7 @@ class ConferenceSerializer < ActiveModel::Serializer
|
|||
object.program.difficulty_levels.map do |difficulty_level| { id: difficulty_level.id,
|
||||
title: difficulty_level.title,
|
||||
description: difficulty_level.description
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ class ConferenceSerializer < ActiveModel::Serializer
|
|||
title: event_type.title,
|
||||
length: event_type.length,
|
||||
description: event_type.description
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -36,9 +36,9 @@ class ConferenceSerializer < ActiveModel::Serializer
|
|||
difficulty_level_id: event.difficulty_level_id,
|
||||
track_id: event.track_id,
|
||||
speaker_names: event.speaker_names
|
||||
}
|
||||
}
|
||||
end
|
||||
}
|
||||
}
|
||||
end
|
||||
else
|
||||
[]
|
||||
|
|
@ -49,22 +49,10 @@ class ConferenceSerializer < ActiveModel::Serializer
|
|||
object.program.tracks.map do |track| { 'id' => track.id,
|
||||
'name' => track.name,
|
||||
'description' => track.description
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def name
|
||||
object.title
|
||||
end
|
||||
|
||||
def year
|
||||
object.start_date.try(:year)
|
||||
end
|
||||
|
||||
def socialtag
|
||||
object.contact.social_tag
|
||||
end
|
||||
|
||||
def revision
|
||||
object.revision || 0
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ class EventSerializer < ActiveModel::Serializer
|
|||
|
||||
def date
|
||||
t = object.start_time
|
||||
t.blank? ? '' : %{ #{l t, format: :short}#{t.formatted_offset(false)} }
|
||||
t.blank? ? '' : %{ #{I18n.l t, format: :short}#{t.formatted_offset(false)} }
|
||||
end
|
||||
|
||||
def speaker_ids
|
||||
|
|
|
|||
91
spec/serializers/conference_serializer_spec.rb
Normal file
91
spec/serializers/conference_serializer_spec.rb
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
require 'spec_helper'
|
||||
describe ConferenceSerializer, type: :serializer do
|
||||
let(:conference) do
|
||||
create(:conference, short_title: 'goto',
|
||||
description: 'Lorem ipsum dolor sit',
|
||||
start_date: Date.new(2014, 03, 04),
|
||||
end_date: Date.new(2014, 03, 10))
|
||||
end
|
||||
|
||||
let(:serializer) { ConferenceSerializer.new(conference) }
|
||||
let(:expected_hash) do
|
||||
{
|
||||
conference: {
|
||||
short_title: 'goto',
|
||||
title: 'The dog and pony show',
|
||||
description: 'Lorem ipsum dolor sit',
|
||||
start_date: '2014-03-04',
|
||||
end_date: '2014-03-10',
|
||||
logo: '/logos/original/missing.png',
|
||||
difficulty_levels:
|
||||
[{id: 1,
|
||||
title: 'Easy',
|
||||
description: 'Events are understandable for everyone without knowledge of the topic.'
|
||||
},
|
||||
{id: 2,
|
||||
title: 'Medium',
|
||||
description: 'Events require a basic understanding of the topic.'
|
||||
},
|
||||
{id: 3,
|
||||
title: 'Hard',
|
||||
description: 'Events require expert knowledge of the topic.'
|
||||
}
|
||||
],
|
||||
event_types:
|
||||
[{id: 1,
|
||||
title: 'Talk',
|
||||
length: 30,
|
||||
description: 'Presentation in lecture format'
|
||||
},
|
||||
{id: 2,
|
||||
title: 'Workshop',
|
||||
length: 60,
|
||||
description: 'Interactive hands-on practice'
|
||||
}
|
||||
],
|
||||
rooms: [],
|
||||
tracks: [],
|
||||
date_range: 'March 04 - 10',
|
||||
revision: 1
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
context 'conference does not have rooms and tracks' do
|
||||
it 'sets conference attributes with empty room and tracks' do
|
||||
expect(serializer.to_json).to eq expected_hash.to_json
|
||||
end
|
||||
end
|
||||
|
||||
context 'conference has rooms and tracks' do
|
||||
before do
|
||||
venue = create(:venue, conference: conference)
|
||||
_room = create(:room, venue: venue)
|
||||
_track = create(:track, program: conference.program)
|
||||
|
||||
room_hash = {
|
||||
rooms: [{
|
||||
id: 1,
|
||||
size: 4,
|
||||
events: []
|
||||
}
|
||||
]
|
||||
}
|
||||
track_hash = {
|
||||
tracks: [{
|
||||
id: 1,
|
||||
name: 'Example Track',
|
||||
description: 'Lorem Ipsum dolsum'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
expected_hash[:conference].merge! room_hash
|
||||
expected_hash[:conference].merge! track_hash
|
||||
end
|
||||
|
||||
it 'sets conference attributes with rooms and tracks' do
|
||||
expect(serializer.to_json).to eq expected_hash.to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
58
spec/serializers/event_serializer_spec.rb
Normal file
58
spec/serializers/event_serializer_spec.rb
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
require 'spec_helper'
|
||||
describe EventSerializer, type: :serializer do
|
||||
let(:event) { create(:event, title: 'Some Talk', abstract: 'Lorem ipsum dolor sit amet') }
|
||||
let(:serializer) { EventSerializer.new(event) }
|
||||
|
||||
context 'event does not have date, speakers, room and tracks assigned' do
|
||||
it 'sets guid, title, length, abstract and type' do
|
||||
expected_json = {
|
||||
event: {
|
||||
guid: event.guid,
|
||||
title: 'Some Talk',
|
||||
length: 30,
|
||||
date: '',
|
||||
language: nil,
|
||||
abstract: '<p>Lorem ipsum dolor sit amet</p>',
|
||||
speaker_ids: [],
|
||||
type: 'Example Event Type',
|
||||
room: nil,
|
||||
track: nil
|
||||
}
|
||||
}.to_json
|
||||
|
||||
expect(serializer.to_json).to eq expected_json
|
||||
end
|
||||
end
|
||||
|
||||
context 'event has date, speakers, room and tracks assigned' do
|
||||
let(:speaker) { create(:speaker) }
|
||||
let(:room) { create(:room) }
|
||||
let(:track) { create(:track) }
|
||||
|
||||
before do
|
||||
event.update_attributes(start_time: Date.new(2014, 03, 04), language: 'English')
|
||||
event.event_users << speaker
|
||||
event.room = room
|
||||
event.track = track
|
||||
end
|
||||
|
||||
it 'sets guid, title, length, abstract, type, date, language, speakers, room and track' do
|
||||
expected_json = {
|
||||
event: {
|
||||
guid: event.guid,
|
||||
title: 'Some Talk',
|
||||
length: 30,
|
||||
date: ' 2014-03-04T00:00:00+0000 ',
|
||||
language: 'English',
|
||||
abstract: '<p>Lorem ipsum dolor sit amet</p>',
|
||||
speaker_ids: [speaker.user.id],
|
||||
type: 'Example Event Type',
|
||||
room: room.guid,
|
||||
track: track.guid
|
||||
}
|
||||
}.to_json
|
||||
|
||||
expect(serializer.to_json).to eq expected_json
|
||||
end
|
||||
end
|
||||
end
|
||||
17
spec/serializers/room_serializer_spec.rb
Normal file
17
spec/serializers/room_serializer_spec.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
require 'spec_helper'
|
||||
describe RoomSerializer, type: :serializer do
|
||||
let(:room) { create(:room) }
|
||||
let(:serializer) { RoomSerializer.new(room) }
|
||||
|
||||
it 'set guid, name and description' do
|
||||
expected_json = {
|
||||
room: {
|
||||
guid: room.guid,
|
||||
name: 'Example Room',
|
||||
description: ''
|
||||
}
|
||||
}.to_json
|
||||
|
||||
expect(serializer.to_json).to eq expected_json
|
||||
end
|
||||
end
|
||||
35
spec/serializers/speaker_serializer_spec.rb
Normal file
35
spec/serializers/speaker_serializer_spec.rb
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
require 'spec_helper'
|
||||
describe SpeakerSerializer, type: :serializer do
|
||||
let(:speaker) { create(:user, name: 'John Doe', affiliation: 'JohnDoesInc', biography: nil) }
|
||||
let(:serializer) { SpeakerSerializer.new(speaker) }
|
||||
|
||||
context 'speaker does not have biography' do
|
||||
it 'sets name and affiliation' do
|
||||
expected_json = {
|
||||
speaker: {
|
||||
name: 'John Doe',
|
||||
affiliation: 'JohnDoesInc',
|
||||
biography: nil
|
||||
}
|
||||
}.to_json
|
||||
|
||||
expect(serializer.to_json).to eq expected_json
|
||||
end
|
||||
end
|
||||
|
||||
context 'speaker has biography' do
|
||||
before{ speaker.update_attributes(biography: 'Doest of all Jon Does') }
|
||||
|
||||
it 'sets name, affiliation and biography' do
|
||||
expected_json = {
|
||||
speaker: {
|
||||
name: 'John Doe',
|
||||
affiliation: 'JohnDoesInc',
|
||||
biography: '<p>Doest of all Jon Does</p>'
|
||||
}
|
||||
}.to_json
|
||||
|
||||
expect(serializer.to_json).to eq expected_json
|
||||
end
|
||||
end
|
||||
end
|
||||
18
spec/serializers/track_serializer_spec.rb
Normal file
18
spec/serializers/track_serializer_spec.rb
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe TrackSerializer, type: :serializer do
|
||||
let(:track) { create(:track) }
|
||||
let(:serializer) { TrackSerializer.new(track) }
|
||||
|
||||
it 'sets guild, name, color' do
|
||||
expected_json = {
|
||||
track: {
|
||||
guid: track.guid,
|
||||
name: 'Example Track',
|
||||
color: '#ffffff'
|
||||
}
|
||||
}.to_json
|
||||
|
||||
expect(serializer.to_json).to eq expected_json
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue