From 06c23c4c7ff842f7c6237f3ac43fc9d19509a947 Mon Sep 17 00:00:00 2001
From: Sven Bohm
Date: Mon, 21 Nov 2011 13:14:16 -0500
Subject: postgresql adapter handles quoting of not a number (NaN) and Infinity
---
.../active_record/connection_adapters/postgresql_adapter.rb | 9 +++++++--
activerecord/test/cases/adapters/postgresql/quoting_test.rb | 12 ++++++++++++
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 2f01fbb829..0b102d787a 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -415,8 +415,13 @@ module ActiveRecord
case value
when Float
- return super unless value.infinite? && column.type == :datetime
- "'#{value.to_s.downcase}'"
+ if value.infinite? && column.type == :datetime
+ "'#{value.to_s.downcase}'"
+ elsif value.infinite? || value.nan?
+ "'#{value.to_s}'"
+ else
+ super
+ end
when Numeric
return super unless column.sql_type == 'money'
# Not truly string input, so doesn't require (or allow) escape string syntax.
diff --git a/activerecord/test/cases/adapters/postgresql/quoting_test.rb b/activerecord/test/cases/adapters/postgresql/quoting_test.rb
index 172055f15c..f8a605b67c 100644
--- a/activerecord/test/cases/adapters/postgresql/quoting_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/quoting_test.rb
@@ -19,6 +19,18 @@ module ActiveRecord
assert_equal 'f', @conn.type_cast(false, nil)
assert_equal 'f', @conn.type_cast(false, c)
end
+
+ def test_quote_float_nan
+ nan = 0.0/0
+ c = Column.new(nil, 1, 'float')
+ assert_equal "'NaN'", @conn.quote(nan, c)
+ end
+
+ def test_quote_float_infinity
+ infinity = 1.0/0
+ c = Column.new(nil, 1, 'float')
+ assert_equal "'Infinity'", @conn.quote(infinity, c)
+ end
end
end
end
--
cgit v1.2.3
From 3def2d6113e552548119b3e5e459d2d8b3309d50 Mon Sep 17 00:00:00 2001
From: "Suraj N. Kurapati"
Date: Fri, 6 Jan 2012 01:49:06 -0800
Subject: gemspec assumes that user kept all generated files
This commit allows the user be lazy and not update
their gemspec's `files` directive after deleting
unwanted files from their generated Rails plugin.
---
railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec
index 8588e88077..82ffeebb86 100644
--- a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.summary = "TODO: Summary of <%= camelized %>."
s.description = "TODO: Description of <%= camelized %>."
- s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
+ s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
<% unless options.skip_test_unit? -%>
s.test_files = Dir["test/**/*"]
<% end -%>
--
cgit v1.2.3
From e5425c8f68fbb720fcbf4b14e1f154ac27dbbbed Mon Sep 17 00:00:00 2001
From: Marcos Tapajos
Date: Fri, 13 Jan 2012 00:14:11 -0200
Subject: Cache (FileStore) clear should keep .gitkeep
---
activesupport/lib/active_support/cache/file_store.rb | 2 +-
activesupport/test/caching_test.rb | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb
index 9460532af0..1604cd12af 100644
--- a/activesupport/lib/active_support/cache/file_store.rb
+++ b/activesupport/lib/active_support/cache/file_store.rb
@@ -23,7 +23,7 @@ module ActiveSupport
end
def clear(options = nil)
- root_dirs = Dir.entries(cache_path).reject{|f| f.in?(EXCLUDED_DIRS)}
+ root_dirs = Dir.entries(cache_path).reject{|f| f.in?(EXCLUDED_DIRS + [".gitkeep"])}
FileUtils.rm_r(root_dirs.collect{|f| File.join(cache_path, f)})
end
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index 3454c378d3..030e31d158 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -572,6 +572,13 @@ class FileStoreTest < ActiveSupport::TestCase
include CacheDeleteMatchedBehavior
include CacheIncrementDecrementBehavior
+ def test_clear
+ filepath = File.join(cache_dir, ".gitkeep")
+ FileUtils.touch(filepath)
+ @cache.clear
+ assert File.exist?(filepath)
+ end
+
def test_key_transformation
key = @cache.send(:key_file_path, "views/index?id=1")
assert_equal "views/index?id=1", @cache.send(:file_path_key, key)
--
cgit v1.2.3
From 06ea1bad551badbdfb02ca7e23cb727f490a0e72 Mon Sep 17 00:00:00 2001
From: Matt Williams
Date: Tue, 17 Jan 2012 13:54:09 +0100
Subject: race_condition_ttl should be an integer
---
activesupport/lib/active_support/cache.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb
index 7d032ca984..9b668c2969 100644
--- a/activesupport/lib/active_support/cache.rb
+++ b/activesupport/lib/active_support/cache.rb
@@ -280,7 +280,7 @@ module ActiveSupport
end
end
if entry && entry.expired?
- race_ttl = options[:race_condition_ttl].to_f
+ race_ttl = options[:race_condition_ttl].to_i
if race_ttl and Time.now.to_f - entry.expires_at <= race_ttl
entry.expires_at = Time.now + race_ttl
write_entry(key, entry, :expires_in => race_ttl * 2)
--
cgit v1.2.3
From 12c44fe7f566990923fd0814acaa76b83309c832 Mon Sep 17 00:00:00 2001
From: Ryan Oblak
Date: Fri, 9 Mar 2012 16:33:40 -0800
Subject: Fixed bug in Quoting that caused classes to be quoted incorrectly
---
.../lib/active_record/connection_adapters/abstract/quoting.rb | 1 +
activerecord/test/cases/connection_adapters/quoting_test.rb | 11 +++++++++++
2 files changed, 12 insertions(+)
create mode 100644 activerecord/test/cases/connection_adapters/quoting_test.rb
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
index 44ac37c498..6f9f0399db 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
@@ -34,6 +34,7 @@ module ActiveRecord
when Numeric then value.to_s
when Date, Time then "'#{quoted_date(value)}'"
when Symbol then "'#{quote_string(value.to_s)}'"
+ when Class then "'#{value.to_s}'"
else
"'#{quote_string(YAML.dump(value))}'"
end
diff --git a/activerecord/test/cases/connection_adapters/quoting_test.rb b/activerecord/test/cases/connection_adapters/quoting_test.rb
new file mode 100644
index 0000000000..f523cea9ca
--- /dev/null
+++ b/activerecord/test/cases/connection_adapters/quoting_test.rb
@@ -0,0 +1,11 @@
+module ActiveRecord
+ module ConnectionAdapters
+ module Quoting
+ class QuotingTest < ActiveRecord::TestCase
+ def test_quoting_classes
+ assert_equal "'Object'", AbstractAdapter.new(nil).quote(Object)
+ end
+ end
+ end
+ end
+end
\ No newline at end of file
--
cgit v1.2.3
From 7d2bbb6ca4d5c3edd576def3f042e6c39549bb57 Mon Sep 17 00:00:00 2001
From: Anuj Dutta
Date: Fri, 2 Mar 2012 10:40:57 +0000
Subject: Removed max-stale from the tests since it's a request cache-control
directive, just for clarity sake.
---
actionpack/test/controller/render_test.rb | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index e040878b26..582106a328 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -102,12 +102,12 @@ class TestController < ActionController::Base
end
def conditional_hello_with_expires_in_with_public_with_more_keys
- expires_in 1.minute, :public => true, 'max-stale' => 5.hours
+ expires_in 1.minute, :public => true, 's-maxage' => 5.hours
render :action => 'hello_world'
end
def conditional_hello_with_expires_in_with_public_with_more_keys_old_syntax
- expires_in 1.minute, :public => true, :private => nil, 'max-stale' => 5.hours
+ expires_in 1.minute, :public => true, :private => nil, 's-maxage' => 5.hours
render :action => 'hello_world'
end
@@ -1421,12 +1421,12 @@ class ExpiresInRenderTest < ActionController::TestCase
def test_expires_in_header_with_additional_headers
get :conditional_hello_with_expires_in_with_public_with_more_keys
- assert_equal "max-age=60, public, max-stale=18000", @response.headers["Cache-Control"]
+ assert_equal "max-age=60, public, s-maxage=18000", @response.headers["Cache-Control"]
end
def test_expires_in_old_syntax
get :conditional_hello_with_expires_in_with_public_with_more_keys_old_syntax
- assert_equal "max-age=60, public, max-stale=18000", @response.headers["Cache-Control"]
+ assert_equal "max-age=60, public, s-maxage=18000", @response.headers["Cache-Control"]
end
def test_expires_now
--
cgit v1.2.3
From 0f8f99b989be949708331b81489053c94bd0d953 Mon Sep 17 00:00:00 2001
From: Pan Thomakos
Date: Sun, 18 Mar 2012 11:24:04 -0700
Subject: Removed ActiveSupport#load_all!
This is no longer used and actually raises an error when trying to load
`ActiveSupport::Dependencies`. I removed the related code and added the
`Dependencies` module to the autoload list.
---
activesupport/lib/active_support.rb | 15 +--------------
activesupport/lib/active_support/time.rb | 4 ----
2 files changed, 1 insertion(+), 18 deletions(-)
diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb
index dbf0c25c5c..8f018dcbc6 100644
--- a/activesupport/lib/active_support.rb
+++ b/activesupport/lib/active_support.rb
@@ -22,20 +22,6 @@
#++
require 'securerandom'
-
-module ActiveSupport
- class << self
- attr_accessor :load_all_hooks
- def on_load_all(&hook) load_all_hooks << hook end
- def load_all!; load_all_hooks.each { |hook| hook.call } end
- end
- self.load_all_hooks = []
-
- on_load_all do
- [Dependencies, Deprecation, Gzip, MessageVerifier, Multibyte]
- end
-end
-
require "active_support/dependencies/autoload"
require "active_support/version"
require "active_support/logger"
@@ -44,6 +30,7 @@ module ActiveSupport
extend ActiveSupport::Autoload
autoload :Concern
+ autoload :Dependencies
autoload :DescendantsTracker
autoload :FileUpdateChecker
autoload :LogSubscriber
diff --git a/activesupport/lib/active_support/time.rb b/activesupport/lib/active_support/time.rb
index 9634b52ecf..bcd5d78b54 100644
--- a/activesupport/lib/active_support/time.rb
+++ b/activesupport/lib/active_support/time.rb
@@ -4,10 +4,6 @@ module ActiveSupport
autoload :Duration, 'active_support/duration'
autoload :TimeWithZone, 'active_support/time_with_zone'
autoload :TimeZone, 'active_support/values/time_zone'
-
- on_load_all do
- [Duration, TimeWithZone, TimeZone]
- end
end
require 'date'
--
cgit v1.2.3
From 0f2555f0af279c925280e051db3a3c29359c3d2a Mon Sep 17 00:00:00 2001
From: Alexander Zubkov
Date: Thu, 29 Mar 2012 12:20:55 +0400
Subject: Change the example for habtm association to use proc according to
changelog
---
activerecord/lib/active_record/associations.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index b901f06ca4..95bb742c50 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1596,7 +1596,7 @@ module ActiveRecord
# has_and_belongs_to_many :categories, :join_table => "prods_cats"
# has_and_belongs_to_many :categories, :readonly => true
# has_and_belongs_to_many :active_projects, :join_table => 'developers_projects', :delete_sql =>
- # "DELETE FROM developers_projects WHERE active=1 AND developer_id = #{id} AND project_id = #{record.id}"
+ # proc { |record| "DELETE FROM developers_projects WHERE active=1 AND developer_id = #{id} AND project_id = #{record.id}" }
def has_and_belongs_to_many(name, options = {}, &extension)
Builder::HasAndBelongsToMany.build(self, name, options, &extension)
end
--
cgit v1.2.3
From 0e49ef433093c0ed08c7df8609b0b9e3dae5150c Mon Sep 17 00:00:00 2001
From: Patrick Helm
Date: Thu, 12 Apr 2012 16:25:28 +0200
Subject: Provided fix for calling rake tasks within mountable engines
---
railties/lib/rails/engine.rb | 7 ++++++-
railties/test/railties/engine_test.rb | 31 +++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index 131d6e5711..ceb8905c8f 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -603,7 +603,12 @@ module Rails
desc "Copy migrations from #{railtie_name} to application"
task :migrations do
ENV["FROM"] = railtie_name
- Rake::Task["railties:install:migrations"].invoke
+ if Rake::Task.task_defined?("railties:install:migrations")
+ Rake::Task["railties:install:migrations"].invoke
+ else
+ Rake::Task["app:railties:install:migrations"].invoke
+ end
+
end
end
end
diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb
index 5e93a8e783..1650a15080 100644
--- a/railties/test/railties/engine_test.rb
+++ b/railties/test/railties/engine_test.rb
@@ -112,6 +112,37 @@ module RailtiesTest
end
end
+ test "mountable engine should copy migrations within engine_path" do
+ @plugin.write "lib/bukkits.rb", <<-RUBY
+ module Bukkits
+ class Engine < ::Rails::Engine
+ isolate_namespace Bukkits
+ end
+ end
+ RUBY
+
+ @plugin.write "db/migrate/0_add_first_name_to_users.rb", <<-RUBY
+ class AddFirstNameToUsers < ActiveRecord::Migration
+ end
+ RUBY
+
+ @plugin.write "Rakefile", <<-RUBY
+ APP_RAKEFILE = '#{app_path}/Rakefile'
+ load 'rails/tasks/engine.rake'
+ RUBY
+
+ add_to_config "ActiveRecord::Base.timestamped_migrations = false"
+
+ boot_rails
+
+ Dir.chdir(@plugin.path) do
+ output = `bundle exec rake app:bukkits:install:migrations`
+ assert File.exists?("#{app_path}/db/migrate/0_add_first_name_to_users.bukkits.rb")
+ assert_match(/Copied migration 0_add_first_name_to_users.bukkits.rb from bukkits/, output)
+ assert_equal 1, Dir["#{app_path}/db/migrate/*.rb"].length
+ end
+ end
+
test "no rake task without migrations" do
boot_rails
require 'rake'
--
cgit v1.2.3
From 3527852dba6e68eca1c4ed3d8024c10e6a0ec008 Mon Sep 17 00:00:00 2001
From: Chad Jolly
Date: Sat, 21 Apr 2012 14:03:23 -0600
Subject: Improve signed cookies documentation
---
actionpack/lib/action_dispatch/middleware/cookies.rb | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb
index 0c717c8503..551e39eb33 100644
--- a/actionpack/lib/action_dispatch/middleware/cookies.rb
+++ b/actionpack/lib/action_dispatch/middleware/cookies.rb
@@ -29,6 +29,7 @@ module ActionDispatch
# # Sets a signed cookie, which prevents a user from tampering with its value.
# # The cookie is signed by your app's config.secret_token value.
# # Rails generates this value by default when you create a new Rails app.
+ # # Signed cookies must read with the signed method cookies.signed[:key]
# cookies.signed[:user_id] = current_user.id
#
# # Sets a "permanent" cookie (which expires in 20 years from now).
@@ -39,9 +40,10 @@ module ActionDispatch
#
# Examples for reading:
#
- # cookies[:user_name] # => "david"
- # cookies.size # => 2
- # cookies[:lat_lon] # => [47.68, -122.37]
+ # cookies[:user_name] # => "david"
+ # cookies.size # => 2
+ # cookies[:lat_lon] # => [47.68, -122.37]
+ # cookies.signed[:login] # => "XJ-122"
#
# Example for deleting:
#
--
cgit v1.2.3
From 2f681254ee9481f30baa53720c1570decb437725 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Mon, 30 Apr 2012 10:49:20 -0500
Subject: delete_all raise an error if a limit is provided - fixes #4979
---
activerecord/lib/active_record/relation.rb | 2 ++
activerecord/test/cases/relations_test.rb | 4 ++++
2 files changed, 6 insertions(+)
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 333d31d8a3..779e052e3c 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -390,6 +390,8 @@ module ActiveRecord
# If you need to destroy dependent associations or call your before_* or
# +after_destroy+ callbacks, use the +destroy_all+ method instead.
def delete_all(conditions = nil)
+ raise ActiveRecordError.new("delete_all doesn't support limit scope") if self.limit_value
+
if conditions
where(conditions).delete_all
else
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 4b8b57bac2..3ef357e297 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -688,6 +688,10 @@ class RelationTest < ActiveRecord::TestCase
assert davids.loaded?
end
+ def test_delete_all_limit_error
+ assert_raises(ActiveRecord::ActiveRecordError) { Author.limit(10).delete_all }
+ end
+
def test_select_argument_error
assert_raises(ArgumentError) { Developer.select }
end
--
cgit v1.2.3
From 13823a4cf35e99582c9b634a94c362d565b7841c Mon Sep 17 00:00:00 2001
From: James Sanders & Jason Noble
Date: Mon, 30 Apr 2012 11:37:31 -0600
Subject: Don't type cast values that don't respond to to_i to 1
---
.../active_record/connection_adapters/column.rb | 2 +-
activerecord/test/cases/column_test.rb | 24 ++++++++++++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb
index b7e1513422..9af8e46120 100644
--- a/activerecord/lib/active_record/connection_adapters/column.rb
+++ b/activerecord/lib/active_record/connection_adapters/column.rb
@@ -95,7 +95,7 @@ module ActiveRecord
case type
when :string, :text then value
- when :integer then value.to_i rescue value ? 1 : 0
+ when :integer then value.to_i
when :float then value.to_f
when :decimal then klass.value_to_decimal(value)
when :datetime, :timestamp then klass.string_to_time(value)
diff --git a/activerecord/test/cases/column_test.rb b/activerecord/test/cases/column_test.rb
index ccc57cb876..4fcf8a33a4 100644
--- a/activerecord/test/cases/column_test.rb
+++ b/activerecord/test/cases/column_test.rb
@@ -24,6 +24,30 @@ module ActiveRecord
assert !column.type_cast('off')
assert !column.type_cast('OFF')
end
+
+ def test_type_cast_integer
+ column = Column.new("field", nil, "integer")
+ assert_equal 1, column.type_cast(1)
+ assert_equal 1, column.type_cast('1')
+ assert_equal 1, column.type_cast('1ignore')
+ assert_equal 0, column.type_cast('bad1')
+ assert_equal 0, column.type_cast('bad')
+ assert_equal 1, column.type_cast(1.7)
+ assert_nil column.type_cast(nil)
+ end
+
+ def test_type_cast_non_integer_to_integer
+ column = Column.new("field", nil, "integer")
+ assert_raises(NoMethodError) do
+ column.type_cast([])
+ end
+ assert_raises(NoMethodError) do
+ column.type_cast(true)
+ end
+ assert_raises(NoMethodError) do
+ column.type_cast(false)
+ end
+ end
end
end
end
--
cgit v1.2.3
From d53877880835db241e1afeeb9bd6a8037c32e2fd Mon Sep 17 00:00:00 2001
From: Sebi Burkhard
Date: Tue, 1 May 2012 11:28:46 +0700
Subject: JSON: encode BigDecimal NaN/Infinity as null.
---
activesupport/lib/active_support/json/encoding.rb | 4 +++-
activesupport/test/json/encoding_test.rb | 1 +
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb
index e0dee0e072..ef45a546b6 100644
--- a/activesupport/lib/active_support/json/encoding.rb
+++ b/activesupport/lib/active_support/json/encoding.rb
@@ -183,6 +183,8 @@ class Numeric
end
class Float
+ # Encoding Infinity or NaN to JSON should return "null". The default returns
+ # "Infinity" or "NaN" what breaks parsing the JSON. E.g. JSON.parse('[NaN]').
def as_json(options = nil) finite? ? self : NilClass::AS_JSON end #:nodoc:
end
@@ -195,7 +197,7 @@ class BigDecimal
# That's why a JSON string is returned. The JSON literal is not numeric, but if
# the other end knows by contract that the data is supposed to be a BigDecimal,
# it still has the chance to post-process the string and get the real value.
- def as_json(options = nil) to_s end #:nodoc:
+ def as_json(options = nil) finite? ? to_s : NilClass::AS_JSON end #:nodoc:
end
class Regexp
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb
index 8493f4dc2c..babacf4d3a 100644
--- a/activesupport/test/json/encoding_test.rb
+++ b/activesupport/test/json/encoding_test.rb
@@ -30,6 +30,7 @@ class TestJSONEncoding < ActiveSupport::TestCase
[ 0.0/0.0, %(null) ],
[ 1.0/0.0, %(null) ],
[ -1.0/0.0, %(null) ],
+ [ BigDecimal('0.0')/BigDecimal('0.0'), %(null) ],
[ BigDecimal('2.5'), %("#{BigDecimal('2.5').to_s}") ]]
StringTests = [[ 'this is the ', %("this is the \\u003Cstring\\u003E")],
--
cgit v1.2.3
From 5722915fa7e172a5632b76023539f024e5711049 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Tue, 1 May 2012 19:27:36 +0530
Subject: changelog fixes. Closes #3911
---
activerecord/CHANGELOG.md | 13 -------------
1 file changed, 13 deletions(-)
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index aa84dacf07..6f0b5bfce6 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -580,19 +580,6 @@
a URI that specifies the connection configuration. For example:
ActiveRecord::Base.establish_connection 'postgres://localhost/foo'
-* Active Record's dynamic finder will now raise the error if you passing in less number of arguments than what you call in method signature.
-
- So if you were doing this and expecting the second argument to be nil:
-
- User.find_by_username_and_group("sikachu")
-
- You'll now get `ArgumentError: wrong number of arguments (1 for 2).` You'll then have to do this:
-
- User.find_by_username_and_group("sikachu", nil)
-
- *Prem Sichanugrist*
-
-
## Rails 3.1.0 (August 30, 2011) ##
* Add a proxy_association method to association proxies, which can be called by association
--
cgit v1.2.3
From 9ebfd634a71f7830e994f122bf09bdc6fe0ea17a Mon Sep 17 00:00:00 2001
From: Rodrigo Pavano
Date: Tue, 1 May 2012 15:54:15 -0300
Subject: Removing unused local vars in Queue tests
---
railties/test/application/queue_test.rb | 2 --
1 file changed, 2 deletions(-)
diff --git a/railties/test/application/queue_test.rb b/railties/test/application/queue_test.rb
index ec809d7cc1..71b0c2bc38 100644
--- a/railties/test/application/queue_test.rb
+++ b/railties/test/application/queue_test.rb
@@ -32,7 +32,6 @@ module ApplicationTests
test "in development mode, an enqueued job will be processed in a separate thread" do
app("development")
- current = Thread.current
job = Struct.new(:origin, :target).new(Thread.current)
def job.run
@@ -48,7 +47,6 @@ module ApplicationTests
test "in test mode, explicitly draining the queue will process it in a separate thread" do
app("test")
- current = Thread.current
job = Struct.new(:origin, :target).new(Thread.current)
def job.run
--
cgit v1.2.3
From eb3bfe293663746f42bae00b3b516418822f9a81 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 2 May 2012 01:10:59 +0530
Subject: remove unused pguides rake task from railties
---
railties/Rakefile | 9 ---------
1 file changed, 9 deletions(-)
diff --git a/railties/Rakefile b/railties/Rakefile
index c4a91a1d36..d1331deac3 100755
--- a/railties/Rakefile
+++ b/railties/Rakefile
@@ -60,12 +60,3 @@ task :release => :package do
Rake::Gemcutter::Tasks.new(spec).define
Rake::Task['gem:push'].invoke
end
-
-desc "Publish the guides"
-task :pguides => :generate_guides do
- require 'rake/contrib/sshpublisher'
- mkdir_p 'pkg'
- `tar -czf pkg/guides.gz guides/output`
- Rake::SshFilePublisher.new("web.rubyonrails.org", "/u/sites/guides.rubyonrails.org/public", "pkg", "guides.gz").upload
- `ssh web.rubyonrails.org 'cd /u/sites/guides.rubyonrails.org/public/ && tar -xvzf guides.gz && mv guides/output/* . && rm -rf guides*'`
-end
--
cgit v1.2.3
From 0ddec98b950ad73028c6c11f7d0b7a19e96687d7 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 2 May 2012 01:29:46 +0530
Subject: copy-edit guide [ci skip]
---
guides/source/command_line.textile | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/guides/source/command_line.textile b/guides/source/command_line.textile
index 95a01710b5..6dc78880f8 100644
--- a/guides/source/command_line.textile
+++ b/guides/source/command_line.textile
@@ -446,8 +446,7 @@ app/model/post.rb:
NOTE. When using specific annotations and custom annotations, the annotation name (FIXME, BUG etc) is not displayed in the output lines.
-Be default, rake notes will look in the app, config, lib, script and test directories for notes. If you would like to search additional directories,
-simply provide the directories as a comma seperated list in an environment variable +SOURCE_ANNOTATION_DIRECTORIES+.
+By default, +rake notes+ will look in the +app+, +config+, +lib+, +script+ and +test+ directories. If you would like to search other directories, you can provide them as a comma separated list in an environment variable +SOURCE_ANNOTATION_DIRECTORIES+.
$ export SOURCE_ANNOTATION_DIRECTORIES='rspec,vendor'
--
cgit v1.2.3
From 17f2958d853ef0dbee1aa6fa6d7b89d1ca3d4352 Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Tue, 1 May 2012 13:01:29 -0700
Subject: Use :github option in Gemfile and make hashes consistent
---
Gemfile | 18 +++++++++---------
railties/lib/rails/generators/app_base.rb | 16 ++++++++--------
2 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/Gemfile b/Gemfile
index c1486b725d..005031d843 100644
--- a/Gemfile
+++ b/Gemfile
@@ -3,30 +3,30 @@ source 'https://rubygems.org'
gemspec
if ENV['AREL']
- gem 'arel', :path => ENV['AREL']
+ gem 'arel', path: ENV['AREL']
else
gem 'arel'
end
-gem 'rack-test', :git => "git://github.com/brynary/rack-test.git"
+gem 'rack-test', github: "brynary/rack-test"
gem 'bcrypt-ruby', '~> 3.0.0'
gem 'jquery-rails'
if ENV['JOURNEY']
- gem 'journey', :path => ENV['JOURNEY']
+ gem 'journey', path: ENV['JOURNEY']
else
- gem 'journey', :git => "git://github.com/rails/journey"
+ gem 'journey', github: "rails/journey"
end
if ENV['AR_DEPRECATED_FINDERS']
gem 'active_record_deprecated_finders', path: ENV['AR_DEPRECATED_FINDERS']
else
- gem 'active_record_deprecated_finders', git: 'git://github.com/rails/active_record_deprecated_finders'
+ gem 'active_record_deprecated_finders', github: 'rails/active_record_deprecated_finders'
end
# This needs to be with require false to avoid
# it being automatically loaded by sprockets
-gem 'uglifier', '>= 1.0.3', :require => false
+gem 'uglifier', '>= 1.0.3', require: false
gem 'rake', '>= 0.8.7'
gem 'mocha', '>= 0.11.2'
@@ -36,7 +36,7 @@ group :doc do
# to a bug, but the PR that fixes it has been there
# for some weeks unapplied. As a temporary solution
# this is our own fork with the fix.
- gem 'sdoc', :git => 'git://github.com/fxn/sdoc.git'
+ gem 'sdoc', github: 'fxn/sdoc'
gem 'RedCloth', '~> 4.2'
gem 'w3c_validators'
end
@@ -90,9 +90,9 @@ if ENV['ORACLE_ENHANCED_PATH'] || ENV['ORACLE_ENHANCED']
gem 'ruby-oci8', '>= 2.0.4'
end
if ENV['ORACLE_ENHANCED_PATH']
- gem 'activerecord-oracle_enhanced-adapter', :path => ENV['ORACLE_ENHANCED_PATH']
+ gem 'activerecord-oracle_enhanced-adapter', path: ENV['ORACLE_ENHANCED_PATH']
else
- gem 'activerecord-oracle_enhanced-adapter', :git => 'git://github.com/rsim/oracle-enhanced.git'
+ gem 'activerecord-oracle_enhanced-adapter', github: 'rsim/oracle-enhanced'
end
end
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index b677e974c8..64d8ed0684 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -138,23 +138,23 @@ module Rails
if options.dev?
<<-GEMFILE.strip_heredoc
gem 'rails', :path => '#{Rails::Generators::RAILS_DEV_PATH}'
- gem 'journey', :git => 'https://github.com/rails/journey.git'
- gem 'arel', :git => 'https://github.com/rails/arel.git'
- gem 'active_record_deprecated_finders', :git => 'git://github.com/rails/active_record_deprecated_finders.git'
+ gem 'journey', :github => 'rails/journey'
+ gem 'arel', :github => 'rails/arel'
+ gem 'active_record_deprecated_finders', :github => 'rails/active_record_deprecated_finders'
GEMFILE
elsif options.edge?
<<-GEMFILE.strip_heredoc
- gem 'rails', :git => 'https://github.com/rails/rails.git'
- gem 'journey', :git => 'https://github.com/rails/journey.git'
- gem 'arel', :git => 'https://github.com/rails/arel.git'
- gem 'active_record_deprecated_finders', :git => 'git://github.com/rails/active_record_deprecated_finders.git'
+ gem 'rails', :github => 'rails/rails'
+ gem 'journey', :github => 'rails/journey'
+ gem 'arel', :github => 'rails/arel'
+ gem 'active_record_deprecated_finders', :github => 'rails/active_record_deprecated_finders'
GEMFILE
else
<<-GEMFILE.strip_heredoc
gem 'rails', '#{Rails::VERSION::STRING}'
# Bundle edge Rails instead:
- # gem 'rails', :git => 'https://github.com/rails/rails.git'
+ # gem 'rails', :github => 'rails/rails'
GEMFILE
end
end
--
cgit v1.2.3
From ed10107fa1f1e9f1bfe84c53ea6dc74efdbfbfc7 Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Tue, 1 May 2012 16:25:03 -0700
Subject: Fix tests
---
railties/test/generators/shared_generator_tests.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb
index 92117855b7..33c6c0d856 100644
--- a/railties/test/generators/shared_generator_tests.rb
+++ b/railties/test/generators/shared_generator_tests.rb
@@ -110,7 +110,7 @@ module SharedGeneratorTests
def test_edge_option
generator([destination_root], :edge => true).expects(:bundle_command).with('install').once
quietly { generator.invoke_all }
- assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("https://github.com/rails/rails.git")}["']$}
+ assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+:github\s+=>\s+["']#{Regexp.escape("rails/rails")}["']$}
end
def test_skip_gemfile
--
cgit v1.2.3
From a6c41601fe7d39320cc44091952e360ea2bae726 Mon Sep 17 00:00:00 2001
From: Carlos Antonio da Silva
Date: Tue, 1 May 2012 23:29:56 -0300
Subject: Build fix for plugin new generator change
Related to a06a84bf77082a7435973fa1b6c8254fb410f243
---
railties/test/generators/plugin_new_generator_test.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb
index 4bb5f04a79..6c31b80c7d 100644
--- a/railties/test/generators/plugin_new_generator_test.rb
+++ b/railties/test/generators/plugin_new_generator_test.rb
@@ -32,7 +32,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
content = capture(:stderr){ run_generator [File.join(destination_root, "things4.3")] }
assert_equal "Invalid plugin name things4.3. Please give a name which use only alphabetic or numeric or \"_\" characters.\n", content
-
+
content = capture(:stderr){ run_generator [File.join(destination_root, "43things")] }
assert_equal "Invalid plugin name 43things. Please give a name which does not start with numbers.\n", content
end
@@ -211,7 +211,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
def test_creating_gemspec
run_generator
assert_file "bukkits.gemspec", /s.name\s+= "bukkits"/
- assert_file "bukkits.gemspec", /s.files = Dir\["\{app,config,db,lib\}\/\*\*\/\*"\]/
+ assert_file "bukkits.gemspec", /s.files = Dir\["\{app,config,db,lib\}\/\*\*\/\*", "MIT-LICENSE", "Rakefile", "README\.rdoc"\]/
assert_file "bukkits.gemspec", /s.test_files = Dir\["test\/\*\*\/\*"\]/
assert_file "bukkits.gemspec", /s.version\s+ = Bukkits::VERSION/
end
--
cgit v1.2.3
From 5d685f9db77e05afe6fbf50ee77d1fb6f63aeaef Mon Sep 17 00:00:00 2001
From: Alexey Vakhov
Date: Fri, 27 Apr 2012 11:28:53 +0400
Subject: Add Rails::DBConsole tests
---
railties/lib/rails/commands/dbconsole.rb | 56 ++++++++------
railties/test/commands/dbconsole_test.rb | 128 +++++++++++++++++++++++++++++++
2 files changed, 162 insertions(+), 22 deletions(-)
create mode 100644 railties/test/commands/dbconsole_test.rb
diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb
index 6fc127efae..25a8caeec3 100644
--- a/railties/lib/rails/commands/dbconsole.rb
+++ b/railties/lib/rails/commands/dbconsole.rb
@@ -5,12 +5,15 @@ require 'rbconfig'
module Rails
class DBConsole
+ attr_reader :arguments
+
def self.start(app)
new(app).start
end
- def initialize(app)
+ def initialize(app, arguments = ARGV)
@app = app
+ @arguments = arguments
end
def start
@@ -31,8 +34,8 @@ module Rails
options['header'] = h
end
- opt.parse!(ARGV)
- abort opt.to_s unless (0..1).include?(ARGV.size)
+ opt.parse!(arguments)
+ abort opt.to_s unless (0..1).include?(arguments.size)
end
unless config = @app.config.database_configuration[Rails.env]
@@ -40,20 +43,6 @@ module Rails
end
- def find_cmd(*commands)
- dirs_on_path = ENV['PATH'].to_s.split(File::PATH_SEPARATOR)
- commands += commands.map{|cmd| "#{cmd}.exe"} if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
-
- full_path_command = nil
- found = commands.detect do |cmd|
- dir = dirs_on_path.detect do |path|
- full_path_command = File.join(path, cmd)
- File.executable? full_path_command
- end
- end
- found ? full_path_command : abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.")
- end
-
case config["adapter"]
when /^mysql/
args = {
@@ -72,17 +61,17 @@ module Rails
args << config['database']
- exec(find_cmd('mysql', 'mysql5'), *args)
+ find_cmd_and_exec(['mysql', 'mysql5'], *args)
when "postgresql", "postgres"
ENV['PGUSER'] = config["username"] if config["username"]
ENV['PGHOST'] = config["host"] if config["host"]
ENV['PGPORT'] = config["port"].to_s if config["port"]
ENV['PGPASSWORD'] = config["password"].to_s if config["password"] && include_password
- exec(find_cmd('psql'), config["database"])
+ find_cmd_and_exec('psql', config["database"])
when "sqlite"
- exec(find_cmd('sqlite'), config["database"])
+ find_cmd_and_exec('sqlite', config["database"])
when "sqlite3"
args = []
@@ -91,7 +80,7 @@ module Rails
args << "-header" if options['header']
args << config['database']
- exec(find_cmd('sqlite3'), *args)
+ find_cmd_and_exec('sqlite3', *args)
when "oracle", "oracle_enhanced"
logon = ""
@@ -102,12 +91,35 @@ module Rails
logon << "@#{config['database']}" if config['database']
end
- exec(find_cmd('sqlplus'), logon)
+ find_cmd_and_exec('sqlplus', logon)
else
abort "Unknown command-line client for #{config['database']}. Submit a Rails patch to add support!"
end
end
+
+ protected
+
+ def find_cmd_and_exec(commands, *args)
+ commands = Array(commands)
+
+ dirs_on_path = ENV['PATH'].to_s.split(File::PATH_SEPARATOR)
+ commands += commands.map{|cmd| "#{cmd}.exe"} if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
+
+ full_path_command = nil
+ found = commands.detect do |cmd|
+ dir = dirs_on_path.detect do |path|
+ full_path_command = File.join(path, cmd)
+ File.executable? full_path_command
+ end
+ end
+
+ if found
+ exec full_path_command, *args
+ else
+ abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.")
+ end
+ end
end
end
diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb
new file mode 100644
index 0000000000..0bf417c014
--- /dev/null
+++ b/railties/test/commands/dbconsole_test.rb
@@ -0,0 +1,128 @@
+require 'abstract_unit'
+require 'rails/commands/dbconsole'
+
+class Rails::DBConsoleTest < ActiveSupport::TestCase
+ def teardown
+ %w[PGUSER PGHOST PGPORT PGPASSWORD'].each{|key| ENV.delete(key)}
+ end
+
+ def test_no_database_configured
+ start [], false
+ assert aborted
+ assert_match /No database is configured for the environment '\w+'/, output
+ end
+
+ def test_mysql
+ dbconsole.expects(:find_cmd_and_exec).with(%w[mysql mysql5], 'db')
+ start [], {adapter: 'mysql', database: 'db'}
+ assert !aborted
+ end
+
+ def test_mysql_full
+ dbconsole.expects(:find_cmd_and_exec).with(%w[mysql mysql5], '--host=locahost', '--port=1234', '--socket=socket', '--user=user', '--default-character-set=UTF-8', '-p', 'db')
+ start [], {adapter: 'mysql', database: 'db', host: 'locahost', port: 1234, socket: 'socket', username: 'user', password: 'qwerty', encoding: 'UTF-8'}
+ assert !aborted
+ end
+
+ def test_mysql_include_password
+ dbconsole.expects(:find_cmd_and_exec).with(%w[mysql mysql5], '--user=user', '--password=qwerty', 'db')
+ start ['-p'], {adapter: 'mysql', database: 'db', username: 'user', password: 'qwerty'}
+ assert !aborted
+ end
+
+ def test_postgresql
+ dbconsole.expects(:find_cmd_and_exec).with('psql', 'db')
+ start [], {adapter: 'postgresql', database: 'db'}
+ assert !aborted
+ end
+
+ def test_postgresql_full
+ dbconsole.expects(:find_cmd_and_exec).with('psql', 'db')
+ start [], {adapter: 'postgresql', database: 'db', username: 'user', password: 'q1w2e3', host: 'host', port: 5432}
+ assert !aborted
+ assert_equal 'user', ENV['PGUSER']
+ assert_equal 'host', ENV['PGHOST']
+ assert_equal '5432', ENV['PGPORT']
+ assert_not_equal 'q1w2e3', ENV['PGPASSWORD']
+ end
+
+ def test_postgresql_include_password
+ dbconsole.expects(:find_cmd_and_exec).with('psql', 'db')
+ start ['-p'], {adapter: 'postgresql', database: 'db', username: 'user', password: 'q1w2e3'}
+ assert !aborted
+ assert_equal 'user', ENV['PGUSER']
+ assert_equal 'q1w2e3', ENV['PGPASSWORD']
+ end
+
+ def test_sqlite
+ dbconsole.expects(:find_cmd_and_exec).with('sqlite', 'db')
+ start [], {adapter: 'sqlite', database: 'db'}
+ assert !aborted
+ end
+
+ def test_sqlite3
+ dbconsole.expects(:find_cmd_and_exec).with('sqlite3', 'db')
+ start [], {adapter: 'sqlite3', database: 'db'}
+ assert !aborted
+ end
+
+ def test_sqlite3_mode
+ dbconsole.expects(:find_cmd_and_exec).with('sqlite3', '-html', 'db')
+ start ['--mode', 'html'], {adapter: 'sqlite3', database: 'db'}
+ assert !aborted
+ end
+
+ def test_sqlite3_header
+ dbconsole.expects(:find_cmd_and_exec).with('sqlite3', '-header', 'db')
+ start ['--header'], {adapter: 'sqlite3', database: 'db'}
+ assert !aborted
+ end
+
+ def test_oracle
+ dbconsole.expects(:find_cmd_and_exec).with('sqlplus', 'user@db')
+ start [], {adapter: 'oracle', database: 'db', username: 'user', password: 'secret'}
+ assert !aborted
+ end
+
+ def test_oracle_include_password
+ dbconsole.expects(:find_cmd_and_exec).with('sqlplus', 'user/secret@db')
+ start ['-p'], {adapter: 'oracle', database: 'db', username: 'user', password: 'secret'}
+ assert !aborted
+ end
+
+ def test_unknown_command_line_client
+ start [], {adapter: 'unknown', database: 'db'}
+ assert aborted
+ assert_match /Unknown command-line client for db/, output
+ end
+
+ private
+ attr_reader :aborted, :output
+
+ def dbconsole
+ @dbconsole ||= Rails::DBConsole.new(app)
+ end
+
+ def start(argv = [], database_configuration = {})
+ dbconsole.stubs(arguments: argv)
+ app.config.stubs(database_configuration: {
+ Rails.env => database_configuration ? database_configuration.stringify_keys : database_configuration
+ })
+
+ @aborted = false
+ @output = capture(:stderr) do
+ begin
+ dbconsole.start
+ rescue SystemExit
+ @aborted = true
+ end
+ end
+ end
+
+ def app
+ @app ||= begin
+ config = mock("config")
+ stub("app", config: config)
+ end
+ end
+end
--
cgit v1.2.3
From 18aa1ae29c3459a6b2c10c7634770209a72c6cfe Mon Sep 17 00:00:00 2001
From: David FRANCOIS
Date: Sat, 28 Apr 2012 23:44:51 +0200
Subject: BigDecimal string wrapping in JSON serialization can now be
opted-out, fixes #6033
---
activesupport/CHANGELOG.md | 3 +++
activesupport/lib/active_support/json/encoding.rb | 15 ++++++++++++++-
activesupport/test/json/encoding_test.rb | 11 +++++++++++
3 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index d32c0f3aed..82921741b8 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -32,6 +32,9 @@
* Unicode database updated to 6.1.0.
+* Adds `encode_big_decimal_as_string` option to force JSON serialization of BigDecimals as numeric instead
+ of wrapping them in strings for safety.
+
## Rails 3.2.2 (March 1, 2012) ##
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb
index ef45a546b6..ab12f3f454 100644
--- a/activesupport/lib/active_support/json/encoding.rb
+++ b/activesupport/lib/active_support/json/encoding.rb
@@ -17,6 +17,7 @@ module ActiveSupport
class << self
delegate :use_standard_json_time_format, :use_standard_json_time_format=,
:escape_html_entities_in_json, :escape_html_entities_in_json=,
+ :encode_big_decimal_as_string, :encode_big_decimal_as_string=,
:to => :'ActiveSupport::JSON::Encoding'
end
@@ -104,6 +105,9 @@ module ActiveSupport
# If true, use ISO 8601 format for dates and times. Otherwise, fall back to the Active Support legacy format.
attr_accessor :use_standard_json_time_format
+ # If false, serializes BigDecimal objects as numeric instead of wrapping them in a string
+ attr_accessor :encode_big_decimal_as_string
+
attr_accessor :escape_regex
attr_reader :escape_html_entities_in_json
@@ -133,6 +137,7 @@ module ActiveSupport
self.use_standard_json_time_format = true
self.escape_html_entities_in_json = false
+ self.encode_big_decimal_as_string = true
end
end
end
@@ -197,7 +202,15 @@ class BigDecimal
# That's why a JSON string is returned. The JSON literal is not numeric, but if
# the other end knows by contract that the data is supposed to be a BigDecimal,
# it still has the chance to post-process the string and get the real value.
- def as_json(options = nil) finite? ? to_s : NilClass::AS_JSON end #:nodoc:
+ #
+ # Use ActiveSupport.use_standard_json_big_decimal_format = true to override this behaviour
+ def as_json(options = nil) #:nodoc:
+ if finite?
+ ActiveSupport.encode_big_decimal_as_string ? to_s : self
+ else
+ NilClass::AS_JSON
+ end
+ end
end
class Regexp
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb
index babacf4d3a..0566ebf291 100644
--- a/activesupport/test/json/encoding_test.rb
+++ b/activesupport/test/json/encoding_test.rb
@@ -274,6 +274,17 @@ class TestJSONEncoding < ActiveSupport::TestCase
JSON.parse(json_string_and_date))
end
+ def test_opt_out_big_decimal_string_serialization
+ big_decimal = BigDecimal('2.5')
+
+ begin
+ ActiveSupport.encode_big_decimal_as_string = false
+ assert_equal big_decimal.to_s, big_decimal.to_json
+ ensure
+ ActiveSupport.encode_big_decimal_as_string = true
+ end
+ end
+
protected
def object_keys(json_object)
--
cgit v1.2.3
From 6d6907e40d2ff5b08560ee24fc192a72acfa0347 Mon Sep 17 00:00:00 2001
From: Edgars Beigarts
Date: Mon, 21 Nov 2011 10:30:07 +0200
Subject: Refactored remove_column
---
.../active_record/connection_adapters/abstract/schema_definitions.rb | 2 +-
.../active_record/connection_adapters/abstract/schema_statements.rb | 2 --
activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb | 2 +-
activerecord/test/cases/migration_test.rb | 4 ++--
4 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
index 3546873550..f0b6ae2b7d 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
@@ -408,7 +408,7 @@ module ActiveRecord
# t.remove(:qualification)
# t.remove(:qualification, :experience)
def remove(*column_names)
- @base.remove_column(@table_name, column_names)
+ @base.remove_column(@table_name, *column_names)
end
# Removes the given index from the table.
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
index 30a4f9aa35..e7a4f061fd 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -618,8 +618,6 @@ module ActiveRecord
end
def columns_for_remove(table_name, *column_names)
- column_names = column_names.flatten
-
raise ArgumentError.new("You must specify at least one column name. Example: remove_column(:people, :first_name)") if column_names.blank?
column_names.map {|column_name| quote_column_name(column_name) }
end
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
index 83f75e3505..44e407a561 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
@@ -446,7 +446,7 @@ module ActiveRecord
def remove_column(table_name, *column_names) #:nodoc:
raise ArgumentError.new("You must specify at least one column name. Example: remove_column(:people, :first_name)") if column_names.empty?
- column_names.flatten.each do |column_name|
+ column_names.each do |column_name|
alter_table(table_name) do |definition|
definition.columns.delete(definition[column_name])
end
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb
index e71b84a3a5..f788690b0d 100644
--- a/activerecord/test/cases/migration_test.rb
+++ b/activerecord/test/cases/migration_test.rb
@@ -588,14 +588,14 @@ class ChangeTableMigrationsTest < ActiveRecord::TestCase
def test_remove_drops_single_column
with_change_table do |t|
- @connection.expects(:remove_column).with(:delete_me, [:bar])
+ @connection.expects(:remove_column).with(:delete_me, :bar)
t.remove :bar
end
end
def test_remove_drops_multiple_columns
with_change_table do |t|
- @connection.expects(:remove_column).with(:delete_me, [:bar, :baz])
+ @connection.expects(:remove_column).with(:delete_me, :bar, :baz)
t.remove :bar, :baz
end
end
--
cgit v1.2.3
From ce5c2b88fead992db51476c14cc2d7c323f5cd0c Mon Sep 17 00:00:00 2001
From: Bogdan Gusiev
Date: Wed, 2 May 2012 10:41:34 +0300
Subject: ActionPack: remove tests for hash_for_* methods
---
actionpack/test/controller/routing_test.rb | 18 ------------------
1 file changed, 18 deletions(-)
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index 9441b46d47..bcb4e6a766 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -891,23 +891,6 @@ class RouteSetTest < ActiveSupport::TestCase
MockController.build(set.url_helpers).new
end
- def test_named_route_hash_access_method
- controller = setup_named_route_test
-
- assert_equal(
- { :controller => 'people', :action => 'show', :id => 5, :use_route => "show", :only_path => false },
- controller.send(:hash_for_show_url, :id => 5))
-
- assert_equal(
- { :controller => 'people', :action => 'index', :use_route => "index", :only_path => false },
- controller.send(:hash_for_index_url))
-
- assert_equal(
- { :controller => 'people', :action => 'show', :id => 5, :use_route => "show", :only_path => true },
- controller.send(:hash_for_show_path, :id => 5)
- )
- end
-
def test_named_route_url_method
controller = setup_named_route_test
@@ -919,7 +902,6 @@ class RouteSetTest < ActiveSupport::TestCase
assert_equal "http://test.host/admin/users", controller.send(:users_url)
assert_equal '/admin/users', controller.send(:users_path)
- assert_equal '/admin/users', url_for(set, controller.send(:hash_for_users_url), { :controller => 'users', :action => 'index' })
end
def test_named_route_url_method_with_anchor
--
cgit v1.2.3
From 5eb32af28b16cf8d26ce291232239892154227d4 Mon Sep 17 00:00:00 2001
From: Oscar Del Ben
Date: Wed, 2 May 2012 10:21:02 +0200
Subject: Use new hash syntax in generated Gemfile
---
railties/lib/rails/generators/app_base.rb | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index 64d8ed0684..6df33d65e9 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -137,24 +137,24 @@ module Rails
def rails_gemfile_entry
if options.dev?
<<-GEMFILE.strip_heredoc
- gem 'rails', :path => '#{Rails::Generators::RAILS_DEV_PATH}'
- gem 'journey', :github => 'rails/journey'
- gem 'arel', :github => 'rails/arel'
- gem 'active_record_deprecated_finders', :github => 'rails/active_record_deprecated_finders'
+ gem 'rails', path: '#{Rails::Generators::RAILS_DEV_PATH}'
+ gem 'journey', github: 'rails/journey'
+ gem 'arel', github: 'rails/arel'
+ gem 'active_record_deprecated_finders', github: 'rails/active_record_deprecated_finders'
GEMFILE
elsif options.edge?
<<-GEMFILE.strip_heredoc
- gem 'rails', :github => 'rails/rails'
- gem 'journey', :github => 'rails/journey'
- gem 'arel', :github => 'rails/arel'
- gem 'active_record_deprecated_finders', :github => 'rails/active_record_deprecated_finders'
+ gem 'rails', github: 'rails/rails'
+ gem 'journey', github: 'rails/journey'
+ gem 'arel', github: 'rails/arel'
+ gem 'active_record_deprecated_finders', github: 'rails/active_record_deprecated_finders'
GEMFILE
else
<<-GEMFILE.strip_heredoc
gem 'rails', '#{Rails::VERSION::STRING}'
# Bundle edge Rails instead:
- # gem 'rails', :github => 'rails/rails'
+ # gem 'rails', github: 'rails/rails'
GEMFILE
end
end
@@ -194,9 +194,9 @@ module Rails
# Gems used only for assets and not required
# in production environments by default.
group :assets do
- gem 'sprockets-rails', :git => 'https://github.com/rails/sprockets-rails.git'
- gem 'sass-rails', :git => 'https://github.com/rails/sass-rails.git'
- gem 'coffee-rails', :git => 'https://github.com/rails/coffee-rails.git'
+ gem 'sprockets-rails', github: 'rails/sprockets-rails'
+ gem 'sass-rails', github: 'rails/sass-rails'
+ gem 'coffee-rails', github: 'rails/coffee-rails'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
#{javascript_runtime_gemfile_entry}
@@ -208,7 +208,7 @@ module Rails
# Gems used only for assets and not required
# in production environments by default.
group :assets do
- gem 'sprockets-rails', :git => 'https://github.com/rails/sprockets-rails.git'
+ gem 'sprockets-rails', github: 'rails/sprockets-rails'
gem 'sass-rails', '~> 4.0.0.beta'
gem 'coffee-rails', '~> 4.0.0.beta'
@@ -230,7 +230,7 @@ module Rails
if defined?(JRUBY_VERSION)
"gem 'therubyrhino'\n"
else
- "# gem 'therubyracer', :platform => :ruby\n"
+ "# gem 'therubyracer', platform: :ruby\n"
end
end
--
cgit v1.2.3
From 84feca4aaafb597f8cc16c3a5c16ce7014d95ada Mon Sep 17 00:00:00 2001
From: "Roman V. Babenko"
Date: Wed, 2 May 2012 13:36:16 +0300
Subject: Rakefile executable attributes and shebang lines has been removed
---
Rakefile | 2 --
actionmailer/Rakefile | 1 -
actionpack/Rakefile | 1 -
activemodel/Rakefile | 0
activerecord/Rakefile | 1 -
activesupport/Rakefile | 0
railties/Rakefile | 1 -
railties/lib/rails/generators/rails/app/templates/Rakefile | 1 -
railties/lib/rails/generators/rails/plugin_new/templates/Rakefile | 1 -
9 files changed, 8 deletions(-)
mode change 100755 => 100644 Rakefile
mode change 100755 => 100644 actionmailer/Rakefile
mode change 100755 => 100644 actionpack/Rakefile
mode change 100755 => 100644 activemodel/Rakefile
mode change 100755 => 100644 activerecord/Rakefile
mode change 100755 => 100644 activesupport/Rakefile
mode change 100755 => 100644 railties/Rakefile
mode change 100755 => 100644 railties/lib/rails/generators/rails/app/templates/Rakefile
mode change 100755 => 100644 railties/lib/rails/generators/rails/plugin_new/templates/Rakefile
diff --git a/Rakefile b/Rakefile
old mode 100755
new mode 100644
index 0d218844b2..21eb60bbe1
--- a/Rakefile
+++ b/Rakefile
@@ -1,5 +1,3 @@
-#!/usr/bin/env rake
-
require 'rdoc/task'
require 'sdoc'
require 'net/http'
diff --git a/actionmailer/Rakefile b/actionmailer/Rakefile
old mode 100755
new mode 100644
index 8f5aeb9603..c1c4171cdf
--- a/actionmailer/Rakefile
+++ b/actionmailer/Rakefile
@@ -1,4 +1,3 @@
-#!/usr/bin/env rake
require 'rake/testtask'
require 'rake/packagetask'
require 'rubygems/package_task'
diff --git a/actionpack/Rakefile b/actionpack/Rakefile
old mode 100755
new mode 100644
index bb1e704767..17d95bfd1d
--- a/actionpack/Rakefile
+++ b/actionpack/Rakefile
@@ -1,4 +1,3 @@
-#!/usr/bin/env rake
require 'rake/testtask'
require 'rake/packagetask'
require 'rubygems/package_task'
diff --git a/activemodel/Rakefile b/activemodel/Rakefile
old mode 100755
new mode 100644
diff --git a/activerecord/Rakefile b/activerecord/Rakefile
old mode 100755
new mode 100644
index 4090293b56..7feb0b75a0
--- a/activerecord/Rakefile
+++ b/activerecord/Rakefile
@@ -1,4 +1,3 @@
-#!/usr/bin/env rake
require 'rake/testtask'
require 'rake/packagetask'
require 'rubygems/package_task'
diff --git a/activesupport/Rakefile b/activesupport/Rakefile
old mode 100755
new mode 100644
diff --git a/railties/Rakefile b/railties/Rakefile
old mode 100755
new mode 100644
index d1331deac3..108413235a
--- a/railties/Rakefile
+++ b/railties/Rakefile
@@ -1,4 +1,3 @@
-#!/usr/bin/env rake
require 'rake/testtask'
require 'rubygems/package_task'
diff --git a/railties/lib/rails/generators/rails/app/templates/Rakefile b/railties/lib/rails/generators/rails/app/templates/Rakefile
old mode 100755
new mode 100644
index 4dc1023f1f..6eb23f68a3
--- a/railties/lib/rails/generators/rails/app/templates/Rakefile
+++ b/railties/lib/rails/generators/rails/app/templates/Rakefile
@@ -1,4 +1,3 @@
-#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile b/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile
old mode 100755
new mode 100644
index b7bc69d2e5..743036362e
--- a/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile
@@ -1,4 +1,3 @@
-#!/usr/bin/env rake
begin
require 'bundler/setup'
rescue LoadError
--
cgit v1.2.3
From e17cc4d493e369217f216418287a5a0de084915d Mon Sep 17 00:00:00 2001
From: "Roman V. Babenko"
Date: Wed, 2 May 2012 13:56:13 +0300
Subject: Gem cont presence checking has been removed
---
railties/lib/rails/backtrace_cleaner.rb | 2 --
railties/test/backtrace_cleaner_test.rb | 32 +++++++++++++++-----------------
2 files changed, 15 insertions(+), 19 deletions(-)
diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb
index 539f68a3be..8cc8eb1103 100644
--- a/railties/lib/rails/backtrace_cleaner.rb
+++ b/railties/lib/rails/backtrace_cleaner.rb
@@ -17,8 +17,6 @@ module Rails
private
def add_gem_filters
- return unless defined?(Gem)
-
gems_paths = (Gem.path | [Gem.default_dir]).map { |p| Regexp.escape(p) }
return if gems_paths.empty?
diff --git a/railties/test/backtrace_cleaner_test.rb b/railties/test/backtrace_cleaner_test.rb
index cbe7d35f6d..2dd74f8fd1 100644
--- a/railties/test/backtrace_cleaner_test.rb
+++ b/railties/test/backtrace_cleaner_test.rb
@@ -1,26 +1,24 @@
require 'abstract_unit'
require 'rails/backtrace_cleaner'
-if defined? Gem
- class BacktraceCleanerVendorGemTest < ActiveSupport::TestCase
- def setup
- @cleaner = Rails::BacktraceCleaner.new
- end
+class BacktraceCleanerVendorGemTest < ActiveSupport::TestCase
+ def setup
+ @cleaner = Rails::BacktraceCleaner.new
+ end
+
+ test "should format installed gems correctly" do
+ @backtrace = [ "#{Gem.path[0]}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
+ @result = @cleaner.clean(@backtrace, :all)
+ assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0]
+ end
- test "should format installed gems correctly" do
- @backtrace = [ "#{Gem.path[0]}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
+ test "should format installed gems not in Gem.default_dir correctly" do
+ @target_dir = Gem.path.detect { |p| p != Gem.default_dir }
+ # skip this test if default_dir is the only directory on Gem.path
+ if @target_dir
+ @backtrace = [ "#{@target_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
@result = @cleaner.clean(@backtrace, :all)
assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0]
end
-
- test "should format installed gems not in Gem.default_dir correctly" do
- @target_dir = Gem.path.detect { |p| p != Gem.default_dir }
- # skip this test if default_dir is the only directory on Gem.path
- if @target_dir
- @backtrace = [ "#{@target_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
- @result = @cleaner.clean(@backtrace, :all)
- assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0]
- end
- end
end
end
--
cgit v1.2.3
From 1206e88a7535d29487b416121c31b23762a12abd Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Wed, 2 May 2012 16:27:22 +0530
Subject: build fix for SharedGeneratorTests
---
railties/test/generators/shared_generator_tests.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb
index 33c6c0d856..325f9475e7 100644
--- a/railties/test/generators/shared_generator_tests.rb
+++ b/railties/test/generators/shared_generator_tests.rb
@@ -104,13 +104,13 @@ module SharedGeneratorTests
generator([destination_root], :dev => true).expects(:bundle_command).with('install').once
quietly { generator.invoke_all }
rails_path = File.expand_path('../../..', Rails.root)
- assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:path\s+=>\s+["']#{Regexp.escape(rails_path)}["']$/
+ assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:path\s+:\s+["']#{Regexp.escape(rails_path)}["']$/
end
def test_edge_option
generator([destination_root], :edge => true).expects(:bundle_command).with('install').once
quietly { generator.invoke_all }
- assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+:github\s+=>\s+["']#{Regexp.escape("rails/rails")}["']$}
+ assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+:github\s+:\s+["']#{Regexp.escape("rails/rails")}["']$}
end
def test_skip_gemfile
--
cgit v1.2.3
From 1cfa34f83e89d8b66bafa2eb866ed4e023a404ed Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Wed, 2 May 2012 17:31:29 +0530
Subject: Fix build for railties generators
---
railties/test/generators/app_generator_test.rb | 2 +-
railties/test/generators/shared_generator_tests.rb | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 94983c504c..d13dc8d4ac 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -246,7 +246,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
if defined?(JRUBY_VERSION)
assert_file "Gemfile", /gem\s+["']therubyrhino["']$/
else
- assert_file "Gemfile", /# gem\s+["']therubyracer["']+, :platform => :ruby$/
+ assert_file "Gemfile", /# gem\s+["']therubyracer["']+, platform: :ruby$/
end
end
diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb
index 325f9475e7..e78e67725d 100644
--- a/railties/test/generators/shared_generator_tests.rb
+++ b/railties/test/generators/shared_generator_tests.rb
@@ -104,13 +104,13 @@ module SharedGeneratorTests
generator([destination_root], :dev => true).expects(:bundle_command).with('install').once
quietly { generator.invoke_all }
rails_path = File.expand_path('../../..', Rails.root)
- assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:path\s+:\s+["']#{Regexp.escape(rails_path)}["']$/
+ assert_file 'Gemfile', /^gem\s+["']rails["'],\s+path:\s+["']#{Regexp.escape(rails_path)}["']$/
end
def test_edge_option
generator([destination_root], :edge => true).expects(:bundle_command).with('install').once
quietly { generator.invoke_all }
- assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+:github\s+:\s+["']#{Regexp.escape("rails/rails")}["']$}
+ assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["']$}
end
def test_skip_gemfile
--
cgit v1.2.3
From 02f2e3d538f79d61ab5abdcdb3bea30843d3ee4a Mon Sep 17 00:00:00 2001
From: Bogdan Gusiev
Date: Wed, 2 May 2012 16:04:27 +0300
Subject: ActionPack routes: remove some useless code.
---
.../lib/action_dispatch/routing/route_set.rb | 30 +++-------------------
1 file changed, 4 insertions(+), 26 deletions(-)
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 7a7810a95c..6e685c84fd 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -99,12 +99,12 @@ module ActionDispatch
@module = Module.new do
protected
- def handle_positional_args(args, options, route)
+ def handle_positional_args(args, options, segment_keys)
inner_options = args.extract_options!
result = options.dup
if args.any?
- keys = route.segment_keys
+ keys = segment_keys
if args.size < keys.size - 1 # take format into account
keys -= self.url_options.keys if self.respond_to?(:url_options)
keys -= options.keys
@@ -161,34 +161,13 @@ module ActionDispatch
end
end
- def hash_access_name(name, only_path)
- if only_path
- :"hash_for_#{name}_path"
- else
- :"hash_for_#{name}_url"
- end
- end
-
def define_named_route_methods(name, route)
[true, false].each do |only_path|
hash = route.defaults.merge(:use_route => name, :only_path => only_path)
- define_hash_access route, name, hash
define_url_helper route, name, hash
end
end
- def define_hash_access(route, name, options)
- selector = hash_access_name(name, options[:only_path])
-
- @module.module_eval do
- redefine_method(selector) do |*args|
- self.handle_positional_args(args, options, route)
- end
- protected selector
- end
- helpers << selector
- end
-
# Create a url helper allowing ordered parameters to be associated
# with corresponding dynamic segments, so you can do:
#
@@ -204,7 +183,6 @@ module ActionDispatch
#
def define_url_helper(route, name, options)
selector = url_helper_name(name, options[:only_path])
- hash_access_method = hash_access_name(name, options[:only_path])
if optimize_helper?(route)
@module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
@@ -215,7 +193,7 @@ module ActionDispatch
options[:path] = "#{optimized_helper(route)}"
ActionDispatch::Http::URL.url_for(options)
else
- url_for(#{hash_access_method}(*args))
+ url_for(handle_positional_args(args, #{options.inspect}, #{route.segment_keys.inspect}))
end
end
END_EVAL
@@ -223,7 +201,7 @@ module ActionDispatch
@module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
remove_possible_method :#{selector}
def #{selector}(*args)
- url_for(#{hash_access_method}(*args))
+ url_for(handle_positional_args(args, #{options.inspect}, #{route.segment_keys.inspect}))
end
END_EVAL
end
--
cgit v1.2.3
From da88d800b8e67841af8b4270c13bcac4559b6f74 Mon Sep 17 00:00:00 2001
From: Bogdan Gusiev
Date: Wed, 2 May 2012 18:31:45 +0300
Subject: RouteSet: remove some code dups
---
.../lib/action_dispatch/routing/route_set.rb | 29 ++++++++--------------
1 file changed, 10 insertions(+), 19 deletions(-)
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 6e685c84fd..57ce7b4ba9 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -184,27 +184,18 @@ module ActionDispatch
def define_url_helper(route, name, options)
selector = url_helper_name(name, options[:only_path])
- if optimize_helper?(route)
- @module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
- remove_possible_method :#{selector}
- def #{selector}(*args)
- if args.size == #{route.required_parts.size} && !args.last.is_a?(Hash) && optimize_routes_generation?
- options = #{options.inspect}.merge!(url_options)
- options[:path] = "#{optimized_helper(route)}"
- ActionDispatch::Http::URL.url_for(options)
- else
- url_for(handle_positional_args(args, #{options.inspect}, #{route.segment_keys.inspect}))
- end
- end
- END_EVAL
- else
- @module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
- remove_possible_method :#{selector}
- def #{selector}(*args)
+ @module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
+ remove_possible_method :#{selector}
+ def #{selector}(*args)
+ if #{optimize_helper?(route)} && args.size == #{route.required_parts.size} && !args.last.is_a?(Hash) && optimize_routes_generation?
+ options = #{options.inspect}.merge!(url_options)
+ options[:path] = "#{optimized_helper(route)}"
+ ActionDispatch::Http::URL.url_for(options)
+ else
url_for(handle_positional_args(args, #{options.inspect}, #{route.segment_keys.inspect}))
end
- END_EVAL
- end
+ end
+ END_EVAL
helpers << selector
end
--
cgit v1.2.3
From 61ba0fe82c440d244d70afc9aad5c8ea9d6e810d Mon Sep 17 00:00:00 2001
From: Mark Turner
Date: Wed, 2 May 2012 11:14:40 -0700
Subject: Enable ActionDispatch::Http::Headers to support fetch
---
actionpack/lib/action_dispatch/http/headers.rb | 15 ++++++++-------
actionpack/test/dispatch/header_test.rb | 5 +++++
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/actionpack/lib/action_dispatch/http/headers.rb b/actionpack/lib/action_dispatch/http/headers.rb
index 040b51e040..a3bb25f75a 100644
--- a/actionpack/lib/action_dispatch/http/headers.rb
+++ b/actionpack/lib/action_dispatch/http/headers.rb
@@ -14,17 +14,18 @@ module ActionDispatch
end
def [](header_name)
- if include?(header_name)
- super
- else
- super(env_name(header_name))
- end
+ super env_name(header_name)
+ end
+
+ def fetch(header_name, default=nil, &block)
+ super env_name(header_name), default, &block
end
private
- # Converts a HTTP header name to an environment variable name.
+ # Converts a HTTP header name to an environment variable name if it is
+ # not contained within the headers hash.
def env_name(header_name)
- @@env_cache[header_name]
+ include?(header_name) ? header_name : @@env_cache[header_name]
end
end
end
diff --git a/actionpack/test/dispatch/header_test.rb b/actionpack/test/dispatch/header_test.rb
index ec6ba494dc..bc7cad8db5 100644
--- a/actionpack/test/dispatch/header_test.rb
+++ b/actionpack/test/dispatch/header_test.rb
@@ -13,4 +13,9 @@ class HeaderTest < ActiveSupport::TestCase
assert_equal "text/plain", @headers["CONTENT_TYPE"]
assert_equal "text/plain", @headers["HTTP_CONTENT_TYPE"]
end
+
+ test "fetch" do
+ assert_equal "text/plain", @headers.fetch("content-type", nil)
+ assert_equal "not found", @headers.fetch('not-found', 'not found')
+ end
end
--
cgit v1.2.3
From 976e7e44ee68cb32f74a8de9b81e18800e42065b Mon Sep 17 00:00:00 2001
From: Aaron Patterson
Date: Wed, 2 May 2012 11:55:14 -0700
Subject: * move exception message to exception constructor * save original
exception * keep original backtrace
---
.../action_dispatch/middleware/session/abstract_store.rb | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
index 45a00b5056..e82132b445 100644
--- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
@@ -7,6 +7,15 @@ require 'active_support/core_ext/object/blank'
module ActionDispatch
module Session
class SessionRestoreError < StandardError #:nodoc:
+ attr_reader :original_exception
+
+ def initialize(const_error)
+ @original_exception = const_error
+
+ super("Session contains objects whose class definition isn't available.\n" +
+ "Remember to require the classes for all objects kept in the session.\n" +
+ "(Original exception: #{const_error.message} [#{const_error.class}])\n")
+ end
end
module DestroyableSession
@@ -58,11 +67,8 @@ module ActionDispatch
begin
# Note that the regexp does not allow $1 to end with a ':'
$1.constantize
- rescue LoadError, NameError => const_error
- raise ActionDispatch::Session::SessionRestoreError,
- "Session contains objects whose class definition isn't available.\n" +
- "Remember to require the classes for all objects kept in the session.\n" +
- "(Original exception: #{const_error.message} [#{const_error.class}])\n"
+ rescue LoadError, NameError => e
+ raise ActionDispatch::Session::SessionRestoreError, e, e.backtrace
end
retry
else
--
cgit v1.2.3
From 9a41edf0d9bdd757963aed9885cd4bfce324d613 Mon Sep 17 00:00:00 2001
From: Nico
Date: Wed, 2 May 2012 22:31:24 +0200
Subject: added proc evaluation for action cache's layout parameter
---
.../lib/action_controller/caching/actions.rb | 6 ++--
actionpack/test/controller/caching_test.rb | 33 +++++++++++++++++++++-
2 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb
index 59ec197347..80901b8bf3 100644
--- a/actionpack/lib/action_controller/caching/actions.rb
+++ b/actionpack/lib/action_controller/caching/actions.rb
@@ -133,6 +133,8 @@ module ActionController #:nodoc:
end
def filter(controller)
+ cache_layout = @cache_layout.respond_to?(:call) ? @cache_layout.call(controller) : @cache_layout
+
path_options = if @cache_path.respond_to?(:call)
controller.instance_exec(controller, &@cache_path)
else
@@ -144,13 +146,13 @@ module ActionController #:nodoc:
body = controller.read_fragment(cache_path.path, @store_options)
unless body
- controller.action_has_layout = false unless @cache_layout
+ controller.action_has_layout = false unless cache_layout
yield
controller.action_has_layout = true
body = controller._save_fragment(cache_path.path, @store_options)
end
- body = controller.render_to_string(:text => body, :layout => true) unless @cache_layout
+ body = controller.render_to_string(:text => body, :layout => true) unless cache_layout
controller.response_body = body
controller.content_type = Mime[cache_path.extension || :html]
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index e8546cb154..9efe328d62 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -236,6 +236,7 @@ class ActionCachingTestController < CachingController
caches_action :with_layout
caches_action :with_format_and_http_param, :cache_path => Proc.new { |c| { :key => 'value' } }
caches_action :layout_false, :layout => false
+ caches_action :with_layout_proc_param, :layout => Proc.new { |c| c.params[:layout] }
caches_action :record_not_found, :four_oh_four, :simple_runtime_error
caches_action :streaming
@@ -282,6 +283,7 @@ class ActionCachingTestController < CachingController
alias_method :edit, :index
alias_method :destroy, :index
alias_method :layout_false, :with_layout
+ alias_method :with_layout_proc_param, :with_layout
def expire
expire_action :controller => 'action_caching_test', :action => 'index'
@@ -403,11 +405,40 @@ class ActionCacheTest < ActionController::TestCase
get :layout_false
assert_response :success
assert_not_equal cached_time, @response.body
-
body = body_to_string(read_fragment('hostname.com/action_caching_test/layout_false'))
assert_equal cached_time, body
end
+ def test_action_cache_with_layout_and_layout_cache_false_via_proc
+ get :with_layout_proc_param, :layout => false
+ assert_response :success
+ cached_time = content_to_cache
+ assert_not_equal cached_time, @response.body
+ assert fragment_exist?('hostname.com/action_caching_test/with_layout_proc_param')
+ reset!
+
+ get :with_layout_proc_param, :layout => false
+ assert_response :success
+ assert_not_equal cached_time, @response.body
+ body = body_to_string(read_fragment('hostname.com/action_caching_test/with_layout_proc_param'))
+ assert_equal cached_time, body
+ end
+
+ def test_action_cache_with_layout_and_layout_cache_true_via_proc
+ get :with_layout_proc_param, :layout => true
+ assert_response :success
+ cached_time = content_to_cache
+ assert_not_equal cached_time, @response.body
+ assert fragment_exist?('hostname.com/action_caching_test/with_layout_proc_param')
+ reset!
+
+ get :with_layout_proc_param, :layout => true
+ assert_response :success
+ assert_not_equal cached_time, @response.body
+ body = body_to_string(read_fragment('hostname.com/action_caching_test/with_layout_proc_param'))
+ assert_equal @response.body, body
+ end
+
def test_action_cache_conditional_options
@request.env['HTTP_ACCEPT'] = 'application/json'
get :index
--
cgit v1.2.3
From 08307383482b5dd4894589de2edf4bb62821d0fd Mon Sep 17 00:00:00 2001
From: Aaron Patterson
Date: Wed, 2 May 2012 14:45:12 -0700
Subject: imported options, switched to object composition
---
.../middleware/session/abstract_store.rb | 69 ++++++++++++++++++----
1 file changed, 56 insertions(+), 13 deletions(-)
diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
index e82132b445..56c71b962a 100644
--- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
@@ -18,19 +18,6 @@ module ActionDispatch
end
end
- module DestroyableSession
- def destroy
- clear
- options = @env[Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY] if @env
- options ||= {}
- @by.send(:destroy_session, @env, options[:id], options) if @by
- options[:id] = nil
- @loaded = false
- end
- end
-
- ::Rack::Session::Abstract::SessionHash.send :include, DestroyableSession
-
module Compatibility
def initialize(app, options = {})
options[:key] ||= '_session_id'
@@ -81,12 +68,68 @@ module ActionDispatch
include Compatibility
include StaleSessionCheck
+ ENV_SESSION_KEY = Rack::Session::Abstract::ENV_SESSION_KEY # :nodoc:
+ ENV_SESSION_OPTIONS_KEY = Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY # :nodoc:
+
private
+ module DestroyableSession
+ def destroy
+ clear
+ options = @env[Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY] if @env
+ options ||= {}
+ @by.send(:destroy_session, @env, options[:id], options) if @by
+ options[:id] = nil
+ @loaded = false
+ end
+ end
+
+ ::Rack::Session::Abstract::SessionHash.send :include, DestroyableSession
+
+ def prepare_session(env)
+ session_was = env[ENV_SESSION_KEY]
+ env[ENV_SESSION_KEY] = Rack::Session::Abstract::SessionHash.new(self, env)
+ env[ENV_SESSION_OPTIONS_KEY] = Request::Session::Options.new(self, env, @default_options)
+ env[ENV_SESSION_KEY].merge! session_was if session_was
+ end
+
def set_cookie(env, session_id, cookie)
request = ActionDispatch::Request.new(env)
request.cookie_jar[key] = cookie
end
end
end
+
+ class Request
+ # SessionHash is responsible to lazily load the session from store.
+ class Session
+ class Options #:nodoc:
+ def initialize(by, env, default_options)
+ @by = by
+ @env = env
+ @session_id_loaded = false
+ @delegate = default_options
+ end
+
+ def [](key)
+ load_session_id! if key == :id && session_id_not_loaded?
+ @delegate[key]
+ end
+
+ def []=(k,v); @delegate[k] = v; end
+ def to_hash; @delegate.dup; end
+ def values_at(*args) @delegate.values_at(*args); end
+
+ private
+ def session_id_not_loaded?
+ !(@session_id_loaded || @delegate.key?(:id))
+ end
+
+ def load_session_id!
+ @delegate[:id] = @by.send(:extract_session_id, @env)
+ @session_id_loaded = true
+ end
+ end
+ end
+ end
end
--
cgit v1.2.3
From 6c6288318a5f0bd8fae0ba599792d35f42ce44b1 Mon Sep 17 00:00:00 2001
From: Aaron Patterson
Date: Wed, 2 May 2012 14:56:00 -0700
Subject: use hash fetches to populate the :id value
---
.../middleware/session/abstract_store.rb | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
index 56c71b962a..6dd554ee49 100644
--- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
@@ -112,23 +112,18 @@ module ActionDispatch
end
def [](key)
- load_session_id! if key == :id && session_id_not_loaded?
- @delegate[key]
+ if key == :id
+ @delegate.fetch(key) {
+ @delegate[:id] = @by.send(:extract_session_id, @env)
+ }
+ else
+ @delegate[key]
+ end
end
def []=(k,v); @delegate[k] = v; end
def to_hash; @delegate.dup; end
def values_at(*args) @delegate.values_at(*args); end
-
- private
- def session_id_not_loaded?
- !(@session_id_loaded || @delegate.key?(:id))
- end
-
- def load_session_id!
- @delegate[:id] = @by.send(:extract_session_id, @env)
- @session_id_loaded = true
- end
end
end
end
--
cgit v1.2.3
From 8d33be7d367af03de6706a05d1d8dfdeed91f446 Mon Sep 17 00:00:00 2001
From: Aaron Patterson
Date: Wed, 2 May 2012 14:57:27 -0700
Subject: remove unused ivar
---
.../lib/action_dispatch/middleware/session/abstract_store.rb | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
index 6dd554ee49..b4a7f1ab89 100644
--- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
@@ -105,10 +105,9 @@ module ActionDispatch
class Session
class Options #:nodoc:
def initialize(by, env, default_options)
- @by = by
- @env = env
- @session_id_loaded = false
- @delegate = default_options
+ @by = by
+ @env = env
+ @delegate = default_options
end
def [](key)
--
cgit v1.2.3
From c2807fb031cb96f92a3ef62cabd1fc7a7cd8c13d Mon Sep 17 00:00:00 2001
From: Aaron Patterson
Date: Wed, 2 May 2012 14:58:56 -0700
Subject: oops, forgot some semicolons
---
actionpack/lib/action_dispatch/middleware/session/abstract_store.rb | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
index b4a7f1ab89..b1e77eff3c 100644
--- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
@@ -120,9 +120,9 @@ module ActionDispatch
end
end
- def []=(k,v); @delegate[k] = v; end
- def to_hash; @delegate.dup; end
- def values_at(*args) @delegate.values_at(*args); end
+ def []=(k,v); @delegate[k] = v; end
+ def to_hash; @delegate.dup; end
+ def values_at(*args); @delegate.values_at(*args); end
end
end
end
--
cgit v1.2.3
From 385afd47dab645f97b79c25419ec5e1f5b52babe Mon Sep 17 00:00:00 2001
From: Aaron Patterson
Date: Wed, 2 May 2012 15:06:21 -0700
Subject: session hash imported
---
.../middleware/session/abstract_store.rb | 126 ++++++++++++++++++---
1 file changed, 111 insertions(+), 15 deletions(-)
diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
index b1e77eff3c..e9f5a9aebe 100644
--- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
@@ -73,26 +73,17 @@ module ActionDispatch
private
- module DestroyableSession
- def destroy
- clear
- options = @env[Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY] if @env
- options ||= {}
- @by.send(:destroy_session, @env, options[:id], options) if @by
- options[:id] = nil
- @loaded = false
- end
- end
-
- ::Rack::Session::Abstract::SessionHash.send :include, DestroyableSession
-
def prepare_session(env)
session_was = env[ENV_SESSION_KEY]
- env[ENV_SESSION_KEY] = Rack::Session::Abstract::SessionHash.new(self, env)
+ env[ENV_SESSION_KEY] = Request::Session.new(self, env)
env[ENV_SESSION_OPTIONS_KEY] = Request::Session::Options.new(self, env, @default_options)
env[ENV_SESSION_KEY].merge! session_was if session_was
end
+ def loaded_session?(session)
+ !session.is_a?(Request::Session) || session.loaded?
+ end
+
def set_cookie(env, session_id, cookie)
request = ActionDispatch::Request.new(env)
request.cookie_jar[key] = cookie
@@ -102,7 +93,10 @@ module ActionDispatch
class Request
# SessionHash is responsible to lazily load the session from store.
- class Session
+ class Session < Hash
+ ENV_SESSION_KEY = Rack::Session::Abstract::ENV_SESSION_KEY # :nodoc:
+ ENV_SESSION_OPTIONS_KEY = Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY # :nodoc:
+
class Options #:nodoc:
def initialize(by, env, default_options)
@by = by
@@ -124,6 +118,108 @@ module ActionDispatch
def to_hash; @delegate.dup; end
def values_at(*args); @delegate.values_at(*args); end
end
+
+ def destroy
+ clear
+ options = @env[Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY] if @env
+ options ||= {}
+ @by.send(:destroy_session, @env, options[:id], options) if @by
+ options[:id] = nil
+ @loaded = false
+ end
+
+ def initialize(by, env)
+ super()
+ @by = by
+ @env = env
+ @loaded = false
+ end
+
+ def [](key)
+ load_for_read!
+ super(key.to_s)
+ end
+
+ def has_key?(key)
+ load_for_read!
+ super(key.to_s)
+ end
+ alias :key? :has_key?
+ alias :include? :has_key?
+
+ def []=(key, value)
+ load_for_write!
+ super(key.to_s, value)
+ end
+
+ def clear
+ load_for_write!
+ super
+ end
+
+ def to_hash
+ load_for_read!
+ h = {}.replace(self)
+ h.delete_if { |k,v| v.nil? }
+ h
+ end
+
+ def update(hash)
+ load_for_write!
+ super(stringify_keys(hash))
+ end
+
+ def delete(key)
+ load_for_write!
+ super(key.to_s)
+ end
+
+ def inspect
+ if loaded?
+ super
+ else
+ "#<#{self.class}:0x#{self.object_id.to_s(16)} not yet loaded>"
+ end
+ end
+
+ def exists?
+ return @exists if instance_variable_defined?(:@exists)
+ @exists = @by.send(:session_exists?, @env)
+ end
+
+ def loaded?
+ @loaded
+ end
+
+ def empty?
+ load_for_read!
+ super
+ end
+
+ private
+
+ def load_for_read!
+ load! if !loaded? && exists?
+ end
+
+ def load_for_write!
+ load! unless loaded?
+ end
+
+ def load!
+ id, session = @by.send(:load_session, @env)
+ @env[ENV_SESSION_OPTIONS_KEY][:id] = id
+ replace(stringify_keys(session))
+ @loaded = true
+ end
+
+ def stringify_keys(other)
+ hash = {}
+ other.each do |key, value|
+ hash[key.to_s] = value
+ end
+ hash
+ end
end
end
end
--
cgit v1.2.3
From 1ef527f9f96dd6cb9d6f0a93886a28838885513e Mon Sep 17 00:00:00 2001
From: Aaron Patterson
Date: Wed, 2 May 2012 15:14:47 -0700
Subject: converted session hash to delegation
---
.../middleware/session/abstract_store.rb | 40 ++++++++++------------
1 file changed, 19 insertions(+), 21 deletions(-)
diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
index e9f5a9aebe..48f1006e5e 100644
--- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
@@ -93,7 +93,7 @@ module ActionDispatch
class Request
# SessionHash is responsible to lazily load the session from store.
- class Session < Hash
+ class Session # :nodoc:
ENV_SESSION_KEY = Rack::Session::Abstract::ENV_SESSION_KEY # :nodoc:
ENV_SESSION_OPTIONS_KEY = Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY # :nodoc:
@@ -119,66 +119,64 @@ module ActionDispatch
def values_at(*args); @delegate.values_at(*args); end
end
+ def initialize(by, env)
+ @by = by
+ @env = env
+ @delegate = {}
+ @loaded = false
+ end
+
def destroy
clear
- options = @env[Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY] if @env
+ options = @env[ENV_SESSION_OPTIONS_KEY] if @env
options ||= {}
@by.send(:destroy_session, @env, options[:id], options) if @by
options[:id] = nil
@loaded = false
end
- def initialize(by, env)
- super()
- @by = by
- @env = env
- @loaded = false
- end
-
def [](key)
load_for_read!
- super(key.to_s)
+ @delegate[key.to_s]
end
def has_key?(key)
load_for_read!
- super(key.to_s)
+ @delegate.key?(key.to_s)
end
alias :key? :has_key?
alias :include? :has_key?
def []=(key, value)
load_for_write!
- super(key.to_s, value)
+ @delegate[key.to_s] = value
end
def clear
load_for_write!
- super
+ @delegate.clear
end
def to_hash
load_for_read!
- h = {}.replace(self)
- h.delete_if { |k,v| v.nil? }
- h
+ @delegate.dup.delete_if { |_,v| v.nil? }
end
def update(hash)
load_for_write!
- super(stringify_keys(hash))
+ @delegate.update stringify_keys(hash)
end
def delete(key)
load_for_write!
- super(key.to_s)
+ @delegate.delete key.to_s
end
def inspect
if loaded?
super
else
- "#<#{self.class}:0x#{self.object_id.to_s(16)} not yet loaded>"
+ "#<#{self.class}:0x#{(object_id << 1).to_s(16)} not yet loaded>"
end
end
@@ -193,7 +191,7 @@ module ActionDispatch
def empty?
load_for_read!
- super
+ @delegate.empty?
end
private
@@ -209,7 +207,7 @@ module ActionDispatch
def load!
id, session = @by.send(:load_session, @env)
@env[ENV_SESSION_OPTIONS_KEY][:id] = id
- replace(stringify_keys(session))
+ @delegate.replace(stringify_keys(session))
@loaded = true
end
--
cgit v1.2.3
From dc2352c58f0f05d9df171538483f31d42e9f0668 Mon Sep 17 00:00:00 2001
From: Aaron Patterson
Date: Wed, 2 May 2012 15:33:20 -0700
Subject: initialize instance variables
---
.../lib/action_dispatch/middleware/session/abstract_store.rb | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
index 48f1006e5e..3710667238 100644
--- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
@@ -124,6 +124,7 @@ module ActionDispatch
@env = env
@delegate = {}
@loaded = false
+ @exists = nil # we haven't checked yet
end
def destroy
@@ -181,7 +182,7 @@ module ActionDispatch
end
def exists?
- return @exists if instance_variable_defined?(:@exists)
+ return @exists unless @exists.nil?
@exists = @by.send(:session_exists?, @env)
end
@@ -205,18 +206,16 @@ module ActionDispatch
end
def load!
- id, session = @by.send(:load_session, @env)
+ id, session = @by.load_session @env
@env[ENV_SESSION_OPTIONS_KEY][:id] = id
@delegate.replace(stringify_keys(session))
@loaded = true
end
def stringify_keys(other)
- hash = {}
- other.each do |key, value|
+ other.each_with_object({}) { |(key, value), hash|
hash[key.to_s] = value
- end
- hash
+ }
end
end
end
--
cgit v1.2.3
From 56030506563352944fed12a6bb4793bb2462094b Mon Sep 17 00:00:00 2001
From: Andrew White
Date: Wed, 2 May 2012 23:42:43 +0100
Subject: Reset the request parameters after a constraints check
A callable object passed as a constraint for a route may access the request
parameters as part of its check. This causes the combined parameters hash
to be cached in the environment hash. If the constraint fails then any subsequent
access of the request parameters will be against that stale hash.
To fix this we delete the cache after every call to `matches?`. This may have a
negative performance impact if the contraint wraps a large number of routes as the
parameters hash is built by merging GET, POST and path parameters.
Fixes #2510.
---
actionpack/lib/action_dispatch/http/parameters.rb | 4 ++++
actionpack/lib/action_dispatch/routing/mapper.rb | 2 ++
actionpack/test/dispatch/routing_test.rb | 19 +++++++++++++++++++
3 files changed, 25 insertions(+)
diff --git a/actionpack/lib/action_dispatch/http/parameters.rb b/actionpack/lib/action_dispatch/http/parameters.rb
index d9b63faf5e..bcfd0b0d00 100644
--- a/actionpack/lib/action_dispatch/http/parameters.rb
+++ b/actionpack/lib/action_dispatch/http/parameters.rb
@@ -35,6 +35,10 @@ module ActionDispatch
@env["action_dispatch.request.path_parameters"] ||= {}
end
+ def reset_parameters #:nodoc:
+ @env.delete("action_dispatch.request.parameters")
+ end
+
private
# TODO: Validate that the characters are UTF-8. If they aren't,
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 1a1a054985..4ea3937057 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -35,6 +35,8 @@ module ActionDispatch
}
return true
+ ensure
+ req.reset_parameters
end
def call(env)
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 4b8d308043..a96d2edcf9 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -2512,3 +2512,22 @@ private
%(You are being redirected.)
end
end
+
+class TestConstraintsAccessingParameters < ActionDispatch::IntegrationTest
+ Routes = ActionDispatch::Routing::RouteSet.new.tap do |app|
+ app.draw do
+ ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] }
+
+ get "/:foo" => ok, :constraints => lambda { |r| r.params[:foo] == 'foo' }
+ get "/:bar" => ok
+ end
+ end
+
+ def app; Routes end
+
+ test "parameters are reset between constraint checks" do
+ get "/bar"
+ assert_equal nil, @request.params[:foo]
+ assert_equal "bar", @request.params[:bar]
+ end
+end
--
cgit v1.2.3
From e737f142bd102b4c464481ab685cad2a00ee022e Mon Sep 17 00:00:00 2001
From: schneems
Date: Mon, 30 Apr 2012 16:29:49 -0500
Subject: Add backtrace to development routing error page
If a user gets a routing error due to a view helper such as using user_path without an :id they must go to their logs to see the backtrace. By adding in the trace template, a user can see which line the error occurred on without leaving the browser.
When a routing error occurs outside of the view the application trace will be blank and will not confuse developers.
---
.../action_dispatch/middleware/templates/rescues/routing_error.erb | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb
index f06c07daa5..177d383e94 100644
--- a/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb
+++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb
@@ -12,4 +12,6 @@
<% end %>
Try running rake routes for more information on available routes.
-
\ No newline at end of file
+
+
+<%= render :template => "rescues/_trace" %>
--
cgit v1.2.3
From 07e5301e697d6a02ed3c079aba07c261d53c1846 Mon Sep 17 00:00:00 2001
From: Marcelo Silveira
Date: Thu, 26 Apr 2012 19:27:55 -0300
Subject: Made `first` finder consistent among database engines by adding a
default order clause (fixes #5103)
---
.../lib/active_record/relation/finder_methods.rb | 20 ++++++++++++++++++--
activerecord/test/cases/finder_test.rb | 6 ++++++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 1ceb1949a4..9fd8b49ffb 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -60,6 +60,9 @@ module ActiveRecord
where(*args).first!
end
+ # Find the first record (or first N records if a parameter is supplied).
+ # If no order is defined it will order by primary key.
+ #
# Examples:
#
# Person.first # returns the first object fetched by SELECT * FROM people
@@ -67,7 +70,15 @@ module ActiveRecord
# Person.where(["user_name = :u", { :u => user_name }]).first
# Person.order("created_on DESC").offset(5).first
def first(limit = nil)
- limit ? limit(limit).to_a : find_first
+ if limit
+ if order_values.empty? && primary_key
+ order("#{quoted_table_name}.#{quoted_primary_key} ASC").limit(limit).to_a
+ else
+ limit(limit).to_a
+ end
+ else
+ find_first
+ end
end
# Same as +first+ but raises ActiveRecord::RecordNotFound if no record
@@ -319,7 +330,12 @@ module ActiveRecord
if loaded?
@records.first
else
- @first ||= limit(1).to_a[0]
+ @first ||=
+ if order_values.empty? && primary_key
+ order("#{quoted_table_name}.#{quoted_primary_key} ASC").limit(1).to_a[0]
+ else
+ limit(1).to_a[0]
+ end
end
end
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index 29469c42ed..fdc7fad40a 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -163,6 +163,12 @@ class FinderTest < ActiveRecord::TestCase
end
end
+ def test_first_have_primary_key_order_by_default
+ expected = topics(:first)
+ expected.touch # PostgreSQL changes the default order if no order clause is used
+ assert_equal expected, Topic.first
+ end
+
def test_model_class_responds_to_first_bang
assert Topic.first!
Topic.delete_all
--
cgit v1.2.3
From 489166e114ba3af54b1f2081027cd44078d32bbc Mon Sep 17 00:00:00 2001
From: Marcelo Silveira
Date: Thu, 26 Apr 2012 20:10:10 -0300
Subject: Document `last`, check for primary key on default order and use
quoted table and column names
---
activerecord/lib/active_record/relation/finder_methods.rb | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 9fd8b49ffb..4a41f1ea8b 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -87,6 +87,9 @@ module ActiveRecord
first or raise RecordNotFound
end
+ # Find the last record (or last N records if a parameter is supplied).
+ # If no order is defined it will order by primary key.
+ #
# Examples:
#
# Person.last # returns the last object fetched by SELECT * FROM people
@@ -94,8 +97,8 @@ module ActiveRecord
# Person.order("created_on DESC").offset(5).last
def last(limit = nil)
if limit
- if order_values.empty?
- order("#{primary_key} DESC").limit(limit).reverse
+ if order_values.empty? && primary_key
+ order("#{quoted_table_name}.#{quoted_primary_key} DESC").limit(limit).reverse
else
to_a.last(limit)
end
--
cgit v1.2.3
From 1379375f93c53d4c49fa8592b6117c3ade263f2e Mon Sep 17 00:00:00 2001
From: Marcelo Silveira
Date: Thu, 26 Apr 2012 21:03:25 -0300
Subject: Introducing `take` as a replacement to the old behavior of `first`
---
activerecord/lib/active_record/querying.rb | 2 +-
.../lib/active_record/relation/finder_methods.rb | 27 ++++++++++++++++++++++
activerecord/test/cases/finder_test.rb | 26 +++++++++++++++++++--
3 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/activerecord/lib/active_record/querying.rb b/activerecord/lib/active_record/querying.rb
index 29b8b2fb73..4d8283bcff 100644
--- a/activerecord/lib/active_record/querying.rb
+++ b/activerecord/lib/active_record/querying.rb
@@ -3,7 +3,7 @@ require 'active_support/deprecation'
module ActiveRecord
module Querying
- delegate :find, :first, :first!, :last, :last!, :all, :exists?, :any?, :many?, :to => :scoped
+ delegate :find, :take, :take!, :first, :first!, :last, :last!, :all, :exists?, :any?, :many?, :to => :scoped
delegate :first_or_create, :first_or_create!, :first_or_initialize, :to => :scoped
delegate :find_by, :find_by!, :to => :scoped
delegate :destroy, :destroy_all, :delete, :delete_all, :update, :update_all, :to => :scoped
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 4a41f1ea8b..7af69d3483 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -60,6 +60,25 @@ module ActiveRecord
where(*args).first!
end
+ # Gives a record (or N records if a parameter is supplied) without any implied
+ # order. The order will depend on the database implementation.
+ # If an order is supplied it will be respected.
+ #
+ # Examples:
+ #
+ # Person.take # returns an object fetched by SELECT * FROM people
+ # Person.take(5) # returns 5 objects fetched by SELECT * FROM people LIMIT 5
+ # Person.where(["name LIKE '%?'", name]).take
+ def take(limit = nil)
+ limit ? limit(limit).to_a : find_take
+ end
+
+ # Same as +take+ but raises ActiveRecord::RecordNotFound if no record
+ # is found. Note that take! accepts no arguments.
+ def take!
+ take or raise RecordNotFound
+ end
+
# Find the first record (or first N records if a parameter is supplied).
# If no order is defined it will order by primary key.
#
@@ -329,6 +348,14 @@ module ActiveRecord
end
end
+ def find_take
+ if loaded?
+ @records.take(1)[0]
+ else
+ @take ||= limit(1).to_a[0]
+ end
+ end
+
def find_first
if loaded?
@records.first
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index fdc7fad40a..54801bd101 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -143,6 +143,26 @@ class FinderTest < ActiveRecord::TestCase
assert_equal [Account], accounts.collect(&:class).uniq
end
+ def test_take
+ assert_equal topics(:first), Topic.take
+ end
+
+ def test_take_failing
+ assert_nil Topic.where("title = 'This title does not exist'").take
+ end
+
+ def test_take_bang_present
+ assert_nothing_raised do
+ assert_equal topics(:second), Topic.where("title = 'The Second Topic of the day'").take!
+ end
+ end
+
+ def test_take_bang_missing
+ assert_raises ActiveRecord::RecordNotFound do
+ Topic.where("title = 'This title does not exist'").take!
+ end
+ end
+
def test_first
assert_equal topics(:second).title, Topic.where("title = 'The Second Topic of the day'").first.title
end
@@ -197,7 +217,8 @@ class FinderTest < ActiveRecord::TestCase
end
end
- def test_first_and_last_with_integer_should_use_sql_limit
+ def test_take_and_first_and_last_with_integer_should_use_sql_limit
+ assert_sql(/LIMIT 3|ROWNUM <= 3/) { Topic.take(3).entries }
assert_sql(/LIMIT 2|ROWNUM <= 2/) { Topic.first(2).entries }
assert_sql(/LIMIT 5|ROWNUM <= 5/) { Topic.last(5).entries }
end
@@ -218,7 +239,8 @@ class FinderTest < ActiveRecord::TestCase
assert_no_match(/LIMIT/, query.first)
end
- def test_first_and_last_with_integer_should_return_an_array
+ def test_take_and_first_and_last_with_integer_should_return_an_array
+ assert_kind_of Array, Topic.take(5)
assert_kind_of Array, Topic.first(5)
assert_kind_of Array, Topic.last(5)
end
--
cgit v1.2.3
From 66b9e4c857b5987a52f0442ae382ee18dc3dd30a Mon Sep 17 00:00:00 2001
From: Marcelo Silveira
Date: Thu, 26 Apr 2012 21:06:54 -0300
Subject: Adding note about `first` and `take` to the changelog
---
activerecord/CHANGELOG.md | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 6f0b5bfce6..a661a44f1f 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,5 +1,11 @@
## Rails 4.0.0 (unreleased) ##
+* Added default order to `first` to assure consistent results among
+ diferent database engines. Introduced `take` as a replacement to
+ the old behavior of `first`.
+
+ *Marcelo Silveira*
+
* Added an :index option to automatically create indexes for references
and belongs_to statements in migrations.
--
cgit v1.2.3
From 2bf65caf565c5923684953557594fc287c80c6ca Mon Sep 17 00:00:00 2001
From: Marcelo Silveira
Date: Fri, 27 Apr 2012 18:22:11 -0300
Subject: Use Array#first instead of Array#[0]
---
activerecord/lib/active_record/relation/finder_methods.rb | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 7af69d3483..d13bed95ce 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -350,9 +350,9 @@ module ActiveRecord
def find_take
if loaded?
- @records.take(1)[0]
+ @records.take(1).first
else
- @take ||= limit(1).to_a[0]
+ @take ||= limit(1).to_a.first
end
end
@@ -362,9 +362,9 @@ module ActiveRecord
else
@first ||=
if order_values.empty? && primary_key
- order("#{quoted_table_name}.#{quoted_primary_key} ASC").limit(1).to_a[0]
+ order("#{quoted_table_name}.#{quoted_primary_key} ASC").limit(1).to_a.first
else
- limit(1).to_a[0]
+ limit(1).to_a.first
end
end
end
@@ -377,7 +377,7 @@ module ActiveRecord
if offset_value || limit_value
to_a.last
else
- reverse_order.limit(1).to_a[0]
+ reverse_order.limit(1).to_a.first
end
end
end
--
cgit v1.2.3
From 878db1f4ef842a7c6c406aefb4dd2e629b5f47af Mon Sep 17 00:00:00 2001
From: Marcelo Silveira
Date: Fri, 27 Apr 2012 20:19:11 -0300
Subject: Use arel nodes instead of raw sql
---
.../lib/active_record/connection_adapters/postgresql_adapter.rb | 5 ++++-
activerecord/lib/active_record/relation/finder_methods.rb | 6 +++---
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 273c165084..68cf495025 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -1233,7 +1233,10 @@ module ActiveRecord
# Construct a clean list of column names from the ORDER BY clause, removing
# any ASC/DESC modifiers
- order_columns = orders.collect { |s| s.gsub(/\s+(ASC|DESC)\s*(NULLS\s+(FIRST|LAST)\s*)?/i, '') }
+ order_columns = orders.collect do |s|
+ s = s.to_sql unless s.is_a?(String)
+ s.gsub(/\s+(ASC|DESC)\s*(NULLS\s+(FIRST|LAST)\s*)?/i, '')
+ end
order_columns.delete_if { |c| c.blank? }
order_columns = order_columns.zip((0...order_columns.size).to_a).map { |s,i| "#{s} AS alias_#{i}" }
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index d13bed95ce..3c9c9c4e84 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -91,7 +91,7 @@ module ActiveRecord
def first(limit = nil)
if limit
if order_values.empty? && primary_key
- order("#{quoted_table_name}.#{quoted_primary_key} ASC").limit(limit).to_a
+ order(arel_table[primary_key].asc).limit(limit).to_a
else
limit(limit).to_a
end
@@ -117,7 +117,7 @@ module ActiveRecord
def last(limit = nil)
if limit
if order_values.empty? && primary_key
- order("#{quoted_table_name}.#{quoted_primary_key} DESC").limit(limit).reverse
+ order(arel_table[primary_key].desc).limit(limit).reverse
else
to_a.last(limit)
end
@@ -362,7 +362,7 @@ module ActiveRecord
else
@first ||=
if order_values.empty? && primary_key
- order("#{quoted_table_name}.#{quoted_primary_key} ASC").limit(1).to_a.first
+ order(arel_table[primary_key].asc).limit(1).to_a.first
else
limit(1).to_a.first
end
--
cgit v1.2.3
From 5b360dbb9b968ea1389a278a8ae10328fb273ea2 Mon Sep 17 00:00:00 2001
From: Aaron Patterson
Date: Wed, 2 May 2012 17:29:33 -0700
Subject: testing session store behavior
---
.../middleware/session/abstract_store.rb | 26 +++++++---
actionpack/test/dispatch/request/session_test.rb | 48 +++++++++++++++++++
.../test/dispatch/session/abstract_store_test.rb | 56 ++++++++++++++++++++++
3 files changed, 123 insertions(+), 7 deletions(-)
create mode 100644 actionpack/test/dispatch/request/session_test.rb
create mode 100644 actionpack/test/dispatch/session/abstract_store_test.rb
diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
index 3710667238..550c0d8d71 100644
--- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
@@ -68,16 +68,10 @@ module ActionDispatch
include Compatibility
include StaleSessionCheck
- ENV_SESSION_KEY = Rack::Session::Abstract::ENV_SESSION_KEY # :nodoc:
- ENV_SESSION_OPTIONS_KEY = Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY # :nodoc:
-
private
def prepare_session(env)
- session_was = env[ENV_SESSION_KEY]
- env[ENV_SESSION_KEY] = Request::Session.new(self, env)
- env[ENV_SESSION_OPTIONS_KEY] = Request::Session::Options.new(self, env, @default_options)
- env[ENV_SESSION_KEY].merge! session_was if session_was
+ Request::Session.create(self, env, @default_options)
end
def loaded_session?(session)
@@ -97,6 +91,19 @@ module ActionDispatch
ENV_SESSION_KEY = Rack::Session::Abstract::ENV_SESSION_KEY # :nodoc:
ENV_SESSION_OPTIONS_KEY = Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY # :nodoc:
+ def self.create(store, env, default_options)
+ session_was = env[ENV_SESSION_KEY]
+ session = Request::Session.new(store, env)
+ env[ENV_SESSION_KEY] = session
+ env[ENV_SESSION_OPTIONS_KEY] = Request::Session::Options.new(store, env, default_options)
+ env[ENV_SESSION_KEY].merge! session_was if session_was
+ session
+ end
+
+ def self.find(env)
+ env[ENV_SESSION_KEY]
+ end
+
class Options #:nodoc:
def initialize(by, env, default_options)
@by = by
@@ -195,6 +202,11 @@ module ActionDispatch
@delegate.empty?
end
+ def merge!(other)
+ load_for_write!
+ @delegate.merge!(other)
+ end
+
private
def load_for_read!
diff --git a/actionpack/test/dispatch/request/session_test.rb b/actionpack/test/dispatch/request/session_test.rb
new file mode 100644
index 0000000000..4d24456ba6
--- /dev/null
+++ b/actionpack/test/dispatch/request/session_test.rb
@@ -0,0 +1,48 @@
+require 'abstract_unit'
+require 'action_dispatch/middleware/session/abstract_store'
+
+module ActionDispatch
+ class Request
+ class SessionTest < ActiveSupport::TestCase
+ def test_create_adds_itself_to_env
+ env = {}
+ s = Session.create(store, env, {})
+ assert_equal s, env[Rack::Session::Abstract::ENV_SESSION_KEY]
+ end
+
+ def test_to_hash
+ env = {}
+ s = Session.create(store, env, {})
+ s['foo'] = 'bar'
+ assert_equal 'bar', s['foo']
+ assert_equal({'foo' => 'bar'}, s.to_hash)
+ end
+
+ def test_create_merges_old
+ env = {}
+ s = Session.create(store, env, {})
+ s['foo'] = 'bar'
+
+ s1 = Session.create(store, env, {})
+ refute_equal s, s1
+ assert_equal 'bar', s1['foo']
+ end
+
+ def test_find
+ env = {}
+ assert_nil Session.find(env)
+
+ s = Session.create(store, env, {})
+ assert_equal s, Session.find(env)
+ end
+
+ private
+ def store
+ Class.new {
+ def load_session(env); [1, {}]; end
+ def session_exists?(env); true; end
+ }.new
+ end
+ end
+ end
+end
diff --git a/actionpack/test/dispatch/session/abstract_store_test.rb b/actionpack/test/dispatch/session/abstract_store_test.rb
new file mode 100644
index 0000000000..8daf3d3f5e
--- /dev/null
+++ b/actionpack/test/dispatch/session/abstract_store_test.rb
@@ -0,0 +1,56 @@
+require 'abstract_unit'
+require 'action_dispatch/middleware/session/abstract_store'
+
+module ActionDispatch
+ module Session
+ class AbstractStoreTest < ActiveSupport::TestCase
+ class MemoryStore < AbstractStore
+ def initialize(app)
+ @sessions = {}
+ super
+ end
+
+ def get_session(env, sid)
+ sid ||= 1
+ session = @sessions[sid] ||= {}
+ [sid, session]
+ end
+
+ def set_session(env, sid, session, options)
+ @sessions[sid] = session
+ end
+ end
+
+ def test_session_is_set
+ env = {}
+ as = MemoryStore.new app
+ as.call(env)
+
+ assert @env
+ assert Request::Session.find @env
+ end
+
+ def test_new_session_object_is_merged_with_old
+ env = {}
+ as = MemoryStore.new app
+ as.call(env)
+
+ assert @env
+ session = Request::Session.find @env
+ session['foo'] = 'bar'
+
+ as.call(@env)
+ session1 = Request::Session.find @env
+
+ refute_equal session, session1
+ assert_equal session.to_hash, session1.to_hash
+ end
+
+ private
+ def app(&block)
+ @env = nil
+ lambda { |env| @env = env }
+ end
+ end
+ end
+end
--
cgit v1.2.3
From 9aa5bb4bc4946a7fdcb8d017b92a88b27ddaf808 Mon Sep 17 00:00:00 2001
From: Aaron Patterson
Date: Wed, 2 May 2012 17:54:08 -0700
Subject: extract options finding to a method
---
.../lib/action_dispatch/middleware/session/abstract_store.rb | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
index 550c0d8d71..134ca2dc5f 100644
--- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
@@ -134,11 +134,14 @@ module ActionDispatch
@exists = nil # we haven't checked yet
end
+ def options
+ @env[ENV_SESSION_OPTIONS_KEY]
+ end
+
def destroy
clear
- options = @env[ENV_SESSION_OPTIONS_KEY] if @env
- options ||= {}
- @by.send(:destroy_session, @env, options[:id], options) if @by
+ options = self.options || {}
+ @by.send(:destroy_session, @env, options[:id], options)
options[:id] = nil
@loaded = false
end
@@ -219,7 +222,7 @@ module ActionDispatch
def load!
id, session = @by.load_session @env
- @env[ENV_SESSION_OPTIONS_KEY][:id] = id
+ options[:id] = id
@delegate.replace(stringify_keys(session))
@loaded = true
end
--
cgit v1.2.3
From 36720af42995c8bac06ea7187e2c5768f89c2783 Mon Sep 17 00:00:00 2001
From: Santiago Pastorino
Date: Wed, 2 May 2012 18:12:43 -0700
Subject: Add CHANGELOG entry
---
actionpack/CHANGELOG.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 99602f14d9..6bad313aef 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,5 +1,7 @@
## Rails 4.0.0 (unreleased) ##
+* Add backtrace to development routing error page. *Richard Schneeman*
+
* Replace `include_seconds` boolean argument with `:include_seconds => true` option
in `distance_of_time_in_words` and `time_ago_in_words` signature. *Dmitriy Kiriyenko*
--
cgit v1.2.3
From 5d26c8f00a11e40660be7516a13512ed522863ed Mon Sep 17 00:00:00 2001
From: Carlos Antonio da Silva
Date: Wed, 2 May 2012 23:09:40 -0300
Subject: Fix issue with private kernel methods and collection associations.
Closes #2508
Change CollectionProxy#method_missing to use scoped.public_send, to
avoid a problem described in issue #2508 when trying to use class
methods with names like "open", that clash with private kernel methods.
Also changed the dynamic matcher instantiator to send straight to
scoped, to avoid another roundtrip to method_missing.
---
activerecord/lib/active_record/associations/collection_proxy.rb | 4 ++--
activerecord/test/cases/associations/has_many_associations_test.rb | 5 +++++
activerecord/test/models/company.rb | 5 +++++
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index ad029d1101..50d16b16a9 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -81,7 +81,7 @@ module ActiveRecord
def method_missing(method, *args, &block)
match = DynamicFinderMatch.match(method)
if match && match.instantiator?
- send(:find_or_instantiator_by_attributes, match, match.attribute_names, *args) do |r|
+ scoped.send(:find_or_instantiator_by_attributes, match, match.attribute_names, *args) do |r|
proxy_association.send :set_owner_attributes, r
proxy_association.send :add_to_target, r
yield(r) if block_given?
@@ -101,7 +101,7 @@ module ActiveRecord
end
else
- scoped.readonly(nil).send(method, *args, &block)
+ scoped.readonly(nil).public_send(method, *args, &block)
end
end
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index a98e5b115c..f74fe42dc2 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -1703,4 +1703,9 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
ensure
ActiveRecord::Base.dependent_restrict_raises = option_before
end
+
+ def test_collection_association_with_private_kernel_method
+ firm = companies(:first_firm)
+ assert_equal [accounts(:signals37)], firm.accounts.open
+ end
end
diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb
index fbdfaa2c29..7b993d5a2c 100644
--- a/activerecord/test/models/company.rb
+++ b/activerecord/test/models/company.rb
@@ -198,6 +198,11 @@ class Account < ActiveRecord::Base
@destroyed_account_ids ||= Hash.new { |h,k| h[k] = [] }
end
+ # Test private kernel method through collection proxy using has_many.
+ def self.open
+ where('firm_name = ?', '37signals')
+ end
+
before_destroy do |account|
if account.firm
Account.destroyed_account_ids[account.firm.id] << account.id
--
cgit v1.2.3
From 7273adabed9a3a7aa04014e50ec0ad077ee364aa Mon Sep 17 00:00:00 2001
From: Teng Siong Ong
Date: Thu, 3 May 2012 03:28:32 -0500
Subject: cache_store has an extra option of :null_store.
---
guides/source/configuring.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/guides/source/configuring.textile b/guides/source/configuring.textile
index 68426221bf..66e453c3ff 100644
--- a/guides/source/configuring.textile
+++ b/guides/source/configuring.textile
@@ -70,7 +70,7 @@ NOTE. The +config.asset_path+ configuration is ignored if the asset pipeline is
* +config.action_view.cache_template_loading+ controls whether or not templates should be reloaded on each request. Defaults to whatever is set for +config.cache_classes+.
-* +config.cache_store+ configures which cache store to use for Rails caching. Options include one of the symbols +:memory_store+, +:file_store+, +:mem_cache_store+, or an object that implements the cache API. Defaults to +:file_store+ if the directory +tmp/cache+ exists, and to +:memory_store+ otherwise.
+* +config.cache_store+ configures which cache store to use for Rails caching. Options include one of the symbols +:memory_store+, +:file_store+, +:mem_cache_store+, +:null_store+, or an object that implements the cache API. Defaults to +:file_store+ if the directory +tmp/cache+ exists, and to +:memory_store+ otherwise.
* +config.colorize_logging+ specifies whether or not to use ANSI color codes when logging information. Defaults to true.
--
cgit v1.2.3
From 3d02195174a41b96f3f55219256677b8da06d0cb Mon Sep 17 00:00:00 2001
From: Marcelo Silveira
Date: Thu, 3 May 2012 09:10:33 -0300
Subject: No need to work around 1.8 warnings anymore.
---
actionmailer/test/abstract_unit.rb | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)
diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb
index 3a519253f9..487102b564 100644
--- a/actionmailer/test/abstract_unit.rb
+++ b/actionmailer/test/abstract_unit.rb
@@ -1,16 +1,4 @@
-# Pathname has a warning, so require it first while silencing
-# warnings to shut it up.
-#
-# Also, in 1.9, Bundler creates warnings due to overriding
-# Rubygems methods
-begin
- old, $VERBOSE = $VERBOSE, nil
- require 'pathname'
- require File.expand_path('../../../load_paths', __FILE__)
-ensure
- $VERBOSE = old
-end
-
+require File.expand_path('../../../load_paths', __FILE__)
require 'active_support/core_ext/kernel/reporting'
# These are the normal settings that will be set up by Railties
--
cgit v1.2.3
From 5f2f9b57c404f27f9519d1e5dfb972981181da66 Mon Sep 17 00:00:00 2001
From: Marcelo Silveira
Date: Thu, 3 May 2012 09:11:31 -0300
Subject: No need to force conversion to Symbol since case ensures it's already
one.
---
actionmailer/lib/action_mailer/delivery_methods.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/actionmailer/lib/action_mailer/delivery_methods.rb b/actionmailer/lib/action_mailer/delivery_methods.rb
index d1467fb526..3b38dbccc7 100644
--- a/actionmailer/lib/action_mailer/delivery_methods.rb
+++ b/actionmailer/lib/action_mailer/delivery_methods.rb
@@ -65,7 +65,7 @@ module ActionMailer
when NilClass
raise "Delivery method cannot be nil"
when Symbol
- if klass = delivery_methods[method.to_sym]
+ if klass = delivery_methods[method]
mail.delivery_method(klass, send(:"#{method}_settings"))
else
raise "Invalid delivery method #{method.inspect}"
--
cgit v1.2.3
From e821611cb6142d2055de565fabe783ffd6ef4cfb Mon Sep 17 00:00:00 2001
From: Paul McMahon
Date: Thu, 3 May 2012 18:02:25 +0900
Subject: use extract_options!
---
actionpack/lib/action_dispatch/routing/redirection.rb | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/actionpack/lib/action_dispatch/routing/redirection.rb b/actionpack/lib/action_dispatch/routing/redirection.rb
index 444a79c50d..95c588c00a 100644
--- a/actionpack/lib/action_dispatch/routing/redirection.rb
+++ b/actionpack/lib/action_dispatch/routing/redirection.rb
@@ -1,5 +1,6 @@
require 'action_dispatch/http/request'
require 'active_support/core_ext/uri'
+require 'active_support/core_ext/array/extract_options'
require 'rack/utils'
module ActionDispatch
@@ -99,7 +100,7 @@ module ActionDispatch
# match 'accounts/:name' => redirect(SubdomainRedirector.new('api'))
#
def redirect(*args, &block)
- options = args.last.is_a?(Hash) ? args.pop : {}
+ options = args.extract_options!
status = options.delete(:status) || 301
return OptionRedirect.new(status, options) if options.any?
--
cgit v1.2.3
From a544e006814a1ef82db6af50637eee3d35740c39 Mon Sep 17 00:00:00 2001
From: Andy Lindeman
Date: Thu, 3 May 2012 09:16:38 -0400
Subject: Allows assert_redirected_to to accept a regular expression
---
actionpack/CHANGELOG.md | 2 ++
.../action_dispatch/testing/assertions/response.rb | 33 +++++++++++++---------
.../test/controller/action_pack_assertions_test.rb | 4 +++
3 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 6bad313aef..96dee33f7b 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,5 +1,7 @@
## Rails 4.0.0 (unreleased) ##
+* Allows `assert_redirected_to` to match against a regular expression. *Andy Lindeman*
+
* Add backtrace to development routing error page. *Richard Schneeman*
* Replace `include_seconds` boolean argument with `:include_seconds => true` option
diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb
index 40d38c59d6..8f6fff5d32 100644
--- a/actionpack/lib/action_dispatch/testing/assertions/response.rb
+++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb
@@ -53,15 +53,18 @@ module ActionDispatch
# # assert that the redirection was to the url for @customer
# assert_redirected_to @customer
#
+ # # asserts that the redirection matches the regular expression
+ # assert_redirected_to %r(\Ahttp://example.org)
+ #
def assert_redirected_to(options = {}, message=nil)
assert_response(:redirect, message)
- return true if options == @response.location
+ return true if options === @response.location
redirect_is = normalize_argument_to_redirection(@response.location)
redirect_expected = normalize_argument_to_redirection(options)
message ||= "Expected response to be a redirect to <#{redirect_expected}> but was a redirect to <#{redirect_is}>"
- assert_equal redirect_expected, redirect_is, message
+ assert_operator redirect_expected, :===, redirect_is, message
end
private
@@ -71,17 +74,21 @@ module ActionDispatch
end
def normalize_argument_to_redirection(fragment)
- case fragment
- when %r{^\w[A-Za-z\d+.-]*:.*}
- fragment
- when String
- @request.protocol + @request.host_with_port + fragment
- when :back
- raise RedirectBackError unless refer = @request.headers["Referer"]
- refer
- else
- @controller.url_for(fragment)
- end.delete("\0\r\n")
+ normalized = case fragment
+ when Regexp
+ fragment
+ when %r{^\w[A-Za-z\d+.-]*:.*}
+ fragment
+ when String
+ @request.protocol + @request.host_with_port + fragment
+ when :back
+ raise RedirectBackError unless refer = @request.headers["Referer"]
+ refer
+ else
+ @controller.url_for(fragment)
+ end
+
+ normalized.respond_to?(:delete) ? normalized.delete("\0\r\n") : normalized
end
end
end
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb
index b121ca9481..f5f397c9c0 100644
--- a/actionpack/test/controller/action_pack_assertions_test.rb
+++ b/actionpack/test/controller/action_pack_assertions_test.rb
@@ -178,6 +178,9 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
assert_raise(ActiveSupport::TestCase::Assertion) do
assert_redirected_to 'http://test.host/route_two'
end
+ assert_raise(ActiveSupport::TestCase::Assertion) do
+ assert_redirected_to %r(^http://test.host/route_two)
+ end
assert_raise(ActiveSupport::TestCase::Assertion) do
assert_redirected_to :controller => 'action_pack_assertions', :action => 'nothing', :id => 'two'
end
@@ -212,6 +215,7 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
process :redirect_to_top_level_named_route
# assert_redirected_to "http://test.host/action_pack_assertions/foo" would pass because of exact match early return
assert_redirected_to "/action_pack_assertions/foo"
+ assert_redirected_to %r(/action_pack_assertions/foo)
end
end
--
cgit v1.2.3
From 95960767447b9ba7232ec1c85e08093bb4b9dd07 Mon Sep 17 00:00:00 2001
From: Nicholas Yianilos
Date: Thu, 3 May 2012 09:41:29 -0400
Subject: refactored extracting :size => 'XxY' into an extract_size! method
---
actionpack/lib/action_view/helpers/asset_tag_helper.rb | 8 ++------
actionpack/lib/action_view/helpers/form_tag_helper.rb | 4 +---
actionpack/lib/action_view/helpers/tag_helper.rb | 6 ++++++
actionpack/lib/action_view/helpers/tags/text_area.rb | 4 +---
4 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index 7985683a72..cca4de5aee 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -393,9 +393,7 @@ module ActionView
options[:alt] = options.fetch(:alt){ image_alt(src) }
end
- if size = options.delete(:size)
- options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
- end
+ extract_size!(options, :width, :height)
if mouseover = options.delete(:mouseover)
options[:onmouseover] = "this.src='#{path_to_image(mouseover)}'"
@@ -448,9 +446,7 @@ module ActionView
multiple_sources_tag('video', sources) do |options|
options[:poster] = path_to_image(options[:poster]) if options[:poster]
- if size = options.delete(:size)
- options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
- end
+ extract_size!(options, :width, :height)
end
end
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index b5e0970612..1dcf3621f0 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -317,9 +317,7 @@ module ActionView
def text_area_tag(name, content = nil, options = {})
options = options.stringify_keys
- if size = options.delete("size")
- options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split)
- end
+ extract_size!(options, 'cols', 'rows')
escape = options.delete("escape") { true }
content = ERB::Util.html_escape(content) if escape
diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb
index f7afa48256..1eeff38ab8 100644
--- a/actionpack/lib/action_view/helpers/tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/tag_helper.rb
@@ -137,6 +137,12 @@ module ActionView
"<#{name}#{tag_options}>#{PRE_CONTENT_STRINGS[name.to_sym]}#{content}#{name}>".html_safe
end
+ def extract_size!(options, x_attribute, y_attribute)
+ if size = options.delete(:size)
+ options[x_attribute], options[y_attribute] = size.split("x") if size =~ %r{^\d+x\d+$}
+ end
+ end
+
def tag_options(options, escape = true)
return if options.blank?
attrs = []
diff --git a/actionpack/lib/action_view/helpers/tags/text_area.rb b/actionpack/lib/action_view/helpers/tags/text_area.rb
index f74652c5e7..160f020263 100644
--- a/actionpack/lib/action_view/helpers/tags/text_area.rb
+++ b/actionpack/lib/action_view/helpers/tags/text_area.rb
@@ -6,9 +6,7 @@ module ActionView
options = @options.stringify_keys
add_default_name_and_id(options)
- if size = options.delete("size")
- options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split)
- end
+ extract_size!(options, 'cols', 'rows')
content_tag("textarea", options.delete('value') || value_before_type_cast(object), options)
end
--
cgit v1.2.3
From 1ab0523cfd405f2f8097841405947c0d26b72150 Mon Sep 17 00:00:00 2001
From: Bogdan Gusiev
Date: Thu, 3 May 2012 18:44:12 +0300
Subject: RouteSet: optimize routes generation when globbing is used
---
actionpack/lib/action_dispatch/routing/route_set.rb | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 57ce7b4ba9..7abd7bd008 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -202,7 +202,7 @@ module ActionDispatch
# Clause check about when we need to generate an optimized helper.
def optimize_helper?(route) #:nodoc:
- route.ast.grep(Journey::Nodes::Star).empty? && route.requirements.except(:controller, :action).empty?
+ route.requirements.except(:controller, :action).empty?
end
# Generates the interpolation to be used in the optimized helper.
@@ -214,7 +214,10 @@ module ActionDispatch
end
route.required_parts.each_with_index do |part, i|
- string_route.gsub!(part.inspect, "\#{Journey::Router::Utils.escape_fragment(args[#{i}].to_param)}")
+ # Replace each route parameter
+ # e.g. :id for regular parameter or *path for globbing
+ # with ruby string interpolation code
+ string_route.gsub!(/(\*|:)#{part}/, "\#{Journey::Router::Utils.escape_fragment(args[#{i}].to_param)}")
end
string_route
--
cgit v1.2.3
From c4f02295df74ed4e09b664dd5bf3d00a5aa9b6a4 Mon Sep 17 00:00:00 2001
From: Aaron Patterson
Date: Thu, 3 May 2012 14:28:11 -0700
Subject: bread AD::Request::Session to it's own file, consolidate HASH OF DOOM
lookups
---
actionpack/lib/action_dispatch/http/request.rb | 5 +-
actionpack/lib/action_dispatch/middleware/flash.rb | 2 +-
.../middleware/session/abstract_store.rb | 151 +------------------
actionpack/lib/action_dispatch/request/session.rb | 166 +++++++++++++++++++++
4 files changed, 171 insertions(+), 153 deletions(-)
create mode 100644 actionpack/lib/action_dispatch/request/session.rb
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb
index 796e0dbc45..9748956052 100644
--- a/actionpack/lib/action_dispatch/http/request.rb
+++ b/actionpack/lib/action_dispatch/http/request.rb
@@ -6,6 +6,7 @@ require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/core_ext/string/access'
require 'active_support/inflector'
require 'action_dispatch/http/headers'
+require 'action_dispatch/request/session'
require 'action_controller/metal/exceptions'
module ActionDispatch
@@ -220,11 +221,11 @@ module ActionDispatch
end
def session=(session) #:nodoc:
- @env['rack.session'] = session
+ Session.set @env, session
end
def session_options=(options)
- @env['rack.session.options'] = options
+ Session::Options.set @env, options
end
# Override Rack's GET method to support indifferent access
diff --git a/actionpack/lib/action_dispatch/middleware/flash.rb b/actionpack/lib/action_dispatch/middleware/flash.rb
index fd0ce62a3b..bc68615be7 100644
--- a/actionpack/lib/action_dispatch/middleware/flash.rb
+++ b/actionpack/lib/action_dispatch/middleware/flash.rb
@@ -218,7 +218,7 @@ module ActionDispatch
def call(env)
@app.call(env)
ensure
- session = env['rack.session'] || {}
+ session = Request::Session.find(env) || {}
flash_hash = env[KEY]
if flash_hash
diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
index 134ca2dc5f..d902adaff1 100644
--- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
@@ -2,6 +2,7 @@ require 'rack/utils'
require 'rack/request'
require 'rack/session/abstract/id'
require 'action_dispatch/middleware/cookies'
+require 'action_dispatch/request/session'
require 'active_support/core_ext/object/blank'
module ActionDispatch
@@ -84,154 +85,4 @@ module ActionDispatch
end
end
end
-
- class Request
- # SessionHash is responsible to lazily load the session from store.
- class Session # :nodoc:
- ENV_SESSION_KEY = Rack::Session::Abstract::ENV_SESSION_KEY # :nodoc:
- ENV_SESSION_OPTIONS_KEY = Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY # :nodoc:
-
- def self.create(store, env, default_options)
- session_was = env[ENV_SESSION_KEY]
- session = Request::Session.new(store, env)
- env[ENV_SESSION_KEY] = session
- env[ENV_SESSION_OPTIONS_KEY] = Request::Session::Options.new(store, env, default_options)
- env[ENV_SESSION_KEY].merge! session_was if session_was
- session
- end
-
- def self.find(env)
- env[ENV_SESSION_KEY]
- end
-
- class Options #:nodoc:
- def initialize(by, env, default_options)
- @by = by
- @env = env
- @delegate = default_options
- end
-
- def [](key)
- if key == :id
- @delegate.fetch(key) {
- @delegate[:id] = @by.send(:extract_session_id, @env)
- }
- else
- @delegate[key]
- end
- end
-
- def []=(k,v); @delegate[k] = v; end
- def to_hash; @delegate.dup; end
- def values_at(*args); @delegate.values_at(*args); end
- end
-
- def initialize(by, env)
- @by = by
- @env = env
- @delegate = {}
- @loaded = false
- @exists = nil # we haven't checked yet
- end
-
- def options
- @env[ENV_SESSION_OPTIONS_KEY]
- end
-
- def destroy
- clear
- options = self.options || {}
- @by.send(:destroy_session, @env, options[:id], options)
- options[:id] = nil
- @loaded = false
- end
-
- def [](key)
- load_for_read!
- @delegate[key.to_s]
- end
-
- def has_key?(key)
- load_for_read!
- @delegate.key?(key.to_s)
- end
- alias :key? :has_key?
- alias :include? :has_key?
-
- def []=(key, value)
- load_for_write!
- @delegate[key.to_s] = value
- end
-
- def clear
- load_for_write!
- @delegate.clear
- end
-
- def to_hash
- load_for_read!
- @delegate.dup.delete_if { |_,v| v.nil? }
- end
-
- def update(hash)
- load_for_write!
- @delegate.update stringify_keys(hash)
- end
-
- def delete(key)
- load_for_write!
- @delegate.delete key.to_s
- end
-
- def inspect
- if loaded?
- super
- else
- "#<#{self.class}:0x#{(object_id << 1).to_s(16)} not yet loaded>"
- end
- end
-
- def exists?
- return @exists unless @exists.nil?
- @exists = @by.send(:session_exists?, @env)
- end
-
- def loaded?
- @loaded
- end
-
- def empty?
- load_for_read!
- @delegate.empty?
- end
-
- def merge!(other)
- load_for_write!
- @delegate.merge!(other)
- end
-
- private
-
- def load_for_read!
- load! if !loaded? && exists?
- end
-
- def load_for_write!
- load! unless loaded?
- end
-
- def load!
- id, session = @by.load_session @env
- options[:id] = id
- @delegate.replace(stringify_keys(session))
- @loaded = true
- end
-
- def stringify_keys(other)
- other.each_with_object({}) { |(key, value), hash|
- hash[key.to_s] = value
- }
- end
- end
- end
end
diff --git a/actionpack/lib/action_dispatch/request/session.rb b/actionpack/lib/action_dispatch/request/session.rb
new file mode 100644
index 0000000000..338165935b
--- /dev/null
+++ b/actionpack/lib/action_dispatch/request/session.rb
@@ -0,0 +1,166 @@
+require 'rack/session/abstract/id'
+
+module ActionDispatch
+ class Request < Rack::Request
+ # SessionHash is responsible to lazily load the session from store.
+ class Session # :nodoc:
+ ENV_SESSION_KEY = Rack::Session::Abstract::ENV_SESSION_KEY # :nodoc:
+ ENV_SESSION_OPTIONS_KEY = Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY # :nodoc:
+
+ def self.create(store, env, default_options)
+ session_was = find env
+ session = Request::Session.new(store, env)
+ session.merge! session_was if session_was
+
+ set(env, session)
+ Options.set(env, Request::Session::Options.new(store, env, default_options))
+ session
+ end
+
+ def self.find(env)
+ env[ENV_SESSION_KEY]
+ end
+
+ def self.set(env, session)
+ env[ENV_SESSION_KEY] = session
+ end
+
+ class Options #:nodoc:
+ def self.set(env, options)
+ env[ENV_SESSION_OPTIONS_KEY] = options
+ end
+
+ def self.find(env)
+ env[ENV_SESSION_OPTIONS_KEY]
+ end
+
+ def initialize(by, env, default_options)
+ @by = by
+ @env = env
+ @delegate = default_options
+ end
+
+ def [](key)
+ if key == :id
+ @delegate.fetch(key) {
+ @delegate[:id] = @by.send(:extract_session_id, @env)
+ }
+ else
+ @delegate[key]
+ end
+ end
+
+ def []=(k,v); @delegate[k] = v; end
+ def to_hash; @delegate.dup; end
+ def values_at(*args); @delegate.values_at(*args); end
+ end
+
+ def initialize(by, env)
+ @by = by
+ @env = env
+ @delegate = {}
+ @loaded = false
+ @exists = nil # we haven't checked yet
+ end
+
+ def options
+ Options.find @env
+ end
+
+ def destroy
+ clear
+ options = self.options || {}
+ @by.send(:destroy_session, @env, options[:id], options)
+ options[:id] = nil
+ @loaded = false
+ end
+
+ def [](key)
+ load_for_read!
+ @delegate[key.to_s]
+ end
+
+ def has_key?(key)
+ load_for_read!
+ @delegate.key?(key.to_s)
+ end
+ alias :key? :has_key?
+ alias :include? :has_key?
+
+ def []=(key, value)
+ load_for_write!
+ @delegate[key.to_s] = value
+ end
+
+ def clear
+ load_for_write!
+ @delegate.clear
+ end
+
+ def to_hash
+ load_for_read!
+ @delegate.dup.delete_if { |_,v| v.nil? }
+ end
+
+ def update(hash)
+ load_for_write!
+ @delegate.update stringify_keys(hash)
+ end
+
+ def delete(key)
+ load_for_write!
+ @delegate.delete key.to_s
+ end
+
+ def inspect
+ if loaded?
+ super
+ else
+ "#<#{self.class}:0x#{(object_id << 1).to_s(16)} not yet loaded>"
+ end
+ end
+
+ def exists?
+ return @exists unless @exists.nil?
+ @exists = @by.send(:session_exists?, @env)
+ end
+
+ def loaded?
+ @loaded
+ end
+
+ def empty?
+ load_for_read!
+ @delegate.empty?
+ end
+
+ def merge!(other)
+ load_for_write!
+ @delegate.merge!(other)
+ end
+
+ private
+
+ def load_for_read!
+ load! if !loaded? && exists?
+ end
+
+ def load_for_write!
+ load! unless loaded?
+ end
+
+ def load!
+ id, session = @by.load_session @env
+ options[:id] = id
+ @delegate.replace(stringify_keys(session))
+ @loaded = true
+ end
+
+ def stringify_keys(other)
+ other.each_with_object({}) { |(key, value), hash|
+ hash[key.to_s] = value
+ }
+ end
+ end
+ end
+end
--
cgit v1.2.3
From 8eedd1a4a7bed400d0daed1fecafc4f84c5561f2 Mon Sep 17 00:00:00 2001
From: twinturbo
Date: Thu, 3 May 2012 15:47:02 -0700
Subject: Make ActionController#head pass rack-link
---
actionpack/lib/action_controller/metal/head.rb | 21 +++++++-
.../test/controller/new_base/bare_metal_test.rb | 60 ++++++++++++++++++++++
2 files changed, 80 insertions(+), 1 deletion(-)
diff --git a/actionpack/lib/action_controller/metal/head.rb b/actionpack/lib/action_controller/metal/head.rb
index a618533d09..802c44cc73 100644
--- a/actionpack/lib/action_controller/metal/head.rb
+++ b/actionpack/lib/action_controller/metal/head.rb
@@ -27,8 +27,27 @@ module ActionController
self.status = status
self.location = url_for(location) if location
- self.content_type = Mime[formats.first] if formats
+
+ if include_content_type?(self.status)
+ self.content_type = Mime[formats.first] if formats
+ else
+ headers.delete('Content-Type')
+ end
+
self.response_body = " "
end
+
+ private
+ # :nodoc:
+ def include_content_type?(status)
+ case status
+ when 100..199
+ false
+ when 204, 205, 304
+ false
+ else
+ true
+ end
+ end
end
end
diff --git a/actionpack/test/controller/new_base/bare_metal_test.rb b/actionpack/test/controller/new_base/bare_metal_test.rb
index c424dcbd8d..df457f8a3c 100644
--- a/actionpack/test/controller/new_base/bare_metal_test.rb
+++ b/actionpack/test/controller/new_base/bare_metal_test.rb
@@ -37,6 +37,36 @@ module BareMetalTest
def index
head :not_found
end
+
+ def continue
+ self.content_type = "text/html"
+ head 100
+ end
+
+ def switching_protocols
+ self.content_type = "text/html"
+ head 101
+ end
+
+ def processing
+ self.content_type = "text/html"
+ head 102
+ end
+
+ def no_content
+ self.content_type = "text/html"
+ head 204
+ end
+
+ def reset_content
+ self.content_type = "text/html"
+ head 205
+ end
+
+ def not_modified
+ self.content_type = "text/html"
+ head 304
+ end
end
class HeadTest < ActiveSupport::TestCase
@@ -44,6 +74,36 @@ module BareMetalTest
status = HeadController.action(:index).call(Rack::MockRequest.env_for("/")).first
assert_equal 404, status
end
+
+ test "head :continue (100) does not return a content-type header" do
+ headers = HeadController.action(:continue).call(Rack::MockRequest.env_for("/")).second
+ assert_nil headers['Content-Type']
+ end
+
+ test "head :continue (101) does not return a content-type header" do
+ headers = HeadController.action(:continue).call(Rack::MockRequest.env_for("/")).second
+ assert_nil headers['Content-Type']
+ end
+
+ test "head :processing (102) does not return a content-type header" do
+ headers = HeadController.action(:processing).call(Rack::MockRequest.env_for("/")).second
+ assert_nil headers['Content-Type']
+ end
+
+ test "head :no_content (204) does not return a content-type header" do
+ headers = HeadController.action(:no_content).call(Rack::MockRequest.env_for("/")).second
+ assert_nil headers['Content-Type']
+ end
+
+ test "head :reset_content (205) does not return a content-type header" do
+ headers = HeadController.action(:reset_content).call(Rack::MockRequest.env_for("/")).second
+ assert_nil headers['Content-Type']
+ end
+
+ test "head :not_modified (304) does not return a content-type header" do
+ headers = HeadController.action(:not_modified).call(Rack::MockRequest.env_for("/")).second
+ assert_nil headers['Content-Type']
+ end
end
class BareControllerTest < ActionController::TestCase
--
cgit v1.2.3
From 8edd21c66fee41f755cf962e898646005ae866c0 Mon Sep 17 00:00:00 2001
From: twinturbo
Date: Thu, 3 May 2012 17:24:05 -0700
Subject: Remove content-length as well
---
actionpack/lib/action_controller/metal/head.rb | 5 +++--
actionpack/test/controller/new_base/bare_metal_test.rb | 6 ++++++
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/actionpack/lib/action_controller/metal/head.rb b/actionpack/lib/action_controller/metal/head.rb
index 802c44cc73..5bdbde9ebb 100644
--- a/actionpack/lib/action_controller/metal/head.rb
+++ b/actionpack/lib/action_controller/metal/head.rb
@@ -28,10 +28,11 @@ module ActionController
self.status = status
self.location = url_for(location) if location
- if include_content_type?(self.status)
+ if include_content_headers?(self.status)
self.content_type = Mime[formats.first] if formats
else
headers.delete('Content-Type')
+ headers.delete('Content-Length')
end
self.response_body = " "
@@ -39,7 +40,7 @@ module ActionController
private
# :nodoc:
- def include_content_type?(status)
+ def include_content_headers?(status)
case status
when 100..199
false
diff --git a/actionpack/test/controller/new_base/bare_metal_test.rb b/actionpack/test/controller/new_base/bare_metal_test.rb
index df457f8a3c..5bcd79ebec 100644
--- a/actionpack/test/controller/new_base/bare_metal_test.rb
+++ b/actionpack/test/controller/new_base/bare_metal_test.rb
@@ -78,31 +78,37 @@ module BareMetalTest
test "head :continue (100) does not return a content-type header" do
headers = HeadController.action(:continue).call(Rack::MockRequest.env_for("/")).second
assert_nil headers['Content-Type']
+ assert_nil headers['Content-Length']
end
test "head :continue (101) does not return a content-type header" do
headers = HeadController.action(:continue).call(Rack::MockRequest.env_for("/")).second
assert_nil headers['Content-Type']
+ assert_nil headers['Content-Length']
end
test "head :processing (102) does not return a content-type header" do
headers = HeadController.action(:processing).call(Rack::MockRequest.env_for("/")).second
assert_nil headers['Content-Type']
+ assert_nil headers['Content-Length']
end
test "head :no_content (204) does not return a content-type header" do
headers = HeadController.action(:no_content).call(Rack::MockRequest.env_for("/")).second
assert_nil headers['Content-Type']
+ assert_nil headers['Content-Length']
end
test "head :reset_content (205) does not return a content-type header" do
headers = HeadController.action(:reset_content).call(Rack::MockRequest.env_for("/")).second
assert_nil headers['Content-Type']
+ assert_nil headers['Content-Length']
end
test "head :not_modified (304) does not return a content-type header" do
headers = HeadController.action(:not_modified).call(Rack::MockRequest.env_for("/")).second
assert_nil headers['Content-Type']
+ assert_nil headers['Content-Length']
end
end
--
cgit v1.2.3
From 616de66c55b58479e7da4271a0c990529395440e Mon Sep 17 00:00:00 2001
From: Alexey Vakhov
Date: Fri, 4 May 2012 12:32:35 +0400
Subject: Fix ActiveModel README example
---
activemodel/README.rdoc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/activemodel/README.rdoc b/activemodel/README.rdoc
index 9b05384792..1fd75141f8 100644
--- a/activemodel/README.rdoc
+++ b/activemodel/README.rdoc
@@ -25,7 +25,7 @@ to integrate with Action Pack out of the box: ActiveModel::Model.
person = Person.new(:name => 'bob', :age => '18')
person.name # => 'bob'
- person.age # => 18
+ person.age # => '18'
person.valid? # => true
It includes model name introspections, conversions, translations and
--
cgit v1.2.3
From 0d8cf53296a4d7c1e6d85c533784a2607bfe3baa Mon Sep 17 00:00:00 2001
From: Jared Armstrong
Date: Sat, 17 Mar 2012 00:37:56 +1300
Subject: Allow ActiveRecord::Relation merges to maintain context of joined
associations
---
.../active_record/associations/join_dependency.rb | 2 +-
.../join_dependency/join_association.rb | 7 ++++-
activerecord/lib/active_record/relation/merger.rb | 31 +++++++++++++++++++---
activerecord/test/cases/relations_test.rb | 9 ++++++-
4 files changed, 43 insertions(+), 6 deletions(-)
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb
index cd366ac8b7..e3d8356f49 100644
--- a/activerecord/lib/active_record/associations/join_dependency.rb
+++ b/activerecord/lib/active_record/associations/join_dependency.rb
@@ -109,7 +109,7 @@ module ActiveRecord
case associations
when Symbol, String
reflection = parent.reflections[associations.to_s.intern] or
- raise ConfigurationError, "Association named '#{ associations }' was not found; perhaps you misspelled it?"
+ raise ConfigurationError, "Association named '#{ associations }' was not found on #{parent.active_record.name}; perhaps you misspelled it?"
unless join_association = find_join_association(reflection, parent)
@reflections << reflection
join_association = build_join_association(reflection, parent)
diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
index 0d7d28e458..ea4856408d 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -55,7 +55,12 @@ module ActiveRecord
def find_parent_in(other_join_dependency)
other_join_dependency.join_parts.detect do |join_part|
- parent == join_part
+ case parent
+ when JoinBase
+ parent.active_record == join_part.active_record
+ else
+ parent == join_part
+ end
end
end
diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb
index 3f880ce5e9..c2f0a82fd3 100644
--- a/activerecord/lib/active_record/relation/merger.rb
+++ b/activerecord/lib/active_record/relation/merger.rb
@@ -29,7 +29,7 @@ module ActiveRecord
end
class Merger
- attr_reader :relation, :values
+ attr_reader :relation, :other
def initialize(relation, other)
if other.default_scoped? && other.klass != relation.klass
@@ -37,13 +37,17 @@ module ActiveRecord
end
@relation = relation
- @values = other.values
+ @other = other
+ end
+
+ def values
+ @other.values
end
def normal_values
Relation::SINGLE_VALUE_METHODS +
Relation::MULTI_VALUE_METHODS -
- [:where, :order, :bind, :reverse_order, :lock, :create_with, :reordering]
+ [:where, :joins, :order, :bind, :reverse_order, :lock, :create_with, :reordering]
end
def merge
@@ -54,6 +58,7 @@ module ActiveRecord
merge_multi_values
merge_single_values
+ merge_joins
relation
end
@@ -84,6 +89,26 @@ module ActiveRecord
end
end
+ def merge_joins
+ return if values[:joins].blank?
+
+ if other.klass == relation.klass
+ relation.joins!(values[:joins])
+ else
+ joins_to_stash, other_joins = values[:joins].partition { |join|
+ case join
+ when Hash, Symbol, Array
+ true
+ else
+ false
+ end
+ }
+
+ join_dependency = ActiveRecord::Associations::JoinDependency.new(other.klass, joins_to_stash, [])
+ relation.joins!(join_dependency.join_associations + other_joins)
+ end
+ end
+
def merged_binds
if values[:bind]
(relation.bind_values + values[:bind]).uniq(&:first)
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 3ef357e297..48fc82bbc7 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -6,6 +6,7 @@ require 'models/topic'
require 'models/comment'
require 'models/author'
require 'models/comment'
+require 'models/rating'
require 'models/entrant'
require 'models/developer'
require 'models/reply'
@@ -19,7 +20,7 @@ require 'models/minivan'
class RelationTest < ActiveRecord::TestCase
fixtures :authors, :topics, :entrants, :developers, :companies, :developers_projects, :accounts, :categories, :categorizations, :posts, :comments,
- :tags, :taggings, :cars, :minivans
+ :ratings, :tags, :taggings, :cars, :minivans
def test_do_not_double_quote_string_id
van = Minivan.last
@@ -731,6 +732,12 @@ class RelationTest < ActiveRecord::TestCase
assert_equal 1, comments.count
end
+ def test_relation_merging_with_merged_joins
+ special_comments_with_ratings = SpecialComment.joins(:ratings)
+ posts_with_special_comments_with_ratings = Post.group("posts.id").joins(:special_comments).merge(special_comments_with_ratings)
+ assert_equal 1, authors(:david).posts.merge(posts_with_special_comments_with_ratings).to_a.length
+ end
+
def test_count
posts = Post.scoped
--
cgit v1.2.3
From 0c76a52c472546083a199f685f96170031b36fdd Mon Sep 17 00:00:00 2001
From: Jon Leighton
Date: Wed, 2 May 2012 23:57:52 +0100
Subject: clean up implementation of dynamic methods. use method compilation
etc.
---
activerecord/lib/active_record.rb | 2 -
.../active_record/associations/collection_proxy.rb | 6 +-
.../lib/active_record/dynamic_finder_match.rb | 108 ----------
activerecord/lib/active_record/dynamic_matchers.rb | 228 ++++++++++++++++++---
.../lib/active_record/dynamic_scope_match.rb | 30 ---
.../lib/active_record/relation/finder_methods.rb | 41 ----
.../test/cases/dynamic_finder_match_test.rb | 106 ----------
activerecord/test/cases/named_scope_test.rb | 5 +-
8 files changed, 204 insertions(+), 322 deletions(-)
delete mode 100644 activerecord/lib/active_record/dynamic_finder_match.rb
delete mode 100644 activerecord/lib/active_record/dynamic_scope_match.rb
delete mode 100644 activerecord/test/cases/dynamic_finder_match_test.rb
diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb
index c4b10a8dae..ed26b4899f 100644
--- a/activerecord/lib/active_record.rb
+++ b/activerecord/lib/active_record.rb
@@ -63,8 +63,6 @@ module ActiveRecord
autoload :CounterCache
autoload :ConnectionHandling
autoload :DynamicMatchers
- autoload :DynamicFinderMatch
- autoload :DynamicScopeMatch
autoload :Explain
autoload :Inheritance
autoload :Integration
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index 50d16b16a9..8bbab75de6 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -79,9 +79,9 @@ module ActiveRecord
end
def method_missing(method, *args, &block)
- match = DynamicFinderMatch.match(method)
- if match && match.instantiator?
- scoped.send(:find_or_instantiator_by_attributes, match, match.attribute_names, *args) do |r|
+ match = DynamicMatchers::Method.match(method)
+ if match && match.is_a?(DynamicMatchers::Instantiator)
+ scoped.send(method, *args) do |r|
proxy_association.send :set_owner_attributes, r
proxy_association.send :add_to_target, r
yield(r) if block_given?
diff --git a/activerecord/lib/active_record/dynamic_finder_match.rb b/activerecord/lib/active_record/dynamic_finder_match.rb
deleted file mode 100644
index 0473d6aafc..0000000000
--- a/activerecord/lib/active_record/dynamic_finder_match.rb
+++ /dev/null
@@ -1,108 +0,0 @@
-module ActiveRecord
-
- # = Active Record Dynamic Finder Match
- #
- # Refer to ActiveRecord::Base documentation for Dynamic attribute-based finders for detailed info
- #
- class DynamicFinderMatch
- def self.match(method)
- method = method.to_s
- klass = klasses.find do |_klass|
- _klass.matches?(method)
- end
- klass.new(method) if klass
- end
-
- def self.matches?(method)
- method =~ self::METHOD_PATTERN
- end
-
- def self.klasses
- [FindBy, FindByBang, FindOrInitializeCreateBy, FindOrCreateByBang]
- end
-
- def initialize(method)
- @finder = :first
- @instantiator = nil
- match_data = method.match(self.class::METHOD_PATTERN)
- @attribute_names = match_data[-1].split("_and_")
- initialize_from_match_data(match_data)
- end
-
- attr_reader :finder, :attribute_names, :instantiator
-
- def finder?
- @finder && !@instantiator
- end
-
- def creator?
- @finder == :first && @instantiator == :create
- end
-
- def instantiator?
- @instantiator
- end
-
- def bang?
- false
- end
-
- def valid_arguments?(arguments)
- arguments.size >= @attribute_names.size
- end
-
- def save_record?
- @instantiator == :create
- end
-
- def save_method
- bang? ? :save! : :save
- end
-
- private
-
- def initialize_from_match_data(match_data)
- end
- end
-
- class FindBy < DynamicFinderMatch
- METHOD_PATTERN = /^find_(all_|last_)?by_([_a-zA-Z]\w*)$/
-
- def initialize_from_match_data(match_data)
- @finder = :last if match_data[1] == 'last_'
- @finder = :all if match_data[1] == 'all_'
- end
- end
-
- class FindByBang < DynamicFinderMatch
- METHOD_PATTERN = /^find_by_([_a-zA-Z]\w*)\!$/
-
- def bang?
- true
- end
- end
-
- class FindOrInitializeCreateBy < DynamicFinderMatch
- METHOD_PATTERN = /^find_or_(initialize|create)_by_([_a-zA-Z]\w*)$/
-
- def initialize_from_match_data(match_data)
- @instantiator = match_data[1] == 'initialize' ? :new : :create
- end
-
- def valid_arguments?(arguments)
- arguments.size == 1 && arguments.first.is_a?(Hash) || super
- end
- end
-
- class FindOrCreateByBang < DynamicFinderMatch
- METHOD_PATTERN = /^find_or_create_by_([_a-zA-Z]\w*)\!$/
-
- def initialize_from_match_data(match_data)
- @instantiator = :create
- end
-
- def bang?
- true
- end
- end
-end
diff --git a/activerecord/lib/active_record/dynamic_matchers.rb b/activerecord/lib/active_record/dynamic_matchers.rb
index e35b1c91a0..01efaee8fc 100644
--- a/activerecord/lib/active_record/dynamic_matchers.rb
+++ b/activerecord/lib/active_record/dynamic_matchers.rb
@@ -1,7 +1,7 @@
module ActiveRecord
module DynamicMatchers
- def respond_to?(method_id, include_private = false)
- match = find_dynamic_match(method_id)
+ def respond_to?(name, include_private = false)
+ match = Method.match(name)
valid_match = match && all_attributes_exists?(match.attribute_names)
valid_match || super
@@ -18,43 +18,213 @@ module ActiveRecord
#
# Each dynamic finder using scoped_by_* is also defined in the class after it
# is first invoked, so that future attempts to use it do not run through method_missing.
- def method_missing(method_id, *arguments, &block)
- if match = find_dynamic_match(method_id)
+ def method_missing(name, *arguments, &block)
+ if match = Method.match(name)
attribute_names = match.attribute_names
super unless all_attributes_exists?(attribute_names)
- unless match.valid_arguments?(arguments)
- method_trace = "#{__FILE__}:#{__LINE__}:in `#{method_id}'"
- backtrace = [method_trace] + caller
- raise ArgumentError, "wrong number of arguments (#{arguments.size} for #{attribute_names.size})", backtrace
- end
-
- if match.respond_to?(:scope?) && match.scope?
- define_scope_method(method_id, attribute_names)
- send(method_id, *arguments)
- elsif match.finder?
- options = arguments.extract_options!
- relation = options.any? ? scoped(options) : scoped
- relation.send :find_by_attributes, match, attribute_names, *arguments, &block
- elsif match.instantiator?
- scoped.send :find_or_instantiator_by_attributes, match, attribute_names, *arguments, &block
- end
+ match.define(self)
+ send(name, *arguments, &block)
else
super
end
end
- def define_scope_method(method_id, attribute_names) #:nodoc
- self.class_eval <<-METHOD, __FILE__, __LINE__ + 1
- def self.#{method_id}(*args) # def self.scoped_by_user_name_and_password(*args)
- conditions = Hash[[:#{attribute_names.join(',:')}].zip(args)] # conditions = Hash[[:user_name, :password].zip(args)]
- where(conditions) # where(conditions)
- end # end
- METHOD
+ class Method
+ def self.match(name)
+ klass = klasses.find { |k| name =~ k.pattern }
+ klass.new(name) if klass
+ end
+
+ def self.klasses
+ [
+ FindBy, FindAllBy, FindLastBy, FindByBang, ScopedBy,
+ FindOrInitializeBy, FindOrCreateBy, FindOrCreateByBang
+ ]
+ end
+
+ def self.pattern
+ /^#{prefix}_([_a-zA-Z]\w*)#{suffix}$/
+ end
+
+ def self.prefix
+ raise NotImplementedError
+ end
+
+ def self.suffix
+ ''
+ end
+
+ attr_reader :name, :attribute_names
+
+ def initialize(name)
+ @name = name.to_s
+ @attribute_names = @name.match(self.class.pattern)[1].split('_and_')
+ end
+
+ def define(klass)
+ klass.class_eval <<-CODE, __FILE__, __LINE__ + 1
+ def self.#{name}(#{signature})
+ #{body}
+ end
+ CODE
+ end
+
+ def body
+ raise NotImplementedError
+ end
+ end
+
+ class Finder < Method
+ def body
+ <<-CODE
+ result = #{result}
+ result && block_given? ? yield(result) : result
+ CODE
+ end
+
+ def result
+ "scoped.apply_finder_options(options).#{finder}(#{attributes_hash})"
+ end
+
+ def signature
+ attribute_names.join(', ') + ", options = {}"
+ end
+
+ def attributes_hash
+ "{" + attribute_names.map { |name| ":#{name} => #{name}" }.join(',') + "}"
+ end
+
+ def finder
+ raise NotImplementedError
+ end
+ end
+
+ class FindBy < Finder
+ def self.prefix
+ "find_by"
+ end
+
+ def finder
+ "find_by"
+ end
+ end
+
+ class FindByBang < Finder
+ def self.prefix
+ "find_by"
+ end
+
+ def self.suffix
+ "!"
+ end
+
+ def finder
+ "find_by!"
+ end
+ end
+
+ class FindAllBy < Finder
+ def self.prefix
+ "find_all_by"
+ end
+
+ def finder
+ "where"
+ end
+
+ def result
+ "#{super}.to_a"
+ end
+ end
+
+ class FindLastBy < Finder
+ def self.prefix
+ "find_last_by"
+ end
+
+ def finder
+ "where"
+ end
+
+ def result
+ "#{super}.last"
+ end
end
- def find_dynamic_match(method_id) #:nodoc:
- DynamicFinderMatch.match(method_id) || DynamicScopeMatch.match(method_id)
+ class ScopedBy < Finder
+ def self.prefix
+ "scoped_by"
+ end
+
+ def body
+ "where(#{attributes_hash})"
+ end
+ end
+
+ class Instantiator < Method
+ # This is nasty, but it doesn't matter because it will be deprecated.
+ def self.dispatch(klass, attribute_names, instantiator, args, block)
+ if args.length == 1 && args.first.is_a?(Hash)
+ attributes = args.first.stringify_keys
+ conditions = attributes.slice(*attribute_names)
+ rest = [attributes.except(*attribute_names)]
+ else
+ raise ArgumentError, "too few arguments" unless args.length >= attribute_names.length
+
+ conditions = Hash[attribute_names.map.with_index { |n, i| [n, args[i]] }]
+ rest = args.drop(attribute_names.length)
+ end
+
+ klass.where(conditions).first ||
+ klass.create_with(conditions).send(instantiator, *rest, &block)
+ end
+
+ def signature
+ "*args, &block"
+ end
+
+ def body
+ "#{self.class}.dispatch(self, #{attribute_names.inspect}, #{instantiator.inspect}, args, block)"
+ end
+
+ def instantiator
+ raise NotImplementedError
+ end
+ end
+
+ class FindOrInitializeBy < Instantiator
+ def self.prefix
+ "find_or_initialize_by"
+ end
+
+ def instantiator
+ "new"
+ end
+ end
+
+ class FindOrCreateBy < Instantiator
+ def self.prefix
+ "find_or_create_by"
+ end
+
+ def instantiator
+ "create"
+ end
+ end
+
+ class FindOrCreateByBang < Instantiator
+ def self.prefix
+ "find_or_create_by"
+ end
+
+ def self.suffix
+ "!"
+ end
+
+ def instantiator
+ "create!"
+ end
end
# Similar in purpose to +expand_hash_conditions_for_aggregates+.
diff --git a/activerecord/lib/active_record/dynamic_scope_match.rb b/activerecord/lib/active_record/dynamic_scope_match.rb
deleted file mode 100644
index 6c043d29c4..0000000000
--- a/activerecord/lib/active_record/dynamic_scope_match.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-module ActiveRecord
-
- # = Active Record Dynamic Scope Match
- #
- # Provides dynamic attribute-based scopes such as scoped_by_price(4.99)
- # if, for example, the Product has an attribute with that name. You can
- # chain more scoped_by_* methods after the other. It acts like a named
- # scope except that it's dynamic.
- class DynamicScopeMatch
- METHOD_PATTERN = /^scoped_by_([_a-zA-Z]\w*)$/
-
- def self.match(method)
- if method.to_s =~ METHOD_PATTERN
- new(true, $1 && $1.split('_and_'))
- end
- end
-
- def initialize(scope, attribute_names)
- @scope = scope
- @attribute_names = attribute_names
- end
-
- attr_reader :scope, :attribute_names
- alias :scope? :scope
-
- def valid_arguments?(arguments)
- arguments.size >= @attribute_names.size
- end
- end
-end
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 3c9c9c4e84..a78e3d08e4 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -243,47 +243,6 @@ module ActiveRecord
ids_array.empty? ? raise(ThrowResult) : table[primary_key].in(ids_array)
end
- def find_by_attributes(match, attributes, *args)
- conditions = Hash[attributes.map {|a| [a, args[attributes.index(a)]]}]
- result = where(conditions).send(match.finder)
-
- if match.bang? && result.blank?
- raise RecordNotFound, "Couldn't find #{@klass.name} with #{conditions.to_a.collect {|p| p.join(' = ')}.join(', ')}"
- else
- if block_given? && result
- yield(result)
- else
- result
- end
- end
- end
-
- def find_or_instantiator_by_attributes(match, attributes, *args)
- options = args.size > 1 && args.last(2).all?{ |a| a.is_a?(Hash) } ? args.extract_options! : {}
- protected_attributes_for_create, unprotected_attributes_for_create = {}, {}
- args.each_with_index do |arg, i|
- if arg.is_a?(Hash)
- protected_attributes_for_create = args[i].with_indifferent_access
- else
- unprotected_attributes_for_create[attributes[i]] = args[i]
- end
- end
-
- conditions = (protected_attributes_for_create.merge(unprotected_attributes_for_create)).slice(*attributes).symbolize_keys
-
- record = where(conditions).first
-
- unless record
- record = @klass.new(protected_attributes_for_create, options) do |r|
- r.assign_attributes(unprotected_attributes_for_create, :without_protection => true)
- end
- yield(record) if block_given?
- record.send(match.save_method) if match.save_record?
- end
-
- record
- end
-
def find_with_ids(*ids)
return to_a.find { |*block_args| yield(*block_args) } if block_given?
diff --git a/activerecord/test/cases/dynamic_finder_match_test.rb b/activerecord/test/cases/dynamic_finder_match_test.rb
deleted file mode 100644
index db619faa83..0000000000
--- a/activerecord/test/cases/dynamic_finder_match_test.rb
+++ /dev/null
@@ -1,106 +0,0 @@
-require "cases/helper"
-
-module ActiveRecord
- class DynamicFinderMatchTest < ActiveRecord::TestCase
- def test_find_or_create_by
- match = DynamicFinderMatch.match("find_or_create_by_age_and_sex_and_location")
- assert_not_nil match
- assert !match.finder?
- assert match.instantiator?
- assert_equal :first, match.finder
- assert_equal :create, match.instantiator
- assert_equal %w(age sex location), match.attribute_names
- end
-
- def test_find_or_initialize_by
- match = DynamicFinderMatch.match("find_or_initialize_by_age_and_sex_and_location")
- assert_not_nil match
- assert !match.finder?
- assert match.instantiator?
- assert_equal :first, match.finder
- assert_equal :new, match.instantiator
- assert_equal %w(age sex location), match.attribute_names
- end
-
- def test_find_no_match
- assert_nil DynamicFinderMatch.match("not_a_finder")
- end
-
- def find_by_bang
- match = DynamicFinderMatch.match("find_by_age_and_sex_and_location!")
- assert_not_nil match
- assert match.finder?
- assert match.bang?
- assert_equal :first, match.finder
- assert_equal %w(age sex location), match.attribute_names
- end
-
- def test_find_by
- match = DynamicFinderMatch.match("find_by_age_and_sex_and_location")
- assert_not_nil match
- assert match.finder?
- assert_equal :first, match.finder
- assert_equal %w(age sex location), match.attribute_names
- end
-
- def test_find_by_with_symbol
- m = DynamicFinderMatch.match(:find_by_foo)
- assert_equal :first, m.finder
- assert_equal %w{ foo }, m.attribute_names
- end
-
- def test_find_all_by_with_symbol
- m = DynamicFinderMatch.match(:find_all_by_foo)
- assert_equal :all, m.finder
- assert_equal %w{ foo }, m.attribute_names
- end
-
- def test_find_all_by
- match = DynamicFinderMatch.match("find_all_by_age_and_sex_and_location")
- assert_not_nil match
- assert match.finder?
- assert_equal :all, match.finder
- assert_equal %w(age sex location), match.attribute_names
- end
-
- def test_find_last_by
- m = DynamicFinderMatch.match(:find_last_by_foo)
- assert_equal :last, m.finder
- assert_equal %w{ foo }, m.attribute_names
- end
-
- def test_find_by!
- m = DynamicFinderMatch.match(:find_by_foo!)
- assert_equal :first, m.finder
- assert m.bang?, 'should be banging'
- assert_equal %w{ foo }, m.attribute_names
- end
-
- def test_find_or_create
- m = DynamicFinderMatch.match(:find_or_create_by_foo)
- assert_equal :first, m.finder
- assert_equal %w{ foo }, m.attribute_names
- assert_equal :create, m.instantiator
- end
-
- def test_find_or_create!
- m = DynamicFinderMatch.match(:find_or_create_by_foo!)
- assert_equal :first, m.finder
- assert m.bang?, 'should be banging'
- assert_equal %w{ foo }, m.attribute_names
- assert_equal :create, m.instantiator
- end
-
- def test_find_or_initialize
- m = DynamicFinderMatch.match(:find_or_initialize_by_foo)
- assert_equal :first, m.finder
- assert_equal %w{ foo }, m.attribute_names
- assert_equal :new, m.instantiator
- end
-
- def test_garbage
- assert !DynamicFinderMatch.match(:fooo), 'should be false'
- assert !DynamicFinderMatch.match(:find_by), 'should be false'
- end
- end
-end
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb
index f8557259fb..479b375360 100644
--- a/activerecord/test/cases/named_scope_test.rb
+++ b/activerecord/test/cases/named_scope_test.rb
@@ -442,13 +442,12 @@ end
class DynamicScopeMatchTest < ActiveRecord::TestCase
def test_scoped_by_no_match
- assert_nil ActiveRecord::DynamicScopeMatch.match("not_scoped_at_all")
+ assert_nil ActiveRecord::DynamicMatchers::ScopedBy.match("not_scoped_at_all")
end
def test_scoped_by
- match = ActiveRecord::DynamicScopeMatch.match("scoped_by_age_and_sex_and_location")
+ match = ActiveRecord::DynamicMatchers::ScopedBy.match("scoped_by_age_and_sex_and_location")
assert_not_nil match
- assert match.scope?
assert_equal %w(age sex location), match.attribute_names
end
end
--
cgit v1.2.3
From 75a22814ef331ebeb35ee827699fc4177984921f Mon Sep 17 00:00:00 2001
From: Jon Leighton
Date: Thu, 3 May 2012 00:38:30 +0100
Subject: extract code from AR::Base
---
.../active_record/associations/collection_proxy.rb | 2 +-
activerecord/lib/active_record/dynamic_matchers.rb | 60 ++++++++++------------
activerecord/test/cases/named_scope_test.rb | 4 +-
3 files changed, 31 insertions(+), 35 deletions(-)
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index 8bbab75de6..261a829281 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -79,7 +79,7 @@ module ActiveRecord
end
def method_missing(method, *args, &block)
- match = DynamicMatchers::Method.match(method)
+ match = DynamicMatchers::Method.match(self, method)
if match && match.is_a?(DynamicMatchers::Instantiator)
scoped.send(method, *args) do |r|
proxy_association.send :set_owner_attributes, r
diff --git a/activerecord/lib/active_record/dynamic_matchers.rb b/activerecord/lib/active_record/dynamic_matchers.rb
index 01efaee8fc..f3f143940f 100644
--- a/activerecord/lib/active_record/dynamic_matchers.rb
+++ b/activerecord/lib/active_record/dynamic_matchers.rb
@@ -1,10 +1,8 @@
module ActiveRecord
module DynamicMatchers
def respond_to?(name, include_private = false)
- match = Method.match(name)
- valid_match = match && all_attributes_exists?(match.attribute_names)
-
- valid_match || super
+ match = Method.match(self, name)
+ match && match.valid? || super
end
private
@@ -19,11 +17,10 @@ module ActiveRecord
# Each dynamic finder using scoped_by_* is also defined in the class after it
# is first invoked, so that future attempts to use it do not run through method_missing.
def method_missing(name, *arguments, &block)
- if match = Method.match(name)
- attribute_names = match.attribute_names
- super unless all_attributes_exists?(attribute_names)
+ match = Method.match(self, name)
- match.define(self)
+ if match && match.valid?
+ match.define
send(name, *arguments, &block)
else
super
@@ -31,9 +28,9 @@ module ActiveRecord
end
class Method
- def self.match(name)
+ def self.match(model, name)
klass = klasses.find { |k| name =~ k.pattern }
- klass.new(name) if klass
+ klass.new(model, name) if klass
end
def self.klasses
@@ -55,15 +52,32 @@ module ActiveRecord
''
end
- attr_reader :name, :attribute_names
+ attr_reader :model, :name, :attribute_names
- def initialize(name)
+ def initialize(model, name)
+ @model = model
@name = name.to_s
@attribute_names = @name.match(self.class.pattern)[1].split('_and_')
end
- def define(klass)
- klass.class_eval <<-CODE, __FILE__, __LINE__ + 1
+ def expand_attribute_names_for_aggregates
+ attribute_names.map do |attribute_name|
+ if aggregation = model.reflect_on_aggregation(attribute_name.to_sym)
+ model.send(:aggregate_mapping, aggregation).map do |field_attr, _|
+ field_attr.to_sym
+ end
+ else
+ attribute_name.to_sym
+ end
+ end.flatten
+ end
+
+ def valid?
+ (expand_attribute_names_for_aggregates - model.column_methods_hash.keys).empty?
+ end
+
+ def define
+ model.class_eval <<-CODE, __FILE__, __LINE__ + 1
def self.#{name}(#{signature})
#{body}
end
@@ -227,24 +241,6 @@ module ActiveRecord
end
end
- # Similar in purpose to +expand_hash_conditions_for_aggregates+.
- def expand_attribute_names_for_aggregates(attribute_names)
- attribute_names.map do |attribute_name|
- if aggregation = reflect_on_aggregation(attribute_name.to_sym)
- aggregate_mapping(aggregation).map do |field_attr, _|
- field_attr.to_sym
- end
- else
- attribute_name.to_sym
- end
- end.flatten
- end
-
- def all_attributes_exists?(attribute_names)
- (expand_attribute_names_for_aggregates(attribute_names) -
- column_methods_hash.keys).empty?
- end
-
def aggregate_mapping(reflection)
mapping = reflection.options[:mapping] || [reflection.name, reflection.name]
mapping.first.is_a?(Array) ? mapping : [mapping]
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb
index 479b375360..393e578219 100644
--- a/activerecord/test/cases/named_scope_test.rb
+++ b/activerecord/test/cases/named_scope_test.rb
@@ -442,11 +442,11 @@ end
class DynamicScopeMatchTest < ActiveRecord::TestCase
def test_scoped_by_no_match
- assert_nil ActiveRecord::DynamicMatchers::ScopedBy.match("not_scoped_at_all")
+ assert_nil ActiveRecord::DynamicMatchers::ScopedBy.match(nil, "not_scoped_at_all")
end
def test_scoped_by
- match = ActiveRecord::DynamicMatchers::ScopedBy.match("scoped_by_age_and_sex_and_location")
+ match = ActiveRecord::DynamicMatchers::ScopedBy.match(nil, "scoped_by_age_and_sex_and_location")
assert_not_nil match
assert_equal %w(age sex location), match.attribute_names
end
--
cgit v1.2.3
From 4bd9482a1a890c50264b4a9320e6853f1a0bde69 Mon Sep 17 00:00:00 2001
From: Jon Leighton
Date: Thu, 3 May 2012 00:47:50 +0100
Subject: de-globalise method
---
activerecord/lib/active_record/dynamic_matchers.rb | 9 +--------
activerecord/lib/active_record/reflection.rb | 4 ++++
activerecord/lib/active_record/sanitization.rb | 2 +-
3 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/activerecord/lib/active_record/dynamic_matchers.rb b/activerecord/lib/active_record/dynamic_matchers.rb
index f3f143940f..96a3a69d0d 100644
--- a/activerecord/lib/active_record/dynamic_matchers.rb
+++ b/activerecord/lib/active_record/dynamic_matchers.rb
@@ -63,9 +63,7 @@ module ActiveRecord
def expand_attribute_names_for_aggregates
attribute_names.map do |attribute_name|
if aggregation = model.reflect_on_aggregation(attribute_name.to_sym)
- model.send(:aggregate_mapping, aggregation).map do |field_attr, _|
- field_attr.to_sym
- end
+ aggregation.mapping.map { |m| m.first.to_sym }
else
attribute_name.to_sym
end
@@ -240,10 +238,5 @@ module ActiveRecord
"create!"
end
end
-
- def aggregate_mapping(reflection)
- mapping = reflection.options[:mapping] || [reflection.name, reflection.name]
- mapping.first.is_a?(Array) ? mapping : [mapping]
- end
end
end
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index d4f4d593c6..c380b5c029 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -153,6 +153,10 @@ module ActiveRecord
# Holds all the meta-data about an aggregation as it was specified in the
# Active Record class.
class AggregateReflection < MacroReflection #:nodoc:
+ def mapping
+ mapping = options[:mapping] || [name, name]
+ mapping.first.is_a?(Array) ? mapping : [mapping]
+ end
end
# Holds all the meta-data about an association as it was specified in the
diff --git a/activerecord/lib/active_record/sanitization.rb b/activerecord/lib/active_record/sanitization.rb
index 81b13fe529..5530be3219 100644
--- a/activerecord/lib/active_record/sanitization.rb
+++ b/activerecord/lib/active_record/sanitization.rb
@@ -58,7 +58,7 @@ module ActiveRecord
expanded_attrs = {}
attrs.each do |attr, value|
if aggregation = reflect_on_aggregation(attr.to_sym)
- mapping = aggregate_mapping(aggregation)
+ mapping = aggregation.mapping
mapping.each do |field_attr, aggregate_attr|
if mapping.size == 1 && !value.respond_to?(aggregate_attr)
expanded_attrs[field_attr] = value
--
cgit v1.2.3
From 780e8939c0f76399c76b13539f1ffe2d0940d941 Mon Sep 17 00:00:00 2001
From: Jon Leighton
Date: Thu, 3 May 2012 00:49:33 +0100
Subject: #to_sym is unnecessary
---
activerecord/lib/active_record/dynamic_matchers.rb | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/activerecord/lib/active_record/dynamic_matchers.rb b/activerecord/lib/active_record/dynamic_matchers.rb
index 96a3a69d0d..1a057ea25e 100644
--- a/activerecord/lib/active_record/dynamic_matchers.rb
+++ b/activerecord/lib/active_record/dynamic_matchers.rb
@@ -63,15 +63,15 @@ module ActiveRecord
def expand_attribute_names_for_aggregates
attribute_names.map do |attribute_name|
if aggregation = model.reflect_on_aggregation(attribute_name.to_sym)
- aggregation.mapping.map { |m| m.first.to_sym }
+ aggregation.mapping.map(&:first)
else
- attribute_name.to_sym
+ attribute_name
end
end.flatten
end
def valid?
- (expand_attribute_names_for_aggregates - model.column_methods_hash.keys).empty?
+ (expand_attribute_names_for_aggregates - model.column_names).empty?
end
def define
--
cgit v1.2.3
From d1729b917f13810a01ec99b9795a4cce8ee9361d Mon Sep 17 00:00:00 2001
From: Jon Leighton
Date: Thu, 3 May 2012 00:54:16 +0100
Subject: actually don't need to expand the aggregates at all
---
activerecord/lib/active_record/dynamic_matchers.rb | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/activerecord/lib/active_record/dynamic_matchers.rb b/activerecord/lib/active_record/dynamic_matchers.rb
index 1a057ea25e..8726442d0b 100644
--- a/activerecord/lib/active_record/dynamic_matchers.rb
+++ b/activerecord/lib/active_record/dynamic_matchers.rb
@@ -60,18 +60,8 @@ module ActiveRecord
@attribute_names = @name.match(self.class.pattern)[1].split('_and_')
end
- def expand_attribute_names_for_aggregates
- attribute_names.map do |attribute_name|
- if aggregation = model.reflect_on_aggregation(attribute_name.to_sym)
- aggregation.mapping.map(&:first)
- else
- attribute_name
- end
- end.flatten
- end
-
def valid?
- (expand_attribute_names_for_aggregates - model.column_names).empty?
+ attribute_names.all? { |name| model.columns_hash[name] || model.reflect_on_aggregation(name.to_sym) }
end
def define
--
cgit v1.2.3
From 1385388452c6dc86afe0668c41e0f5a491dc193a Mon Sep 17 00:00:00 2001
From: Carlos Antonio da Silva
Date: Thu, 3 May 2012 00:10:27 -0300
Subject: Allow configuring a different queue consumer
Also make sure to not use default queue consumer with custom queue
implementation. It is up to the new queue implementation to
start / shutdown the consumer.
---
railties/lib/rails/application.rb | 2 +-
railties/lib/rails/application/configuration.rb | 8 +++--
railties/lib/rails/application/finisher.rb | 4 +--
railties/test/application/queue_test.rb | 39 +++++++++++++++++++++++--
4 files changed, 44 insertions(+), 9 deletions(-)
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index c7b19c964a..c4edbae55b 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -66,7 +66,7 @@ module Rails
end
end
- attr_accessor :assets, :sandbox
+ attr_accessor :assets, :sandbox, :queue_consumer
alias_method :sandbox?, :sandbox
attr_reader :reloaders
attr_writer :queue
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index 25bb680f69..a2e5dece16 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -8,10 +8,11 @@ module Rails
attr_accessor :allow_concurrency, :asset_host, :asset_path, :assets, :autoflush_log,
:cache_classes, :cache_store, :consider_all_requests_local, :console,
:dependency_loading, :exceptions_app, :file_watcher, :filter_parameters,
- :force_ssl, :helpers_paths, :logger, :log_formatter, :log_tags, :preload_frameworks,
- :railties_order, :relative_url_root, :secret_token,
+ :force_ssl, :helpers_paths, :logger, :log_formatter, :log_tags,
+ :preload_frameworks, :railties_order, :relative_url_root, :secret_token,
:serve_static_assets, :ssl_options, :static_cache_control, :session_options,
- :time_zone, :reload_classes_only_on_change, :use_schema_cache_dump, :queue
+ :time_zone, :reload_classes_only_on_change, :use_schema_cache_dump,
+ :queue, :queue_consumer
attr_writer :log_level
attr_reader :encoding
@@ -44,6 +45,7 @@ module Rails
@log_formatter = ActiveSupport::Logger::SimpleFormatter.new
@use_schema_cache_dump = true
@queue = Rails::Queueing::Queue
+ @queue_consumer = Rails::Queueing::ThreadedConsumer
@assets = ActiveSupport::OrderedOptions.new
@assets.enabled = false
diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb
index 6a24e01f29..84f2601f28 100644
--- a/railties/lib/rails/application/finisher.rb
+++ b/railties/lib/rails/application/finisher.rb
@@ -96,8 +96,8 @@ module Rails
initializer :activate_queue_consumer do |app|
if config.queue == Rails::Queueing::Queue
- consumer = Rails::Queueing::ThreadedConsumer.start(app.queue)
- at_exit { consumer.shutdown }
+ app.queue_consumer = config.queue_consumer.start(app.queue)
+ at_exit { app.queue_consumer.shutdown }
end
end
end
diff --git a/railties/test/application/queue_test.rb b/railties/test/application/queue_test.rb
index 71b0c2bc38..da8bdeed52 100644
--- a/railties/test/application/queue_test.rb
+++ b/railties/test/application/queue_test.rb
@@ -63,7 +63,7 @@ module ApplicationTests
test "in test mode, the queue can be observed" do
app("test")
- job = Class.new(Struct.new(:id)) do
+ job = Struct.new(:id) do
def run
end
end
@@ -79,7 +79,7 @@ module ApplicationTests
assert_equal jobs, Rails.queue.jobs
end
- test "a custom queue implementation can be provided" do
+ def setup_custom_queue
add_to_env_config "production", <<-RUBY
require "my_queue"
config.queue = MyQueue
@@ -94,10 +94,14 @@ module ApplicationTests
RUBY
app("production")
+ end
+
+ test "a custom queue implementation can be provided" do
+ setup_custom_queue
assert_kind_of MyQueue, Rails.queue
- job = Class.new(Struct.new(:id, :ran)) do
+ job = Struct.new(:id, :ran) do
def run
self.ran = true
end
@@ -108,5 +112,34 @@ module ApplicationTests
assert_equal true, job1.ran
end
+
+ test "a custom consumer implementation can be provided" do
+ add_to_env_config "production", <<-RUBY
+ require "my_queue_consumer"
+ config.queue_consumer = MyQueueConsumer
+ RUBY
+
+ app_file "lib/my_queue_consumer.rb", <<-RUBY
+ class MyQueueConsumer < Rails::Queueing::ThreadedConsumer
+ attr_reader :started
+
+ def start
+ @started = true
+ self
+ end
+ end
+ RUBY
+
+ app("production")
+
+ assert_kind_of MyQueueConsumer, Rails.application.queue_consumer
+ assert Rails.application.queue_consumer.started
+ end
+
+ test "default consumer is not used with custom queue implementation" do
+ setup_custom_queue
+
+ assert_nil Rails.application.queue_consumer
+ end
end
end
--
cgit v1.2.3
From 8fbf2e197f0a327ab95bc85b3d3d683e68e09cf3 Mon Sep 17 00:00:00 2001
From: Carlos Antonio da Silva
Date: Thu, 3 May 2012 00:15:50 -0300
Subject: Allow overriding exception handling in threaded consumer
---
railties/lib/rails/queueing.rb | 6 +++++-
railties/test/queueing/threaded_consumer_test.rb | 19 +++++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/railties/lib/rails/queueing.rb b/railties/lib/rails/queueing.rb
index 2e187b8555..896dd91034 100644
--- a/railties/lib/rails/queueing.rb
+++ b/railties/lib/rails/queueing.rb
@@ -53,7 +53,7 @@ module Rails
begin
job.run
rescue Exception => e
- Rails.logger.error "Job Error: #{e.message}\n#{e.backtrace.join("\n")}"
+ handle_exception e
end
end
end
@@ -64,6 +64,10 @@ module Rails
@queue.push nil
@thread.join
end
+
+ def handle_exception(e)
+ Rails.logger.error "Job Error: #{e.message}\n#{e.backtrace.join("\n")}"
+ end
end
end
end
diff --git a/railties/test/queueing/threaded_consumer_test.rb b/railties/test/queueing/threaded_consumer_test.rb
index 559de2a82d..c34a966d6e 100644
--- a/railties/test/queueing/threaded_consumer_test.rb
+++ b/railties/test/queueing/threaded_consumer_test.rb
@@ -78,4 +78,23 @@ class TestThreadConsumer < ActiveSupport::TestCase
assert_equal 1, logger.logged(:error).size
assert_match(/Job Error: RuntimeError: Error!/, logger.logged(:error).last)
end
+
+ test "test overriding exception handling" do
+ @consumer.shutdown
+ @consumer = Class.new(Rails::Queueing::ThreadedConsumer) do
+ attr_reader :last_error
+ def handle_exception(e)
+ @last_error = e.message
+ end
+ end.start(@queue)
+
+ job = Job.new(1) do
+ raise "RuntimeError: Error!"
+ end
+
+ @queue.push job
+ sleep 0.1
+
+ assert_equal "RuntimeError: Error!", @consumer.last_error
+ end
end
--
cgit v1.2.3
From 7a6116b633479effe81a820d84aaf29572cc3412 Mon Sep 17 00:00:00 2001
From: Carlos Antonio da Silva
Date: Thu, 3 May 2012 22:26:30 -0300
Subject: Add some docs and changelog entry
---
guides/source/configuring.textile | 26 +++++++++++++++-----------
railties/CHANGELOG.md | 4 ++++
railties/lib/rails/queueing.rb | 4 ++--
3 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/guides/source/configuring.textile b/guides/source/configuring.textile
index 66e453c3ff..71cc972517 100644
--- a/guides/source/configuring.textile
+++ b/guides/source/configuring.textile
@@ -76,6 +76,17 @@ NOTE. The +config.asset_path+ configuration is ignored if the asset pipeline is
* +config.consider_all_requests_local+ is a flag. If true then any error will cause detailed debugging information to be dumped in the HTTP response, and the +Rails::Info+ controller will show the application runtime context in +/rails/info/properties+. True by default in development and test environments, and false in production mode. For finer-grained control, set this to false and implement +local_request?+ in controllers to specify which requests should provide debugging information on errors.
+* +config.console+ allows you to set class that will be used as console you run +rails console+. It's best to run it in +console+ block:
+
+
+console do
+ # this block is called only when running console,
+ # so we can safely require pry here
+ require "pry"
+ config.console = Pry
+end
+
+
* +config.dependency_loading+ is a flag that allows you to disable constant autoloading setting it to false. It only has effect if +config.cache_classes+ is true, which it is by default in production mode. This flag is set to false by +config.threadsafe!+.
* +config.eager_load_paths+ accepts an array of paths from which Rails will eager load on boot if cache classes is enabled. Defaults to every folder in the +app+ directory of the application.
@@ -100,6 +111,10 @@ NOTE. The +config.asset_path+ configuration is ignored if the asset pipeline is
* +config.preload_frameworks+ enables or disables preloading all frameworks at startup. Enabled by +config.threadsafe!+. Defaults to +nil+, so is disabled.
+* +config.queue+ configures a different queue implementation for the application. Defaults to +Rails::Queueing::Queue+. Note that, if the default queue is changed, the default +queue_consumer+ is not going to be initialized, it is up to the new queue implementation to handle starting and shutting down its own consumer(s).
+
+* +config.queue_consumer+ configures a different consumer implementation for the default queue. Defaults to +Rails::Queueing::ThreadedConsumer+.
+
* +config.reload_classes_only_on_change+ enables or disables reloading of classes only when tracked files change. By default tracks everything on autoload paths and is set to true. If +config.cache_classes+ is true, this option is ignored.
* +config.secret_token+ used for specifying a key which allows sessions for the application to be verified against a known secure key to prevent tampering. Applications get +config.secret_token+ initialized to a random key in +config/initializers/secret_token.rb+.
@@ -122,17 +137,6 @@ WARNING: Threadsafe operation is incompatible with the normal workings of develo
* +config.whiny_nils+ enables or disables warnings when a certain set of methods are invoked on +nil+ and it does not respond to them. Defaults to true in development and test environments.
-* +config.console+ allows you to set class that will be used as console you run +rails console+. It's best to run it in +console+ block:
-
-
-console do
- # this block is called only when running console,
- # so we can safely require pry here
- require "pry"
- config.console = Pry
-end
-
-
h4. Configuring Assets
Rails 3.1, by default, is set up to use the +sprockets+ gem to manage assets within an application. This gem concatenates and compresses assets in order to make serving them much less painful.
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index bc34ced283..b7c042cee3 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ##
+* Add `config.queue_consumer` to allow the default consumer to be configurable. *Carlos Antonio da Silva*
+
+* Add Rails.queue as an interface with a default implementation that consumes jobs in a separate thread. *Yehuda Katz*
+
* Remove Rack::SSL in favour of ActionDispatch::SSL. *Rafael Mendonça França*
* Remove Active Resource from Rails framework. *Prem Sichangrist*
diff --git a/railties/lib/rails/queueing.rb b/railties/lib/rails/queueing.rb
index 896dd91034..b4bc7fcd18 100644
--- a/railties/lib/rails/queueing.rb
+++ b/railties/lib/rails/queueing.rb
@@ -16,13 +16,13 @@ module Rails
# Jobs are run in a separate thread to catch mistakes where code
# assumes that the job is run in the same thread.
class TestQueue < ::Queue
- # Get a list of the jobs off this queue. This method may not be
+ # Get a list of the jobs off this queue. This method may not be
# available on production queues.
def jobs
@que.dup
end
- # Drain the queue, running all jobs in a different thread. This method
+ # Drain the queue, running all jobs in a different thread. This method
# may not be available on production queues.
def drain
# run the jobs in a separate thread so assumptions of synchronous
--
cgit v1.2.3
From 510cf0ad93f07e9285178c8b7ba7d4d68c139fec Mon Sep 17 00:00:00 2001
From: Jon Leighton
Date: Fri, 4 May 2012 14:30:57 +0100
Subject: extract deprecated dynamic methods
---
activerecord/lib/active_record/dynamic_matchers.rb | 178 +++++----------------
activerecord/test/cases/named_scope_test.rb | 4 +-
2 files changed, 40 insertions(+), 142 deletions(-)
diff --git a/activerecord/lib/active_record/dynamic_matchers.rb b/activerecord/lib/active_record/dynamic_matchers.rb
index 8726442d0b..e278e62ce7 100644
--- a/activerecord/lib/active_record/dynamic_matchers.rb
+++ b/activerecord/lib/active_record/dynamic_matchers.rb
@@ -1,5 +1,10 @@
module ActiveRecord
- module DynamicMatchers
+ module DynamicMatchers #:nodoc:
+ # This code in this file seems to have a lot of indirection, but the indirection
+ # is there to provide extension points for the active_record_deprecated_finders
+ # gem. When we stop supporting active_record_deprecated_finders (from Rails 5),
+ # then we can remove the indirection.
+
def respond_to?(name, include_private = false)
match = Method.match(self, name)
match && match.valid? || super
@@ -7,15 +12,6 @@ module ActiveRecord
private
- # Enables dynamic finders like User.find_by_user_name(user_name) and
- # User.scoped_by_user_name(user_name). Refer to Dynamic attribute-based finders
- # section at the top of this file for more detailed information.
- #
- # It's even possible to use all the additional parameters to +find+. For example, the
- # full interface for +find_all_by_amount+ is actually find_all_by_amount(amount, options).
- #
- # Each dynamic finder using scoped_by_* is also defined in the class after it
- # is first invoked, so that future attempts to use it do not run through method_missing.
def method_missing(name, *arguments, &block)
match = Method.match(self, name)
@@ -28,28 +24,27 @@ module ActiveRecord
end
class Method
- def self.match(model, name)
- klass = klasses.find { |k| name =~ k.pattern }
- klass.new(model, name) if klass
- end
+ @matchers = []
- def self.klasses
- [
- FindBy, FindAllBy, FindLastBy, FindByBang, ScopedBy,
- FindOrInitializeBy, FindOrCreateBy, FindOrCreateByBang
- ]
- end
+ class << self
+ attr_reader :matchers
- def self.pattern
- /^#{prefix}_([_a-zA-Z]\w*)#{suffix}$/
- end
+ def match(model, name)
+ klass = matchers.find { |k| name =~ k.pattern }
+ klass.new(model, name) if klass
+ end
- def self.prefix
- raise NotImplementedError
- end
+ def pattern
+ /^#{prefix}_([_a-zA-Z]\w*)#{suffix}$/
+ end
- def self.suffix
- ''
+ def prefix
+ raise NotImplementedError
+ end
+
+ def suffix
+ ''
+ end
end
attr_reader :model, :name, :attribute_names
@@ -77,20 +72,20 @@ module ActiveRecord
end
end
- class Finder < Method
+ module Finder
+ # Extended in active_record_deprecated_finders
def body
- <<-CODE
- result = #{result}
- result && block_given? ? yield(result) : result
- CODE
+ result
end
+ # Extended in active_record_deprecated_finders
def result
- "scoped.apply_finder_options(options).#{finder}(#{attributes_hash})"
+ "#{finder}(#{attributes_hash})"
end
+ # Extended in active_record_deprecated_finders
def signature
- attribute_names.join(', ') + ", options = {}"
+ attribute_names.join(', ')
end
def attributes_hash
@@ -102,7 +97,10 @@ module ActiveRecord
end
end
- class FindBy < Finder
+ class FindBy < Method
+ Method.matchers << self
+ include Finder
+
def self.prefix
"find_by"
end
@@ -112,7 +110,10 @@ module ActiveRecord
end
end
- class FindByBang < Finder
+ class FindByBang < Method
+ Method.matchers << self
+ include Finder
+
def self.prefix
"find_by"
end
@@ -125,108 +126,5 @@ module ActiveRecord
"find_by!"
end
end
-
- class FindAllBy < Finder
- def self.prefix
- "find_all_by"
- end
-
- def finder
- "where"
- end
-
- def result
- "#{super}.to_a"
- end
- end
-
- class FindLastBy < Finder
- def self.prefix
- "find_last_by"
- end
-
- def finder
- "where"
- end
-
- def result
- "#{super}.last"
- end
- end
-
- class ScopedBy < Finder
- def self.prefix
- "scoped_by"
- end
-
- def body
- "where(#{attributes_hash})"
- end
- end
-
- class Instantiator < Method
- # This is nasty, but it doesn't matter because it will be deprecated.
- def self.dispatch(klass, attribute_names, instantiator, args, block)
- if args.length == 1 && args.first.is_a?(Hash)
- attributes = args.first.stringify_keys
- conditions = attributes.slice(*attribute_names)
- rest = [attributes.except(*attribute_names)]
- else
- raise ArgumentError, "too few arguments" unless args.length >= attribute_names.length
-
- conditions = Hash[attribute_names.map.with_index { |n, i| [n, args[i]] }]
- rest = args.drop(attribute_names.length)
- end
-
- klass.where(conditions).first ||
- klass.create_with(conditions).send(instantiator, *rest, &block)
- end
-
- def signature
- "*args, &block"
- end
-
- def body
- "#{self.class}.dispatch(self, #{attribute_names.inspect}, #{instantiator.inspect}, args, block)"
- end
-
- def instantiator
- raise NotImplementedError
- end
- end
-
- class FindOrInitializeBy < Instantiator
- def self.prefix
- "find_or_initialize_by"
- end
-
- def instantiator
- "new"
- end
- end
-
- class FindOrCreateBy < Instantiator
- def self.prefix
- "find_or_create_by"
- end
-
- def instantiator
- "create"
- end
- end
-
- class FindOrCreateByBang < Instantiator
- def self.prefix
- "find_or_create_by"
- end
-
- def self.suffix
- "!"
- end
-
- def instantiator
- "create!"
- end
- end
end
end
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb
index 393e578219..2e87c5be2f 100644
--- a/activerecord/test/cases/named_scope_test.rb
+++ b/activerecord/test/cases/named_scope_test.rb
@@ -442,11 +442,11 @@ end
class DynamicScopeMatchTest < ActiveRecord::TestCase
def test_scoped_by_no_match
- assert_nil ActiveRecord::DynamicMatchers::ScopedBy.match(nil, "not_scoped_at_all")
+ assert_nil ActiveRecord::DynamicMatchers::Method.match(nil, "not_scoped_at_all")
end
def test_scoped_by
- match = ActiveRecord::DynamicMatchers::ScopedBy.match(nil, "scoped_by_age_and_sex_and_location")
+ match = ActiveRecord::DynamicMatchers::Method.match(nil, "scoped_by_age_and_sex_and_location")
assert_not_nil match
assert_equal %w(age sex location), match.attribute_names
end
--
cgit v1.2.3
From 42eda20cce08c5006e71f0098067cc098fc3970c Mon Sep 17 00:00:00 2001
From: Shalva Usubov
Date: Fri, 4 May 2012 17:36:42 +0400
Subject: Update documentation for button_to.
---
actionpack/lib/action_view/helpers/url_helper.rb | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb
index d0f716cc80..08aa626dcc 100644
--- a/actionpack/lib/action_view/helpers/url_helper.rb
+++ b/actionpack/lib/action_view/helpers/url_helper.rb
@@ -303,7 +303,10 @@ module ActionView
#
# <%= button_to "Create", :action => "create", :remote => true, :form => { "data-type" => "json" } %>
# # => ""
#
#
@@ -313,6 +316,7 @@ module ActionView
# #
# #
# #
+ # #
# #
# # "
#
@@ -323,6 +327,7 @@ module ActionView
# #
# #
# #
+ # #
# #
# # "
# #
--
cgit v1.2.3
From 8c3f4bec1fc6b50025f256f5244acbb8e892c9ee Mon Sep 17 00:00:00 2001
From: "Mark J. Titorenko"
Date: Fri, 4 May 2012 15:18:59 +0100
Subject: added beginning_of_hour support to core_ext calculations for Time and
DateTime
---
.../lib/active_support/core_ext/date_time/calculations.rb | 11 +++++++++++
.../lib/active_support/core_ext/time/calculations.rb | 15 +++++++++++++++
activesupport/test/core_ext/date_time_ext_test.rb | 8 ++++++++
activesupport/test/core_ext/time_ext_test.rb | 8 ++++++++
activesupport/test/core_ext/time_with_zone_test.rb | 14 ++++++++++++++
5 files changed, 56 insertions(+)
diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb
index 0e5aa5af10..020fa1a06d 100644
--- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb
@@ -91,6 +91,17 @@ class DateTime
change(:hour => 23, :min => 59, :sec => 59)
end
+ # Returns a new DateTime representing the start of the hour (hh:00:00)
+ def beginning_of_hour
+ change(:min => 0)
+ end
+ alias :at_beginning_of_hour :beginning_of_hour
+
+ # Returns a new DateTime representing the end of the hour (hh:59:59)
+ def end_of_hour
+ change(:min => 59, :sec => 59)
+ end
+
# Adjusts DateTime to UTC by adding its offset value; offset is set to 0
#
# Example:
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb
index 1434e186c3..a0f610d60c 100644
--- a/activesupport/lib/active_support/core_ext/time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -257,6 +257,21 @@ class Time
)
end
+ # Returns a new Time representing the start of the hour (x:00)
+ def beginning_of_hour
+ change(:min => 0)
+ end
+ alias :at_beginning_of_hour :beginning_of_hour
+
+ # Returns a new Time representing the end of the hour, x:59:59.999999 (.999999999 in ruby1.9)
+ def end_of_hour
+ change(
+ :min => 59,
+ :sec => 59,
+ :usec => 999999.999
+ )
+ end
+
# Returns a new Time representing the start of the month (1st of the month, 0:00)
def beginning_of_month
#self - ((self.mday-1).days + self.seconds_since_midnight)
diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb
index cd8cb5d18b..3da0825489 100644
--- a/activesupport/test/core_ext/date_time_ext_test.rb
+++ b/activesupport/test/core_ext/date_time_ext_test.rb
@@ -91,6 +91,14 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal DateTime.civil(2005,2,4,23,59,59), DateTime.civil(2005,2,4,10,10,10).end_of_day
end
+ def test_beginning_of_hour
+ assert_equal DateTime.civil(2005,2,4,19,0,0), DateTime.civil(2005,2,4,19,30,10).beginning_of_hour
+ end
+
+ def test_end_of_hour
+ assert_equal DateTime.civil(2005,2,4,19,59,59), DateTime.civil(2005,2,4,19,30,10).end_of_hour
+ end
+
def test_beginning_of_month
assert_equal DateTime.civil(2005,2,1,0,0,0), DateTime.civil(2005,2,22,10,10,10).beginning_of_month
end
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb
index c542acca68..4c1ed4b1ae 100644
--- a/activesupport/test/core_ext/time_ext_test.rb
+++ b/activesupport/test/core_ext/time_ext_test.rb
@@ -93,6 +93,10 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
end
end
+ def test_beginning_of_hour
+ assert_equal Time.local(2005,2,4,19,0,0), Time.local(2005,2,4,19,30,10).beginning_of_hour
+ end
+
def test_beginning_of_month
assert_equal Time.local(2005,2,1,0,0,0), Time.local(2005,2,22,10,10,10).beginning_of_month
end
@@ -127,6 +131,10 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal Time.local(2007,9,2,23,59,59,999999.999), Time.local(2007,9,02,0,0,0).end_of_week #sunday
end
+ def test_end_of_hour
+ assert_equal Time.local(2005,2,4,19,59,59,999999.999), Time.local(2005,2,4,19,30,10).end_of_hour
+ end
+
def test_end_of_month
assert_equal Time.local(2005,3,31,23,59,59,999999.999), Time.local(2005,3,20,10,10,10).end_of_month
assert_equal Time.local(2005,2,28,23,59,59,999999.999), Time.local(2005,2,20,10,10,10).end_of_month
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb
index 7cf3842a16..ed9150a8f9 100644
--- a/activesupport/test/core_ext/time_with_zone_test.rb
+++ b/activesupport/test/core_ext/time_with_zone_test.rb
@@ -512,6 +512,20 @@ class TimeWithZoneTest < ActiveSupport::TestCase
assert_equal "Fri, 31 Dec 1999 23:59:59 EST -05:00", @twz.end_of_day.inspect
end
+ def test_beginning_of_hour
+ utc = Time.utc(2000, 1, 1, 0, 30)
+ twz = ActiveSupport::TimeWithZone.new(utc, @time_zone)
+ assert_equal "Fri, 31 Dec 1999 19:30:00 EST -05:00", twz.inspect
+ assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", twz.beginning_of_hour.inspect
+ end
+
+ def test_end_of_hour
+ utc = Time.utc(2000, 1, 1, 0, 30)
+ twz = ActiveSupport::TimeWithZone.new(utc, @time_zone)
+ assert_equal "Fri, 31 Dec 1999 19:30:00 EST -05:00", twz.inspect
+ assert_equal "Fri, 31 Dec 1999 19:59:59 EST -05:00", twz.end_of_hour.inspect
+ end
+
def test_since
assert_equal "Fri, 31 Dec 1999 19:00:01 EST -05:00", @twz.since(1).inspect
end
--
cgit v1.2.3
From 6223d72b52b0d0bf0d8e0820673f4bf15b3321f6 Mon Sep 17 00:00:00 2001
From: "Mark J. Titorenko"
Date: Fri, 4 May 2012 16:11:32 +0100
Subject: enable tests for beginning_of_* and end_of_* within time zone tests;
enable test for future_with_time_current_as_time_with_zone; fix
beginning_of_month test.
---
activesupport/test/core_ext/time_with_zone_test.rb | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb
index 7cf3842a16..331010091e 100644
--- a/activesupport/test/core_ext/time_with_zone_test.rb
+++ b/activesupport/test/core_ext/time_with_zone_test.rb
@@ -191,7 +191,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase
end
end
- def future_with_time_current_as_time_with_zone
+ def test_future_with_time_current_as_time_with_zone
twz = ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,45) )
Time.stubs(:current).returns(twz)
assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,44)).future?
@@ -482,32 +482,32 @@ class TimeWithZoneTest < ActiveSupport::TestCase
assert_equal "Fri, 31 Dec 1999 19:00:30 EST -05:00", @twz.advance(:seconds => 30).inspect
end
- def beginning_of_year
+ def test_beginning_of_year
assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect
assert_equal "Fri, 01 Jan 1999 00:00:00 EST -05:00", @twz.beginning_of_year.inspect
end
- def end_of_year
+ def test_end_of_year
assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect
assert_equal "Fri, 31 Dec 1999 23:59:59 EST -05:00", @twz.end_of_year.inspect
end
- def beginning_of_month
+ def test_beginning_of_month
assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect
- assert_equal "Fri, 01 Dec 1999 00:00:00 EST -05:00", @twz.beginning_of_month.inspect
+ assert_equal "Wed, 01 Dec 1999 00:00:00 EST -05:00", @twz.beginning_of_month.inspect
end
- def end_of_month
+ def test_end_of_month
assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect
assert_equal "Fri, 31 Dec 1999 23:59:59 EST -05:00", @twz.end_of_month.inspect
end
- def beginning_of_day
+ def test_beginning_of_day
assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect
assert_equal "Fri, 31 Dec 1999 00:00:00 EST -05:00", @twz.beginning_of_day.inspect
end
- def end_of_day
+ def test_end_of_day
assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect
assert_equal "Fri, 31 Dec 1999 23:59:59 EST -05:00", @twz.end_of_day.inspect
end
--
cgit v1.2.3
From 544a10e428cda02e7baa38586ef266daaef20d89 Mon Sep 17 00:00:00 2001
From: Mike Manewitz
Date: Fri, 4 May 2012 10:24:56 -0500
Subject: Editing log levels to reflect this doc:
http://api.rubyonrails.org/classes/ActiveSupport/BufferedLogger/Severity.html
---
guides/source/debugging_rails_applications.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/guides/source/debugging_rails_applications.textile b/guides/source/debugging_rails_applications.textile
index 903ed59e7b..45fa4ada78 100644
--- a/guides/source/debugging_rails_applications.textile
+++ b/guides/source/debugging_rails_applications.textile
@@ -124,7 +124,7 @@ h4. Log Levels
When something is logged it's printed into the corresponding log if the log level of the message is equal or higher than the configured log level. If you want to know the current log level you can call the +Rails.logger.level+ method.
-The available log levels are: +:debug+, +:info+, +:warn+, +:error+, and +:fatal+, corresponding to the log level numbers from 0 up to 4 respectively. To change the default log level, use
+The available log levels are: +:debug+, +:info+, +:warn+, +:error+, +:fatal+, and +:unknown+, corresponding to the log level numbers from 0 up to 5 respectively. To change the default log level, use
config.log_level = :warn # In any environment initializer, or
--
cgit v1.2.3
From 7f536f9158588b66c0e5a6aa8772b919812f9cb9 Mon Sep 17 00:00:00 2001
From: Kristian Freeman
Date: Fri, 4 May 2012 09:56:07 -0700
Subject: Play nice with some lint patterns
---
guides/assets/stylesheets/main.css | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/guides/assets/stylesheets/main.css b/guides/assets/stylesheets/main.css
index 42b85fefa3..60859a6930 100644
--- a/guides/assets/stylesheets/main.css
+++ b/guides/assets/stylesheets/main.css
@@ -196,11 +196,12 @@ a, a:link, a:visited {
width: 27em;
display: block;
background: #980905;
- border-radius: 1em;
-webkit-border-radius: 1em;
-moz-border-radius: 1em;
+ border-radius: 1em;
-webkit-box-shadow: 0.25em 0.25em 1em rgba(0,0,0,0.25);
-moz-box-shadow: rgba(0,0,0,0.25) 0.25em 0.25em 1em;
+ box-shadow: 0.25em 0.25em 1em rgba(0,0,0,0.25);
color: #f1938c;
padding: 1.5em 2em;
position: absolute;
@@ -447,8 +448,8 @@ div.important p, div.caution p, div.warning p, div.note p, div.info p {
#edge-badge {
position: fixed;
- right: 0px;
- top: 0px;
+ right: 0;
+ top: 0;
z-index: 100;
border: none;
}
--
cgit v1.2.3
From c8e057198796f1052f2e3e185f0c777292e75394 Mon Sep 17 00:00:00 2001
From: Ernesto Tagwerker
Date: Fri, 4 May 2012 14:35:16 -0300
Subject: Added reference to I18n.localize, as discussed here:
https://github.com/rails/rails/issues/4027
---
actionpack/lib/action_view/helpers/translation_helper.rb | 3 +++
1 file changed, 3 insertions(+)
diff --git a/actionpack/lib/action_view/helpers/translation_helper.rb b/actionpack/lib/action_view/helpers/translation_helper.rb
index fd06bfa2a8..8171bea8ed 100644
--- a/actionpack/lib/action_view/helpers/translation_helper.rb
+++ b/actionpack/lib/action_view/helpers/translation_helper.rb
@@ -63,6 +63,9 @@ module ActionView
alias :t :translate
# Delegates to I18n.localize with no additional functionality.
+ #
+ # See http://rubydoc.info/github/svenfuchs/i18n/master/I18n/Backend/Base:localize
+ # for more information.
def localize(*args)
I18n.localize(*args)
end
--
cgit v1.2.3
From 04202a3f8d66c0675eac41fbf63309f4be356e81 Mon Sep 17 00:00:00 2001
From: Marc-Andre Lafortune
Date: Fri, 4 May 2012 13:48:02 -0400
Subject: Adjust error message for partial names starting with an uppercase
letter.
---
actionpack/lib/action_view/renderer/partial_renderer.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb
index c5d5540510..87609fd5ff 100644
--- a/actionpack/lib/action_view/renderer/partial_renderer.rb
+++ b/actionpack/lib/action_view/renderer/partial_renderer.rb
@@ -343,8 +343,8 @@ module ActionView
if String === partial && @variable.to_s !~ /^[a-z_][a-zA-Z_0-9]*$/
raise ArgumentError.new("The partial name (#{partial}) is not a valid Ruby identifier; " +
- "make sure your partial name starts with a letter or underscore, " +
- "and is followed by any combinations of letters, numbers, or underscores.")
+ "make sure your partial name starts with a lowercase letter or underscore, " +
+ "and is followed by any combination of letters, numbers and underscores.")
end
self
--
cgit v1.2.3
From 638d0020a2ad92993cb9c7385ad7584618c7af1c Mon Sep 17 00:00:00 2001
From: Aaron Patterson
Date: Fri, 4 May 2012 10:57:55 -0700
Subject: create a request::session object in the memecache store middleware
---
.../lib/action_dispatch/middleware/session/mem_cache_store.rb | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb b/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb
index 4dd9a946c2..c51cbddfb5 100644
--- a/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb
@@ -12,6 +12,16 @@ module ActionDispatch
options[:expire_after] ||= options[:expires]
super
end
+
+ private
+
+ def prepare_session(env)
+ Request::Session.create(self, env, @default_options)
+ end
+
+ def loaded_session?(session)
+ !session.is_a?(Request::Session) || session.loaded?
+ end
end
end
end
--
cgit v1.2.3
From e2218b7ee5df4580df8d502cbe4ef47b4f1c4a8c Mon Sep 17 00:00:00 2001
From: Aaron Patterson
Date: Fri, 4 May 2012 11:03:37 -0700
Subject: create a request session in the cookie stores
---
actionpack/lib/action_dispatch/middleware/session/cookie_store.rb | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
index a4866f5a8f..8d673dd95e 100644
--- a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
@@ -46,6 +46,14 @@ module ActionDispatch
private
+ def prepare_session(env)
+ Request::Session.create(self, env, @default_options)
+ end
+
+ def loaded_session?(session)
+ !session.is_a?(Request::Session) || session.loaded?
+ end
+
def unpacked_cookie_data(env)
env["action_dispatch.request.unsigned_session_cookie"] ||= begin
stale_session_check! do
--
cgit v1.2.3
From 319db7b189fe1f02268c99c9e9566312535c02ec Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Fri, 4 May 2012 23:45:27 +0530
Subject: update invalid partial error message as per
04202a3f8d66c0675eac41fbf63309f4be356e81
---
actionpack/test/template/render_test.rb | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index cdaca56ef2..e7f5f100bf 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -153,15 +153,15 @@ module RenderTestCases
def test_render_partial_with_invalid_name
e = assert_raises(ArgumentError) { @view.render(:partial => "test/200") }
assert_equal "The partial name (test/200) is not a valid Ruby identifier; " +
- "make sure your partial name starts with a letter or underscore, " +
- "and is followed by any combinations of letters, numbers, or underscores.", e.message
+ "make sure your partial name starts with a lowercase letter or underscore, " +
+ "and is followed by any combination of letters, numbers and underscores.", e.message
end
def test_render_partial_with_missing_filename
e = assert_raises(ArgumentError) { @view.render(:partial => "test/") }
assert_equal "The partial name (test/) is not a valid Ruby identifier; " +
- "make sure your partial name starts with a letter or underscore, " +
- "and is followed by any combinations of letters, numbers, or underscores.", e.message
+ "make sure your partial name starts with a lowercase letter or underscore, " +
+ "and is followed by any combination of letters, numbers and underscores.", e.message
end
def test_render_partial_with_incompatible_object
--
cgit v1.2.3
From d03aa104e069be4e301efa8cefb90a2a785a7bff Mon Sep 17 00:00:00 2001
From: Carlos Antonio da Silva
Date: Thu, 3 May 2012 23:26:54 -0300
Subject: Force given path to http methods in mapper to skip canonical action
checking
This fixes the following scenario:
resources :contacts do
post 'new', action: 'new', on: :collection, as: :new
end
Where the /new path is not generated because it's considered a canonical
action, part of the normal resource actions:
new_contacts POST /contacts(.:format) contacts#new
Fixes #2999
---
actionpack/lib/action_dispatch/routing/mapper.rb | 5 +++--
actionpack/test/controller/routing_test.rb | 4 ++--
actionpack/test/dispatch/routing_test.rb | 9 ++++++++-
3 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 4ea3937057..2a7d540517 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -535,7 +535,8 @@ module ActionDispatch
private
def map_method(method, args, &block)
options = args.extract_options!
- options[:via] = method
+ options[:via] = method
+ options[:path] ||= args.first if args.first.is_a?(String)
match(*args, options, &block)
self
end
@@ -1509,7 +1510,7 @@ module ActionDispatch
prefix = shallow_scoping? ?
"#{@scope[:shallow_path]}/#{parent_resource.path}/:id" : @scope[:path]
- path = if canonical_action?(action, path.blank?)
+ if canonical_action?(action, path.blank?)
prefix.to_s
else
"#{prefix}/#{action_path(action, path)}"
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index bcb4e6a766..cd91064ab8 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -1405,7 +1405,7 @@ class RouteSetTest < ActiveSupport::TestCase
end
end
end
-
+
def test_route_with_subdomain_and_constraints_must_receive_params
name_param = nil
set.draw do
@@ -1418,7 +1418,7 @@ class RouteSetTest < ActiveSupport::TestCase
set.recognize_path('http://subdomain.example.org/page/mypage'))
assert_equal(name_param, 'mypage')
end
-
+
def test_route_requirement_recognize_with_ignore_case
set.draw do
get 'page/:name' => 'pages#show',
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index a96d2edcf9..c8e1b34b99 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -171,6 +171,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
post :preview, :on => :collection
end
end
+
+ post 'new', :action => 'new', :on => :collection, :as => :new
end
resources :replies do
@@ -876,6 +878,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
assert_equal '/projects/1/edit', edit_project_path(:id => '1')
end
+ def test_projects_with_post_action_and_new_path_on_collection
+ post '/projects/new'
+ assert_equal "project#new", @response.body
+ assert_equal "/projects/new", new_projects_path
+ end
+
def test_projects_involvements
get '/projects/1/involvements'
assert_equal 'involvements#index', @response.body
@@ -2450,7 +2458,6 @@ class TestMultipleNestedController < ActionDispatch::IntegrationTest
get "/foo/bar/baz"
assert_equal "/pooh", @response.body
end
-
end
class TestTildeAndMinusPaths < ActionDispatch::IntegrationTest
--
cgit v1.2.3
From 26e7678ab374a730196ae889e31bce2ea0cb0735 Mon Sep 17 00:00:00 2001
From: Aaron Patterson
Date: Fri, 4 May 2012 11:26:03 -0700
Subject: session creation methods to a module
---
.../action_dispatch/middleware/session/abstract_store.rb | 15 +++++++++------
.../action_dispatch/middleware/session/cookie_store.rb | 9 +--------
.../action_dispatch/middleware/session/mem_cache_store.rb | 11 +----------
3 files changed, 11 insertions(+), 24 deletions(-)
diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
index d902adaff1..64159fa8e7 100644
--- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
@@ -65,12 +65,7 @@ module ActionDispatch
end
end
- class AbstractStore < Rack::Session::Abstract::ID
- include Compatibility
- include StaleSessionCheck
-
- private
-
+ module SessionObject # :nodoc:
def prepare_session(env)
Request::Session.create(self, env, @default_options)
end
@@ -78,6 +73,14 @@ module ActionDispatch
def loaded_session?(session)
!session.is_a?(Request::Session) || session.loaded?
end
+ end
+
+ class AbstractStore < Rack::Session::Abstract::ID
+ include Compatibility
+ include StaleSessionCheck
+ include SessionObject
+
+ private
def set_cookie(env, session_id, cookie)
request = ActionDispatch::Request.new(env)
diff --git a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
index 8d673dd95e..dbcf703ec3 100644
--- a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
@@ -43,17 +43,10 @@ module ActionDispatch
class CookieStore < Rack::Session::Cookie
include Compatibility
include StaleSessionCheck
+ include SessionObject
private
- def prepare_session(env)
- Request::Session.create(self, env, @default_options)
- end
-
- def loaded_session?(session)
- !session.is_a?(Request::Session) || session.loaded?
- end
-
def unpacked_cookie_data(env)
env["action_dispatch.request.unsigned_session_cookie"] ||= begin
stale_session_check! do
diff --git a/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb b/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb
index c51cbddfb5..38a737cd2b 100644
--- a/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb
@@ -6,22 +6,13 @@ module ActionDispatch
class MemCacheStore < Rack::Session::Memcache
include Compatibility
include StaleSessionCheck
+ include SessionObject
def initialize(app, options = {})
require 'memcache'
options[:expire_after] ||= options[:expires]
super
end
-
- private
-
- def prepare_session(env)
- Request::Session.create(self, env, @default_options)
- end
-
- def loaded_session?(session)
- !session.is_a?(Request::Session) || session.loaded?
- end
end
end
end
--
cgit v1.2.3
From 3f46e7aae9f56a8fa1f4dd800d8947d780cd5534 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Fri, 4 May 2012 23:58:15 +0530
Subject: fix doc [ci skip]
---
actionpack/lib/action_view/helpers/url_helper.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb
index 08aa626dcc..1145f348c2 100644
--- a/actionpack/lib/action_view/helpers/url_helper.rb
+++ b/actionpack/lib/action_view/helpers/url_helper.rb
@@ -315,7 +315,7 @@ module ActionView
# # => ""
--
cgit v1.2.3
From df36c5f7ffd2657e11eea4e407401c9ff2aa0533 Mon Sep 17 00:00:00 2001
From: Alexey Vakhov
Date: Wed, 11 Apr 2012 11:28:19 +0600
Subject: Fix assert_template assertion with :layout option
---
actionpack/lib/action_controller/test_case.rb | 2 +-
actionpack/test/controller/action_pack_assertions_test.rb | 10 ++++++++++
.../test/fixtures/test/hello_world_with_partial.html.erb | 2 ++
3 files changed, 13 insertions(+), 1 deletion(-)
create mode 100644 actionpack/test/fixtures/test/hello_world_with_partial.html.erb
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb
index 21997c4d79..aee54bf515 100644
--- a/actionpack/lib/action_controller/test_case.rb
+++ b/actionpack/lib/action_controller/test_case.rb
@@ -120,7 +120,7 @@ module ActionController
options[:partial], @partials.keys)
assert_includes @partials, expected_partial, msg
end
- else
+ elsif options.key?(:partial)
assert @partials.empty?,
"Expected no partials to be rendered"
end
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb
index f5f397c9c0..01151b336b 100644
--- a/actionpack/test/controller/action_pack_assertions_test.rb
+++ b/actionpack/test/controller/action_pack_assertions_test.rb
@@ -76,6 +76,11 @@ class ActionPackAssertionsController < ActionController::Base
render "test/hello_world", :layout => "layouts/standard"
end
+ def render_with_layout_and_partial
+ @variable_for_layout = nil
+ render "test/hello_world_with_partial", :layout => "layouts/standard"
+ end
+
def session_stuffing
session['xmas'] = 'turkey'
render :text => "ho ho ho"
@@ -478,6 +483,11 @@ class AssertTemplateTest < ActionController::TestCase
assert_template :layout => "layouts/standard"
end
+ def test_passes_with_layout_and_partial
+ get :render_with_layout_and_partial
+ assert_template :layout => "layouts/standard"
+ end
+
def test_assert_template_reset_between_requests
get :hello_world
assert_template 'test/hello_world'
diff --git a/actionpack/test/fixtures/test/hello_world_with_partial.html.erb b/actionpack/test/fixtures/test/hello_world_with_partial.html.erb
new file mode 100644
index 0000000000..ec31545356
--- /dev/null
+++ b/actionpack/test/fixtures/test/hello_world_with_partial.html.erb
@@ -0,0 +1,2 @@
+Hello world!
+<%= render '/test/partial' %>
--
cgit v1.2.3
From 4bd05a7bdc5003c9ebb090dcb0dc4949e4fb8ad3 Mon Sep 17 00:00:00 2001
From: Alexey Vakhov
Date: Wed, 11 Apr 2012 11:55:51 +0600
Subject: Fix assert_template :layout => nil assertion
---
actionpack/lib/action_controller/test_case.rb | 7 +++++--
actionpack/test/controller/action_pack_assertions_test.rb | 12 ++++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb
index aee54bf515..f664da4ffe 100644
--- a/actionpack/lib/action_controller/test_case.rb
+++ b/actionpack/lib/action_controller/test_case.rb
@@ -20,7 +20,9 @@ module ActionController
ActiveSupport::Notifications.subscribe("render_template.action_view") do |name, start, finish, id, payload|
path = payload[:layout]
- @layouts[path] += 1
+ if path
+ @layouts[path] += 1
+ end
end
ActiveSupport::Notifications.subscribe("!render_template.action_view") do |name, start, finish, id, payload|
@@ -90,7 +92,8 @@ module ActionController
end
end
when Hash
- if expected_layout = options[:layout]
+ if options.key?(:layout)
+ expected_layout = options[:layout]
msg = message || sprintf("expecting layout <%s> but action rendered <%s>",
expected_layout, @layouts.keys)
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb
index 01151b336b..bc6630a02d 100644
--- a/actionpack/test/controller/action_pack_assertions_test.rb
+++ b/actionpack/test/controller/action_pack_assertions_test.rb
@@ -478,6 +478,13 @@ class AssertTemplateTest < ActionController::TestCase
end
end
+ def test_fails_expecting_no_layout
+ get :render_with_layout
+ assert_raise(ActiveSupport::TestCase::Assertion) do
+ assert_template :layout => nil
+ end
+ end
+
def test_passes_with_correct_layout
get :render_with_layout
assert_template :layout => "layouts/standard"
@@ -488,6 +495,11 @@ class AssertTemplateTest < ActionController::TestCase
assert_template :layout => "layouts/standard"
end
+ def test_passed_with_no_layout
+ get :hello_world
+ assert_template :layout => nil
+ end
+
def test_assert_template_reset_between_requests
get :hello_world
assert_template 'test/hello_world'
--
cgit v1.2.3
From 0d19a081ee12b46791d8709e5c0898429e2ef91f Mon Sep 17 00:00:00 2001
From: Alexey Vakhov
Date: Wed, 11 Apr 2012 12:45:28 +0600
Subject: Improve assert_template layout checking
---
actionpack/lib/action_controller/test_case.rb | 18 +++++++++++++++---
.../test/controller/action_pack_assertions_test.rb | 15 +++++++++++++++
2 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb
index f664da4ffe..ad02375f12 100644
--- a/actionpack/lib/action_controller/test_case.rb
+++ b/actionpack/lib/action_controller/test_case.rb
@@ -22,6 +22,9 @@ module ActionController
path = payload[:layout]
if path
@layouts[path] += 1
+ if path =~ /^layouts\/(.*)/
+ @layouts[$1] += 1
+ end
end
end
@@ -61,6 +64,15 @@ module ActionController
# # assert that the exact template "admin/posts/new" was rendered
# assert_template %r{\Aadmin/posts/new\Z}
#
+ # # assert that the layout 'admin' was rendered
+ # assert_template :layout => 'admin'
+ # assert_template :layout => 'layouts/admin'
+ # assert_template :layout => :admin
+ #
+ # # assert that no layout was rendered
+ # assert_template :layout => nil
+ # assert_template :layout => false
+ #
# # assert that the "_customer" partial was rendered twice
# assert_template :partial => '_customer', :count => 2
#
@@ -98,11 +110,11 @@ module ActionController
expected_layout, @layouts.keys)
case expected_layout
- when String
- assert_includes @layouts.keys, expected_layout, msg
+ when String, Symbol
+ assert_includes @layouts.keys, expected_layout.to_s, msg
when Regexp
assert(@layouts.keys.any? {|l| l =~ expected_layout }, msg)
- when nil
+ when nil, false
assert(@layouts.empty?, msg)
end
end
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb
index bc6630a02d..9b0d4d0f4c 100644
--- a/actionpack/test/controller/action_pack_assertions_test.rb
+++ b/actionpack/test/controller/action_pack_assertions_test.rb
@@ -500,6 +500,21 @@ class AssertTemplateTest < ActionController::TestCase
assert_template :layout => nil
end
+ def test_passed_with_no_layout_false
+ get :hello_world
+ assert_template :layout => false
+ end
+
+ def test_passes_with_correct_layout_without_layouts_prefix
+ get :render_with_layout
+ assert_template :layout => "standard"
+ end
+
+ def test_passes_with_correct_layout_symbol
+ get :render_with_layout
+ assert_template :layout => :standard
+ end
+
def test_assert_template_reset_between_requests
get :hello_world
assert_template 'test/hello_world'
--
cgit v1.2.3
From 7a093606f662cda2de597d81dde974ecbe375701 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Fri, 4 May 2012 12:44:34 -0700
Subject: Merge pull request #4445 from nragaz/role_based_params_wrapping
specify a role for identifying accessible attributes when wrapping params
---
.../lib/action_controller/metal/params_wrapper.rb | 5 +++--
actionpack/test/controller/params_wrapper_test.rb | 17 +++++++++++++++--
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb
index 7e2316d01c..fc8a8c9dcd 100644
--- a/actionpack/lib/action_controller/metal/params_wrapper.rb
+++ b/actionpack/lib/action_controller/metal/params_wrapper.rb
@@ -166,8 +166,9 @@ module ActionController
unless options[:include] || options[:exclude]
model ||= _default_wrap_model
- if model.respond_to?(:accessible_attributes) && model.accessible_attributes.present?
- options[:include] = model.accessible_attributes.to_a
+ role = options.has_key?(:as) ? options[:as] : :default
+ if model.respond_to?(:accessible_attributes) && model.accessible_attributes(role).present?
+ options[:include] = model.accessible_attributes(role).to_a
elsif model.respond_to?(:attribute_names) && model.attribute_names.present?
options[:include] = model.attribute_names
end
diff --git a/actionpack/test/controller/params_wrapper_test.rb b/actionpack/test/controller/params_wrapper_test.rb
index c4d2614200..fa1608b9df 100644
--- a/actionpack/test/controller/params_wrapper_test.rb
+++ b/actionpack/test/controller/params_wrapper_test.rb
@@ -174,7 +174,7 @@ class ParamsWrapperTest < ActionController::TestCase
def test_accessible_wrapped_keys_from_matching_model
User.expects(:respond_to?).with(:accessible_attributes).returns(true)
- User.expects(:accessible_attributes).twice.returns(["username"])
+ User.expects(:accessible_attributes).with(:default).twice.returns(["username"])
with_default_wrapper_options do
@request.env['CONTENT_TYPE'] = 'application/json'
@@ -186,7 +186,7 @@ class ParamsWrapperTest < ActionController::TestCase
def test_accessible_wrapped_keys_from_specified_model
with_default_wrapper_options do
Person.expects(:respond_to?).with(:accessible_attributes).returns(true)
- Person.expects(:accessible_attributes).twice.returns(["username"])
+ Person.expects(:accessible_attributes).with(:default).twice.returns(["username"])
UsersController.wrap_parameters Person
@@ -195,6 +195,19 @@ class ParamsWrapperTest < ActionController::TestCase
assert_parameters({ 'username' => 'sikachu', 'title' => 'Developer', 'person' => { 'username' => 'sikachu' }})
end
end
+
+ def test_accessible_wrapped_keys_with_role_from_specified_model
+ with_default_wrapper_options do
+ Person.expects(:respond_to?).with(:accessible_attributes).returns(true)
+ Person.expects(:accessible_attributes).with(:admin).twice.returns(["username"])
+
+ UsersController.wrap_parameters Person, :as => :admin
+
+ @request.env['CONTENT_TYPE'] = 'application/json'
+ post :parse, { 'username' => 'sikachu', 'title' => 'Developer' }
+ assert_parameters({ 'username' => 'sikachu', 'title' => 'Developer', 'person' => { 'username' => 'sikachu' }})
+ end
+ end
def test_not_wrapping_abstract_model
User.expects(:respond_to?).with(:accessible_attributes).returns(false)
--
cgit v1.2.3
From 81f92cbc2b4c1f99c08d04a8a360efe64a12faf8 Mon Sep 17 00:00:00 2001
From: Carlos Antonio da Silva
Date: Fri, 4 May 2012 16:51:17 -0300
Subject: Use Hash#fetch instead of has_key? check
---
actionpack/lib/action_controller/metal/params_wrapper.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb
index fc8a8c9dcd..1f52c164de 100644
--- a/actionpack/lib/action_controller/metal/params_wrapper.rb
+++ b/actionpack/lib/action_controller/metal/params_wrapper.rb
@@ -166,7 +166,7 @@ module ActionController
unless options[:include] || options[:exclude]
model ||= _default_wrap_model
- role = options.has_key?(:as) ? options[:as] : :default
+ role = options.fetch(:as, :default)
if model.respond_to?(:accessible_attributes) && model.accessible_attributes(role).present?
options[:include] = model.accessible_attributes(role).to_a
elsif model.respond_to?(:attribute_names) && model.attribute_names.present?
--
cgit v1.2.3
From d4838fdcb2b311a01329d9994752894e3d308719 Mon Sep 17 00:00:00 2001
From: Aaron Patterson
Date: Fri, 4 May 2012 14:17:03 -0700
Subject: make sure the superclass matches so load order does not matter
---
actionpack/lib/action_dispatch/middleware/cookies.rb | 2 +-
actionpack/lib/action_dispatch/middleware/flash.rb | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb
index 2c0c31de9d..de9c55d96c 100644
--- a/actionpack/lib/action_dispatch/middleware/cookies.rb
+++ b/actionpack/lib/action_dispatch/middleware/cookies.rb
@@ -2,7 +2,7 @@ require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/hash/keys'
module ActionDispatch
- class Request
+ class Request < Rack::Request
def cookie_jar
env['action_dispatch.cookies'] ||= Cookies::CookieJar.build(self)
end
diff --git a/actionpack/lib/action_dispatch/middleware/flash.rb b/actionpack/lib/action_dispatch/middleware/flash.rb
index bc68615be7..17776c2356 100644
--- a/actionpack/lib/action_dispatch/middleware/flash.rb
+++ b/actionpack/lib/action_dispatch/middleware/flash.rb
@@ -1,5 +1,5 @@
module ActionDispatch
- class Request
+ class Request < Rack::Request
# Access the contents of the flash. Use flash["notice"] to
# read a notice you put there or flash["notice"] = "hello"
# to put a new one.
--
cgit v1.2.3
From d5cc7113076ccd82b6e7582ce77fd2062323c87d Mon Sep 17 00:00:00 2001
From: Aaron Patterson
Date: Fri, 4 May 2012 15:55:36 -0700
Subject: need to dup the default options so that mutations will not impact us
---
actionpack/lib/action_dispatch/request/session.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/actionpack/lib/action_dispatch/request/session.rb b/actionpack/lib/action_dispatch/request/session.rb
index 338165935b..4ad7071820 100644
--- a/actionpack/lib/action_dispatch/request/session.rb
+++ b/actionpack/lib/action_dispatch/request/session.rb
@@ -37,7 +37,7 @@ module ActionDispatch
def initialize(by, env, default_options)
@by = by
@env = env
- @delegate = default_options
+ @delegate = default_options.dup
end
def [](key)
--
cgit v1.2.3
From 2ec6ef5ddae7667e7bb37c0aa905848a9027da82 Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Fri, 4 May 2012 21:39:41 -0700
Subject: Change unless + ! into if
---
activerecord/lib/active_record/fixtures.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index 9796b0a321..a01e2f74ff 100644
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -823,7 +823,7 @@ module ActiveRecord
end
def setup_fixtures
- return unless !ActiveRecord::Base.configurations.blank?
+ return if ActiveRecord::Base.configurations.blank?
if pre_loaded_fixtures && !use_transactional_fixtures
raise RuntimeError, 'pre_loaded_fixtures requires use_transactional_fixtures'
--
cgit v1.2.3
From c5176023a0585278c533610daf1eaf6ba7d19cd8 Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Fri, 4 May 2012 00:54:04 -0700
Subject: Duplicate column_defaults properly (closes #6115)
---
activerecord/lib/active_record/core.rb | 5 ++++-
activerecord/test/cases/base_test.rb | 8 +++++++-
activerecord/test/schema/schema.rb | 1 +
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index eb8f4ad669..9a76c9f617 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -1,5 +1,6 @@
require 'active_support/concern'
require 'active_support/core_ext/hash/indifferent_access'
+require 'active_support/core_ext/object/duplicable'
require 'thread'
module ActiveRecord
@@ -165,7 +166,9 @@ module ActiveRecord
# # Instantiates a single new object bypassing mass-assignment security
# User.new({ :first_name => 'Jamie', :is_admin => true }, :without_protection => true)
def initialize(attributes = nil, options = {})
- @attributes = self.class.initialize_attributes(self.class.column_defaults.dup)
+ # TODO: use deep_dup after fixing it to also dup values
+ defaults = Hash[self.class.column_defaults.map { |k, v| [k, v.duplicable? ? v.dup : v] }]
+ @attributes = self.class.initialize_attributes(defaults)
@columns_hash = self.class.column_types.dup
init_internals
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index 35e0045e4c..c1b0cb8886 100644
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -1909,7 +1909,7 @@ class BasicsTest < ActiveRecord::TestCase
end
def test_attribute_names
- assert_equal ["id", "type", "ruby_type", "firm_id", "firm_name", "name", "client_of", "rating", "account_id"],
+ assert_equal ["id", "type", "ruby_type", "firm_id", "firm_name", "name", "client_of", "rating", "account_id", "description"],
Company.attribute_names
end
@@ -2001,6 +2001,12 @@ class BasicsTest < ActiveRecord::TestCase
assert_nil hash['firm_name']
end
+ def test_default_values_are_deeply_dupped
+ company = Company.new
+ company.description << "foo"
+ assert_equal "", Company.new.description
+ end
+
["find_by", "find_by!"].each do |meth|
test "#{meth} delegates to scoped" do
record = stub
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb
index 377fde5c96..7082d5dc86 100644
--- a/activerecord/test/schema/schema.rb
+++ b/activerecord/test/schema/schema.rb
@@ -173,6 +173,7 @@ ActiveRecord::Schema.define do
t.integer :client_of
t.integer :rating, :default => 1
t.integer :account_id
+ t.string :description, :null => false, :default => ""
end
add_index :companies, [:firm_id, :type, :rating, :ruby_type], :name => "company_index"
--
cgit v1.2.3
From 2ce5e4fa6c6f44eb0c5cbf812ca62aa03b802379 Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Fri, 4 May 2012 23:11:09 -0700
Subject: Give more detailed instructions in script/rails in engine
closes #4894
---
railties/lib/rails/engine/commands.rb | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/railties/lib/rails/engine/commands.rb b/railties/lib/rails/engine/commands.rb
index b71119af77..ffbc0b4bd6 100644
--- a/railties/lib/rails/engine/commands.rb
+++ b/railties/lib/rails/engine/commands.rb
@@ -34,6 +34,10 @@ The common rails commands available for engines are:
destroy Undo code generated with "generate" (short-cut alias: "d")
All commands can be run with -h for more information.
+
+If you want to run any commands that need to be run in context
+of the application, like `rails server` or `rails console`,
+you should do it from application's directory (typically test/dummy).
EOT
exit(1)
end
--
cgit v1.2.3
From 3ea70f985b1799c27b907724920e5615018e505d Mon Sep 17 00:00:00 2001
From: Marc-Andre Lafortune
Date: Sat, 5 May 2012 02:24:57 -0400
Subject: Use respond_to_missing? for OrderedOptions
---
activesupport/lib/active_support/ordered_options.rb | 2 +-
activesupport/test/ordered_options_test.rb | 8 ++++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb
index 538e41e0eb..60e6cd55ad 100644
--- a/activesupport/lib/active_support/ordered_options.rb
+++ b/activesupport/lib/active_support/ordered_options.rb
@@ -36,7 +36,7 @@ module ActiveSupport #:nodoc:
end
end
- def respond_to?(name)
+ def respond_to_missing?(name, include_private)
true
end
end
diff --git a/activesupport/test/ordered_options_test.rb b/activesupport/test/ordered_options_test.rb
index 3526c7a366..f60f9a58e3 100644
--- a/activesupport/test/ordered_options_test.rb
+++ b/activesupport/test/ordered_options_test.rb
@@ -77,4 +77,12 @@ class OrderedOptionsTest < ActiveSupport::TestCase
assert copy.kind_of?(original.class)
assert_not_equal copy.object_id, original.object_id
end
+
+ def test_introspection
+ a = ActiveSupport::OrderedOptions.new
+ assert a.respond_to?(:blah)
+ assert a.respond_to?(:blah=)
+ assert_equal 42, a.method(:blah=).call(42)
+ assert_equal 42, a.method(:blah).call
+ end
end
--
cgit v1.2.3
From 9bda37474e2cd3db63102f6b63246ebc54011ad2 Mon Sep 17 00:00:00 2001
From: Marc-Andre Lafortune
Date: Sat, 5 May 2012 02:34:18 -0400
Subject: Use respond_to_missing? for Chars
---
activesupport/lib/active_support/multibyte/chars.rb | 4 ++--
activesupport/test/multibyte_chars_test.rb | 9 +++++++++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb
index 9a748dfa60..b20c980f36 100644
--- a/activesupport/lib/active_support/multibyte/chars.rb
+++ b/activesupport/lib/active_support/multibyte/chars.rb
@@ -62,8 +62,8 @@ module ActiveSupport #:nodoc:
# Returns +true+ if _obj_ responds to the given method. Private methods are included in the search
# only if the optional second parameter evaluates to +true+.
- def respond_to?(method, include_private=false)
- super || @wrapped_string.respond_to?(method, include_private)
+ def respond_to_missing?(method, include_private)
+ @wrapped_string.respond_to?(method, include_private)
end
# Returns +true+ when the proxy class can handle the string. Returns +false+ otherwise.
diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb
index 90aa13b3e6..a8d69d0ec3 100644
--- a/activesupport/test/multibyte_chars_test.rb
+++ b/activesupport/test/multibyte_chars_test.rb
@@ -458,6 +458,15 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase
assert !''.mb_chars.respond_to?(:undefined_method) # Not defined
end
+ def test_method_works_for_proxyed_methods
+ assert_equal 'll', 'hello'.mb_chars.method(:slice).call(2..3) # Defined on Chars
+ chars = 'hello'.mb_chars
+ assert_equal 'Hello', chars.method(:capitalize!).call # Defined on Chars
+ assert_equal 'Hello', chars
+ assert_equal 'jello', 'hello'.mb_chars.method(:gsub).call(/h/, 'j') # Defined on String
+ assert_raise(NameError){ ''.mb_chars.method(:undefined_method) } # Not defined
+ end
+
def test_acts_like_string
assert 'Bambi'.mb_chars.acts_like_string?
end
--
cgit v1.2.3
From 14762dc5effbc7bb9ae94cb5af895a9a33512867 Mon Sep 17 00:00:00 2001
From: Marc-Andre Lafortune
Date: Sat, 5 May 2012 02:42:48 -0400
Subject: Use respond_to_missing for TimeWithZone
---
activesupport/lib/active_support/time_with_zone.rb | 6 +++---
activesupport/test/core_ext/time_with_zone_test.rb | 1 +
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index 1cb71012ef..120b2a4c28 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -311,10 +311,10 @@ module ActiveSupport
end
# Ensure proxy class responds to all methods that underlying time instance responds to.
- def respond_to?(sym, include_priv = false)
+ def respond_to_missing?(sym, include_priv)
# consistently respond false to acts_like?(:date), regardless of whether #time is a Time or DateTime
- return false if sym.to_s == 'acts_like_date?'
- super || time.respond_to?(sym, include_priv)
+ return false if sym.to_sym == :acts_like_date?
+ time.respond_to?(sym, include_priv)
end
# Send the missing method to +time+ instance, and wrap result in a new TimeWithZone with the existing +time_zone+.
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb
index 7cf3842a16..00a03de875 100644
--- a/activesupport/test/core_ext/time_with_zone_test.rb
+++ b/activesupport/test/core_ext/time_with_zone_test.rb
@@ -450,6 +450,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase
def test_ruby_19_weekday_name_query_methods
%w(sunday? monday? tuesday? wednesday? thursday? friday? saturday?).each do |name|
assert_respond_to @twz, name
+ assert_equal @twz.send(name), @twz.method(name).call
end
end
--
cgit v1.2.3
From a9721d89417c3912944d26610b4df370c56be8ae Mon Sep 17 00:00:00 2001
From: Michael Pearson
Date: Mon, 30 Apr 2012 10:42:06 +1000
Subject: Modify test schema.rb to use a VARCHAR rather than a TEXT when a
default is required to keep MySQL happy.
---
activerecord/test/schema/schema.rb | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb
index 7082d5dc86..cef08cd99c 100644
--- a/activerecord/test/schema/schema.rb
+++ b/activerecord/test/schema/schema.rb
@@ -38,7 +38,9 @@ ActiveRecord::Schema.define do
create_table :admin_users, :force => true do |t|
t.string :name
t.text :settings, :null => true
- t.text :preferences, :null => false, :default => ""
+ # MySQL does not allow default values for blobs. Fake it out with a
+ # big varchar below.
+ t.string :preferences, :null => false, :default => '', :limit => 1024
t.references :account
end
--
cgit v1.2.3
From 4b905606e33f0adba61c2032f0972623ba40e5e5 Mon Sep 17 00:00:00 2001
From: Michael Pearson
Date: Mon, 30 Apr 2012 09:46:08 +1000
Subject: Default to 'strict mode' in MySQL
---
.../lib/active_record/connection_adapters/mysql2_adapter.rb | 6 ++++++
activerecord/lib/active_record/connection_adapters/mysql_adapter.rb | 5 +++++
2 files changed, 11 insertions(+)
diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
index 92908d9599..41195dd8e3 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
@@ -253,6 +253,12 @@ module ActiveRecord
# By default, MySQL 'where id is null' selects the last inserted id.
# Turn this off. http://dev.rubyonrails.org/ticket/6778
variable_assignments = ['SQL_AUTO_IS_NULL=0']
+
+ # Make MySQL reject illegal values rather than truncating or
+ # blanking them. See
+ # http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_strict_all_tables
+ variable_assignments << "SQL_MODE='STRICT_ALL_TABLES'"
+
encoding = @config[:encoding]
# make sure we set the encoding
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index 724dbff1f0..f74febba75 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -404,6 +404,11 @@ module ActiveRecord
# By default, MySQL 'where id is null' selects the last inserted id.
# Turn this off. http://dev.rubyonrails.org/ticket/6778
execute("SET SQL_AUTO_IS_NULL=0", :skip_logging)
+
+ # Make MySQL reject illegal values rather than truncating or
+ # blanking them. See
+ # http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_strict_all_tables
+ execute("SET SQL_MODE='STRICT_ALL_TABLES'", :skip_logging)
end
def select(sql, name = nil, binds = [])
--
cgit v1.2.3
From acb39848ae4cfe1d22cd8a83c5db636d80c22b47 Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Sat, 5 May 2012 00:42:12 -0700
Subject: Try to convert object passed to debug_hash to hash
SessionStore was recently changed to delegate to hash
object instead of inherit from it. Since we don't want
to extend SessionStore with every method implemented in
Hash, it's better to just convert any object passed to
debug_hash (which is also better as we don't require
to pass Hash instance there, it can be any object that
can be converted to Hash).
---
.../middleware/templates/rescues/_request_and_response.erb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb
index 0c5bafa666..823f5d25b6 100644
--- a/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb
+++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb
@@ -12,8 +12,8 @@
request_dump = clean_params.empty? ? 'None' : clean_params.inspect.gsub(',', ",\n")
- def debug_hash(hash)
- hash.sort_by { |k, v| k.to_s }.map { |k, v| "#{k}: #{v.inspect rescue $!.message}" }.join("\n")
+ def debug_hash(object)
+ object.to_hash.sort_by { |k, v| k.to_s }.map { |k, v| "#{k}: #{v.inspect rescue $!.message}" }.join("\n")
end unless self.class.method_defined?(:debug_hash)
%>
--
cgit v1.2.3
From 7c4d3311332d8d6718f29c0f275325ef999d4734 Mon Sep 17 00:00:00 2001
From: Michael Pearson
Date: Sat, 5 May 2012 17:11:33 +1000
Subject: Add config option, rdoc, tests for mysql(2) STRICT_ALL_TABLES mode.
---
.../active_record/connection_adapters/mysql2_adapter.rb | 6 ++++--
.../active_record/connection_adapters/mysql_adapter.rb | 7 +++++--
.../test/cases/adapters/mysql/connection_test.rb | 13 +++++++++++++
.../test/cases/adapters/mysql2/connection_test.rb | 16 ++++++++++++++++
4 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
index 41195dd8e3..350ccce03d 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
@@ -256,8 +256,10 @@ module ActiveRecord
# Make MySQL reject illegal values rather than truncating or
# blanking them. See
- # http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_strict_all_tables
- variable_assignments << "SQL_MODE='STRICT_ALL_TABLES'"
+ # http://dev.mysql.com/doc/refman/5.5/en/server-sql-mode.html#sqlmode_strict_all_tables
+ if @config.fetch(:strict, true)
+ variable_assignments << "SQL_MODE='STRICT_ALL_TABLES'"
+ end
encoding = @config[:encoding]
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index f74febba75..0b6734b010 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -53,6 +53,7 @@ module ActiveRecord
# * :database - The name of the database. No default, must be provided.
# * :encoding - (Optional) Sets the client encoding by executing "SET NAMES " after connection.
# * :reconnect - Defaults to false (See MySQL documentation: http://dev.mysql.com/doc/refman/5.0/en/auto-reconnect.html).
+ # * :strict - Defaults to true. Enable STRICT_ALL_TABLES. (See MySQL documentation: http://dev.mysql.com/doc/refman/5.5/en/server-sql-mode.html)
# * :sslca - Necessary to use MySQL with an SSL connection.
# * :sslkey - Necessary to use MySQL with an SSL connection.
# * :sslcert - Necessary to use MySQL with an SSL connection.
@@ -407,8 +408,10 @@ module ActiveRecord
# Make MySQL reject illegal values rather than truncating or
# blanking them. See
- # http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_strict_all_tables
- execute("SET SQL_MODE='STRICT_ALL_TABLES'", :skip_logging)
+ # http://dev.mysql.com/doc/refman/5.5/en/server-sql-mode.html#sqlmode_strict_all_tables
+ if @config.fetch(:strict, true)
+ execute("SET SQL_MODE='STRICT_ALL_TABLES'", :skip_logging)
+ end
end
def select(sql, name = nil, binds = [])
diff --git a/activerecord/test/cases/adapters/mysql/connection_test.rb b/activerecord/test/cases/adapters/mysql/connection_test.rb
index fa2ba8d592..5e1c52c9ba 100644
--- a/activerecord/test/cases/adapters/mysql/connection_test.rb
+++ b/activerecord/test/cases/adapters/mysql/connection_test.rb
@@ -120,6 +120,19 @@ class MysqlConnectionTest < ActiveRecord::TestCase
end
end
+ def test_mysql_default_in_strict_mode
+ result = @connection.exec_query "SELECT @@SESSION.sql_mode"
+ assert_equal [["STRICT_ALL_TABLES"]], result.rows
+ end
+
+ def test_mysql_strict_mode_disabled
+ run_without_connection do |orig_connection|
+ ActiveRecord::Model.establish_connection(orig_connection.merge({:strict => false}))
+ result = ActiveRecord::Model.connection.exec_query "SELECT @@SESSION.sql_mode"
+ assert_equal [['']], result.rows
+ end
+ end
+
private
def run_without_connection
diff --git a/activerecord/test/cases/adapters/mysql2/connection_test.rb b/activerecord/test/cases/adapters/mysql2/connection_test.rb
index 8e2b9ca9a5..684c7f5929 100644
--- a/activerecord/test/cases/adapters/mysql2/connection_test.rb
+++ b/activerecord/test/cases/adapters/mysql2/connection_test.rb
@@ -29,6 +29,22 @@ class MysqlConnectionTest < ActiveRecord::TestCase
assert @connection.active?
end
+ # TODO: Below is a straight up copy/paste from mysql/connection_test.rb
+ # I'm not sure what the correct way is to share these tests between
+ # adapters in minitest.
+ def test_mysql_default_in_strict_mode
+ result = @connection.exec_query "SELECT @@SESSION.sql_mode"
+ assert_equal [["STRICT_ALL_TABLES"]], result.rows
+ end
+
+ def test_mysql_strict_mode_disabled
+ run_without_connection do |orig_connection|
+ ActiveRecord::Model.establish_connection(orig_connection.merge({:strict => false}))
+ result = ActiveRecord::Model.connection.exec_query "SELECT @@SESSION.sql_mode"
+ assert_equal [['']], result.rows
+ end
+ end
+
private
def run_without_connection
--
cgit v1.2.3
From 2054a17dd8e8be74b906a211d217e3183e2f40d6 Mon Sep 17 00:00:00 2001
From: Michael Pearson
Date: Sat, 5 May 2012 17:23:13 +1000
Subject: Changelog entry regarding mysql(2) STRICT_ALL_TABLES
---
activerecord/CHANGELOG.md | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index a661a44f1f..31886c8212 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,5 +1,11 @@
## Rails 4.0.0 (unreleased) ##
+* `mysql` and `mysql2` connections will set `SQL_MODE=STRICT_ALL_TABLES` by
+ default to avoid silent data loss. This can be disabled by specifying
+ `strict: false` in your `database.yml`.
+
+ *Michael Pearson*
+
* Added default order to `first` to assure consistent results among
diferent database engines. Introduced `take` as a replacement to
the old behavior of `first`.
--
cgit v1.2.3
From 56bf1f74557e68455552eeac1bc975cf9ba57766 Mon Sep 17 00:00:00 2001
From: Marcelo Silveira
Date: Sat, 5 May 2012 12:07:20 -0300
Subject: Use `take` instead of `first` to avoid unwanted implicit ordering
(fixes #6147)
---
activerecord/lib/active_record/relation/finder_methods.rb | 8 ++++----
activerecord/test/cases/finder_test.rb | 4 ++++
activerecord/test/cases/relations_test.rb | 10 +++++++++-
3 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index a78e3d08e4..cc716bbfd1 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -51,13 +51,13 @@ module ActiveRecord
# Post.find_by "published_at < ?", 2.weeks.ago
#
def find_by(*args)
- where(*args).first
+ where(*args).take
end
# Like find_by, except that if no record is found, raises
# an ActiveRecord::RecordNotFound error.
def find_by!(*args)
- where(*args).first!
+ where(*args).take!
end
# Gives a record (or N records if a parameter is supplied) without any implied
@@ -269,7 +269,7 @@ module ActiveRecord
substitute = connection.substitute_at(column, bind_values.length)
relation = where(table[primary_key].eq(substitute))
relation.bind_values += [[column, id]]
- record = relation.first
+ record = relation.take
unless record
conditions = arel.where_sql
@@ -309,7 +309,7 @@ module ActiveRecord
def find_take
if loaded?
- @records.take(1).first
+ @records.first
else
@take ||= limit(1).to_a.first
end
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index 54801bd101..630acdbc46 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -113,6 +113,10 @@ class FinderTest < ActiveRecord::TestCase
assert_equal [], Topic.find([])
end
+ def test_find_doesnt_have_implicit_ordering
+ assert_sql(/^((?!ORDER).)*$/) { Topic.find(1) }
+ end
+
def test_find_by_ids_missing_one
assert_raise(ActiveRecord::RecordNotFound) { Topic.find(1, 2, 45) }
end
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 3ef357e297..8cef4423c5 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -255,7 +255,7 @@ class RelationTest < ActiveRecord::TestCase
assert_equal nil, Developer.none.calculate(:average, 'salary')
end
end
-
+
def test_null_relation_metadata_methods
assert_equal "", Developer.none.to_sql
assert_equal({}, Developer.none.where_values_hash)
@@ -1287,6 +1287,10 @@ class RelationTest < ActiveRecord::TestCase
assert_equal nil, Post.scoped.find_by("1 = 0")
end
+ test "find_by doesn't have implicit ordering" do
+ assert_sql(/^((?!ORDER).)*$/) { Post.find_by(author_id: 2) }
+ end
+
test "find_by! with hash conditions returns the first matching record" do
assert_equal posts(:eager_other), Post.order(:id).find_by!(author_id: 2)
end
@@ -1299,6 +1303,10 @@ class RelationTest < ActiveRecord::TestCase
assert_equal posts(:eager_other), Post.order(:id).find_by!('author_id = ?', 2)
end
+ test "find_by! doesn't have implicit ordering" do
+ assert_sql(/^((?!ORDER).)*$/) { Post.find_by!(author_id: 2) }
+ end
+
test "find_by! raises RecordNotFound if the record is missing" do
assert_raises(ActiveRecord::RecordNotFound) do
Post.scoped.find_by!("1 = 0")
--
cgit v1.2.3
From 9d906d04ef09c585f215c0dcae6af05e0316831e Mon Sep 17 00:00:00 2001
From: Marcelo Silveira
Date: Sat, 5 May 2012 13:15:09 -0300
Subject: Update `first`, `last` and `take` in guides
---
guides/source/active_record_querying.textile | 50 +++++++++++++++++++++++-----
1 file changed, 42 insertions(+), 8 deletions(-)
diff --git a/guides/source/active_record_querying.textile b/guides/source/active_record_querying.textile
index f9dbaa1125..d16cdd66ee 100644
--- a/guides/source/active_record_querying.textile
+++ b/guides/source/active_record_querying.textile
@@ -99,9 +99,26 @@ SELECT * FROM clients WHERE (clients.id = 10) LIMIT 1
Model.find(primary_key) will raise an +ActiveRecord::RecordNotFound+ exception if no matching record is found.
+h5. +take+
+
+Model.take retrieves a record without any implicit ordering. The retrieved record may vary depending on the database engine. For example:
+
+
+client = Client.take
+# => #
+
+
+The SQL equivalent of the above is:
+
+
+SELECT * FROM clients LIMIT 1
+
+
+Model.take returns +nil+ if no record is found. No exception will be raised.
+
h5. +first+
-Model.first finds the first record matched by the supplied options, if any. For example:
+Model.first finds the first record. If no order is chained it will order by primary key. For example:
client = Client.first
@@ -111,14 +128,14 @@ client = Client.first
The SQL equivalent of the above is:
-SELECT * FROM clients LIMIT 1
+SELECT * FROM clients ORDER BY clients.id ASC LIMIT 1
Model.first returns +nil+ if no matching record is found. No exception will be raised.
h5. +last+
-Model.last finds the last record matched by the supplied options. For example:
+Model.last finds the last record. If no order is chained it will order by primary key. For example:
client = Client.last
@@ -148,12 +165,29 @@ Client.find_by first_name: 'Jon'
It is equivalent to writing:
-Client.where(first_name: 'Lifo').first
+Client.where(first_name: 'Lifo').take
+h5(#take_1). +take!+
+
+Model.take! retrieves a record without any implicit ordering. For example:
+
+
+client = Client.take!
+# => #
+
+
+The SQL equivalent of the above is:
+
+
+SELECT * FROM clients LIMIT 1
+
+
+Model.take! raises +RecordNotFound+ if no matching record is found.
+
h5(#first_1). +first!+
-Model.first! finds the first record. For example:
+Model.first! finds the first record. If no order is chained it will order by primary key. For example:
client = Client.first!
@@ -163,14 +197,14 @@ client = Client.first!
The SQL equivalent of the above is:
-SELECT * FROM clients LIMIT 1
+SELECT * FROM clients ORDER BY clients.id ASC LIMIT 1
Model.first! raises +RecordNotFound+ if no matching record is found.
h5(#last_1). +last!+
-Model.last! finds the last record. For example:
+Model.last! finds the last record. If no order is chained it will order by primary key. For example:
client = Client.last!
@@ -200,7 +234,7 @@ Client.find_by! first_name: 'Jon'
It is equivalent to writing:
-Client.where(first_name: 'Lifo').first!
+Client.where(first_name: 'Lifo').take!
h4. Retrieving Multiple Objects
--
cgit v1.2.3
From e0aadf12e3e6f3e98609bcc51e2428cf3843cfd3 Mon Sep 17 00:00:00 2001
From: Vasiliy Ermolovich
Date: Sat, 5 May 2012 20:34:06 +0300
Subject: check checkboxes with array of strings as :checked option
---
actionpack/lib/action_view/helpers/tags/collection_helpers.rb | 2 +-
actionpack/test/template/form_collections_helper_test.rb | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/actionpack/lib/action_view/helpers/tags/collection_helpers.rb b/actionpack/lib/action_view/helpers/tags/collection_helpers.rb
index 6a1479069f..4e33e79a36 100644
--- a/actionpack/lib/action_view/helpers/tags/collection_helpers.rb
+++ b/actionpack/lib/action_view/helpers/tags/collection_helpers.rb
@@ -49,7 +49,7 @@ module ActionView
accept = if current_value.respond_to?(:call)
current_value.call(item)
else
- Array(current_value).include?(value)
+ Array(current_value).map(&:to_s).include?(value.to_s)
end
if accept
diff --git a/actionpack/test/template/form_collections_helper_test.rb b/actionpack/test/template/form_collections_helper_test.rb
index 4d878635ef..c73e80ed88 100644
--- a/actionpack/test/template/form_collections_helper_test.rb
+++ b/actionpack/test/template/form_collections_helper_test.rb
@@ -195,6 +195,15 @@ class FormCollectionsHelperTest < ActionView::TestCase
assert_no_select 'input[type=checkbox][value=2][checked=checked]'
end
+ test 'collection check boxes accepts selected string values as :checked option' do
+ collection = (1..3).map{|i| [i, "Category #{i}"] }
+ with_collection_check_boxes :user, :category_ids, collection, :first, :last, :checked => ['1', '3']
+
+ assert_select 'input[type=checkbox][value=1][checked=checked]'
+ assert_select 'input[type=checkbox][value=3][checked=checked]'
+ assert_no_select 'input[type=checkbox][value=2][checked=checked]'
+ end
+
test 'collection check boxes accepts a single checked value' do
collection = (1..3).map{|i| [i, "Category #{i}"] }
with_collection_check_boxes :user, :category_ids, collection, :first, :last, :checked => 3
--
cgit v1.2.3
From a9668680fd5eda2797f003a710eaf220768d95da Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 5 May 2012 23:54:16 +0530
Subject: some corrections in the AR query guide [ci skip]
---
guides/source/active_record_querying.textile | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/guides/source/active_record_querying.textile b/guides/source/active_record_querying.textile
index d16cdd66ee..a9cb424eaa 100644
--- a/guides/source/active_record_querying.textile
+++ b/guides/source/active_record_querying.textile
@@ -101,7 +101,7 @@ SELECT * FROM clients WHERE (clients.id = 10) LIMIT 1
h5. +take+
-Model.take retrieves a record without any implicit ordering. The retrieved record may vary depending on the database engine. For example:
+Model.take retrieves a record without any implicit ordering. For example:
client = Client.take
@@ -114,11 +114,13 @@ The SQL equivalent of the above is:
SELECT * FROM clients LIMIT 1
-Model.take returns +nil+ if no record is found. No exception will be raised.
+Model.take returns +nil+ if no record is found and no exception will be raised.
+
+TIP: The retrieved record may vary depending on the database engine.
h5. +first+
-Model.first finds the first record. If no order is chained it will order by primary key. For example:
+Model.first finds the first record ordered by the primary key. For example:
client = Client.first
@@ -131,11 +133,11 @@ The SQL equivalent of the above is:
SELECT * FROM clients ORDER BY clients.id ASC LIMIT 1
-Model.first returns +nil+ if no matching record is found. No exception will be raised.
+Model.first returns +nil+ if no matching record is found and no exception will be raised.
h5. +last+
-Model.last finds the last record. If no order is chained it will order by primary key. For example:
+Model.last finds the last record ordered by the primary key. For example:
client = Client.last
@@ -148,7 +150,7 @@ The SQL equivalent of the above is:
SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1
-Model.last returns +nil+ if no matching record is found. No exception will be raised.
+Model.last returns +nil+ if no matching record is found and no exception will be raised.
h5. +find_by+
@@ -183,11 +185,11 @@ The SQL equivalent of the above is:
SELECT * FROM clients LIMIT 1
-Model.take! raises +RecordNotFound+ if no matching record is found.
+Model.take! raises +ActiveRecord::RecordNotFound+ if no matching record is found.
h5(#first_1). +first!+
-Model.first! finds the first record. If no order is chained it will order by primary key. For example:
+Model.first! finds the first record ordered by the primary key. For example:
client = Client.first!
@@ -200,11 +202,11 @@ The SQL equivalent of the above is:
SELECT * FROM clients ORDER BY clients.id ASC LIMIT 1
-Model.first! raises +RecordNotFound+ if no matching record is found.
+Model.first! raises +ActiveRecord::RecordNotFound+ if no matching record is found.
h5(#last_1). +last!+
-Model.last! finds the last record. If no order is chained it will order by primary key. For example:
+Model.last! finds the last record ordered by the primary key. For example:
client = Client.last!
@@ -217,18 +219,18 @@ The SQL equivalent of the above is:
SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1
-Model.last! raises +RecordNotFound+ if no matching record is found.
+Model.last! raises +ActiveRecord::RecordNotFound+ if no matching record is found.
h5(#find_by_1). +find_by!+
-Model.find_by! finds the first record matching some conditions. It raises +RecordNotFound+ if no matching record is found. For example:
+Model.find_by! finds the first record matching some conditions. It raises +ActiveRecord::RecordNotFound+ if no matching record is found. For example:
Client.find_by! first_name: 'Lifo'
# => #
Client.find_by! first_name: 'Jon'
-# => RecordNotFound
+# => ActiveRecord::RecordNotFound
It is equivalent to writing:
--
cgit v1.2.3
From b7e3f3c7c40e31572d941cb29fe03fd8d95e3985 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 6 May 2012 00:46:16 +0530
Subject: Revert "Play nice with some lint patterns"
This reverts commit 7f536f9158588b66c0e5a6aa8772b919812f9cb9.
Reason: If at all this is done, this should be done in rails master.
---
guides/assets/stylesheets/main.css | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/guides/assets/stylesheets/main.css b/guides/assets/stylesheets/main.css
index 60859a6930..42b85fefa3 100644
--- a/guides/assets/stylesheets/main.css
+++ b/guides/assets/stylesheets/main.css
@@ -196,12 +196,11 @@ a, a:link, a:visited {
width: 27em;
display: block;
background: #980905;
+ border-radius: 1em;
-webkit-border-radius: 1em;
-moz-border-radius: 1em;
- border-radius: 1em;
-webkit-box-shadow: 0.25em 0.25em 1em rgba(0,0,0,0.25);
-moz-box-shadow: rgba(0,0,0,0.25) 0.25em 0.25em 1em;
- box-shadow: 0.25em 0.25em 1em rgba(0,0,0,0.25);
color: #f1938c;
padding: 1.5em 2em;
position: absolute;
@@ -448,8 +447,8 @@ div.important p, div.caution p, div.warning p, div.note p, div.info p {
#edge-badge {
position: fixed;
- right: 0;
- top: 0;
+ right: 0px;
+ top: 0px;
z-index: 100;
border: none;
}
--
cgit v1.2.3
From 58a49875df63729f07a9a81d1ee349087d258df5 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 6 May 2012 01:05:43 +0530
Subject: Make RedCloth not convert double hyphens to emdashes. Closes #5292
As mentioned in http://redcloth.org/textile/writing-paragraph-text/#dashes
RedCloth converts double hyphens to emdashes. This causes problems in
the guides where options like --database, --full are rendered incorrectly.
This commit fixes it by customizing the emdash method in the
RedCloth::Formatters::HTML module to just return '--'. See their FAQ
http://redcloth.org/faq in the section 'How do I customize RedCloth?'
---
guides/rails_guides/textile_extensions.rb | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/guides/rails_guides/textile_extensions.rb b/guides/rails_guides/textile_extensions.rb
index 4677fae504..0a002a785f 100644
--- a/guides/rails_guides/textile_extensions.rb
+++ b/guides/rails_guides/textile_extensions.rb
@@ -1,5 +1,11 @@
require 'active_support/core_ext/object/inclusion'
+module RedCloth::Formatters::HTML
+ def emdash(opts)
+ "--"
+ end
+end
+
module RailsGuides
module TextileExtensions
def notestuff(body)
--
cgit v1.2.3
From 7f160b06a24547a41a59994a736d6b11beb0c30e Mon Sep 17 00:00:00 2001
From: Egor Lynko
Date: Sun, 29 Apr 2012 19:39:16 +0300
Subject: Prevent creating valid time-like objects from blank string from db
Issue #6045
---
.../active_record/connection_adapters/column.rb | 6 ++---
activerecord/test/cases/column_test.rb | 28 ++++++++++++++++++++++
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb
index 9af8e46120..1933ce2b46 100644
--- a/activerecord/lib/active_record/connection_adapters/column.rb
+++ b/activerecord/lib/active_record/connection_adapters/column.rb
@@ -158,7 +158,7 @@ module ActiveRecord
def value_to_date(value)
if value.is_a?(String)
- return nil if value.empty?
+ return nil if value.blank?
fast_string_to_date(value) || fallback_string_to_date(value)
elsif value.respond_to?(:to_date)
value.to_date
@@ -169,14 +169,14 @@ module ActiveRecord
def string_to_time(string)
return string unless string.is_a?(String)
- return nil if string.empty?
+ return nil if string.blank?
fast_string_to_time(string) || fallback_string_to_time(string)
end
def string_to_dummy_time(string)
return string unless string.is_a?(String)
- return nil if string.empty?
+ return nil if string.blank?
string_to_time "2000-01-01 #{string}"
end
diff --git a/activerecord/test/cases/column_test.rb b/activerecord/test/cases/column_test.rb
index 4fcf8a33a4..4111a5f808 100644
--- a/activerecord/test/cases/column_test.rb
+++ b/activerecord/test/cases/column_test.rb
@@ -48,6 +48,34 @@ module ActiveRecord
column.type_cast(false)
end
end
+
+ def test_type_cast_time
+ column = Column.new("field", nil, "time")
+ assert_equal nil, column.type_cast('')
+ assert_equal nil, column.type_cast(' ')
+
+ time_string = Time.now.utc.strftime("%T")
+ assert_equal time_string, column.type_cast(time_string).strftime("%T")
+ end
+
+ def test_type_cast_datetime_and_timestamp
+ [Column.new("field", nil, "datetime"), Column.new("field", nil, "timestamp")].each do |column|
+ assert_equal nil, column.type_cast('')
+ assert_equal nil, column.type_cast(' ')
+
+ datetime_string = Time.now.utc.strftime("%FT%T")
+ assert_equal datetime_string, column.type_cast(datetime_string).strftime("%FT%T")
+ end
+ end
+
+ def test_type_cast_date
+ column = Column.new("field", nil, "date")
+ assert_equal nil, column.type_cast('')
+ assert_equal nil, column.type_cast(' ')
+
+ date_string = Time.now.utc.strftime("%F")
+ assert_equal date_string, column.type_cast(date_string).strftime("%F")
+ end
end
end
end
--
cgit v1.2.3
From 06c787d2359660529ff5b927d3d34f22379eef00 Mon Sep 17 00:00:00 2001
From: Jon Leighton
Date: Sat, 5 May 2012 21:36:24 +0100
Subject: Revert "Merge pull request #5494 from
armstrjare/active_record_relation_keep_association_join_context_on_merge"
This reverts commit dcd04e76179611a9db28c9e391aa7d6c2a5b046a, reversing
changes made to 58a49875df63729f07a9a81d1ee349087d258df5.
---
.../active_record/associations/join_dependency.rb | 2 +-
.../join_dependency/join_association.rb | 7 +----
activerecord/lib/active_record/relation/merger.rb | 31 +++-------------------
activerecord/test/cases/relations_test.rb | 9 +------
4 files changed, 6 insertions(+), 43 deletions(-)
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb
index e3d8356f49..cd366ac8b7 100644
--- a/activerecord/lib/active_record/associations/join_dependency.rb
+++ b/activerecord/lib/active_record/associations/join_dependency.rb
@@ -109,7 +109,7 @@ module ActiveRecord
case associations
when Symbol, String
reflection = parent.reflections[associations.to_s.intern] or
- raise ConfigurationError, "Association named '#{ associations }' was not found on #{parent.active_record.name}; perhaps you misspelled it?"
+ raise ConfigurationError, "Association named '#{ associations }' was not found; perhaps you misspelled it?"
unless join_association = find_join_association(reflection, parent)
@reflections << reflection
join_association = build_join_association(reflection, parent)
diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
index ea4856408d..0d7d28e458 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -55,12 +55,7 @@ module ActiveRecord
def find_parent_in(other_join_dependency)
other_join_dependency.join_parts.detect do |join_part|
- case parent
- when JoinBase
- parent.active_record == join_part.active_record
- else
- parent == join_part
- end
+ parent == join_part
end
end
diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb
index c2f0a82fd3..3f880ce5e9 100644
--- a/activerecord/lib/active_record/relation/merger.rb
+++ b/activerecord/lib/active_record/relation/merger.rb
@@ -29,7 +29,7 @@ module ActiveRecord
end
class Merger
- attr_reader :relation, :other
+ attr_reader :relation, :values
def initialize(relation, other)
if other.default_scoped? && other.klass != relation.klass
@@ -37,17 +37,13 @@ module ActiveRecord
end
@relation = relation
- @other = other
- end
-
- def values
- @other.values
+ @values = other.values
end
def normal_values
Relation::SINGLE_VALUE_METHODS +
Relation::MULTI_VALUE_METHODS -
- [:where, :joins, :order, :bind, :reverse_order, :lock, :create_with, :reordering]
+ [:where, :order, :bind, :reverse_order, :lock, :create_with, :reordering]
end
def merge
@@ -58,7 +54,6 @@ module ActiveRecord
merge_multi_values
merge_single_values
- merge_joins
relation
end
@@ -89,26 +84,6 @@ module ActiveRecord
end
end
- def merge_joins
- return if values[:joins].blank?
-
- if other.klass == relation.klass
- relation.joins!(values[:joins])
- else
- joins_to_stash, other_joins = values[:joins].partition { |join|
- case join
- when Hash, Symbol, Array
- true
- else
- false
- end
- }
-
- join_dependency = ActiveRecord::Associations::JoinDependency.new(other.klass, joins_to_stash, [])
- relation.joins!(join_dependency.join_associations + other_joins)
- end
- end
-
def merged_binds
if values[:bind]
(relation.bind_values + values[:bind]).uniq(&:first)
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 48fc82bbc7..3ef357e297 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -6,7 +6,6 @@ require 'models/topic'
require 'models/comment'
require 'models/author'
require 'models/comment'
-require 'models/rating'
require 'models/entrant'
require 'models/developer'
require 'models/reply'
@@ -20,7 +19,7 @@ require 'models/minivan'
class RelationTest < ActiveRecord::TestCase
fixtures :authors, :topics, :entrants, :developers, :companies, :developers_projects, :accounts, :categories, :categorizations, :posts, :comments,
- :ratings, :tags, :taggings, :cars, :minivans
+ :tags, :taggings, :cars, :minivans
def test_do_not_double_quote_string_id
van = Minivan.last
@@ -732,12 +731,6 @@ class RelationTest < ActiveRecord::TestCase
assert_equal 1, comments.count
end
- def test_relation_merging_with_merged_joins
- special_comments_with_ratings = SpecialComment.joins(:ratings)
- posts_with_special_comments_with_ratings = Post.group("posts.id").joins(:special_comments).merge(special_comments_with_ratings)
- assert_equal 1, authors(:david).posts.merge(posts_with_special_comments_with_ratings).to_a.length
- end
-
def test_count
posts = Post.scoped
--
cgit v1.2.3
From f9646c8a6312e8d2d5ecc5d35e6201a7f4fe00ba Mon Sep 17 00:00:00 2001
From: Mitch Crowe
Date: Sat, 5 May 2012 18:34:54 -0700
Subject: SpawnMethods#merge returns the intersection when passed an array, and
not the union. Update the documentation to reflect this.
---
activerecord/lib/active_record/relation/spawn_methods.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb
index 41e55dfd0e..f6d178db7a 100644
--- a/activerecord/lib/active_record/relation/spawn_methods.rb
+++ b/activerecord/lib/active_record/relation/spawn_methods.rb
@@ -7,7 +7,7 @@ module ActiveRecord
module SpawnMethods
# Merges in the conditions from other, if other is an ActiveRecord::Relation.
- # Returns an array representing the union of the resulting records with other, if other is an array.
+ # Returns an array representing the intersection of the resulting records with other, if other is an array.
#
# ==== Examples
#
@@ -16,7 +16,7 @@ module ActiveRecord
#
# recent_posts = Post.order('created_at DESC').first(5)
# Post.where(:published => true).merge(recent_posts)
- # # Returns the union of all published posts with the 5 most recently created posts.
+ # # Returns the intersection of all published posts with the 5 most recently created posts.
# # (This is just an example. You'd probably want to do this with a single query!)
#
def merge(other)
--
cgit v1.2.3
From 3532200576bed84bedf3554336dfc92ce9ce1cab Mon Sep 17 00:00:00 2001
From: Steven Soroka
Date: Wed, 27 Jul 2011 18:37:06 -0400
Subject: Raise a rescuable exception when Rails doesn't know what to do with
the format, rather than responding with a head :not_acceptable (406)
---
.../lib/action_controller/metal/exceptions.rb | 3 ++
.../lib/action_controller/metal/mime_responds.rb | 3 +-
.../middleware/exception_wrapper.rb | 1 +
actionpack/test/controller/mime_responds_test.rb | 32 +++++++++++++---------
4 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/actionpack/lib/action_controller/metal/exceptions.rb b/actionpack/lib/action_controller/metal/exceptions.rb
index 9a9db0fe5f..90648c37ad 100644
--- a/actionpack/lib/action_controller/metal/exceptions.rb
+++ b/actionpack/lib/action_controller/metal/exceptions.rb
@@ -38,4 +38,7 @@ module ActionController
class UnknownHttpMethod < ActionControllerError #:nodoc:
end
+
+ class UnknownFormat < ActionControllerError #:nodoc:
+ end
end
diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb
index f467b74256..2c96145820 100644
--- a/actionpack/lib/action_controller/metal/mime_responds.rb
+++ b/actionpack/lib/action_controller/metal/mime_responds.rb
@@ -375,8 +375,7 @@ module ActionController #:nodoc:
lookup_context.rendered_format = lookup_context.formats.first
collector
else
- head :not_acceptable
- nil
+ raise ActionController::UnknownFormat.new
end
end
diff --git a/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb b/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb
index c0532c80c4..982f6641bf 100644
--- a/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb
+++ b/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb
@@ -10,6 +10,7 @@ module ActionDispatch
'AbstractController::ActionNotFound' => :not_found,
'ActionController::MethodNotAllowed' => :method_not_allowed,
'ActionController::NotImplemented' => :not_implemented,
+ 'ActionController::UnknownFormat' => :not_acceptable,
'ActionController::InvalidAuthenticityToken' => :unprocessable_entity
)
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index ac056319fc..bdcd5561a8 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -207,8 +207,9 @@ class RespondToControllerTest < ActionController::TestCase
get :html_or_xml
assert_equal 'HTML', @response.body
- get :just_xml
- assert_response 406
+ assert_raises(ActionController::UnknownFormat) do
+ get :just_xml
+ end
end
def test_all
@@ -239,8 +240,10 @@ class RespondToControllerTest < ActionController::TestCase
assert_equal 'HTML', @response.body
@request.accept = "text/javascript, text/html"
- xhr :get, :just_xml
- assert_response 406
+
+ assert_raises(ActionController::UnknownFormat) do
+ xhr :get, :just_xml
+ end
end
def test_json_or_yaml_with_leading_star_star
@@ -495,9 +498,9 @@ class RespondToControllerTest < ActionController::TestCase
end
def test_invalid_format
- get :using_defaults, :format => "invalidformat"
- assert_equal " ", @response.body
- assert_equal "text/html", @response.content_type
+ assert_raises(ActionController::UnknownFormat) do
+ get :using_defaults, :format => "invalidformat"
+ end
end
end
@@ -701,12 +704,14 @@ class RespondWithControllerTest < ActionController::TestCase
def test_not_acceptable
@request.accept = "application/xml"
- get :using_resource_with_block
- assert_equal 406, @response.status
+ assert_raises(ActionController::UnknownFormat) do
+ get :using_resource_with_block
+ end
@request.accept = "text/javascript"
- get :using_resource_with_overwrite_block
- assert_equal 406, @response.status
+ assert_raises(ActionController::UnknownFormat) do
+ get :using_resource_with_overwrite_block
+ end
end
def test_using_resource_for_post_with_html_redirects_on_success
@@ -984,8 +989,9 @@ class RespondWithControllerTest < ActionController::TestCase
def test_clear_respond_to
@controller = InheritedRespondWithController.new
@request.accept = "text/html"
- get :index
- assert_equal 406, @response.status
+ assert_raises(ActionController::UnknownFormat) do
+ get :index
+ end
end
def test_first_in_respond_to_has_higher_priority
--
cgit v1.2.3
From ec4045c02fb112937116f827c508c3680a495326 Mon Sep 17 00:00:00 2001
From: Steven Soroka
Date: Thu, 28 Jul 2011 00:01:29 -0400
Subject: added an integration test that checks ActionController::UnknownFormat
renders 406 :not_acceptable
---
actionpack/test/controller/integration_test.rb | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb
index 877b91b563..9f2dbda25f 100644
--- a/actionpack/test/controller/integration_test.rb
+++ b/actionpack/test/controller/integration_test.rb
@@ -405,6 +405,15 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest
end
end
+ def test_request_with_bad_format
+ with_test_route_set do
+ xhr :get, '/get.php'
+ assert_equal 406, status
+ assert_response 406
+ assert_response :not_acceptable
+ end
+ end
+
def test_get_with_query_string
with_test_route_set do
get '/get_with_params?foo=bar'
--
cgit v1.2.3
From 6471ced656ad0e61f12b2a7d6f51ef5b2408e64a Mon Sep 17 00:00:00 2001
From: Steven Soroka
Date: Sun, 6 May 2012 00:34:08 -0500
Subject: remove .new from raise ActionController::UnknownFormat
---
actionpack/lib/action_controller/metal/mime_responds.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb
index 2c96145820..7917926978 100644
--- a/actionpack/lib/action_controller/metal/mime_responds.rb
+++ b/actionpack/lib/action_controller/metal/mime_responds.rb
@@ -375,7 +375,7 @@ module ActionController #:nodoc:
lookup_context.rendered_format = lookup_context.formats.first
collector
else
- raise ActionController::UnknownFormat.new
+ raise ActionController::UnknownFormat
end
end
--
cgit v1.2.3
From c02846ff52457b19c5cdd6f67eb7086cb887e136 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Sun, 6 May 2012 12:11:40 +0300
Subject: Update actionpack/CHANGELOG.md
---
actionpack/CHANGELOG.md | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 96dee33f7b..b819f2e613 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ##
+* `respond_to` and `respond_with` now raise ActionController::UnknownFormat instead
+ of directly returning head 406. The exception is rescued and converted to 406
+ in the exception handling middleware. *Steven Soroka*
+
* Allows `assert_redirected_to` to match against a regular expression. *Andy Lindeman*
* Add backtrace to development routing error page. *Richard Schneeman*
@@ -12,7 +16,7 @@
* Make current object and counter (when it applies) variables accessible when
rendering templates with :object / :collection. *Carlos Antonio da Silva*
-* JSONP now uses mimetype application/javascript instead of application/json *omjokine*
+* JSONP now uses mimetype application/javascript instead of application/json. *omjokine*
* Allow to lazy load `default_form_builder` by passing a `String` instead of a constant. *Piotr Sarnacki*
--
cgit v1.2.3
From 9b854ccd77498e5c0f30912596737f0b8efa4654 Mon Sep 17 00:00:00 2001
From: Rob Zolkos
Date: Sun, 6 May 2012 21:04:02 +1000
Subject: Add missing public method doc to TimeWithZone.name
---
activesupport/lib/active_support/time_with_zone.rb | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index 1cb71012ef..9d89e425fc 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -35,8 +35,10 @@ module ActiveSupport
# t.is_a?(ActiveSupport::TimeWithZone) # => true
#
class TimeWithZone
+
+ # Report class name as 'Time' to thwart type checking
def self.name
- 'Time' # Report class name as 'Time' to thwart type checking
+ 'Time'
end
include Comparable
--
cgit v1.2.3
From 19c91d7b72a8fbf5a315868c7089c1ecf499e811 Mon Sep 17 00:00:00 2001
From: Alex Soulim
Date: Sun, 6 May 2012 19:33:47 +0400
Subject: Fix typo in submit_tag helper documentation
---
actionpack/lib/action_view/helpers/form_tag_helper.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index ef35a411ad..0d824bd574 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -408,7 +408,7 @@ module ActionView
# # =>
#
# submit_tag "Edit", :disable_with => "Editing...", :class => "edit_button"
- # # =>
+ # # =>
#
# submit_tag "Save", :confirm => "Are you sure?"
# # =>
--
cgit v1.2.3
From ed1703bcb206a740957c0a93df5f25177dedc0de Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sun, 6 May 2012 22:32:22 +0530
Subject: doc edits [ci skip]
---
actionpack/lib/action_dispatch/middleware/cookies.rb | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb
index 3a5442918d..771f075275 100644
--- a/actionpack/lib/action_dispatch/middleware/cookies.rb
+++ b/actionpack/lib/action_dispatch/middleware/cookies.rb
@@ -26,10 +26,9 @@ module ActionDispatch
# # Sets a cookie that expires in 1 hour.
# cookies[:login] = { :value => "XJ-122", :expires => 1.hour.from_now }
#
- # # Sets a signed cookie, which prevents a user from tampering with its value.
+ # # Sets a signed cookie, which prevents users from tampering with its value.
# # The cookie is signed by your app's config.secret_token value.
- # # Rails generates this value by default when you create a new Rails app.
- # # Signed cookies must read with the signed method cookies.signed[:key]
+ # # It can be read using the signed method cookies.signed[:key]
# cookies.signed[:user_id] = current_user.id
#
# # Sets a "permanent" cookie (which expires in 20 years from now).
--
cgit v1.2.3
From 657b4ff04ad43bf26ded31ebfc003075f46dad53 Mon Sep 17 00:00:00 2001
From: Alexey Gaziev
Date: Tue, 24 Apr 2012 13:59:55 +0400
Subject: Nice logic for deep_dup in rails
---
activesupport/lib/active_support/core_ext/array.rb | 1 +
.../lib/active_support/core_ext/array/deep_dup.rb | 6 +++
.../lib/active_support/core_ext/hash/deep_dup.rb | 6 +--
.../lib/active_support/core_ext/object.rb | 1 +
.../lib/active_support/core_ext/object/deep_dup.rb | 6 +++
activesupport/test/core_ext/deep_dup_test.rb | 54 ++++++++++++++++++++++
activesupport/test/core_ext/hash_ext_test.rb | 15 ------
railties/lib/rails/configuration.rb | 2 +
8 files changed, 72 insertions(+), 19 deletions(-)
create mode 100644 activesupport/lib/active_support/core_ext/array/deep_dup.rb
create mode 100644 activesupport/lib/active_support/core_ext/object/deep_dup.rb
create mode 100644 activesupport/test/core_ext/deep_dup_test.rb
diff --git a/activesupport/lib/active_support/core_ext/array.rb b/activesupport/lib/active_support/core_ext/array.rb
index 79ba79192a..d6e1398a27 100644
--- a/activesupport/lib/active_support/core_ext/array.rb
+++ b/activesupport/lib/active_support/core_ext/array.rb
@@ -1,6 +1,7 @@
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/array/access'
require 'active_support/core_ext/array/uniq_by'
+require 'active_support/core_ext/array/deep_dup'
require 'active_support/core_ext/array/conversions'
require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/array/grouping'
diff --git a/activesupport/lib/active_support/core_ext/array/deep_dup.rb b/activesupport/lib/active_support/core_ext/array/deep_dup.rb
new file mode 100644
index 0000000000..82f9805236
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/array/deep_dup.rb
@@ -0,0 +1,6 @@
+class Array
+ # Returns a deep copy of array.
+ def deep_dup
+ map { |it| it.deep_dup }
+ end
+end
diff --git a/activesupport/lib/active_support/core_ext/hash/deep_dup.rb b/activesupport/lib/active_support/core_ext/hash/deep_dup.rb
index 9ab179c566..882f27623e 100644
--- a/activesupport/lib/active_support/core_ext/hash/deep_dup.rb
+++ b/activesupport/lib/active_support/core_ext/hash/deep_dup.rb
@@ -1,10 +1,8 @@
class Hash
# Returns a deep copy of hash.
def deep_dup
- duplicate = self.dup
- duplicate.each_pair do |k,v|
- duplicate[k] = v.is_a?(Hash) ? v.deep_dup : v
+ each_with_object(dup) do |(key, value), hash|
+ hash[key.deep_dup] = value.deep_dup
end
- duplicate
end
end
diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb
index 9ad1e12699..ec2157221f 100644
--- a/activesupport/lib/active_support/core_ext/object.rb
+++ b/activesupport/lib/active_support/core_ext/object.rb
@@ -1,6 +1,7 @@
require 'active_support/core_ext/object/acts_like'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/object/duplicable'
+require 'active_support/core_ext/object/deep_dup'
require 'active_support/core_ext/object/try'
require 'active_support/core_ext/object/inclusion'
diff --git a/activesupport/lib/active_support/core_ext/object/deep_dup.rb b/activesupport/lib/active_support/core_ext/object/deep_dup.rb
new file mode 100644
index 0000000000..daae98dde1
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/object/deep_dup.rb
@@ -0,0 +1,6 @@
+class Object
+ # Returns a deep copy of object if it's duplicable.
+ def deep_dup
+ duplicable? ? dup : self
+ end
+end
diff --git a/activesupport/test/core_ext/deep_dup_test.rb b/activesupport/test/core_ext/deep_dup_test.rb
new file mode 100644
index 0000000000..2a00fc5315
--- /dev/null
+++ b/activesupport/test/core_ext/deep_dup_test.rb
@@ -0,0 +1,54 @@
+require 'active_support/core_ext/object'
+require 'active_support/core_ext/array'
+require 'active_support/core_ext/hash'
+
+class DeepDupTest < ActiveSupport::TestCase
+
+ def test_array_deep_dup
+ array = [1, [2, 3]]
+ dup = array.deep_dup
+ dup[1][2] = 4
+ assert_equal nil, array[1][2]
+ assert_equal 4, dup[1][2]
+ end
+
+ def test_hash_deep_dup
+ hash = { :a => { :b => 'b' } }
+ dup = hash.deep_dup
+ dup[:a][:c] = 'c'
+ assert_equal nil, hash[:a][:c]
+ assert_equal 'c', dup[:a][:c]
+ end
+
+ def test_array_deep_dup_with_hash_inside
+ array = [1, { :a => 2, :b => 3 } ]
+ dup = array.deep_dup
+ dup[1][:c] = 4
+ assert_equal nil, array[1][:c]
+ assert_equal 4, dup[1][:c]
+ end
+
+ def test_hash_deep_dup_with_array_inside
+ hash = { :a => [1, 2] }
+ dup = hash.deep_dup
+ dup[:a][2] = 'c'
+ assert_equal nil, hash[:a][2]
+ assert_equal 'c', dup[:a][2]
+ end
+
+ def test_deep_dup_initialize
+ zero_hash = Hash.new 0
+ hash = { :a => zero_hash }
+ dup = hash.deep_dup
+ assert_equal 0, dup[:a][44]
+ end
+
+ def test_object_deep_dup
+ object = Object.new
+ dup = object.deep_dup
+ dup.instance_variable_set(:@a, 1)
+ assert !object.instance_variable_defined?(:@a)
+ assert dup.instance_variable_defined?(:@a)
+ end
+
+end
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index 80b3c16328..1cd10eb6e2 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -363,21 +363,6 @@ class HashExtTest < ActiveSupport::TestCase
assert_equal expected, hash_1
end
- def test_deep_dup
- hash = { :a => { :b => 'b' } }
- dup = hash.deep_dup
- dup[:a][:c] = 'c'
- assert_equal nil, hash[:a][:c]
- assert_equal 'c', dup[:a][:c]
- end
-
- def test_deep_dup_initialize
- zero_hash = Hash.new 0
- hash = { :a => zero_hash }
- dup = hash.deep_dup
- assert_equal 0, dup[:a][44]
- end
-
def test_store_on_indifferent_access
hash = HashWithIndifferentAccess.new
hash.store(:test1, 1)
diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb
index 493eacdc5a..7baebed882 100644
--- a/railties/lib/rails/configuration.rb
+++ b/railties/lib/rails/configuration.rb
@@ -1,6 +1,8 @@
require 'active_support/deprecation'
require 'active_support/ordered_options'
+require 'active_support/core_ext/object'
require 'active_support/core_ext/hash/deep_dup'
+require 'active_support/core_ext/array/deep_dup'
require 'rails/paths'
require 'rails/rack'
--
cgit v1.2.3
From aa5dd1439b49ae0e4a0574238ade338f9d05080b Mon Sep 17 00:00:00 2001
From: Alexey Gaziev
Date: Tue, 24 Apr 2012 14:05:38 +0400
Subject: Guides for deep_dup
---
.../source/active_support_core_extensions.textile | 64 ++++++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile
index e4a6e145b9..98f9a67ca7 100644
--- a/guides/source/active_support_core_extensions.textile
+++ b/guides/source/active_support_core_extensions.textile
@@ -154,6 +154,40 @@ WARNING. Any class can disallow duplication removing +dup+ and +clone+ or raisin
NOTE: Defined in +active_support/core_ext/object/duplicable.rb+.
+h4. +deep_dup+
+
+When data is very big and have many layers we need some recursive method to duplicate it right. For example, if we want to duplicate Array with some string inside and then work with this string as with part of duplicated object.
+
+
+array = ['string']
+dup = array.dup
+dup[0] << '?'
+array.object_id == dup.object_id # => false
+array[0] == dup[0] # => true
+
+
+Active Support provides +deep_dup+ to dup all objects recursively inside deep dupilicated Array or Hash:
+
+If object can be duplicable - then it is just an alias for dup.
+
+
+string = 'abc'
+dup = string.deep_dup
+string.object_id == dup.object_id # => false
+
+
+If not - this method will return original object.
+
+
+number = 1
+dup = number.deep_dup
+number.object_id == dup.object_id # => true
+
+
+WARNING. The same as in +duplicable?+ because +deep_dup+ uses that method.
+
+NOTE: Defined in +active_support/core_ext/object/deep_dup.rb+.
+
h4. +try+
Sometimes you want to call a method provided the receiver object is not +nil+, which is something you usually check first. +try+ is like +Object#send+ except that it returns +nil+ if sent to +nil+.
@@ -2217,6 +2251,19 @@ Thus, in this case the behavior is different for +nil+, and the differences with
NOTE: Defined in +active_support/core_ext/array/wrap.rb+.
+h4. Duplicating
+
+The method +Array.deep_dup+ duplicates itself and all objects inside recursively with ActiveSupport method +Object#deep_dup+. It works like +Array#map+ with sending +deep_dup+ method to each object inside.
+
+
+array = [1, [2, 3]]
+dup = array.deep_dup
+dup[1][2] = 4
+array[1][2] == nil # => true
+
+
+NOTE: Defined in +active_support/core_ext/array/deep_dup.rb+.
+
h4. Grouping
h5. +in_groups_of(number, fill_with = nil)+
@@ -2423,6 +2470,23 @@ The method +deep_merge!+ performs a deep merge in place.
NOTE: Defined in +active_support/core_ext/hash/deep_merge.rb+.
+h4. Deep duplicating
+
+The method +Hash.deep_dup+ duplicates itself and all keys and values inside recursively with ActiveSupport method +Object#deep_dup+. It works like +Enumerator#each_with_object+ with sending +deep_dup+ method to each pair inside.
+
+
+hash = { :a => 1, :b => { :c => 2, :d => [3, 4] } }
+
+dup = hash.deep_dup
+dup[:b][:e] = 5
+dup[:b][:d] << 5
+
+hash[:b][:e] == nil # => true
+hash[:b][:d] == [3, 4] # => true
+
+
+NOTE: Defined in +active_support/core_ext/hash/deep_dup.rb+.
+
h4. Diffing
The method +diff+ returns a hash that represents a diff of the receiver and the argument with the following logic:
--
cgit v1.2.3
From 5a2a72df0fba466461980d5a3a368015c349176f Mon Sep 17 00:00:00 2001
From: Shaliko Usubov
Date: Sun, 6 May 2012 21:49:31 +0400
Subject: Change unless + else into if + else
---
actionpack/lib/action_view/helpers/date_helper.rb | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb
index 6bd8e62e0d..f0a593d2c1 100644
--- a/actionpack/lib/action_view/helpers/date_helper.rb
+++ b/actionpack/lib/action_view/helpers/date_helper.rb
@@ -66,12 +66,12 @@ module ActionView
# distance_of_time_in_words(Time.now, Time.now) # => less than a minute
#
def distance_of_time_in_words(from_time, to_time = 0, include_seconds_or_options = {}, options = {})
- unless include_seconds_or_options.is_a?(Hash)
+ if include_seconds_or_options.is_a?(Hash)
+ options = include_seconds_or_options
+ else
ActiveSupport::Deprecation.warn "distance_of_time_in_words and time_ago_in_words now accept :include_seconds " +
"as a part of options hash, not a boolean argument", caller
options[:include_seconds] ||= !!include_seconds_or_options
- else
- options = include_seconds_or_options
end
from_time = from_time.to_time if from_time.respond_to?(:to_time)
--
cgit v1.2.3
From 352d033ab9d9a03f3222aedefbc11e29a1fb5ffa Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Sun, 6 May 2012 10:53:27 -0700
Subject: Reword guide entry for `deep_dup` method.
---
.../source/active_support_core_extensions.textile | 37 ++++++++++++++--------
1 file changed, 23 insertions(+), 14 deletions(-)
diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile
index 98f9a67ca7..ab5ceaf2b3 100644
--- a/guides/source/active_support_core_extensions.textile
+++ b/guides/source/active_support_core_extensions.textile
@@ -156,27 +156,38 @@ NOTE: Defined in +active_support/core_ext/object/duplicable.rb+.
h4. +deep_dup+
-When data is very big and have many layers we need some recursive method to duplicate it right. For example, if we want to duplicate Array with some string inside and then work with this string as with part of duplicated object.
+The +deep_dup+ method returns deep copy of given object. Normally, when you +dup+ an object that contains other objects, ruby does not +dup+ them. If you have array with a string, for example, it will look like this:
-array = ['string']
-dup = array.dup
-dup[0] << '?'
-array.object_id == dup.object_id # => false
-array[0] == dup[0] # => true
+array = ['string']
+duplicate = array.dup
+
+duplicate.push 'another-string'
+
+array #=> ['string']
+duplicate #=> ['string', 'another-string']
+
+duplicate.first.gsub!('string', 'foo')
+
+array #=> ['foo']
+duplicate #=> ['foo', 'another-string']
-Active Support provides +deep_dup+ to dup all objects recursively inside deep dupilicated Array or Hash:
+As you can see, after duplicating +Array+ instance, we got another object, therefore we can modify it and the original object will stay unchanged. This is not true for array's elements, however. Since +dup+ does not make deep copy, the string inside array is still the same object.
-If object can be duplicable - then it is just an alias for dup.
+If you need a deep copy of an object, you should use +deep_dup+ in such situation:
-string = 'abc'
-dup = string.deep_dup
-string.object_id == dup.object_id # => false
+array = ['string']
+duplicate = array.dup
+
+duplicate.first.gsub!('string', 'foo')
+
+array #=> ['string']
+duplicate #=> ['foo']
-If not - this method will return original object.
+If object is not duplicable +deep_dup+ will just return this object:
number = 1
@@ -184,8 +195,6 @@ dup = number.deep_dup
number.object_id == dup.object_id # => true
-WARNING. The same as in +duplicable?+ because +deep_dup+ uses that method.
-
NOTE: Defined in +active_support/core_ext/object/deep_dup.rb+.
h4. +try+
--
cgit v1.2.3
From 040392860886d9362b33c6c8ef99113a99dd18cf Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Sun, 6 May 2012 10:56:38 -0700
Subject: Updated CHANGELOG entry for `deep_dup`
---
activesupport/CHANGELOG.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index 82921741b8..b02cefa600 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,5 +1,7 @@
## Rails 4.0.0 (unreleased) ##
+* `deep_dup` works more expectedly now and duplicates also values in +Hash+ instances and elements in +Array+ instances. *Alexey Gaziev*
+
* Inflector no longer applies ice -> ouse to words like slice, police, ets *Wes Morgan*
* Add `ActiveSupport::Deprecations.behavior = :silence` to completely ignore Rails runtime deprecations *twinturbo*
--
cgit v1.2.3
From 98553a5574a37f96b90acb8dcfa64b4c15a93de4 Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Sun, 6 May 2012 11:12:54 -0700
Subject: Keep all methods in object/deep_dup
---
activesupport/lib/active_support/core_ext/array.rb | 1 -
.../lib/active_support/core_ext/array/deep_dup.rb | 6 ------
activesupport/lib/active_support/core_ext/hash.rb | 1 -
.../lib/active_support/core_ext/hash/deep_dup.rb | 8 --------
.../lib/active_support/core_ext/object/deep_dup.rb | 16 ++++++++++++++++
activesupport/test/core_ext/deep_dup_test.rb | 3 +--
6 files changed, 17 insertions(+), 18 deletions(-)
delete mode 100644 activesupport/lib/active_support/core_ext/array/deep_dup.rb
delete mode 100644 activesupport/lib/active_support/core_ext/hash/deep_dup.rb
diff --git a/activesupport/lib/active_support/core_ext/array.rb b/activesupport/lib/active_support/core_ext/array.rb
index d6e1398a27..79ba79192a 100644
--- a/activesupport/lib/active_support/core_ext/array.rb
+++ b/activesupport/lib/active_support/core_ext/array.rb
@@ -1,7 +1,6 @@
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/array/access'
require 'active_support/core_ext/array/uniq_by'
-require 'active_support/core_ext/array/deep_dup'
require 'active_support/core_ext/array/conversions'
require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/array/grouping'
diff --git a/activesupport/lib/active_support/core_ext/array/deep_dup.rb b/activesupport/lib/active_support/core_ext/array/deep_dup.rb
deleted file mode 100644
index 82f9805236..0000000000
--- a/activesupport/lib/active_support/core_ext/array/deep_dup.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-class Array
- # Returns a deep copy of array.
- def deep_dup
- map { |it| it.deep_dup }
- end
-end
diff --git a/activesupport/lib/active_support/core_ext/hash.rb b/activesupport/lib/active_support/core_ext/hash.rb
index fd1cda991e..501483498d 100644
--- a/activesupport/lib/active_support/core_ext/hash.rb
+++ b/activesupport/lib/active_support/core_ext/hash.rb
@@ -1,6 +1,5 @@
require 'active_support/core_ext/hash/conversions'
require 'active_support/core_ext/hash/deep_merge'
-require 'active_support/core_ext/hash/deep_dup'
require 'active_support/core_ext/hash/diff'
require 'active_support/core_ext/hash/except'
require 'active_support/core_ext/hash/indifferent_access'
diff --git a/activesupport/lib/active_support/core_ext/hash/deep_dup.rb b/activesupport/lib/active_support/core_ext/hash/deep_dup.rb
deleted file mode 100644
index 882f27623e..0000000000
--- a/activesupport/lib/active_support/core_ext/hash/deep_dup.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-class Hash
- # Returns a deep copy of hash.
- def deep_dup
- each_with_object(dup) do |(key, value), hash|
- hash[key.deep_dup] = value.deep_dup
- end
- end
-end
diff --git a/activesupport/lib/active_support/core_ext/object/deep_dup.rb b/activesupport/lib/active_support/core_ext/object/deep_dup.rb
index daae98dde1..2c4383ac94 100644
--- a/activesupport/lib/active_support/core_ext/object/deep_dup.rb
+++ b/activesupport/lib/active_support/core_ext/object/deep_dup.rb
@@ -4,3 +4,19 @@ class Object
duplicable? ? dup : self
end
end
+
+class Array
+ # Returns a deep copy of array.
+ def deep_dup
+ map { |it| it.deep_dup }
+ end
+end
+
+class Hash
+ # Returns a deep copy of hash.
+ def deep_dup
+ each_with_object(dup) do |(key, value), hash|
+ hash[key.deep_dup] = value.deep_dup
+ end
+ end
+end
diff --git a/activesupport/test/core_ext/deep_dup_test.rb b/activesupport/test/core_ext/deep_dup_test.rb
index 2a00fc5315..91d558dbb5 100644
--- a/activesupport/test/core_ext/deep_dup_test.rb
+++ b/activesupport/test/core_ext/deep_dup_test.rb
@@ -1,6 +1,5 @@
+require 'abstract_unit'
require 'active_support/core_ext/object'
-require 'active_support/core_ext/array'
-require 'active_support/core_ext/hash'
class DeepDupTest < ActiveSupport::TestCase
--
cgit v1.2.3
From 93742701b5e1e55599a89c536dd343885086b2a0 Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Sun, 6 May 2012 10:54:25 -0700
Subject: Use deep_dup in aciverecord default columns assignment
---
activerecord/lib/active_record/core.rb | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index 9a76c9f617..a869ed8c04 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -1,6 +1,6 @@
require 'active_support/concern'
require 'active_support/core_ext/hash/indifferent_access'
-require 'active_support/core_ext/object/duplicable'
+require 'active_support/core_ext/object/deep_dup'
require 'thread'
module ActiveRecord
@@ -166,9 +166,7 @@ module ActiveRecord
# # Instantiates a single new object bypassing mass-assignment security
# User.new({ :first_name => 'Jamie', :is_admin => true }, :without_protection => true)
def initialize(attributes = nil, options = {})
- # TODO: use deep_dup after fixing it to also dup values
- defaults = Hash[self.class.column_defaults.map { |k, v| [k, v.duplicable? ? v.dup : v] }]
- @attributes = self.class.initialize_attributes(defaults)
+ @attributes = self.class.initialize_attributes(self.class.column_defaults.deep_dup)
@columns_hash = self.class.column_types.dup
init_internals
--
cgit v1.2.3
From 346bb018499cde6699fcce6c68dd7e9be45c75e1 Mon Sep 17 00:00:00 2001
From: Dmitry Vorotilin
Date: Fri, 4 May 2012 18:40:32 +0400
Subject: More faster rails dbconsole
---
railties/lib/rails/commands.rb | 3 +-
railties/lib/rails/commands/dbconsole.rb | 38 ++++++++++----
railties/test/commands/dbconsole_test.rb | 85 +++++++++++++++++++++-----------
3 files changed, 86 insertions(+), 40 deletions(-)
diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb
index 82cdd6053b..7f473c237c 100644
--- a/railties/lib/rails/commands.rb
+++ b/railties/lib/rails/commands.rb
@@ -57,8 +57,7 @@ when 'server'
when 'dbconsole'
require 'rails/commands/dbconsole'
- require APP_PATH
- Rails::DBConsole.start(Rails.application)
+ Rails::DBConsole.start
when 'application', 'runner'
require "rails/commands/#{command}"
diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb
index 25a8caeec3..aaba47117f 100644
--- a/railties/lib/rails/commands/dbconsole.rb
+++ b/railties/lib/rails/commands/dbconsole.rb
@@ -5,15 +5,37 @@ require 'rbconfig'
module Rails
class DBConsole
- attr_reader :arguments
+ attr_reader :arguments, :config
- def self.start(app)
- new(app).start
+ def self.start
+ new(config).start
end
- def initialize(app, arguments = ARGV)
- @app = app
- @arguments = arguments
+ def self.config
+ config = begin
+ YAML.load(ERB.new(IO.read("config/database.yml")).result)
+ rescue SyntaxError, StandardError
+ require APP_PATH
+ Rails.application.config.database_configuration
+ end
+
+ unless config[env]
+ abort "No database is configured for the environment '#{env}'"
+ end
+
+ config[env]
+ end
+
+ def self.env
+ if Rails.respond_to?(:env)
+ Rails.env
+ else
+ ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
+ end
+ end
+
+ def initialize(config, arguments = ARGV)
+ @config, @arguments = config, arguments
end
def start
@@ -38,10 +60,6 @@ module Rails
abort opt.to_s unless (0..1).include?(arguments.size)
end
- unless config = @app.config.database_configuration[Rails.env]
- abort "No database is configured for the environment '#{Rails.env}'"
- end
-
case config["adapter"]
when /^mysql/
diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb
index 0bf417c014..5ef7ceef3b 100644
--- a/railties/test/commands/dbconsole_test.rb
+++ b/railties/test/commands/dbconsole_test.rb
@@ -3,42 +3,70 @@ require 'rails/commands/dbconsole'
class Rails::DBConsoleTest < ActiveSupport::TestCase
def teardown
- %w[PGUSER PGHOST PGPORT PGPASSWORD'].each{|key| ENV.delete(key)}
+ %w[PGUSER PGHOST PGPORT PGPASSWORD].each{|key| ENV.delete(key)}
end
- def test_no_database_configured
- start [], false
+ def test_config
+ Rails::DBConsole.const_set(:APP_PATH, "erb")
+
+ app_config({})
+ capture_abort { Rails::DBConsole.config }
assert aborted
assert_match /No database is configured for the environment '\w+'/, output
+
+ app_config(development: "with_init")
+ assert_equal Rails::DBConsole.config, "with_init"
+
+ app_db_file("development:\n without_init")
+ assert_equal Rails::DBConsole.config, "without_init"
+
+ app_db_file("development:\n <%= Rails.something_app_specific %>")
+ assert_equal Rails::DBConsole.config, "with_init"
+
+ app_db_file("development:\n\ninvalid")
+ assert_equal Rails::DBConsole.config, "with_init"
+ end
+
+ def test_env
+ assert_equal Rails::DBConsole.env, "development"
+
+ Rails.stubs(:respond_to?).with(:env).returns(false)
+ assert_equal Rails::DBConsole.env, "development"
+
+ ENV['RACK_ENV'] = "rack_env"
+ assert_equal Rails::DBConsole.env, "rack_env"
+
+ ENV['RAILS_ENV'] = "rails_env"
+ assert_equal Rails::DBConsole.env, "rails_env"
end
def test_mysql
dbconsole.expects(:find_cmd_and_exec).with(%w[mysql mysql5], 'db')
- start [], {adapter: 'mysql', database: 'db'}
+ start(adapter: 'mysql', database: 'db')
assert !aborted
end
def test_mysql_full
dbconsole.expects(:find_cmd_and_exec).with(%w[mysql mysql5], '--host=locahost', '--port=1234', '--socket=socket', '--user=user', '--default-character-set=UTF-8', '-p', 'db')
- start [], {adapter: 'mysql', database: 'db', host: 'locahost', port: 1234, socket: 'socket', username: 'user', password: 'qwerty', encoding: 'UTF-8'}
+ start(adapter: 'mysql', database: 'db', host: 'locahost', port: 1234, socket: 'socket', username: 'user', password: 'qwerty', encoding: 'UTF-8')
assert !aborted
end
def test_mysql_include_password
dbconsole.expects(:find_cmd_and_exec).with(%w[mysql mysql5], '--user=user', '--password=qwerty', 'db')
- start ['-p'], {adapter: 'mysql', database: 'db', username: 'user', password: 'qwerty'}
+ start({adapter: 'mysql', database: 'db', username: 'user', password: 'qwerty'}, ['-p'])
assert !aborted
end
def test_postgresql
dbconsole.expects(:find_cmd_and_exec).with('psql', 'db')
- start [], {adapter: 'postgresql', database: 'db'}
+ start(adapter: 'postgresql', database: 'db')
assert !aborted
end
def test_postgresql_full
dbconsole.expects(:find_cmd_and_exec).with('psql', 'db')
- start [], {adapter: 'postgresql', database: 'db', username: 'user', password: 'q1w2e3', host: 'host', port: 5432}
+ start(adapter: 'postgresql', database: 'db', username: 'user', password: 'q1w2e3', host: 'host', port: 5432)
assert !aborted
assert_equal 'user', ENV['PGUSER']
assert_equal 'host', ENV['PGHOST']
@@ -48,7 +76,7 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase
def test_postgresql_include_password
dbconsole.expects(:find_cmd_and_exec).with('psql', 'db')
- start ['-p'], {adapter: 'postgresql', database: 'db', username: 'user', password: 'q1w2e3'}
+ start({adapter: 'postgresql', database: 'db', username: 'user', password: 'q1w2e3'}, ['-p'])
assert !aborted
assert_equal 'user', ENV['PGUSER']
assert_equal 'q1w2e3', ENV['PGPASSWORD']
@@ -56,42 +84,42 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase
def test_sqlite
dbconsole.expects(:find_cmd_and_exec).with('sqlite', 'db')
- start [], {adapter: 'sqlite', database: 'db'}
+ start(adapter: 'sqlite', database: 'db')
assert !aborted
end
def test_sqlite3
dbconsole.expects(:find_cmd_and_exec).with('sqlite3', 'db')
- start [], {adapter: 'sqlite3', database: 'db'}
+ start(adapter: 'sqlite3', database: 'db')
assert !aborted
end
def test_sqlite3_mode
dbconsole.expects(:find_cmd_and_exec).with('sqlite3', '-html', 'db')
- start ['--mode', 'html'], {adapter: 'sqlite3', database: 'db'}
+ start({adapter: 'sqlite3', database: 'db'}, ['--mode', 'html'])
assert !aborted
end
def test_sqlite3_header
dbconsole.expects(:find_cmd_and_exec).with('sqlite3', '-header', 'db')
- start ['--header'], {adapter: 'sqlite3', database: 'db'}
+ start({adapter: 'sqlite3', database: 'db'}, ['--header'])
assert !aborted
end
def test_oracle
dbconsole.expects(:find_cmd_and_exec).with('sqlplus', 'user@db')
- start [], {adapter: 'oracle', database: 'db', username: 'user', password: 'secret'}
+ start(adapter: 'oracle', database: 'db', username: 'user', password: 'secret')
assert !aborted
end
def test_oracle_include_password
dbconsole.expects(:find_cmd_and_exec).with('sqlplus', 'user/secret@db')
- start ['-p'], {adapter: 'oracle', database: 'db', username: 'user', password: 'secret'}
+ start({adapter: 'oracle', database: 'db', username: 'user', password: 'secret'}, ['-p'])
assert !aborted
end
def test_unknown_command_line_client
- start [], {adapter: 'unknown', database: 'db'}
+ start(adapter: 'unknown', database: 'db')
assert aborted
assert_match /Unknown command-line client for db/, output
end
@@ -100,29 +128,30 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase
attr_reader :aborted, :output
def dbconsole
- @dbconsole ||= Rails::DBConsole.new(app)
+ @dbconsole ||= Rails::DBConsole.new(nil)
end
- def start(argv = [], database_configuration = {})
- dbconsole.stubs(arguments: argv)
- app.config.stubs(database_configuration: {
- Rails.env => database_configuration ? database_configuration.stringify_keys : database_configuration
- })
+ def start(config = {}, argv = [])
+ dbconsole.stubs(config: config.stringify_keys, arguments: argv)
+ capture_abort { dbconsole.start }
+ end
+ def capture_abort
@aborted = false
@output = capture(:stderr) do
begin
- dbconsole.start
+ yield
rescue SystemExit
@aborted = true
end
end
end
- def app
- @app ||= begin
- config = mock("config")
- stub("app", config: config)
- end
+ def app_db_file(result)
+ IO.stubs(:read).with("config/database.yml").returns(result)
+ end
+
+ def app_config(result)
+ Rails.application.config.stubs(:database_configuration).returns(result.stringify_keys)
end
end
--
cgit v1.2.3
From 9d03e20b1969c267a524873907f6993e351cfc97 Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Sun, 6 May 2012 12:33:02 -0700
Subject: Remove obsolete deep_dup requires
---
railties/lib/rails/configuration.rb | 2 --
1 file changed, 2 deletions(-)
diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb
index 7baebed882..3d66019e5e 100644
--- a/railties/lib/rails/configuration.rb
+++ b/railties/lib/rails/configuration.rb
@@ -1,8 +1,6 @@
require 'active_support/deprecation'
require 'active_support/ordered_options'
require 'active_support/core_ext/object'
-require 'active_support/core_ext/hash/deep_dup'
-require 'active_support/core_ext/array/deep_dup'
require 'rails/paths'
require 'rails/rack'
--
cgit v1.2.3
From a29bc1cf7b8580a815523e4c3a79e931f03ab8c2 Mon Sep 17 00:00:00 2001
From: Jeremy Kemper
Date: Sun, 6 May 2012 12:44:03 -0700
Subject: Fix that optimized named routes should also work as singleton methods
on the url_helpers module
---
.../lib/action_dispatch/routing/route_set.rb | 3 ++-
actionpack/test/dispatch/routing_test.rb | 24 ++++++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 7abd7bd008..8fc0f283fc 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -188,7 +188,8 @@ module ActionDispatch
remove_possible_method :#{selector}
def #{selector}(*args)
if #{optimize_helper?(route)} && args.size == #{route.required_parts.size} && !args.last.is_a?(Hash) && optimize_routes_generation?
- options = #{options.inspect}.merge!(url_options)
+ options = #{options.inspect}
+ options.merge!(url_options) if respond_to?(:url_options)
options[:path] = "#{optimized_helper(route)}"
ActionDispatch::Http::URL.url_for(options)
else
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index c8e1b34b99..e5345754cd 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -2538,3 +2538,27 @@ class TestConstraintsAccessingParameters < ActionDispatch::IntegrationTest
assert_equal "bar", @request.params[:bar]
end
end
+
+class TestOptimizedNamedRoutes < ActionDispatch::IntegrationTest
+ Routes = ActionDispatch::Routing::RouteSet.new.tap do |app|
+ app.draw do
+ ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] }
+ get '/foo' => ok, as: :foo
+ end
+ end
+
+ include Routes.url_helpers
+ def app; Routes end
+
+ test 'enabled when not mounted and default_url_options is empty' do
+ assert Routes.url_helpers.optimize_routes_generation?
+ end
+
+ test 'named route called as singleton method' do
+ assert_equal '/foo', Routes.url_helpers.foo_path
+ end
+
+ test 'named route called on included module' do
+ assert_equal '/foo', foo_path
+ end
+end
--
cgit v1.2.3
From 3ac93d662933ee032227da0bcce57807c7d57889 Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Sun, 6 May 2012 19:06:49 -0700
Subject: [guides] Add comments to deep_dup example, fix second example [ci
skip]
---
guides/source/active_support_core_extensions.textile | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile
index ab5ceaf2b3..c56cb0b9e5 100644
--- a/guides/source/active_support_core_extensions.textile
+++ b/guides/source/active_support_core_extensions.textile
@@ -164,11 +164,13 @@ duplicate = array.dup
duplicate.push 'another-string'
+# object was duplicated, element added only to duplicate
array #=> ['string']
duplicate #=> ['string', 'another-string']
duplicate.first.gsub!('string', 'foo')
+# first element was not duplicated, it will be changed for both arrays
array #=> ['foo']
duplicate #=> ['foo', 'another-string']
@@ -179,7 +181,7 @@ If you need a deep copy of an object, you should use +deep_dup+ in such situatio
array = ['string']
-duplicate = array.dup
+duplicate = array.deep_dup
duplicate.first.gsub!('string', 'foo')
--
cgit v1.2.3
From 552f535796b92df57ae7e7ea339307c45683c71b Mon Sep 17 00:00:00 2001
From: Mark Rushakoff
Date: Sun, 6 May 2012 20:40:48 -0700
Subject: are ran -> are run
The former is grammatically incorrect.
---
guides/source/configuring.textile | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/guides/source/configuring.textile b/guides/source/configuring.textile
index 59f12e98ab..5bfb45f778 100644
--- a/guides/source/configuring.textile
+++ b/guides/source/configuring.textile
@@ -182,13 +182,13 @@ The full set of methods that can be used in this block are as follows:
* +force_plural+ allows pluralized model names. Defaults to +false+.
* +helper+ defines whether or not to generate helpers. Defaults to +true+.
* +integration_tool+ defines which integration tool to use. Defaults to +nil+.
-* +javascripts+ turns on the hook for javascripts in generators. Used in Rails for when the +scaffold+ generator is ran. Defaults to +true+.
+* +javascripts+ turns on the hook for javascripts in generators. Used in Rails for when the +scaffold+ generator is run. Defaults to +true+.
* +javascript_engine+ configures the engine to be used (for eg. coffee) when generating assets. Defaults to +nil+.
* +orm+ defines which orm to use. Defaults to +false+ and will use Active Record by default.
* +performance_tool+ defines which performance tool to use. Defaults to +nil+.
* +resource_controller+ defines which generator to use for generating a controller when using +rails generate resource+. Defaults to +:controller+.
* +scaffold_controller+ different from +resource_controller+, defines which generator to use for generating a _scaffolded_ controller when using +rails generate scaffold+. Defaults to +:scaffold_controller+.
-* +stylesheets+ turns on the hook for stylesheets in generators. Used in Rails for when the +scaffold+ generator is ran, but this hook can be used in other generates as well. Defaults to +true+.
+* +stylesheets+ turns on the hook for stylesheets in generators. Used in Rails for when the +scaffold+ generator is run, but this hook can be used in other generates as well. Defaults to +true+.
* +stylesheet_engine+ configures the stylesheet engine (for eg. sass) to be used when generating assets. Defaults to +:css+.
* +test_framework+ defines which test framework to use. Defaults to +false+ and will use Test::Unit by default.
* +template_engine+ defines which template engine to use, such as ERB or Haml. Defaults to +:erb+.
@@ -585,13 +585,13 @@ TIP: If you have any ordering dependency in your initializers, you can control t
h3. Initialization events
-Rails has 5 initialization events which can be hooked into (listed in the order that they are ran):
+Rails has 5 initialization events which can be hooked into (listed in the order that they are run):
* +before_configuration+: This is run as soon as the application constant inherits from +Rails::Application+. The +config+ calls are evaluated before this happens.
* +before_initialize+: This is run directly before the initialization process of the application occurs with the +:bootstrap_hook+ initializer near the beginning of the Rails initialization process.
-* +to_prepare+: Run after the initializers are ran for all Railties (including the application itself), but before eager loading and the middleware stack is built. More importantly, will run upon every request in +development+, but only once (during boot-up) in +production+ and +test+.
+* +to_prepare+: Run after the initializers are run for all Railties (including the application itself), but before eager loading and the middleware stack is built. More importantly, will run upon every request in +development+, but only once (during boot-up) in +production+ and +test+.
* +before_eager_load+: This is run directly before eager loading occurs, which is the default behaviour for the _production_ environment and not for the +development+ environment.
@@ -732,7 +732,7 @@ The error occurred while evaluating nil.each
*+load_config_initializers+* Loads all Ruby files from +config/initializers+ in the application, railties and engines. The files in this directory can be used to hold configuration settings that should be made after all of the frameworks are loaded.
-*+engines_blank_point+* Provides a point-in-initialization to hook into if you wish to do anything before engines are loaded. After this point, all railtie and engine initializers are ran.
+*+engines_blank_point+* Provides a point-in-initialization to hook into if you wish to do anything before engines are loaded. After this point, all railtie and engine initializers are run.
*+add_generator_templates+* Finds templates for generators at +lib/templates+ for the application, railities and engines and adds these to the +config.generators.templates+ setting, which will make the templates available for all generators to reference.
--
cgit v1.2.3
From 055857841ad53fcc1ccd20756f085690bd221646 Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Sun, 6 May 2012 21:36:59 -0700
Subject: Ensure that Rails.env is equal to "test" by default when running
tests.
Rails.env when running tests on localhost differs from travis ci
which makes it harder to write tests that check env related things.
---
railties/test/abstract_unit.rb | 2 ++
1 file changed, 2 insertions(+)
diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb
index 29ebdc6511..dfcf5aa27d 100644
--- a/railties/test/abstract_unit.rb
+++ b/railties/test/abstract_unit.rb
@@ -1,3 +1,5 @@
+ENV["RAILS_ENV"] ||= "test"
+
require File.expand_path("../../../load_paths", __FILE__)
require 'stringio'
--
cgit v1.2.3
From d98bbdee14384ff2e99e2f1716a8dff681521dea Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Sun, 6 May 2012 21:38:34 -0700
Subject: Fix build
---
railties/test/commands/dbconsole_test.rb | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb
index 5ef7ceef3b..85a7edfacd 100644
--- a/railties/test/commands/dbconsole_test.rb
+++ b/railties/test/commands/dbconsole_test.rb
@@ -14,30 +14,33 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase
assert aborted
assert_match /No database is configured for the environment '\w+'/, output
- app_config(development: "with_init")
+ app_config(test: "with_init")
assert_equal Rails::DBConsole.config, "with_init"
- app_db_file("development:\n without_init")
+ app_db_file("test:\n without_init")
assert_equal Rails::DBConsole.config, "without_init"
- app_db_file("development:\n <%= Rails.something_app_specific %>")
+ app_db_file("test:\n <%= Rails.something_app_specific %>")
assert_equal Rails::DBConsole.config, "with_init"
- app_db_file("development:\n\ninvalid")
+ app_db_file("test:\n\ninvalid")
assert_equal Rails::DBConsole.config, "with_init"
end
def test_env
- assert_equal Rails::DBConsole.env, "development"
+ assert_equal Rails::DBConsole.env, "test"
Rails.stubs(:respond_to?).with(:env).returns(false)
- assert_equal Rails::DBConsole.env, "development"
+ assert_equal Rails::DBConsole.env, "test"
+ ENV['RAILS_ENV'] = nil
ENV['RACK_ENV'] = "rack_env"
assert_equal Rails::DBConsole.env, "rack_env"
ENV['RAILS_ENV'] = "rails_env"
assert_equal Rails::DBConsole.env, "rails_env"
+ ensure
+ ENV['RAILS_ENV'] = "test"
end
def test_mysql
@@ -138,7 +141,7 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase
def capture_abort
@aborted = false
- @output = capture(:stderr) do
+ @output = capture(:stderr) do
begin
yield
rescue SystemExit
--
cgit v1.2.3
From 9f3637fad5bb68b13a6d004694ba8d2b5e6b8d9d Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Mon, 7 May 2012 00:33:26 -0500
Subject: adding observer example
---
activemodel/README.rdoc | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/activemodel/README.rdoc b/activemodel/README.rdoc
index 1fd75141f8..0c7089598c 100644
--- a/activemodel/README.rdoc
+++ b/activemodel/README.rdoc
@@ -135,6 +135,16 @@ behavior out of the box:
pattern in a Rails App and take advantage of all the standard observer
functions.
+ class PersonObserver < ActiveModel::Observer
+ def after_create(person)
+ person.logger.info("New person added!")
+ end
+
+ def after_destroy(person)
+ person.logger.warn("Person with an id of #{person.id} was destroyed!")
+ end
+ end
+
{Learn more}[link:classes/ActiveModel/Observer.html]
* Making objects serializable
--
cgit v1.2.3
From c962680e1902d2c9474f0be8ba7b0b8ab361cae6 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Mon, 7 May 2012 00:40:00 -0500
Subject: fixing active model links in readme
---
activemodel/README.rdoc | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/activemodel/README.rdoc b/activemodel/README.rdoc
index 0c7089598c..1485709991 100644
--- a/activemodel/README.rdoc
+++ b/activemodel/README.rdoc
@@ -53,7 +53,7 @@ behavior out of the box:
person.clear_name
person.clear_age
- {Learn more}[link:classes/ActiveModel/AttributeMethods.html]
+ {Learn more}[http://api.rubyonrails.org/classes/ActiveModel/AttributeMethods.html]
* Callbacks for certain operations
@@ -71,7 +71,7 @@ behavior out of the box:
This generates +before_create+, +around_create+ and +after_create+
class methods that wrap your create method.
- {Learn more}[link:classes/ActiveModel/Callbacks.html]
+ {Learn more}[http://api.rubyonrails.org/classes/ActiveModel/Callbacks.html]
* Tracking value changes
@@ -88,7 +88,7 @@ behavior out of the box:
person.save
person.previous_changes # => {'name' => ['bob, 'robert']}
- {Learn more}[link:classes/ActiveModel/Dirty.html]
+ {Learn more}[http://api.rubyonrails.org/classes/ActiveModel/Dirty.html]
* Adding +errors+ interface to objects
@@ -116,7 +116,7 @@ behavior out of the box:
person.errors.full_messages
# => ["Name can not be nil"]
- {Learn more}[link:classes/ActiveModel/Errors.html]
+ {Learn more}[http://api.rubyonrails.org/classes/ActiveModel/Errors.html]
* Model name introspection
@@ -127,7 +127,7 @@ behavior out of the box:
NamedPerson.model_name # => "NamedPerson"
NamedPerson.model_name.human # => "Named person"
- {Learn more}[link:classes/ActiveModel/Naming.html]
+ {Learn more}[http://api.rubyonrails.org/ActiveModel/Naming.html]
* Observer support
@@ -145,7 +145,7 @@ behavior out of the box:
end
end
- {Learn more}[link:classes/ActiveModel/Observer.html]
+ {Learn more}[http://api.rubyonrails.org/classes/ActiveModel/Observer.html]
* Making objects serializable
@@ -157,7 +157,7 @@ behavior out of the box:
s.to_json # => "{\"name\":null}"
s.to_xml # => "\n "My attribute"
- {Learn more}[link:classes/ActiveModel/Translation.html]
+ {Learn more}[http://api.rubyonrails.org/classes/ActiveModel/Translation.html]
* Validation support
@@ -186,7 +186,7 @@ behavior out of the box:
person.first_name = 'zoolander'
person.valid? # => false
- {Learn more}[link:classes/ActiveModel/Validations.html]
+ {Learn more}[http://api.rubyonrails.org/classes/ActiveModel/Validations.html]
* Custom validators
@@ -208,7 +208,7 @@ behavior out of the box:
p.name = "Bob"
p.valid? # => true
- {Learn more}[link:classes/ActiveModel/Validator.html]
+ {Learn more}[http://api.rubyonrails.org/classes/ActiveModel/Validator.html]
== Download and installation
--
cgit v1.2.3
From 79f1daf2cef87c706cdaa98398de3e5cf401e839 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Mon, 7 May 2012 00:45:54 -0500
Subject: marking some active model classes
---
activemodel/README.rdoc | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/activemodel/README.rdoc b/activemodel/README.rdoc
index 1485709991..b8c7846c1d 100644
--- a/activemodel/README.rdoc
+++ b/activemodel/README.rdoc
@@ -75,7 +75,7 @@ behavior out of the box:
* Tracking value changes
- The ActiveModel::Dirty module allows for tracking attribute changes:
+ The +ActiveModel::Dirty+ module allows for tracking attribute changes:
person = Person.new
person.name # => nil
@@ -131,7 +131,7 @@ behavior out of the box:
* Observer support
- ActiveModel::Observers allows your object to implement the Observer
+ +ActiveModel::Observers+ allows your object to implement the Observer
pattern in a Rails App and take advantage of all the standard observer
functions.
@@ -149,7 +149,7 @@ behavior out of the box:
* Making objects serializable
- ActiveModel::Serialization provides a standard interface for your object
+ +ActiveModel::Serialization+ provides a standard interface for your object
to provide +to_json+ or +to_xml+ serialization.
s = SerialPerson.new
--
cgit v1.2.3
From 204a79fe61051dac19ac854f22f22ca4288162b8 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Mon, 7 May 2012 00:48:19 -0500
Subject: fixing marked actived model classes in readme
---
activemodel/README.rdoc | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/activemodel/README.rdoc b/activemodel/README.rdoc
index b8c7846c1d..df9ca93051 100644
--- a/activemodel/README.rdoc
+++ b/activemodel/README.rdoc
@@ -75,7 +75,7 @@ behavior out of the box:
* Tracking value changes
- The +ActiveModel::Dirty+ module allows for tracking attribute changes:
+ The ActiveModel::Dirty module allows for tracking attribute changes:
person = Person.new
person.name # => nil
@@ -131,7 +131,7 @@ behavior out of the box:
* Observer support
- +ActiveModel::Observers+ allows your object to implement the Observer
+ ActiveModel::Observers allows your object to implement the Observer
pattern in a Rails App and take advantage of all the standard observer
functions.
@@ -149,7 +149,7 @@ behavior out of the box:
* Making objects serializable
- +ActiveModel::Serialization+ provides a standard interface for your object
+ ActiveModel::Serialization provides a standard interface for your object
to provide +to_json+ or +to_xml+ serialization.
s = SerialPerson.new
--
cgit v1.2.3
From cf243be4d5c50d0df28b7a51f403584184a17fb2 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Mon, 7 May 2012 12:18:51 +0530
Subject: note that WIP guides are not in the index menu [ci skip]
---
guides/source/index.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/guides/source/index.html.erb b/guides/source/index.html.erb
index 5439459b42..74805b2754 100644
--- a/guides/source/index.html.erb
+++ b/guides/source/index.html.erb
@@ -13,7 +13,7 @@ Ruby on Rails Guides
and <%= link_to 'Free Kindle Reading Apps', 'http://www.amazon.com/gp/kindle/kcp' %> for the iPad,
iPhone, Mac, Android, etc. Download them from <%= link_to 'here', @mobi %>.
-
Guides marked with this icon are currently being worked on. While they might still be useful to you, they may contain incomplete information and even errors. You can help by reviewing them and posting your comments and corrections to the author.
+
Guides marked with this icon are currently being worked on and will not be available in the Guides Index menu. While still useful, they may contain incomplete information and even errors. You can help by reviewing them and posting your comments and corrections.
<% end %>
--
cgit v1.2.3
From 8c4777f446d9e14deb077f44d31579a5a96e68ae Mon Sep 17 00:00:00 2001
From: "Mark J. Titorenko"
Date: Mon, 7 May 2012 12:04:51 +0100
Subject: Added documentation for +beginning_of_hour+ and +end_of_hour+ to
Active Support Core Extensions guide.
---
.../source/active_support_core_extensions.textile | 31 ++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile
index e4a6e145b9..a238a84e8c 100644
--- a/guides/source/active_support_core_extensions.textile
+++ b/guides/source/active_support_core_extensions.textile
@@ -3064,6 +3064,28 @@ date.end_of_day # => Sun Jun 06 23:59:59 +0200 2010
+beginning_of_day+ is aliased to +at_beginning_of_day+, +midnight+, +at_midnight+.
+h6. +beginning_of_hour+, +end_of_hour+
+
+The method +beginning_of_hour+ returns a timestamp at the beginning of the hour (hh:00:00):
+
+
+date = DateTime.new(2010, 6, 7, 19, 55, 25)
+date.beginning_of_hour # => Mon Jun 07 19:00:00 +0200 2010
+
+
+The method +end_of_hour+ returns a timestamp at the end of the hour (hh:59:59):
+
+
+date = DateTime.new(2010, 6, 7, 19, 55, 25)
+date.end_of_hour # => Mon Jun 07 19:59:59 +0200 2010
+
+
++beginning_of_hour+ is aliased to +at_beginning_of_hour+.
+
+INFO: +beginning_of_hour+ and +end_of_hour+ are implemented for +Time+ and +DateTime+ but *not* +Date+ as it does not make sense to request the beginning or end of an hour on a +Date+ instance.
+
+NOTE: All the following methods are defined in +active_support/core_ext/date/calculations.rb+.
+
h6. +ago+, +since+
The method +ago+ receives a number of seconds as argument and returns a timestamp those many seconds ago from midnight:
@@ -3131,6 +3153,13 @@ since (in)
On the other hand, +advance+ and +change+ are also defined and support more options, they are documented below.
+The following methods are only implemented in +active_support/core_ext/date_time/calculations.rb+ as they only make sense when used with a +DateTime+ instance:
+
+
+beginning_of_hour (at_beginning_of_hour)
+end_of_hour
+
+
h5. Named Datetimes
h6. +DateTime.current+
@@ -3273,6 +3302,8 @@ ago
since (in)
beginning_of_day (midnight, at_midnight, at_beginning_of_day)
end_of_day
+beginning_of_hour (at_beginning_of_hour)
+end_of_hour
beginning_of_week (at_beginning_of_week)
end_of_week (at_end_of_week)
monday
--
cgit v1.2.3
From f174e8dcef66446cb7483c48dc746887b29078b6 Mon Sep 17 00:00:00 2001
From: "Mark J. Titorenko"
Date: Mon, 7 May 2012 12:07:35 +0100
Subject: Corrections to +beginning_of_day+ and +end_of_day+ example dates.
---
guides/source/active_support_core_extensions.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile
index a238a84e8c..c9e9a13c09 100644
--- a/guides/source/active_support_core_extensions.textile
+++ b/guides/source/active_support_core_extensions.textile
@@ -3052,14 +3052,14 @@ The method +beginning_of_day+ returns a timestamp at the beginning of the day (0
date = Date.new(2010, 6, 7)
-date.beginning_of_day # => Sun Jun 07 00:00:00 +0200 2010
+date.beginning_of_day # => Mon Jun 07 00:00:00 +0200 2010
The method +end_of_day+ returns a timestamp at the end of the day (23:59:59):
date = Date.new(2010, 6, 7)
-date.end_of_day # => Sun Jun 06 23:59:59 +0200 2010
+date.end_of_day # => Mon Jun 07 23:59:59 +0200 2010
+beginning_of_day+ is aliased to +at_beginning_of_day+, +midnight+, +at_midnight+.
--
cgit v1.2.3
From 61587b18d2b4b03041cc7e54da00cff6344abeec Mon Sep 17 00:00:00 2001
From: "Mark J. Titorenko"
Date: Mon, 7 May 2012 12:24:40 +0100
Subject: Remove accidentally pasted NOTE section during introduction of
+beginning_of_hour+ and +end_of_hour+ documentation.
---
guides/source/active_support_core_extensions.textile | 2 --
1 file changed, 2 deletions(-)
diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile
index c9e9a13c09..43dc0c12cf 100644
--- a/guides/source/active_support_core_extensions.textile
+++ b/guides/source/active_support_core_extensions.textile
@@ -3084,8 +3084,6 @@ date.end_of_hour # => Mon Jun 07 19:59:59 +0200 2010
INFO: +beginning_of_hour+ and +end_of_hour+ are implemented for +Time+ and +DateTime+ but *not* +Date+ as it does not make sense to request the beginning or end of an hour on a +Date+ instance.
-NOTE: All the following methods are defined in +active_support/core_ext/date/calculations.rb+.
-
h6. +ago+, +since+
The method +ago+ receives a number of seconds as argument and returns a timestamp those many seconds ago from midnight:
--
cgit v1.2.3
From 89fff791fa55da09d39b09c7a5e5afe066f79f85 Mon Sep 17 00:00:00 2001
From: Rob Zolkos
Date: Mon, 7 May 2012 21:43:05 +1000
Subject: Doc for ActiveRecord::Result empty? method
---
activerecord/lib/active_record/result.rb | 1 +
1 file changed, 1 insertion(+)
diff --git a/activerecord/lib/active_record/result.rb b/activerecord/lib/active_record/result.rb
index fb4b89b87b..fd276ccf5d 100644
--- a/activerecord/lib/active_record/result.rb
+++ b/activerecord/lib/active_record/result.rb
@@ -28,6 +28,7 @@ module ActiveRecord
alias :map! :map
alias :collect! :map
+ # Returns true if there are no records.
def empty?
rows.empty?
end
--
cgit v1.2.3
From 9250e24db313b1e1c46abf6e73a51b81d2ac19b4 Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Mon, 7 May 2012 17:47:24 +0530
Subject: Locking ruby-prof for now.
Need to investigate why build is failing because of
ruby-prof.
---
Gemfile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Gemfile b/Gemfile
index 005031d843..10202ca877 100644
--- a/Gemfile
+++ b/Gemfile
@@ -50,7 +50,7 @@ instance_eval File.read local_gemfile if File.exists? local_gemfile
platforms :mri do
group :test do
- gem 'ruby-prof'
+ gem 'ruby-prof', '0.10.8'
end
end
--
cgit v1.2.3
From bc06e8d706fd8818d434c66f46d2e889ca24bd2d Mon Sep 17 00:00:00 2001
From: Ayrton De Craene
Date: Mon, 7 May 2012 15:40:08 +0200
Subject: Compressed all images from the guide through ImageOptim which saves
sometimes up to 74.6% in size [ci skip]
---
guides/assets/images/belongs_to.png | Bin 34017 -> 26076 bytes
guides/assets/images/book_icon.gif | Bin 337 -> 329 bytes
guides/assets/images/challenge.png | Bin 54134 -> 33373 bytes
guides/assets/images/chapters_icon.gif | Bin 628 -> 620 bytes
guides/assets/images/check_bullet.gif | Bin 384 -> 376 bytes
guides/assets/images/credits_pic_blank.gif | Bin 613 -> 597 bytes
guides/assets/images/csrf.png | Bin 41996 -> 32179 bytes
guides/assets/images/customized_error_messages.png | Bin 5055 -> 2561 bytes
guides/assets/images/edge_badge.png | Bin 7945 -> 5964 bytes
guides/assets/images/error_messages.png | Bin 14645 -> 10964 bytes
guides/assets/images/feature_tile.gif | Bin 43 -> 35 bytes
guides/assets/images/footer_tile.gif | Bin 44 -> 36 bytes
guides/assets/images/fxn.png | Bin 20664 -> 15434 bytes
.../images/getting_started/confirm_dialog.png | Bin 36070 -> 29542 bytes
.../images/getting_started/form_with_errors.png | Bin 20820 -> 14031 bytes
.../index_action_with_edit_link.png | Bin 15547 -> 9772 bytes
guides/assets/images/getting_started/new_post.png | Bin 14334 -> 5888 bytes
.../images/getting_started/post_with_comments.png | Bin 31630 -> 18496 bytes
.../routing_error_no_controller.png | Bin 15744 -> 6268 bytes
.../routing_error_no_route_matches.png | Bin 16065 -> 6508 bytes
.../getting_started/show_action_for_posts.png | Bin 6885 -> 2991 bytes
.../template_is_missing_posts_new.png | Bin 15168 -> 5851 bytes
.../getting_started/undefined_method_post_path.png | Bin 15254 -> 9217 bytes
.../unknown_action_create_for_posts.png | Bin 12652 -> 4146 bytes
.../unknown_action_new_for_posts.png | Bin 12756 -> 4208 bytes
guides/assets/images/grey_bullet.gif | Bin 45 -> 37 bytes
guides/assets/images/habtm.png | Bin 63801 -> 49325 bytes
guides/assets/images/has_many.png | Bin 38582 -> 28988 bytes
guides/assets/images/has_many_through.png | Bin 100220 -> 79428 bytes
guides/assets/images/has_one.png | Bin 39022 -> 29072 bytes
guides/assets/images/has_one_through.png | Bin 92594 -> 72434 bytes
guides/assets/images/header_backdrop.png | Bin 882 -> 224 bytes
guides/assets/images/header_tile.gif | Bin 44 -> 36 bytes
guides/assets/images/i18n/demo_html_safe.png | Bin 11946 -> 10073 bytes
.../assets/images/i18n/demo_localized_pirate.png | Bin 15027 -> 11485 bytes
guides/assets/images/i18n/demo_translated_en.png | Bin 12057 -> 9325 bytes
.../assets/images/i18n/demo_translated_pirate.png | Bin 13392 -> 10202 bytes
.../images/i18n/demo_translation_missing.png | Bin 13143 -> 10260 bytes
guides/assets/images/i18n/demo_untranslated.png | Bin 11925 -> 9224 bytes
guides/assets/images/icons/callouts/1.png | Bin 329 -> 147 bytes
guides/assets/images/icons/callouts/10.png | Bin 361 -> 183 bytes
guides/assets/images/icons/callouts/11.png | Bin 565 -> 290 bytes
guides/assets/images/icons/callouts/12.png | Bin 617 -> 322 bytes
guides/assets/images/icons/callouts/13.png | Bin 623 -> 328 bytes
guides/assets/images/icons/callouts/14.png | Bin 411 -> 246 bytes
guides/assets/images/icons/callouts/15.png | Bin 640 -> 340 bytes
guides/assets/images/icons/callouts/2.png | Bin 353 -> 168 bytes
guides/assets/images/icons/callouts/3.png | Bin 350 -> 170 bytes
guides/assets/images/icons/callouts/4.png | Bin 345 -> 165 bytes
guides/assets/images/icons/callouts/5.png | Bin 348 -> 169 bytes
guides/assets/images/icons/callouts/6.png | Bin 355 -> 176 bytes
guides/assets/images/icons/callouts/7.png | Bin 344 -> 160 bytes
guides/assets/images/icons/callouts/8.png | Bin 357 -> 176 bytes
guides/assets/images/icons/callouts/9.png | Bin 357 -> 177 bytes
guides/assets/images/icons/caution.png | Bin 2554 -> 2300 bytes
guides/assets/images/icons/example.png | Bin 2354 -> 2079 bytes
guides/assets/images/icons/home.png | Bin 1340 -> 1163 bytes
guides/assets/images/icons/important.png | Bin 2657 -> 2451 bytes
guides/assets/images/icons/next.png | Bin 1302 -> 1146 bytes
guides/assets/images/icons/note.png | Bin 2730 -> 2155 bytes
guides/assets/images/icons/prev.png | Bin 1348 -> 1126 bytes
guides/assets/images/icons/tip.png | Bin 2602 -> 2248 bytes
guides/assets/images/icons/up.png | Bin 1320 -> 1133 bytes
guides/assets/images/icons/warning.png | Bin 2828 -> 2616 bytes
guides/assets/images/jaimeiniesta.jpg | Bin 11913 -> 7617 bytes
guides/assets/images/nav_arrow.gif | Bin 427 -> 419 bytes
guides/assets/images/polymorphic.png | Bin 85248 -> 66415 bytes
guides/assets/images/radar.png | Bin 19521 -> 17101 bytes
guides/assets/images/rails_guides_kindle_cover.jpg | Bin 31785 -> 20955 bytes
guides/assets/images/rails_guides_logo.gif | Bin 5114 -> 5106 bytes
guides/assets/images/rails_welcome.png | Bin 121314 -> 71979 bytes
guides/assets/images/session_fixation.png | Bin 47860 -> 38451 bytes
guides/assets/images/tab_grey.gif | Bin 4924 -> 4684 bytes
guides/assets/images/tab_info.gif | Bin 4762 -> 4522 bytes
guides/assets/images/tab_note.gif | Bin 4807 -> 4566 bytes
guides/assets/images/tab_red.gif | Bin 4753 -> 4507 bytes
guides/assets/images/tab_yellow.gif | Bin 4759 -> 4519 bytes
guides/assets/images/tab_yellow.png | Bin 1611 -> 1441 bytes
guides/assets/images/validation_error_messages.png | Bin 1107 -> 583 bytes
guides/assets/images/vijaydev.jpg | Bin 4610 -> 2897 bytes
80 files changed, 0 insertions(+), 0 deletions(-)
diff --git a/guides/assets/images/belongs_to.png b/guides/assets/images/belongs_to.png
index 44243edbca..43c963ffa8 100644
Binary files a/guides/assets/images/belongs_to.png and b/guides/assets/images/belongs_to.png differ
diff --git a/guides/assets/images/book_icon.gif b/guides/assets/images/book_icon.gif
index c81d5db520..efc5e06880 100644
Binary files a/guides/assets/images/book_icon.gif and b/guides/assets/images/book_icon.gif differ
diff --git a/guides/assets/images/challenge.png b/guides/assets/images/challenge.png
index d163748640..30be3d7028 100644
Binary files a/guides/assets/images/challenge.png and b/guides/assets/images/challenge.png differ
diff --git a/guides/assets/images/chapters_icon.gif b/guides/assets/images/chapters_icon.gif
index 06fb415f4a..a61c28c02d 100644
Binary files a/guides/assets/images/chapters_icon.gif and b/guides/assets/images/chapters_icon.gif differ
diff --git a/guides/assets/images/check_bullet.gif b/guides/assets/images/check_bullet.gif
index 1fcfeba250..bd54ef64c9 100644
Binary files a/guides/assets/images/check_bullet.gif and b/guides/assets/images/check_bullet.gif differ
diff --git a/guides/assets/images/credits_pic_blank.gif b/guides/assets/images/credits_pic_blank.gif
index f6f654fc65..a6b335d0c9 100644
Binary files a/guides/assets/images/credits_pic_blank.gif and b/guides/assets/images/credits_pic_blank.gif differ
diff --git a/guides/assets/images/csrf.png b/guides/assets/images/csrf.png
index ab73baafe8..a8123d47c3 100644
Binary files a/guides/assets/images/csrf.png and b/guides/assets/images/csrf.png differ
diff --git a/guides/assets/images/customized_error_messages.png b/guides/assets/images/customized_error_messages.png
index fa676991e3..fcf47b4be0 100644
Binary files a/guides/assets/images/customized_error_messages.png and b/guides/assets/images/customized_error_messages.png differ
diff --git a/guides/assets/images/edge_badge.png b/guides/assets/images/edge_badge.png
index cddd46c4b8..a35dc9f8ee 100644
Binary files a/guides/assets/images/edge_badge.png and b/guides/assets/images/edge_badge.png differ
diff --git a/guides/assets/images/error_messages.png b/guides/assets/images/error_messages.png
index 428892194a..1189e486d4 100644
Binary files a/guides/assets/images/error_messages.png and b/guides/assets/images/error_messages.png differ
diff --git a/guides/assets/images/feature_tile.gif b/guides/assets/images/feature_tile.gif
index 75469361db..ba0171b761 100644
Binary files a/guides/assets/images/feature_tile.gif and b/guides/assets/images/feature_tile.gif differ
diff --git a/guides/assets/images/footer_tile.gif b/guides/assets/images/footer_tile.gif
index bb33fc1ff0..09dbfd2973 100644
Binary files a/guides/assets/images/footer_tile.gif and b/guides/assets/images/footer_tile.gif differ
diff --git a/guides/assets/images/fxn.png b/guides/assets/images/fxn.png
index 9b531ee584..6800fc9bc3 100644
Binary files a/guides/assets/images/fxn.png and b/guides/assets/images/fxn.png differ
diff --git a/guides/assets/images/getting_started/confirm_dialog.png b/guides/assets/images/getting_started/confirm_dialog.png
index a26c09ef2d..1a13eddd91 100644
Binary files a/guides/assets/images/getting_started/confirm_dialog.png and b/guides/assets/images/getting_started/confirm_dialog.png differ
diff --git a/guides/assets/images/getting_started/form_with_errors.png b/guides/assets/images/getting_started/form_with_errors.png
index badefe6ea6..6910e1647e 100644
Binary files a/guides/assets/images/getting_started/form_with_errors.png and b/guides/assets/images/getting_started/form_with_errors.png differ
diff --git a/guides/assets/images/getting_started/index_action_with_edit_link.png b/guides/assets/images/getting_started/index_action_with_edit_link.png
index 6e58a13756..bf23cba231 100644
Binary files a/guides/assets/images/getting_started/index_action_with_edit_link.png and b/guides/assets/images/getting_started/index_action_with_edit_link.png differ
diff --git a/guides/assets/images/getting_started/new_post.png b/guides/assets/images/getting_started/new_post.png
index dc9459032a..b573cb164c 100644
Binary files a/guides/assets/images/getting_started/new_post.png and b/guides/assets/images/getting_started/new_post.png differ
diff --git a/guides/assets/images/getting_started/post_with_comments.png b/guides/assets/images/getting_started/post_with_comments.png
index bd9b2e10f5..e13095ff8f 100644
Binary files a/guides/assets/images/getting_started/post_with_comments.png and b/guides/assets/images/getting_started/post_with_comments.png differ
diff --git a/guides/assets/images/getting_started/routing_error_no_controller.png b/guides/assets/images/getting_started/routing_error_no_controller.png
index 92a39efd78..407ea2ea06 100644
Binary files a/guides/assets/images/getting_started/routing_error_no_controller.png and b/guides/assets/images/getting_started/routing_error_no_controller.png differ
diff --git a/guides/assets/images/getting_started/routing_error_no_route_matches.png b/guides/assets/images/getting_started/routing_error_no_route_matches.png
index bc768a94a2..d461807c5d 100644
Binary files a/guides/assets/images/getting_started/routing_error_no_route_matches.png and b/guides/assets/images/getting_started/routing_error_no_route_matches.png differ
diff --git a/guides/assets/images/getting_started/show_action_for_posts.png b/guides/assets/images/getting_started/show_action_for_posts.png
index 5c8c4d8e5e..9467df6a07 100644
Binary files a/guides/assets/images/getting_started/show_action_for_posts.png and b/guides/assets/images/getting_started/show_action_for_posts.png differ
diff --git a/guides/assets/images/getting_started/template_is_missing_posts_new.png b/guides/assets/images/getting_started/template_is_missing_posts_new.png
index 9f070d59db..6860aaeca7 100644
Binary files a/guides/assets/images/getting_started/template_is_missing_posts_new.png and b/guides/assets/images/getting_started/template_is_missing_posts_new.png differ
diff --git a/guides/assets/images/getting_started/undefined_method_post_path.png b/guides/assets/images/getting_started/undefined_method_post_path.png
index f568bf315c..c29cb2f54f 100644
Binary files a/guides/assets/images/getting_started/undefined_method_post_path.png and b/guides/assets/images/getting_started/undefined_method_post_path.png differ
diff --git a/guides/assets/images/getting_started/unknown_action_create_for_posts.png b/guides/assets/images/getting_started/unknown_action_create_for_posts.png
index 03d92dfb7d..1eca14b988 100644
Binary files a/guides/assets/images/getting_started/unknown_action_create_for_posts.png and b/guides/assets/images/getting_started/unknown_action_create_for_posts.png differ
diff --git a/guides/assets/images/getting_started/unknown_action_new_for_posts.png b/guides/assets/images/getting_started/unknown_action_new_for_posts.png
index b63883d922..fd72586573 100644
Binary files a/guides/assets/images/getting_started/unknown_action_new_for_posts.png and b/guides/assets/images/getting_started/unknown_action_new_for_posts.png differ
diff --git a/guides/assets/images/grey_bullet.gif b/guides/assets/images/grey_bullet.gif
index e75e8e93a1..3c08b1571c 100644
Binary files a/guides/assets/images/grey_bullet.gif and b/guides/assets/images/grey_bullet.gif differ
diff --git a/guides/assets/images/habtm.png b/guides/assets/images/habtm.png
index fea78b0b5c..326b91903a 100644
Binary files a/guides/assets/images/habtm.png and b/guides/assets/images/habtm.png differ
diff --git a/guides/assets/images/has_many.png b/guides/assets/images/has_many.png
index 6cff58460d..e7589e3b75 100644
Binary files a/guides/assets/images/has_many.png and b/guides/assets/images/has_many.png differ
diff --git a/guides/assets/images/has_many_through.png b/guides/assets/images/has_many_through.png
index 85d7599925..858c898dc1 100644
Binary files a/guides/assets/images/has_many_through.png and b/guides/assets/images/has_many_through.png differ
diff --git a/guides/assets/images/has_one.png b/guides/assets/images/has_one.png
index a70ddaaa86..93faa05b07 100644
Binary files a/guides/assets/images/has_one.png and b/guides/assets/images/has_one.png differ
diff --git a/guides/assets/images/has_one_through.png b/guides/assets/images/has_one_through.png
index 89a7617a30..07dac1a27d 100644
Binary files a/guides/assets/images/has_one_through.png and b/guides/assets/images/has_one_through.png differ
diff --git a/guides/assets/images/header_backdrop.png b/guides/assets/images/header_backdrop.png
index ff2982175e..72b030478f 100644
Binary files a/guides/assets/images/header_backdrop.png and b/guides/assets/images/header_backdrop.png differ
diff --git a/guides/assets/images/header_tile.gif b/guides/assets/images/header_tile.gif
index e2c878d492..476b5dbd57 100644
Binary files a/guides/assets/images/header_tile.gif and b/guides/assets/images/header_tile.gif differ
diff --git a/guides/assets/images/i18n/demo_html_safe.png b/guides/assets/images/i18n/demo_html_safe.png
index f881f60dac..9afa8ebec1 100644
Binary files a/guides/assets/images/i18n/demo_html_safe.png and b/guides/assets/images/i18n/demo_html_safe.png differ
diff --git a/guides/assets/images/i18n/demo_localized_pirate.png b/guides/assets/images/i18n/demo_localized_pirate.png
index 9134709573..bf8d0b558c 100644
Binary files a/guides/assets/images/i18n/demo_localized_pirate.png and b/guides/assets/images/i18n/demo_localized_pirate.png differ
diff --git a/guides/assets/images/i18n/demo_translated_en.png b/guides/assets/images/i18n/demo_translated_en.png
index ecdd878d38..e887bfa306 100644
Binary files a/guides/assets/images/i18n/demo_translated_en.png and b/guides/assets/images/i18n/demo_translated_en.png differ
diff --git a/guides/assets/images/i18n/demo_translated_pirate.png b/guides/assets/images/i18n/demo_translated_pirate.png
index 41c580923a..aa5618a865 100644
Binary files a/guides/assets/images/i18n/demo_translated_pirate.png and b/guides/assets/images/i18n/demo_translated_pirate.png differ
diff --git a/guides/assets/images/i18n/demo_translation_missing.png b/guides/assets/images/i18n/demo_translation_missing.png
index af9e2d0427..867aa7c42d 100644
Binary files a/guides/assets/images/i18n/demo_translation_missing.png and b/guides/assets/images/i18n/demo_translation_missing.png differ
diff --git a/guides/assets/images/i18n/demo_untranslated.png b/guides/assets/images/i18n/demo_untranslated.png
index 3603f43463..2ea6404822 100644
Binary files a/guides/assets/images/i18n/demo_untranslated.png and b/guides/assets/images/i18n/demo_untranslated.png differ
diff --git a/guides/assets/images/icons/callouts/1.png b/guides/assets/images/icons/callouts/1.png
index 7d473430b7..c5d02adcf4 100644
Binary files a/guides/assets/images/icons/callouts/1.png and b/guides/assets/images/icons/callouts/1.png differ
diff --git a/guides/assets/images/icons/callouts/10.png b/guides/assets/images/icons/callouts/10.png
index 997bbc8246..fe89f9ef83 100644
Binary files a/guides/assets/images/icons/callouts/10.png and b/guides/assets/images/icons/callouts/10.png differ
diff --git a/guides/assets/images/icons/callouts/11.png b/guides/assets/images/icons/callouts/11.png
index ce47dac3f5..9244a1ac4b 100644
Binary files a/guides/assets/images/icons/callouts/11.png and b/guides/assets/images/icons/callouts/11.png differ
diff --git a/guides/assets/images/icons/callouts/12.png b/guides/assets/images/icons/callouts/12.png
index 31daf4e2f2..ae56459f4c 100644
Binary files a/guides/assets/images/icons/callouts/12.png and b/guides/assets/images/icons/callouts/12.png differ
diff --git a/guides/assets/images/icons/callouts/13.png b/guides/assets/images/icons/callouts/13.png
index 14021a89c2..1181f9f892 100644
Binary files a/guides/assets/images/icons/callouts/13.png and b/guides/assets/images/icons/callouts/13.png differ
diff --git a/guides/assets/images/icons/callouts/14.png b/guides/assets/images/icons/callouts/14.png
index 64014b75fe..4274e6580a 100644
Binary files a/guides/assets/images/icons/callouts/14.png and b/guides/assets/images/icons/callouts/14.png differ
diff --git a/guides/assets/images/icons/callouts/15.png b/guides/assets/images/icons/callouts/15.png
index 0d65765fcf..39304de94f 100644
Binary files a/guides/assets/images/icons/callouts/15.png and b/guides/assets/images/icons/callouts/15.png differ
diff --git a/guides/assets/images/icons/callouts/2.png b/guides/assets/images/icons/callouts/2.png
index 5d09341b2f..8c57970ba9 100644
Binary files a/guides/assets/images/icons/callouts/2.png and b/guides/assets/images/icons/callouts/2.png differ
diff --git a/guides/assets/images/icons/callouts/3.png b/guides/assets/images/icons/callouts/3.png
index ef7b700471..57a33d15b4 100644
Binary files a/guides/assets/images/icons/callouts/3.png and b/guides/assets/images/icons/callouts/3.png differ
diff --git a/guides/assets/images/icons/callouts/4.png b/guides/assets/images/icons/callouts/4.png
index adb8364eb5..f061ab02b8 100644
Binary files a/guides/assets/images/icons/callouts/4.png and b/guides/assets/images/icons/callouts/4.png differ
diff --git a/guides/assets/images/icons/callouts/5.png b/guides/assets/images/icons/callouts/5.png
index 4d7eb46002..b4de02da11 100644
Binary files a/guides/assets/images/icons/callouts/5.png and b/guides/assets/images/icons/callouts/5.png differ
diff --git a/guides/assets/images/icons/callouts/6.png b/guides/assets/images/icons/callouts/6.png
index 0ba694af6c..0e055eec1e 100644
Binary files a/guides/assets/images/icons/callouts/6.png and b/guides/assets/images/icons/callouts/6.png differ
diff --git a/guides/assets/images/icons/callouts/7.png b/guides/assets/images/icons/callouts/7.png
index 472e96f8ac..5ead87d040 100644
Binary files a/guides/assets/images/icons/callouts/7.png and b/guides/assets/images/icons/callouts/7.png differ
diff --git a/guides/assets/images/icons/callouts/8.png b/guides/assets/images/icons/callouts/8.png
index 5e60973c21..cb99545eb6 100644
Binary files a/guides/assets/images/icons/callouts/8.png and b/guides/assets/images/icons/callouts/8.png differ
diff --git a/guides/assets/images/icons/callouts/9.png b/guides/assets/images/icons/callouts/9.png
index a0676d26cc..0ac03602f6 100644
Binary files a/guides/assets/images/icons/callouts/9.png and b/guides/assets/images/icons/callouts/9.png differ
diff --git a/guides/assets/images/icons/caution.png b/guides/assets/images/icons/caution.png
index cb9d5ea0df..031e19c776 100644
Binary files a/guides/assets/images/icons/caution.png and b/guides/assets/images/icons/caution.png differ
diff --git a/guides/assets/images/icons/example.png b/guides/assets/images/icons/example.png
index bba1c0010d..1b0e482059 100644
Binary files a/guides/assets/images/icons/example.png and b/guides/assets/images/icons/example.png differ
diff --git a/guides/assets/images/icons/home.png b/guides/assets/images/icons/home.png
index 37a5231bac..24149d6e78 100644
Binary files a/guides/assets/images/icons/home.png and b/guides/assets/images/icons/home.png differ
diff --git a/guides/assets/images/icons/important.png b/guides/assets/images/icons/important.png
index 1096c23295..dafcf0f59e 100644
Binary files a/guides/assets/images/icons/important.png and b/guides/assets/images/icons/important.png differ
diff --git a/guides/assets/images/icons/next.png b/guides/assets/images/icons/next.png
index 64e126bdda..355b329f5a 100644
Binary files a/guides/assets/images/icons/next.png and b/guides/assets/images/icons/next.png differ
diff --git a/guides/assets/images/icons/note.png b/guides/assets/images/icons/note.png
index 841820f7c4..08d35a6f5c 100644
Binary files a/guides/assets/images/icons/note.png and b/guides/assets/images/icons/note.png differ
diff --git a/guides/assets/images/icons/prev.png b/guides/assets/images/icons/prev.png
index 3e8f12fe24..ea564c865e 100644
Binary files a/guides/assets/images/icons/prev.png and b/guides/assets/images/icons/prev.png differ
diff --git a/guides/assets/images/icons/tip.png b/guides/assets/images/icons/tip.png
index a3a029d898..d834e6d1bb 100644
Binary files a/guides/assets/images/icons/tip.png and b/guides/assets/images/icons/tip.png differ
diff --git a/guides/assets/images/icons/up.png b/guides/assets/images/icons/up.png
index 2db1ce62fa..379f0045af 100644
Binary files a/guides/assets/images/icons/up.png and b/guides/assets/images/icons/up.png differ
diff --git a/guides/assets/images/icons/warning.png b/guides/assets/images/icons/warning.png
index 0b0c419df2..72a8a5d873 100644
Binary files a/guides/assets/images/icons/warning.png and b/guides/assets/images/icons/warning.png differ
diff --git a/guides/assets/images/jaimeiniesta.jpg b/guides/assets/images/jaimeiniesta.jpg
index 445f048d92..aef95222a9 100644
Binary files a/guides/assets/images/jaimeiniesta.jpg and b/guides/assets/images/jaimeiniesta.jpg differ
diff --git a/guides/assets/images/nav_arrow.gif b/guides/assets/images/nav_arrow.gif
index c4f57658d7..ff081819ad 100644
Binary files a/guides/assets/images/nav_arrow.gif and b/guides/assets/images/nav_arrow.gif differ
diff --git a/guides/assets/images/polymorphic.png b/guides/assets/images/polymorphic.png
index ff2fd9f76d..a3cbc4502a 100644
Binary files a/guides/assets/images/polymorphic.png and b/guides/assets/images/polymorphic.png differ
diff --git a/guides/assets/images/radar.png b/guides/assets/images/radar.png
index f61e08763f..caa5b7655b 100644
Binary files a/guides/assets/images/radar.png and b/guides/assets/images/radar.png differ
diff --git a/guides/assets/images/rails_guides_kindle_cover.jpg b/guides/assets/images/rails_guides_kindle_cover.jpg
index 9eb16720a9..f068bd9a04 100644
Binary files a/guides/assets/images/rails_guides_kindle_cover.jpg and b/guides/assets/images/rails_guides_kindle_cover.jpg differ
diff --git a/guides/assets/images/rails_guides_logo.gif b/guides/assets/images/rails_guides_logo.gif
index a24683a34e..9b0ad5af28 100644
Binary files a/guides/assets/images/rails_guides_logo.gif and b/guides/assets/images/rails_guides_logo.gif differ
diff --git a/guides/assets/images/rails_welcome.png b/guides/assets/images/rails_welcome.png
index f2aa210d19..8ad2d351de 100644
Binary files a/guides/assets/images/rails_welcome.png and b/guides/assets/images/rails_welcome.png differ
diff --git a/guides/assets/images/session_fixation.png b/guides/assets/images/session_fixation.png
index 6b084508db..ac3ab01614 100644
Binary files a/guides/assets/images/session_fixation.png and b/guides/assets/images/session_fixation.png differ
diff --git a/guides/assets/images/tab_grey.gif b/guides/assets/images/tab_grey.gif
index e9680b7136..995adb76cf 100644
Binary files a/guides/assets/images/tab_grey.gif and b/guides/assets/images/tab_grey.gif differ
diff --git a/guides/assets/images/tab_info.gif b/guides/assets/images/tab_info.gif
index 458fea9a61..e9dd164f18 100644
Binary files a/guides/assets/images/tab_info.gif and b/guides/assets/images/tab_info.gif differ
diff --git a/guides/assets/images/tab_note.gif b/guides/assets/images/tab_note.gif
index 1d5c171ed6..f9b546c6f8 100644
Binary files a/guides/assets/images/tab_note.gif and b/guides/assets/images/tab_note.gif differ
diff --git a/guides/assets/images/tab_red.gif b/guides/assets/images/tab_red.gif
index daf140b5a8..0613093ddc 100644
Binary files a/guides/assets/images/tab_red.gif and b/guides/assets/images/tab_red.gif differ
diff --git a/guides/assets/images/tab_yellow.gif b/guides/assets/images/tab_yellow.gif
index dc961c99dd..39a3c2dc6a 100644
Binary files a/guides/assets/images/tab_yellow.gif and b/guides/assets/images/tab_yellow.gif differ
diff --git a/guides/assets/images/tab_yellow.png b/guides/assets/images/tab_yellow.png
index cceea6581f..3ab1c56c4d 100644
Binary files a/guides/assets/images/tab_yellow.png and b/guides/assets/images/tab_yellow.png differ
diff --git a/guides/assets/images/validation_error_messages.png b/guides/assets/images/validation_error_messages.png
index 622d35da5d..30e4ca4a3d 100644
Binary files a/guides/assets/images/validation_error_messages.png and b/guides/assets/images/validation_error_messages.png differ
diff --git a/guides/assets/images/vijaydev.jpg b/guides/assets/images/vijaydev.jpg
index e21d3cabfc..fe5e4f1cb4 100644
Binary files a/guides/assets/images/vijaydev.jpg and b/guides/assets/images/vijaydev.jpg differ
--
cgit v1.2.3
From ae0a4ca2e16ff055883f38abb3999b303ba3295c Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Mon, 7 May 2012 09:49:54 -0500
Subject: removing the surrounding +s in active model readme
---
activemodel/README.rdoc | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/activemodel/README.rdoc b/activemodel/README.rdoc
index df9ca93051..1485709991 100644
--- a/activemodel/README.rdoc
+++ b/activemodel/README.rdoc
@@ -75,7 +75,7 @@ behavior out of the box:
* Tracking value changes
- The ActiveModel::Dirty module allows for tracking attribute changes:
+ The ActiveModel::Dirty module allows for tracking attribute changes:
person = Person.new
person.name # => nil
@@ -131,7 +131,7 @@ behavior out of the box:
* Observer support
- ActiveModel::Observers allows your object to implement the Observer
+ ActiveModel::Observers allows your object to implement the Observer
pattern in a Rails App and take advantage of all the standard observer
functions.
@@ -149,7 +149,7 @@ behavior out of the box:
* Making objects serializable
- ActiveModel::Serialization provides a standard interface for your object
+ ActiveModel::Serialization provides a standard interface for your object
to provide +to_json+ or +to_xml+ serialization.
s = SerialPerson.new
--
cgit v1.2.3
From 40b5d2823722fec2c2e02f3ed46f7f47f2205b73 Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Mon, 7 May 2012 17:04:10 +0200
Subject: Revert "Compressed all images from the guide through ImageOptim which
saves sometimes up to 74.6% in size [ci skip]"
Reason: this change can't really be done in docrails,
see http://weblog.rubyonrails.org/2012/3/7/what-is-docrails/
This reverts commit bc06e8d706fd8818d434c66f46d2e889ca24bd2d.
---
guides/assets/images/belongs_to.png | Bin 26076 -> 34017 bytes
guides/assets/images/book_icon.gif | Bin 329 -> 337 bytes
guides/assets/images/challenge.png | Bin 33373 -> 54134 bytes
guides/assets/images/chapters_icon.gif | Bin 620 -> 628 bytes
guides/assets/images/check_bullet.gif | Bin 376 -> 384 bytes
guides/assets/images/credits_pic_blank.gif | Bin 597 -> 613 bytes
guides/assets/images/csrf.png | Bin 32179 -> 41996 bytes
guides/assets/images/customized_error_messages.png | Bin 2561 -> 5055 bytes
guides/assets/images/edge_badge.png | Bin 5964 -> 7945 bytes
guides/assets/images/error_messages.png | Bin 10964 -> 14645 bytes
guides/assets/images/feature_tile.gif | Bin 35 -> 43 bytes
guides/assets/images/footer_tile.gif | Bin 36 -> 44 bytes
guides/assets/images/fxn.png | Bin 15434 -> 20664 bytes
.../images/getting_started/confirm_dialog.png | Bin 29542 -> 36070 bytes
.../images/getting_started/form_with_errors.png | Bin 14031 -> 20820 bytes
.../index_action_with_edit_link.png | Bin 9772 -> 15547 bytes
guides/assets/images/getting_started/new_post.png | Bin 5888 -> 14334 bytes
.../images/getting_started/post_with_comments.png | Bin 18496 -> 31630 bytes
.../routing_error_no_controller.png | Bin 6268 -> 15744 bytes
.../routing_error_no_route_matches.png | Bin 6508 -> 16065 bytes
.../getting_started/show_action_for_posts.png | Bin 2991 -> 6885 bytes
.../template_is_missing_posts_new.png | Bin 5851 -> 15168 bytes
.../getting_started/undefined_method_post_path.png | Bin 9217 -> 15254 bytes
.../unknown_action_create_for_posts.png | Bin 4146 -> 12652 bytes
.../unknown_action_new_for_posts.png | Bin 4208 -> 12756 bytes
guides/assets/images/grey_bullet.gif | Bin 37 -> 45 bytes
guides/assets/images/habtm.png | Bin 49325 -> 63801 bytes
guides/assets/images/has_many.png | Bin 28988 -> 38582 bytes
guides/assets/images/has_many_through.png | Bin 79428 -> 100220 bytes
guides/assets/images/has_one.png | Bin 29072 -> 39022 bytes
guides/assets/images/has_one_through.png | Bin 72434 -> 92594 bytes
guides/assets/images/header_backdrop.png | Bin 224 -> 882 bytes
guides/assets/images/header_tile.gif | Bin 36 -> 44 bytes
guides/assets/images/i18n/demo_html_safe.png | Bin 10073 -> 11946 bytes
.../assets/images/i18n/demo_localized_pirate.png | Bin 11485 -> 15027 bytes
guides/assets/images/i18n/demo_translated_en.png | Bin 9325 -> 12057 bytes
.../assets/images/i18n/demo_translated_pirate.png | Bin 10202 -> 13392 bytes
.../images/i18n/demo_translation_missing.png | Bin 10260 -> 13143 bytes
guides/assets/images/i18n/demo_untranslated.png | Bin 9224 -> 11925 bytes
guides/assets/images/icons/callouts/1.png | Bin 147 -> 329 bytes
guides/assets/images/icons/callouts/10.png | Bin 183 -> 361 bytes
guides/assets/images/icons/callouts/11.png | Bin 290 -> 565 bytes
guides/assets/images/icons/callouts/12.png | Bin 322 -> 617 bytes
guides/assets/images/icons/callouts/13.png | Bin 328 -> 623 bytes
guides/assets/images/icons/callouts/14.png | Bin 246 -> 411 bytes
guides/assets/images/icons/callouts/15.png | Bin 340 -> 640 bytes
guides/assets/images/icons/callouts/2.png | Bin 168 -> 353 bytes
guides/assets/images/icons/callouts/3.png | Bin 170 -> 350 bytes
guides/assets/images/icons/callouts/4.png | Bin 165 -> 345 bytes
guides/assets/images/icons/callouts/5.png | Bin 169 -> 348 bytes
guides/assets/images/icons/callouts/6.png | Bin 176 -> 355 bytes
guides/assets/images/icons/callouts/7.png | Bin 160 -> 344 bytes
guides/assets/images/icons/callouts/8.png | Bin 176 -> 357 bytes
guides/assets/images/icons/callouts/9.png | Bin 177 -> 357 bytes
guides/assets/images/icons/caution.png | Bin 2300 -> 2554 bytes
guides/assets/images/icons/example.png | Bin 2079 -> 2354 bytes
guides/assets/images/icons/home.png | Bin 1163 -> 1340 bytes
guides/assets/images/icons/important.png | Bin 2451 -> 2657 bytes
guides/assets/images/icons/next.png | Bin 1146 -> 1302 bytes
guides/assets/images/icons/note.png | Bin 2155 -> 2730 bytes
guides/assets/images/icons/prev.png | Bin 1126 -> 1348 bytes
guides/assets/images/icons/tip.png | Bin 2248 -> 2602 bytes
guides/assets/images/icons/up.png | Bin 1133 -> 1320 bytes
guides/assets/images/icons/warning.png | Bin 2616 -> 2828 bytes
guides/assets/images/jaimeiniesta.jpg | Bin 7617 -> 11913 bytes
guides/assets/images/nav_arrow.gif | Bin 419 -> 427 bytes
guides/assets/images/polymorphic.png | Bin 66415 -> 85248 bytes
guides/assets/images/radar.png | Bin 17101 -> 19521 bytes
guides/assets/images/rails_guides_kindle_cover.jpg | Bin 20955 -> 31785 bytes
guides/assets/images/rails_guides_logo.gif | Bin 5106 -> 5114 bytes
guides/assets/images/rails_welcome.png | Bin 71979 -> 121314 bytes
guides/assets/images/session_fixation.png | Bin 38451 -> 47860 bytes
guides/assets/images/tab_grey.gif | Bin 4684 -> 4924 bytes
guides/assets/images/tab_info.gif | Bin 4522 -> 4762 bytes
guides/assets/images/tab_note.gif | Bin 4566 -> 4807 bytes
guides/assets/images/tab_red.gif | Bin 4507 -> 4753 bytes
guides/assets/images/tab_yellow.gif | Bin 4519 -> 4759 bytes
guides/assets/images/tab_yellow.png | Bin 1441 -> 1611 bytes
guides/assets/images/validation_error_messages.png | Bin 583 -> 1107 bytes
guides/assets/images/vijaydev.jpg | Bin 2897 -> 4610 bytes
80 files changed, 0 insertions(+), 0 deletions(-)
diff --git a/guides/assets/images/belongs_to.png b/guides/assets/images/belongs_to.png
index 43c963ffa8..44243edbca 100644
Binary files a/guides/assets/images/belongs_to.png and b/guides/assets/images/belongs_to.png differ
diff --git a/guides/assets/images/book_icon.gif b/guides/assets/images/book_icon.gif
index efc5e06880..c81d5db520 100644
Binary files a/guides/assets/images/book_icon.gif and b/guides/assets/images/book_icon.gif differ
diff --git a/guides/assets/images/challenge.png b/guides/assets/images/challenge.png
index 30be3d7028..d163748640 100644
Binary files a/guides/assets/images/challenge.png and b/guides/assets/images/challenge.png differ
diff --git a/guides/assets/images/chapters_icon.gif b/guides/assets/images/chapters_icon.gif
index a61c28c02d..06fb415f4a 100644
Binary files a/guides/assets/images/chapters_icon.gif and b/guides/assets/images/chapters_icon.gif differ
diff --git a/guides/assets/images/check_bullet.gif b/guides/assets/images/check_bullet.gif
index bd54ef64c9..1fcfeba250 100644
Binary files a/guides/assets/images/check_bullet.gif and b/guides/assets/images/check_bullet.gif differ
diff --git a/guides/assets/images/credits_pic_blank.gif b/guides/assets/images/credits_pic_blank.gif
index a6b335d0c9..f6f654fc65 100644
Binary files a/guides/assets/images/credits_pic_blank.gif and b/guides/assets/images/credits_pic_blank.gif differ
diff --git a/guides/assets/images/csrf.png b/guides/assets/images/csrf.png
index a8123d47c3..ab73baafe8 100644
Binary files a/guides/assets/images/csrf.png and b/guides/assets/images/csrf.png differ
diff --git a/guides/assets/images/customized_error_messages.png b/guides/assets/images/customized_error_messages.png
index fcf47b4be0..fa676991e3 100644
Binary files a/guides/assets/images/customized_error_messages.png and b/guides/assets/images/customized_error_messages.png differ
diff --git a/guides/assets/images/edge_badge.png b/guides/assets/images/edge_badge.png
index a35dc9f8ee..cddd46c4b8 100644
Binary files a/guides/assets/images/edge_badge.png and b/guides/assets/images/edge_badge.png differ
diff --git a/guides/assets/images/error_messages.png b/guides/assets/images/error_messages.png
index 1189e486d4..428892194a 100644
Binary files a/guides/assets/images/error_messages.png and b/guides/assets/images/error_messages.png differ
diff --git a/guides/assets/images/feature_tile.gif b/guides/assets/images/feature_tile.gif
index ba0171b761..75469361db 100644
Binary files a/guides/assets/images/feature_tile.gif and b/guides/assets/images/feature_tile.gif differ
diff --git a/guides/assets/images/footer_tile.gif b/guides/assets/images/footer_tile.gif
index 09dbfd2973..bb33fc1ff0 100644
Binary files a/guides/assets/images/footer_tile.gif and b/guides/assets/images/footer_tile.gif differ
diff --git a/guides/assets/images/fxn.png b/guides/assets/images/fxn.png
index 6800fc9bc3..9b531ee584 100644
Binary files a/guides/assets/images/fxn.png and b/guides/assets/images/fxn.png differ
diff --git a/guides/assets/images/getting_started/confirm_dialog.png b/guides/assets/images/getting_started/confirm_dialog.png
index 1a13eddd91..a26c09ef2d 100644
Binary files a/guides/assets/images/getting_started/confirm_dialog.png and b/guides/assets/images/getting_started/confirm_dialog.png differ
diff --git a/guides/assets/images/getting_started/form_with_errors.png b/guides/assets/images/getting_started/form_with_errors.png
index 6910e1647e..badefe6ea6 100644
Binary files a/guides/assets/images/getting_started/form_with_errors.png and b/guides/assets/images/getting_started/form_with_errors.png differ
diff --git a/guides/assets/images/getting_started/index_action_with_edit_link.png b/guides/assets/images/getting_started/index_action_with_edit_link.png
index bf23cba231..6e58a13756 100644
Binary files a/guides/assets/images/getting_started/index_action_with_edit_link.png and b/guides/assets/images/getting_started/index_action_with_edit_link.png differ
diff --git a/guides/assets/images/getting_started/new_post.png b/guides/assets/images/getting_started/new_post.png
index b573cb164c..dc9459032a 100644
Binary files a/guides/assets/images/getting_started/new_post.png and b/guides/assets/images/getting_started/new_post.png differ
diff --git a/guides/assets/images/getting_started/post_with_comments.png b/guides/assets/images/getting_started/post_with_comments.png
index e13095ff8f..bd9b2e10f5 100644
Binary files a/guides/assets/images/getting_started/post_with_comments.png and b/guides/assets/images/getting_started/post_with_comments.png differ
diff --git a/guides/assets/images/getting_started/routing_error_no_controller.png b/guides/assets/images/getting_started/routing_error_no_controller.png
index 407ea2ea06..92a39efd78 100644
Binary files a/guides/assets/images/getting_started/routing_error_no_controller.png and b/guides/assets/images/getting_started/routing_error_no_controller.png differ
diff --git a/guides/assets/images/getting_started/routing_error_no_route_matches.png b/guides/assets/images/getting_started/routing_error_no_route_matches.png
index d461807c5d..bc768a94a2 100644
Binary files a/guides/assets/images/getting_started/routing_error_no_route_matches.png and b/guides/assets/images/getting_started/routing_error_no_route_matches.png differ
diff --git a/guides/assets/images/getting_started/show_action_for_posts.png b/guides/assets/images/getting_started/show_action_for_posts.png
index 9467df6a07..5c8c4d8e5e 100644
Binary files a/guides/assets/images/getting_started/show_action_for_posts.png and b/guides/assets/images/getting_started/show_action_for_posts.png differ
diff --git a/guides/assets/images/getting_started/template_is_missing_posts_new.png b/guides/assets/images/getting_started/template_is_missing_posts_new.png
index 6860aaeca7..9f070d59db 100644
Binary files a/guides/assets/images/getting_started/template_is_missing_posts_new.png and b/guides/assets/images/getting_started/template_is_missing_posts_new.png differ
diff --git a/guides/assets/images/getting_started/undefined_method_post_path.png b/guides/assets/images/getting_started/undefined_method_post_path.png
index c29cb2f54f..f568bf315c 100644
Binary files a/guides/assets/images/getting_started/undefined_method_post_path.png and b/guides/assets/images/getting_started/undefined_method_post_path.png differ
diff --git a/guides/assets/images/getting_started/unknown_action_create_for_posts.png b/guides/assets/images/getting_started/unknown_action_create_for_posts.png
index 1eca14b988..03d92dfb7d 100644
Binary files a/guides/assets/images/getting_started/unknown_action_create_for_posts.png and b/guides/assets/images/getting_started/unknown_action_create_for_posts.png differ
diff --git a/guides/assets/images/getting_started/unknown_action_new_for_posts.png b/guides/assets/images/getting_started/unknown_action_new_for_posts.png
index fd72586573..b63883d922 100644
Binary files a/guides/assets/images/getting_started/unknown_action_new_for_posts.png and b/guides/assets/images/getting_started/unknown_action_new_for_posts.png differ
diff --git a/guides/assets/images/grey_bullet.gif b/guides/assets/images/grey_bullet.gif
index 3c08b1571c..e75e8e93a1 100644
Binary files a/guides/assets/images/grey_bullet.gif and b/guides/assets/images/grey_bullet.gif differ
diff --git a/guides/assets/images/habtm.png b/guides/assets/images/habtm.png
index 326b91903a..fea78b0b5c 100644
Binary files a/guides/assets/images/habtm.png and b/guides/assets/images/habtm.png differ
diff --git a/guides/assets/images/has_many.png b/guides/assets/images/has_many.png
index e7589e3b75..6cff58460d 100644
Binary files a/guides/assets/images/has_many.png and b/guides/assets/images/has_many.png differ
diff --git a/guides/assets/images/has_many_through.png b/guides/assets/images/has_many_through.png
index 858c898dc1..85d7599925 100644
Binary files a/guides/assets/images/has_many_through.png and b/guides/assets/images/has_many_through.png differ
diff --git a/guides/assets/images/has_one.png b/guides/assets/images/has_one.png
index 93faa05b07..a70ddaaa86 100644
Binary files a/guides/assets/images/has_one.png and b/guides/assets/images/has_one.png differ
diff --git a/guides/assets/images/has_one_through.png b/guides/assets/images/has_one_through.png
index 07dac1a27d..89a7617a30 100644
Binary files a/guides/assets/images/has_one_through.png and b/guides/assets/images/has_one_through.png differ
diff --git a/guides/assets/images/header_backdrop.png b/guides/assets/images/header_backdrop.png
index 72b030478f..ff2982175e 100644
Binary files a/guides/assets/images/header_backdrop.png and b/guides/assets/images/header_backdrop.png differ
diff --git a/guides/assets/images/header_tile.gif b/guides/assets/images/header_tile.gif
index 476b5dbd57..e2c878d492 100644
Binary files a/guides/assets/images/header_tile.gif and b/guides/assets/images/header_tile.gif differ
diff --git a/guides/assets/images/i18n/demo_html_safe.png b/guides/assets/images/i18n/demo_html_safe.png
index 9afa8ebec1..f881f60dac 100644
Binary files a/guides/assets/images/i18n/demo_html_safe.png and b/guides/assets/images/i18n/demo_html_safe.png differ
diff --git a/guides/assets/images/i18n/demo_localized_pirate.png b/guides/assets/images/i18n/demo_localized_pirate.png
index bf8d0b558c..9134709573 100644
Binary files a/guides/assets/images/i18n/demo_localized_pirate.png and b/guides/assets/images/i18n/demo_localized_pirate.png differ
diff --git a/guides/assets/images/i18n/demo_translated_en.png b/guides/assets/images/i18n/demo_translated_en.png
index e887bfa306..ecdd878d38 100644
Binary files a/guides/assets/images/i18n/demo_translated_en.png and b/guides/assets/images/i18n/demo_translated_en.png differ
diff --git a/guides/assets/images/i18n/demo_translated_pirate.png b/guides/assets/images/i18n/demo_translated_pirate.png
index aa5618a865..41c580923a 100644
Binary files a/guides/assets/images/i18n/demo_translated_pirate.png and b/guides/assets/images/i18n/demo_translated_pirate.png differ
diff --git a/guides/assets/images/i18n/demo_translation_missing.png b/guides/assets/images/i18n/demo_translation_missing.png
index 867aa7c42d..af9e2d0427 100644
Binary files a/guides/assets/images/i18n/demo_translation_missing.png and b/guides/assets/images/i18n/demo_translation_missing.png differ
diff --git a/guides/assets/images/i18n/demo_untranslated.png b/guides/assets/images/i18n/demo_untranslated.png
index 2ea6404822..3603f43463 100644
Binary files a/guides/assets/images/i18n/demo_untranslated.png and b/guides/assets/images/i18n/demo_untranslated.png differ
diff --git a/guides/assets/images/icons/callouts/1.png b/guides/assets/images/icons/callouts/1.png
index c5d02adcf4..7d473430b7 100644
Binary files a/guides/assets/images/icons/callouts/1.png and b/guides/assets/images/icons/callouts/1.png differ
diff --git a/guides/assets/images/icons/callouts/10.png b/guides/assets/images/icons/callouts/10.png
index fe89f9ef83..997bbc8246 100644
Binary files a/guides/assets/images/icons/callouts/10.png and b/guides/assets/images/icons/callouts/10.png differ
diff --git a/guides/assets/images/icons/callouts/11.png b/guides/assets/images/icons/callouts/11.png
index 9244a1ac4b..ce47dac3f5 100644
Binary files a/guides/assets/images/icons/callouts/11.png and b/guides/assets/images/icons/callouts/11.png differ
diff --git a/guides/assets/images/icons/callouts/12.png b/guides/assets/images/icons/callouts/12.png
index ae56459f4c..31daf4e2f2 100644
Binary files a/guides/assets/images/icons/callouts/12.png and b/guides/assets/images/icons/callouts/12.png differ
diff --git a/guides/assets/images/icons/callouts/13.png b/guides/assets/images/icons/callouts/13.png
index 1181f9f892..14021a89c2 100644
Binary files a/guides/assets/images/icons/callouts/13.png and b/guides/assets/images/icons/callouts/13.png differ
diff --git a/guides/assets/images/icons/callouts/14.png b/guides/assets/images/icons/callouts/14.png
index 4274e6580a..64014b75fe 100644
Binary files a/guides/assets/images/icons/callouts/14.png and b/guides/assets/images/icons/callouts/14.png differ
diff --git a/guides/assets/images/icons/callouts/15.png b/guides/assets/images/icons/callouts/15.png
index 39304de94f..0d65765fcf 100644
Binary files a/guides/assets/images/icons/callouts/15.png and b/guides/assets/images/icons/callouts/15.png differ
diff --git a/guides/assets/images/icons/callouts/2.png b/guides/assets/images/icons/callouts/2.png
index 8c57970ba9..5d09341b2f 100644
Binary files a/guides/assets/images/icons/callouts/2.png and b/guides/assets/images/icons/callouts/2.png differ
diff --git a/guides/assets/images/icons/callouts/3.png b/guides/assets/images/icons/callouts/3.png
index 57a33d15b4..ef7b700471 100644
Binary files a/guides/assets/images/icons/callouts/3.png and b/guides/assets/images/icons/callouts/3.png differ
diff --git a/guides/assets/images/icons/callouts/4.png b/guides/assets/images/icons/callouts/4.png
index f061ab02b8..adb8364eb5 100644
Binary files a/guides/assets/images/icons/callouts/4.png and b/guides/assets/images/icons/callouts/4.png differ
diff --git a/guides/assets/images/icons/callouts/5.png b/guides/assets/images/icons/callouts/5.png
index b4de02da11..4d7eb46002 100644
Binary files a/guides/assets/images/icons/callouts/5.png and b/guides/assets/images/icons/callouts/5.png differ
diff --git a/guides/assets/images/icons/callouts/6.png b/guides/assets/images/icons/callouts/6.png
index 0e055eec1e..0ba694af6c 100644
Binary files a/guides/assets/images/icons/callouts/6.png and b/guides/assets/images/icons/callouts/6.png differ
diff --git a/guides/assets/images/icons/callouts/7.png b/guides/assets/images/icons/callouts/7.png
index 5ead87d040..472e96f8ac 100644
Binary files a/guides/assets/images/icons/callouts/7.png and b/guides/assets/images/icons/callouts/7.png differ
diff --git a/guides/assets/images/icons/callouts/8.png b/guides/assets/images/icons/callouts/8.png
index cb99545eb6..5e60973c21 100644
Binary files a/guides/assets/images/icons/callouts/8.png and b/guides/assets/images/icons/callouts/8.png differ
diff --git a/guides/assets/images/icons/callouts/9.png b/guides/assets/images/icons/callouts/9.png
index 0ac03602f6..a0676d26cc 100644
Binary files a/guides/assets/images/icons/callouts/9.png and b/guides/assets/images/icons/callouts/9.png differ
diff --git a/guides/assets/images/icons/caution.png b/guides/assets/images/icons/caution.png
index 031e19c776..cb9d5ea0df 100644
Binary files a/guides/assets/images/icons/caution.png and b/guides/assets/images/icons/caution.png differ
diff --git a/guides/assets/images/icons/example.png b/guides/assets/images/icons/example.png
index 1b0e482059..bba1c0010d 100644
Binary files a/guides/assets/images/icons/example.png and b/guides/assets/images/icons/example.png differ
diff --git a/guides/assets/images/icons/home.png b/guides/assets/images/icons/home.png
index 24149d6e78..37a5231bac 100644
Binary files a/guides/assets/images/icons/home.png and b/guides/assets/images/icons/home.png differ
diff --git a/guides/assets/images/icons/important.png b/guides/assets/images/icons/important.png
index dafcf0f59e..1096c23295 100644
Binary files a/guides/assets/images/icons/important.png and b/guides/assets/images/icons/important.png differ
diff --git a/guides/assets/images/icons/next.png b/guides/assets/images/icons/next.png
index 355b329f5a..64e126bdda 100644
Binary files a/guides/assets/images/icons/next.png and b/guides/assets/images/icons/next.png differ
diff --git a/guides/assets/images/icons/note.png b/guides/assets/images/icons/note.png
index 08d35a6f5c..841820f7c4 100644
Binary files a/guides/assets/images/icons/note.png and b/guides/assets/images/icons/note.png differ
diff --git a/guides/assets/images/icons/prev.png b/guides/assets/images/icons/prev.png
index ea564c865e..3e8f12fe24 100644
Binary files a/guides/assets/images/icons/prev.png and b/guides/assets/images/icons/prev.png differ
diff --git a/guides/assets/images/icons/tip.png b/guides/assets/images/icons/tip.png
index d834e6d1bb..a3a029d898 100644
Binary files a/guides/assets/images/icons/tip.png and b/guides/assets/images/icons/tip.png differ
diff --git a/guides/assets/images/icons/up.png b/guides/assets/images/icons/up.png
index 379f0045af..2db1ce62fa 100644
Binary files a/guides/assets/images/icons/up.png and b/guides/assets/images/icons/up.png differ
diff --git a/guides/assets/images/icons/warning.png b/guides/assets/images/icons/warning.png
index 72a8a5d873..0b0c419df2 100644
Binary files a/guides/assets/images/icons/warning.png and b/guides/assets/images/icons/warning.png differ
diff --git a/guides/assets/images/jaimeiniesta.jpg b/guides/assets/images/jaimeiniesta.jpg
index aef95222a9..445f048d92 100644
Binary files a/guides/assets/images/jaimeiniesta.jpg and b/guides/assets/images/jaimeiniesta.jpg differ
diff --git a/guides/assets/images/nav_arrow.gif b/guides/assets/images/nav_arrow.gif
index ff081819ad..c4f57658d7 100644
Binary files a/guides/assets/images/nav_arrow.gif and b/guides/assets/images/nav_arrow.gif differ
diff --git a/guides/assets/images/polymorphic.png b/guides/assets/images/polymorphic.png
index a3cbc4502a..ff2fd9f76d 100644
Binary files a/guides/assets/images/polymorphic.png and b/guides/assets/images/polymorphic.png differ
diff --git a/guides/assets/images/radar.png b/guides/assets/images/radar.png
index caa5b7655b..f61e08763f 100644
Binary files a/guides/assets/images/radar.png and b/guides/assets/images/radar.png differ
diff --git a/guides/assets/images/rails_guides_kindle_cover.jpg b/guides/assets/images/rails_guides_kindle_cover.jpg
index f068bd9a04..9eb16720a9 100644
Binary files a/guides/assets/images/rails_guides_kindle_cover.jpg and b/guides/assets/images/rails_guides_kindle_cover.jpg differ
diff --git a/guides/assets/images/rails_guides_logo.gif b/guides/assets/images/rails_guides_logo.gif
index 9b0ad5af28..a24683a34e 100644
Binary files a/guides/assets/images/rails_guides_logo.gif and b/guides/assets/images/rails_guides_logo.gif differ
diff --git a/guides/assets/images/rails_welcome.png b/guides/assets/images/rails_welcome.png
index 8ad2d351de..f2aa210d19 100644
Binary files a/guides/assets/images/rails_welcome.png and b/guides/assets/images/rails_welcome.png differ
diff --git a/guides/assets/images/session_fixation.png b/guides/assets/images/session_fixation.png
index ac3ab01614..6b084508db 100644
Binary files a/guides/assets/images/session_fixation.png and b/guides/assets/images/session_fixation.png differ
diff --git a/guides/assets/images/tab_grey.gif b/guides/assets/images/tab_grey.gif
index 995adb76cf..e9680b7136 100644
Binary files a/guides/assets/images/tab_grey.gif and b/guides/assets/images/tab_grey.gif differ
diff --git a/guides/assets/images/tab_info.gif b/guides/assets/images/tab_info.gif
index e9dd164f18..458fea9a61 100644
Binary files a/guides/assets/images/tab_info.gif and b/guides/assets/images/tab_info.gif differ
diff --git a/guides/assets/images/tab_note.gif b/guides/assets/images/tab_note.gif
index f9b546c6f8..1d5c171ed6 100644
Binary files a/guides/assets/images/tab_note.gif and b/guides/assets/images/tab_note.gif differ
diff --git a/guides/assets/images/tab_red.gif b/guides/assets/images/tab_red.gif
index 0613093ddc..daf140b5a8 100644
Binary files a/guides/assets/images/tab_red.gif and b/guides/assets/images/tab_red.gif differ
diff --git a/guides/assets/images/tab_yellow.gif b/guides/assets/images/tab_yellow.gif
index 39a3c2dc6a..dc961c99dd 100644
Binary files a/guides/assets/images/tab_yellow.gif and b/guides/assets/images/tab_yellow.gif differ
diff --git a/guides/assets/images/tab_yellow.png b/guides/assets/images/tab_yellow.png
index 3ab1c56c4d..cceea6581f 100644
Binary files a/guides/assets/images/tab_yellow.png and b/guides/assets/images/tab_yellow.png differ
diff --git a/guides/assets/images/validation_error_messages.png b/guides/assets/images/validation_error_messages.png
index 30e4ca4a3d..622d35da5d 100644
Binary files a/guides/assets/images/validation_error_messages.png and b/guides/assets/images/validation_error_messages.png differ
diff --git a/guides/assets/images/vijaydev.jpg b/guides/assets/images/vijaydev.jpg
index fe5e4f1cb4..e21d3cabfc 100644
Binary files a/guides/assets/images/vijaydev.jpg and b/guides/assets/images/vijaydev.jpg differ
--
cgit v1.2.3
From 700dd0014b8c19651650923dff28912e7d3607b9 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Mon, 7 May 2012 20:43:04 +0530
Subject: Revert "fixing active model links in readme"
This reverts commit c962680e1902d2c9474f0be8ba7b0b8ab361cae6.
Reason: The links must be relative to work in both edge and stable api
sites.
---
activemodel/README.rdoc | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/activemodel/README.rdoc b/activemodel/README.rdoc
index 1485709991..0c7089598c 100644
--- a/activemodel/README.rdoc
+++ b/activemodel/README.rdoc
@@ -53,7 +53,7 @@ behavior out of the box:
person.clear_name
person.clear_age
- {Learn more}[http://api.rubyonrails.org/classes/ActiveModel/AttributeMethods.html]
+ {Learn more}[link:classes/ActiveModel/AttributeMethods.html]
* Callbacks for certain operations
@@ -71,7 +71,7 @@ behavior out of the box:
This generates +before_create+, +around_create+ and +after_create+
class methods that wrap your create method.
- {Learn more}[http://api.rubyonrails.org/classes/ActiveModel/Callbacks.html]
+ {Learn more}[link:classes/ActiveModel/Callbacks.html]
* Tracking value changes
@@ -88,7 +88,7 @@ behavior out of the box:
person.save
person.previous_changes # => {'name' => ['bob, 'robert']}
- {Learn more}[http://api.rubyonrails.org/classes/ActiveModel/Dirty.html]
+ {Learn more}[link:classes/ActiveModel/Dirty.html]
* Adding +errors+ interface to objects
@@ -116,7 +116,7 @@ behavior out of the box:
person.errors.full_messages
# => ["Name can not be nil"]
- {Learn more}[http://api.rubyonrails.org/classes/ActiveModel/Errors.html]
+ {Learn more}[link:classes/ActiveModel/Errors.html]
* Model name introspection
@@ -127,7 +127,7 @@ behavior out of the box:
NamedPerson.model_name # => "NamedPerson"
NamedPerson.model_name.human # => "Named person"
- {Learn more}[http://api.rubyonrails.org/ActiveModel/Naming.html]
+ {Learn more}[link:classes/ActiveModel/Naming.html]
* Observer support
@@ -145,7 +145,7 @@ behavior out of the box:
end
end
- {Learn more}[http://api.rubyonrails.org/classes/ActiveModel/Observer.html]
+ {Learn more}[link:classes/ActiveModel/Observer.html]
* Making objects serializable
@@ -157,7 +157,7 @@ behavior out of the box:
s.to_json # => "{\"name\":null}"
s.to_xml # => "\n "My attribute"
- {Learn more}[http://api.rubyonrails.org/classes/ActiveModel/Translation.html]
+ {Learn more}[link:classes/ActiveModel/Translation.html]
* Validation support
@@ -186,7 +186,7 @@ behavior out of the box:
person.first_name = 'zoolander'
person.valid? # => false
- {Learn more}[http://api.rubyonrails.org/classes/ActiveModel/Validations.html]
+ {Learn more}[link:classes/ActiveModel/Validations.html]
* Custom validators
@@ -208,7 +208,7 @@ behavior out of the box:
p.name = "Bob"
p.valid? # => true
- {Learn more}[http://api.rubyonrails.org/classes/ActiveModel/Validator.html]
+ {Learn more}[link:classes/ActiveModel/Validator.html]
== Download and installation
--
cgit v1.2.3
From 17ef794299ae10c2a7b8ce7a2da68258267c9720 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Mon, 7 May 2012 11:28:03 -0500
Subject: adding example about using cattr_accessor with subclasses
---
.../lib/active_support/core_ext/class/attribute_accessors.rb | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
index 5cb528cfe9..4f8866ce9d 100644
--- a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
+++ b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
@@ -15,6 +15,14 @@ require 'active_support/core_ext/array/extract_options'
# Person.hair_colors # => [:brown, :black, :blonde, :red]
# Person.new.hair_colors # => [:brown, :black, :blonde, :red]
#
+# class Female < Person
+# end
+#
+# Female.hair_colors << :pink
+# Female.hair_colors # => [:brown, :black, :blonde, :red, :pink]
+# Female.new.hair_colors # => [:brown, :black, :blonde, :red, :pink]
+# Person.hair_colors # => [:brown, :black, :blonde, :red, :pink]
+#
# To opt out of the instance writer method, pass :instance_writer => false.
# To opt out of the instance reader method, pass :instance_reader => false.
# To opt out of both instance methods, pass :instance_accessor => false.
--
cgit v1.2.3
From 7b487e5dc16bcf7f94c031cc1411f940df8c0fc8 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Mon, 7 May 2012 12:39:41 -0500
Subject: added docs to cattr_accessor method
---
.../core_ext/class/attribute_accessors.rb | 62 +++++++++++++++++-----
1 file changed, 50 insertions(+), 12 deletions(-)
diff --git a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
index 4f8866ce9d..72a918f839 100644
--- a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
+++ b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
@@ -7,21 +7,21 @@ require 'active_support/core_ext/array/extract_options'
# also change the value for parent class. Similarly if parent class changes the value
# then that would change the value of subclasses too.
#
-# class Person
-# cattr_accessor :hair_colors
-# end
+# class Person
+# cattr_accessor :hair_colors
+# end
#
-# Person.hair_colors = [:brown, :black, :blonde, :red]
-# Person.hair_colors # => [:brown, :black, :blonde, :red]
-# Person.new.hair_colors # => [:brown, :black, :blonde, :red]
+# Person.hair_colors = [:brown, :black, :blonde, :red]
+# Person.hair_colors # => [:brown, :black, :blonde, :red]
+# Person.new.hair_colors # => [:brown, :black, :blonde, :red]
#
-# class Female < Person
-# end
+# class Female < Person
+# end
#
-# Female.hair_colors << :pink
-# Female.hair_colors # => [:brown, :black, :blonde, :red, :pink]
-# Female.new.hair_colors # => [:brown, :black, :blonde, :red, :pink]
-# Person.hair_colors # => [:brown, :black, :blonde, :red, :pink]
+# Female.hair_colors << :pink
+# Female.hair_colors # => [:brown, :black, :blonde, :red, :pink]
+# Female.new.hair_colors # => [:brown, :black, :blonde, :red, :pink]
+# Person.hair_colors # => [:brown, :black, :blonde, :red, :pink]
#
# To opt out of the instance writer method, pass :instance_writer => false.
# To opt out of the instance reader method, pass :instance_reader => false.
@@ -83,6 +83,44 @@ class Class
end
end
+ # Defines class and instance accessors for class attributes.
+ #
+ # class Person
+ # cattr_accessor :hair_colors
+ # end
+ #
+ # Person.hair_colors = [:brown, :black, :blonde, :red]
+ # Person.hair_colors # => [:brown, :black, :blonde, :red]
+ # Person.new.hair_colors # => [:brown, :black, :blonde, :red]
+ #
+ # If a subclass changes the value then that would also change the value for
+ # parent class. Similarly if parent class changes the value then that would
+ # change the value of subclasses too.
+ #
+ # class Male < Person
+ # end
+ #
+ # Male.hair_colors << :blue
+ # Person.hair_colors # => [:brown, :black, :blonde, :red, :blue]
+ #
+ # To opt out of the instance writer method, pass :instance_writer => false.
+ # To opt out of the instance reader method, pass :instance_reader => false.
+ #
+ # class Person
+ # cattr_accessor :hair_colors, :instance_writer => false, :instance_reader => false
+ # end
+ #
+ # Person.new.hair_colors = [:brown] # => NoMethodError
+ # Person.new.hair_colors # => NoMethodError
+ #
+ # Or pass :instance_accessor => false, to opt out both instance methods.
+ #
+ # class Person
+ # cattr_accessor :hair_colors, :instance_accessor => false
+ # end
+ #
+ # Person.new.hair_colors = [:brown] # => NoMethodError
+ # Person.new.hair_colors # => NoMethodError
def cattr_accessor(*syms, &blk)
cattr_reader(*syms)
cattr_writer(*syms, &blk)
--
cgit v1.2.3
From 66e0e4216c55c29557a2789a96c3847a901ccb30 Mon Sep 17 00:00:00 2001
From: Alexey Gaziev
Date: Mon, 30 Apr 2012 00:40:19 +0400
Subject: Fix some guides for AS core_ext
---
.../source/active_support_core_extensions.textile | 130 +++++++++++----------
1 file changed, 66 insertions(+), 64 deletions(-)
diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile
index e4a6e145b9..4bee3e400e 100644
--- a/guides/source/active_support_core_extensions.textile
+++ b/guides/source/active_support_core_extensions.textile
@@ -1034,49 +1034,6 @@ A model may find it useful to set +:instance_accessor+ to +false+ as a way to pr
NOTE: Defined in +active_support/core_ext/class/attribute_accessors.rb+.
-h4. Class Inheritable Attributes
-
-WARNING: Class Inheritable Attributes are deprecated. It's recommended that you use +Class#class_attribute+ instead.
-
-Class variables are shared down the inheritance tree. Class instance variables are not shared, but they are not inherited either. The macros +class_inheritable_reader+, +class_inheritable_writer+, and +class_inheritable_accessor+ provide accessors for class-level data which is inherited but not shared with children:
-
-
-module ActionController
- class Base
- # FIXME: REVISE/SIMPLIFY THIS COMMENT.
- # The value of allow_forgery_protection is inherited,
- # but its value in a particular class does not affect
- # the value in the rest of the controllers hierarchy.
- class_inheritable_accessor :allow_forgery_protection
- end
-end
-
-
-They accomplish this with class instance variables and cloning on subclassing, there are no class variables involved. Cloning is performed with +dup+ as long as the value is duplicable.
-
-There are some variants specialised in arrays and hashes:
-
-
-class_inheritable_array
-class_inheritable_hash
-
-
-Those writers take any inherited array or hash into account and extend them rather than overwrite them.
-
-As with vanilla class attribute accessors these macros create convenience instance methods for reading and writing. The generation of the writer instance method can be prevented setting +:instance_writer+ to +false+ (not any false value, but exactly +false+):
-
-
-module ActiveRecord
- class Base
- class_inheritable_accessor :default_scoping, :instance_writer => false
- end
-end
-
-
-Since values are copied when a subclass is defined, if the base class changes the attribute after that, the subclass does not see the new value. That's the point.
-
-NOTE: Defined in +active_support/core_ext/class/inheritable_attributes.rb+.
-
h4. Subclasses & Descendants
h5. +subclasses+
@@ -1255,9 +1212,14 @@ Pass a +:separator+ to truncate the string at a natural break:
# => "Oh dear! Oh..."
-In the above example "dear" gets cut first, but then +:separator+ prevents it.
+The option +:separator+ can be a regexp:
+
+
+"Oh dear! Oh dear! I shall be late!".truncate(18, :separator => /\s/)
+# => "Oh dear! Oh..."
+
-WARNING: The option +:separator+ can't be a regexp.
+In above examples "dear" gets cut first, but then +:separator+ prevents it.
NOTE: Defined in +active_support/core_ext/string/filters.rb+.
@@ -1810,6 +1772,43 @@ Singular forms are aliased so you are able to say:
NOTE: Defined in +active_support/core_ext/numeric/bytes.rb+.
+h4. Time
+
+Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years.
+
+These methods use Time#advance for precise date calculations when using from_now, ago, etc.
+as well as adding or subtracting their results from a Time object. For example:
+
+
+# equivalent to Time.now.advance(:months => 1)
+1.month.from_now
+
+# equivalent to Time.now.advance(:years => 2)
+2.years.from_now
+
+# equivalent to Time.now.advance(:months => 4, :years => 5)
+(4.months + 5.years).from_now
+
+
+While these methods provide precise calculation when used as in the examples above, care
+should be taken to note that this is not true if the result of `months', `years', etc is
+converted before use:
+
+
+# equivalent to 30.days.to_i.from_now
+1.month.to_i.from_now
+
+# equivalent to 365.25.days.to_f.from_now
+1.year.to_f.from_now
+
+
+In such cases, Ruby's core
+Date[http://ruby-doc.org/stdlib/libdoc/date/rdoc/Date.html] and
+Time[http://ruby-doc.org/stdlib/libdoc/time/rdoc/Time.html] should be used for precision
+date and time arithmetic.
+
+NOTE: Defined in +active_support/core_ext/numeric/time.rb+.
+
h3. Extensions to +Integer+
h4. +multiple_of?+
@@ -2103,20 +2102,20 @@ To do so it sends +to_xml+ to every item in turn, and collects the results under
By default, the name of the root element is the underscorized and dasherized plural of the name of the class of the first item, provided the rest of elements belong to that type (checked with is_a?) and they are not hashes. In the example above that's "contributors".
-If there's any element that does not belong to the type of the first one the root node becomes "records":
+If there's any element that does not belong to the type of the first one the root node becomes "objects":
[Contributor.first, Commit.first].to_xml
# =>
#
-#
-#
+#
+#
-#
+#
+#
-#
+#
+#
-If the receiver is an array of hashes the root element is by default also "records":
+If the receiver is an array of hashes the root element is by default also "objects":
[{:a => 1, :b => 2}, {:c => 3}].to_xml
# =>
#
-#
-#
+#
+#
-#
+#
+#
-#
+#
+#
WARNING. If the collection is empty the root element is by default "nil-classes". That's a gotcha, for example the root element of the list of contributors above would not be "contributors" if the collection was empty, but "nil-classes". You may use the :root option to ensure a consistent root element.
-The name of children nodes is by default the name of the root node singularized. In the examples above we've seen "contributor" and "record". The option :children allows you to set these node names.
+The name of children nodes is by default the name of the root node singularized. In the examples above we've seen "contributor" and "object". The option :children allows you to set these node names.
The default XML builder is a fresh instance of Builder::XmlMarkup. You can configure your own builder via the :builder option. The method also accepts options like :dasherize and friends, they are forwarded to the builder:
@@ -2707,22 +2706,25 @@ NOTE: Defined in +active_support/core_ext/range/blockless_step.rb+.
h4. +include?+
-The method +Range#include?+ says whether some value falls between the ends of a given instance:
+The methods +Range#include?+ and +Range#===+ say whether some value falls between the ends of a given instance:
(2..3).include?(Math::E) # => true
-Active Support extends this method so that the argument may be another range in turn. In that case we test whether the ends of the argument range belong to the receiver themselves:
+Active Support extends these methods so that the argument may be another range in turn. In that case we test whether the ends of the argument range belong to the receiver themselves:
(1..10).include?(3..7) # => true
(1..10).include?(0..7) # => false
(1..10).include?(3..11) # => false
(1...9).include?(3..9) # => false
-
-WARNING: The original +Range#include?+ is still the one aliased to +Range#===+.
+(1..10) === (3..7) # => true
+(1..10) === (0..7) # => false
+(1..10) === (3..11) # => false
+(1...9) === (3..9) # => false
+
NOTE: Defined in +active_support/core_ext/range/include_range.rb+.
--
cgit v1.2.3
From 8b67a022ec8754e5dab8df2a8bbec37df61a5fc2 Mon Sep 17 00:00:00 2001
From: Alexey Gaziev
Date: Mon, 30 Apr 2012 01:14:52 +0400
Subject: Added tests for comparsion operator for Range
---
activesupport/test/core_ext/range_ext_test.rb | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/activesupport/test/core_ext/range_ext_test.rb b/activesupport/test/core_ext/range_ext_test.rb
index cf1ec448c2..9c3389ba82 100644
--- a/activesupport/test/core_ext/range_ext_test.rb
+++ b/activesupport/test/core_ext/range_ext_test.rb
@@ -41,6 +41,18 @@ class RangeTest < ActiveSupport::TestCase
assert((1..10).include?(1...10))
end
+ def test_should_compare_identical_inclusive
+ assert((1..10) === (1..10))
+ end
+
+ def test_should_compare_identical_exclusive
+ assert((1...10) === (1...10))
+ end
+
+ def test_should_compare_other_with_exlusive_end
+ assert((1..10) === (1...10))
+ end
+
def test_exclusive_end_should_not_include_identical_with_inclusive_end
assert !(1...10).include?(1..10)
end
--
cgit v1.2.3
From d785b292a8c921989f606696dff3765836d1fb44 Mon Sep 17 00:00:00 2001
From: Alexey Gaziev
Date: Mon, 7 May 2012 22:40:59 +0400
Subject: Changes for numeric api for Time because Time.current works different
---
activesupport/lib/active_support/core_ext/numeric/time.rb | 6 +++---
guides/source/active_support_core_extensions.textile | 8 ++++----
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/activesupport/lib/active_support/core_ext/numeric/time.rb b/activesupport/lib/active_support/core_ext/numeric/time.rb
index 822f766af7..2bf3d1f278 100644
--- a/activesupport/lib/active_support/core_ext/numeric/time.rb
+++ b/activesupport/lib/active_support/core_ext/numeric/time.rb
@@ -8,13 +8,13 @@ class Numeric
# These methods use Time#advance for precise date calculations when using from_now, ago, etc.
# as well as adding or subtracting their results from a Time object. For example:
#
- # # equivalent to Time.now.advance(:months => 1)
+ # # equivalent to Time.current.advance(:months => 1)
# 1.month.from_now
#
- # # equivalent to Time.now.advance(:years => 2)
+ # # equivalent to Time.current.advance(:years => 2)
# 2.years.from_now
#
- # # equivalent to Time.now.advance(:months => 4, :years => 5)
+ # # equivalent to Time.current.advance(:months => 4, :years => 5)
# (4.months + 5.years).from_now
#
# While these methods provide precise calculation when used as in the examples above, care
diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile
index 4bee3e400e..52c1cea4b9 100644
--- a/guides/source/active_support_core_extensions.textile
+++ b/guides/source/active_support_core_extensions.textile
@@ -184,7 +184,7 @@ You can evaluate code in the context of any object's singleton class using +clas
class Proc
def bind(object)
- block, time = self, Time.now
+ block, time = self, Time.current
object.class_eval do
method_name = "__bind_#{time.to_i}_#{time.usec}"
define_method(method_name, &block)
@@ -1780,13 +1780,13 @@ These methods use Time#advance for precise date calculations when using from_now
as well as adding or subtracting their results from a Time object. For example:
-# equivalent to Time.now.advance(:months => 1)
+# equivalent to Time.current.advance(:months => 1)
1.month.from_now
-# equivalent to Time.now.advance(:years => 2)
+# equivalent to Time.current.advance(:years => 2)
2.years.from_now
-# equivalent to Time.now.advance(:months => 4, :years => 5)
+# equivalent to Time.current.advance(:months => 4, :years => 5)
(4.months + 5.years).from_now
--
cgit v1.2.3
From 4d0e6db9ec7537401d05f523ba8b29955f84f846 Mon Sep 17 00:00:00 2001
From: Jeremy Kemper
Date: Mon, 7 May 2012 14:53:57 -0700
Subject: Add passing tests for generating URLs with nested SCRIPT_NAMEs
---
actionpack/test/dispatch/mount_test.rb | 5 +++++
actionpack/test/dispatch/url_generation_test.rb | 15 ++++++++++++---
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/actionpack/test/dispatch/mount_test.rb b/actionpack/test/dispatch/mount_test.rb
index f7a746120e..536e35ab2e 100644
--- a/actionpack/test/dispatch/mount_test.rb
+++ b/actionpack/test/dispatch/mount_test.rb
@@ -37,6 +37,11 @@ class TestRoutingMount < ActionDispatch::IntegrationTest
assert_equal "/sprockets -- /omg", response.body
end
+ def test_mounting_works_with_nested_script_name
+ get "/foo/sprockets/omg", {}, 'SCRIPT_NAME' => '/foo', 'PATH_INFO' => '/sprockets/omg'
+ assert_equal "/foo/sprockets -- /omg", response.body
+ end
+
def test_mounting_works_with_scope
get "/its_a/sprocket/omg"
assert_equal "/its_a/sprocket -- /omg", response.body
diff --git a/actionpack/test/dispatch/url_generation_test.rb b/actionpack/test/dispatch/url_generation_test.rb
index 985ff2e81a..e56e8ddc57 100644
--- a/actionpack/test/dispatch/url_generation_test.rb
+++ b/actionpack/test/dispatch/url_generation_test.rb
@@ -3,7 +3,7 @@ require 'abstract_unit'
module TestUrlGeneration
class WithMountPoint < ActionDispatch::IntegrationTest
Routes = ActionDispatch::Routing::RouteSet.new
- Routes.draw { get "/foo", :to => "my_route_generating#index", :as => :foo }
+ include Routes.url_helpers
class ::MyRouteGeneratingController < ActionController::Base
include Routes.url_helpers
@@ -12,7 +12,11 @@ module TestUrlGeneration
end
end
- include Routes.url_helpers
+ Routes.draw do
+ get "/foo", :to => "my_route_generating#index", :as => :foo
+
+ mount MyRouteGeneratingController.action(:index), at: '/bar'
+ end
def _routes
Routes
@@ -30,11 +34,16 @@ module TestUrlGeneration
assert_equal "/bar/foo", foo_path(:script_name => "/bar")
end
- test "the request's SCRIPT_NAME takes precedence over the routes'" do
+ test "the request's SCRIPT_NAME takes precedence over the route" do
get "/foo", {}, 'SCRIPT_NAME' => "/new", 'action_dispatch.routes' => Routes
assert_equal "/new/foo", response.body
end
+ test "the request's SCRIPT_NAME wraps the mounted app's" do
+ get '/new/bar/foo', {}, 'SCRIPT_NAME' => '/new', 'PATH_INFO' => '/bar/foo', 'action_dispatch.routes' => Routes
+ assert_equal "/new/bar/foo", response.body
+ end
+
test "handling http protocol with https set" do
https!
assert_equal "http://www.example.com/foo", foo_url(:protocol => "http")
--
cgit v1.2.3
From 2fb6d12ad3a03c1d9b310fc6a01150f1af2af73b Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Mon, 7 May 2012 17:33:54 -0500
Subject: added docs and examples to cattr_writer method
---
.../core_ext/class/attribute_accessors.rb | 46 +++++++++++++++++++---
1 file changed, 41 insertions(+), 5 deletions(-)
diff --git a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
index 72a918f839..7d85fd512c 100644
--- a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
+++ b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
@@ -58,6 +58,42 @@ class Class
end
end
+ # Defines a class attribute if it's not defined and creates a writer method to allow
+ # assignment to the attribute.
+ #
+ # class Person
+ # cattr_writer :hair_colors
+ # end
+ #
+ # Person.hair_colors = [:brown, :black]
+ # Person.class_variable_get("@@hair_colors") # => [:brown, :black]
+ # Person.new.hair_colors = [:blonde, :red]
+ # Person.class_variable_get("@@hair_colors") # => [:blonde, :red]
+ #
+ # The attribute name must be any word character starting with a letter or underscore
+ # and without spaces.
+ #
+ # class Person
+ # cattr_writer :"1_Badname "
+ # end
+ # # => NameError: invalid attribute name
+ #
+ # If you want to opt out the instance writer method, pass instance_writer: false
+ # or instance_accessor: false.
+ #
+ # class Person
+ # cattr_writer :hair_colors, instance_writer: false
+ # end
+ #
+ # Person.new.hair_colors = [:blonde, :red] # => NoMethodError
+ #
+ # Also, you can pass a block to set up the variable with a default value.
+ #
+ # class Person
+ # cattr_writer(:hair_colors) {[:brown, :black, :blonde, :red]}
+ # end
+ #
+ # Person.class_variable_get("@@hair_colors") # => [:brown, :black, :blonde, :red]
def cattr_writer(*syms)
options = syms.extract_options!
syms.each do |sym|
@@ -103,20 +139,20 @@ class Class
# Male.hair_colors << :blue
# Person.hair_colors # => [:brown, :black, :blonde, :red, :blue]
#
- # To opt out of the instance writer method, pass :instance_writer => false.
- # To opt out of the instance reader method, pass :instance_reader => false.
+ # To opt out of the instance writer method, pass instance_writer: false.
+ # To opt out of the instance reader method, pass instance_reader: false.
#
# class Person
- # cattr_accessor :hair_colors, :instance_writer => false, :instance_reader => false
+ # cattr_accessor :hair_colors, instance_writer: false, instance_reader: false
# end
#
# Person.new.hair_colors = [:brown] # => NoMethodError
# Person.new.hair_colors # => NoMethodError
#
- # Or pass :instance_accessor => false, to opt out both instance methods.
+ # Or pass instance_accessor: false, to opt out both instance methods.
#
# class Person
- # cattr_accessor :hair_colors, :instance_accessor => false
+ # cattr_accessor :hair_colors, instance_accessor: false
# end
#
# Person.new.hair_colors = [:brown] # => NoMethodError
--
cgit v1.2.3
From 1ff35304885d86800d802748a053e0f4bef2ac91 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Mon, 7 May 2012 19:04:27 -0500
Subject: better docs for cattr_accessor and cattr_writer
---
.../active_support/core_ext/class/attribute_accessors.rb | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
index 7d85fd512c..4461cd6608 100644
--- a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
+++ b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
@@ -87,10 +87,12 @@ class Class
#
# Person.new.hair_colors = [:blonde, :red] # => NoMethodError
#
- # Also, you can pass a block to set up the variable with a default value.
+ # Also, you can pass a block to set up the attribute with a default value.
#
# class Person
- # cattr_writer(:hair_colors) {[:brown, :black, :blonde, :red]}
+ # cattr_writer :hair_colors do
+ # [:brown, :black, :blonde, :red]
+ # end
# end
#
# Person.class_variable_get("@@hair_colors") # => [:brown, :black, :blonde, :red]
@@ -157,6 +159,16 @@ class Class
#
# Person.new.hair_colors = [:brown] # => NoMethodError
# Person.new.hair_colors # => NoMethodError
+ #
+ # Also you can pass a block to set up the attribute with a default value.
+ #
+ # class Person
+ # cattr_accessor :hair_colors do
+ # [:brown, :black, :blonde, :red]
+ # end
+ # end
+ #
+ # Person.class_variable_get("@@hair_colors") #=> [:brown, :black, :blonde, :red]
def cattr_accessor(*syms, &blk)
cattr_reader(*syms)
cattr_writer(*syms, &blk)
--
cgit v1.2.3
From 2805c28e3e9a7386fe144754a9b664c424add2b3 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Mon, 7 May 2012 19:37:00 -0500
Subject: added docs to cattr_reader
---
.../core_ext/class/attribute_accessors.rb | 27 ++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
index 4461cd6608..8b41b10c32 100644
--- a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
+++ b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
@@ -34,6 +34,33 @@ require 'active_support/core_ext/array/extract_options'
# Person.new.hair_colors = [:brown] # => NoMethodError
# Person.new.hair_colors # => NoMethodError
class Class
+ # Defines a class attribute if it's not defined and creates a reader method that
+ # returns the attribute value.
+ #
+ # class Person
+ # cattr_reader :hair_colors
+ # end
+ #
+ # Person.class_variable_set("@@hair_colors", [:brown, :black])
+ # Person.hair_colors # => [:brown, :black]
+ # Person.new.hair_colors # => [:brown, :black]
+ #
+ # The attribute name must be any word character starting with a letter or underscore
+ # and without spaces.
+ #
+ # class Person
+ # cattr_reader :"1_Badname "
+ # end
+ # # => NameError: invalid attribute name
+ #
+ # If you want to opt out the instance writer method, pass instance_reader: false
+ # or instance_accessor: false.
+ #
+ # class Person
+ # cattr_reader :hair_colors, instance_reader: false
+ # end
+ #
+ # Person.new.hair_colors # => NoMethodError
def cattr_reader(*syms)
options = syms.extract_options!
syms.each do |sym|
--
cgit v1.2.3
From 4831a895c445f650c9daf0b445136ceb653f781b Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Mon, 7 May 2012 22:47:35 -0500
Subject: added docs to alias_attribute method
---
activemodel/lib/active_model/attribute_methods.rb | 31 +++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb
index 97a83e58af..59977b6142 100644
--- a/activemodel/lib/active_model/attribute_methods.rb
+++ b/activemodel/lib/active_model/attribute_methods.rb
@@ -180,6 +180,37 @@ module ActiveModel
undefine_attribute_methods
end
+
+ # Allows you to make aliases for attributes.
+ #
+ # For example:
+ #
+ # class Person
+ #
+ # include ActiveModel::AttributeMethods
+ # attr_accessor :name
+ # attribute_method_prefix 'clear_'
+ #
+ # define_attribute_methods [:name]
+ #
+ # private
+ #
+ # def clear_attribute(attr)
+ # send("#{attr}=", nil)
+ # end
+ # end
+ #
+ # class Person
+ # attr_accessor :nickname
+ #
+ # alias_attribute :nickname, :name
+ # end
+ #
+ # person = Person.new
+ # person.nickname = "Bob"
+ # person.nickname # => "Bob"
+ # person.clear_nickname
+ # person.nickname # => nil
def alias_attribute(new_name, old_name)
attribute_method_matchers.each do |matcher|
matcher_new = matcher.method_name(new_name).to_s
--
cgit v1.2.3
From e8d1f10ac42b171b8d0e73a6a59f7e7e4b094a23 Mon Sep 17 00:00:00 2001
From: Edward Tsech
Date: Tue, 8 May 2012 09:05:38 +0200
Subject: Improve readability of metaprogramming annotations at
AbstractController callbacks.
---
actionpack/lib/abstract_controller/callbacks.rb | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/actionpack/lib/abstract_controller/callbacks.rb b/actionpack/lib/abstract_controller/callbacks.rb
index c0fa28cae9..520c210721 100644
--- a/actionpack/lib/abstract_controller/callbacks.rb
+++ b/actionpack/lib/abstract_controller/callbacks.rb
@@ -163,11 +163,11 @@ module AbstractController
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
# Append a before, after or around filter. See _insert_callbacks
# for details on the allowed parameters.
- def #{filter}_filter(*names, &blk) # def before_filter(*names, &blk)
- _insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options|
- set_callback(:process_action, :#{filter}, name, options) # set_callback(:process_action, :before, name, options)
- end # end
- end # end
+ def #{filter}_filter(*names, &blk) # def before_filter(*names, &blk)
+ _insert_callbacks(names, blk) do |name, options| # _insert_callbacks(names, blk) do |name, options|
+ set_callback(:process_action, :#{filter}, name, options) # set_callback(:process_action, :before, name, options)
+ end # end
+ end # end
# Prepend a before, after or around filter. See _insert_callbacks
# for details on the allowed parameters.
@@ -179,11 +179,11 @@ module AbstractController
# Skip a before, after or around filter. See _insert_callbacks
# for details on the allowed parameters.
- def skip_#{filter}_filter(*names) # def skip_before_filter(*names)
- _insert_callbacks(names) do |name, options| # _insert_callbacks(names) do |name, options|
- skip_callback(:process_action, :#{filter}, name, options) # skip_callback(:process_action, :before, name, options)
- end # end
- end # end
+ def skip_#{filter}_filter(*names) # def skip_before_filter(*names)
+ _insert_callbacks(names) do |name, options| # _insert_callbacks(names) do |name, options|
+ skip_callback(:process_action, :#{filter}, name, options) # skip_callback(:process_action, :before, name, options)
+ end # end
+ end # end
# *_filter is the same as append_*_filter
alias_method :append_#{filter}_filter, :#{filter}_filter # alias_method :append_before_filter, :before_filter
--
cgit v1.2.3
From 3ca28dec0f5a4c41816f187dc31a922be5ebff89 Mon Sep 17 00:00:00 2001
From: Kunal Shah
Date: Mon, 7 May 2012 18:56:36 -0400
Subject: If content_type is explicitly passed to the :head method use the
value or fallback
---
actionpack/lib/action_controller/metal/head.rb | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/actionpack/lib/action_controller/metal/head.rb b/actionpack/lib/action_controller/metal/head.rb
index 5bdbde9ebb..2fcd933d32 100644
--- a/actionpack/lib/action_controller/metal/head.rb
+++ b/actionpack/lib/action_controller/metal/head.rb
@@ -20,6 +20,7 @@ module ActionController
options, status = status, nil if status.is_a?(Hash)
status ||= options.delete(:status) || :ok
location = options.delete(:location)
+ content_type = options.delete(:content_type)
options.each do |key, value|
headers[key.to_s.dasherize.split('-').each { |v| v[0] = v[0].chr.upcase }.join('-')] = value.to_s
@@ -29,7 +30,7 @@ module ActionController
self.location = url_for(location) if location
if include_content_headers?(self.status)
- self.content_type = Mime[formats.first] if formats
+ self.content_type = content_type || (Mime[formats.first] if formats)
else
headers.delete('Content-Type')
headers.delete('Content-Length')
--
cgit v1.2.3
From c09a92fb9e08ee36d795a237899d3439930ef784 Mon Sep 17 00:00:00 2001
From: Kunal Shah
Date: Mon, 7 May 2012 15:23:06 -0400
Subject: Add failing test re #3436 which demonstrates content_type is not
respected when using the :head method/shortcut
---
actionpack/test/controller/render_test.rb | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index 5e699c0daf..3d58c02338 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -505,6 +505,14 @@ class TestController < ActionController::Base
render :text => "hello world!"
end
+ def head_created
+ head :created
+ end
+
+ def head_created_with_application_json_content_type
+ head :created, :content_type => "application/json"
+ end
+
def head_with_location_header
head :location => "/foo"
end
@@ -1177,6 +1185,19 @@ class RenderTest < ActionController::TestCase
assert_equal "\n
Hello
\n\n", @response.body
end
+ def test_head_created
+ post :head_created
+ assert_blank @response.body
+ assert_response :created
+ end
+
+ def test_head_created_with_application_json_content_type
+ post :head_created_with_application_json_content_type
+ assert_blank @response.body
+ assert_equal "application/json", @response.content_type
+ assert_response :created
+ end
+
def test_head_with_location_header
get :head_with_location_header
assert_blank @response.body
--
cgit v1.2.3
From b3bd01c154e8294cbd0ecaa2aa0b7b3ac322592c Mon Sep 17 00:00:00 2001
From: Edward Tsech
Date: Tue, 8 May 2012 11:08:15 +0200
Subject: Add annotaion for class_eval in AbstractController#helper_method [ci
skip]
---
actionpack/lib/abstract_controller/helpers.rb | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/actionpack/lib/abstract_controller/helpers.rb b/actionpack/lib/abstract_controller/helpers.rb
index 77cc4c07d9..4e0672d590 100644
--- a/actionpack/lib/abstract_controller/helpers.rb
+++ b/actionpack/lib/abstract_controller/helpers.rb
@@ -49,9 +49,9 @@ module AbstractController
meths.each do |meth|
_helpers.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1
- def #{meth}(*args, &blk)
- controller.send(%(#{meth}), *args, &blk)
- end
+ def #{meth}(*args, &blk) # def current_user(*args, &blk)
+ controller.send(%(#{meth}), *args, &blk) # controller.send(:current_user, *args, &blk)
+ end # end
ruby_eval
end
end
--
cgit v1.2.3
From ceb1dcc3dbd4f3e5d42f46bb5746c87c1fcf47ff Mon Sep 17 00:00:00 2001
From: Paul Campbell
Date: Tue, 8 May 2012 11:44:58 +0100
Subject: add humans.txt
---
.../rails/generators/rails/app/templates/public/humans.txt.tt | 9 +++++++++
1 file changed, 9 insertions(+)
create mode 100644 railties/lib/rails/generators/rails/app/templates/public/humans.txt.tt
diff --git a/railties/lib/rails/generators/rails/app/templates/public/humans.txt.tt b/railties/lib/rails/generators/rails/app/templates/public/humans.txt.tt
new file mode 100644
index 0000000000..1c49e5c70a
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/public/humans.txt.tt
@@ -0,0 +1,9 @@
+# See more about this file at: http://humanstxt.org/
+# For format suggestions, see: http://humanstxt.org/Standard.html
+/* TEAM */
+ <%= ENV['USER'].titlecase %>
+
+/* APP */
+ Name: <%= app_const_base %>
+ Date Created: <%= Date.today.strftime("%B %d, %Y") %>
+ Software: Ruby on Rails
--
cgit v1.2.3
From 757a0ce6aaa19af20daea29a1d5e5b16c506f89b Mon Sep 17 00:00:00 2001
From: Arun Agrawal
Date: Tue, 8 May 2012 16:41:20 +0530
Subject: Adding test for humans.txt
---
railties/test/generators/app_generator_test.rb | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index d13dc8d4ac..a0c308a3b8 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -383,6 +383,12 @@ class AppGeneratorTest < Rails::Generators::TestCase
assert_no_match(/run bundle install/, output)
end
+ def test_humans_txt_file
+ date = Date.today.strftime("%B %d, %Y")
+ run_generator [File.join(destination_root, 'things-43')]
+ assert_file "things-43/public/humans.txt", /Name: Things43/, /Software: Ruby on Rails/, /Date Created: #{date}/
+ end
+
protected
def action(*args, &block)
--
cgit v1.2.3
From a9c27e7d5e82099f783f68897bba6741aad2c53c Mon Sep 17 00:00:00 2001
From: Edward Tsech
Date: Tue, 8 May 2012 16:26:26 +0200
Subject: Add example for image_submit_tag with confirmation. [ci skip]
---
actionpack/lib/action_view/helpers/form_tag_helper.rb | 3 +++
1 file changed, 3 insertions(+)
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index ef35a411ad..8e8a56c65c 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -502,6 +502,9 @@ module ActionView
#
# image_submit_tag("agree.png", :disabled => true, :class => "agree_disagree_button")
# # =>
+ #
+ # image_submit_tag("save.png", :confirm => "Are you sure?")
+ # # =>
def image_submit_tag(source, options = {})
options = options.stringify_keys
--
cgit v1.2.3
From e8c9aeca4e054a365d2b64f542617a40f656c666 Mon Sep 17 00:00:00 2001
From: "Mark J. Titorenko"
Date: Tue, 8 May 2012 15:37:18 +0100
Subject: Fix NumberHelper options wrapping to prevent verbatim blocks being
rendered instead of line continuations. While I'm at it, wrap long comment
lines consistently.
---
.../lib/action_view/helpers/number_helper.rb | 253 +++++++++++++--------
1 file changed, 161 insertions(+), 92 deletions(-)
diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb
index 2011351bd2..dfc26acfad 100644
--- a/actionpack/lib/action_view/helpers/number_helper.rb
+++ b/actionpack/lib/action_view/helpers/number_helper.rb
@@ -28,17 +28,20 @@ module ActionView
end
end
- # Formats a +number+ into a US phone number (e.g., (555) 123-9876). You can customize the format
- # in the +options+ hash.
+ # Formats a +number+ into a US phone number (e.g., (555)
+ # 123-9876). You can customize the format in the +options+ hash.
#
# ==== Options
#
- # * :area_code - Adds parentheses around the area code.
- # * :delimiter - Specifies the delimiter to use (defaults to "-").
- # * :extension - Specifies an extension to add to the end of the
- # generated number.
- # * :country_code - Sets the country code for the phone number.
- # * :raise - If true, raises +InvalidNumberError+ when the argument is invalid.
+ # * :area_code - Adds parentheses around the area code.
+ # * :delimiter - Specifies the delimiter to use
+ # (defaults to "-").
+ # * :extension - Specifies an extension to add to the
+ # end of the generated number.
+ # * :country_code - Sets the country code for the phone
+ # number.
+ # * :raise - If true, raises +InvalidNumberError+ when
+ # the argument is invalid.
#
# ==== Examples
#
@@ -81,24 +84,31 @@ module ActionView
ERB::Util.html_escape(str)
end
- # Formats a +number+ into a currency string (e.g., $13.65). You can customize the format
- # in the +options+ hash.
+ # Formats a +number+ into a currency string (e.g., $13.65). You
+ # can customize the format in the +options+ hash.
#
# ==== Options
#
- # * :locale - Sets the locale to be used for formatting (defaults to current locale).
- # * :precision - Sets the level of precision (defaults to 2).
- # * :unit - Sets the denomination of the currency (defaults to "$").
- # * :separator - Sets the separator between the units (defaults to ".").
- # * :delimiter - Sets the thousands delimiter (defaults to ",").
- # * :format - Sets the format for non-negative numbers (defaults to "%u%n").
- # Fields are %u for the currency, and %n
- # for the number.
- # * :negative_format - Sets the format for negative numbers (defaults to prepending
- # an hyphen to the formatted number given by :format).
- # Accepts the same fields than :format, except
- # %n is here the absolute value of the number.
- # * :raise - If true, raises +InvalidNumberError+ when the argument is invalid.
+ # * :locale - Sets the locale to be used for formatting
+ # (defaults to current locale).
+ # * :precision - Sets the level of precision (defaults
+ # to 2).
+ # * :unit - Sets the denomination of the currency
+ # (defaults to "$").
+ # * :separator - Sets the separator between the units
+ # (defaults to ".").
+ # * :delimiter - Sets the thousands delimiter (defaults
+ # to ",").
+ # * :format - Sets the format for non-negative numbers
+ # (defaults to "%u%n"). Fields are %u for the
+ # currency, and %n for the number.
+ # * :negative_format - Sets the format for negative
+ # numbers (defaults to prepending an hyphen to the formatted
+ # number given by :format). Accepts the same fields
+ # than :format, except %n is here the
+ # absolute value of the number.
+ # * :raise - If true, raises +InvalidNumberError+ when
+ # the argument is invalid.
#
# ==== Examples
#
@@ -148,23 +158,29 @@ module ActionView
end
end
- # Formats a +number+ as a percentage string (e.g., 65%). You can customize the format in the +options+ hash.
+ # Formats a +number+ as a percentage string (e.g., 65%). You can
+ # customize the format in the +options+ hash.
#
# ==== Options
#
- # * :locale - Sets the locale to be used for formatting (defaults to current
- # locale).
- # * :precision - Sets the precision of the number (defaults to 3).
- # * :significant - If +true+, precision will be the # of significant_digits. If +false+,
- # the # of fractional digits (defaults to +false+).
- # * :separator - Sets the separator between the fractional and integer digits (defaults
- # to ".").
- # * :delimiter - Sets the thousands delimiter (defaults to "").
- # * :strip_insignificant_zeros - If +true+ removes insignificant zeros after the decimal separator
- # (defaults to +false+).
- # * :format - Specifies the format of the percentage string
- # The number field is %n (defaults to "%n%").
- # * :raise - If true, raises +InvalidNumberError+ when the argument is invalid.
+ # * :locale - Sets the locale to be used for formatting
+ # (defaults to current locale).
+ # * :precision - Sets the precision of the number
+ # (defaults to 3).
+ # * :significant - If +true+, precision will be the #
+ # of significant_digits. If +false+, the # of fractional
+ # digits (defaults to +false+).
+ # * :separator - Sets the separator between the
+ # fractional and integer digits (defaults to ".").
+ # * :delimiter - Sets the thousands delimiter (defaults
+ # to "").
+ # * :strip_insignificant_zeros - If +true+ removes
+ # insignificant zeros after the decimal separator (defaults to
+ # +false+).
+ # * :format - Specifies the format of the percentage
+ # string The number field is %n (defaults to "%n%").
+ # * :raise - If true, raises +InvalidNumberError+ when
+ # the argument is invalid.
#
# ==== Examples
#
@@ -200,15 +216,20 @@ module ActionView
end
end
- # Formats a +number+ with grouped thousands using +delimiter+ (e.g., 12,324). You can
- # customize the format in the +options+ hash.
+ # Formats a +number+ with grouped thousands using +delimiter+
+ # (e.g., 12,324). You can customize the format in the +options+
+ # hash.
#
# ==== Options
#
- # * :locale - Sets the locale to be used for formatting (defaults to current locale).
- # * :delimiter - Sets the thousands delimiter (defaults to ",").
- # * :separator - Sets the separator between the fractional and integer digits (defaults to ".").
- # * :raise - If true, raises +InvalidNumberError+ when the argument is invalid.
+ # * :locale - Sets the locale to be used for formatting
+ # (defaults to current locale).
+ # * :delimiter - Sets the thousands delimiter (defaults
+ # to ",").
+ # * :separator - Sets the separator between the
+ # fractional and integer digits (defaults to ".").
+ # * :raise - If true, raises +InvalidNumberError+ when
+ # the argument is invalid.
#
# ==== Examples
#
@@ -236,23 +257,32 @@ module ActionView
safe_join(parts, options[:separator])
end
- # Formats a +number+ with the specified level of :precision (e.g., 112.32 has a precision
- # of 2 if +:significant+ is +false+, and 5 if +:significant+ is +true+).
+ # Formats a +number+ with the specified level of
+ # :precision (e.g., 112.32 has a precision of 2 if
+ # +:significant+ is +false+, and 5 if +:significant+ is +true+).
# You can customize the format in the +options+ hash.
#
# ==== Options
- # * :locale - Sets the locale to be used for formatting (defaults to current locale).
- # * :precision - Sets the precision of the number (defaults to 3).
- # * :significant - If +true+, precision will be the # of significant_digits. If +false+,
- # the # of fractional digits (defaults to +false+).
- # * :separator - Sets the separator between the fractional and integer digits (defaults
- # to ".").
- # * :delimiter - Sets the thousands delimiter (defaults to "").
- # * :strip_insignificant_zeros - If +true+ removes insignificant zeros after the decimal separator
- # (defaults to +false+).
- # * :raise - If true, raises +InvalidNumberError+ when the argument is invalid.
+ #
+ # * :locale - Sets the locale to be used for formatting
+ # (defaults to current locale).
+ # * :precision - Sets the precision of the number
+ # (defaults to 3).
+ # * :significant - If +true+, precision will be the #
+ # of significant_digits. If +false+, the # of fractional
+ # digits (defaults to +false+).
+ # * :separator - Sets the separator between the
+ # fractional and integer digits (defaults to ".").
+ # * :delimiter - Sets the thousands delimiter (defaults
+ # to "").
+ # * :strip_insignificant_zeros - If +true+ removes
+ # insignificant zeros after the decimal separator (defaults to
+ # +false+).
+ # * :raise - If true, raises +InvalidNumberError+ when
+ # the argument is invalid.
#
# ==== Examples
+ #
# number_with_precision(111.2345) # => 111.235
# number_with_precision(111.2345, :precision => 2) # => 111.23
# number_with_precision(13, :precision => 5) # => 13.00000
@@ -305,23 +335,37 @@ module ActionView
STORAGE_UNITS = [:byte, :kb, :mb, :gb, :tb].freeze
- # Formats the bytes in +number+ into a more understandable representation
- # (e.g., giving it 1500 yields 1.5 KB). This method is useful for
- # reporting file sizes to users. You can customize the
- # format in the +options+ hash.
+ # Formats the bytes in +number+ into a more understandable
+ # representation (e.g., giving it 1500 yields 1.5 KB). This
+ # method is useful for reporting file sizes to users. You can
+ # customize the format in the +options+ hash.
#
- # See number_to_human if you want to pretty-print a generic number.
+ # See number_to_human if you want to pretty-print a
+ # generic number.
#
# ==== Options
- # * :locale - Sets the locale to be used for formatting (defaults to current locale).
- # * :precision - Sets the precision of the number (defaults to 3).
- # * :significant - If +true+, precision will be the # of significant_digits. If +false+, the # of fractional digits (defaults to +true+)
- # * :separator - Sets the separator between the fractional and integer digits (defaults to ".").
- # * :delimiter - Sets the thousands delimiter (defaults to "").
- # * :strip_insignificant_zeros - If +true+ removes insignificant zeros after the decimal separator (defaults to +true+)
- # * :prefix - If +:si+ formats the number using the SI prefix (defaults to :binary)
- # * :raise - If true, raises +InvalidNumberError+ when the argument is invalid.
+ #
+ # * :locale - Sets the locale to be used for formatting
+ # (defaults to current locale).
+ # * :precision - Sets the precision of the number
+ # (defaults to 3).
+ # * :significant - If +true+, precision will be the #
+ # of significant_digits. If +false+, the # of fractional
+ # digits (defaults to +true+)
+ # * :separator - Sets the separator between the
+ # fractional and integer digits (defaults to ".").
+ # * :delimiter - Sets the thousands delimiter (defaults
+ # to "").
+ # * :strip_insignificant_zeros - If +true+ removes
+ # insignificant zeros after the decimal separator (defaults to
+ # +true+)
+ # * :prefix - If +:si+ formats the number using the SI
+ # prefix (defaults to :binary)
+ # * :raise - If true, raises +InvalidNumberError+ when
+ # the argument is invalid.
+ #
# ==== Examples
+ #
# number_to_human_size(123) # => 123 Bytes
# number_to_human_size(1234) # => 1.21 KB
# number_to_human_size(12345) # => 12.1 KB
@@ -332,8 +376,10 @@ module ActionView
# number_to_human_size(483989, :precision => 2) # => 470 KB
# number_to_human_size(1234567, :precision => 2, :separator => ',') # => 1,2 MB
#
- # Non-significant zeros after the fractional separator are stripped out by default (set
- # :strip_insignificant_zeros to +false+ to change that):
+ # Non-significant zeros after the fractional separator are
+ # stripped out by default (set
+ # :strip_insignificant_zeros to +false+ to change
+ # that):
# number_to_human_size(1234567890123, :precision => 5) # => "1.1229 TB"
# number_to_human_size(524288000, :precision => 5) # => "500 MB"
def number_to_human_size(number, options = {})
@@ -371,33 +417,55 @@ module ActionView
DECIMAL_UNITS = {0 => :unit, 1 => :ten, 2 => :hundred, 3 => :thousand, 6 => :million, 9 => :billion, 12 => :trillion, 15 => :quadrillion,
-1 => :deci, -2 => :centi, -3 => :mili, -6 => :micro, -9 => :nano, -12 => :pico, -15 => :femto}.freeze
- # Pretty prints (formats and approximates) a number in a way it is more readable by humans
- # (eg.: 1200000000 becomes "1.2 Billion"). This is useful for numbers that
- # can get very large (and too hard to read).
+ # Pretty prints (formats and approximates) a number in a way it
+ # is more readable by humans (eg.: 1200000000 becomes "1.2
+ # Billion"). This is useful for numbers that can get very large
+ # (and too hard to read).
#
- # See number_to_human_size if you want to print a file size.
+ # See number_to_human_size if you want to print a file
+ # size.
#
- # You can also define you own unit-quantifier names if you want to use other decimal units
- # (eg.: 1500 becomes "1.5 kilometers", 0.150 becomes "150 milliliters", etc). You may define
- # a wide range of unit quantifiers, even fractional ones (centi, deci, mili, etc).
+ # You can also define you own unit-quantifier names if you want
+ # to use other decimal units (eg.: 1500 becomes "1.5
+ # kilometers", 0.150 becomes "150 milliliters", etc). You may
+ # define a wide range of unit quantifiers, even fractional ones
+ # (centi, deci, mili, etc).
#
# ==== Options
- # * :locale - Sets the locale to be used for formatting (defaults to current locale).
- # * :precision - Sets the precision of the number (defaults to 3).
- # * :significant - If +true+, precision will be the # of significant_digits. If +false+, the # of fractional digits (defaults to +true+)
- # * :separator - Sets the separator between the fractional and integer digits (defaults to ".").
- # * :delimiter - Sets the thousands delimiter (defaults to "").
- # * :strip_insignificant_zeros - If +true+ removes insignificant zeros after the decimal separator (defaults to +true+)
- # * :units - A Hash of unit quantifier names. Or a string containing an i18n scope where to find this hash. It might have the following keys:
- # * *integers*: :unit, :ten, :hundred, :thousand, :million, :billion, :trillion, :quadrillion
- # * *fractionals*: :deci, :centi, :mili, :micro, :nano, :pico, :femto
- # * :format - Sets the format of the output string (defaults to "%n %u"). The field types are:
- # %u The quantifier (ex.: 'thousand')
- # %n The number
- # * :raise - If true, raises +InvalidNumberError+ when the argument is invalid.
#
+ # * :locale - Sets the locale to be used for formatting
+ # (defaults to current locale).
+ # * :precision - Sets the precision of the number
+ # (defaults to 3).
+ # * :significant - If +true+, precision will be the #
+ # of significant_digits. If +false+, the # of fractional
+ # digits (defaults to +true+)
+ # * :separator - Sets the separator between the
+ # fractional and integer digits (defaults to ".").
+ # * :delimiter - Sets the thousands delimiter (defaults
+ # to "").
+ # * :strip_insignificant_zeros - If +true+ removes
+ # insignificant zeros after the decimal separator (defaults to
+ # +true+)
+ # * :units - A Hash of unit quantifier names. Or a
+ # string containing an i18n scope where to find this hash. It
+ # might have the following keys:
+ # * *integers*: :unit, :ten,
+ # *:hundred, :thousand, :million,
+ # *:billion, :trillion,
+ # *:quadrillion
+ # * *fractionals*: :deci, :centi,
+ # *:mili, :micro, :nano,
+ # *:pico, :femto
+ # * :format - Sets the format of the output string
+ # (defaults to "%n %u"). The field types are:
+ # * %u - The quantifier (ex.: 'thousand')
+ # * %n - The number
+ # * :raise - If true, raises +InvalidNumberError+ when
+ # the argument is invalid.
#
# ==== Examples
+ #
# number_to_human(123) # => "123"
# number_to_human(1234) # => "1.23 Thousand"
# number_to_human(12345) # => "12.3 Thousand"
@@ -414,8 +482,9 @@ module ActionView
# :separator => ',',
# :significant => false) # => "1,2 Million"
#
- # Unsignificant zeros after the decimal separator are stripped out by default (set
- # :strip_insignificant_zeros to +false+ to change that):
+ # Non-significant zeros after the decimal separator are stripped
+ # out by default (set :strip_insignificant_zeros to
+ # +false+ to change that):
# number_to_human(12345012345, :significant_digits => 6) # => "12.345 Billion"
# number_to_human(500000000, :precision => 5) # => "500 Million"
#
--
cgit v1.2.3
From f31613a0312bfb2529d0ac262337cd7338cb868d Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Tue, 8 May 2012 23:49:20 +0530
Subject: cut some duplication and minor edits [ci skip]
---
.../core_ext/class/attribute_accessors.rb | 41 +++-------------------
1 file changed, 4 insertions(+), 37 deletions(-)
diff --git a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
index 8b41b10c32..fa1dbfdf06 100644
--- a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
+++ b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
@@ -2,37 +2,6 @@ require 'active_support/core_ext/array/extract_options'
# Extends the class object with class and instance accessors for class attributes,
# just like the native attr* accessors for instance attributes.
-#
-# Note that unlike +class_attribute+, if a subclass changes the value then that would
-# also change the value for parent class. Similarly if parent class changes the value
-# then that would change the value of subclasses too.
-#
-# class Person
-# cattr_accessor :hair_colors
-# end
-#
-# Person.hair_colors = [:brown, :black, :blonde, :red]
-# Person.hair_colors # => [:brown, :black, :blonde, :red]
-# Person.new.hair_colors # => [:brown, :black, :blonde, :red]
-#
-# class Female < Person
-# end
-#
-# Female.hair_colors << :pink
-# Female.hair_colors # => [:brown, :black, :blonde, :red, :pink]
-# Female.new.hair_colors # => [:brown, :black, :blonde, :red, :pink]
-# Person.hair_colors # => [:brown, :black, :blonde, :red, :pink]
-#
-# To opt out of the instance writer method, pass :instance_writer => false.
-# To opt out of the instance reader method, pass :instance_reader => false.
-# To opt out of both instance methods, pass :instance_accessor => false.
-#
-# class Person
-# cattr_accessor :hair_colors, :instance_writer => false, :instance_reader => false
-# end
-#
-# Person.new.hair_colors = [:brown] # => NoMethodError
-# Person.new.hair_colors # => NoMethodError
class Class
# Defines a class attribute if it's not defined and creates a reader method that
# returns the attribute value.
@@ -45,15 +14,14 @@ class Class
# Person.hair_colors # => [:brown, :black]
# Person.new.hair_colors # => [:brown, :black]
#
- # The attribute name must be any word character starting with a letter or underscore
- # and without spaces.
+ # The attribute name must be a valid method name in Ruby.
#
# class Person
# cattr_reader :"1_Badname "
# end
# # => NameError: invalid attribute name
#
- # If you want to opt out the instance writer method, pass instance_reader: false
+ # If you want to opt out the instance reader method, you can pass instance_reader: false
# or instance_accessor: false.
#
# class Person
@@ -97,8 +65,7 @@ class Class
# Person.new.hair_colors = [:blonde, :red]
# Person.class_variable_get("@@hair_colors") # => [:blonde, :red]
#
- # The attribute name must be any word character starting with a letter or underscore
- # and without spaces.
+ # The attribute name must be a valid method name in Ruby.
#
# class Person
# cattr_writer :"1_Badname "
@@ -148,7 +115,7 @@ class Class
end
end
- # Defines class and instance accessors for class attributes.
+ # Defines both class and instance accessors for class attributes.
#
# class Person
# cattr_accessor :hair_colors
--
cgit v1.2.3
From 7e26f7f0f7e3c230c333e1b265727a9b8cf7c91f Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Tue, 8 May 2012 23:54:47 +0530
Subject: simplify the alias_attribute example [ci skip]
---
activemodel/lib/active_model/attribute_methods.rb | 21 +--------------------
1 file changed, 1 insertion(+), 20 deletions(-)
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb
index 59977b6142..25d5d84ce6 100644
--- a/activemodel/lib/active_model/attribute_methods.rb
+++ b/activemodel/lib/active_model/attribute_methods.rb
@@ -183,34 +183,15 @@ module ActiveModel
# Allows you to make aliases for attributes.
#
- # For example:
- #
# class Person
- #
- # include ActiveModel::AttributeMethods
# attr_accessor :name
- # attribute_method_prefix 'clear_'
- #
- # define_attribute_methods [:name]
- #
- # private
- #
- # def clear_attribute(attr)
- # send("#{attr}=", nil)
- # end
- # end
- #
- # class Person
- # attr_accessor :nickname
- #
# alias_attribute :nickname, :name
# end
#
# person = Person.new
# person.nickname = "Bob"
# person.nickname # => "Bob"
- # person.clear_nickname
- # person.nickname # => nil
+ # person.name # => "Bob"
def alias_attribute(new_name, old_name)
attribute_method_matchers.each do |matcher|
matcher_new = matcher.method_name(new_name).to_s
--
cgit v1.2.3
From 2882a3c827a06b021dc950cd09568e0bac729c76 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 9 May 2012 00:06:17 +0530
Subject: remove redundant and stray line [ci skip]
---
.../lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb | 2 --
1 file changed, 2 deletions(-)
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb
index e3329c0345..7bff0c1149 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb
@@ -136,8 +136,6 @@ module ActionView
# #
# #
#
- # * = The application.js file is only referenced if it exists
- #
# You can also include all JavaScripts in the +javascripts+ directory using :all as the source:
#
# javascript_include_tag :all
--
cgit v1.2.3
From 8a9e031bcea772a5a9608fa17db824651138f352 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 9 May 2012 01:41:22 +0530
Subject: update some examples in asset tag helper docs [ci skip]
---
.../lib/action_view/helpers/asset_tag_helper.rb | 30 +++++++++++-----------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index 7985683a72..adc62ec6a9 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -13,15 +13,16 @@ module ActionView
# the assets exist before linking to them:
#
# image_tag("rails.png")
- # # =>
+ # # =>
# stylesheet_link_tag("application")
- # # =>
+ # # =>
+ #
#
# === Using asset hosts
#
# By default, Rails links to these assets on the current host in the public
# folder, but you can direct Rails to link to assets from a dedicated asset
- # server by setting ActionController::Base.asset_host in the application
+ # server by setting ActionController::Base.asset_host in the application
# configuration, typically in config/environments/production.rb.
# For example, you'd define assets.example.com to be your asset
# host this way, inside the configure block of your environment-specific
@@ -32,9 +33,9 @@ module ActionView
# Helpers take that into account:
#
# image_tag("rails.png")
- # # =>
+ # # =>
# stylesheet_link_tag("application")
- # # =>
+ # # =>
#
# Browsers typically open at most two simultaneous connections to a single
# host, which means your assets often have to wait for other assets to finish
@@ -45,9 +46,9 @@ module ActionView
# will open eight simultaneous connections rather than two.
#
# image_tag("rails.png")
- # # =>
+ # # =>
# stylesheet_link_tag("application")
- # # =>
+ # # =>
#
# To do this, you can either setup four actual hosts, or you can use wildcard
# DNS to CNAME the wildcard to a single asset host. You can read more about
@@ -64,29 +65,28 @@ module ActionView
# "http://assets#{Digest::MD5.hexdigest(source).to_i(16) % 2 + 1}.example.com"
# }
# image_tag("rails.png")
- # # =>
+ # # =>
# stylesheet_link_tag("application")
- # # =>
+ # # =>
#
# The example above generates "http://assets1.example.com" and
# "http://assets2.example.com". This option is useful for example if
# you need fewer/more than four hosts, custom host names, etc.
#
# As you see the proc takes a +source+ parameter. That's a string with the
- # absolute path of the asset with any extensions and timestamps in place,
- # for example "/images/rails.png?1230601161".
+ # absolute path of the asset, for example "/assets/rails.png".
#
# ActionController::Base.asset_host = Proc.new { |source|
- # if source.starts_with?('/images')
- # "http://images.example.com"
+ # if source.ends_with?('.css')
+ # "http://stylesheets.example.com"
# else
# "http://assets.example.com"
# end
# }
# image_tag("rails.png")
- # # =>
+ # # =>
# stylesheet_link_tag("application")
- # # =>
+ # # =>
#
# Alternatively you may ask for a second parameter +request+. That one is
# particularly useful for serving assets from an SSL-protected page. The
--
cgit v1.2.3
From ef9dd2722342ef86f01cbca1dfd5174993d2d56f Mon Sep 17 00:00:00 2001
From: Xavier Noria
Date: Wed, 9 May 2012 00:47:45 +0200
Subject: registers ceb1dcc in the CHANGELOG
---
railties/CHANGELOG.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index b7c042cee3..01df2c5b64 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,5 +1,7 @@
## Rails 4.0.0 (unreleased) ##
+* The application generator generates `public/humans.txt` with some basic data. *Paul Campbell*
+
* Add `config.queue_consumer` to allow the default consumer to be configurable. *Carlos Antonio da Silva*
* Add Rails.queue as an interface with a default implementation that consumes jobs in a separate thread. *Yehuda Katz*
--
cgit v1.2.3
From f1cc45e56a4fc6e80bb4be4434dbf49d41adfd83 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Wed, 9 May 2012 13:40:34 +0530
Subject: fix a couple of formatting issues [ci skip]
---
actionpack/lib/action_view/helpers/text_helper.rb | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb
index fffc37ce9e..698f4434ba 100644
--- a/actionpack/lib/action_view/helpers/text_helper.rb
+++ b/actionpack/lib/action_view/helpers/text_helper.rb
@@ -90,7 +90,7 @@ module ActionView
# Highlights one or more +phrases+ everywhere in +text+ by inserting it into
# a :highlighter string. The highlighter can be specialized by passing :highlighter
- # as a single-quoted string with \1 where the phrase is to be inserted (defaults to
+ # as a single-quoted string with \1 where the phrase is to be inserted (defaults to
# '\1')
#
# ==== Examples
@@ -108,7 +108,9 @@ module ActionView
#
# You can still use highlight with the old API that accepts the
# +highlighter+ as its optional third parameter:
- # highlight('You searched for: rails', 'rails', '\1') # => You searched for: rails
+ #
+ # highlight('You searched for: rails', 'rails', '\1')
+ # # => You searched for: rails
def highlight(text, phrases, *args)
options = args.extract_options!
unless args.empty?
--
cgit v1.2.3
From af44c2ba4a82cf21842071d7c7711de086768f2f Mon Sep 17 00:00:00 2001
From: Alexey Muranov
Date: Sat, 31 Dec 2011 19:03:16 +0100
Subject: Remove unused parameter in ::instantiate_fixtures
Second parameter of Fixtures::instantiate_fixtures was not used, so i removed it.
---
activerecord/lib/active_record/fixtures.rb | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index a01e2f74ff..a6995b8e96 100644
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -411,7 +411,7 @@ module ActiveRecord
cache_for_connection(connection).update(fixtures_map)
end
- def self.instantiate_fixtures(object, fixture_name, fixtures, load_instances = true)
+ def self.instantiate_fixtures(object, fixtures, load_instances = true)
if load_instances
fixtures.each do |name, fixture|
begin
@@ -424,8 +424,8 @@ module ActiveRecord
end
def self.instantiate_all_loaded_fixtures(object, load_instances = true)
- all_loaded_fixtures.each do |table_name, fixtures|
- ActiveRecord::Fixtures.instantiate_fixtures(object, table_name, fixtures, load_instances)
+ all_loaded_fixtures.each_value do |fixtures|
+ instantiate_fixtures(object, fixtures, load_instances)
end
end
@@ -901,8 +901,8 @@ module ActiveRecord
ActiveRecord::Fixtures.instantiate_all_loaded_fixtures(self, load_instances?)
else
raise RuntimeError, 'Load fixtures before instantiating them.' if @loaded_fixtures.nil?
- @loaded_fixtures.each do |fixture_name, fixtures|
- ActiveRecord::Fixtures.instantiate_fixtures(self, fixture_name, fixtures, load_instances?)
+ @loaded_fixtures.each_value do |fixtures|
+ ActiveRecord::Fixtures.instantiate_fixtures(self, fixtures, load_instances?)
end
end
end
--
cgit v1.2.3
From caeca1f69b3a6f25248390daa37561cf2cbd8cd6 Mon Sep 17 00:00:00 2001
From: Alexey Muranov
Date: Sun, 1 Jan 2012 18:53:16 +0100
Subject: Remove unused private method in fixtures.rb
Remove the unused private method ActiveRecord::Fixtures#yaml_fixtures_key(path).
---
activerecord/lib/active_record/fixtures.rb | 3 ---
1 file changed, 3 deletions(-)
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index a6995b8e96..06db1f5a92 100644
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -651,9 +651,6 @@ module ActiveRecord
"#{@fixture_path}.yml"
end
- def yaml_fixtures_key(path)
- ::File.basename(@fixture_path).split(".").first
- end
end
class Fixture #:nodoc:
--
cgit v1.2.3
From e154823935859ae918ca26a7e73477d331e4a142 Mon Sep 17 00:00:00 2001
From: Nikita Beloglazov
Date: Thu, 26 Apr 2012 21:05:56 +0300
Subject: Fix bug when url_for changes controller.
---
actionpack/lib/action_dispatch/routing/route_set.rb | 4 ++--
actionpack/test/dispatch/routing_test.rb | 9 +++++++++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 8fc0f283fc..a2044cc33b 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -494,11 +494,11 @@ module ActionDispatch
if options[:controller]
options[:action] ||= 'index'
- options[:controller] = options[:controller].to_s
+ options[:controller] = options[:controller].to_s.dup
end
if options[:action]
- options[:action] = options[:action].to_s
+ options[:action] = options[:action].to_s.dup
end
end
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index e5345754cd..6d0cfe9b8a 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -829,6 +829,15 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
assert_equal original_options, options
end
+ # checks that url_for doesn't change controller and action
+ def test_url_for_with_no_side_effects_on_strings
+ # freeze controller and action to be sure they are not changed
+ # we'll get RuntimeError if somebody tries to modify them
+ options = {:controller => '/projects'.freeze, :action => 'status'.freeze}
+
+ url_for options
+ end
+
# tests the arguments modification free version of define_hash_access
def test_named_route_with_no_side_effects
original_options = { :host => 'test.host' }
--
cgit v1.2.3
From beea9f5d4eb96a6d13863a403ce100ae9710259a Mon Sep 17 00:00:00 2001
From: Andrew White
Date: Wed, 9 May 2012 11:48:33 +0100
Subject: Refactor Generator class to not rely on in-place editing the
controller
---
actionpack/lib/action_dispatch/routing/route_set.rb | 15 ++++++++++-----
actionpack/test/dispatch/routing_test.rb | 12 ++++++------
2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index a2044cc33b..58c67e2cbe 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -460,12 +460,12 @@ module ActionDispatch
normalize_options!
normalize_controller_action_id!
use_relative_controller!
- controller.sub!(%r{^/}, '') if controller
+ normalize_controller!
handle_nil_action!
end
def controller
- @controller ||= @options[:controller]
+ @options[:controller]
end
def current_controller
@@ -494,11 +494,11 @@ module ActionDispatch
if options[:controller]
options[:action] ||= 'index'
- options[:controller] = options[:controller].to_s.dup
+ options[:controller] = options[:controller].to_s
end
if options[:action]
- options[:action] = options[:action].to_s.dup
+ options[:action] = options[:action].to_s
end
end
@@ -522,10 +522,15 @@ module ActionDispatch
old_parts = current_controller.split('/')
size = controller.count("/") + 1
parts = old_parts[0...-size] << controller
- @controller = @options[:controller] = parts.join("/")
+ @options[:controller] = parts.join("/")
end
end
+ # Remove leading slashes from controllers
+ def normalize_controller!
+ @options[:controller] = controller.sub(%r{^/}, '') if controller
+ end
+
# This handles the case of :action => nil being explicitly passed.
# It is identical to :action => "index"
def handle_nil_action!
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 6d0cfe9b8a..d356187ca8 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -829,13 +829,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
assert_equal original_options, options
end
- # checks that url_for doesn't change controller and action
- def test_url_for_with_no_side_effects_on_strings
- # freeze controller and action to be sure they are not changed
- # we'll get RuntimeError if somebody tries to modify them
- options = {:controller => '/projects'.freeze, :action => 'status'.freeze}
+ def test_url_for_does_not_modify_controller
+ controller = '/projects'
+ options = {:controller => controller, :action => 'status', :only_path => true}
+ url = url_for(options)
- url_for options
+ assert_equal '/projects/status', url
+ assert_equal '/projects', controller
end
# tests the arguments modification free version of define_hash_access
--
cgit v1.2.3
From 44d1804b0a86de02865c48c552bbc57da3dc7836 Mon Sep 17 00:00:00 2001
From: Hemant Kumar
Date: Wed, 9 May 2012 17:32:15 +0530
Subject: Fix transaction state not changing when after record gets commited
---
activerecord/lib/active_record/transactions.rb | 8 ++-----
.../test/cases/transaction_callbacks_test.rb | 25 ++++++++++++++++++++++
2 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb
index 743dfc5a38..64e5640791 100644
--- a/activerecord/lib/active_record/transactions.rb
+++ b/activerecord/lib/active_record/transactions.rb
@@ -302,12 +302,8 @@ module ActiveRecord
def remember_transaction_record_state #:nodoc:
@_start_transaction_state ||= {}
@_start_transaction_state[:id] = id if has_attribute?(self.class.primary_key)
- unless @_start_transaction_state.include?(:new_record)
- @_start_transaction_state[:new_record] = @new_record
- end
- unless @_start_transaction_state.include?(:destroyed)
- @_start_transaction_state[:destroyed] = @destroyed
- end
+ @_start_transaction_state[:new_record] = @new_record
+ @_start_transaction_state[:destroyed] = @destroyed
@_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) + 1
end
diff --git a/activerecord/test/cases/transaction_callbacks_test.rb b/activerecord/test/cases/transaction_callbacks_test.rb
index f8b3e01a49..9246157a13 100644
--- a/activerecord/test/cases/transaction_callbacks_test.rb
+++ b/activerecord/test/cases/transaction_callbacks_test.rb
@@ -290,3 +290,28 @@ class TransactionObserverCallbacksTest < ActiveRecord::TestCase
assert_equal %w{ after_rollback }, topic.history
end
end
+
+class SaveFromAfterCommitBlockTest < ActiveRecord::TestCase
+ self.use_transactional_fixtures = false
+
+ class TopicWithSaveInCallback < ActiveRecord::Base
+ self.table_name = :topics
+ after_commit :cache_topic, :on => :create
+ attr_accessor :cached
+
+ def cache_topic
+ unless cached
+ self.cached = true
+ self.save
+ else
+ self.cached = false
+ end
+ end
+ end
+
+ def test_after_commit_in_save
+ topic = TopicWithSaveInCallback.new()
+ topic.save
+ assert_equal true, topic.cached
+ end
+end
--
cgit v1.2.3
From 821771374f32e77d9ca3fb951ef53d629199a4c8 Mon Sep 17 00:00:00 2001
From: "Mark J. Titorenko"
Date: Wed, 9 May 2012 13:35:49 +0100
Subject: Add CHANGELOG section for unreleased Rails 3.2.4; document addition
of #beginning_of_hour and #end_of_hour to Time and DateTime core extensions.
---
activesupport/CHANGELOG.md | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index b02cefa600..288e1affbd 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -38,6 +38,17 @@
of wrapping them in strings for safety.
+## Rails 3.2.4 (unreleased) ##
+
+* Added #beginning_of_hour and #end_of_hour to Time and DateTime core
+ extensions. *Mark J. Titorenko*
+
+
+## Rails 3.2.3 (March 30, 2012) ##
+
+* No changes.
+
+
## Rails 3.2.2 (March 1, 2012) ##
* No changes.
--
cgit v1.2.3
From 946875db2246b88c922a8370652d5c44dbb1939e Mon Sep 17 00:00:00 2001
From: "Mark J. Titorenko"
Date: Wed, 9 May 2012 13:40:08 +0100
Subject: Consistent CHANGELOG entry indentation.
---
activesupport/CHANGELOG.md | 44 ++++++++++++++++++++++----------------------
1 file changed, 22 insertions(+), 22 deletions(-)
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index 288e1affbd..c0d780789a 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,41 +1,41 @@
## Rails 4.0.0 (unreleased) ##
-* `deep_dup` works more expectedly now and duplicates also values in +Hash+ instances and elements in +Array+ instances. *Alexey Gaziev*
+* `deep_dup` works more expectedly now and duplicates also values in +Hash+ instances and elements in +Array+ instances. *Alexey Gaziev*
-* Inflector no longer applies ice -> ouse to words like slice, police, ets *Wes Morgan*
+* Inflector no longer applies ice -> ouse to words like slice, police, ets *Wes Morgan*
-* Add `ActiveSupport::Deprecations.behavior = :silence` to completely ignore Rails runtime deprecations *twinturbo*
+* Add `ActiveSupport::Deprecations.behavior = :silence` to completely ignore Rails runtime deprecations *twinturbo*
-* Make Module#delegate stop using `send` - can no longer delegate to private methods. *dasch*
+* Make Module#delegate stop using `send` - can no longer delegate to private methods. *dasch*
-* AS::Callbacks: deprecate `:rescuable` option. *Bogdan Gusiev*
+* AS::Callbacks: deprecate `:rescuable` option. *Bogdan Gusiev*
-* Adds Integer#ordinal to get the ordinal suffix string of an integer. *Tim Gildea*
+* Adds Integer#ordinal to get the ordinal suffix string of an integer. *Tim Gildea*
-* AS::Callbacks: `:per_key` option is no longer supported
+* AS::Callbacks: `:per_key` option is no longer supported
-* `AS::Callbacks#define_callbacks`: add `:skip_after_callbacks_if_terminated` option.
+* `AS::Callbacks#define_callbacks`: add `:skip_after_callbacks_if_terminated` option.
-* Add html_escape_once to ERB::Util, and delegate escape_once tag helper to it. *Carlos Antonio da Silva*
+* Add html_escape_once to ERB::Util, and delegate escape_once tag helper to it. *Carlos Antonio da Silva*
-* Remove ActiveSupport::TestCase#pending method, use `skip` instead. *Carlos Antonio da Silva*
+* Remove ActiveSupport::TestCase#pending method, use `skip` instead. *Carlos Antonio da Silva*
-* Deprecates the compatibility method Module#local_constant_names,
- use Module#local_constants instead (which returns symbols). *fxn*
+* Deprecates the compatibility method Module#local_constant_names,
+ use Module#local_constants instead (which returns symbols). *fxn*
-* Deletes the compatibility method Module#method_names,
- use Module#methods from now on (which returns symbols). *fxn*
+* Deletes the compatibility method Module#method_names,
+ use Module#methods from now on (which returns symbols). *fxn*
-* Deletes the compatibility method Module#instance_method_names,
- use Module#instance_methods from now on (which returns symbols). *fxn*
+* Deletes the compatibility method Module#instance_method_names,
+ use Module#instance_methods from now on (which returns symbols). *fxn*
-* BufferedLogger is deprecated. Use ActiveSupport::Logger, or the logger
- from Ruby stdlib.
+* BufferedLogger is deprecated. Use ActiveSupport::Logger, or the logger
+ from Ruby stdlib.
-* Unicode database updated to 6.1.0.
+* Unicode database updated to 6.1.0.
-* Adds `encode_big_decimal_as_string` option to force JSON serialization of BigDecimals as numeric instead
- of wrapping them in strings for safety.
+* Adds `encode_big_decimal_as_string` option to force JSON serialization of BigDecimals as numeric instead
+ of wrapping them in strings for safety.
## Rails 3.2.4 (unreleased) ##
@@ -241,7 +241,7 @@
* Hash.from_xml no longer loses attributes on tags containing only whitespace *André Arko*
-## Rails 3.0.6 (April 5, 2011) ##
+## Rails 3.0.6 (April 5, 2011) ##
* No changes.
--
cgit v1.2.3
From 1024c688a9190461549d4943661e9862cb1a17d4 Mon Sep 17 00:00:00 2001
From: Hemant Kumar
Date: Wed, 9 May 2012 18:37:46 +0530
Subject: after_commit :on => :update should be called when save is
called from after_commit callback
---
activerecord/test/cases/transaction_callbacks_test.rb | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/activerecord/test/cases/transaction_callbacks_test.rb b/activerecord/test/cases/transaction_callbacks_test.rb
index 9246157a13..6e6a9afeff 100644
--- a/activerecord/test/cases/transaction_callbacks_test.rb
+++ b/activerecord/test/cases/transaction_callbacks_test.rb
@@ -297,7 +297,13 @@ class SaveFromAfterCommitBlockTest < ActiveRecord::TestCase
class TopicWithSaveInCallback < ActiveRecord::Base
self.table_name = :topics
after_commit :cache_topic, :on => :create
+ after_commit :call_update, :on => :update
attr_accessor :cached
+ attr_accessor :record_updated
+
+ def call_update
+ self.record_updated = true
+ end
def cache_topic
unless cached
@@ -313,5 +319,6 @@ class SaveFromAfterCommitBlockTest < ActiveRecord::TestCase
topic = TopicWithSaveInCallback.new()
topic.save
assert_equal true, topic.cached
+ assert_equal true, topic.record_updated
end
end
--
cgit v1.2.3
From 041b6c6ccb2130ee8c87db2dd53736c22a79f3e8 Mon Sep 17 00:00:00 2001
From: Hemant Kumar
Date: Wed, 9 May 2012 18:43:18 +0530
Subject: make both cached and record_updated accessors in one line
---
activerecord/test/cases/transaction_callbacks_test.rb | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/activerecord/test/cases/transaction_callbacks_test.rb b/activerecord/test/cases/transaction_callbacks_test.rb
index 6e6a9afeff..9846f5b12d 100644
--- a/activerecord/test/cases/transaction_callbacks_test.rb
+++ b/activerecord/test/cases/transaction_callbacks_test.rb
@@ -298,8 +298,7 @@ class SaveFromAfterCommitBlockTest < ActiveRecord::TestCase
self.table_name = :topics
after_commit :cache_topic, :on => :create
after_commit :call_update, :on => :update
- attr_accessor :cached
- attr_accessor :record_updated
+ attr_accessor :cached, :record_updated
def call_update
self.record_updated = true
--
cgit v1.2.3
From 12ceb4581aeef1638b9e38545210bd0004adbb8f Mon Sep 17 00:00:00 2001
From: Alexey Muranov
Date: Sun, 1 Jan 2012 18:54:52 +0100
Subject: Rename some variables
Rename some parameters and instance and local variables, mostly in fixtures.rb. Also remove an unused assignment to an instance variable.
There are minor code changes.
---
activerecord/lib/active_record/fixtures.rb | 156 +++++++++++++++--------------
activerecord/test/cases/helper.rb | 4 +-
2 files changed, 82 insertions(+), 78 deletions(-)
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index 06db1f5a92..c630af59f0 100644
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -372,19 +372,23 @@ module ActiveRecord
#
# Any fixture labeled "DEFAULTS" is safely ignored.
class Fixtures
+ #--
+ # NOTE: an instance of Fixtures can be called fixture_set, it is normally stored in a single YAML file and possibly in a folder with the same name.
+ #++
MAX_ID = 2 ** 30 - 1
@@all_cached_fixtures = Hash.new { |h,k| h[k] = {} }
- def self.default_fixture_model_name(fixture_name) # :nodoc:
+ def self.default_fixture_model_name(fixture_set_name) # :nodoc:
ActiveRecord::Base.pluralize_table_names ?
- fixture_name.singularize.camelize :
- fixture_name.camelize
+ fixture_set_name.singularize.camelize :
+ fixture_set_name.camelize
end
- def self.default_fixture_table_name(fixture_name) # :nodoc:
- "#{ActiveRecord::Base.table_name_prefix}"\
- "#{fixture_name.tr('/', '_')}#{ActiveRecord::Base.table_name_suffix}".to_sym
+ def self.default_fixture_table_name(fixture_set_name) # :nodoc:
+ "#{ ActiveRecord::Base.table_name_prefix }"\
+ "#{ fixture_set_name.tr('/', '_') }"\
+ "#{ ActiveRecord::Base.table_name_suffix }".to_sym
end
def self.reset_cache
@@ -411,11 +415,11 @@ module ActiveRecord
cache_for_connection(connection).update(fixtures_map)
end
- def self.instantiate_fixtures(object, fixtures, load_instances = true)
+ def self.instantiate_fixtures(object, fixture_set, load_instances = true)
if load_instances
- fixtures.each do |name, fixture|
+ fixture_set.each do |fixture_name, fixture|
begin
- object.instance_variable_set "@#{name}", fixture.find
+ object.instance_variable_set "@#{fixture_name}", fixture.find
rescue FixtureClassNotFound
nil
end
@@ -424,61 +428,59 @@ module ActiveRecord
end
def self.instantiate_all_loaded_fixtures(object, load_instances = true)
- all_loaded_fixtures.each_value do |fixtures|
- instantiate_fixtures(object, fixtures, load_instances)
+ all_loaded_fixtures.each_value do |fixture_set|
+ instantiate_fixtures(object, fixture_set, load_instances)
end
end
cattr_accessor :all_loaded_fixtures
self.all_loaded_fixtures = {}
- def self.create_fixtures(fixtures_directory, table_names, class_names = {})
- table_names = Array(table_names).map(&:to_s)
+ def self.create_fixtures(fixtures_directory, fixture_set_names, class_names = {})
+ fixture_set_names = Array(fixture_set_names).map(&:to_s)
class_names = class_names.stringify_keys
# FIXME: Apparently JK uses this.
connection = block_given? ? yield : ActiveRecord::Base.connection
- files_to_read = table_names.reject { |table_name|
- fixture_is_cached?(connection, table_name)
+ files_to_read = fixture_set_names.reject { |fs_name|
+ fixture_is_cached?(connection, fs_name)
}
unless files_to_read.empty?
connection.disable_referential_integrity do
fixtures_map = {}
- fixture_files = files_to_read.map do |path|
- fixture_name = path
-
- fixtures_map[fixture_name] = new( # ActiveRecord::Fixtures.new
+ fixture_sets = files_to_read.map do |fs_name|
+ fixtures_map[fs_name] = new( # ActiveRecord::Fixtures.new
connection,
- fixture_name,
- class_names[fixture_name.to_s] || default_fixture_model_name(fixture_name),
- ::File.join(fixtures_directory, path))
+ fs_name,
+ class_names[fs_name] || default_fixture_model_name(fs_name),
+ ::File.join(fixtures_directory, fs_name))
end
all_loaded_fixtures.update(fixtures_map)
connection.transaction(:requires_new => true) do
- fixture_files.each do |ff|
- conn = ff.model_class.respond_to?(:connection) ? ff.model_class.connection : connection
- table_rows = ff.table_rows
+ fixture_sets.each do |fs|
+ conn = fs.model_class.respond_to?(:connection) ? fs.model_class.connection : connection
+ table_rows = fs.table_rows
table_rows.keys.each do |table|
conn.delete "DELETE FROM #{conn.quote_table_name(table)}", 'Fixture Delete'
end
- table_rows.each do |table_name,rows|
+ table_rows.each do |fixture_set_name, rows|
rows.each do |row|
- conn.insert_fixture(row, table_name)
+ conn.insert_fixture(row, fixture_set_name)
end
end
end
# Cap primary key sequences to max(pk).
if connection.respond_to?(:reset_pk_sequence!)
- fixture_files.each do |ff|
- connection.reset_pk_sequence!(ff.table_name)
+ fixture_sets.each do |fs|
+ connection.reset_pk_sequence!(fs.table_name)
end
end
end
@@ -486,7 +488,7 @@ module ActiveRecord
cache_fixtures(connection, fixtures_map)
end
end
- cached_fixtures(connection, table_names)
+ cached_fixtures(connection, fixture_set_names)
end
# Returns a consistent, platform-independent identifier for +label+.
@@ -497,26 +499,23 @@ module ActiveRecord
attr_reader :table_name, :name, :fixtures, :model_class
- def initialize(connection, fixture_name, class_name, fixture_path)
- @connection = connection
- @fixture_path = fixture_path
- @name = fixture_name
- @class_name = class_name
-
- @fixtures = {}
+ def initialize(connection, name, class_name, path)
+ @fixtures = {} # Ordered hash
+ @name = name
+ @path = path
- # Should be an AR::Base type class
- if class_name.is_a?(Class)
+ if class_name.is_a?(Class) # TODO: Should be an AR::Base type class, or any?
@model_class = class_name
else
@model_class = class_name.constantize rescue nil
end
- @connection = model_class.connection if model_class && model_class.respond_to?(:connection)
+ @connection = ( model_class.respond_to?(:connection) ?
+ model_class.connection : connection )
@table_name = ( model_class.respond_to?(:table_name) ?
model_class.table_name :
- self.class.default_fixture_table_name(fixture_name) )
+ self.class.default_fixture_table_name(name) )
read_fixture_files
end
@@ -555,8 +554,8 @@ module ActiveRecord
if model_class && model_class < ActiveRecord::Model
# fill in timestamp columns if they aren't specified and the model is set to record_timestamps
if model_class.record_timestamps
- timestamp_column_names.each do |name|
- row[name] = now unless row.key?(name)
+ timestamp_column_names.each do |c_name|
+ row[c_name] = now unless row.key?(c_name)
end
end
@@ -634,21 +633,21 @@ module ActiveRecord
end
def read_fixture_files
- yaml_files = Dir["#{@fixture_path}/**/*.yml"].select { |f|
+ yaml_files = Dir["#{@path}/**/*.yml"].select { |f|
::File.file?(f)
} + [yaml_file_path]
yaml_files.each do |file|
Fixtures::File.open(file) do |fh|
- fh.each do |name, row|
- fixtures[name] = ActiveRecord::Fixture.new(row, model_class)
+ fh.each do |fixture_name, row|
+ fixtures[fixture_name] = ActiveRecord::Fixture.new(row, model_class)
end
end
end
end
def yaml_file_path
- "#{@fixture_path}.yml"
+ "#{@path}.yml"
end
end
@@ -705,7 +704,7 @@ module ActiveRecord
class_attribute :fixture_table_names
class_attribute :fixture_class_names
class_attribute :use_transactional_fixtures
- class_attribute :use_instantiated_fixtures # true, false, or :no_instances
+ class_attribute :use_instantiated_fixtures # true, false, or :no_instances
class_attribute :pre_loaded_fixtures
self.fixture_table_names = []
@@ -713,9 +712,8 @@ module ActiveRecord
self.use_instantiated_fixtures = false
self.pre_loaded_fixtures = false
- self.fixture_class_names = Hash.new do |h, fixture_name|
- fixture_name = fixture_name.to_s
- h[fixture_name] = ActiveRecord::Fixtures.default_fixture_model_name(fixture_name)
+ self.fixture_class_names = Hash.new do |h, fixture_set_name|
+ h[fixture_set_name] = ActiveRecord::Fixtures.default_fixture_model_name(fixture_set_name)
end
end
@@ -739,18 +737,18 @@ module ActiveRecord
self.fixture_class_names = self.fixture_class_names.merge(class_names.stringify_keys)
end
- def fixtures(*fixture_names)
- if fixture_names.first == :all
- fixture_names = Dir["#{fixture_path}/**/*.yml"].map { |f|
+ def fixtures(*fixture_set_names)
+ if fixture_set_names.first == :all
+ fixture_set_names = Dir["#{fixture_path}/**/*.yml"].map { |f|
File.basename f, '.yml'
}
else
- fixture_names = fixture_names.flatten.map { |n| n.to_s }
+ fixture_set_names = fixture_set_names.flatten.map { |n| n.to_s }
end
- self.fixture_table_names |= fixture_names
- require_fixture_classes(fixture_names)
- setup_fixture_accessors(fixture_names)
+ self.fixture_table_names |= fixture_set_names
+ require_fixture_classes(fixture_set_names)
+ setup_fixture_accessors(fixture_set_names)
end
def try_to_load_dependency(file_name)
@@ -765,33 +763,39 @@ module ActiveRecord
end
end
- def require_fixture_classes(fixture_names = nil)
- (fixture_names || fixture_table_names).each do |fixture_name|
- file_name = fixture_name.to_s
+ def require_fixture_classes(fixture_set_names = nil)
+ if fixture_set_names
+ fixture_set_names = fixture_set_names.map { |n| n.to_s }
+ else
+ fixture_set_names = fixture_table_names
+ end
+
+ fixture_set_names.each do |file_name|
file_name = file_name.singularize if ActiveRecord::Base.pluralize_table_names
try_to_load_dependency(file_name)
end
end
- def setup_fixture_accessors(fixture_names = nil)
- fixture_names = Array(fixture_names || fixture_table_names)
+ def setup_fixture_accessors(fixture_set_names = nil)
+ fixture_set_names = Array(fixture_set_names || fixture_table_names)
methods = Module.new do
- fixture_names.each do |fixture_name|
- fixture_name = fixture_name.to_s
- accessor_name = fixture_name.tr('/', '_').to_sym
+ fixture_set_names.each do |fs_name|
+ fs_name = fs_name.to_s
+ accessor_name = fs_name.tr('/', '_').to_sym
- define_method(accessor_name) do |*fixtures|
- force_reload = fixtures.pop if fixtures.last == true || fixtures.last == :reload
+ define_method(accessor_name) do |*fixture_names|
+ force_reload = fixture_names.pop if fixture_names.last == true || fixture_names.last == :reload
- @fixture_cache[fixture_name] ||= {}
+ @fixture_cache[fs_name] ||= {}
- instances = fixtures.map do |fixture|
- @fixture_cache[fixture_name].delete(fixture) if force_reload
+ instances = fixture_names.map do |f_name|
+ f_name = f_name.to_s
+ @fixture_cache[fs_name].delete(f_name) if force_reload
- if @loaded_fixtures[fixture_name][fixture.to_s]
- @fixture_cache[fixture_name][fixture] ||= @loaded_fixtures[fixture_name][fixture.to_s].find
+ if @loaded_fixtures[fs_name][f_name]
+ @fixture_cache[fs_name][f_name] ||= @loaded_fixtures[fs_name][f_name].find
else
- raise StandardError, "No entry named '#{fixture}' found for fixture collection '#{fixture_name}'"
+ raise StandardError, "No fixture named '#{f_name}' found for fixture set '#{fs_name}'"
end
end
@@ -898,8 +902,8 @@ module ActiveRecord
ActiveRecord::Fixtures.instantiate_all_loaded_fixtures(self, load_instances?)
else
raise RuntimeError, 'Load fixtures before instantiating them.' if @loaded_fixtures.nil?
- @loaded_fixtures.each_value do |fixtures|
- ActiveRecord::Fixtures.instantiate_fixtures(self, fixtures, load_instances?)
+ @loaded_fixtures.each_value do |fixture_set|
+ ActiveRecord::Fixtures.instantiate_fixtures(self, fixture_set, load_instances?)
end
end
end
diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb
index 345ae0b582..20279f814b 100644
--- a/activerecord/test/cases/helper.rb
+++ b/activerecord/test/cases/helper.rb
@@ -80,8 +80,8 @@ class ActiveSupport::TestCase
self.use_instantiated_fixtures = false
self.use_transactional_fixtures = true
- def create_fixtures(*table_names, &block)
- ActiveRecord::Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names, fixture_class_names, &block)
+ def create_fixtures(*fixture_set_names, &block)
+ ActiveRecord::Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, fixture_set_names, fixture_class_names, &block)
end
end
--
cgit v1.2.3
From 3a6ffbbe42688f40edc8e0a12d0f556ef3720b9d Mon Sep 17 00:00:00 2001
From: Nick Novitski
Date: Wed, 9 May 2012 13:20:19 -0700
Subject: remove inappropriate comma
A qualifying clause beginning with words like "as", "if", or "although" should have a comma separating it from any following clauses in a sentence, but should not have a comma immediately after the beginning word, unless it is to separate a third, non-essential clause.
Example 1: "Although I would quite like to go to lunch with you, I find myself instead writing a detailed commit message to justify a single-character documentation change."
Example 2: "Despite, as you might well imagine, wishing I hadn't even noticed it in the first place, I still felt the error was worth correcting."
---
guides/source/security.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/guides/source/security.textile b/guides/source/security.textile
index ac64b82bf6..ac55d60368 100644
--- a/guides/source/security.textile
+++ b/guides/source/security.textile
@@ -627,7 +627,7 @@ h4. Whitelists versus Blacklists
-- _When sanitizing, protecting or verifying something, whitelists over blacklists._
-A blacklist can be a list of bad e-mail addresses, non-public actions or bad HTML tags. This is opposed to a whitelist which lists the good e-mail addresses, public actions, good HTML tags and so on. Although, sometimes it is not possible to create a whitelist (in a SPAM filter, for example), _(highlight)prefer to use whitelist approaches_:
+A blacklist can be a list of bad e-mail addresses, non-public actions or bad HTML tags. This is opposed to a whitelist which lists the good e-mail addresses, public actions, good HTML tags and so on. Although sometimes it is not possible to create a whitelist (in a SPAM filter, for example), _(highlight)prefer to use whitelist approaches_:
* Use before_filter :only => [...] instead of :except => [...]. This way you don't forget to turn it off for newly added actions.
* Use attr_accessible instead of attr_protected. See the mass-assignment section for details
--
cgit v1.2.3
From ea40990f4b64e4518d9f34e3d3101d2480217e19 Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Wed, 9 May 2012 17:08:36 -0700
Subject: Allow to run `connection_adapters/quoting_test.rb` independently
---
activerecord/test/cases/connection_adapters/quoting_test.rb | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/activerecord/test/cases/connection_adapters/quoting_test.rb b/activerecord/test/cases/connection_adapters/quoting_test.rb
index f523cea9ca..59dcb96ebc 100644
--- a/activerecord/test/cases/connection_adapters/quoting_test.rb
+++ b/activerecord/test/cases/connection_adapters/quoting_test.rb
@@ -1,3 +1,5 @@
+require "cases/helper"
+
module ActiveRecord
module ConnectionAdapters
module Quoting
@@ -8,4 +10,4 @@ module ActiveRecord
end
end
end
-end
\ No newline at end of file
+end
--
cgit v1.2.3
From 6cbe8dab1e64d42eb376137366b48f1e20f9ddb9 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Thu, 10 May 2012 02:09:59 -0500
Subject: deleting empty lines in docs parts
---
activesupport/lib/active_support/callbacks.rb | 8 --------
1 file changed, 8 deletions(-)
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index cbeba3139a..1972d439ed 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -54,7 +54,6 @@ module ActiveSupport
# saving...
# - save
# saved
- #
module Callbacks
extend Concern
@@ -73,7 +72,6 @@ module ActiveSupport
# run_callbacks :save do
# save
# end
- #
def run_callbacks(kind, key = nil, &block)
#TODO: deprecate key argument
runner_name = self.class.__define_callbacks(kind, self)
@@ -199,7 +197,6 @@ module ActiveSupport
# yield self
# end
# end
- #
def define_conditional_callback
name = "_conditional_callback_#{@kind}_#{next_id}"
@klass.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
@@ -253,7 +250,6 @@ module ActiveSupport
# Objects::
# a method is created that calls the before_foo method
# on the object.
- #
def _compile_filter(filter)
method_name = "_callback_#{@kind}_#{next_id}"
case filter
@@ -405,7 +401,6 @@ module ActiveSupport
# will be called only when it returns a false value.
# * :prepend - If true, the callback will be prepended to the existing
# chain rather than appended.
- #
def set_callback(name, *filter_list, &block)
mapped = nil
@@ -430,7 +425,6 @@ module ActiveSupport
# class Writer < Person
# skip_callback :validate, :before, :check_membership, :if => lambda { self.age > 18 }
# end
- #
def skip_callback(name, *filter_list, &block)
__update_callbacks(name, filter_list, block) do |target, chain, type, filters, options|
filters.each do |filter|
@@ -449,7 +443,6 @@ module ActiveSupport
end
# Remove all set callbacks for the given event.
- #
def reset_callbacks(symbol)
callbacks = send("_#{symbol}_callbacks")
@@ -530,7 +523,6 @@ module ActiveSupport
# define_callbacks :save, :scope => [:name]
#
# would call Audit#save.
- #
def define_callbacks(*callbacks)
config = callbacks.last.is_a?(Hash) ? callbacks.pop : {}
callbacks.each do |callback|
--
cgit v1.2.3
From c1ce4144d1ef5bea3d829167cb52a5abc8d2ef7e Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Thu, 10 May 2012 02:21:03 -0500
Subject: AS::Callbacks#run_callbacks remove key argument
---
activesupport/CHANGELOG.md | 2 ++
activesupport/lib/active_support/callbacks.rb | 3 +--
activesupport/test/callback_inheritance_test.rb | 2 +-
activesupport/test/callbacks_test.rb | 6 +++---
4 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index c0d780789a..ef96df9227 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,5 +1,7 @@
## Rails 4.0.0 (unreleased) ##
+* `AS::Callbacks#run_callbacks` remove `key` argument. *Francesco Rodriguez*
+
* `deep_dup` works more expectedly now and duplicates also values in +Hash+ instances and elements in +Array+ instances. *Alexey Gaziev*
* Inflector no longer applies ice -> ouse to words like slice, police, ets *Wes Morgan*
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index cbeba3139a..3c7dbb369c 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -74,8 +74,7 @@ module ActiveSupport
# save
# end
#
- def run_callbacks(kind, key = nil, &block)
- #TODO: deprecate key argument
+ def run_callbacks(kind, &block)
runner_name = self.class.__define_callbacks(kind, self)
send(runner_name, &block)
end
diff --git a/activesupport/test/callback_inheritance_test.rb b/activesupport/test/callback_inheritance_test.rb
index e5ac9511df..6be8ea8b84 100644
--- a/activesupport/test/callback_inheritance_test.rb
+++ b/activesupport/test/callback_inheritance_test.rb
@@ -29,7 +29,7 @@ class GrandParent
end
def dispatch
- run_callbacks(:dispatch, action_name) do
+ run_callbacks :dispatch do
@log << action_name
end
self
diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb
index 25688a9da5..b7c3b130c3 100644
--- a/activesupport/test/callbacks_test.rb
+++ b/activesupport/test/callbacks_test.rb
@@ -112,7 +112,7 @@ module CallbacksTest
end
def dispatch
- run_callbacks :dispatch, action_name do
+ run_callbacks :dispatch do
@logger << "Done"
end
self
@@ -153,7 +153,7 @@ module CallbacksTest
end
def save
- run_callbacks :save, :action
+ run_callbacks :save
end
end
@@ -338,7 +338,7 @@ module CallbacksTest
end
def save
- run_callbacks :save, "hyphen-ated" do
+ run_callbacks :save do
@stuff
end
end
--
cgit v1.2.3
From e471aacf60f36a6f3074eebe32216b8c55c02434 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Thu, 10 May 2012 02:56:36 -0500
Subject: removing key argument from run_callbacks - fix build
---
actionpack/lib/abstract_controller/callbacks.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/actionpack/lib/abstract_controller/callbacks.rb b/actionpack/lib/abstract_controller/callbacks.rb
index 520c210721..5705ab590c 100644
--- a/actionpack/lib/abstract_controller/callbacks.rb
+++ b/actionpack/lib/abstract_controller/callbacks.rb
@@ -14,7 +14,7 @@ module AbstractController
# Override AbstractController::Base's process_action to run the
# process_action callbacks around the normal behavior.
def process_action(*args)
- run_callbacks(:process_action, action_name) do
+ run_callbacks(:process_action) do
super
end
end
--
cgit v1.2.3
From 039917b4086c3567f298716114301b161bb5b1fe Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Thu, 10 May 2012 03:29:46 -0500
Subject: Remove key argument from run_callbacks to fix build
---
activesupport/lib/active_support/testing/performance.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb
index 244ee1a224..f6bf0318f7 100644
--- a/activesupport/lib/active_support/testing/performance.rb
+++ b/activesupport/lib/active_support/testing/performance.rb
@@ -61,7 +61,7 @@ module ActiveSupport
ensure
begin
teardown
- run_callbacks :teardown, :enumerator => :reverse_each
+ run_callbacks :teardown
rescue Exception => e
result = @runner.puke(self.class, method_name, e)
end
--
cgit v1.2.3
From b5005b6259144eeea5b903d659f54bd8a0343d25 Mon Sep 17 00:00:00 2001
From: grosser
Date: Thu, 10 May 2012 08:19:45 -0700
Subject: add unless_exist option to memory store
---
activesupport/lib/active_support/cache/memory_store.rb | 1 +
activesupport/test/caching_test.rb | 7 +++++++
2 files changed, 8 insertions(+)
diff --git a/activesupport/lib/active_support/cache/memory_store.rb b/activesupport/lib/active_support/cache/memory_store.rb
index b15bb42c88..7fd5e3b53d 100644
--- a/activesupport/lib/active_support/cache/memory_store.rb
+++ b/activesupport/lib/active_support/cache/memory_store.rb
@@ -137,6 +137,7 @@ module ActiveSupport
def write_entry(key, entry, options) # :nodoc:
synchronize do
old_entry = @data[key]
+ return false if @data.key?(key) && options[:unless_exist]
@cache_size -= old_entry.size if old_entry
@cache_size += entry.size
@key_access[key] = Time.now.to_f
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index bb9ce23276..d62b782e2d 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -684,6 +684,13 @@ class MemoryStoreTest < ActiveSupport::TestCase
assert @cache.exist?(2)
assert !@cache.exist?(1)
end
+
+ def test_write_with_unless_exist
+ assert_equal true, @cache.write(1, "aaaaaaaaaa")
+ assert_equal false, @cache.write(1, "aaaaaaaaaa", :unless_exist => true)
+ @cache.write(1, nil)
+ assert_equal false, @cache.write(1, "aaaaaaaaaa", :unless_exist => true)
+ end
end
uses_memcached 'memcached backed store' do
--
cgit v1.2.3
From 32dd5fcaad8adda837fa7e501e23634ad9491d2d Mon Sep 17 00:00:00 2001
From: Rafael Magana
Date: Thu, 10 May 2012 08:59:44 -0700
Subject: remove duplicate usage of Rack::Utils.status_code in
LogSubscriber#process_action
---
actionpack/lib/action_controller/log_subscriber.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/actionpack/lib/action_controller/log_subscriber.rb b/actionpack/lib/action_controller/log_subscriber.rb
index 4c76f4c43b..11aa393bf9 100644
--- a/actionpack/lib/action_controller/log_subscriber.rb
+++ b/actionpack/lib/action_controller/log_subscriber.rb
@@ -20,7 +20,7 @@ module ActionController
status = payload[:status]
if status.nil? && payload[:exception].present?
- status = Rack::Utils.status_code(ActionDispatch::ExceptionWrapper.new({}, payload[:exception]).status_code)
+ status = ActionDispatch::ExceptionWrapper.new({}, payload[:exception]).status_code
end
message = "Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in %.0fms" % event.duration
message << " (#{additions.join(" | ")})" unless additions.blank?
--
cgit v1.2.3
From c8f5a216df7d14463027425b53968d7f7023bf85 Mon Sep 17 00:00:00 2001
From: Ben Wilhelm
Date: Thu, 10 May 2012 11:15:32 -0700
Subject: Modified template in sample is new.html.erb, not index.html.erb
---
guides/source/getting_started.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile
index 947abd7ba0..1e9bd1f144 100644
--- a/guides/source/getting_started.textile
+++ b/guides/source/getting_started.textile
@@ -717,7 +717,7 @@ If you reload
try to save a post without a title, Rails will send you back to the
form, but that's not very useful. You need to tell the user that
something went wrong. To do that, you'll modify
-+app/views/posts/index.html.erb+ to check for error messages:
++app/views/posts/new.html.erb+ to check for error messages:
<%= form_for :post, :url => { :action => :create } do |f| %>
--
cgit v1.2.3
From 5277d550d9a2039f82922ce9aca85ea4db5eb615 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Thu, 10 May 2012 17:24:53 +0530
Subject: remove unnecessary 'examples' noise [ci skip]
---
.../abstract/schema_definitions.rb | 24 ++++++++++------------
.../abstract/schema_statements.rb | 22 +++++++-------------
2 files changed, 18 insertions(+), 28 deletions(-)
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
index f0b6ae2b7d..f17baec722 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
@@ -262,7 +262,7 @@ module ActiveRecord
# Adds index options to the indexes hash, keyed by column name
# This is primarily used to track indexes that need to be created after the table
- # === Examples
+ #
# index(:account_id, :name => 'index_projects_on_account_id')
def index(column_name, options = {})
indexes[column_name] = options
@@ -348,7 +348,7 @@ module ActiveRecord
# Adds a new column to the named table.
# See TableDefinition#column for details of the options you can use.
- # ===== Example
+ #
# ====== Creating a simple column
# t.column(:name, :string)
def column(column_name, type, options = {})
@@ -363,7 +363,6 @@ module ActiveRecord
# Adds a new index to the table. +column_name+ can be a single Symbol, or
# an Array of Symbols. See SchemaStatements#add_index
#
- # ===== Examples
# ====== Creating a simple index
# t.index(:name)
# ====== Creating a unique index
@@ -380,7 +379,7 @@ module ActiveRecord
end
# Adds timestamps (+created_at+ and +updated_at+) columns to the table. See SchemaStatements#add_timestamps
- # ===== Example
+ #
# t.timestamps
def timestamps
@base.add_timestamps(@table_name)
@@ -388,7 +387,7 @@ module ActiveRecord
# Changes the column's definition according to the new options.
# See TableDefinition#column for details of the options you can use.
- # ===== Examples
+ #
# t.change(:name, :string, :limit => 80)
# t.change(:description, :text)
def change(column_name, type, options = {})
@@ -396,7 +395,7 @@ module ActiveRecord
end
# Sets a new default value for a column. See SchemaStatements#change_column_default
- # ===== Examples
+ #
# t.change_default(:qualification, 'new')
# t.change_default(:authorized, 1)
def change_default(column_name, default)
@@ -404,7 +403,7 @@ module ActiveRecord
end
# Removes the column(s) from the table definition.
- # ===== Examples
+ #
# t.remove(:qualification)
# t.remove(:qualification, :experience)
def remove(*column_names)
@@ -413,7 +412,6 @@ module ActiveRecord
# Removes the given index from the table.
#
- # ===== Examples
# ====== Remove the index_table_name_on_column in the table_name table
# t.remove_index :column
# ====== Remove the index named index_table_name_on_branch_id in the table_name table
@@ -427,14 +425,14 @@ module ActiveRecord
end
# Removes the timestamp columns (+created_at+ and +updated_at+) from the table.
- # ===== Example
+ #
# t.remove_timestamps
def remove_timestamps
@base.remove_timestamps(@table_name)
end
# Renames a column.
- # ===== Example
+ #
# t.rename(:description, :name)
def rename(column_name, new_column_name)
@base.rename_column(@table_name, column_name, new_column_name)
@@ -442,7 +440,7 @@ module ActiveRecord
# Adds a reference. Optionally adds a +type+ column, if :polymorphic option is provided.
# references and belongs_to are acceptable.
- # ===== Examples
+ #
# t.references(:goat)
# t.references(:goat, :polymorphic => true)
# t.belongs_to(:goat)
@@ -460,7 +458,7 @@ module ActiveRecord
# Removes a reference. Optionally removes a +type+ column.
# remove_references and remove_belongs_to are acceptable.
- # ===== Examples
+ #
# t.remove_references(:goat)
# t.remove_references(:goat, :polymorphic => true)
# t.remove_belongs_to(:goat)
@@ -475,7 +473,7 @@ module ActiveRecord
alias :remove_belongs_to :remove_references
# Adds a column or columns of a specified type
- # ===== Examples
+ #
# t.string(:goat)
# t.string(:goat, :sheep)
%w( string text integer float decimal datetime timestamp time date binary boolean ).each do |column_type|
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
index e7a4f061fd..62b0f51bb2 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -21,7 +21,6 @@ module ActiveRecord
# Checks to see if the table +table_name+ exists on the database.
#
- # === Example
# table_exists?(:developers)
def table_exists?(table_name)
tables.include?(table_name.to_s)
@@ -32,7 +31,6 @@ module ActiveRecord
# Checks to see if an index exists on a table for a given index definition.
#
- # === Examples
# # Check an index exists
# index_exists?(:suppliers, :company_id)
#
@@ -126,7 +124,6 @@ module ActiveRecord
# Set to true to drop the table before creating it.
# Defaults to false.
#
- # ===== Examples
# ====== Add a backend specific option to the generated SQL (MySQL)
# create_table(:suppliers, :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8')
# generates:
@@ -193,7 +190,6 @@ module ActiveRecord
# Set to true to drop the table before creating it.
# Defaults to false.
#
- # ===== Examples
# ====== Add a backend specific option to the generated SQL (MySQL)
# create_join_table(:assemblies, :parts, :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8')
# generates:
@@ -215,7 +211,6 @@ module ActiveRecord
# A block for changing columns in +table+.
#
- # === Example
# # change_table() yields a Table instance
# change_table(:suppliers) do |t|
# t.column :name, :string, :limit => 60
@@ -229,7 +224,6 @@ module ActiveRecord
#
# Defaults to false.
#
- # ===== Examples
# ====== Add a column
# change_table(:suppliers) do |t|
# t.column :name, :string, :limit => 60
@@ -288,7 +282,7 @@ module ActiveRecord
end
# Renames a table.
- # ===== Example
+ #
# rename_table('octopuses', 'octopi')
def rename_table(table_name, new_name)
raise NotImplementedError, "rename_table is not implemented"
@@ -308,7 +302,7 @@ module ActiveRecord
end
# Removes the column(s) from the table definition.
- # ===== Examples
+ #
# remove_column(:suppliers, :qualification)
# remove_columns(:suppliers, :qualification, :experience)
def remove_column(table_name, *column_names)
@@ -318,7 +312,7 @@ module ActiveRecord
# Changes the column's definition according to the new options.
# See TableDefinition#column for details of the options you can use.
- # ===== Examples
+ #
# change_column(:suppliers, :name, :string, :limit => 80)
# change_column(:accounts, :description, :text)
def change_column(table_name, column_name, type, options = {})
@@ -326,7 +320,7 @@ module ActiveRecord
end
# Sets a new default value for a column.
- # ===== Examples
+ #
# change_column_default(:suppliers, :qualification, 'new')
# change_column_default(:accounts, :authorized, 1)
# change_column_default(:users, :email, nil)
@@ -335,7 +329,7 @@ module ActiveRecord
end
# Renames a column.
- # ===== Example
+ #
# rename_column(:suppliers, :description, :name)
def rename_column(table_name, column_name, new_column_name)
raise NotImplementedError, "rename_column is not implemented"
@@ -347,8 +341,6 @@ module ActiveRecord
# The index will be named after the table and the column name(s), unless
# you pass :name as an option.
#
- # ===== Examples
- #
# ====== Creating a simple index
# add_index(:suppliers, :name)
# generates
@@ -537,7 +529,7 @@ module ActiveRecord
end
# Adds timestamps (created_at and updated_at) columns to the named table.
- # ===== Examples
+ #
# add_timestamps(:suppliers)
def add_timestamps(table_name)
add_column table_name, :created_at, :datetime
@@ -545,7 +537,7 @@ module ActiveRecord
end
# Removes the timestamp columns (created_at and updated_at) from the table definition.
- # ===== Examples
+ #
# remove_timestamps(:suppliers)
def remove_timestamps(table_name)
remove_column table_name, :updated_at
--
cgit v1.2.3
From e306ca3627965bf038d6b39a9480ae57bff9c18e Mon Sep 17 00:00:00 2001
From: Andrew White
Date: Thu, 10 May 2012 20:28:53 +0100
Subject: Refactor the handling of default_url_options in integration tests
This commit improves the handling of default_url_options in integration
tests by making behave closer to how a real application operates.
Specifically the following issues have been addressed:
* Options specified in routes.rb are used (fixes #546)
* Options specified in controllers are used
* Request parameters are recalled correctly
* Tests can override default_url_options directly
---
.../lib/action_dispatch/testing/integration.rb | 31 +++++++--
actionpack/test/controller/integration_test.rb | 80 ++++++++++++++++++++++
2 files changed, 104 insertions(+), 7 deletions(-)
diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb
index 69d54f6981..08fd28d72d 100644
--- a/actionpack/lib/action_dispatch/testing/integration.rb
+++ b/actionpack/lib/action_dispatch/testing/integration.rb
@@ -201,9 +201,16 @@ module ActionDispatch
reset!
end
- remove_method :default_url_options
- def default_url_options
- { :host => host, :protocol => https? ? "https" : "http" }
+ def url_options
+ @url_options ||= default_url_options.dup.tap do |url_options|
+ url_options.reverse_merge!(controller.url_options) if controller
+
+ if @app.respond_to?(:routes) && @app.routes.respond_to?(:default_url_options)
+ url_options.reverse_merge!(@app.routes.default_url_options)
+ end
+
+ url_options.reverse_merge!(:host => host, :protocol => https? ? "https" : "http")
+ end
end
# Resets the instance. This can be used to reset the state information
@@ -216,6 +223,7 @@ module ActionDispatch
@controller = @request = @response = nil
@_mock_session = nil
@request_count = 0
+ @url_options = nil
self.host = DEFAULT_HOST
self.remote_addr = "127.0.0.1"
@@ -310,6 +318,7 @@ module ActionDispatch
response = _mock_session.last_response
@response = ActionDispatch::TestResponse.new(response.status, response.headers, response.body)
@html_document = nil
+ @url_options = nil
@controller = session.last_request.env['action_controller.instance']
@@ -367,12 +376,14 @@ module ActionDispatch
end
end
- extend ActiveSupport::Concern
- include ActionDispatch::Routing::UrlFor
+ def default_url_options
+ reset! unless integration_session
+ integration_session.default_url_options
+ end
- def url_options
+ def default_url_options=(options)
reset! unless integration_session
- integration_session.url_options
+ integration_session.default_url_options = options
end
def respond_to?(method, include_private = false)
@@ -476,6 +487,7 @@ module ActionDispatch
class IntegrationTest < ActiveSupport::TestCase
include Integration::Runner
include ActionController::TemplateAssertions
+ include ActionDispatch::Routing::UrlFor
@@app = nil
@@ -495,5 +507,10 @@ module ActionDispatch
def app
super || self.class.app
end
+
+ def url_options
+ reset! unless integration_session
+ integration_session.url_options
+ end
end
end
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb
index 9f2dbda25f..fb41dcb33a 100644
--- a/actionpack/test/controller/integration_test.rb
+++ b/actionpack/test/controller/integration_test.rb
@@ -615,3 +615,83 @@ class EnvironmentFilterIntegrationTest < ActionDispatch::IntegrationTest
assert_equal '[FILTERED]', request.filtered_env['rack.request.form_vars']
end
end
+
+class UrlOptionsIntegrationTest < ActionDispatch::IntegrationTest
+ class FooController < ActionController::Base
+ def index
+ render :text => "foo#index"
+ end
+
+ def show
+ render :text => "foo#show"
+ end
+
+ def edit
+ render :text => "foo#show"
+ end
+ end
+
+ class BarController < ActionController::Base
+ def default_url_options
+ { :host => "bar.com" }
+ end
+
+ def index
+ render :text => "foo#index"
+ end
+ end
+
+ def self.routes
+ @routes ||= ActionDispatch::Routing::RouteSet.new
+ end
+
+ def self.call(env)
+ routes.call(env)
+ end
+
+ def app
+ self.class
+ end
+
+ routes.draw do
+ default_url_options :host => "foo.com"
+
+ scope :module => "url_options_integration_test" do
+ get "/foo" => "foo#index", :as => :foos
+ get "/foo/:id" => "foo#show", :as => :foo
+ get "/foo/:id/edit" => "foo#edit", :as => :edit_foo
+ get "/bar" => "bar#index", :as => :bars
+ end
+ end
+
+ test "session uses default url options from routes" do
+ assert_equal "http://foo.com/foo", foos_url
+ end
+
+ test "current host overrides default url options from routes" do
+ get "/foo"
+ assert_response :success
+ assert_equal "http://www.example.com/foo", foos_url
+ end
+
+ test "controller can override default url options from request" do
+ get "/bar"
+ assert_response :success
+ assert_equal "http://bar.com/foo", foos_url
+ end
+
+ test "test can override default url options" do
+ default_url_options[:host] = "foobar.com"
+ assert_equal "http://foobar.com/foo", foos_url
+
+ get "/bar"
+ assert_response :success
+ assert_equal "http://foobar.com/foo", foos_url
+ end
+
+ test "current request path parameters are recalled" do
+ get "/foo/1"
+ assert_response :success
+ assert_equal "/foo/1/edit", url_for(:action => 'edit', :only_path => true)
+ end
+end
--
cgit v1.2.3
From 09a48b2324207ccbf6f421e5e7caf7655f1e905a Mon Sep 17 00:00:00 2001
From: Andrew White
Date: Thu, 10 May 2012 22:52:00 +0100
Subject: Don't ignore nil positional arguments for url helpers - fixes #6196.
---
.../lib/action_dispatch/routing/route_set.rb | 2 +-
actionpack/test/dispatch/routing_test.rb | 35 ++++++++++++++++++++++
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 58c67e2cbe..0ae668d42a 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -103,7 +103,7 @@ module ActionDispatch
inner_options = args.extract_options!
result = options.dup
- if args.any?
+ if args.size > 0
keys = segment_keys
if args.size < keys.size - 1 # take format into account
keys -= self.url_options.keys if self.respond_to?(:url_options)
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index d356187ca8..6f22cb3ea8 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -2571,3 +2571,38 @@ class TestOptimizedNamedRoutes < ActionDispatch::IntegrationTest
assert_equal '/foo', foo_path
end
end
+
+class TestNamedRouteUrlHelpers < ActionDispatch::IntegrationTest
+ class CategoriesController < ActionController::Base
+ def show
+ render :text => "categories#show"
+ end
+ end
+
+ class ProductsController < ActionController::Base
+ def show
+ render :text => "products#show"
+ end
+ end
+
+ Routes = ActionDispatch::Routing::RouteSet.new.tap do |app|
+ app.draw do
+ scope :module => "test_named_route_url_helpers" do
+ get "/categories/:id" => 'categories#show', :as => :category
+ get "/products/:id" => 'products#show', :as => :product
+ end
+ end
+ end
+
+ def app; Routes end
+
+ include Routes.url_helpers
+
+ test "url helpers do not ignore nil parameters when using non-optimized routes" do
+ Routes.stubs(:optimize_routes_generation?).returns(false)
+
+ get "/categories/1"
+ assert_response :success
+ assert_raises(ActionController::RoutingError) { product_path(nil) }
+ end
+end
--
cgit v1.2.3
From fa21b73ebb8339ad388f149c817c433b6254d490 Mon Sep 17 00:00:00 2001
From: Andrew White
Date: Thu, 10 May 2012 23:16:40 +0100
Subject: Return false for exists? with new records - fixes #6199.
---
activerecord/lib/active_record/relation/finder_methods.rb | 3 +--
activerecord/test/cases/finder_test.rb | 1 +
activerecord/test/cases/relations_test.rb | 1 +
3 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index cc716bbfd1..4fedd33d64 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -170,9 +170,8 @@ module ActiveRecord
# Person.exists?(['name LIKE ?', "%#{query}%"])
# Person.exists?
def exists?(id = false)
- return false if id.nil?
-
id = id.id if ActiveRecord::Model === id
+ return false if id.nil?
join_dependency = construct_join_dependency_for_association_find
relation = construct_relation_for_association_find(join_dependency)
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index 630acdbc46..c960773284 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -32,6 +32,7 @@ class FinderTest < ActiveRecord::TestCase
assert Topic.exists?(:author_name => "Mary", :approved => true)
assert Topic.exists?(["parent_id = ?", 1])
assert !Topic.exists?(45)
+ assert !Topic.exists?(Topic.new)
begin
assert !Topic.exists?("foo")
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 8cef4423c5..76b868c7b4 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -644,6 +644,7 @@ class RelationTest < ActiveRecord::TestCase
assert ! davids.exists?(authors(:mary).id)
assert ! davids.exists?("42")
assert ! davids.exists?(42)
+ assert ! davids.exists?(davids.new)
fake = Author.where(:name => 'fake author')
assert ! fake.exists?
--
cgit v1.2.3
From b14d1cd8aefac1895f83139c00ce130e89277c9f Mon Sep 17 00:00:00 2001
From: Piotr Sarnacki
Date: Thu, 10 May 2012 14:11:59 -0700
Subject: Failing test for #6251
---
railties/test/generators/plugin_new_generator_test.rb | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb
index 6c31b80c7d..51374e5f3f 100644
--- a/railties/test/generators/plugin_new_generator_test.rb
+++ b/railties/test/generators/plugin_new_generator_test.rb
@@ -236,6 +236,13 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
assert_no_file "test/dummy"
end
+ def test_creating_dummy_application_with_different_name
+ run_generator [destination_root, "--dummy_path", "spec/fake"]
+ assert_file "spec/fake"
+ assert_file "spec/fake/config/application.rb"
+ assert_no_file "test/dummy"
+ end
+
def test_creating_dummy_without_tests_but_with_dummy_path
run_generator [destination_root, "--dummy_path", "spec/dummy", "--skip-test-unit"]
assert_file "spec/dummy"
--
cgit v1.2.3
From 0d48b12fc56df574bb81cfaf0f5fb4713e9230fc Mon Sep 17 00:00:00 2001
From: David Padilla
Date: Thu, 10 May 2012 15:56:13 -0500
Subject: Fixes issue #6251
Plugin generator crashes when using the --dummy-path option
Code was assuming the application name in `config/application.rb`
was module Dummy.
---
railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
index f4263d1b98..722e37e20b 100644
--- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
+++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
@@ -302,7 +302,7 @@ task :default => :test
dummy_application_path = File.expand_path("#{dummy_path}/config/application.rb", destination_root)
unless options[:pretend] || !File.exists?(dummy_application_path)
contents = File.read(dummy_application_path)
- contents[(contents.index("module Dummy"))..-1]
+ contents[(contents.index(/module ([\w]+)\n(.*)class Application/m))..-1]
end
end
end
--
cgit v1.2.3
From 9b4514c3b8ecfbc40a44dbd4c2ebd4ce67f4a459 Mon Sep 17 00:00:00 2001
From: Andrew White
Date: Fri, 11 May 2012 07:23:24 +0100
Subject: Copy literal route constraints to defaults - fixes #3571 and #6224.
---
actionpack/CHANGELOG.md | 5 +++
actionpack/lib/action_dispatch/routing/mapper.rb | 19 ++++++++++
.../test/dispatch/routing_assertions_test.rb | 6 ++--
actionpack/test/dispatch/routing_test.rb | 42 ++++++++++++++++++++++
4 files changed, 69 insertions(+), 3 deletions(-)
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index b819f2e613..f25e853e84 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 4.0.0 (unreleased) ##
+* Copy literal route constraints to defaults so that url generation know about them.
+ The copied constraints are `:protocol`, `:subdomain`, `:domain`, `:host` and `:port`.
+
+ *Andrew White*
+
* `respond_to` and `respond_with` now raise ActionController::UnknownFormat instead
of directly returning head 406. The exception is rescued and converted to 406
in the exception handling middleware. *Steven Soroka*
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 2a7d540517..7a22b65c44 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1,5 +1,6 @@
require 'active_support/core_ext/hash/except'
require 'active_support/core_ext/hash/reverse_merge'
+require 'active_support/core_ext/hash/slice'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/enumerable'
require 'active_support/inflector'
@@ -100,6 +101,10 @@ module ActionDispatch
raise ArgumentError, "Regexp multiline option not allowed in routing requirements: #{requirement.inspect}"
end
end
+
+ if @options[:constraints].is_a?(Hash)
+ (@options[:defaults] ||= {}).reverse_merge!(defaults_from_constraints(@options[:constraints]))
+ end
end
# match "account/overview"
@@ -245,6 +250,11 @@ module ActionDispatch
def default_action
@options[:action] || @scope[:action]
end
+
+ def defaults_from_constraints(constraints)
+ url_keys = [:protocol, :subdomain, :domain, :host, :port]
+ constraints.slice(*url_keys).select{ |k, v| v.is_a?(String) || v.is_a?(Fixnum) }
+ end
end
# Invokes Rack::Mount::Utils.normalize path and ensure that
@@ -641,6 +651,10 @@ module ActionDispatch
block, options[:constraints] = options[:constraints], {}
end
+ if options[:constraints].is_a?(Hash)
+ (options[:defaults] ||= {}).reverse_merge!(defaults_from_constraints(options[:constraints]))
+ end
+
scope_options.each do |option|
if value = options.delete(option)
recover[option] = @scope[option]
@@ -849,6 +863,11 @@ module ActionDispatch
def override_keys(child) #:nodoc:
child.key?(:only) || child.key?(:except) ? [:only, :except] : []
end
+
+ def defaults_from_constraints(constraints)
+ url_keys = [:protocol, :subdomain, :domain, :host, :port]
+ constraints.slice(*url_keys).select{ |k, v| v.is_a?(String) || v.is_a?(Fixnum) }
+ end
end
# Resource routing allows you to quickly declare all of the common routes
diff --git a/actionpack/test/dispatch/routing_assertions_test.rb b/actionpack/test/dispatch/routing_assertions_test.rb
index e953029456..517354ae58 100644
--- a/actionpack/test/dispatch/routing_assertions_test.rb
+++ b/actionpack/test/dispatch/routing_assertions_test.rb
@@ -47,7 +47,7 @@ class RoutingAssertionsTest < ActionController::TestCase
def test_assert_recognizes_with_extras
assert_recognizes({ :controller => 'articles', :action => 'index', :page => '1' }, '/articles', { :page => '1' })
end
-
+
def test_assert_recognizes_with_method
assert_recognizes({ :controller => 'articles', :action => 'create' }, { :path => '/articles', :method => :post })
assert_recognizes({ :controller => 'articles', :action => 'update', :id => '1' }, { :path => '/articles/1', :method => :put })
@@ -57,7 +57,7 @@ class RoutingAssertionsTest < ActionController::TestCase
assert_raise(ActionController::RoutingError) do
assert_recognizes({ :controller => 'secure_articles', :action => 'index' }, 'http://test.host/secure/articles')
end
- assert_recognizes({ :controller => 'secure_articles', :action => 'index' }, 'https://test.host/secure/articles')
+ assert_recognizes({ :controller => 'secure_articles', :action => 'index', :protocol => 'https://' }, 'https://test.host/secure/articles')
end
def test_assert_recognizes_with_block_constraint
@@ -90,7 +90,7 @@ class RoutingAssertionsTest < ActionController::TestCase
assert_raise(ActionController::RoutingError) do
assert_routing('http://test.host/secure/articles', { :controller => 'secure_articles', :action => 'index' })
end
- assert_routing('https://test.host/secure/articles', { :controller => 'secure_articles', :action => 'index' })
+ assert_routing('https://test.host/secure/articles', { :controller => 'secure_articles', :action => 'index', :protocol => 'https://' })
end
def test_assert_routing_with_block_constraint
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 6f22cb3ea8..3cec816f1c 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -2606,3 +2606,45 @@ class TestNamedRouteUrlHelpers < ActionDispatch::IntegrationTest
assert_raises(ActionController::RoutingError) { product_path(nil) }
end
end
+
+class TestUrlConstraints < ActionDispatch::IntegrationTest
+ Routes = ActionDispatch::Routing::RouteSet.new.tap do |app|
+ app.draw do
+ ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] }
+
+ constraints :subdomain => 'admin' do
+ get '/' => ok, :as => :admin_root
+ end
+
+ scope :constraints => { :protocol => 'https://' } do
+ get '/' => ok, :as => :secure_root
+ end
+
+ get '/' => ok, :as => :alternate_root, :constraints => { :port => 8080 }
+ end
+ end
+
+ include Routes.url_helpers
+ def app; Routes end
+
+ test "constraints are copied to defaults when using constraints method" do
+ assert_equal 'http://admin.example.com/', admin_root_url
+
+ get 'http://admin.example.com/'
+ assert_response :success
+ end
+
+ test "constraints are copied to defaults when using scope constraints hash" do
+ assert_equal 'https://www.example.com/', secure_root_url
+
+ get 'https://www.example.com/'
+ assert_response :success
+ end
+
+ test "constraints are copied to defaults when using route constraints hash" do
+ assert_equal 'http://www.example.com:8080/', alternate_root_url
+
+ get 'http://www.example.com:8080/'
+ assert_response :success
+ end
+end
--
cgit v1.2.3
From 1065ef8fd3ad499feec01b39292ee435c1f71c13 Mon Sep 17 00:00:00 2001
From: Edward Tsech
Date: Fri, 11 May 2012 11:11:41 +0200
Subject: Fix copypaste. [ci skip]
---
activesupport/test/core_ext/hash_ext_test.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index 1cd10eb6e2..822fcbc53e 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -491,11 +491,11 @@ class HashExtTest < ActiveSupport::TestCase
original = { :a => 'x', :b => 'y', :c => 10 }
expected = { :a => 'x', :b => 'y' }
- # Should return a new hash with only the given keys.
+ # Should return a new hash without the given keys.
assert_equal expected, original.except(:c)
assert_not_equal expected, original
- # Should replace the hash with only the given keys.
+ # Should replace the hash without the given keys.
assert_equal expected, original.except!(:c)
assert_equal expected, original
end
--
cgit v1.2.3
From 1abf15657b47b32dd5ba295bcdb618b41b46c0bc Mon Sep 17 00:00:00 2001
From: Enrico Carlesso
Date: Fri, 11 May 2012 11:50:15 +0200
Subject: In robots.txt, User-agent should be all downcase except for the first
'U', according with http://en.wikipedia.org/wiki/Robots_exclusion_standard
---
guides/code/getting_started/public/robots.txt | 2 +-
railties/lib/rails/generators/rails/app/templates/public/robots.txt | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/guides/code/getting_started/public/robots.txt b/guides/code/getting_started/public/robots.txt
index 085187fa58..1a3a5e4dd2 100644
--- a/guides/code/getting_started/public/robots.txt
+++ b/guides/code/getting_started/public/robots.txt
@@ -1,5 +1,5 @@
# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
#
# To ban all spiders from the entire site uncomment the next two lines:
-# User-Agent: *
+# User-agent: *
# Disallow: /
diff --git a/railties/lib/rails/generators/rails/app/templates/public/robots.txt b/railties/lib/rails/generators/rails/app/templates/public/robots.txt
index 085187fa58..1a3a5e4dd2 100644
--- a/railties/lib/rails/generators/rails/app/templates/public/robots.txt
+++ b/railties/lib/rails/generators/rails/app/templates/public/robots.txt
@@ -1,5 +1,5 @@
# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
#
# To ban all spiders from the entire site uncomment the next two lines:
-# User-Agent: *
+# User-agent: *
# Disallow: /
--
cgit v1.2.3
From c9a4e65217cc0711f264410484d23fb8b519b660 Mon Sep 17 00:00:00 2001
From: Egor Homakov
Date: Fri, 11 May 2012 14:48:02 +0400
Subject: Update guides/source/configuring.textile
---
guides/source/configuring.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/guides/source/configuring.textile b/guides/source/configuring.textile
index c4e54348d4..bed8ce3eb6 100644
--- a/guides/source/configuring.textile
+++ b/guides/source/configuring.textile
@@ -448,7 +448,7 @@ There are a few configuration options available in Active Support:
* +config.active_support.bare+ enables or disables the loading of +active_support/all+ when booting Rails. Defaults to +nil+, which means +active_support/all+ is loaded.
-* +config.active_support.escape_html_entities_in_json+ enables or disables the escaping of HTML entities in JSON serialization. Defaults to +true+.
+* +config.active_support.escape_html_entities_in_json+ enables or disables the escaping of HTML entities in JSON serialization. Defaults to +false+.
* +config.active_support.use_standard_json_time_format+ enables or disables serializing dates to ISO 8601 format. Defaults to +false+.
--
cgit v1.2.3
From d4f4b858d3c493ea74a1e4ed8ed6566bfa4c7e27 Mon Sep 17 00:00:00 2001
From: Egor Homakov
Date: Fri, 11 May 2012 15:40:03 +0400
Subject: Update guides/source/configuring.textile
---
guides/source/configuring.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/guides/source/configuring.textile b/guides/source/configuring.textile
index bed8ce3eb6..b2c9300034 100644
--- a/guides/source/configuring.textile
+++ b/guides/source/configuring.textile
@@ -450,7 +450,7 @@ There are a few configuration options available in Active Support:
* +config.active_support.escape_html_entities_in_json+ enables or disables the escaping of HTML entities in JSON serialization. Defaults to +false+.
-* +config.active_support.use_standard_json_time_format+ enables or disables serializing dates to ISO 8601 format. Defaults to +false+.
+* +config.active_support.use_standard_json_time_format+ enables or disables serializing dates to ISO 8601 format. Defaults to +true+.
* +ActiveSupport::BufferedLogger.silencer+ is set to +false+ to disable the ability to silence logging in a block. The default is +true+.
--
cgit v1.2.3
From 21190f37f8b48bbb991aa7a6400ed4e20bb3768b Mon Sep 17 00:00:00 2001
From: Edward Tsech
Date: Fri, 11 May 2012 12:09:57 +0200
Subject: Test Hash#except can receive more than one argument.
---
activesupport/test/core_ext/hash_ext_test.rb | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index 1cd10eb6e2..afca636777 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -500,6 +500,12 @@ class HashExtTest < ActiveSupport::TestCase
assert_equal expected, original
end
+ def test_except_with_more_than_one_argument
+ original = { :a => 'x', :b => 'y', :c => 10 }
+ expected = { :a => 'x' }
+ assert_equal expected, original.except(:b, :c)
+ end
+
def test_except_with_original_frozen
original = { :a => 'x', :b => 'y' }
original.freeze
--
cgit v1.2.3
From 24e4bc31b98a773924887137afb6f415ef1c0a9e Mon Sep 17 00:00:00 2001
From: Elia Schito
Date: Fri, 11 May 2012 14:47:26 +0200
Subject: Move HTTP Token auth docs above the Token module
---
.../action_controller/metal/http_authentication.rb | 86 +++++++++++-----------
1 file changed, 44 insertions(+), 42 deletions(-)
diff --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb
index 87225d74c1..57bb0e2a32 100644
--- a/actionpack/lib/action_controller/metal/http_authentication.rb
+++ b/actionpack/lib/action_controller/metal/http_authentication.rb
@@ -2,8 +2,9 @@ require 'base64'
require 'active_support/core_ext/object/blank'
module ActionController
+ # Makes it dead easy to do HTTP Basic, Digest and Token authentication.
module HttpAuthentication
- # Makes it dead easy to do HTTP \Basic and \Digest authentication.
+ # Makes it dead easy to do HTTP \Basic authentication.
#
# === Simple \Basic example
#
@@ -60,47 +61,6 @@ module ActionController
#
# assert_equal 200, status
# end
- #
- # === Simple \Digest example
- #
- # require 'digest/md5'
- # class PostsController < ApplicationController
- # REALM = "SuperSecret"
- # USERS = {"dhh" => "secret", #plain text password
- # "dap" => Digest::MD5.hexdigest(["dap",REALM,"secret"].join(":"))} #ha1 digest password
- #
- # before_filter :authenticate, :except => [:index]
- #
- # def index
- # render :text => "Everyone can see me!"
- # end
- #
- # def edit
- # render :text => "I'm only accessible if you know the password"
- # end
- #
- # private
- # def authenticate
- # authenticate_or_request_with_http_digest(REALM) do |username|
- # USERS[username]
- # end
- # end
- # end
- #
- # === Notes
- #
- # The +authenticate_or_request_with_http_digest+ block must return the user's password
- # or the ha1 digest hash so the framework can appropriately hash to check the user's
- # credentials. Returning +nil+ will cause authentication to fail.
- #
- # Storing the ha1 hash: MD5(username:realm:password), is better than storing a plain password. If
- # the password file or database is compromised, the attacker would be able to use the ha1 hash to
- # authenticate as the user at this +realm+, but would not have the user's password to try using at
- # other sites.
- #
- # In rare instances, web servers or front proxies strip authorization headers before
- # they reach your application. You can debug this situation by logging all environment
- # variables, and check for HTTP_AUTHORIZATION, amongst others.
module Basic
extend self
@@ -155,6 +115,48 @@ module ActionController
end
end
+ # Makes it dead easy to do HTTP \Digest authentication.
+ #
+ # === Simple \Digest example
+ #
+ # require 'digest/md5'
+ # class PostsController < ApplicationController
+ # REALM = "SuperSecret"
+ # USERS = {"dhh" => "secret", #plain text password
+ # "dap" => Digest::MD5.hexdigest(["dap",REALM,"secret"].join(":"))} #ha1 digest password
+ #
+ # before_filter :authenticate, :except => [:index]
+ #
+ # def index
+ # render :text => "Everyone can see me!"
+ # end
+ #
+ # def edit
+ # render :text => "I'm only accessible if you know the password"
+ # end
+ #
+ # private
+ # def authenticate
+ # authenticate_or_request_with_http_digest(REALM) do |username|
+ # USERS[username]
+ # end
+ # end
+ # end
+ #
+ # === Notes
+ #
+ # The +authenticate_or_request_with_http_digest+ block must return the user's password
+ # or the ha1 digest hash so the framework can appropriately hash to check the user's
+ # credentials. Returning +nil+ will cause authentication to fail.
+ #
+ # Storing the ha1 hash: MD5(username:realm:password), is better than storing a plain password. If
+ # the password file or database is compromised, the attacker would be able to use the ha1 hash to
+ # authenticate as the user at this +realm+, but would not have the user's password to try using at
+ # other sites.
+ #
+ # In rare instances, web servers or front proxies strip authorization headers before
+ # they reach your application. You can debug this situation by logging all environment
+ # variables, and check for HTTP_AUTHORIZATION, amongst others.
module Digest
extend self
--
cgit v1.2.3
From bd2b1c126bae98d93426915e036513dc0137ce25 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hrvoje=20=C5=A0imi=C4=87?=
Date: Fri, 11 May 2012 16:09:10 +0200
Subject: missing 'with'
---
activerecord/lib/active_record/aggregations.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb
index a4db627535..c7a329d74d 100644
--- a/activerecord/lib/active_record/aggregations.rb
+++ b/activerecord/lib/active_record/aggregations.rb
@@ -71,7 +71,7 @@ module ActiveRecord
# Now it's possible to access attributes from the database through the value objects instead. If
# you choose to name the composition the same as the attribute's name, it will be the only way to
# access that attribute. That's the case with our +balance+ attribute. You interact with the value
- # objects just like you would any other attribute, though:
+ # objects just like you would with any other attribute:
#
# customer.balance = Money.new(20) # sets the Money value object and the attribute
# customer.balance # => Money value object
--
cgit v1.2.3
From 1b956700ee61e8cc5fab140b38d702767e3d03f1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hrvoje=20=C5=A0imi=C4=87?=
Date: Fri, 11 May 2012 16:27:21 +0200
Subject: better wording
---
activerecord/lib/active_record/nested_attributes.rb | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb
index 32a1dae6bc..95a2ddcc11 100644
--- a/activerecord/lib/active_record/nested_attributes.rb
+++ b/activerecord/lib/active_record/nested_attributes.rb
@@ -19,10 +19,10 @@ module ActiveRecord
# = Active Record Nested Attributes
#
# Nested attributes allow you to save attributes on associated records
- # through the parent. By default nested attribute updating is turned off,
- # you can enable it using the accepts_nested_attributes_for class method.
- # When you enable nested attributes an attribute writer is defined on
- # the model.
+ # through the parent. By default nested attribute updating is turned off
+ # and you can enable it using the accepts_nested_attributes_for class
+ # method. When you enable nested attributes an attribute writer is
+ # defined on the model.
#
# The attribute writer is named after the association, which means that
# in the following example, two new methods are added to your model:
--
cgit v1.2.3
From 7ce4ce33c7c3229752c51dd92ca9d758ec452fc1 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Fri, 11 May 2012 10:51:36 -0500
Subject: added docs to String#at
---
.../lib/active_support/core_ext/string/access.rb | 25 ++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb
index 23aaee9c43..8a922a7069 100644
--- a/activesupport/lib/active_support/core_ext/string/access.rb
+++ b/activesupport/lib/active_support/core_ext/string/access.rb
@@ -1,6 +1,31 @@
require 'active_support/multibyte'
class String
+ # If you pass a single Fixnum, returns a substring of one character at that
+ # position. The first character of the string is at position 0, the next at
+ # position 1, and so on. If a range is supplied, a substring containing
+ # characters at offsets given by the range is returned. In both cases, if an
+ # offset is negative, it is counted from the end of the string. Returns nil
+ # if the initial offset falls outside the string. Returns an empty string if
+ # the beginning of the range is greater than the end of the string.
+ #
+ # str = "hello"
+ # str.at(0) #=> "h"
+ # str.at(1..3) #=> "ell"
+ # str.at(-2) #=> "l"
+ # str.at(-2..-1) #=> "lo"
+ # str.at(5) #=> nil
+ # str.at(5..-1) #=> ""
+ #
+ # If a Regexp is given, the matching portion of the string is returned.
+ # If a String is given, that given string is returned if it occurs in
+ # the string. In both cases, nil is returned if there is no match.
+ #
+ # str = "hello"
+ # str.at(/lo/) #=> "lo"
+ # str.at(/ol/) #=> nil
+ # str.at("lo") #=> "lo"
+ # str.at("ol") #=> nil
def at(position)
self[position]
end
--
cgit v1.2.3
From 1004ccc84b16a78d9aa3180e57dda278002fe53e Mon Sep 17 00:00:00 2001
From: Eric Carty-Fickes
Date: Fri, 11 May 2012 11:12:32 -0500
Subject: Clarify expire_action with namespaced controllers
---
guides/source/caching_with_rails.textile | 36 ++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/guides/source/caching_with_rails.textile b/guides/source/caching_with_rails.textile
index e455b504ce..34a100cd3a 100644
--- a/guides/source/caching_with_rails.textile
+++ b/guides/source/caching_with_rails.textile
@@ -229,6 +229,42 @@ class ProductsController < ActionController
end
+Sometimes it is necessary to disambiguate the controller when you call +expire_action+, such as when there are two identically named controllers in separate namespaces:
+
+
+class ProductsController < ActionController
+ caches_action :index
+
+ def index
+ @products = Product.all
+ end
+end
+
+module Admin
+ class ProductsController < ActionController
+ cache_sweeper :product_sweeper
+
+ def new
+ @product = Product.new
+ end
+
+ def create
+ @product = Product.create(params[:product])
+ end
+ end
+end
+
+class ProductSweeper < ActionController::Caching::Sweeper
+ observe Product
+
+ def after_create(product)
+ expire_action(:controller => '/products', :action => 'index')
+ end
+end
+
+
+Note the use of '/products' here rather than 'products'. If you wanted to expire an action cache for the +Admin::ProductsController+, you would use 'admin/products' instead.
+
h4. SQL Caching
Query caching is a Rails feature that caches the result set returned by each query so that if Rails encounters the same query again for that request, it will use the cached result set as opposed to running the query against the database again.
--
cgit v1.2.3
From 315350847f5089fa2b314b00d485e5121f5622d4 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Fri, 11 May 2012 11:35:26 -0500
Subject: added docs to String#to
---
activesupport/lib/active_support/core_ext/string/access.rb | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb
index 8a922a7069..5cdf42ce4b 100644
--- a/activesupport/lib/active_support/core_ext/string/access.rb
+++ b/activesupport/lib/active_support/core_ext/string/access.rb
@@ -34,6 +34,19 @@ class String
self[position..-1]
end
+ # Returns the beginning of the string up to position. If the position is
+ # negative, it is counted from the end of the string.
+ #
+ # str = "hello"
+ # str.to(0) #=> "h"
+ # str.to(3) #=> "hell"
+ # str.to(-2) #=> "hell"
+ #
+ # You can mix it with +from+ method and do fun things like:
+ #
+ # str = "hello"
+ # str.from(0).to(-1) #=> "hello"
+ # str.from(1).to(-2) #=> "ell"
def to(position)
self[0..position]
end
--
cgit v1.2.3
From 0822dc01f68eb262274fbedcf97a224e6457ff3b Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Fri, 11 May 2012 11:41:22 -0500
Subject: improve String#to docs
---
activesupport/lib/active_support/core_ext/string/access.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb
index 5cdf42ce4b..9494a9b69d 100644
--- a/activesupport/lib/active_support/core_ext/string/access.rb
+++ b/activesupport/lib/active_support/core_ext/string/access.rb
@@ -34,8 +34,8 @@ class String
self[position..-1]
end
- # Returns the beginning of the string up to position. If the position is
- # negative, it is counted from the end of the string.
+ # Returns a substring from the beginning of the string to the given position.
+ # If the position is negative, it is counted from the end of the string.
#
# str = "hello"
# str.to(0) #=> "h"
--
cgit v1.2.3
From 07045fa919b4787d8ec458a1594f62cdedaf1b06 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Fri, 11 May 2012 11:47:40 -0500
Subject: added docs to String#from
---
activesupport/lib/active_support/core_ext/string/access.rb | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb
index 9494a9b69d..1436d43be6 100644
--- a/activesupport/lib/active_support/core_ext/string/access.rb
+++ b/activesupport/lib/active_support/core_ext/string/access.rb
@@ -30,6 +30,19 @@ class String
self[position]
end
+ # Returns a substring from the given position to the end of the string.
+ # If the position is negative, it is counted from the end of the string.
+ #
+ # str = "hello"
+ # str.from(0) #=> "hello"
+ # str.from(3) #=> "lo"
+ # str.from(-2) #=> "lo"
+ #
+ # You can mix it with +to+ method and do fun things like:
+ #
+ # str = "hello"
+ # str.from(0).to(-1) #=> "hello"
+ # str.from(1).to(-2) #=> "ell"
def from(position)
self[position..-1]
end
--
cgit v1.2.3
From 84784b4f234c0f21096202309805c3c304901baa Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Fri, 11 May 2012 12:20:57 -0500
Subject: added docs to String#first
---
activesupport/lib/active_support/core_ext/string/access.rb | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb
index 1436d43be6..43024fb012 100644
--- a/activesupport/lib/active_support/core_ext/string/access.rb
+++ b/activesupport/lib/active_support/core_ext/string/access.rb
@@ -64,6 +64,17 @@ class String
self[0..position]
end
+ # Returns the first character of the string. If a limit is supplied,
+ # returns a substring from the beginning of the string to the given
+ # limit. If the given limit is greater than or equal to the string
+ # length, returns it self.
+ #
+ # str = "hello"
+ # str.first #=> "h"
+ # str.first(1) #=> "h"
+ # str.first(2) #=> "he"
+ # str.first(0) #=> ""
+ # str.first(6) #=> "hello"
def first(limit = 1)
if limit == 0
''
--
cgit v1.2.3
From 074359dfa8d9e16058de4bd6375b2438fef3de83 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Fri, 11 May 2012 12:24:45 -0500
Subject: fix typo in String#first
---
activesupport/lib/active_support/core_ext/string/access.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb
index 43024fb012..9bb0c597b2 100644
--- a/activesupport/lib/active_support/core_ext/string/access.rb
+++ b/activesupport/lib/active_support/core_ext/string/access.rb
@@ -67,7 +67,7 @@ class String
# Returns the first character of the string. If a limit is supplied,
# returns a substring from the beginning of the string to the given
# limit. If the given limit is greater than or equal to the string
- # length, returns it self.
+ # length, returns self.
#
# str = "hello"
# str.first #=> "h"
--
cgit v1.2.3
From b2e9d33515eb858507cfab8e15eb4a9e049a433a Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Fri, 11 May 2012 12:56:53 -0500
Subject: improve String#first docs
---
activesupport/lib/active_support/core_ext/string/access.rb | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb
index 9bb0c597b2..baa5b84db6 100644
--- a/activesupport/lib/active_support/core_ext/string/access.rb
+++ b/activesupport/lib/active_support/core_ext/string/access.rb
@@ -64,10 +64,9 @@ class String
self[0..position]
end
- # Returns the first character of the string. If a limit is supplied,
- # returns a substring from the beginning of the string to the given
- # limit. If the given limit is greater than or equal to the string
- # length, returns self.
+ # Returns the first character. If a limit is supplied, returns a substring
+ # from the beginning of the string until it reaches the limit value. If the
+ # given limit is greater than or equal to the string length, returns self.
#
# str = "hello"
# str.first #=> "h"
--
cgit v1.2.3
From ed116eda053e8cccb5dda1c4724f8609eceaa90f Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Fri, 11 May 2012 13:11:06 -0500
Subject: added docs to String#last
---
activesupport/lib/active_support/core_ext/string/access.rb | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb
index baa5b84db6..76b30b4c19 100644
--- a/activesupport/lib/active_support/core_ext/string/access.rb
+++ b/activesupport/lib/active_support/core_ext/string/access.rb
@@ -84,6 +84,16 @@ class String
end
end
+ # Returns the last character of the string. If a limit is supplied, returns a substring
+ # from the end of the string until it reaches the limit value (counting backwards). If
+ # the given limit is greater than or equal to the string length, returns self.
+ #
+ # str = "hello"
+ # str.last #=> "h"
+ # str.last(1) #=> "h"
+ # str.last(2) #=> "lo"
+ # str.last(0) #=> ""
+ # str.last(6) #=> "hello"
def last(limit = 1)
if limit == 0
''
--
cgit v1.2.3
From 53ef85dae8081e81f7dbb1f09a6150777f509cd4 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Fri, 11 May 2012 13:16:35 -0500
Subject: fix String#last example
---
activesupport/lib/active_support/core_ext/string/access.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb
index 76b30b4c19..2ebfd48818 100644
--- a/activesupport/lib/active_support/core_ext/string/access.rb
+++ b/activesupport/lib/active_support/core_ext/string/access.rb
@@ -89,7 +89,7 @@ class String
# the given limit is greater than or equal to the string length, returns self.
#
# str = "hello"
- # str.last #=> "h"
+ # str.last #=> "o"
# str.last(1) #=> "h"
# str.last(2) #=> "lo"
# str.last(0) #=> ""
--
cgit v1.2.3
From 39c483fec56b98b0cdb11b705cd7e63b43d60a64 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Fri, 11 May 2012 13:18:00 -0500
Subject: fix String#last example
---
activesupport/lib/active_support/core_ext/string/access.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb
index 2ebfd48818..5c32a2453d 100644
--- a/activesupport/lib/active_support/core_ext/string/access.rb
+++ b/activesupport/lib/active_support/core_ext/string/access.rb
@@ -90,7 +90,7 @@ class String
#
# str = "hello"
# str.last #=> "o"
- # str.last(1) #=> "h"
+ # str.last(1) #=> "o"
# str.last(2) #=> "lo"
# str.last(0) #=> ""
# str.last(6) #=> "hello"
--
cgit v1.2.3
From a0d9b7903588cd988c8c9b4164494c792344f43e Mon Sep 17 00:00:00 2001
From: Scott Johnson <7.scott.j@gmail.com>
Date: Fri, 11 May 2012 13:42:37 -0500
Subject: update engines guide to show how to have an engine's
ApplicationController inherit from the main application's
ApplicationController
---
guides/source/engines.textile | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/guides/source/engines.textile b/guides/source/engines.textile
index 71bcf6b713..b94ede44c4 100644
--- a/guides/source/engines.textile
+++ b/guides/source/engines.textile
@@ -448,6 +448,8 @@ rake db:migrate SCOPE=blorgh VERSION=0
h4. Using a class provided by the application
+h5. Using a model provided by the application
+
When an engine is created, it may want to use specific classes from an application to provide links between the pieces of the engine and the pieces of the application. In the case of the +blorgh+ engine, making posts and comments have authors would make a lot of sense.
Usually, an application would have a +User+ class that would provide the objects that would represent the posts' and comments' authors, but there could be a case where the application calls this class something different, such as +Person+. It's because of this reason that the engine should not hardcode the associations to be exactly for a +User+ class, but should allow for some flexibility around what the class is called.
@@ -544,6 +546,19 @@ end
Now instead of the ugly Ruby object output the author's name will be displayed.
+h5. Using a controller provided by the application
+
+Because Rails controllers generally share code for for things like authentication and accessing session variables, by default they inherit from ApplicationController. Rails engines, however are scoped to run independently from the main application, so each engine gets a scoped ApplicationController. This namespace prevents code collisions, but often engine controllers should access methods in the main application's ApplicationController. An easy way to provide this acess is to change the engine's scoped ApplicationController to inherit from the main application's ApplicationController. For our Blorgh engine this would be done by changing +app/controllers/blorgh/application_controller.rb+ to look like:
+
+
+ class Blorgh::ApplicationController < ApplicationController
+ end
+
+
+By default, the engine's controllers inherit from Blorgh::ApplicationController. So, after making this change they will have access to the main applications ApplicationController as though they were part of the main application.
+
+This change does require that the engine is run from a Rails application that has an ApplicationController.
+
h4. Configuring an engine
This section covers firstly how you can make the +user_class+ setting of the Blorgh engine configurable, followed by general configuration tips for the engine.
--
cgit v1.2.3
From a8637cf4938d2decd17e702c399ca9c0cf1a6052 Mon Sep 17 00:00:00 2001
From: Jon Leighton
Date: Fri, 11 May 2012 17:17:29 +0100
Subject: Use respond_to?(:to_ary) rather than is_a?(Enumerable) to detect
collection-thing.
---
activemodel/lib/active_model/serialization.rb | 4 ++--
activemodel/lib/active_model/serializers/xml.rb | 4 +++-
activemodel/test/cases/serialization_test.rb | 18 ++++++++++++++++++
.../test/cases/serializers/xml_serialization_test.rb | 17 +++++++++++++++++
4 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/activemodel/lib/active_model/serialization.rb b/activemodel/lib/active_model/serialization.rb
index 4403ef060b..00cd05b7ef 100644
--- a/activemodel/lib/active_model/serialization.rb
+++ b/activemodel/lib/active_model/serialization.rb
@@ -87,8 +87,8 @@ module ActiveModel
Array(options[:methods]).each { |m| hash[m.to_s] = send(m) if respond_to?(m) }
serializable_add_includes(options) do |association, records, opts|
- hash[association.to_s] = if records.is_a?(Enumerable)
- records.map { |a| a.serializable_hash(opts) }
+ hash[association.to_s] = if records.respond_to?(:to_ary)
+ records.to_ary.map { |a| a.serializable_hash(opts) }
else
records.serializable_hash(opts)
end
diff --git a/activemodel/lib/active_model/serializers/xml.rb b/activemodel/lib/active_model/serializers/xml.rb
index 5084298210..b78f1ff3f3 100644
--- a/activemodel/lib/active_model/serializers/xml.rb
+++ b/activemodel/lib/active_model/serializers/xml.rb
@@ -115,7 +115,9 @@ module ActiveModel
merged_options = opts.merge(options.slice(:builder, :indent))
merged_options[:skip_instruct] = true
- if records.is_a?(Enumerable)
+ if records.respond_to?(:to_ary)
+ records = records.to_ary
+
tag = ActiveSupport::XmlMini.rename_key(association.to_s, options)
type = options[:skip_types] ? { } : {:type => "array"}
association_name = association.to_s.singularize
diff --git a/activemodel/test/cases/serialization_test.rb b/activemodel/test/cases/serialization_test.rb
index 66b18d65e5..d2ba9fd95d 100644
--- a/activemodel/test/cases/serialization_test.rb
+++ b/activemodel/test/cases/serialization_test.rb
@@ -105,6 +105,24 @@ class SerializationTest < ActiveModel::TestCase
assert_equal expected, @user.serializable_hash(:include => :friends)
end
+ class FriendList
+ def initialize(friends)
+ @friends = friends
+ end
+
+ def to_ary
+ @friends
+ end
+ end
+
+ def test_include_option_with_ary
+ @user.friends = FriendList.new(@user.friends)
+ expected = {"email"=>"david@example.com", "gender"=>"male", "name"=>"David",
+ "friends"=>[{"name"=>'Joe', "email"=>'joe@example.com', "gender"=>'male'},
+ {"name"=>'Sue', "email"=>'sue@example.com', "gender"=>'female'}]}
+ assert_equal expected, @user.serializable_hash(:include => :friends)
+ end
+
def test_multiple_includes
expected = {"email"=>"david@example.com", "gender"=>"male", "name"=>"David",
"address"=>{"street"=>"123 Lane", "city"=>"Springfield", "state"=>"CA", "zip"=>11111},
diff --git a/activemodel/test/cases/serializers/xml_serialization_test.rb b/activemodel/test/cases/serializers/xml_serialization_test.rb
index 38aecf51ff..5fa227e0e0 100644
--- a/activemodel/test/cases/serializers/xml_serialization_test.rb
+++ b/activemodel/test/cases/serializers/xml_serialization_test.rb
@@ -188,6 +188,23 @@ class XmlSerializationTest < ActiveModel::TestCase
assert_match %r{}, xml
end
+ class FriendList
+ def initialize(friends)
+ @friends = friends
+ end
+
+ def to_ary
+ @friends
+ end
+ end
+
+ test "include option with ary" do
+ @contact.friends = FriendList.new(@contact.friends)
+ xml = @contact.to_xml :include => :friends, :indent => 0
+ assert_match %r{}, xml
+ assert_match %r{}, xml
+ end
+
test "multiple includes" do
xml = @contact.to_xml :indent => 0, :skip_instruct => true, :include => [ :address, :friends ]
assert xml.include?(@contact.address.to_xml(:indent => 0, :skip_instruct => true))
--
cgit v1.2.3
From c86a32d7451c5d901620ac58630460915292f88b Mon Sep 17 00:00:00 2001
From: Jon Leighton
Date: Fri, 11 May 2012 17:19:30 +0100
Subject: CollectionProxy < Relation
This helps bring the interfaces of CollectionProxy and Relation closer
together, and reduces the delegation backflips we need to perform.
For example, first_or_create is defined thus:
class ActiveRecord::Relation
def first_or_create(...)
first || create(...)
end
end
If CollectionProxy < Relation, then post.comments.first_or_create will
hit the association's #create method which will actually add the new record
to the association, just as post.comments.create would.
With the previous delegation, post.comments.first_or_create expands to
post.comments.scoped.first_or_create, where post.comments.scoped has no
knowledge of the association.
---
.../associations/collection_association.rb | 8 +----
.../active_record/associations/collection_proxy.rb | 37 +++++++++++--------
.../lib/active_record/autosave_association.rb | 2 +-
.../active_record/relation/predicate_builder.rb | 6 ++--
.../lib/active_record/relation/query_methods.rb | 42 +++++++++++-----------
.../lib/active_record/relation/spawn_methods.rb | 13 ++++---
activerecord/test/cases/associations/eager_test.rb | 2 +-
.../has_and_belongs_to_many_associations_test.rb | 2 +-
.../associations/has_many_associations_test.rb | 21 ++++++++---
.../test/cases/associations/join_model_test.rb | 2 +-
.../test/cases/autosave_association_test.rb | 4 +--
11 files changed, 79 insertions(+), 60 deletions(-)
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 14aa557b6c..00321ec860 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -16,12 +16,6 @@ module ActiveRecord
# If you need to work on all current children, new and existing records,
# +load_target+ and the +loaded+ flag are your friends.
class CollectionAssociation < Association #:nodoc:
- attr_reader :proxy
-
- def initialize(owner, reflection)
- super
- @proxy = CollectionProxy.new(self)
- end
# Implements the reader method, e.g. foo.items for Foo.has_many :items
def reader(force_reload = false)
@@ -31,7 +25,7 @@ module ActiveRecord
reload
end
- proxy
+ CollectionProxy.new(self)
end
# Implements the writer method, e.g. foo.items= for Foo.has_many :items
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index 261a829281..47ed9f58d8 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -33,14 +33,7 @@ module ActiveRecord
#
# is computed directly through SQL and does not trigger by itself the
# instantiation of the actual post records.
- class CollectionProxy # :nodoc:
- alias :proxy_extend :extend
-
- instance_methods.each { |m| undef_method m unless m.to_s =~ /^(?:nil\?|send|object_id|to_a)$|^__|^respond_to|proxy_/ }
-
- delegate :group, :order, :limit, :joins, :where, :preload, :eager_load, :includes, :from,
- :lock, :readonly, :having, :pluck, :to => :scoped
-
+ class CollectionProxy < Relation # :nodoc:
delegate :target, :load_target, :loaded?, :to => :@association
delegate :select, :find, :first, :last,
@@ -52,7 +45,8 @@ module ActiveRecord
def initialize(association)
@association = association
- Array(association.options[:extend]).each { |ext| proxy_extend(ext) }
+ super association.klass, association.klass.arel_table
+ merge! association.scoped
end
alias_method :new, :build
@@ -61,15 +55,24 @@ module ActiveRecord
@association
end
+ # We don't want this object to be put on the scoping stack, because
+ # that could create an infinite loop where we call an @association
+ # method, which gets the current scope, which is this object, which
+ # delegates to @association, and so on.
+ def scoping
+ @association.scoped.scoping { yield }
+ end
+
+ def spawn
+ scoped
+ end
+
def scoped(options = nil)
association = @association
- scope = association.scoped
- scope.extending! do
+ super.extending! do
define_method(:proxy_association) { association }
end
- scope.merge!(options) if options
- scope
end
def respond_to?(name, include_private = false)
@@ -81,7 +84,7 @@ module ActiveRecord
def method_missing(method, *args, &block)
match = DynamicMatchers::Method.match(self, method)
if match && match.is_a?(DynamicMatchers::Instantiator)
- scoped.send(method, *args) do |r|
+ super do |r|
proxy_association.send :set_owner_attributes, r
proxy_association.send :add_to_target, r
yield(r) if block_given?
@@ -101,10 +104,14 @@ module ActiveRecord
end
else
- scoped.readonly(nil).public_send(method, *args, &block)
+ super
end
end
+ def ==(other)
+ load_target == other
+ end
+
# Forwards === explicitly to the \target because the instance method
# removal above doesn't catch it. Loads the \target if needed.
def ===(other)
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb
index 3005bef092..d545e7799d 100644
--- a/activerecord/lib/active_record/autosave_association.rb
+++ b/activerecord/lib/active_record/autosave_association.rb
@@ -350,7 +350,7 @@ module ActiveRecord
end
records_to_destroy.each do |record|
- association.proxy.destroy(record)
+ association.destroy(record)
end
end
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb
index b40bf2b3cf..6a0cdd5917 100644
--- a/activerecord/lib/active_record/relation/predicate_builder.rb
+++ b/activerecord/lib/active_record/relation/predicate_builder.rb
@@ -34,9 +34,6 @@ module ActiveRecord
private
def self.build(attribute, value)
case value
- when ActiveRecord::Relation
- value = value.select(value.klass.arel_table[value.klass.primary_key]) if value.select_values.empty?
- attribute.in(value.arel.ast)
when Array, ActiveRecord::Associations::CollectionProxy
values = value.to_a.map {|x| x.is_a?(ActiveRecord::Model) ? x.id : x}
ranges, values = values.partition {|v| v.is_a?(Range)}
@@ -59,6 +56,9 @@ module ActiveRecord
array_predicates = ranges.map { |range| attribute.in(range) }
array_predicates << values_predicate
array_predicates.inject { |composite, predicate| composite.or(predicate) }
+ when ActiveRecord::Relation
+ value = value.select(value.klass.arel_table[value.klass.primary_key]) if value.select_values.empty?
+ attribute.in(value.arel.ast)
when Range
attribute.in(value)
when ActiveRecord::Model
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 855477eaed..29536b16c4 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -40,7 +40,7 @@ module ActiveRecord
alias extensions extending_values
def includes(*args)
- args.empty? ? self : clone.includes!(*args)
+ args.empty? ? self : spawn.includes!(*args)
end
def includes!(*args)
@@ -51,7 +51,7 @@ module ActiveRecord
end
def eager_load(*args)
- args.blank? ? self : clone.eager_load!(*args)
+ args.blank? ? self : spawn.eager_load!(*args)
end
def eager_load!(*args)
@@ -60,7 +60,7 @@ module ActiveRecord
end
def preload(*args)
- args.blank? ? self : clone.preload!(*args)
+ args.blank? ? self : spawn.preload!(*args)
end
def preload!(*args)
@@ -79,7 +79,7 @@ module ActiveRecord
# User.includes(:posts).where("posts.name = 'foo'").references(:posts)
# # => Query now knows the string references posts, so adds a JOIN
def references(*args)
- args.blank? ? self : clone.references!(*args)
+ args.blank? ? self : spawn.references!(*args)
end
def references!(*args)
@@ -120,7 +120,7 @@ module ActiveRecord
if block_given?
to_a.select { |*block_args| value.call(*block_args) }
else
- clone.select!(value)
+ spawn.select!(value)
end
end
@@ -130,7 +130,7 @@ module ActiveRecord
end
def group(*args)
- args.blank? ? self : clone.group!(*args)
+ args.blank? ? self : spawn.group!(*args)
end
def group!(*args)
@@ -139,7 +139,7 @@ module ActiveRecord
end
def order(*args)
- args.blank? ? self : clone.order!(*args)
+ args.blank? ? self : spawn.order!(*args)
end
def order!(*args)
@@ -165,7 +165,7 @@ module ActiveRecord
# generates a query with 'ORDER BY id ASC, name ASC'.
#
def reorder(*args)
- args.blank? ? self : clone.reorder!(*args)
+ args.blank? ? self : spawn.reorder!(*args)
end
def reorder!(*args)
@@ -175,7 +175,7 @@ module ActiveRecord
end
def joins(*args)
- args.compact.blank? ? self : clone.joins!(*args)
+ args.compact.blank? ? self : spawn.joins!(*args)
end
def joins!(*args)
@@ -186,7 +186,7 @@ module ActiveRecord
end
def bind(value)
- clone.bind!(value)
+ spawn.bind!(value)
end
def bind!(value)
@@ -195,7 +195,7 @@ module ActiveRecord
end
def where(opts, *rest)
- opts.blank? ? self : clone.where!(opts, *rest)
+ opts.blank? ? self : spawn.where!(opts, *rest)
end
def where!(opts, *rest)
@@ -206,7 +206,7 @@ module ActiveRecord
end
def having(opts, *rest)
- opts.blank? ? self : clone.having!(opts, *rest)
+ opts.blank? ? self : spawn.having!(opts, *rest)
end
def having!(opts, *rest)
@@ -217,7 +217,7 @@ module ActiveRecord
end
def limit(value)
- clone.limit!(value)
+ spawn.limit!(value)
end
def limit!(value)
@@ -226,7 +226,7 @@ module ActiveRecord
end
def offset(value)
- clone.offset!(value)
+ spawn.offset!(value)
end
def offset!(value)
@@ -235,7 +235,7 @@ module ActiveRecord
end
def lock(locks = true)
- clone.lock!(locks)
+ spawn.lock!(locks)
end
def lock!(locks = true)
@@ -283,7 +283,7 @@ module ActiveRecord
end
def readonly(value = true)
- clone.readonly!(value)
+ spawn.readonly!(value)
end
def readonly!(value = true)
@@ -292,7 +292,7 @@ module ActiveRecord
end
def create_with(value)
- clone.create_with!(value)
+ spawn.create_with!(value)
end
def create_with!(value)
@@ -301,7 +301,7 @@ module ActiveRecord
end
def from(value)
- clone.from!(value)
+ spawn.from!(value)
end
def from!(value)
@@ -320,7 +320,7 @@ module ActiveRecord
# User.select(:name).uniq.uniq(false)
# # => You can also remove the uniqueness
def uniq(value = true)
- clone.uniq!(value)
+ spawn.uniq!(value)
end
def uniq!(value = true)
@@ -366,7 +366,7 @@ module ActiveRecord
# end
def extending(*modules, &block)
if modules.any? || block
- clone.extending!(*modules, &block)
+ spawn.extending!(*modules, &block)
else
self
end
@@ -382,7 +382,7 @@ module ActiveRecord
end
def reverse_order
- clone.reverse_order!
+ spawn.reverse_order!
end
def reverse_order!
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb
index f6d178db7a..80d087a9ea 100644
--- a/activerecord/lib/active_record/relation/spawn_methods.rb
+++ b/activerecord/lib/active_record/relation/spawn_methods.rb
@@ -5,7 +5,12 @@ require 'active_record/relation/merger'
module ActiveRecord
module SpawnMethods
-
+
+ # This is overridden by Associations::CollectionProxy
+ def spawn #:nodoc:
+ clone
+ end
+
# Merges in the conditions from other, if other is an ActiveRecord::Relation.
# Returns an array representing the intersection of the resulting records with other, if other is an array.
#
@@ -23,7 +28,7 @@ module ActiveRecord
if other.is_a?(Array)
to_a & other
elsif other
- clone.merge!(other)
+ spawn.merge!(other)
else
self
end
@@ -42,7 +47,7 @@ module ActiveRecord
# Post.where('id > 10').order('id asc').except(:where) # discards the where condition but keeps the order
#
def except(*skips)
- result = self.class.new(@klass, table, values.except(*skips))
+ result = Relation.new(klass, table, values.except(*skips))
result.default_scoped = default_scoped
result.extend(*extending_values) if extending_values.any?
result
@@ -56,7 +61,7 @@ module ActiveRecord
# Post.order('id asc').only(:where, :order) # uses the specified order
#
def only(*onlies)
- result = self.class.new(@klass, table, values.slice(*onlies))
+ result = Relation.new(klass, table, values.slice(*onlies))
result.default_scoped = default_scoped
result.extend(*extending_values) if extending_values.any?
result
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index 2e44005847..08467900f9 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -189,7 +189,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
author = assert_queries(3) { Author.scoped(:includes => {:posts_with_comments => :comments}).find(author_id) } # find the author, then find the posts, then find the comments
author.posts_with_comments.each do |post_with_comments|
assert_equal post_with_comments.comments.length, post_with_comments.comments.count
- assert_nil post_with_comments.comments.uniq!
+ assert_nil post_with_comments.comments.to_a.uniq!
end
end
diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
index 22fd80df28..cd581485d5 100644
--- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -497,7 +497,7 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
def test_include_uses_array_include_after_loaded
project = projects(:active_record)
- project.developers.class # force load target
+ project.developers.load_target
developer = project.developers.first
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index f74fe42dc2..47ad6a1ba7 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -892,12 +892,11 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
client_id = firm.clients_of_firm.first.id
assert_equal 1, firm.clients_of_firm.size
- cleared = firm.clients_of_firm.clear
+ firm.clients_of_firm.clear
assert_equal 0, firm.clients_of_firm.size
assert_equal 0, firm.clients_of_firm(true).size
assert_equal [], Client.destroyed_client_ids[firm.id]
- assert_equal firm.clients_of_firm.object_id, cleared.object_id
# Should not be destroyed since the association is not dependent.
assert_nothing_raised do
@@ -1359,7 +1358,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
def test_include_uses_array_include_after_loaded
firm = companies(:first_firm)
- firm.clients.class # force load target
+ firm.clients.load_target
client = firm.clients.first
@@ -1409,7 +1408,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
def test_calling_first_or_last_on_loaded_association_should_not_fetch_with_query
firm = companies(:first_firm)
- firm.clients.class # force load target
+ firm.clients.load_target
assert firm.clients.loaded?
assert_no_queries do
@@ -1708,4 +1707,18 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
firm = companies(:first_firm)
assert_equal [accounts(:signals37)], firm.accounts.open
end
+
+ test "first_or_initialize adds the record to the association" do
+ firm = Firm.create! name: 'omg'
+ client = firm.clients_of_firm.first_or_initialize
+ assert_equal [client], firm.clients_of_firm
+ end
+
+ test "first_or_create adds the record to the association" do
+ firm = Firm.create! name: 'omg'
+ firm.clients_of_firm.load_target
+ client = firm.clients_of_firm.first_or_create name: 'lol'
+ assert_equal [client], firm.clients_of_firm
+ assert_equal [client], firm.reload.clients_of_firm
+ end
end
diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb
index 3606ce691c..20b0eeb5ea 100644
--- a/activerecord/test/cases/associations/join_model_test.rb
+++ b/activerecord/test/cases/associations/join_model_test.rb
@@ -676,7 +676,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
def test_has_many_through_include_uses_array_include_after_loaded
david = authors(:david)
- david.categories.class # force load target
+ david.categories.load_target
category = david.categories.first
diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb
index c93c91803e..8ef3bfef15 100644
--- a/activerecord/test/cases/autosave_association_test.rb
+++ b/activerecord/test/cases/autosave_association_test.rb
@@ -872,7 +872,7 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase
2.times { |i| @pirate.parrots.create!(:name => "parrots_#{i}") }
before = @pirate.parrots.map { |c| c.mark_for_destruction ; c }
- class << @pirate.parrots
+ class << @pirate.association(:parrots)
def destroy(*args)
super
raise 'Oh noes!'
@@ -1277,7 +1277,7 @@ module AutosaveAssociationOnACollectionAssociationTests
def test_should_not_load_the_associated_models_if_they_were_not_loaded_yet
assert_queries(1) { @pirate.catchphrase = 'Arr'; @pirate.save! }
- @pirate.send(@association_name).class # hack to load the target
+ @pirate.send(@association_name).load_target
assert_queries(3) do
@pirate.catchphrase = 'Yarr'
--
cgit v1.2.3
From 8f50bbee31ca4b2cc2ac9b9889c421f6a38d97f4 Mon Sep 17 00:00:00 2001
From: Jon Leighton
Date: Fri, 11 May 2012 18:19:39 +0100
Subject: set_owner_attributes is covered by the scoping
---
activerecord/lib/active_record/associations/collection_proxy.rb | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index 47ed9f58d8..66815d83bc 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -84,10 +84,9 @@ module ActiveRecord
def method_missing(method, *args, &block)
match = DynamicMatchers::Method.match(self, method)
if match && match.is_a?(DynamicMatchers::Instantiator)
- super do |r|
- proxy_association.send :set_owner_attributes, r
- proxy_association.send :add_to_target, r
- yield(r) if block_given?
+ super do |record|
+ proxy_association.add_to_target(record)
+ yield record if block_given?
end
elsif target.respond_to?(method) || (!proxy_association.klass.respond_to?(method) && Class.respond_to?(method))
--
cgit v1.2.3
From be7c6ee56d40b2205cb071b8d616191eac292ce8 Mon Sep 17 00:00:00 2001
From: Jon Leighton
Date: Fri, 11 May 2012 19:42:53 +0100
Subject: extract deprecated code
---
activerecord/lib/active_record/associations/collection_proxy.rb | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index 66815d83bc..96911d1d79 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -82,14 +82,7 @@ module ActiveRecord
end
def method_missing(method, *args, &block)
- match = DynamicMatchers::Method.match(self, method)
- if match && match.is_a?(DynamicMatchers::Instantiator)
- super do |record|
- proxy_association.add_to_target(record)
- yield record if block_given?
- end
-
- elsif target.respond_to?(method) || (!proxy_association.klass.respond_to?(method) && Class.respond_to?(method))
+ if target.respond_to?(method) || (!proxy_association.klass.respond_to?(method) && Class.respond_to?(method))
if load_target
if target.respond_to?(method)
target.send(method, *args, &block)
--
cgit v1.2.3
From ecef5a9f224ad3ac74c0466b33cef0226ec0787c Mon Sep 17 00:00:00 2001
From: Jon Leighton
Date: Fri, 11 May 2012 20:05:04 +0100
Subject: this stuff can all be handled by Relation
---
.../active_record/associations/collection_proxy.rb | 38 ----------------------
1 file changed, 38 deletions(-)
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index 96911d1d79..b3e46d3707 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -75,31 +75,6 @@ module ActiveRecord
end
end
- def respond_to?(name, include_private = false)
- super ||
- (load_target && target.respond_to?(name, include_private)) ||
- proxy_association.klass.respond_to?(name, include_private)
- end
-
- def method_missing(method, *args, &block)
- if target.respond_to?(method) || (!proxy_association.klass.respond_to?(method) && Class.respond_to?(method))
- if load_target
- if target.respond_to?(method)
- target.send(method, *args, &block)
- else
- begin
- super
- rescue NoMethodError => e
- raise e, e.message.sub(/ for #<.*$/, " via proxy for #{target}")
- end
- end
- end
-
- else
- super
- end
- end
-
def ==(other)
load_target == other
end
@@ -129,19 +104,6 @@ module ActiveRecord
proxy_association.reload
self
end
-
- # Define array public methods because we know it should be invoked over
- # the target, so we can have a performance improvement using those methods
- # in association collections
- Array.public_instance_methods.each do |m|
- unless method_defined?(m)
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
- def #{m}(*args, &block)
- target.public_send(:#{m}, *args, &block) if load_target
- end
- RUBY
- end
- end
end
end
end
--
cgit v1.2.3
From ef440bb0c3378a04300c592ec8432d26afc6ad1d Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Fri, 11 May 2012 16:21:32 -0500
Subject: remove unnecessary 'examples' noise
---
activesupport/lib/active_support/core_ext/string/filters.rb | 1 -
activesupport/lib/active_support/core_ext/string/inflections.rb | 6 ------
activesupport/lib/active_support/core_ext/string/output_safety.rb | 2 --
3 files changed, 9 deletions(-)
diff --git a/activesupport/lib/active_support/core_ext/string/filters.rb b/activesupport/lib/active_support/core_ext/string/filters.rb
index 32a37296d5..2478f42290 100644
--- a/activesupport/lib/active_support/core_ext/string/filters.rb
+++ b/activesupport/lib/active_support/core_ext/string/filters.rb
@@ -5,7 +5,6 @@ class String
# the string, and then changing remaining consecutive whitespace
# groups into one space each.
#
- # Examples:
# %{ Multi-line
# string }.squish # => "Multi-line string"
# " foo bar \n \t boo".squish # => "foo bar boo"
diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb
index 049ffe7986..070bfd7af6 100644
--- a/activesupport/lib/active_support/core_ext/string/inflections.rb
+++ b/activesupport/lib/active_support/core_ext/string/inflections.rb
@@ -13,7 +13,6 @@ class String
# the singular form will be returned if count == 1.
# For any other value of +count+ the plural will be returned.
#
- # ==== Examples
# 'post'.pluralize # => "posts"
# 'octopus'.pluralize # => "octopi"
# 'sheep'.pluralize # => "sheep"
@@ -46,7 +45,6 @@ class String
# in the string. It raises a NameError when the name is not in CamelCase
# or is not initialized. See ActiveSupport::Inflector.constantize
#
- # Examples
# 'Module'.constantize # => Module
# 'Class'.constantize # => Class
# 'blargle'.constantize # => NameError: wrong constant name blargle
@@ -58,7 +56,6 @@ class String
# in the string. It returns nil when the name is not in CamelCase
# or is not initialized. See ActiveSupport::Inflector.safe_constantize
#
- # Examples
# 'Module'.safe_constantize # => Module
# 'Class'.safe_constantize # => Class
# 'blargle'.safe_constantize # => nil
@@ -140,8 +137,6 @@ class String
# Replaces special characters in a string so that it may be used as part of a 'pretty' URL.
#
- # ==== Examples
- #
# class Person
# def to_param
# "#{id}-#{name.parameterize}"
@@ -194,7 +189,6 @@ class String
# +separate_class_name_and_id_with_underscore+ sets whether
# the method should put '_' between the name and 'id'.
#
- # Examples
# 'Message'.foreign_key # => "message_id"
# 'Message'.foreign_key(false) # => "messageid"
# 'Admin::Post'.foreign_key # => "post_id"
diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb
index 215ba87ca9..6bda970e40 100644
--- a/activesupport/lib/active_support/core_ext/string/output_safety.rb
+++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb
@@ -14,7 +14,6 @@ class ERB
# In your ERB templates, use this method to escape any unsafe content. For example:
# <%=h @person.name %>
#
- # ==== Example:
# puts html_escape('is a > 0 & a < 10?')
# # => is a > 0 & a < 10?
def html_escape(s)
@@ -37,7 +36,6 @@ class ERB
# A utility method for escaping HTML without affecting existing escaped entities.
#
- # ==== Examples
# html_escape_once('1 < 2 & 3')
# # => "1 < 2 & 3"
#
--
cgit v1.2.3
From 7bf6edf819adf48b253dce7673ec82cda821646b Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Fri, 11 May 2012 16:42:23 -0500
Subject: added examples to String#exclude?
---
activesupport/lib/active_support/core_ext/string/exclude.rb | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/activesupport/lib/active_support/core_ext/string/exclude.rb b/activesupport/lib/active_support/core_ext/string/exclude.rb
index 5e184ec1b3..114bcb87f0 100644
--- a/activesupport/lib/active_support/core_ext/string/exclude.rb
+++ b/activesupport/lib/active_support/core_ext/string/exclude.rb
@@ -1,5 +1,10 @@
class String
- # The inverse of String#include?. Returns true if the string does not include the other string.
+ # The inverse of String#include?. Returns true if the string
+ # does not include the other string.
+ #
+ # "hello".exclude? "lo" #=> false
+ # "hello".exclude? "ol" #=> true
+ # "hello".exclude? ?h #=> false
def exclude?(string)
!include?(string)
end
--
cgit v1.2.3
From a6381042fa9899544c365dfa369ab15c79f7f158 Mon Sep 17 00:00:00 2001
From: Santiago Pastorino
Date: Thu, 10 May 2012 19:28:02 -0300
Subject: Remove ruby/shim
require 'action_view' is now much faster
---
actionpack/lib/abstract_controller.rb | 1 -
actionpack/lib/action_view.rb | 2 +-
activesupport/lib/active_support/ruby/shim.rb | 15 ---------------
3 files changed, 1 insertion(+), 17 deletions(-)
delete mode 100644 activesupport/lib/active_support/ruby/shim.rb
diff --git a/actionpack/lib/abstract_controller.rb b/actionpack/lib/abstract_controller.rb
index cc5878c88e..f970007621 100644
--- a/actionpack/lib/abstract_controller.rb
+++ b/actionpack/lib/abstract_controller.rb
@@ -3,7 +3,6 @@ $:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.inc
require 'action_pack'
require 'active_support/concern'
-require 'active_support/ruby/shim'
require 'active_support/dependencies/autoload'
require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/module/attr_internal'
diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb
index 349a3fcc6e..4aa3c12d52 100644
--- a/actionpack/lib/action_view.rb
+++ b/actionpack/lib/action_view.rb
@@ -21,9 +21,9 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
-require 'active_support/ruby/shim'
require 'active_support/core_ext/class/attribute_accessors'
+require 'active_support'
require 'action_pack'
module ActionView
diff --git a/activesupport/lib/active_support/ruby/shim.rb b/activesupport/lib/active_support/ruby/shim.rb
deleted file mode 100644
index 13e96b3596..0000000000
--- a/activesupport/lib/active_support/ruby/shim.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# Backported Ruby builtins so you can code with the latest & greatest
-# but still run on any Ruby 1.8.x.
-#
-# Date next_year, next_month
-# DateTime to_date, to_datetime, xmlschema
-# Enumerable group_by, none?
-# String ord
-# Time to_date, to_time, to_datetime
-require 'active_support'
-require 'active_support/core_ext/date/calculations'
-require 'active_support/core_ext/date_time/conversions'
-require 'active_support/core_ext/enumerable'
-require 'active_support/core_ext/string/conversions'
-require 'active_support/core_ext/string/interpolation'
-require 'active_support/core_ext/time/conversions'
--
cgit v1.2.3
From abd6f4a2b14fb048c95b3211f2c9fe5f1c006bc0 Mon Sep 17 00:00:00 2001
From: Santiago Pastorino
Date: Thu, 10 May 2012 19:50:56 -0300
Subject: Move require to where it's needed
---
actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb | 1 +
actionpack/lib/action_dispatch/middleware/exception_wrapper.rb | 3 ++-
actionpack/lib/action_view.rb | 2 --
actionpack/lib/action_view/base.rb | 1 +
actionpack/lib/action_view/helpers/form_helper.rb | 1 +
actionpack/lib/action_view/template/resolver.rb | 1 +
6 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb b/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb
index 114b0e73c9..6b269e7a31 100644
--- a/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb
+++ b/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb
@@ -1,6 +1,7 @@
require 'set'
require 'cgi'
require 'active_support/core_ext/class/attribute'
+require 'active_support/core_ext/class/attribute_accessors'
module HTML
class Sanitizer
diff --git a/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb b/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb
index 982f6641bf..a8f49bd3bd 100644
--- a/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb
+++ b/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb
@@ -1,5 +1,6 @@
require 'action_controller/metal/exceptions'
require 'active_support/core_ext/exception'
+require 'active_support/core_ext/class/attribute_accessors'
module ActionDispatch
class ExceptionWrapper
@@ -76,4 +77,4 @@ module ActionDispatch
@backtrace_cleaner ||= @env['action_dispatch.backtrace_cleaner']
end
end
-end
\ No newline at end of file
+end
diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb
index 4aa3c12d52..438f53ede9 100644
--- a/actionpack/lib/action_view.rb
+++ b/actionpack/lib/action_view.rb
@@ -21,8 +21,6 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
-require 'active_support/core_ext/class/attribute_accessors'
-
require 'active_support'
require 'action_pack'
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 5f81f24a2e..f98648d930 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -1,6 +1,7 @@
require 'active_support/core_ext/module/attr_internal'
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/class/attribute'
+require 'active_support/core_ext/class/attribute_accessors'
require 'active_support/ordered_options'
require 'action_view/log_subscriber'
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 67f2abe509..0fbd6ac41b 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -5,6 +5,7 @@ require 'action_view/helpers/form_tag_helper'
require 'action_view/helpers/active_model_helper'
require 'action_view/helpers/tags'
require 'active_support/core_ext/class/attribute'
+require 'active_support/core_ext/class/attribute_accessors'
require 'active_support/core_ext/hash/slice'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/string/output_safety'
diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb
index 8ea2e5bfe4..08155af013 100644
--- a/actionpack/lib/action_view/template/resolver.rb
+++ b/actionpack/lib/action_view/template/resolver.rb
@@ -1,5 +1,6 @@
require "pathname"
require "active_support/core_ext/class"
+require "active_support/core_ext/class/attribute_accessors"
require "action_view/template"
module ActionView
--
cgit v1.2.3
From a00228c1a35578c4bf4d462eec977a50120288da Mon Sep 17 00:00:00 2001
From: Santiago Pastorino
Date: Thu, 10 May 2012 20:48:23 -0300
Subject: Lazy load I18n
---
actionpack/lib/action_view.rb | 5 +++--
activemodel/lib/active_model.rb | 5 +++--
activerecord/lib/active_record.rb | 5 +++--
activesupport/lib/active_support/i18n.rb | 1 +
4 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb
index 438f53ede9..3823f87027 100644
--- a/actionpack/lib/action_view.rb
+++ b/actionpack/lib/action_view.rb
@@ -76,7 +76,8 @@ module ActionView
ENCODING_FLAG = '#.*coding[:=]\s*(\S+)[ \t]*'
end
-require 'active_support/i18n'
require 'active_support/core_ext/string/output_safety'
-I18n.load_path << "#{File.dirname(__FILE__)}/action_view/locale/en.yml"
+ActiveSupport.on_load(:i18n) do
+ I18n.load_path << "#{File.dirname(__FILE__)}/action_view/locale/en.yml"
+end
diff --git a/activemodel/lib/active_model.rb b/activemodel/lib/active_model.rb
index 2586147a20..7503fb7929 100644
--- a/activemodel/lib/active_model.rb
+++ b/activemodel/lib/active_model.rb
@@ -59,5 +59,6 @@ module ActiveModel
end
end
-require 'active_support/i18n'
-I18n.load_path << File.dirname(__FILE__) + '/active_model/locale/en.yml'
+ActiveSupport.on_load(:i18n) do
+ I18n.load_path << File.dirname(__FILE__) + '/active_model/locale/en.yml'
+end
diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb
index ed26b4899f..210820062b 100644
--- a/activerecord/lib/active_record.rb
+++ b/activerecord/lib/active_record.rb
@@ -22,7 +22,6 @@
#++
require 'active_support'
-require 'active_support/i18n'
require 'active_model'
require 'arel'
require 'active_record_deprecated_finders'
@@ -145,4 +144,6 @@ ActiveSupport.on_load(:active_record) do
Arel::Table.engine = self
end
-I18n.load_path << File.dirname(__FILE__) + '/active_record/locale/en.yml'
+ActiveSupport.on_load(:i18n) do
+ I18n.load_path << File.dirname(__FILE__) + '/active_record/locale/en.yml'
+end
diff --git a/activesupport/lib/active_support/i18n.rb b/activesupport/lib/active_support/i18n.rb
index f9c5e5e2f8..188653bd9b 100644
--- a/activesupport/lib/active_support/i18n.rb
+++ b/activesupport/lib/active_support/i18n.rb
@@ -6,4 +6,5 @@ rescue LoadError => e
raise e
end
+ActiveSupport.run_load_hooks(:i18n)
I18n.load_path << "#{File.dirname(__FILE__)}/locale/en.yml"
--
cgit v1.2.3
From 36dd1857dc097b6fbc65396bfabaa152da9c899f Mon Sep 17 00:00:00 2001
From: Santiago Pastorino
Date: Fri, 11 May 2012 13:56:05 -0300
Subject: Remove useless load path modifications
---
actionmailer/lib/action_mailer.rb | 3 ---
actionmailer/test/abstract_unit.rb | 3 ---
actionpack/lib/abstract_controller.rb | 3 ---
actionpack/lib/action_dispatch.rb | 6 ------
actionpack/test/abstract_unit.rb | 6 ------
actionpack/test/ts_isolated.rb | 3 ---
activemodel/lib/active_model.rb | 2 --
activemodel/test/cases/helper.rb | 3 ---
activesupport/test/abstract_unit.rb | 3 ---
activesupport/test/ts_isolated.rb | 2 --
railties/Rakefile | 3 ++-
railties/test/isolation/abstract_unit.rb | 5 ++---
12 files changed, 4 insertions(+), 38 deletions(-)
diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb
index 1045dd58ef..e45a1cd5ff 100644
--- a/actionmailer/lib/action_mailer.rb
+++ b/actionmailer/lib/action_mailer.rb
@@ -21,9 +21,6 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
-actionpack_path = File.expand_path('../../../actionpack/lib', __FILE__)
-$:.unshift(actionpack_path) if File.directory?(actionpack_path) && !$:.include?(actionpack_path)
-
require 'abstract_controller'
require 'action_view'
require 'action_mailer/version'
diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb
index 487102b564..99c44179fd 100644
--- a/actionmailer/test/abstract_unit.rb
+++ b/actionmailer/test/abstract_unit.rb
@@ -8,9 +8,6 @@ silence_warnings do
Encoding.default_external = "UTF-8"
end
-lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
-$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
-
require 'minitest/autorun'
require 'action_mailer'
require 'action_mailer/test_case'
diff --git a/actionpack/lib/abstract_controller.rb b/actionpack/lib/abstract_controller.rb
index f970007621..b95ea5f0b2 100644
--- a/actionpack/lib/abstract_controller.rb
+++ b/actionpack/lib/abstract_controller.rb
@@ -1,6 +1,3 @@
-activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__)
-$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
-
require 'action_pack'
require 'active_support/concern'
require 'active_support/dependencies/autoload'
diff --git a/actionpack/lib/action_dispatch.rb b/actionpack/lib/action_dispatch.rb
index e3b04ac097..1e4ac70f3d 100644
--- a/actionpack/lib/action_dispatch.rb
+++ b/actionpack/lib/action_dispatch.rb
@@ -21,12 +21,6 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
-activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__)
-$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
-
-activemodel_path = File.expand_path('../../../activemodel/lib', __FILE__)
-$:.unshift(activemodel_path) if File.directory?(activemodel_path) && !$:.include?(activemodel_path)
-
require 'active_support'
require 'active_support/dependencies/autoload'
require 'active_support/core_ext/module/attribute_accessors'
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index 22ba047328..ba06bcae51 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -1,11 +1,5 @@
require File.expand_path('../../../load_paths', __FILE__)
-lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
-$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
-
-activemodel_path = File.expand_path('../../../activemodel/lib', __FILE__)
-$:.unshift(activemodel_path) if File.directory?(activemodel_path) && !$:.include?(activemodel_path)
-
$:.unshift(File.dirname(__FILE__) + '/lib')
$:.unshift(File.dirname(__FILE__) + '/fixtures/helpers')
$:.unshift(File.dirname(__FILE__) + '/fixtures/alternate_helpers')
diff --git a/actionpack/test/ts_isolated.rb b/actionpack/test/ts_isolated.rb
index ae2a0c95f6..595b4018e9 100644
--- a/actionpack/test/ts_isolated.rb
+++ b/actionpack/test/ts_isolated.rb
@@ -1,6 +1,3 @@
-$:.unshift(File.dirname(__FILE__))
-$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
-
require 'minitest/autorun'
require 'rbconfig'
require 'abstract_unit'
diff --git a/activemodel/lib/active_model.rb b/activemodel/lib/active_model.rb
index 7503fb7929..ded1b752df 100644
--- a/activemodel/lib/active_model.rb
+++ b/activemodel/lib/active_model.rb
@@ -21,8 +21,6 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
-activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__)
-$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
require 'active_support'
require 'active_model/version'
diff --git a/activemodel/test/cases/helper.rb b/activemodel/test/cases/helper.rb
index 4347b17cbc..7d6f11b5a5 100644
--- a/activemodel/test/cases/helper.rb
+++ b/activemodel/test/cases/helper.rb
@@ -1,8 +1,5 @@
require File.expand_path('../../../../load_paths', __FILE__)
-lib = File.expand_path("#{File.dirname(__FILE__)}/../../lib")
-$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
-
require 'config'
require 'active_model'
require 'active_support/core_ext/string/access'
diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb
index 40e25ce0cd..57ed4a6b60 100644
--- a/activesupport/test/abstract_unit.rb
+++ b/activesupport/test/abstract_unit.rb
@@ -7,9 +7,6 @@ ensure
$VERBOSE = old
end
-lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
-$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
-
require 'active_support/core_ext/kernel/reporting'
require 'active_support/core_ext/string/encoding'
diff --git a/activesupport/test/ts_isolated.rb b/activesupport/test/ts_isolated.rb
index 1d96c20bb6..938bb4ee99 100644
--- a/activesupport/test/ts_isolated.rb
+++ b/activesupport/test/ts_isolated.rb
@@ -1,5 +1,3 @@
-$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
-
require 'minitest/autorun'
require 'active_support/test_case'
require 'rbconfig'
diff --git a/railties/Rakefile b/railties/Rakefile
index 108413235a..993ba840ff 100644
--- a/railties/Rakefile
+++ b/railties/Rakefile
@@ -20,7 +20,8 @@ namespace :test do
'test',
'lib',
"#{File.dirname(__FILE__)}/../activesupport/lib",
- "#{File.dirname(__FILE__)}/../actionpack/lib"
+ "#{File.dirname(__FILE__)}/../actionpack/lib",
+ "#{File.dirname(__FILE__)}/../activemodel/lib"
]
ruby "-I#{dash_i.join ':'}", file
end
diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb
index f2dc0c71b1..03be81e59f 100644
--- a/railties/test/isolation/abstract_unit.rb
+++ b/railties/test/isolation/abstract_unit.rb
@@ -17,8 +17,8 @@ RAILS_FRAMEWORK_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../..")
# These files do not require any others and are needed
# to run the tests
-require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/isolation"
-require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/core_ext/kernel/reporting"
+require "active_support/testing/isolation"
+require "active_support/core_ext/kernel/reporting"
module TestHelpers
module Paths
@@ -248,7 +248,6 @@ module TestHelpers
def use_frameworks(arr)
to_remove = [:actionmailer,
- :activemodel,
:activerecord] - arr
if to_remove.include? :activerecord
remove_from_config "config.active_record.whitelist_attributes = true"
--
cgit v1.2.3
From 53cc85fad3440d5817ecf7e0e8cd0c7ff3d9a062 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Fri, 11 May 2012 17:08:31 -0500
Subject: added docs to String#to_date
---
activesupport/lib/active_support/core_ext/string/conversions.rb | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb
index 9084bbee32..c42163a2f0 100644
--- a/activesupport/lib/active_support/core_ext/string/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/string/conversions.rb
@@ -15,6 +15,12 @@ class String
end
end
+ # Converts a string to a Date value.
+ #
+ # "1-1-2012".to_date #=> Sun, 01 Jan 2012
+ # "01/01/2012".to_date #=> Sun, 01 Jan 2012
+ # "2012-12-13".to_date #=> Thu, 13 Dec 2012
+ # "12/13/2012".to_date #=> ArgumentError: invalid date
def to_date
unless blank?
date_values = ::Date._parse(self, false).values_at(:year, :mon, :mday)
--
cgit v1.2.3
From fbf1858ed9fdb98f1489e045936d871978de928f Mon Sep 17 00:00:00 2001
From: Santiago Pastorino
Date: Fri, 11 May 2012 19:25:19 -0300
Subject: Add test directory to TestTask's libs
---
actionpack/Rakefile | 1 +
1 file changed, 1 insertion(+)
diff --git a/actionpack/Rakefile b/actionpack/Rakefile
index 17d95bfd1d..50e3bb0d48 100644
--- a/actionpack/Rakefile
+++ b/actionpack/Rakefile
@@ -23,6 +23,7 @@ end
namespace :test do
Rake::TestTask.new(:isolated) do |t|
+ t.libs << 'test'
t.pattern = 'test/ts_isolated.rb'
end
--
cgit v1.2.3
From a0b46b5f1b8b554f438dd4efcbd71274c34a5dae Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Fri, 11 May 2012 17:30:46 -0500
Subject: added docs to String#to_datetime
---
activesupport/lib/active_support/core_ext/string/conversions.rb | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb
index c42163a2f0..050eea33ee 100644
--- a/activesupport/lib/active_support/core_ext/string/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/string/conversions.rb
@@ -29,6 +29,12 @@ class String
end
end
+ # Converts a string to a DateTime value.
+ #
+ # "1-1-2012".to_datetime #=> Sun, 01 Jan 2012 00:00:00 +0000
+ # "01/01/2012 23:59:59".to_datetime #=> Sun, 01 Jan 2012 23:59:59 +0000
+ # "2012-12-13 12:50".to_datetime #=> Thu, 13 Dec 2012 12:50:00 +0000
+ # "12/13/2012".to_datetime #=> ArgumentError: invalid date
def to_datetime
unless blank?
date_values = ::Date._parse(self, false).
--
cgit v1.2.3
From 2091e5a65e2950689ad3242d67fdd7b15aa3411b Mon Sep 17 00:00:00 2001
From: Jon Leighton
Date: Fri, 11 May 2012 23:43:18 +0100
Subject: Remove #=== quirk
Makes it consistent with Relation. Can't see a use for this.
---
activerecord/lib/active_record/associations/collection_proxy.rb | 6 ------
.../cases/associations/has_and_belongs_to_many_associations_test.rb | 5 -----
activerecord/test/cases/associations/has_many_associations_test.rb | 6 ------
3 files changed, 17 deletions(-)
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index b3e46d3707..cf4cc98f38 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -79,12 +79,6 @@ module ActiveRecord
load_target == other
end
- # Forwards === explicitly to the \target because the instance method
- # removal above doesn't catch it. Loads the \target if needed.
- def ===(other)
- other === load_target
- end
-
def to_ary
load_target.dup
end
diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
index cd581485d5..470f0c3fd3 100644
--- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -123,11 +123,6 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
assert active_record.developers.include?(david)
end
- def test_triple_equality
- assert !(Array === Developer.find(1).projects)
- assert Developer.find(1).projects === Array
- end
-
def test_adding_single
jamis = Developer.find(2)
jamis.projects.reload # causing the collection to load
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 47ad6a1ba7..13d8c68b33 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -326,12 +326,6 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
authors(:david).readonly_comments.each { |c| assert c.readonly? }
end
- def test_triple_equality
- # sometimes tests on Oracle fail if ORDER BY is not provided therefore add always :order with :first
- assert !(Array === Firm.scoped(:order => "id").first.clients)
- assert Firm.scoped(:order => "id").first.clients === Array
- end
-
def test_finding_default_orders
assert_equal "Summit", Firm.scoped(:order => "id").first.clients.first.name
end
--
cgit v1.2.3
From 7dba51288fa2926e65afcc1022491a0f4e3c4d5c Mon Sep 17 00:00:00 2001
From: Erich Menge
Date: Fri, 11 May 2012 18:51:01 -0500
Subject: Better document the difference between #clone and #dup. Add #nodoc to
initialize_dup and use :method: to document the #dup method. Relates to issue
#6235
---
activerecord/lib/active_record/core.rb | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index a869ed8c04..f376cd034a 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -204,13 +204,38 @@ module ActiveRecord
self
end
-
+
+ ##
+ # :method: clone
+ # Identical to Ruby's clone method. This is a "shallow" copy. Be warned that your attributes are not copied.
+ # That means that modifying attributes of the clone will modify the original, since they will both point to the
+ # same attributes hash. If you need a copy of your attributes hash, please use the #dup method.
+ #
+ # Example:
+ #
+ # user = User.first
+ # new_user = user.clone
+ # user.name # => "Bob"
+ # new_user.name = "Joe"
+ # user.name # => "Joe"
+ #
+ # user.object_id == new_user.object_id # => false
+ # user.name.object_id == new_user.name.object_id # => true
+ #
+ # Use #dup instead, for a copy of the attributes hash.
+ # user.name.object_id == user.dup.name.object_id # => false
+
+ ##
+ # :method: dup
# Duped objects have no id assigned and are treated as new records. Note
# that this is a "shallow" copy as it copies the object's attributes
# only, not its associations. The extent of a "deep" copy is application
# specific and is therefore left to the application to implement according
# to its need.
# The dup method does not preserve the timestamps (created|updated)_(at|on).
+
+ ##
+ # :nodoc:
def initialize_dup(other)
cloned_attributes = other.clone_attributes(:read_attribute_before_type_cast)
self.class.initialize_attributes(cloned_attributes)
--
cgit v1.2.3
From fc6ab69777af21db3afb45de8ae08ffc316e69e9 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Fri, 11 May 2012 23:02:05 -0500
Subject: removing trailing spaces
---
activesupport/lib/active_support/core_ext/string/conversions.rb | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb
index 050eea33ee..022b376aec 100644
--- a/activesupport/lib/active_support/core_ext/string/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/string/conversions.rb
@@ -17,9 +17,9 @@ class String
# Converts a string to a Date value.
#
- # "1-1-2012".to_date #=> Sun, 01 Jan 2012
- # "01/01/2012".to_date #=> Sun, 01 Jan 2012
- # "2012-12-13".to_date #=> Thu, 13 Dec 2012
+ # "1-1-2012".to_date #=> Sun, 01 Jan 2012
+ # "01/01/2012".to_date #=> Sun, 01 Jan 2012
+ # "2012-12-13".to_date #=> Thu, 13 Dec 2012
# "12/13/2012".to_date #=> ArgumentError: invalid date
def to_date
unless blank?
--
cgit v1.2.3
From c78c29556e3fe338e4f8d27a917765a4f75c9b0d Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Fri, 11 May 2012 23:16:44 -0500
Subject: added examples to Integer#multiple_of?
---
activesupport/lib/active_support/core_ext/integer/multiple.rb | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/activesupport/lib/active_support/core_ext/integer/multiple.rb b/activesupport/lib/active_support/core_ext/integer/multiple.rb
index 8dff217ddc..907a0df723 100644
--- a/activesupport/lib/active_support/core_ext/integer/multiple.rb
+++ b/activesupport/lib/active_support/core_ext/integer/multiple.rb
@@ -1,5 +1,9 @@
class Integer
# Check whether the integer is evenly divisible by the argument.
+ #
+ # 0.multiple_of?(0) #=> true
+ # 5.multiple_of?(5) #=> false
+ # 10.multiple_of?(2) #=> true
def multiple_of?(number)
number != 0 ? self % number == 0 : zero?
end
--
cgit v1.2.3
From 1d1939056a81dd809b623a17d9930cf0bd1ca8ca Mon Sep 17 00:00:00 2001
From: Egor Homakov
Date: Sat, 12 May 2012 10:26:22 +0400
Subject: Update
railties/lib/rails/generators/rails/app/templates/config/application.rb
---
.../lib/rails/generators/rails/app/templates/config/application.rb | 3 +++
1 file changed, 3 insertions(+)
diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb
index c8a3c13b95..daa04c144e 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/application.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -43,6 +43,9 @@ module <%= app_const_base %>
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
+
+ # Enable escaping HTML in JSON. The default is false.
+ # config.active_support.escape_html_entities_in_json = true
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
--
cgit v1.2.3
From 38b4e7c8b1c4c46985b6e598d6df2df97457308a Mon Sep 17 00:00:00 2001
From: Geoffrey Roguelon
Date: Sat, 12 May 2012 10:36:35 +0200
Subject: Add commas missing in performance tests
---
guides/code/getting_started/test/performance/browsing_test.rb | 2 +-
.../generators/rails/app/templates/test/performance/browsing_test.rb | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/guides/code/getting_started/test/performance/browsing_test.rb b/guides/code/getting_started/test/performance/browsing_test.rb
index 3fea27b916..2a849b7f2b 100644
--- a/guides/code/getting_started/test/performance/browsing_test.rb
+++ b/guides/code/getting_started/test/performance/browsing_test.rb
@@ -3,7 +3,7 @@ require 'rails/performance_test_help'
class BrowsingTest < ActionDispatch::PerformanceTest
# Refer to the documentation for all available options
- # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
+ # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory],
# :output => 'tmp/performance', :formats => [:flat] }
def test_homepage
diff --git a/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb b/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb
index 3fea27b916..2a849b7f2b 100644
--- a/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb
+++ b/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb
@@ -3,7 +3,7 @@ require 'rails/performance_test_help'
class BrowsingTest < ActionDispatch::PerformanceTest
# Refer to the documentation for all available options
- # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
+ # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory],
# :output => 'tmp/performance', :formats => [:flat] }
def test_homepage
--
cgit v1.2.3
From 219342b642bb3e965147364fabe6a02a8edea559 Mon Sep 17 00:00:00 2001
From: Vasiliy Ermolovich
Date: Sat, 12 May 2012 13:31:30 +0300
Subject: remove docs related to ruby 1.8 from Array#wrap
---
activesupport/lib/active_support/core_ext/array/wrap.rb | 3 ---
1 file changed, 3 deletions(-)
diff --git a/activesupport/lib/active_support/core_ext/array/wrap.rb b/activesupport/lib/active_support/core_ext/array/wrap.rb
index 4834eca8b1..9ea93d7226 100644
--- a/activesupport/lib/active_support/core_ext/array/wrap.rb
+++ b/activesupport/lib/active_support/core_ext/array/wrap.rb
@@ -25,9 +25,6 @@ class Array
# Array(:foo => :bar) # => [[:foo, :bar]]
# Array.wrap(:foo => :bar) # => [{:foo => :bar}]
#
- # Array("foo\nbar") # => ["foo\n", "bar"], in Ruby 1.8
- # Array.wrap("foo\nbar") # => ["foo\nbar"]
- #
# There's also a related idiom that uses the splat operator:
#
# [*object]
--
cgit v1.2.3
From 39eff2d62d76933c9b552d19dc81d9d1194353c3 Mon Sep 17 00:00:00 2001
From: angelo giovanni capilleri
Date: Sat, 12 May 2012 12:37:16 +0200
Subject: mispelling error in actionpach changelog
---
actionpack/CHANGELOG.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index f25e853e84..24cbe35acc 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -5780,7 +5780,7 @@
== Rendering a collection of partials
The example of partial use describes a familar pattern where a template needs
- to iterate over a array and render a sub template for each of the elements.
+ to iterate over an array and render a sub template for each of the elements.
This pattern has been implemented as a single method that accepts an array and
renders a partial by the same name of as the elements contained within. So the
three-lined example in "Using partials" can be rewritten with a single line:
--
cgit v1.2.3
From b8f394f4a381e0b4cefd289df7cf7281bf0f79e9 Mon Sep 17 00:00:00 2001
From: Vasiliy Ermolovich
Date: Sat, 12 May 2012 14:07:21 +0300
Subject: Object#try can't call private methods
---
activesupport/CHANGELOG.md | 2 ++
activesupport/lib/active_support/core_ext/object/try.rb | 4 ++--
activesupport/test/core_ext/object_and_class_ext_test.rb | 14 +++++++++++++-
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index ef96df9227..fe322b4865 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,5 +1,7 @@
## Rails 4.0.0 (unreleased) ##
+* `Object#try` can't call private methods . *Vasiliy Ermolovich*
+
* `AS::Callbacks#run_callbacks` remove `key` argument. *Francesco Rodriguez*
* `deep_dup` works more expectedly now and duplicates also values in +Hash+ instances and elements in +Array+ instances. *Alexey Gaziev*
diff --git a/activesupport/lib/active_support/core_ext/object/try.rb b/activesupport/lib/active_support/core_ext/object/try.rb
index e77a9da0ec..40a8101ca3 100644
--- a/activesupport/lib/active_support/core_ext/object/try.rb
+++ b/activesupport/lib/active_support/core_ext/object/try.rb
@@ -1,5 +1,5 @@
class Object
- # Invokes the method identified by the symbol +method+, passing it any arguments
+ # Invokes the public method identified by the symbol +method+, passing it any arguments
# and/or the block specified, just like the regular Ruby Object#send does.
#
# *Unlike* that method however, a +NoMethodError+ exception will *not* be raised
@@ -29,7 +29,7 @@ class Object
if a.empty? && block_given?
yield self
else
- __send__(*a, &b)
+ public_send(*a, &b)
end
end
end
diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb
index b027fccab3..98ab82609e 100644
--- a/activesupport/test/core_ext/object_and_class_ext_test.rb
+++ b/activesupport/test/core_ext/object_and_class_ext_test.rb
@@ -101,7 +101,7 @@ class ObjectTryTest < ActiveSupport::TestCase
assert !@string.respond_to?(method)
assert_raise(NoMethodError) { @string.try(method) }
end
-
+
def test_nonexisting_method_with_arguments
method = :undefined_method
assert !@string.respond_to?(method)
@@ -138,4 +138,16 @@ class ObjectTryTest < ActiveSupport::TestCase
nil.try { ran = true }
assert_equal false, ran
end
+
+ def test_try_with_private_method
+ klass = Class.new do
+ private
+
+ def private_method
+ 'private method'
+ end
+ end
+
+ assert_raise(NoMethodError) { klass.new.try(:private_method) }
+ end
end
--
cgit v1.2.3
From 47570d4f1ff18c3a59bc100a1886a08c59c1e14b Mon Sep 17 00:00:00 2001
From: angelo giovanni capilleri
Date: Sat, 12 May 2012 13:12:15 +0200
Subject: mispelling errors in render_text_test.rb and sqlite_specific_schema
---
actionpack/test/controller/new_base/render_text_test.rb | 4 ++--
activerecord/test/schema/sqlite_specific_schema.rb | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/actionpack/test/controller/new_base/render_text_test.rb b/actionpack/test/controller/new_base/render_text_test.rb
index e0b38b29fa..f8d02e8b6c 100644
--- a/actionpack/test/controller/new_base/render_text_test.rb
+++ b/actionpack/test/controller/new_base/render_text_test.rb
@@ -65,7 +65,7 @@ module RenderText
class RenderTextTest < Rack::TestCase
describe "Rendering text using render :text"
- test "rendering text from a action with default options renders the text with the layout" do
+ test "rendering text from an action with default options renders the text with the layout" do
with_routing do |set|
set.draw { get ':controller', :action => 'index' }
@@ -75,7 +75,7 @@ module RenderText
end
end
- test "rendering text from a action with default options renders the text without the layout" do
+ test "rendering text from an action with default options renders the text without the layout" do
with_routing do |set|
set.draw { get ':controller', :action => 'index' }
diff --git a/activerecord/test/schema/sqlite_specific_schema.rb b/activerecord/test/schema/sqlite_specific_schema.rb
index ea05b35fe0..e9ddeb32cf 100644
--- a/activerecord/test/schema/sqlite_specific_schema.rb
+++ b/activerecord/test/schema/sqlite_specific_schema.rb
@@ -1,5 +1,5 @@
ActiveRecord::Schema.define do
- # For sqlite 3.1.0+, make a table with a autoincrement column
+ # For sqlite 3.1.0+, make a table with an autoincrement column
if supports_autoincrement?
create_table :table_with_autoincrement, :force => true do |t|
t.column :name, :string
--
cgit v1.2.3
From 3a59eab5f78f4c11915eba150c88ce384d046dff Mon Sep 17 00:00:00 2001
From: Santiago Pastorino
Date: Sat, 12 May 2012 09:18:37 -0300
Subject: Remove wrong rack/utils dependency from AS
Closes #6274
---
activesupport/lib/active_support/cache/file_store.rb | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb
index e7316b23b3..89bdb741d0 100644
--- a/activesupport/lib/active_support/cache/file_store.rb
+++ b/activesupport/lib/active_support/cache/file_store.rb
@@ -1,7 +1,7 @@
require 'active_support/core_ext/file/atomic'
require 'active_support/core_ext/string/conversions'
require 'active_support/core_ext/object/inclusion'
-require 'rack/utils'
+require 'uri/common'
module ActiveSupport
module Cache
@@ -126,7 +126,7 @@ module ActiveSupport
# Translate a key into a file path.
def key_file_path(key)
- fname = Rack::Utils.escape(key)
+ fname = URI.encode_www_form_component(key)
hash = Zlib.adler32(fname)
hash, dir_1 = hash.divmod(0x1000)
dir_2 = hash.modulo(0x1000)
@@ -144,7 +144,7 @@ module ActiveSupport
# Translate a file path into a key.
def file_path_key(path)
fname = path[cache_path.to_s.size..-1].split(File::SEPARATOR, 4).last
- Rack::Utils.unescape(fname)
+ URI.decode_www_form_component(fname, Encoding::UTF_8)
end
# Delete empty directories in the cache.
--
cgit v1.2.3
From d897255f8a25c72aa72f14d2f82cb87058447fac Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 12 May 2012 18:07:10 +0530
Subject: copy editing [ci skip]
---
guides/source/engines.textile | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/guides/source/engines.textile b/guides/source/engines.textile
index b94ede44c4..880be57fb5 100644
--- a/guides/source/engines.textile
+++ b/guides/source/engines.textile
@@ -548,16 +548,16 @@ Now instead of the ugly Ruby object output the author's name will be displayed.
h5. Using a controller provided by the application
-Because Rails controllers generally share code for for things like authentication and accessing session variables, by default they inherit from ApplicationController. Rails engines, however are scoped to run independently from the main application, so each engine gets a scoped ApplicationController. This namespace prevents code collisions, but often engine controllers should access methods in the main application's ApplicationController. An easy way to provide this acess is to change the engine's scoped ApplicationController to inherit from the main application's ApplicationController. For our Blorgh engine this would be done by changing +app/controllers/blorgh/application_controller.rb+ to look like:
+Because Rails controllers generally share code for things like authentication and accessing session variables, by default they inherit from ApplicationController. Rails engines, however are scoped to run independently from the main application, so each engine gets a scoped +ApplicationController+. This namespace prevents code collisions, but often engine controllers should access methods in the main application's +ApplicationController+. An easy way to provide this access is to change the engine's scoped +ApplicationController+ to inherit from the main application's +ApplicationController+. For our Blorgh engine this would be done by changing +app/controllers/blorgh/application_controller.rb+ to look like:
- class Blorgh::ApplicationController < ApplicationController
- end
+class Blorgh::ApplicationController < ApplicationController
+end
-By default, the engine's controllers inherit from Blorgh::ApplicationController. So, after making this change they will have access to the main applications ApplicationController as though they were part of the main application.
+By default, the engine's controllers inherit from Blorgh::ApplicationController. So, after making this change they will have access to the main applications +ApplicationController+ as though they were part of the main application.
-This change does require that the engine is run from a Rails application that has an ApplicationController.
+This change does require that the engine is run from a Rails application that has an +ApplicationController+.
h4. Configuring an engine
--
cgit v1.2.3
From f2af26dc817281b39a11d1f7131824dfbd4f7a76 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 12 May 2012 18:07:26 +0530
Subject: fix incorrect example [ci skip]
---
activesupport/lib/active_support/core_ext/integer/multiple.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/activesupport/lib/active_support/core_ext/integer/multiple.rb b/activesupport/lib/active_support/core_ext/integer/multiple.rb
index 907a0df723..7c6c2f1ca7 100644
--- a/activesupport/lib/active_support/core_ext/integer/multiple.rb
+++ b/activesupport/lib/active_support/core_ext/integer/multiple.rb
@@ -2,7 +2,7 @@ class Integer
# Check whether the integer is evenly divisible by the argument.
#
# 0.multiple_of?(0) #=> true
- # 5.multiple_of?(5) #=> false
+ # 6.multiple_of?(5) #=> false
# 10.multiple_of?(2) #=> true
def multiple_of?(number)
number != 0 ? self % number == 0 : zero?
--
cgit v1.2.3
From 84d198b4a0846ae74ff49001adaa7c3c80bc0607 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 12 May 2012 18:10:08 +0530
Subject: copy edits [ci skip]
---
activerecord/lib/active_record/core.rb | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index f376cd034a..2bf9cb304e 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -209,9 +209,7 @@ module ActiveRecord
# :method: clone
# Identical to Ruby's clone method. This is a "shallow" copy. Be warned that your attributes are not copied.
# That means that modifying attributes of the clone will modify the original, since they will both point to the
- # same attributes hash. If you need a copy of your attributes hash, please use the #dup method.
- #
- # Example:
+ # same attributes hash. If you need a copy of your attributes hash, please use the #dup method.
#
# user = User.first
# new_user = user.clone
@@ -222,7 +220,6 @@ module ActiveRecord
# user.object_id == new_user.object_id # => false
# user.name.object_id == new_user.name.object_id # => true
#
- # Use #dup instead, for a copy of the attributes hash.
# user.name.object_id == user.dup.name.object_id # => false
##
--
cgit v1.2.3
From eab0520e132e373618f6e3ce585ebd71ec501e97 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Sat, 12 May 2012 14:42:35 +0200
Subject: Revert "Merge pull request #6142 from spartan-developer/master"
This reverts commit 667d0bdd90ef6e6b691f0cc4cf5535b8da69f248, reversing
changes made to 4ae6bab6bb02c9390188a49f9a749400f6a0ac94.
---
actionpack/lib/action_view/helpers/asset_tag_helper.rb | 8 ++++++--
actionpack/lib/action_view/helpers/form_tag_helper.rb | 4 +++-
actionpack/lib/action_view/helpers/tag_helper.rb | 6 ------
actionpack/lib/action_view/helpers/tags/text_area.rb | 4 +++-
4 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index 5f1f08d19c..adc62ec6a9 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -393,7 +393,9 @@ module ActionView
options[:alt] = options.fetch(:alt){ image_alt(src) }
end
- extract_size!(options, :width, :height)
+ if size = options.delete(:size)
+ options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
+ end
if mouseover = options.delete(:mouseover)
options[:onmouseover] = "this.src='#{path_to_image(mouseover)}'"
@@ -446,7 +448,9 @@ module ActionView
multiple_sources_tag('video', sources) do |options|
options[:poster] = path_to_image(options[:poster]) if options[:poster]
- extract_size!(options, :width, :height)
+ if size = options.delete(:size)
+ options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
+ end
end
end
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index 7cdb09d7d2..248cc2f6a3 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -317,7 +317,9 @@ module ActionView
def text_area_tag(name, content = nil, options = {})
options = options.stringify_keys
- extract_size!(options, 'cols', 'rows')
+ if size = options.delete("size")
+ options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split)
+ end
escape = options.delete("escape") { true }
content = ERB::Util.html_escape(content) if escape
diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb
index 1eeff38ab8..f7afa48256 100644
--- a/actionpack/lib/action_view/helpers/tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/tag_helper.rb
@@ -137,12 +137,6 @@ module ActionView
"<#{name}#{tag_options}>#{PRE_CONTENT_STRINGS[name.to_sym]}#{content}#{name}>".html_safe
end
- def extract_size!(options, x_attribute, y_attribute)
- if size = options.delete(:size)
- options[x_attribute], options[y_attribute] = size.split("x") if size =~ %r{^\d+x\d+$}
- end
- end
-
def tag_options(options, escape = true)
return if options.blank?
attrs = []
diff --git a/actionpack/lib/action_view/helpers/tags/text_area.rb b/actionpack/lib/action_view/helpers/tags/text_area.rb
index 160f020263..f74652c5e7 100644
--- a/actionpack/lib/action_view/helpers/tags/text_area.rb
+++ b/actionpack/lib/action_view/helpers/tags/text_area.rb
@@ -6,7 +6,9 @@ module ActionView
options = @options.stringify_keys
add_default_name_and_id(options)
- extract_size!(options, 'cols', 'rows')
+ if size = options.delete("size")
+ options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split)
+ end
content_tag("textarea", options.delete('value') || value_before_type_cast(object), options)
end
--
cgit v1.2.3
From f2f6534272b7895aa39183890043bc8c8e0ee1e8 Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Sat, 12 May 2012 19:08:19 +0530
Subject: s/wether/whether [ci skip]
---
activerecord/lib/active_record/core.rb | 2 +-
railties/lib/rails/generators/rails/app/templates/config/application.rb | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index a869ed8c04..ff2b0b5576 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -77,7 +77,7 @@ module ActiveRecord
##
# :singleton-method:
- # Specifies wether or not has_many or has_one association option
+ # Specifies whether or not has_many or has_one association option
# :dependent => :restrict raises an exception. If set to true, the
# ActiveRecord::DeleteRestrictionError exception will be raised
# along with a DEPRECATION WARNING. If set to false, an error would
diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb
index daa04c144e..6991b5a5f8 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/application.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -58,7 +58,7 @@ module <%= app_const_base %>
# parameters by using an attr_accessible or attr_protected declaration.
<%= comment_if :skip_active_record %>config.active_record.whitelist_attributes = true
- # Specifies wether or not has_many or has_one association option :dependent => :restrict raises
+ # Specifies whether or not has_many or has_one association option :dependent => :restrict raises
# an exception. If set to true, then an ActiveRecord::DeleteRestrictionError exception would be
# raised. If set to false, then an error will be added on the model instead.
<%= comment_if :skip_active_record %>config.active_record.dependent_restrict_raises = false
--
cgit v1.2.3
From 26e2c082595ecca360954cfc20ecc52221748f7b Mon Sep 17 00:00:00 2001
From: Richard Hulse
Date: Sun, 13 May 2012 14:16:50 +1200
Subject: [guides] add local precompilation section
---
guides/source/asset_pipeline.textile | 37 +++++++++++++++++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)
diff --git a/guides/source/asset_pipeline.textile b/guides/source/asset_pipeline.textile
index 010154f1d1..59f106acb2 100644
--- a/guides/source/asset_pipeline.textile
+++ b/guides/source/asset_pipeline.textile
@@ -396,7 +396,7 @@ Rails comes bundled with a rake task to compile the asset manifests and other fi
Compiled assets are written to the location specified in +config.assets.prefix+. By default, this is the +public/assets+ directory.
-You can call this task on the server during deployment to create compiled versions of your assets directly on the server. If you do not have write access to your production file system, you can call this task locally and then deploy the compiled assets.
+You can call this task on the server during deployment to create compiled versions of your assets directly on the server. See the next section for information on compiling locally.
The rake task is:
@@ -516,6 +516,41 @@ If you're compiling nginx with Phusion Passenger you'll need to pass that option
A robust configuration for Apache is possible but tricky; please Google around. (Or help update this Guide if you have a good example configuration for Apache.)
+h4. Local Precompilation
+
+There are several reasons why you might precompile your assets locally. Among them are:
+
+* You may not have write access to your production file system.
+* You may be deploying to more than one server, and want to avoid the duplication of work.
+* You may be doing frequent deploys that do not include asset changes.
+
+Local compilation allows you to commit the compiled files into source control, and deploy as normal.
+
+There are two caveats:
+
+* You must not run the Capistrano deployment task.
+* You must change the following two application configuration settings.
+
+In development.rb place the following line:
+
+
+config.assets.prefix = "/dev-assets"
+
+
+You will also need this in application.rb:
+
+
+config.assets.initialize_on_precompile = false
+
+
+The +prefix+ change makes rails use a different URL for serving assets in development mode, and so pass all requests to Sprockets. Production is still set to +/assets+. Without this changes the application would serve the precompiled assets in development, and you would not see any local changes until you next compiled assets.
+
+The +initialize_on_precompile+ change tell the precompile task to run without invoking Rails.
+
+You will also need to ensure that any compressors or minifers are available on you development system.
+
+In practice, this will allow you to precompile locally, have those files in your working tree, and commit those files to source control when needed. Development mode will work as expected.
+
h4. Live Compilation
In some circumstances you may wish to use live compilation. In this mode all requests for assets in the pipeline are handled by Sprockets directly.
--
cgit v1.2.3
From a7e0b2f843c4a6fdfe08a45c09d2ff44bcfe994e Mon Sep 17 00:00:00 2001
From: Vasiliy Ermolovich
Date: Sun, 13 May 2012 14:25:41 +0300
Subject: update docs on Object#try
---
activesupport/lib/active_support/core_ext/object/try.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/activesupport/lib/active_support/core_ext/object/try.rb b/activesupport/lib/active_support/core_ext/object/try.rb
index 40a8101ca3..3e63b1e82a 100644
--- a/activesupport/lib/active_support/core_ext/object/try.rb
+++ b/activesupport/lib/active_support/core_ext/object/try.rb
@@ -24,7 +24,7 @@ class Object
# Without a method argument try will yield to the block unless the receiver is nil.
# @person.try { |p| "#{p.first_name} #{p.last_name}" }
#--
- # +try+ behaves like +Object#send+, unless called on +NilClass+.
+ # +try+ behaves like +Object#public_send+, unless called on +NilClass+.
def try(*a, &b)
if a.empty? && block_given?
yield self
--
cgit v1.2.3
From 88fc7495b9aa0facd3363ace4871118a0905d6c2 Mon Sep 17 00:00:00 2001
From: Oscar Del Ben
Date: Sun, 13 May 2012 08:21:06 -0700
Subject: Update docs to public_send for Object#try
---
activesupport/lib/active_support/core_ext/object/try.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/activesupport/lib/active_support/core_ext/object/try.rb b/activesupport/lib/active_support/core_ext/object/try.rb
index 3e63b1e82a..48eb546a7d 100644
--- a/activesupport/lib/active_support/core_ext/object/try.rb
+++ b/activesupport/lib/active_support/core_ext/object/try.rb
@@ -1,6 +1,6 @@
class Object
# Invokes the public method identified by the symbol +method+, passing it any arguments
- # and/or the block specified, just like the regular Ruby Object#send does.
+ # and/or the block specified, just like the regular Ruby Object#public_send does.
#
# *Unlike* that method however, a +NoMethodError+ exception will *not* be raised
# and +nil+ will be returned instead, if the receiving object is a +nil+ object or NilClass.
--
cgit v1.2.3
From 873ac28660b6cec15064a4d321e121f68e54ee06 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Sun, 13 May 2012 12:22:43 -0500
Subject: adding examples to Hash#deep_merge method
---
activesupport/lib/active_support/core_ext/hash/deep_merge.rb | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/activesupport/lib/active_support/core_ext/hash/deep_merge.rb b/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
index af771c86ff..2fa397bcd0 100644
--- a/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
+++ b/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
@@ -1,11 +1,16 @@
class Hash
# Returns a new hash with +self+ and +other_hash+ merged recursively.
+ #
+ # h1 = {x: {y: [4,5,6]}, z: [7,8,9]}
+ # h2 = {x: {y: [7,8,9]}, z: "xyz"}
+ #
+ # h1.deep_merge(h2) #=> {:x => {:y => [7, 8, 9]}, :z => "xyz"}
+ # h2.deep_merge(h1) #=> {:x => {:y => [4, 5, 6]}, :z => [7, 8, 9]}
def deep_merge(other_hash)
dup.deep_merge!(other_hash)
end
- # Returns a new hash with +self+ and +other_hash+ merged recursively.
- # Modifies the receiver in place.
+ # Same as +deep_merge+, but modifies +self+
def deep_merge!(other_hash)
other_hash.each_pair do |k,v|
tv = self[k]
--
cgit v1.2.3
From cb61f57a02488c92e1dc8cc8e8fa52ed5f249955 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Sun, 13 May 2012 12:44:17 -0500
Subject: added example to Hash#stringify_keys
---
activesupport/lib/active_support/core_ext/hash/keys.rb | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb
index 230a84dabc..f72582571f 100644
--- a/activesupport/lib/active_support/core_ext/hash/keys.rb
+++ b/activesupport/lib/active_support/core_ext/hash/keys.rb
@@ -1,5 +1,8 @@
class Hash
# Return a new hash with all keys converted to strings.
+ #
+ # { :name => 'Rob', :years => '28' }.stringify_keys
+ # #=> { "name" => "Rob", "years" => "28" }
def stringify_keys
result = {}
keys.each do |key|
@@ -8,7 +11,8 @@ class Hash
result
end
- # Destructively convert all keys to strings.
+ # Destructively convert all keys to strings. Same as
+ # +stringify_keys+, but modifies +self+.
def stringify_keys!
keys.each do |key|
self[key.to_s] = delete(key)
--
cgit v1.2.3
From 817f9e64ee4e5b02efd9b4047c23340bf4b75586 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Sun, 13 May 2012 12:45:25 -0500
Subject: unnecessary 'examples' noise in Hash#assert_valid_keys docs
---
activesupport/lib/active_support/core_ext/hash/keys.rb | 1 -
1 file changed, 1 deletion(-)
diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb
index f72582571f..057fff05e3 100644
--- a/activesupport/lib/active_support/core_ext/hash/keys.rb
+++ b/activesupport/lib/active_support/core_ext/hash/keys.rb
@@ -45,7 +45,6 @@ class Hash
# Note that keys are NOT treated indifferently, meaning if you use strings for keys but assert symbols
# as keys, this will fail.
#
- # ==== Examples
# { :name => 'Rob', :years => '28' }.assert_valid_keys(:name, :age) # => raises "ArgumentError: Unknown key: years"
# { :name => 'Rob', :age => '28' }.assert_valid_keys('name', 'age') # => raises "ArgumentError: Unknown key: name"
# { :name => 'Rob', :age => '28' }.assert_valid_keys(:name, :age) # => passes, raises nothing
--
cgit v1.2.3
From 92dbdb2340839f5d21b467eb68675f597fa3a588 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Sun, 13 May 2012 12:49:15 -0500
Subject: added example to Hash#symbolize_keys
---
activesupport/lib/active_support/core_ext/hash/keys.rb | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb
index 057fff05e3..81ee71d5fb 100644
--- a/activesupport/lib/active_support/core_ext/hash/keys.rb
+++ b/activesupport/lib/active_support/core_ext/hash/keys.rb
@@ -1,7 +1,7 @@
class Hash
# Return a new hash with all keys converted to strings.
#
- # { :name => 'Rob', :years => '28' }.stringify_keys
+ # { name: 'Rob', years: '28' }.stringify_keys
# #=> { "name" => "Rob", "years" => "28" }
def stringify_keys
result = {}
@@ -22,6 +22,9 @@ class Hash
# Return a new hash with all keys converted to symbols, as long as
# they respond to +to_sym+.
+ #
+ # { 'name' => 'Rob', 'years' => '28' }.symbolize_keys
+ # #=> { :name => "Rob", :years => "28" }
def symbolize_keys
result = {}
keys.each do |key|
@@ -32,7 +35,7 @@ class Hash
alias_method :to_options, :symbolize_keys
# Destructively convert all keys to symbols, as long as they respond
- # to +to_sym+.
+ # to +to_sym+. Same as +symbolize_keys+, but modifies self.
def symbolize_keys!
keys.each do |key|
self[(key.to_sym rescue key)] = delete(key)
--
cgit v1.2.3
From 16301cce760ad98c6dc07c53f67c990fd5d684b4 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Sun, 13 May 2012 12:52:54 -0500
Subject: marking self in Hash#symbolize_keys!
---
activesupport/lib/active_support/core_ext/hash/keys.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb
index 81ee71d5fb..e0aa352818 100644
--- a/activesupport/lib/active_support/core_ext/hash/keys.rb
+++ b/activesupport/lib/active_support/core_ext/hash/keys.rb
@@ -35,7 +35,7 @@ class Hash
alias_method :to_options, :symbolize_keys
# Destructively convert all keys to symbols, as long as they respond
- # to +to_sym+. Same as +symbolize_keys+, but modifies self.
+ # to +to_sym+. Same as +symbolize_keys+, but modifies +self+.
def symbolize_keys!
keys.each do |key|
self[(key.to_sym rescue key)] = delete(key)
--
cgit v1.2.3
From e6e6f4ef8675ea001801362b42cdabb13801da67 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 14 May 2012 06:52:50 +1000
Subject: Briefly explain static file routing in the getting started guide
---
guides/source/getting_started.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile
index 1e9bd1f144..bdd385918f 100644
--- a/guides/source/getting_started.textile
+++ b/guides/source/getting_started.textile
@@ -193,7 +193,7 @@ Now that we have made the controller and view, we need to tell Rails when we wan
To fix this, delete the +index.html+ file located inside the +public+ directory of the application.
-You need to do this because Rails will serve any static file in the +public+ directory that matches a route in preference to any dynamic content you generate from the controllers.
+You need to do this because Rails will serve any static file in the +public+ directory that matches a route in preference to any dynamic content you generate from the controllers. The +index.html+ file is special: it will be served if a request comes in at the root route, e.g. http://localhost:3000. If another request such as http://localhost:3000/welcome happened, a static file at public/welcome.html would be served first, but only if it existed.
Next, you have to tell Rails where your actual home page is located.
--
cgit v1.2.3
From 9e4fd33ae8860388cff54af44ee07f19a09ba9f6 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 14 May 2012 06:54:40 +1000
Subject: Re-enforce/re-explain what happens when you go to root route
(Welcome#index) better
---
guides/source/getting_started.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile
index bdd385918f..a689cf1c3b 100644
--- a/guides/source/getting_started.textile
+++ b/guides/source/getting_started.textile
@@ -210,7 +210,7 @@ Blog::Application.routes.draw do
The +root :to => "welcome#index"+ tells Rails to map requests to the root of the application 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":http://localhost:3000 in your browser, you'll see +Hello, Rails!+.
+If you navigate to "http://localhost:3000":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.
NOTE. For more information about routing, refer to "Rails Routing from the Outside In":routing.html.
--
cgit v1.2.3
From 96fb77fe8000569ccc6b5bfd91668719bf92fa3d Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 14 May 2012 06:55:45 +1000
Subject: Separate CR out in CRUD explanation, explain each letter one at a
time
---
guides/source/getting_started.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile
index a689cf1c3b..540084eb15 100644
--- a/guides/source/getting_started.textile
+++ b/guides/source/getting_started.textile
@@ -220,7 +220,7 @@ Now that you've seen how to create a controller, an action and a view, let's cre
In the Blog application, you will now create a new _resource_. A resource is the term used for a collection of similar objects, such as posts, people or animals. You can create, read, update and destroy items for a resource and these operations are referred to as _CRUD_ operations.
-In the next section, you will add the ability to create new posts in your application and be able to view them. This is the "CR" from CRUD. The form for doing this will look like this:
+In the next section, you will add the ability to create new posts in your application and be able to view them. This is the "C" and the "R" from CRUD: creation and reading. The form for doing this will look like this:
!images/getting_started/new_post.png(The new post form)!
--
cgit v1.2.3
From dbd131fc0e9394438eb0e76796c89160a924b7ef Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 14 May 2012 06:56:43 +1000
Subject: Rails actually has one root route defined
---
guides/source/getting_started.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile
index 540084eb15..3a5868b13e 100644
--- a/guides/source/getting_started.textile
+++ b/guides/source/getting_started.textile
@@ -232,7 +232,7 @@ The first thing that you are going to need to create a new post within the appli
!images/getting_started/routing_error_no_route_matches.png(A routing error, no route matches /posts/new)!
-This is because there is nowhere inside the routes for the application -- defined inside +config/routes.rb+ -- that defines this route. By default, Rails has no routes configured at all, and so you must define your routes as you need them.
+This is because there is nowhere inside the routes for the application -- defined inside +config/routes.rb+ -- that defines this route. By default, Rails has no routes configured at all, besides the root route you defined earlier, and so you must define your routes as you need them.
To do this, you're going to need to create a route inside +config/routes.rb+ file, on a new line between the +do+ and the +end+ for the +draw+ method:
--
cgit v1.2.3
From 5f7caff82572daa2adc9a83f280b58572b3ba3e2 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 14 May 2012 07:02:58 +1000
Subject: Wrap 'Missing template posts/new' error message in a blockquote for
better formatting
---
guides/source/getting_started.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile
index 3a5868b13e..6a07f87abd 100644
--- a/guides/source/getting_started.textile
+++ b/guides/source/getting_started.textile
@@ -282,9 +282,9 @@ You're getting this error now because Rails expects plain actions like this one
In the above image, the bottom line has been truncated. Let's see what the full thing looks like:
-
+
+
That's quite a lot of text! Let's quickly go through and understand what each part of it does.
--
cgit v1.2.3
From d4801d0229515aae37d8f7a2f72c83990d2d977b Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 14 May 2012 07:06:41 +1000
Subject: Correct code wrapping around content of welcome/index.html.erb
---
guides/source/getting_started.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile
index 6a07f87abd..84c438e607 100644
--- a/guides/source/getting_started.textile
+++ b/guides/source/getting_started.textile
@@ -183,9 +183,9 @@ Rails will create several files for you. Most important of these are of course t
Open the +app/views/welcome/index.html.erb+ file in your text editor and edit it to contain a single line of code:
-
+
Hello, Rails!
-
+
h4. Setting the Application Home Page
--
cgit v1.2.3
From 8e4148bf9dd43601609b70ffbc354d80563c86e2 Mon Sep 17 00:00:00 2001
From: Angelo Capilleri
Date: Sun, 13 May 2012 23:11:46 +0200
Subject: mispelling asset_tag_helper
---
actionpack/lib/action_view/helpers/asset_tag_helper.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index adc62ec6a9..ae5420dbd8 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -323,7 +323,7 @@ module ActionView
end
alias_method :path_to_audio, :audio_path # aliased to avoid conflicts with an audio_path named route
- # Computes the full URL to a audio asset in the public audios directory.
+ # Computes the full URL to an audio asset in the public audios directory.
# This will use +audio_path+ internally, so most of their behaviors will be the same.
def audio_url(source)
URI.join(current_host, path_to_audio(source)).to_s
--
cgit v1.2.3
From bbd37753bf59a11a9e9b38a3ac7a94ec2906e188 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Sun, 13 May 2012 19:47:27 -0500
Subject: Fixing Hash#stringify_keys docs
---
activesupport/lib/active_support/core_ext/hash/keys.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb
index e0aa352818..be4d611ce7 100644
--- a/activesupport/lib/active_support/core_ext/hash/keys.rb
+++ b/activesupport/lib/active_support/core_ext/hash/keys.rb
@@ -1,7 +1,7 @@
class Hash
# Return a new hash with all keys converted to strings.
#
- # { name: 'Rob', years: '28' }.stringify_keys
+ # { :name => 'Rob', :years => '28' }.stringify_keys
# #=> { "name" => "Rob", "years" => "28" }
def stringify_keys
result = {}
--
cgit v1.2.3
From fa03e37d31d7c69c90d41f0764c374318d8dced0 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Sun, 13 May 2012 20:26:53 -0500
Subject: removing unnecessary 'examples' noise from activesupport
---
activesupport/lib/active_support/backtrace_cleaner.rb | 6 ------
activesupport/lib/active_support/callbacks.rb | 2 --
.../lib/active_support/core_ext/date/calculations.rb | 2 --
.../lib/active_support/core_ext/date/conversions.rb | 2 --
.../lib/active_support/core_ext/date_time/calculations.rb | 2 --
.../lib/active_support/core_ext/date_time/conversions.rb | 1 -
activesupport/lib/active_support/core_ext/enumerable.rb | 4 ++--
activesupport/lib/active_support/core_ext/hash/diff.rb | 2 --
.../lib/active_support/core_ext/module/aliasing.rb | 2 --
.../lib/active_support/core_ext/range/conversions.rb | 2 --
activesupport/lib/active_support/core_ext/string/inquiry.rb | 2 +-
activesupport/lib/active_support/duration.rb | 1 -
activesupport/lib/active_support/inflector/inflections.rb | 9 +--------
activesupport/lib/active_support/inflector/methods.rb | 13 -------------
activesupport/lib/active_support/inflector/transliterate.rb | 2 --
activesupport/lib/active_support/multibyte.rb | 3 +--
activesupport/lib/active_support/multibyte/chars.rb | 11 -----------
activesupport/lib/active_support/multibyte/unicode.rb | 3 ---
activesupport/lib/active_support/tagged_logging.rb | 2 +-
activesupport/lib/active_support/time_with_zone.rb | 4 ----
activesupport/lib/active_support/values/time_zone.rb | 10 +++++-----
21 files changed, 11 insertions(+), 74 deletions(-)
diff --git a/activesupport/lib/active_support/backtrace_cleaner.rb b/activesupport/lib/active_support/backtrace_cleaner.rb
index e97bb25b9f..7c3a41288b 100644
--- a/activesupport/lib/active_support/backtrace_cleaner.rb
+++ b/activesupport/lib/active_support/backtrace_cleaner.rb
@@ -8,8 +8,6 @@ module ActiveSupport
# instead of the file system root. The typical silencer use case is to exclude the output of a noisy library from the
# backtrace, so that you can focus on the rest.
#
- # ==== Example:
- #
# bc = BacktraceCleaner.new
# bc.add_filter { |line| line.gsub(Rails.root, '') }
# bc.add_silencer { |line| line =~ /mongrel|rubygems/ }
@@ -42,8 +40,6 @@ module ActiveSupport
# Adds a filter from the block provided. Each line in the backtrace will be mapped against this filter.
#
- # Example:
- #
# # Will turn "/my/rails/root/app/models/person.rb" into "/app/models/person.rb"
# backtrace_cleaner.add_filter { |line| line.gsub(Rails.root, '') }
def add_filter(&block)
@@ -53,8 +49,6 @@ module ActiveSupport
# Adds a silencer from the block provided. If the silencer returns true for a given line, it will be excluded from
# the clean backtrace.
#
- # Example:
- #
# # Will reject all lines that include the word "mongrel", like "/gems/mongrel/server.rb" or "/app/my_mongrel_server/rb"
# backtrace_cleaner.add_silencer { |line| line =~ /mongrel/ }
def add_silencer(&block)
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index c6c7e2821b..4e319b4bba 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -23,8 +23,6 @@ module ActiveSupport
# methods, procs or lambdas, or callback objects that respond to certain predetermined
# methods. See +ClassMethods.set_callback+ for details.
#
- # ==== Example
- #
# class Record
# include ActiveSupport::Callbacks
# define_callbacks :save
diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb
index 323126fcfa..3e36c54eba 100644
--- a/activesupport/lib/active_support/core_ext/date/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date/calculations.rb
@@ -107,8 +107,6 @@ class Date
# Returns a new Date where one or more of the elements have been changed according to the +options+ parameter.
#
- # Examples:
- #
# Date.new(2007, 5, 12).change(:day => 1) # => Date.new(2007, 5, 1)
# Date.new(2007, 5, 12).change(:year => 2005, :month => 1) # => Date.new(2005, 1, 12)
def change(options)
diff --git a/activesupport/lib/active_support/core_ext/date/conversions.rb b/activesupport/lib/active_support/core_ext/date/conversions.rb
index 97e3c71992..81f969e786 100644
--- a/activesupport/lib/active_support/core_ext/date/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/date/conversions.rb
@@ -26,7 +26,6 @@ class Date
#
# This method is aliased to to_s.
#
- # ==== Examples
# date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
#
# date.to_formatted_s(:db) # => "2007-11-10"
@@ -69,7 +68,6 @@ class Date
# Converts a Date instance to a Time, where the time is set to the beginning of the day.
# The timezone can be either :local or :utc (default :local).
#
- # ==== Examples
# date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
#
# date.to_time # => Sat Nov 10 00:00:00 0800 2007
diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb
index 020fa1a06d..fd78044b5d 100644
--- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb
@@ -104,8 +104,6 @@ class DateTime
# Adjusts DateTime to UTC by adding its offset value; offset is set to 0
#
- # Example:
- #
# DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-6, 24)) # => Mon, 21 Feb 2005 10:11:12 -0600
# DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-6, 24)).utc # => Mon, 21 Feb 2005 16:11:12 +0000
def utc
diff --git a/activesupport/lib/active_support/core_ext/date_time/conversions.rb b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
index 6338dc6397..19925198c0 100644
--- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
@@ -42,7 +42,6 @@ class DateTime
alias_method :to_default_s, :to_s unless (instance_methods(false) & [:to_s, 'to_s']).empty?
alias_method :to_s, :to_formatted_s
- # Returns the +utc_offset+ as an +HH:MM formatted string. Examples:
#
# datetime = DateTime.civil(2000, 1, 1, 0, 0, 0, Rational(-6, 24))
# datetime.formatted_offset # => "-06:00"
diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb
index b9c632e4f5..02d5a7080f 100644
--- a/activesupport/lib/active_support/core_ext/enumerable.rb
+++ b/activesupport/lib/active_support/core_ext/enumerable.rb
@@ -1,5 +1,5 @@
module Enumerable
- # Calculates a sum from the elements. Examples:
+ # Calculates a sum from the elements.
#
# payments.sum { |p| p.price * p.tax_rate }
# payments.sum(&:price)
@@ -26,7 +26,7 @@ module Enumerable
end
end
- # Convert an enumerable to a hash. Examples:
+ # Convert an enumerable to a hash.
#
# people.index_by(&:login)
# => { "nextangle" => , "chade-" => , ...}
diff --git a/activesupport/lib/active_support/core_ext/hash/diff.rb b/activesupport/lib/active_support/core_ext/hash/diff.rb
index 855dcb38bc..831dee8ecb 100644
--- a/activesupport/lib/active_support/core_ext/hash/diff.rb
+++ b/activesupport/lib/active_support/core_ext/hash/diff.rb
@@ -1,8 +1,6 @@
class Hash
# Returns a hash that represents the difference between two hashes.
#
- # Examples:
- #
# {1 => 2}.diff(1 => 2) # => {}
# {1 => 2}.diff(1 => 3) # => {1 => 2}
# {}.diff(1 => 2) # => {1 => 2}
diff --git a/activesupport/lib/active_support/core_ext/module/aliasing.rb b/activesupport/lib/active_support/core_ext/module/aliasing.rb
index 382156ecd8..580cb80413 100644
--- a/activesupport/lib/active_support/core_ext/module/aliasing.rb
+++ b/activesupport/lib/active_support/core_ext/module/aliasing.rb
@@ -45,8 +45,6 @@ class Module
# Allows you to make aliases for attributes, which includes
# getter, setter, and query methods.
#
- # Example:
- #
# class Content < ActiveRecord::Base
# # has a title attribute
# end
diff --git a/activesupport/lib/active_support/core_ext/range/conversions.rb b/activesupport/lib/active_support/core_ext/range/conversions.rb
index 43134b4314..b1a12781f3 100644
--- a/activesupport/lib/active_support/core_ext/range/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/range/conversions.rb
@@ -5,8 +5,6 @@ class Range
# Gives a human readable format of the range.
#
- # ==== Example
- #
# (1..100).to_formatted_s # => "1..100"
def to_formatted_s(format = :default)
if formatter = RANGE_FORMATS[format]
diff --git a/activesupport/lib/active_support/core_ext/string/inquiry.rb b/activesupport/lib/active_support/core_ext/string/inquiry.rb
index 2562a7cef6..1dcd949536 100644
--- a/activesupport/lib/active_support/core_ext/string/inquiry.rb
+++ b/activesupport/lib/active_support/core_ext/string/inquiry.rb
@@ -2,7 +2,7 @@ require 'active_support/string_inquirer'
class String
# Wraps the current string in the ActiveSupport::StringInquirer class,
- # which gives you a prettier way to test for equality. Example:
+ # which gives you a prettier way to test for equality.
#
# env = 'production'.inquiry
# env.production? # => true
diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb
index 00c67a470d..2cdc991120 100644
--- a/activesupport/lib/active_support/duration.rb
+++ b/activesupport/lib/active_support/duration.rb
@@ -5,7 +5,6 @@ require 'active_support/core_ext/object/acts_like'
module ActiveSupport
# Provides accurate date and time measurements using Date#advance and
# Time#advance, respectively. It mainly supports the methods on Numeric.
- # Example:
#
# 1.month.ago # equivalent to Time.now.advance(:months => -1)
class Duration < BasicObject
diff --git a/activesupport/lib/active_support/inflector/inflections.rb b/activesupport/lib/active_support/inflector/inflections.rb
index 13b23d627a..600e353812 100644
--- a/activesupport/lib/active_support/inflector/inflections.rb
+++ b/activesupport/lib/active_support/inflector/inflections.rb
@@ -3,7 +3,7 @@ require 'active_support/core_ext/array/prepend_and_append'
module ActiveSupport
module Inflector
# A singleton instance of this class is yielded by Inflector.inflections, which can then be used to specify additional
- # inflection rules. Examples:
+ # inflection rules.
#
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1\2en'
@@ -40,7 +40,6 @@ module ActiveSupport
# A camelized string that contains the acronym will maintain the acronym when titleized or humanized, and will
# convert the acronym into a non-delimited single lowercase word when passed to +underscore+.
#
- # Examples:
# acronym 'HTML'
# titleize 'html' #=> 'HTML'
# camelize 'html' #=> 'HTML'
@@ -70,7 +69,6 @@ module ActiveSupport
# `acronym` may be used to specify any word that contains an acronym or otherwise needs to maintain a non-standard
# capitalization. The only restriction is that the word must begin with a capital letter.
#
- # Examples:
# acronym 'RESTful'
# underscore 'RESTful' #=> 'restful'
# underscore 'RESTfulController' #=> 'restful_controller'
@@ -105,7 +103,6 @@ module ActiveSupport
# Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used
# for strings, not regular expressions. You simply pass the irregular in singular and plural form.
#
- # Examples:
# irregular 'octopus', 'octopi'
# irregular 'person', 'people'
def irregular(singular, plural)
@@ -127,7 +124,6 @@ module ActiveSupport
# Add uncountable words that shouldn't be attempted inflected.
#
- # Examples:
# uncountable "money"
# uncountable "money", "information"
# uncountable %w( money information rice )
@@ -139,7 +135,6 @@ module ActiveSupport
# When using a regular expression based replacement, the normal humanize formatting is called after the replacement.
# When a string is used, the human form should be specified as desired (example: 'The name', not 'the_name')
#
- # Examples:
# human /_cnt$/i, '\1_count'
# human "legacy_col_person_name", "Name"
def human(rule, replacement)
@@ -150,7 +145,6 @@ module ActiveSupport
# Give the scope as a symbol of the inflection type, the options are: :plurals,
# :singulars, :uncountables, :humans.
#
- # Examples:
# clear :all
# clear :plurals
def clear(scope = :all)
@@ -166,7 +160,6 @@ module ActiveSupport
# Yields a singleton instance of Inflector::Inflections so you can specify additional
# inflector rules.
#
- # Example:
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.uncountable "rails"
# end
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb
index 4fcd32edf2..48296841aa 100644
--- a/activesupport/lib/active_support/inflector/methods.rb
+++ b/activesupport/lib/active_support/inflector/methods.rb
@@ -16,7 +16,6 @@ module ActiveSupport
# Returns the plural form of the word in the string.
#
- # Examples:
# "post".pluralize # => "posts"
# "octopus".pluralize # => "octopi"
# "sheep".pluralize # => "sheep"
@@ -28,7 +27,6 @@ module ActiveSupport
# The reverse of +pluralize+, returns the singular form of a word in a string.
#
- # Examples:
# "posts".singularize # => "post"
# "octopi".singularize # => "octopus"
# "sheep".singularize # => "sheep"
@@ -43,7 +41,6 @@ module ActiveSupport
#
# +camelize+ will also convert '/' to '::' which is useful for converting paths to namespaces.
#
- # Examples:
# "active_model".camelize # => "ActiveModel"
# "active_model".camelize(:lower) # => "activeModel"
# "active_model/errors".camelize # => "ActiveModel::Errors"
@@ -67,7 +64,6 @@ module ActiveSupport
#
# Changes '::' to '/' to convert namespaces to paths.
#
- # Examples:
# "ActiveModel".underscore # => "active_model"
# "ActiveModel::Errors".underscore # => "active_model/errors"
#
@@ -89,7 +85,6 @@ module ActiveSupport
# Capitalizes the first word and turns underscores into spaces and strips a
# trailing "_id", if any. Like +titleize+, this is meant for creating pretty output.
#
- # Examples:
# "employee_salary" # => "Employee salary"
# "author_id" # => "Author"
def humanize(lower_case_and_underscored_word)
@@ -108,7 +103,6 @@ module ActiveSupport
#
# +titleize+ is also aliased as +titlecase+.
#
- # Examples:
# "man from the boondocks".titleize # => "Man From The Boondocks"
# "x-men: the last stand".titleize # => "X Men: The Last Stand"
# "TheManWithoutAPast".titleize # => "The Man Without A Past"
@@ -120,7 +114,6 @@ module ActiveSupport
# Create the name of a table like Rails does for models to table names. This method
# uses the +pluralize+ method on the last word in the string.
#
- # Examples
# "RawScaledScorer".tableize # => "raw_scaled_scorers"
# "egg_and_ham".tableize # => "egg_and_hams"
# "fancyCategory".tableize # => "fancy_categories"
@@ -132,7 +125,6 @@ module ActiveSupport
# Note that this returns a string and not a Class. (To convert to an actual class
# follow +classify+ with +constantize+.)
#
- # Examples:
# "egg_and_hams".classify # => "EggAndHam"
# "posts".classify # => "Post"
#
@@ -145,7 +137,6 @@ module ActiveSupport
# Replaces underscores with dashes in the string.
#
- # Example:
# "puni_puni".dasherize # => "puni-puni"
def dasherize(underscored_word)
underscored_word.tr('_', '-')
@@ -183,7 +174,6 @@ module ActiveSupport
# +separate_class_name_and_id_with_underscore+ sets whether
# the method should put '_' between the name and 'id'.
#
- # Examples:
# "Message".foreign_key # => "message_id"
# "Message".foreign_key(false) # => "messageid"
# "Admin::Post".foreign_key # => "post_id"
@@ -253,7 +243,6 @@ module ActiveSupport
# Returns the suffix that should be added to a number to denote the position
# in an ordered sequence such as 1st, 2nd, 3rd, 4th.
#
- # Examples:
# ordinal(1) # => "st"
# ordinal(2) # => "nd"
# ordinal(1002) # => "nd"
@@ -276,7 +265,6 @@ module ActiveSupport
# Turns a number into an ordinal string used to denote the position in an
# ordered sequence such as 1st, 2nd, 3rd, 4th.
#
- # Examples:
# ordinalize(1) # => "1st"
# ordinalize(2) # => "2nd"
# ordinalize(1002) # => "1002nd"
@@ -302,7 +290,6 @@ module ActiveSupport
# Applies inflection rules for +singularize+ and +pluralize+.
#
- # Examples:
# apply_inflections("post", inflections.plurals) # => "posts"
# apply_inflections("posts", inflections.singulars) # => "post"
def apply_inflections(word, rules)
diff --git a/activesupport/lib/active_support/inflector/transliterate.rb b/activesupport/lib/active_support/inflector/transliterate.rb
index 40e7a0e389..a372b6d1f7 100644
--- a/activesupport/lib/active_support/inflector/transliterate.rb
+++ b/activesupport/lib/active_support/inflector/transliterate.rb
@@ -66,8 +66,6 @@ module ActiveSupport
# Replaces special characters in a string so that it may be used as part of a 'pretty' URL.
#
- # ==== Examples
- #
# class Person
# def to_param
# "#{id}-#{name.parameterize}"
diff --git a/activesupport/lib/active_support/multibyte.rb b/activesupport/lib/active_support/multibyte.rb
index 5efe13c537..977fe95dbe 100644
--- a/activesupport/lib/active_support/multibyte.rb
+++ b/activesupport/lib/active_support/multibyte.rb
@@ -7,7 +7,6 @@ module ActiveSupport #:nodoc:
# class so you can support other encodings. See the ActiveSupport::Multibyte::Chars implementation for
# an example how to do this.
#
- # Example:
# ActiveSupport::Multibyte.proxy_class = CharsForUTF32
def self.proxy_class=(klass)
@proxy_class = klass
@@ -18,4 +17,4 @@ module ActiveSupport #:nodoc:
@proxy_class ||= ActiveSupport::Multibyte::Chars
end
end
-end
\ No newline at end of file
+end
diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb
index b20c980f36..4fe925f7f4 100644
--- a/activesupport/lib/active_support/multibyte/chars.rb
+++ b/activesupport/lib/active_support/multibyte/chars.rb
@@ -74,7 +74,6 @@ module ActiveSupport #:nodoc:
# Works just like String#split, with the exception that the items in the resulting list are Chars
# instances instead of String. This makes chaining methods easier.
#
- # Example:
# 'Café périferôl'.mb_chars.split(/é/).map { |part| part.upcase.to_s } # => ["CAF", " P", "RIFERÔL"]
def split(*args)
@wrapped_string.split(*args).map { |i| i.mb_chars }
@@ -88,7 +87,6 @@ module ActiveSupport #:nodoc:
# Reverses all characters in the string.
#
- # Example:
# 'Café'.mb_chars.reverse.to_s # => 'éfaC'
def reverse
chars(Unicode.unpack_graphemes(@wrapped_string).reverse.flatten.pack('U*'))
@@ -97,7 +95,6 @@ module ActiveSupport #:nodoc:
# Limits the byte size of the string to a number of bytes without breaking characters. Usable
# when the storage for a string is limited for some reason.
#
- # Example:
# 'こんにちは'.mb_chars.limit(7).to_s # => "こん"
def limit(limit)
slice(0...translate_offset(limit))
@@ -105,7 +102,6 @@ module ActiveSupport #:nodoc:
# Converts characters in the string to uppercase.
#
- # Example:
# 'Laurent, où sont les tests ?'.mb_chars.upcase.to_s # => "LAURENT, OÙ SONT LES TESTS ?"
def upcase
chars Unicode.upcase(@wrapped_string)
@@ -113,7 +109,6 @@ module ActiveSupport #:nodoc:
# Converts characters in the string to lowercase.
#
- # Example:
# 'VĚDA A VÝZKUM'.mb_chars.downcase.to_s # => "věda a výzkum"
def downcase
chars Unicode.downcase(@wrapped_string)
@@ -121,7 +116,6 @@ module ActiveSupport #:nodoc:
# Converts characters in the string to the opposite case.
#
- # Example:
# 'El Cañón".mb_chars.swapcase.to_s # => "eL cAÑÓN"
def swapcase
chars Unicode.swapcase(@wrapped_string)
@@ -129,7 +123,6 @@ module ActiveSupport #:nodoc:
# Converts the first character to uppercase and the remainder to lowercase.
#
- # Example:
# 'über'.mb_chars.capitalize.to_s # => "Über"
def capitalize
(slice(0) || chars('')).upcase + (slice(1..-1) || chars('')).downcase
@@ -137,7 +130,6 @@ module ActiveSupport #:nodoc:
# Capitalizes the first letter of every word, when possible.
#
- # Example:
# "ÉL QUE SE ENTERÓ".mb_chars.titleize # => "Él Que Se Enteró"
# "日本語".mb_chars.titleize # => "日本語"
def titleize
@@ -157,7 +149,6 @@ module ActiveSupport #:nodoc:
# Performs canonical decomposition on all the characters.
#
- # Example:
# 'é'.length # => 2
# 'é'.mb_chars.decompose.to_s.length # => 3
def decompose
@@ -166,7 +157,6 @@ module ActiveSupport #:nodoc:
# Performs composition on all the characters.
#
- # Example:
# 'é'.length # => 3
# 'é'.mb_chars.compose.to_s.length # => 2
def compose
@@ -175,7 +165,6 @@ module ActiveSupport #:nodoc:
# Returns the number of grapheme clusters in the string.
#
- # Example:
# 'क्षि'.mb_chars.length # => 4
# 'क्षि'.mb_chars.grapheme_length # => 3
def grapheme_length
diff --git a/activesupport/lib/active_support/multibyte/unicode.rb b/activesupport/lib/active_support/multibyte/unicode.rb
index cb89d45c92..678f551193 100644
--- a/activesupport/lib/active_support/multibyte/unicode.rb
+++ b/activesupport/lib/active_support/multibyte/unicode.rb
@@ -15,7 +15,6 @@ module ActiveSupport
# The default normalization used for operations that require normalization. It can be set to any of the
# normalizations in NORMALIZATION_FORMS.
#
- # Example:
# ActiveSupport::Multibyte::Unicode.default_normalization_form = :c
attr_accessor :default_normalization_form
@default_normalization_form = :kc
@@ -72,7 +71,6 @@ module ActiveSupport
# Unpack the string at grapheme boundaries. Returns a list of character lists.
#
- # Example:
# Unicode.unpack_graphemes('क्षि') # => [[2325, 2381], [2359], [2367]]
# Unicode.unpack_graphemes('Café') # => [[67], [97], [102], [233]]
def unpack_graphemes(string)
@@ -107,7 +105,6 @@ module ActiveSupport
# Reverse operation of unpack_graphemes.
#
- # Example:
# Unicode.pack_graphemes(Unicode.unpack_graphemes('क्षि')) # => 'क्षि'
def pack_graphemes(unpacked)
unpacked.flatten.pack('U*')
diff --git a/activesupport/lib/active_support/tagged_logging.rb b/activesupport/lib/active_support/tagged_logging.rb
index 538a36f6d9..5e080df518 100644
--- a/activesupport/lib/active_support/tagged_logging.rb
+++ b/activesupport/lib/active_support/tagged_logging.rb
@@ -3,7 +3,7 @@ require 'logger'
require 'active_support/logger'
module ActiveSupport
- # Wraps any standard Logger object to provide tagging capabilities. Examples:
+ # Wraps any standard Logger object to provide tagging capabilities.
#
# logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
# logger.tagged("BCX") { logger.info "Stuff" } # Logs "[BCX] Stuff"
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index cd07c24257..67ac1b6ccd 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -8,7 +8,6 @@ module ActiveSupport
#
# You shouldn't ever need to create a TimeWithZone instance directly via new . Instead use methods
# +local+, +parse+, +at+ and +now+ on TimeZone instances, and +in_time_zone+ on Time and DateTime instances.
- # Examples:
#
# Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
# Time.zone.local(2007, 2, 10, 15, 30, 45) # => Sat, 10 Feb 2007 15:30:45 EST -05:00
@@ -20,7 +19,6 @@ module ActiveSupport
# See Time and TimeZone for further documentation of these methods.
#
# TimeWithZone instances implement the same API as Ruby Time instances, so that Time and TimeWithZone instances are interchangeable.
- # Examples:
#
# t = Time.zone.now # => Sun, 18 May 2008 13:27:25 EDT -04:00
# t.hour # => 13
@@ -122,8 +120,6 @@ module ActiveSupport
# %Y/%m/%d %H:%M:%S +offset style by setting ActiveSupport::JSON::Encoding.use_standard_json_time_format
# to false.
#
- # ==== Examples
- #
# # With ActiveSupport::JSON::Encoding.use_standard_json_time_format = true
# Time.utc(2005,2,1,15,15,10).in_time_zone.to_json
# # => "2005-02-01T15:15:10Z"
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index 9543e50395..0059898ebf 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -176,7 +176,7 @@ module ActiveSupport
UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.sub(':', '')
# Assumes self represents an offset from UTC in seconds (as returned from Time#utc_offset)
- # and turns this into an +HH:MM formatted string. Example:
+ # and turns this into an +HH:MM formatted string.
#
# TimeZone.seconds_to_utc_offset(-21_600) # => "-06:00"
def self.seconds_to_utc_offset(seconds, colon = true)
@@ -239,7 +239,7 @@ module ActiveSupport
"(GMT#{formatted_offset}) #{name}"
end
- # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from given values. Example:
+ # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from given values.
#
# Time.zone = "Hawaii" # => "Hawaii"
# Time.zone.local(2007, 2, 1, 15, 30, 45) # => Thu, 01 Feb 2007 15:30:45 HST -10:00
@@ -248,7 +248,7 @@ module ActiveSupport
ActiveSupport::TimeWithZone.new(nil, self, time)
end
- # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from number of seconds since the Unix epoch. Example:
+ # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from number of seconds since the Unix epoch.
#
# Time.zone = "Hawaii" # => "Hawaii"
# Time.utc(2000).to_f # => 946684800.0
@@ -258,7 +258,7 @@ module ActiveSupport
utc.in_time_zone(self)
end
- # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from parsed string. Example:
+ # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from parsed string.
#
# Time.zone = "Hawaii" # => "Hawaii"
# Time.zone.parse('1999-12-31 14:00:00') # => Fri, 31 Dec 1999 14:00:00 HST -10:00
@@ -279,7 +279,7 @@ module ActiveSupport
end
# Returns an ActiveSupport::TimeWithZone instance representing the current time
- # in the time zone represented by +self+. Example:
+ # in the time zone represented by +self+.
#
# Time.zone = 'Hawaii' # => "Hawaii"
# Time.zone.now # => Wed, 23 Jan 2008 20:24:27 HST -10:00
--
cgit v1.2.3
From 7a95d079a31a4468d9ecbe5b4bbcd834f49ad92e Mon Sep 17 00:00:00 2001
From: Alexey Vakhov
Date: Mon, 14 May 2012 09:13:59 +0400
Subject: Missed colon
---
activemodel/lib/active_model/serialization.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/activemodel/lib/active_model/serialization.rb b/activemodel/lib/active_model/serialization.rb
index 00cd05b7ef..3751e4a741 100644
--- a/activemodel/lib/active_model/serialization.rb
+++ b/activemodel/lib/active_model/serialization.rb
@@ -64,7 +64,7 @@ module ActiveModel
# person.to_json # => "{\"name\":\"Bob\"}"
# person.to_xml # => "\n:only, :except, :methods and include.
+ # Valid options are :only, :except, :methods and :include.
# The following are all valid examples:
#
# person.serializable_hash(:only => 'name')
--
cgit v1.2.3
From d7c4d0c772e3ab91b9a564b3a6cb2d3f7d8b9833 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Mon, 14 May 2012 00:18:57 -0500
Subject: adding examples to deep_dup method
---
.../lib/active_support/core_ext/object/deep_dup.rb | 24 +++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/activesupport/lib/active_support/core_ext/object/deep_dup.rb b/activesupport/lib/active_support/core_ext/object/deep_dup.rb
index 2c4383ac94..883f5f556c 100644
--- a/activesupport/lib/active_support/core_ext/object/deep_dup.rb
+++ b/activesupport/lib/active_support/core_ext/object/deep_dup.rb
@@ -1,5 +1,13 @@
class Object
- # Returns a deep copy of object if it's duplicable.
+ # Returns a deep copy of object if it's duplicable. If it's
+ # not duplicable, returns +self+.
+ #
+ # object = Object.new
+ # dup = object.deep_dup
+ # dup.instance_variable_set(:@a, 1)
+ #
+ # object.instance_variable_defined?(:@a) #=> false
+ # dup.instance_variable_defined?(:@a) #=> true
def deep_dup
duplicable? ? dup : self
end
@@ -7,6 +15,13 @@ end
class Array
# Returns a deep copy of array.
+ #
+ # array = [1, [2, 3]]
+ # dup = array.deep_dup
+ # dup[1][2] = 4
+ #
+ # array[1][2] #=> nil
+ # dup[1][2] #=> 4
def deep_dup
map { |it| it.deep_dup }
end
@@ -14,6 +29,13 @@ end
class Hash
# Returns a deep copy of hash.
+ #
+ # hash = { a: { b: 'b' } }
+ # dup = hash.deep_dup
+ # dup[:a][:c] = 'c'
+ #
+ # hash[:a][:c] #=> nil
+ # dup[:a][:c] #=> "c"
def deep_dup
each_with_object(dup) do |(key, value), hash|
hash[key.deep_dup] = value.deep_dup
--
cgit v1.2.3
From 8ef67de03409d0d21e42605e063e501d3ee764cf Mon Sep 17 00:00:00 2001
From: Vijay Dev
Date: Mon, 14 May 2012 15:17:59 +0530
Subject: fix format in getting started guide [ci skip]
---
guides/source/getting_started.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile
index 84c438e607..e89602218e 100644
--- a/guides/source/getting_started.textile
+++ b/guides/source/getting_started.textile
@@ -193,7 +193,7 @@ Now that we have made the controller and view, we need to tell Rails when we wan
To fix this, delete the +index.html+ file located inside the +public+ directory of the application.
-You need to do this because Rails will serve any static file in the +public+ directory that matches a route in preference to any dynamic content you generate from the controllers. The +index.html+ file is special: it will be served if a request comes in at the root route, e.g. http://localhost:3000. If another request such as http://localhost:3000/welcome happened, a static file at public/welcome.html would be served first, but only if it existed.
+You need to do this because Rails will serve any static file in the +public+ directory that matches a route in preference to any dynamic content you generate from the controllers. The +index.html+ file is special: it will be served if a request comes in at the root route, e.g. http://localhost:3000. If another request such as http://localhost:3000/welcome happened, a static file at public/welcome.html would be served first, but only if it existed.
Next, you have to tell Rails where your actual home page is located.
--
cgit v1.2.3
From ee4e48eab06659b3fea64c70590e8d260a230445 Mon Sep 17 00:00:00 2001
From: Ayrton De Craene
Date: Mon, 14 May 2012 13:24:32 +0200
Subject: Improved the readability of some sentences [ci skip]
---
guides/source/i18n.textile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/guides/source/i18n.textile b/guides/source/i18n.textile
index 6179694c40..a9da843d04 100644
--- a/guides/source/i18n.textile
+++ b/guides/source/i18n.textile
@@ -127,7 +127,7 @@ If you want to translate your Rails application to a *single language other than
However, you would probably like to *provide support for more locales* in your application. In such case, you need to set and pass the locale between requests.
-WARNING: You may be tempted to store the chosen locale in a _session_ or a cookie. *Do not do so*. The locale should be transparent and a part of the URL. This way you don't break people's basic assumptions about the web itself: if you send a URL of some page to a friend, she should see the same page, same content. A fancy word for this would be that you're being "RESTful":http://en.wikipedia.org/wiki/Representational_State_Transfer. Read more about the RESTful approach in "Stefan Tilkov's articles":http://www.infoq.com/articles/rest-introduction. There may be some exceptions to this rule, which are discussed below.
+WARNING: You may be tempted to store the chosen locale in a _session_ or a cookie, however *do not do this*. The locale should be transparent and a part of the URL. This way you won't break people's basic assumptions about the web itself: if you send a URL to a friend, they should see the same page and content as you. A fancy word for this would be that you're being "RESTful":http://en.wikipedia.org/wiki/Representational_State_Transfer. Read more about the RESTful approach in "Stefan Tilkov's articles":http://www.infoq.com/articles/rest-introduction. Sometimes there are exceptions to this rule and those are discussed below.
The _setting part_ is easy. You can set the locale in a +before_filter+ in the +ApplicationController+ like this:
--
cgit v1.2.3
From 888383e0accf376109f29020c7f8cfbaa39338b9 Mon Sep 17 00:00:00 2001
From: Ayrton De Craene
Date: Mon, 14 May 2012 14:04:24 +0200
Subject: 'Netherlands locale' does not make any sense, it's Dutch locale [ci
skip]
---
guides/source/i18n.textile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/guides/source/i18n.textile b/guides/source/i18n.textile
index a9da843d04..ee7176a6c8 100644
--- a/guides/source/i18n.textile
+++ b/guides/source/i18n.textile
@@ -220,7 +220,7 @@ Every helper method dependent on +url_for+ (e.g. helpers for named routes like +
You may be satisfied with this. It does impact the readability of URLs, though, when the locale "hangs" at the end of every URL in your application. Moreover, from the architectural standpoint, locale is usually hierarchically above the other parts of the application domain: and URLs should reflect this.
-You probably want URLs to look like this: +www.example.com/en/books+ (which loads the English locale) and +www.example.com/nl/books+ (which loads the Netherlands locale). This is achievable with the "over-riding +default_url_options+" strategy from above: you just have to set up your routes with "+path_prefix+":http://api.rubyonrails.org/classes/ActionController/Resources.html#M000354 option in this way:
+You probably want URLs to look like this: +www.example.com/en/books+ (which loads the English locale) and +www.example.com/nl/books+ (which loads the Dutch locale). This is achievable with the "over-riding +default_url_options+" strategy from above: you just have to set up your routes with "+path_prefix+":http://api.rubyonrails.org/classes/ActionController/Resources.html#M000354 option in this way:
# config/routes.rb
@@ -229,7 +229,7 @@ scope "/:locale" do
end
-Now, when you call the +books_path+ method you should get +"/en/books"+ (for the default locale). An URL like +http://localhost:3001/nl/books+ should load the Netherlands locale, then, and following calls to +books_path+ should return +"/nl/books"+ (because the locale changed).
+Now, when you call the +books_path+ method you should get +"/en/books"+ (for the default locale). An URL like +http://localhost:3001/nl/books+ should load the Dutch locale, then, and following calls to +books_path+ should return +"/nl/books"+ (because the locale changed).
If you don't want to force the use of a locale in your routes you can use an optional path scope (denoted by the parentheses) like so:
--
cgit v1.2.3
From 17059a4868532f0046f1ec0ecc643a2211d6db45 Mon Sep 17 00:00:00 2001
From: Francesco Rodriguez
Date: Mon, 14 May 2012 10:50:40 -0500
Subject: Removing ==Examples and last blank lines of docs from railties
---
railties/lib/rails.rb | 3 ---
railties/lib/rails/engine.rb | 5 ----
railties/lib/rails/generators.rb | 4 ---
railties/lib/rails/generators/actions.rb | 42 ------------------------------
railties/lib/rails/generators/base.rb | 3 ---
railties/lib/rails/generators/migration.rb | 4 ---
6 files changed, 61 deletions(-)
diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb
index 59c3c56e59..670477f91a 100644
--- a/railties/lib/rails.rb
+++ b/railties/lib/rails.rb
@@ -107,14 +107,11 @@ module Rails
# * The environment variable RAILS_GROUPS;
# * The optional envs given as argument and the hash with group dependencies;
#
- # == Examples
- #
# groups :assets => [:development, :test]
#
# # Returns
# # => [:default, :development, :assets] for Rails.env == "development"
# # => [:default, :production] for Rails.env == "production"
- #
def groups(*groups)
hash = groups.extract_options!
env = Rails.env
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index 9bf9cbe022..ef48bc4f94 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -39,8 +39,6 @@ module Rails
# and autoload_once_paths, which, differently from a Railtie, are scoped to
# the current engine.
#
- # Example:
- #
# class MyEngine < Rails::Engine
# # Add a load path for this specific Engine
# config.autoload_paths << File.expand_path("../lib/some/path", __FILE__)
@@ -336,11 +334,8 @@ module Rails
# It will affect the priority of loading views, helpers, assets and all the other files
# related to engine or application.
#
- # Example:
- #
# # load Blog::Engine with highest priority, followed by application and other railties
# config.railties_order = [Blog::Engine, :main_app, :all]
- #
class Engine < Railtie
autoload :Configuration, "rails/engine/configuration"
autoload :Railties, "rails/engine/railties"
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index 55642f8140..4fa990171d 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -95,7 +95,6 @@ module Rails
# some of them are not available by adding a fallback:
#
# Rails::Generators.fallbacks[:shoulda] = :test_unit
- #
def self.fallbacks
@fallbacks ||= {}
end
@@ -115,8 +114,6 @@ module Rails
# Generators names must end with "_generator.rb". This is required because Rails
# looks in load paths and loads the generator just before it's going to be used.
#
- # ==== Examples
- #
# find_by_namespace :webrat, :rails, :integration
#
# Will search for the following generators:
@@ -125,7 +122,6 @@ module Rails
#
# Notice that "rails:generators:webrat" could be loaded as well, what
# Rails looks for is the first and last parts of the namespace.
- #
def self.find_by_namespace(name, base=nil, context=nil) #:nodoc:
lookups = []
lookups << "#{base}:#{name}" if base
diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb
index 9b0649e456..6cd2ea2bbd 100644
--- a/railties/lib/rails/generators/actions.rb
+++ b/railties/lib/rails/generators/actions.rb
@@ -8,12 +8,9 @@ module Rails
# Adds an entry into Gemfile for the supplied gem. If env
# is specified, add the gem to the given environment.
#
- # ==== Example
- #
# gem "rspec", :group => :test
# gem "technoweenie-restful-authentication", :lib => "restful-authentication", :source => "http://gems.github.com/"
# gem "rails", "3.0", :git => "git://github.com/rails/rails"
- #
def gem(*args)
options = args.extract_options!
name, version = args
@@ -43,12 +40,9 @@ module Rails
# Wraps gem entries inside a group.
#
- # ==== Example
- #
# gem_group :development, :test do
# gem "rspec-rails"
# end
- #
def gem_group(*names, &block)
name = names.map(&:inspect).join(", ")
log :gemfile, "group #{name}"
@@ -66,10 +60,7 @@ module Rails
# Add the given source to Gemfile
#
- # ==== Example
- #
# add_source "http://gems.github.com/"
- #
def add_source(source, options={})
log :source, source
@@ -83,8 +74,6 @@ module Rails
# If options :env is specified, the line is appended to the corresponding
# file in config/environments.
#
- # ==== Examples
- #
# environment do
# "config.autoload_paths += %W(#{config.root}/extras)"
# end
@@ -92,7 +81,6 @@ module Rails
# environment(nil, :env => "development") do
# "config.active_record.observers = :cacher"
# end
- #
def environment(data=nil, options={}, &block)
sentinel = /class [a-z_:]+ < Rails::Application/i
env_file_sentinel = /::Application\.configure do/
@@ -112,12 +100,9 @@ module Rails
# Run a command in git.
#
- # ==== Examples
- #
# git :init
# git :add => "this.file that.rb"
# git :add => "onefile.rb", :rm => "badfile.cxx"
- #
def git(commands={})
if commands.is_a?(Symbol)
run "git #{commands}"
@@ -131,15 +116,12 @@ module Rails
# Create a new file in the vendor/ directory. Code can be specified
# in a block or a data string can be given.
#
- # ==== Examples
- #
# vendor("sekrit.rb") do
# sekrit_salt = "#{Time.now}--#{3.years.ago}--#{rand}--"
# "salt = '#{sekrit_salt}'"
# end
#
# vendor("foreign.rb", "# Foreign code is fun")
- #
def vendor(filename, data=nil, &block)
log :vendor, filename
create_file("vendor/#{filename}", data, :verbose => false, &block)
@@ -148,14 +130,11 @@ module Rails
# Create a new file in the lib/ directory. Code can be specified
# in a block or a data string can be given.
#
- # ==== Examples
- #
# lib("crypto.rb") do
# "crypted_special_value = '#{rand}--#{Time.now}--#{rand(1337)}--'"
# end
#
# lib("foreign.rb", "# Foreign code is fun")
- #
def lib(filename, data=nil, &block)
log :lib, filename
create_file("lib/#{filename}", data, :verbose => false, &block)
@@ -163,8 +142,6 @@ module Rails
# Create a new Rakefile with the provided code (either in a block or a string).
#
- # ==== Examples
- #
# rakefile("bootstrap.rake") do
# project = ask("What is the UNIX name of your project?")
#
@@ -178,7 +155,6 @@ module Rails
# end
#
# rakefile('seed.rake', 'puts "Planting seeds"')
- #
def rakefile(filename, data=nil, &block)
log :rakefile, filename
create_file("lib/tasks/#{filename}", data, :verbose => false, &block)
@@ -186,8 +162,6 @@ module Rails
# Create a new initializer with the provided code (either in a block or a string).
#
- # ==== Examples
- #
# initializer("globals.rb") do
# data = ""
#
@@ -199,7 +173,6 @@ module Rails
# end
#
# initializer("api.rb", "API_KEY = '123456'")
- #
def initializer(filename, data=nil, &block)
log :initializer, filename
create_file("config/initializers/#{filename}", data, :verbose => false, &block)
@@ -209,10 +182,7 @@ module Rails
# The second parameter is the argument string that is passed to
# the generator or an Array that is joined.
#
- # ==== Example
- #
# generate(:authenticated, "user session")
- #
def generate(what, *args)
log :generate, what
argument = args.map {|arg| arg.to_s }.flatten.join(" ")
@@ -222,12 +192,9 @@ module Rails
# Runs the supplied rake task
#
- # ==== Example
- #
# rake("db:migrate")
# rake("db:migrate", :env => "production")
# rake("gems:install", :sudo => true)
- #
def rake(command, options={})
log :rake, command
env = options[:env] || ENV["RAILS_ENV"] || 'development'
@@ -237,10 +204,7 @@ module Rails
# Just run the capify command in root
#
- # ==== Example
- #
# capify!
- #
def capify!
log :capify, ""
in_root { run("#{extify(:capify)} .", :verbose => false) }
@@ -248,10 +212,7 @@ module Rails
# Make an entry in Rails routing file config/routes.rb
#
- # === Example
- #
# route "root :to => 'welcome#index'"
- #
def route(routing_code)
log :route, routing_code
sentinel = /\.routes\.draw do\s*$/
@@ -263,10 +224,7 @@ module Rails
# Reads the given file at the source root and prints it in the console.
#
- # === Example
- #
# readme "README"
- #
def readme(path)
log File.read(find_in_source_paths(path))
end
diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb
index 1648b9674a..28d7680669 100644
--- a/railties/lib/rails/generators/base.rb
+++ b/railties/lib/rails/generators/base.rb
@@ -187,10 +187,7 @@ module Rails
# Remove a previously added hook.
#
- # ==== Examples
- #
# remove_hook_for :orm
- #
def self.remove_hook_for(*names)
remove_invocation(*names)
diff --git a/railties/lib/rails/generators/migration.rb b/railties/lib/rails/generators/migration.rb
index 0c5c4f6e09..5bf98bb6e0 100644
--- a/railties/lib/rails/generators/migration.rb
+++ b/railties/lib/rails/generators/migration.rb
@@ -3,7 +3,6 @@ module Rails
# Holds common methods for migrations. It assumes that migrations has the
# [0-9]*_name format and can be used by another frameworks (like Sequel)
# just by implementing the next migration version method.
- #
module Migration
attr_reader :migration_number, :migration_file_name, :migration_class_name
@@ -38,10 +37,7 @@ module Rails
# The migration version, migration file name, migration class name are
# available as instance variables in the template to be rendered.
#
- # ==== Examples
- #
# migration_template "migration.rb", "db/migrate/add_foo_to_bar.rb"
- #
def migration_template(source, destination=nil, config={})
destination = File.expand_path(destination || source, self.destination_root)
--
cgit v1.2.3
From 151aa9abae131f1a03513f756aeaef2fc403f9bb Mon Sep 17 00:00:00 2001
From: Vasiliy Ermolovich
Date: Mon, 14 May 2012 21:49:42 +0300
Subject: remove docs on Range#step
---
guides/source/active_support_core_extensions.textile | 12 ------------
1 file changed, 12 deletions(-)
diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile
index 8045316e98..bf30ed64c8 100644
--- a/guides/source/active_support_core_extensions.textile
+++ b/guides/source/active_support_core_extensions.textile
@@ -2767,18 +2767,6 @@ As the example depicts, the +:db+ format generates a +BETWEEN+ SQL clause. That
NOTE: Defined in +active_support/core_ext/range/conversions.rb+.
-h4. +step+
-
-Active Support extends the method +Range#step+ so that it can be invoked without a block:
-
-
-(1..10).step(2) # => [1, 3, 5, 7, 9]
-
-
-As the example shows, in that case the method returns an array with the corresponding elements.
-
-NOTE: Defined in +active_support/core_ext/range/blockless_step.rb+.
-
h4. +include?+
The methods +Range#include?+ and +Range#===+ say whether some value falls between the ends of a given instance:
--
cgit v1.2.3