aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/assertions/response_assertions_test.rb
blob: ca1d58765d7b5b4a593609363e829ea07b6af148 (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
require 'abstract_unit'
require 'action_dispatch/testing/assertions/response'

module ActionDispatch
  module Assertions
    class ResponseAssertionsTest < ActiveSupport::TestCase
      include ResponseAssertions

      FakeResponse = Struct.new(:response_code) do
        [:success, :missing, :redirect, :error].each do |sym|
          define_method("#{sym}?") do
            sym == response_code
          end
        end
      end

      def test_assert_response_predicate_methods
        [:success, :missing, :redirect, :error].each do |sym|
          @response = FakeResponse.new sym
          assert_response sym

          assert_raises(MiniTest::Assertion) {
            assert_response :unauthorized
          }
        end
      end

      def test_assert_response_fixnum
        @response = FakeResponse.new 400
        assert_response 400

        assert_raises(MiniTest::Assertion) {
          assert_response :unauthorized
        }

        assert_raises(MiniTest::Assertion) {
          assert_response 500
        }
      end

      def test_assert_response_sym_status
        @response = FakeResponse.new 401
        assert_response :unauthorized

        assert_raises(MiniTest::Assertion) {
          assert_response :ok
        }

        assert_raises(MiniTest::Assertion) {
          assert_response :success
        }
      end
    end
  end
end