diff options
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/api/web/embeds_controller_spec.rb | 52 | ||||
-rw-r--r-- | spec/controllers/settings/migrations_controller_spec.rb | 79 | ||||
-rw-r--r-- | spec/controllers/settings/sessions_controller_spec.rb | 30 |
3 files changed, 161 insertions, 0 deletions
diff --git a/spec/controllers/api/web/embeds_controller_spec.rb b/spec/controllers/api/web/embeds_controller_spec.rb new file mode 100644 index 000000000..6b7297189 --- /dev/null +++ b/spec/controllers/api/web/embeds_controller_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Api::Web::EmbedsController do + render_views + + let(:user) { Fabricate(:user) } + before { sign_in user } + + describe 'POST #create' do + subject(:response) { post :create, params: { url: url } } + subject(:body) { JSON.parse(response.body, symbolize_names: true) } + + context 'when successfully finds status' do + let(:status) { Fabricate(:status) } + let(:url) { "http://#{ Rails.configuration.x.web_domain }/@#{status.account.username}/#{status.id}" } + + it 'returns a right response' do + expect(response).to have_http_status :ok + expect(body[:author_name]).to eq status.account.username + end + end + + context 'when fails to find status' do + let(:url) { 'https://host.test/oembed.html' } + let(:service_instance) { double('fetch_oembed_service') } + + before do + allow(FetchOEmbedService).to receive(:new) { service_instance } + allow(service_instance).to receive(:call) { call_result } + end + + context 'when successfully fetching oembed' do + let(:call_result) { { result: :ok } } + + it 'returns a right response' do + expect(response).to have_http_status :ok + expect(body[:result]).to eq 'ok' + end + end + + context 'when fails to fetch oembed' do + let(:call_result) { nil } + + it 'returns a right response' do + expect(response).to have_http_status :not_found + end + end + end + end +end diff --git a/spec/controllers/settings/migrations_controller_spec.rb b/spec/controllers/settings/migrations_controller_spec.rb new file mode 100644 index 000000000..a621bcf1c --- /dev/null +++ b/spec/controllers/settings/migrations_controller_spec.rb @@ -0,0 +1,79 @@ +require 'rails_helper' + +describe Settings::MigrationsController do + render_views + + shared_examples 'authenticate user' do + it 'redirects to sign_in page' do + is_expected.to redirect_to new_user_session_path + end + end + + describe 'GET #show' do + + context 'when user is not sign in' do + subject { get :show } + + it_behaves_like 'authenticate user' + end + + context 'when user is sign in' do + subject { get :show } + + let(:user) { Fabricate(:user, account: account) } + let(:account) { Fabricate(:account, moved_to_account: moved_to_account) } + before { sign_in user, scope: :user } + + context 'when user does not have moved to account' do + let(:moved_to_account) { nil } + + it 'renders show page' do + is_expected.to have_http_status 200 + is_expected.to render_template :show + end + end + + context 'when user does not have moved to account' do + let(:moved_to_account) { Fabricate(:account) } + + it 'renders show page' do + is_expected.to have_http_status 200 + is_expected.to render_template :show + end + end + end + end + + describe 'PUT #update' do + + context 'when user is not sign in' do + subject { put :update } + + it_behaves_like 'authenticate user' + end + + context 'when user is sign in' do + subject { put :update, params: { migration: { acct: acct } } } + + let(:user) { Fabricate(:user) } + before { sign_in user, scope: :user } + + context 'when migration account is changed' do + let(:acct) { Fabricate(:account) } + + it 'updates moved to account' do + is_expected.to redirect_to settings_migration_path + expect(user.account.reload.moved_to_account_id).to eq acct.id + end + end + + context 'when acct is a current account' do + let(:acct) { user.account } + + it 'renders show' do + is_expected.to render_template :show + end + end + end + end +end diff --git a/spec/controllers/settings/sessions_controller_spec.rb b/spec/controllers/settings/sessions_controller_spec.rb new file mode 100644 index 000000000..52b204a6a --- /dev/null +++ b/spec/controllers/settings/sessions_controller_spec.rb @@ -0,0 +1,30 @@ +require 'rails_helper' + +describe Settings::SessionsController do + render_views + + let(:user) { Fabricate(:user) } + let(:session_activation) { Fabricate(:session_activation, user: user) } + before { sign_in user, scope: :user } + + describe 'DELETE #destroy' do + subject { delete :destroy, params: { id: id } } + + context 'when session activation exists' do + let(:id) { session_activation.id } + + it 'destroys session activation' do + is_expected.to redirect_to edit_user_registration_path + expect(SessionActivation.find_by(id: id)).to be_nil + end + end + + context 'when session activation does not exist' do + let(:id) { session_activation.id + 1000 } + + it 'destroys session activation' do + is_expected.to have_http_status :not_found + end + end + end +end |