mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Merge commit 'mainstream/master'
Conflicts: actionpack/lib/action_controller/response.rb actionpack/lib/action_controller/test_case.rb actionpack/lib/action_controller/url_rewriter.rb activerecord/lib/active_record/associations.rb activesupport/lib/active_support/core_ext/time/conversions.rb railties/doc/guides/creating_plugins/acts_as_yaffle.txt railties/doc/guides/creating_plugins/creating_plugins.txt railties/doc/guides/creating_plugins/migration_generator.txt railties/doc/guides/creating_plugins/odds_and_ends.txt railties/doc/guides/creating_plugins/preparation.txt railties/doc/guides/creating_plugins/string_to_squawk.txt railties/doc/guides/creating_plugins/view_helper.txt railties/doc/guides/securing_rails_applications/creating_records_directly_from_form_parameters.txt railties/doc/guides/testing_rails_applications/testing_rails_applications.txt
This commit is contained in:
@@ -32,7 +32,7 @@ module ActionController # :nodoc:
|
||||
class AbstractResponse
|
||||
DEFAULT_HEADERS = { "Cache-Control" => "no-cache" }
|
||||
attr_accessor :request
|
||||
|
||||
|
||||
# The body content (e.g. HTML) of the response, as a String.
|
||||
attr_accessor :body
|
||||
# The headers of the response, as a Hash. It maps header names to header values.
|
||||
|
||||
@@ -25,7 +25,7 @@ module ActionController
|
||||
#
|
||||
# Functional tests are written as follows:
|
||||
# 1. First, one uses the +get+, +post+, +put+, +delete+ or +head+ method to simulate
|
||||
# an HTTP request.
|
||||
# an HTTP request.
|
||||
# 2. Then, one asserts whether the current state is as expected. "State" can be anything:
|
||||
# the controller's HTTP response, the database contents, etc.
|
||||
#
|
||||
@@ -35,11 +35,11 @@ module ActionController
|
||||
# def test_create
|
||||
# # Simulate a POST response with the given HTTP parameters.
|
||||
# post(:create, :book => { :title => "Love Hina" })
|
||||
#
|
||||
#
|
||||
# # Assert that the controller tried to redirect us to
|
||||
# # the created book's URI.
|
||||
# assert_response :found
|
||||
#
|
||||
#
|
||||
# # Assert that the controller really put the book in the database.
|
||||
# assert_not_nil Book.find_by_title("Love Hina")
|
||||
# end
|
||||
|
||||
@@ -19,7 +19,7 @@ module ActionController
|
||||
#
|
||||
# <%= link_to('Click here', :controller => 'users',
|
||||
# :action => 'new', :message => 'Welcome!') %>
|
||||
#
|
||||
#
|
||||
# #=> Generates a link to: /users/new?message=Welcome%21
|
||||
#
|
||||
# link_to, and all other functions that require URL generation functionality,
|
||||
@@ -74,7 +74,7 @@ module ActionController
|
||||
#
|
||||
# class User < ActiveRecord::Base
|
||||
# include ActionController::UrlWriter # !!!
|
||||
#
|
||||
#
|
||||
# def name=(value)
|
||||
# write_attribute('name', value)
|
||||
# write_attribute('base_uri', users_path) # !!!
|
||||
|
||||
@@ -741,7 +741,7 @@ module ActiveRecord
|
||||
# If false, don't validate the associated objects when saving the parent object. true by default.
|
||||
# [:accessible]
|
||||
# Mass assignment is allowed for this assocation (similar to <tt>ActiveRecord::Base#attr_accessible</tt>).
|
||||
|
||||
|
||||
# Option examples:
|
||||
# has_many :comments, :order => "posted_on"
|
||||
# has_many :comments, :include => :author
|
||||
|
||||
@@ -30,7 +30,7 @@ module ActiveSupport #:nodoc:
|
||||
# time.to_s(:time) # => "06:10:17"
|
||||
#
|
||||
# time.to_formatted_s(:db) # => "2007-01-18 06:10:17"
|
||||
# time.to_formatted_s(:number) # => "20070118061017"
|
||||
# time.to_formatted_s(:number) # => "20070118061017"
|
||||
# time.to_formatted_s(:short) # => "18 Jan 06:10"
|
||||
# time.to_formatted_s(:long) # => "January 18, 2007 06:10"
|
||||
# time.to_formatted_s(:long_ordinal) # => "January 18th, 2007 06:10"
|
||||
|
||||
@@ -17,7 +17,7 @@ end
|
||||
class ActsAsYaffleTest < Test::Unit::TestCase
|
||||
end
|
||||
------------------------------------------------------
|
||||
|
||||
|
||||
[source, ruby]
|
||||
------------------------------------------------------
|
||||
# File: vendor/plugins/lib/acts_as_yaffle.rb
|
||||
@@ -40,11 +40,11 @@ module Yaffle
|
||||
def acts_as_something
|
||||
send :include, InstanceMethods
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
# any method placed here will apply to instaces, like @hickwall
|
||||
end
|
||||
end
|
||||
end
|
||||
------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
The Basics of Creating Rails Plugins
|
||||
====================================
|
||||
|
||||
Pretend for a moment that you are an avid bird watcher. Your favorite bird is the Yaffle, and you want to create a plugin that allows other developers to share in the Yaffle goodness.
|
||||
Pretend for a moment that you are an avid bird watcher. Your favorite bird is the Yaffle, and you want to create a plugin that allows other developers to share in the Yaffle goodness.
|
||||
|
||||
In this tutorial you will learn how to create a plugin that includes:
|
||||
|
||||
@@ -56,7 +56,7 @@ ActionController::Routing::Routes.draw do |map|
|
||||
map.yaffles
|
||||
end
|
||||
-------------------------------------------
|
||||
|
||||
|
||||
In addition you'll learn how to:
|
||||
|
||||
* test your plugins.
|
||||
|
||||
@@ -7,7 +7,7 @@ We'll be relying on the built-in rails generate template for this tutorial. Goi
|
||||
Type:
|
||||
|
||||
script/generate
|
||||
|
||||
|
||||
You should see the line:
|
||||
|
||||
Plugins (vendor/plugins): yaffle
|
||||
@@ -34,13 +34,13 @@ Now you can add code to your generator:
|
||||
class YaffleGenerator < Rails::Generator::NamedBase
|
||||
def manifest
|
||||
record do |m|
|
||||
m.migration_template 'migration:migration.rb', "db/migrate", {:assigns => yaffle_local_assigns,
|
||||
m.migration_template 'migration:migration.rb', "db/migrate", {:assigns => yaffle_local_assigns,
|
||||
:migration_file_name => "add_yaffle_fields_to_#{custom_file_name}"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
def custom_file_name
|
||||
custom_name = class_name.underscore.downcase
|
||||
custom_name = custom_name.pluralize if ActiveRecord::Base.pluralize_table_names
|
||||
@@ -68,7 +68,7 @@ This does a few things:
|
||||
When you run the generator like
|
||||
|
||||
script/generate yaffle bird
|
||||
|
||||
|
||||
You will see a new file:
|
||||
|
||||
[source, ruby]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
=== Work with init.rb ===
|
||||
|
||||
The plugin initializer script 'init.rb' is invoked via `eval` (not `require`) so it has slightly different behavior.
|
||||
The plugin initializer script 'init.rb' is invoked via `eval` (not `require`) so it has slightly different behavior.
|
||||
|
||||
If you reopen any classes in init.rb itself your changes will potentially be made to the wrong module. There are 2 ways around this:
|
||||
|
||||
@@ -21,7 +21,7 @@ end
|
||||
|
||||
OR you can use `module_eval` or `class_eval`:
|
||||
|
||||
---------------------------------------------------
|
||||
---------------------------------------------------
|
||||
# File: vendor/plugins/yaffle/init.rb
|
||||
|
||||
Hash.class_eval do
|
||||
|
||||
@@ -123,7 +123,7 @@ ActiveRecord::Schema.define(:version => 0) do
|
||||
end
|
||||
|
||||
# File: vendor/plugins/yaffle/test/test_helper.rb
|
||||
|
||||
|
||||
ENV['RAILS_ENV'] = 'test'
|
||||
ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..'
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ Your test should fail with `no such file to load -- ./test/../lib/core_ext.rb (L
|
||||
1.) Failure ...
|
||||
No tests were specified
|
||||
--------------------------------------------------------
|
||||
|
||||
|
||||
Great - now you are ready to start development. The first thing we'll do is to add a method to String called `to_squawk` which will prefix the string with the word ``squawk!''. The test will look something like this:
|
||||
|
||||
[source, ruby]
|
||||
@@ -73,14 +73,14 @@ end
|
||||
--------------------------------------------------------
|
||||
|
||||
[source, ruby]
|
||||
--------------------------------------------------------
|
||||
--------------------------------------------------------
|
||||
# File: vendor/plugins/yaffle/init.rb
|
||||
|
||||
require "core_ext"
|
||||
--------------------------------------------------------
|
||||
--------------------------------------------------------
|
||||
|
||||
[source, ruby]
|
||||
--------------------------------------------------------
|
||||
--------------------------------------------------------
|
||||
# File: vendor/plugins/yaffle/lib/core_ext.rb
|
||||
|
||||
String.class_eval do
|
||||
|
||||
@@ -36,7 +36,7 @@ require "view_helpers"
|
||||
ActionView::Base.send :include, YaffleViewHelper
|
||||
---------------------------------------------------------------
|
||||
|
||||
Then add the view helpers file and
|
||||
Then add the view helpers file and
|
||||
|
||||
[source, ruby]
|
||||
---------------------------------------------------------------
|
||||
|
||||
@@ -9,7 +9,7 @@ CREATE TABLE users (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name VARCHAR(20) NOT NULL, -- the login name
|
||||
password VARCHAR(20) NOT NULL,
|
||||
role VARCHAR(20) NOT NULL DEFAULT "User", -- e.g. "Admin", "Moderator, "User"
|
||||
role VARCHAR(20) NOT NULL DEFAULT "User", -- e.g. "Admin", "Moderator, "User"
|
||||
approved INTEGER NOT NULL DEFAULT 0 -- is the registered accound approved by the administrator?
|
||||
);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ Make sure you have Ruby 1.8.6 or greater and Rails 2.0 or greater.
|
||||
Also, hats off to xal (and others) for creating this site.
|
||||
|
||||
|
||||
== Testing 1-2-3... is this thing on?
|
||||
== Testing 1-2-3... is this thing on?
|
||||
|
||||
=== What are These Strange Creatures?
|
||||
|
||||
@@ -212,7 +212,7 @@ class SecretAgent
|
||||
attr_accessor :username
|
||||
attr_accessor :password
|
||||
|
||||
# our "constructor"
|
||||
# our "constructor"
|
||||
def initialize(username,password)
|
||||
@username = username
|
||||
@password = password
|
||||
@@ -323,7 +323,7 @@ test_bam_zap_sock_pow(HelloTestCase) [/example/test.rb:62]:
|
||||
|
||||
2) Error:
|
||||
test_uh_oh_hotdog(HelloTestCase):
|
||||
NameError: undefined local variable or method 'does_this_var_speak_korean' for
|
||||
NameError: undefined local variable or method 'does_this_var_speak_korean' for
|
||||
#<HelloTestCase:0x28c59a0> /example/test.rb:68:in 'test_uh_oh_hotdog'
|
||||
|
||||
4 tests, 12 assertions, 1 failures, 1 errors
|
||||
@@ -618,9 +618,9 @@ On any given Sunday, a YAML fixture file may look like this:
|
||||
---------------------------------------------
|
||||
# low & behold! I am a YAML comment!
|
||||
david:
|
||||
id: 1
|
||||
name: David Heinemeier Hansson
|
||||
birthday: 1979-10-15
|
||||
id: 1
|
||||
name: David Heinemeier Hansson
|
||||
birthday: 1979-10-15
|
||||
profession: Systems development
|
||||
|
||||
steve:
|
||||
@@ -640,9 +640,9 @@ A CSV fixture looks like this:
|
||||
|
||||
--------------------------------------------------------------
|
||||
id, username, password, stretchable, comments
|
||||
1, sclaus, ihatekids, false, I like to say ""Ho! Ho! Ho!""
|
||||
1, sclaus, ihatekids, false, I like to say ""Ho! Ho! Ho!""
|
||||
2, ebunny, ihateeggs, true, Hoppity hop y'all
|
||||
3, tfairy, ilovecavities, true, "Pull your teeth, I will"
|
||||
3, tfairy, ilovecavities, true, "Pull your teeth, I will"
|
||||
--------------------------------------------------------------
|
||||
|
||||
The first line is the header. It is a comma-separated list of fields. The rest of the file is the payload: 1 record per line. A few notes about this format:
|
||||
@@ -916,7 +916,7 @@ For example, let's say we have a `MoviesController` with an action called `movie
|
||||
def movie
|
||||
@movie = Movie.find(params[:id])
|
||||
if @movie.nil?
|
||||
flash['message'] = "That movie has been burned."
|
||||
flash['message'] = "That movie has been burned."
|
||||
redirect_to :controller => 'error', :action => 'missing'
|
||||
end
|
||||
end
|
||||
@@ -928,7 +928,7 @@ Now, to test out if the proper movie is being set, we could have a series of tes
|
||||
----------------------------------------------------
|
||||
# this test proves that fetching a movie works
|
||||
def test_successfully_finding_a_movie
|
||||
get :movie, "id" => "1"
|
||||
get :movie, "id" => "1"
|
||||
assert_not_nil assigns["movie"]
|
||||
assert_equal 1, assigns["movie"].id
|
||||
assert flash.empty?
|
||||
@@ -936,7 +936,7 @@ end
|
||||
|
||||
# and when we can't find a movie...
|
||||
def test_movie_not_found
|
||||
get :movie, "id" => "666999"
|
||||
get :movie, "id" => "666999"
|
||||
assert_nil assigns["movie"]
|
||||
assert flash.has_key?("message")
|
||||
assert assigns.empty?
|
||||
@@ -966,7 +966,7 @@ Ensures the expected template was responsible for rendering. For example:
|
||||
+
|
||||
[source, ruby]
|
||||
--------------------------------------
|
||||
assert_template "user/profile"
|
||||
assert_template "user/profile"
|
||||
--------------------------------------
|
||||
+
|
||||
This code will fail unless the template located at app/views/user/profile.rhtml was rendered.
|
||||
@@ -1035,9 +1035,9 @@ These examples are taken from the same docs too:
|
||||
[source, ruby]
|
||||
-------------------------------------------------------------
|
||||
# assert that there is a "span" tag
|
||||
assert_tag :tag => "span"
|
||||
assert_tag :tag => "span"
|
||||
|
||||
# assert that there is a "span" inside of a "div"
|
||||
# assert that there is a "span" inside of a "div"
|
||||
assert_tag :tag => "span", :parent => { :tag => "div" }
|
||||
|
||||
# assert that there is a "span" somewhere inside a table
|
||||
@@ -1272,7 +1272,7 @@ require 'my_mailer'
|
||||
class MyMailerTest < Test::Unit::TestCase
|
||||
fixtures :users
|
||||
FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
|
||||
CHARSET = "utf-8"
|
||||
CHARSET = "utf-8"
|
||||
|
||||
include ActionMailer::Quoting
|
||||
|
||||
@@ -1358,7 +1358,7 @@ class ActionMailer::Base
|
||||
mail.to = destinations
|
||||
if destinations.size > 0
|
||||
mail.ready_to_send
|
||||
Net::SMTP.start(server_settings[:address], server_settings[:port], server_settings[:domain],
|
||||
Net::SMTP.start(server_settings[:address], server_settings[:port], server_settings[:domain],
|
||||
server_settings[:user_name], server_settings[:password], server_settings[:authentication]) do |smtp|
|
||||
smtp.sendmail(mail.encoded, mail.from, destinations)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user