Skip to content

Commit

Permalink
Fix SQL error in admin measures API (mastodon#30753)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored Jun 18, 2024
1 parent d97fcd0 commit 58ace2e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/lib/admin/metrics/measure/query_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def sanitized_sql_string
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
Expand Down
21 changes: 19 additions & 2 deletions spec/requests/api/v1/admin/measures_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,28 @@
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)
Expand All @@ -22,7 +39,7 @@
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)
Expand Down

0 comments on commit 58ace2e

Please sign in to comment.