2008-04-19 14:06:57 -04:00
|
|
|
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
|
2009-10-04 00:31:38 -04:00
|
|
|
with_test_route_set do
|
|
|
|
assert_equal "/people", homepage_path
|
|
|
|
end
|
2008-04-19 14:06:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_homepage_url
|
2009-10-04 00:31:38 -04:00
|
|
|
with_test_route_set do
|
|
|
|
assert_equal "http://test.host/people", homepage_url
|
|
|
|
end
|
2008-04-19 14:06:57 -04:00
|
|
|
end
|
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_link_to_person
|
2009-10-04 00:31:38 -04:00
|
|
|
with_test_route_set do
|
|
|
|
person = mock(:name => "David")
|
|
|
|
person.class.extend ActiveModel::Naming
|
2011-06-06 08:13:06 -04:00
|
|
|
expects(:mocha_mock_path).with(person).returns("/people/1")
|
2009-10-04 00:31:38 -04:00
|
|
|
assert_equal '<a href="/people/1">David</a>', link_to_person(person)
|
|
|
|
end
|
2008-04-19 14:06:57 -04:00
|
|
|
end
|
2009-10-04 00:31:38 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
def with_test_route_set
|
|
|
|
with_routing do |set|
|
2010-08-05 09:44:23 -04:00
|
|
|
set.draw do
|
2012-04-24 23:32:09 -04:00
|
|
|
get 'people', :to => 'people#index', :as => :people
|
2009-10-04 00:31:38 -04:00
|
|
|
end
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
end
|
2008-04-19 14:06:57 -04:00
|
|
|
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
|
2011-10-03 04:05:25 -04:00
|
|
|
|
|
|
|
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
|
2012-09-24 17:37:45 -04:00
|
|
|
|
|
|
|
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
|