コミットを比較
2
コミット
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
|
|
ae3d9b3876 | ||
|
|
b7d92b7ddd |
@@ -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
|
||||
|
||||
|
||||
@@ -69,11 +69,8 @@ class TagVersionsController < ApplicationController
|
||||
|
||||
parent_tags =
|
||||
build_version_values(cur_parent_tag_ids, prev_parent_tag_ids, key: :tag_id)
|
||||
.filter_map do |h|
|
||||
parent = parent_json[h[:tag_id]]
|
||||
next unless parent
|
||||
|
||||
{ tag: parent,
|
||||
.map do |h|
|
||||
{ tag: parent_json.fetch(h[:tag_id]),
|
||||
type: h[:type] }
|
||||
end
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -215,36 +215,6 @@ RSpec.describe 'TagVersions API', type: :request do
|
||||
expect(first.fetch('created_at')).to eq(t_v1.iso8601)
|
||||
end
|
||||
|
||||
[:parent_shared, :parent_new, :parent_old].each do |parent_key|
|
||||
it "omits deleted #{ parent_key } from parent diffs" do
|
||||
deleted_parent = public_send(parent_key)
|
||||
deleted_parent.tag_names.destroy_all
|
||||
deleted_parent.destroy!
|
||||
|
||||
get '/tags/versions', params: { id: tag.id }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json.fetch('count')).to eq(2)
|
||||
|
||||
versions = json.fetch('versions')
|
||||
expect(versions.map { _1.fetch('version_no') }).to eq([2, 1])
|
||||
|
||||
expected_parents = [
|
||||
[parent_shared.id, 'context'],
|
||||
[parent_new.id, 'added'],
|
||||
[parent_old.id, 'removed']].reject { _1.first == deleted_parent.id }
|
||||
expect(versions.first.fetch('parent_tags').map { |entry|
|
||||
[entry.fetch('tag').fetch('id'), entry.fetch('type')]
|
||||
}).to eq(expected_parents)
|
||||
|
||||
expected_first_parents = [parent_shared.id, parent_old.id]
|
||||
.reject { _1 == deleted_parent.id }.map { [_1, 'added'] }
|
||||
expect(versions.second.fetch('parent_tags').map { |entry|
|
||||
[entry.fetch('tag').fetch('id'), entry.fetch('type')]
|
||||
}).to eq(expected_first_parents)
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns empty when the specified tag has no versions' do
|
||||
fresh_tag = create(:tag, primary_name: 'no_versions_tag', category: :general)
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする