chgk_rating 2.0.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/Gemfile +3 -1
  4. data/LICENSE +1 -1
  5. data/README.md +4 -4
  6. data/Rakefile +4 -2
  7. data/chgk_rating.gemspec +19 -12
  8. data/lib/chgk_rating/attribute_mappings.rb +108 -97
  9. data/lib/chgk_rating/chgk_object.rb +5 -1
  10. data/lib/chgk_rating/client.rb +4 -2
  11. data/lib/chgk_rating/collections/base.rb +20 -15
  12. data/lib/chgk_rating/collections/players.rb +3 -1
  13. data/lib/chgk_rating/collections/ratings/player_ratings.rb +3 -1
  14. data/lib/chgk_rating/collections/ratings/team_ratings.rb +3 -1
  15. data/lib/chgk_rating/collections/recaps.rb +4 -2
  16. data/lib/chgk_rating/collections/teams.rb +3 -1
  17. data/lib/chgk_rating/collections/tournaments/player_tournaments.rb +12 -8
  18. data/lib/chgk_rating/collections/tournaments/tournament_team_players.rb +3 -1
  19. data/lib/chgk_rating/collections/tournaments/tournament_team_results.rb +3 -1
  20. data/lib/chgk_rating/collections/tournaments/tournament_teams.rb +4 -1
  21. data/lib/chgk_rating/collections/tournaments/tournaments.rb +12 -8
  22. data/lib/chgk_rating/concerns/searching.rb +10 -9
  23. data/lib/chgk_rating/connection.rb +10 -8
  24. data/lib/chgk_rating/error.rb +7 -5
  25. data/lib/chgk_rating/models/base.rb +23 -16
  26. data/lib/chgk_rating/models/player.rb +3 -1
  27. data/lib/chgk_rating/models/rating/player_rating.rb +3 -1
  28. data/lib/chgk_rating/models/rating/rating.rb +3 -1
  29. data/lib/chgk_rating/models/rating/team_rating.rb +3 -1
  30. data/lib/chgk_rating/models/recap.rb +3 -1
  31. data/lib/chgk_rating/models/team.rb +3 -1
  32. data/lib/chgk_rating/models/tournament/player_tournament.rb +3 -1
  33. data/lib/chgk_rating/models/tournament/tournament.rb +3 -1
  34. data/lib/chgk_rating/models/tournament/tournament_team.rb +3 -1
  35. data/lib/chgk_rating/models/tournament/tournament_team_player.rb +3 -1
  36. data/lib/chgk_rating/models/tournament/tournament_team_result.rb +3 -1
  37. data/lib/chgk_rating/request.rb +10 -9
  38. data/lib/chgk_rating/utils/snakecase.rb +9 -7
  39. data/lib/chgk_rating/utils/transformations.rb +43 -37
  40. data/lib/chgk_rating/version.rb +4 -2
  41. data/lib/chgk_rating.rb +3 -1
  42. data/lib/ext/date.rb +6 -8
  43. data/lib/ext/date_time.rb +4 -2
  44. data/lib/ext/uri.rb +6 -6
  45. metadata +61 -80
  46. data/spec/lib/chgk_rating/client_spec.rb +0 -247
  47. data/spec/lib/chgk_rating/collections/player_ratings_spec.rb +0 -15
  48. data/spec/lib/chgk_rating/collections/players_spec.rb +0 -45
  49. data/spec/lib/chgk_rating/collections/recaps_spec.rb +0 -21
  50. data/spec/lib/chgk_rating/collections/team_ratings_spec.rb +0 -25
  51. data/spec/lib/chgk_rating/collections/teams_spec.rb +0 -42
  52. data/spec/lib/chgk_rating/collections/tournaments/player_tournaments_spec.rb +0 -38
  53. data/spec/lib/chgk_rating/collections/tournaments/tournament_team_players_spec.rb +0 -18
  54. data/spec/lib/chgk_rating/collections/tournaments/tournament_team_results_spec.rb +0 -17
  55. data/spec/lib/chgk_rating/collections/tournaments/tournament_teams_spec.rb +0 -60
  56. data/spec/lib/chgk_rating/collections/tournaments/tournaments_spec.rb +0 -62
  57. data/spec/lib/chgk_rating/models/base_spec.rb +0 -34
  58. data/spec/lib/chgk_rating/models/player_rating_spec.rb +0 -22
  59. data/spec/lib/chgk_rating/models/player_spec.rb +0 -62
  60. data/spec/lib/chgk_rating/models/recap_spec.rb +0 -35
  61. data/spec/lib/chgk_rating/models/team_rating_spec.rb +0 -27
  62. data/spec/lib/chgk_rating/models/team_spec.rb +0 -89
  63. data/spec/lib/chgk_rating/models/tournament/tournament_spec.rb +0 -92
  64. data/spec/lib/chgk_rating/models/tournament/tournament_team_player_spec.rb +0 -21
  65. data/spec/lib/chgk_rating/models/tournament/tournament_team_result_spec.rb +0 -19
  66. data/spec/lib/chgk_rating/models/tournament/tournament_team_spec.rb +0 -36
  67. data/spec/lib/chgk_rating/utils/snakecase_spec.rb +0 -12
  68. data/spec/lib/chgk_rating/utils/transformations_spec.rb +0 -16
  69. data/spec/lib/chgk_rating_spec.rb +0 -5
  70. data/spec/lib/ext/date_spec.rb +0 -7
  71. data/spec/lib/ext/date_time_spec.rb +0 -11
  72. data/spec/lib/ext/uri_spec.rb +0 -7
  73. data/spec/spec_helper.rb +0 -15
  74. data/spec/support/shared_examples.rb +0 -63
  75. data/spec/support/test_client.rb +0 -6
  76. data/spec/support/vcr.rb +0 -11
@@ -1,17 +0,0 @@
1
- RSpec.describe ChgkRating::Collections::TournamentTeamResults do
2
- subject do
3
- VCR.use_cassette 'team_results_at_tournament' do
4
- described_class.new(tournament: 3506, team: 52853)
5
- end
6
- end
7
-
8
- it_behaves_like 'tournament team result' do
9
- let(:team_result) { subject[0] }
10
- end
11
- it_behaves_like 'not a hash'
12
- it_behaves_like 'an array'
13
-
14
- specify '#to_a' do
15
- expect(subject.to_a[2]['tour']).to eq '3'
16
- end
17
- end
@@ -1,60 +0,0 @@
1
- RSpec.describe ChgkRating::Collections::TournamentTeams do
2
- subject do
3
- VCR.use_cassette 'teams_at_tournament' do
4
- described_class.new(tournament: 3506)
5
- end
6
- end
7
- let(:team) { subject[0] }
8
- let(:tournament_team_h) { team.to_h }
9
-
10
- it_behaves_like 'not a hash'
11
- it_behaves_like 'an array'
12
-
13
- specify('#id') { expect(team.id).to eq '2124' }
14
- specify('#current_name') { expect(team.current_name).to eq 'Полосатый мамонт' }
15
- specify('#base_name') { expect(team.base_name).to eq 'Полосатый мамонт' }
16
- specify('#position') { expect(team.position).to eq 3 }
17
- specify('#questions_total') { expect(team.questions_total).to eq 34 }
18
- specify('#bonus_a') { expect(team.bonus_a).to eq 1575 }
19
- specify('#bonus_b') { expect(team.bonus_b).to eq -47 }
20
- specify('#tech_rating') { expect(team.tech_rating).to eq 2549 }
21
- specify('#predicted_position') { expect(team.predicted_position).to eq 2 }
22
- specify('#d_bonus_a') { expect(team.d_bonus_a).to eq 1575 }
23
- specify('#d_bonus_b') { expect(team.d_bonus_b).to eq 420 }
24
- specify('#d_diff_bonus') { expect(team.d_diff_bonus).to eq -47 }
25
- specify('#included_in_rating') { expect(team.included_in_rating).to eq true }
26
- specify('#result') { expect(team.result).to eq [true, true, true, false, true, true,
27
- true, true, true, true, true,
28
- true, true, false, false, false, false,
29
- true, true, true, true, true, false, true,
30
- true, true, false, false, true, false,
31
- true, true, false, true, true, false, true,
32
- false, true, false, true, true, true,
33
- false, true, true, true, true] }
34
-
35
- specify '#to_a' do
36
- expect(subject.to_a[2]['idteam']).to eq '28434'
37
- end
38
-
39
- # to_h for a fully loaded model
40
- specify '#to_h for a model' do
41
- expect(tournament_team_h['idteam']).to eq '2124'
42
- expect(tournament_team_h['position']).to eq '3.0'
43
- expect(tournament_team_h['questions_total']).to eq '34'
44
- expect(tournament_team_h['mask']).to eq ["1", "1", "1", "0", "1", "1", "1", "1", "1", "1", "1",
45
- "1", "1", "0", "0", "0", "0", "1", "1", "1", "1", "1",
46
- "0", "1", "1", "1", "0", "0", "1", "0", "1", "1", "0",
47
- "1", "1", "0", "1", "0", "1", "0", "1", "1", "1", "0",
48
- "1", "1", "1", "1"]
49
- expect(tournament_team_h['bonus_a']).to eq '1575'
50
- expect(tournament_team_h['bonus_b']).to eq '-47'
51
- expect(tournament_team_h['tech_rating']).to eq '2549'
52
- expect(tournament_team_h['d_bonus_a']).to eq '1575'
53
- expect(tournament_team_h['d_bonus_b']).to eq '420'
54
- expect(tournament_team_h['d_diff_bonus']).to eq '-47'
55
- expect(tournament_team_h['predicted_position']).to eq '2'
56
- expect(tournament_team_h['included_in_rating']).to eq '1'
57
- expect(tournament_team_h['current_name']).to eq 'Полосатый мамонт'
58
- expect(tournament_team_h['base_name']).to eq 'Полосатый мамонт'
59
- end
60
- end
@@ -1,62 +0,0 @@
1
- RSpec.describe ChgkRating::Collections::Tournaments do
2
- context 'all tournaments for a team by season' do
3
- subject do
4
- VCR.use_cassette 'team_tournaments_season' do
5
- described_class.new(team: 1, season_id: 4)
6
- end
7
- end
8
-
9
- it_behaves_like 'not a hash'
10
- it_behaves_like 'an array'
11
-
12
- specify '#to_a' do
13
- tournaments_arr = subject.to_a
14
- expect(tournaments_arr[2]['idtournament']).to eq '150'
15
- end
16
- specify('#id') { expect(subject[0].id).to eq '188' }
17
- specify('#team') { expect(subject.team.id).to eq 1 }
18
- specify('#season_id') { expect(subject.season_id).to eq 4 }
19
- end
20
-
21
- context 'all tournaments' do
22
- subject do
23
- VCR.use_cassette 'tournaments' do
24
- described_class.new
25
- end
26
- end
27
- let(:tournament) { subject[0] }
28
-
29
- it_behaves_like 'not a hash'
30
- it_behaves_like 'an array'
31
-
32
- specify '#to_a' do
33
- tournaments_arr = subject.to_a
34
- expect(tournaments_arr[10]['idtournament']).to eq '1538'
35
- end
36
- specify('#id') { expect(tournament.id).to eq '1908' }
37
- specify('#name') { expect(tournament.name).to eq 'Фестиваль в Мариуполе' }
38
- specify('#date_start') { expect(tournament.date_start).to eq DateTime.parse('1989-09-01 00:00:00') }
39
- specify('#date_end') { expect(tournament.date_end).to eq DateTime.parse('1989-09-03 00:00:00') }
40
- specify('#type_name') { expect(tournament.type_name).to eq 'Обычный' }
41
- end
42
-
43
- context 'tournaments for a team' do
44
- subject do
45
- VCR.use_cassette 'team_tournaments' do
46
- described_class.new(team: 1)
47
- end
48
- end
49
- let(:tournament) { subject['8'][0] }
50
-
51
- it_behaves_like 'a hash'
52
- it_behaves_like 'not an array'
53
-
54
- specify '#to_h' do
55
- subject_h = subject.to_h['7']
56
- expect(subject_h['tournaments'][0]['idtournament']).to eq '367'
57
- expect(subject_h['idseason']).to eq '7'
58
- expect(subject_h['idteam']).to eq '1'
59
- end
60
- specify('#id') { expect(tournament.id).to eq '424' }
61
- end
62
- end
@@ -1,34 +0,0 @@
1
- RSpec.describe ChgkRating::Models::Base do
2
- describe '.no_lazy_support!' do
3
- let!(:klass) do
4
- Class.new(described_class) do
5
- no_lazy_support!
6
- def initialize ; end
7
- end
8
- end
9
-
10
- subject { klass.new }
11
-
12
- it { is_expected.not_to respond_to(:lazy) }
13
-
14
- it 'should define NO_LAZY_SUPPORT constant' do
15
- expect(klass::NO_LAZY_SUPPORT).to eq(true)
16
- end
17
- end
18
-
19
- describe '.no_eager_loading!' do
20
- let!(:klass) do
21
- Class.new(described_class) do
22
- no_eager_loading!
23
- def initialize ; end
24
- end
25
- end
26
-
27
- subject { klass.new }
28
-
29
- it 'should raise an EagerLoadingNotSupported error' do
30
- expect( -> { subject.eager_load! }).to raise_error(ChgkRating::Error::EagerLoadingNotSupported).
31
- with_message 'Eager loading is not supported for this resource.'
32
- end
33
- end
34
- end
@@ -1,22 +0,0 @@
1
- RSpec.describe ChgkRating::Models::PlayerRating do
2
- subject do
3
- VCR.use_cassette 'rating_player_release' do
4
- described_class.new 1336, player: 1000
5
- end
6
- end
7
-
8
- let(:rating_h) { subject.to_h }
9
-
10
- specify('#player') { expect(subject.player.id).to eq '1000' }
11
- specify('#release_id') { expect(subject.release_id).to eq '1336' }
12
- specify('#rating') { expect(subject.rating).to eq 7674 }
13
- specify('#rating_position') { expect(subject.rating_position).to eq 1417 }
14
- specify('#date') { expect(subject.date).to eq Date.new(2018, 04, 12) }
15
- specify('#tournaments_in_year') { expect(subject.tournaments_in_year).to eq 15 }
16
- specify('#tournament_count_total') { expect(subject.tournament_count_total).to eq 284 }
17
- specify '#to_h' do
18
- expect(rating_h['idplayer']).to eq '1000'
19
- expect(rating_h['tournaments_in_year']).to eq '15'
20
- expect(rating_h['tournament_count_total']).to eq '284'
21
- end
22
- end
@@ -1,62 +0,0 @@
1
- RSpec.describe ChgkRating::Models::Player do
2
- subject do
3
- VCR.use_cassette 'player' do
4
- described_class.new 42511
5
- end
6
- end
7
- let(:player_h) { subject.to_h }
8
- let(:lazy_player) { described_class.new 42511, lazy: true }
9
-
10
- it_behaves_like 'model with eager loading'
11
- it_behaves_like 'model with lazy support'
12
-
13
- specify('#id') { expect(subject.id).to eq '42511' }
14
- specify('#surname') { expect(subject.surname).to eq 'Некрылов' }
15
- specify('#name') { expect(subject.name).to eq 'Николай' }
16
- specify('#patronymic') { expect(subject.patronymic).to eq 'Андреевич' }
17
- specify('#db_chgk_info_tag') { expect(subject.db_chgk_info_tag).to eq 'nnekrylov' }
18
- specify('#comment') { expect(subject.comment).to eq '' }
19
-
20
- specify '#to_h' do
21
- expect(player_h['idplayer']).to eq '42511'
22
- expect(player_h['name']).to eq 'Николай'
23
- expect(player_h['surname']).to eq 'Некрылов'
24
- expect(player_h['patronymic']).to eq 'Андреевич'
25
- expect(player_h['comment']).to eq ''
26
- expect(player_h['db_chgk_info_tag']).to eq 'nnekrylov'
27
- end
28
-
29
- specify '#eager_load!' do
30
- VCR.use_cassette 'player' do
31
- lazy_player.eager_load!
32
- end
33
- expect(lazy_player.name).to eq 'Николай'
34
- end
35
-
36
- describe '#rating' do
37
- let(:player_rating) do
38
- VCR.use_cassette 'player_rating_release' do
39
- subject.rating 1000
40
- end
41
- end
42
- it { expect(player_rating).to be_an_instance_of ChgkRating::Models::PlayerRating }
43
- end
44
-
45
- describe '#ratings' do
46
- let(:player_ratings) do
47
- VCR.use_cassette 'player_ratings_all_releases' do
48
- subject.ratings
49
- end
50
- end
51
- it { expect(player_ratings).to be_an_instance_of ChgkRating::Collections::PlayerRatings }
52
- end
53
-
54
- describe '#tournaments' do
55
- let(:player_tournaments) do
56
- VCR.use_cassette 'player_tournaments2' do
57
- subject.tournaments
58
- end
59
- end
60
- it { expect(player_tournaments).to be_an_instance_of ChgkRating::Collections::PlayerTournaments }
61
- end
62
- end
@@ -1,35 +0,0 @@
1
- RSpec.describe ChgkRating::Models::Recap do
2
- subject do
3
- VCR.use_cassette 'recap_last_season' do
4
- described_class.new :last, team: 7931
5
- end
6
- end
7
- let(:recap_h) { subject.to_h }
8
-
9
- it_behaves_like 'model without eager loading'
10
- it_behaves_like 'model without lazy support'
11
-
12
- specify('#season_id') { expect(subject.season_id).to eq '51' }
13
- specify('#team') { expect(subject.team.id).to eq '7931' }
14
- specify('#captain') { expect(subject.captain.id).to eq '23539' }
15
- specify('#players') { expect(subject.players.first.id).to eq '2668' }
16
- specify '#to_h' do
17
- expect(recap_h['idseason']).to eq '51'
18
- expect(recap_h['idteam']).to eq '7931'
19
- expect(recap_h['captain']).to eq '23539'
20
- expect(recap_h['players']).to eq %w(2668 6654 23539 53735 94783 98697 115867 149858)
21
- end
22
-
23
- context 'with season number' do
24
- subject do
25
- VCR.use_cassette 'recap' do
26
- described_class.new 9, team: 1
27
- end
28
- end
29
-
30
- specify('#season_id') { expect(subject.season_id).to eq '9' }
31
- specify('#team') { expect(subject.team.id).to eq '1' }
32
- specify('#captain') { expect(subject.captain.id).to eq '2935' }
33
- specify('#players') { expect(subject.players.first.id).to eq '2935' }
34
- end
35
- end
@@ -1,27 +0,0 @@
1
- RSpec.describe ChgkRating::Models::TeamRating do
2
- subject do
3
- VCR.use_cassette 'rating_release' do
4
- described_class.new 24, team: 1
5
- end
6
- end
7
- let(:rating_h) { subject.to_h }
8
-
9
- it_behaves_like 'model without eager loading'
10
- it_behaves_like 'model without lazy support'
11
-
12
- specify('#team') { expect(subject.team.id).to eq '1' }
13
- specify('#release_id') { expect(subject.release_id).to eq '24' }
14
- specify('#rating') { expect(subject.rating).to eq 9071 }
15
- specify('#rating_position') { expect(subject.rating_position).to eq 9 }
16
- specify('#date') { expect(subject.date).to eq Date.new(1999, 01, 07) }
17
- specify('#formula') { expect(subject.formula).to eq :b }
18
-
19
- specify '#to_h' do
20
- expect(rating_h['idteam']).to eq '1'
21
- expect(rating_h['idrelease']).to eq '24'
22
- expect(rating_h['rating']).to eq '9071'
23
- expect(rating_h['rating_position']).to eq '9'
24
- expect(rating_h['date']).to eq '1999-01-07'
25
- expect(rating_h['formula']).to eq 'b'
26
- end
27
- end
@@ -1,89 +0,0 @@
1
- RSpec.describe ChgkRating::Models::Team do
2
- subject do
3
- VCR.use_cassette 'team' do
4
- described_class.new 1
5
- end
6
- end
7
- let(:team_h) { subject.to_h }
8
- let(:lazy_team) { described_class.new 1, lazy: true }
9
-
10
- it_behaves_like 'model with eager loading'
11
- it_behaves_like 'model with lazy support'
12
-
13
- specify('#id') { expect(subject.id).to eq '1' }
14
- specify('#town') { expect(subject.town).to eq 'Москва' }
15
- specify('#name') { expect(subject.name).to eq 'Неспроста' }
16
- specify('#comment') { expect(subject.comment).to eq '' }
17
-
18
- specify '#tournaments' do
19
- tournaments = VCR.use_cassette 'team_tournaments' do
20
- subject.tournaments['2']
21
- end
22
-
23
- expect(tournaments[0].id).to eq '54'
24
- expect(tournaments[1].id).to eq '25'
25
- end
26
-
27
- specify '#to_h' do
28
- expect(team_h['idteam']).to eq '1'
29
- expect(team_h['name']).to eq 'Неспроста'
30
- expect(team_h['town']).to eq 'Москва'
31
- expect(team_h['comment']).to eq ''
32
- end
33
-
34
- specify '#eager_load!' do
35
- VCR.use_cassette 'team' do
36
- lazy_team.eager_load!
37
- end
38
- expect(lazy_team.name).to eq 'Неспроста'
39
- end
40
-
41
- describe '#at_tournament' do
42
- it { expect(subject.at_tournament('1000')).to be_an_instance_of ChgkRating::Models::TournamentTeam }
43
- end
44
-
45
- describe '#rating' do
46
- let(:team_rating) do
47
- VCR.use_cassette 'rating_release' do
48
- subject.rating 24
49
- end
50
- end
51
- it { expect(team_rating).to be_an_instance_of ChgkRating::Models::TeamRating }
52
- end
53
-
54
- describe '#recap' do
55
- let(:team_recap) do
56
- VCR.use_cassette 'recap' do
57
- subject.recap 9
58
- end
59
- end
60
- it { expect(team_recap).to be_an_instance_of ChgkRating::Models::Recap }
61
- end
62
-
63
- describe '#recaps' do
64
- let(:team_recaps) do
65
- VCR.use_cassette 'recaps' do
66
- subject.recaps
67
- end
68
- end
69
- it { expect(team_recaps).to be_an_instance_of ChgkRating::Collections::Recaps }
70
- end
71
-
72
- describe '#tournaments' do
73
- let(:team_tournaments) do
74
- VCR.use_cassette 'team_tournaments' do
75
- subject.tournaments
76
- end
77
- end
78
- it { expect(team_tournaments).to be_an_instance_of ChgkRating::Collections::Tournaments }
79
- end
80
-
81
- describe '#ratings' do
82
- let(:team_ratings) do
83
- VCR.use_cassette 'team_ratings' do
84
- subject.ratings
85
- end
86
- end
87
- it { expect(team_ratings).to be_an_instance_of ChgkRating::Collections::TeamRatings }
88
- end
89
- end
@@ -1,92 +0,0 @@
1
- RSpec.describe ChgkRating::Models::Tournament do
2
- subject do
3
- VCR.use_cassette 'tournament' do
4
- described_class.new 3506
5
- end
6
- end
7
- let(:lazy_tournament) { described_class.new 3506, lazy: true }
8
- let(:tournament_h) { subject.to_h }
9
-
10
- it_behaves_like 'model with eager loading'
11
- it_behaves_like 'model with lazy support'
12
-
13
- specify('#id') { expect(subject.id).to eq '3506' }
14
- specify('#name') { expect(subject.name).to eq 'Чемпионат Перми и Пермского края' }
15
- specify('#long_name') { expect(subject.long_name).to eq 'XV Чемпионат Перми и Пермского края по игре "Что? Где? Когда?"' }
16
- specify('#date_start') { expect(subject.date_start).to eq DateTime.parse('2015-11-08 14:00:00') }
17
- specify('#date_end') { expect(subject.date_end).to eq DateTime.parse('2015-11-08 18:00:00') }
18
- specify('#tour_count') { expect(subject.tour_count).to eq 4 }
19
- specify('#tour_questions') { expect(subject.tour_questions).to eq 12 }
20
- specify('#tour_ques_per_tour') { expect(subject.tour_ques_per_tour).to eq 0 }
21
- specify('#questions_total') { expect(subject.questions_total).to eq 48 }
22
- specify('#type_name') { expect(subject.type_name).to eq 'Обычный' }
23
- specify('#main_payment_value') { expect(subject.main_payment_value).to eq 660 }
24
- specify('#discounted_payment_value') { expect(subject.discounted_payment_value).to eq 360 }
25
- specify('#discounted_payment_reason') { expect(subject.discounted_payment_reason).to eq 'для детских команд; 480 - для студенческих' }
26
- specify('#date_requests_allowed_to') { expect(subject.date_requests_allowed_to).to be_nil }
27
- specify('#comment') { expect(subject.comment).to eq '' }
28
- specify('#town') { expect(subject.town).to eq 'Пермь' }
29
- specify('#site_url') { expect(subject.site_url).to eq URI.parse('https://vk.com/chgk.perm.championship') }
30
- specify '#to_h' do
31
- expect(tournament_h['idtournament']).to eq '3506'
32
- expect(tournament_h['date_start']).to eq '2015-11-08T14:00:00+00:00'
33
- expect(tournament_h['date_end']).to eq '2015-11-08T18:00:00+00:00'
34
- expect(tournament_h['tour_count']).to eq '4'
35
- expect(tournament_h['tour_questions']).to eq '12'
36
- expect(tournament_h['tour_ques_per_tour']).to eq '0'
37
- expect(tournament_h['questions_total']).to eq '48'
38
- expect(tournament_h['main_payment_value']).to eq '660.0'
39
- expect(tournament_h['discounted_payment_value']).to eq '360.0'
40
- expect(tournament_h['date_requests_allowed_to']).to eq ''
41
- expect(tournament_h['site_url']).to eq 'https://vk.com/chgk.perm.championship'
42
- expect(tournament_h['name']).to eq 'Чемпионат Перми и Пермского края'
43
- expect(tournament_h['town']).to eq 'Пермь'
44
- expect(tournament_h['long_name']).to eq 'XV Чемпионат Перми и Пермского края по игре "Что? Где? Когда?"'
45
- expect(tournament_h['type_name']).to eq 'Обычный'
46
- expect(tournament_h['discounted_payment_reason']).to eq 'для детских команд; 480 - для студенческих'
47
- expect(tournament_h['comment']).to eq ''
48
- end
49
-
50
- specify '#eager_load!' do
51
- VCR.use_cassette 'tournament' do
52
- lazy_tournament.eager_load!
53
- end
54
- expect(lazy_tournament.name).to eq 'Чемпионат Перми и Пермского края'
55
- end
56
-
57
- describe '#team_results' do
58
- let(:team_results) do
59
- VCR.use_cassette 'team_results_at_tournament' do
60
- subject.team_results(52853)
61
- end
62
- end
63
-
64
- it { expect(team_results).to be_an_instance_of ChgkRating::Collections::TournamentTeamResults }
65
- end
66
-
67
- describe '#team_players' do
68
- let(:players) do
69
- VCR.use_cassette 'team_players_at_tournament' do
70
- subject.team_players(52853)
71
- end
72
- end
73
-
74
- it { expect(players).to be_an_instance_of ChgkRating::Collections::TournamentTeamPlayers }
75
- end
76
-
77
- describe '#team_by' do
78
- let(:team) { subject.team_by 52853 }
79
-
80
- it { expect(team).to be_an_instance_of ChgkRating::Models::TournamentTeam }
81
- end
82
-
83
- describe '#team_list' do
84
- let(:team_list) do
85
- VCR.use_cassette 'teams_at_tournament' do
86
- subject.team_list
87
- end
88
- end
89
-
90
- it { expect(team_list).to be_an_instance_of ChgkRating::Collections::TournamentTeams }
91
- end
92
- end
@@ -1,21 +0,0 @@
1
- RSpec.describe ChgkRating::Models::TournamentTeamPlayer do
2
- subject do
3
- VCR.use_cassette 'team_players_at_tournament' do
4
- test_client.team_players_at_tournament(3506, 52853)[0]
5
- end
6
- end
7
- let(:tournament_player_h) { subject.to_h }
8
-
9
- it_behaves_like 'model without eager loading'
10
- it_behaves_like 'model without lazy support'
11
- it_behaves_like 'tournament team player' do
12
- let(:player) { subject }
13
- end
14
-
15
- specify '#to_h' do
16
- expect(tournament_player_h['idplayer']).to eq '51249'
17
- expect(tournament_player_h['is_captain']).to eq '1'
18
- expect(tournament_player_h['is_base']).to eq '1'
19
- expect(tournament_player_h['is_foreign']).to eq '0'
20
- end
21
- end
@@ -1,19 +0,0 @@
1
- RSpec.describe ChgkRating::Models::TournamentTeamResult do
2
- subject do
3
- VCR.use_cassette 'team_results_at_tournament' do
4
- test_client.team_results_at_tournament(3506, 52853)[0]
5
- end
6
- end
7
- let(:tournament_team_result_h) { subject.to_h }
8
-
9
- it_behaves_like 'model without eager loading'
10
- it_behaves_like 'model without lazy support'
11
- it_behaves_like 'tournament team result' do
12
- let(:team_result) { subject }
13
- end
14
-
15
- specify '#to_h' do
16
- expect(tournament_team_result_h['tour']).to eq '1'
17
- expect(tournament_team_result_h['mask']).to eq %w(0 0 0 0 1 1 1 0 0 1 0 0)
18
- end
19
- end
@@ -1,36 +0,0 @@
1
- RSpec.describe ChgkRating::Models::TournamentTeam do
2
- # this is always a lazily-loaded object as
3
- # we cannot get info about a specific team participating in a tournament!
4
- subject { described_class.new '52853', tournament: '3506', lazy: true }
5
- let(:tournament_team_h) { subject.to_h }
6
-
7
- it_behaves_like 'model without eager loading'
8
- it_behaves_like 'model with lazy support'
9
-
10
- specify('#tournament') { expect(subject.tournament.id).to eq '3506' }
11
- specify('#team') { expect(subject.team.id).to eq '52853' }
12
- specify('#id') { expect(subject.id).to eq '52853' }
13
- specify '#to_h' do
14
- expect(tournament_team_h['idteam']).to eq '52853'
15
- end
16
-
17
- describe '#players' do
18
- let(:players) do
19
- VCR.use_cassette 'team_players_at_tournament' do
20
- subject.players
21
- end
22
- end
23
-
24
- it { expect(players).to be_an_instance_of ChgkRating::Collections::TournamentTeamPlayers }
25
- end
26
-
27
- describe '#results' do
28
- let(:results) do
29
- VCR.use_cassette 'team_results_at_tournament' do
30
- subject.results
31
- end
32
- end
33
-
34
- it { expect(results).to be_an_instance_of ChgkRating::Collections::TournamentTeamResults }
35
- end
36
- end
@@ -1,12 +0,0 @@
1
- RSpec.describe String do
2
- describe '#snakecase_upcase' do
3
- let(:result) { 'SNAKE_CASE' }
4
-
5
- it 'should convert the string properly' do
6
- expect('SnakeCase'.snakecase_upcase).to eq result
7
- expect('Snake-Case'.snakecase_upcase).to eq result
8
- expect('Snake Case'.snakecase_upcase).to eq result
9
- expect('Snake - Case'.snakecase_upcase).to eq result
10
- end
11
- end
12
- end
@@ -1,16 +0,0 @@
1
- RSpec.describe ChgkRating::Utils::Transformations do
2
- specify '.to_boolean' do
3
- expect(described_class.send(:to_boolean).call('1')).to eq(true)
4
- expect(described_class.send(:to_boolean).call('0')).to eq(false)
5
- end
6
-
7
- specify '.to_binary_boolean' do
8
- expect(described_class.send(:to_binary_boolean).call(true)).to eq('1')
9
- expect(described_class.send(:to_binary_boolean).call(false)).to eq('0')
10
- end
11
-
12
- specify '.to_star' do
13
- expect(described_class.send(:to_star, :to_i).call('1')).to eq(1)
14
- expect(described_class.send(:to_star, :to_sym, true).call(%w(one two apple))).to eq(%i(one two apple))
15
- end
16
- end
@@ -1,5 +0,0 @@
1
- RSpec.describe ChgkRating do
2
- specify '.client' do
3
- expect(ChgkRating.client).to be_an_instance_of(ChgkRating::Client)
4
- end
5
- end
@@ -1,7 +0,0 @@
1
- RSpec.describe Date do
2
- specify '.parse_safely' do
3
- expect(described_class.parse_safely('2017-09-28 12:00:33').to_s).to eq('2017-09-28')
4
- expect(described_class.parse_safely('gibberish')).to be_nil
5
- expect(described_class.parse_safely(nil)).to be_nil
6
- end
7
- end
@@ -1,11 +0,0 @@
1
- RSpec.describe DateTime do
2
- subject { DateTime.new(2018,01,24,16,58,34) }
3
-
4
- specify '#to_s_chgk' do
5
- expect(subject.to_s_chgk).to eq '2018-01-24 16:58:34'
6
- end
7
-
8
- specify '.parse_safely' do
9
- expect(described_class.parse_safely('2017-09-28 12:00:33').to_s).to eq('2017-09-28T12:00:33+00:00')
10
- end
11
- end
@@ -1,7 +0,0 @@
1
- RSpec.describe URI do
2
- specify '.parse_safely' do
3
- expect(described_class.parse_safely('http://example.com/test').to_s).to eq('http://example.com/test')
4
- expect(described_class.parse_safely('gibberish').to_s).to eq 'gibberish'
5
- expect(described_class.parse_safely(nil)).to be_nil
6
- end
7
- end