|
14 | 14 | let(:topic) { Fabricate(:topic, user: user) }
|
15 | 15 | let!(:first_post) { Fabricate(:post, topic: topic) }
|
16 | 16 | let(:second_post) { Fabricate(:post, topic: topic) }
|
17 |
| - let!(:starts_at) { "2020-04-24 14:15:00" } |
18 |
| - let!(:ends_at) { "2020-04-24 16:15:00" } |
19 |
| - let!(:alt_starts_at) { "2020-04-24 14:14:25" } |
20 |
| - let!(:alt_ends_at) { "2020-04-24 19:15:25" } |
| 17 | + let!(:starts_at) { Time.zone.parse("2020-04-24 14:15:00") } |
| 18 | + let!(:ends_at) { Time.zone.parse("2020-04-24 16:15:00") } |
| 19 | + let!(:alt_starts_at) { Time.zone.parse("2020-04-24 14:14:25") } |
| 20 | + let!(:alt_ends_at) { Time.zone.parse("2020-04-24 19:15:25") } |
21 | 21 | let(:event) do
|
22 | 22 | DiscoursePostEvent::Event.create!(
|
23 | 23 | id: first_post.id,
|
|
32 | 32 | original_ends_at: Time.now - 8.hours,
|
33 | 33 | )
|
34 | 34 | end
|
| 35 | + let(:first_post_starts_at) do |
| 36 | + Time.zone.parse( |
| 37 | + first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT], |
| 38 | + ) |
| 39 | + end |
| 40 | + let(:first_post_ends_at) do |
| 41 | + Time.zone.parse(first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_ENDS_AT]) |
| 42 | + end |
35 | 43 |
|
36 | 44 | describe "#after_commit[:create, :update]" do
|
37 | 45 | context "when a post event has been created" do
|
|
49 | 57 | }.to change { DiscoursePostEvent::EventDate.count }
|
50 | 58 | first_post.topic.reload
|
51 | 59 |
|
52 |
| - expect( |
53 |
| - first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT], |
54 |
| - ).to eq(starts_at) |
55 |
| - expect( |
56 |
| - first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_ENDS_AT], |
57 |
| - ).to eq(ends_at) |
58 |
| - expect(DiscoursePostEvent::EventDate.last.starts_at).to eq_time( |
59 |
| - DateTime.parse(starts_at), |
60 |
| - ) |
61 |
| - expect(DiscoursePostEvent::EventDate.last.ends_at).to eq_time(DateTime.parse(ends_at)) |
| 60 | + expect(first_post_starts_at).to eq_time(starts_at) |
| 61 | + expect(first_post_ends_at).to eq_time(ends_at) |
| 62 | + expect(DiscoursePostEvent::EventDate.last.starts_at).to eq_time(starts_at) |
| 63 | + expect(DiscoursePostEvent::EventDate.last.ends_at).to eq_time(ends_at) |
62 | 64 | end
|
63 | 65 | end
|
64 | 66 |
|
|
108 | 110 | first_post.topic.reload
|
109 | 111 |
|
110 | 112 | expect(first_post.is_first_post?).to be(true)
|
111 |
| - expect( |
112 |
| - first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT], |
113 |
| - ).to eq(starts_at) |
114 |
| - expect( |
115 |
| - first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_ENDS_AT], |
116 |
| - ).to eq(ends_at) |
| 113 | + expect(first_post_starts_at).to eq_time(starts_at) |
| 114 | + expect(first_post_ends_at).to eq_time(ends_at) |
117 | 115 |
|
118 | 116 | first_event_date = post_event.event_dates.last
|
119 |
| - expect(first_event_date.starts_at).to eq_time(DateTime.parse(starts_at)) |
| 117 | + expect(first_event_date.starts_at).to eq_time(starts_at) |
120 | 118 | expect(first_event_date.finished_at).to be nil
|
121 | 119 |
|
122 | 120 | post_event.update_with_params!(
|
|
129 | 127 | second_event_date = post_event.event_dates.last
|
130 | 128 |
|
131 | 129 | expect(
|
132 |
| - first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT], |
| 130 | + Time.zone.parse( |
| 131 | + first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT], |
| 132 | + ), |
133 | 133 | ).to eq(alt_starts_at)
|
134 | 134 | expect(
|
135 |
| - first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_ENDS_AT], |
| 135 | + Time.zone.parse( |
| 136 | + first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_ENDS_AT], |
| 137 | + ), |
136 | 138 | ).to eq(alt_ends_at)
|
137 | 139 |
|
138 | 140 | expect(first_event_date.finished_at).not_to be nil
|
139 |
| - expect(second_event_date.starts_at).to eq_time(DateTime.parse(alt_starts_at)) |
| 141 | + expect(second_event_date.starts_at).to eq_time(alt_starts_at) |
140 | 142 |
|
141 | 143 | second_event_date.update_columns(finished_at: Time.current)
|
142 |
| - expect(post_event.starts_at).to eq_time(DateTime.parse(alt_starts_at)) |
143 |
| - expect(post_event.ends_at).to eq_time(DateTime.parse(alt_ends_at)) |
| 144 | + expect(post_event.starts_at).to eq_time(alt_starts_at) |
| 145 | + expect(post_event.ends_at).to eq_time(alt_ends_at) |
144 | 146 | end
|
145 | 147 | end
|
146 | 148 |
|
|
161 | 163 | ).to be_blank
|
162 | 164 |
|
163 | 165 | second_event_date = post_event.event_dates.last
|
164 |
| - expect(second_event_date.starts_at).to eq_time(DateTime.parse(alt_starts_at)) |
| 166 | + expect(second_event_date.starts_at).to eq_time(alt_starts_at) |
165 | 167 | end
|
166 | 168 | end
|
167 | 169 | end
|
|
183 | 185 | first_post.topic.reload
|
184 | 186 |
|
185 | 187 | expect(first_post.is_first_post?).to be(true)
|
186 |
| - expect( |
187 |
| - first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT], |
188 |
| - ).to eq(starts_at) |
189 |
| - expect( |
190 |
| - first_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_ENDS_AT], |
191 |
| - ).to eq(ends_at) |
| 188 | + expect(first_post_starts_at).to eq_time(starts_at) |
| 189 | + expect(first_post_ends_at).to eq_time(ends_at) |
192 | 190 |
|
193 | 191 | post_event.destroy!
|
194 | 192 | first_post.topic.reload
|
|
225 | 223 |
|
226 | 224 | expect(first_post.is_first_post?).to be(true)
|
227 | 225 | expect(
|
228 |
| - second_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT], |
| 226 | + Time.zone.parse( |
| 227 | + second_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT], |
| 228 | + ), |
229 | 229 | ).to eq(starts_at)
|
230 | 230 | expect(
|
231 |
| - second_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_ENDS_AT], |
| 231 | + Time.zone.parse( |
| 232 | + second_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_ENDS_AT], |
| 233 | + ), |
232 | 234 | ).to eq(ends_at)
|
233 | 235 | expect(second_post.is_first_post?).to be(false)
|
234 | 236 |
|
235 | 237 | second_post_event.destroy!
|
236 | 238 | second_post.topic.reload
|
237 | 239 |
|
238 | 240 | expect(
|
239 |
| - second_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT], |
| 241 | + Time.zone.parse( |
| 242 | + second_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_STARTS_AT], |
| 243 | + ), |
240 | 244 | ).to eq(starts_at)
|
241 | 245 | expect(
|
242 |
| - second_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_ENDS_AT], |
| 246 | + Time.zone.parse( |
| 247 | + second_post.topic.custom_fields[DiscoursePostEvent::TOPIC_POST_EVENT_ENDS_AT], |
| 248 | + ), |
243 | 249 | ).to eq(ends_at)
|
244 | 250 | end
|
245 | 251 | end
|
|
0 commit comments