File: controller_method_test.rb

package info (click to toggle)
ruby-responders 3.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 348 kB
  • sloc: ruby: 1,648; makefile: 6
file content (74 lines) | stat: -rw-r--r-- 1,351 bytes parent folder | download | duplicates (2)
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
# frozen_string_literal: true

require "test_helper"

ActionController::Base.extend Responders::ControllerMethod

module FooResponder
  def to_html
    @resource << "foo"
    super
  end
end

module BarResponder
  def to_html
    @resource << "bar"
    super
  end
end

module PeopleResponder
  def to_html
    @resource << "baz"
    super
  end
end

class PeopleController < ApplicationController
  responders :foo, BarResponder

  def index
    @array = []
    respond_with(@array) do |format|
      format.html { render body: "Success!" }
    end
  end
end

class SpecialPeopleController < PeopleController
  responders :people
end

class ControllerMethodTest < ActionController::TestCase
  tests PeopleController

  def setup
    @controller.stubs(:polymorphic_url).returns("/")
  end

  def test_foo_responder_gets_added
    get :index
    assert assigns(:array).include? "foo"
  end

  def test_bar_responder_gets_added
    get :index
    assert assigns(:array).include? "bar"
  end
end

class ControllerMethodInheritanceTest < ActionController::TestCase
  tests SpecialPeopleController

  def setup
    @controller.stubs(:polymorphic_url).returns("/")
  end

  def test_responder_is_inherited
    get :index
    assert assigns(:array).include? "foo"
    assert assigns(:array).include? "bar"
    assert assigns(:array).include? "baz"
  end
end