-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtalk_spec.rb
More file actions
264 lines (229 loc) · 8.9 KB
/
talk_spec.rb
File metadata and controls
264 lines (229 loc) · 8.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# == Schema Information
#
# Table name: talks
#
# id :bigint not null, primary key
# abstract :text(65535)
# acquired_seats :integer default(0), not null
# document_url :string(255)
# end_offset :integer default(0), not null
# end_time :time
# execution_phases :json
# expected_participants :json
# movie_url :string(255)
# number_of_seats :integer default(0), not null
# show_on_timetable :boolean
# start_offset :integer default(0), not null
# start_time :time
# title :string(255)
# type :string(255) not null
# video_published :boolean default(FALSE), not null
# created_at :datetime not null
# updated_at :datetime not null
# conference_day_id :integer
# conference_id :integer
# sponsor_id :integer
# talk_category_id :bigint
# talk_difficulty_id :bigint
# talk_time_id :integer
# track_id :integer
#
# Indexes
#
# fk_rails_9c6f538eea (type)
# index_talks_on_conference_id (conference_id)
# index_talks_on_talk_category_id (talk_category_id)
# index_talks_on_talk_difficulty_id (talk_difficulty_id)
# index_talks_on_track_id (track_id)
#
# Foreign Keys
#
# fk_rails_... (type => talk_types.id)
#
require 'rails_helper'
describe Talk, type: :model do
context 'live?' do
let!(:cndt2020) { create(:cndt2020) }
let!(:talk) { create(:talk1) }
let!(:proposal_item_config_1) { create(:proposal_item_configs_presentation_method, :live, conference: cndt2020) }
let!(:proposal_item_config_2) { create(:proposal_item_configs_presentation_method, :video, conference: cndt2020) }
context 'live session' do
let!(:presentation_method) { create(:presentation_method, conference: cndt2020, talk:, params: proposal_item_config_1.id) }
it 'should be true' do
expect(talk.live?).to(be_truthy)
end
end
context 'non-live session' do
let!(:presentation_method) { create(:presentation_method, conference: cndt2020, talk:, params: proposal_item_config_2.id) }
it 'should be true' do
expect(talk.live?).to(be_falsey)
end
end
end
describe '#export_csv' do
let!(:cndt2020) { create(:cndt2020) }
let!(:talk) { create(:talk1) }
let!(:proposal_item_config_1) { create(:proposal_item_configs_presentation_method, :live, conference: cndt2020) }
let!(:proposal_item_config_2) { create(:proposal_item_configs_presentation_method, :video, conference: cndt2020) }
let(:expected) {
<<~EOS
id,title,abstract,speaker,session_time,difficulty,category,created_at,additional_documents,twitter_id,company,start_to_end,sponsor_session,presentation_method,avatar_url,date,track_id
1,talk1,あいうえおかきくけこさしすせそ,"",40,,,#{talk.created_at.strftime('%Y-%m-%d %H:%M:%S +0900')},"","","",12:00-12:40,No,,"",2020-09-08,A
EOS
}
context 'has full attributes' do
it 'export csv' do
File.open(Talk.export_csv(cndt2020, [talk]), 'r', encoding: 'UTF-8') do |file|
expect(file.read).to(eq(expected))
end
end
end
context 'on registration term' do
let!(:talk) { create(:has_no_conference_days) }
let(:expected) {
<<~EOS
id,title,abstract,speaker,session_time,difficulty,category,created_at,additional_documents,twitter_id,company,start_to_end,sponsor_session,presentation_method,avatar_url,date,track_id
100,not accepted talk,あいうえおかきくけこさしすせそ,"",40,,,#{talk.created_at.strftime('%Y-%m-%d %H:%M:%S +0900')},"","","","",No,,"",,
EOS
}
it 'export csv without attributes will be decided later' do
File.open(Talk.export_csv(cndt2020, [talk]), 'r', encoding: 'UTF-8') do |file|
expect(file.read).to(eq(expected))
end
end
end
end
describe '#calendar' do
let!(:cndt2020) { create(:cndt2020) }
let!(:talk) { create(:talk1, :has_room) }
it 'has full attributes' do
expect(talk.calendar.summary).to(eq('talk1'))
expect(talk.calendar.description.value).to(eq("
TrackA
会場: ONLINE
https://event.cloudnativedays.jp/cndt2020/talks/1
あいうえおかきくけこさしすせそ
"))
expect(talk.calendar.dtstart.value).to(eq(DateTime.new(2020, 9, 8, 12)))
expect(talk.calendar.dtend.value).to(eq(DateTime.new(2020, 9, 8, 12, 40)))
end
end
describe 'Chat message' do
let!(:cndt2020) { create(:cndt2020) }
let!(:talk) { create(:talk1, :has_room) }
let!(:alice) { create(:alice, :on_cndt2020, conference: cndt2020) }
let!(:bob) { create(:bob, :on_cndt2020, conference: cndt2020) }
context 'if talk has child messages' do
before do
create_list(:messages, 2, :alice, :roomid1, profile: alice)
create_list(:messages, 2, :alice, :roomid1, :qa, profile: alice)
create_list(:messages, 2, :alice, :roomid2, profile: alice)
end
it 'should return chat messages' do
expect(talk.chat_messages.count).to(eq(4))
end
it 'should return qa messages only' do
expect(talk.qa_messages.count).to(eq(2))
end
end
end
describe '#archived?' do
let!(:cndt2020) { create(:cndt2020) }
let!(:talk) { create(:talk1) }
context 'talk is not finished' do
around { |e| travel_to(Time.zone.local(2020, 9, 8, 12, 49)) { e.run } }
it 'returns false' do
expect(talk.archived?).to(be_falsey)
end
end
context 'talk is finished' do
around { |e| travel_to(Time.zone.local(2020, 9, 8, 13, 50)) { e.run } }
it 'returns true' do
expect(talk.archived?).to(be_truthy)
end
end
end
describe '#allowed_showing_video?' do
before do
create(:proposal_item_configs_whether_it_can_be_published, :all_ok, conference: cndt2020)
create(:proposal_item_configs_whether_it_can_be_published, :only_video, conference: cndt2020)
create(:proposal_item_configs_whether_it_can_be_published, :only_slide, conference: cndt2020)
create(:proposal_item_configs_whether_it_can_be_published, :all_ng, conference: cndt2020)
end
let!(:cndt2020) { create(:cndt2020) }
context 'all ok' do
let!(:talk) { create(:talk1) }
let!(:whether_it_can_be_published) { create(:proposal_item_whether_it_can_be_published, :all_ok, talk:) }
it 'should be true' do
expect(talk.allowed_showing_video?).to(be_truthy)
end
end
context 'only video' do
let!(:talk) { create(:talk1) }
let!(:whether_it_can_be_published) { create(:proposal_item_whether_it_can_be_published, :only_video, talk:) }
it 'should be true' do
expect(talk.allowed_showing_video?).to(be_truthy)
end
end
context 'only slide' do
let!(:talk) { create(:talk1) }
let!(:whether_it_can_be_published) { create(:proposal_item_whether_it_can_be_published, :only_slide, talk:) }
it 'should be false' do
expect(talk.allowed_showing_video?).to(be_falsey)
end
end
context 'all_ng' do
let!(:talk) { create(:talk1) }
let!(:whether_it_can_be_published) { create(:proposal_item_whether_it_can_be_published, :all_ng, talk:) }
it 'should be false' do
expect(talk.allowed_showing_video?).to(be_falsey)
end
end
end
describe '#offline_participation_size' do
let!(:cndt2020) { create(:cndt2020) }
let!(:talk) { create(:talk1) }
let!(:alice) { create(:alice, :on_cndt2020, conference: cndt2020) }
let!(:bob) { create(:bob, :on_cndt2020, :offline, conference: cndt2020) }
context 'only online' do
before do
create(:registered_talk, talk:, profile: alice)
end
it 'return 0' do
expect(talk.offline_participation_size).to(eq(0))
end
end
context 'has one offline registration' do
before do
create(:registered_talk, talk:, profile: alice)
create(:registered_talk, talk:, profile: bob)
end
it 'return 1' do
expect(talk.offline_participation_size).to(eq(1))
end
end
end
describe '#online_participation_size' do
let!(:cndt2020) { create(:cndt2020) }
let!(:talk) { create(:talk1) }
let!(:alice) { create(:alice, :on_cndt2020, conference: cndt2020) }
let!(:bob) { create(:bob, :on_cndt2020, :offline, conference: cndt2020) }
context 'only offline' do
before do
create(:registered_talk, talk:, profile: bob)
end
it 'return 0' do
expect(talk.online_participation_size).to(eq(0))
end
end
context 'has one online registration' do
before do
create(:registered_talk, talk:, profile: alice)
create(:registered_talk, talk:, profile: bob)
end
it 'return 1' do
expect(talk.online_participation_size).to(eq(1))
end
end
end
end