Skip to content

Commit

Permalink
Merge branch 'master' into nested_has_many_through
Browse files Browse the repository at this point in the history
  • Loading branch information
jonleighton committed Mar 7, 2011
2 parents bb063b2 + 5968d7a commit 67b17d0
Show file tree
Hide file tree
Showing 25 changed files with 193 additions and 44 deletions.
5 changes: 4 additions & 1 deletion actionmailer/lib/rails/generators/mailer/USAGE
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
Description:
============
Stubs out a new mailer and its views. Pass the mailer name, either
CamelCased or under_scored, and an optional list of emails as arguments.

This generates a mailer class in app/mailers and invokes your template
engine and test framework generators.

Example:
`rails generate mailer Notifications signup forgot_password invoice`
========
rails generate mailer Notifications signup forgot_password invoice

creates a Notifications mailer class, views, test, and fixtures:
Mailer: app/mailers/notifications.rb
Views: app/views/notifications/signup.erb [...]
Test: test/functional/notifications_test.rb
Fixtures: test/fixtures/notifications/signup [...]

4 changes: 2 additions & 2 deletions actionmailer/test/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ def teardown
assert_equal(2, email.parts.length)
assert_equal("multipart/related", email.mime_type)
assert_equal("multipart/alternative", email.parts[0].mime_type)
assert_equal("text/plain", email.parts[0].parts[0].mime_type)
assert_equal("text/html", email.parts[0].parts[1].mime_type)
assert_equal("text/plain", email.parts[0].parts[0].mime_type)
assert_equal("text/html", email.parts[0].parts[1].mime_type)
assert_equal("logo.png", email.parts[1].filename)
end

Expand Down
11 changes: 10 additions & 1 deletion actionpack/lib/action_controller/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ def assign_parameters(routes, controller_path, action, parameters = {})
end

def recycle!
write_cookies!
@env.delete('HTTP_COOKIE') if @cookies.blank?
@env.delete('action_dispatch.cookies')
@cookies = nil
@formats = nil
@env.delete_if { |k, v| k =~ /^(action_dispatch|rack)\.request/ }
@env.delete_if { |k, v| k =~ /^action_dispatch\.rescue/ }
Expand Down Expand Up @@ -301,7 +305,11 @@ def exists?
# and cookies, though. For sessions, you just do:
#
# @request.session[:key] = "value"
# @request.cookies["key"] = "value"
# @request.cookies[:key] = "value"
#
# To clear the cookies for a test just clear the request's cookies hash:
#
# @request.cookies.clear
#
# == \Testing named routes
#
Expand Down Expand Up @@ -416,6 +424,7 @@ def process(action, parameters = nil, session = nil, flash = nil, http_method =
@controller.process_with_new_base_test(@request, @response)
@assigns = @controller.respond_to?(:view_assigns) ? @controller.view_assigns : {}
@request.session.delete('flash') if @request.session['flash'].blank?
@request.cookies.merge!(@response.cookies)
@response
end

Expand Down
2 changes: 2 additions & 0 deletions actionpack/lib/action_dispatch/routing/route_set.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'rack/mount'
require 'forwardable'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/object/to_query'
require 'active_support/core_ext/hash/slice'

Expand Down Expand Up @@ -330,6 +331,7 @@ def empty?
end

def add_route(app, conditions = {}, requirements = {}, defaults = {}, name = nil, anchor = true)
raise ArgumentError, "Invalid route name: '#{name}'" unless name.blank? || name.to_s.match(/^[_a-z]\w*$/i)
route = Route.new(self, app, conditions, requirements, defaults, name, anchor)
@set.add_route(*route)
named_routes[name] = route if name
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/testing/test_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def flash
end

def cookies
HashWithIndifferentAccess.new(@request.cookies.merge(@response.cookies))
@request.cookies.merge(@response.cookies).with_indifferent_access
end

def redirect_to_url
Expand Down
7 changes: 6 additions & 1 deletion actionpack/lib/action_dispatch/testing/test_request.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/hash/reverse_merge'
require 'rack/utils'

module ActionDispatch
class TestRequest < Request
Expand Down Expand Up @@ -77,10 +78,14 @@ def cookies
private
def write_cookies!
unless @cookies.blank?
@env['HTTP_COOKIE'] = @cookies.map { |name, value| "#{name}=#{value};" }.join(' ')
@env['HTTP_COOKIE'] = @cookies.map { |name, value| escape_cookie(name, value) }.join('; ')
end
end

def escape_cookie(name, value)
"#{Rack::Utils.escape(name)}=#{Rack::Utils.escape(value)}"
end

def delete_nil_values!
@env.delete_if { |k, v| v.nil? }
end
Expand Down
7 changes: 4 additions & 3 deletions actionpack/lib/action_view/helpers/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'active_support/core_ext/hash/slice'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/string/output_safety'
require 'active_support/core_ext/array/extract_options'

module ActionView
# = Action View Form Helpers
Expand Down Expand Up @@ -880,9 +881,9 @@ def range_field(object_name, method, options = {})

private

def instantiate_builder(record, record_object = nil, options = nil, &block)
options, record_object = record_object, nil if record_object.is_a?(Hash)
options ||= {}
def instantiate_builder(record, *args, &block)
options = args.extract_options!
record_object = args.shift

case record
when String, Symbol
Expand Down
65 changes: 65 additions & 0 deletions actionpack/test/dispatch/cookies_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ def string_key
cookies['user_name'] = "david"
head :ok
end

def symbol_key_mock
cookies[:user_name] = "david" if cookies[:user_name] == "andrew"
head :ok
end

def string_key_mock
cookies['user_name'] = "david" if cookies['user_name'] == "andrew"
head :ok
end

def noop
head :ok
end
end

tests TestController
Expand Down Expand Up @@ -411,6 +425,57 @@ def test_cookies_hash_is_indifferent_access
end
end

def test_setting_request_cookies_is_indifferent_access
@request.cookies.clear
@request.cookies[:user_name] = "andrew"
get :string_key_mock
assert_equal "david", cookies[:user_name]

@request.cookies.clear
@request.cookies['user_name'] = "andrew"
get :symbol_key_mock
assert_equal "david", cookies['user_name']
end

def test_cookies_retained_across_requests
get :symbol_key
assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"]
assert_equal "david", cookies[:user_name]

get :noop
assert_nil @response.headers["Set-Cookie"]
assert_equal "user_name=david", @request.env['HTTP_COOKIE']
assert_equal "david", cookies[:user_name]

get :noop
assert_nil @response.headers["Set-Cookie"]
assert_equal "user_name=david", @request.env['HTTP_COOKIE']
assert_equal "david", cookies[:user_name]
end

def test_cookies_can_be_cleared
get :symbol_key
assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"]
assert_equal "david", cookies[:user_name]

@request.cookies.clear
get :noop
assert_nil @response.headers["Set-Cookie"]
assert_nil @request.env['HTTP_COOKIE']
assert_nil cookies[:user_name]

get :symbol_key
assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"]
assert_equal "david", cookies[:user_name]
end

def test_cookies_are_escaped
@request.cookies[:user_ids] = '1;2'
get :noop
assert_equal "user_ids=1%3B2", @request.env['HTTP_COOKIE']
assert_equal "1;2", cookies[:user_ids]
end

private
def assert_cookie_header(expected)
header = @response.headers["Set-Cookie"]
Expand Down
32 changes: 32 additions & 0 deletions actionpack/test/dispatch/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2313,6 +2313,38 @@ def test_controller_name_with_leading_slash_raise_error
end
end

def test_invalid_route_name_raises_error
assert_raise(ArgumentError) do
self.class.stub_controllers do |routes|
routes.draw { get '/products', :to => 'products#index', :as => 'products ' }
end
end

assert_raise(ArgumentError) do
self.class.stub_controllers do |routes|
routes.draw { get '/products', :to => 'products#index', :as => ' products' }
end
end

assert_raise(ArgumentError) do
self.class.stub_controllers do |routes|
routes.draw { get '/products', :to => 'products#index', :as => 'products!' }
end
end

assert_raise(ArgumentError) do
self.class.stub_controllers do |routes|
routes.draw { get '/products', :to => 'products#index', :as => 'products index' }
end
end

assert_raise(ArgumentError) do
self.class.stub_controllers do |routes|
routes.draw { get '/products', :to => 'products#index', :as => '1products' }
end
end
end

def test_nested_route_in_nested_resource
get "/posts/1/comments/2/views"
assert_equal "comments#views", @response.body
Expand Down
4 changes: 2 additions & 2 deletions actionpack/test/dispatch/test_request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class TestRequestTest < ActiveSupport::TestCase

req.cookies["user_name"] = "david"
assert_equal({"user_name" => "david"}, req.cookies)
assert_equal "user_name=david;", req.env["HTTP_COOKIE"]
assert_equal "user_name=david", req.env["HTTP_COOKIE"]

req.cookies["login"] = "XJ-122"
assert_equal({"user_name" => "david", "login" => "XJ-122"}, req.cookies)
assert_equal %w(login=XJ-122 user_name=david), req.env["HTTP_COOKIE"].split(/; ?/).sort
assert_equal %w(login=XJ-122 user_name=david), req.env["HTTP_COOKIE"].split(/; /).sort
end
end
19 changes: 19 additions & 0 deletions actionpack/test/template/form_options_helper_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
require 'abstract_unit'
require 'tzinfo'

class Map < Hash
def category
"<mus>"
end
end

TZInfo::Timezone.cattr_reader :loaded_zones

class FormOptionsHelperTest < ActionView::TestCase
Expand Down Expand Up @@ -394,6 +400,19 @@ def test_select_under_fields_for
)
end

def test_fields_for_with_record_inherited_from_hash
map = Map.new

output_buffer = fields_for :map, map do |f|
concat f.select(:category, %w( abe <mus> hest))
end

assert_dom_equal(
"<select id=\"map_category\" name=\"map[category]\"><option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\" selected=\"selected\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
output_buffer
)
end

def test_select_under_fields_for_with_index
@post = Post.new
@post.category = "<mus>"
Expand Down
2 changes: 1 addition & 1 deletion activemodel/lib/active_model/observing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def count_observers
def instantiate_observer(observer) #:nodoc:
# string/symbol
if observer.respond_to?(:to_sym)
observer = observer.to_s.camelize.constantize.instance
observer.to_s.camelize.constantize.instance
elsif observer.respond_to?(:instance)
observer.instance
else
Expand Down
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/backtrace_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module ActiveSupport
# filter or modify the paths of any lines of the backtrace, you can call BacktraceCleaner#remove_filters! These two methods
# will give you a completely untouched backtrace.
#
# Example:
# ==== Example:
#
# bc = BacktraceCleaner.new
# bc.add_filter { |line| line.gsub(Rails.root, '') }
Expand Down
25 changes: 11 additions & 14 deletions activesupport/lib/active_support/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -484,19 +484,20 @@ def merged_options(call_options) # :nodoc:
# object responds to +cache_key+. Otherwise, to_param method will be
# called. If the key is a Hash, then keys will be sorted alphabetically.
def expanded_key(key) # :nodoc:
if key.respond_to?(:cache_key)
key = key.cache_key.to_s
elsif key.is_a?(Array)
return key.cache_key.to_s if key.respond_to?(:cache_key)

case key
when Array
if key.size > 1
key.collect{|element| expanded_key(element)}.to_param
key = key.collect{|element| expanded_key(element)}
else
key.first.to_param
key = key.first
end
elsif key.is_a?(Hash)
key = key.to_a.sort{|a,b| a.first.to_s <=> b.first.to_s}.collect{|k,v| "#{k}=#{v}"}.to_param
else
key = key.to_param
when Hash
key = key.sort_by { |k,_| k.to_s }.collect{|k,v| "#{k}=#{v}"}
end

key.to_param
end

# Prefix a key with the namespace. Namespace and key will be delimited with a colon.
Expand Down Expand Up @@ -589,11 +590,7 @@ def compressed?
# Check if the entry is expired. The +expires_in+ parameter can override the
# value set when the entry was created.
def expired?
if @expires_in && @created_at + @expires_in <= Time.now.to_f
true
else
false
end
@expires_in && @created_at + @expires_in <= Time.now.to_f
end

# Set a new time when the entry will expire.
Expand Down
12 changes: 6 additions & 6 deletions activesupport/lib/active_support/configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,21 @@ def #{name}=(value); config.#{name} = value; end
end

# Reads and writes attributes from a configuration <tt>OrderedHash</tt>.
#
# require 'active_support/configurable'
#
#
# require 'active_support/configurable'
#
# class User
# include ActiveSupport::Configurable
# end
# end
#
# user = User.new
#
#
# user.config.allowed_access = true
# user.config.level = 1
#
# user.config.allowed_access # => true
# user.config.level # => 1
#
#
def config
@_config ||= self.class.config.inheritable_copy
end
Expand Down
Loading

0 comments on commit 67b17d0

Please sign in to comment.