File: injector_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 (38 lines) | stat: -rw-r--r-- 1,104 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
# frozen_string_literal: true

require "test_helper"

module WebConsole
  class InjectorTest < ActiveSupport::TestCase
    test "closes body if closable" do
      closed = false

      body = [ "foo" ]
      body.define_singleton_method(:close) { closed = true }

      assert_equal [ [ "foobar" ], {} ], Injector.new(body, {}).inject("bar")
      assert closed
    end

    test "support fancy bodies like Rack::BodyProxy" do
      closed = false
      body = Rack::BodyProxy.new([ "foo" ]) { closed = true }

      assert_equal [ [ "foobar" ], {} ], Injector.new(body, {}).inject("bar")
      assert closed
    end

    test "support fancy bodies like ActionDispatch::Response::RackBody" do
      body = ActionDispatch::Response.create(200, {}, [ "foo" ]).to_a.last

      assert_equal [ [ "foobar" ], {} ], Injector.new(body, {}).inject("bar")
    end

    test "updates the content-length header" do
      body = [ "foo" ]
      headers = { Rack::CONTENT_LENGTH => 3 }

      assert_equal [ [ "foobar" ], { Rack::CONTENT_LENGTH => "6" } ], Injector.new(body, headers).inject("bar")
    end
  end
end