From b7d92b7ddd55f2f4c4f861402e12f5deae7c93a9 Mon Sep 17 00:00:00 2001 From: Codex Night Worker Date: Fri, 13 Nov 2026 12:25:24 +0900 Subject: [PATCH 1/2] AI: address issue #439 --- backend/app/controllers/posts_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/app/controllers/posts_controller.rb b/backend/app/controllers/posts_controller.rb index ba15e99..bf54551 100644 --- a/backend/app/controllers/posts_controller.rb +++ b/backend/app/controllers/posts_controller.rb @@ -314,7 +314,9 @@ class PostsController < ApplicationController def viewed return head :unauthorized unless current_user - current_user.viewed_posts << Post.find(params[:id]) + UserPostView.create_or_find_by!( + user: current_user, + post: Post.find(params[:id])) head :no_content end -- 2.53.0 From ae3d9b38765f529f2d2f142bdb8eb4198b35df5b Mon Sep 17 00:00:00 2001 From: Codex Night Worker Date: Fri, 13 Nov 2026 12:41:39 +0900 Subject: [PATCH 2/2] AI: address review on PR #468 --- backend/spec/requests/posts_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/backend/spec/requests/posts_spec.rb b/backend/spec/requests/posts_spec.rb index aa5f7c1..ca74978 100644 --- a/backend/spec/requests/posts_spec.rb +++ b/backend/spec/requests/posts_spec.rb @@ -2559,6 +2559,21 @@ RSpec.describe 'Posts API', type: :request do expect(user.reload.viewed?(post_record)).to be(true) end + + it '204 and keeps one view on repeated requests' do + sign_in_as(user) + + expect { + post "/posts/#{ post_record.id }/viewed" + }.to change(UserPostView, :count).by(1) + expect(response).to have_http_status(:no_content) + + expect { + post "/posts/#{ post_record.id }/viewed" + }.not_to change(UserPostView, :count) + expect(response).to have_http_status(:no_content) + expect(user.reload.viewed?(post_record)).to be(true) + end end describe 'DELETE /posts/:id/viewed' do -- 2.53.0