This commit is contained in:
Shlok Srivastava 2017-05-08 15:53:26 +00:00 committed by GitHub
commit aa974489df
69 changed files with 1371 additions and 377 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)

View file

@ -27,12 +27,6 @@ describe Program do
expect(build(:program)).to be_valid
end
it 'is valid for rating of 5' do
expect(build(:program, rating: 5)).to be_valid
end
it { is_expected.to validate_numericality_of(:rating).is_greater_than_or_equal_to(0).is_less_than_or_equal_to(10).only_integer }
it { is_expected.to validate_numericality_of(:schedule_interval).is_greater_than_or_equal_to(5).is_less_than_or_equal_to(60) }
describe 'schedule_interval_divisor_60' do
@ -60,6 +54,22 @@ describe Program do
end
describe 'voting_dates_exist' do
it 'is invalid with rating_enabled true, when voting dates does not exist' do
expect(build(:program, rating_enabled: true)).not_to be_valid
end
it 'is valid with rating_enabled true, when voting dates exist' do
expect(build(:program, rating_enabled: true, voting_start_date: Date.today, voting_end_date: Date.today + 1)).to be_valid
end
it 'is valid with blind_voting true, when voting dates exist' do
expect(build(:program, blind_voting: true, voting_start_date: Date.today, voting_end_date: Date.today + 1)).to be_valid
end
it 'is invalid with blind_voting true, when voting dates does not exist' do
expect(build(:program, blind_voting: true)).not_to be_valid
end
it 'is valid, when both voting_start_date and voting_end_date are set' do
expect(build(:program, voting_start_date: Date.today, voting_end_date: Date.today + 1)).to be_valid
end
@ -125,19 +135,6 @@ describe Program do
end
end
describe '#rating_enabled?' do
it 'returns true if proposals can be rated (program.rating > 0)' do
program.rating = 3
expect(program.rating_enabled?).to be true
end
it 'returns false if proposals cannot be rated (program.rating == 0) ' do
program = conference.program
program.rating = 0
expect(program.rating_enabled?).to be false
end
end
describe '#cfp_open?' do
describe 'returns true' do
it 'when there is an open Call for Papers for the conference' do

View file

@ -58,7 +58,6 @@ describe User do
it { is_expected.to have_many(:events_registrations).through(:registrations) }
it { is_expected.to have_many(:ticket_purchases).dependent(:destroy) }
it { is_expected.to have_many(:tickets).through(:ticket_purchases) }
it { is_expected.to have_many(:votes).dependent(:destroy) }
it { is_expected.to have_many(:subscriptions).dependent(:destroy) }
end

View file

@ -0,0 +1,37 @@
require 'spec_helper'
describe VotableField do
subject { create(:votable_field) }
describe 'validations' do
it 'has a valid factory' do
expect(build(:votable_field)).to be_valid
end
it 'is not valid without a title' do
subject.title = ''
expect(subject).to be_invalid
end
it 'is not valid without a votable field' do
should validate_presence_of(:votable_type)
end
it 'is valid with title containing special characters but not spaces' do
should allow_value('example-votable&field').for(:title)
end
it 'is not valid with title containing spaces' do
should_not allow_value('example votable field').for(:title)
end
it 'is not valid with unsupported votable_type' do
should_not allow_value('unsupported').for(:votable_type)
end
it 'is valid for supported votable types' do
should allow_value('Event').for(:votable_type)
end
end
end