Skip to content

Commit

Permalink
Updated rails
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Camerer committed May 8, 2008
1 parent 1d74ab0 commit 8f89913
Show file tree
Hide file tree
Showing 46 changed files with 1,256 additions and 414 deletions.
3 changes: 3 additions & 0 deletions script/dbconsole
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/dbconsole'
58 changes: 58 additions & 0 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions vendor/rails/actionpack/lib/action_controller/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 3 additions & 5 deletions vendor/rails/actionpack/lib/action_controller/resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion vendor/rails/actionpack/lib/action_view/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
47 changes: 47 additions & 0 deletions vendor/rails/actionpack/test/controller/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
9 changes: 9 additions & 0 deletions vendor/rails/actionpack/test/controller/new_render_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] %>"
Expand Down Expand Up @@ -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
Expand Down
30 changes: 26 additions & 4 deletions vendor/rails/actionpack/test/controller/resources_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand Down
9 changes: 9 additions & 0 deletions vendor/rails/actionpack/test/template/form_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions vendor/rails/activerecord/CHANGELOG
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
22 changes: 22 additions & 0 deletions vendor/rails/activerecord/README
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion vendor/rails/activerecord/RUNNING_UNIT_TESTS
Original file line number Diff line number Diff line change
Expand Up @@ -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



Loading

0 comments on commit 8f89913

Please sign in to comment.