about summary refs log tree commit diff
path: root/spec/controllers/admin/tags_controller_spec.rb
blob: 3af994071ce724cb09b66fd26f4d601cd1c39679 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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