aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/activerecord/polymorphic_routes_test.rb64
-rw-r--r--actionpack/test/dispatch/prefix_generation_test.rb256
-rw-r--r--actionpack/test/dispatch/routing_test.rb29
-rw-r--r--actionpack/test/dispatch/static_test.rb61
-rw-r--r--actionpack/test/dispatch/url_generation_test.rb3
-rw-r--r--actionpack/test/fixtures/blog_public/.gitignore1
-rw-r--r--actionpack/test/fixtures/blog_public/blog.html1
-rw-r--r--actionpack/test/fixtures/blog_public/index.html1
-rw-r--r--actionpack/test/fixtures/blog_public/subdir/index.html1
-rw-r--r--actionpack/test/lib/controller/fake_models.rb17
-rw-r--r--actionpack/test/template/asset_tag_helper_test.rb23
-rw-r--r--actionpack/test/template/form_helper_test.rb107
-rw-r--r--actionpack/test/template/test_test.rb2
13 files changed, 502 insertions, 64 deletions
diff --git a/actionpack/test/activerecord/polymorphic_routes_test.rb b/actionpack/test/activerecord/polymorphic_routes_test.rb
index 90a1ef982c..448aaa5eee 100644
--- a/actionpack/test/activerecord/polymorphic_routes_test.rb
+++ b/actionpack/test/activerecord/polymorphic_routes_test.rb
@@ -25,6 +25,22 @@ class Series < ActiveRecord::Base
set_table_name 'projects'
end
+module Blog
+ class Post < ActiveRecord::Base
+ set_table_name 'projects'
+ end
+
+ class Blog < ActiveRecord::Base
+ set_table_name 'projects'
+ end
+
+ def self._railtie
+ o = Object.new
+ def o.railtie_name; "blog" end
+ o
+ end
+end
+
class PolymorphicRoutesTest < ActionController::TestCase
include SharedTestRoutes.url_helpers
self.default_url_options[:host] = 'example.com'
@@ -37,6 +53,38 @@ class PolymorphicRoutesTest < ActionController::TestCase
@tax = Tax.new
@fax = Fax.new
@series = Series.new
+ @blog_post = Blog::Post.new
+ @blog_blog = Blog::Blog.new
+ end
+
+ def test_passing_routes_proxy
+ with_namespaced_routes(:blog) do
+ proxy = ActionDispatch::Routing::RoutesProxy.new(_routes, self)
+ @blog_post.save
+ assert_equal "http://example.com/posts/#{@blog_post.id}", polymorphic_url([proxy, @blog_post])
+ end
+ end
+
+ def test_namespaced_model
+ with_namespaced_routes(:blog) do
+ @blog_post.save
+ assert_equal "http://example.com/posts/#{@blog_post.id}", polymorphic_url(@blog_post)
+ end
+ end
+
+ def test_namespaced_model_with_name_the_same_as_namespace
+ with_namespaced_routes(:blog) do
+ @blog_blog.save
+ assert_equal "http://example.com/blogs/#{@blog_blog.id}", polymorphic_url(@blog_blog)
+ end
+ end
+
+ def test_namespaced_model_with_nested_resources
+ with_namespaced_routes(:blog) do
+ @blog_post.save
+ @blog_blog.save
+ assert_equal "http://example.com/blogs/#{@blog_blog.id}/posts/#{@blog_post.id}", polymorphic_url([@blog_blog, @blog_post])
+ end
end
def test_with_record
@@ -385,6 +433,22 @@ class PolymorphicRoutesTest < ActionController::TestCase
end
end
+ def with_namespaced_routes(name)
+ with_routing do |set|
+ set.draw do
+ scope(:module => name) do
+ resources :blogs do
+ resources :posts
+ end
+ resources :posts
+ end
+ end
+
+ self.class.send(:include, @routes.url_helpers)
+ yield
+ end
+ end
+
def with_test_routes(options = {})
with_routing do |set|
set.draw do |map|
diff --git a/actionpack/test/dispatch/prefix_generation_test.rb b/actionpack/test/dispatch/prefix_generation_test.rb
new file mode 100644
index 0000000000..3b47a1b72d
--- /dev/null
+++ b/actionpack/test/dispatch/prefix_generation_test.rb
@@ -0,0 +1,256 @@
+require 'abstract_unit'
+
+module TestGenerationPrefix
+ class WithMountedEngine < ActionDispatch::IntegrationTest
+ require 'rack/test'
+ include Rack::Test::Methods
+
+ class BlogEngine
+ def self.routes
+ @routes ||= begin
+ routes = ActionDispatch::Routing::RouteSet.new
+ routes.draw do
+ match "/posts/:id", :to => "inside_engine_generating#show", :as => :post
+ match "/posts", :to => "inside_engine_generating#index", :as => :posts
+ match "/url_to_application", :to => "inside_engine_generating#url_to_application"
+ match "/polymorphic_path_for_engine", :to => "inside_engine_generating#polymorphic_path_for_engine"
+ match "/conflicting_url", :to => "inside_engine_generating#conflicting"
+ end
+
+ routes
+ end
+ end
+
+ def self.call(env)
+ env['action_dispatch.routes'] = routes
+ routes.call(env)
+ end
+ end
+
+ class RailsApplication
+ def self.routes
+ @routes ||= begin
+ routes = ActionDispatch::Routing::RouteSet.new
+ routes.draw do
+ scope "/:omg", :omg => "awesome" do
+ mount BlogEngine => "/blog", :as => "blog_engine"
+ end
+ match "/generate", :to => "outside_engine_generating#index"
+ match "/polymorphic_path_for_engine", :to => "outside_engine_generating#polymorphic_path_for_engine"
+ match "/polymorphic_with_url_for", :to => "outside_engine_generating#polymorphic_with_url_for"
+ match "/conflicting_url", :to => "outside_engine_generating#conflicting"
+ root :to => "outside_engine_generating#index"
+ end
+
+ routes
+ end
+ end
+
+ def self.call(env)
+ env['action_dispatch.routes'] = routes
+ routes.call(env)
+ end
+ end
+
+ # force draw
+ RailsApplication.routes
+
+ class Post
+ extend ActiveModel::Naming
+
+ def to_param
+ "1"
+ end
+
+ def self.model_name
+ klass = "Post"
+ def klass.name; self end
+
+ ActiveModel::Name.new(klass)
+ end
+ end
+
+ class ::InsideEngineGeneratingController < ActionController::Base
+ include BlogEngine.routes.url_helpers
+ include RailsApplication.routes.mounted_helpers(:app)
+
+ def index
+ render :text => posts_path
+ end
+
+ def show
+ render :text => post_path(:id => params[:id])
+ end
+
+ def url_to_application
+ path = app.url_for( :controller => "outside_engine_generating",
+ :action => "index",
+ :only_path => true)
+ render :text => path
+ end
+
+ def polymorphic_path_for_engine
+ render :text => polymorphic_path(Post.new)
+ end
+
+ def conflicting
+ render :text => "engine"
+ end
+ end
+
+ class ::OutsideEngineGeneratingController < ActionController::Base
+ include BlogEngine.routes.mounted_helpers
+
+ def index
+ render :text => blog_engine.post_path(:id => 1)
+ end
+
+ def polymorphic_path_for_engine
+ render :text => blog_engine.polymorphic_path(Post.new)
+ end
+
+ def polymorphic_with_url_for
+ render :text => blog_engine.url_for(Post.new)
+ end
+
+ def conflicting
+ render :text => "application"
+ end
+ end
+
+ class EngineObject
+ include ActionDispatch::Routing::UrlFor
+ include BlogEngine.routes.url_helpers
+ end
+
+ class AppObject
+ include ActionDispatch::Routing::UrlFor
+ include RailsApplication.routes.url_helpers
+ end
+
+ def app
+ RailsApplication
+ end
+
+ def engine_object
+ @engine_object ||= EngineObject.new
+ end
+
+ def app_object
+ @app_object ||= AppObject.new
+ end
+
+ def setup
+ RailsApplication.routes.default_url_options = {}
+ end
+
+ # Inside Engine
+ test "[ENGINE] generating engine's url use SCRIPT_NAME from request" do
+ get "/pure-awesomeness/blog/posts/1"
+ assert_equal "/pure-awesomeness/blog/posts/1", last_response.body
+ end
+
+ test "[ENGINE] generating application's url never uses SCRIPT_NAME from request" do
+ get "/pure-awesomeness/blog/url_to_application"
+ assert_equal "/generate", last_response.body
+ end
+
+ test "[ENGINE] generating application's url includes default_url_options[:script_name]" do
+ RailsApplication.routes.default_url_options = {:script_name => "/something"}
+ get "/pure-awesomeness/blog/url_to_application"
+ assert_equal "/something/generate", last_response.body
+ end
+
+ test "[ENGINE] generating application's url should give higher priority to default_url_options[:script_name]" do
+ RailsApplication.routes.default_url_options = {:script_name => "/something"}
+ get "/pure-awesomeness/blog/url_to_application", {}, 'SCRIPT_NAME' => '/foo'
+ assert_equal "/something/generate", last_response.body
+ end
+
+ test "[ENGINE] generating engine's url with polymorphic path" do
+ get "/pure-awesomeness/blog/polymorphic_path_for_engine"
+ assert_equal "/pure-awesomeness/blog/posts/1", last_response.body
+ end
+
+ test "[ENGINE] url_helpers from engine have higher priotity than application's url_helpers" do
+ get "/awesome/blog/conflicting_url"
+ assert_equal "engine", last_response.body
+ end
+
+ # Inside Application
+ test "[APP] generating engine's route includes prefix" do
+ get "/generate"
+ assert_equal "/awesome/blog/posts/1", last_response.body
+ end
+
+ test "[APP] generating engine's route includes default_url_options[:script_name]" do
+ RailsApplication.routes.default_url_options = {:script_name => "/something"}
+ get "/generate"
+ assert_equal "/something/awesome/blog/posts/1", last_response.body
+ end
+
+ test "[APP] generating engine's route should give higher priority to default_url_options[:script_name]" do
+ RailsApplication.routes.default_url_options = {:script_name => "/something"}
+ get "/generate", {}, 'SCRIPT_NAME' => "/foo"
+ assert_equal "/something/awesome/blog/posts/1", last_response.body
+ end
+
+ test "[APP] generating engine's url with polymorphic path" do
+ get "/polymorphic_path_for_engine"
+ assert_equal "/awesome/blog/posts/1", last_response.body
+ end
+
+ test "[APP] generating engine's url with url_for(@post)" do
+ get "/polymorphic_with_url_for"
+ assert_equal "http://example.org/awesome/blog/posts/1", last_response.body
+ end
+
+ # Inside any Object
+ test "[OBJECT] generating engine's route includes prefix" do
+ assert_equal "/awesome/blog/posts/1", engine_object.post_path(:id => 1)
+ end
+
+ test "[OBJECT] generating engine's route includes dynamic prefix" do
+ assert_equal "/pure-awesomeness/blog/posts/3", engine_object.post_path(:id => 3, :omg => "pure-awesomeness")
+ end
+
+ test "[OBJECT] generating engine's route includes default_url_options[:script_name]" do
+ RailsApplication.routes.default_url_options = {:script_name => "/something"}
+ assert_equal "/something/pure-awesomeness/blog/posts/3", engine_object.post_path(:id => 3, :omg => "pure-awesomeness")
+ end
+
+ test "[OBJECT] generating application's route" do
+ assert_equal "/", app_object.root_path
+ end
+
+ test "[OBJECT] generating application's route includes default_url_options[:script_name]" do
+ RailsApplication.routes.default_url_options = {:script_name => "/something"}
+ assert_equal "/something/", app_object.root_path
+ end
+
+ test "[OBJECT] generating engine's route with url_for" do
+ path = engine_object.url_for(:controller => "inside_engine_generating",
+ :action => "show",
+ :only_path => true,
+ :omg => "omg",
+ :id => 1)
+ assert_equal "/omg/blog/posts/1", path
+ end
+
+ test "[OBJECT] generating engine's route with named helpers" do
+ path = engine_object.posts_path
+ assert_equal "/awesome/blog/posts", path
+
+ path = engine_object.posts_url(:host => "example.com")
+ assert_equal "http://example.com/awesome/blog/posts", path
+ end
+
+ test "[OBJECT] generating engine's route with polymorphic_url" do
+ path = engine_object.polymorphic_path(Post.new)
+ assert_equal "/awesome/blog/posts/1", path
+
+ path = engine_object.polymorphic_url(Post.new, :host => "www.example.com")
+ assert_equal "http://www.example.com/awesome/blog/posts/1", path
+ end
+ end
+end
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index c90c1041ed..b642adc06b 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -2151,3 +2151,32 @@ private
%(<html><body>You are being <a href="#{ERB::Util.h(url)}">redirected</a>.</body></html>)
end
end
+
+
+class TestDefaultScope < ActionController::IntegrationTest
+ module ::Blog
+ class PostsController < ActionController::Base
+ def index
+ render :text => "blog/posts#index"
+ end
+ end
+ end
+
+ DefaultScopeRoutes = ActionDispatch::Routing::RouteSet.new
+ DefaultScopeRoutes.default_scope = {:module => :blog}
+ DefaultScopeRoutes.draw do
+ resources :posts
+ end
+
+ def app
+ DefaultScopeRoutes
+ end
+
+ include DefaultScopeRoutes.url_helpers
+
+ def test_default_scope
+ get '/posts'
+ assert_equal "blog/posts#index", @response.body
+ end
+end
+
diff --git a/actionpack/test/dispatch/static_test.rb b/actionpack/test/dispatch/static_test.rb
index e6957bb0ea..2eb82fc5d8 100644
--- a/actionpack/test/dispatch/static_test.rb
+++ b/actionpack/test/dispatch/static_test.rb
@@ -1,28 +1,23 @@
require 'abstract_unit'
-class StaticTest < ActiveSupport::TestCase
- DummyApp = lambda { |env|
- [200, {"Content-Type" => "text/plain"}, ["Hello, World!"]]
- }
- App = ActionDispatch::Static.new(DummyApp, "#{FIXTURE_LOAD_PATH}/public")
-
- test "serves dynamic content" do
+module StaticTests
+ def test_serves_dynamic_content
assert_equal "Hello, World!", get("/nofile")
end
- test "serves static index at root" do
+ def test_serves_static_index_at_root
assert_equal "/index.html", get("/index.html")
assert_equal "/index.html", get("/index")
assert_equal "/index.html", get("/")
end
- test "serves static file in directory" do
+ def test_serves_static_file_in_directory
assert_equal "/foo/bar.html", get("/foo/bar.html")
assert_equal "/foo/bar.html", get("/foo/bar/")
assert_equal "/foo/bar.html", get("/foo/bar")
end
- test "serves static index file in directory" do
+ def test_serves_static_index_file_in_directory
assert_equal "/foo/index.html", get("/foo/index.html")
assert_equal "/foo/index.html", get("/foo/")
assert_equal "/foo/index.html", get("/foo")
@@ -30,6 +25,50 @@ class StaticTest < ActiveSupport::TestCase
private
def get(path)
- Rack::MockRequest.new(App).request("GET", path).body
+ Rack::MockRequest.new(@app).request("GET", path).body
end
end
+
+class StaticTest < ActiveSupport::TestCase
+ DummyApp = lambda { |env|
+ [200, {"Content-Type" => "text/plain"}, ["Hello, World!"]]
+ }
+ App = ActionDispatch::Static.new(DummyApp, "#{FIXTURE_LOAD_PATH}/public")
+
+ def setup
+ @app = App
+ end
+
+ include StaticTests
+end
+
+class MultipleDirectorisStaticTest < ActiveSupport::TestCase
+ DummyApp = lambda { |env|
+ [200, {"Content-Type" => "text/plain"}, ["Hello, World!"]]
+ }
+ App = ActionDispatch::Static.new(DummyApp,
+ { "/" => "#{FIXTURE_LOAD_PATH}/public",
+ "/blog" => "#{FIXTURE_LOAD_PATH}/blog_public",
+ "/foo" => "#{FIXTURE_LOAD_PATH}/non_existing_dir"
+ })
+
+ def setup
+ @app = App
+ end
+
+ include StaticTests
+
+ test "serves files from other mounted directories" do
+ assert_equal "/blog/index.html", get("/blog/index.html")
+ assert_equal "/blog/index.html", get("/blog/index")
+ assert_equal "/blog/index.html", get("/blog/")
+
+ assert_equal "/blog/blog.html", get("/blog/blog/")
+ assert_equal "/blog/blog.html", get("/blog/blog.html")
+ assert_equal "/blog/blog.html", get("/blog/blog")
+
+ assert_equal "/blog/subdir/index.html", get("/blog/subdir/index.html")
+ assert_equal "/blog/subdir/index.html", get("/blog/subdir/")
+ assert_equal "/blog/subdir/index.html", get("/blog/subdir")
+ end
+end
diff --git a/actionpack/test/dispatch/url_generation_test.rb b/actionpack/test/dispatch/url_generation_test.rb
index f83651d583..2b54bc62b0 100644
--- a/actionpack/test/dispatch/url_generation_test.rb
+++ b/actionpack/test/dispatch/url_generation_test.rb
@@ -31,7 +31,7 @@ module TestUrlGeneration
end
test "the request's SCRIPT_NAME takes precedence over the routes'" do
- get "/foo", {}, 'SCRIPT_NAME' => "/new"
+ get "/foo", {}, 'SCRIPT_NAME' => "/new", 'action_dispatch.routes' => Routes
assert_equal "/new/foo", response.body
end
@@ -41,3 +41,4 @@ module TestUrlGeneration
end
end
end
+
diff --git a/actionpack/test/fixtures/blog_public/.gitignore b/actionpack/test/fixtures/blog_public/.gitignore
new file mode 100644
index 0000000000..312e635ee6
--- /dev/null
+++ b/actionpack/test/fixtures/blog_public/.gitignore
@@ -0,0 +1 @@
+absolute/*
diff --git a/actionpack/test/fixtures/blog_public/blog.html b/actionpack/test/fixtures/blog_public/blog.html
new file mode 100644
index 0000000000..79ad44c010
--- /dev/null
+++ b/actionpack/test/fixtures/blog_public/blog.html
@@ -0,0 +1 @@
+/blog/blog.html \ No newline at end of file
diff --git a/actionpack/test/fixtures/blog_public/index.html b/actionpack/test/fixtures/blog_public/index.html
new file mode 100644
index 0000000000..2de3825481
--- /dev/null
+++ b/actionpack/test/fixtures/blog_public/index.html
@@ -0,0 +1 @@
+/blog/index.html \ No newline at end of file
diff --git a/actionpack/test/fixtures/blog_public/subdir/index.html b/actionpack/test/fixtures/blog_public/subdir/index.html
new file mode 100644
index 0000000000..517bded335
--- /dev/null
+++ b/actionpack/test/fixtures/blog_public/subdir/index.html
@@ -0,0 +1 @@
+/blog/subdir/index.html \ No newline at end of file
diff --git a/actionpack/test/lib/controller/fake_models.rb b/actionpack/test/lib/controller/fake_models.rb
index bf3e175f1f..c4127ee699 100644
--- a/actionpack/test/lib/controller/fake_models.rb
+++ b/actionpack/test/lib/controller/fake_models.rb
@@ -83,7 +83,7 @@ class Comment
def to_key; id ? [id] : nil end
def save; @id = 1; @post_id = 1 end
def persisted?; @id.present? end
- def to_param; @id; end
+ def to_param; @id.to_s; end
def name
@id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}"
end
@@ -149,3 +149,18 @@ class Author < Comment
attr_accessor :post
def post_attributes=(attributes); end
end
+
+module Blog
+ def self._railtie
+ self
+ end
+
+ class Post < Struct.new(:title, :id)
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
+
+ def persisted?
+ id.present?
+ end
+ end
+end
diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb
index 6d5e4893c4..2b83cfe1a9 100644
--- a/actionpack/test/template/asset_tag_helper_test.rb
+++ b/actionpack/test/template/asset_tag_helper_test.rb
@@ -387,6 +387,15 @@ class AssetTagHelperTest < ActionView::TestCase
assert_equal %(<img alt="Rails" src="#{expected_path}" />), image_tag("rails.png")
end
+ def test_env_asset_path
+ @controller.config.asset_path = "/assets%s"
+ def @controller.env; @_env ||= {} end
+ @controller.env["action_dispatch.asset_path"] = "/omg%s"
+
+ expected_path = "/assets/omg/images/rails.png"
+ assert_equal %(<img alt="Rails" src="#{expected_path}" />), image_tag("rails.png")
+ end
+
def test_proc_asset_id
@controller.config.asset_path = Proc.new do |asset_path|
"/assets.v12345#{asset_path}"
@@ -396,6 +405,20 @@ class AssetTagHelperTest < ActionView::TestCase
assert_equal %(<img alt="Rails" src="#{expected_path}" />), image_tag("rails.png")
end
+ def test_env_proc_asset_path
+ @controller.config.asset_path = Proc.new do |asset_path|
+ "/assets.v12345#{asset_path}"
+ end
+
+ def @controller.env; @_env ||= {} end
+ @controller.env["action_dispatch.asset_path"] = Proc.new do |asset_path|
+ "/omg#{asset_path}"
+ end
+
+ expected_path = "/assets.v12345/omg/images/rails.png"
+ assert_equal %(<img alt="Rails" src="#{expected_path}" />), image_tag("rails.png")
+ end
+
def test_image_tag_interpreting_email_cid_correctly
# An inline image has no need for an alt tag to be automatically generated from the cid:
assert_equal '<img src="cid:thi%25%25sis@acontentid" />', image_tag("cid:thi%25%25sis@acontentid")
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 9a1fe01872..97a08d45ba 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -75,15 +75,39 @@ class FormHelperTest < ActionView::TestCase
@post.body = "Back to the hill and over it again!"
@post.secret = 1
@post.written_on = Date.new(2004, 6, 15)
+
+ @blog_post = Blog::Post.new("And his name will be forty and four.", 44)
end
+ Routes = ActionDispatch::Routing::RouteSet.new
+ Routes.draw do
+ resources :posts do
+ resources :comments
+ end
+
+ namespace :admin do
+ resources :posts do
+ resources :comments
+ end
+ end
+
+ match "/foo", :to => "controller#action"
+ root :to => "main#index"
+ end
+
+ def _routes
+ Routes
+ end
+
+ include Routes.url_helpers
+
def url_for(object)
@url_for_options = object
- if object.is_a?(Hash)
- "http://www.example.com"
- else
- super
+ if object.is_a?(Hash) && object[:use_route].blank? && object[:controller].blank?
+ object.merge!(:controller => "main", :action => "index")
end
+ object
+ super
end
def test_label
@@ -628,7 +652,7 @@ class FormHelperTest < ActionView::TestCase
end
expected =
- "<form accept-charset='UTF-8' action='http://www.example.com' id='create-post' method='post'>" +
+ "<form accept-charset='UTF-8' action='/' id='create-post' method='post'>" +
snowman +
"<label for='post_title'>The Title</label>" +
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
@@ -653,6 +677,21 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
+ def test_form_for_with_isolated_namespaced_model
+ form_for(@blog_post) do |f|
+ concat f.text_field :title
+ concat f.submit('Edit post')
+ end
+
+ expected =
+ "<form accept-charset='UTF-8' action='/posts/44' method='post'>" +
+ snowman +
+ "<label for='post_title'>The Title</label>" +
+ "<input name='post[title]' size='30' type='text' id='post_title' value='And his name will be forty and four.' />" +
+ "<input name='commit' id='post_submit' type='submit' value='Edit post' />" +
+ "</form>"
+ end
+
def test_form_for_with_symbol_object_name
form_for(@post, :as => "other_name", :html => { :id => 'create-post' }) do |f|
concat f.label(:title, :class => 'post_title')
@@ -683,7 +722,7 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = whole_form("http://www.example.com", "create-post", nil, "put") do
+ expected = whole_form("/", "create-post", nil, "put") do
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
@@ -702,7 +741,7 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = whole_form("http://www.example.com", "create-post", nil, :method => "put", :remote => true) do
+ expected = whole_form("/", "create-post", nil, :method => "put", :remote => true) do
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
@@ -721,7 +760,7 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected = whole_form("http://www.example.com", nil, nil, :remote => true) do
+ expected = whole_form("/", nil, nil, :remote => true) do
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
@@ -738,7 +777,7 @@ class FormHelperTest < ActionView::TestCase
concat f.check_box(:secret)
end
- expected = whole_form("http://www.example.com", "create-post") do
+ expected = whole_form("/", "create-post") do
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
@@ -1478,7 +1517,7 @@ class FormHelperTest < ActionView::TestCase
end
expected =
- "<form accept-charset='UTF-8' action='http://www.example.com' id='create-post' method='post'>" +
+ "<form accept-charset='UTF-8' action='/' id='create-post' method='post'>" +
snowman +
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
@@ -1502,7 +1541,7 @@ class FormHelperTest < ActionView::TestCase
end
expected =
- whole_form("http://www.example.com", "create-post") do
+ whole_form("/", "create-post") do
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[comment][name]' type='text' id='post_comment_name' value='new comment' size='30' />"
@@ -1546,7 +1585,7 @@ class FormHelperTest < ActionView::TestCase
txt << %{</div>}
end
- def form_text(action = "http://www.example.com", id = nil, html_class = nil, remote = nil)
+ def form_text(action = "/", id = nil, html_class = nil, remote = nil)
txt = %{<form accept-charset="UTF-8" action="#{action}"}
txt << %{ data-remote="true"} if remote
txt << %{ class="#{html_class}"} if html_class
@@ -1554,7 +1593,7 @@ class FormHelperTest < ActionView::TestCase
txt << %{ method="post">}
end
- def whole_form(action = "http://www.example.com", id = nil, html_class = nil, options = nil)
+ def whole_form(action = "/", id = nil, html_class = nil, options = nil)
contents = block_given? ? yield : ""
if options.is_a?(Hash)
@@ -1655,7 +1694,7 @@ class FormHelperTest < ActionView::TestCase
assert_deprecated do
form_for(:post, @post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end
end
- expected = whole_form("http://www.example.com", "some_form", "some_class")
+ expected = whole_form("/", "some_form", "some_class")
assert_dom_equal expected, output_buffer
end
@@ -1710,14 +1749,14 @@ class FormHelperTest < ActionView::TestCase
@comment.save
form_for([@post, @comment]) {}
- expected = whole_form(comment_path(@post, @comment), "edit_comment_1", "edit_comment", "put")
+ expected = whole_form(post_comment_path(@post, @comment), "edit_comment_1", "edit_comment", "put")
assert_dom_equal expected, output_buffer
end
def test_form_for_with_new_object_in_list
form_for([@post, @comment]) {}
- expected = whole_form(comments_path(@post), "new_comment", "new_comment")
+ expected = whole_form(post_comments_path(@post), "new_comment", "new_comment")
assert_dom_equal expected, output_buffer
end
@@ -1725,14 +1764,14 @@ class FormHelperTest < ActionView::TestCase
@comment.save
form_for([:admin, @post, @comment]) {}
- expected = whole_form(admin_comment_path(@post, @comment), "edit_comment_1", "edit_comment", "put")
+ expected = whole_form(admin_post_comment_path(@post, @comment), "edit_comment_1", "edit_comment", "put")
assert_dom_equal expected, output_buffer
end
def test_form_for_with_new_object_and_namespace_in_list
form_for([:admin, @post, @comment]) {}
- expected = whole_form(admin_comments_path(@post), "new_comment", "new_comment")
+ expected = whole_form(admin_post_comments_path(@post), "new_comment", "new_comment")
assert_dom_equal expected, output_buffer
end
@@ -1749,38 +1788,6 @@ class FormHelperTest < ActionView::TestCase
end
protected
- def comments_path(post)
- "/posts/#{post.id}/comments"
- end
- alias_method :post_comments_path, :comments_path
-
- def comment_path(post, comment)
- "/posts/#{post.id}/comments/#{comment.id}"
- end
- alias_method :post_comment_path, :comment_path
-
- def admin_comments_path(post)
- "/admin/posts/#{post.id}/comments"
- end
- alias_method :admin_post_comments_path, :admin_comments_path
-
- def admin_comment_path(post, comment)
- "/admin/posts/#{post.id}/comments/#{comment.id}"
- end
- alias_method :admin_post_comment_path, :admin_comment_path
-
- def posts_path
- "/posts"
- end
-
- def post_path(post, options = {})
- if options[:format]
- "/posts/#{post.id}.#{options[:format]}"
- else
- "/posts/#{post.id}"
- end
- end
-
def protect_against_forgery?
false
end
diff --git a/actionpack/test/template/test_test.rb b/actionpack/test/template/test_test.rb
index 68e790cf46..20c96824d6 100644
--- a/actionpack/test/template/test_test.rb
+++ b/actionpack/test/template/test_test.rb
@@ -39,7 +39,7 @@ class PeopleHelperTest < ActionView::TestCase
with_test_route_set do
person = mock(:name => "David")
person.class.extend ActiveModel::Naming
- expects(:mocha_mock_path).with(person).returns("/people/1")
+ _routes.url_helpers.expects(:hash_for_mocha_mock_path).with(person).returns("/people/1")
assert_equal '<a href="/people/1">David</a>', link_to_person(person)
end
end