File: helper_test.rb

package info (click to toggle)
ruby-web-console 4.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 632 kB
  • sloc: ruby: 1,496; javascript: 497; sh: 19; makefile: 4
file content (91 lines) | stat: -rw-r--r-- 1,930 bytes parent folder | download
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# frozen_string_literal: true

require "test_helper"

module WebConsole
  class HelperTest < ActionDispatch::IntegrationTest
    class BaseApplication
      def call(env)
        [ status, headers, body ]
      end

      private

        def request
          Request.new(@env)
        end

        def status
          500
        end

        def headers
          { Rack::CONTENT_TYPE => "text/html; charset=utf-8" }
        end

        def body
          Array(<<-HTML.strip_heredoc)
            <html>
              <head>
                <title>Hello world</title>
              </head>
              <body>
                <p id="hello-world">Hello world</p>
              </body>
            </html>
          HTML
        end
    end

    class SingleConsoleApplication < BaseApplication
      def call(env)
        @env = env

        console

        super
      end
    end

    class MultipleConsolesApplication < BaseApplication
      def call(env)
        @env = env

        console
        console

        super
      end
    end

    setup do
      Thread.current[:__web_console_exception] = nil
      Thread.current[:__web_console_binding] = nil

      Request.stubs(:permissions).returns(IPAddr.new("0.0.0.0/0"))

      @app = Middleware.new(SingleConsoleApplication.new)
    end

    test "renders a console into a view" do
      get "/", params: nil, headers: { "CONTENT_TYPE" => "text/html" }

      assert_select "#console"
    end

    test "raises an error when trying to spawn a console more than once" do
      @app = Middleware.new(MultipleConsolesApplication.new)

      assert_raises(DoubleRenderError) do
        get "/", params: nil, headers: { "CONTENT_TYPE" => "text/html" }
      end
    end

    test "doesn't hijack current view" do
      get "/", params: nil, headers: { "CONTENT_TYPE" => "text/html" }

      assert_select "#hello-world"
      assert_select "#console"
    end
  end
end