Implement Event Ratings

This commit is contained in:
shlok007 2016-09-22 20:06:46 -04:00 committed by Shlok Srivastava
parent 5be1ad52ee
commit 20f4853487
67 changed files with 1298 additions and 378 deletions

View file

@ -169,70 +169,6 @@ describe Event do
end
end
describe '#user_rating' do
it 'returns 0 if the event has no votes' do
expect(event.user_rating(user)).to eq 0
end
it 'returns 0 if the event has no votes from that user' do
create(:vote, user: another_user, event: event)
expect(event.user_rating(user)).to eq 0
end
it 'returns the rating if the event has votes from that user' do
create(:vote, user: another_user, event: event, rating: 3)
create(:vote, user: user, event: event, rating: 2)
expect(event.user_rating(user)).to eq 2
end
end
describe '#voted?' do
it 'returns false if the event has no votes' do
expect(event.voted?).to eq false
end
it 'returns false if the event has no votes by that user' do
create(:vote, user: another_user, event: event)
expect(event.voted?(user)).to eq false
end
it 'returns true when the event has votes' do
create(:vote, user: another_user, event: event)
expect(event.voted?).to eq true
end
it 'returns true when the event has votes by that user' do
create(:vote, user: user, event: event)
expect(event.voted?(user)).to eq true
end
end
describe '#average_rating' do
context 'returns 0' do
it 'when there are no votes' do
expect(event.average_rating).to eq 0
end
end
context 'returns the average voting' do
before :each do
another_user = create(:user)
create(:vote, user: user, event: event, rating: 1)
create(:vote, user: another_user, event: event, rating: 3)
end
it 'when there are votes and the average is integer' do
expect(event.average_rating).to eq '2'
end
it 'when there are votes and the average is float' do
new_user = create(:user)
create(:vote, user: new_user, event: event, rating: 3)
expect(event.average_rating).to eq '2.33'
end
end
end
describe '#submitter' do
it 'returns the user that submitted the event' do
submitter = create(:user)