From 4f9b7432dd4d323ac6cc4efceeae2efaffe62e7d Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 27 Sep 2016 16:58:23 +0200 Subject: Fix #52 - Add API versioning (v1) --- spec/controllers/api/accounts_controller_spec.rb | 116 -------------- spec/controllers/api/apps_controller_spec.rb | 26 ---- spec/controllers/api/follows_controller_spec.rb | 50 ------ spec/controllers/api/media_controller_spec.rb | 58 ------- spec/controllers/api/statuses_controller_spec.rb | 173 --------------------- .../controllers/api/v1/accounts_controller_spec.rb | 116 ++++++++++++++ spec/controllers/api/v1/apps_controller_spec.rb | 26 ++++ spec/controllers/api/v1/follows_controller_spec.rb | 50 ++++++ spec/controllers/api/v1/media_controller_spec.rb | 58 +++++++ .../controllers/api/v1/statuses_controller_spec.rb | 173 +++++++++++++++++++++ spec/helpers/api/accounts_helper_spec.rb | 5 - spec/helpers/api/apps_helper_spec.rb | 15 -- spec/helpers/api/follows_helper_spec.rb | 5 - spec/helpers/api/media_helper_spec.rb | 5 - spec/helpers/api/salmon_helper_spec.rb | 5 - spec/helpers/api/statuses_helper_spec.rb | 5 - spec/helpers/api/subscriptions_helper_spec.rb | 5 - 17 files changed, 423 insertions(+), 468 deletions(-) delete mode 100644 spec/controllers/api/accounts_controller_spec.rb delete mode 100644 spec/controllers/api/apps_controller_spec.rb delete mode 100644 spec/controllers/api/follows_controller_spec.rb delete mode 100644 spec/controllers/api/media_controller_spec.rb delete mode 100644 spec/controllers/api/statuses_controller_spec.rb create mode 100644 spec/controllers/api/v1/accounts_controller_spec.rb create mode 100644 spec/controllers/api/v1/apps_controller_spec.rb create mode 100644 spec/controllers/api/v1/follows_controller_spec.rb create mode 100644 spec/controllers/api/v1/media_controller_spec.rb create mode 100644 spec/controllers/api/v1/statuses_controller_spec.rb delete mode 100644 spec/helpers/api/accounts_helper_spec.rb delete mode 100644 spec/helpers/api/apps_helper_spec.rb delete mode 100644 spec/helpers/api/follows_helper_spec.rb delete mode 100644 spec/helpers/api/media_helper_spec.rb delete mode 100644 spec/helpers/api/salmon_helper_spec.rb delete mode 100644 spec/helpers/api/statuses_helper_spec.rb delete mode 100644 spec/helpers/api/subscriptions_helper_spec.rb (limited to 'spec') diff --git a/spec/controllers/api/accounts_controller_spec.rb b/spec/controllers/api/accounts_controller_spec.rb deleted file mode 100644 index 7fef8b9fe..000000000 --- a/spec/controllers/api/accounts_controller_spec.rb +++ /dev/null @@ -1,116 +0,0 @@ -require 'rails_helper' - -RSpec.describe Api::AccountsController, type: :controller do - render_views - - let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) } - let(:token) { double acceptable?: true, resource_owner_id: user.id } - - before do - stub_request(:post, "https://pubsubhubbub.superfeedr.com/").to_return(:status => 200, :body => "", :headers => {}) - allow(controller).to receive(:doorkeeper_token) { token } - end - - describe 'GET #show' do - it 'returns http success' do - get :show, params: { id: user.account.id } - expect(response).to have_http_status(:success) - end - end - - describe 'GET #statuses' do - it 'returns http success' do - get :statuses, params: { id: user.account.id } - expect(response).to have_http_status(:success) - end - end - - describe 'GET #followers' do - it 'returns http success' do - get :followers, params: { id: user.account.id } - expect(response).to have_http_status(:success) - end - end - - describe 'GET #following' do - it 'returns http success' do - get :following, params: { id: user.account.id } - expect(response).to have_http_status(:success) - end - end - - describe 'POST #follow' do - let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account } - - before do - post :follow, params: { id: other_account.id } - end - - it 'returns http success' do - expect(response).to have_http_status(:success) - end - - it 'creates a following relation between user and target user' do - expect(user.account.following?(other_account)).to be true - end - end - - describe 'POST #unfollow' do - let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account } - - before do - user.account.follow!(other_account) - post :unfollow, params: { id: other_account.id } - end - - it 'returns http success' do - expect(response).to have_http_status(:success) - end - - it 'removes the following relation between user and target user' do - expect(user.account.following?(other_account)).to be false - end - end - - describe 'GET #relationships' do - let(:simon) { Fabricate(:user, email: 'simon@example.com', account: Fabricate(:account, username: 'simon')).account } - let(:lewis) { Fabricate(:user, email: 'lewis@example.com', account: Fabricate(:account, username: 'lewis')).account } - - before do - user.account.follow!(simon) - lewis.follow!(user.account) - end - - context 'provided only one ID' do - before do - get :relationships, params: { id: simon.id } - end - - it 'returns http success' do - expect(response).to have_http_status(:success) - end - - it 'returns JSON with correct data' do - json = body_as_json - - expect(json).to be_a Enumerable - expect(json.first[:following]).to be true - expect(json.first[:followed_by]).to be false - end - end - - context 'provided multiple IDs' do - before do - get :relationships, params: { id: [simon.id, lewis.id] } - end - - it 'returns http success' do - expect(response).to have_http_status(:success) - end - - xit 'returns JSON with correct data' do - # todo - end - end - end -end diff --git a/spec/controllers/api/apps_controller_spec.rb b/spec/controllers/api/apps_controller_spec.rb deleted file mode 100644 index ebadddde2..000000000 --- a/spec/controllers/api/apps_controller_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'rails_helper' - -RSpec.describe Api::AppsController, type: :controller do - render_views - - describe 'POST #create' do - before do - post :create, params: { name: 'Test app', redirect_uri: 'urn:ietf:wg:oauth:2.0:oob' } - end - - it 'returns http success' do - expect(response).to have_http_status(:success) - end - - it 'creates an OAuth app' do - expect(Doorkeeper::Application.find_by(name: 'Test app')).to_not be nil - end - - it 'returns client ID and client secret' do - json = body_as_json - - expect(json[:client_id]).to_not be_blank - expect(json[:client_secret]).to_not be_blank - end - end -end diff --git a/spec/controllers/api/follows_controller_spec.rb b/spec/controllers/api/follows_controller_spec.rb deleted file mode 100644 index f1775dfbc..000000000 --- a/spec/controllers/api/follows_controller_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'rails_helper' - -RSpec.describe Api::FollowsController, type: :controller do - render_views - - let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) } - let(:token) { double acceptable?: true, resource_owner_id: user.id } - - before do - allow(controller).to receive(:doorkeeper_token) { token } - end - - describe 'POST #create' do - before do - stub_request(:get, "https://quitter.no/.well-known/host-meta").to_return(request_fixture('.host-meta.txt')) - stub_request(:get, "https://quitter.no/.well-known/webfinger?resource=acct:gargron@quitter.no").to_return(request_fixture('webfinger.txt')) - stub_request(:get, "https://quitter.no/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt')) - stub_request(:get, "https://quitter.no/avatar/7477-300-20160211190340.png").to_return(request_fixture('avatar.txt')) - stub_request(:post, "https://quitter.no/main/push/hub").to_return(:status => 200, :body => "", :headers => {}) - stub_request(:post, "https://quitter.no/main/salmon/user/7477").to_return(:status => 200, :body => "", :headers => {}) - stub_request(:post, "https://pubsubhubbub.superfeedr.com/").to_return(:status => 200, :body => "", :headers => {}) - - post :create, params: { uri: 'gargron@quitter.no' } - end - - it 'returns http success' do - expect(response).to have_http_status(:success) - end - - it 'creates account for remote user' do - expect(Account.find_by(username: 'gargron', domain: 'quitter.no')).to_not be_nil - end - - it 'creates a follow relation between user and remote user' do - expect(user.account.following?(Account.find_by(username: 'gargron', domain: 'quitter.no'))).to be true - end - - it 'sends a salmon slap to the remote user' do - expect(a_request(:post, "https://quitter.no/main/salmon/user/7477")).to have_been_made - end - - it 'notifies own hub' do - expect(a_request(:post, "https://pubsubhubbub.superfeedr.com/")).to have_been_made - end - - it 'subscribes to remote hub' do - expect(a_request(:post, "https://quitter.no/main/push/hub")).to have_been_made - end - end -end diff --git a/spec/controllers/api/media_controller_spec.rb b/spec/controllers/api/media_controller_spec.rb deleted file mode 100644 index e6c44cc9f..000000000 --- a/spec/controllers/api/media_controller_spec.rb +++ /dev/null @@ -1,58 +0,0 @@ -require 'rails_helper' - -RSpec.describe Api::MediaController, type: :controller do - render_views - - let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) } - let(:token) { double acceptable?: true, resource_owner_id: user.id } - - before do - allow(controller).to receive(:doorkeeper_token) { token } - end - - describe 'POST #create' do - context 'image/jpeg' do - before do - post :create, params: { file: fixture_file_upload('files/attachment.jpg', 'image/jpeg') } - end - - it 'returns http success' do - expect(response).to have_http_status(:success) - end - - it 'creates a media attachment' do - expect(MediaAttachment.first).to_not be_nil - end - - it 'uploads a file' do - expect(MediaAttachment.first).to have_attached_file(:file) - end - - it 'returns media ID in JSON' do - expect(body_as_json[:id]).to eq MediaAttachment.first.id - end - end - - context 'video/webm' do - before do - post :create, params: { file: fixture_file_upload('files/attachment.webm', 'video/webm') } - end - - xit 'returns http success' do - expect(response).to have_http_status(:success) - end - - xit 'creates a media attachment' do - expect(MediaAttachment.first).to_not be_nil - end - - xit 'uploads a file' do - expect(MediaAttachment.first).to have_attached_file(:file) - end - - xit 'returns media ID in JSON' do - expect(body_as_json[:id]).to eq MediaAttachment.first.id - end - end - end -end diff --git a/spec/controllers/api/statuses_controller_spec.rb b/spec/controllers/api/statuses_controller_spec.rb deleted file mode 100644 index b1f0a7bcc..000000000 --- a/spec/controllers/api/statuses_controller_spec.rb +++ /dev/null @@ -1,173 +0,0 @@ -require 'rails_helper' - -RSpec.describe Api::StatusesController, type: :controller do - render_views - - let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) } - let(:token) { double acceptable?: true, resource_owner_id: user.id } - - before do - stub_request(:post, "https://pubsubhubbub.superfeedr.com/").to_return(:status => 200, :body => "", :headers => {}) - allow(controller).to receive(:doorkeeper_token) { token } - end - - describe 'GET #show' do - let(:status) { Fabricate(:status, account: user.account) } - - it 'returns http success' do - get :show, params: { id: status.id } - expect(response).to have_http_status(:success) - end - end - - describe 'GET #context' do - let(:status) { Fabricate(:status, account: user.account) } - - before do - Fabricate(:status, account: user.account, thread: status) - end - - it 'returns http success' do - get :context, params: { id: status.id } - expect(response).to have_http_status(:success) - end - end - - describe 'GET #home' do - it 'returns http success' do - get :home - expect(response).to have_http_status(:success) - end - end - - describe 'GET #mentions' do - it 'returns http success' do - get :mentions - expect(response).to have_http_status(:success) - end - end - - describe 'POST #create' do - before do - post :create, params: { status: 'Hello world' } - end - - it 'returns http success' do - expect(response).to have_http_status(:success) - end - end - - describe 'DELETE #destroy' do - let(:status) { Fabricate(:status, account: user.account) } - - before do - post :destroy, params: { id: status.id } - end - - it 'returns http success' do - expect(response).to have_http_status(:success) - end - - it 'removes the status' do - expect(Status.find_by(id: status.id)).to be nil - end - end - - describe 'POST #reblog' do - let(:status) { Fabricate(:status, account: user.account) } - - before do - post :reblog, params: { id: status.id } - end - - it 'returns http success' do - expect(response).to have_http_status(:success) - end - - it 'updates the reblogs count' do - expect(status.reblogs_count).to eq 1 - end - - it 'updates the reblogged attribute' do - expect(user.account.reblogged?(status)).to be true - end - - it 'return json with updated attributes' do - hash_body = body_as_json - - expect(hash_body[:reblog][:id]).to eq status.id - expect(hash_body[:reblog][:reblogs_count]).to eq 1 - expect(hash_body[:reblog][:reblogged]).to be true - end - end - - describe 'POST #unreblog' do - let(:status) { Fabricate(:status, account: user.account) } - - before do - post :reblog, params: { id: status.id } - post :unreblog, params: { id: status.id } - end - - it 'returns http success' do - expect(response).to have_http_status(:success) - end - - it 'updates the reblogs count' do - expect(status.reblogs_count).to eq 0 - end - - it 'updates the reblogged attribute' do - expect(user.account.reblogged?(status)).to be false - end - end - - describe 'POST #favourite' do - let(:status) { Fabricate(:status, account: user.account) } - - before do - post :favourite, params: { id: status.id } - end - - it 'returns http success' do - expect(response).to have_http_status(:success) - end - - it 'updates the favourites count' do - expect(status.favourites_count).to eq 1 - end - - it 'updates the favourited attribute' do - expect(user.account.favourited?(status)).to be true - end - - it 'return json with updated attributes' do - hash_body = body_as_json - - expect(hash_body[:id]).to eq status.id - expect(hash_body[:favourites_count]).to eq 1 - expect(hash_body[:favourited]).to be true - end - end - - describe 'POST #unfavourite' do - let(:status) { Fabricate(:status, account: user.account) } - - before do - post :favourite, params: { id: status.id } - post :unfavourite, params: { id: status.id } - end - - it 'returns http success' do - expect(response).to have_http_status(:success) - end - - it 'updates the favourites count' do - expect(status.favourites_count).to eq 0 - end - - it 'updates the favourited attribute' do - expect(user.account.favourited?(status)).to be false - end - end -end diff --git a/spec/controllers/api/v1/accounts_controller_spec.rb b/spec/controllers/api/v1/accounts_controller_spec.rb new file mode 100644 index 000000000..bc7c78c70 --- /dev/null +++ b/spec/controllers/api/v1/accounts_controller_spec.rb @@ -0,0 +1,116 @@ +require 'rails_helper' + +RSpec.describe Api::V1::AccountsController, type: :controller do + render_views + + let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) } + let(:token) { double acceptable?: true, resource_owner_id: user.id } + + before do + stub_request(:post, "https://pubsubhubbub.superfeedr.com/").to_return(:status => 200, :body => "", :headers => {}) + allow(controller).to receive(:doorkeeper_token) { token } + end + + describe 'GET #show' do + it 'returns http success' do + get :show, params: { id: user.account.id } + expect(response).to have_http_status(:success) + end + end + + describe 'GET #statuses' do + it 'returns http success' do + get :statuses, params: { id: user.account.id } + expect(response).to have_http_status(:success) + end + end + + describe 'GET #followers' do + it 'returns http success' do + get :followers, params: { id: user.account.id } + expect(response).to have_http_status(:success) + end + end + + describe 'GET #following' do + it 'returns http success' do + get :following, params: { id: user.account.id } + expect(response).to have_http_status(:success) + end + end + + describe 'POST #follow' do + let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account } + + before do + post :follow, params: { id: other_account.id } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'creates a following relation between user and target user' do + expect(user.account.following?(other_account)).to be true + end + end + + describe 'POST #unfollow' do + let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account } + + before do + user.account.follow!(other_account) + post :unfollow, params: { id: other_account.id } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'removes the following relation between user and target user' do + expect(user.account.following?(other_account)).to be false + end + end + + describe 'GET #relationships' do + let(:simon) { Fabricate(:user, email: 'simon@example.com', account: Fabricate(:account, username: 'simon')).account } + let(:lewis) { Fabricate(:user, email: 'lewis@example.com', account: Fabricate(:account, username: 'lewis')).account } + + before do + user.account.follow!(simon) + lewis.follow!(user.account) + end + + context 'provided only one ID' do + before do + get :relationships, params: { id: simon.id } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'returns JSON with correct data' do + json = body_as_json + + expect(json).to be_a Enumerable + expect(json.first[:following]).to be true + expect(json.first[:followed_by]).to be false + end + end + + context 'provided multiple IDs' do + before do + get :relationships, params: { id: [simon.id, lewis.id] } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + xit 'returns JSON with correct data' do + # todo + end + end + end +end diff --git a/spec/controllers/api/v1/apps_controller_spec.rb b/spec/controllers/api/v1/apps_controller_spec.rb new file mode 100644 index 000000000..20a0755ff --- /dev/null +++ b/spec/controllers/api/v1/apps_controller_spec.rb @@ -0,0 +1,26 @@ +require 'rails_helper' + +RSpec.describe Api::V1::AppsController, type: :controller do + render_views + + describe 'POST #create' do + before do + post :create, params: { name: 'Test app', redirect_uri: 'urn:ietf:wg:oauth:2.0:oob' } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'creates an OAuth app' do + expect(Doorkeeper::Application.find_by(name: 'Test app')).to_not be nil + end + + it 'returns client ID and client secret' do + json = body_as_json + + expect(json[:client_id]).to_not be_blank + expect(json[:client_secret]).to_not be_blank + end + end +end diff --git a/spec/controllers/api/v1/follows_controller_spec.rb b/spec/controllers/api/v1/follows_controller_spec.rb new file mode 100644 index 000000000..1346141fa --- /dev/null +++ b/spec/controllers/api/v1/follows_controller_spec.rb @@ -0,0 +1,50 @@ +require 'rails_helper' + +RSpec.describe Api::V1::FollowsController, type: :controller do + render_views + + let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) } + let(:token) { double acceptable?: true, resource_owner_id: user.id } + + before do + allow(controller).to receive(:doorkeeper_token) { token } + end + + describe 'POST #create' do + before do + stub_request(:get, "https://quitter.no/.well-known/host-meta").to_return(request_fixture('.host-meta.txt')) + stub_request(:get, "https://quitter.no/.well-known/webfinger?resource=acct:gargron@quitter.no").to_return(request_fixture('webfinger.txt')) + stub_request(:get, "https://quitter.no/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt')) + stub_request(:get, "https://quitter.no/avatar/7477-300-20160211190340.png").to_return(request_fixture('avatar.txt')) + stub_request(:post, "https://quitter.no/main/push/hub").to_return(:status => 200, :body => "", :headers => {}) + stub_request(:post, "https://quitter.no/main/salmon/user/7477").to_return(:status => 200, :body => "", :headers => {}) + stub_request(:post, "https://pubsubhubbub.superfeedr.com/").to_return(:status => 200, :body => "", :headers => {}) + + post :create, params: { uri: 'gargron@quitter.no' } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'creates account for remote user' do + expect(Account.find_by(username: 'gargron', domain: 'quitter.no')).to_not be_nil + end + + it 'creates a follow relation between user and remote user' do + expect(user.account.following?(Account.find_by(username: 'gargron', domain: 'quitter.no'))).to be true + end + + it 'sends a salmon slap to the remote user' do + expect(a_request(:post, "https://quitter.no/main/salmon/user/7477")).to have_been_made + end + + it 'notifies own hub' do + expect(a_request(:post, "https://pubsubhubbub.superfeedr.com/")).to have_been_made + end + + it 'subscribes to remote hub' do + expect(a_request(:post, "https://quitter.no/main/push/hub")).to have_been_made + end + end +end diff --git a/spec/controllers/api/v1/media_controller_spec.rb b/spec/controllers/api/v1/media_controller_spec.rb new file mode 100644 index 000000000..1b91354d4 --- /dev/null +++ b/spec/controllers/api/v1/media_controller_spec.rb @@ -0,0 +1,58 @@ +require 'rails_helper' + +RSpec.describe Api::V1::MediaController, type: :controller do + render_views + + let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) } + let(:token) { double acceptable?: true, resource_owner_id: user.id } + + before do + allow(controller).to receive(:doorkeeper_token) { token } + end + + describe 'POST #create' do + context 'image/jpeg' do + before do + post :create, params: { file: fixture_file_upload('files/attachment.jpg', 'image/jpeg') } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'creates a media attachment' do + expect(MediaAttachment.first).to_not be_nil + end + + it 'uploads a file' do + expect(MediaAttachment.first).to have_attached_file(:file) + end + + it 'returns media ID in JSON' do + expect(body_as_json[:id]).to eq MediaAttachment.first.id + end + end + + context 'video/webm' do + before do + post :create, params: { file: fixture_file_upload('files/attachment.webm', 'video/webm') } + end + + xit 'returns http success' do + expect(response).to have_http_status(:success) + end + + xit 'creates a media attachment' do + expect(MediaAttachment.first).to_not be_nil + end + + xit 'uploads a file' do + expect(MediaAttachment.first).to have_attached_file(:file) + end + + xit 'returns media ID in JSON' do + expect(body_as_json[:id]).to eq MediaAttachment.first.id + end + end + end +end diff --git a/spec/controllers/api/v1/statuses_controller_spec.rb b/spec/controllers/api/v1/statuses_controller_spec.rb new file mode 100644 index 000000000..7af54299a --- /dev/null +++ b/spec/controllers/api/v1/statuses_controller_spec.rb @@ -0,0 +1,173 @@ +require 'rails_helper' + +RSpec.describe Api::V1::StatusesController, type: :controller do + render_views + + let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) } + let(:token) { double acceptable?: true, resource_owner_id: user.id } + + before do + stub_request(:post, "https://pubsubhubbub.superfeedr.com/").to_return(:status => 200, :body => "", :headers => {}) + allow(controller).to receive(:doorkeeper_token) { token } + end + + describe 'GET #show' do + let(:status) { Fabricate(:status, account: user.account) } + + it 'returns http success' do + get :show, params: { id: status.id } + expect(response).to have_http_status(:success) + end + end + + describe 'GET #context' do + let(:status) { Fabricate(:status, account: user.account) } + + before do + Fabricate(:status, account: user.account, thread: status) + end + + it 'returns http success' do + get :context, params: { id: status.id } + expect(response).to have_http_status(:success) + end + end + + describe 'GET #home' do + it 'returns http success' do + get :home + expect(response).to have_http_status(:success) + end + end + + describe 'GET #mentions' do + it 'returns http success' do + get :mentions + expect(response).to have_http_status(:success) + end + end + + describe 'POST #create' do + before do + post :create, params: { status: 'Hello world' } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + end + + describe 'DELETE #destroy' do + let(:status) { Fabricate(:status, account: user.account) } + + before do + post :destroy, params: { id: status.id } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'removes the status' do + expect(Status.find_by(id: status.id)).to be nil + end + end + + describe 'POST #reblog' do + let(:status) { Fabricate(:status, account: user.account) } + + before do + post :reblog, params: { id: status.id } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'updates the reblogs count' do + expect(status.reblogs_count).to eq 1 + end + + it 'updates the reblogged attribute' do + expect(user.account.reblogged?(status)).to be true + end + + it 'return json with updated attributes' do + hash_body = body_as_json + + expect(hash_body[:reblog][:id]).to eq status.id + expect(hash_body[:reblog][:reblogs_count]).to eq 1 + expect(hash_body[:reblog][:reblogged]).to be true + end + end + + describe 'POST #unreblog' do + let(:status) { Fabricate(:status, account: user.account) } + + before do + post :reblog, params: { id: status.id } + post :unreblog, params: { id: status.id } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'updates the reblogs count' do + expect(status.reblogs_count).to eq 0 + end + + it 'updates the reblogged attribute' do + expect(user.account.reblogged?(status)).to be false + end + end + + describe 'POST #favourite' do + let(:status) { Fabricate(:status, account: user.account) } + + before do + post :favourite, params: { id: status.id } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'updates the favourites count' do + expect(status.favourites_count).to eq 1 + end + + it 'updates the favourited attribute' do + expect(user.account.favourited?(status)).to be true + end + + it 'return json with updated attributes' do + hash_body = body_as_json + + expect(hash_body[:id]).to eq status.id + expect(hash_body[:favourites_count]).to eq 1 + expect(hash_body[:favourited]).to be true + end + end + + describe 'POST #unfavourite' do + let(:status) { Fabricate(:status, account: user.account) } + + before do + post :favourite, params: { id: status.id } + post :unfavourite, params: { id: status.id } + end + + it 'returns http success' do + expect(response).to have_http_status(:success) + end + + it 'updates the favourites count' do + expect(status.favourites_count).to eq 0 + end + + it 'updates the favourited attribute' do + expect(user.account.favourited?(status)).to be false + end + end +end diff --git a/spec/helpers/api/accounts_helper_spec.rb b/spec/helpers/api/accounts_helper_spec.rb deleted file mode 100644 index 8880aaef4..000000000 --- a/spec/helpers/api/accounts_helper_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Api::AccountsHelper, type: :helper do - -end diff --git a/spec/helpers/api/apps_helper_spec.rb b/spec/helpers/api/apps_helper_spec.rb deleted file mode 100644 index e26bca2cc..000000000 --- a/spec/helpers/api/apps_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the Api::AppsHelper. For example: -# -# describe Api::AppsHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe Api::AppsHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/helpers/api/follows_helper_spec.rb b/spec/helpers/api/follows_helper_spec.rb deleted file mode 100644 index ecd9acc7a..000000000 --- a/spec/helpers/api/follows_helper_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Api::FollowsHelper, type: :helper do - -end diff --git a/spec/helpers/api/media_helper_spec.rb b/spec/helpers/api/media_helper_spec.rb deleted file mode 100644 index 5eb2def2a..000000000 --- a/spec/helpers/api/media_helper_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Api::MediaHelper, type: :helper do - -end diff --git a/spec/helpers/api/salmon_helper_spec.rb b/spec/helpers/api/salmon_helper_spec.rb deleted file mode 100644 index 23f1584df..000000000 --- a/spec/helpers/api/salmon_helper_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Api::SalmonHelper, type: :helper do - -end diff --git a/spec/helpers/api/statuses_helper_spec.rb b/spec/helpers/api/statuses_helper_spec.rb deleted file mode 100644 index c1793fda5..000000000 --- a/spec/helpers/api/statuses_helper_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Api::StatusesHelper, type: :helper do - -end diff --git a/spec/helpers/api/subscriptions_helper_spec.rb b/spec/helpers/api/subscriptions_helper_spec.rb deleted file mode 100644 index 9e6457c6f..000000000 --- a/spec/helpers/api/subscriptions_helper_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Api::SubscriptionsHelper, type: :helper do - -end -- cgit