From 58ace2e45e16a69977267d03874568c11043f04c Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 18 Jun 2024 18:04:58 +0200 Subject: [PATCH] Fix SQL error in admin measures API (#30753) --- app/lib/admin/metrics/measure/query_helper.rb | 2 +- spec/requests/api/v1/admin/measures_spec.rb | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/lib/admin/metrics/measure/query_helper.rb b/app/lib/admin/metrics/measure/query_helper.rb index 5969a96ba..47cfc63e5 100644 --- a/app/lib/admin/metrics/measure/query_helper.rb +++ b/app/lib/admin/metrics/measure/query_helper.rb @@ -18,7 +18,7 @@ module Admin::Metrics::Measure::QueryHelper def generated_series_days Arel.sql( <<~SQL.squish - SELECT generate_series(timestamp :start_at, :end_at, '1 day')::date AS period + SELECT generate_series(:start_at::timestamp, :end_at::timestamp, '1 day')::date AS period SQL ) end diff --git a/spec/requests/api/v1/admin/measures_spec.rb b/spec/requests/api/v1/admin/measures_spec.rb index 15f2df84c..80fed79d9 100644 --- a/spec/requests/api/v1/admin/measures_spec.rb +++ b/spec/requests/api/v1/admin/measures_spec.rb @@ -7,11 +7,28 @@ describe 'Admin Measures' do let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) } let(:headers) { { 'Authorization' => "Bearer #{token.token}" } } let(:account) { Fabricate(:account) } + let(:params) do + { + keys: %w(instance_accounts instance_follows instance_followers), + instance_accounts: { + domain: 'mastodon.social', + include_subdomains: true, + }, + instance_follows: { + domain: 'mastodon.social', + include_subdomains: true, + }, + instance_followers: { + domain: 'mastodon.social', + include_subdomains: true, + }, + } + end describe 'GET /api/v1/admin/measures' do context 'when not authorized' do it 'returns http forbidden' do - post '/api/v1/admin/measures', params: { account_id: account.id, limit: 2 } + post '/api/v1/admin/measures', params: params expect(response) .to have_http_status(403) @@ -22,7 +39,7 @@ describe 'Admin Measures' do let(:scopes) { 'admin:read' } it 'returns http success and status json' do - post '/api/v1/admin/measures', params: { account_id: account.id, limit: 2 }, headers: headers + post '/api/v1/admin/measures', params: params, headers: headers expect(response) .to have_http_status(200)