Permalink
Browse files

Updated rails

  • Loading branch information...
1 parent 1d74ab0 commit 8f899135f9b645aa8069e21d7705239f2be44a8c Justin Camerer committed May 8, 2008
Showing with 1,256 additions and 414 deletions.
  1. +3 −0 script/dbconsole
  2. +58 −0 spec/controllers/users_controller_spec.rb
  3. +3 −3 vendor/rails/actionpack/lib/action_controller/base.rb
  4. +3 −5 vendor/rails/actionpack/lib/action_controller/resources.rb
  5. +3 −3 vendor/rails/actionpack/lib/action_controller/routing/optimisations.rb
  6. +1 −1 vendor/rails/actionpack/lib/action_view/base.rb
  7. +9 −5 vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb
  8. +47 −0 vendor/rails/actionpack/test/controller/base_test.rb
  9. +9 −0 vendor/rails/actionpack/test/controller/new_render_test.rb
  10. +26 −4 vendor/rails/actionpack/test/controller/resources_test.rb
  11. +9 −0 vendor/rails/actionpack/test/template/form_helper_test.rb
  12. +9 −0 vendor/rails/activerecord/CHANGELOG
  13. +22 −0 vendor/rails/activerecord/README
  14. +4 −1 vendor/rails/activerecord/RUNNING_UNIT_TESTS
  15. +6 −1 vendor/rails/activerecord/lib/active_record/association_preload.rb
  16. +24 −1 vendor/rails/activerecord/lib/active_record/associations.rb
  17. +2 −2 vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb
  18. +1 −12 vendor/rails/activerecord/lib/active_record/base.rb
  19. +190 −0 vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
  20. +81 −6 vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
  21. +6 −3 vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
  22. +10 −9 vendor/rails/activerecord/test/cases/adapter_test.rb
  23. +4 −0 vendor/rails/activerecord/test/cases/associations/eager_test.rb
  24. +6 −0 vendor/rails/activerecord/test/cases/associations_test.rb
  25. +9 −0 vendor/rails/activerecord/test/cases/finder_test.rb
  26. +225 −1 vendor/rails/activerecord/test/cases/migration_test.rb
  27. +104 −107 vendor/rails/activerecord/test/cases/schema_dumper_test.rb
  28. +4 −0 vendor/rails/activerecord/test/models/developer.rb
  29. +2 −0 vendor/rails/activerecord/test/models/post.rb
  30. +2 −0 vendor/rails/activesupport/CHANGELOG
  31. +2 −10 vendor/rails/activesupport/lib/active_support/core_ext/kernel/daemonizing.rb
  32. +1 −0 vendor/rails/activesupport/lib/active_support/core_ext/process.rb
  33. +25 −0 vendor/rails/activesupport/lib/active_support/core_ext/process/daemon.rb
  34. +14 −0 vendor/rails/activesupport/lib/active_support/deprecation.rb
  35. +6 −0 vendor/rails/activesupport/lib/active_support/ordered_options.rb
  36. +222 −217 vendor/rails/activesupport/lib/active_support/values/time_zone.rb
  37. +3 −3 vendor/rails/activesupport/lib/active_support/whiny_nil.rb
  38. +10 −0 vendor/rails/activesupport/test/deprecation_test.rb
  39. +13 −0 vendor/rails/activesupport/test/ordered_options_test.rb
  40. +4 −0 vendor/rails/railties/CHANGELOG
  41. +3 −0 vendor/rails/railties/bin/dbconsole
  42. +55 −0 vendor/rails/railties/lib/commands/dbconsole.rb
  43. +8 −8 vendor/rails/railties/lib/commands/servers/mongrel.rb
  44. +2 −1 vendor/rails/railties/lib/rails/plugin/locator.rb
  45. +1 −1 vendor/rails/railties/lib/rails_generator/generators/applications/app/app_generator.rb
  46. +5 −10 vendor/rails/railties/lib/tasks/databases.rake
View
@@ -0,0 +1,3 @@
+#!/usr/bin/env ruby
+require File.dirname(__FILE__) + '/../config/boot'
+require 'commands/dbconsole'
@@ -0,0 +1,58 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+# Be sure to include AuthenticatedTestHelper in spec/spec_helper.rb instead
+# Then, you can remove it from this and the units test.
+include AuthenticatedTestHelper
+
+describe UsersController do
+ fixtures :users
+ fixtures :roles
+
+ describe 'when logged in as an admin' do
+ before(:each) do
+ login_as(:iamjwc)
+ end
+
+ it 'should display a list of the users' do
+ get :index
+ response.should_not be_redirect
+ end
+
+ it 'should be able to create new users' do
+ lambda do
+ create_user
+ response.should be_redirect
+ end.should change(User, :count).by(1)
+ end
+
+ it 'should be able to suspend and unsuspend a user' do
+ user = users(:activated)
+ user.suspended?.should be_false
+
+ put :suspend, :id => user.id
+
+ user.reload
+ user.suspended?.should be_true
+
+ put :unsuspend, :id => user.id
+
+ user.reload
+ user.suspended?.should be_false
+ end
+
+ it 'should be able to send a user a password reset code' do
+ user = users(:activated)
+ user.password_reset_code.should be_nil
+
+ put :reset_password, :id => user.id
+
+ user.reload
+ user.password_reset_code.should_not be_nil
+ end
+ end
+
+ def create_user(options = {})
+ post :create, :user => { :login => 'quire', :email => 'quire@example.com',
+ :password => 'quire', :password_confirmation => 'quire' }.merge(options)
+ end
+end
@@ -532,9 +532,9 @@ def process(request, response, method = :perform_action, *arguments) #:nodoc:
# Returns a URL that has been rewritten according to the options hash and the defined Routes.
# (For doing a complete redirect, use redirect_to).
- #  
+ #
# <tt>url_for</tt> is used to:
- #  
+ #
# All keys given to url_for are forwarded to the Route module, save for the following:
# * <tt>:anchor</tt> -- specifies the anchor name to be appended to the path. For example,
# <tt>url_for :controller => 'posts', :action => 'show', :id => 10, :anchor => 'comments'</tt>
@@ -998,7 +998,7 @@ def rewrite_options(options) #:nodoc:
# As you can infer from the example, this is mostly useful for situations where you want to centralize dynamic decisions about the
# urls as they stem from the business domain. Please note that any individual url_for call can always override the defaults set
# by this method.
- def default_url_options(options) #:doc:
+ def default_url_options(options = nil)
end
# Redirects the browser to the target specified in +options+. This parameter can take one of three forms:
@@ -524,11 +524,9 @@ 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)
- action_path = action
- if resource.options[:path_names]
- action_path = resource.options[:path_names][action]
- action_path ||= Base.resources_path_names[action] || action
- end
+
+ action_path = resource.options[:path_names][action] if resource.options[:path_names].is_a?(Hash)
+ action_path ||= Base.resources_path_names[action] || action
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)
@@ -61,9 +61,9 @@ def guard_condition
# if they're using foo_url(:id=>2) it's one
# argument, but we don't want to generate /foos/id2
if number_of_arguments == 1
- "defined?(request) && request && args.size == 1 && !args.first.is_a?(Hash)"
+ "(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == 1 && !args.first.is_a?(Hash)"
else
- "defined?(request) && request && args.size == #{number_of_arguments}"
+ "(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == #{number_of_arguments}"
end
end
@@ -98,7 +98,7 @@ def generation_code
# argument
class PositionalArgumentsWithAdditionalParams < PositionalArguments
def guard_condition
- "defined?(request) && request && args.size == #{route.segment_keys.size + 1} && !args.last.has_key?(:anchor) && !args.last.has_key?(:port) && !args.last.has_key?(:host)"
+ "(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == #{route.segment_keys.size + 1} && !args.last.has_key?(:anchor) && !args.last.has_key?(:port) && !args.last.has_key?(:host)"
end
# This case uses almost the same code as positional arguments,
@@ -185,7 +185,7 @@ class Base
attr_internal :request
delegate :request_forgery_protection_token, :template, :params, :session, :cookies, :response, :headers,
- :flash, :logger, :to => :controller
+ :flash, :logger, :action_name, :to => :controller
module CompiledTemplates #:nodoc:
# holds compiled template code
@@ -614,23 +614,27 @@ def add_default_name_and_id(options)
end
def tag_name
- "#{@object_name}[#{@method_name}]"
+ "#{@object_name}[#{sanitized_method_name}]"
end
def tag_name_with_index(index)
- "#{@object_name}[#{index}][#{@method_name}]"
+ "#{@object_name}[#{index}][#{sanitized_method_name}]"
end
def tag_id
- "#{sanitized_object_name}_#{@method_name}"
+ "#{sanitized_object_name}_#{sanitized_method_name}"
end
def tag_id_with_index(index)
- "#{sanitized_object_name}_#{index}_#{@method_name}"
+ "#{sanitized_object_name}_#{index}_#{sanitized_method_name}"
end
def sanitized_object_name
- @object_name.gsub(/[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
+ @sanitized_object_name ||= @object_name.gsub(/[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
+ end
+
+ def sanitized_method_name
+ @sanitized_method_name ||= @method_name.sub(/\?$/,"")
end
end
@@ -48,6 +48,15 @@ def method_missing(selector)
end
+class DefaultUrlOptionsController < ActionController::Base
+ def default_url_options_action
+ end
+
+ def default_url_options(options = nil)
+ { :host => 'www.override.com', :action => 'new', :bacon => 'chunky' }
+ end
+end
+
class ControllerClassTests < Test::Unit::TestCase
def test_controller_path
assert_equal 'empty', EmptyController.controller_path
@@ -134,3 +143,41 @@ def test_get_on_hidden_should_fail
assert_response 404
end
end
+
+class DefaultUrlOptionsTest < Test::Unit::TestCase
+ def setup
+ @controller = DefaultUrlOptionsController.new
+
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+
+ @request.host = 'www.example.com'
+ end
+
+ def test_default_url_options_are_used_if_set
+ ActionController::Routing::Routes.draw do |map|
+ map.default_url_options 'default_url_options', :controller => 'default_url_options'
+ map.connect ':controller/:action/:id'
+ end
+
+ get :default_url_options_action # Make a dummy request so that the controller is initialized properly.
+
+ assert_equal 'http://www.override.com/default_url_options/new?bacon=chunky', @controller.url_for(:controller => 'default_url_options')
+ assert_equal 'http://www.override.com/default_url_options?bacon=chunky', @controller.send(:default_url_options_url)
+ ensure
+ ActionController::Routing::Routes.load!
+ end
+end
+
+class EnsureNamedRoutesWorksTicket22BugTest < Test::Unit::TestCase
+ def test_named_routes_still_work
+ ActionController::Routing::Routes.draw do |map|
+ map.resources :things
+ end
+ EmptyController.send :include, ActionController::UrlWriter
+
+ assert_equal '/things', EmptyController.new.send(:things_path)
+ ensure
+ ActionController::Routing::Routes.load!
+ end
+end
@@ -246,6 +246,10 @@ def accessing_request_in_template
def accessing_logger_in_template
render :inline => "<%= logger.class %>"
end
+
+ def accessing_action_name_in_template
+ render :inline => "<%= action_name %>"
+ end
def accessing_params_in_template_with_layout
render :layout => nil, :inline => "Hello: <%= params[:name] %>"
@@ -545,6 +549,11 @@ def test_access_to_logger_in_view
get :accessing_logger_in_template
assert_equal "Logger", @response.body
end
+
+ def test_access_to_action_name_in_view
+ get :accessing_action_name_in_template
+ assert_equal "accessing_action_name_in_template", @response.body
+ end
def test_render_xml
get :render_xml_hello
@@ -226,6 +226,28 @@ def test_member_when_override_paths_for_default_restful_actions_with
end
end
+ def test_member_when_changed_default_restful_actions_and_path_names_not_specified
+ default_path_names = ActionController::Base.resources_path_names
+ ActionController::Base.resources_path_names = {:new => 'nuevo', :edit => 'editar'}
+
+ with_restful_routing :messages do
+ new_options = { :action => 'new', :controller => 'messages' }
+ new_path = "/messages/nuevo"
+ edit_options = { :action => 'edit', :id => '1', :controller => 'messages' }
+ edit_path = "/messages/1/editar"
+
+ assert_restful_routes_for :messages do |options|
+ assert_recognizes(options.merge(new_options), :path => new_path, :method => :get)
+ end
+
+ assert_restful_routes_for :messages do |options|
+ assert_recognizes(options.merge(edit_options), :path => edit_path, :method => :get)
+ end
+ end
+ ensure
+ ActionController::Base.resources_path_names = default_path_names
+ end
+
def test_with_two_member_actions_with_same_method
[:put, :post].each do |method|
with_restful_routing :messages, :member => { :mark => method, :unmark => method } do
@@ -691,11 +713,11 @@ def assert_restful_routes_for(controller_name, options = {})
options[:options] ||= {}
options[:options][:controller] = options[:controller] || controller_name.to_s
- new_action = "new"
- edit_action = "edit"
+ new_action = ActionController::Base.resources_path_names[:new] || "new"
+ edit_action = ActionController::Base.resources_path_names[:edit] || "edit"
if options[:path_names]
- new_action = options[:path_names][:new] || "new"
- edit_action = options[:path_names][:edit] || "edit"
+ new_action = options[:path_names][:new] if options[:path_names][:new]
+ edit_action = options[:path_names][:edit] if options[:path_names][:edit]
end
collection_path = "/#{options[:path_prefix]}#{options[:as] || controller_name}"
@@ -6,6 +6,7 @@
alias_method :title_before_type_cast, :title unless respond_to?(:title_before_type_cast)
alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast)
alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast)
+ alias_method :secret?, :secret
def new_record=(boolean)
@new_record = boolean
@@ -71,10 +72,12 @@ def test_label
'<label class="title_label" for="post_title">Title</label>',
label("post", "title", nil, :class => 'title_label')
)
+ assert_dom_equal('<label for="post_secret">Secret?</label>', label("post", "secret?"))
end
def test_label_with_symbols
assert_dom_equal('<label for="post_title">Title</label>', label(:post, :title))
+ assert_dom_equal('<label for="post_secret">Secret?</label>', label(:post, :secret?))
end
def test_label_with_for_attribute_as_symbol
@@ -140,6 +143,8 @@ def test_text_field_doesnt_change_param_values
def test_hidden_field
assert_dom_equal '<input id="post_title" name="post[title]" type="hidden" value="Hello World" />',
hidden_field("post", "title")
+ assert_dom_equal '<input id="post_secret" name="post[secret]" type="hidden" value="1" />',
+ hidden_field("post", "secret?")
end
def test_hidden_field_with_escapes
@@ -172,6 +177,10 @@ def test_check_box
'<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
check_box("post", "secret")
)
+ assert_dom_equal(
+ '<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
+ check_box("post", "secret?")
+ )
end
def test_check_box_with_explicit_checked_and_unchecked_values
@@ -1,5 +1,14 @@
*SVN*
+* Added change_table for migrations (Jeff Dean) [#71]. Example:
+
+ change_table :videos do |t|
+ t.timestamps # adds created_at, updated_at
+ t.belongs_to :goat # add goat_id integer
+ t.string :name, :email, :limit => 20 # adds name and email both with a 20 char limit
+ t.remove :name, :email # removes the name and email columns
+ end
+
* Fixed has_many :through .create with no parameters caused a "can't dup NilClass" error (Steven Soroka) [#85]
* Added block-setting of attributes for Base.create like Base.new already has (Adam Meehan) [#39]
@@ -164,6 +164,28 @@ A short rundown of the major features:
ActiveRecord::Base.logger = Log4r::Logger.new("Application Log")
+* Database agnostic schema management with Migrations
+
+ class AddSystemSettings < ActiveRecord::Migration
+ def self.up
+ create_table :system_settings do |t|
+ t.string :name
+ t.string :label
+ t.text :value
+ t.string :type
+ t.integer :position
+ end
+
+ SystemSetting.create :name => "notice", :label => "Use notice?", :value => 1
+ end
+
+ def self.down
+ drop_table :system_settings
+ end
+ end
+
+ {Learn more}[link:classes/ActiveRecord/Migration.html]
+
== Simple example (1/2): Defining tables and classes (using MySQL)
Data definitions are specified only in the database. Active Record queries the database for
@@ -27,7 +27,10 @@ you can do so with:
rake test_mysql TEST=test/cases/base_test.rb
-That'll run the base suite using the MySQL-Ruby adapter.
+That'll run the base suite using the MySQL-Ruby adapter. Some tests rely on the schema
+being initialized - you can initialize the schema with:
+
+ rake test_mysql TEST=test/cases/aaa_create_tables_test.rb
Oops, something went wrong.

0 comments on commit 8f89913

Please sign in to comment.