Compare commits

...
This repository has been archived on 2023-07-01. You can view files and clone it, but cannot push or open issues or pull requests.

5 Commits

Author SHA1 Message Date
Surinna Curtis 920d25f8c9 Handle local_only param when creating statuses. 2017-12-17 05:12:01 +00:00
Surinna Curtis 578438b360 Specs for local-only of new statuses
Some of these should fail currently.
2017-12-17 05:12:01 +00:00
Surinna Curtis 358fd2121a Expose local_only? in REST::StatusSerializer 2017-12-16 21:50:22 +00:00
Surinna Curtis cb11b0ee5a Add failing specs for local_only in API responses. 2017-12-16 21:47:29 +00:00
Surinna Curtis bdaaddeff9 expect /api/v1/statuses to 403 for unauthed reqs for local-only statuses 2017-12-16 20:08:04 +00:00
4 changed files with 127 additions and 6 deletions

View File

@ -42,6 +42,7 @@ class Api::V1::StatusesController < Api::BaseController
@status = PostStatusService.new.call(current_user.account,
status_params[:status],
status_params[:in_reply_to_id].blank? ? nil : Status.find(status_params[:in_reply_to_id]),
local_only: status_params[:local_only],
media_ids: status_params[:media_ids],
sensitive: status_params[:sensitive],
spoiler_text: status_params[:spoiler_text],
@ -72,7 +73,7 @@ class Api::V1::StatusesController < Api::BaseController
end
def status_params
params.permit(:status, :in_reply_to_id, :sensitive, :spoiler_text, :visibility, media_ids: [])
params.permit(:status, :in_reply_to_id, :local_only, :sensitive, :spoiler_text, :visibility, media_ids: [])
end
def pagination_params(core_params)

View File

@ -3,7 +3,8 @@
class REST::StatusSerializer < ActiveModel::Serializer
attributes :id, :created_at, :in_reply_to_id, :in_reply_to_account_id,
:sensitive, :spoiler_text, :visibility, :language,
:uri, :content, :url, :reblogs_count, :favourites_count
:uri, :content, :url, :reblogs_count, :favourites_count,
:local_only
attribute :favourited, if: :current_user?
attribute :reblogged, if: :current_user?

View File

@ -6,6 +6,7 @@ class PostStatusService < BaseService
# @param [String] text Message
# @param [Status] in_reply_to Optional status to reply to
# @param [Hash] options
# @option [Boolean] :local_only
# @option [Boolean] :sensitive
# @option [String] :visibility
# @option [String] :spoiler_text
@ -25,6 +26,7 @@ class PostStatusService < BaseService
ApplicationRecord.transaction do
status = account.statuses.create!(text: text,
thread: in_reply_to,
local_only: options[:local_only],
sensitive: options[:sensitive],
spoiler_text: options[:spoiler_text] || '',
visibility: options[:visibility] || account.user&.setting_default_privacy,

View File

@ -35,13 +35,71 @@ RSpec.describe Api::V1::StatusesController, type: :controller do
end
describe 'POST #create' do
before do
post :create, params: { status: 'Hello world' }
context 'with local_only unspecified and no eyeball' do
before do
post :create, params: { status: 'Hello world' }
end
let(:status_response) { JSON.parse(response.body) }
it 'returns http success' do
expect(response).to have_http_status(:success)
end
it 'creates a non-local-only status' do
expect(status_response["local_only"]).to be false
end
end
it 'returns http success' do
expect(response).to have_http_status(:success)
context 'with local_only unspecified and an eyeball' do
before do
post :create, params: { status: "Hello world #{Status.new.local_only_emoji}" }
end
let(:status_response) { JSON.parse(response.body) }
it 'returns http success' do
expect(response).to have_http_status(:success)
end
it 'creates a local-only status' do
expect(status_response["local_only"]).to be true
end
end
context 'with local_only set to true' do
before do
post :create, params: { status: 'Hello world', local_only: true }
end
let(:status_response) { JSON.parse(response.body) }
it 'returns http success' do
expect(response).to have_http_status(:success)
end
it 'creates a local-only status' do
expect(status_response["local_only"]).to be true
end
end
context 'with local_only set to false' do
before do
post :create, params: { status: 'Hello world', local_only: false }
end
let(:status_response) { JSON.parse(response.body) }
it 'returns http success' do
expect(response).to have_http_status(:success)
end
it 'creates a non-local-only status' do
expect(status_response["local_only"]).to be false
end
end
end
describe 'DELETE #destroy' do
@ -59,6 +117,36 @@ RSpec.describe Api::V1::StatusesController, type: :controller do
expect(Status.find_by(id: status.id)).to be nil
end
end
describe 'the "local_only" property' do
context 'for a local-only status' do
let(:status) { Fabricate(:status, account: user.account, local_only: true) }
before do
get :show, params: { id: status.id }
end
let(:status_response) { JSON.parse(response.body) }
it 'is true' do
expect(status_response["local_only"]).to be true
end
end
context 'for a non-local-only status' do
let(:status) { Fabricate(:status, account: user.account, local_only: false) }
before do
get :show, params: { id: status.id }
end
let(:status_response) { JSON.parse(response.body) }
it 'is false' do
expect(status_response["local_only"]).to be false
end
end
end
end
context 'without an oauth token' do
@ -123,5 +211,34 @@ RSpec.describe Api::V1::StatusesController, type: :controller do
end
end
end
context 'with a local-only status' do
let(:status) { Fabricate(:status, account: user.account, visibility: :public, local_only: true) }
describe 'GET #show' do
it 'returns http unautharized' do
get :show, params: { id: status.id }
expect(response).to have_http_status(:missing)
end
end
describe 'GET #context' do
before do
Fabricate(:status, account: user.account, thread: status)
end
it 'returns http unautharized' do
get :context, params: { id: status.id }
expect(response).to have_http_status(:missing)
end
end
describe 'GET #card' do
it 'returns http unautharized' do
get :card, params: { id: status.id }
expect(response).to have_http_status(:missing)
end
end
end
end
end