require 'rails_helper' RSpec.describe 'History boundaries shared with Counts', type: :request do let!(:tag) { create(:tag, primary_name: 'description tag') } let!(:description) do TagDescription.create!(tag:, language_code: 'ja', version_no: 2, body: 'private body') end before do ['create', 'discard'].each_with_index do |event, index| TagDescriptionVersion.create!(tag_id: tag.id, language_code: 'ja', version_no: index + 1, event_type: event, body: 'private body', created_at: Time.utc(2024)) end end it 'keeps discarded history private while exposing the current description' do get '/counts/query', params: { resource: 'tag_descriptions', definition: 'history', mode: 'details', locale: 'ja', execution_at: '2025-01-01T00:00:00Z' } expect(response).to have_http_status(:ok) expect(response.parsed_body).to include('count' => 0, 'output_count' => 2, 'excluded_count' => 2, 'versions' => []) paths = [ "/wiki/#{ description.id }", '/wiki/title/description%20tag', "/tags/#{ tag.id }/description"] paths.each do |path| get path, params: { locale: 'ja' } expect(response).to have_http_status(:ok) expect(response.parsed_body.fetch('body')).to eq(description.body) end get '/sitemap_entries/descriptions', params: { locale: 'ja' } expect(response).to have_http_status(:ok) expect(response.parsed_body['ids']).not_to include(description.id) end it 'omits private revision references and rejects history and diff requests' do get "/wiki/#{ description.id }", params: { locale: 'ja' } expect(response).to have_http_status(:ok) expect(response.parsed_body).to include( 'revision_id' => nil, 'pred' => nil, 'succ' => nil, 'updated_at' => description.updated_at.iso8601(3)) version = TagDescriptionVersion.find_by!( tag_id: tag.id, language_code: 'ja', version_no: 2) get "/wiki/#{ description.id }", params: { locale: 'ja', version: version.id } expect(response).to have_http_status(:not_found) get "/wiki/#{ description.id }/diff", params: { locale: 'ja' } expect(response).to have_http_status(:not_found) end it 'permits the server-authenticated administrator to read the discarded description' do sign_in_as(create(:user, :admin)) get "/tags/#{ tag.id }/description", params: { locale: 'ja' } expect(response).to have_http_status(:ok) expect(response.parsed_body['body']).to eq('private body') expect(response.headers['Cache-Control']).to include('no-store') end end