summaryrefslogtreecommitdiff
path: root/test/controllers/topics/locks_controller_test.rb
blob: 233b65d33f2f66e1ed6ff690159fb009bef93706 (plain)
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
# frozen_string_literal: true

require 'test_helper'

class Topics::LocksControllerTest < ActionController::TestCase
  setup do
    @user = create(:moderator)
    @topic = create(:topic)
    @forum = @topic.forum
  end

  test 'can be locked and unlocked' do
    sign_in @user

    post :create, params: { topic_id: @topic, forum_id: @forum, lock_reason: 'Because I feel like it' }

    @topic.reload
    assert_response :redirect
    assert_redirected_to forum_topic_path(@forum, @topic)
    assert_not_nil @topic.locked_at
    assert_equal @user, @topic.locked_by
    assert_equal 'Because I feel like it', @topic.lock_reason

    delete :destroy, params: { topic_id: @topic, forum_id: @forum }

    @topic.reload
    assert_response :redirect
    assert_redirected_to forum_topic_path(@forum, @topic)
    assert_nil @topic.locked_at
  end
end