Skip to content

Commit

Permalink
Merge branch 'flexibus/#379/teams-page-design' of https://github.com/…
Browse files Browse the repository at this point in the history
…hpi-swt2/sport-portal into flexibus/#379/teams-page-design
  • Loading branch information
emanuel.metzenthin committed Jan 20, 2018
2 parents a112d53 + 6c388a6 commit 8feeb57
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 133 deletions.
2 changes: 1 addition & 1 deletion spec/controllers/events_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@
expect(response).to redirect_to(events_url)
end
end
#this test is only for leagues

describe "GET League#schedule" do
it "should generate schedule if not existing" do
event = League.create! valid_league_attributes
Expand Down
9 changes: 0 additions & 9 deletions spec/factories/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,6 @@
end
end

factory :event_with_teams do
transient do
teams_count 5
end
after(:create) do |event, evaluator|
FactoryBot.create_list(:team, evaluator.teams_count, events: [event])
end
end

trait :fcfs do
selection_type Event.selection_types[:fcfs]
end
Expand Down
5 changes: 0 additions & 5 deletions spec/factories/leagues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,5 @@
factory :league, parent: :event, traits: [:has_dates], class: League do
game_mode :round_robin
gameday_duration 7

factory :league_with_teams, class: League, parent: :event_with_teams, traits: [:has_dates] do
game_mode :round_robin
gameday_duration 7
end
end
end
3 changes: 0 additions & 3 deletions spec/factories/rankinglists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
game_mode Rankinglist.game_modes.keys.sample
initial_value 1.3
player_type Event.player_types[:single]

factory :rankinglist_with_teams, class: "Rankinglist", parent: :event_with_teams do
end
end
end
5 changes: 0 additions & 5 deletions spec/factories/tournaments.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
FactoryBot.define do
factory :tournament, parent: :event, traits: [:has_dates], class: Tournament do
game_mode :ko

factory :tournament_with_teams, class: Tournament, parent: :event_with_teams, traits: [:has_dates] do
teams_count 4
game_mode :ko
end
end
end
133 changes: 78 additions & 55 deletions spec/features/event/new_event_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
require 'rails_helper'

describe 'new event page', type: :feature do

def fill_in_fields_with(fields = {})
fields.each do |field_symbol, input|
fill_in Event.human_attribute_name(field_symbol), with: input
end
end

def select_dropdowns_with(dropdowns = {})
dropdowns.each do |dropdown, input|
select input, from: dropdown
end
end

def has_input_fields(*fields)
fields.each do |field|
expect(page).to have_field(Event.human_attribute_name field)
end
end

def has_content(fields)
fields.each do |field, content|
expect(page).to have_content(Event.human_attribute_name field)
expect(page).to have_content content
end
end

before(:each) do
@user = FactoryBot.create :user
sign_in @user
Expand All @@ -10,90 +36,89 @@
let(:new_path) { new_league_path } # /new?type=league

it 'should render without errors' do
visit new_path
end
visit new_path
end

it 'should be possible to enter date conditions' do
visit new_path

expect(page).to have_field(Event.human_attribute_name :deadline)
expect(page).to have_field(Event.human_attribute_name :startdate)
expect(page).to have_field(Event.human_attribute_name :enddate)
has_input_fields :deadline, :startdate, :enddate
end

it 'should have a field for league duration' do
visit new_path

expect(page).to have_field('event_duration')
expect(page).to have_field 'event_duration'
end

it 'should be possible to create a date conditions' do
visit new_path
fill_in Event.human_attribute_name(:name), with: 'name'
fill_in Event.human_attribute_name(:discipline), with: 'soccer'
select League.human_game_mode(:round_robin), from: Event.human_attribute_name(:game_mode)
select Event.human_player_type(:single), from: Event.human_attribute_name(:player_type)
fill_in Event.human_attribute_name(:max_teams), with: '5'
let(:league) { FactoryBot.build(:league) }
let(:valid_league_input_fields) { { name: league.name,
discipline: league.discipline,
max_teams: league.max_teams,
deadline: league.deadline,
startdate: league.startdate,
enddate: league.enddate,
gameday_duration: league.gameday_duration } }
let(:valid_league_dropdowns) { { Event.human_attribute_name(:game_mode) => League.human_game_mode(:round_robin),
Event.human_attribute_name(:player_type) => Event.human_player_type(:single) } }

fill_in Event.human_attribute_name(:deadline), with: Date.tomorrow.to_s
fill_in Event.human_attribute_name(:startdate), with: (Date.tomorrow + 2).to_s
fill_in Event.human_attribute_name(:enddate), with: (Date.tomorrow + 3).to_s
fill_in Event.human_attribute_name(:gameday_duration), with: '1'
it 'should be possible to create a league' do
visit new_path
fill_in_fields_with valid_league_input_fields
select_dropdowns_with valid_league_dropdowns

find('input[type="submit"]').click
has_content valid_league_input_fields
has_content valid_league_dropdowns

expect(page).to have_current_path(/.*\/leagues\/\d+/)
expect(page).to have_content(Date.tomorrow.to_s)
expect(page).to have_content((Date.tomorrow + 2).to_s)
expect(page).to have_content((Date.tomorrow + 3).to_s)
end
end

context "for ranking lists" do
context 'for ranking lists' do
before :each do
visit new_rankinglist_path
end

it "should show a field for choosing the ranking metric" do
it 'should show a field for choosing the ranking metric' do
expect(page).to have_field('rankinglist_game_mode')
end

it "should show a field for choosing the initial value of the ranking metric" do
it 'should show a field for choosing the initial value of the ranking metric' do
expect(page).to have_field('rankinglist_initial_value')
end

it "should not show a field for defining a deadline" do
it 'should not show a field for defining a deadline' do
expect(page).not_to have_field('event_deadline')
end

it "should not show a field for defining a enddate " do
it 'should not show a field for defining a enddate ' do
expect(page).not_to have_field('event_enddate')
end

it "should not show a field for defining a startdate" do
it 'should not show a field for defining a startdate' do
expect(page).not_to have_field('event_startdate')
end

it "should not show a field for defining whether its a team or single player sport" do
it 'should not show a field for defining whether its a team or single player sport' do
expect(page).not_to have_field('event_player_type')
end

it "should not show a field for the duration" do
it 'should not show a field for the duration' do
expect(page).not_to have_field('event_duration')
end
let(:rankinglist) { FactoryBot.build :rankinglist }
let(:ranking_list_input_fields) { { name: rankinglist.name, discipline: rankinglist.discipline,
max_teams: rankinglist.max_teams, initial_value: rankinglist.initial_value } }

it "should be possible to create a rankinglist" do
rankinglist = FactoryBot.build :rankinglist

fill_in Event.human_attribute_name(:name), with: rankinglist.name
fill_in Event.human_attribute_name(:discipline), with: rankinglist.discipline
it 'should be possible to create a rankinglist' do
fill_in_fields_with ranking_list_input_fields
select Rankinglist.human_game_mode(:true_skill), from: Event.human_attribute_name(:game_mode)
fill_in Event.human_attribute_name(:max_teams), with: rankinglist.max_teams
fill_in Event.human_attribute_name(:initial_value), with: rankinglist.initial_value

find('input[type="submit"]').click

expect(page).to have_current_path(/.*\/rankinglists\/\d+/)
has_content ranking_list_input_fields.except(:initial_value)
end
end

Expand All @@ -107,36 +132,34 @@
it 'should be possible to enter date conditions' do
visit new_path

expect(page).to have_field(Event.human_attribute_name :deadline)
expect(page).to have_field(Event.human_attribute_name :startdate)
expect(page).to have_field(Event.human_attribute_name :enddate)
has_input_fields :deadline, :startdate, :enddate
end

it 'should have a field for league duration' do
it 'should have a field for tournament duration' do
visit new_path

expect(page).to have_field('event_duration')
expect(page).to have_field 'event_duration'
end

it 'should be possible to create a date conditions' do
let(:tournament) { FactoryBot.build(:tournament) }
let(:valid_tournament_input_fields) { { name: tournament.name,
discipline: tournament.discipline,
max_teams: tournament.max_teams,
deadline: tournament.deadline,
startdate: tournament.startdate,
enddate: tournament.enddate } }
let(:valid_tournament_dropdowns) { { Event.human_attribute_name(:game_mode) => Tournament.human_game_mode(tournament.game_mode),
Event.human_attribute_name(:player_type) => Event.human_player_type(:single) } }
it 'should be possible to create a tournament' do
visit new_path

fill_in Event.human_attribute_name(:name), with: 'name'
fill_in Event.human_attribute_name(:discipline), with: 'soccer'
select Tournament.human_game_mode(:ko), from: Event.human_attribute_name(:game_mode)
select Event.human_player_type(:single), from: Event.human_attribute_name(:player_type)
fill_in Event.human_attribute_name(:max_teams), with: '5'

fill_in Event.human_attribute_name(:deadline), with: Date.tomorrow.to_s
fill_in Event.human_attribute_name(:startdate), with: (Date.tomorrow + 2).to_s
fill_in Event.human_attribute_name(:enddate), with: (Date.tomorrow + 3).to_s

fill_in_fields_with valid_tournament_input_fields
select_dropdowns_with valid_tournament_dropdowns
find('input[type="submit"]').click

expect(page).to have_current_path(/.*\/(events|tournaments|leagues)\/\d+/)
expect(page).to have_content(Date.tomorrow.to_s)
expect(page).to have_content((Date.tomorrow + 2).to_s)
expect(page).to have_content((Date.tomorrow + 3).to_s)
expect(page).to have_current_path(/.*\/tournaments\/\d+/)
has_content valid_tournament_input_fields
has_content valid_tournament_dropdowns
end
end
end
44 changes: 44 additions & 0 deletions spec/models/actual_event_examples.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
shared_examples 'an actual event' do |for_class: :event|
let(:event) { FactoryBot.build(for_class) }
it 'should not validate without selection_type' do
event.selection_type = nil
expect(event.valid?).to eq(false)
end

it 'should have an attribute deadline' do
date = Date.tomorrow
expect(event.deadline).to eq date

event.deadline = nil
expect(event).not_to be_valid
end

it 'should have an attribute startdate' do
date = Date.current + 2
expect(event.startdate).to eq date

expect(event).to be_valid
event.startdate = nil
expect(event).not_to be_valid
end

it 'should have an attribute enddate' do
date = Date.current + 3
expect(event.enddate).to eq date

expect(event).to be_valid
event.enddate = nil
expect(event).not_to be_valid
end

it 'should not be possible to have an enddate, that is before the startdate' do
expect(event).to be_valid
event.enddate = Date.current
event.startdate = Date.current + 1
expect(event).not_to be_valid
end

it 'should be possible to get the duration in day of a event' do
expect(event.duration).to eq(2)
end
end
60 changes: 11 additions & 49 deletions spec/models/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,62 +23,21 @@

describe 'Event model', type: :model do

let(:event) { FactoryBot.build(:league) }
let(:event) { FactoryBot.build(:event) }

it 'should not validate without name' do
league = FactoryBot.build(:league, name: nil)
expect(league.valid?).to eq(false)
event = FactoryBot.build(:event, name: nil)
expect(event.valid?).to eq(false)
end

it 'should not validate without discipline' do
league = FactoryBot.build(:league, discipline: nil)
expect(league.valid?).to eq(false)
event = FactoryBot.build(:event, discipline: nil)
expect(event.valid?).to eq(false)
end

it 'should not validate without game_mode' do
league = FactoryBot.build(:league, game_mode: nil)
expect(league.valid?).to eq(false)
end

it 'should not validate without selection_type' do
league = FactoryBot.build(:league, selection_type: nil)
expect(league.valid?).to eq(false)
end

it 'should have an attribute deadline' do
date = Date.tomorrow
expect(event.deadline).to eq date

event.deadline = nil
expect(event).not_to be_valid
end

it 'should have an attribute startdate' do
date = Date.current + 2
expect(event.startdate).to eq date

expect(event).to be_valid
event.startdate = nil
expect(event).not_to be_valid
end

it 'should have an attribute enddate' do
date = Date.current + 3
expect(event.enddate).to eq date

expect(event).to be_valid
event.enddate = nil
expect(event).not_to be_valid
end

it 'should not be possible to have an enddate, that is before the startdate' do
expect(event).to be_valid
event.enddate = Date.current
expect(event).not_to be_valid
end

it 'should be possible to get the duration in day of an event' do
expect(event.duration).to eq(2)
event = FactoryBot.build(:event, game_mode: nil)
expect(event.valid?).to eq(false)
end

it 'should only show active events' do
Expand All @@ -105,8 +64,11 @@
expect(passed_deadline_event.deadline_has_passed?).to be true
end

it "generate_Schedule? should raise a NotImplementedError" do
it 'generate_Schedule? should raise a NotImplementedError' do
event = FactoryBot.build :event
# This is apparently not the correct way to implement an abstract method in ruby.
# (https://stackoverflow.com/a/2502835/8921181, http://ruby-doc.org/core-2.2.0/NotImplementedError.html)
# But it is the only way I know of right now to somewhat document that this has to be implemented by subclasses.
expect { event.generate_schedule }.to raise_error NotImplementedError
end
end
Loading

0 comments on commit 8feeb57

Please sign in to comment.