aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.travis.yml3
-rw-r--r--Gemfile6
-rw-r--r--actionpack/lib/action_controller/test_case.rb12
-rw-r--r--actionpack/lib/action_dispatch/testing/integration.rb1
-rw-r--r--actionpack/test/abstract_unit.rb10
-rw-r--r--actionpack/test/dispatch/template_assertions_test.rb58
-rw-r--r--activesupport/activesupport.gemspec2
-rw-r--r--activesupport/lib/active_support/i18n_railtie.rb4
-rw-r--r--guides/source/active_record_basics.md9
-rw-r--r--railties/lib/rails/generators/app_base.rb15
-rw-r--r--railties/test/application/initializers/i18n_test.rb20
-rw-r--r--railties/test/commands/console_test.rb7
-rw-r--r--railties/test/generators/app_generator_test.rb13
13 files changed, 121 insertions, 39 deletions
diff --git a/.travis.yml b/.travis.yml
index 8eee7b129b..43b08044d3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -11,7 +11,8 @@ rvm:
- jruby
env:
- "GEM=railties"
- - "GEM=ap,am,amo,as,av"
+ - "GEM=ap"
+ - "GEM=am,amo,as,av"
- "GEM=ar:mysql"
- "GEM=ar:mysql2"
- "GEM=ar:sqlite3"
diff --git a/Gemfile b/Gemfile
index 60c4b31e5b..49a68c7d9d 100644
--- a/Gemfile
+++ b/Gemfile
@@ -87,6 +87,12 @@ platforms :jruby do
end
end
+platforms :rbx do
+ # The rubysl-yaml gem doesn't ship with Psych by default
+ # as it needs libyaml that isn't always available.
+ gem 'psych', '~> 2.0'
+end
+
# gems that are necessary for ActiveRecord tests with Oracle database
if ENV['ORACLE_ENHANCED']
platforms :ruby do
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb
index a18c35e3e9..657924a16c 100644
--- a/actionpack/lib/action_controller/test_case.rb
+++ b/actionpack/lib/action_controller/test_case.rb
@@ -13,10 +13,7 @@ module ActionController
end
def setup_subscriptions
- @_partials = Hash.new(0)
- @_templates = Hash.new(0)
- @_layouts = Hash.new(0)
- @_files = Hash.new(0)
+ reset_template_assertion
@_subscribers = []
@_subscribers << ActiveSupport::Notifications.subscribe("render_template.action_view") do |_name, _start, _finish, _id, payload|
@@ -56,10 +53,15 @@ module ActionController
end
def process(*args)
+ reset_template_assertion
+ super
+ end
+
+ def reset_template_assertion
@_partials = Hash.new(0)
@_templates = Hash.new(0)
@_layouts = Hash.new(0)
- super
+ @_files = Hash.new(0)
end
# Asserts that the request was rendered with the appropriate template file or partials.
diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb
index cb2cb10870..12b796b95f 100644
--- a/actionpack/lib/action_dispatch/testing/integration.rb
+++ b/actionpack/lib/action_dispatch/testing/integration.rb
@@ -329,6 +329,7 @@ module ActionDispatch
xml_http_request xhr get_via_redirect post_via_redirect).each do |method|
define_method(method) do |*args|
reset! unless integration_session
+ reset_template_assertion
# reset the html_document variable, but only for new get/post calls
@html_document = nil unless method == 'cookies' || method == 'assigns'
integration_session.__send__(method, *args).tap do
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index b07d8a7be0..4e17d57dad 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -19,6 +19,8 @@ require 'drb'
require 'drb/unix'
require 'tempfile'
+PROCESS_COUNT = (ENV['N'] || 4).to_i
+
require 'active_support/testing/autorun'
require 'abstract_controller'
require 'action_controller'
@@ -109,7 +111,9 @@ end
module ActiveSupport
class TestCase
include ActionDispatch::DrawOnce
- parallelize_me! if ActiveSupport::Testing::Isolation.forking_env?
+ if ActiveSupport::Testing::Isolation.forking_env? && PROCESS_COUNT > 0
+ parallelize_me!
+ end
end
end
@@ -489,7 +493,7 @@ class ForkingExecutor
end
end
-if ActiveSupport::Testing::Isolation.forking_env?
+if ActiveSupport::Testing::Isolation.forking_env? && PROCESS_COUNT > 0
# Use N processes (N defaults to 4)
- Minitest.parallel_executor = ForkingExecutor.new((ENV['N'] || 4).to_i)
+ Minitest.parallel_executor = ForkingExecutor.new(PROCESS_COUNT)
end
diff --git a/actionpack/test/dispatch/template_assertions_test.rb b/actionpack/test/dispatch/template_assertions_test.rb
new file mode 100644
index 0000000000..b8bc8e22d4
--- /dev/null
+++ b/actionpack/test/dispatch/template_assertions_test.rb
@@ -0,0 +1,58 @@
+require 'abstract_unit'
+
+class AssertTemplateController < ActionController::Base
+ def render_with_partial
+ render partial: 'test/partial'
+ end
+
+ def render_with_template
+ render 'test/hello_world'
+ end
+
+ def render_with_layout
+ @variable_for_layout = nil
+ render 'test/hello_world', layout: "layouts/standard"
+ end
+
+ def render_with_file
+ render file: 'README.rdoc'
+ end
+
+ def render_nothing
+ head :ok
+ end
+end
+
+class AssertTemplateControllerTest < ActionDispatch::IntegrationTest
+ def test_assert_template_reset_between_requests
+ get '/assert_template/render_with_template'
+ assert_template 'test/hello_world'
+
+ get '/assert_template/render_nothing'
+ assert_template nil
+ end
+
+ def test_assert_partial_reset_between_requests
+ get '/assert_template/render_with_partial'
+ assert_template partial: 'test/_partial'
+
+ get '/assert_template/render_nothing'
+ assert_template partial: nil
+ end
+
+ def test_assert_layout_reset_between_requests
+ get '/assert_template/render_with_layout'
+ assert_template layout: 'layouts/standard'
+
+ get '/assert_template/render_nothing'
+ assert_template layout: nil
+ end
+
+ def test_assert_file_reset_between_requests
+ get '/assert_template/render_with_file'
+ assert_template file: 'README.rdoc'
+
+ get '/assert_template/render_nothing'
+ assert_template file: nil
+ end
+end
diff --git a/activesupport/activesupport.gemspec b/activesupport/activesupport.gemspec
index f3625e8b79..c0b457c341 100644
--- a/activesupport/activesupport.gemspec
+++ b/activesupport/activesupport.gemspec
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
s.rdoc_options.concat ['--encoding', 'UTF-8']
- s.add_dependency 'i18n', '~> 0.6', '>= 0.6.9'
+ s.add_dependency 'i18n', '>= 0.7.0.dev', '< 0.8'
s.add_dependency 'json', '~> 1.7', '>= 1.7.7'
s.add_dependency 'tzinfo', '~> 1.1'
s.add_dependency 'minitest', '~> 5.1'
diff --git a/activesupport/lib/active_support/i18n_railtie.rb b/activesupport/lib/active_support/i18n_railtie.rb
index 23cd6716e3..affcfb7398 100644
--- a/activesupport/lib/active_support/i18n_railtie.rb
+++ b/activesupport/lib/active_support/i18n_railtie.rb
@@ -8,8 +8,6 @@ module I18n
config.i18n.railties_load_path = []
config.i18n.load_path = []
config.i18n.fallbacks = ActiveSupport::OrderedOptions.new
- # Enforce I18n to check the available locales when setting a locale.
- config.i18n.enforce_available_locales = true
# Set the i18n configuration after initialization since a lot of
# configuration is still usually done in application initializers.
@@ -36,7 +34,7 @@ module I18n
# Avoid issues with setting the default_locale by disabling available locales
# check while configuring.
enforce_available_locales = app.config.i18n.delete(:enforce_available_locales)
- enforce_available_locales = I18n.enforce_available_locales unless I18n.enforce_available_locales.nil?
+ enforce_available_locales = I18n.enforce_available_locales if enforce_available_locales.nil?
I18n.enforce_available_locales = false
app.config.i18n.each do |setting, value|
diff --git a/guides/source/active_record_basics.md b/guides/source/active_record_basics.md
index 21022f1abb..eff93ce41d 100644
--- a/guides/source/active_record_basics.md
+++ b/guides/source/active_record_basics.md
@@ -310,10 +310,10 @@ models and validate that an attribute value is not empty, is unique and not
already in the database, follows a specific format and many more.
Validation is a very important issue to consider when persisting to the database, so
-the methods `create`, `save` and `update` take it into account when
+the methods `save` and `update` take it into account when
running: they return `false` when validation fails and they didn't actually
perform any operation on the database. All of these have a bang counterpart (that
-is, `create!`, `save!` and `update!`), which are stricter in that
+is, `save!` and `update!`), which are stricter in that
they raise the exception `ActiveRecord::RecordInvalid` if validation fails.
A quick example to illustrate:
@@ -322,8 +322,9 @@ class User < ActiveRecord::Base
validates :name, presence: true
end
-User.create # => false
-User.create! # => ActiveRecord::RecordInvalid: Validation failed: Name can't be blank
+user = User.new
+user.save # => false
+user.save! # => ActiveRecord::RecordInvalid: Validation failed: Name can't be blank
```
You can learn more about validations in the [Active Record Validations
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index 20e512a7ff..7f5a916c5d 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -114,6 +114,7 @@ module Rails
jbuilder_gemfile_entry,
sdoc_gemfile_entry,
spring_gemfile_entry,
+ psych_gemfile_entry,
@extra_entries].flatten.find_all(&@gem_filter)
end
@@ -204,11 +205,13 @@ module Rails
if options.dev?
[GemfileEntry.path('rails', Rails::Generators::RAILS_DEV_PATH),
GemfileEntry.github('arel', 'rails/arel'),
- GemfileEntry.github('rack', 'rack/rack')]
+ GemfileEntry.github('rack', 'rack/rack'),
+ GemfileEntry.github('i18n', 'svenfuchs/i18n')]
elsif options.edge?
[GemfileEntry.github('rails', 'rails/rails'),
GemfileEntry.github('arel', 'rails/arel'),
- GemfileEntry.github('rack', 'rack/rack')]
+ GemfileEntry.github('rack', 'rack/rack'),
+ GemfileEntry.github('i18n', 'svenfuchs/i18n')]
else
[GemfileEntry.version('rails',
Rails::VERSION::STRING,
@@ -313,6 +316,14 @@ module Rails
GemfileEntry.new('spring', nil, comment, group: :development)
end
+ def psych_gemfile_entry
+ return [] unless defined?(Rubinius)
+
+ comment = 'Use Psych as the YAML engine, instead of Syck, so serialized ' \
+ 'data can be read safely from different rubies (see http://git.io/uuLVag)'
+ GemfileEntry.new('psych', '~> 2.0', comment, platforms: :rbx)
+ end
+
def bundle_command(command)
say_status :run, "bundle #{command}"
diff --git a/railties/test/application/initializers/i18n_test.rb b/railties/test/application/initializers/i18n_test.rb
index bc34897cdf..9ee54796a4 100644
--- a/railties/test/application/initializers/i18n_test.rb
+++ b/railties/test/application/initializers/i18n_test.rb
@@ -184,28 +184,13 @@ en:
assert_fallbacks ca: [:ca, :"es-ES", :es, :'en-US', :en]
end
- test "config.i18n.enforce_available_locales is set to true by default and avoids I18n warnings" do
- add_to_config <<-RUBY
- config.i18n.default_locale = :it
- RUBY
-
- output = capture(:stderr) { load_app }
- assert_no_match %r{deprecated.*enforce_available_locales}, output
- assert_equal true, I18n.enforce_available_locales
-
- assert_raise I18n::InvalidLocale do
- I18n.locale = :es
- end
- end
-
test "disable config.i18n.enforce_available_locales" do
add_to_config <<-RUBY
config.i18n.enforce_available_locales = false
config.i18n.default_locale = :fr
RUBY
- output = capture(:stderr) { load_app }
- assert_no_match %r{deprecated.*enforce_available_locales}, output
+ load_app
assert_equal false, I18n.enforce_available_locales
assert_nothing_raised do
@@ -220,8 +205,7 @@ en:
config.i18n.default_locale = :fr
RUBY
- output = capture(:stderr) { load_app }
- assert_no_match %r{deprecated.*enforce_available_locales}, output
+ load_app
assert_equal false, I18n.enforce_available_locales
assert_nothing_raised do
diff --git a/railties/test/commands/console_test.rb b/railties/test/commands/console_test.rb
index f765143f1d..4aea3e980f 100644
--- a/railties/test/commands/console_test.rb
+++ b/railties/test/commands/console_test.rb
@@ -58,9 +58,12 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
end
def test_start_with_debugger
- rails_console = Rails::Console.new(app, parse_arguments(["--debugger"]))
- rails_console.expects(:require_debugger).returns(nil)
+ stubbed_console = Class.new(Rails::Console) do
+ def require_debugger
+ end
+ end
+ rails_console = stubbed_console.new(app, parse_arguments(["--debugger"]))
silence_stream(STDOUT) { rails_console.start }
end
end
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 409616d0d2..aff484f3eb 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -488,6 +488,19 @@ class AppGeneratorTest < Rails::Generators::TestCase
end
end
+ def test_psych_gem
+ run_generator
+ gem_regex = /gem 'psych',\s+'~> 2.0', \s+platforms: :rbx/
+
+ assert_file "Gemfile" do |content|
+ if defined?(Rubinius)
+ assert_match(gem_regex, content)
+ else
+ assert_no_match(gem_regex, content)
+ end
+ end
+ end
+
protected
def action(*args, &block)