aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/abstract_unit.rb2
-rw-r--r--actionpack/test/controller/action_pack_assertions_test.rb66
-rw-r--r--actionpack/test/controller/layout_test.rb2
-rw-r--r--actionpack/test/lib/fixture_template.rb29
-rw-r--r--actionpack/test/template/form_helper_test.rb6
-rw-r--r--actionpack/test/template/testing/fixture_resolver_test.rb18
-rw-r--r--actionpack/test/template/testing/null_resolver_test.rb12
7 files changed, 80 insertions, 55 deletions
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index f3ff258016..89ba0990f1 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -16,8 +16,8 @@ require 'test/unit'
require 'abstract_controller'
require 'action_controller'
require 'action_view'
+require 'action_view/testing/resolvers'
require 'action_dispatch'
-require 'fixture_template'
require 'active_support/dependencies'
require 'active_model'
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb
index 1741b58f72..765e111226 100644
--- a/actionpack/test/controller/action_pack_assertions_test.rb
+++ b/actionpack/test/controller/action_pack_assertions_test.rb
@@ -344,25 +344,6 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
end
end
- def test_assert_template_with_partial
- get :partial
- assert_template :partial => '_partial'
- end
-
- def test_assert_template_with_nil
- get :nothing
- assert_template nil
- end
-
- def test_assert_template_with_string
- get :hello_world
- assert_template 'hello_world'
- end
-
- def test_assert_template_with_symbol
- get :hello_world
- assert_template :hello_world
- end
# check if we were rendered by a file-based template?
def test_rendered_action
@@ -387,7 +368,6 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
assert_nil @response.redirect_url
end
-
# check server errors
def test_server_error_response_code
process :response500
@@ -538,6 +518,52 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
end
end
+class AssertTemplateTest < ActionController::TestCase
+ tests ActionPackAssertionsController
+
+ def test_with_partial
+ get :partial
+ assert_template :partial => '_partial'
+ end
+
+ def test_with_nil_passes_when_no_template_rendered
+ get :nothing
+ assert_template nil
+ end
+
+ def test_with_nil_fails_when_template_rendered
+ get :hello_world
+ assert_raise(ActiveSupport::TestCase::Assertion) do
+ assert_template nil
+ end
+ end
+
+ def test_passes_with_correct_string
+ get :hello_world
+ assert_template 'hello_world'
+ assert_template 'test/hello_world'
+ end
+
+ def test_passes_with_correct_symbol
+ get :hello_world
+ assert_template :hello_world
+ end
+
+ def test_fails_with_incorrect_string
+ get :hello_world
+ assert_raise(ActiveSupport::TestCase::Assertion) do
+ assert_template 'hello_planet'
+ end
+ end
+
+ def test_fails_with_incorrect_symbol
+ get :hello_world
+ assert_raise(ActiveSupport::TestCase::Assertion) do
+ assert_template :hello_planet
+ end
+ end
+end
+
class ActionPackHeaderTest < ActionController::TestCase
tests ActionPackAssertionsController
diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb
index 48be7571ea..165c61ffad 100644
--- a/actionpack/test/controller/layout_test.rb
+++ b/actionpack/test/controller/layout_test.rb
@@ -10,8 +10,6 @@ ActionView::Template::register_template_handler :mab,
ActionController::Base.view_paths = [ File.dirname(__FILE__) + '/../fixtures/layout_tests/' ]
-require "fixture_template"
-
class LayoutTest < ActionController::Base
def self.controller_path; 'views' end
def self._implied_layout_name; to_s.underscore.gsub(/_controller$/, '') ; end
diff --git a/actionpack/test/lib/fixture_template.rb b/actionpack/test/lib/fixture_template.rb
deleted file mode 100644
index b49ccd39ca..0000000000
--- a/actionpack/test/lib/fixture_template.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-module ActionView #:nodoc:
- class FixtureResolver < PathResolver
- attr_reader :hash
-
- def initialize(hash = {})
- super()
- @hash = hash
- end
-
- private
-
- def query(path, exts, formats)
- query = Regexp.escape(path)
- exts.each do |ext|
- query << '(' << ext.map {|e| e && Regexp.escape(".#{e}") }.join('|') << '|)'
- end
-
- templates = []
- @hash.select { |k,v| k =~ /^#{query}$/ }.each do |path, source|
- handler, format = extract_handler_and_format(path, formats)
- templates << Template.new(source, path, handler,
- :virtual_path => path, :format => format)
- end
-
- templates.sort_by {|t| -t.identifier.match(/^#{query}$/).captures.reject(&:blank?).size }
- end
-
- end
-end \ No newline at end of file
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 47ac911540..2234fbece9 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -33,11 +33,11 @@ class FormHelperTest < ActionView::TestCase
I18n.backend.store_translations 'submit', {
:helpers => {
:submit => {
- :create => 'Create {{model}}',
- :update => 'Confirm {{model}} changes',
+ :create => 'Create %{model}',
+ :update => 'Confirm %{model} changes',
:submit => 'Save changes',
:another_post => {
- :update => 'Update your {{model}}'
+ :update => 'Update your %{model}'
}
}
}
diff --git a/actionpack/test/template/testing/fixture_resolver_test.rb b/actionpack/test/template/testing/fixture_resolver_test.rb
new file mode 100644
index 0000000000..de83540468
--- /dev/null
+++ b/actionpack/test/template/testing/fixture_resolver_test.rb
@@ -0,0 +1,18 @@
+require 'abstract_unit'
+
+class FixtureResolverTest < ActiveSupport::TestCase
+ def test_should_return_empty_list_for_unknown_path
+ resolver = ActionView::FixtureResolver.new()
+ templates = resolver.find_all("path", "arbitrary", false, {:locale => [], :formats => [:html], :handlers => []})
+ assert_equal [], templates, "expected an empty list of templates"
+ end
+
+ def test_should_return_template_for_declared_path
+ resolver = ActionView::FixtureResolver.new("arbitrary/path" => "this text")
+ templates = resolver.find_all("path", "arbitrary", false, {:locale => [], :formats => [:html], :handlers => []})
+ assert_equal 1, templates.size, "expected one template"
+ assert_equal "this text", templates.first.source
+ assert_equal "arbitrary/path", templates.first.virtual_path
+ assert_equal [:html], templates.first.formats
+ end
+end
diff --git a/actionpack/test/template/testing/null_resolver_test.rb b/actionpack/test/template/testing/null_resolver_test.rb
new file mode 100644
index 0000000000..e142506e6a
--- /dev/null
+++ b/actionpack/test/template/testing/null_resolver_test.rb
@@ -0,0 +1,12 @@
+require 'abstract_unit'
+
+class NullResolverTest < ActiveSupport::TestCase
+ def test_should_return_template_for_any_path
+ resolver = ActionView::NullResolver.new()
+ templates = resolver.find_all("path", "arbitrary", false, {:locale => [], :formats => [:html], :handlers => []})
+ assert_equal 1, templates.size, "expected one template"
+ assert_equal "Template generated by Null Resolver", templates.first.source
+ assert_equal "arbitrary/path", templates.first.virtual_path
+ assert_equal [:html], templates.first.formats
+ end
+end