aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test/template/test_test.rb
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2013-04-17 00:06:11 +0200
committerŁukasz Strzałkowski <lukasz.strzalkowski@gmail.com>2013-06-20 17:23:16 +0200
commiteb23754ebbfbf2d465cc0f900720704fb3703633 (patch)
tree5bd1764233b59075341611b1e857d418c794d812 /actionview/test/template/test_test.rb
parent5bcdf4faa6da7acb762dab680372f8520a0533c2 (diff)
downloadrails-eb23754ebbfbf2d465cc0f900720704fb3703633.tar.gz
rails-eb23754ebbfbf2d465cc0f900720704fb3703633.tar.bz2
rails-eb23754ebbfbf2d465cc0f900720704fb3703633.zip
Move template tests from actionpack to actionview
Diffstat (limited to 'actionview/test/template/test_test.rb')
-rw-r--r--actionview/test/template/test_test.rb80
1 files changed, 80 insertions, 0 deletions
diff --git a/actionview/test/template/test_test.rb b/actionview/test/template/test_test.rb
new file mode 100644
index 0000000000..108a674d95
--- /dev/null
+++ b/actionview/test/template/test_test.rb
@@ -0,0 +1,80 @@
+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