Skip to content

Commit

Permalink
Merge branch 'master' of github.com:rails/rails
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Jun 8, 2010
2 parents 6ebc7c8 + 5c9f27a commit df40dbe
Show file tree
Hide file tree
Showing 24 changed files with 667 additions and 114 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -32,7 +32,7 @@ if mri || RUBY_ENGINE == "rbx"
gem "sqlite3-ruby", "~> 1.3.0", :require => 'sqlite3'

group :db do
# gem "pg", ">= 0.9.0"
gem "pg", ">= 0.9.0"
gem "mysql", ">= 2.8.1"
end
elsif RUBY_ENGINE == "jruby"
Expand Down
10 changes: 0 additions & 10 deletions actionpack/CHANGELOG
@@ -1,15 +1,5 @@
*Rails 3.0.0 [beta 4] (June 8th, 2010)*

* Add shallow routes back to the new router [Diego Carrion]

resources :posts do
shallow do
resources :comments
end
end

You can now use comment_path for /comments/1 instead of post_comment_path for /posts/1/comments/1.

* Remove middleware laziness [José Valim]

* Make session stores rely on request.cookie_jar and change set_session semantics to return the cookie value instead of a boolean. [José Valim]
Expand Down
1 change: 1 addition & 0 deletions actionpack/lib/action_controller/caching/sweeping.rb
Expand Up @@ -57,6 +57,7 @@ class Sweeper < ActiveRecord::Observer #:nodoc:
def before(controller)
self.controller = controller
callback(:before) if controller.perform_caching
true # before method from sweeper should always return true
end

def after(controller)
Expand Down
37 changes: 11 additions & 26 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -350,10 +350,6 @@ def constraints(constraints = {})
scope(:constraints => constraints) { yield }
end

def shallow
scope(:shallow => true) { yield }
end

def defaults(defaults = {})
scope(:defaults => defaults) { yield }
end
Expand All @@ -378,21 +374,12 @@ def scope_options
@scope_options ||= private_methods.grep(/^merge_(.+)_scope$/) { $1.to_sym }
end

def merge_shallow_scope(parent, child)
parent or child
end

def merge_path_scope(parent, child)
parent_path = (@scope[:shallow] and child.eql?(':id')) ? parent.split('/').last : parent
Mapper.normalize_path "#{parent_path}/#{child}"
Mapper.normalize_path("#{parent}/#{child}")
end

def merge_name_prefix_scope(parent, child)
if @scope[:shallow]
child
else
parent ? "#{parent}_#{child}" : child
end
parent ? "#{parent}_#{child}" : child
end

def merge_module_scope(parent, child)
Expand Down Expand Up @@ -535,10 +522,6 @@ def nested_options
options["#{singular}_id".to_sym] = id_constraint if id_constraint?
options
end

def shallow?
options[:shallow]
end
end

class SingletonResource < Resource #:nodoc:
Expand Down Expand Up @@ -620,12 +603,8 @@ def resources(*resources, &block)

resource = Resource.new(resources.pop, options)

scope(:path => resource.path, :controller => resource.controller, :shallow => resource.shallow?) do
scope(:path => resource.path, :controller => resource.controller) do
with_scope_level(:resources, resource) do
if @scope[:shallow] && @scope[:name_prefix]
@scope[:path] = "/#{@scope[:name_prefix].pluralize}/:#{@scope[:name_prefix]}_id/#{resource.path}"
end

yield if block_given?

with_scope_level(:collection) do
Expand All @@ -639,8 +618,6 @@ def resources(*resources, &block)
with_scope_level(:member) do
scope(':id') do
scope(resource.options) do
@scope[:name_prefix] = nil if @scope[:shallow]

get :show if resource.actions.include?(:show)
put :update if resource.actions.include?(:update)
delete :destroy if resource.actions.include?(:destroy)
Expand Down Expand Up @@ -702,6 +679,14 @@ def nested
end
end

def namespace(path)
if resource_scope?
nested { super }
else
super
end
end

def match(*args)
options = args.extract_options!

Expand Down
14 changes: 8 additions & 6 deletions actionpack/lib/action_view/test_case.rb
Expand Up @@ -131,12 +131,14 @@ def make_test_case_available_to_view!
end

def _view
view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @controller)
view.singleton_class.send :include, _helpers
view.singleton_class.send :include, @controller._router.url_helpers
view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash"
view.output_buffer = self.output_buffer
view
@_view ||= begin
view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @controller)
view.singleton_class.send :include, _helpers
view.singleton_class.send :include, @controller._router.url_helpers
view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash"
view.output_buffer = self.output_buffer
view
end
end

EXCLUDE_IVARS = %w{
Expand Down
3 changes: 3 additions & 0 deletions actionpack/test/abstract_unit.rb
Expand Up @@ -24,6 +24,9 @@
require 'action_dispatch'
require 'active_support/dependencies'
require 'active_model'
require 'active_record'
require 'action_controller/caching'
require 'action_controller/caching/sweeping'

begin
require 'ruby-debug'
Expand Down
6 changes: 6 additions & 0 deletions actionpack/test/controller/filters_test.rb
Expand Up @@ -445,6 +445,12 @@ def filter_three

end


def test_before_method_of_sweeper_should_always_return_true
sweeper = ActionController::Caching::Sweeper.send(:new)
assert sweeper.before(TestController.new)
end

def test_non_yielding_around_filters_not_returning_false_do_not_raise
controller = NonYieldingAroundFilterController.new
controller.instance_variable_set "@filter_return_value", true
Expand Down
61 changes: 22 additions & 39 deletions actionpack/test/dispatch/routing_test.rb
Expand Up @@ -34,33 +34,6 @@ def self.matches?(request)
end
end

resources :users do
shallow do
resources :photos do
resources :types do
member do
post :preview
end
collection do
delete :erase
end
end
end
end
end

shallow do
resources :teams do
resources :players
end

resources :countries do
resources :cities do
resources :places
end
end
end

match 'account/logout' => redirect("/logout"), :as => :logout_redirect
match 'account/login', :to => redirect("/login")

Expand Down Expand Up @@ -171,6 +144,16 @@ def self.matches?(request)

resources :sheep

resources :clients do
namespace :google do
resource :account do
namespace :secret do
resource :info
end
end
end
end

match 'sprockets.js' => ::TestRoutingMapper::SprocketsApp

match 'people/:id/update', :to => 'people#update', :as => :update_person
Expand Down Expand Up @@ -779,18 +762,6 @@ def test_update_person_route
end
end

def test_shallow_routes
with_test_routes do
assert_equal '/photos/4', photo_path(4)
assert_equal '/types/10/edit', edit_type_path(10)
assert_equal '/types/5/preview', preview_type_path(5)
assert_equal '/photos/2/types', photo_types_path(2)
assert_equal '/cities/1/places', url_for(:controller => :places, :action => :index, :city_id => 1, :only_path => true)
assert_equal '/teams/new', url_for(:controller => :teams, :action => :new, :only_path => true)
assert_equal '/photos/11/types/erase', url_for(:controller => :types, :action => :erase, :photo_id => 11, :only_path => true)
end
end

def test_update_project_person
with_test_routes do
get '/projects/1/people/2/update'
Expand Down Expand Up @@ -852,6 +823,18 @@ def test_nested_namespace
assert_equal '/account/admin/subscription', account_admin_subscription_path
end
end

def test_namespace_nested_in_resources
with_test_routes do
get '/clients/1/google/account'
assert_equal '/clients/1/google/account', client_google_account_path(1)
assert_equal 'google/accounts#show', @response.body

get '/clients/1/google/account/secret/info'
assert_equal '/clients/1/google/account/secret/info', client_google_account_secret_info_path(1)
assert_equal 'google/secret/infos#show', @response.body
end
end

def test_articles_with_id
with_test_routes do
Expand Down
4 changes: 4 additions & 0 deletions actionpack/test/template/test_case_test.rb
Expand Up @@ -37,6 +37,10 @@ class GeneralViewTest < ActionView::TestCase
include SharedTests
test_case = self

test "memoizes the _view" do
assert_same _view, _view
end

test "works without testing a helper module" do
assert_equal 'Eloy', render('developers/developer', :developer => stub(:name => 'Eloy'))
end
Expand Down
4 changes: 4 additions & 0 deletions activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*Rails 3.0.0 [beta 4] (June 8th, 2010)*

* Fixed that ActiveRecord::Base.compute_type would swallow NoMethodError #4751 [Andrew Bloomgarden, Andrew White]

* Add index length support for MySQL. #1852 [Emili Parreno, Pratik Naik]

Example:
Expand All @@ -12,6 +14,8 @@

* find_or_create_by_attr(value, ...) works when attr is protected. #4457 [Santiago Pastorino, Marc-André Lafortune]

* New callbacks: after_commit and after_rollback. Do expensive operations like image thumbnailing after_commit instead of after_save. #2991 [Brian Durand]

* Serialized attributes are not converted to YAML if they are any of the formats that can be serialized to XML (like Hash, Array and Strings). [José Valim]

* Destroy uses optimistic locking. If lock_version on the record you're destroying doesn't match lock_version in the database, a StaleObjectError is raised. #1966 [Curtis Hawthorne]
Expand Down
4 changes: 3 additions & 1 deletion activerecord/lib/active_record/base.rb
Expand Up @@ -1219,7 +1219,9 @@ def compute_type(type_name)
begin
constant = candidate.constantize
return constant if candidate == constant.to_s
rescue NameError
rescue NameError => e
# We don't want to swallow NoMethodError < NameError errors
raise e unless e.instance_of?(NameError)
rescue ArgumentError
end
end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/callbacks.rb
Expand Up @@ -31,7 +31,7 @@ module ActiveRecord
# class CreditCard < ActiveRecord::Base
# # Strip everything but digits, so the user can specify "555 234 34" or
# # "5552-3434" or both will mean "55523434"
# def before_validation_on_create
# before_validation(:on => :create) do
# self.number = number.gsub(/[^0-9]/, "") if attribute_present?("number")
# end
# end
Expand Down

0 comments on commit df40dbe

Please sign in to comment.