]> cat aescling's git repositories - mastodon.git/commitdiff
Fix Admin::TagsController#unhide (#9481)
authorysksn <bluewhale1982@gmail.com>
Mon, 10 Dec 2018 20:37:38 +0000 (05:37 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Mon, 10 Dec 2018 20:37:38 +0000 (21:37 +0100)
app/controllers/admin/tags_controller.rb
spec/controllers/admin/tags_controller_spec.rb [new file with mode: 0644]

index 3f22565664153c950c70427551d83b9a97bac990..e9f4f2cfa3b35a67101d0957ee6a22f1f66f41fc 100644 (file)
@@ -18,7 +18,7 @@ module Admin
 
     def unhide
       authorize @tag, :unhide?
-      @tag.account_tag_stat.update!(hidden: true)
+      @tag.account_tag_stat.update!(hidden: false)
       redirect_to admin_tags_path(@filter_params)
     end
 
diff --git a/spec/controllers/admin/tags_controller_spec.rb b/spec/controllers/admin/tags_controller_spec.rb
new file mode 100644 (file)
index 0000000..3af9940
--- /dev/null
@@ -0,0 +1,71 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe Admin::TagsController, type: :controller do
+  render_views
+
+  before do
+    sign_in Fabricate(:user, admin: true)
+  end
+
+  describe 'GET #index' do
+    before do
+      account_tag_stat = Fabricate(:tag).account_tag_stat
+      account_tag_stat.update(hidden: hidden, accounts_count: 1)
+      get :index, params: { hidden: hidden }
+    end
+
+    context 'with hidden tags' do
+      let(:hidden) { true }
+
+      it 'returns status 200' do
+        expect(response).to have_http_status(200)
+      end
+    end
+
+    context 'without hidden tags' do
+      let(:hidden) { false }
+
+      it 'returns status 200' do
+        expect(response).to have_http_status(200)
+      end
+    end
+  end
+
+  describe 'POST #hide' do
+    let(:tag) { Fabricate(:tag) }
+
+    before do
+      tag.account_tag_stat.update(hidden: false)
+      post :hide, params: { id: tag.id }
+    end
+
+    it 'hides tag' do
+      tag.reload
+      expect(tag).to be_hidden
+    end
+
+    it 'redirects to admin_tags_path' do
+      expect(response).to redirect_to(admin_tags_path(controller.instance_variable_get(:@filter_params)))
+    end
+  end
+
+  describe 'POST #unhide' do
+    let(:tag) { Fabricate(:tag) }
+
+    before do
+      tag.account_tag_stat.update(hidden: true)
+      post :unhide, params: { id: tag.id }
+    end
+
+    it 'unhides tag' do
+      tag.reload
+      expect(tag).not_to be_hidden
+    end
+
+    it 'redirects to admin_tags_path' do
+      expect(response).to redirect_to(admin_tags_path(controller.instance_variable_get(:@filter_params)))
+    end
+  end
+end