mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-15 20:54:03 +00:00
Merge pull request #931 from nishanthvijayan/fix-api-events-speakers
Fix api controllers events and speakers
This commit is contained in:
commit
c4e782a90c
4 changed files with 81 additions and 3 deletions
|
|
@ -5,10 +5,10 @@ module Api
|
|||
respond_to :json
|
||||
|
||||
def index
|
||||
events = Event.includes(:conference, :track, :room, :event_type, event_users: :user)
|
||||
events = Event.includes(:track, :room, :event_type, event_users: :user)
|
||||
|
||||
if @conference
|
||||
events = events.where(conference: @conference)
|
||||
events = events.where(program: @conference.program)
|
||||
end
|
||||
|
||||
respond_with events.confirmed
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ module Api
|
|||
|
||||
def index
|
||||
if @conference
|
||||
users = User.joins(event_users: { event: :conference })
|
||||
users = User.joins(event_users: { event: { program: :conference} })
|
||||
users = users.where(conferences: { short_title: @conference.short_title })
|
||||
else
|
||||
users = User.joins(:event_users)
|
||||
|
|
|
|||
35
spec/controllers/api/v1/events_controller_spec.rb
Normal file
35
spec/controllers/api/v1/events_controller_spec.rb
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Api::V1::EventsController do
|
||||
let!(:conference) { create(:conference) }
|
||||
let!(:event) { create(:event_full, state: 'confirmed', title: 'Example Event') }
|
||||
let!(:conference_event) { create(:event_full, state: 'confirmed', title: 'Conference Event', program: conference.program) }
|
||||
|
||||
describe 'GET #index' do
|
||||
context 'without conference scope' do
|
||||
it 'returns all confirmed events' do
|
||||
|
||||
get :index, format: :json
|
||||
json = JSON.parse(response.body)['events']
|
||||
expect(response).to be_success
|
||||
|
||||
expect(json.length).to eq(2)
|
||||
expect(json[0]['title']).to eq('Example Event')
|
||||
expect(json[1]['title']).to eq('Conference Event')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with conference scope' do
|
||||
it 'returns all confirmed events of conference' do
|
||||
|
||||
get :index, conference_id: conference.short_title, format: :json
|
||||
json = JSON.parse(response.body)['events']
|
||||
|
||||
expect(response).to be_success
|
||||
|
||||
expect(json.length).to eq(1)
|
||||
expect(json[0]['title']).to eq('Conference Event')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
43
spec/controllers/api/v1/speakers_controller_spec.rb
Normal file
43
spec/controllers/api/v1/speakers_controller_spec.rb
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Api::V1::SpeakersController do
|
||||
let!(:conference) { create(:conference) }
|
||||
let!(:event) { create(:event_full) }
|
||||
let!(:conference_event) { create(:event_full, program: conference.program) }
|
||||
|
||||
let(:speaker) { create(:user, name: 'Speaker') }
|
||||
let(:conference_speaker) { create(:user, name: 'Conf_Speaker') }
|
||||
|
||||
describe 'GET #index' do
|
||||
before do
|
||||
event.event_users << create(:speaker, user: speaker)
|
||||
conference_event.event_users << create(:speaker, user: conference_speaker)
|
||||
end
|
||||
|
||||
context 'without conference scope' do
|
||||
it 'returns all speakers' do
|
||||
|
||||
get :index, format: :json
|
||||
json = JSON.parse(response.body)['speakers']
|
||||
expect(response).to be_success
|
||||
|
||||
expect(json.length).to eq(2)
|
||||
expect(json[0]['name']).to eq('Speaker')
|
||||
expect(json[1]['name']).to eq('Conf_Speaker')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with conference scope' do
|
||||
it 'returns all speakers of conference' do
|
||||
|
||||
get :index, conference_id: conference.short_title, format: :json
|
||||
json = JSON.parse(response.body)['speakers']
|
||||
|
||||
expect(response).to be_success
|
||||
|
||||
expect(json.length).to eq(1)
|
||||
expect(json[0]['name']).to eq('Conf_Speaker')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue