Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:lifo/docrails
Browse files Browse the repository at this point in the history
  • Loading branch information
FooBarWidget committed Aug 8, 2008
2 parents 62d8a1c + d2553c3 commit 920ad94
Show file tree
Hide file tree
Showing 270 changed files with 9,700 additions and 3,625 deletions.
Empty file modified actionmailer/README
100755 → 100644
Empty file.
Empty file modified actionmailer/Rakefile
100755 → 100644
Empty file.
Empty file modified actionmailer/lib/action_mailer.rb
100755 → 100644
Empty file.
21 changes: 16 additions & 5 deletions actionmailer/lib/action_mailer/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class Base

private_class_method :new #:nodoc:

class_inheritable_accessor :template_root
class_inheritable_accessor :view_paths
cattr_accessor :logger

cattr_accessor :template_extensions
Expand Down Expand Up @@ -425,8 +425,12 @@ def register_template_extension(extension)
template_extensions << extension
end

def template_root
self.view_paths && self.view_paths.first
end

def template_root=(root)
write_inheritable_attribute(:template_root, ActionView::PathSet.new(Array(root)))
self.view_paths = ActionView::Base.process_view_paths(root)
end
end

Expand Down Expand Up @@ -529,24 +533,31 @@ def initialize_defaults(method_name)
end

def render_message(method_name, body)
render :file => method_name, :body => body, :use_full_path => true
render :file => method_name, :body => body
end

def render(opts)
body = opts.delete(:body)
if opts[:file] && opts[:file] !~ /\//
opts[:file] = "#{mailer_name}/#{opts[:file]}"
end
opts[:use_full_path] = true
initialize_template_class(body).render(opts)
end

def template_root
self.class.template_root
end

def template_root=(root)
self.class.template_root = root
end

def template_path
"#{template_root}/#{mailer_name}"
end

def initialize_template_class(assigns)
ActionView::Base.new(template_root, assigns, self)
ActionView::Base.new(view_paths, assigns, self)
end

def sort_parts(parts, order = [])
Expand Down
18 changes: 13 additions & 5 deletions actionmailer/test/abstract_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ def self.start(*args)
end
end

# Wrap tests that use Mocha and skip if unavailable.
def uses_mocha(test_name)
gem 'mocha', ">=0.9.0"
def uses_gem(gem_name, test_name, version = '> 0')
require 'rubygems'
gem gem_name.to_s, version
require gem_name.to_s
yield
rescue Gem::LoadError
$stderr.puts "Skipping #{test_name} tests (Mocha >= 0.5 is required). `gem install mocha` and try again."
rescue LoadError
$stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again."
end

# Wrap tests that use Mocha and skip if unavailable.
unless defined? uses_mocha
def uses_mocha(test_name, &block)
uses_gem('mocha', test_name, '>= 0.5.5', &block)
end
end

def set_delivery_method(delivery_method)
Expand Down
6 changes: 3 additions & 3 deletions actionmailer/test/mail_service_test.rb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -942,13 +942,13 @@ def test_return_path_with_deliver
class InheritableTemplateRootTest < Test::Unit::TestCase
def test_attr
expected = "#{File.dirname(__FILE__)}/fixtures/path.with.dots"
assert_equal [expected], FunkyPathMailer.template_root.map(&:to_s)
assert_equal expected, FunkyPathMailer.template_root

sub = Class.new(FunkyPathMailer)
sub.template_root = 'test/path'

assert_equal ['test/path'], sub.template_root.map(&:to_s)
assert_equal [expected], FunkyPathMailer.template_root.map(&:to_s)
assert_equal 'test/path', sub.template_root
assert_equal expected, FunkyPathMailer.template_root
end
end

Expand Down
18 changes: 18 additions & 0 deletions actionpack/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
*Edge*

* Added back ActionController::Base.allow_concurrency flag [Josh Peek]

* AbstractRequest.relative_url_root is no longer automatically configured by a HTTP header. It can now be set in your configuration environment with config.action_controller.relative_url_root [Josh Peek]

* Update Prototype to 1.6.0.2 #599 [Patrick Joyce]

* Conditional GET utility methods. [Jeremy Kemper]
* etag!([:admin, post, current_user]) sets the ETag response header and returns head(:not_modified) if it matches the If-None-Match request header.
* last_modified!(post.updated_at) sets Last-Modified and returns head(:not_modified) if it's no later than If-Modified-Since.

* All 2xx requests are considered successful [Josh Peek]

* Fixed that AssetTagHelper#compute_public_path shouldn't cache the asset_host along with the source or per-request proc's won't run [DHH]

* Removed config.action_view.cache_template_loading, use config.cache_classes instead [Josh Peek]

* Get buffer for fragment cache from template's @output_buffer [Josh Peek]

* Set config.action_view.warn_cache_misses = true to receive a warning if you perform an action that results in an expensive disk operation that could be cached [Josh Peek]

* Refactor template preloading. New abstractions include Renderable mixins and a refactored Template class [Josh Peek]
Expand Down
Empty file modified actionpack/lib/action_controller.rb
100755 → 100644
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ def assert_redirected_to(options = {}, message=nil)
#
def assert_template(expected = nil, message=nil)
clean_backtrace do
rendered = expected ? @response.rendered_file(!expected.include?('/')) : @response.rendered_file
rendered = @response.rendered_template
msg = build_message(message, "expecting <?> but rendering with <?>", expected, rendered)
assert_block(msg) do
if expected.nil?
!@response.rendered_with_file?
@response.rendered_template.nil?
else
rendered.match(expected)
rendered.to_s.match(expected)
end
end
end
Expand Down
44 changes: 22 additions & 22 deletions actionpack/lib/action_controller/assertions/routing_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module ActionController
module Assertions
# Suite of assertions to test routes generated by Rails and the handling of requests made to them.
module RoutingAssertions
# Asserts that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash)
# Asserts that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash)
# match +path+. Basically, it asserts that Rails recognizes the route given by +expected_options+.
#
# Pass a hash in the second argument (+path+) to specify the request method. This is useful for routes
Expand All @@ -14,16 +14,16 @@ module RoutingAssertions
#
# You can also pass in +extras+ with a hash containing URL parameters that would normally be in the query string. This can be used
# to assert that values in the query string string will end up in the params hash correctly. To test query strings you must use the
# extras argument, appending the query string on the path directly will not work. For example:
# extras argument, appending the query string on the path directly will not work. For example:
#
# # assert that a path of '/items/list/1?view=print' returns the correct options
# assert_recognizes({:controller => 'items', :action => 'list', :id => '1', :view => 'print'}, 'items/list/1', { :view => "print" })
# assert_recognizes({:controller => 'items', :action => 'list', :id => '1', :view => 'print'}, 'items/list/1', { :view => "print" })
#
# The +message+ parameter allows you to pass in an error message that is displayed upon failure.
# The +message+ parameter allows you to pass in an error message that is displayed upon failure.
#
# ==== Examples
# # Check the default route (i.e., the index action)
# assert_recognizes({:controller => 'items', :action => 'index'}, 'items')
# assert_recognizes({:controller => 'items', :action => 'index'}, 'items')
#
# # Test a specific action
# assert_recognizes({:controller => 'items', :action => 'list'}, 'items/list')
Expand All @@ -44,16 +44,16 @@ def assert_recognizes(expected_options, path, extras={}, message=nil)
request_method = nil
end

clean_backtrace do
ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
clean_backtrace do
ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
request = recognized_request_for(path, request_method)

expected_options = expected_options.clone
extras.each_key { |key| expected_options.delete key } unless extras.nil?

expected_options.stringify_keys!
routing_diff = expected_options.diff(request.path_parameters)
msg = build_message(message, "The recognized options <?> did not match <?>, difference: <?>",
msg = build_message(message, "The recognized options <?> did not match <?>, difference: <?>",
request.path_parameters, expected_options, expected_options.diff(request.path_parameters))
assert_block(msg) { request.path_parameters == expected_options }
end
Expand All @@ -64,7 +64,7 @@ def assert_recognizes(expected_options, path, extras={}, message=nil)
# a query string. The +message+ parameter allows you to specify a custom error message for assertion failures.
#
# The +defaults+ parameter is unused.
#
#
# ==== Examples
# # Asserts that the default action is generated for a route with no action
# assert_generates("/items", :controller => "items", :action => "index")
Expand All @@ -73,34 +73,34 @@ def assert_recognizes(expected_options, path, extras={}, message=nil)
# assert_generates("/items/list", :controller => "items", :action => "list")
#
# # Tests the generation of a route with a parameter
# assert_generates("/items/list/1", { :controller => "items", :action => "list", :id => "1" })
# assert_generates("/items/list/1", { :controller => "items", :action => "list", :id => "1" })
#
# # Asserts that the generated route gives us our custom route
# assert_generates "changesets/12", { :controller => 'scm', :action => 'show_diff', :revision => "12" }
def assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)
clean_backtrace do
clean_backtrace do
expected_path = "/#{expected_path}" unless expected_path[0] == ?/
# Load routes.rb if it hasn't been loaded.
ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?

generated_path, extra_keys = ActionController::Routing::Routes.generate_extras(options, defaults)
found_extras = options.reject {|k, v| ! extra_keys.include? k}

msg = build_message(message, "found extras <?>, not <?>", found_extras, extras)
assert_block(msg) { found_extras == extras }
msg = build_message(message, "The generated path <?> did not match <?>", generated_path,

msg = build_message(message, "The generated path <?> did not match <?>", generated_path,
expected_path)
assert_block(msg) { expected_path == generated_path }
end
end

# Asserts that path and options match both ways; in other words, it verifies that <tt>path</tt> generates
# Asserts that path and options match both ways; in other words, it verifies that <tt>path</tt> generates
# <tt>options</tt> and then that <tt>options</tt> generates <tt>path</tt>. This essentially combines +assert_recognizes+
# and +assert_generates+ into one step.
#
# The +extras+ hash allows you to specify options that would normally be provided as a query string to the action. The
# +message+ parameter allows you to specify a custom error message to display upon failure.
# +message+ parameter allows you to specify a custom error message to display upon failure.
#
# ==== Examples
# # Assert a basic route: a controller with the default action (index)
Expand All @@ -119,12 +119,12 @@ def assert_generates(expected_path, options, defaults={}, extras = {}, message=n
# assert_routing({ :method => 'put', :path => '/product/321' }, { :controller => "product", :action => "update", :id => "321" })
def assert_routing(path, options, defaults={}, extras={}, message=nil)
assert_recognizes(options, path, extras, message)
controller, default_controller = options[:controller], defaults[:controller]

controller, default_controller = options[:controller], defaults[:controller]
if controller && controller.include?(?/) && default_controller && default_controller.include?(?/)
options[:controller] = "/#{controller}"
end

assert_generates(path.is_a?(Hash) ? path[:path] : path, options, defaults, extras, message)
end

Expand Down
26 changes: 16 additions & 10 deletions actionpack/lib/action_controller/assertions/selector_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ def assert_select_rjs(*args, &block)

if rjs_type == :insert
arg = args.shift
position = arg
insertion = "insert_#{arg}".to_sym
raise ArgumentError, "Unknown RJS insertion type #{arg}" unless RJS_STATEMENTS[insertion]
statement = "(#{RJS_STATEMENTS[insertion]})"
Expand All @@ -418,6 +419,7 @@ def assert_select_rjs(*args, &block)
else
statement = "#{RJS_STATEMENTS[:any]}"
end
position ||= Regexp.new(RJS_INSERTIONS.join('|'))

# Next argument we're looking for is the element identifier. If missing, we pick
# any element.
Expand All @@ -434,9 +436,14 @@ def assert_select_rjs(*args, &block)
Regexp.new("\\$\\(\"#{id}\"\\)#{statement}\\(#{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
when :remove, :show, :hide, :toggle
Regexp.new("#{statement}\\(\"#{id}\"\\)")
else
Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
end
when :replace, :replace_html
Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)")
when :insert, :insert_html
Regexp.new("Element.insert\\(\\\"#{id}\\\", \\{ #{position}: #{RJS_PATTERN_HTML} \\}\\);")
else
Regexp.union(Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)"),
Regexp.new("Element.insert\\(\\\"#{id}\\\", \\{ #{position}: #{RJS_PATTERN_HTML} \\}\\);"))
end

# Duplicate the body since the next step involves destroying it.
matches = nil
Expand All @@ -445,7 +452,7 @@ def assert_select_rjs(*args, &block)
matches = @response.body.match(pattern)
else
@response.body.gsub(pattern) do |match|
html = unescape_rjs($2)
html = unescape_rjs(match)
matches ||= []
matches.concat HTML::Document.new(html).root.children.select { |n| n.tag? }
""
Expand Down Expand Up @@ -585,17 +592,16 @@ def assert_select_email(&block)
:hide => /Element\.hide/,
:toggle => /Element\.toggle/
}
RJS_STATEMENTS[:any] = Regexp.new("(#{RJS_STATEMENTS.values.join('|')})")
RJS_PATTERN_HTML = /"((\\"|[^"])*)"/
RJS_INSERTIONS = [:top, :bottom, :before, :after]
RJS_INSERTIONS.each do |insertion|
RJS_STATEMENTS["insert_#{insertion}".to_sym] = Regexp.new(Regexp.quote("new Insertion.#{insertion.to_s.camelize}"))
RJS_STATEMENTS["insert_#{insertion}".to_sym] = /Element.insert\(\"([^\"]*)\", \{ #{insertion.to_s.downcase}: #{RJS_PATTERN_HTML} \}\);/
end
RJS_STATEMENTS[:any] = Regexp.new("(#{RJS_STATEMENTS.values.join('|')})")
RJS_STATEMENTS[:insert_html] = Regexp.new(RJS_INSERTIONS.collect do |insertion|
Regexp.quote("new Insertion.#{insertion.to_s.camelize}")
/Element.insert\(\"([^\"]*)\", \{ #{insertion.to_s.downcase}: #{RJS_PATTERN_HTML} \}\);/
end.join('|'))
RJS_PATTERN_HTML = /"((\\"|[^"])*)"/
RJS_PATTERN_EVERYTHING = Regexp.new("#{RJS_STATEMENTS[:any]}\\(\"([^\"]*)\", #{RJS_PATTERN_HTML}\\)",
Regexp::MULTILINE)
RJS_PATTERN_EVERYTHING = Regexp.new("#{RJS_STATEMENTS[:any]}\\(\"([^\"]*)\", #{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
RJS_PATTERN_UNICODE_ESCAPED_CHAR = /\\u([0-9a-zA-Z]{4})/
end

Expand Down
Loading

0 comments on commit 920ad94

Please sign in to comment.