Merge pull request #1371 from amiedes/test-coverage
Increase test coverage for user model. Fix small bug.
This commit is contained in:
commit
f73c449be8
2 changed files with 49 additions and 1 deletions
|
|
@ -87,7 +87,7 @@ class User < ActiveRecord::Base
|
||||||
# ====Returns
|
# ====Returns
|
||||||
# * +true+ or +false+
|
# * +true+ or +false+
|
||||||
def registered_to_event? event
|
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
|
end
|
||||||
|
|
||||||
def subscribed? conference
|
def subscribed? conference
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ describe User do
|
||||||
let(:event1) { create(:event, program: conference.program) }
|
let(:event1) { create(:event, program: conference.program) }
|
||||||
let(:another_conference) { create(:conference) }
|
let(:another_conference) { create(:conference) }
|
||||||
let(:event2) { create(:event, program: another_conference.program) }
|
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
|
describe 'validation' do
|
||||||
it 'has a valid factory' do
|
it 'has a valid factory' do
|
||||||
|
|
@ -87,6 +89,34 @@ describe User do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'methods' do
|
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
|
describe '#name' do
|
||||||
it 'returns the username as name if there is not name' do
|
it 'returns the username as name if there is not name' do
|
||||||
user = create(:user, name: nil)
|
user = create(:user, name: nil)
|
||||||
|
|
@ -94,6 +124,24 @@ describe User do
|
||||||
end
|
end
|
||||||
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
|
describe '#subscribed?' do
|
||||||
context 'user has subscribed to conference' do
|
context 'user has subscribed to conference' do
|
||||||
before { create(:subscription, user: user, conference: conference) }
|
before { create(:subscription, user: user, conference: conference) }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue