Permalink
Browse files

Merge branch 'master' of git://github.com/rails/rails

  • Loading branch information...
2 parents b8bc92e + 60be4b0 commit 342dcfe789d11e07f89d4ddfc3dc581da650a65e @dhh dhh committed Apr 12, 2008
@@ -337,6 +337,10 @@ class Base
@@resource_action_separator = "/"
cattr_accessor :resource_action_separator
+ # Allow to override path names for default resources' actions
+ @@resources_path_names = { :new => 'new', :edit => 'edit' }
+ cattr_accessor :resources_path_names
+
# Sets the token parameter name for RequestForgery. Calling #protect_from_forgery sets it to :authenticity_token by default
cattr_accessor :request_forgery_protection_token
@@ -39,12 +39,7 @@ def self.included(base) #:nodoc:
base.class_eval do
include InstanceMethods
extend ClassMethods
-
- helper do
- def render_component(options)
- @controller.send!(:render_component_as_string, options)
- end
- end
+ helper HelperMethods
# If this controller was instantiated to process a component request,
# +parent_controller+ points to the instantiator of this controller.
@@ -67,6 +62,12 @@ def process_with_components(request, response, parent_controller = nil) #:nodoc:
end
end
+ module HelperMethods
+ def render_component(options)
+ @controller.send!(:render_component_as_string, options)
+ end
+ end
+
module InstanceMethods
# Extracts the action_name from the request parameters and performs that action.
def process_with_components(request, response, method = :perform_action, *arguments) #:nodoc:
@@ -73,7 +73,7 @@ def polymorphic_url(record_or_hash_or_array, options = {})
end
record = extract_record(record_or_hash_or_array)
- format = (options[:action].to_s == "formatted" and record_or_hash_or_array.pop)
+ format = extract_format(record_or_hash_or_array, options)
namespace = extract_namespace(record_or_hash_or_array)
args = case record_or_hash_or_array
@@ -152,6 +152,16 @@ def extract_record(record_or_hash_or_array)
end
end
+ def extract_format(record_or_hash_or_array, options)
+ if options[:action].to_s == "formatted" && record_or_hash_or_array.is_a?(Array)
+ record_or_hash_or_array.pop
+ elsif options[:format]
+ options[:format]
+ else
+ nil
+ end
+ end
+
def extract_namespace(record_or_hash_or_array)
returning "" do |namespace|
if record_or_hash_or_array.is_a?(Array)
@@ -80,7 +80,9 @@ def path
end
def new_path
- @new_path ||= "#{path}/new"
+ new_action = self.options[:path_names][:new] if self.options[:path_names]
+ new_action ||= Base.resources_path_names[:new]
+ @new_path ||= "#{path}/#{new_action}"
end
def member_path
@@ -266,6 +268,13 @@ def initialize(entity, options)
# notes.resources :attachments
# end
#
+ # * <tt>:path_names</tt> - specify different names for the 'new' and 'edit' actions. For example:
+ # # new_products_path == '/productos/nuevo'
+ # map.resources :products, :as => 'productos', :path_names => { :new => 'nuevo', :edit => 'editar' }
+ #
+ # You can also set default action names from an environment, like this:
+ # config.action_controller.resources_path_names = { :new => 'nuevo', :edit => 'editar' }
+ #
# * <tt>:path_prefix</tt> - set a prefix to the routes with required route variables.
#
# Weblog comments usually belong to a post, so you might use resources like:
@@ -515,8 +524,14 @@ def map_member_actions(map, resource)
resource.member_methods.each do |method, actions|
actions.each do |action|
action_options = action_options_for(action, resource, method)
- map.named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}", action_options)
- map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}.:format",action_options)
+ action_path = action
+ if resource.options[:path_names]
+ action_path = resource.options[:path_names][action]
+ action_path ||= Base.resources_path_names[action]
+ end
+
+ map.named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}", action_options)
+ map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}.:format",action_options)
end
end
@@ -41,7 +41,7 @@ def test_failsafe_response
CGI.expects(:new).raises('some multipart parsing failure')
ActionController::Routing::Routes.stubs(:reload)
- Dispatcher.stubs(:log_failsafe_exception)
+ Dispatcher.any_instance.stubs(:log_failsafe_exception)
assert_nothing_raised { dispatch }
@@ -65,13 +65,18 @@ def test_formatted_url_helper
formatted_polymorphic_url([@article, :pdf])
end
- # TODO: should this work?
- def xtest_format_option
+ def test_format_option
@article.save
- expects(:article_url).with(@article, :format => :pdf)
+ expects(:article_url).with(@article, :pdf)
polymorphic_url(@article, :format => :pdf)
end
+ def test_id_and_format_option
+ @article.save
+ expects(:article_url).with(:id => @article, :format => :pdf)
+ polymorphic_url(:id => @article, :format => :pdf)
+ end
+
def test_with_nested
@response.save
expects(:article_response_url).with(@article, @response)
@@ -76,6 +76,12 @@ def test_default_restful_routes
end
end
+ def test_override_paths_for_default_restful_actions
+ resource = ActionController::Resources::Resource.new(:messages,
+ :path_names => {:new => 'nuevo', :edit => 'editar'})
+ assert_equal resource.new_path, "#{resource.path}/nuevo"
+ end
+
def test_multiple_default_restful_routes
with_restful_routing :messages, :comments do
assert_simply_restful_for :messages
@@ -8,11 +8,17 @@ def self.unpacked_path
def initialize(name, options = {})
require 'rubygems' unless Object.const_defined?(:Gem)
- @name = name.to_s
- if options[:version]
+
+ if options[:requirement]
+ @requirement = options[:requirement]
+ elsif options[:version]
@requirement = Gem::Requirement.create(options[:version])
- @version = @requirement.instance_variable_get("@requirements").first.last
+ else
+ raise ArgumentError.new('Must pass either :version or :requirement')
end
+
+ @version = @requirement.instance_variable_get("@requirements").first.last if @requirement
+ @name = name.to_s
@lib = options[:lib]
@source = options[:source]
@loaded = @frozen = @load_paths_added = false
@@ -35,6 +41,14 @@ def add_load_paths
puts $!.to_s
end
+ def dependencies
+ all_dependencies = specification.dependencies.map do |dependency|
+ GemDependency.new(dependency.name, :requirement => dependency.version_requirements)
+ end
+ all_dependencies += all_dependencies.map(&:dependencies).flatten
+ all_dependencies.uniq
+ end
+
def gem_dir(base_directory)
File.join(base_directory, specification.full_name)
end
@@ -64,10 +78,6 @@ def install
Gem::GemRunner.new.run(install_command)
end
- def specification
- @spec ||= Gem.source_index.search(Gem::Dependency.new(@name, @requirement)).sort_by { |s| s.version }.last
- end
-
def unpack_to(directory)
FileUtils.mkdir_p directory
Dir.chdir directory do
@@ -83,6 +93,16 @@ def unpack_to(directory)
end
end
+ def ==(other)
+ self.name == other.name && self.requirement == other.requirement
+ end
+
+private ###################################################################
+
+ def specification
+ @spec ||= Gem.source_index.search(Gem::Dependency.new(@name, @requirement)).sort_by { |s| s.version }.last
+ end
+
def install_command
cmd = %w(install) << @name
cmd << "--version" << "#{@requirement.to_s}" if @requirement
@@ -38,14 +38,17 @@ namespace :rails do
end
end
- desc 'Lock to latest Edge Rails'
+ desc 'Lock to latest Edge Rails, for a specific release use RELEASE=1.2.0'
task :edge do
require 'open-uri'
+ version = ENV["RELEASE"] || "edge"
+ target = "rails_#{version}.zip"
+ url = "http://dev.rubyonrails.org/archives/#{target}"
chdir 'vendor' do
- puts 'Downloading Rails'
- File.open('rails_edge.zip', 'wb') do |dst|
- open 'http://dev.rubyonrails.org/archives/rails_edge.zip' do |src|
+ puts "Downloading Rails from #{url}"
+ File.open('rails.zip', 'wb') do |dst|
+ open url do |src|
while chunk = src.read(4096)
dst << chunk
end
@@ -54,8 +57,8 @@ namespace :rails do
puts 'Unpacking Rails'
rm_rf 'rails'
- `unzip rails_edge.zip`
- %w(rails_edge.zip rails/Rakefile rails/cleanlogs.sh rails/pushgems.rb rails/release.rb).each do |goner|
+ `unzip rails.zip`
+ %w(rails.zip rails/Rakefile rails/cleanlogs.sh rails/pushgems.rb rails/release.rb).each do |goner|
rm_f goner
end
end
@@ -39,4 +39,20 @@ namespace :gems do
gem.unpack_to(File.join(RAILS_ROOT, 'vendor', 'gems')) if gem.loaded?
end
end
+
+ namespace :unpack do
+ desc "Unpacks the specified gems and its dependencies into vendor/gems"
+ task :dependencies => :unpack do
+ require 'rubygems'
+ require 'rubygems/gem_runner'
+ Rails.configuration.gems.each do |gem|
+ next unless ENV['GEM'].blank? || ENV['GEM'] == gem.name
+ gem.dependencies.each do |dependency|
+ dependency.add_load_paths # double check that we have not already unpacked
+ next if dependency.frozen?
+ dependency.unpack_to(File.join(RAILS_ROOT, 'vendor', 'gems'))
+ end
+ end
+ end
+ end
end

0 comments on commit 342dcfe

Please sign in to comment.