about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorAkihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>2017-05-30 01:05:01 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-05-29 18:05:01 +0200
commitc347327d54571f3e3e5ac2a01e6ad9e164e1d802 (patch)
tree656cd15051f80214152d9cd9a8cdf60aed7044ee /spec
parentfd328cf6e8fac0af2b3ec7f755a734f0fe2385c7 (diff)
Spec Settings::Exports (#3384)
* Spec output of Settings::Exports::BlockedAccountsController

* Spec output of Settings::Exports::FollowingAccountsController

* Spec output of Settings::Exports::MutedAccountsController

* Spec Settings::Exports::BaseController

This commit removes duplicate specs in classes inheriting
Settings::Exports::BaseController as well.
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/settings/exports/base_controller_spec.rb29
-rw-r--r--spec/controllers/settings/exports/blocked_accounts_controller_spec.rb12
-rw-r--r--spec/controllers/settings/exports/following_accounts_controller_spec.rb12
-rw-r--r--spec/controllers/settings/exports/muted_accounts_controller_spec.rb12
4 files changed, 44 insertions, 21 deletions
diff --git a/spec/controllers/settings/exports/base_controller_spec.rb b/spec/controllers/settings/exports/base_controller_spec.rb
new file mode 100644
index 000000000..c924d449a
--- /dev/null
+++ b/spec/controllers/settings/exports/base_controller_spec.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe Settings::Exports::BaseController do
+  controller do
+    def export_data
+      @export.account.username
+    end
+  end
+
+  describe 'GET #index' do
+    it 'returns a csv of the exported data when signed in' do
+      user = Fabricate(:user)
+      sign_in user
+      get :index, format: :csv
+
+      expect(response).to have_http_status(:success)
+      expect(response.content_type).to eq 'text/csv'
+      expect(response.headers['Content-Disposition']).to eq 'attachment; filename="base.csv"'
+      expect(response.body).to eq user.account.username
+    end
+
+    it 'returns unauthorized when not signed in' do
+      get :index, format: :csv
+      expect(response).to have_http_status(:unauthorized)
+    end
+  end
+end
diff --git a/spec/controllers/settings/exports/blocked_accounts_controller_spec.rb b/spec/controllers/settings/exports/blocked_accounts_controller_spec.rb
index e79a6729a..5ff41b7fc 100644
--- a/spec/controllers/settings/exports/blocked_accounts_controller_spec.rb
+++ b/spec/controllers/settings/exports/blocked_accounts_controller_spec.rb
@@ -3,17 +3,15 @@ require 'rails_helper'
 describe Settings::Exports::BlockedAccountsController do
   render_views
 
-  before do
-    sign_in Fabricate(:user), scope: :user
-  end
-
   describe 'GET #index' do
     it 'returns a csv of the blocking accounts' do
+      user = Fabricate(:user)
+      user.account.block!(Fabricate(:account, username: 'username', domain: 'domain'))
+
+      sign_in user, scope: :user
       get :index, format: :csv
 
-      expect(response).to have_http_status(:success)
-      expect(response.content_type).to eq 'text/csv'
-      expect(response.headers['Content-Disposition']).to eq 'attachment; filename="blocked_accounts.csv"'
+      expect(response.body).to eq "username@domain\n"
     end
   end
 end
diff --git a/spec/controllers/settings/exports/following_accounts_controller_spec.rb b/spec/controllers/settings/exports/following_accounts_controller_spec.rb
index 503455fea..786769d24 100644
--- a/spec/controllers/settings/exports/following_accounts_controller_spec.rb
+++ b/spec/controllers/settings/exports/following_accounts_controller_spec.rb
@@ -3,17 +3,15 @@ require 'rails_helper'
 describe Settings::Exports::FollowingAccountsController do
   render_views
 
-  before do
-    sign_in Fabricate(:user), scope: :user
-  end
-
   describe 'GET #index' do
     it 'returns a csv of the following accounts' do
+      user = Fabricate(:user)
+      user.account.follow!(Fabricate(:account, username: 'username', domain: 'domain'))
+
+      sign_in user, scope: :user
       get :index, format: :csv
 
-      expect(response).to have_http_status(:success)
-      expect(response.content_type).to eq 'text/csv'
-      expect(response.headers['Content-Disposition']).to eq 'attachment; filename="following_accounts.csv"'
+      expect(response.body).to eq "username@domain\n"
     end
   end
 end
diff --git a/spec/controllers/settings/exports/muted_accounts_controller_spec.rb b/spec/controllers/settings/exports/muted_accounts_controller_spec.rb
index 37c3a0fcf..f42d7881e 100644
--- a/spec/controllers/settings/exports/muted_accounts_controller_spec.rb
+++ b/spec/controllers/settings/exports/muted_accounts_controller_spec.rb
@@ -3,17 +3,15 @@ require 'rails_helper'
 describe Settings::Exports::MutedAccountsController do
   render_views
 
-  before do
-    sign_in Fabricate(:user), scope: :user
-  end
-
   describe 'GET #index' do
     it 'returns a csv of the muting accounts' do
+      user = Fabricate(:user)
+      user.account.mute!(Fabricate(:account, username: 'username', domain: 'domain'))
+
+      sign_in user, scope: :user
       get :index, format: :csv
 
-      expect(response).to have_http_status(:success)
-      expect(response.content_type).to eq 'text/csv'
-      expect(response.headers['Content-Disposition']).to eq 'attachment; filename="muted_accounts.csv"'
+      expect(response.body).to eq "username@domain\n"
     end
   end
 end