Add missing test case for PostController#timings.

This commit is contained in:
Guo Xiang Tan 2017-09-04 16:36:02 +08:00
parent 1043a2e99f
commit 5c1143cd55
2 changed files with 23 additions and 1 deletions

View File

@ -588,9 +588,10 @@ class TopicsController < ApplicationController
current_user,
params[:topic_id].to_i,
params[:topic_time].to_i,
(params[:timings] || []).map { |post_number, t| [post_number.to_i, t.to_i] },
(params[:timings] || {}).map { |post_number, t| [post_number.to_i, t.to_i] },
mobile: view_context.mobile_view?
)
render nothing: true
end

View File

@ -4,6 +4,27 @@ RSpec.describe TopicsController do
let(:topic) { Fabricate(:topic) }
let(:user) { Fabricate(:user) }
describe '#timings' do
let(:post_1) { Fabricate(:post, topic: topic) }
it 'should record the timing' do
sign_in(user)
post "/topics/timings.json",
topic_id: topic.id,
topic_time: 5,
timings: { post_1.post_number => 2 }
expect(response).to be_success
post_timing = PostTiming.first
expect(post_timing.topic).to eq(topic)
expect(post_timing.user).to eq(user)
expect(post_timing.msecs).to eq(2)
end
end
describe '#timer' do
context 'when a user is not logged in' do
it 'should return the right response' do