Merge pull request #1371 from amiedes/test-coverage

Increase test coverage for user model. Fix small bug.
This commit is contained in:
Ana María Martínez Gómez 2017-03-17 13:32:47 +01:00 committed by GitHub
commit f73c449be8
2 changed files with 49 additions and 1 deletions

View file

@ -87,7 +87,7 @@ class User < ActiveRecord::Base
# ====Returns
# * +true+ or +false+
def registered_to_event? event
event.registrations.pluck(:id).include? self.registrations.find_by(conference_id: event.program.conference.id).id
event.registrations.include? registrations.find_by(conference: event.program.conference)
end
def subscribed? conference

View file

@ -14,6 +14,8 @@ describe User do
let(:event1) { create(:event, program: conference.program) }
let(:another_conference) { create(:conference) }
let(:event2) { create(:event, program: another_conference.program) }
let(:registration) { create(:registration, user: user, conference: conference) }
let(:events_registration) { create(:events_registration, event: event1, registration: registration) }
describe 'validation' do
it 'has a valid factory' do
@ -87,6 +89,34 @@ describe User do
end
describe 'methods' do
describe '#attended_event?' do
context 'user has attended to the event' do
before do
events_registration.update_attributes(attended: true)
end
it 'returns true' do
expect(user.attended_event?(event1)).to be true
end
end
context 'user did not register for the event' do
it 'returns false' do
expect(user.attended_event?(event1)).to be false
end
end
context 'user registered for the event, but did not attend' do
before do
events_registration
end
it 'returns false' do
expect(user.attended_event?(event1)).to be false
end
end
end
describe '#name' do
it 'returns the username as name if there is not name' do
user = create(:user, name: nil)
@ -94,6 +124,24 @@ describe User do
end
end
describe '#registered_to_event?' do
context 'user has registered to event' do
before do
events_registration
end
it 'returns true' do
expect(user.registered_to_event?(event1)).to be true
end
end
context 'user has not registered to event' do
it 'returns false' do
expect(user.registered_to_event?(event1)).to be false
end
end
end
describe '#subscribed?' do
context 'user has subscribed to conference' do
before { create(:subscription, user: user, conference: conference) }