mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge branch 'master' into testclean
* master: Add documentation for inheritance_column method Use ArgumentError vs. RuntimeError, which is more precise. CSV fixtures aren't supported by default anymore, update generated test_helper.rb to reflect that fix quoting for ActiveSupport::Duration instances Add few information on the field types Add the options method to action_controller testcase.
This commit is contained in:
commit
a7826bd8b7
9 changed files with 81 additions and 6 deletions
|
@ -15,7 +15,7 @@ module ActionMailer #:nodoc:
|
||||||
|
|
||||||
def any(*args, &block)
|
def any(*args, &block)
|
||||||
options = args.extract_options!
|
options = args.extract_options!
|
||||||
raise "You have to supply at least one format" if args.empty?
|
raise ArgumentError, "You have to supply at least one format" if args.empty?
|
||||||
args.each { |type| send(type, options.dup, &block) }
|
args.each { |type| send(type, options.dup, &block) }
|
||||||
end
|
end
|
||||||
alias :all :any
|
alias :all :any
|
||||||
|
|
|
@ -435,8 +435,13 @@ module ActionController
|
||||||
end
|
end
|
||||||
|
|
||||||
# Executes a request simulating HEAD HTTP method and set/volley the response
|
# Executes a request simulating HEAD HTTP method and set/volley the response
|
||||||
def head(action, parameters = nil, session = nil, flash = nil)
|
def head(action, *args)
|
||||||
process(action, "HEAD", parameters, session, flash)
|
process(action, "HEAD", *args)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Executes a request simulating OPTIONS HTTP method and set/volley the response
|
||||||
|
def options(action, *args)
|
||||||
|
process(action, "OPTIONS", *args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil)
|
def xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil)
|
||||||
|
|
|
@ -197,6 +197,11 @@ XML
|
||||||
assert_raise(NoMethodError) { head :test_params, "document body", :id => 10 }
|
assert_raise(NoMethodError) { head :test_params, "document body", :id => 10 }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_options
|
||||||
|
options :test_params
|
||||||
|
assert_equal 200, @response.status
|
||||||
|
end
|
||||||
|
|
||||||
def test_process_without_flash
|
def test_process_without_flash
|
||||||
process :set_flash
|
process :set_flash
|
||||||
assert_equal '><', flash['test']
|
assert_equal '><', flash['test']
|
||||||
|
|
|
@ -31,7 +31,7 @@ module ActiveRecord
|
||||||
# BigDecimals need to be put in a non-normalized form and quoted.
|
# BigDecimals need to be put in a non-normalized form and quoted.
|
||||||
when nil then "NULL"
|
when nil then "NULL"
|
||||||
when BigDecimal then value.to_s('F')
|
when BigDecimal then value.to_s('F')
|
||||||
when Numeric then value.to_s
|
when Numeric, ActiveSupport::Duration then value.to_s
|
||||||
when Date, Time then "'#{quoted_date(value)}'"
|
when Date, Time then "'#{quoted_date(value)}'"
|
||||||
when Symbol then "'#{quote_string(value.to_s)}'"
|
when Symbol then "'#{quote_string(value.to_s)}'"
|
||||||
when Class then "'#{value.to_s}'"
|
when Class then "'#{value.to_s}'"
|
||||||
|
|
|
@ -104,6 +104,8 @@ module ActiveRecord
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Defines the name of the table column which will store the class name on single-table
|
||||||
|
# inheritance situations.
|
||||||
def inheritance_column
|
def inheritance_column
|
||||||
'type'
|
'type'
|
||||||
end
|
end
|
||||||
|
|
|
@ -76,6 +76,12 @@ module ActiveRecord
|
||||||
date_string = Time.now.utc.strftime("%F")
|
date_string = Time.now.utc.strftime("%F")
|
||||||
assert_equal date_string, column.type_cast(date_string).strftime("%F")
|
assert_equal date_string, column.type_cast(date_string).strftime("%F")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_type_cast_duration_to_integer
|
||||||
|
column = Column.new("field", nil, "integer")
|
||||||
|
assert_equal 1800, column.type_cast(30.minutes)
|
||||||
|
assert_equal 7200, column.type_cast(2.hours)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -216,6 +216,14 @@ module ActiveRecord
|
||||||
def test_string_with_crazy_column
|
def test_string_with_crazy_column
|
||||||
assert_equal "'lo\\\\l'", @quoter.quote('lo\l', FakeColumn.new(:foo))
|
assert_equal "'lo\\\\l'", @quoter.quote('lo\l', FakeColumn.new(:foo))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_quote_duration
|
||||||
|
assert_equal "1800", @quoter.quote(30.minutes)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_quote_duration_int_column
|
||||||
|
assert_equal "7200", @quoter.quote(2.hours, FakeColumn.new(:integer))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@ class ActiveSupport::TestCase
|
||||||
<% unless options[:skip_active_record] -%>
|
<% unless options[:skip_active_record] -%>
|
||||||
ActiveRecord::Migration.check_pending!
|
ActiveRecord::Migration.check_pending!
|
||||||
|
|
||||||
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
||||||
#
|
#
|
||||||
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
||||||
# -- they do not yet inherit this setting
|
# -- they do not yet inherit this setting
|
||||||
|
|
|
@ -19,6 +19,55 @@ Description:
|
||||||
then the generator will create a module with a table_name_prefix method
|
then the generator will create a module with a table_name_prefix method
|
||||||
to prefix the model's table name with the module name (e.g. admin_account)
|
to prefix the model's table name with the module name (e.g. admin_account)
|
||||||
|
|
||||||
|
Available field types:
|
||||||
|
|
||||||
|
Just after the field name you can specify a type like text or boolean.
|
||||||
|
It will generate the column with the associated SQL type. For instance:
|
||||||
|
|
||||||
|
`rails generate model post title:string body:text`
|
||||||
|
|
||||||
|
will generate a title column with a varchar type and a body column with a text
|
||||||
|
type. You can use the following types:
|
||||||
|
|
||||||
|
integer
|
||||||
|
primary_key
|
||||||
|
decimal
|
||||||
|
float
|
||||||
|
boolean
|
||||||
|
binary
|
||||||
|
string
|
||||||
|
text
|
||||||
|
date
|
||||||
|
time
|
||||||
|
datetime
|
||||||
|
timestamp
|
||||||
|
|
||||||
|
You can also consider `references` as a kind of type. For instance, if you run:
|
||||||
|
|
||||||
|
`rails generate model photo title:string album:references`
|
||||||
|
|
||||||
|
It will generate an album_id column. You should generate this kind of fields when
|
||||||
|
you will use a `belongs_to` association for instance. `references` also support
|
||||||
|
the polymorphism, you could enable the polymorphism like this:
|
||||||
|
|
||||||
|
`rails generate model product supplier:references{polymorphic}`
|
||||||
|
|
||||||
|
You can also specify some options just after the field type. You can use the
|
||||||
|
following options:
|
||||||
|
|
||||||
|
limit Set the maximum size of the field giving a number between curly braces
|
||||||
|
default Set a default value for the field
|
||||||
|
precision Defines the precision for the decimal fields
|
||||||
|
scale Defines the scale for the decimal fields
|
||||||
|
uniq Defines the field values as unique
|
||||||
|
index Will add an index on the field
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
`rails generate model user pseudo:string{30}`
|
||||||
|
`rails generate model user pseudo:string:uniq`
|
||||||
|
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
`rails generate model account`
|
`rails generate model account`
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue