aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/test_test.rb
blob: e843a1deb45391ddf9f0d48cdd0571889489766c (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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
require 'abstract_unit'

module PeopleHelper
  def title(text)
    content_tag(:h1, text)
  end

  def homepage_path
    people_path
  end

  def homepage_url
    people_url
  end

  def link_to_person(person)
    link_to person.name, person
  end
end

class PeopleHelperTest < ActionView::TestCase
  def test_title
    assert_equal "<h1>Ruby on Rails</h1>", title("Ruby on Rails")
  end

  def test_homepage_path
    with_test_route_set do
      assert_equal "/people", homepage_path
    end
  end

  def test_homepage_url
    with_test_route_set do
      assert_equal "http://test.host/people", homepage_url
    end
  end

  def test_link_to_person
    with_test_route_set do
      person = mock(:name => "David")
      person.class.extend ActiveModel::Naming
      expects(:mocha_mock_path).with(person).returns("/people/1")
      assert_equal '<a href="/people/1">David</a>', link_to_person(person)
    end
  end

  private
    def with_test_route_set
      with_routing do |set|
        set.draw do
          get 'people', :to => 'people#index', :as => :people
        end
        yield
      end
    end
end

class CrazyHelperTest < ActionView::TestCase
  tests PeopleHelper

  def test_helper_class_can_be_set_manually_not_just_inferred
    assert_equal PeopleHelper, self.class.helper_class
  end
end

class CrazySymbolHelperTest < ActionView::TestCase
  tests :people

  def test_set_helper_class_using_symbol
    assert_equal PeopleHelper, self.class.helper_class
  end
end

class CrazyStringHelperTest < ActionView::TestCase
  tests 'people'

  def test_set_helper_class_using_string
    assert_equal PeopleHelper, self.class.helper_class
  end
end

describe PeopleHelper do
  it "resolves the right helper_class" do
    assert_equal PeopleHelper, self.class.helper_class
  end
end

describe PeopleHelper, :helper_class do
  it "resolves the right helper_class" do
    assert_equal PeopleHelper, self.class.helper_class
  end
end

describe PeopleHelper do
  describe "even while nested" do
    it "resolves the right helper_class" do
      assert_equal PeopleHelper, self.class.helper_class
    end
  end
end

describe PeopleHelper, :helper_class do
  describe "even while nested" do
    it "resolves the right helper_class" do
      assert_equal PeopleHelper, self.class.helper_class
    end
  end
end

describe "PeopleHelper" do
  it "resolves the right helper_class" do
    assert_equal PeopleHelper, self.class.helper_class
  end
end

describe "PeopleHelperTest" do
  it "resolves the right helper_class" do
    assert_equal PeopleHelper, self.class.helper_class
  end
end

describe "PeopleHelper" do
  describe "even while nested" do
    it "resolves the right helper_class" do
      assert_equal PeopleHelper, self.class.helper_class
    end
  end
end

describe "PeopleHelperTest" do
  describe "even while nested" do
    it "resolves the right helper_class" do
      assert_equal PeopleHelper, self.class.helper_class
    end
  end
end