barker 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.simplecov +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +50 -0
- data/LICENSE +22 -0
- data/README.md +204 -0
- data/Rakefile +12 -0
- data/barker.gemspec +29 -0
- data/ci/run +20 -0
- data/lib/barker/answer.rb +11 -0
- data/lib/barker/api/base.rb +145 -0
- data/lib/barker/api/response/base.rb +25 -0
- data/lib/barker/api/response/candidate.rb +38 -0
- data/lib/barker/api/response/candidate_answer.rb +23 -0
- data/lib/barker/api/response/candidate_joker.rb +21 -0
- data/lib/barker/api/response/candidate_question.rb +51 -0
- data/lib/barker/api/response/error.rb +17 -0
- data/lib/barker/api/response/game_show.rb +43 -0
- data/lib/barker/api/response/round.rb +21 -0
- data/lib/barker/api/response.rb +15 -0
- data/lib/barker/api.rb +7 -0
- data/lib/barker/candidate.rb +52 -0
- data/lib/barker/candidate_answer.rb +42 -0
- data/lib/barker/candidate_joker.rb +30 -0
- data/lib/barker/candidate_question.rb +116 -0
- data/lib/barker/candidate_round.rb +32 -0
- data/lib/barker/entity.rb +15 -0
- data/lib/barker/game_show.rb +176 -0
- data/lib/barker/guideline/base.rb +33 -0
- data/lib/barker/guideline/llmcquiz/questions.yaml +300 -0
- data/lib/barker/guideline/llmcquiz.rb +28 -0
- data/lib/barker/guideline/mock.rb +17 -0
- data/lib/barker/guideline.rb +8 -0
- data/lib/barker/import/yaml.rb +22 -0
- data/lib/barker/import.rb +6 -0
- data/lib/barker/joker.rb +28 -0
- data/lib/barker/question.rb +12 -0
- data/lib/barker/quiz.rb +19 -0
- data/lib/barker/repo/memory/game_show.rb +38 -0
- data/lib/barker/repo/memory.rb +8 -0
- data/lib/barker/repo.rb +6 -0
- data/lib/barker/round.rb +68 -0
- data/lib/barker/stage.rb +38 -0
- data/lib/barker/store/memory.rb +158 -0
- data/lib/barker/store.rb +6 -0
- data/lib/barker/validations.rb +14 -0
- data/lib/barker/version.rb +3 -0
- data/lib/barker.rb +45 -0
- data/test/factories/answer.rb +21 -0
- data/test/factories/candidate.rb +23 -0
- data/test/factories/candidate_answer.rb +12 -0
- data/test/factories/candidate_joker.rb +8 -0
- data/test/factories/candidate_question.rb +16 -0
- data/test/factories/candidate_round.rb +8 -0
- data/test/factories/game_show.rb +12 -0
- data/test/factories/joker.rb +5 -0
- data/test/factories/question.rb +13 -0
- data/test/factories/quiz.rb +11 -0
- data/test/factories/round.rb +12 -0
- data/test/factories/stage.rb +12 -0
- data/test/fixtures/questions.yaml +20 -0
- data/test/test_helper.rb +72 -0
- data/test/test_mocks.rb +21 -0
- data/test/unit/answer_test.rb +49 -0
- data/test/unit/api/base_test.rb +207 -0
- data/test/unit/api/response/base_test.rb +35 -0
- data/test/unit/api/response/candidate_answer_test.rb +64 -0
- data/test/unit/api/response/candidate_joker_test.rb +60 -0
- data/test/unit/api/response/candidate_question_test.rb +99 -0
- data/test/unit/api/response/candidate_test.rb +82 -0
- data/test/unit/api/response/game_show_test.rb +105 -0
- data/test/unit/api/response/round_test.rb +49 -0
- data/test/unit/candidate_answer_test.rb +66 -0
- data/test/unit/candidate_question_test.rb +277 -0
- data/test/unit/candidate_round_test.rb +64 -0
- data/test/unit/candidate_test.rb +76 -0
- data/test/unit/game_show_test.rb +372 -0
- data/test/unit/guideline/base_test.rb +34 -0
- data/test/unit/guideline/llmcquiz_test.rb +35 -0
- data/test/unit/guideline/mock_test.rb +33 -0
- data/test/unit/import/yaml_test.rb +41 -0
- data/test/unit/joker_test.rb +32 -0
- data/test/unit/question_test.rb +55 -0
- data/test/unit/quiz_test.rb +37 -0
- data/test/unit/repo/memory/game_show_test.rb +54 -0
- data/test/unit/round_test.rb +167 -0
- data/test/unit/stage_test.rb +53 -0
- metadata +283 -0
@@ -0,0 +1,207 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Barker
|
4
|
+
module Api
|
5
|
+
class BaseTest < Spec
|
6
|
+
|
7
|
+
test "api" do
|
8
|
+
assert_kind_of Barker::Api::Base, api
|
9
|
+
end
|
10
|
+
|
11
|
+
test "create" do
|
12
|
+
response = api.create(:guideline => :mock)
|
13
|
+
assert_kind_of Barker::Api::Response::GameShow, response
|
14
|
+
assert response.ok?
|
15
|
+
end
|
16
|
+
|
17
|
+
test "get" do
|
18
|
+
game_show_id = api.create(:guideline => :mock).game_show_id
|
19
|
+
|
20
|
+
response = api.get(game_show_id)
|
21
|
+
assert_kind_of Barker::Api::Response::GameShow, response
|
22
|
+
assert response.ok?
|
23
|
+
end
|
24
|
+
|
25
|
+
test "remove" do
|
26
|
+
game_show_id = api.create(:guideline => :mock).game_show_id
|
27
|
+
|
28
|
+
response = api.get(game_show_id)
|
29
|
+
|
30
|
+
api.remove(game_show_id)
|
31
|
+
|
32
|
+
response = api.get(game_show_id)
|
33
|
+
assert_kind_of Barker::Api::Response::Error, response
|
34
|
+
assert_equal Barker::Errors::RecordNotFound, response.error
|
35
|
+
end
|
36
|
+
|
37
|
+
test "get unknown game show" do
|
38
|
+
response = api.get(nil)
|
39
|
+
assert_kind_of Barker::Api::Response::Error, response
|
40
|
+
refute response.ok?
|
41
|
+
assert_equal Barker::Errors::RecordNotFound, response.error
|
42
|
+
end
|
43
|
+
|
44
|
+
test "candidate join and leave" do
|
45
|
+
game_show_id = api.create(:guideline => :mock).game_show_id
|
46
|
+
candidate_id = 42
|
47
|
+
candidate_locale = 'de'
|
48
|
+
|
49
|
+
# join
|
50
|
+
response = api.join(game_show_id, candidate_id, candidate_locale)
|
51
|
+
assert_kind_of Barker::Api::Response::Candidate, response
|
52
|
+
assert response.ok?
|
53
|
+
|
54
|
+
# leave
|
55
|
+
response = api.leave(game_show_id, candidate_id)
|
56
|
+
assert_kind_of Barker::Api::Response::Candidate, response
|
57
|
+
assert response.ok?
|
58
|
+
end
|
59
|
+
|
60
|
+
test "start" do
|
61
|
+
game_show_id = api.create(:guideline => :mock).game_show_id
|
62
|
+
|
63
|
+
response = api.start(game_show_id)
|
64
|
+
assert_kind_of Barker::Api::Response::GameShow, response
|
65
|
+
assert response.ok?
|
66
|
+
end
|
67
|
+
|
68
|
+
test "finish" do
|
69
|
+
game_show_id = api.create(:guideline => :mock).game_show_id
|
70
|
+
|
71
|
+
response = api.finish(game_show_id)
|
72
|
+
assert_kind_of Barker::Api::Response::GameShow, response
|
73
|
+
assert response.ok?
|
74
|
+
end
|
75
|
+
|
76
|
+
test "abort" do
|
77
|
+
game_show_id = api.create(:guideline => :mock).game_show_id
|
78
|
+
|
79
|
+
response = api.abort(game_show_id)
|
80
|
+
assert_kind_of Barker::Api::Response::GameShow, response
|
81
|
+
assert response.ok?
|
82
|
+
end
|
83
|
+
|
84
|
+
test "next round / next stage" do
|
85
|
+
game_show_id = api.create(:guideline => :mock).game_show_id
|
86
|
+
candidate_id = 42
|
87
|
+
candidate_locale = 'de'
|
88
|
+
|
89
|
+
api.join(game_show_id, candidate_id, candidate_locale)
|
90
|
+
api.start(game_show_id)
|
91
|
+
|
92
|
+
response = api.next_stage(game_show_id)
|
93
|
+
assert_kind_of Barker::Api::Response::GameShow, response
|
94
|
+
assert response.ok?
|
95
|
+
|
96
|
+
response = api.next_round(game_show_id)
|
97
|
+
assert_kind_of Barker::Api::Response::GameShow, response
|
98
|
+
assert response.ok?
|
99
|
+
end
|
100
|
+
|
101
|
+
test "ask" do
|
102
|
+
game_show_id = api.create(:guideline => :mock).game_show_id
|
103
|
+
candidate_id = 42
|
104
|
+
candidate_locale = 'de'
|
105
|
+
|
106
|
+
api.join(game_show_id, candidate_id, candidate_locale)
|
107
|
+
api.start(game_show_id)
|
108
|
+
api.next_stage(game_show_id)
|
109
|
+
api.next_round(game_show_id)
|
110
|
+
|
111
|
+
response = api.ask(game_show_id, candidate_id)
|
112
|
+
assert_kind_of Barker::Api::Response::CandidateQuestion, response
|
113
|
+
assert response.ok?
|
114
|
+
|
115
|
+
assert_kind_of Barker::Api::Response::CandidateAnswer, response.answers[0]
|
116
|
+
assert response.answers[0].ok?
|
117
|
+
|
118
|
+
assert_kind_of Barker::Api::Response::CandidateAnswer, response.given_answer
|
119
|
+
assert response.ok?
|
120
|
+
end
|
121
|
+
|
122
|
+
test "ask reset timer" do
|
123
|
+
game_show_id = api.create(:guideline => :llmcquiz).game_show_id
|
124
|
+
candidate_id = 42
|
125
|
+
candidate_locale = 'de'
|
126
|
+
|
127
|
+
api.join(game_show_id, candidate_id, candidate_locale)
|
128
|
+
api.start(game_show_id)
|
129
|
+
api.next_stage(game_show_id)
|
130
|
+
api.next_round(game_show_id)
|
131
|
+
|
132
|
+
response = api.ask(game_show_id, candidate_id)
|
133
|
+
assert_in_delta 35, response.time_left, 1
|
134
|
+
|
135
|
+
asked_at = Time.now + 5
|
136
|
+
|
137
|
+
Time.stubs(:now).returns(asked_at)
|
138
|
+
|
139
|
+
response = api.ask(game_show_id, candidate_id)
|
140
|
+
assert_in_delta 30, response.time_left, 1
|
141
|
+
|
142
|
+
Time.stubs(:now).returns(asked_at + 5)
|
143
|
+
|
144
|
+
response = api.ask(game_show_id, candidate_id, :reset_timer => true)
|
145
|
+
assert_in_delta 35, response.time_left, 1
|
146
|
+
end
|
147
|
+
|
148
|
+
test "answer" do
|
149
|
+
game_show_id = api.create(:guideline => :mock).game_show_id
|
150
|
+
candidate_id = 42
|
151
|
+
candidate_locale = 'de'
|
152
|
+
|
153
|
+
api.join(game_show_id, candidate_id, candidate_locale)
|
154
|
+
api.start(game_show_id)
|
155
|
+
|
156
|
+
api.next_stage(game_show_id)
|
157
|
+
api.next_round(game_show_id)
|
158
|
+
response = api.ask(game_show_id, candidate_id)
|
159
|
+
answer_id = response.answers[0].answer_id
|
160
|
+
|
161
|
+
response = api.answer(game_show_id, candidate_id, answer_id)
|
162
|
+
assert_kind_of Barker::Api::Response::CandidateAnswer, response
|
163
|
+
assert response.ok?
|
164
|
+
end
|
165
|
+
|
166
|
+
test "joker" do
|
167
|
+
game_show_id = api.create(:guideline => :mock).game_show_id
|
168
|
+
candidate_id = 42
|
169
|
+
candidate_locale = 'de'
|
170
|
+
|
171
|
+
api.join(game_show_id, candidate_id, candidate_locale)
|
172
|
+
api.start(game_show_id)
|
173
|
+
|
174
|
+
api.next_stage(game_show_id)
|
175
|
+
api.next_round(game_show_id)
|
176
|
+
response = api.ask(game_show_id, candidate_id)
|
177
|
+
|
178
|
+
response = api.joker(game_show_id, candidate_id, 'fifty_fifty')
|
179
|
+
assert_kind_of Barker::Api::Response::CandidateJoker, response
|
180
|
+
assert response.ok?
|
181
|
+
end
|
182
|
+
|
183
|
+
test "catch_error wrapper method" do
|
184
|
+
game_show_id = api.create(:guideline => :mock).game_show_id
|
185
|
+
candidate_id = 42
|
186
|
+
candidate_locale = 'de'
|
187
|
+
|
188
|
+
api.join(game_show_id, candidate_id, candidate_locale)
|
189
|
+
api.start(game_show_id)
|
190
|
+
|
191
|
+
api.next_stage(game_show_id)
|
192
|
+
api.next_round(game_show_id)
|
193
|
+
response = api.ask(game_show_id, candidate_id)
|
194
|
+
|
195
|
+
response = api.joker(game_show_id, candidate_id, 'unkown')
|
196
|
+
assert_kind_of Barker::Api::Response::Error, response
|
197
|
+
assert_equal false, response.ok?
|
198
|
+
assert_equal Barker::Errors::UnknownJokerError, response.error
|
199
|
+
end
|
200
|
+
|
201
|
+
private
|
202
|
+
|
203
|
+
let(:api) { Barker::Api::Base.new }
|
204
|
+
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Barker
|
4
|
+
module Api
|
5
|
+
module Response
|
6
|
+
class BaseTest < Spec
|
7
|
+
|
8
|
+
test "instance" do
|
9
|
+
assert_kind_of Barker::Api::Response::Base, klass.new
|
10
|
+
end
|
11
|
+
|
12
|
+
test "without error" do
|
13
|
+
is_ok = klass.new
|
14
|
+
assert is_ok.ok?
|
15
|
+
refute is_ok.error?
|
16
|
+
assert_nil is_ok.error
|
17
|
+
end
|
18
|
+
|
19
|
+
test "with error" do
|
20
|
+
is_not_ok = klass.new(:error => 'msg')
|
21
|
+
refute is_not_ok.ok?
|
22
|
+
assert is_not_ok.error?
|
23
|
+
assert_equal 'msg', is_not_ok.error
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def klass
|
29
|
+
Barker::Api::Response::Base
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Barker
|
4
|
+
module Api
|
5
|
+
module Response
|
6
|
+
class CandidateAnswerTest < Spec
|
7
|
+
|
8
|
+
test "instance" do
|
9
|
+
assert_kind_of Barker::Api::Response::CandidateAnswer, klass.new
|
10
|
+
end
|
11
|
+
|
12
|
+
test "inherit from base" do
|
13
|
+
assert klass < Barker::Api::Response::Base
|
14
|
+
end
|
15
|
+
|
16
|
+
test "candidate_answer" do
|
17
|
+
assert_equal candidate_answer, subject.candidate_answer
|
18
|
+
end
|
19
|
+
|
20
|
+
test "delegate" do
|
21
|
+
assert_delegate :id
|
22
|
+
assert_delegate :answer_id
|
23
|
+
assert_delegate :candidate_id
|
24
|
+
assert_delegate :label
|
25
|
+
assert_delegate :revealed?
|
26
|
+
assert_delegate :correct?
|
27
|
+
end
|
28
|
+
|
29
|
+
test "to_hash" do
|
30
|
+
result = subject.to_hash
|
31
|
+
assert_kind_of Hash, result
|
32
|
+
|
33
|
+
assert result.has_key? 'id'
|
34
|
+
assert result.has_key? 'answer_id'
|
35
|
+
assert result.has_key? 'candidate_id'
|
36
|
+
assert result.has_key? 'label'
|
37
|
+
assert result.has_key? 'revealed?'
|
38
|
+
assert result.has_key? 'correct?'
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def assert_delegate(method)
|
44
|
+
assert candidate_answer.respond_to?(method), "CandidateAnswer should respond to #{method}"
|
45
|
+
assert subject.respond_to?(method), "Response::CandidateAnswer should respond to #{method}"
|
46
|
+
assert_equal candidate_answer.send(method), subject.send(method), "CandidateAnswer##{method} != Response::CandidateAnswer##{method}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def klass
|
50
|
+
Barker::Api::Response::CandidateAnswer
|
51
|
+
end
|
52
|
+
|
53
|
+
def subject
|
54
|
+
klass.new(:candidate_answer => candidate_answer)
|
55
|
+
end
|
56
|
+
|
57
|
+
def candidate_answer
|
58
|
+
@candidate_answer ||= FactoryGirl.build :candidate_answer
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Barker
|
4
|
+
module Api
|
5
|
+
module Response
|
6
|
+
class CandidateJokerTest < Spec
|
7
|
+
|
8
|
+
test "instance" do
|
9
|
+
assert_kind_of Barker::Api::Response::CandidateJoker, klass.new
|
10
|
+
end
|
11
|
+
|
12
|
+
test "inherit from base" do
|
13
|
+
assert klass < Barker::Api::Response::Base
|
14
|
+
end
|
15
|
+
|
16
|
+
test "candidate_joker" do
|
17
|
+
assert_equal candidate_joker, subject.candidate_joker
|
18
|
+
end
|
19
|
+
|
20
|
+
test "delegate" do
|
21
|
+
assert_delegate :id
|
22
|
+
assert_delegate :joker_id
|
23
|
+
assert_delegate :candidate_id
|
24
|
+
assert_delegate :used_at
|
25
|
+
end
|
26
|
+
|
27
|
+
test "to_hash" do
|
28
|
+
result = subject.to_hash
|
29
|
+
assert_kind_of Hash, result
|
30
|
+
|
31
|
+
assert result.has_key? 'id'
|
32
|
+
assert result.has_key? 'joker_id'
|
33
|
+
assert result.has_key? 'candidate_id'
|
34
|
+
assert result.has_key? 'used_at'
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def assert_delegate(method)
|
40
|
+
assert candidate_joker.respond_to?(method), "CandidateJoker should respond to #{method}"
|
41
|
+
assert subject.respond_to?(method), "Response::CandidateJoker should respond to #{method}"
|
42
|
+
assert_equal candidate_joker.send(method), subject.send(method), "CandidateJoker##{method} != Response::CandidateJoker##{method}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def klass
|
46
|
+
Barker::Api::Response::CandidateJoker
|
47
|
+
end
|
48
|
+
|
49
|
+
def subject
|
50
|
+
klass.new(:candidate_joker => candidate_joker)
|
51
|
+
end
|
52
|
+
|
53
|
+
def candidate_joker
|
54
|
+
@candidate_joker ||= FactoryGirl.build :candidate_joker
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Barker
|
4
|
+
module Api
|
5
|
+
module Response
|
6
|
+
class CandidateQuestionTest < Spec
|
7
|
+
|
8
|
+
test "instance" do
|
9
|
+
assert_kind_of Barker::Api::Response::CandidateQuestion, klass.new
|
10
|
+
end
|
11
|
+
|
12
|
+
test "inherit from base" do
|
13
|
+
assert klass < Barker::Api::Response::Base
|
14
|
+
end
|
15
|
+
|
16
|
+
test "candidate_question" do
|
17
|
+
assert_equal candidate_question, subject.candidate_question
|
18
|
+
end
|
19
|
+
|
20
|
+
test "delegate" do
|
21
|
+
assert_delegate :id
|
22
|
+
assert_delegate :question_id
|
23
|
+
assert_delegate :candidate_id
|
24
|
+
assert_delegate :label
|
25
|
+
assert_delegate :state
|
26
|
+
assert_delegate :asked_at
|
27
|
+
assert_delegate :answered_at
|
28
|
+
assert_delegate :asked?
|
29
|
+
assert_delegate :answered?
|
30
|
+
assert_delegate :open?
|
31
|
+
assert_delegate :time_left
|
32
|
+
assert_delegate :timeout?
|
33
|
+
end
|
34
|
+
|
35
|
+
test "answers" do
|
36
|
+
assert_kind_of Array, subject.answers
|
37
|
+
assert_kind_of Response::CandidateAnswer, subject.answers[0]
|
38
|
+
end
|
39
|
+
|
40
|
+
test "given_answer" do
|
41
|
+
assert_kind_of Response::CandidateAnswer, subject.given_answer
|
42
|
+
end
|
43
|
+
|
44
|
+
test "to_hash" do
|
45
|
+
result = subject.to_hash
|
46
|
+
assert_kind_of Hash, result
|
47
|
+
|
48
|
+
assert result.has_key? 'id'
|
49
|
+
assert result.has_key? 'question_id'
|
50
|
+
assert result.has_key? 'candidate_id'
|
51
|
+
assert result.has_key? 'label'
|
52
|
+
assert result.has_key? 'state'
|
53
|
+
assert result.has_key? 'asked_at'
|
54
|
+
assert result.has_key? 'answered_at'
|
55
|
+
assert result.has_key? 'asked?'
|
56
|
+
assert result.has_key? 'answered?'
|
57
|
+
assert result.has_key? 'open?'
|
58
|
+
assert result.has_key? 'time_left'
|
59
|
+
assert result.has_key? 'timeout?'
|
60
|
+
assert result.has_key? 'correct?'
|
61
|
+
assert result.has_key? 'wrong?'
|
62
|
+
assert result.has_key? 'answers'
|
63
|
+
assert result.has_key? 'given_answer'
|
64
|
+
|
65
|
+
assert_kind_of Array, result['answers']
|
66
|
+
assert_kind_of Hash, result['answers'][0]
|
67
|
+
|
68
|
+
assert_nil result['given_answer']
|
69
|
+
|
70
|
+
subject.candidate_question.answer subject.answers[0].answer_id
|
71
|
+
|
72
|
+
result = subject.to_hash
|
73
|
+
assert_kind_of Hash, result['given_answer']
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def assert_delegate(method)
|
79
|
+
assert candidate_question.respond_to?(method), "CandidateQuestion should respond to #{method}"
|
80
|
+
assert subject.respond_to?(method), "Response::CandidateQuestion should respond to #{method}"
|
81
|
+
assert_equal candidate_question.send(method), subject.send(method), "CandidateQuestion##{method} != Response::CandidateQuestion##{method}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def klass
|
85
|
+
Barker::Api::Response::CandidateQuestion
|
86
|
+
end
|
87
|
+
|
88
|
+
def subject
|
89
|
+
klass.new(:candidate_question => candidate_question)
|
90
|
+
end
|
91
|
+
|
92
|
+
def candidate_question
|
93
|
+
@candidate_question ||= FactoryGirl.build :candidate_question
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Barker
|
4
|
+
module Api
|
5
|
+
module Response
|
6
|
+
class CandidateTest < Spec
|
7
|
+
|
8
|
+
test "instance" do
|
9
|
+
assert_kind_of Barker::Api::Response::Candidate, klass.new
|
10
|
+
end
|
11
|
+
|
12
|
+
test "inherit from base" do
|
13
|
+
assert klass < Barker::Api::Response::Base
|
14
|
+
end
|
15
|
+
|
16
|
+
test "candidate" do
|
17
|
+
assert_equal candidate, subject.candidate
|
18
|
+
end
|
19
|
+
|
20
|
+
test "jokers" do
|
21
|
+
assert_kind_of Array, subject.jokers
|
22
|
+
assert_nil subject.jokers[0]
|
23
|
+
|
24
|
+
subject.candidate.jokers << FactoryGirl.build(:candidate_joker, :candidate => subject.candidate)
|
25
|
+
|
26
|
+
assert_kind_of Response::CandidateJoker, subject.jokers[0]
|
27
|
+
end
|
28
|
+
|
29
|
+
test "delegate" do
|
30
|
+
assert_delegate :id
|
31
|
+
assert_delegate :candidate_id
|
32
|
+
assert_delegate :locale
|
33
|
+
assert_delegate :jokers
|
34
|
+
assert_delegate :joined_at
|
35
|
+
assert_delegate :leaved_at
|
36
|
+
assert_delegate :aborted_at
|
37
|
+
assert_delegate :joined?
|
38
|
+
assert_delegate :leaved?
|
39
|
+
assert_delegate :aborted?
|
40
|
+
end
|
41
|
+
|
42
|
+
test "to_hash" do
|
43
|
+
result = subject.to_hash
|
44
|
+
assert_kind_of Hash, result
|
45
|
+
|
46
|
+
assert result.has_key? 'id'
|
47
|
+
assert result.has_key? 'candidate_id'
|
48
|
+
assert result.has_key? 'locale'
|
49
|
+
assert result.has_key? 'jokers'
|
50
|
+
assert result.has_key? 'joker_ids'
|
51
|
+
assert result.has_key? 'joined_at'
|
52
|
+
assert result.has_key? 'leaved_at'
|
53
|
+
assert result.has_key? 'aborted_at'
|
54
|
+
assert result.has_key? 'joined?'
|
55
|
+
assert result.has_key? 'leaved?'
|
56
|
+
assert result.has_key? 'aborted?'
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def assert_delegate(method)
|
62
|
+
assert candidate.respond_to?(method), "Candidate should respond to #{method}"
|
63
|
+
assert subject.respond_to?(method), "Response::Candidate should respond to #{method}"
|
64
|
+
assert_equal candidate.send(method), subject.send(method), "Candidate##{method} != Response::Candidate##{method}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def klass
|
68
|
+
Barker::Api::Response::Candidate
|
69
|
+
end
|
70
|
+
|
71
|
+
def subject
|
72
|
+
klass.new(:candidate => candidate)
|
73
|
+
end
|
74
|
+
|
75
|
+
def candidate
|
76
|
+
@candidate ||= FactoryGirl.build :candidate
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Barker
|
4
|
+
module Api
|
5
|
+
module Response
|
6
|
+
class GameShowTest < Spec
|
7
|
+
|
8
|
+
test "instance" do
|
9
|
+
assert_kind_of Barker::Api::Response::GameShow, klass.new
|
10
|
+
end
|
11
|
+
|
12
|
+
test "inherit from base" do
|
13
|
+
assert klass < Barker::Api::Response::Base
|
14
|
+
end
|
15
|
+
|
16
|
+
test "game_show" do
|
17
|
+
assert_equal game_show, subject.game_show
|
18
|
+
end
|
19
|
+
|
20
|
+
test "candidates" do
|
21
|
+
assert_kind_of Array, subject.candidates
|
22
|
+
assert_kind_of Response::Candidate, subject.candidates[0]
|
23
|
+
end
|
24
|
+
|
25
|
+
test "rounds" do
|
26
|
+
assert_kind_of Array, subject.rounds
|
27
|
+
assert_kind_of Response::Round, subject.rounds[0]
|
28
|
+
end
|
29
|
+
|
30
|
+
test "to_hash" do
|
31
|
+
result = subject.to_hash
|
32
|
+
assert_kind_of Hash, result
|
33
|
+
|
34
|
+
assert result.has_key? 'id'
|
35
|
+
assert result.has_key? 'game_show_id'
|
36
|
+
assert result.has_key? 'joker_ids'
|
37
|
+
assert result.has_key? 'jokers'
|
38
|
+
assert result.has_key? 'started_at'
|
39
|
+
assert result.has_key? 'finished_at'
|
40
|
+
assert result.has_key? 'aborted_at'
|
41
|
+
assert result.has_key? 'started?'
|
42
|
+
assert result.has_key? 'finished?'
|
43
|
+
assert result.has_key? 'aborted?'
|
44
|
+
assert result.has_key? 'running?'
|
45
|
+
assert result.has_key? 'stage'
|
46
|
+
assert result.has_key? 'round'
|
47
|
+
assert result.has_key? 'next_stage?'
|
48
|
+
assert result.has_key? 'next_round?'
|
49
|
+
assert result.has_key? 'candidates'
|
50
|
+
assert result.has_key? 'rounds'
|
51
|
+
assert result.has_key? 'round_time'
|
52
|
+
|
53
|
+
assert_kind_of Array, result['candidates']
|
54
|
+
assert_kind_of Hash, result['candidates'][0]
|
55
|
+
|
56
|
+
assert_kind_of Array, result['rounds']
|
57
|
+
assert_kind_of Hash, result['rounds'][0]
|
58
|
+
end
|
59
|
+
|
60
|
+
test "delegate" do
|
61
|
+
assert_delegate :id
|
62
|
+
assert_delegate :game_show_id
|
63
|
+
assert_delegate :started_at
|
64
|
+
assert_delegate :finished_at
|
65
|
+
assert_delegate :aborted_at
|
66
|
+
assert_delegate :started?
|
67
|
+
assert_delegate :finished?
|
68
|
+
assert_delegate :aborted?
|
69
|
+
assert_delegate :running?
|
70
|
+
assert_delegate :stage
|
71
|
+
assert_delegate :round
|
72
|
+
assert_delegate :next_stage?
|
73
|
+
assert_delegate :next_round?
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def assert_delegate(method)
|
79
|
+
assert game_show.respond_to?(method), "GameShow should respond to #{method}"
|
80
|
+
assert subject.respond_to?(method), "Response::GameShow should respond to #{method}"
|
81
|
+
assert_equal game_show.send(method), subject.send(method), "GameShow##{method} != Response::GameShow##{method}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def klass
|
85
|
+
Barker::Api::Response::GameShow
|
86
|
+
end
|
87
|
+
|
88
|
+
def subject
|
89
|
+
klass.new(:game_show => game_show)
|
90
|
+
end
|
91
|
+
|
92
|
+
def game_show
|
93
|
+
if @game_show
|
94
|
+
@game_show
|
95
|
+
else
|
96
|
+
@game_show ||= FactoryGirl.build :game_show
|
97
|
+
@game_show.start
|
98
|
+
@game_show
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Barker
|
4
|
+
module Api
|
5
|
+
module Response
|
6
|
+
class RoundTest < Spec
|
7
|
+
|
8
|
+
test "instance" do
|
9
|
+
assert_kind_of Barker::Api::Response::Round, klass.new
|
10
|
+
end
|
11
|
+
|
12
|
+
test "inherit from base" do
|
13
|
+
assert klass < Barker::Api::Response::Base
|
14
|
+
end
|
15
|
+
|
16
|
+
test "round" do
|
17
|
+
assert_equal round, subject.round
|
18
|
+
end
|
19
|
+
|
20
|
+
test "questions" do
|
21
|
+
assert_kind_of Array, subject.questions
|
22
|
+
assert_kind_of Response::CandidateQuestion, subject.questions[0]
|
23
|
+
end
|
24
|
+
|
25
|
+
test "to_hash" do
|
26
|
+
result = subject.to_hash
|
27
|
+
|
28
|
+
assert_kind_of Array, result['questions']
|
29
|
+
assert_kind_of Hash, result['questions'][0]
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def klass
|
35
|
+
Barker::Api::Response::Round
|
36
|
+
end
|
37
|
+
|
38
|
+
def subject
|
39
|
+
klass.new(:round => round)
|
40
|
+
end
|
41
|
+
|
42
|
+
def round
|
43
|
+
@round ||= FactoryGirl.build :round
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|