diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 996dab4d263..15bcbb23362 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -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 diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index 6da482ec63b..d2e1990e3cc 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -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