diff --git a/app/controllers/api/v1/statuses/favourited_by_accounts_controller.rb b/app/controllers/api/v1/statuses/favourited_by_accounts_controller.rb index 3cca246ce8..98b69c347f 100644 --- a/app/controllers/api/v1/statuses/favourited_by_accounts_controller.rb +++ b/app/controllers/api/v1/statuses/favourited_by_accounts_controller.rb @@ -14,7 +14,7 @@ class Api::V1::Statuses::FavouritedByAccountsController < Api::V1::Statuses::Bas def load_accounts scope = default_accounts - scope = scope.where.not(id: current_account.excluded_from_timeline_account_ids) unless current_account.nil? + scope = scope.not_excluded_by_account(current_account) unless current_account.nil? scope.merge(paginated_favourites).to_a end diff --git a/app/controllers/api/v1/statuses/reblogged_by_accounts_controller.rb b/app/controllers/api/v1/statuses/reblogged_by_accounts_controller.rb index dd3e60846b..aacab5f8f4 100644 --- a/app/controllers/api/v1/statuses/reblogged_by_accounts_controller.rb +++ b/app/controllers/api/v1/statuses/reblogged_by_accounts_controller.rb @@ -14,7 +14,7 @@ class Api::V1::Statuses::RebloggedByAccountsController < Api::V1::Statuses::Base def load_accounts scope = default_accounts - scope = scope.where.not(id: current_account.excluded_from_timeline_account_ids) unless current_account.nil? + scope = scope.not_excluded_by_account(current_account) unless current_account.nil? scope.merge(paginated_statuses).to_a end diff --git a/spec/controllers/api/v1/statuses/favourited_by_accounts_controller_spec.rb b/spec/requests/api/v1/statuses/favourited_by_accounts_spec.rb similarity index 52% rename from spec/controllers/api/v1/statuses/favourited_by_accounts_controller_spec.rb rename to spec/requests/api/v1/statuses/favourited_by_accounts_spec.rb index 01816743e5..44296f4c37 100644 --- a/spec/controllers/api/v1/statuses/favourited_by_accounts_controller_spec.rb +++ b/spec/requests/api/v1/statuses/favourited_by_accounts_spec.rb @@ -2,21 +2,21 @@ require 'rails_helper' -RSpec.describe Api::V1::Statuses::FavouritedByAccountsController do - render_views - - let(:user) { Fabricate(:user) } - let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') } - let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, application: app, scopes: 'read:accounts') } +RSpec.describe 'API V1 Statuses Favourited by Accounts' do + let(:user) { Fabricate(:user) } + let(:scopes) { 'read:accounts' } + # let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') } + let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) } + let(:headers) { { 'Authorization' => "Bearer #{token.token}" } } let(:alice) { Fabricate(:account) } let(:bob) { Fabricate(:account) } context 'with an oauth token' do - before do - allow(controller).to receive(:doorkeeper_token) { token } + subject do + get "/api/v1/statuses/#{status.id}/favourited_by", headers: headers, params: { limit: 2 } end - describe 'GET #index' do + describe 'GET /api/v1/statuses/:status_id/favourited_by' do let(:status) { Fabricate(:status, account: user.account) } before do @@ -24,30 +24,38 @@ RSpec.describe Api::V1::Statuses::FavouritedByAccountsController do Favourite.create!(account: bob, status: status) end - it 'returns http success' do - get :index, params: { status_id: status.id, limit: 2 } - expect(response).to have_http_status(200) - expect(response.headers['Link'].links.size).to eq(2) - end - - it 'returns accounts who favorited the status' do - get :index, params: { status_id: status.id, limit: 2 } - expect(body_as_json.size).to eq 2 - expect([body_as_json[0][:id], body_as_json[1][:id]]).to contain_exactly(alice.id.to_s, bob.id.to_s) + it 'returns http success and accounts who favourited the status' do + subject + + expect(response) + .to have_http_status(200) + expect(response.headers['Link'].links.size) + .to eq(2) + + expect(body_as_json.size) + .to eq(2) + expect(body_as_json) + .to contain_exactly( + include(id: alice.id.to_s), + include(id: bob.id.to_s) + ) end it 'does not return blocked users' do user.account.block!(bob) - get :index, params: { status_id: status.id, limit: 2 } - expect(body_as_json.size).to eq 1 - expect(body_as_json[0][:id]).to eq alice.id.to_s + + subject + + expect(body_as_json.size) + .to eq 1 + expect(body_as_json.first[:id]).to eq(alice.id.to_s) end end end context 'without an oauth token' do - before do - allow(controller).to receive(:doorkeeper_token).and_return(nil) + subject do + get "/api/v1/statuses/#{status.id}/favourited_by", params: { limit: 2 } end context 'with a private status' do @@ -59,7 +67,8 @@ RSpec.describe Api::V1::Statuses::FavouritedByAccountsController do end it 'returns http unauthorized' do - get :index, params: { status_id: status.id } + subject + expect(response).to have_http_status(404) end end @@ -74,7 +83,8 @@ RSpec.describe Api::V1::Statuses::FavouritedByAccountsController do end it 'returns http success' do - get :index, params: { status_id: status.id } + subject + expect(response).to have_http_status(200) end end diff --git a/spec/controllers/api/v1/statuses/reblogged_by_accounts_controller_spec.rb b/spec/requests/api/v1/statuses/reblogged_by_accounts_spec.rb similarity index 57% rename from spec/controllers/api/v1/statuses/reblogged_by_accounts_controller_spec.rb rename to spec/requests/api/v1/statuses/reblogged_by_accounts_spec.rb index 0d15cca75c..6f99ce9464 100644 --- a/spec/controllers/api/v1/statuses/reblogged_by_accounts_controller_spec.rb +++ b/spec/requests/api/v1/statuses/reblogged_by_accounts_spec.rb @@ -2,21 +2,20 @@ require 'rails_helper' -RSpec.describe Api::V1::Statuses::RebloggedByAccountsController do - render_views - - let(:user) { Fabricate(:user) } - let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') } - let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, application: app, scopes: 'read:accounts') } +RSpec.describe 'API V1 Statuses Reblogged by Accounts' do + let(:user) { Fabricate(:user) } + let(:scopes) { 'read:accounts' } + let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) } + let(:headers) { { 'Authorization' => "Bearer #{token.token}" } } let(:alice) { Fabricate(:account) } let(:bob) { Fabricate(:account) } context 'with an oauth token' do - before do - allow(controller).to receive(:doorkeeper_token) { token } + subject do + get "/api/v1/statuses/#{status.id}/reblogged_by", headers: headers, params: { limit: 2 } end - describe 'GET #index' do + describe 'GET /api/v1/statuses/:status_id/reblogged_by' do let(:status) { Fabricate(:status, account: user.account) } before do @@ -25,27 +24,37 @@ RSpec.describe Api::V1::Statuses::RebloggedByAccountsController do end it 'returns accounts who reblogged the status', :aggregate_failures do - get :index, params: { status_id: status.id, limit: 2 } - - expect(response).to have_http_status(200) - expect(response.headers['Link'].links.size).to eq(2) - - expect(body_as_json.size).to eq 2 - expect([body_as_json[0][:id], body_as_json[1][:id]]).to contain_exactly(alice.id.to_s, bob.id.to_s) + subject + + expect(response) + .to have_http_status(200) + expect(response.headers['Link'].links.size) + .to eq(2) + + expect(body_as_json.size) + .to eq(2) + expect(body_as_json) + .to contain_exactly( + include(id: alice.id.to_s), + include(id: bob.id.to_s) + ) end it 'does not return blocked users' do user.account.block!(bob) - get :index, params: { status_id: status.id, limit: 2 } - expect(body_as_json.size).to eq 1 - expect(body_as_json[0][:id]).to eq alice.id.to_s + + subject + + expect(body_as_json.size) + .to eq 1 + expect(body_as_json.first[:id]).to eq(alice.id.to_s) end end end context 'without an oauth token' do - before do - allow(controller).to receive(:doorkeeper_token).and_return(nil) + subject do + get "/api/v1/statuses/#{status.id}/reblogged_by", params: { limit: 2 } end context 'with a private status' do @@ -57,7 +66,8 @@ RSpec.describe Api::V1::Statuses::RebloggedByAccountsController do end it 'returns http unauthorized' do - get :index, params: { status_id: status.id } + subject + expect(response).to have_http_status(404) end end @@ -72,7 +82,8 @@ RSpec.describe Api::V1::Statuses::RebloggedByAccountsController do end it 'returns http success' do - get :index, params: { status_id: status.id } + subject + expect(response).to have_http_status(200) end end