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

@ -0,0 +1,7 @@
FactoryGirl.define do
factory :votable_field do
title { Faker::Lorem.word }
votable_type { 'Event' }
conference
end
end

View file

@ -1,7 +0,0 @@
FactoryGirl.define do
factory :vote do
event
user
rating 1
end
end

View file

@ -12,19 +12,5 @@ feature Program do
sign_in organizer
end
scenario 'changes rating', feature: true, js: true do
visit admin_conference_program_path(conference.short_title)
click_link 'Edit'
fill_in 'program_rating', with: '4'
click_button 'Update Program'
# Validations
expect(flash)
.to eq('The program was successfully updated.')
expect(find('#rating').text).to eq('4')
end
end
end

View file

@ -15,6 +15,7 @@ feature Event do
@event = create(:event, program: conference.program, title: 'Example Proposal')
@event.event_users.create(user: participant, event_role: 'submitter')
@event.event_users.create(user: participant, event_role: 'speaker')
create(:votable_field, conference: conference, for_admin: true)
end
after(:each) do
@ -26,6 +27,38 @@ feature Event do
sign_in organizer
end
scenario 'for program with voting enabled can successfully vote' do
conference.program.update(rating_enabled: true, voting_start_date: Date.current - 1, voting_end_date: Date.current + 1)
visit admin_conference_program_event_path(conference.short_title, @event)
expect(page.has_content?('Overall Votes')).to eq true
expect(page.has_content?('Your Votes')).to eq true
end
scenario 'for program with voting disabled cannot successfuly vote' do
conference.program.update(rating_enabled: false, voting_start_date: Date.today, voting_end_date: Date.today + 1)
visit admin_conference_program_event_path(conference.short_title, @event)
expect(page.has_content?('Overall Votes')).to eq false
expect(page.has_content?('Your Votes')).to eq false
end
scenario 'for program with blind voting enabled cannot see overall votes' do
conference.program.update(rating_enabled: true, voting_start_date: Date.today, voting_end_date: Date.today + 1, blind_voting: true)
visit admin_conference_program_event_path(conference.short_title, @event)
expect(page.has_content?('Overall Votes')).to eq false
expect(page.has_content?('Your Votes')).to eq true
end
scenario 'for program with blind voting disabled can see overall votes' do
conference.program.update(rating_enabled: true, voting_start_date: Date.today, voting_end_date: Date.today + 1, blind_voting: false)
visit admin_conference_program_event_path(conference.short_title, @event)
expect(page.has_content?('Overall Votes')).to eq true
expect(page.has_content?('Your Votes')).to eq true
end
scenario 'rejects a proposal', feature: true, js: true do
visit admin_conference_program_events_path(conference.short_title)
expect(page.has_content?('Example Proposal')).to be true

View file

@ -21,15 +21,6 @@ feature 'Version' do
expect(page).to have_text("#{organizer.name} updated social tag, email, googleplus and sponsor email of contact details in conference #{conference.short_title}")
end
scenario 'display changes in program', feature: true, versioning: true, js: true do
visit edit_admin_conference_program_path(conference.short_title)
fill_in 'program_rating', with: '4'
click_button 'Update Program'
visit admin_revision_history_path
expect(page).to have_text("#{organizer.name} updated rating of program in conference #{conference.short_title}")
end
scenario 'display changes in cfp', feature: true, versioning: true, js: true do
cfp = create(:cfp, program: conference.program)
cfp.update_attributes(start_date: (Date.today + 1).strftime('%d/%m/%Y'), end_date: (Date.today + 3).strftime('%d/%m/%Y'))
@ -346,20 +337,6 @@ feature 'Version' do
expect(page).to have_text("Someone (probably via the console) re-added #{organizer.name}'s comment on event #{event.title} in conference #{conference.short_title}")
end
scenario 'display changes in vote', feature: true, versioning: true, js: true do
conference.program.rating = 1
create(:event, program: conference.program, title: 'My first event')
event = create(:event, program: conference.program, title: 'My second event')
create(:vote, user: organizer, event: event)
Vote.last.destroy
PaperTrail::Version.last.reify.save
visit admin_revision_history_path
expect(page).to have_text("Someone (probably via the console) voted on event My second event in conference #{conference.short_title}")
expect(page).to have_text("Someone (probably via the console) deleted #{organizer.name}'s vote on event #{event.title} in conference #{conference.short_title}")
expect(page).to have_text("Someone (probably via the console) re-added #{organizer.name}'s vote on event #{event.title} in conference #{conference.short_title}")
end
scenario 'display changes in campaign', feature: true, versioning: true, js: true do
campaign = create(:campaign, conference: conference, name: 'Test Campaign', utm_campaign: 'campaign')
campaign.update_attributes(utm_source: 'source', utm_medium: 'medium', utm_term: 'term', utm_content: 'content')

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