about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorDavid Yip <yipdw@member.fsf.org>2018-06-03 03:01:09 -0500
committerGitHub <noreply@github.com>2018-06-03 03:01:09 -0500
commit5dd2a78034c4ab8d7eac6f4553185eadc48b6c26 (patch)
tree24f23aa2e14a8e64aa39559ba76a6a938ce42d24 /spec
parentcfdbb36bdf06de01b6701e667cc986fd701efe3c (diff)
parent8343f56b2c1d23f1c2c2c42515bae1d9a4119ff6 (diff)
Merge pull request #528 from glitch-soc/merge-upstream
Merge with tootsuite/master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/settings/migrations_controller_spec.rb79
1 files changed, 79 insertions, 0 deletions
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