about summary refs log tree commit diff
path: root/spec/controllers/concerns
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-05-30 13:06:01 -0400
committerEugen Rochko <eugen@zeonfederated.com>2017-05-30 19:06:01 +0200
commit0ebe7d6d236d47bf805a920dc722897bafec7459 (patch)
treee3f08f8d34ef2ea58978e528f53518f864c04c71 /spec/controllers/concerns
parent23081bb2994b34108fb06e15d3101849a3077cf9 (diff)
Remove exports/base controller in favor of shared concern (#3444)
Diffstat (limited to 'spec/controllers/concerns')
-rw-r--r--spec/controllers/concerns/export_controller_concern_spec.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/controllers/concerns/export_controller_concern_spec.rb b/spec/controllers/concerns/export_controller_concern_spec.rb
new file mode 100644
index 000000000..9d6f782b9
--- /dev/null
+++ b/spec/controllers/concerns/export_controller_concern_spec.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe ApplicationController, type: :controller do
+  controller do
+    include ExportControllerConcern
+    def index
+      send_export_file
+    end
+    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="anonymous.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