提交 bf48af53 编写于 作者: A Aaron Patterson

Merge branch 'master' into set_binds

* master: (24 commits)
  unscope should remove bind values associated with the where
  reverse_order_value= is not private, so no need to send
  avoid more dynamic symbols
  no need to to_sym
  recover from test runs that leave the database in a bad state
  updates screenshot data [ci skip]
  "serie" => "series"
  revises a few things in the getting started guide [ci skip]
  Favor canonical environment variables for secrets
  removed extra comma [ci skip]
  Only lookup `config.log_level` for stdlib `::Logger`. Closes #11665.
  Updated Changelog to reflect removal of :dependent => :restrict
  standardize on jruby_skip & rbx_skip
  fix bug in becomes! when changing from base to subclass. Closes #13272.
  highlight http://localhost:3000 in README.md. Closes #13643. [ci skip]
  doc proc/lambda arg on inclusion validation. Closes #13689. [ci skip]
  Skip Spring App Generator tests on JRuby
  fixes a typo in a CHANGELOG
  upgrade SDoc
  fixes the Gemfile generator templates
  ...

Conflicts:
	activerecord/test/cases/hot_compatibility_test.rb
......@@ -18,7 +18,7 @@ gem 'coffee-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0', require: false
group :doc do
gem 'sdoc'
gem 'sdoc', '~> 0.4.0'
gem 'redcarpet', '~> 2.2.2', platforms: :ruby
gem 'w3c_validators'
gem 'kindlerb'
......
......@@ -59,7 +59,8 @@ independently outside Rails.
Run with `--help` or `-h` for options.
4. Using a browser, go to http://localhost:3000 and you'll see: "Welcome aboard: You're riding Ruby on Rails!"
4. Using a browser, go to `http://localhost:3000` and you'll see:
"Welcome aboard: You're riding Ruby on Rails!"
5. Follow the guidelines to start developing your application. You may find
the following resources handy:
......
......@@ -674,7 +674,7 @@ def attachments
# For example:
#
# class Notifier < ActionMailer::Base
# default from: 'no-reply@test.lindsaar.net',
# default from: 'no-reply@test.lindsaar.net'
#
# def welcome
# mail(to: 'mikel@test.lindsaar.net')
......
......@@ -62,3 +62,12 @@ def set_delivery_method(method)
def restore_delivery_method
ActionMailer::Base.delivery_method = @old_delivery_method
end
# Skips the current run on Rubinius using Minitest::Assertions#skip
def rubinius_skip(message = '')
skip message if RUBY_ENGINE == 'rbx'
end
# Skips the current run on JRuby using Minitest::Assertions#skip
def jruby_skip(message = '')
skip message if defined?(JRUBY_VERSION)
end
......@@ -351,3 +351,12 @@ class ProductsController < ResourcesController; end
class ImagesController < ResourcesController; end
end
end
# Skips the current run on Rubinius using Minitest::Assertions#skip
def rubinius_skip(message = '')
skip message if RUBY_ENGINE == 'rbx'
end
# Skips the current run on JRuby using Minitest::Assertions#skip
def jruby_skip(message = '')
skip message if defined?(JRUBY_VERSION)
end
......@@ -37,10 +37,8 @@ def test_serves_static_index_file_in_directory
end
def test_served_static_file_with_non_english_filename
if RUBY_ENGINE == 'jruby '
skip "Stop skipping if following bug gets fixed: " \
jruby_skip "Stop skipping if following bug gets fixed: " \
"http://jira.codehaus.org/browse/JRUBY-7192"
end
assert_html "means hello in Japanese\n", get("/foo/#{Rack::Utils.escape("こんにちは.html")}")
end
......
......@@ -331,3 +331,11 @@ def stderr_logger
end
end
# Skips the current run on Rubinius using Minitest::Assertions#skip
def rubinius_skip(message = '')
skip message if RUBY_ENGINE == 'rbx'
end
# Skips the current run on JRuby using Minitest::Assertions#skip
def jruby_skip(message = '')
skip message if defined?(JRUBY_VERSION)
end
......@@ -182,7 +182,7 @@ def with_collection_check_boxes(*args, &block)
end
# COLLECTION CHECK BOXES
test 'collection check boxes accepts a collection and generate a serie of checkboxes for value method' do
test 'collection check boxes accepts a collection and generate a series of checkboxes for value method' do
collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')]
with_collection_check_boxes :user, :category_ids, collection, :id, :name
......@@ -204,7 +204,7 @@ def with_collection_check_boxes(*args, &block)
assert_select "input[type=hidden][name='user[other_category_ids][]'][value=]", :count => 1
end
test 'collection check boxes accepts a collection and generate a serie of checkboxes with labels for label method' do
test 'collection check boxes accepts a collection and generate a series of checkboxes with labels for label method' do
collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')]
with_collection_check_boxes :user, :category_ids, collection, :id, :name
......
......@@ -29,7 +29,8 @@ module HelperMethods
# * <tt>:in</tt> - An enumerable object of available items. This can be
# supplied as a proc, lambda or symbol which returns an enumerable. If the
# enumerable is a numerical range the test is performed with <tt>Range#cover?</tt>,
# otherwise with <tt>include?</tt>.
# otherwise with <tt>include?</tt>. When using a proc or lambda the instance
# under validation is passed as an argument.
# * <tt>:within</tt> - A synonym(or alias) for <tt>:in</tt>
# * <tt>:message</tt> - Specifies a custom error message (default is: "is
# not included in the list").
......
* Fix bug in `becomes!` when changing from the base model to a STI sub-class.
Fixes #13272.
*the-web-dev*, *Yves Senn*
* Currently Active Record can be configured via the environment variable
`DATABASE_URL` or by manually injecting a hash of values which is what Rails does,
reading in `database.yml` and setting Active Record appropriately. Active Record
......
......@@ -87,6 +87,9 @@ def enum(definitions)
# def status() STATUS.key self[:status] end
define_method(name) { enum_values.key self[name] }
# def status_before_type_cast() STATUS.key self[:status] end
define_method("#{name}_before_type_cast") { enum_values.key self[name] }
pairs = values.respond_to?(:each_pair) ? values.each_pair : values.each_with_index
pairs.each do |value, i|
enum_values[value] = i
......
......@@ -196,7 +196,11 @@ def becomes(klass)
# share the same set of attributes.
def becomes!(klass)
became = becomes(klass)
became.public_send("#{klass.inheritance_column}=", klass.sti_name) unless self.class.descends_from_active_record?
sti_type = nil
if !klass.descends_from_active_record?
sti_type = klass.sti_name
end
became.public_send("#{klass.inheritance_column}=", sti_type)
became
end
......
......@@ -858,11 +858,11 @@ def symbol_unscoping(scope)
end
single_val_method = Relation::SINGLE_VALUE_METHODS.include?(scope)
unscope_code = :"#{scope}_value#{'s' unless single_val_method}="
unscope_code = "#{scope}_value#{'s' unless single_val_method}="
case scope
when :order
self.send(:reverse_order_value=, false)
self.reverse_order_value = false
result = []
else
result = [] unless single_val_method
......@@ -872,17 +872,19 @@ def symbol_unscoping(scope)
end
def where_unscoping(target_value)
target_value_sym = target_value.to_sym
target_value = target_value.to_s
where_values.reject! do |rel|
case rel
when Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality, Arel::Nodes::NotEqual
subrelation = (rel.left.kind_of?(Arel::Attributes::Attribute) ? rel.left : rel.right)
subrelation.name.to_sym == target_value_sym
subrelation.name == target_value
else
raise "unscope(where: #{target_value.inspect}) failed: unscoping #{rel.class} is unimplemented."
end
end
bind_values.reject! { |col,_| col.name == target_value }
end
def custom_join_ast(table, joins)
......
......@@ -88,4 +88,8 @@ class EnumTest < ActiveRecord::TestCase
assert Book.written.create.written?
assert Book.read.create.read?
end
test "_before_type_cast returns the enum label (required for form fields)" do
assert_equal "proposed", @book.status_before_type_cast
end
end
......@@ -5,7 +5,7 @@ class HotCompatibilityTest < ActiveRecord::TestCase
setup do
@klass = Class.new(ActiveRecord::Base) do
connection.create_table :hot_compatibilities, :force => true do |t|
connection.create_table :hot_compatibilities, force: true do |t|
t.string :foo
t.string :bar
end
......
......@@ -128,6 +128,17 @@ def test_alt_becomes_works_with_sti
assert_kind_of Cabbage, cabbage
end
def test_alt_becomes_bang_resets_inheritance_type_column
vegetable = Vegetable.create!(name: "Red Pepper")
assert_nil vegetable.custom_type
cabbage = vegetable.becomes!(Cabbage)
assert_equal "Cabbage", cabbage.custom_type
vegetable = cabbage.becomes!(Vegetable)
assert_nil cabbage.custom_type
end
def test_inheritance_find_all
companies = Company.all.merge!(:order => 'id').to_a
assert_kind_of Firm, companies[0], "37signals should be a firm"
......
......@@ -1524,6 +1524,15 @@ def test_presence
assert merged.to_sql.include?("bbq")
end
def test_unscope_removes_binds
left = Post.where(id: Arel::Nodes::BindParam.new('?'))
column = Post.columns_hash['id']
left.bind_values += [[column, 20]]
relation = left.unscope(where: :id)
assert_equal [], relation.bind_values
end
def test_merging_removes_rhs_bind_parameters
left = Post.where(id: Arel::Nodes::BindParam.new('?'))
column = Post.columns_hash['id']
......
require 'active_support/core_ext/module/aliasing'
require 'active_support/core_ext/object/acts_like'
class Range #:nodoc:
......@@ -17,7 +16,7 @@ def step_with_time_with_zone(n = 1, &block)
private
def ensure_iteration_allowed
if first.acts_like?(:time)
if first.is_a?(Time)
raise TypeError, "can't iterate from #{first.class}"
end
end
......
......@@ -70,9 +70,20 @@ def html_escape_once(s)
# them inside a script tag to avoid XSS vulnerability:
#
# <script>
# var currentUser = <%= json_escape current_user.to_json %>;
# var currentUser = <%= raw json_escape(current_user.to_json) %>;
# </script>
#
# It is necessary to +raw+ the result of +json_escape+, so that quotation marks
# don't get converted to <tt>&quot;</tt> entities. +json_escape+ doesn't
# automatically flag the result as HTML safe, since the raw value is unsafe to
# use inside HTML attributes.
#
# If you need to output JSON elsewhere in your HTML, you can just do something
# like this, as any unsafe characters (including quotation marks) will be
# automatically escaped for you:
#
# <div data-user-info="<%= current_user.to_json %>">...</div>
#
# WARNING: this helper only works with valid JSON. Using this on non-JSON values
# will open up serious XSS vulnerabilities. For example, if you replace the
# +current_user.to_json+ in the example above with user input instead, the browser
......@@ -88,17 +99,6 @@ def html_escape_once(s)
# is recommended that you always apply this helper (other libraries, such as the
# JSON gem, do not provide this kind of protection by default; also some gems
# might override +to_json+ to bypass Active Support's encoder).
#
# The output of this helper method is marked as HTML safe so that you can directly
# include it inside a <tt><script></tt> tag as shown above.
#
# However, it is NOT safe to use the output of this inside an HTML attribute,
# because quotation marks are not escaped. Doing so might break your page's layout.
# If you intend to use this inside an HTML attribute, you should use the
# +html_escape+ helper (or its +h+ alias) instead:
#
# <div data-user-info="<%= h current_user.to_json %>">...</div>
#
def json_escape(s)
result = s.to_s.gsub(JSON_ESCAPE_REGEXP, JSON_ESCAPE)
s.html_safe? ? result.html_safe : result
......
......@@ -34,5 +34,5 @@ def rubinius_skip(message = '')
# Skips the current run on JRuby using Minitest::Assertions#skip
def jruby_skip(message = '')
skip message if RUBY_ENGINE == 'jruby'
skip message if defined?(JRUBY_VERSION)
end
......@@ -112,4 +112,8 @@ def test_include_on_time_with_zone
end
end
def test_date_time_with_each
datetime = DateTime.now
assert ((datetime - 1.hour)..datetime).each {}
end
end
source 'https://rubygems.org'
gem 'rails', '4.0.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails'
gem 'sass-rails', '~> 4.0.1'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails'
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.0.3'
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# To use ActiveModel has_secure_password
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/jonleighton/spring
gem 'spring', group: :development
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano', group: :development
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
# To use debugger
# gem 'debugger'
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.0.0)
actionpack (= 4.0.0)
mail (~> 2.5.3)
actionpack (4.0.0)
activesupport (= 4.0.0)
builder (~> 3.1.0)
erubis (~> 2.7.0)
actionmailer (4.1.0)
actionpack (= 4.1.0)
actionview (= 4.1.0)
mail (~> 2.5.4)
actionpack (4.1.0)
actionview (= 4.1.0)
activesupport (= 4.1.0)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
activemodel (4.0.0)
activesupport (= 4.0.0)
builder (~> 3.1.0)
activerecord (4.0.0)
activemodel (= 4.0.0)
activerecord-deprecated_finders (~> 1.0.2)
activesupport (= 4.0.0)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.0)
i18n (~> 0.6, >= 0.6.4)
minitest (~> 4.2)
multi_json (~> 1.3)
actionview (4.1.0)
activesupport (= 4.1.0)
builder (~> 3.1)
erubis (~> 2.7.0)
activemodel (4.1.0)
activesupport (= 4.1.0)
builder (~> 3.1)
activerecord (4.1.0)
activemodel (= 4.1.0)
activesupport (= 4.1.0)
arel (~> 5.0.0)
activesupport (4.1.0)
i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
arel (4.0.0)
atomic (1.1.10)
builder (3.1.4)
coffee-rails (4.0.0)
tzinfo (~> 1.1)
arel (5.0.0)
atomic (1.1.14)
builder (3.2.2)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0.beta, < 5.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.6.3)
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
execjs (2.0.2)
hike (1.2.3)
i18n (0.6.4)
jbuilder (2.0.0)
i18n (0.6.9)
jbuilder (2.0.2)
activesupport (>= 3.0.0)
multi_json (>= 1.2.0)
jquery-rails (3.0.2)
jquery-rails (3.0.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.0)
json (1.8.1)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.23)
minitest (4.7.5)
multi_json (1.7.7)
mime-types (1.25.1)
minitest (5.2.1)
multi_json (1.8.4)
polyglot (0.3.3)
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
rails (4.0.0)
actionmailer (= 4.0.0)
actionpack (= 4.0.0)
activerecord (= 4.0.0)
activesupport (= 4.0.0)
rails (4.1.0)
actionmailer (= 4.1.0)
actionpack (= 4.1.0)
actionview (= 4.1.0)
activemodel (= 4.1.0)
activerecord (= 4.1.0)
activesupport (= 4.1.0)
bundler (>= 1.3.0, < 2.0)
railties (= 4.0.0)
railties (= 4.1.0)
sprockets-rails (~> 2.0.0)
railties (4.0.0)
actionpack (= 4.0.0)
activesupport (= 4.0.0)
railties (4.1.0)
actionpack (= 4.1.0)
activesupport (= 4.1.0)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.1.0)
rdoc (3.12.2)
rake (10.1.1)
rdoc (4.1.1)
json (~> 1.4)
sass (3.2.9)
sass-rails (4.0.0)
railties (>= 4.0.0.beta, < 5.0)
sass (3.2.13)
sass-rails (4.0.1)
railties (>= 4.0.0, < 5.0)
sass (>= 3.1.10)
sprockets-rails (~> 2.0.0)
sdoc (0.3.20)
json (>= 1.1.3)
rdoc (~> 3.10)
sprockets (2.10.0)
sdoc (0.4.0)
json (~> 1.8)
rdoc (~> 4.0, < 5.0)
spring (1.0.0)
sprockets (2.10.1)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.0.0)
sprockets-rails (2.0.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (~> 2.8)
sqlite3 (1.3.7)
sqlite3 (1.3.8)
thor (0.18.1)
thread_safe (0.1.0)
thread_safe (0.1.3)
atomic
tilt (1.4.1)
treetop (1.4.14)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
turbolinks (1.2.0)
turbolinks (2.2.0)
coffee-rails
tzinfo (0.3.37)
uglifier (2.1.1)
tzinfo (1.1.0)
thread_safe (~> 0.1)
uglifier (2.4.0)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
json (>= 1.8.0)
PLATFORMS
ruby
DEPENDENCIES
coffee-rails
coffee-rails (~> 4.0.0)
jbuilder (~> 2.0)
jquery-rails
rails (= 4.0.0)
sass-rails
sdoc
rails (= 4.1.0)
sass-rails (~> 4.0.1)
sdoc (~> 0.4.0)
spring
sqlite3
turbolinks
uglifier (>= 1.0.3)
uglifier (>= 1.3.0)
......@@ -106,7 +106,7 @@ run the following:
$ rails --version
```
If it says something like "Rails 4.0.0", you are ready to continue.
If it says something like "Rails 4.1.0", you are ready to continue.
### Creating the Blog Application
......@@ -123,42 +123,40 @@ rights to create files, and type:
$ rails new blog
```
This will create a Rails application called Blog in a directory called blog and
This will create a Rails application called Blog in a `blog` directory and
install the gem dependencies that are already mentioned in `Gemfile` using
`bundle install`.
TIP: You can see all of the command line options that the Rails application
builder accepts by running `rails new -h`.
After you create the blog application, switch to its folder to continue work
directly in that application:
After you create the blog application, switch to its folder:
```bash
$ cd blog
```
The `rails new blog` command we ran above created a folder in your working
directory called `blog`. The `blog` directory has a number of auto-generated
files and folders that make up the structure of a Rails application. Most of the
work in this tutorial will happen in the `app/` folder, but here's a basic
rundown on the function of each of the files and folders that Rails created by default:
The `blog` directory has a number of auto-generated files and folders that make
up the structure of a Rails application. Most of the work in this tutorial will
happen in the `app` folder, but here's a basic rundown on the function of each
of the files and folders that Rails created by default:
| File/Folder | Purpose |
| ----------- | ------- |
|app/|Contains the controllers, models, views, helpers, mailers and assets for your application. You'll focus on this folder for the remainder of this guide.|
|bin/|Contains the rails script that starts your app and can contain other scripts you use to deploy or run your application.|
|config/|Configure your application's runtime rules, routes, database, and more. This is covered in more detail in [Configuring Rails Applications](configuring.html)|
|app|Contains the controllers, models, views, helpers, mailers and assets for your application. You'll focus on this folder for the remainder of this guide.|
|bin|Contains the rails script that starts your app and can contain other scripts you use to deploy or run your application.|
|config/|Configure your application's routes, database, and more. This is covered in more detail in [Configuring Rails Applications](configuring.html).|
|config.ru|Rack configuration for Rack based servers used to start the application.|
|db/|Contains your current database schema, as well as the database migrations.|
|Gemfile<br>Gemfile.lock|These files allow you to specify what gem dependencies are needed for your Rails application. These files are used by the Bundler gem. For more information about Bundler, see [the Bundler website](http://gembundler.com) |
|lib/|Extended modules for your application.|
|log/|Application log files.|
|public/|The only folder seen to the world as-is. Contains the static files and compiled assets.|
|db|Contains your current database schema, as well as the database migrations.|
|Gemfile<br>Gemfile.lock|These files allow you to specify what gem dependencies are needed for your Rails application. These files are used by the Bundler gem. For more information about Bundler, see [the Bundler website](http://gembundler.com).|
|lib|Extended modules for your application.|
|log|Application log files.|
|public|The only folder seen by the world as-is. Contains static files and compiled assets.|
|Rakefile|This file locates and loads tasks that can be run from the command line. The task definitions are defined throughout the components of Rails. Rather than changing Rakefile, you should add your own tasks by adding files to the lib/tasks directory of your application.|
|README.rdoc|This is a brief instruction manual for your application. You should edit this file to tell others what your application does, how to set it up, and so on.|
|test/|Unit tests, fixtures, and other test apparatus. These are covered in [Testing Rails Applications](testing.html)|
|tmp/|Temporary files (like cache, pid and session files)|
|vendor/|A place for all third-party code. In a typical Rails application, this includes Ruby Gems and the Rails source code (if you optionally install it into your project).|
|test|Unit tests, fixtures, and other test apparatus. These are covered in [Testing Rails Applications](testing.html).|
|tmp|Temporary files (like cache, pid, and session files).|
|vendor|A place for all third-party code. In a typical Rails application this includes vendored gems.|
Hello, Rails!
-------------
......@@ -170,7 +168,7 @@ get your Rails application server running.
You actually have a functional Rails application already. To see it, you need to
start a web server on your development machine. You can do this by running the
following in the root directory of your rails application:
following in the `blog` directory:
```bash
$ rails server
......@@ -179,16 +177,17 @@ $ rails server
TIP: Compiling CoffeeScript to JavaScript requires a JavaScript runtime and the
absence of a runtime will give you an `execjs` error. Usually Mac OS X and
Windows come with a JavaScript runtime installed. Rails adds the `therubyracer`
gem to Gemfile in a commented line for new apps and you can uncomment if you
need it. `therubyrhino` is the recommended runtime for JRuby users and is added
by default to Gemfile in apps generated under JRuby. You can investigate about
all the supported runtimes at [ExecJS](https://github.com/sstephenson/execjs#readme).
gem to the generated `Gemfile` in a commented line for new apps and you can
uncomment if you need it. `therubyrhino` is the recommended runtime for JRuby
users and is added by default to the `Gemfile` in apps generated under JRuby.
You can investigate about all the supported runtimes at
[ExecJS](https://github.com/sstephenson/execjs#readme).
This will fire up WEBrick, a webserver built into Ruby by default. To see your
application in action, open a browser window and navigate to <http://localhost:3000>.
You should see the Rails default information page:
This will fire up WEBrick, a web server distributed with Ruby by default. To see
your application in action, open a browser window and navigate to
<http://localhost:3000>. You should see the Rails default information page:
![Welcome Aboard screenshot](images/getting_started/rails_welcome.png)
![Welcome aboard screenshot](images/getting_started/rails_welcome.jpg)
TIP: To stop the web server, hit Ctrl+C in the terminal window where it's
running. To verify the server has stopped you should see your command prompt
......@@ -197,7 +196,7 @@ dollar sign `$`. In development mode, Rails does not generally require you to
restart the server; changes you make in files will be automatically picked up by
the server.
The "Welcome Aboard" page is the _smoke test_ for a new Rails application: it
The "Welcome aboard" page is the _smoke test_ for a new Rails application: it
makes sure that you have your software configured correctly enough to serve a
page. You can also click on the _About your application's environment_ link to
see a summary of your application's environment.
......@@ -216,8 +215,9 @@ it to a view.
A view's purpose is to display this information in a human readable format. An
important distinction to make is that it is the _controller_, not the view,
where information is collected. The view should just display that information.
By default, view templates are written in a language called ERB (Embedded Ruby)
which is converted by the request cycle in Rails before being sent to the user.
By default, view templates are written in a language called eRuby (Embedded
Ruby) which is processed by the request cycle in Rails before being sent to the
user.
To create a new controller, you will need to run the "controller" generator and
tell it you want a controller called "welcome" with an action called "index",
......@@ -262,23 +262,25 @@ of code:
### Setting the Application Home Page
Now that we have made the controller and view, we need to tell Rails when we
want `Hello, Rails!` to show up. In our case, we want it to show up when we
want "Hello, Rails!" to show up. In our case, we want it to show up when we
navigate to the root URL of our site, <http://localhost:3000>. At the moment,
"Welcome Aboard" is occupying that spot.
"Welcome aboard" is occupying that spot.
Next, you have to tell Rails where your actual home page is located.
Open the file `config/routes.rb` in your editor.
```ruby
Blog::Application.routes.draw do
Rails.application.routes.draw do
get "welcome/index"
# The priority is based upon order of creation:
# first created -> highest priority.
# ...
#
# You can have the root of your site routed with "root"
# root "welcome#index"
#
# ...
```
This is your application's _routing file_ which holds entries in a special DSL
......@@ -289,17 +291,18 @@ to a specific controller and action. Find the line beginning with `root` and
uncomment it. It should look something like the following:
```ruby
root "welcome#index"
root 'welcome#index'
```
The `root "welcome#index"` tells Rails to map requests to the root of the
`root 'welcome#index'` tells Rails to map requests to the root of the
application to the welcome controller's index action and `get "welcome/index"`
tells Rails to map requests to <http://localhost:3000/welcome/index> to the
welcome controller's index action. This was created earlier when you ran the
controller generator (`rails generate controller welcome index`).
If you navigate to <http://localhost:3000> in your browser, you'll see the
`Hello, Rails!` message you put into `app/views/welcome/index.html.erb`,
Launch the web server again if you stopped it to generate the controller (`rails
server`) and navigate to <http://localhost:3000> in your browser. You'll see the
"Hello, Rails!" message you put into `app/views/welcome/index.html.erb`,
indicating that this new route is indeed going to `WelcomeController`'s `index`
action and is rendering the view correctly.
......
......@@ -614,6 +614,10 @@ config.active_record.mass_assignment_sanitizer = :strict
Rails 3.2 deprecates `vendor/plugins` and Rails 4.0 will remove them completely. While it's not strictly necessary as part of a Rails 3.2 upgrade, you can start replacing any plugins by extracting them to gems and adding them to your Gemfile. If you choose not to make them gems, you can move them into, say, `lib/my_plugin/*` and add an appropriate initializer in `config/initializers/my_plugin.rb`.
### Active Record
Option `:dependent => :restrict` has been removed from `belongs_to`. If you want to prevent deleting the object if there are any associated objects, you can set `:dependent => :destroy` and return `false` after checking for existence of association from any of the associated object's destroy callbacks.
Upgrading from Rails 3.0 to Rails 3.1
-------------------------------------
......
* `test_help.rb` now automatically checks/maintains your test datbase
* Only lookup `config.log_level` for stdlib `::Logger` instances.
Assign it as is for third party loggers like `Log4r::Logger`.
Fixes #13421.
*Yves Senn*
* The `Gemfile` of new applications depends on SDoc ~> 0.4.0.
*Xavier Noria*
* `test_help.rb` now automatically checks/maintains your test database
schema. (Use `config.active_record.maintain_test_schema = false` to
disable.)
......
......@@ -53,7 +53,11 @@ module Bootstrap
logger
end
Rails.logger.level = ActiveSupport::Logger.const_get(config.log_level.to_s.upcase)
if ::Logger === Rails.logger
Rails.logger.level = ActiveSupport::Logger.const_get(config.log_level.to_s.upcase)
else
Rails.logger.level = config.log_level
end
end
# Initialize cache early in the stack so railties can make use of it.
......
......@@ -352,7 +352,7 @@ def jbuilder_gemfile_entry
def sdoc_gemfile_entry
comment = 'bundle exec rake doc:rails generates the API under doc/api.'
GemfileEntry.new('sdoc', nil, comment, { group: :doc, require: false })
GemfileEntry.new('sdoc', '~> 0.4.0', comment, group: :doc)
end
def coffee_gemfile_entry
......
......@@ -6,12 +6,10 @@ source 'https://rubygems.org'
# <%= gem.comment %>
<% end -%>
<%= gem.commented_out ? '# ' : '' %>gem '<%= gem.name %>'<% if gem.version -%>
, '<%= gem.version %>'
<% elsif gem.options.any? -%>
<%= gem.commented_out ? '# ' : '' %>gem '<%= gem.name %>'<%= %(, '#{gem.version}') if gem.version -%>
<% if gem.options.any? -%>
,<%= gem.padding(max_width) %><%= gem.options.map { |k,v|
"#{k}: #{v.inspect}" }.join(', ') %>
<% else %>
<% end -%>
<% end -%>
......
......@@ -19,4 +19,4 @@ test:
# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%%= ENV["RAILS_SECRET_KEY_BASE"] %>
secret_key_base: <%%= ENV["SECRET_KEY_BASE"] %>
......@@ -29,12 +29,10 @@ end
# <%= gem.comment %>
<% end -%>
<%= gem.commented_out ? '# ' : '' %>gem '<%= gem.name %>'<% if gem.version -%>
, '<%= gem.version %>'
<% elsif gem.options.any? -%>
<%= gem.commented_out ? '# ' : '' %>gem '<%= gem.name %>'<%= %(, '#{gem.version}') if gem.version -%>
<% if gem.options.any? -%>
,<%= gem.padding(max_width) %><%= gem.options.map { |k,v|
"#{k}: #{v.inspect}" }.join(', ') %>
<% else %>
<% end -%>
<% end -%>
......
......@@ -61,11 +61,9 @@ def destination(path)
# You can provide a configuration hash as second argument. This method returns the output
# printed by the generator.
def run_generator(args=self.default_arguments, config={})
without_thor_debug do
capture(:stdout) do
args += ['--skip-bundle'] unless args.include? '--dev'
self.generator_class.start(args, config.reverse_merge(destination_root: destination_root))
end
capture(:stdout) do
args += ['--skip-bundle'] unless args.include? '--dev'
self.generator_class.start(args, config.reverse_merge(destination_root: destination_root))
end
end
......@@ -102,14 +100,6 @@ def migration_file_name(relative) # :nodoc:
dirname, file_name = File.dirname(absolute), File.basename(absolute).sub(/\.rb$/, '')
Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
end
# TODO: remove this once Bundler 1.5.2 is released
def without_thor_debug # :nodoc:
thor_debug, ENV['THOR_DEBUG'] = ENV['THOR_DEBUG'], nil
yield
ensure
ENV['THOR_DEBUG'] = thor_debug
end
end
end
end
......
......@@ -17,3 +17,12 @@ class Application < Rails::Application
secrets.secret_key_base = 'b3c631c314c0bbca50c1b2843150fe33'
end
end
# Skips the current run on Rubinius using Minitest::Assertions#skip
def rubinius_skip(message = '')
skip message if RUBY_ENGINE == 'rbx'
end
# Skips the current run on JRuby using Minitest::Assertions#skip
def jruby_skip(message = '')
skip message if defined?(JRUBY_VERSION)
end
......@@ -754,7 +754,7 @@ def index
end
end
test "config.log_level with custom logger" do
test "lookup config.log_level with custom logger (stdlib Logger)" do
make_basic_app do |app|
app.config.logger = Logger.new(STDOUT)
app.config.log_level = :info
......@@ -762,6 +762,19 @@ def index
assert_equal Logger::INFO, Rails.logger.level
end
test "assign log_level as is with custom logger (third party logger)" do
logger_class = Class.new do
attr_accessor :level
end
logger_instance = logger_class.new
make_basic_app do |app|
app.config.logger = logger_instance
app.config.log_level = :info
end
assert_equal logger_instance, Rails.logger
assert_equal :info, Rails.logger.level
end
test "respond_to? accepts include_private" do
make_basic_app
......
......@@ -390,9 +390,9 @@ def test_inclusion_of_debugger
end
end
def test_inclusion_of_lazy_loaded_sdoc
def test_inclusion_of_doc
run_generator
assert_file 'Gemfile', /gem 'sdoc', \s+group: :doc, require: false/
assert_file 'Gemfile', /gem 'sdoc',\s+'~> 0.4.0',\s+group: :doc/
end
def test_template_from_dir_pwd
......@@ -458,12 +458,14 @@ def test_spring
end
def test_spring_binstubs
jruby_skip "spring doesn't run on JRuby"
generator.stubs(:bundle_command).with('install')
generator.expects(:bundle_command).with('exec spring binstub --all').once
quietly { generator.invoke_all }
end
def test_spring_no_fork
jruby_skip "spring doesn't run on JRuby"
Process.stubs(:respond_to?).with(:fork).returns(false)
run_generator
......
......@@ -93,8 +93,8 @@ module Generation
# Build an application by invoking the generator and going through the whole stack.
def build_app(options = {})
@prev_rails_env = ENV['RAILS_ENV']
ENV['RAILS_ENV'] = 'development'
ENV['RAILS_SECRET_KEY_BASE'] ||= SecureRandom.hex(16)
ENV['RAILS_ENV'] = "development"
ENV['SECRET_KEY_BASE'] ||= SecureRandom.hex(16)
FileUtils.rm_rf(app_path)
FileUtils.cp_r(app_template_path, app_path)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册