From 9991f14fced25dac3699b473a05cc7a196f9220e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Emin=20=C4=B0NA=C3=87?= Date: Tue, 14 Apr 2015 22:50:36 +0300 Subject: Fix for has_and_belongs_to_many & has_many_through associations while partial_writes is false This will fix #19663 Also with this fix, active record does not fire unnecassary update queries while partial_writes is true --- activerecord/CHANGELOG.md | 8 +++++++- .../associations/has_many_through_association.rb | 5 ++++- .../has_and_belongs_to_many_associations_test.rb | 13 +++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index f13a80195a..f7fdb6755d 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,10 @@ +* Improved partial writes with HABTM and has many through associations + to fire database query only if relation has been changed. + + Fixes #19663. + + *Mehmet Emin İNAÇ* + * Rework `ActiveRecord::Relation#last` 1. Never perform additional SQL on loaded relation @@ -18,7 +25,6 @@ *Bogdan Gusiev* - * Allow `joins` to be unscoped. Closes #13775. diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 36fc381343..7ddb96db13 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -86,7 +86,10 @@ module ActiveRecord end def save_through_record(record) - build_through_record(record).save! + association = build_through_record(record) + if association.changed? + association.save! + end ensure @through_records.delete(record.object_id) 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 5c4586da19..cab9dff6ca 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 @@ -982,4 +982,17 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase Project.first.developers_required_by_default.create!(name: "Sean", salary: 50000) end end + + def test_has_and_belongs_to_many_while_partial_writes_false + begin + original_partial_writes = ActiveRecord::Base.partial_writes + ActiveRecord::Base.partial_writes = false + developer = Developer.new(name: "Mehmet Emin İNAÇ") + developer.projects << Project.new(name: "Bounty") + + assert developer.save + ensure + ActiveRecord::Base.partial_writes = original_partial_writes + end + end end -- cgit v1.2.3 From 215857e0c185530d526dc91cbc3bbaff9c353746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Emin=20=C4=B0NA=C3=87?= Date: Tue, 16 Feb 2016 00:31:39 +0200 Subject: Dynamically show available sql types [ci skip] Dynamically list available sql data types based on current database adapter. --- railties/lib/rails/generators/rails/model/USAGE | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/railties/lib/rails/generators/rails/model/USAGE b/railties/lib/rails/generators/rails/model/USAGE index 025bcf4774..c95e523fb5 100644 --- a/railties/lib/rails/generators/rails/model/USAGE +++ b/railties/lib/rails/generators/rails/model/USAGE @@ -35,17 +35,7 @@ Available field types: type. If no type is specified the string type will be used by default. You can use the following types: - integer - primary_key - decimal - float - boolean - binary - string - text - date - time - datetime + <%= ActiveRecord::Base.connection.native_database_types.keys.join("\n\t") %> You can also consider `references` as a kind of type. For instance, if you run: -- cgit v1.2.3 From ea2bf991a90a1c04ce867cfbbe7ac52b8456359f Mon Sep 17 00:00:00 2001 From: seunghwan oh Date: Wed, 1 Jun 2016 18:15:44 +0900 Subject: Add --skip-coffee generating option Usage `rails new awesome-project --skip-coffee` --- railties/lib/rails/generators/app_base.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index f0a3289563..27229956a6 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -67,6 +67,9 @@ module Rails class_option :skip_listen, type: :boolean, default: false, desc: "Don't generate configuration that depends on the listen gem" + class_option :skip_coffee, type: :boolean, default: false, + desc: "Don't use CoffeeScript" + class_option :skip_javascript, type: :boolean, aliases: '-J', default: false, desc: 'Skip JavaScript files' @@ -319,7 +322,9 @@ module Rails if options[:skip_javascript] || options[:skip_sprockets] [] else - gems = [coffee_gemfile_entry, javascript_runtime_gemfile_entry] + gems = [javascript_runtime_gemfile_entry] + gems << coffee_gemfile_entry unless options[:skip_coffee] + gems << GemfileEntry.version("#{options[:javascript]}-rails", nil, "Use #{options[:javascript]} as the JavaScript library") -- cgit v1.2.3 From a26d4ad64b0451301711b7050dea2593c977cfd3 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sun, 19 Jun 2016 10:14:06 +0900 Subject: `PolymorphicReflection` is not using the methods from `ThroughReflection` `ThroughReflection` initializes `@delegate_reflection` and delegate all public methods to `delegate_reflection`. But `PolymorphicReflection` does not initialize `@delegate_reflection`. It is enough to inherit `AbstractReflection` (using `alias_candidate` only). --- activerecord/lib/active_record/reflection.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index bf398b0d40..6684283f03 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -135,8 +135,8 @@ module ActiveRecord # BelongsToReflection # HasAndBelongsToManyReflection # ThroughReflection - # PolymorphicReflection - # RuntimeReflection + # PolymorphicReflection + # RuntimeReflection class AbstractReflection # :nodoc: def through_reflection? false @@ -981,7 +981,7 @@ module ActiveRecord end - class PolymorphicReflection < ThroughReflection # :nodoc: + class PolymorphicReflection < AbstractReflection # :nodoc: def initialize(reflection, previous_reflection) @reflection = reflection @previous_reflection = previous_reflection -- cgit v1.2.3 From 2495a0ba33832d20e3eadc163999dd40123e10c1 Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Thu, 12 May 2016 14:21:07 -0500 Subject: Extract notes from files in binary Prevents: ArgumentError: invalid byte sequence in UTF-8 railties/lib/rails/source_annotation_extractor.rb:115:in `=~' railties/lib/rails/source_annotation_extractor.rb:115:in `block in extract_annotations_from' And there's no reason we need to interpret the files as UTF-8 when scanning for annotations. Applies to Rails 4.2 as well. --- railties/lib/rails/source_annotation_extractor.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/lib/rails/source_annotation_extractor.rb b/railties/lib/rails/source_annotation_extractor.rb index f0df76d3f3..c60e59cb88 100644 --- a/railties/lib/rails/source_annotation_extractor.rb +++ b/railties/lib/rails/source_annotation_extractor.rb @@ -116,7 +116,7 @@ class SourceAnnotationExtractor # Otherwise it returns an empty hash. def extract_annotations_from(file, pattern) lineno = 0 - result = File.readlines(file).inject([]) do |list, line| + result = File.readlines(file, encoding: Encoding::BINARY).inject([]) do |list, line| lineno += 1 next list unless line =~ pattern list << Annotation.new(lineno, $1, $2) -- cgit v1.2.3 From fa5200fc21f6c9a2202d9af29cf0122d98a5d8d8 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sun, 18 Sep 2016 11:04:39 +0900 Subject: change `MemCacheStore#increment` and `MemCacheStore#decrement` to public API [ci skip] I'm not sure why these methods not public. But these methods are public in other cache stores, I think that may be in public. Ref: http://edgeapi.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-increment http://edgeapi.rubyonrails.org/classes/ActiveSupport/Cache/FileStore.html#method-i-increment http://edgeapi.rubyonrails.org/classes/ActiveSupport/Cache/MemoryStore.html#method-i-increment http://edgeapi.rubyonrails.org/classes/ActiveSupport/Cache/NullStore.html#method-i-increment --- activesupport/lib/active_support/cache/mem_cache_store.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb index cfd5e39bc4..00f4480308 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/mem_cache_store.rb @@ -110,7 +110,7 @@ module ActiveSupport # operator and can only be used on values written with the :raw option. # Calling it on a value not stored with :raw will initialize that value # to zero. - def increment(name, amount = 1, options = nil) # :nodoc: + def increment(name, amount = 1, options = nil) options = merged_options(options) instrument(:increment, name, amount: amount) do rescue_error_with nil do @@ -123,7 +123,7 @@ module ActiveSupport # operator and can only be used on values written with the :raw option. # Calling it on a value not stored with :raw will initialize that value # to zero. - def decrement(name, amount = 1, options = nil) # :nodoc: + def decrement(name, amount = 1, options = nil) options = merged_options(options) instrument(:decrement, name, amount: amount) do rescue_error_with nil do -- cgit v1.2.3 From 02bcd71960c3ec6073d4ef2e9b5d208ceeaa61fe Mon Sep 17 00:00:00 2001 From: "v.promzelev" Date: Fri, 23 Sep 2016 15:52:34 +0400 Subject: initialize errors with name of class and other params --- activerecord/lib/active_record/relation/finder_methods.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 5e580ac865..97a819c5af 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -353,7 +353,7 @@ module ActiveRecord if ids.nil? error = "Couldn't find #{name}" error << " with#{conditions}" if conditions - raise RecordNotFound, error + raise RecordNotFound.new(error, name) elsif Array(ids).size == 1 error = "Couldn't find #{name} with '#{primary_key}'=#{ids}#{conditions}" raise RecordNotFound.new(error, name, primary_key, ids) @@ -361,7 +361,7 @@ module ActiveRecord error = "Couldn't find all #{name.pluralize} with '#{primary_key}': " error << "(#{ids.join(", ")})#{conditions} (found #{result_size} results, but was looking for #{expected_size})" - raise RecordNotFound, error + raise RecordNotFound.new(error, name, primary_key, ids) end end -- cgit v1.2.3 From 30b498036fe35ff9acb698dbc7364e289161113d Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 3 Oct 2016 05:36:12 +0900 Subject: Fix `add_index` to normalize column names and options Currently does not work the following code. ```ruby add_index(:people, ["last_name", "first_name"], order: { last_name: :desc, first_name: :asc }) ``` Normalize column names and options to fix the issue. --- .../active_record/connection_adapters/abstract/schema_statements.rb | 3 ++- .../lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 1 + activerecord/test/cases/adapters/mysql2/active_schema_test.rb | 3 +++ activerecord/test/cases/adapters/postgresql/active_schema_test.rb | 4 ++++ 4 files changed, 10 insertions(+), 1 deletion(-) 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 29520ed9c8..6146be436d 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -1171,6 +1171,7 @@ module ActiveRecord if order = options[:order] case order when Hash + order = order.symbolize_keys quoted_columns.each { |name, column| column << " #{order[name].upcase}" if order[name].present? } when String quoted_columns.each { |name, column| column << " #{order.upcase}" if order.present? } @@ -1192,7 +1193,7 @@ module ActiveRecord def quoted_columns_for_index(column_names, **options) return [column_names] if column_names.is_a?(String) - quoted_columns = Hash[column_names.map { |name| [name, quote_column_name(name).dup] }] + quoted_columns = Hash[column_names.map { |name| [name.to_sym, quote_column_name(name).dup] }] add_options_for_index_columns(quoted_columns, options).values end diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index be8511f119..fd8cb5d7c3 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -718,6 +718,7 @@ module ActiveRecord if length = options[:length] case length when Hash + length = length.symbolize_keys quoted_columns.each { |name, column| column << "(#{length[name]})" if length[name].present? } when Integer quoted_columns.each { |name, column| column << "(#{length})" } diff --git a/activerecord/test/cases/adapters/mysql2/active_schema_test.rb b/activerecord/test/cases/adapters/mysql2/active_schema_test.rb index a70eb5a094..2a528b2cb1 100644 --- a/activerecord/test/cases/adapters/mysql2/active_schema_test.rb +++ b/activerecord/test/cases/adapters/mysql2/active_schema_test.rb @@ -28,12 +28,15 @@ class Mysql2ActiveSchemaTest < ActiveRecord::Mysql2TestCase expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`(15)) " assert_equal expected, add_index(:people, [:last_name, :first_name], length: 15) + assert_equal expected, add_index(:people, ["last_name", "first_name"], length: 15) expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`) " assert_equal expected, add_index(:people, [:last_name, :first_name], length: { last_name: 15 }) + assert_equal expected, add_index(:people, ["last_name", "first_name"], length: { last_name: 15 }) expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`(10)) " assert_equal expected, add_index(:people, [:last_name, :first_name], length: { last_name: 15, first_name: 10 }) + assert_equal expected, add_index(:people, ["last_name", :first_name], length: { last_name: 15, "first_name" => 10 }) %w(SPATIAL FULLTEXT UNIQUE).each do |type| expected = "CREATE #{type} INDEX `index_people_on_last_name` ON `people` (`last_name`) " diff --git a/activerecord/test/cases/adapters/postgresql/active_schema_test.rb b/activerecord/test/cases/adapters/postgresql/active_schema_test.rb index d3c65f3d94..b787de8453 100644 --- a/activerecord/test/cases/adapters/postgresql/active_schema_test.rb +++ b/activerecord/test/cases/adapters/postgresql/active_schema_test.rb @@ -39,6 +39,10 @@ class PostgresqlActiveSchemaTest < ActiveRecord::PostgreSQLTestCase expected = %(CREATE INDEX CONCURRENTLY "index_people_on_last_name" ON "people" ("last_name")) assert_equal expected, add_index(:people, :last_name, algorithm: :concurrently) + expected = %(CREATE INDEX "index_people_on_last_name_and_first_name" ON "people" ("last_name" DESC, "first_name" ASC)) + assert_equal expected, add_index(:people, [:last_name, :first_name], order: { last_name: :desc, first_name: :asc }) + assert_equal expected, add_index(:people, ["last_name", :first_name], order: { last_name: :desc, "first_name" => :asc }) + %w(gin gist hash btree).each do |type| expected = %(CREATE INDEX "index_people_on_last_name" ON "people" USING #{type} ("last_name")) assert_equal expected, add_index(:people, :last_name, using: type) -- cgit v1.2.3 From 444cf0d6424dcfaef009b9046b23c281791f0e9b Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 3 Oct 2016 06:49:27 +0900 Subject: Remove unnecessary `respond_to?(:indexes)` checking Currently all adapters (postgresql, mysql2, sqlite3, oracle-enhanced, and sqlserver) implemented `indexes` and schema dumper expects implemented `indexes`. https://github.com/rails/rails/blob/v5.0.0/activerecord/lib/active_record/schema_dumper.rb#L208 Therefore `respond_to?(:indexes)` checking is unnecessary. --- .../abstract/schema_statements.rb | 4 ---- activerecord/test/cases/adapter_test.rb | 23 +++++++++------------- 2 files changed, 9 insertions(+), 18 deletions(-) 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 29520ed9c8..2d6bf5e874 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -1199,10 +1199,6 @@ module ActiveRecord def index_name_for_remove(table_name, options = {}) return options[:name] if can_remove_index_by_name?(options) - # if the adapter doesn't support the indexes call the best we can do - # is return the default index name for the options provided - return index_name(table_name, options) unless respond_to?(:indexes) - checks = [] if options.is_a?(Hash) diff --git a/activerecord/test/cases/adapter_test.rb b/activerecord/test/cases/adapter_test.rb index 8fa0645b0f..6862863443 100644 --- a/activerecord/test/cases/adapter_test.rb +++ b/activerecord/test/cases/adapter_test.rb @@ -69,20 +69,15 @@ module ActiveRecord def test_indexes idx_name = "accounts_idx" - if @connection.respond_to?(:indexes) - indexes = @connection.indexes("accounts") - assert indexes.empty? - - @connection.add_index :accounts, :firm_id, name: idx_name - indexes = @connection.indexes("accounts") - assert_equal "accounts", indexes.first.table - assert_equal idx_name, indexes.first.name - assert !indexes.first.unique - assert_equal ["firm_id"], indexes.first.columns - else - warn "#{@connection.class} does not respond to #indexes" - end - + indexes = @connection.indexes("accounts") + assert indexes.empty? + + @connection.add_index :accounts, :firm_id, name: idx_name + indexes = @connection.indexes("accounts") + assert_equal "accounts", indexes.first.table + assert_equal idx_name, indexes.first.name + assert !indexes.first.unique + assert_equal ["firm_id"], indexes.first.columns ensure @connection.remove_index(:accounts, name: idx_name) rescue nil end -- cgit v1.2.3 From 1e6aab94d561c60c358cf33675a6a1373d11b97f Mon Sep 17 00:00:00 2001 From: Iain Beeston Date: Mon, 3 Oct 2016 08:56:01 +0100 Subject: Corrected comments referring to ActiveModel::Attributes Should be ActiveRecord::Attributes (ActiveModel::Attributes does not exist) --- activemodel/lib/active_model/type.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activemodel/lib/active_model/type.rb b/activemodel/lib/active_model/type.rb index 313f17830f..0d3349e236 100644 --- a/activemodel/lib/active_model/type.rb +++ b/activemodel/lib/active_model/type.rb @@ -27,7 +27,7 @@ module ActiveModel delegate :add_modifier, to: :registry # Add a new type to the registry, allowing it to be referenced as a - # symbol by ActiveModel::Attributes::ClassMethods#attribute. If your + # symbol by ActiveRecord::Attributes::ClassMethods#attribute. If your # type is only meant to be used with a specific database adapter, you can # do so by passing +adapter: :postgresql+. If your type has the same # name as a native type for the current adapter, an exception will be -- cgit v1.2.3 From aeb2fee25b3dcace0a100e1c4cddf29723545ec2 Mon Sep 17 00:00:00 2001 From: Iain Beeston Date: Mon, 3 Oct 2016 11:29:31 +0100 Subject: Corrected comments referring to documentation in `ActiveRecord::Type::Value` This is now defined in `ActiveModel::Type::Value` (`ActiveRecord::Type::Value` still exists but it's effectively an alias) --- activerecord/lib/active_record/attributes.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/attributes.rb b/activerecord/lib/active_record/attributes.rb index 4b92e5835f..dcbfca1c04 100644 --- a/activerecord/lib/active_record/attributes.rb +++ b/activerecord/lib/active_record/attributes.rb @@ -116,7 +116,7 @@ module ActiveRecord # Users may also define their own custom types, as long as they respond # to the methods defined on the value type. The method +deserialize+ or # +cast+ will be called on your type object, with raw input from the - # database or from your controllers. See ActiveRecord::Type::Value for the + # database or from your controllers. See ActiveModel::Type::Value for the # expected API. It is recommended that your type objects inherit from an # existing type, or from ActiveRecord::Type::Value # @@ -143,7 +143,7 @@ module ActiveRecord # store_listing.price_in_cents # => 1000 # # For more details on creating custom types, see the documentation for - # ActiveRecord::Type::Value. For more details on registering your types + # ActiveModel::Type::Value. For more details on registering your types # to be referenced by a symbol, see ActiveRecord::Type.register. You can # also pass a type object directly, in place of a symbol. # @@ -190,7 +190,7 @@ module ActiveRecord # The type of an attribute is given the opportunity to change how dirty # tracking is performed. The methods +changed?+ and +changed_in_place?+ # will be called from ActiveModel::Dirty. See the documentation for those - # methods in ActiveRecord::Type::Value for more details. + # methods in ActiveModel::Type::Value for more details. def attribute(name, cast_type, **options) name = name.to_s reload_schema_from_cache -- cgit v1.2.3 From 0da4a08bdfea28a0cc881ca5831aadfcf8a3b7eb Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sun, 5 Jun 2016 00:38:40 +0900 Subject: Prevent `RangeError` for `belongs_to` associations Currently to access `belongs_to` associations raises a `RangeError` if foreign key attribute has out of range value. It should return a nil value rather than raising a `RangeError`. Fixes #20140. --- .../lib/active_record/associations/singular_association.rb | 2 ++ .../cases/associations/belongs_to_associations_test.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/activerecord/lib/active_record/associations/singular_association.rb b/activerecord/lib/active_record/associations/singular_association.rb index e386cc0e4c..a9e7edddff 100644 --- a/activerecord/lib/active_record/associations/singular_association.rb +++ b/activerecord/lib/active_record/associations/singular_association.rb @@ -51,6 +51,8 @@ module ActiveRecord sc.execute(binds, klass, conn) do |record| set_inverse_instance record end.first + rescue RangeError + nil end def replace(record) diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 2418346d1b..da6e42b89b 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -1062,6 +1062,20 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert_equal 1, parent.reload.children_count end + def test_belongs_to_with_out_of_range_value_assigning + model = Class.new(Comment) do + def self.name; "Temp"; end + validates :post, presence: true + end + + comment = model.new + comment.post_id = 10_000_000_000 + + assert_nil comment.post + assert_not comment.valid? + assert_equal [{ error: :blank }], comment.errors.details[:post] + end + def test_polymorphic_with_custom_primary_key toy = Toy.create! sponsor = Sponsor.create!(sponsorable: toy) -- cgit v1.2.3 From c5bcbb0914b154ab487f95ec7e039cbd26a47e26 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Fri, 14 Oct 2016 04:50:38 +0900 Subject: Quote table name properly If does not quote table name properly, invalid SQL is generated. --- .../postgresql/schema_statements.rb | 16 +++++++-------- .../connection_adapters/postgresql_adapter.rb | 2 +- .../connection_adapters/sqlite3_adapter.rb | 10 +++++---- activerecord/test/cases/adapter_test.rb | 7 +++++-- activerecord/test/cases/view_test.rb | 24 ++++++++++++++-------- 5 files changed, 35 insertions(+), 24 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index 83310233f0..69f797da3a 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -86,7 +86,7 @@ module ActiveRecord SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace - WHERE c.relkind IN ('r', 'v','m') -- (r)elation/table, (v)iew, (m)aterialized view + WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view AND n.nspname = ANY (current_schemas(false)) SQL end @@ -108,13 +108,13 @@ module ActiveRecord name = Utils.extract_schema_qualified_name(name.to_s) return false unless name.identifier - select_value(<<-SQL, "SCHEMA").to_i > 0 - SELECT COUNT(*) + select_values(<<-SQL, "SCHEMA").any? + SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view - AND c.relname = '#{name.identifier}' - AND n.nspname = #{name.schema ? "'#{name.schema}'" : 'ANY (current_schemas(false))'} + AND c.relname = #{quote(name.identifier)} + AND n.nspname = #{name.schema ? quote(name.schema) : "ANY (current_schemas(false))"} SQL end @@ -137,8 +137,8 @@ module ActiveRecord FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('v','m') -- (v)iew, (m)aterialized view - AND c.relname = '#{name.identifier}' - AND n.nspname = #{name.schema ? "'#{name.schema}'" : 'ANY (current_schemas(false))'} + AND c.relname = #{quote(name.identifier)} + AND n.nspname = #{name.schema ? quote(name.schema) : "ANY (current_schemas(false))"} SQL end @@ -441,7 +441,7 @@ module ActiveRecord WITH pk_constraint AS ( SELECT conrelid, unnest(conkey) AS connum FROM pg_constraint WHERE contype = 'p' - AND conrelid = '#{quote_table_name(table_name)}'::regclass + AND conrelid = #{quote(quote_table_name(table_name))}::regclass ), cons AS ( SELECT conrelid, connum, row_number() OVER() AS rownum FROM pk_constraint ) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index a33e64883e..acd1eeace7 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -750,7 +750,7 @@ module ActiveRecord col_description(a.attrelid, a.attnum) AS comment FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum - WHERE a.attrelid = '#{quote_table_name(table_name)}'::regclass + WHERE a.attrelid = #{quote(quote_table_name(table_name))}::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum end_sql diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index e2b534b511..ebeac425d0 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -530,10 +530,12 @@ module ActiveRecord def table_structure_with_collation(table_name, basic_structure) collation_hash = {} - sql = "SELECT sql FROM - (SELECT * FROM sqlite_master UNION ALL - SELECT * FROM sqlite_temp_master) - WHERE type='table' and name='#{ table_name }' \;" + sql = <<-SQL + SELECT sql FROM + (SELECT * FROM sqlite_master UNION ALL + SELECT * FROM sqlite_temp_master) + WHERE type = 'table' AND name = #{quote(table_name)} + SQL # Result will have following sample string # CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, diff --git a/activerecord/test/cases/adapter_test.rb b/activerecord/test/cases/adapter_test.rb index 8fa0645b0f..cfbc8ab942 100644 --- a/activerecord/test/cases/adapter_test.rb +++ b/activerecord/test/cases/adapter_test.rb @@ -42,8 +42,10 @@ module ActiveRecord def test_table_exists? ActiveSupport::Deprecation.silence do assert @connection.table_exists?("accounts") - assert !@connection.table_exists?("nonexistingtable") - assert !@connection.table_exists?(nil) + assert @connection.table_exists?(:accounts) + assert_not @connection.table_exists?("nonexistingtable") + assert_not @connection.table_exists?("'") + assert_not @connection.table_exists?(nil) end end @@ -63,6 +65,7 @@ module ActiveRecord assert @connection.data_source_exists?("accounts") assert @connection.data_source_exists?(:accounts) assert_not @connection.data_source_exists?("nonexistingtable") + assert_not @connection.data_source_exists?("'") assert_not @connection.data_source_exists?(nil) end diff --git a/activerecord/test/cases/view_test.rb b/activerecord/test/cases/view_test.rb index 0e38cee334..1f326d4b39 100644 --- a/activerecord/test/cases/view_test.rb +++ b/activerecord/test/cases/view_test.rb @@ -11,20 +11,21 @@ module ViewBehavior end class Ebook < ActiveRecord::Base + self.table_name = "ebooks'" self.primary_key = "id" end def setup super @connection = ActiveRecord::Base.connection - create_view "ebooks", <<-SQL + create_view "ebooks'", <<-SQL SELECT id, name, status FROM books WHERE format = 'ebook' SQL end def teardown super - drop_view "ebooks" + drop_view "ebooks'" end def test_reading @@ -66,15 +67,20 @@ module ViewBehavior def test_does_not_assume_id_column_as_primary_key model = Class.new(ActiveRecord::Base) do - self.table_name = "ebooks" + self.table_name = "ebooks'" end assert_nil model.primary_key end def test_does_not_dump_view_as_table - schema = dump_table_schema "ebooks" - assert_no_match %r{create_table "ebooks"}, schema + schema = dump_table_schema "ebooks'" + assert_no_match %r{create_table "ebooks'"}, schema end + + private + def quote_table_name(name) + @connection.quote_table_name(name) + end end if ActiveRecord::Base.connection.supports_views? @@ -83,11 +89,11 @@ if ActiveRecord::Base.connection.supports_views? private def create_view(name, query) - @connection.execute "CREATE VIEW #{name} AS #{query}" + @connection.execute "CREATE VIEW #{quote_table_name(name)} AS #{query}" end def drop_view(name) - @connection.execute "DROP VIEW #{name}" if @connection.view_exists? name + @connection.execute "DROP VIEW #{quote_table_name(name)}" if @connection.view_exists? name end end @@ -206,11 +212,11 @@ if ActiveRecord::Base.connection.respond_to?(:supports_materialized_views?) && private def create_view(name, query) - @connection.execute "CREATE MATERIALIZED VIEW #{name} AS #{query}" + @connection.execute "CREATE MATERIALIZED VIEW #{quote_table_name(name)} AS #{query}" end def drop_view(name) - @connection.execute "DROP MATERIALIZED VIEW #{name}" if @connection.view_exists? name + @connection.execute "DROP MATERIALIZED VIEW #{quote_table_name(name)}" if @connection.view_exists? name end end end -- cgit v1.2.3 From 32fc0331227ab9b14c875837ea66be8ee70ab96b Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Thu, 13 Oct 2016 22:24:49 +0000 Subject: Support index.length for MySQL 8.0.0-dmr MySQL 8.0.0-dmr `SUB_PART` column of `information_schema.statistics` changed to varbinary(12), which is bigint(3) in MySQL 5.6. Addresses #26774 --- .../lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 003ba6eff5..e7bd0e7c12 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -388,7 +388,7 @@ module ActiveRecord end indexes.last.columns << row[:Column_name] - indexes.last.lengths.merge!(row[:Column_name] => row[:Sub_part]) if row[:Sub_part] + indexes.last.lengths.merge!(row[:Column_name] => row[:Sub_part].to_i) if row[:Sub_part] end end -- cgit v1.2.3 From 77bdbb5f41307f5566f41964479369521a616223 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Fri, 14 Oct 2016 09:15:51 +0900 Subject: add missing closing tag [ci skip] --- activejob/lib/active_job/exceptions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activejob/lib/active_job/exceptions.rb b/activejob/lib/active_job/exceptions.rb index d236f03d53..c759068f9e 100644 --- a/activejob/lib/active_job/exceptions.rb +++ b/activejob/lib/active_job/exceptions.rb @@ -17,7 +17,7 @@ module ActiveJob # ==== Options # * :wait - Re-enqueues the job with a delay specified either in seconds (default: 3 seconds), # as a computing proc that the number of executions so far as an argument, or as a symbol reference of - # :exponentially_longer<>, which applies the wait algorithm of (executions ** 4) + 2 + # :exponentially_longer, which applies the wait algorithm of (executions ** 4) + 2 # (first wait 3s, then 18s, then 83s, etc) # * :attempts - Re-enqueues the job the specified number of times (default: 5 attempts) # * :queue - Re-enqueues the job on a different queue -- cgit v1.2.3 From e84ed4fd17a9e662d1da647c27ebeffa29c94a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Burgos?= Date: Thu, 15 Sep 2016 12:03:00 +0200 Subject: Use built-in #transform_values when available. The methods Hash#transform_values and Hash#transform_values! have been implemented in Ruby and they'll be available as part of the standard library. Here's the link to the discussion in Ruby's issue tracker: https://bugs.ruby-lang.org/issues/12512 These methods are implemented in C so they're expected to perform better. --- activesupport/lib/active_support/core_ext/hash/transform_values.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/hash/transform_values.rb b/activesupport/lib/active_support/core_ext/hash/transform_values.rb index 7d507ac998..a307996980 100644 --- a/activesupport/lib/active_support/core_ext/hash/transform_values.rb +++ b/activesupport/lib/active_support/core_ext/hash/transform_values.rb @@ -16,7 +16,7 @@ class Hash result[key] = yield(value) end result - end + end unless method_defined? :transform_values # Destructively converts all values using the +block+ operations. # Same as +transform_values+ but modifies +self+. @@ -25,5 +25,5 @@ class Hash each do |key, value| self[key] = yield(value) end - end + end unless method_defined? :transform_values! end -- cgit v1.2.3 From 994ce87bbda7cc4b0059c951b06cdd15dc26cb97 Mon Sep 17 00:00:00 2001 From: Iain Beeston Date: Mon, 3 Oct 2016 14:06:11 +0100 Subject: Moved database-specific ActiveModel types into ActiveRecord ie. DecimalWithoutScale, Text and UnsignedInteger --- activemodel/CHANGELOG.md | 4 ++++ activemodel/lib/active_model/type.rb | 4 ---- .../lib/active_model/type/decimal_without_scale.rb | 11 ----------- activemodel/lib/active_model/type/text.rb | 11 ----------- activemodel/lib/active_model/type/unsigned_integer.rb | 15 --------------- activemodel/test/cases/type/unsigned_integer_test.rb | 18 ------------------ activerecord/CHANGELOG.md | 4 ++++ activerecord/lib/active_record/type.rb | 6 +++--- .../lib/active_record/type/decimal_without_scale.rb | 9 +++++++++ activerecord/lib/active_record/type/text.rb | 9 +++++++++ .../lib/active_record/type/unsigned_integer.rb | 15 +++++++++++++++ activerecord/test/cases/type/unsigned_integer_test.rb | 17 +++++++++++++++++ 12 files changed, 61 insertions(+), 62 deletions(-) delete mode 100644 activemodel/lib/active_model/type/decimal_without_scale.rb delete mode 100644 activemodel/lib/active_model/type/text.rb delete mode 100644 activemodel/lib/active_model/type/unsigned_integer.rb delete mode 100644 activemodel/test/cases/type/unsigned_integer_test.rb create mode 100644 activerecord/lib/active_record/type/decimal_without_scale.rb create mode 100644 activerecord/lib/active_record/type/text.rb create mode 100644 activerecord/lib/active_record/type/unsigned_integer.rb create mode 100644 activerecord/test/cases/type/unsigned_integer_test.rb diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md index 10f1de6706..5242014a4f 100644 --- a/activemodel/CHANGELOG.md +++ b/activemodel/CHANGELOG.md @@ -1,3 +1,7 @@ +* Moved DecimalWithoutScale, Text, and UnsignedInteger from Active Model to Active Record + + *Iain Beeston* + * Removed deprecated `:tokenizer` in the length validator. *Rafael Mendonça França* diff --git a/activemodel/lib/active_model/type.rb b/activemodel/lib/active_model/type.rb index 313f17830f..a4e5a060f7 100644 --- a/activemodel/lib/active_model/type.rb +++ b/activemodel/lib/active_model/type.rb @@ -7,14 +7,11 @@ require "active_model/type/boolean" require "active_model/type/date" require "active_model/type/date_time" require "active_model/type/decimal" -require "active_model/type/decimal_without_scale" require "active_model/type/float" require "active_model/type/immutable_string" require "active_model/type/integer" require "active_model/type/string" -require "active_model/type/text" require "active_model/type/time" -require "active_model/type/unsigned_integer" require "active_model/type/registry" @@ -53,7 +50,6 @@ module ActiveModel register(:immutable_string, Type::ImmutableString) register(:integer, Type::Integer) register(:string, Type::String) - register(:text, Type::Text) register(:time, Type::Time) end end diff --git a/activemodel/lib/active_model/type/decimal_without_scale.rb b/activemodel/lib/active_model/type/decimal_without_scale.rb deleted file mode 100644 index 985e1038ed..0000000000 --- a/activemodel/lib/active_model/type/decimal_without_scale.rb +++ /dev/null @@ -1,11 +0,0 @@ -require "active_model/type/big_integer" - -module ActiveModel - module Type - class DecimalWithoutScale < BigInteger # :nodoc: - def type - :decimal - end - end - end -end diff --git a/activemodel/lib/active_model/type/text.rb b/activemodel/lib/active_model/type/text.rb deleted file mode 100644 index 7c0d647706..0000000000 --- a/activemodel/lib/active_model/type/text.rb +++ /dev/null @@ -1,11 +0,0 @@ -require "active_model/type/string" - -module ActiveModel - module Type - class Text < String # :nodoc: - def type - :text - end - end - end -end diff --git a/activemodel/lib/active_model/type/unsigned_integer.rb b/activemodel/lib/active_model/type/unsigned_integer.rb deleted file mode 100644 index 288fa23efe..0000000000 --- a/activemodel/lib/active_model/type/unsigned_integer.rb +++ /dev/null @@ -1,15 +0,0 @@ -module ActiveModel - module Type - class UnsignedInteger < Integer # :nodoc: - private - - def max_value - super * 2 - end - - def min_value - 0 - end - end - end -end diff --git a/activemodel/test/cases/type/unsigned_integer_test.rb b/activemodel/test/cases/type/unsigned_integer_test.rb deleted file mode 100644 index 026cb08a06..0000000000 --- a/activemodel/test/cases/type/unsigned_integer_test.rb +++ /dev/null @@ -1,18 +0,0 @@ -require "cases/helper" -require "active_model/type" - -module ActiveModel - module Type - class UnsignedIntegerTest < ActiveModel::TestCase - test "unsigned int max value is in range" do - assert_equal(4294967295, UnsignedInteger.new.serialize(4294967295)) - end - - test "minus value is out of range" do - assert_raises(ActiveModel::RangeError) do - UnsignedInteger.new.serialize(-1) - end - end - end - end -end diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 15b49e0a0b..2f4b7ca231 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,7 @@ +* Moved DecimalWithoutScale, Text, and UnsignedInteger from Active Model to Active Record + + *Iain Beeston* + * Fixed support for case insensitive comparisons of `text` columns in PostgreSQL. diff --git a/activerecord/lib/active_record/type.rb b/activerecord/lib/active_record/type.rb index 84373dddf2..3333a1a620 100644 --- a/activerecord/lib/active_record/type.rb +++ b/activerecord/lib/active_record/type.rb @@ -7,7 +7,10 @@ require "active_record/type/internal/timezone" require "active_record/type/date" require "active_record/type/date_time" +require "active_record/type/decimal_without_scale" require "active_record/type/time" +require "active_record/type/text" +require "active_record/type/unsigned_integer" require "active_record/type/serialized" require "active_record/type/adapter_specific_registry" @@ -54,12 +57,9 @@ module ActiveRecord Binary = ActiveModel::Type::Binary Boolean = ActiveModel::Type::Boolean Decimal = ActiveModel::Type::Decimal - DecimalWithoutScale = ActiveModel::Type::DecimalWithoutScale Float = ActiveModel::Type::Float Integer = ActiveModel::Type::Integer String = ActiveModel::Type::String - Text = ActiveModel::Type::Text - UnsignedInteger = ActiveModel::Type::UnsignedInteger register(:big_integer, Type::BigInteger, override: false) register(:binary, Type::Binary, override: false) diff --git a/activerecord/lib/active_record/type/decimal_without_scale.rb b/activerecord/lib/active_record/type/decimal_without_scale.rb new file mode 100644 index 0000000000..7ce33e9cd3 --- /dev/null +++ b/activerecord/lib/active_record/type/decimal_without_scale.rb @@ -0,0 +1,9 @@ +module ActiveRecord + module Type + class DecimalWithoutScale < ActiveModel::Type::BigInteger # :nodoc: + def type + :decimal + end + end + end +end diff --git a/activerecord/lib/active_record/type/text.rb b/activerecord/lib/active_record/type/text.rb new file mode 100644 index 0000000000..cb1949700a --- /dev/null +++ b/activerecord/lib/active_record/type/text.rb @@ -0,0 +1,9 @@ +module ActiveRecord + module Type + class Text < ActiveModel::Type::String # :nodoc: + def type + :text + end + end + end +end diff --git a/activerecord/lib/active_record/type/unsigned_integer.rb b/activerecord/lib/active_record/type/unsigned_integer.rb new file mode 100644 index 0000000000..9ae0109f9f --- /dev/null +++ b/activerecord/lib/active_record/type/unsigned_integer.rb @@ -0,0 +1,15 @@ +module ActiveRecord + module Type + class UnsignedInteger < ActiveModel::Type::Integer # :nodoc: + private + + def max_value + super * 2 + end + + def min_value + 0 + end + end + end +end diff --git a/activerecord/test/cases/type/unsigned_integer_test.rb b/activerecord/test/cases/type/unsigned_integer_test.rb new file mode 100644 index 0000000000..1cd4dbc2c5 --- /dev/null +++ b/activerecord/test/cases/type/unsigned_integer_test.rb @@ -0,0 +1,17 @@ +require "cases/helper" + +module ActiveRecord + module Type + class UnsignedIntegerTest < ActiveRecord::TestCase + test "unsigned int max value is in range" do + assert_equal(4294967295, UnsignedInteger.new.serialize(4294967295)) + end + + test "minus value is out of range" do + assert_raises(ActiveModel::RangeError) do + UnsignedInteger.new.serialize(-1) + end + end + end + end +end -- cgit v1.2.3 From bd8b50d2e512383bdb7abbde03f576d02145ae3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 14 Oct 2016 23:43:26 -0300 Subject: Add comment to remove code when we are in Ruby 2.4 --- activesupport/lib/active_support/core_ext/hash/transform_values.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/activesupport/lib/active_support/core_ext/hash/transform_values.rb b/activesupport/lib/active_support/core_ext/hash/transform_values.rb index a307996980..2f693bff0c 100644 --- a/activesupport/lib/active_support/core_ext/hash/transform_values.rb +++ b/activesupport/lib/active_support/core_ext/hash/transform_values.rb @@ -26,4 +26,5 @@ class Hash self[key] = yield(value) end end unless method_defined? :transform_values! + # TODO: Remove this file when supporting only Ruby 2.4+. end -- cgit v1.2.3 From 894c033843fe93f50bfe47c98a77bb3183988d09 Mon Sep 17 00:00:00 2001 From: Iain Beeston Date: Fri, 14 Oct 2016 17:21:11 +0100 Subject: Refactored ActiveModel::Type tests into their own files --- activemodel/test/cases/type/big_integer_test.rb | 24 ++++ activemodel/test/cases/type/binary_test.rb | 15 +++ activemodel/test/cases/type/boolean_test.rb | 39 +++++++ activemodel/test/cases/type/date_test.rb | 19 ++++ activemodel/test/cases/type/date_time_test.rb | 38 +++++++ activemodel/test/cases/type/float_test.rb | 22 ++++ .../test/cases/type/immutable_string_test.rb | 21 ++++ activemodel/test/cases/type/integer_test.rb | 7 ++ activemodel/test/cases/type/registry_test.rb | 52 ++++----- activemodel/test/cases/type/string_test.rb | 37 +++--- activemodel/test/cases/type/time_test.rb | 21 ++++ activemodel/test/cases/type/value_test.rb | 14 +++ activemodel/test/cases/types_test.rb | 125 --------------------- 13 files changed, 266 insertions(+), 168 deletions(-) create mode 100644 activemodel/test/cases/type/big_integer_test.rb create mode 100644 activemodel/test/cases/type/binary_test.rb create mode 100644 activemodel/test/cases/type/boolean_test.rb create mode 100644 activemodel/test/cases/type/date_test.rb create mode 100644 activemodel/test/cases/type/date_time_test.rb create mode 100644 activemodel/test/cases/type/float_test.rb create mode 100644 activemodel/test/cases/type/immutable_string_test.rb create mode 100644 activemodel/test/cases/type/time_test.rb create mode 100644 activemodel/test/cases/type/value_test.rb delete mode 100644 activemodel/test/cases/types_test.rb diff --git a/activemodel/test/cases/type/big_integer_test.rb b/activemodel/test/cases/type/big_integer_test.rb new file mode 100644 index 0000000000..db1d215083 --- /dev/null +++ b/activemodel/test/cases/type/big_integer_test.rb @@ -0,0 +1,24 @@ +require "cases/helper" +require "active_model/type" + +module ActiveModel + module Type + class BigIntegerTest < ActiveModel::TestCase + def test_type_cast_big_integer + type = Type::BigInteger.new + assert_equal 1, type.cast(1) + assert_equal 1, type.cast("1") + end + + def test_small_values + type = Type::BigInteger.new + assert_equal -9999999999999999999999999999999, type.serialize(-9999999999999999999999999999999) + end + + def test_large_values + type = Type::BigInteger.new + assert_equal 9999999999999999999999999999999, type.serialize(9999999999999999999999999999999) + end + end + end +end diff --git a/activemodel/test/cases/type/binary_test.rb b/activemodel/test/cases/type/binary_test.rb new file mode 100644 index 0000000000..e6a32dbeec --- /dev/null +++ b/activemodel/test/cases/type/binary_test.rb @@ -0,0 +1,15 @@ +require "cases/helper" +require "active_model/type" + +module ActiveModel + module Type + class BinaryTest < ActiveModel::TestCase + def test_type_cast_binary + type = Type::Binary.new + assert_equal nil, type.cast(nil) + assert_equal "1", type.cast("1") + assert_equal 1, type.cast(1) + end + end + end +end diff --git a/activemodel/test/cases/type/boolean_test.rb b/activemodel/test/cases/type/boolean_test.rb new file mode 100644 index 0000000000..92e5aebfb7 --- /dev/null +++ b/activemodel/test/cases/type/boolean_test.rb @@ -0,0 +1,39 @@ +require "cases/helper" +require "active_model/type" + +module ActiveModel + module Type + class BooleanTest < ActiveModel::TestCase + def test_type_cast_boolean + type = Type::Boolean.new + assert type.cast("").nil? + assert type.cast(nil).nil? + + assert type.cast(true) + assert type.cast(1) + assert type.cast("1") + assert type.cast("t") + assert type.cast("T") + assert type.cast("true") + assert type.cast("TRUE") + assert type.cast("on") + assert type.cast("ON") + assert type.cast(" ") + assert type.cast("\u3000\r\n") + assert type.cast("\u0000") + assert type.cast("SOMETHING RANDOM") + + # explicitly check for false vs nil + assert_equal false, type.cast(false) + assert_equal false, type.cast(0) + assert_equal false, type.cast("0") + assert_equal false, type.cast("f") + assert_equal false, type.cast("F") + assert_equal false, type.cast("false") + assert_equal false, type.cast("FALSE") + assert_equal false, type.cast("off") + assert_equal false, type.cast("OFF") + end + end + end +end diff --git a/activemodel/test/cases/type/date_test.rb b/activemodel/test/cases/type/date_test.rb new file mode 100644 index 0000000000..44e20a327b --- /dev/null +++ b/activemodel/test/cases/type/date_test.rb @@ -0,0 +1,19 @@ +require "cases/helper" +require "active_model/type" + +module ActiveModel + module Type + class DateTest < ActiveModel::TestCase + def test_type_cast_date + type = Type::Date.new + assert_equal nil, type.cast(nil) + assert_equal nil, type.cast("") + assert_equal nil, type.cast(" ") + assert_equal nil, type.cast("ABC") + + date_string = ::Time.now.utc.strftime("%F") + assert_equal date_string, type.cast(date_string).strftime("%F") + end + end + end +end diff --git a/activemodel/test/cases/type/date_time_test.rb b/activemodel/test/cases/type/date_time_test.rb new file mode 100644 index 0000000000..fb82260d2b --- /dev/null +++ b/activemodel/test/cases/type/date_time_test.rb @@ -0,0 +1,38 @@ +require "cases/helper" +require "active_model/type" + +module ActiveModel + module Type + class DateTimeTest < ActiveModel::TestCase + def test_type_cast_datetime_and_timestamp + type = Type::DateTime.new + assert_equal nil, type.cast(nil) + assert_equal nil, type.cast("") + assert_equal nil, type.cast(" ") + assert_equal nil, type.cast("ABC") + + datetime_string = ::Time.now.utc.strftime("%FT%T") + assert_equal datetime_string, type.cast(datetime_string).strftime("%FT%T") + end + + def test_string_to_time_with_timezone + ["UTC", "US/Eastern"].each do |zone| + with_timezone_config default: zone do + type = Type::DateTime.new + assert_equal ::Time.utc(2013, 9, 4, 0, 0, 0), type.cast("Wed, 04 Sep 2013 03:00:00 EAT") + end + end + end + + private + + def with_timezone_config(default:) + old_zone_default = ::Time.zone_default + ::Time.zone_default = ::Time.find_zone(default) + yield + ensure + ::Time.zone_default = old_zone_default + end + end + end +end diff --git a/activemodel/test/cases/type/float_test.rb b/activemodel/test/cases/type/float_test.rb new file mode 100644 index 0000000000..2e34f57f7e --- /dev/null +++ b/activemodel/test/cases/type/float_test.rb @@ -0,0 +1,22 @@ +require "cases/helper" +require "active_model/type" + +module ActiveModel + module Type + class FloatTest < ActiveModel::TestCase + def test_type_cast_float + type = Type::Float.new + assert_equal 1.0, type.cast("1") + end + + def test_changing_float + type = Type::Float.new + + assert type.changed?(5.0, 5.0, "5wibble") + assert_not type.changed?(5.0, 5.0, "5") + assert_not type.changed?(5.0, 5.0, "5.0") + assert_not type.changed?(nil, nil, nil) + end + end + end +end diff --git a/activemodel/test/cases/type/immutable_string_test.rb b/activemodel/test/cases/type/immutable_string_test.rb new file mode 100644 index 0000000000..23e58974fb --- /dev/null +++ b/activemodel/test/cases/type/immutable_string_test.rb @@ -0,0 +1,21 @@ +require "cases/helper" +require "active_model/type" + +module ActiveModel + module Type + class ImmutableStringTest < ActiveModel::TestCase + test "cast strings are frozen" do + s = "foo" + type = Type::ImmutableString.new + assert_equal true, type.cast(s).frozen? + end + + test "immutable strings are not duped coming out" do + s = "foo" + type = Type::ImmutableString.new + assert_same s, type.cast(s) + assert_same s, type.deserialize(s) + end + end + end +end diff --git a/activemodel/test/cases/type/integer_test.rb b/activemodel/test/cases/type/integer_test.rb index e00246b602..d81ce189e6 100644 --- a/activemodel/test/cases/type/integer_test.rb +++ b/activemodel/test/cases/type/integer_test.rb @@ -1,5 +1,6 @@ require "cases/helper" require "active_model/type" +require "active_support/core_ext/numeric/time" module ActiveModel module Type @@ -41,6 +42,12 @@ module ActiveModel assert_equal 0, type.serialize(false) end + test "casting duration" do + type = Type::Integer.new + assert_equal 1800, type.cast(30.minutes) + assert_equal 7200, type.cast(2.hours) + end + test "changed?" do type = Type::Integer.new diff --git a/activemodel/test/cases/type/registry_test.rb b/activemodel/test/cases/type/registry_test.rb index 2a48998a62..927b6d0307 100644 --- a/activemodel/test/cases/type/registry_test.rb +++ b/activemodel/test/cases/type/registry_test.rb @@ -2,38 +2,40 @@ require "cases/helper" require "active_model/type" module ActiveModel - class RegistryTest < ActiveModel::TestCase - test "a class can be registered for a symbol" do - registry = Type::Registry.new - registry.register(:foo, ::String) - registry.register(:bar, ::Array) + module Type + class RegistryTest < ActiveModel::TestCase + test "a class can be registered for a symbol" do + registry = Type::Registry.new + registry.register(:foo, ::String) + registry.register(:bar, ::Array) - assert_equal "", registry.lookup(:foo) - assert_equal [], registry.lookup(:bar) - end - - test "a block can be registered" do - registry = Type::Registry.new - registry.register(:foo) do |*args| - [*args, "block for foo"] + assert_equal "", registry.lookup(:foo) + assert_equal [], registry.lookup(:bar) end - registry.register(:bar) do |*args| - [*args, "block for bar"] + + test "a block can be registered" do + registry = Type::Registry.new + registry.register(:foo) do |*args| + [*args, "block for foo"] + end + registry.register(:bar) do |*args| + [*args, "block for bar"] + end + + assert_equal [:foo, 1, "block for foo"], registry.lookup(:foo, 1) + assert_equal [:foo, 2, "block for foo"], registry.lookup(:foo, 2) + assert_equal [:bar, 1, 2, 3, "block for bar"], registry.lookup(:bar, 1, 2, 3) end - assert_equal [:foo, 1, "block for foo"], registry.lookup(:foo, 1) - assert_equal [:foo, 2, "block for foo"], registry.lookup(:foo, 2) - assert_equal [:bar, 1, 2, 3, "block for bar"], registry.lookup(:bar, 1, 2, 3) - end + test "a reasonable error is given when no type is found" do + registry = Type::Registry.new - test "a reasonable error is given when no type is found" do - registry = Type::Registry.new + e = assert_raises(ArgumentError) do + registry.lookup(:foo) + end - e = assert_raises(ArgumentError) do - registry.lookup(:foo) + assert_equal "Unknown type :foo", e.message end - - assert_equal "Unknown type :foo", e.message end end end diff --git a/activemodel/test/cases/type/string_test.rb b/activemodel/test/cases/type/string_test.rb index 7b25a1ef74..222083817e 100644 --- a/activemodel/test/cases/type/string_test.rb +++ b/activemodel/test/cases/type/string_test.rb @@ -2,26 +2,27 @@ require "cases/helper" require "active_model/type" module ActiveModel - class StringTypeTest < ActiveModel::TestCase - test "type casting" do - type = Type::String.new - assert_equal "t", type.cast(true) - assert_equal "f", type.cast(false) - assert_equal "123", type.cast(123) - end + module Type + class StringTest < ActiveModel::TestCase + test "type casting" do + type = Type::String.new + assert_equal "t", type.cast(true) + assert_equal "f", type.cast(false) + assert_equal "123", type.cast(123) + end - test "immutable strings are not duped coming out" do - s = "foo" - type = Type::ImmutableString.new - assert_same s, type.cast(s) - assert_same s, type.deserialize(s) - end + test "cast strings are mutable" do + s = "foo" + type = Type::String.new + assert_equal false, type.cast(s).frozen? + end - test "values are duped coming out" do - s = "foo" - type = Type::String.new - assert_not_same s, type.cast(s) - assert_not_same s, type.deserialize(s) + test "values are duped coming out" do + s = "foo" + type = Type::String.new + assert_not_same s, type.cast(s) + assert_not_same s, type.deserialize(s) + end end end end diff --git a/activemodel/test/cases/type/time_test.rb b/activemodel/test/cases/type/time_test.rb new file mode 100644 index 0000000000..a6a79833e6 --- /dev/null +++ b/activemodel/test/cases/type/time_test.rb @@ -0,0 +1,21 @@ +require "cases/helper" +require "active_model/type" + +module ActiveModel + module Type + class TimeTest < ActiveModel::TestCase + def test_type_cast_time + type = Type::Time.new + assert_equal nil, type.cast(nil) + assert_equal nil, type.cast("") + assert_equal nil, type.cast("ABC") + + time_string = ::Time.now.utc.strftime("%T") + assert_equal time_string, type.cast(time_string).strftime("%T") + + assert_equal ::Time.utc(2000, 1, 1, 16, 45, 54), type.cast("2015-06-13T19:45:54+03:00") + assert_equal ::Time.utc(1999, 12, 31, 21, 7, 8), type.cast("06:07:08+09:00") + end + end + end +end diff --git a/activemodel/test/cases/type/value_test.rb b/activemodel/test/cases/type/value_test.rb new file mode 100644 index 0000000000..d8b3e7f164 --- /dev/null +++ b/activemodel/test/cases/type/value_test.rb @@ -0,0 +1,14 @@ +require "cases/helper" +require "active_model/type" + +module ActiveModel + module Type + class ValueTest < ActiveModel::TestCase + def test_type_equality + assert_equal Type::Value.new, Type::Value.new + assert_not_equal Type::Value.new, Type::Integer.new + assert_not_equal Type::Value.new(precision: 1), Type::Value.new(precision: 2) + end + end + end +end diff --git a/activemodel/test/cases/types_test.rb b/activemodel/test/cases/types_test.rb deleted file mode 100644 index c46775cb41..0000000000 --- a/activemodel/test/cases/types_test.rb +++ /dev/null @@ -1,125 +0,0 @@ -require "cases/helper" -require "active_model/type" -require "active_support/core_ext/numeric/time" - -module ActiveModel - class TypesTest < ActiveModel::TestCase - def test_type_cast_boolean - type = Type::Boolean.new - assert type.cast("").nil? - assert type.cast(nil).nil? - - assert type.cast(true) - assert type.cast(1) - assert type.cast("1") - assert type.cast("t") - assert type.cast("T") - assert type.cast("true") - assert type.cast("TRUE") - assert type.cast("on") - assert type.cast("ON") - assert type.cast(" ") - assert type.cast("\u3000\r\n") - assert type.cast("\u0000") - assert type.cast("SOMETHING RANDOM") - - # explicitly check for false vs nil - assert_equal false, type.cast(false) - assert_equal false, type.cast(0) - assert_equal false, type.cast("0") - assert_equal false, type.cast("f") - assert_equal false, type.cast("F") - assert_equal false, type.cast("false") - assert_equal false, type.cast("FALSE") - assert_equal false, type.cast("off") - assert_equal false, type.cast("OFF") - end - - def test_type_cast_float - type = Type::Float.new - assert_equal 1.0, type.cast("1") - end - - def test_changing_float - type = Type::Float.new - - assert type.changed?(5.0, 5.0, "5wibble") - assert_not type.changed?(5.0, 5.0, "5") - assert_not type.changed?(5.0, 5.0, "5.0") - assert_not type.changed?(nil, nil, nil) - end - - def test_type_cast_binary - type = Type::Binary.new - assert_equal nil, type.cast(nil) - assert_equal "1", type.cast("1") - assert_equal 1, type.cast(1) - end - - def test_type_cast_time - type = Type::Time.new - assert_equal nil, type.cast(nil) - assert_equal nil, type.cast("") - assert_equal nil, type.cast("ABC") - - time_string = Time.now.utc.strftime("%T") - assert_equal time_string, type.cast(time_string).strftime("%T") - - assert_equal ::Time.utc(2000, 1, 1, 16, 45, 54), type.cast("2015-06-13T19:45:54+03:00") - assert_equal ::Time.utc(1999, 12, 31, 21, 7, 8), type.cast("06:07:08+09:00") - end - - def test_type_cast_datetime_and_timestamp - type = Type::DateTime.new - assert_equal nil, type.cast(nil) - assert_equal nil, type.cast("") - assert_equal nil, type.cast(" ") - assert_equal nil, type.cast("ABC") - - datetime_string = Time.now.utc.strftime("%FT%T") - assert_equal datetime_string, type.cast(datetime_string).strftime("%FT%T") - end - - def test_type_cast_date - type = Type::Date.new - assert_equal nil, type.cast(nil) - assert_equal nil, type.cast("") - assert_equal nil, type.cast(" ") - assert_equal nil, type.cast("ABC") - - date_string = Time.now.utc.strftime("%F") - assert_equal date_string, type.cast(date_string).strftime("%F") - end - - def test_type_cast_duration_to_integer - type = Type::Integer.new - assert_equal 1800, type.cast(30.minutes) - assert_equal 7200, type.cast(2.hours) - end - - def test_string_to_time_with_timezone - ["UTC", "US/Eastern"].each do |zone| - with_timezone_config default: zone do - type = Type::DateTime.new - assert_equal Time.utc(2013, 9, 4, 0, 0, 0), type.cast("Wed, 04 Sep 2013 03:00:00 EAT") - end - end - end - - def test_type_equality - assert_equal Type::Value.new, Type::Value.new - assert_not_equal Type::Value.new, Type::Integer.new - assert_not_equal Type::Value.new(precision: 1), Type::Value.new(precision: 2) - end - - private - - def with_timezone_config(default:) - old_zone_default = ::Time.zone_default - ::Time.zone_default = ::Time.find_zone(default) - yield - ensure - ::Time.zone_default = old_zone_default - end - end -end -- cgit v1.2.3 From f2f9b8868590bb4be8965583096862e29b9f83fb Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Sat, 15 Oct 2016 12:27:18 +0200 Subject: Introduce a benchmark template [ci skip] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This replaces boilerplate in the “benchmark your code” section of the contributors’ guide with an executable template. I also amended the text to encourage best practices and codified it in the template. For now this is only good for relatively self-contained changes that can be inlined into a simple script. In the future, this can be expanded to cover how to measure the difference between two commits. The output looks like this: ``` ==================================== Empty ===================================== Warming up -------------------------------------- blank? 225.963k i/100ms fast_blank? 238.147k i/100ms Calculating ------------------------------------- blank? 8.825M (± 6.4%) i/s - 44.063M in 5.014824s fast_blank? 9.311M (± 6.3%) i/s - 46.439M in 5.009153s Comparison: fast_blank?: 9310694.8 i/s blank?: 8824801.7 i/s - same-ish: difference falls within error ================================= Single Space ================================= Warming up -------------------------------------- blank? 56.581k i/100ms fast_blank? 232.774k i/100ms Calculating ------------------------------------- blank? 813.985k (±16.7%) i/s - 4.017M in 5.076576s fast_blank? 9.547M (± 5.2%) i/s - 47.719M in 5.013204s Comparison: fast_blank?: 9547414.0 i/s blank?: 813985.0 i/s - 11.73x slower ================================== Two Spaces ================================== Warming up -------------------------------------- blank? 58.265k i/100ms fast_blank? 244.056k i/100ms Calculating ------------------------------------- blank? 823.343k (±16.2%) i/s - 4.020M in 5.014213s fast_blank? 9.484M (± 4.9%) i/s - 47.347M in 5.005339s Comparison: fast_blank?: 9484021.6 i/s blank?: 823343.1 i/s - 11.52x slower =============================== Mixed Whitspaces =============================== Warming up -------------------------------------- blank? 53.919k i/100ms fast_blank? 237.103k i/100ms Calculating ------------------------------------- blank? 763.435k (±16.8%) i/s - 3.720M in 5.018029s fast_blank? 9.672M (± 5.8%) i/s - 48.369M in 5.019356s Comparison: fast_blank?: 9672467.2 i/s blank?: 763435.4 i/s - 12.67x slower =============================== Very Long String =============================== Warming up -------------------------------------- blank? 34.037k i/100ms fast_blank? 240.366k i/100ms Calculating ------------------------------------- blank? 409.731k (± 8.9%) i/s - 2.042M in 5.028235s fast_blank? 9.794M (± 4.3%) i/s - 49.035M in 5.016328s Comparison: fast_blank?: 9794225.2 i/s blank?: 409731.4 i/s - 23.90x slower ``` --- guides/bug_report_templates/benchmark.rb | 49 ++++++++++++++++++++++++++ guides/source/contributing_to_ruby_on_rails.md | 45 ++++++++++------------- 2 files changed, 67 insertions(+), 27 deletions(-) create mode 100644 guides/bug_report_templates/benchmark.rb diff --git a/guides/bug_report_templates/benchmark.rb b/guides/bug_report_templates/benchmark.rb new file mode 100644 index 0000000000..ae51d7027f --- /dev/null +++ b/guides/bug_report_templates/benchmark.rb @@ -0,0 +1,49 @@ +begin + require "bundler/inline" +rescue LoadError => e + $stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" + raise e +end + +gemfile(true) do + source "https://rubygems.org" + gem "rails", github: "rails/rails" + gem "benchmark-ips" +end + +require "active_support" +require "active_support/core_ext/object/blank" + +# Your patch goes here. +class String + def fast_blank? + true + end +end + +# Enumerate some representative scenarios here. +# +# It is very easy to make an optimization that improves performance for a +# specific scenario you care about but regresses on other common cases. +# Therefore, you should test your change against a list of representative +# scenarios. Ideally, they should be based on real-world scenarios extracted +# from production applications. +SCENARIOS = { + "Empty" => "", + "Single Space" => " ", + "Two Spaces" => " ", + "Mixed Whitspaces" => " \t\r\n", + "Very Long String" => " " * 100 +} + +SCENARIOS.each_pair do |name, value| + puts + puts " #{name} ".center(80, "=") + puts + + Benchmark.ips do |x| + x.report('blank?') { value.blank? } + x.report('fast_blank?') { value.fast_blank? } + x.compare! + end +end diff --git a/guides/source/contributing_to_ruby_on_rails.md b/guides/source/contributing_to_ruby_on_rails.md index 4f938f5deb..5791e7a12a 100644 --- a/guides/source/contributing_to_ruby_on_rails.md +++ b/guides/source/contributing_to_ruby_on_rails.md @@ -270,33 +270,24 @@ The above are guidelines - please use your best judgment in using them. ### Benchmark Your Code -If your change has an impact on the performance of Rails, please use the -[benchmark-ips](https://github.com/evanphx/benchmark-ips) gem to provide -benchmark results for comparison. - -Here's an example of using benchmark-ips: - -```ruby -require 'benchmark/ips' - -Benchmark.ips do |x| - x.report('addition') { 1 + 2 } - x.report('addition with send') { 1.send(:+, 2) } -end -``` - -This will generate a report with the following information: - -``` -Calculating ------------------------------------- - addition 132.013k i/100ms - addition with send 125.413k i/100ms -------------------------------------------------- - addition 9.677M (± 1.7%) i/s - 48.449M - addition with send 6.794M (± 1.1%) i/s - 33.987M -``` - -Please see the benchmark/ips [README](https://github.com/evanphx/benchmark-ips/blob/master/README.md) for more information. +For changes that might have an impact on performance, please benchmark your +code and measure the impact. Please share the benchmark script you used as well +as the results. You should consider including these information in your commit +message, which allows future contributors to easily verify your findings and +determine if they are still relevant. (For example, future optimizations in the +Ruby VM might render certain optimizations unnecessary.) + +It is very easy to make an optimization that improves performance for a +specific scenario you care about but regresses on other common cases. +Therefore, you should test your change against a list of representative +scenarios. Ideally, they should be based on real-world scenarios extracted +from production applications. + +You can use the [benchmark template](https://github.com/rails/rails/blob/master/guides/bug_report_templates/benchmark.rb) +as a starting point. It includes the boilerplate code to setup a benchmark +using the [benchmark-ips](https://github.com/evanphx/benchmark-ips) gem. The +template is designed for testing relatively self-contained changes that can be +inlined into the script. ### Running Tests -- cgit v1.2.3 From 6fccd7b6293dcae383757379c5c3809c6674084e Mon Sep 17 00:00:00 2001 From: Sammy Larbi Date: Thu, 13 Oct 2016 17:53:41 -0500 Subject: Allow any key in Renderer environment hash When rendering arbitrary templates, it is helpful to not overwrite `env` keys with nil if they don't match any found in the `RACK_KEY_TRANSLATION` This allows the developer to set the environment to exactly what is needed for rendering. --- actionpack/CHANGELOG.md | 5 +++++ actionpack/lib/action_controller/renderer.rb | 4 +++- actionpack/test/controller/renderer_test.rb | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index eef3db8f24..c9c347ea26 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,8 @@ +* Allow keys not found in RACK_KEY_TRANSLATION for setting the environment when rendering + arbitrary templates. + + *Sammy Larbi* + * Remove deprecated support to non-keyword arguments in `ActionDispatch::IntegrationTest#process`, `#get`, `#post`, `#patch`, `#put`, `#delete`, and `#head`. diff --git a/actionpack/lib/action_controller/renderer.rb b/actionpack/lib/action_controller/renderer.rb index 0739f16965..243a54330e 100644 --- a/actionpack/lib/action_controller/renderer.rb +++ b/actionpack/lib/action_controller/renderer.rb @@ -102,7 +102,9 @@ module ActionController method: ->(v) { v.upcase }, } - def rack_key_for(key); RACK_KEY_TRANSLATION[key]; end + def rack_key_for(key) + RACK_KEY_TRANSLATION.fetch(key, key.to_s) + end def rack_value_for(key, value) RACK_VALUE_TRANSLATION.fetch(key, IDENTITY).call value diff --git a/actionpack/test/controller/renderer_test.rb b/actionpack/test/controller/renderer_test.rb index d6f09f2d90..866600b935 100644 --- a/actionpack/test/controller/renderer_test.rb +++ b/actionpack/test/controller/renderer_test.rb @@ -60,6 +60,14 @@ class RendererTest < ActiveSupport::TestCase assert_equal "true", content end + test "rendering with custom env using a key that is not in RACK_KEY_TRANSLATION" do + value = "warden is here" + renderer = ApplicationController.renderer.new warden: value + content = renderer.render inline: "<%= request.env['warden'] %>" + + assert_equal value, content + end + test "rendering with defaults" do renderer = ApplicationController.renderer.new https: true content = renderer.render inline: "<%= request.ssl? %>" -- cgit v1.2.3 From 1f979184efc27e73f42c5d86c7f19437c6719612 Mon Sep 17 00:00:00 2001 From: Zach Aysan Date: Sat, 15 Oct 2016 08:52:07 -0400 Subject: Make `process` a non-private method and update documentation. --- .../lib/action_dispatch/testing/integration.rb | 198 +++++++++++---------- 1 file changed, 100 insertions(+), 98 deletions(-) diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index d137473ef4..6c2d4c3c42 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -11,62 +11,37 @@ require "action_dispatch/testing/request_encoder" module ActionDispatch module Integration #:nodoc: module RequestHelpers - # Performs a GET request with the given parameters. - # - # - +path+: The URI (as a String) on which you want to perform a GET - # request. - # - +params+: The HTTP parameters that you want to pass. This may - # be +nil+, - # a Hash, or a String that is appropriately encoded - # (application/x-www-form-urlencoded or - # multipart/form-data). - # - +headers+: Additional headers to pass, as a Hash. The headers will be - # merged into the Rack env hash. - # - +env+: Additional env to pass, as a Hash. The headers will be - # merged into the Rack env hash. - # - # This method returns a Response object, which one can use to - # inspect the details of the response. Furthermore, if this method was - # called from an ActionDispatch::IntegrationTest object, then that - # object's @response instance variable will point to the same - # response object. - # - # You can also perform POST, PATCH, PUT, DELETE, and HEAD requests with - # +#post+, +#patch+, +#put+, +#delete+, and +#head+. - # - # Example: - # - # get '/feed', params: { since: 201501011400 } - # post '/profile', headers: { "X-Test-Header" => "testvalue" } + # Performs a GET request with the given parameters. See +#process+ for more + # details. def get(path, **args) process(:get, path, **args) end - # Performs a POST request with the given parameters. See +#get+ for more + # Performs a POST request with the given parameters. See +#process+ for more # details. def post(path, **args) process(:post, path, **args) end - # Performs a PATCH request with the given parameters. See +#get+ for more + # Performs a PATCH request with the given parameters. See +#process+ for more # details. def patch(path, **args) process(:patch, path, **args) end - # Performs a PUT request with the given parameters. See +#get+ for more + # Performs a PUT request with the given parameters. See +#process+ for more # details. def put(path, **args) process(:put, path, **args) end - # Performs a DELETE request with the given parameters. See +#get+ for + # Performs a DELETE request with the given parameters. See +#process+ for # more details. def delete(path, **args) process(:delete, path, **args) end - # Performs a HEAD request with the given parameters. See +#get+ for more + # Performs a HEAD request with the given parameters. See +#process+ for more # details. def head(path, *args) process(:head, path, *args) @@ -198,91 +173,118 @@ module ActionDispatch @https end - # Set the host name to use in the next request. + # Performs the actual request. # - # session.host! "www.example.com" - alias :host! :host= - - private - def _mock_session - @_mock_session ||= Rack::MockSession.new(@app, host) + # - +method+: The HTTP method (GET, POST, PATCH, PUT, DELETE, HEAD, OPTIONS) + # as a symbol. + # - +path+: The URI (as a String) on which you want to perform a GET + # request. + # - +params+: The HTTP parameters that you want to pass. This may + # be +nil+, + # a Hash, or a String that is appropriately encoded + # (application/x-www-form-urlencoded or + # multipart/form-data). + # - +headers+: Additional headers to pass, as a Hash. The headers will be + # merged into the Rack env hash. + # - +env+: Additional env to pass, as a Hash. The headers will be + # merged into the Rack env hash. + # + # This method is rarely used directly. Use +#get+, +#post+, or other standard + # HTTP methods in integration tests. Only +#process+ is only required for an + # OPTIONS request. + # + # This method returns a Response object, which one can use to + # inspect the details of the response. Furthermore, if this method was + # called from an ActionDispatch::IntegrationTest object, then that + # object's @response instance variable will point to the same + # response object. + # + # Examples: + # process :get, '/author', params: { since: 201501011400 } + def process(method, path, params: nil, headers: nil, env: nil, xhr: false, as: nil) + request_encoder = RequestEncoder.encoder(as) + headers ||= {} + + if method == :get && as == :json && params + headers["X-Http-Method-Override"] = "GET" + method = :post end - # Performs the actual request. - def process(method, path, params: nil, headers: nil, env: nil, xhr: false, as: nil) - request_encoder = RequestEncoder.encoder(as) - headers ||= {} + if path =~ %r{://} + path = build_expanded_path(path, request_encoder) do |location| + https! URI::HTTPS === location if location.scheme - if method == :get && as == :json && params - headers["X-Http-Method-Override"] = "GET" - method = :post + if url_host = location.host + default = Rack::Request::DEFAULT_PORTS[location.scheme] + url_host += ":#{location.port}" if default != location.port + host! url_host + end end + elsif as + path = build_expanded_path(path, request_encoder) + end - if path =~ %r{://} - path = build_expanded_path(path, request_encoder) do |location| - https! URI::HTTPS === location if location.scheme + hostname, port = host.split(":") - if url_host = location.host - default = Rack::Request::DEFAULT_PORTS[location.scheme] - url_host += ":#{location.port}" if default != location.port - host! url_host - end - end - elsif as - path = build_expanded_path(path, request_encoder) - end + request_env = { + :method => method, + :params => request_encoder.encode_params(params), - hostname, port = host.split(":") + "SERVER_NAME" => hostname, + "SERVER_PORT" => port || (https? ? "443" : "80"), + "HTTPS" => https? ? "on" : "off", + "rack.url_scheme" => https? ? "https" : "http", - request_env = { - :method => method, - :params => request_encoder.encode_params(params), + "REQUEST_URI" => path, + "HTTP_HOST" => host, + "REMOTE_ADDR" => remote_addr, + "CONTENT_TYPE" => request_encoder.content_type, + "HTTP_ACCEPT" => accept + } - "SERVER_NAME" => hostname, - "SERVER_PORT" => port || (https? ? "443" : "80"), - "HTTPS" => https? ? "on" : "off", - "rack.url_scheme" => https? ? "https" : "http", + wrapped_headers = Http::Headers.from_hash({}) + wrapped_headers.merge!(headers) if headers - "REQUEST_URI" => path, - "HTTP_HOST" => host, - "REMOTE_ADDR" => remote_addr, - "CONTENT_TYPE" => request_encoder.content_type, - "HTTP_ACCEPT" => accept - } + if xhr + wrapped_headers["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest" + wrapped_headers["HTTP_ACCEPT"] ||= [Mime[:js], Mime[:html], Mime[:xml], "text/xml", "*/*"].join(", ") + end - wrapped_headers = Http::Headers.from_hash({}) - wrapped_headers.merge!(headers) if headers + # this modifies the passed request_env directly + if wrapped_headers.present? + Http::Headers.from_hash(request_env).merge!(wrapped_headers) + end + if env.present? + Http::Headers.from_hash(request_env).merge!(env) + end - if xhr - wrapped_headers["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest" - wrapped_headers["HTTP_ACCEPT"] ||= [Mime[:js], Mime[:html], Mime[:xml], "text/xml", "*/*"].join(", ") - end + session = Rack::Test::Session.new(_mock_session) - # this modifies the passed request_env directly - if wrapped_headers.present? - Http::Headers.from_hash(request_env).merge!(wrapped_headers) - end - if env.present? - Http::Headers.from_hash(request_env).merge!(env) - end + # NOTE: rack-test v0.5 doesn't build a default uri correctly + # Make sure requested path is always a full uri + session.request(build_full_uri(path, request_env), request_env) - session = Rack::Test::Session.new(_mock_session) + @request_count += 1 + @request = ActionDispatch::Request.new(session.last_request.env) + response = _mock_session.last_response + @response = ActionDispatch::TestResponse.from_response(response) + @response.request = @request + @html_document = nil + @url_options = nil - # NOTE: rack-test v0.5 doesn't build a default uri correctly - # Make sure requested path is always a full uri - session.request(build_full_uri(path, request_env), request_env) + @controller = @request.controller_instance - @request_count += 1 - @request = ActionDispatch::Request.new(session.last_request.env) - response = _mock_session.last_response - @response = ActionDispatch::TestResponse.from_response(response) - @response.request = @request - @html_document = nil - @url_options = nil + response.status + end - @controller = @request.controller_instance + # Set the host name to use in the next request. + # + # session.host! "www.example.com" + alias :host! :host= - response.status + private + def _mock_session + @_mock_session ||= Rack::MockSession.new(@app, host) end def build_full_uri(path, env) -- cgit v1.2.3 From be6990bf01f422ab79dcd4c8660a04ecdc5a9a5c Mon Sep 17 00:00:00 2001 From: rmarone Date: Sat, 15 Oct 2016 09:20:41 -0400 Subject: Pull request for ticket 26769 (#26770) * Clarify the default behavior of log_formatter Updates language to remove reference to production.rb and fix quoting --- guides/source/configuring.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 022886a122..79ded19c27 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -110,7 +110,7 @@ numbers. By default, Rails filters out passwords by adding `Rails.application.co * `config.force_ssl` forces all requests to be served over HTTPS by using the `ActionDispatch::SSL` middleware, and sets `config.action_mailer.default_url_options` to be `{ protocol: 'https' }`. This can be configured by setting `config.ssl_options` - see the [ActionDispatch::SSL documentation](http://edgeapi.rubyonrails.org/classes/ActionDispatch/SSL.html) for details. -* `config.log_formatter` defines the formatter of the Rails logger. This option defaults to an instance of `ActiveSupport::Logger::SimpleFormatter` for all modes except production, where it defaults to `Logger::Formatter`. If you are setting a value for `config.logger` you must manually pass the value of your formatter to your logger before it is wrapped in an `ActiveSupport::TaggedLogging` instance, Rails will not do it for you. +* `config.log_formatter` defines the formatter of the Rails logger. This option defaults to an instance of `ActiveSupport::Logger::SimpleFormatter` for all modes. If you are setting a value for `config.logger` you must manually pass the value of your formatter to your logger before it is wrapped in an `ActiveSupport::TaggedLogging` instance, Rails will not do it for you. * `config.log_level` defines the verbosity of the Rails logger. This option defaults to `:debug` for all environments. The available log levels are: `:debug`, -- cgit v1.2.3 From 10781f30a0401224477b3295ea16f816d522c71f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 15 Oct 2016 11:13:13 -0300 Subject: Copy-edit the documentation [ci skip] --- actionpack/lib/action_dispatch/testing/integration.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 6c2d4c3c42..f3e7c6998f 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -177,7 +177,7 @@ module ActionDispatch # # - +method+: The HTTP method (GET, POST, PATCH, PUT, DELETE, HEAD, OPTIONS) # as a symbol. - # - +path+: The URI (as a String) on which you want to perform a GET + # - +path+: The URI (as a String) on which you want to perform the # request. # - +params+: The HTTP parameters that you want to pass. This may # be +nil+, @@ -190,8 +190,8 @@ module ActionDispatch # merged into the Rack env hash. # # This method is rarely used directly. Use +#get+, +#post+, or other standard - # HTTP methods in integration tests. Only +#process+ is only required for an - # OPTIONS request. + # HTTP methods in integration tests. +#process+ is only required when using a + # request method that doesn't have a method defined in the integrations tests. # # This method returns a Response object, which one can use to # inspect the details of the response. Furthermore, if this method was @@ -199,7 +199,7 @@ module ActionDispatch # object's @response instance variable will point to the same # response object. # - # Examples: + # Example: # process :get, '/author', params: { since: 201501011400 } def process(method, path, params: nil, headers: nil, env: nil, xhr: false, as: nil) request_encoder = RequestEncoder.encoder(as) -- cgit v1.2.3 From bb93276b8d399103e1b5b31b094e755efc3a7dab Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sun, 16 Oct 2016 19:07:31 +0200 Subject: Bump bundler version in the before_install hook of travis - We were running into issues with old bundler versions on 4.2 builds. So we bumped the bundler version on 4-2-stable branch in https://github.com/rails/rails/pull/26592. - This commit applies same change to master as per discussion in https://github.com/rails/rails/pull/26592#issuecomment-254026755. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 88dd6b7b5d..d29ef1702a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ addons: bundler_args: --without test --jobs 3 --retry 3 before_install: - "rm ${BUNDLE_GEMFILE}.lock" + - "gem update bundler" - "[ -f /tmp/beanstalkd-1.10/Makefile ] || (curl -L https://github.com/kr/beanstalkd/archive/v1.10.tar.gz | tar xz -C /tmp)" - "pushd /tmp/beanstalkd-1.10 && make && (./beanstalkd &); popd" -- cgit v1.2.3 From 6aa378400218404f1002177f5457e296079ae255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=AA=E0=A5=8D=E0=A4=B0=E0=A4=A5=E0=A4=AE=E0=A5=87?= =?UTF-8?q?=E0=A4=B6=20Sonpatki?= Date: Sun, 16 Oct 2016 20:31:28 +0200 Subject: /s/integrations/integration [ci skip] (#26801) --- actionpack/lib/action_dispatch/testing/integration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index f3e7c6998f..e24b943026 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -191,7 +191,7 @@ module ActionDispatch # # This method is rarely used directly. Use +#get+, +#post+, or other standard # HTTP methods in integration tests. +#process+ is only required when using a - # request method that doesn't have a method defined in the integrations tests. + # request method that doesn't have a method defined in the integration tests. # # This method returns a Response object, which one can use to # inspect the details of the response. Furthermore, if this method was -- cgit v1.2.3 From f6cc4f5648f7003a41f8e1c488a399abe4c73568 Mon Sep 17 00:00:00 2001 From: Alex Kitchens Date: Mon, 17 Oct 2016 16:31:01 -0500 Subject: [ci skip] Fix typo in Guides: Contributing --- guides/source/contributing_to_ruby_on_rails.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/source/contributing_to_ruby_on_rails.md b/guides/source/contributing_to_ruby_on_rails.md index 5791e7a12a..830a546570 100644 --- a/guides/source/contributing_to_ruby_on_rails.md +++ b/guides/source/contributing_to_ruby_on_rails.md @@ -272,7 +272,7 @@ The above are guidelines - please use your best judgment in using them. For changes that might have an impact on performance, please benchmark your code and measure the impact. Please share the benchmark script you used as well -as the results. You should consider including these information in your commit +as the results. You should consider including this information in your commit message, which allows future contributors to easily verify your findings and determine if they are still relevant. (For example, future optimizations in the Ruby VM might render certain optimizations unnecessary.) -- cgit v1.2.3 From 4aae8bfe4dc6da1722e7f0f1722cf1f7ef472c19 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Mon, 17 Oct 2016 21:16:54 -0400 Subject: Convert ActionController::Parameters to a hash in button_to MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before, an error would be raised saying that the method `to_param` was undefined on the instance of `ActionController::Parameters`. Now, we are checking to see if the `params` object being passed to `button_to` responds to the `permitted?` method, and if so, we will call `to_h` on it. If it does not respond to `permitted?`, then the `params` will remain unchanged. [Jon Moss, Rafael Mendonça França] --- actionview/lib/action_view/helpers/url_helper.rb | 6 ++++++ actionview/test/template/url_helper_test.rb | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb index dad0e9dac3..2445887c17 100644 --- a/actionview/lib/action_view/helpers/url_helper.rb +++ b/actionview/lib/action_view/helpers/url_helper.rb @@ -331,6 +331,12 @@ module ActionView inner_tags = method_tag.safe_concat(button).safe_concat(request_token_tag) if params + params = if params.respond_to?(:permitted?) + params.to_h + else + params + end + to_form_params(params).each do |param| inner_tags.safe_concat tag(:input, type: "hidden", name: param[:name], value: param[:value]) end diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb index 2ef2be65d2..4f73241f52 100644 --- a/actionview/test/template/url_helper_test.rb +++ b/actionview/test/template/url_helper_test.rb @@ -221,6 +221,22 @@ class UrlHelperTest < ActiveSupport::TestCase ) end + class FakeParams + def permitted? + end + + def to_h + { foo: :bar, baz: "quux" } + end + end + + def test_button_to_with_strong_params + assert_dom_equal( + %{
}, + button_to("Hello", "http://www.example.com", params: FakeParams.new) + ) + end + def test_button_to_with_nested_hash_params assert_dom_equal( %{
}, -- cgit v1.2.3 From 6d7f35ecb1ab6d58bb81ecbf5ff18009fb002425 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Tue, 18 Oct 2016 08:17:54 +0900 Subject: add `ActionController::Parameters#merge!` This method has the same behavior as `Hash#merge!`, returns current `ActionController::Parameters`. --- actionpack/CHANGELOG.md | 4 ++++ .../lib/action_controller/metal/strong_parameters.rb | 7 +++++++ .../controller/parameters/parameters_permit_test.rb | 17 +++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index c9c347ea26..d4b8d9b456 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,7 @@ +* Add `ActionController::Parameters#merge!`, which behaves the same as `Hash#merge!`. + + *Yuji Yaginuma* + * Allow keys not found in RACK_KEY_TRANSLATION for setting the environment when rendering arbitrary templates. diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index b64617d084..9df67d4be1 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -573,6 +573,13 @@ module ActionController ) end + # Returns current ActionController::Parameters instance which + # +other_hash+ merges into current hash. + def merge!(other_hash) + @parameters.merge!(other_hash.to_h) + self + end + # This is required by ActiveModel attribute assignment, so that user can # pass +Parameters+ to a mass assignment methods in a model. It should not # matter as we are using +HashWithIndifferentAccess+ internally. diff --git a/actionpack/test/controller/parameters/parameters_permit_test.rb b/actionpack/test/controller/parameters/parameters_permit_test.rb index 728d8e1279..e66c2807c3 100644 --- a/actionpack/test/controller/parameters/parameters_permit_test.rb +++ b/actionpack/test/controller/parameters/parameters_permit_test.rb @@ -244,6 +244,23 @@ class ParametersPermitTest < ActiveSupport::TestCase assert merged_params[:id] end + test "not permitted is sticky beyond merge!" do + assert_not @params.merge!(a: "b").permitted? + end + + test "permitted is sticky beyond merge!" do + @params.permit! + assert @params.merge!(a: "b").permitted? + end + + test "merge! with parameters" do + other_params = ActionController::Parameters.new(id: "1234").permit! + @params.merge!(other_params) + + assert_equal "1234", @params[:id] + assert_equal "32", @params[:person][:age] + end + test "modifying the parameters" do @params[:person][:hometown] = "Chicago" @params[:person][:family] = { brother: "Jonas" } -- cgit v1.2.3 From 2aab983fff209d5b696beb8d37564aeba9a6d7b3 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Wed, 19 Oct 2016 17:00:33 +0900 Subject: update doc about `change_column_default` [ci skip] Follow up to #20018. --- activerecord/lib/active_record/migration.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 627e93b5b6..f333769159 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -278,8 +278,10 @@ module ActiveRecord # # * change_column(table_name, column_name, type, options): Changes # the column to a different type using the same parameters as add_column. - # * change_column_default(table_name, column_name, default): Sets a - # default value for +column_name+ defined by +default+ on +table_name+. + # * change_column_default(table_name, column_name, default_or_changes): + # Sets a default value for +column_name+ defined by +default_or_changes+ on + # +table_name+. Passing a hash containing :from and :to + # as +default_or_changes+ will make this change reversible in the migration. # * change_column_null(table_name, column_name, null, default = nil): # Sets or removes a +NOT NULL+ constraint on +column_name+. The +null+ flag # indicates whether the value can be +NULL+. See -- cgit v1.2.3 From 2448fbabf4972a3a86dac4a0c46d28c2113d6609 Mon Sep 17 00:00:00 2001 From: Orhan Toy Date: Wed, 19 Oct 2016 19:38:21 +0200 Subject: Fix indentation of code examples This commit fixes the generated HTML of the two code examples. --- .../connection_adapters/abstract/schema_definitions.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 ffde4f2c93..83d1d7cd01 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -475,7 +475,7 @@ module ActiveRecord # Checks to see if a column exists. # - # t.string(:name) unless t.column_exists?(:name, :string) + # t.string(:name) unless t.column_exists?(:name, :string) # # See {connection.column_exists?}[rdoc-ref:SchemaStatements#column_exists?] def column_exists?(column_name, type = nil, options = {}) @@ -496,9 +496,9 @@ module ActiveRecord # Checks to see if an index exists. # - # unless t.index_exists?(:branch_id) - # t.index(:branch_id) - # end + # unless t.index_exists?(:branch_id) + # t.index(:branch_id) + # end # # See {connection.index_exists?}[rdoc-ref:SchemaStatements#index_exists?] def index_exists?(column_name, options = {}) -- cgit v1.2.3 From a01cf703e23a96bad044766efad58b4d56d8bf11 Mon Sep 17 00:00:00 2001 From: claudiob Date: Wed, 19 Oct 2016 11:48:43 -0700 Subject: Add missing require --- activesupport/lib/active_support/hash_with_indifferent_access.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index 74a603c05d..a56943d99d 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -1,5 +1,6 @@ require "active_support/core_ext/hash/keys" require "active_support/core_ext/hash/reverse_merge" +require "active_support/core_ext/hash/indifferent_access" module ActiveSupport # Implements a hash where keys :foo and "foo" are considered -- cgit v1.2.3 From cd5e4188ee49b77ca10a6fce3d88414ad28aef3d Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 19 Oct 2016 14:38:06 -0700 Subject: Merge pull request #26829 from headius/wait_for_events_in_listen_tests Wait for file events to propagated for slower Listen backends. --- activesupport/test/file_update_checker_shared_tests.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/activesupport/test/file_update_checker_shared_tests.rb b/activesupport/test/file_update_checker_shared_tests.rb index cd6a58e840..48cd387196 100644 --- a/activesupport/test/file_update_checker_shared_tests.rb +++ b/activesupport/test/file_update_checker_shared_tests.rb @@ -49,6 +49,7 @@ module FileUpdateCheckerSharedTests checker = new_checker(tmpfiles) { i += 1 } touch(tmpfiles) + wait assert checker.execute_if_updated assert_equal 1, i @@ -62,6 +63,7 @@ module FileUpdateCheckerSharedTests checker = new_checker(tmpfiles) { i += 1 } touch(tmpfiles) + wait assert checker.execute_if_updated assert_equal 1, i @@ -75,6 +77,7 @@ module FileUpdateCheckerSharedTests checker = new_checker(tmpfiles) { i += 1 } rm_f(tmpfiles) + wait assert checker.execute_if_updated assert_equal 1, i @@ -87,6 +90,7 @@ module FileUpdateCheckerSharedTests assert !checker.updated? touch(tmpfiles) + wait assert checker.updated? end @@ -100,6 +104,7 @@ module FileUpdateCheckerSharedTests assert !checker.updated? touch(tmpfiles) + wait assert checker.updated? end @@ -113,6 +118,7 @@ module FileUpdateCheckerSharedTests assert !checker.updated? rm_f(tmpfiles) + wait assert checker.updated? end @@ -129,6 +135,7 @@ module FileUpdateCheckerSharedTests checker = new_checker(tmpfiles) { i += 1 } touch(tmpfiles[1..-1]) + wait assert checker.execute_if_updated assert_equal 1, i @@ -145,6 +152,7 @@ module FileUpdateCheckerSharedTests checker = new_checker(tmpfiles) { i += 1 } touch(tmpfiles[1..-1]) + wait assert checker.execute_if_updated assert_equal 1, i @@ -157,6 +165,7 @@ module FileUpdateCheckerSharedTests assert !checker.updated? touch(tmpfiles) + wait assert checker.updated? checker.execute @@ -169,6 +178,7 @@ module FileUpdateCheckerSharedTests checker = new_checker([], tmpdir => :rb) { i += 1 } touch(tmpfile("foo.rb")) + wait assert checker.execute_if_updated assert_equal 1, i @@ -180,11 +190,13 @@ module FileUpdateCheckerSharedTests checker = new_checker([], tmpdir => [:rb, :txt]) { i += 1 } touch(tmpfile("foo.rb")) + wait assert checker.execute_if_updated assert_equal 1, i touch(tmpfile("foo.txt")) + wait assert checker.execute_if_updated assert_equal 2, i @@ -196,6 +208,7 @@ module FileUpdateCheckerSharedTests checker = new_checker([], tmpdir => :txt) { i += 1 } touch(tmpfile("foo.rb")) + wait assert !checker.execute_if_updated assert_equal 0, i @@ -208,6 +221,7 @@ module FileUpdateCheckerSharedTests checker = new_checker([non_existing]) { i += 1 } touch(non_existing) + wait assert checker.execute_if_updated assert_equal 1, i @@ -226,6 +240,7 @@ module FileUpdateCheckerSharedTests assert_equal 0, i touch(File.join(subdir, "nested.rb")) + wait assert checker.execute_if_updated assert_equal 1, i @@ -240,17 +255,20 @@ module FileUpdateCheckerSharedTests checker = new_checker([], tmpdir => :rb, subdir => :txt) { i += 1 } touch(tmpfile("new.txt")) + wait assert !checker.execute_if_updated assert_equal 0, i # subdir does not look for Ruby files, but its parent tmpdir does. touch(File.join(subdir, "nested.rb")) + wait assert checker.execute_if_updated assert_equal 1, i touch(File.join(subdir, "nested.txt")) + wait assert checker.execute_if_updated assert_equal 2, i -- cgit v1.2.3 From af45bbc3c9413ac44e68a7f9efb3e53f14b9f399 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 19 Oct 2016 17:49:36 -0700 Subject: render_bind should be private --- activerecord/lib/active_record/log_subscriber.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb index ad71c6cde8..ca9143c57d 100644 --- a/activerecord/lib/active_record/log_subscriber.rb +++ b/activerecord/lib/active_record/log_subscriber.rb @@ -15,16 +15,6 @@ module ActiveRecord rt end - def render_bind(attr, type_casted_value) - value = if attr.type.binary? && attr.value - "<#{attr.value_for_database.to_s.bytesize} bytes of binary data>" - else - type_casted_value - end - - [attr.name, value] - end - def sql(event) self.class.runtime += event.duration return unless logger.debug? @@ -52,6 +42,16 @@ module ActiveRecord private + def render_bind(attr, type_casted_value) + value = if attr.type.binary? && attr.value + "<#{attr.value_for_database.to_s.bytesize} bytes of binary data>" + else + type_casted_value + end + + [attr.name, value] + end + def colorize_payload_name(name, payload_name) if payload_name.blank? || payload_name == "SQL" # SQL vs Model Load/Exists color(name, MAGENTA, true) -- cgit v1.2.3 From fc72d6815ad6ed447f1aea2dd98579305ea1cca4 Mon Sep 17 00:00:00 2001 From: Josua Schmid Date: Wed, 19 Oct 2016 18:43:57 +0200 Subject: Fix copy_time_to: Copy nsec instead of usec `copy_time_to` is a helper function for date and time calculations. It's being used by `prev_week`, `next_week` and `prev_weekday` to keep the time fraction when jumping around between days. Previously the nanoseconds part was lost during the operation. This lead to problems in practice if you were using the `end_of_day` calculation. Resulting in the time fraction of `end_of_day` not being the same as next week's `end_of_day`. With this fix `copy_time_to` doesn't forget the `nsec` digits. --- activesupport/CHANGELOG.md | 6 ++++++ .../lib/active_support/core_ext/date_and_time/calculations.rb | 2 +- activesupport/test/core_ext/date_and_time_behavior.rb | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index f840783059..91dfc556d3 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,9 @@ +* Fix `DateAndTime::Calculations#copy_time_to`. Copy `nsec` instead of `usec`. + + Jumping forward or backward between weeks now preserves nanosecond digits. + + *Josua Schmid* + * Fix `ActiveSupport::TimeWithZone#in` across DST boundaries. Previously calls to `in` were being sent to the non-DST aware diff --git a/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb index c614f14289..f2ba7fdda5 100644 --- a/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb @@ -334,7 +334,7 @@ module DateAndTime end def copy_time_to(other) - other.change(hour: hour, min: min, sec: sec, usec: try(:usec)) + other.change(hour: hour, min: min, sec: sec, nsec: try(:nsec)) end end end diff --git a/activesupport/test/core_ext/date_and_time_behavior.rb b/activesupport/test/core_ext/date_and_time_behavior.rb index bf83ac602f..6cc9781e02 100644 --- a/activesupport/test/core_ext/date_and_time_behavior.rb +++ b/activesupport/test/core_ext/date_and_time_behavior.rb @@ -126,7 +126,9 @@ module DateAndTimeBehavior end def test_next_week_at_same_time - assert_equal date_time_init(2005,2,28,15,15,10), date_time_init(2005,2,22,15,15,10).next_week(:monday, same_time: true) + assert_equal date_time_init(2005,2,28,15,15,10), date_time_init(2005,2,22,15,15,10).next_week(:monday, same_time: true) + assert_equal date_time_init(2005,2,28,15,15,10,999999), date_time_init(2005,2,22,15,15,10,999999).next_week(:monday, same_time: true) + assert_equal date_time_init(2005,2,28,15,15,10,Rational(999999999, 1000)), date_time_init(2005,2,22,15,15,10,Rational(999999999, 1000)).next_week(:monday, same_time: true) assert_equal date_time_init(2005,3,4,15,15,10), date_time_init(2005,2,22,15,15,10).next_week(:friday, same_time: true) assert_equal date_time_init(2006,10,30,0,0,0), date_time_init(2006,10,23,0,0,0).next_week(:monday, same_time: true) assert_equal date_time_init(2006,11,1,0,0,0), date_time_init(2006,10,23,0,0,0).next_week(:wednesday, same_time: true) -- cgit v1.2.3 From b10227728bc9aa21bfebb2e0bbc12f416122d278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 20 Oct 2016 10:32:25 -0300 Subject: Merge pull request #26830 from headius/mask_forking_fsevent_test_on_jruby Mask forking filesystem event on JRuby. --- activesupport/test/evented_file_update_checker_test.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/activesupport/test/evented_file_update_checker_test.rb b/activesupport/test/evented_file_update_checker_test.rb index cc47318974..77d8dcb0f8 100644 --- a/activesupport/test/evented_file_update_checker_test.rb +++ b/activesupport/test/evented_file_update_checker_test.rb @@ -36,6 +36,8 @@ class EventedFileUpdateCheckerTest < ActiveSupport::TestCase end test "notifies forked processes" do + jruby_skip "Forking not available on JRuby" + FileUtils.touch(tmpfiles) checker = new_checker(tmpfiles) {} -- cgit v1.2.3 From 1345511081a7b4562281cf77d9e5aeeae2d3eb02 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 20 Oct 2016 09:21:16 -0700 Subject: Use old typecasting method if no type casted binds are passed in Query cache doesn't type cast bind parameters since it isn't actually querying the database, so it can't pass those values in. Type casting in the query cache method would cause the values to be type cast twice in the case that there is a cache miss (since the methods it calls will type cast *again*). If logging is disabled, then adding the type cast code to the query cache method will needlessly typecast the values (since the only reason those values are type cast is for display in the logs). Fixes #26828. --- activerecord/lib/active_record/log_subscriber.rb | 11 +++++++- activerecord/test/cases/query_cache_test.rb | 36 +++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb index ca9143c57d..4b8d8d9105 100644 --- a/activerecord/lib/active_record/log_subscriber.rb +++ b/activerecord/lib/active_record/log_subscriber.rb @@ -29,7 +29,8 @@ module ActiveRecord binds = nil unless (payload[:binds] || []).empty? - binds = " " + payload[:binds].zip(payload[:type_casted_binds]).map { |attr, value| + casted_params = type_casted_binds(payload[:binds], payload[:type_casted_binds]) + binds = " " + payload[:binds].zip(casted_params).map { |attr, value| render_bind(attr, value) }.inspect end @@ -42,6 +43,10 @@ module ActiveRecord private + def type_casted_binds(binds, casted_binds) + casted_binds || binds.map { |attr| type_cast attr.value_for_database } + end + def render_bind(attr, type_casted_value) value = if attr.type.binary? && attr.value "<#{attr.value_for_database.to_s.bytesize} bytes of binary data>" @@ -84,6 +89,10 @@ module ActiveRecord def logger ActiveRecord::Base.logger end + + def type_cast(value) + ActiveRecord::Base.connection.type_cast(value) + end end end diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb index 16cf2bd2d0..4cd258695d 100644 --- a/activerecord/test/cases/query_cache_test.rb +++ b/activerecord/test/cases/query_cache_test.rb @@ -10,9 +10,30 @@ class QueryCacheTest < ActiveRecord::TestCase fixtures :tasks, :topics, :categories, :posts, :categories_posts - teardown do + class ShouldNotHaveExceptionsLogger < ActiveRecord::LogSubscriber + attr_reader :logger + + def initialize + super + @logger = ::Logger.new File::NULL + @exception = false + end + + def exception? + @exception + end + + def sql(event) + super + rescue + @exception = true + end + end + + def teardown Task.connection.clear_query_cache ActiveRecord::Base.connection.disable_query_cache! + super end def test_exceptional_middleware_clears_and_disables_cache_on_error @@ -121,6 +142,19 @@ class QueryCacheTest < ActiveRecord::TestCase end end + def test_cache_does_not_raise_exceptions + logger = ShouldNotHaveExceptionsLogger.new + subscriber = ActiveSupport::Notifications.subscribe "sql.active_record", logger + + ActiveRecord::Base.cache do + assert_queries(1) { Task.find(1); Task.find(1) } + end + + assert_not_predicate logger, :exception? + ensure + ActiveSupport::Notifications.unsubscribe subscriber + end + def test_cache_is_flat Task.cache do assert_queries(1) { Topic.find(1); Topic.find(1); } -- cgit v1.2.3 From 85dd85fe01a44a40a0363c6382382c35505522e0 Mon Sep 17 00:00:00 2001 From: Bruno Facca Date: Thu, 20 Oct 2016 15:38:49 -0200 Subject: [ci skip] Fix return values of Hash Extensions examples The hashes returned in some examples of the following sections had items in a different order than their receivers. That may mislead readers into believing those methods will not preserve element order. Extensions to Hash/Working with Keys/transform_keys and transform_keys! Extensions to Hash/Working with Keys/stringify_keys and stringify_keys! Extensions to Hash/Working with Keys/symbolize_keys and symbolize_keys! Extensions to Hash/Slicing --- guides/source/active_support_core_extensions.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index 60a6c37f82..70b04a9695 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -2661,7 +2661,7 @@ The method `transform_keys` accepts a block and returns a hash that has applied ```ruby {nil => nil, 1 => 1, a: :a}.transform_keys { |key| key.to_s.upcase } -# => {"" => nil, "A" => :a, "1" => 1} +# => {"" => nil, "1" => 1, "A" => :a} ``` In case of key collision, one of the values will be chosen. The chosen value may not always be the same given the same hash: @@ -2703,7 +2703,7 @@ The method `stringify_keys` returns a hash that has a stringified version of the ```ruby {nil => nil, 1 => 1, a: :a}.stringify_keys -# => {"" => nil, "a" => :a, "1" => 1} +# => {"" => nil, "1" => 1, "a" => :a} ``` In case of key collision, one of the values will be chosen. The chosen value may not always be the same given the same hash: @@ -2745,7 +2745,7 @@ The method `symbolize_keys` returns a hash that has a symbolized version of the ```ruby {nil => nil, 1 => 1, "a" => "a"}.symbolize_keys -# => {1=>1, nil=>nil, :a=>"a"} +# => {nil=>nil, 1=>1, :a=>"a"} ``` WARNING. Note in the previous example only one key was symbolized. @@ -2822,7 +2822,7 @@ Ruby has built-in support for taking slices out of strings and arrays. Active Su ```ruby {a: 1, b: 2, c: 3}.slice(:a, :c) -# => {:c=>3, :a=>1} +# => {:a=>1, :c=>3} {a: 1, b: 2, c: 3}.slice(:b, :X) # => {:b=>2} # non-existing keys are ignored -- cgit v1.2.3 From fb2f8d2b75b1999b7ff7adef16ba7fb34600fa0d Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Thu, 20 Oct 2016 20:32:24 +0200 Subject: remove trailing whitespace [ci skip] --- guides/source/active_record_migrations.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/guides/source/active_record_migrations.md b/guides/source/active_record_migrations.md index a45becf670..5b70bcdb3c 100644 --- a/guides/source/active_record_migrations.md +++ b/guides/source/active_record_migrations.md @@ -1018,10 +1018,10 @@ such features, the `execute` method can be used to execute arbitrary SQL. Migrations and Seed Data ------------------------ -The main purpose of Rails' migration feature is to issue commands that modify the -schema using a consistent process. Migrations can also be used -to add or modify data. This is useful in an existing database that can't be destroyed -and recreated, such as a production database. +The main purpose of Rails' migration feature is to issue commands that modify the +schema using a consistent process. Migrations can also be used +to add or modify data. This is useful in an existing database that can't be destroyed +and recreated, such as a production database. ```ruby class AddInitialProducts < ActiveRecord::Migration[5.0] @@ -1037,10 +1037,10 @@ class AddInitialProducts < ActiveRecord::Migration[5.0] end ``` -To add initial data after a database is created, Rails has a built-in -'seeds' feature that makes the process quick and easy. This is especially -useful when reloading the database frequently in development and test environments. -It's easy to get started with this feature: just fill up `db/seeds.rb` with some +To add initial data after a database is created, Rails has a built-in +'seeds' feature that makes the process quick and easy. This is especially +useful when reloading the database frequently in development and test environments. +It's easy to get started with this feature: just fill up `db/seeds.rb` with some Ruby code, and run `rails db:seed`: ```ruby -- cgit v1.2.3 From dba9ce8ec87f99a5be830043c3fb9a745f983a93 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Thu, 20 Oct 2016 20:32:57 +0200 Subject: guides, include note about modifiers when using the CLI. [ci skip] This was pointed out on https://github.com/rails/rails/issues/15583#issuecomment-239212831 The comment was lost in the changes made by fcd0ac066e0959a9f4fa4459a27e041abe8eb52a and 3e1373a773085d5f19cb6a466ab2736cc1ca2713 --- guides/source/active_record_migrations.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/guides/source/active_record_migrations.md b/guides/source/active_record_migrations.md index 5b70bcdb3c..d91c9bd606 100644 --- a/guides/source/active_record_migrations.md +++ b/guides/source/active_record_migrations.md @@ -467,6 +467,8 @@ the first time (i.e. on the date the migration is applied). Some adapters may support additional options; see the adapter specific API docs for further information. +NOTE: `null` and `default` cannot be specified via command line. + ### Foreign Keys While it's not required you might want to add foreign key constraints to -- cgit v1.2.3 From dce4751a74342bd94802eb49b411663b66ace28b Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Thu, 20 Oct 2016 21:20:03 +0200 Subject: doc, hide non-public methods form the api docs. [ci skip] This is a follow up to #25681, specifically this comment: https://github.com/rails/rails/pull/25681#issuecomment-238294002 The way the thread local variable is stored is an implementation detail and subject to change. It makes no sense to only generate a reader or writer as you'd have to know where to read from or where it writes to. --- .../active_support/core_ext/module/attribute_accessors_per_thread.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb b/activesupport/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb index b1e6fe71e0..1e82b4acc2 100644 --- a/activesupport/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +++ b/activesupport/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb @@ -34,7 +34,7 @@ class Module # end # # Current.new.user # => NoMethodError - def thread_mattr_reader(*syms) + def thread_mattr_reader(*syms) # :nodoc: options = syms.extract_options! syms.each do |sym| @@ -77,7 +77,7 @@ class Module # end # # Current.new.user = "DHH" # => NoMethodError - def thread_mattr_writer(*syms) + def thread_mattr_writer(*syms) # :nodoc: options = syms.extract_options! syms.each do |sym| raise NameError.new("invalid attribute name: #{sym}") unless /^[_A-Za-z]\w*$/.match?(sym) -- cgit v1.2.3 From f0bacbc2c4fe2dcfc2db555f35fb553a1a1ce88a Mon Sep 17 00:00:00 2001 From: Gaurav Sharma Date: Fri, 21 Oct 2016 09:37:24 +0530 Subject: update kindlerb gem Ruby Kindle periodical-format ebook generator --- Gemfile | 2 +- Gemfile.lock | 14 +++++--------- guides/Rakefile | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index 53044252a0..97a19188bc 100644 --- a/Gemfile +++ b/Gemfile @@ -39,7 +39,7 @@ group :doc do gem "sdoc", "1.0.0.beta2" gem "redcarpet", "~> 3.2.3", platforms: :ruby gem "w3c_validators" - gem "kindlerb", "0.1.1" + gem "kindlerb", ">= 1.0.1" end # Active Support. diff --git a/Gemfile.lock b/Gemfile.lock index d4059c607d..63850eee90 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -211,7 +211,7 @@ GEM railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (2.0.2) - kindlerb (0.1.1) + kindlerb (1.0.1) mustache nokogiri listen (3.1.5) @@ -239,19 +239,15 @@ GEM mysql2 (0.4.4-x64-mingw32) mysql2 (0.4.4-x86-mingw32) nio4r (1.2.1) - nokogiri (1.6.8) + nokogiri (1.6.8.1) mini_portile2 (~> 2.1.0) - pkg-config (~> 1.1.7) - nokogiri (1.6.8-x64-mingw32) + nokogiri (1.6.8.1-x64-mingw32) mini_portile2 (~> 2.1.0) - pkg-config (~> 1.1.7) - nokogiri (1.6.8-x86-mingw32) + nokogiri (1.6.8.1-x86-mingw32) mini_portile2 (~> 2.1.0) - pkg-config (~> 1.1.7) pg (0.19.0) pg (0.19.0-x64-mingw32) pg (0.19.0-x86-mingw32) - pkg-config (1.1.7) psych (2.1.1) puma (3.6.0) qu (0.2.0) @@ -383,7 +379,7 @@ DEPENDENCIES em-hiredis hiredis jquery-rails - kindlerb (= 0.1.1) + kindlerb (>= 1.0.1) listen (>= 3.0.5, < 3.2) minitest (< 5.3.4) mocha (~> 0.14) diff --git a/guides/Rakefile b/guides/Rakefile index 353966fc55..bf501f6a64 100644 --- a/guides/Rakefile +++ b/guides/Rakefile @@ -13,7 +13,7 @@ namespace :guides do desc "Generate .mobi file. The kindlegen executable must be in your PATH. You can get it for free from http://www.amazon.com/gp/feature.html?docId=1000765211" task :kindle do - unless `kindlerb -v 2> /dev/null` =~ /kindlerb 0.1.1/ + unless `kindlerb -v 2> /dev/null` =~ /kindlerb 1.0.1/ abort "Please `gem install kindlerb` and make sure you have `kindlegen` in your PATH" end unless `convert` =~ /convert/ -- cgit v1.2.3 From 07ffe7a6211b2bac59f385f4a0a67d11e4d42c24 Mon Sep 17 00:00:00 2001 From: denisovlev Date: Thu, 20 Oct 2016 15:44:22 +0300 Subject: Fix `ActiveSupport::TimeZone#strptime` cannot parse timestamps (%Q, %s) --- activesupport/CHANGELOG.md | 7 ++++++ .../lib/active_support/values/time_zone.rb | 26 +++++++++++++--------- activesupport/test/time_zone_test.rb | 18 +++++++++++++++ 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 91dfc556d3..13d152f4c6 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,10 @@ +* Fix `ActiveSupport::TimeZone#strptime`. + Support for timestamps in format of seconds (%s) and milliseconds (%Q). + + Fixes #26840. + + *Lev Denisov* + * Fix `DateAndTime::Calculations#copy_time_to`. Copy `nsec` instead of `usec`. Jumping forward or backward between weeks now preserves nanosecond digits. diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index cb97a0e135..a562f33420 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -450,17 +450,21 @@ module ActiveSupport raise ArgumentError, "invalid date" if parts.nil? return if parts.empty? - time = Time.new( - parts.fetch(:year, now.year), - parts.fetch(:mon, now.month), - parts.fetch(:mday, parts[:year] || parts[:mon] ? 1 : now.day), - parts.fetch(:hour, 0), - parts.fetch(:min, 0), - parts.fetch(:sec, 0) + parts.fetch(:sec_fraction, 0), - parts.fetch(:offset, 0) - ) - - if parts[:offset] + if parts[:seconds] + time = Time.at(parts[:seconds]) + else + time = Time.new( + parts.fetch(:year, now.year), + parts.fetch(:mon, now.month), + parts.fetch(:mday, parts[:year] || parts[:mon] ? 1 : now.day), + parts.fetch(:hour, 0), + parts.fetch(:min, 0), + parts.fetch(:sec, 0) + parts.fetch(:sec_fraction, 0), + parts.fetch(:offset, 0) + ) + end + + if parts[:offset] || parts[:seconds] TimeWithZone.new(time.utc, self) else TimeWithZone.new(nil, self, time) diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index 76fee1fdd4..bd29584478 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -395,6 +395,24 @@ class TimeZoneTest < ActiveSupport::TestCase end end + def test_strptime_with_timestamp_seconds + with_env_tz "US/Eastern" do + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + time_str = "1470272280" + time = zone.strptime(time_str, "%s") + assert_equal Time.at(1470272280), time + end + end + + def test_strptime_with_timestamp_milliseconds + with_env_tz "US/Eastern" do + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + time_str = "1470272280000" + time = zone.strptime(time_str, "%Q") + assert_equal Time.at(1470272280), time + end + end + def test_utc_offset_lazy_loaded_from_tzinfo_when_not_passed_in_to_initialize tzinfo = TZInfo::Timezone.get("America/New_York") zone = ActiveSupport::TimeZone.create(tzinfo.name, nil, tzinfo) -- cgit v1.2.3 From 1b7263143a91f87faabde3a5d10c74308876f640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gomes=20J=C3=BAnior?= Date: Fri, 21 Oct 2016 10:32:49 -0200 Subject: don't create db directory when skip active_record --- railties/lib/rails/generators/rails/app/app_generator.rb | 1 + railties/test/generators/app_generator_test.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 9f9c50ca10..03573b274d 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -241,6 +241,7 @@ module Rails end def create_db_files + return if options[:skip_active_record] build(:db) end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 8f7fa1155f..830e49a1b5 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -356,6 +356,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_generator_if_skip_active_record_is_given run_generator [destination_root, "--skip-active-record"] + assert_no_directory "db/" assert_no_file "config/database.yml" assert_no_file "app/models/application_record.rb" assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/ -- cgit v1.2.3 From 5f382d41c30b1e433d777a8daaedb247d7f2a57c Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Fri, 21 Oct 2016 09:33:25 -0500 Subject: Explicitly unpack the expanded args to avoid execution order diff. In https://bugs.ruby-lang.org/issues/12860 I argue that MRI's execution order here is incorrect. The splatting of the 'c' args should happen before the shift, but it happens after. On JRuby, it behaves the way you would expect, leading to the 'c' args splat still containing the block and producing an error like "cannot convert proc to symbol" when the send attempts to coerce it. This patch makes the unpacking order explicit with a multi-assign, which behaves properly on all implementations I tested. --- activesupport/lib/active_support/callbacks.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 890b1cd73b..9b9c9cbbdd 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -410,8 +410,8 @@ module ActiveSupport # values. def make_lambda lambda do |target, value, &block| - c = expand(target, value, block) - c.shift.send(*c, &c.shift) + target, block, method, *arguments = expand(target, value, block) + target.send(method, *arguments, &block) end end @@ -419,8 +419,8 @@ module ActiveSupport # values, but then return the boolean inverse of that result. def inverted_lambda lambda do |target, value, &block| - c = expand(target, value, block) - ! c.shift.send(*c, &c.shift) + target, block, method, *arguments = expand(target, value, block) + ! target.send(method, *arguments, &block) end end -- cgit v1.2.3 From 267439205849bb15f3aa38361d8daece633f9bac Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Fri, 21 Oct 2016 10:16:58 -0500 Subject: Additional fix for argument-splat ordering differences. See #26854 --- activesupport/lib/active_support/callbacks.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 9b9c9cbbdd..2ad1145fae 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -117,8 +117,8 @@ module ActiveSupport (skipped ||= []) << current next else - expanded = current.expand_call_template(env, invoke_sequence) - expanded.shift.send(*expanded, &expanded.shift) + target, block, method, *arguments = current.expand_call_template(env, invoke_sequence) + target.send(method, *arguments, &block) end current.invoke_after(env) skipped.pop.invoke_after(env) while skipped && skipped.first -- cgit v1.2.3 From 0d454d08061e183064c8148d313dbf05cab8c23b Mon Sep 17 00:00:00 2001 From: Gabi Stefanini Date: Wed, 19 Oct 2016 01:54:26 -0400 Subject: Add examples of queue_adapter and perform_enqueued jobs to API Docs. --- activejob/lib/active_job/test_helper.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/activejob/lib/active_job/test_helper.rb b/activejob/lib/active_job/test_helper.rb index bbd2a0c06c..1a8b3375ae 100644 --- a/activejob/lib/active_job/test_helper.rb +++ b/activejob/lib/active_job/test_helper.rb @@ -269,6 +269,25 @@ module ActiveJob instantiate_job(matching_job) end + # Performs all enqueued jobs in the duration of the block. + # + # def test_perform_enqueued_jobs + # perform_enqueued_jobs do + # MyJob.perform_later(1, 2, 3) + # end + # assert_performed_jobs 1 + # end + # + # This method also supports filtering. If the +:only+ option is specified, + # then only the listed job(s) will be performed. + # + # def test_perform_enqueued_jobs_with_only + # perform_enqueued_jobs(only: MyJob) do + # MyJob.perform_later(1, 2, 3) # will be performed + # HelloJob.perform_later(1, 2, 3) # will not be perfomed + # end + # assert_performed_jobs 1 + # end def perform_enqueued_jobs(only: nil) old_perform_enqueued_jobs = queue_adapter.perform_enqueued_jobs old_perform_enqueued_at_jobs = queue_adapter.perform_enqueued_at_jobs @@ -286,6 +305,11 @@ module ActiveJob end end + # Accesses the queue_adapter set by ActiveJob::Base. + # + # def test_assert_job_has_custom_queue_adapter_set + # assert_instance_of CustomQueueAdapter, HelloJob.queue_adapter + # end def queue_adapter ActiveJob::Base.queue_adapter end -- cgit v1.2.3 From 22a822e5813ef7ea9ab6dbbb670a363899a083af Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Thu, 4 Aug 2016 03:36:30 +0300 Subject: Fixed: Optimistic locking does not work well with null in the database --- activerecord/CHANGELOG.md | 6 ++ .../lib/active_record/locking/optimistic.rb | 10 ++-- activerecord/test/cases/locking_test.rb | 66 ++++++++++++++++++---- activerecord/test/schema/schema.rb | 2 + 4 files changed, 69 insertions(+), 15 deletions(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 15b49e0a0b..db9c394a65 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,9 @@ +* Fixed: Optimistic locking does not work well with null in the database. + + Fixes #26024 + + *bogdanvlviv* + * Fixed support for case insensitive comparisons of `text` columns in PostgreSQL. diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb index 8e8a97990a..fa9e789b24 100644 --- a/activerecord/lib/active_record/locking/optimistic.rb +++ b/activerecord/lib/active_record/locking/optimistic.rb @@ -60,6 +60,7 @@ module ActiveRecord end private + def increment_lock lock_col = self.class.locking_column previous_lock_value = send(lock_col).to_i @@ -80,7 +81,8 @@ module ActiveRecord return 0 if attribute_names.empty? lock_col = self.class.locking_column - previous_lock_value = send(lock_col).to_i + previous_lock_value = read_attribute_before_type_cast(lock_col) + increment_lock attribute_names += [lock_col] @@ -91,7 +93,7 @@ module ActiveRecord affected_rows = relation.where( self.class.primary_key => id, - lock_col => previous_lock_value, + lock_col => previous_lock_value ).update_all( attributes_for_update(attribute_names).map do |name| [name, _read_attribute(name)] @@ -104,9 +106,9 @@ module ActiveRecord affected_rows - # If something went wrong, revert the version. + # If something went wrong, revert the locking_column value. rescue Exception - send(lock_col + "=", previous_lock_value) + send(lock_col + "=", previous_lock_value.to_i) raise end end diff --git a/activerecord/test/cases/locking_test.rb b/activerecord/test/cases/locking_test.rb index 13b6f6daaf..8b6a969c9e 100644 --- a/activerecord/test/cases/locking_test.rb +++ b/activerecord/test/cases/locking_test.rb @@ -161,14 +161,6 @@ class OptimisticLockingTest < ActiveRecord::TestCase assert_equal(error.record.object_id, p2.object_id) end - def test_lock_new_with_nil - p1 = Person.new(first_name: "anika") - p1.save! - p1.lock_version = nil # simulate bad fixture or column with no default - p1.save! - assert_equal 1, p1.lock_version - end - def test_lock_new_when_explicitly_passing_nil p1 = Person.new(first_name: "anika", lock_version: nil) p1.save! @@ -222,22 +214,73 @@ class OptimisticLockingTest < ActiveRecord::TestCase def test_lock_without_default_sets_version_to_zero t1 = LockWithoutDefault.new + assert_equal 0, t1.lock_version + assert_nil t1.lock_version_before_type_cast + + t1.save! + t1.reload - t1.save - t1 = LockWithoutDefault.find(t1.id) assert_equal 0, t1.lock_version + assert_equal 0, t1.lock_version_before_type_cast + end + + def test_lock_without_default_should_work_with_null_in_the_database + ActiveRecord::Base.connection.execute("INSERT INTO lock_without_defaults(title) VALUES('title1')") + t1 = LockWithoutDefault.last + t2 = LockWithoutDefault.last + + assert_equal 0, t1.lock_version + assert_nil t1.lock_version_before_type_cast + assert_equal 0, t2.lock_version + assert_nil t2.lock_version_before_type_cast + + t1.title = "new title1" + t2.title = "new title2" + + assert_nothing_raised { t1.save! } + assert_equal 1, t1.lock_version + assert_equal "new title1", t1.title + + assert_raise(ActiveRecord::StaleObjectError) { t2.save! } + assert_equal 0, t2.lock_version + assert_equal "new title2", t2.title end def test_lock_with_custom_column_without_default_sets_version_to_zero t1 = LockWithCustomColumnWithoutDefault.new + assert_equal 0, t1.custom_lock_version assert_nil t1.custom_lock_version_before_type_cast t1.save! t1.reload + assert_equal 0, t1.custom_lock_version - assert [0, "0"].include?(t1.custom_lock_version_before_type_cast) + assert_equal 0, t1.custom_lock_version_before_type_cast + end + + def test_lock_with_custom_column_without_default_should_work_with_null_in_the_database + ActiveRecord::Base.connection.execute("INSERT INTO lock_without_defaults_cust(title) VALUES('title1')") + + t1 = LockWithCustomColumnWithoutDefault.last + t2 = LockWithCustomColumnWithoutDefault.last + + assert_equal 0, t1.custom_lock_version + assert_nil t1.custom_lock_version_before_type_cast + assert_equal 0, t2.custom_lock_version + assert_nil t2.custom_lock_version_before_type_cast + + t1.title = "new title1" + t2.title = "new title2" + + assert_nothing_raised { t1.save! } + assert_equal 1, t1.custom_lock_version + assert_equal "new title1", t1.title + + assert_raise(ActiveRecord::StaleObjectError) { t2.save! } + assert_equal 0, t2.custom_lock_version + assert_equal "new title2", t2.title end def test_readonly_attributes @@ -461,6 +504,7 @@ unless in_memory_db? end protected + def duel(zzz = 5) t0, t1, t2, t3 = nil, nil, nil, nil diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index d2fb090118..983ac076a9 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -436,10 +436,12 @@ ActiveRecord::Schema.define do end create_table :lock_without_defaults, force: true do |t| + t.column :title, :string t.column :lock_version, :integer end create_table :lock_without_defaults_cust, force: true do |t| + t.column :title, :string t.column :custom_lock_version, :integer end -- cgit v1.2.3 From a60a20bb7faae4d0758676b865f625275c500e4e Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Mon, 22 Aug 2016 21:16:08 +0300 Subject: Added ability update locking_column value --- activerecord/CHANGELOG.md | 5 ++ .../lib/active_record/locking/optimistic.rb | 14 ++-- activerecord/test/cases/dirty_test.rb | 2 +- activerecord/test/cases/locking_test.rb | 76 ++++++++++++++++++++++ 4 files changed, 90 insertions(+), 7 deletions(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index db9c394a65..f847c71420 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,8 @@ +* Optimistic locking: Added ability update locking_column value. + Ignore optimistic locking if update with new locking_column value. + + *bogdanvlviv* + * Fixed: Optimistic locking does not work well with null in the database. Fixes #26024 diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb index fa9e789b24..d39b7181f4 100644 --- a/activerecord/lib/active_record/locking/optimistic.rb +++ b/activerecord/lib/active_record/locking/optimistic.rb @@ -78,17 +78,19 @@ module ActiveRecord def _update_record(attribute_names = self.attribute_names) #:nodoc: return super unless locking_enabled? - return 0 if attribute_names.empty? lock_col = self.class.locking_column - previous_lock_value = read_attribute_before_type_cast(lock_col) - - increment_lock - attribute_names += [lock_col] - attribute_names.uniq! + return super if attribute_names.include?(lock_col) + return 0 if attribute_names.empty? begin + previous_lock_value = read_attribute_before_type_cast(lock_col) + + increment_lock + + attribute_names.push(lock_col) + relation = self.class.unscoped affected_rows = relation.where( diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb index 09bd00291d..3bd8475bb0 100644 --- a/activerecord/test/cases/dirty_test.rb +++ b/activerecord/test/cases/dirty_test.rb @@ -341,7 +341,7 @@ class DirtyTest < ActiveRecord::TestCase def test_partial_update_with_optimistic_locking person = Person.new(first_name: "foo") - old_lock_version = 1 + old_lock_version = person.lock_version with_partial_writes Person, false do assert_queries(2) { 2.times { person.save! } } diff --git a/activerecord/test/cases/locking_test.rb b/activerecord/test/cases/locking_test.rb index 8b6a969c9e..0579df0a07 100644 --- a/activerecord/test/cases/locking_test.rb +++ b/activerecord/test/cases/locking_test.rb @@ -247,6 +247,44 @@ class OptimisticLockingTest < ActiveRecord::TestCase assert_equal "new title2", t2.title end + def test_lock_without_default_should_update_with_lock_col + t1 = LockWithoutDefault.create(title: "title1", lock_version: 6) + + assert_equal 6, t1.lock_version + + t1.update(lock_version: 0) + t1.reload + + assert_equal 0, t1.lock_version + end + + def test_lock_without_default_queries_count + t1 = LockWithoutDefault.create(title: "title1") + + assert_equal "title1", t1.title + assert_equal 0, t1.lock_version + + assert_queries(1) { t1.update(title: "title2") } + + t1.reload + assert_equal "title2", t1.title + assert_equal 1, t1.lock_version + + assert_queries(1) { t1.update(title: "title3", lock_version: 6) } + + t1.reload + assert_equal "title3", t1.title + assert_equal 6, t1.lock_version + + t2 = LockWithoutDefault.new(title: "title1") + + assert_queries(1) { t2.save! } + + t2.reload + assert_equal "title1", t2.title + assert_equal 0, t2.lock_version + end + def test_lock_with_custom_column_without_default_sets_version_to_zero t1 = LockWithCustomColumnWithoutDefault.new @@ -283,6 +321,44 @@ class OptimisticLockingTest < ActiveRecord::TestCase assert_equal "new title2", t2.title end + def test_lock_with_custom_column_without_default_should_update_with_lock_col + t1 = LockWithCustomColumnWithoutDefault.create(title: "title1", custom_lock_version: 6) + + assert_equal 6, t1.custom_lock_version + + t1.update(custom_lock_version: 0) + t1.reload + + assert_equal 0, t1.custom_lock_version + end + + def test_lock_with_custom_column_without_default_queries_count + t1 = LockWithCustomColumnWithoutDefault.create(title: "title1") + + assert_equal "title1", t1.title + assert_equal 0, t1.custom_lock_version + + assert_queries(1) { t1.update(title: "title2") } + + t1.reload + assert_equal "title2", t1.title + assert_equal 1, t1.custom_lock_version + + assert_queries(1) { t1.update(title: "title3", custom_lock_version: 6) } + + t1.reload + assert_equal "title3", t1.title + assert_equal 6, t1.custom_lock_version + + t2 = LockWithCustomColumnWithoutDefault.new(title: "title1") + + assert_queries(1) { t2.save! } + + t2.reload + assert_equal "title1", t2.title + assert_equal 0, t2.custom_lock_version + end + def test_readonly_attributes assert_equal Set.new([ "name" ]), ReadonlyNameShip.readonly_attributes -- cgit v1.2.3 From e16a5fb508bf7833d7f7a9429ccd3b20990b7d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 21 Oct 2016 16:14:39 -0300 Subject: Revert "Undefine assings in IntegrationTest" This reverts commit 5dde413e1d14c42eb87071db20d075a7b962cb01. Reason: The gem defines it so we don't need to remove --- actionpack/lib/action_dispatch/testing/integration.rb | 2 -- actionpack/test/controller/integration_test.rb | 8 -------- 2 files changed, 10 deletions(-) diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index e24b943026..e2ea96513c 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -599,8 +599,6 @@ module ActionDispatch class IntegrationTest < ActiveSupport::TestCase include TestProcess - undef :assigns - module UrlOptions extend ActiveSupport::Concern def url_options diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 652c0f0dd2..1f02e0e908 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -153,14 +153,6 @@ class IntegrationTestTest < ActiveSupport::TestCase mixin.__send__(:remove_method, :method_missing) end end - - def test_assigns_is_undefined_and_not_point_to_the_gem - e = assert_raises(NoMethodError) do - @test.assigns(:foo) - end - - assert_match(/undefined method/, e.message) - end end # Tests that integration tests don't call Controller test methods for processing. -- cgit v1.2.3 From 9531e69f996643b57d25f6b9faa08346f011eed8 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Fri, 21 Oct 2016 14:36:51 -0500 Subject: Skip test that depends on RubyVM when it is not available (JRuby). --- activesupport/test/executor_test.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/activesupport/test/executor_test.rb b/activesupport/test/executor_test.rb index d409216206..03ec6020c3 100644 --- a/activesupport/test/executor_test.rb +++ b/activesupport/test/executor_test.rb @@ -192,6 +192,8 @@ class ExecutorTest < ActiveSupport::TestCase end def test_class_serial_is_unaffected + skip if !defined?(RubyVM) + hook = Class.new do define_method(:run) do nil -- cgit v1.2.3 From 797f1dd63c68eb44c1af358d377cfef271e685c5 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 21 Oct 2016 11:27:26 -0700 Subject: Prevent the test framework from being loaded in production mode The test framework should not be autoloaded in production mode. Before this commit, the testing railtie would extend AS::TestCase. This caused AS::TestCase to be preloaded regardless of the environment in which we were running. This commit just moves the code that adds line filtering support in to the test command where we actually execute the test runner. That allows us to maintain the line runner feature but only load the minimal amount of code we need. --- railties/lib/rails/commands/test/test_command.rb | 5 +++++ railties/lib/rails/test_unit/railtie.rb | 6 ------ railties/test/application/runner_test.rb | 9 +++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/railties/lib/rails/commands/test/test_command.rb b/railties/lib/rails/commands/test/test_command.rb index 1b2e3af9cc..e97b9cbbba 100644 --- a/railties/lib/rails/commands/test/test_command.rb +++ b/railties/lib/rails/commands/test/test_command.rb @@ -1,5 +1,6 @@ require "rails/command" require "rails/test_unit/minitest_plugin" +require "rails/test_unit/line_filtering" module Rails module Command @@ -11,6 +12,10 @@ module Rails def perform(*) $LOAD_PATH << Rails::Command.root.join("test") + # Add test line filtering support for running test by line number + # via the command line. + ActiveSupport::TestCase.extend Rails::LineFiltering + Minitest.run_via[:rails] = true require "active_support/testing/autorun" diff --git a/railties/lib/rails/test_unit/railtie.rb b/railties/lib/rails/test_unit/railtie.rb index d0fc795515..ec91673e40 100644 --- a/railties/lib/rails/test_unit/railtie.rb +++ b/railties/lib/rails/test_unit/railtie.rb @@ -1,5 +1,3 @@ -require "rails/test_unit/line_filtering" - if defined?(Rake.application) && Rake.application.top_level_tasks.grep(/^(default$|test(:|$))/).any? ENV["RAILS_ENV"] ||= "test" end @@ -13,10 +11,6 @@ module Rails c.integration_tool :test_unit end - initializer "test_unit.line_filtering" do - ActiveSupport::TestCase.extend Rails::LineFiltering - end - rake_tasks do load "rails/test_unit/testing.rake" end diff --git a/railties/test/application/runner_test.rb b/railties/test/application/runner_test.rb index 77e7a2cca5..8769703f66 100644 --- a/railties/test/application/runner_test.rb +++ b/railties/test/application/runner_test.rb @@ -43,6 +43,15 @@ module ApplicationTests assert_match "42", Dir.chdir(app_path) { `bin/rails runner "bin/count_users.rb"` } end + def test_no_minitest_loaded_in_production_mode + app_file "bin/print_features.rb", <<-SCRIPT + p $LOADED_FEATURES.grep(/minitest/) + SCRIPT + assert_match "[]", Dir.chdir(app_path) { + `RAILS_ENV=production bin/rails runner "bin/print_features.rb"` + } + end + def test_should_set_dollar_0_to_file app_file "bin/dollar0.rb", <<-SCRIPT puts $0 -- cgit v1.2.3 From fe09e7bd7155e8ff9ae58671a4a3508d52d54712 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Fri, 21 Oct 2016 15:57:35 -0500 Subject: Soften this test since YAML.dump may produce keys in other orders. --- actionpack/test/controller/parameters/serialization_test.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/actionpack/test/controller/parameters/serialization_test.rb b/actionpack/test/controller/parameters/serialization_test.rb index 4fb1564c68..6fba2fde91 100644 --- a/actionpack/test/controller/parameters/serialization_test.rb +++ b/actionpack/test/controller/parameters/serialization_test.rb @@ -14,12 +14,10 @@ class ParametersSerializationTest < ActiveSupport::TestCase test "yaml serialization" do params = ActionController::Parameters.new(key: :value) - assert_equal <<-end_of_yaml.strip_heredoc, YAML.dump(params) - --- !ruby/object:ActionController::Parameters - parameters: !ruby/hash:ActiveSupport::HashWithIndifferentAccess - key: :value - permitted: false - end_of_yaml + yaml_dump = YAML.dump(params) + assert_match("--- !ruby/object:ActionController::Parameters", yaml_dump) + assert_match(/parameters: !ruby\/hash:ActiveSupport::HashWithIndifferentAccess\n\s+key: :value/, yaml_dump) + assert_match("permitted: false", yaml_dump) end test "yaml deserialization" do -- cgit v1.2.3 From b6f935bbf9b8470b370ea613dc61218849aabf89 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 21 Oct 2016 14:44:17 -0700 Subject: Use `on_load` to trigger commandline processing code We need to use on_load so that plugins will get the same functionality --- activesupport/lib/active_support/test_case.rb | 2 ++ railties/lib/rails/commands/test/test_command.rb | 5 ----- railties/lib/rails/test_unit/railtie.rb | 8 ++++++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index 1c599b8851..3de4ccc1da 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -65,5 +65,7 @@ module ActiveSupport alias :assert_not_predicate :refute_predicate alias :assert_not_respond_to :refute_respond_to alias :assert_not_same :refute_same + + ActiveSupport.run_load_hooks(:active_support_test_case, self) end end diff --git a/railties/lib/rails/commands/test/test_command.rb b/railties/lib/rails/commands/test/test_command.rb index e97b9cbbba..1b2e3af9cc 100644 --- a/railties/lib/rails/commands/test/test_command.rb +++ b/railties/lib/rails/commands/test/test_command.rb @@ -1,6 +1,5 @@ require "rails/command" require "rails/test_unit/minitest_plugin" -require "rails/test_unit/line_filtering" module Rails module Command @@ -12,10 +11,6 @@ module Rails def perform(*) $LOAD_PATH << Rails::Command.root.join("test") - # Add test line filtering support for running test by line number - # via the command line. - ActiveSupport::TestCase.extend Rails::LineFiltering - Minitest.run_via[:rails] = true require "active_support/testing/autorun" diff --git a/railties/lib/rails/test_unit/railtie.rb b/railties/lib/rails/test_unit/railtie.rb index ec91673e40..746120e6a1 100644 --- a/railties/lib/rails/test_unit/railtie.rb +++ b/railties/lib/rails/test_unit/railtie.rb @@ -1,3 +1,5 @@ +require "rails/test_unit/line_filtering" + if defined?(Rake.application) && Rake.application.top_level_tasks.grep(/^(default$|test(:|$))/).any? ENV["RAILS_ENV"] ||= "test" end @@ -11,6 +13,12 @@ module Rails c.integration_tool :test_unit end + initializer "test_unit.line_filtering" do + ActiveSupport.on_load(:active_support_test_case) { + ActiveSupport::TestCase.extend Rails::LineFiltering + } + end + rake_tasks do load "rails/test_unit/testing.rake" end -- cgit v1.2.3 From 51de32b2ec8543a91a8a37013445455dd1d02115 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Fri, 21 Oct 2016 17:19:44 -0500 Subject: Lazy-load blade for actioncable tests; no blade on JRuby. --- actioncable/Rakefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/actioncable/Rakefile b/actioncable/Rakefile index 648de57004..87d443919c 100644 --- a/actioncable/Rakefile +++ b/actioncable/Rakefile @@ -1,7 +1,6 @@ require "rake/testtask" require "pathname" require "action_cable" -require "blade" dir = File.dirname(__FILE__) @@ -25,6 +24,7 @@ namespace :test do end task :integration do + require "blade" if ENV["CI"] Blade.start(interface: :ci) else @@ -36,6 +36,7 @@ end namespace :assets do desc "Compile Action Cable assets" task :compile do + require "blade" Blade.build end end -- cgit v1.2.3 From 56bfaf7f03882f738bb65fd232b4c67541afc4f5 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Wed, 7 Sep 2016 11:35:01 +0530 Subject: Fix regression caused due to removal of select method from CollectionAssociation - CollectionAssociation#select was removed in https://github.com/rails/rails/pull/25989 in favor of QueryMethods#select but it caused a regression when passing arguments to select and a block. - This used to work earlier in Rails 4.2 and Rails 5. See gist https://gist.github.com/prathamesh-sonpatki/a7df922273473a77dfbc742a4be4b618. - This commit restores the behavior of Rails 4.2 and Rails 5.0.0 to allow passing arguments and block at the same time but also deprecates it. - Because, these arguments do not have any effect on the output of select when select is used with a block. - Updated documentation to remove the example passing arguments and block at the same time to `CollectionProxy#select`. --- activerecord/CHANGELOG.md | 5 +++++ .../lib/active_record/associations/collection_proxy.rb | 6 ------ activerecord/lib/active_record/relation/query_methods.rb | 11 ++++++++++- .../test/cases/associations/has_many_associations_test.rb | 7 +++++++ 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index f847c71420..cc7ba49c87 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,8 @@ +* Deprecate passing arguments and block at the same time to + `ActiveRecord::QueryMethods#select`. + + *Prathamesh Sonpatki* + * Optimistic locking: Added ability update locking_column value. Ignore optimistic locking if update with new locking_column value. diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index dda240585e..0800639c24 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -106,12 +106,6 @@ module ActiveRecord # # #, # # # # # ] - # - # person.pets.select(:name) { |pet| pet.name =~ /oo/ } - # # => [ - # # #, - # # # - # # ] # Finds an object in the collection responding to the +id+. Uses the same # rules as ActiveRecord::Base.find. Returns ActiveRecord::RecordNotFound diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 9fbbe32e7f..c6d0902e0d 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -242,7 +242,16 @@ module ActiveRecord # Model.select(:field).first.other_field # # => ActiveModel::MissingAttributeError: missing attribute: other_field def select(*fields) - return super if block_given? + if block_given? + if fields.any? + ActiveSupport::Deprecation.warn(<<-WARNING.squish) + When select is called with a block, it ignores other arguments. This behavior is now deprecated and will result in an ArgumentError in Rails 5.1. You can safely remove the arguments to resolve the deprecation warning because they do not have any effect on the output of the call to the select method with a block. + WARNING + end + + return super() + end + raise ArgumentError, "Call this with at least one field" if fields.empty? spawn._select!(*fields) end diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 0ce67f971b..c1e04714fb 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -788,6 +788,13 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal [1], posts(:welcome).comments.select { |c| c.id == 1 }.map(&:id) end + def test_select_with_block_and_specific_attributes + assert_deprecated do + comments = posts(:welcome).comments.select(:id, :body) { |c| c.id == 1 } + assert_equal [1], comments.map(&:id) + end + end + def test_select_without_foreign_key assert_equal companies(:first_firm).accounts.first.credit_limit, companies(:first_firm).accounts.select(:credit_limit).first.credit_limit end -- cgit v1.2.3 From fbda46758bdf4b356df468d92f86111b779265cf Mon Sep 17 00:00:00 2001 From: claudiob Date: Fri, 21 Oct 2016 22:48:14 -0700 Subject: Revert #26826 and add documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit a01cf703 as explained in the comment to #26826: Realized that this PR caused the following warning in Travis CI: ``` /home/travis/build/rails/rails/activesupport/lib/active_support/dependencies.rb:293: warning: loading in progress, circular require considered harmful - /home/travis/build/rails/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb ``` Indeed, `active_support/core_ext/hash/indifferent_access.rb` **needs** to require `active_support/hash_with_indifferent_access.rb` in order to access the class `ActiveSupport::HashWithIndifferentAccess`. The other way around, though, is not _strictly_ required, unless someone tries (like I did in the [gist above](https://gist.github.com/claudiob/43cc7fe77ff95951538af2825a71e5ec)) to use `ActiveSupport::HashWithIndifferentAccess` by only requiring `active_support/hash_with_indifferent_access.rb` without first requiring `active_support/core_ext/hash/indifferent_access.rb`. I think the solution to this is to revert this PR and instead change the documentation to explicitly state that **developers should not require 'active_support/hash_with_indifferent_access'** if all they want is to use `ActiveSupport::HashWithIndifferentAccess` – instead they should require `active_support/core_ext/hash/indifferent_access.rb`. --- activesupport/lib/active_support/hash_with_indifferent_access.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index a56943d99d..7ecc5c19bd 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -1,6 +1,5 @@ require "active_support/core_ext/hash/keys" require "active_support/core_ext/hash/reverse_merge" -require "active_support/core_ext/hash/indifferent_access" module ActiveSupport # Implements a hash where keys :foo and "foo" are considered @@ -41,6 +40,12 @@ module ActiveSupport # rgb = { black: '#000000', white: '#FFFFFF' }.with_indifferent_access # # which may be handy. + # + # To access this class outside of Rails, require the core extension with: + # + # require "active_support/core_ext/hash/indifferent_access" + # + # which will, in turn, require this file. class HashWithIndifferentAccess < Hash # Returns +true+ so that Array#extract_options! finds members of # this class. -- cgit v1.2.3 From f13ec72664fd13d33d617103ca964a7592295854 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sat, 22 Oct 2016 20:06:34 -0500 Subject: Update mysql adapter error message when disconnected --- activerecord/test/cases/adapters/mysql2/connection_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activerecord/test/cases/adapters/mysql2/connection_test.rb b/activerecord/test/cases/adapters/mysql2/connection_test.rb index 8d8955e5c9..b441ce3a34 100644 --- a/activerecord/test/cases/adapters/mysql2/connection_test.rb +++ b/activerecord/test/cases/adapters/mysql2/connection_test.rb @@ -68,7 +68,7 @@ class Mysql2ConnectionTest < ActiveRecord::Mysql2TestCase error = assert_raise(ActiveRecord::StatementInvalid) do @connection.execute("SELECT 1") end - assert_match(/closed MySQL connection/, error.message) + assert_match(/MySQL client is not connected/, error.message) end def test_quote_after_disconnect @@ -76,7 +76,7 @@ class Mysql2ConnectionTest < ActiveRecord::Mysql2TestCase error = assert_raise(Mysql2::Error) do @connection.quote("string") end - assert_match(/closed MySQL connection/, error.message) + assert_match(/MySQL client is not connected/, error.message) end def test_active_after_disconnect -- cgit v1.2.3 From 52852733d28c22199cafaf392a96745644967f9b Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sat, 22 Oct 2016 20:09:02 -0500 Subject: Update mysql2 version in Gemfile.lock --- Gemfile.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d4059c607d..1513bc2f0a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -235,9 +235,9 @@ GEM multi_json (1.12.1) multipart-post (2.0.0) mustache (1.0.3) - mysql2 (0.4.4) - mysql2 (0.4.4-x64-mingw32) - mysql2 (0.4.4-x86-mingw32) + mysql2 (0.4.5) + mysql2 (0.4.5-x64-mingw32) + mysql2 (0.4.5-x86-mingw32) nio4r (1.2.1) nokogiri (1.6.8) mini_portile2 (~> 2.1.0) @@ -421,4 +421,4 @@ DEPENDENCIES websocket-client-simple! BUNDLED WITH - 1.13.2 + 1.13.6 -- cgit v1.2.3 From 331d080a66fe90609f76a5d6b4e9b844186f78cf Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Sun, 23 Oct 2016 09:19:54 +0300 Subject: Revert "Made ActiveRecord consistently use ActiveRecord::Type (not" This reverts commit 671eb742eec77b5c8281ac2a2e3976ef32a6e424. This is not a change we would like moving forward. --- activerecord/CHANGELOG.md | 4 ---- activerecord/lib/active_record/attribute_methods/query.rb | 2 +- activerecord/lib/active_record/type.rb | 4 ++-- activerecord/lib/active_record/type/helpers.rb | 5 ----- activerecord/lib/active_record/type/internal/abstract_json.rb | 4 ++-- activerecord/lib/active_record/type/serialized.rb | 4 ++-- activerecord/lib/active_record/type/value.rb | 5 ----- activerecord/test/cases/serialized_attribute_test.rb | 4 ++-- 8 files changed, 9 insertions(+), 23 deletions(-) delete mode 100644 activerecord/lib/active_record/type/helpers.rb delete mode 100644 activerecord/lib/active_record/type/value.rb diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index cc7ba49c87..487195a2e0 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -19,10 +19,6 @@ *Edho Arief* -* Made ActiveRecord consistently use `ActiveRecord::Type` (not `ActiveModel::Type`) - - *Iain Beeston* - * Serialize JSON attribute value `nil` as SQL `NULL`, not JSON `null` *Trung Duc Tran* diff --git a/activerecord/lib/active_record/attribute_methods/query.rb b/activerecord/lib/active_record/attribute_methods/query.rb index 05f0e974b6..10498f4322 100644 --- a/activerecord/lib/active_record/attribute_methods/query.rb +++ b/activerecord/lib/active_record/attribute_methods/query.rb @@ -19,7 +19,7 @@ module ActiveRecord if Numeric === value || value !~ /[^0-9]/ !value.to_i.zero? else - return false if ActiveRecord::Type::Boolean::FALSE_VALUES.include?(value) + return false if ActiveModel::Type::Boolean::FALSE_VALUES.include?(value) !value.blank? end elsif value.respond_to?(:zero?) diff --git a/activerecord/lib/active_record/type.rb b/activerecord/lib/active_record/type.rb index 84373dddf2..0b48d2186a 100644 --- a/activerecord/lib/active_record/type.rb +++ b/activerecord/lib/active_record/type.rb @@ -1,6 +1,4 @@ require "active_model/type" -require "active_record/type/helpers" -require "active_record/type/value" require "active_record/type/internal/abstract_json" require "active_record/type/internal/timezone" @@ -50,6 +48,7 @@ module ActiveRecord end end + Helpers = ActiveModel::Type::Helpers BigInteger = ActiveModel::Type::BigInteger Binary = ActiveModel::Type::Binary Boolean = ActiveModel::Type::Boolean @@ -60,6 +59,7 @@ module ActiveRecord String = ActiveModel::Type::String Text = ActiveModel::Type::Text UnsignedInteger = ActiveModel::Type::UnsignedInteger + Value = ActiveModel::Type::Value register(:big_integer, Type::BigInteger, override: false) register(:binary, Type::Binary, override: false) diff --git a/activerecord/lib/active_record/type/helpers.rb b/activerecord/lib/active_record/type/helpers.rb deleted file mode 100644 index a32ccd4bc3..0000000000 --- a/activerecord/lib/active_record/type/helpers.rb +++ /dev/null @@ -1,5 +0,0 @@ -module ActiveRecord - module Type - Helpers = ActiveModel::Type::Helpers - end -end diff --git a/activerecord/lib/active_record/type/internal/abstract_json.rb b/activerecord/lib/active_record/type/internal/abstract_json.rb index 67028546e4..e19c5a14da 100644 --- a/activerecord/lib/active_record/type/internal/abstract_json.rb +++ b/activerecord/lib/active_record/type/internal/abstract_json.rb @@ -1,8 +1,8 @@ module ActiveRecord module Type module Internal # :nodoc: - class AbstractJson < Type::Value # :nodoc: - include Type::Helpers::Mutable + class AbstractJson < ActiveModel::Type::Value # :nodoc: + include ActiveModel::Type::Helpers::Mutable def type :json diff --git a/activerecord/lib/active_record/type/serialized.rb b/activerecord/lib/active_record/type/serialized.rb index ca12c83b1a..ac9134bfcb 100644 --- a/activerecord/lib/active_record/type/serialized.rb +++ b/activerecord/lib/active_record/type/serialized.rb @@ -1,7 +1,7 @@ module ActiveRecord module Type - class Serialized < DelegateClass(Type::Value) # :nodoc: - include Type::Helpers::Mutable + class Serialized < DelegateClass(ActiveModel::Type::Value) # :nodoc: + include ActiveModel::Type::Helpers::Mutable attr_reader :subtype, :coder diff --git a/activerecord/lib/active_record/type/value.rb b/activerecord/lib/active_record/type/value.rb deleted file mode 100644 index 89ef29106b..0000000000 --- a/activerecord/lib/active_record/type/value.rb +++ /dev/null @@ -1,5 +0,0 @@ -module ActiveRecord - module Type - class Value < ActiveModel::Type::Value; end - end -end diff --git a/activerecord/test/cases/serialized_attribute_test.rb b/activerecord/test/cases/serialized_attribute_test.rb index 8e9514de7c..bebd856faf 100644 --- a/activerecord/test/cases/serialized_attribute_test.rb +++ b/activerecord/test/cases/serialized_attribute_test.rb @@ -313,8 +313,8 @@ class SerializedAttributeTest < ActiveRecord::TestCase return if value.nil? value.gsub(" encoded", "") end - type = Class.new(ActiveRecord::Type::Value) do - include ActiveRecord::Type::Helpers::Mutable + type = Class.new(ActiveModel::Type::Value) do + include ActiveModel::Type::Helpers::Mutable def serialize(value) return if value.nil? -- cgit v1.2.3 From 2bb74c9a82da04cae9e7266b8f0f0cc5802ce1bc Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Sun, 23 Oct 2016 17:22:31 +0300 Subject: Add info about updating locking column value [ci skip] Follow #26050 --- activerecord/lib/active_record/locking/optimistic.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb index d39b7181f4..98215b1c9b 100644 --- a/activerecord/lib/active_record/locking/optimistic.rb +++ b/activerecord/lib/active_record/locking/optimistic.rb @@ -47,6 +47,7 @@ module ActiveRecord # self.locking_column = :lock_person # end # + # Note that, optimistic locking will be ignored if you update the locking column value. module Optimistic extend ActiveSupport::Concern -- cgit v1.2.3 From 69a3fa1efc979f9d65110560d9779c2f8a74d8f6 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sun, 23 Oct 2016 20:03:40 +0530 Subject: Use Hash#compact and Hash#compact! from Ruby 2.4 - Ruby 2.4 has added Hash#compact and Hash#compact! so we can use it now. - Reference: https://bugs.ruby-lang.org/issues/11818 and https://bugs.ruby-lang.org/issues/12863. --- activesupport/CHANGELOG.md | 9 +++-- .../lib/active_support/core_ext/hash/compact.rb | 40 ++++++++++++---------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 13d152f4c6..83ff80e31a 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,8 @@ +* Use `Hash#compact` and `Hash#compact!` from Ruby 2.4. Old Ruby versions + will continue to get these methods from Active Support as before. + + *Prathamesh Sonpatki* + * Fix `ActiveSupport::TimeZone#strptime`. Support for timestamps in format of seconds (%s) and milliseconds (%Q). @@ -21,10 +26,10 @@ Time.zone = "US/Eastern" t = Time.zone.local(2016,11,6,1) - # => Sun, 06 Nov 2016 01:00:00 EDT -05:00 + # => Sun, 06 Nov 2016 01:00:00 EDT -05:00 t.in(1.hour) - # => Sun, 06 Nov 2016 01:00:00 EST -05:00 + # => Sun, 06 Nov 2016 01:00:00 EST -05:00 Fixes #26580. diff --git a/activesupport/lib/active_support/core_ext/hash/compact.rb b/activesupport/lib/active_support/core_ext/hash/compact.rb index 78b3387c3b..5cae495bda 100644 --- a/activesupport/lib/active_support/core_ext/hash/compact.rb +++ b/activesupport/lib/active_support/core_ext/hash/compact.rb @@ -1,23 +1,27 @@ class Hash - # Returns a hash with non +nil+ values. - # - # hash = { a: true, b: false, c: nil } - # hash.compact # => { a: true, b: false } - # hash # => { a: true, b: false, c: nil } - # { c: nil }.compact # => {} - # { c: true }.compact # => { c: true } - def compact - select { |_, value| !value.nil? } + unless Hash.instance_methods(false).include?(:compact) + # Returns a hash with non +nil+ values. + # + # hash = { a: true, b: false, c: nil } + # hash.compact # => { a: true, b: false } + # hash # => { a: true, b: false, c: nil } + # { c: nil }.compact # => {} + # { c: true }.compact # => { c: true } + def compact + select { |_, value| !value.nil? } + end end - # Replaces current hash with non +nil+ values. - # Returns nil if no changes were made, otherwise returns the hash. - # - # hash = { a: true, b: false, c: nil } - # hash.compact! # => { a: true, b: false } - # hash # => { a: true, b: false } - # { c: true }.compact! # => nil - def compact! - reject! { |_, value| value.nil? } + unless Hash.instance_methods(false).include?(:compact!) + # Replaces current hash with non +nil+ values. + # Returns nil if no changes were made, otherwise returns the hash. + # + # hash = { a: true, b: false, c: nil } + # hash.compact! # => { a: true, b: false } + # hash # => { a: true, b: false } + # { c: true }.compact! # => nil + def compact! + reject! { |_, value| value.nil? } + end end end -- cgit v1.2.3 From c5a4d007b8147c2f042844ac267821afa378d8e5 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sun, 23 Oct 2016 21:17:31 +0530 Subject: Fix brittle tests which were relying on the error message text from mysql2 gem - These tests were fixed earlier on master in https://github.com/rails/rails/commit/f13ec72664fd13d33d617103ca964a7592295854. - They started failing in first place due to change in https://github.com/brianmario/mysql2/commit/f14023fcfee9e85e6fc1b0e568048811518f8c23. - They will fail again when the message is changed in mysql2 so let's not rely on the error message. --- activerecord/test/cases/adapters/mysql2/connection_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/activerecord/test/cases/adapters/mysql2/connection_test.rb b/activerecord/test/cases/adapters/mysql2/connection_test.rb index b441ce3a34..ff012efc5f 100644 --- a/activerecord/test/cases/adapters/mysql2/connection_test.rb +++ b/activerecord/test/cases/adapters/mysql2/connection_test.rb @@ -65,18 +65,18 @@ class Mysql2ConnectionTest < ActiveRecord::Mysql2TestCase def test_execute_after_disconnect @connection.disconnect! - error = assert_raise(ActiveRecord::StatementInvalid) do + + assert_raise(ActiveRecord::StatementInvalid) do @connection.execute("SELECT 1") end - assert_match(/MySQL client is not connected/, error.message) end def test_quote_after_disconnect @connection.disconnect! - error = assert_raise(Mysql2::Error) do + + assert_raise(Mysql2::Error) do @connection.quote("string") end - assert_match(/MySQL client is not connected/, error.message) end def test_active_after_disconnect -- cgit v1.2.3 From a3ce625c76355ebd095d55bb5c3864db73247826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=AA=E0=A5=8D=E0=A4=B0=E0=A4=A5=E0=A4=AE=E0=A5=87?= =?UTF-8?q?=E0=A4=B6=20Sonpatki?= Date: Sun, 23 Oct 2016 21:27:59 +0530 Subject: HSTS subdomains is now true, so let's fix documentation [ci skip] (#26870) - Followup of fda5afeb --- actionpack/lib/action_dispatch/middleware/ssl.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionpack/lib/action_dispatch/middleware/ssl.rb b/actionpack/lib/action_dispatch/middleware/ssl.rb index c9bd417aa2..557721c301 100644 --- a/actionpack/lib/action_dispatch/middleware/ssl.rb +++ b/actionpack/lib/action_dispatch/middleware/ssl.rb @@ -23,7 +23,7 @@ module ActionDispatch # `180.days` (recommended). # * `subdomains`: Set to `true` to tell the browser to apply these settings # to all subdomains. This protects your cookies from interception by a - # vulnerable site on a subdomain. Defaults to `false`. + # vulnerable site on a subdomain. Defaults to `true`. # * `preload`: Advertise that this site may be included in browsers' # preloaded HSTS lists. HSTS protects your site on every visit *except the # first visit* since it hasn't seen your HSTS header yet. To close this -- cgit v1.2.3 From 65b1c991b18852e879df8b3c092cc286c5c087f9 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sun, 23 Oct 2016 12:21:35 -0400 Subject: Small grammar fix for #26867 [ci skip] --- activerecord/lib/active_record/locking/optimistic.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb index 98215b1c9b..82882469e3 100644 --- a/activerecord/lib/active_record/locking/optimistic.rb +++ b/activerecord/lib/active_record/locking/optimistic.rb @@ -47,7 +47,8 @@ module ActiveRecord # self.locking_column = :lock_person # end # - # Note that, optimistic locking will be ignored if you update the locking column value. + # Please note that the optimistic locking will be ignored if you update the + # locking column's value. module Optimistic extend ActiveSupport::Concern -- cgit v1.2.3 From a0d0648efb5faa5d8d94a090e8b6ff498a7a9475 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Sun, 23 Oct 2016 16:50:07 -0200 Subject: Merge release note entry for Date/Time/DateTime extensions The first release note entry mentioned #on_weekday?, but that was only added by the second PR mentioned there. To simplify reading the notes just merge the two, since they are related methods. [ci skip] --- guides/source/5_0_release_notes.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/guides/source/5_0_release_notes.md b/guides/source/5_0_release_notes.md index cc332cbf97..964dbf9450 100644 --- a/guides/source/5_0_release_notes.md +++ b/guides/source/5_0_release_notes.md @@ -1000,7 +1000,8 @@ Please refer to the [Changelog][active-support] for detailed changes. * Added `#on_weekend?`, `#on_weekday?`, `#next_weekday`, `#prev_weekday` methods to `Date`, `Time`, and `DateTime`. - ([Pull Request](https://github.com/rails/rails/pull/18335)) + ([Pull Request](https://github.com/rails/rails/pull/18335), + [Pull Request](https://github.com/rails/rails/pull/23687)) * Added `same_time` option to `#next_week` and `#prev_week` for `Date`, `Time`, and `DateTime`. @@ -1051,9 +1052,6 @@ Please refer to the [Changelog][active-support] for detailed changes. * Added `Array#second_to_last` and `Array#third_to_last` methods. ([Pull Request](https://github.com/rails/rails/pull/23583)) -* Added `#on_weekday?` method to `Date`, `Time`, and `DateTime`. - ([Pull Request](https://github.com/rails/rails/pull/23687)) - * Publish `ActiveSupport::Executor` and `ActiveSupport::Reloader` APIs to allow components and libraries to manage, and participate in, the execution of application code, and the application reloading process. -- cgit v1.2.3 From 308e84e982b940983b4b3d5b41b0b3ac11fbae40 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 24 Oct 2016 18:26:13 +0800 Subject: `Broadcast#silence` breaks custom loggers that does not include `LoggerSilence`. --- activesupport/lib/active_support/logger.rb | 4 ++-- activesupport/test/broadcast_logger_test.rb | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/activesupport/lib/active_support/logger.rb b/activesupport/lib/active_support/logger.rb index 3ba6461b57..ea09d7d2df 100644 --- a/activesupport/lib/active_support/logger.rb +++ b/activesupport/lib/active_support/logger.rb @@ -59,14 +59,14 @@ module ActiveSupport define_method(:silence) do |level = Logger::ERROR, &block| if logger.respond_to?(:silence) logger.silence(level) do - if respond_to?(:silence) + if defined?(super) super(level, &block) else block.call(self) end end else - if respond_to?(:silence) + if defined?(super) super(level, &block) else block.call(self) diff --git a/activesupport/test/broadcast_logger_test.rb b/activesupport/test/broadcast_logger_test.rb index 4b74f1313e..aaa657ce13 100644 --- a/activesupport/test/broadcast_logger_test.rb +++ b/activesupport/test/broadcast_logger_test.rb @@ -69,6 +69,20 @@ module ActiveSupport assert_equal ::Logger::FATAL, log2.local_level end + test "#silence does not break custom loggers" do + new_logger = FakeLogger.new + custom_logger = CustomLogger.new + custom_logger.extend(Logger.broadcast(new_logger)) + + custom_logger.silence do + custom_logger.error "from error" + custom_logger.unknown "from unknown" + end + + assert_equal [[::Logger::ERROR, "from error", nil], [::Logger::UNKNOWN, "from unknown", nil]], custom_logger.adds + assert_equal [[::Logger::ERROR, "from error", nil], [::Logger::UNKNOWN, "from unknown", nil]], new_logger.adds + end + test "#silence silences all loggers below the default level of ERROR" do logger.silence do logger.debug "test" @@ -98,9 +112,7 @@ module ActiveSupport assert_equal [[::Logger::FATAL, "seen", nil]], log2.adds end - class FakeLogger - include LoggerSilence - + class CustomLogger attr_reader :adds, :closed, :chevrons attr_accessor :level, :progname, :formatter, :local_level @@ -150,5 +162,9 @@ module ActiveSupport @closed = true end end + + class FakeLogger < CustomLogger + include LoggerSilence + end end end -- cgit v1.2.3 From 0f87413f41050d6e3eacefb97a05a5d954f602d1 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Mon, 24 Oct 2016 20:17:31 +0900 Subject: update description of Etag [ci skip] The document is written with "only generate weak", but it can also be used to strong etag. Also, add missing entory for #24387 --- guides/source/5_0_release_notes.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/guides/source/5_0_release_notes.md b/guides/source/5_0_release_notes.md index 964dbf9450..a98f7be067 100644 --- a/guides/source/5_0_release_notes.md +++ b/guides/source/5_0_release_notes.md @@ -417,7 +417,7 @@ Please refer to the [Changelog][action-pack] for detailed changes. `ActionDispatch::IntegrationTest` instead. ([commit](https://github.com/rails/rails/commit/4414c5d1795e815b102571425974a8b1d46d932d)) -* Rails will only generate "weak", instead of strong ETags. +* Rails generates weak ETags by default. ([Pull Request](https://github.com/rails/rails/pull/17573)) * Controller actions without an explicit `render` call and with no @@ -453,6 +453,9 @@ Please refer to the [Changelog][action-pack] for detailed changes. `ActionController::Live`. ([More details in this issue](https://github.com/rails/rails/issues/25581)) +* Introduce `Response#strong_etag=` and `#weak_etag=` and analogous + options for `fresh_when` and `stale?`. + ([Pull Request](https://github.com/rails/rails/pull/24387)) Action View ------------- -- cgit v1.2.3 From 094638e54441c1f375b8a6dd958113e2fc81fcf1 Mon Sep 17 00:00:00 2001 From: Erol Fornoles Date: Mon, 24 Oct 2016 22:28:40 +0800 Subject: Fix typo in Upgrading Ruby on Rails Guide [ci skip] --- guides/source/upgrading_ruby_on_rails.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 2372590cec..dda2b12a3a 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -325,7 +325,7 @@ should support caching. #### Configure the Output of `db:structure:dump` -If you're using `schema_search_path` or other PostgreSQL extentions, you can control how the schema is +If you're using `schema_search_path` or other PostgreSQL extensions, you can control how the schema is dumped. Set to `:all` to generate all dumps, or to `:schema_search_path` to generate from schema search path. config.active_record.dump_schemas = :all -- cgit v1.2.3 From d60af5739c0b0a9501b26b67cc443b9952b72d5d Mon Sep 17 00:00:00 2001 From: Mia Zbikowski Date: Mon, 24 Oct 2016 15:36:33 -0400 Subject: Fix model schema doc strings --- activerecord/lib/active_record/model_schema.rb | 147 +++++++++++++++++-------- 1 file changed, 103 insertions(+), 44 deletions(-) diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb index 76b3169411..524aca23c7 100644 --- a/activerecord/lib/active_record/model_schema.rb +++ b/activerecord/lib/active_record/model_schema.rb @@ -2,71 +2,130 @@ module ActiveRecord module ModelSchema extend ActiveSupport::Concern + ## + # :singleton-method: primary_key_prefix_type + # :call-seq: primary_key_prefix_type + # Accessor for the name of the prefix string to prepend to every table name. So if set + # to "basecamp_", all table names will be named like "basecamp_projects", "basecamp_people", + # etc. This is a convenient way of creating a namespace for tables in a shared database. + # By default, the prefix is the empty string. + # + # If you are organising your models within modules you can add a prefix to the models within + # a namespace by defining a singleton method in the parent module called table_name_prefix which + # returns your chosen prefix. + + ## + # :singleton-method: primary_key_prefix_type= + # :call-seq: primary_key_prefix_type=(prefix) + # Accessor for the name of the prefix string to prepend to every table name. So if set + # to "basecamp_", all table names will be named like "basecamp_projects", "basecamp_people", + # etc. This is a convenient way of creating a namespace for tables in a shared database. + # By default, the prefix is the empty string. + # + # If you are organising your models within modules you can add a prefix to the models within + # a namespace by defining a singleton method in the parent module called table_name_prefix which + # returns your chosen prefix. + + ## + # :singleton-method: table_name_suffix + # :call-seq: table_name_suffix + # Works like +table_name_prefix+, but appends instead of prepends (set to "_basecamp" gives "projects_basecamp", + # "people_basecamp"). By default, the suffix is the empty string. + # + # If you are organising your models within modules, you can add a suffix to the models within + # a namespace by defining a singleton method in the parent module called table_name_suffix which + # returns your chosen suffix. + + ## + # :singleton-method: table_name_suffix= + # :call-seq: table_name_suffix=(suffix) + # Works like +table_name_prefix+, but appends instead of prepends (set to "_basecamp" gives "projects_basecamp", + # "people_basecamp"). By default, the suffix is the empty string. + # + # If you are organising your models within modules, you can add a suffix to the models within + # a namespace by defining a singleton method in the parent module called table_name_suffix which + # returns your chosen suffix. + + ## + # :singleton-method: schema_migrations_table_name + # :call-seq: schema_migrations_table_name + # Accessor for the name of the schema migrations table. By default, the value is "schema_migrations" + + ## + # :singleton-method: schema_migrations_table_name= + # :call-seq: schema_migrations_table_name=(table_name) + # Sets the name of the schema migrations table. By default, the value is "schema_migrations" + + ## + # :singleton-method: internal_metadata_table_name + # :call-seq: internal_metadata_table_name + # Accessor for the name of the internal metadata table. By default, the value is "ar_internal_metadata" + + ## + # :singleton-method: internal_metadata_table_name= + # :call-seq: internal_metadata_table_name=(table_name) + # Sets the name of the internal metadata table. By default, the value is "ar_internal_metadata" + + ## + # :singleton-method: protected_environments + # :call-seq: protected_environments + # Accessor for an array of names of environments where destructive actions should be prohibited. By default, + # the value is ["production"] + + ## + # :singleton-method: protected_environments= + # :call-seq: protected_environments=(environments) + # Sets an array of names of environments where destructive actions should be prohibited. By default, + # the value is ["production"] + + ## + # :singleton-method: pluralize_table_names + # :call-seq: pluralize_table_names + # Indicates whether table names should be the pluralized versions of the corresponding class names. + # If true, the default table name for a Product class will be +products+. If false, it would just be +product+. + # See table_name for the full rules on table/class naming. This is true, by default. + + ## + # :singleton-method: pluralize_table_names= + # :call-seq: pluralize_table_names=(value) + # Set whether table names should be the pluralized versions of the corresponding class names. + # If true, the default table name for a Product class will be +products+. If false, it would just be +product+. + # See table_name for the full rules on table/class naming. This is true, by default. + + ## + # :singleton-method: ignored_columns + # :call-seq: ignored_columns + # Sets list of columns names the model should ignore. Ignored columns won't have attribute + # accessors defined, and won't be referenced in SQL queries. + + ## + # :singleton-method: ignored_columns= + # :call-seq: ignored_columns=(columns) + # Lists the columns names the model should ignore. Ignored columns won't have attribute accessors defined, and + # won't be referenced in SQL queries. + included do - ## - # :singleton-method: - # Accessor for the prefix type that will be prepended to every primary key column name. - # The options are :table_name and :table_name_with_underscore. If the first is specified, - # the Product class will look for "productid" instead of "id" as the primary column. If the - # latter is specified, the Product class will look for "product_id" instead of "id". Remember - # that this is a global setting for all Active Records. + mattr_accessor :primary_key_prefix_type, instance_writer: false - ## - # :singleton-method: - # Accessor for the name of the prefix string to prepend to every table name. So if set - # to "basecamp_", all table names will be named like "basecamp_projects", "basecamp_people", - # etc. This is a convenient way of creating a namespace for tables in a shared database. - # By default, the prefix is the empty string. - # - # If you are organising your models within modules you can add a prefix to the models within - # a namespace by defining a singleton method in the parent module called table_name_prefix which - # returns your chosen prefix. class_attribute :table_name_prefix, instance_writer: false self.table_name_prefix = "" - ## - # :singleton-method: - # Works like +table_name_prefix+, but appends instead of prepends (set to "_basecamp" gives "projects_basecamp", - # "people_basecamp"). By default, the suffix is the empty string. - # - # If you are organising your models within modules, you can add a suffix to the models within - # a namespace by defining a singleton method in the parent module called table_name_suffix which - # returns your chosen suffix. class_attribute :table_name_suffix, instance_writer: false self.table_name_suffix = "" - ## - # :singleton-method: - # Accessor for the name of the schema migrations table. By default, the value is "schema_migrations" class_attribute :schema_migrations_table_name, instance_accessor: false self.schema_migrations_table_name = "schema_migrations" - ## - # :singleton-method: - # Accessor for the name of the internal metadata table. By default, the value is "ar_internal_metadata" class_attribute :internal_metadata_table_name, instance_accessor: false self.internal_metadata_table_name = "ar_internal_metadata" - ## - # :singleton-method: - # Accessor for an array of names of environments where destructive actions should be prohibited. By default, - # the value is ["production"] class_attribute :protected_environments, instance_accessor: false self.protected_environments = ["production"] - ## - # :singleton-method: - # Indicates whether table names should be the pluralized versions of the corresponding class names. - # If true, the default table name for a Product class will be +products+. If false, it would just be +product+. - # See table_name for the full rules on table/class naming. This is true, by default. class_attribute :pluralize_table_names, instance_writer: false self.pluralize_table_names = true - ## - # :singleton-method: - # Accessor for the list of columns names the model should ignore. Ignored columns won't have attribute - # accessors defined, and won't be referenced in SQL queries. class_attribute :ignored_columns, instance_accessor: false self.ignored_columns = [].freeze -- cgit v1.2.3 From d9bd2f5b8b393f7192636229517bf6ba8da80af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Mon, 24 Oct 2016 18:04:54 -0200 Subject: Copy-edits on #26880 * Put a blank line after :call-seq: otherwise it will think the whole test is the call seq. * Improve some text. * Use some rdoc formatting. * Restores the documentation of table_name_prefix. [ci skip] --- activerecord/lib/active_record/model_schema.rb | 84 ++++++++++++++++---------- 1 file changed, 52 insertions(+), 32 deletions(-) diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb index 524aca23c7..525f7444a5 100644 --- a/activerecord/lib/active_record/model_schema.rb +++ b/activerecord/lib/active_record/model_schema.rb @@ -5,22 +5,37 @@ module ActiveRecord ## # :singleton-method: primary_key_prefix_type # :call-seq: primary_key_prefix_type - # Accessor for the name of the prefix string to prepend to every table name. So if set - # to "basecamp_", all table names will be named like "basecamp_projects", "basecamp_people", - # etc. This is a convenient way of creating a namespace for tables in a shared database. - # By default, the prefix is the empty string. # - # If you are organising your models within modules you can add a prefix to the models within - # a namespace by defining a singleton method in the parent module called table_name_prefix which - # returns your chosen prefix. + # The prefix type that will be prepended to every primary key column name. + # The options are +:table_name+ and +:table_name_with_underscore+. If the first is specified, + # the Product class will look for "productid" instead of "id" as the primary column. If the + # latter is specified, the Product class will look for "product_id" instead of "id". Remember + # that this is a global setting for all Active Records. ## # :singleton-method: primary_key_prefix_type= - # :call-seq: primary_key_prefix_type=(prefix) - # Accessor for the name of the prefix string to prepend to every table name. So if set - # to "basecamp_", all table names will be named like "basecamp_projects", "basecamp_people", - # etc. This is a convenient way of creating a namespace for tables in a shared database. - # By default, the prefix is the empty string. + # :call-seq: primary_key_prefix_type=(prefix_type) + # + # Sets the prefix type that will be prepended to every primary key column name. + # The options are +:table_name+ and +:table_name_with_underscore+. If the first is specified, + # the Product class will look for "productid" instead of "id" as the primary column. If the + # latter is specified, the Product class will look for "product_id" instead of "id". Remember + # that this is a global setting for all Active Records. + + ## + # :singleton-method: table_name_prefix + # :call-seq: table_name_prefix + # + # The prefix string to prepend to every table name. + + ## + # :singleton-method: table_name_prefix= + # :call-seq: table_name_prefix=(prefix) + # + # Sets the prefix string to prepend to every table name. So if set to "basecamp_", all table + # names will be named like "basecamp_projects", "basecamp_people", etc. This is a convenient + # way of creating a namespace for tables in a shared database. By default, the prefix is the + # empty string. # # If you are organising your models within modules you can add a prefix to the models within # a namespace by defining a singleton method in the parent module called table_name_prefix which @@ -29,17 +44,14 @@ module ActiveRecord ## # :singleton-method: table_name_suffix # :call-seq: table_name_suffix - # Works like +table_name_prefix+, but appends instead of prepends (set to "_basecamp" gives "projects_basecamp", - # "people_basecamp"). By default, the suffix is the empty string. # - # If you are organising your models within modules, you can add a suffix to the models within - # a namespace by defining a singleton method in the parent module called table_name_suffix which - # returns your chosen suffix. + # The suffix string to append to every table name. ## # :singleton-method: table_name_suffix= # :call-seq: table_name_suffix=(suffix) - # Works like +table_name_prefix+, but appends instead of prepends (set to "_basecamp" gives "projects_basecamp", + # + # Works like +table_name_prefix=+, but appends instead of prepends (set to "_basecamp" gives "projects_basecamp", # "people_basecamp"). By default, the suffix is the empty string. # # If you are organising your models within modules, you can add a suffix to the models within @@ -49,63 +61,71 @@ module ActiveRecord ## # :singleton-method: schema_migrations_table_name # :call-seq: schema_migrations_table_name - # Accessor for the name of the schema migrations table. By default, the value is "schema_migrations" + # + # The name of the schema migrations table. By default, the value is "schema_migrations". ## # :singleton-method: schema_migrations_table_name= # :call-seq: schema_migrations_table_name=(table_name) - # Sets the name of the schema migrations table. By default, the value is "schema_migrations" + # + # Sets the name of the schema migrations table. ## # :singleton-method: internal_metadata_table_name # :call-seq: internal_metadata_table_name - # Accessor for the name of the internal metadata table. By default, the value is "ar_internal_metadata" + # + # The name of the internal metadata table. By default, the value is "ar_internal_metadata". ## # :singleton-method: internal_metadata_table_name= # :call-seq: internal_metadata_table_name=(table_name) - # Sets the name of the internal metadata table. By default, the value is "ar_internal_metadata" + # + # Sets the name of the internal metadata table. ## # :singleton-method: protected_environments # :call-seq: protected_environments - # Accessor for an array of names of environments where destructive actions should be prohibited. By default, - # the value is ["production"] + # + # The array of names of environments where destructive actions should be prohibited. By default, + # the value is ["production"]. ## # :singleton-method: protected_environments= # :call-seq: protected_environments=(environments) - # Sets an array of names of environments where destructive actions should be prohibited. By default, - # the value is ["production"] + # + # Sets an array of names of environments where destructive actions should be prohibited. ## # :singleton-method: pluralize_table_names # :call-seq: pluralize_table_names + # # Indicates whether table names should be the pluralized versions of the corresponding class names. - # If true, the default table name for a Product class will be +products+. If false, it would just be +product+. + # If true, the default table name for a Product class will be "products". If false, it would just be "product". # See table_name for the full rules on table/class naming. This is true, by default. ## # :singleton-method: pluralize_table_names= # :call-seq: pluralize_table_names=(value) + # # Set whether table names should be the pluralized versions of the corresponding class names. - # If true, the default table name for a Product class will be +products+. If false, it would just be +product+. + # If true, the default table name for a Product class will be "products". If false, it would just be "product". # See table_name for the full rules on table/class naming. This is true, by default. ## # :singleton-method: ignored_columns # :call-seq: ignored_columns - # Sets list of columns names the model should ignore. Ignored columns won't have attribute + # + # The list of columns names the model should ignore. Ignored columns won't have attribute # accessors defined, and won't be referenced in SQL queries. ## # :singleton-method: ignored_columns= # :call-seq: ignored_columns=(columns) - # Lists the columns names the model should ignore. Ignored columns won't have attribute accessors defined, and - # won't be referenced in SQL queries. + # + # Sets the columns names the model should ignore. Ignored columns won't have attribute + # accessors defined, and won't be referenced in SQL queries. included do - mattr_accessor :primary_key_prefix_type, instance_writer: false class_attribute :table_name_prefix, instance_writer: false -- cgit v1.2.3 From 5b54a904101c48aac9467df1f060b83c67bee832 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Tue, 25 Oct 2016 07:58:05 +0900 Subject: remove assets config from `new_framework_defaults` if `--skip-sprockets` is true If `sprockets` is not loaded, `Rails.application.config.assets` is not defined. --- .../app/templates/config/initializers/new_framework_defaults.rb.tt | 2 ++ railties/test/generators/app_generator_test.rb | 3 +++ 2 files changed, 5 insertions(+) diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt index 5ad18cc5ad..3ad3eba98a 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt @@ -32,7 +32,9 @@ ActiveSupport.halt_callback_chains_on_return_false = <%= options[:update] ? true # Configure SSL options to enable HSTS with subdomains. Previous versions had false. Rails.application.config.ssl_options = { hsts: { subdomains: true } } <%- end -%> +<%- unless options[:skip_sprockets] -%> # Unknown asset fallback will return the path passed in when the given # asset is not present in the asset pipeline. Rails.application.config.assets.unknown_asset_fallback = <%= options[:update] ? true : false %> +<%- end -%> diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 830e49a1b5..9299b9ebea 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -412,6 +412,9 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_no_match(/config\.assets\.js_compressor = :uglifier/, content) assert_no_match(/config\.assets\.css_compressor = :sass/, content) end + assert_file "config/initializers/new_framework_defaults.rb" do |content| + assert_no_match(/unknown_asset_fallback/, content) + end end def test_generator_if_skip_action_cable_is_given -- cgit v1.2.3 From be623bf55fee51f26d38f96cbba46b95b1933c4c Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Tue, 25 Oct 2016 09:35:21 +0900 Subject: Missing require extract_options --- activemodel/lib/active_model/validations/with.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/activemodel/lib/active_model/validations/with.rb b/activemodel/lib/active_model/validations/with.rb index 6de01b3392..6ae9630d82 100644 --- a/activemodel/lib/active_model/validations/with.rb +++ b/activemodel/lib/active_model/validations/with.rb @@ -1,3 +1,5 @@ +require "active_support/core_ext/array/extract_options" + module ActiveModel module Validations class WithValidator < EachValidator # :nodoc: -- cgit v1.2.3 From d34a2747cb43cc7f23d134e2853879ef4888e372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 25 Oct 2016 00:08:39 -0200 Subject: Fix plain option in the rails_guides generator --- guides/rails_guides/markdown.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/rails_guides/markdown.rb b/guides/rails_guides/markdown.rb index 33563d669c..ea7bf0fec2 100644 --- a/guides/rails_guides/markdown.rb +++ b/guides/rails_guides/markdown.rb @@ -158,7 +158,7 @@ module RailsGuides @view.content_for(:header_section) { @header } @view.content_for(:page_title) { @title } @view.content_for(:index_section) { @index } - @view.render(layout: @layout, text: @body) + @view.render(layout: @layout, plain: @body) end end end -- cgit v1.2.3 From 393f25bdba83f79a352da4c46bb0925caaea524a Mon Sep 17 00:00:00 2001 From: Gabi Stefanini Date: Mon, 24 Oct 2016 22:25:48 -0400 Subject: Uses queue adapter_method instead of ActiveJob::Base.queue_adapter Change ActiveJob::Base.queue_adapter to use queue_adapter method to make test code consistent. --- activejob/test/cases/test_helper_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activejob/test/cases/test_helper_test.rb b/activejob/test/cases/test_helper_test.rb index 253c557cc5..685c93da2d 100644 --- a/activejob/test/cases/test_helper_test.rb +++ b/activejob/test/cases/test_helper_test.rb @@ -250,7 +250,7 @@ class EnqueuedJobsTest < ActiveJob::TestCase HelloJob.perform_later end - assert_equal 2, ActiveJob::Base.queue_adapter.enqueued_jobs.count + assert_equal 2, queue_adapter.enqueued_jobs.count end end @@ -507,7 +507,7 @@ class PerformedJobsTest < ActiveJob::TestCase HelloJob.perform_later end - assert_equal 2, ActiveJob::Base.queue_adapter.performed_jobs.count + assert_equal 2, queue_adapter.performed_jobs.count end end -- cgit v1.2.3 From 1e7f6488f7e4d52c444233ebd95b830b304030b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 25 Oct 2016 03:06:08 -0200 Subject: Generate HTML not plain text --- guides/rails_guides/markdown.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/rails_guides/markdown.rb b/guides/rails_guides/markdown.rb index ea7bf0fec2..f1e61e485d 100644 --- a/guides/rails_guides/markdown.rb +++ b/guides/rails_guides/markdown.rb @@ -158,7 +158,7 @@ module RailsGuides @view.content_for(:header_section) { @header } @view.content_for(:page_title) { @title } @view.content_for(:index_section) { @index } - @view.render(layout: @layout, plain: @body) + @view.render(layout: @layout, html: @body) end end end -- cgit v1.2.3 From 0b4679f192a4892a6eb09bb6103d967408cfdc83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 25 Oct 2016 03:16:51 -0200 Subject: Fix indentation --- guides/rails_guides/markdown/renderer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/rails_guides/markdown/renderer.rb b/guides/rails_guides/markdown/renderer.rb index f8e32fc498..eebd9ac730 100644 --- a/guides/rails_guides/markdown/renderer.rb +++ b/guides/rails_guides/markdown/renderer.rb @@ -52,7 +52,7 @@ HTML "ruby; html-script: true" when "html" "xml" # HTML is understood, but there are .xml rules in the CSS - else + else "plain" end end -- cgit v1.2.3 From 00632d3c5d545a47fd91d45a49603aa8cbd3ed70 Mon Sep 17 00:00:00 2001 From: Erol Fornoles Date: Tue, 25 Oct 2016 18:29:49 +0800 Subject: Fix small typo in ActionView API documentation [ci skip] --- actionview/lib/action_view/helpers/date_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionview/lib/action_view/helpers/date_helper.rb b/actionview/lib/action_view/helpers/date_helper.rb index 04c5fd4218..ea7259a25d 100644 --- a/actionview/lib/action_view/helpers/date_helper.rb +++ b/actionview/lib/action_view/helpers/date_helper.rb @@ -267,7 +267,7 @@ module ActionView # date_select("article", "written_on", default: 3.days.from_now) # # # Generates a date select that when POSTed is stored in the article variable, in the written_on attribute - # # which is set in the form with todays date, regardless of the value in the Active Record object. + # # which is set in the form with today's date, regardless of the value in the Active Record object. # date_select("article", "written_on", selected: Date.today) # # # Generates a date select that when POSTed is stored in the credit_card variable, in the bill_due attribute -- cgit v1.2.3 From 8b3ed2b68ae615523299c5551b4ad6ab8e7f74cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 25 Oct 2016 11:18:34 -0200 Subject: Fix HTML escaping in the guides render :html escapes the argument if not provided as html safe. --- guides/rails_guides/markdown.rb | 2 +- guides/source/layout.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/guides/rails_guides/markdown.rb b/guides/rails_guides/markdown.rb index f1e61e485d..009e5aff99 100644 --- a/guides/rails_guides/markdown.rb +++ b/guides/rails_guides/markdown.rb @@ -158,7 +158,7 @@ module RailsGuides @view.content_for(:header_section) { @header } @view.content_for(:page_title) { @title } @view.content_for(:index_section) { @index } - @view.render(layout: @layout, html: @body) + @view.render(layout: @layout, html: @body.html_safe) end end end diff --git a/guides/source/layout.html.erb b/guides/source/layout.html.erb index 943fd3fd7f..bb50761b30 100644 --- a/guides/source/layout.html.erb +++ b/guides/source/layout.html.erb @@ -88,7 +88,7 @@
- <%= yield.html_safe %> + <%= yield %>

Feedback

-- cgit v1.2.3 From d1700d33a03f385676061feecc9991563b0b6eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 25 Oct 2016 12:31:35 -0200 Subject: Remove mona lisa image from the tests This image has copyright that we are not giving so it is better to use one image that we own the copyright. --- actionpack/test/controller/integration_test.rb | 4 +-- actionpack/test/controller/test_case_test.rb | 32 ++++++++++----------- .../request/multipart_params_parsing_test.rb | 2 +- actionpack/test/fixtures/multipart/mona_lisa.jpg | Bin 159528 -> 0 bytes .../test/fixtures/multipart/ruby_on_rails.jpg | Bin 0 -> 45142 bytes 5 files changed, 19 insertions(+), 19 deletions(-) delete mode 100644 actionpack/test/fixtures/multipart/mona_lisa.jpg create mode 100644 actionpack/test/fixtures/multipart/ruby_on_rails.jpg diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 1f02e0e908..67a42989c2 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -1070,8 +1070,8 @@ class IntegrationFileUploadTest < ActionDispatch::IntegrationTest def test_fixture_file_upload post "/test_file_upload", params: { - file: fixture_file_upload("/mona_lisa.jpg", "image/jpg") + file: fixture_file_upload("/ruby_on_rails.jpg", "image/jpg") } - assert_equal "159528", @response.body + assert_equal "45142", @response.body end end diff --git a/actionpack/test/controller/test_case_test.rb b/actionpack/test/controller/test_case_test.rb index 82f42e306f..33f11e67ef 100644 --- a/actionpack/test/controller/test_case_test.rb +++ b/actionpack/test/controller/test_case_test.rb @@ -781,7 +781,7 @@ XML READ_PLAIN = "r:binary" def test_test_uploaded_file - filename = "mona_lisa.jpg" + filename = "ruby_on_rails.jpg" path = "#{FILES_DIR}/#{filename}" content_type = "image/png" expected = File.read(path) @@ -801,13 +801,13 @@ XML def test_fixture_path_is_accessed_from_self_instead_of_active_support_test_case TestCaseTest.stub :fixture_path, FILES_DIR do - uploaded_file = fixture_file_upload("/mona_lisa.jpg", "image/png") - assert_equal File.open("#{FILES_DIR}/mona_lisa.jpg", READ_PLAIN).read, uploaded_file.read + uploaded_file = fixture_file_upload("/ruby_on_rails.jpg", "image/png") + assert_equal File.open("#{FILES_DIR}/ruby_on_rails.jpg", READ_PLAIN).read, uploaded_file.read end end def test_test_uploaded_file_with_binary - filename = "mona_lisa.jpg" + filename = "ruby_on_rails.jpg" path = "#{FILES_DIR}/#{filename}" content_type = "image/png" @@ -819,7 +819,7 @@ XML end def test_fixture_file_upload_with_binary - filename = "mona_lisa.jpg" + filename = "ruby_on_rails.jpg" path = "#{FILES_DIR}/#{filename}" content_type = "image/jpg" @@ -831,44 +831,44 @@ XML end def test_fixture_file_upload_should_be_able_access_to_tempfile - file = fixture_file_upload(FILES_DIR + "/mona_lisa.jpg", "image/jpg") + file = fixture_file_upload(FILES_DIR + "/ruby_on_rails.jpg", "image/jpg") assert file.respond_to?(:tempfile), "expected tempfile should respond on fixture file object, got nothing" end def test_fixture_file_upload post :test_file_upload, params: { - file: fixture_file_upload(FILES_DIR + "/mona_lisa.jpg", "image/jpg") + file: fixture_file_upload(FILES_DIR + "/ruby_on_rails.jpg", "image/jpg") } - assert_equal "159528", @response.body + assert_equal "45142", @response.body end def test_fixture_file_upload_relative_to_fixture_path TestCaseTest.stub :fixture_path, FILES_DIR do - uploaded_file = fixture_file_upload("mona_lisa.jpg", "image/jpg") - assert_equal File.open("#{FILES_DIR}/mona_lisa.jpg", READ_PLAIN).read, uploaded_file.read + uploaded_file = fixture_file_upload("ruby_on_rails.jpg", "image/jpg") + assert_equal File.open("#{FILES_DIR}/ruby_on_rails.jpg", READ_PLAIN).read, uploaded_file.read end end def test_fixture_file_upload_ignores_fixture_path_given_full_path TestCaseTest.stub :fixture_path, File.dirname(__FILE__) do - uploaded_file = fixture_file_upload("#{FILES_DIR}/mona_lisa.jpg", "image/jpg") - assert_equal File.open("#{FILES_DIR}/mona_lisa.jpg", READ_PLAIN).read, uploaded_file.read + uploaded_file = fixture_file_upload("#{FILES_DIR}/ruby_on_rails.jpg", "image/jpg") + assert_equal File.open("#{FILES_DIR}/ruby_on_rails.jpg", READ_PLAIN).read, uploaded_file.read end end def test_fixture_file_upload_ignores_nil_fixture_path - uploaded_file = fixture_file_upload("#{FILES_DIR}/mona_lisa.jpg", "image/jpg") - assert_equal File.open("#{FILES_DIR}/mona_lisa.jpg", READ_PLAIN).read, uploaded_file.read + uploaded_file = fixture_file_upload("#{FILES_DIR}/ruby_on_rails.jpg", "image/jpg") + assert_equal File.open("#{FILES_DIR}/ruby_on_rails.jpg", READ_PLAIN).read, uploaded_file.read end def test_action_dispatch_uploaded_file_upload - filename = "mona_lisa.jpg" + filename = "ruby_on_rails.jpg" path = "#{FILES_DIR}/#{filename}" post :test_file_upload, params: { file: Rack::Test::UploadedFile.new(path, "image/jpg", true) } - assert_equal "159528", @response.body + assert_equal "45142", @response.body end def test_test_uploaded_file_exception_when_file_doesnt_exist diff --git a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb index e572c722a0..eb4bb14ed1 100644 --- a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb @@ -142,7 +142,7 @@ class MultipartParamsParsingTest < ActionDispatch::IntegrationTest test "uploads and reads binary file" do with_test_routing do - fixture = FIXTURE_PATH + "/mona_lisa.jpg" + fixture = FIXTURE_PATH + "/ruby_on_rails.jpg" params = { uploaded_data: fixture_file_upload(fixture, "image/jpg") } post "/read", params: params end diff --git a/actionpack/test/fixtures/multipart/mona_lisa.jpg b/actionpack/test/fixtures/multipart/mona_lisa.jpg deleted file mode 100644 index 5cf3bef3d0..0000000000 Binary files a/actionpack/test/fixtures/multipart/mona_lisa.jpg and /dev/null differ diff --git a/actionpack/test/fixtures/multipart/ruby_on_rails.jpg b/actionpack/test/fixtures/multipart/ruby_on_rails.jpg new file mode 100644 index 0000000000..ed284ea0ba Binary files /dev/null and b/actionpack/test/fixtures/multipart/ruby_on_rails.jpg differ -- cgit v1.2.3 From c5d46a8a4e11a2e223186e2d04f4d2867df9d927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 25 Oct 2016 14:46:36 -0200 Subject: Whitespace --- activesupport/lib/active_support/cache/strategy/local_cache.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb index ec2e96a106..f41cc23eb0 100644 --- a/activesupport/lib/active_support/cache/strategy/local_cache.rb +++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb @@ -70,6 +70,7 @@ module ActiveSupport def with_local_cache use_temporary_local_cache(LocalStore.new) { yield } end + # Middleware class can be inserted as a Rack handler to be local cache for the # duration of request. def middleware -- cgit v1.2.3 From c51a9b975f152ac6ff64514320fd33ae2c2c442f Mon Sep 17 00:00:00 2001 From: yui-knk Date: Wed, 26 Oct 2016 11:18:10 +0900 Subject: Ensure `#transform_values` of HWIDA to return HWIDA On Ruby 2.4, naitive `Hash#transform_values` is implemented. `Hash#transform_values` uses an instance of Hash (`rb_hash_new`) to collect returned values of a block. For ensuring `#transform_values` of HWIDA to return HWIDA, we should define `#transform_values` on HWIDA. --- activesupport/lib/active_support/hash_with_indifferent_access.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index 7ecc5c19bd..d3bb5496bf 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -273,6 +273,11 @@ module ActiveSupport dup.tap { |hash| hash.reject!(*args, &block) } end + def transform_values(*args, &block) + return to_enum(:transform_values) unless block_given? + dup.tap { |hash| hash.transform_values!(*args, &block) } + end + # Convert to a regular hash with string keys. def to_hash _new_hash = Hash.new -- cgit v1.2.3 From ae83b01b1988d85e2370a53b8c41f5be1a15e946 Mon Sep 17 00:00:00 2001 From: James Doyley Date: Wed, 26 Oct 2016 09:22:23 +0100 Subject: Update HABTM documentation in guides --- guides/source/association_basics.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md index 3837cda553..03d3daecc8 100644 --- a/guides/source/association_basics.md +++ b/guides/source/association_basics.md @@ -1994,11 +1994,9 @@ The `collection.delete` method removes one or more objects from the collection b @part.assemblies.delete(@assembly1) ``` -WARNING: This does not trigger callbacks on the join records. - ##### `collection.destroy(object, ...)` -The `collection.destroy` method removes one or more objects from the collection by running `destroy` on each record in the join table, including running callbacks. This does not destroy the objects. +The `collection.destroy` method removes one or more objects from the collection by deleting records in the join table. This does not destroy the objects. ```ruby @part.assemblies.destroy(@assembly1) -- cgit v1.2.3 From 48cc754a1070cfc4fefdd49475aea3fc9c1a5e2f Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Wed, 26 Oct 2016 19:08:03 +0900 Subject: Use Regexp#match? rather than Regexp#=== Follow up to 99cf7558000090668b137085bfe6bcc06c4571dc. --- .../active_record/connection_adapters/abstract/schema_statements.rb | 2 +- .../lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 4 ++-- activerecord/lib/active_record/connection_adapters/column.rb | 2 +- activerecord/lib/active_record/connection_adapters/mysql/column.rb | 4 ++-- .../lib/active_record/connection_adapters/mysql/schema_dumper.rb | 2 +- .../lib/active_record/connection_adapters/postgresql/oid/bit.rb | 4 ++-- .../lib/active_record/connection_adapters/postgresql/type_metadata.rb | 2 +- activerecord/lib/active_record/tasks/mysql_database_tasks.rb | 2 +- activerecord/lib/active_record/tasks/postgresql_database_tasks.rb | 2 +- activerecord/test/cases/adapters/mysql2/unsigned_type_test.rb | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) 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 1df20a0c56..5d2943e398 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -1116,7 +1116,7 @@ module ActiveRecord end def add_index_options(table_name, column_name, comment: nil, **options) # :nodoc: - if column_name.is_a?(String) && /\W/ === column_name + if column_name.is_a?(String) && /\W/.match?(column_name) column_names = column_name else column_names = Array(column_name) diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index e7bd0e7c12..0e3392b598 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -694,7 +694,7 @@ module ActiveRecord def register_integer_type(mapping, key, options) # :nodoc: mapping.register_type(key) do |sql_type| - if /\bunsigned\z/ === sql_type + if /\bunsigned\z/.match?(sql_type) Type::UnsignedInteger.new(options) else Type::Integer.new(options) @@ -703,7 +703,7 @@ module ActiveRecord end def extract_precision(sql_type) - if /time/ === sql_type + if /time/.match?(sql_type) super || 0 else super diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb index 1808173592..02d546209d 100644 --- a/activerecord/lib/active_record/connection_adapters/column.rb +++ b/activerecord/lib/active_record/connection_adapters/column.rb @@ -29,7 +29,7 @@ module ActiveRecord end def bigint? - /\Abigint\b/ === sql_type + /\Abigint\b/.match?(sql_type) end # Returns the human name of the column name. diff --git a/activerecord/lib/active_record/connection_adapters/mysql/column.rb b/activerecord/lib/active_record/connection_adapters/mysql/column.rb index 296d9a15f8..f82c556a6f 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql/column.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql/column.rb @@ -5,11 +5,11 @@ module ActiveRecord delegate :extra, to: :sql_type_metadata, allow_nil: true def unsigned? - /\bunsigned\z/ === sql_type + /\bunsigned\z/.match?(sql_type) end def case_sensitive? - collation && collation !~ /_ci\z/ + collation && !/_ci\z/.match?(collation) end def auto_increment? diff --git a/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb b/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb index 39221eeb0c..9b02d8a34b 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb @@ -38,7 +38,7 @@ module ActiveRecord end def schema_precision(column) - super unless /time/ === column.sql_type && column.precision == 0 + super unless /time/.match?(column.sql_type) && column.precision == 0 end def schema_collation(column) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/bit.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/bit.rb index 74bff229ea..302d393277 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/bit.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/bit.rb @@ -34,11 +34,11 @@ module ActiveRecord end def binary? - /\A[01]*\Z/ === value + /\A[01]*\Z/.match?(value) end def hex? - /\A[0-9A-F]*\Z/i === value + /\A[0-9A-F]*\Z/i.match?(value) end protected diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/type_metadata.rb b/activerecord/lib/active_record/connection_adapters/postgresql/type_metadata.rb index bcef8ac715..311988625f 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/type_metadata.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/type_metadata.rb @@ -8,7 +8,7 @@ module ActiveRecord @type_metadata = type_metadata @oid = oid @fmod = fmod - @array = /\[\]$/ === type_metadata.sql_type + @array = /\[\]$/.match?(type_metadata.sql_type) end def sql_type diff --git a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb index 3a5e0b8dfe..5cdb3d53f6 100644 --- a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb +++ b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb @@ -14,7 +14,7 @@ module ActiveRecord connection.create_database configuration["database"], creation_options establish_connection configuration rescue ActiveRecord::StatementInvalid => error - if /database exists/ === error.message + if error.message.include?("database exists") raise DatabaseAlreadyExists else raise diff --git a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb index a3a9430c03..03d3049001 100644 --- a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb +++ b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb @@ -17,7 +17,7 @@ module ActiveRecord configuration.merge("encoding" => encoding) establish_connection configuration rescue ActiveRecord::StatementInvalid => error - if /database .* already exists/ === error.message + if /database .* already exists/.match?(error.message) raise DatabaseAlreadyExists else raise diff --git a/activerecord/test/cases/adapters/mysql2/unsigned_type_test.rb b/activerecord/test/cases/adapters/mysql2/unsigned_type_test.rb index 3df11ce11b..452f8d5ae8 100644 --- a/activerecord/test/cases/adapters/mysql2/unsigned_type_test.rb +++ b/activerecord/test/cases/adapters/mysql2/unsigned_type_test.rb @@ -50,7 +50,7 @@ class Mysql2UnsignedTypeTest < ActiveRecord::Mysql2TestCase t.unsigned_decimal :unsigned_decimal_t, precision: 10, scale: 2 end - @connection.columns("unsigned_types").select { |c| /^unsigned_/ === c.name }.each do |column| + @connection.columns("unsigned_types").select { |c| /^unsigned_/.match?(c.name) }.each do |column| assert column.unsigned? end end -- cgit v1.2.3 From 3b50fb6b2f413b4bfe638b3c9839fe7db5077f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 26 Oct 2016 15:25:02 -0200 Subject: Remove all Journey constant from public API There were never public API only there by mistake. [ci skip] --- actionpack/lib/action_dispatch/journey/formatter.rb | 4 +++- actionpack/lib/action_dispatch/journey/parser.rb | 2 ++ actionpack/lib/action_dispatch/journey/parser_extras.rb | 6 ++++-- actionpack/lib/action_dispatch/journey/route.rb | 8 +++++--- actionpack/lib/action_dispatch/journey/visitors.rb | 4 +++- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/actionpack/lib/action_dispatch/journey/formatter.rb b/actionpack/lib/action_dispatch/journey/formatter.rb index dc8b24b089..03f73c7598 100644 --- a/actionpack/lib/action_dispatch/journey/formatter.rb +++ b/actionpack/lib/action_dispatch/journey/formatter.rb @@ -1,10 +1,11 @@ require "action_controller/metal/exceptions" module ActionDispatch + # :stopdoc: module Journey # The Formatter class is used for formatting URLs. For example, parameters # passed to +url_for+ in Rails will eventually call Formatter#generate. - class Formatter # :nodoc: + class Formatter attr_reader :routes def initialize(routes) @@ -178,4 +179,5 @@ module ActionDispatch end end end + # :stopdoc: end diff --git a/actionpack/lib/action_dispatch/journey/parser.rb b/actionpack/lib/action_dispatch/journey/parser.rb index 01ff2109cb..ee91b11b42 100644 --- a/actionpack/lib/action_dispatch/journey/parser.rb +++ b/actionpack/lib/action_dispatch/journey/parser.rb @@ -8,6 +8,7 @@ require "racc/parser.rb" require "action_dispatch/journey/parser_extras" module ActionDispatch + # :stopdoc: module Journey class Parser < Racc::Parser ##### State transition tables begin ### @@ -193,4 +194,5 @@ module ActionDispatch end end # class Parser end # module Journey + # :startdoc: end # module ActionDispatch diff --git a/actionpack/lib/action_dispatch/journey/parser_extras.rb b/actionpack/lib/action_dispatch/journey/parser_extras.rb index ec26e634e8..4c7e82d93c 100644 --- a/actionpack/lib/action_dispatch/journey/parser_extras.rb +++ b/actionpack/lib/action_dispatch/journey/parser_extras.rb @@ -2,8 +2,9 @@ require "action_dispatch/journey/scanner" require "action_dispatch/journey/nodes/node" module ActionDispatch - module Journey # :nodoc: - class Parser < Racc::Parser # :nodoc: + # :stopdoc: + module Journey + class Parser < Racc::Parser include Journey::Nodes def self.parse(string) @@ -24,4 +25,5 @@ module ActionDispatch end end end + # :startdoc: end diff --git a/actionpack/lib/action_dispatch/journey/route.rb b/actionpack/lib/action_dispatch/journey/route.rb index a9713ff292..79cd010d64 100644 --- a/actionpack/lib/action_dispatch/journey/route.rb +++ b/actionpack/lib/action_dispatch/journey/route.rb @@ -1,6 +1,7 @@ module ActionDispatch - module Journey # :nodoc: - class Route # :nodoc: + # :stopdoc: + module Journey + class Route attr_reader :app, :path, :defaults, :name, :precedence attr_reader :constraints, :internal @@ -80,7 +81,7 @@ module ActionDispatch end end - def requirements # :nodoc: + def requirements # needed for rails `rails routes` @defaults.merge(path.requirements).delete_if { |_,v| /.+?/ == v @@ -176,4 +177,5 @@ module ActionDispatch end end end + # :startdoc: end diff --git a/actionpack/lib/action_dispatch/journey/visitors.rb b/actionpack/lib/action_dispatch/journey/visitors.rb index 452dc84cc5..74f3c0617a 100644 --- a/actionpack/lib/action_dispatch/journey/visitors.rb +++ b/actionpack/lib/action_dispatch/journey/visitors.rb @@ -1,5 +1,6 @@ module ActionDispatch - module Journey # :nodoc: + # :stopdoc: + module Journey class Format ESCAPE_PATH = ->(value) { Router::Utils.escape_path(value) } ESCAPE_SEGMENT = ->(value) { Router::Utils.escape_segment(value) } @@ -261,4 +262,5 @@ module ActionDispatch end end end + # :startdoc: end -- cgit v1.2.3 From fa7efca553e325b2aabb087a4eddf4560c356094 Mon Sep 17 00:00:00 2001 From: Samuel Cochran Date: Fri, 30 Sep 2016 15:26:19 +1000 Subject: Clear the correct query cache This executor currently relies on `ActiveRecord::Base.connection` not changing between `prepare` and `complete`. If something else returns the current ActiveRecord connection to the pool early then this `complete` call will fail to clear the correct query cache and restore the original `query_cache_enabled` status. This has for example been happening in Sidekiq: https://github.com/mperham/sidekiq/pull/3166 We can just keep track of the connection as part of the exector state. --- activerecord/lib/active_record/query_cache.rb | 8 ++++---- activerecord/test/cases/query_cache_test.rb | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/query_cache.rb b/activerecord/lib/active_record/query_cache.rb index c45c8c1697..c42c22ab09 100644 --- a/activerecord/lib/active_record/query_cache.rb +++ b/activerecord/lib/active_record/query_cache.rb @@ -28,12 +28,12 @@ module ActiveRecord enabled = connection.query_cache_enabled connection.enable_query_cache! - enabled + [connection, enabled] end - def self.complete(enabled) - ActiveRecord::Base.connection.clear_query_cache - ActiveRecord::Base.connection.disable_query_cache! unless enabled + def self.complete((connection, enabled)) + connection.clear_query_cache + connection.disable_query_cache! unless enabled unless ActiveRecord::Base.connected? && ActiveRecord::Base.connection.transaction_open? ActiveRecord::Base.clear_active_connections! diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb index 4cd258695d..29b2deea26 100644 --- a/activerecord/test/cases/query_cache_test.rb +++ b/activerecord/test/cases/query_cache_test.rb @@ -51,6 +51,29 @@ class QueryCacheTest < ActiveRecord::TestCase assert !ActiveRecord::Base.connection.query_cache_enabled, "cache off" end + def test_exceptional_middleware_cleans_up_correct_cache + connection = ActiveRecord::Base.connection + called = false + + mw = middleware { |env| + Task.find 1 + Task.find 1 + assert_equal 1, connection.query_cache.length + + # Checkin connection early + ActiveRecord::Base.clear_active_connections! + # Make sure ActiveRecord::Base.connection doesn't checkout the same connection + ActiveRecord::Base.connection_pool.remove(connection) + + called = true + } + mw.call({}) + + assert called + assert_equal 0, connection.query_cache.length + assert !connection.query_cache_enabled, "cache off" + end + def test_exceptional_middleware_leaves_enabled_cache_alone ActiveRecord::Base.connection.enable_query_cache! -- cgit v1.2.3 From 5faa9a235c46037a3b8e4f3308fd7ccadaae8039 Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Thu, 27 Oct 2016 00:13:15 +0300 Subject: Add missing `+` around a some literals. Mainly around `nil` [ci skip] --- actionpack/lib/abstract_controller/base.rb | 8 +++---- .../metal/etag_with_template_digest.rb | 2 +- .../action_controller/metal/strong_parameters.rb | 2 +- actionpack/lib/action_dispatch/http/response.rb | 2 +- .../lib/action_dispatch/middleware/cookies.rb | 4 ++-- actionpack/lib/action_dispatch/middleware/flash.rb | 2 +- actionpack/lib/action_dispatch/request/session.rb | 2 +- .../lib/action_view/helpers/asset_url_helper.rb | 4 ++-- .../lib/action_view/helpers/atom_feed_helper.rb | 4 ++-- actionview/lib/action_view/helpers/date_helper.rb | 4 ++-- actionview/lib/action_view/helpers/text_helper.rb | 2 +- actionview/lib/action_view/layouts.rb | 28 +++++++++++----------- .../lib/action_view/renderer/partial_renderer.rb | 2 +- activemodel/lib/active_model/validations.rb | 4 ++-- .../lib/active_model/validations/validates.rb | 2 +- activemodel/lib/active_model/validations/with.rb | 2 +- activerecord/lib/active_record/aggregations.rb | 2 +- activerecord/lib/active_record/associations.rb | 2 +- .../lib/active_record/associations/association.rb | 2 +- .../associations/collection_association.rb | 5 ++-- .../abstract/connection_pool.rb | 12 +++++----- .../abstract/database_limits.rb | 2 +- .../abstract/database_statements.rb | 2 +- .../connection_adapters/postgresql/utils.rb | 2 +- activerecord/lib/active_record/errors.rb | 2 +- activerecord/lib/active_record/integration.rb | 6 ++--- activerecord/lib/active_record/model_schema.rb | 2 +- activerecord/lib/active_record/reflection.rb | 2 +- activerecord/lib/active_record/scoping/named.rb | 2 +- .../lib/active_record/validations/associated.rb | 2 +- .../lib/active_record/validations/presence.rb | 2 +- .../lib/active_support/core_ext/hash/compact.rb | 2 +- .../active_support/core_ext/kernel/reporting.rb | 2 +- .../lib/active_support/core_ext/securerandom.rb | 2 +- .../lib/active_support/core_ext/string/access.rb | 4 ++-- .../active_support/core_ext/string/inflections.rb | 2 +- activesupport/lib/active_support/json/encoding.rb | 3 ++- .../lib/active_support/multibyte/chars.rb | 2 +- activesupport/lib/active_support/number_helper.rb | 4 ++-- activesupport/lib/active_support/rescuable.rb | 4 ++-- guides/source/i18n.md | 2 +- railties/lib/rails.rb | 4 ++-- 42 files changed, 77 insertions(+), 75 deletions(-) diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb index 8e588812f8..603c2e9ea7 100644 --- a/actionpack/lib/abstract_controller/base.rb +++ b/actionpack/lib/abstract_controller/base.rb @@ -215,7 +215,7 @@ module AbstractController # ==== Returns # * string - The name of the method that handles the action # * false - No valid method name could be found. - # Raise AbstractController::ActionNotFound. + # Raise +AbstractController::ActionNotFound+. def _find_action_name(action_name) _valid_action_name?(action_name) && method_for_action(action_name) end @@ -231,11 +231,11 @@ module AbstractController # with a template matching the action name is considered to exist. # # If you override this method to handle additional cases, you may - # also provide a method (like _handle_method_missing) to handle + # also provide a method (like +_handle_method_missing+) to handle # the case. # - # If none of these conditions are true, and method_for_action - # returns nil, an AbstractController::ActionNotFound exception will be raised. + # If none of these conditions are true, and +method_for_action+ + # returns +nil+, an +AbstractController::ActionNotFound+ exception will be raised. # # ==== Parameters # * action_name - An action name to find a method name for diff --git a/actionpack/lib/action_controller/metal/etag_with_template_digest.rb b/actionpack/lib/action_controller/metal/etag_with_template_digest.rb index 6c103bb042..798564db96 100644 --- a/actionpack/lib/action_controller/metal/etag_with_template_digest.rb +++ b/actionpack/lib/action_controller/metal/etag_with_template_digest.rb @@ -40,7 +40,7 @@ module ActionController end # Pick the template digest to include in the ETag. If the +:template+ option - # is present, use the named template. If +:template+ is nil or absent, use + # is present, use the named template. If +:template+ is +nil+ or absent, use # the default controller/action template. If +:template+ is false, omit the # template digest from the ETag. def pick_template_for_etag(options) diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index b64617d084..eb5fc87072 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -539,7 +539,7 @@ module ActionController new_instance_with_inherited_permitted_status(@parameters.select(&block)) end - # Equivalent to Hash#keep_if, but returns nil if no changes were made. + # Equivalent to Hash#keep_if, but returns +nil+ if no changes were made. def select!(&block) @parameters.select!(&block) self diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index e8173e2a99..fa184c3cb6 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -249,7 +249,7 @@ module ActionDispatch # :nodoc: end end - # Sets the HTTP character set. In case of nil parameter + # Sets the HTTP character set. In case of +nil+ parameter # it sets the charset to utf-8. # # response.charset = 'utf-16' # => 'utf-16' diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb index 6f4fab396a..5be5fe255b 100644 --- a/actionpack/lib/action_dispatch/middleware/cookies.rb +++ b/actionpack/lib/action_dispatch/middleware/cookies.rb @@ -179,7 +179,7 @@ module ActionDispatch # Returns a jar that'll automatically generate a signed representation of cookie value and verify it when reading from # the cookie again. This is useful for creating cookies with values that the user is not supposed to change. If a signed - # cookie was tampered with by the user (or a 3rd party), nil will be returned. + # cookie was tampered with by the user (or a 3rd party), +nil+ will be returned. # # If +secrets.secret_key_base+ and +secrets.secret_token+ (deprecated) are both set, # legacy cookies signed with the old key generator will be transparently upgraded. @@ -202,7 +202,7 @@ module ActionDispatch end # Returns a jar that'll automatically encrypt cookie values before sending them to the client and will decrypt them for read. - # If the cookie was tampered with by the user (or a 3rd party), nil will be returned. + # If the cookie was tampered with by the user (or a 3rd party), +nil+ will be returned. # # If +secrets.secret_key_base+ and +secrets.secret_token+ (deprecated) are both set, # legacy cookies signed with the old key generator will be transparently upgraded. diff --git a/actionpack/lib/action_dispatch/middleware/flash.rb b/actionpack/lib/action_dispatch/middleware/flash.rb index 6900934712..6dddcc6ee1 100644 --- a/actionpack/lib/action_dispatch/middleware/flash.rb +++ b/actionpack/lib/action_dispatch/middleware/flash.rb @@ -129,7 +129,7 @@ module ActionDispatch end # Builds a hash containing the flashes to keep for the next request. - # If there are none to keep, returns nil. + # If there are none to keep, returns +nil+. def to_session_value #:nodoc: flashes_to_keep = @flashes.except(*@discard) return nil if flashes_to_keep.empty? diff --git a/actionpack/lib/action_dispatch/request/session.rb b/actionpack/lib/action_dispatch/request/session.rb index b883ca0f61..9b1ccdab86 100644 --- a/actionpack/lib/action_dispatch/request/session.rb +++ b/actionpack/lib/action_dispatch/request/session.rb @@ -85,7 +85,7 @@ module ActionDispatch end # Returns value of the key stored in the session or - # nil if the given key is not found in the session. + # +nil+ if the given key is not found in the session. def [](key) load_for_read! @delegate[key.to_s] diff --git a/actionview/lib/action_view/helpers/asset_url_helper.rb b/actionview/lib/action_view/helpers/asset_url_helper.rb index e0de2ff4d6..79305d4880 100644 --- a/actionview/lib/action_view/helpers/asset_url_helper.rb +++ b/actionview/lib/action_view/helpers/asset_url_helper.rb @@ -98,7 +98,7 @@ module ActionView # to avoid warnings in the client about mixed media. # Note that the request parameter might not be supplied, e.g. when the assets # are precompiled via a Rake task. Make sure to use a Proc instead of a lambda, - # since a Proc allows missing parameters and sets them to nil. + # since a +Proc+ allows missing parameters and sets them to +nil+. # # config.action_controller.asset_host = Proc.new { |source, request| # if request && request.ssl? @@ -233,7 +233,7 @@ module ActionView stylesheet: ".css" } - # Compute extname to append to asset path. Returns nil if + # Compute extname to append to asset path. Returns +nil+ if # nothing should be added. def compute_asset_extname(source, options = {}) return if options[:extname] == false diff --git a/actionview/lib/action_view/helpers/atom_feed_helper.rb b/actionview/lib/action_view/helpers/atom_feed_helper.rb index 09d243c46d..293662838f 100644 --- a/actionview/lib/action_view/helpers/atom_feed_helper.rb +++ b/actionview/lib/action_view/helpers/atom_feed_helper.rb @@ -163,7 +163,7 @@ module ActionView @xml, @view, @feed_options = xml, view, feed_options end - # Accepts a Date or Time object and inserts it in the proper format. If nil is passed, current time in UTC is used. + # Accepts a Date or Time object and inserts it in the proper format. If +nil+ is passed, current time in UTC is used. def updated(date_or_time = nil) @xml.updated((date_or_time || Time.now.utc).xmlschema) end @@ -174,7 +174,7 @@ module ActionView # # * :published: Time first published. Defaults to the created_at attribute on the record if one such exists. # * :updated: Time of update. Defaults to the updated_at attribute on the record if one such exists. - # * :url: The URL for this entry or false or nil for not having a link tag. Defaults to the polymorphic_url for the record. + # * :url: The URL for this entry or +false+ or +nil+ for not having a link tag. Defaults to the +polymorphic_url+ for the record. # * :id: The ID for this entry. Defaults to "tag:#{@view.request.host},#{@feed_options[:schema_date]}:#{record.class}/#{record.id}" # * :type: The TYPE for this entry. Defaults to "text/html". def entry(record, options = {}) diff --git a/actionview/lib/action_view/helpers/date_helper.rb b/actionview/lib/action_view/helpers/date_helper.rb index 04c5fd4218..206c63b295 100644 --- a/actionview/lib/action_view/helpers/date_helper.rb +++ b/actionview/lib/action_view/helpers/date_helper.rb @@ -220,7 +220,7 @@ module ActionView # the respective locale (e.g. [:year, :month, :day] in the en locale that ships with Rails). # * :include_blank - Include a blank option in every select field so it's possible to set empty # dates. - # * :default - Set a default date if the affected date isn't set or is nil. + # * :default - Set a default date if the affected date isn't set or is +nil+. # * :selected - Set a date that overrides the actual value. # * :disabled - Set to true if you want show the select fields as disabled. # * :prompt - Set to true (for a generic prompt), a prompt string or a hash of prompt strings @@ -866,7 +866,7 @@ module ActionView end # Returns translated month names, but also ensures that a custom month - # name array has a leading nil element. + # name array has a leading +nil+ element. def month_names @month_names ||= begin month_names = @options[:use_month_names] || translated_month_names diff --git a/actionview/lib/action_view/helpers/text_helper.rb b/actionview/lib/action_view/helpers/text_helper.rb index bd3371ccc8..07dccf5b41 100644 --- a/actionview/lib/action_view/helpers/text_helper.rb +++ b/actionview/lib/action_view/helpers/text_helper.rb @@ -151,7 +151,7 @@ module ActionView # defined in :radius (which defaults to 100). If the excerpt radius overflows the beginning or end of the +text+, # then the :omission option (which defaults to "...") will be prepended/appended accordingly. Use the # :separator option to choose the delimitation. The resulting string will be stripped in any case. If the +phrase+ - # isn't found, nil is returned. + # isn't found, +nil+ is returned. # # excerpt('This is an example', 'an', radius: 5) # # => ...s is an exam... diff --git a/actionview/lib/action_view/layouts.rb b/actionview/lib/action_view/layouts.rb index b083de1396..049d28f261 100644 --- a/actionview/lib/action_view/layouts.rb +++ b/actionview/lib/action_view/layouts.rb @@ -92,16 +92,16 @@ module ActionView # layout false # # In these examples, we have three implicit lookup scenarios: - # * The BankController uses the "bank" layout. - # * The ExchangeController uses the "exchange" layout. - # * The CurrencyController inherits the layout from BankController. + # * The +BankController+ uses the "bank" layout. + # * The +ExchangeController+ uses the "exchange" layout. + # * The +CurrencyController+ inherits the layout from BankController. # # However, when a layout is explicitly set, the explicitly set layout wins: - # * The InformationController uses the "information" layout, explicitly set. - # * The TellerController also uses the "information" layout, because the parent explicitly set it. - # * The EmployeeController uses the "employee" layout, because it set the layout to nil, resetting the parent configuration. - # * The VaultController chooses a layout dynamically by calling the access_level_layout method. - # * The TillController does not use a layout at all. + # * The +InformationController+ uses the "information" layout, explicitly set. + # * The +TellerController+ also uses the "information" layout, because the parent explicitly set it. + # * The +EmployeeController+ uses the "employee" layout, because it set the layout to +nil+, resetting the parent configuration. + # * The +VaultController+ chooses a layout dynamically by calling the access_level_layout method. + # * The +TillController+ does not use a layout at all. # # == Types of layouts # @@ -149,8 +149,8 @@ module ActionView # The template will be looked always in app/views/layouts/ folder. But you can point # layouts folder direct also. layout "layouts/demo" is the same as layout "demo". # - # Setting the layout to nil forces it to be looked up in the filesystem and fallbacks to the parent behavior if none exists. - # Setting it to nil is useful to re-enable template lookup overriding a previous configuration set in the parent: + # Setting the layout to +nil+ forces it to be looked up in the filesystem and fallbacks to the parent behavior if none exists. + # Setting it to +nil+ is useful to re-enable template lookup overriding a previous configuration set in the parent: # # class ApplicationController < ActionController::Base # layout "application" @@ -255,7 +255,7 @@ module ActionView # true:: raise an ArgumentError # nil:: Force default layout behavior with inheritance # - # Return value of Proc & Symbol arguments should be String, false, true or nil + # Return value of +Proc & Symbol+ arguments should be +String+, +false+, +true+ or +nil+ # with the same meaning as described above. # ==== Parameters # * layout - The layout to use. @@ -405,11 +405,11 @@ module ActionView # # ==== Parameters # * formats - The formats accepted to this layout - # * require_layout - If set to true and layout is not found, - # an +ArgumentError+ exception is raised (defaults to false) + # * require_layout - If set to +true+ and layout is not found, + # an +ArgumentError+ exception is raised (defaults to +false+) # # ==== Returns - # * template - The template object for the default layout (or nil) + # * template - The template object for the default layout (or +nil+) def _default_layout(formats, require_layout = false) begin value = _layout(formats) if action_has_layout? diff --git a/actionview/lib/action_view/renderer/partial_renderer.rb b/actionview/lib/action_view/renderer/partial_renderer.rb index dfe38c488f..dfa6a629b4 100644 --- a/actionview/lib/action_view/renderer/partial_renderer.rb +++ b/actionview/lib/action_view/renderer/partial_renderer.rb @@ -99,7 +99,7 @@ module ActionView # # <%= render partial: "ad", collection: @advertisements, spacer_template: "ad_divider" %> # - # If the given :collection is nil or empty, render will return nil. This will allow you + # If the given :collection is +nil+ or empty, render will return nil. This will allow you # to specify a text which will displayed instead by using this form: # # <%= render(partial: "ad", collection: @advertisements) || "There's no ad to be displayed" %> diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index df6d3f2bcb..b426590421 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -68,7 +68,7 @@ module ActiveModel # # Options: # * :on - Specifies the contexts where this validation is active. - # Runs in all validation contexts by default (nil). You can pass a symbol + # Runs in all validation contexts by default +nil+. You can pass a symbol # or an array of symbols. (e.g. on: :create or # on: :custom_validation_context or # on: [:create, :custom_validation_context]) @@ -134,7 +134,7 @@ module ActiveModel # # Options: # * :on - Specifies the contexts where this validation is active. - # Runs in all validation contexts by default (nil). You can pass a symbol + # Runs in all validation contexts by default +nil+. You can pass a symbol # or an array of symbols. (e.g. on: :create or # on: :custom_validation_context or # on: [:create, :custom_validation_context]) diff --git a/activemodel/lib/active_model/validations/validates.rb b/activemodel/lib/active_model/validations/validates.rb index c3cbb6e291..f95f44de61 100644 --- a/activemodel/lib/active_model/validations/validates.rb +++ b/activemodel/lib/active_model/validations/validates.rb @@ -72,7 +72,7 @@ module ActiveModel # There is also a list of options that could be used along with validators: # # * :on - Specifies the contexts where this validation is active. - # Runs in all validation contexts by default (nil). You can pass a symbol + # Runs in all validation contexts by default +nil+. You can pass a symbol # or an array of symbols. (e.g. on: :create or # on: :custom_validation_context or # on: [:create, :custom_validation_context]) diff --git a/activemodel/lib/active_model/validations/with.rb b/activemodel/lib/active_model/validations/with.rb index 6ae9630d82..e3f7a9bcb2 100644 --- a/activemodel/lib/active_model/validations/with.rb +++ b/activemodel/lib/active_model/validations/with.rb @@ -45,7 +45,7 @@ module ActiveModel # # Configuration options: # * :on - Specifies the contexts where this validation is active. - # Runs in all validation contexts by default (nil). You can pass a symbol + # Runs in all validation contexts by default +nil+. You can pass a symbol # or an array of symbols. (e.g. on: :create or # on: :custom_validation_context or # on: [:create, :custom_validation_context]) diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb index 5ca8fe576e..08dfc3a64f 100644 --- a/activerecord/lib/active_record/aggregations.rb +++ b/activerecord/lib/active_record/aggregations.rb @@ -206,7 +206,7 @@ module ActiveRecord # or a Proc that is called when a new value is assigned to the value object. The converter is # passed the single value that is used in the assignment and is only called if the new value is # not an instance of :class_name. If :allow_nil is set to true, the converter - # can return nil to skip the assignment. + # can return +nil+ to skip the assignment. # # Option examples: # composed_of :temperature, mapping: %w(reading celsius) diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index b5f1f1980a..3c94c4bd7f 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -264,7 +264,7 @@ module ActiveRecord super end - # Returns the specified association instance if it exists, nil otherwise. + # Returns the specified association instance if it exists, +nil+ otherwise. def association_instance_get(name) @association_cache[name] end diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index f506614591..ada59313a8 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -254,7 +254,7 @@ module ActiveRecord # so that when stale_state is different from the value stored on the last find_target, # the target is stale. # - # This is only relevant to certain associations, which is why it returns nil by default. + # This is only relevant to certain associations, which is why it returns +nil+ by default. def stale_state end diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 278c95e27b..fa4d98f816 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -435,8 +435,9 @@ module ActiveRecord records.each { |record| callback(:after_remove, record) } end - # Delete the given records from the association, using one of the methods :destroy, - # :delete_all or :nullify (or nil, in which case a default is used). + # Delete the given records from the association, + # using one of the methods +:destroy+, +:delete_all+ + # or +:nullify+ (or +nil+, in which case a default is used). def delete_records(records, method) raise NotImplementedError end diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index 2d62fd8d50..fa2f685e43 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -69,7 +69,7 @@ module ActiveRecord # threads, which can occur if a programmer forgets to close a # connection at the end of a thread or a thread dies unexpectedly. # Regardless of this setting, the Reaper will be invoked before every - # blocking wait. (Default nil, which means don't schedule the Reaper). + # blocking wait. (Default +nil+, which means don't schedule the Reaper). # #-- # Synchronization policy: @@ -116,7 +116,7 @@ module ActiveRecord end end - # If +element+ is in the queue, remove and return it, or nil. + # If +element+ is in the queue, remove and return it, or +nil+. def delete(element) synchronize do @queue.delete(element) @@ -135,7 +135,7 @@ module ActiveRecord # If +timeout+ is not given, remove and return the head the # queue if the number of available elements is strictly # greater than the number of threads currently waiting (that - # is, don't jump ahead in line). Otherwise, return nil. + # is, don't jump ahead in line). Otherwise, return +nil+. # # If +timeout+ is given, block if there is no element # available, waiting up to +timeout+ seconds for an element to @@ -171,14 +171,14 @@ module ActiveRecord @queue.size > @num_waiting end - # Removes and returns the head of the queue if possible, or nil. + # Removes and returns the head of the queue if possible, or +nil+. def remove @queue.shift end # Remove and return the head the queue if the number of # available elements is strictly greater than the number of - # threads currently waiting. Otherwise, return nil. + # threads currently waiting. Otherwise, return +nil+. def no_wait_poll remove if can_remove_no_wait? end @@ -282,7 +282,7 @@ module ActiveRecord end # Every +frequency+ seconds, the reaper will call +reap+ on +pool+. - # A reaper instantiated with a nil frequency will never reap the + # A reaper instantiated with a +nil+ frequency will never reap the # connection pool. # # Configure the frequency by setting "reaping_frequency" in your diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_limits.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_limits.rb index 95c72f1e20..407e019326 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_limits.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_limits.rb @@ -46,7 +46,7 @@ module ActiveRecord end # Returns the maximum number of elements in an IN (x,y,z) clause. - # nil means no limit. + # +nil+ means no limit. def in_clause_length nil end diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb index aa2dfdd573..faccd1d641 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -115,7 +115,7 @@ module ActiveRecord # Executes an INSERT query and returns the new record's ID # - # +id_value+ will be returned unless the value is nil, in + # +id_value+ will be returned unless the value is +nil+, in # which case the database will attempt to calculate the last inserted # id and return that value. # diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/utils.rb b/activerecord/lib/active_record/connection_adapters/postgresql/utils.rb index 9a0b80d7d3..1412928ca5 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/utils.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/utils.rb @@ -53,7 +53,7 @@ module ActiveRecord # Returns an instance of ActiveRecord::ConnectionAdapters::PostgreSQL::Name # extracted from +string+. - # +schema+ is nil if not specified in +string+. + # +schema+ is +nil+ if not specified in +string+. # +schema+ and +identifier+ exclude surrounding quotes (regardless of whether provided in +string+) # +string+ supports the range of schema/table references understood by PostgreSQL, for example: # diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb index 8fbe43e3ec..6464d40c94 100644 --- a/activerecord/lib/active_record/errors.rb +++ b/activerecord/lib/active_record/errors.rb @@ -43,7 +43,7 @@ module ActiveRecord # Raised when connection to the database could not been established (for example when # {ActiveRecord::Base.connection=}[rdoc-ref:ConnectionHandling#connection] - # is given a nil object). + # is given a +nil+ object). class ConnectionNotEstablished < ActiveRecordError end diff --git a/activerecord/lib/active_record/integration.rb b/activerecord/lib/active_record/integration.rb index 3c54c6048d..8e71b60b29 100644 --- a/activerecord/lib/active_record/integration.rb +++ b/activerecord/lib/active_record/integration.rb @@ -15,9 +15,9 @@ module ActiveRecord self.cache_timestamp_format = :usec end - # Returns a String, which Action Pack uses for constructing a URL to this - # object. The default implementation returns this record's id as a String, - # or nil if this record's unsaved. + # Returns a +String+, which Action Pack uses for constructing a URL to this + # object. The default implementation returns this record's id as a +String+, + # or +nil+ if this record's unsaved. # # For example, suppose that you have a User model, and that you have a # resources :users route. Normally, +user_path+ will diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb index 525f7444a5..2a28c6bf6d 100644 --- a/activerecord/lib/active_record/model_schema.rb +++ b/activerecord/lib/active_record/model_schema.rb @@ -292,7 +292,7 @@ module ActiveRecord end # Sets the name of the sequence to use when generating ids to the given - # value, or (if the value is nil or false) to the value returned by the + # value, or (if the value is +nil+ or +false+) to the value returned by the # given block. This is required for Oracle and is useful for any # database which relies on sequences for primary key generation. # diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 57020e00c9..19ee7c9834 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -541,7 +541,7 @@ module ActiveRecord # Attempts to find the inverse association name automatically. # If it cannot find a suitable inverse association name, it returns - # nil. + # +nil+. def inverse_name options.fetch(:inverse_of) do if @automatic_inverse_of == false diff --git a/activerecord/lib/active_record/scoping/named.rb b/activerecord/lib/active_record/scoping/named.rb index 094c0e9c6f..6af84c1266 100644 --- a/activerecord/lib/active_record/scoping/named.rb +++ b/activerecord/lib/active_record/scoping/named.rb @@ -42,7 +42,7 @@ module ActiveRecord # Adds a class method for retrieving and querying objects. # The method is intended to return an ActiveRecord::Relation # object, which is composable with other scopes. - # If it returns nil or false, an + # If it returns +nil+ or +false+, an # {all}[rdoc-ref:Scoping::Named::ClassMethods#all] scope is returned instead. # # A \scope represents a narrowing of a database query, such as diff --git a/activerecord/lib/active_record/validations/associated.rb b/activerecord/lib/active_record/validations/associated.rb index b14db85167..c695965d7b 100644 --- a/activerecord/lib/active_record/validations/associated.rb +++ b/activerecord/lib/active_record/validations/associated.rb @@ -37,7 +37,7 @@ module ActiveRecord # # * :message - A custom error message (default is: "is invalid"). # * :on - Specifies the contexts where this validation is active. - # Runs in all validation contexts by default (nil). You can pass a symbol + # Runs in all validation contexts by default +nil+. You can pass a symbol # or an array of symbols. (e.g. on: :create or # on: :custom_validation_context or # on: [:create, :custom_validation_context]) diff --git a/activerecord/lib/active_record/validations/presence.rb b/activerecord/lib/active_record/validations/presence.rb index ad82ea66c4..ca5eda2f84 100644 --- a/activerecord/lib/active_record/validations/presence.rb +++ b/activerecord/lib/active_record/validations/presence.rb @@ -44,7 +44,7 @@ module ActiveRecord # Configuration options: # * :message - A custom error message (default is: "can't be blank"). # * :on - Specifies the contexts where this validation is active. - # Runs in all validation contexts by default (nil). You can pass a symbol + # Runs in all validation contexts by default +nil+. You can pass a symbol # or an array of symbols. (e.g. on: :create or # on: :custom_validation_context or # on: [:create, :custom_validation_context]) diff --git a/activesupport/lib/active_support/core_ext/hash/compact.rb b/activesupport/lib/active_support/core_ext/hash/compact.rb index 5cae495bda..e357284be0 100644 --- a/activesupport/lib/active_support/core_ext/hash/compact.rb +++ b/activesupport/lib/active_support/core_ext/hash/compact.rb @@ -14,7 +14,7 @@ class Hash unless Hash.instance_methods(false).include?(:compact!) # Replaces current hash with non +nil+ values. - # Returns nil if no changes were made, otherwise returns the hash. + # Returns +nil+ if no changes were made, otherwise returns the hash. # # hash = { a: true, b: false, c: nil } # hash.compact! # => { a: true, b: false } diff --git a/activesupport/lib/active_support/core_ext/kernel/reporting.rb b/activesupport/lib/active_support/core_ext/kernel/reporting.rb index d0197af95f..c02618d5f3 100644 --- a/activesupport/lib/active_support/core_ext/kernel/reporting.rb +++ b/activesupport/lib/active_support/core_ext/kernel/reporting.rb @@ -1,7 +1,7 @@ module Kernel module_function - # Sets $VERBOSE to nil for the duration of the block and back to its original + # Sets $VERBOSE to +nil+ for the duration of the block and back to its original # value afterwards. # # silence_warnings do diff --git a/activesupport/lib/active_support/core_ext/securerandom.rb b/activesupport/lib/active_support/core_ext/securerandom.rb index 92392d1a92..82841aa11a 100644 --- a/activesupport/lib/active_support/core_ext/securerandom.rb +++ b/activesupport/lib/active_support/core_ext/securerandom.rb @@ -6,7 +6,7 @@ module SecureRandom # # The argument _n_ specifies the length, of the random string to be generated. # - # If _n_ is not specified or is nil, 16 is assumed. It may be larger in the future. + # If _n_ is not specified or is +nil+, 16 is assumed. It may be larger in the future. # # The result may contain alphanumeric characters except 0, O, I and l # diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb index caa48e34c5..6133826f37 100644 --- a/activesupport/lib/active_support/core_ext/string/access.rb +++ b/activesupport/lib/active_support/core_ext/string/access.rb @@ -3,7 +3,7 @@ class String # 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 + # 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. # @@ -17,7 +17,7 @@ class String # # 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. + # the string. In both cases, +nil+ is returned if there is no match. # # str = "hello" # str.at(/lo/) # => "lo" diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb index 7e12700c8c..765c0919bb 100644 --- a/activesupport/lib/active_support/core_ext/string/inflections.rb +++ b/activesupport/lib/active_support/core_ext/string/inflections.rb @@ -67,7 +67,7 @@ class String end # +safe_constantize+ tries to find a declared constant with the name specified - # in the string. It returns nil when the name is not in CamelCase + # in the string. It returns +nil+ when the name is not in CamelCase # or is not initialized. See ActiveSupport::Inflector.safe_constantize # # 'Module'.safe_constantize # => Module diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index cee731417f..8ff3551edc 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -68,7 +68,8 @@ module ActiveSupport :ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, :EscapedString # Convert an object into a "JSON-ready" representation composed of - # primitives like Hash, Array, String, Numeric, and true/false/nil. + # primitives like Hash, Array, String, Numeric, + # and +true+/+false+/+nil+. # Recursively calls #as_json to the object to recursively build a # fully JSON-ready object. # diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb index 938e4ebb72..262f25b874 100644 --- a/activesupport/lib/active_support/multibyte/chars.rb +++ b/activesupport/lib/active_support/multibyte/chars.rb @@ -87,7 +87,7 @@ module ActiveSupport #:nodoc: end # Works like String#slice!, but returns an instance of - # Chars, or nil if the string was not modified. The string will not be + # Chars, or +nil+ if the string was not modified. The string will not be # modified if the range given is out of bounds # # string = 'Welcome' diff --git a/activesupport/lib/active_support/number_helper.rb b/activesupport/lib/active_support/number_helper.rb index 7a49bbb960..6000ea44be 100644 --- a/activesupport/lib/active_support/number_helper.rb +++ b/activesupport/lib/active_support/number_helper.rb @@ -109,7 +109,7 @@ module ActiveSupport # * :locale - Sets the locale to be used for formatting # (defaults to current locale). # * :precision - Sets the precision of the number - # (defaults to 3). Keeps the number's precision if nil. + # (defaults to 3). Keeps the number's precision if +nil+. # * :significant - If +true+, precision will be the number # of significant_digits. If +false+, the number of fractional # digits (defaults to +false+). @@ -183,7 +183,7 @@ module ActiveSupport # * :locale - Sets the locale to be used for formatting # (defaults to current locale). # * :precision - Sets the precision of the number - # (defaults to 3). Keeps the number's precision if nil. + # (defaults to 3). Keeps the number's precision if +nil+. # * :significant - If +true+, precision will be the number # of significant_digits. If +false+, the number of fractional # digits (defaults to +false+). diff --git a/activesupport/lib/active_support/rescuable.rb b/activesupport/lib/active_support/rescuable.rb index dc3f27a16d..135690cc42 100644 --- a/activesupport/lib/active_support/rescuable.rb +++ b/activesupport/lib/active_support/rescuable.rb @@ -74,7 +74,7 @@ module ActiveSupport # # If no handler matches the exception, check for a handler matching the # (optional) exception.cause. If no handler matches the exception or its - # cause, this returns nil so you can deal with unhandled exceptions. + # cause, this returns +nil+, so you can deal with unhandled exceptions. # Be sure to re-raise unhandled exceptions if this is what you expect. # # begin @@ -83,7 +83,7 @@ module ActiveSupport # rescue_with_handler(exception) || raise # end # - # Returns the exception if it was handled and nil if it was not. + # Returns the exception if it was handled and +nil+ if it was not. def rescue_with_handler(exception, object: self) if handler = handler_for_rescue(exception, object: object) handler.call exception diff --git a/guides/source/i18n.md b/guides/source/i18n.md index 887774961a..fd54bca4ff 100644 --- a/guides/source/i18n.md +++ b/guides/source/i18n.md @@ -166,7 +166,7 @@ def set_locale I18n.locale = extract_locale_from_tld || I18n.default_locale end -# Get locale from top-level domain or return nil if such locale is not available +# Get locale from top-level domain or return +nil+ if such locale is not available # You have to put something like: # 127.0.0.1 application.com # 127.0.0.1 application.it diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index 5d862e3fec..ee48043a50 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -53,7 +53,7 @@ module Rails end # Returns a Pathname object of the current Rails project, - # otherwise it returns nil if there is no project: + # otherwise it returns +nil+ if there is no project: # # Rails.root # # => # @@ -100,7 +100,7 @@ module Rails end # Returns a Pathname object of the public folder of the current - # Rails project, otherwise it returns nil if there is no project: + # Rails project, otherwise it returns +nil+ if there is no project: # # Rails.public_path # # => # -- cgit v1.2.3 From 3db6ca9d0447bbd50ffaaf11d462c982b2a1d871 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Thu, 27 Oct 2016 08:04:02 +0900 Subject: fix initializer name [ci skip] This changed in c046660 --- guides/source/configuring.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 79ded19c27..18416a60ff 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -1181,7 +1181,7 @@ Below is a comprehensive list of all the initializers found in Rails in the orde * `finisher_hook`: Provides a hook for after the initialization of process of the application is complete, as well as running all the `config.after_initialize` blocks for the application, railties and engines. -* `set_routes_reloader`: Configures Action Dispatch to reload the routes file using `ActionDispatch::Callbacks.to_prepare`. +* `set_routes_reloader_hook`: Configures Action Dispatch to reload the routes file using `ActionDispatch::Callbacks.to_prepare`. * `disable_dependency_loading`: Disables the automatic dependency loading if the `config.eager_load` is set to `true`. -- cgit v1.2.3 From 51f1d5a960e250905252b8646ff9563436309b86 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Thu, 27 Oct 2016 08:28:14 +0900 Subject: remove unused `RedirectBackError` class Follow up to 333bfd896e87862cece95deb1ef88132d5f54ba8 --- actionpack/lib/action_controller/metal/redirecting.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/actionpack/lib/action_controller/metal/redirecting.rb b/actionpack/lib/action_controller/metal/redirecting.rb index 2b060e3698..30798c1d99 100644 --- a/actionpack/lib/action_controller/metal/redirecting.rb +++ b/actionpack/lib/action_controller/metal/redirecting.rb @@ -1,12 +1,4 @@ module ActionController - class RedirectBackError < AbstractController::Error #:nodoc: - DEFAULT_MESSAGE = 'No HTTP_REFERER was set in the request to this action, so redirect_to :back could not be called successfully. If this is a test, make sure to specify request.env["HTTP_REFERER"].' - - def initialize(message = nil) - super(message || DEFAULT_MESSAGE) - end - end - module Redirecting extend ActiveSupport::Concern -- cgit v1.2.3 From 09b6cc28bf2bd7c37289d5e9a3e04a04a1ec0db3 Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Mon, 24 Oct 2016 13:53:00 -0500 Subject: Clear query cache during checkin, instead of an execution callback It doesn't make sense for the query cache to persist while a connection moves through the pool and is assigned to a new thread. [Samuel Cochran & Matthew Draper] --- .../connection_adapters/abstract/query_cache.rb | 2 + .../connection_adapters/abstract_adapter.rb | 6 +- activerecord/lib/active_record/query_cache.rb | 11 +-- activerecord/test/cases/query_cache_test.rb | 96 +++++++++++++++------- 4 files changed, 75 insertions(+), 40 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb index 2f8a89e88e..3eac1b66ae 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb @@ -4,6 +4,7 @@ module ActiveRecord class << self def included(base) #:nodoc: dirties_query_cache base, :insert, :update, :delete, :rollback_to_savepoint, :rollback_db_transaction + base.set_callback :checkin, :after, :disable_query_cache! end def dirties_query_cache(base, *method_names) @@ -41,6 +42,7 @@ module ActiveRecord def disable_query_cache! @query_cache_enabled = false + clear_query_cache end # Disable the query cache within the block. diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 0c7197a002..2296df4481 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -62,17 +62,17 @@ module ActiveRecord # notably, the instance methods provided by SchemaStatements are very useful. class AbstractAdapter ADAPTER_NAME = "Abstract".freeze + include ActiveSupport::Callbacks + define_callbacks :checkout, :checkin + include Quoting, DatabaseStatements, SchemaStatements include DatabaseLimits include QueryCache - include ActiveSupport::Callbacks include ColumnDumper include Savepoints SIMPLE_INT = /\A\d+\z/ - define_callbacks :checkout, :checkin - attr_accessor :visitor, :pool attr_reader :schema_cache, :owner, :logger alias :in_use? :owner diff --git a/activerecord/lib/active_record/query_cache.rb b/activerecord/lib/active_record/query_cache.rb index c42c22ab09..23dae825c2 100644 --- a/activerecord/lib/active_record/query_cache.rb +++ b/activerecord/lib/active_record/query_cache.rb @@ -24,17 +24,10 @@ module ActiveRecord end def self.run - connection = ActiveRecord::Base.connection - enabled = connection.query_cache_enabled - connection.enable_query_cache! - - [connection, enabled] + ActiveRecord::Base.connection.enable_query_cache! end - def self.complete((connection, enabled)) - connection.clear_query_cache - connection.disable_query_cache! unless enabled - + def self.complete(_) unless ActiveRecord::Base.connected? && ActiveRecord::Base.connection.transaction_open? ActiveRecord::Base.clear_active_connections! end diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb index 29b2deea26..5b0477aabe 100644 --- a/activerecord/test/cases/query_cache_test.rb +++ b/activerecord/test/cases/query_cache_test.rb @@ -37,7 +37,7 @@ class QueryCacheTest < ActiveRecord::TestCase end def test_exceptional_middleware_clears_and_disables_cache_on_error - assert !ActiveRecord::Base.connection.query_cache_enabled, "cache off" + assert_cache :off mw = middleware { |env| Task.find 1 @@ -47,42 +47,66 @@ class QueryCacheTest < ActiveRecord::TestCase } assert_raises(RuntimeError) { mw.call({}) } - assert_equal 0, ActiveRecord::Base.connection.query_cache.length - assert !ActiveRecord::Base.connection.query_cache_enabled, "cache off" + assert_cache :off end - def test_exceptional_middleware_cleans_up_correct_cache - connection = ActiveRecord::Base.connection - called = false + def test_query_cache_across_threads + ActiveRecord::Base.connection_pool.connections.each do |conn| + assert_cache :off, conn + end + + assert !ActiveRecord::Base.connection.nil? + assert_cache :off + + middleware { + assert_cache :clean - mw = middleware { |env| - Task.find 1 Task.find 1 - assert_equal 1, connection.query_cache.length + assert_cache :dirty - # Checkin connection early + thread_1_connection = ActiveRecord::Base.connection ActiveRecord::Base.clear_active_connections! - # Make sure ActiveRecord::Base.connection doesn't checkout the same connection - ActiveRecord::Base.connection_pool.remove(connection) + assert_cache :off, thread_1_connection - called = true - } - mw.call({}) + started = Concurrent::Event.new + checked = Concurrent::Event.new - assert called - assert_equal 0, connection.query_cache.length - assert !connection.query_cache_enabled, "cache off" - end + thread_2_connection = nil + thread = Thread.new { + thread_2_connection = ActiveRecord::Base.connection - def test_exceptional_middleware_leaves_enabled_cache_alone - ActiveRecord::Base.connection.enable_query_cache! + assert_equal thread_2_connection, thread_1_connection + assert_cache :off - mw = middleware { |env| - raise "lol borked" - } - assert_raises(RuntimeError) { mw.call({}) } + middleware { + assert_cache :clean + + Task.find 1 + assert_cache :dirty + + started.set + checked.wait + + ActiveRecord::Base.clear_active_connections! + }.call({}) + } + + started.wait + + thread_1_connection = ActiveRecord::Base.connection + assert_not_equal thread_1_connection, thread_2_connection + assert_cache :dirty, thread_2_connection + checked.set + thread.join + + assert_cache :off, thread_2_connection + }.call({}) - assert ActiveRecord::Base.connection.query_cache_enabled, "cache on" + ActiveRecord::Base.connection_pool.connections.each do |conn| + assert_cache :off, conn + end + ensure + ActiveRecord::Base.clear_all_connections! end def test_middleware_delegates @@ -106,10 +130,10 @@ class QueryCacheTest < ActiveRecord::TestCase end def test_cache_enabled_during_call - assert !ActiveRecord::Base.connection.query_cache_enabled, "cache off" + assert_cache :off mw = middleware { |env| - assert ActiveRecord::Base.connection.query_cache_enabled, "cache on" + assert_cache :clean [200, {}, nil] } mw.call({}) @@ -295,6 +319,22 @@ class QueryCacheTest < ActiveRecord::TestCase ActiveRecord::QueryCache.install_executor_hooks executor lambda { |env| executor.wrap { app.call(env) } } end + + def assert_cache(state, connection = ActiveRecord::Base.connection) + case state + when :off + assert !connection.query_cache_enabled, "cache should be off" + assert connection.query_cache.empty?, "cache should be empty" + when :clean + assert connection.query_cache_enabled, "cache should be on" + assert connection.query_cache.empty?, "cache should be empty" + when :dirty + assert connection.query_cache_enabled, "cache should be on" + assert !connection.query_cache.empty?, "cache should be dirty" + else + raise "unknown state" + end + end end class QueryCacheExpiryTest < ActiveRecord::TestCase -- cgit v1.2.3 From 56832e791f3ec3e586cf049c6408c7a183fdd3a1 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 27 Oct 2016 09:13:38 +0200 Subject: let Regexp#match? be globally available Regexp#match? should be considered to be part of the Ruby core library. We are emulating it for < 2.4, but not having to require the extension is part of the illusion of the emulation. --- actionpack/lib/action_dispatch/routing/mapper.rb | 1 - actionview/lib/action_view/helpers/asset_tag_helper.rb | 1 - actionview/lib/action_view/helpers/asset_url_helper.rb | 1 - actionview/lib/action_view/helpers/translation_helper.rb | 1 - actionview/lib/action_view/helpers/url_helper.rb | 1 - actionview/lib/action_view/layouts.rb | 1 - actionview/lib/action_view/renderer/partial_renderer.rb | 1 - actionview/lib/action_view/template/error.rb | 1 - actionview/lib/action_view/template/handlers/erb.rb | 1 - actionview/lib/action_view/testing/resolvers.rb | 1 - actionview/test/actionpack/controller/layout_test.rb | 1 - activemodel/lib/active_model/attribute_methods.rb | 1 - activemodel/lib/active_model/validations/format.rb | 1 - activemodel/test/validators/email_validator.rb | 1 - activerecord/lib/active_record/coders/yaml_column.rb | 1 - .../lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 1 - activerecord/lib/active_record/dynamic_matchers.rb | 1 - activerecord/lib/active_record/migration.rb | 1 - activerecord/lib/active_record/relation/delegation.rb | 1 - activerecord/lib/active_record/relation/query_methods.rb | 1 - activerecord/lib/active_record/sanitization.rb | 1 - .../rails/generators/active_record/migration/migration_generator.rb | 1 - .../test/cases/associations/left_outer_join_association_test.rb | 1 - activerecord/test/cases/scoping/default_scoping_test.rb | 1 - activerecord/test/cases/test_case.rb | 1 - activesupport/lib/active_support/rails.rb | 6 ++++++ 26 files changed, 6 insertions(+), 25 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index c481c190bf..c412484895 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1,7 +1,6 @@ require "active_support/core_ext/hash/slice" require "active_support/core_ext/enumerable" require "active_support/core_ext/array/extract_options" -require "active_support/core_ext/regexp" require "action_dispatch/routing/redirection" require "action_dispatch/routing/endpoint" diff --git a/actionview/lib/action_view/helpers/asset_tag_helper.rb b/actionview/lib/action_view/helpers/asset_tag_helper.rb index b1563ac490..39fa11ccfd 100644 --- a/actionview/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionview/lib/action_view/helpers/asset_tag_helper.rb @@ -1,6 +1,5 @@ require "active_support/core_ext/array/extract_options" require "active_support/core_ext/hash/keys" -require "active_support/core_ext/regexp" require "action_view/helpers/asset_url_helper" require "action_view/helpers/tag_helper" diff --git a/actionview/lib/action_view/helpers/asset_url_helper.rb b/actionview/lib/action_view/helpers/asset_url_helper.rb index e0de2ff4d6..fab49e402b 100644 --- a/actionview/lib/action_view/helpers/asset_url_helper.rb +++ b/actionview/lib/action_view/helpers/asset_url_helper.rb @@ -1,5 +1,4 @@ require "zlib" -require "active_support/core_ext/regexp" module ActionView # = Action View Asset URL Helpers diff --git a/actionview/lib/action_view/helpers/translation_helper.rb b/actionview/lib/action_view/helpers/translation_helper.rb index cbabaf5757..47ed41a129 100644 --- a/actionview/lib/action_view/helpers/translation_helper.rb +++ b/actionview/lib/action_view/helpers/translation_helper.rb @@ -1,6 +1,5 @@ require "action_view/helpers/tag_helper" require "active_support/core_ext/string/access" -require "active_support/core_ext/regexp" require "i18n/exceptions" module ActionView diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb index d410976bef..36b7515173 100644 --- a/actionview/lib/action_view/helpers/url_helper.rb +++ b/actionview/lib/action_view/helpers/url_helper.rb @@ -2,7 +2,6 @@ require "action_view/helpers/javascript_helper" require "active_support/core_ext/array/access" require "active_support/core_ext/hash/keys" require "active_support/core_ext/string/output_safety" -require "active_support/core_ext/regexp" module ActionView # = Action View URL Helpers diff --git a/actionview/lib/action_view/layouts.rb b/actionview/lib/action_view/layouts.rb index b083de1396..e8abfeac52 100644 --- a/actionview/lib/action_view/layouts.rb +++ b/actionview/lib/action_view/layouts.rb @@ -1,6 +1,5 @@ require "action_view/rendering" require "active_support/core_ext/module/remove_method" -require "active_support/core_ext/regexp" module ActionView # Layouts reverse the common pattern of including shared headers and footers in many templates to isolate changes in diff --git a/actionview/lib/action_view/renderer/partial_renderer.rb b/actionview/lib/action_view/renderer/partial_renderer.rb index dfe38c488f..c900da3277 100644 --- a/actionview/lib/action_view/renderer/partial_renderer.rb +++ b/actionview/lib/action_view/renderer/partial_renderer.rb @@ -1,5 +1,4 @@ require "concurrent/map" -require "active_support/core_ext/regexp" require "action_view/renderer/partial_renderer/collection_caching" module ActionView diff --git a/actionview/lib/action_view/template/error.rb b/actionview/lib/action_view/template/error.rb index 4010677477..cc90477190 100644 --- a/actionview/lib/action_view/template/error.rb +++ b/actionview/lib/action_view/template/error.rb @@ -1,5 +1,4 @@ require "active_support/core_ext/enumerable" -require "active_support/core_ext/regexp" module ActionView # = Action View Errors diff --git a/actionview/lib/action_view/template/handlers/erb.rb b/actionview/lib/action_view/template/handlers/erb.rb index 6f07de1813..5d047a6991 100644 --- a/actionview/lib/action_view/template/handlers/erb.rb +++ b/actionview/lib/action_view/template/handlers/erb.rb @@ -1,5 +1,4 @@ require "erubis" -require "active_support/core_ext/regexp" module ActionView class Template diff --git a/actionview/lib/action_view/testing/resolvers.rb b/actionview/lib/action_view/testing/resolvers.rb index 5cb9f66529..f072664535 100644 --- a/actionview/lib/action_view/testing/resolvers.rb +++ b/actionview/lib/action_view/testing/resolvers.rb @@ -1,4 +1,3 @@ -require "active_support/core_ext/regexp" require "action_view/template/resolver" module ActionView #:nodoc: diff --git a/actionview/test/actionpack/controller/layout_test.rb b/actionview/test/actionpack/controller/layout_test.rb index 00147d31f3..a342b22161 100644 --- a/actionview/test/actionpack/controller/layout_test.rb +++ b/actionview/test/actionpack/controller/layout_test.rb @@ -1,6 +1,5 @@ require "abstract_unit" require "active_support/core_ext/array/extract_options" -require "active_support/core_ext/regexp" # The view_paths array must be set on Base and not LayoutTest so that LayoutTest's inherited # method has access to the view_paths array when looking for a layout to automatically assign. diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb index 96709486f3..1441b146f8 100644 --- a/activemodel/lib/active_model/attribute_methods.rb +++ b/activemodel/lib/active_model/attribute_methods.rb @@ -1,6 +1,5 @@ require "concurrent/map" require "mutex_m" -require "active_support/core_ext/regexp" module ActiveModel # Raised when an attribute is not defined. diff --git a/activemodel/lib/active_model/validations/format.rb b/activemodel/lib/active_model/validations/format.rb index e4ea42f8f4..fa183885ab 100644 --- a/activemodel/lib/active_model/validations/format.rb +++ b/activemodel/lib/active_model/validations/format.rb @@ -1,4 +1,3 @@ -require "active_support/core_ext/regexp" module ActiveModel module Validations diff --git a/activemodel/test/validators/email_validator.rb b/activemodel/test/validators/email_validator.rb index 43011b277b..9b74d83b37 100644 --- a/activemodel/test/validators/email_validator.rb +++ b/activemodel/test/validators/email_validator.rb @@ -1,4 +1,3 @@ -require "active_support/core_ext/regexp" class EmailValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) diff --git a/activerecord/lib/active_record/coders/yaml_column.rb b/activerecord/lib/active_record/coders/yaml_column.rb index 1c8c9fa272..3a04a10fc9 100644 --- a/activerecord/lib/active_record/coders/yaml_column.rb +++ b/activerecord/lib/active_record/coders/yaml_column.rb @@ -1,5 +1,4 @@ require "yaml" -require "active_support/core_ext/regexp" module ActiveRecord module Coders # :nodoc: diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index e7bd0e7c12..eb1041d082 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -9,7 +9,6 @@ require "active_record/connection_adapters/mysql/schema_dumper" require "active_record/connection_adapters/mysql/type_metadata" require "active_support/core_ext/string/strip" -require "active_support/core_ext/regexp" module ActiveRecord module ConnectionAdapters diff --git a/activerecord/lib/active_record/dynamic_matchers.rb b/activerecord/lib/active_record/dynamic_matchers.rb index 9a7a8d25bb..08d42f3dd4 100644 --- a/activerecord/lib/active_record/dynamic_matchers.rb +++ b/activerecord/lib/active_record/dynamic_matchers.rb @@ -1,4 +1,3 @@ -require "active_support/core_ext/regexp" module ActiveRecord module DynamicMatchers #:nodoc: diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index f333769159..9c3901e736 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -1,7 +1,6 @@ require "set" require "zlib" require "active_support/core_ext/module/attribute_accessors" -require "active_support/core_ext/regexp" module ActiveRecord class MigrationError < ActiveRecordError#:nodoc: diff --git a/activerecord/lib/active_record/relation/delegation.rb b/activerecord/lib/active_record/relation/delegation.rb index d16de4b06c..ac933d25ae 100644 --- a/activerecord/lib/active_record/relation/delegation.rb +++ b/activerecord/lib/active_record/relation/delegation.rb @@ -1,5 +1,4 @@ require "active_support/concern" -require "active_support/core_ext/regexp" module ActiveRecord module Delegation # :nodoc: diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index c6d0902e0d..2a0dd1c10f 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -4,7 +4,6 @@ require "active_record/relation/where_clause" require "active_record/relation/where_clause_factory" require "active_model/forbidden_attributes_protection" require "active_support/core_ext/string/filters" -require "active_support/core_ext/regexp" module ActiveRecord module QueryMethods diff --git a/activerecord/lib/active_record/sanitization.rb b/activerecord/lib/active_record/sanitization.rb index e7c0936984..3d52dc44cf 100644 --- a/activerecord/lib/active_record/sanitization.rb +++ b/activerecord/lib/active_record/sanitization.rb @@ -1,4 +1,3 @@ -require "active_support/core_ext/regexp" module ActiveRecord module Sanitization diff --git a/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb b/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb index 76ed25ea75..12d1f58f67 100644 --- a/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb +++ b/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb @@ -1,5 +1,4 @@ require "rails/generators/active_record" -require "active_support/core_ext/regexp" module ActiveRecord module Generators # :nodoc: diff --git a/activerecord/test/cases/associations/left_outer_join_association_test.rb b/activerecord/test/cases/associations/left_outer_join_association_test.rb index 2cc6468827..42dbbad1c8 100644 --- a/activerecord/test/cases/associations/left_outer_join_association_test.rb +++ b/activerecord/test/cases/associations/left_outer_join_association_test.rb @@ -5,7 +5,6 @@ require "models/author" require "models/essay" require "models/categorization" require "models/person" -require "active_support/core_ext/regexp" class LeftOuterJoinAssociationTest < ActiveRecord::TestCase fixtures :authors, :essays, :posts, :comments, :categorizations, :people diff --git a/activerecord/test/cases/scoping/default_scoping_test.rb b/activerecord/test/cases/scoping/default_scoping_test.rb index 61062da3e1..b3dc979720 100644 --- a/activerecord/test/cases/scoping/default_scoping_test.rb +++ b/activerecord/test/cases/scoping/default_scoping_test.rb @@ -5,7 +5,6 @@ require "models/developer" require "models/computer" require "models/vehicle" require "models/cat" -require "active_support/core_ext/regexp" class DefaultScopingTest < ActiveRecord::TestCase fixtures :developers, :posts, :comments diff --git a/activerecord/test/cases/test_case.rb b/activerecord/test/cases/test_case.rb index 8eddc5a9ed..a4fc69fcd3 100644 --- a/activerecord/test/cases/test_case.rb +++ b/activerecord/test/cases/test_case.rb @@ -2,7 +2,6 @@ require "active_support/test_case" require "active_support/testing/autorun" require "active_support/testing/method_call_assertions" require "active_support/testing/stream" -require "active_support/core_ext/regexp" require "active_record/fixtures" require "cases/validations_repair_helper" diff --git a/activesupport/lib/active_support/rails.rb b/activesupport/lib/active_support/rails.rb index 57380061f7..f6b018f0d3 100644 --- a/activesupport/lib/active_support/rails.rb +++ b/activesupport/lib/active_support/rails.rb @@ -25,3 +25,9 @@ require "active_support/core_ext/module/delegation" # Defines ActiveSupport::Deprecation. require "active_support/deprecation" + +# Defines Regexp#match?. +# +# This should be removed when Rails needs Ruby 2.4 or later, and the require +# added where other Regexp extensions are being used (easy to grep). +require "active_support/core_ext/regexp" -- cgit v1.2.3 From 7506f3390683fd1329e60385515c3c55b39ff1d5 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 27 Oct 2016 09:45:20 +0200 Subject: removes requires already present in active_support/rails --- actionpack/lib/abstract_controller/rendering.rb | 2 -- actionpack/lib/action_dispatch/routing/route_set.rb | 1 - actionview/lib/action_view/template.rb | 1 - activejob/lib/active_job/queue_adapter.rb | 1 - activejob/test/support/integration/test_case_helpers.rb | 1 - activemodel/lib/active_model/naming.rb | 1 - activerecord/lib/active_record/relation/delegation.rb | 2 -- 7 files changed, 9 deletions(-) diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 2cb22cb53d..a0560a8748 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -1,6 +1,4 @@ require "abstract_controller/error" -require "active_support/concern" -require "active_support/core_ext/class/attribute" require "action_view" require "action_view/view_paths" require "set" diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index a1bc357c8b..326329c65f 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -1,5 +1,4 @@ require "action_dispatch/journey" -require "active_support/concern" require "active_support/core_ext/object/to_query" require "active_support/core_ext/hash/slice" require "active_support/core_ext/module/remove_method" diff --git a/actionview/lib/action_view/template.rb b/actionview/lib/action_view/template.rb index c01dd1c028..98571cf55e 100644 --- a/actionview/lib/action_view/template.rb +++ b/actionview/lib/action_view/template.rb @@ -1,6 +1,5 @@ require "active_support/core_ext/object/try" require "active_support/core_ext/kernel/singleton_class" -require "active_support/core_ext/module/delegation" require "thread" module ActionView diff --git a/activejob/lib/active_job/queue_adapter.rb b/activejob/lib/active_job/queue_adapter.rb index 2e9f1e61be..bcc555d33e 100644 --- a/activejob/lib/active_job/queue_adapter.rb +++ b/activejob/lib/active_job/queue_adapter.rb @@ -1,5 +1,4 @@ require "active_job/queue_adapters/inline_adapter" -require "active_support/core_ext/class/attribute" require "active_support/core_ext/string/inflections" module ActiveJob diff --git a/activejob/test/support/integration/test_case_helpers.rb b/activejob/test/support/integration/test_case_helpers.rb index 4c4c56c9da..da8638895b 100644 --- a/activejob/test/support/integration/test_case_helpers.rb +++ b/activejob/test/support/integration/test_case_helpers.rb @@ -1,4 +1,3 @@ -require "active_support/concern" require "active_support/core_ext/string/inflections" require "support/integration/jobs_manager" diff --git a/activemodel/lib/active_model/naming.rb b/activemodel/lib/active_model/naming.rb index 3830d1486d..840fc663c0 100644 --- a/activemodel/lib/active_model/naming.rb +++ b/activemodel/lib/active_model/naming.rb @@ -1,7 +1,6 @@ require "active_support/core_ext/hash/except" require "active_support/core_ext/module/introspection" require "active_support/core_ext/module/remove_method" -require "active_support/core_ext/module/delegation" module ActiveModel class Name diff --git a/activerecord/lib/active_record/relation/delegation.rb b/activerecord/lib/active_record/relation/delegation.rb index ac933d25ae..4b9310b225 100644 --- a/activerecord/lib/active_record/relation/delegation.rb +++ b/activerecord/lib/active_record/relation/delegation.rb @@ -1,5 +1,3 @@ -require "active_support/concern" - module ActiveRecord module Delegation # :nodoc: module DelegateCache # :nodoc: -- cgit v1.2.3 From 94821b4bd10464d52b471380c49f85fac43a8ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Emin=20=C4=B0NA=C3=87?= Date: Fri, 19 Feb 2016 04:42:59 +0200 Subject: Fix HABTM associations join table resolver bug on constants and symbols Using Constant and symbol class_name option for associations are valid but raises exception on HABTM associations. There was a test case which tries to cover symbol class_name usage but doesn't cover correctly. Fixed both symbol usage and constant usage as well. These are all working as expected now; ``` has_and_belongs_to_many :foos, class_name: 'Foo' has_and_belongs_to_many :foos, class_name: :Foo has_and_belongs_to_many :foos, class_name: Foo ``` Closes #23767 --- .../associations/builder/has_and_belongs_to_many.rb | 2 +- .../has_and_belongs_to_many_associations_test.rb | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb index 047292b2bd..42a90b449c 100644 --- a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb +++ b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb @@ -28,7 +28,7 @@ module ActiveRecord::Associations::Builder # :nodoc: class_name = options.fetch(:class_name) { name.to_s.camelize.singularize } - KnownClass.new lhs_class, class_name + KnownClass.new lhs_class, class_name.to_s end 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 06fc7a4388..8aab7cfa47 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 @@ -86,6 +86,10 @@ class DeveloperWithSymbolClassName < Developer has_and_belongs_to_many :projects, class_name: :ProjectWithSymbolsForKeys end +class DeveloperWithConstantClassName < Developer + has_and_belongs_to_many :projects, class_name: ProjectWithSymbolsForKeys +end + class DeveloperWithExtendOption < Developer module NamedExtension def category @@ -939,7 +943,15 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase def test_with_symbol_class_name assert_nothing_raised do - DeveloperWithSymbolClassName.new + developer = DeveloperWithSymbolClassName.new + developer.projects + end + end + + def test_with_constant_class_name + assert_nothing_raised do + developer = DeveloperWithConstantClassName.new + developer.projects end end -- cgit v1.2.3 From 02063a8e63edf90a5ddca68e14a88191478c2a60 Mon Sep 17 00:00:00 2001 From: Julian Nadeau Date: Thu, 27 Oct 2016 13:22:55 -0400 Subject: Fixes an issue where time_zone_conversion that causes an exception in ARs delegation Following off of https://github.com/rails/rails/issues/15945, I realized that super needs to be the first thing that is called in an AbstractModel's inherited method. I was receiving errors within the inherited method of time_zone_conversion, so I tested locally by moving super to the top of the method declaration. All exceptions went away. --- .../lib/active_record/attribute_methods/time_zone_conversion.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb index bea1514cdf..ce9985e2e1 100644 --- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb +++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb @@ -70,6 +70,7 @@ module ActiveRecord private def inherited(subclass) + super # We need to apply this decorator here, rather than on module inclusion. The closure # created by the matcher would otherwise evaluate for `ActiveRecord::Base`, not the # sub class being decorated. As such, changes to `time_zone_aware_attributes`, or @@ -80,7 +81,6 @@ module ActiveRecord TimeZoneConverter.new(type) end end - super end def create_time_zone_conversion_attribute?(name, cast_type) -- cgit v1.2.3 From 007e50d8e5a900547471b6c4ec79d9d217682c5d Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Thu, 27 Oct 2016 15:31:22 -0500 Subject: Permit loads while queries are running A query may wait on a database-level lock, which could lead to a deadlock between threads. --- .../connection_adapters/abstract_mysql_adapter.rb | 6 ++- .../mysql/database_statements.rb | 4 +- .../postgresql/database_statements.rb | 8 +++- .../connection_adapters/postgresql_adapter.rb | 10 ++++- .../connection_adapters/sqlite3_adapter.rb | 44 ++++++++++++---------- 5 files changed, 47 insertions(+), 25 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 8d0a1c0842..3bee0e2c62 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -215,7 +215,11 @@ module ActiveRecord # Executes the SQL statement in the context of this connection. def execute(sql, name = nil) - log(sql, name) { @connection.query(sql) } + log(sql, name) do + ActiveSupport::Dependencies.interlock.permit_concurrent_loads do + @connection.query(sql) + end + end end # Mysql2Adapter doesn't have to free a result after using it, but we use this method diff --git a/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb b/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb index 56800f7590..274753a8a5 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb @@ -86,7 +86,9 @@ module ActiveRecord end begin - result = stmt.execute(*type_casted_binds) + ActiveSupport::Dependencies.interlock.permit_concurrent_loads do + result = stmt.execute(*type_casted_binds) + end rescue Mysql2::Error => e if cache_stmt @statements.delete(sql) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb index 092543259f..520a50506f 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb @@ -85,7 +85,9 @@ module ActiveRecord # Queries the database and returns the results in an Array-like object def query(sql, name = nil) #:nodoc: log(sql, name) do - result_as_array @connection.async_exec(sql) + ActiveSupport::Dependencies.interlock.permit_concurrent_loads do + result_as_array @connection.async_exec(sql) + end end end @@ -95,7 +97,9 @@ module ActiveRecord # need it specifically, you may want consider the exec_query wrapper. def execute(sql, name = nil) log(sql, name) do - @connection.async_exec(sql) + ActiveSupport::Dependencies.interlock.permit_concurrent_loads do + @connection.async_exec(sql) + end end end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index acd1eeace7..710b5cd887 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -601,7 +601,11 @@ module ActiveRecord def exec_no_cache(sql, name, binds) type_casted_binds = type_casted_binds(binds) - log(sql, name, binds, type_casted_binds) { @connection.async_exec(sql, type_casted_binds) } + log(sql, name, binds, type_casted_binds) do + ActiveSupport::Dependencies.interlock.permit_concurrent_loads do + @connection.async_exec(sql, type_casted_binds) + end + end end def exec_cache(sql, name, binds) @@ -609,7 +613,9 @@ module ActiveRecord type_casted_binds = type_casted_binds(binds) log(sql, name, binds, type_casted_binds, stmt_key) do - @connection.exec_prepared(stmt_key, type_casted_binds) + ActiveSupport::Dependencies.interlock.permit_concurrent_loads do + @connection.exec_prepared(stmt_key, type_casted_binds) + end end rescue ActiveRecord::StatementInvalid => e raise unless is_cached_plan_failure?(e) diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index ebeac425d0..bd73668359 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -191,27 +191,29 @@ module ActiveRecord type_casted_binds = type_casted_binds(binds) log(sql, name, binds, type_casted_binds) do - # Don't cache statements if they are not prepared - unless prepare - stmt = @connection.prepare(sql) - begin - cols = stmt.columns - unless without_prepared_statement?(binds) - stmt.bind_params(type_casted_binds) + ActiveSupport::Dependencies.interlock.permit_concurrent_loads do + # Don't cache statements if they are not prepared + unless prepare + stmt = @connection.prepare(sql) + begin + cols = stmt.columns + unless without_prepared_statement?(binds) + stmt.bind_params(type_casted_binds) + end + records = stmt.to_a + ensure + stmt.close end + else + cache = @statements[sql] ||= { + stmt: @connection.prepare(sql) + } + stmt = cache[:stmt] + cols = cache[:cols] ||= stmt.columns + stmt.reset! + stmt.bind_params(type_casted_binds) records = stmt.to_a - ensure - stmt.close end - else - cache = @statements[sql] ||= { - stmt: @connection.prepare(sql) - } - stmt = cache[:stmt] - cols = cache[:cols] ||= stmt.columns - stmt.reset! - stmt.bind_params(type_casted_binds) - records = stmt.to_a end ActiveRecord::Result.new(cols, records) @@ -229,7 +231,11 @@ module ActiveRecord end def execute(sql, name = nil) #:nodoc: - log(sql, name) { @connection.execute(sql) } + log(sql, name) do + ActiveSupport::Dependencies.interlock.permit_concurrent_loads do + @connection.execute(sql) + end + end end def begin_db_transaction #:nodoc: -- cgit v1.2.3 From b56eaa2e1511786570578cc752394f4a5f920a39 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Fri, 28 Oct 2016 11:32:04 +0900 Subject: Fix :stopdoc: to :startdoc: [ci skip] --- actionpack/lib/action_dispatch/journey/formatter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionpack/lib/action_dispatch/journey/formatter.rb b/actionpack/lib/action_dispatch/journey/formatter.rb index 03f73c7598..b5a8ca7262 100644 --- a/actionpack/lib/action_dispatch/journey/formatter.rb +++ b/actionpack/lib/action_dispatch/journey/formatter.rb @@ -179,5 +179,5 @@ module ActionDispatch end end end - # :stopdoc: + # :startdoc: end -- cgit v1.2.3 From a36ef6ee3ed44e6ce1636f12da59c473dddd94bb Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Thu, 27 Oct 2016 20:13:55 +0900 Subject: Explicitly show --no-helper and --no-assets options in help message I'm sorry for causing #24168. I wasn't aware of --no-helper and --no-assets. So I'm adding them to the help message. I'm still not sure how to show `--no-test-framework` though. --- railties/lib/rails/generators/rails/controller/controller_generator.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/railties/lib/rails/generators/rails/controller/controller_generator.rb b/railties/lib/rails/generators/rails/controller/controller_generator.rb index 213de37cce..ced3c85c00 100644 --- a/railties/lib/rails/generators/rails/controller/controller_generator.rb +++ b/railties/lib/rails/generators/rails/controller/controller_generator.rb @@ -3,6 +3,8 @@ module Rails class ControllerGenerator < NamedBase # :nodoc: argument :actions, type: :array, default: [], banner: "action action" class_option :skip_routes, type: :boolean, desc: "Don't add routes to config/routes.rb." + class_option :helper, type: :boolean + class_option :assets, type: :boolean check_class_collision suffix: "Controller" -- cgit v1.2.3 From f7d54c4247df39ee79de241b9f10f3b06ea0f565 Mon Sep 17 00:00:00 2001 From: Erol Fornoles Date: Fri, 28 Oct 2016 18:12:26 +0800 Subject: Add documentation for `config.assets.version` [skip ci] --- guides/source/configuring.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 18416a60ff..c625cf67f6 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -179,6 +179,8 @@ pipeline is enabled. It is set to `true` by default. * `config.assets.debug` disables the concatenation and compression of assets. Set to `true` by default in `development.rb`. +* `config.assets.version` is an option string that is used in MD5 hash generation. This can be changed to force all files to be recompiled. + * `config.assets.compile` is a boolean that can be used to turn on live Sprockets compilation in production. * `config.assets.logger` accepts a logger conforming to the interface of Log4r or the default Ruby `Logger` class. Defaults to the same configured at `config.logger`. Setting `config.assets.logger` to `false` will turn off served assets logging. -- cgit v1.2.3 From 3f2046f00ab0046f9252a5a7b52f617028bc4e0c Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Fri, 28 Oct 2016 13:30:16 +0200 Subject: [ci skip] Revise TagHelper only permitting symbols doc. Follow up to 454460e. Rebuild the sentence so the bit about only symbols allowed comes less out of left field and fits in better with the existing doc. Also remove the `(Legacy syntax)` construct. The sections are properly nested under `=== Options` with `====` and look fine on the generated API doc site. --- actionview/lib/action_view/helpers/tag_helper.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/actionview/lib/action_view/helpers/tag_helper.rb b/actionview/lib/action_view/helpers/tag_helper.rb index b625c1a194..306b71c85e 100644 --- a/actionview/lib/action_view/helpers/tag_helper.rb +++ b/actionview/lib/action_view/helpers/tag_helper.rb @@ -138,8 +138,7 @@ module ActionView # # ==== Options # - # Any passed options become attributes on the generated tag. - # You can only use symbols (not strings) for the attribute names. + # Use symbol keyed options to add attributes to the generated tag. # # tag.section class: %w( kitties puppies ) # # =>

@@ -201,7 +200,7 @@ module ActionView # hash to +options+. Set +escape+ to false to disable attribute value # escaping. # - # ==== Options (Legacy syntax) + # ==== Options # # You can use symbols or strings for the attribute names. # @@ -211,7 +210,7 @@ module ActionView # HTML5 data-* attributes can be set with a single +data+ key # pointing to a hash of sub-attributes. # - # ==== Examples (Legacy syntax) + # ==== Examples # # tag("br") # # =>
-- cgit v1.2.3 From 83776676e54b387fc52081ff31cfd7710bae9e03 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Fri, 28 Oct 2016 20:44:58 +0200 Subject: Hide commands from API site. They're just barren on the site and confure more than guide, instead rely on the built in --help to guide users. --- railties/lib/rails/commands/application/application_command.rb | 2 +- railties/lib/rails/commands/console/console_command.rb | 2 +- railties/lib/rails/commands/dbconsole/dbconsole_command.rb | 2 +- railties/lib/rails/commands/destroy/destroy_command.rb | 4 ++-- railties/lib/rails/commands/generate/generate_command.rb | 4 ++-- railties/lib/rails/commands/help/help_command.rb | 2 +- railties/lib/rails/commands/new/new_command.rb | 2 +- railties/lib/rails/commands/plugin/plugin_command.rb | 2 +- railties/lib/rails/commands/rake/rake_command.rb | 2 +- railties/lib/rails/commands/runner/runner_command.rb | 2 +- railties/lib/rails/commands/server/server_command.rb | 4 ++-- railties/lib/rails/commands/test/test_command.rb | 4 ++-- railties/lib/rails/commands/version/version_command.rb | 2 +- 13 files changed, 17 insertions(+), 17 deletions(-) diff --git a/railties/lib/rails/commands/application/application_command.rb b/railties/lib/rails/commands/application/application_command.rb index 7e3a2b011d..7675d3b3d1 100644 --- a/railties/lib/rails/commands/application/application_command.rb +++ b/railties/lib/rails/commands/application/application_command.rb @@ -13,7 +13,7 @@ module Rails end module Command - class ApplicationCommand < Base + class ApplicationCommand < Base # :nodoc: hide_command! def help diff --git a/railties/lib/rails/commands/console/console_command.rb b/railties/lib/rails/commands/console/console_command.rb index 617066f575..62e3aa19df 100644 --- a/railties/lib/rails/commands/console/console_command.rb +++ b/railties/lib/rails/commands/console/console_command.rb @@ -64,7 +64,7 @@ module Rails end module Command - class ConsoleCommand < Base + class ConsoleCommand < Base # :nodoc: include EnvironmentArgument class_option :sandbox, aliases: "-s", type: :boolean, default: false, diff --git a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb index d3c80da89b..54457cf78b 100644 --- a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb +++ b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb @@ -134,7 +134,7 @@ module Rails end module Command - class DbconsoleCommand < Base + class DbconsoleCommand < Base # :nodoc: include EnvironmentArgument class_option :include_password, aliases: "-p", type: :boolean, diff --git a/railties/lib/rails/commands/destroy/destroy_command.rb b/railties/lib/rails/commands/destroy/destroy_command.rb index 5e6b7f9371..5b552b2070 100644 --- a/railties/lib/rails/commands/destroy/destroy_command.rb +++ b/railties/lib/rails/commands/destroy/destroy_command.rb @@ -2,8 +2,8 @@ require "rails/generators" module Rails module Command - class DestroyCommand < Base - def help # :nodoc: + class DestroyCommand < Base # :nodoc: + def help Rails::Generators.help self.class.command_name end diff --git a/railties/lib/rails/commands/generate/generate_command.rb b/railties/lib/rails/commands/generate/generate_command.rb index b381ca85b9..59b2febc43 100644 --- a/railties/lib/rails/commands/generate/generate_command.rb +++ b/railties/lib/rails/commands/generate/generate_command.rb @@ -2,8 +2,8 @@ require "rails/generators" module Rails module Command - class GenerateCommand < Base - def help # :nodoc: + class GenerateCommand < Base # :nodoc: + def help Rails::Generators.help self.class.command_name end diff --git a/railties/lib/rails/commands/help/help_command.rb b/railties/lib/rails/commands/help/help_command.rb index 5bcc4c8eee..90d37217fc 100644 --- a/railties/lib/rails/commands/help/help_command.rb +++ b/railties/lib/rails/commands/help/help_command.rb @@ -1,6 +1,6 @@ module Rails module Command - class HelpCommand < Base + class HelpCommand < Base # :nodoc: hide_command! def help(*) diff --git a/railties/lib/rails/commands/new/new_command.rb b/railties/lib/rails/commands/new/new_command.rb index 13eedfc479..74d1fa5021 100644 --- a/railties/lib/rails/commands/new/new_command.rb +++ b/railties/lib/rails/commands/new/new_command.rb @@ -1,6 +1,6 @@ module Rails module Command - class NewCommand < Base + class NewCommand < Base # :nodoc: def help Rails::Command.invoke :application, [ "--help" ] end diff --git a/railties/lib/rails/commands/plugin/plugin_command.rb b/railties/lib/rails/commands/plugin/plugin_command.rb index d6d9fe4400..16587ce067 100644 --- a/railties/lib/rails/commands/plugin/plugin_command.rb +++ b/railties/lib/rails/commands/plugin/plugin_command.rb @@ -1,6 +1,6 @@ module Rails module Command - class PluginCommand < Base + class PluginCommand < Base # :nodoc: hide_command! def help diff --git a/railties/lib/rails/commands/rake/rake_command.rb b/railties/lib/rails/commands/rake/rake_command.rb index a43c884170..f03dc81117 100644 --- a/railties/lib/rails/commands/rake/rake_command.rb +++ b/railties/lib/rails/commands/rake/rake_command.rb @@ -1,6 +1,6 @@ module Rails module Command - class RakeCommand < Base + class RakeCommand < Base # :nodoc: extend Rails::Command::Actions namespace "rake" diff --git a/railties/lib/rails/commands/runner/runner_command.rb b/railties/lib/rails/commands/runner/runner_command.rb index 8db6da8759..27666c76b7 100644 --- a/railties/lib/rails/commands/runner/runner_command.rb +++ b/railties/lib/rails/commands/runner/runner_command.rb @@ -1,6 +1,6 @@ module Rails module Command - class RunnerCommand < Base + class RunnerCommand < Base # :nodoc: class_option :environment, aliases: "-e", type: :string, default: Rails::Command.environment.dup, desc: "The environment for the runner to operate under (test/development/production)" diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb index 14cf72f483..e9538b804c 100644 --- a/railties/lib/rails/commands/server/server_command.rb +++ b/railties/lib/rails/commands/server/server_command.rb @@ -139,8 +139,8 @@ module Rails end module Command - class ServerCommand < Base - def help # :nodoc: + class ServerCommand < Base # :nodoc: + def help puts Rails::Server::Options.new.option_parser(Hash.new) end diff --git a/railties/lib/rails/commands/test/test_command.rb b/railties/lib/rails/commands/test/test_command.rb index 1b2e3af9cc..7bf8f61137 100644 --- a/railties/lib/rails/commands/test/test_command.rb +++ b/railties/lib/rails/commands/test/test_command.rb @@ -3,8 +3,8 @@ require "rails/test_unit/minitest_plugin" module Rails module Command - class TestCommand < Base - def help # :nodoc: + class TestCommand < Base # :nodoc: + def help perform # Hand over help printing to minitest. end diff --git a/railties/lib/rails/commands/version/version_command.rb b/railties/lib/rails/commands/version/version_command.rb index 4f3fbfca1b..ac745594ee 100644 --- a/railties/lib/rails/commands/version/version_command.rb +++ b/railties/lib/rails/commands/version/version_command.rb @@ -1,6 +1,6 @@ module Rails module Command - class VersionCommand < Base + class VersionCommand < Base # :nodoc: def perform Rails::Command.invoke :application, [ "--version" ] end -- cgit v1.2.3 From f99c37583dab9e1a6d8a67a407def0b2408df706 Mon Sep 17 00:00:00 2001 From: Genadi Samokovarov Date: Fri, 28 Oct 2016 22:54:16 +0300 Subject: Support plain loggers in DebugExceptions I have been seeing people setting `Logger` instances for `config.logger` and it blowing up on `rails/web-console` usage. Now, I doubt many folks are manually setting `ActionView::Base.logger`, but given that `DebugExceptions` is running in a pretty fragile environment already, having it crash (and being silent) in those cases can be pretty tricky to trace down. I'm proposing we verify whether the `ActionView::Base.logger` supports silencing before we try to do it, to save us the headache of tracing it down. --- .../lib/action_dispatch/middleware/debug_exceptions.rb | 4 +++- actionpack/test/dispatch/debug_exceptions_test.rb | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb index ee644f41c8..1a9018fe0c 100644 --- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb @@ -38,7 +38,9 @@ module ActionDispatch end def render(*) - if logger = ActionView::Base.logger + logger = ActionView::Base.logger + + if logger && logger.respond_to?(:silence) logger.silence { super } else super diff --git a/actionpack/test/dispatch/debug_exceptions_test.rb b/actionpack/test/dispatch/debug_exceptions_test.rb index 2c5e09e283..bff52f2a2b 100644 --- a/actionpack/test/dispatch/debug_exceptions_test.rb +++ b/actionpack/test/dispatch/debug_exceptions_test.rb @@ -384,6 +384,23 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest end end + test "logs with non active support loggers" do + @app = DevelopmentApp + io = StringIO.new + logger = Logger.new(io) + + _old, ActionView::Base.logger = ActionView::Base.logger, logger + begin + assert_nothing_raised do + get "/", headers: { "action_dispatch.show_exceptions" => true, "action_dispatch.logger" => logger } + end + ensure + ActionView::Base.logger = _old + end + + assert_match(/puke/, io.rewind && io.read) + end + test "uses backtrace cleaner from env" do @app = DevelopmentApp backtrace_cleaner = ActiveSupport::BacktraceCleaner.new -- cgit v1.2.3 From dcb364ec8ec89c4c70c8de1965a3d3d6b45de072 Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Fri, 28 Oct 2016 16:33:21 -0500 Subject: Fix the variable scoping issue I introduced in 007e50d8e5a900547471b6c4ec79d9d217682c5d --- activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index bd73668359..a473c5d67d 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -214,9 +214,9 @@ module ActiveRecord stmt.bind_params(type_casted_binds) records = stmt.to_a end - end - ActiveRecord::Result.new(cols, records) + ActiveRecord::Result.new(cols, records) + end end end -- cgit v1.2.3 From a8b996a0eee9aae455c5f82fac0baf24edb3a9c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 28 Oct 2016 21:21:24 -0200 Subject: Revert "Merge pull request #23698 from meinac/add_missing_types_into_ar_model_generator_usage" This reverts commit aaf561d26cf9a879ff40190b625155015c6225da, reversing changes made to 83776676e54b387fc52081ff31cfd7710bae9e03. Reason: It is not a good idea to connect to the database on generators --- railties/lib/rails/generators/rails/model/USAGE | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/railties/lib/rails/generators/rails/model/USAGE b/railties/lib/rails/generators/rails/model/USAGE index c95e523fb5..025bcf4774 100644 --- a/railties/lib/rails/generators/rails/model/USAGE +++ b/railties/lib/rails/generators/rails/model/USAGE @@ -35,7 +35,17 @@ Available field types: type. If no type is specified the string type will be used by default. You can use the following types: - <%= ActiveRecord::Base.connection.native_database_types.keys.join("\n\t") %> + integer + primary_key + decimal + float + boolean + binary + string + text + date + time + datetime You can also consider `references` as a kind of type. For instance, if you run: -- cgit v1.2.3 From fe1f4b2ad56f010a4e9b93d547d63a15953d9dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 29 Oct 2016 01:05:58 -0200 Subject: Add more rubocop rules about whitespaces --- .rubocop.yml | 21 + actioncable/lib/action_cable/channel/naming.rb | 2 +- actioncable/lib/action_cable/engine.rb | 2 +- actioncable/lib/action_cable/remote_connections.rb | 2 +- .../subscription_adapter/subscriber_map.rb | 2 +- actioncable/test/channel/periodic_timers_test.rb | 2 +- actioncable/test/client_test.rb | 22 +- actioncable/test/stubs/room.rb | 2 +- actioncable/test/worker_test.rb | 2 +- actionmailer/lib/action_mailer/base.rb | 4 +- actionmailer/lib/action_mailer/delivery_methods.rb | 4 +- .../action_mailer/inline_preview_interceptor.rb | 2 +- actionmailer/lib/action_mailer/message_delivery.rb | 6 +- actionmailer/lib/action_mailer/railtie.rb | 4 +- actionmailer/test/delivery_methods_test.rb | 2 +- actionmailer/test/mailers/base_mailer.rb | 6 +- actionmailer/test/message_delivery_test.rb | 2 +- actionmailer/test/url_test.rb | 8 +- actionpack/lib/abstract_controller/rendering.rb | 2 +- .../lib/action_controller/metal/conditional_get.rb | 2 +- .../lib/action_controller/metal/exceptions.rb | 2 +- .../action_controller/metal/http_authentication.rb | 6 +- .../lib/action_controller/metal/instrumentation.rb | 2 +- actionpack/lib/action_controller/metal/live.rb | 2 +- .../lib/action_controller/metal/params_wrapper.rb | 2 +- .../lib/action_controller/metal/rendering.rb | 2 +- .../action_controller/metal/strong_parameters.rb | 2 +- actionpack/lib/action_controller/railtie.rb | 2 +- actionpack/lib/action_controller/renderer.rb | 2 +- .../lib/action_dispatch/http/parameter_filter.rb | 2 +- actionpack/lib/action_dispatch/http/response.rb | 2 +- actionpack/lib/action_dispatch/http/upload.rb | 6 +- actionpack/lib/action_dispatch/http/url.rb | 4 +- .../lib/action_dispatch/journey/formatter.rb | 2 +- .../lib/action_dispatch/journey/gtg/builder.rb | 2 +- .../journey/gtg/transition_table.rb | 4 +- .../lib/action_dispatch/journey/nfa/builder.rb | 2 +- .../journey/nfa/transition_table.rb | 2 +- actionpack/lib/action_dispatch/journey/route.rb | 6 +- actionpack/lib/action_dispatch/journey/router.rb | 4 +- actionpack/lib/action_dispatch/journey/visitors.rb | 2 +- .../lib/action_dispatch/middleware/cookies.rb | 4 +- .../middleware/exception_wrapper.rb | 2 +- .../middleware/session/cookie_store.rb | 4 +- actionpack/lib/action_dispatch/request/session.rb | 6 +- actionpack/lib/action_dispatch/routing/mapper.rb | 2 +- .../action_dispatch/routing/polymorphic_routes.rb | 6 +- .../lib/action_dispatch/routing/redirection.rb | 8 +- .../lib/action_dispatch/routing/route_set.rb | 10 +- .../action_dispatch/testing/assertions/response.rb | 2 +- .../action_dispatch/testing/assertions/routing.rb | 6 +- .../lib/action_dispatch/testing/integration.rb | 2 +- actionpack/test/abstract/collector_test.rb | 2 +- actionpack/test/abstract_unit.rb | 2 +- actionpack/test/controller/caching_test.rb | 2 +- actionpack/test/controller/filters_test.rb | 46 +- actionpack/test/controller/flash_hash_test.rb | 4 +- .../controller/http_digest_authentication_test.rb | 4 +- actionpack/test/controller/integration_test.rb | 12 +- .../controller/new_base/render_streaming_test.rb | 2 +- .../test/controller/parameters/mutators_test.rb | 4 +- .../parameters/parameters_permit_test.rb | 10 +- actionpack/test/controller/render_json_test.rb | 2 +- actionpack/test/controller/render_test.rb | 2 +- actionpack/test/controller/renderers_test.rb | 2 +- actionpack/test/controller/resources_test.rb | 6 +- actionpack/test/controller/routing_test.rb | 12 +- actionpack/test/controller/send_file_test.rb | 2 +- actionpack/test/controller/test_case_test.rb | 8 +- .../test/controller/url_for_integration_test.rb | 188 +++---- actionpack/test/controller/url_for_test.rb | 10 +- actionpack/test/dispatch/cookies_test.rb | 12 +- actionpack/test/dispatch/debug_exceptions_test.rb | 2 +- actionpack/test/dispatch/header_test.rb | 4 +- actionpack/test/dispatch/mime_type_test.rb | 2 +- actionpack/test/dispatch/reloader_test.rb | 2 +- .../dispatch/request/query_string_parsing_test.rb | 4 +- .../request/url_encoded_params_parsing_test.rb | 2 +- actionpack/test/dispatch/request_test.rb | 28 +- actionpack/test/dispatch/response_test.rb | 6 +- actionpack/test/dispatch/routing_test.rb | 12 +- actionpack/test/dispatch/static_test.rb | 32 +- actionpack/test/dispatch/uploaded_file_test.rb | 8 +- .../session_autoload_test/foo.rb | 2 +- actionpack/test/journey/gtg/builder_test.rb | 10 +- .../test/journey/gtg/transition_table_test.rb | 2 +- actionpack/test/journey/nfa/simulator_test.rb | 2 +- .../test/journey/nfa/transition_table_test.rb | 4 +- actionpack/test/journey/route_test.rb | 2 +- actionpack/test/journey/router_test.rb | 22 +- actionpack/test/journey/routes_test.rb | 2 +- actionpack/test/lib/controller/fake_models.rb | 4 +- actionview/lib/action_view/context.rb | 2 +- actionview/lib/action_view/flows.rb | 2 +- .../lib/action_view/helpers/asset_tag_helper.rb | 4 +- .../lib/action_view/helpers/atom_feed_helper.rb | 4 +- actionview/lib/action_view/helpers/cache_helper.rb | 2 +- actionview/lib/action_view/helpers/date_helper.rb | 2 +- actionview/lib/action_view/helpers/form_helper.rb | 4 +- .../action_view/helpers/output_safety_helper.rb | 2 +- actionview/lib/action_view/helpers/tags/base.rb | 6 +- .../helpers/tags/collection_check_boxes.rb | 2 +- .../action_view/helpers/tags/collection_helpers.rb | 2 +- .../helpers/tags/collection_radio_buttons.rb | 2 +- actionview/lib/action_view/helpers/url_helper.rb | 4 +- actionview/lib/action_view/lookup_context.rb | 2 +- actionview/lib/action_view/railtie.rb | 2 +- .../lib/action_view/renderer/partial_renderer.rb | 2 +- actionview/lib/action_view/rendering.rb | 2 +- actionview/lib/action_view/template.rb | 2 +- actionview/lib/action_view/template/resolver.rb | 10 +- actionview/lib/action_view/test_case.rb | 6 +- actionview/lib/action_view/testing/resolvers.rb | 2 +- .../test/actionpack/controller/render_test.rb | 4 +- .../test/activerecord/relation_cache_test.rb | 2 +- actionview/test/lib/controller/fake_models.rb | 4 +- actionview/test/template/date_helper_test.rb | 92 ++-- actionview/test/template/digestor_test.rb | 6 +- actionview/test/template/form_helper_test.rb | 42 +- .../test/template/form_options_helper_test.rb | 70 +-- actionview/test/template/form_tag_helper_test.rb | 4 +- actionview/test/template/javascript_helper_test.rb | 8 +- .../test/template/output_safety_helper_test.rb | 4 +- actionview/test/template/text_helper_test.rb | 18 +- activejob/lib/active_job/configured_job.rb | 2 +- activejob/lib/active_job/core.rb | 2 +- activejob/lib/active_job/enqueuing.rb | 2 +- activejob/lib/active_job/exceptions.rb | 2 +- .../lib/active_job/queue_adapters/qu_adapter.rb | 2 +- activejob/lib/active_job/queue_name.rb | 2 +- activejob/lib/active_job/queue_priority.rb | 2 +- activejob/lib/active_job/railtie.rb | 2 +- activejob/test/cases/queue_naming_test.rb | 2 +- activejob/test/cases/queue_priority_test.rb | 2 +- activejob/test/helper.rb | 2 +- activejob/test/models/person.rb | 2 +- activejob/test/support/backburner/inline.rb | 2 +- .../support/delayed_job/delayed/backend/test.rb | 6 +- activejob/test/support/integration/adapters/que.rb | 2 +- .../support/integration/adapters/queue_classic.rb | 2 +- .../test/support/integration/adapters/sneakers.rb | 2 +- .../test/support/integration/test_case_helpers.rb | 8 +- activemodel/lib/active_model/errors.rb | 4 +- activemodel/lib/active_model/model.rb | 2 +- activemodel/lib/active_model/naming.rb | 2 +- activemodel/lib/active_model/serializers/json.rb | 2 +- .../lib/active_model/type/helpers/time_value.rb | 2 +- activemodel/lib/active_model/validations.rb | 2 +- .../lib/active_model/validations/acceptance.rb | 2 +- activemodel/lib/active_model/validations/length.rb | 2 +- activemodel/lib/active_model/validator.rb | 2 +- activemodel/test/cases/serialization_test.rb | 64 +-- activemodel/test/cases/type/integer_test.rb | 4 +- .../cases/validations/absence_validation_test.rb | 2 +- .../validations/acceptance_validation_test.rb | 4 +- .../validations/conditional_validation_test.rb | 2 +- .../validations/confirmation_validation_test.rb | 4 +- .../cases/validations/length_validation_test.rb | 26 +- .../validations/numericality_validation_test.rb | 2 +- .../cases/validations/presence_validation_test.rb | 2 +- activerecord/Rakefile | 4 +- activerecord/examples/performance.rb | 4 +- .../active_record/associations/join_dependency.rb | 18 +- .../associations/preloader/association.rb | 2 +- .../associations/preloader/through_association.rb | 6 +- .../lib/active_record/autosave_association.rb | 6 +- .../abstract/connection_pool.rb | 2 +- .../connection_adapters/abstract/query_cache.rb | 2 +- .../connection_adapters/abstract/schema_dumper.rb | 2 +- .../connection_adapters/abstract_adapter.rb | 2 +- .../connection_adapters/abstract_mysql_adapter.rb | 2 +- .../connection_specification.rb | 4 +- .../mysql/explain_pretty_printer.rb | 2 +- .../connection_adapters/postgresql/oid/hstore.rb | 4 +- .../connection_adapters/sqlite3_adapter.rb | 12 +- .../connection_adapters/statement_pool.rb | 2 +- activerecord/lib/active_record/core.rb | 2 +- activerecord/lib/active_record/fixtures.rb | 14 +- activerecord/lib/active_record/migration.rb | 14 +- activerecord/lib/active_record/railtie.rb | 2 +- activerecord/lib/active_record/reflection.rb | 2 +- .../relation/batches/batch_enumerator.rb | 2 +- activerecord/lib/active_record/schema.rb | 2 +- activerecord/lib/active_record/schema_dumper.rb | 4 +- activerecord/lib/active_record/scoping.rb | 2 +- activerecord/lib/active_record/statement_cache.rb | 6 +- .../lib/active_record/tasks/database_tasks.rb | 2 +- .../tasks/postgresql_database_tasks.rb | 2 +- activerecord/lib/active_record/validations.rb | 6 +- .../connection_adapters/fake_adapter.rb | 2 +- .../test/cases/adapters/mysql2/connection_test.rb | 2 +- .../test/cases/adapters/mysql2/json_test.rb | 12 +- .../cases/adapters/mysql2/reserved_word_test.rb | 10 +- .../test/cases/adapters/mysql2/schema_test.rb | 2 +- .../test/cases/adapters/postgresql/array_test.rb | 18 +- .../test/cases/adapters/postgresql/hstore_test.rb | 26 +- .../test/cases/adapters/postgresql/json_test.rb | 16 +- .../test/cases/adapters/postgresql/quoting_test.rb | 4 +- .../postgresql/schema_authorization_test.rb | 2 +- .../test/cases/adapters/postgresql/schema_test.rb | 6 +- .../cases/adapters/postgresql/timestamp_test.rb | 4 +- .../test/cases/adapters/postgresql/utils_test.rb | 6 +- .../cases/adapters/sqlite3/sqlite3_adapter_test.rb | 2 +- activerecord/test/cases/ar_schema_test.rb | 4 +- .../associations/belongs_to_associations_test.rb | 4 +- .../test/cases/associations/callbacks_test.rb | 4 +- .../associations/cascaded_eager_loading_test.rb | 8 +- .../eager_load_includes_full_sti_class_test.rb | 4 +- .../associations/eager_load_nested_include_test.rb | 2 +- activerecord/test/cases/associations/eager_test.rb | 40 +- .../test/cases/associations/extension_test.rb | 2 +- .../has_and_belongs_to_many_associations_test.rb | 4 +- .../associations/has_many_associations_test.rb | 8 +- .../has_many_through_associations_test.rb | 10 +- .../associations/has_one_associations_test.rb | 2 +- .../has_one_through_associations_test.rb | 2 +- .../test/cases/associations/join_model_test.rb | 28 +- activerecord/test/cases/attribute_methods_test.rb | 12 +- .../test/cases/autosave_association_test.rb | 2 +- activerecord/test/cases/base_test.rb | 28 +- activerecord/test/cases/calculations_test.rb | 12 +- .../test/cases/collection_cache_key_test.rb | 6 +- .../connection_adapters/connection_handler_test.rb | 2 +- .../merge_and_resolve_default_url_config_test.rb | 18 +- .../connection_specification/resolver_test.rb | 4 +- activerecord/test/cases/finder_test.rb | 52 +- activerecord/test/cases/fixture_set/file_test.rb | 2 +- activerecord/test/cases/fixtures_test.rb | 12 +- .../cases/forbidden_attributes_protection_test.rb | 4 +- activerecord/test/cases/json_serialization_test.rb | 6 +- activerecord/test/cases/locking_test.rb | 2 +- .../cases/migration/references_statements_test.rb | 2 +- activerecord/test/cases/migration_test.rb | 8 +- activerecord/test/cases/migrator_test.rb | 8 +- .../test/cases/multiparameter_attributes_test.rb | 8 +- activerecord/test/cases/nested_attributes_test.rb | 6 +- .../cases/nested_attributes_with_callbacks_test.rb | 8 +- activerecord/test/cases/persistence_test.rb | 2 +- activerecord/test/cases/primary_keys_test.rb | 4 +- activerecord/test/cases/relation/where_test.rb | 12 +- activerecord/test/cases/relation_test.rb | 6 +- activerecord/test/cases/relations_test.rb | 42 +- activerecord/test/cases/sanitize_test.rb | 4 +- activerecord/test/cases/schema_dumper_test.rb | 2 +- activerecord/test/cases/schema_loading_test.rb | 2 +- .../test/cases/scoping/named_scoping_test.rb | 4 +- .../test/cases/scoping/relation_scoping_test.rb | 2 +- .../test/cases/serialized_attribute_test.rb | 2 +- .../test/cases/tasks/database_tasks_test.rb | 2 +- activerecord/test/cases/test_case.rb | 4 +- .../test/cases/transaction_callbacks_test.rb | 12 +- activerecord/test/cases/transactions_test.rb | 10 +- .../validations/association_validation_test.rb | 2 +- activerecord/test/models/admin/user.rb | 4 +- activerecord/test/models/company.rb | 4 +- activerecord/test/models/pirate.rb | 16 +- activerecord/test/models/post.rb | 6 +- activesupport/bin/generate_tables | 10 +- activesupport/lib/active_support/cache.rb | 2 +- .../lib/active_support/cache/memory_store.rb | 2 +- .../cache/strategy/local_cache_middleware.rb | 4 +- activesupport/lib/active_support/callbacks.rb | 2 +- .../core_ext/date_time/conversions.rb | 2 +- .../active_support/core_ext/hash/conversions.rb | 6 +- .../active_support/core_ext/hash/reverse_merge.rb | 2 +- .../core_ext/module/qualified_const.rb | 2 +- .../lib/active_support/core_ext/regexp.rb | 2 +- .../lib/active_support/core_ext/securerandom.rb | 2 +- .../lib/active_support/core_ext/string/indent.rb | 4 +- .../core_ext/string/output_safety.rb | 2 +- .../active_support/core_ext/time/calculations.rb | 2 +- activesupport/lib/active_support/dependencies.rb | 2 +- activesupport/lib/active_support/duration.rb | 8 +- .../active_support/duration/iso8601_serializer.rb | 2 +- .../lib/active_support/file_update_checker.rb | 2 +- activesupport/lib/active_support/gzip.rb | 2 +- .../active_support/hash_with_indifferent_access.rb | 2 +- .../lib/active_support/inflector/methods.rb | 4 +- activesupport/lib/active_support/key_generator.rb | 2 +- .../lib/active_support/lazy_load_hooks.rb | 4 +- activesupport/lib/active_support/log_subscriber.rb | 2 +- .../active_support/log_subscriber/test_helper.rb | 2 +- .../lib/active_support/multibyte/unicode.rb | 28 +- .../active_support/notifications/instrumenter.rb | 2 +- .../number_helper/number_to_human_converter.rb | 2 +- .../number_to_human_size_converter.rb | 2 +- .../number_helper/number_to_phone_converter.rb | 2 +- .../number_helper/number_to_rounded_converter.rb | 2 +- activesupport/lib/active_support/ordered_hash.rb | 2 +- .../lib/active_support/ordered_options.rb | 4 +- activesupport/lib/active_support/subscriber.rb | 2 +- .../lib/active_support/testing/declarative.rb | 2 +- .../lib/active_support/values/time_zone.rb | 12 +- activesupport/lib/active_support/xml_mini.rb | 2 +- activesupport/lib/active_support/xml_mini/jdom.rb | 2 +- .../lib/active_support/xml_mini/libxml.rb | 2 +- .../lib/active_support/xml_mini/nokogiri.rb | 2 +- activesupport/lib/active_support/xml_mini/rexml.rb | 2 +- activesupport/test/broadcast_logger_test.rb | 2 +- activesupport/test/caching_test.rb | 6 +- activesupport/test/callbacks_test.rb | 6 +- activesupport/test/core_ext/array/grouping_test.rb | 2 +- .../test/core_ext/date_and_time_behavior.rb | 296 +++++----- .../core_ext/date_and_time_compatibility_test.rb | 4 +- activesupport/test/core_ext/date_ext_test.rb | 142 ++--- activesupport/test/core_ext/date_time_ext_test.rb | 200 +++---- activesupport/test/core_ext/duration_test.rb | 18 +- activesupport/test/core_ext/enumerable_test.rb | 20 +- activesupport/test/core_ext/hash_ext_test.rb | 24 +- activesupport/test/core_ext/module_test.rb | 4 +- activesupport/test/core_ext/numeric_ext_test.rb | 64 +-- .../test/core_ext/object/duplicable_test.rb | 2 +- .../test/core_ext/object/inclusion_test.rb | 6 +- activesupport/test/core_ext/range_ext_test.rb | 6 +- activesupport/test/core_ext/time_ext_test.rb | 604 ++++++++++----------- activesupport/test/core_ext/time_with_zone_test.rb | 194 +++---- activesupport/test/dependencies_test.rb | 10 +- activesupport/test/deprecation_test.rb | 6 +- activesupport/test/gzip_test.rb | 2 +- activesupport/test/inflector_test_cases.rb | 2 +- activesupport/test/json/decoding_test.rb | 18 +- activesupport/test/json/encoding_test.rb | 22 +- activesupport/test/json/encoding_test_cases.rb | 20 +- activesupport/test/message_encryptor_test.rb | 2 +- activesupport/test/multibyte_chars_test.rb | 12 +- activesupport/test/multibyte_test_helpers.rb | 2 +- .../notifications/evented_notification_test.rb | 2 +- .../test/notifications/instrumenter_test.rb | 4 +- activesupport/test/number_helper_test.rb | 58 +- activesupport/test/ordered_hash_test.rb | 6 +- activesupport/test/safe_buffer_test.rb | 2 +- activesupport/test/time_zone_test.rb | 96 ++-- activesupport/test/xml_mini_test.rb | 56 +- ci/travis.rb | 2 +- .../active_record_migrations_gem.rb | 2 +- .../active_record_migrations_master.rb | 2 +- guides/bug_report_templates/benchmark.rb | 4 +- guides/rails_guides/generator.rb | 2 +- guides/rails_guides/helpers.rb | 2 +- guides/rails_guides/indexer.rb | 2 +- guides/rails_guides/kindle.rb | 4 +- guides/rails_guides/levenshtein.rb | 4 +- guides/rails_guides/markdown/renderer.rb | 2 +- guides/w3c_validator.rb | 2 +- railties/lib/rails/application.rb | 4 +- railties/lib/rails/code_statistics.rb | 2 +- railties/lib/rails/command/behavior.rb | 4 +- railties/lib/rails/configuration.rb | 4 +- railties/lib/rails/console/app.rb | 4 +- railties/lib/rails/engine.rb | 10 +- railties/lib/rails/engine/configuration.rb | 2 +- railties/lib/rails/generators.rb | 4 +- railties/lib/rails/generators/actions.rb | 20 +- railties/lib/rails/generators/active_model.rb | 6 +- railties/lib/rails/generators/base.rb | 10 +- .../lib/rails/generators/generated_attribute.rb | 4 +- railties/lib/rails/generators/migration.rb | 2 +- railties/lib/rails/generators/named_base.rb | 2 +- .../rails/generators/rails/app/app_generator.rb | 2 +- .../generators/rails/plugin/plugin_generator.rb | 4 +- railties/lib/rails/generators/resource_helpers.rb | 2 +- railties/lib/rails/initializable.rb | 2 +- railties/lib/rails/source_annotation_extractor.rb | 6 +- railties/test/app_loader_test.rb | 2 +- railties/test/application/assets_test.rb | 4 +- railties/test/application/configuration_test.rb | 6 +- .../application/initializers/frameworks_test.rb | 2 +- .../test/application/initializers/hooks_test.rb | 4 +- railties/test/application/test_runner_test.rb | 12 +- railties/test/code_statistics_calculator_test.rb | 2 +- railties/test/commands/dbconsole_test.rb | 18 +- railties/test/generators/generator_test.rb | 2 +- railties/test/generators/model_generator_test.rb | 16 +- .../test/generators/plugin_test_runner_test.rb | 2 +- railties/test/generators/shared_generator_tests.rb | 2 +- railties/test/isolation/abstract_unit.rb | 2 +- railties/test/path_generation_test.rb | 2 +- railties/test/railties/engine_test.rb | 4 +- railties/test/railties/generators_test.rb | 2 +- tools/profile | 2 +- 380 files changed, 2098 insertions(+), 2077 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 985a036556..e1102b45ce 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -50,6 +50,24 @@ Style/IndentationConsistency: Style/IndentationWidth: Enabled: true +Style/SpaceAfterColon: + Enabled: true + +Style/SpaceAfterComma: + Enabled: true + +Style/SpaceAroundEqualsInParameterDefault: + Enabled: true + +Style/SpaceAroundKeyword: + Enabled: true + +Style/SpaceAroundOperators: + Enabled: true + +Style/SpaceBeforeFirstArg: + Enabled: true + # Defining a method with parameters needs parentheses. Style/MethodDefParentheses: Enabled: true @@ -66,6 +84,9 @@ Style/SpaceInsideBlockBraces: Style/SpaceInsideHashLiteralBraces: Enabled: true +Style/SpaceInsideParens: + Enabled: true + # Check quotes usage according to lint rule below. Style/StringLiterals: Enabled: true diff --git a/actioncable/lib/action_cable/channel/naming.rb b/actioncable/lib/action_cable/channel/naming.rb index b7e88bf73d..b565cb3cac 100644 --- a/actioncable/lib/action_cable/channel/naming.rb +++ b/actioncable/lib/action_cable/channel/naming.rb @@ -12,7 +12,7 @@ module ActionCable # Chats::AppearancesChannel.channel_name # => 'chats:appearances' # FooChats::BarAppearancesChannel.channel_name # => 'foo_chats:bar_appearances' def channel_name - @channel_name ||= name.sub(/Channel$/, "").gsub("::",":").underscore + @channel_name ||= name.sub(/Channel$/, "").gsub("::", ":").underscore end end diff --git a/actioncable/lib/action_cable/engine.rb b/actioncable/lib/action_cable/engine.rb index 4c5c975cd8..e23527b84e 100644 --- a/actioncable/lib/action_cable/engine.rb +++ b/actioncable/lib/action_cable/engine.rb @@ -34,7 +34,7 @@ module ActionCable previous_connection_class = self.connection_class self.connection_class = -> { "ApplicationCable::Connection".safe_constantize || previous_connection_class.call } - options.each { |k,v| send("#{k}=", v) } + options.each { |k, v| send("#{k}=", v) } end end diff --git a/actioncable/lib/action_cable/remote_connections.rb b/actioncable/lib/action_cable/remote_connections.rb index 720ba52d19..d2856bc6ae 100644 --- a/actioncable/lib/action_cable/remote_connections.rb +++ b/actioncable/lib/action_cable/remote_connections.rb @@ -54,7 +54,7 @@ module ActionCable def set_identifier_instance_vars(ids) raise InvalidIdentifiersError unless valid_identifiers?(ids) - ids.each { |k,v| instance_variable_set("@#{k}", v) } + ids.each { |k, v| instance_variable_set("@#{k}", v) } end def valid_identifiers?(ids) diff --git a/actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb b/actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb index 4ec513e3ba..4cce86dcca 100644 --- a/actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb +++ b/actioncable/lib/action_cable/subscription_adapter/subscriber_map.rb @@ -2,7 +2,7 @@ module ActionCable module SubscriptionAdapter class SubscriberMap def initialize - @subscribers = Hash.new { |h,k| h[k] = [] } + @subscribers = Hash.new { |h, k| h[k] = [] } @sync = Mutex.new end diff --git a/actioncable/test/channel/periodic_timers_test.rb b/actioncable/test/channel/periodic_timers_test.rb index 2ee711fd29..0cc4992ef6 100644 --- a/actioncable/test/channel/periodic_timers_test.rb +++ b/actioncable/test/channel/periodic_timers_test.rb @@ -32,7 +32,7 @@ class ActionCable::Channel::PeriodicTimersTest < ActiveSupport::TestCase timers.each_with_index do |timer, i| assert_kind_of Proc, timer[0] - assert_equal i+1, timer[1][:every] + assert_equal i + 1, timer[1][:every] end end diff --git a/actioncable/test/client_test.rb b/actioncable/test/client_test.rb index db10a7ad16..98a114a5f4 100644 --- a/actioncable/test/client_test.rb +++ b/actioncable/test/client_test.rb @@ -186,9 +186,9 @@ class ClientTest < ActionCable::TestCase c = websocket_client(port) assert_equal({ "type" => "welcome" }, c.read_message) # pop the first welcome message off the stack c.send_message command: "subscribe", identifier: JSON.generate(channel: "ClientTest::EchoChannel") - assert_equal({ "identifier"=>"{\"channel\":\"ClientTest::EchoChannel\"}", "type"=>"confirm_subscription" }, c.read_message) + assert_equal({ "identifier" => "{\"channel\":\"ClientTest::EchoChannel\"}", "type" => "confirm_subscription" }, c.read_message) c.send_message command: "message", identifier: JSON.generate(channel: "ClientTest::EchoChannel"), data: JSON.generate(action: "ding", message: "hello") - assert_equal({ "identifier"=>"{\"channel\":\"ClientTest::EchoChannel\"}", "message"=>{ "dong"=>"hello" } }, c.read_message) + assert_equal({ "identifier" => "{\"channel\":\"ClientTest::EchoChannel\"}", "message" => { "dong" => "hello" } }, c.read_message) c.close end end @@ -203,9 +203,9 @@ class ClientTest < ActionCable::TestCase concurrently(clients) do |c| assert_equal({ "type" => "welcome" }, c.read_message) # pop the first welcome message off the stack c.send_message command: "subscribe", identifier: JSON.generate(channel: "ClientTest::EchoChannel") - assert_equal({ "identifier"=>'{"channel":"ClientTest::EchoChannel"}', "type"=>"confirm_subscription" }, c.read_message) + assert_equal({ "identifier" => '{"channel":"ClientTest::EchoChannel"}', "type" => "confirm_subscription" }, c.read_message) c.send_message command: "message", identifier: JSON.generate(channel: "ClientTest::EchoChannel"), data: JSON.generate(action: "ding", message: "hello") - assert_equal({ "identifier"=>'{"channel":"ClientTest::EchoChannel"}', "message"=>{ "dong"=>"hello" } }, c.read_message) + assert_equal({ "identifier" => '{"channel":"ClientTest::EchoChannel"}', "message" => { "dong" => "hello" } }, c.read_message) barrier_1.wait WAIT_WHEN_EXPECTING_EVENT c.send_message command: "message", identifier: JSON.generate(channel: "ClientTest::EchoChannel"), data: JSON.generate(action: "bulk", message: "hello") barrier_2.wait WAIT_WHEN_EXPECTING_EVENT @@ -223,9 +223,9 @@ class ClientTest < ActionCable::TestCase concurrently(clients) do |c| assert_equal({ "type" => "welcome" }, c.read_message) # pop the first welcome message off the stack c.send_message command: "subscribe", identifier: JSON.generate(channel: "ClientTest::EchoChannel") - assert_equal({ "identifier"=>'{"channel":"ClientTest::EchoChannel"}', "type"=>"confirm_subscription" }, c.read_message) + assert_equal({ "identifier" => '{"channel":"ClientTest::EchoChannel"}', "type" => "confirm_subscription" }, c.read_message) c.send_message command: "message", identifier: JSON.generate(channel: "ClientTest::EchoChannel"), data: JSON.generate(action: "ding", message: "hello") - assert_equal({ "identifier"=>'{"channel":"ClientTest::EchoChannel"}', "message"=>{ "dong"=>"hello" } }, c.read_message) + assert_equal({ "identifier" => '{"channel":"ClientTest::EchoChannel"}', "message" => { "dong" => "hello" } }, c.read_message) end concurrently(clients, &:close) @@ -237,16 +237,16 @@ class ClientTest < ActionCable::TestCase c = websocket_client(port) assert_equal({ "type" => "welcome" }, c.read_message) # pop the first welcome message off the stack c.send_message command: "subscribe", identifier: JSON.generate(channel: "ClientTest::EchoChannel") - assert_equal({ "identifier"=>"{\"channel\":\"ClientTest::EchoChannel\"}", "type"=>"confirm_subscription" }, c.read_message) + assert_equal({ "identifier" => "{\"channel\":\"ClientTest::EchoChannel\"}", "type" => "confirm_subscription" }, c.read_message) c.send_message command: "message", identifier: JSON.generate(channel: "ClientTest::EchoChannel"), data: JSON.generate(action: "delay", message: "hello") c.close # disappear before write c = websocket_client(port) assert_equal({ "type" => "welcome" }, c.read_message) # pop the first welcome message off the stack c.send_message command: "subscribe", identifier: JSON.generate(channel: "ClientTest::EchoChannel") - assert_equal({ "identifier"=>"{\"channel\":\"ClientTest::EchoChannel\"}", "type"=>"confirm_subscription" }, c.read_message) + assert_equal({ "identifier" => "{\"channel\":\"ClientTest::EchoChannel\"}", "type" => "confirm_subscription" }, c.read_message) c.send_message command: "message", identifier: JSON.generate(channel: "ClientTest::EchoChannel"), data: JSON.generate(action: "ding", message: "hello") - assert_equal({ "identifier"=>'{"channel":"ClientTest::EchoChannel"}', "message"=>{ "dong"=>"hello" } }, c.read_message) + assert_equal({ "identifier" => '{"channel":"ClientTest::EchoChannel"}', "message" => { "dong" => "hello" } }, c.read_message) c.close # disappear before read end end @@ -259,7 +259,7 @@ class ClientTest < ActionCable::TestCase c = websocket_client(port) assert_equal({ "type" => "welcome" }, c.read_message) c.send_message command: "subscribe", identifier: identifier - assert_equal({ "identifier"=>"{\"channel\":\"ClientTest::EchoChannel\"}", "type"=>"confirm_subscription" }, c.read_message) + assert_equal({ "identifier" => "{\"channel\":\"ClientTest::EchoChannel\"}", "type" => "confirm_subscription" }, c.read_message) assert_equal(1, app.connections.count) assert(app.remote_connections.where(identifier: identifier)) @@ -280,7 +280,7 @@ class ClientTest < ActionCable::TestCase c = websocket_client(port) assert_equal({ "type" => "welcome" }, c.read_message) c.send_message command: "subscribe", identifier: JSON.generate(channel: "ClientTest::EchoChannel") - assert_equal({ "identifier"=>"{\"channel\":\"ClientTest::EchoChannel\"}", "type"=>"confirm_subscription" }, c.read_message) + assert_equal({ "identifier" => "{\"channel\":\"ClientTest::EchoChannel\"}", "type" => "confirm_subscription" }, c.read_message) ActionCable.server.restart c.wait_for_close diff --git a/actioncable/test/stubs/room.rb b/actioncable/test/stubs/room.rb index 9e521cf3a6..1664b07d12 100644 --- a/actioncable/test/stubs/room.rb +++ b/actioncable/test/stubs/room.rb @@ -1,7 +1,7 @@ class Room attr_reader :id, :name - def initialize(id, name="Campfire") + def initialize(id, name = "Campfire") @id = id @name = name end diff --git a/actioncable/test/worker_test.rb b/actioncable/test/worker_test.rb index 63dc453840..3385593f74 100644 --- a/actioncable/test/worker_test.rb +++ b/actioncable/test/worker_test.rb @@ -9,7 +9,7 @@ class WorkerTest < ActiveSupport::TestCase end def process(message) - @last_action = [ :process, message ] + @last_action = [ :process, message ] end def connection diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index e9966c7ff5..1f5738bbab 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -601,7 +601,7 @@ module ActionMailer def body; "" end def header; {} end - def respond_to?(string, include_all=false) + def respond_to?(string, include_all = false) true end @@ -933,7 +933,7 @@ module ActionMailer def create_parts_from_responses(m, responses) if responses.size == 1 && !m.has_attachments? - responses[0].each { |k,v| m[k] = v } + responses[0].each { |k, v| m[k] = v } elsif responses.size > 1 && m.has_attachments? container = Mail::Part.new container.content_type = "multipart/alternative" diff --git a/actionmailer/lib/action_mailer/delivery_methods.rb b/actionmailer/lib/action_mailer/delivery_methods.rb index 6be2c91da6..be98f4c65e 100644 --- a/actionmailer/lib/action_mailer/delivery_methods.rb +++ b/actionmailer/lib/action_mailer/delivery_methods.rb @@ -52,13 +52,13 @@ module ActionMailer # add_delivery_method :sendmail, Mail::Sendmail, # location: '/usr/sbin/sendmail', # arguments: '-i' - def add_delivery_method(symbol, klass, default_options={}) + def add_delivery_method(symbol, klass, default_options = {}) class_attribute(:"#{symbol}_settings") unless respond_to?(:"#{symbol}_settings") send(:"#{symbol}_settings=", default_options) self.delivery_methods = delivery_methods.merge(symbol.to_sym => klass).freeze end - def wrap_delivery_behavior(mail, method=nil, options=nil) # :nodoc: + def wrap_delivery_behavior(mail, method = nil, options = nil) # :nodoc: method ||= self.delivery_method mail.delivery_handler = self diff --git a/actionmailer/lib/action_mailer/inline_preview_interceptor.rb b/actionmailer/lib/action_mailer/inline_preview_interceptor.rb index b7318f0092..9087d335fa 100644 --- a/actionmailer/lib/action_mailer/inline_preview_interceptor.rb +++ b/actionmailer/lib/action_mailer/inline_preview_interceptor.rb @@ -11,7 +11,7 @@ module ActionMailer # ActionMailer::Base.preview_interceptors.delete(ActionMailer::InlinePreviewInterceptor) # class InlinePreviewInterceptor - PATTERN = /src=(?:"cid:[^"]+"|'cid:[^']+')/i + PATTERN = /src=(?:"cid:[^"]+"|'cid:[^']+')/i include Base64 diff --git a/actionmailer/lib/action_mailer/message_delivery.rb b/actionmailer/lib/action_mailer/message_delivery.rb index 994d297768..cf7c57e6bf 100644 --- a/actionmailer/lib/action_mailer/message_delivery.rb +++ b/actionmailer/lib/action_mailer/message_delivery.rb @@ -56,7 +56,7 @@ module ActionMailer # * :wait - Enqueue the email to be delivered with a delay # * :wait_until - Enqueue the email to be delivered at (after) a specific date / time # * :queue - Enqueue the email on the specified queue - def deliver_later!(options={}) + def deliver_later!(options = {}) enqueue_delivery :deliver_now!, options end @@ -72,7 +72,7 @@ module ActionMailer # * :wait - Enqueue the email to be delivered with a delay. # * :wait_until - Enqueue the email to be delivered at (after) a specific date / time. # * :queue - Enqueue the email on the specified queue. - def deliver_later(options={}) + def deliver_later(options = {}) enqueue_delivery :deliver_now, options end @@ -106,7 +106,7 @@ module ActionMailer end end - def enqueue_delivery(delivery_method, options={}) + def enqueue_delivery(delivery_method, options = {}) if processed? ::Kernel.raise "You've accessed the message before asking to " \ "deliver it later, so you may have made local changes that would " \ diff --git a/actionmailer/lib/action_mailer/railtie.rb b/actionmailer/lib/action_mailer/railtie.rb index c47d7781cc..913df8cf93 100644 --- a/actionmailer/lib/action_mailer/railtie.rb +++ b/actionmailer/lib/action_mailer/railtie.rb @@ -28,7 +28,7 @@ module ActionMailer options.cache_store ||= Rails.cache if options.show_previews - options.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/test/mailers/previews" : nil + options.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/test/mailers/previews" : nil end # make sure readers methods get compiled @@ -44,7 +44,7 @@ module ActionMailer register_preview_interceptors(options.delete(:preview_interceptors)) register_observers(options.delete(:observers)) - options.each { |k,v| send("#{k}=", v) } + options.each { |k, v| send("#{k}=", v) } end ActiveSupport.on_load(:action_dispatch_integration_test) { include ActionMailer::TestCase::ClearTestDeliveries } diff --git a/actionmailer/test/delivery_methods_test.rb b/actionmailer/test/delivery_methods_test.rb index 898d32c1e2..f64a69019f 100644 --- a/actionmailer/test/delivery_methods_test.rb +++ b/actionmailer/test/delivery_methods_test.rb @@ -87,7 +87,7 @@ class MailDeliveryTest < ActiveSupport::TestCase from: "jose@test.plataformatec.com" } - def welcome(hash={}) + def welcome(hash = {}) mail(DEFAULT_HEADERS.merge(hash)) end end diff --git a/actionmailer/test/mailers/base_mailer.rb b/actionmailer/test/mailers/base_mailer.rb index 0d45376070..2a8884959c 100644 --- a/actionmailer/test/mailers/base_mailer.rb +++ b/actionmailer/test/mailers/base_mailer.rb @@ -100,18 +100,18 @@ class BaseMailer < ActionMailer::Base end end - def implicit_different_template(template_name="") + def implicit_different_template(template_name = "") mail(template_name: template_name) end - def explicit_different_template(template_name="") + def explicit_different_template(template_name = "") mail do |format| format.text { render template: "#{mailer_name}/#{template_name}" } format.html { render template: "#{mailer_name}/#{template_name}" } end end - def different_layout(layout_name="") + def different_layout(layout_name = "") mail do |format| format.text { render layout: layout_name } format.html { render layout: layout_name } diff --git a/actionmailer/test/message_delivery_test.rb b/actionmailer/test/message_delivery_test.rb index 0eb81a8496..a79d77e1e5 100644 --- a/actionmailer/test/message_delivery_test.rb +++ b/actionmailer/test/message_delivery_test.rb @@ -76,7 +76,7 @@ class MessageDeliveryTest < ActiveSupport::TestCase test "should enqueue a delivery with a delay" do travel_to Time.new(2004, 11, 24, 01, 04, 44) do - assert_performed_with(job: ActionMailer::DeliveryJob, at: Time.current.to_f+600.seconds, args: ["DelayedMailer", "test_message", "deliver_now", 1, 2, 3]) do + assert_performed_with(job: ActionMailer::DeliveryJob, at: Time.current.to_f + 600.seconds, args: ["DelayedMailer", "test_message", "deliver_now", 1, 2, 3]) do @mail.deliver_later wait: 600.seconds end end diff --git a/actionmailer/test/url_test.rb b/actionmailer/test/url_test.rb index 27f6e8a491..6dbfb3a1ff 100644 --- a/actionmailer/test/url_test.rb +++ b/actionmailer/test/url_test.rb @@ -50,11 +50,11 @@ class ActionMailerUrlTest < ActionMailer::TestCase end end - def encode( text, charset="UTF-8" ) - quoted_printable( text, charset ) + def encode(text, charset = "UTF-8") + quoted_printable(text, charset) end - def new_mail( charset="UTF-8" ) + def new_mail(charset = "UTF-8") mail = Mail.new mail.mime_version = "1.0" if charset @@ -81,7 +81,7 @@ class ActionMailerUrlTest < ActionMailer::TestCase AppRoutes.draw do ActiveSupport::Deprecation.silence do get ":controller(/:action(/:id))" - get "/welcome" => "foo#bar", as: "welcome" + get "/welcome" => "foo#bar", as: "welcome" get "/dummy_model" => "foo#baz", as: "dummy_model" end end diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index a0560a8748..d339580435 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -78,7 +78,7 @@ module AbstractController # render :action => "foo" and render "foo/bar" to # render :file => "foo/bar". # :api: plugin - def _normalize_args(action=nil, options={}) + def _normalize_args(action = nil, options = {}) if action.respond_to?(:permitted?) if action.permitted? action diff --git a/actionpack/lib/action_controller/metal/conditional_get.rb b/actionpack/lib/action_controller/metal/conditional_get.rb index 89bf60a0bb..eb636fa3f6 100644 --- a/actionpack/lib/action_controller/metal/conditional_get.rb +++ b/actionpack/lib/action_controller/metal/conditional_get.rb @@ -238,7 +238,7 @@ module ActionController ) options.delete(:private) - response.cache_control[:extras] = options.map { |k,v| "#{k}=#{v}" } + response.cache_control[:extras] = options.map { |k, v| "#{k}=#{v}" } response.date = Time.now unless response.date? end diff --git a/actionpack/lib/action_controller/metal/exceptions.rb b/actionpack/lib/action_controller/metal/exceptions.rb index 3761e6172b..175dd9eb9e 100644 --- a/actionpack/lib/action_controller/metal/exceptions.rb +++ b/actionpack/lib/action_controller/metal/exceptions.rb @@ -14,7 +14,7 @@ module ActionController class RoutingError < ActionControllerError #:nodoc: attr_reader :failures - def initialize(message, failures=[]) + def initialize(message, failures = []) super(message) @failures = failures end diff --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb index a335bf109e..5bf0a99fe4 100644 --- a/actionpack/lib/action_controller/metal/http_authentication.rb +++ b/actionpack/lib/action_controller/metal/http_authentication.rb @@ -224,7 +224,7 @@ module ActionController # Returns the expected response for a request of +http_method+ to +uri+ with the decoded +credentials+ and the expected +password+ # Optional parameter +password_is_ha1+ is set to +true+ by default, since best practice is to store ha1 digest instead # of a plain-text password. - def expected_response(http_method, uri, credentials, password, password_is_ha1=true) + def expected_response(http_method, uri, credentials, password, password_is_ha1 = true) ha1 = password_is_ha1 ? password : ha1(credentials, password) ha2 = ::Digest::MD5.hexdigest([http_method.to_s.upcase, uri].join(":")) ::Digest::MD5.hexdigest([ha1, credentials[:nonce], credentials[:nc], credentials[:cnonce], credentials[:qop], ha2].join(":")) @@ -246,7 +246,7 @@ module ActionController def decode_credentials(header) ActiveSupport::HashWithIndifferentAccess[header.to_s.gsub(/^Digest\s+/, "").split(",").map do |pair| key, value = pair.split("=", 2) - [key.strip, value.to_s.gsub(/^"|"$/,"").delete('\'')] + [key.strip, value.to_s.gsub(/^"|"$/, "").delete('\'')] end] end @@ -314,7 +314,7 @@ module ActionController # Can be much shorter if the Stale directive is implemented. This would # allow a user to use new nonce without prompting the user again for their # username and password. - def validate_nonce(secret_key, request, value, seconds_to_timeout=5*60) + def validate_nonce(secret_key, request, value, seconds_to_timeout = 5 * 60) return false if value.nil? t = ::Base64.decode64(value).split(":").first.to_i nonce(secret_key, t) == value && (t - Time.now.to_i).abs <= seconds_to_timeout diff --git a/actionpack/lib/action_controller/metal/instrumentation.rb b/actionpack/lib/action_controller/metal/instrumentation.rb index 2ede96c667..f83396ae55 100644 --- a/actionpack/lib/action_controller/metal/instrumentation.rb +++ b/actionpack/lib/action_controller/metal/instrumentation.rb @@ -46,7 +46,7 @@ module ActionController render_output end - def send_file(path, options={}) + def send_file(path, options = {}) ActiveSupport::Notifications.instrument("send_file.action_controller", options.merge(path: path)) do super diff --git a/actionpack/lib/action_controller/metal/live.rb b/actionpack/lib/action_controller/metal/live.rb index 26a16104db..fed99e6c82 100644 --- a/actionpack/lib/action_controller/metal/live.rb +++ b/actionpack/lib/action_controller/metal/live.rb @@ -247,7 +247,7 @@ module ActionController # Since we're processing the view in a different thread, copy the # thread locals from the main thread to the child thread. :'( - locals.each { |k,v| t2[k] = v } + locals.each { |k, v| t2[k] = v } begin super(name) diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index 9d1b740025..86e817fe16 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -205,7 +205,7 @@ module ActionController model = name_or_model_or_options end - opts = Options.from_hash _wrapper_options.to_h.slice(:format).merge(options) + opts = Options.from_hash _wrapper_options.to_h.slice(:format).merge(options) opts.model = model opts.klass = self diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb index 67365a143e..e971917ca2 100644 --- a/actionpack/lib/action_controller/metal/rendering.rb +++ b/actionpack/lib/action_controller/metal/rendering.rb @@ -73,7 +73,7 @@ module ActionController end # Normalize arguments by catching blocks and setting them on :update. - def _normalize_args(action=nil, options={}, &blk) #:nodoc: + def _normalize_args(action = nil, options = {}, &blk) #:nodoc: options = super options[:update] = blk if block_given? options diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index b64617d084..9c82abb640 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -680,7 +680,7 @@ module ActionController when Parameters if object.fields_for_style? hash = object.class.new - object.each { |k,v| hash[k] = yield v } + object.each { |k, v| hash[k] = yield v } hash else yield object diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index 6513a556ee..a7cdfe6a98 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -51,7 +51,7 @@ module ActionController extend ::AbstractController::Railties::RoutesHelpers.with(app.routes) extend ::ActionController::Railties::Helpers - options.each do |k,v| + options.each do |k, v| k = "#{k}=" if respond_to?(k) send(k, v) diff --git a/actionpack/lib/action_controller/renderer.rb b/actionpack/lib/action_controller/renderer.rb index 243a54330e..3ff80e6a39 100644 --- a/actionpack/lib/action_controller/renderer.rb +++ b/actionpack/lib/action_controller/renderer.rb @@ -83,7 +83,7 @@ module ActionController private def normalize_keys(env) new_env = {} - env.each_pair { |k,v| new_env[rack_key_for(k)] = rack_value_for(k, v) } + env.each_pair { |k, v| new_env[rack_key_for(k)] = rack_value_for(k, v) } new_env end diff --git a/actionpack/lib/action_dispatch/http/parameter_filter.rb b/actionpack/lib/action_dispatch/http/parameter_filter.rb index 01fe35f5c6..889f55a52a 100644 --- a/actionpack/lib/action_dispatch/http/parameter_filter.rb +++ b/actionpack/lib/action_dispatch/http/parameter_filter.rb @@ -50,7 +50,7 @@ module ActionDispatch def initialize(regexps, deep_regexps, blocks) @regexps = regexps @deep_regexps = deep_regexps.any? ? deep_regexps : nil - @blocks = blocks + @blocks = blocks end def call(original_params, parents = []) diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index e8173e2a99..803ac52605 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -39,7 +39,7 @@ module ActionDispatch # :nodoc: super(header) end - def []=(k,v) + def []=(k, v) if @response.sending? || @response.sent? raise ActionDispatch::IllegalStateError, "header already sent" end diff --git a/actionpack/lib/action_dispatch/http/upload.rb b/actionpack/lib/action_dispatch/http/upload.rb index 9aa73c862b..61ba052e45 100644 --- a/actionpack/lib/action_dispatch/http/upload.rb +++ b/actionpack/lib/action_dispatch/http/upload.rb @@ -24,7 +24,7 @@ module ActionDispatch attr_accessor :headers def initialize(hash) # :nodoc: - @tempfile = hash[:tempfile] + @tempfile = hash[:tempfile] raise(ArgumentError, ":tempfile is required") unless @tempfile @original_filename = hash[:filename] @@ -40,7 +40,7 @@ module ActionDispatch end # Shortcut for +tempfile.read+. - def read(length=nil, buffer=nil) + def read(length = nil, buffer = nil) @tempfile.read(length, buffer) end @@ -50,7 +50,7 @@ module ActionDispatch end # Shortcut for +tempfile.close+. - def close(unlink_now=false) + def close(unlink_now = false) @tempfile.close(unlink_now) end diff --git a/actionpack/lib/action_dispatch/http/url.rb b/actionpack/lib/action_dispatch/http/url.rb index 06ffa983d1..a6937d54ff 100644 --- a/actionpack/lib/action_dispatch/http/url.rb +++ b/actionpack/lib/action_dispatch/http/url.rb @@ -66,7 +66,7 @@ module ActionDispatch end def path_for(options) - path = options[:script_name].to_s.chomp("/".freeze) + path = options[:script_name].to_s.chomp("/".freeze) path << options[:path] if options.key?(:path) add_trailing_slash(path) if options[:trailing_slash] @@ -80,7 +80,7 @@ module ActionDispatch def add_params(path, params) params = { params: params } unless params.is_a?(Hash) - params.reject! { |_,v| v.to_param.nil? } + params.reject! { |_, v| v.to_param.nil? } query = params.to_query path << "?#{query}" unless query.empty? end diff --git a/actionpack/lib/action_dispatch/journey/formatter.rb b/actionpack/lib/action_dispatch/journey/formatter.rb index b5a8ca7262..20ff4441a0 100644 --- a/actionpack/lib/action_dispatch/journey/formatter.rb +++ b/actionpack/lib/action_dispatch/journey/formatter.rb @@ -48,7 +48,7 @@ module ActionDispatch unmatched_keys = (missing_keys || []) & constraints.keys missing_keys = (missing_keys || []) - unmatched_keys - message = "No route matches #{Hash[constraints.sort_by { |k,v| k.to_s }].inspect}" + message = "No route matches #{Hash[constraints.sort_by { |k, v| k.to_s }].inspect}" message << ", missing required keys: #{missing_keys.sort.inspect}" if missing_keys && !missing_keys.empty? message << ", possible unmatched constraints: #{unmatched_keys.sort.inspect}" if unmatched_keys && !unmatched_keys.empty? diff --git a/actionpack/lib/action_dispatch/journey/gtg/builder.rb b/actionpack/lib/action_dispatch/journey/gtg/builder.rb index 9990c66627..0f8bed89bf 100644 --- a/actionpack/lib/action_dispatch/journey/gtg/builder.rb +++ b/actionpack/lib/action_dispatch/journey/gtg/builder.rb @@ -17,7 +17,7 @@ module ActionDispatch def transition_table dtrans = TransitionTable.new marked = {} - state_id = Hash.new { |h,k| h[k] = h.length } + state_id = Hash.new { |h, k| h[k] = h.length } start = firstpos(root) dstates = [start] diff --git a/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb b/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb index 0be18dc26f..beb9f1ef3b 100644 --- a/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb +++ b/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb @@ -12,7 +12,7 @@ module ActionDispatch @regexp_states = {} @string_states = {} @accepting = {} - @memos = Hash.new { |h,k| h[k] = [] } + @memos = Hash.new { |h, k| h[k] = [] } end def add_accepting(state) @@ -56,7 +56,7 @@ module ActionDispatch end def as_json(options = nil) - simple_regexp = Hash.new { |h,k| h[k] = {} } + simple_regexp = Hash.new { |h, k| h[k] = {} } @regexp_states.each do |from, hash| hash.each do |re, to| diff --git a/actionpack/lib/action_dispatch/journey/nfa/builder.rb b/actionpack/lib/action_dispatch/journey/nfa/builder.rb index 19e5752ae5..532f765094 100644 --- a/actionpack/lib/action_dispatch/journey/nfa/builder.rb +++ b/actionpack/lib/action_dispatch/journey/nfa/builder.rb @@ -36,7 +36,7 @@ module ActionDispatch def visit_OR(node) from = @i += 1 children = node.children.map { |c| visit(c) } - to = @i += 1 + to = @i += 1 children.each do |child| @tt[from, child.first] = nil diff --git a/actionpack/lib/action_dispatch/journey/nfa/transition_table.rb b/actionpack/lib/action_dispatch/journey/nfa/transition_table.rb index 4737adc724..543a670da0 100644 --- a/actionpack/lib/action_dispatch/journey/nfa/transition_table.rb +++ b/actionpack/lib/action_dispatch/journey/nfa/transition_table.rb @@ -10,7 +10,7 @@ module ActionDispatch attr_reader :memos def initialize - @table = Hash.new { |h,f| h[f] = {} } + @table = Hash.new { |h, f| h[f] = {} } @memos = {} @accepting = nil @inverted = nil diff --git a/actionpack/lib/action_dispatch/journey/route.rb b/actionpack/lib/action_dispatch/journey/route.rb index 79cd010d64..0cc8d83ac8 100644 --- a/actionpack/lib/action_dispatch/journey/route.rb +++ b/actionpack/lib/action_dispatch/journey/route.rb @@ -83,7 +83,7 @@ module ActionDispatch def requirements # needed for rails `rails routes` - @defaults.merge(path.requirements).delete_if { |_,v| + @defaults.merge(path.requirements).delete_if { |_, v| /.+?/ == v } end @@ -98,7 +98,7 @@ module ActionDispatch def score(constraints) required_keys = path.required_names - supplied_keys = constraints.map { |k,v| v && k.to_s }.compact + supplied_keys = constraints.map { |k, v| v && k.to_s }.compact return -1 unless (required_keys - supplied_keys).empty? @@ -124,7 +124,7 @@ module ActionDispatch end def required_defaults - @required_defaults ||= @defaults.dup.delete_if do |k,_| + @required_defaults ||= @defaults.dup.delete_if do |k, _| parts.include?(k) || !required_default?(k) end end diff --git a/actionpack/lib/action_dispatch/journey/router.rb b/actionpack/lib/action_dispatch/journey/router.rb index d0ef549335..084ae9325e 100644 --- a/actionpack/lib/action_dispatch/journey/router.rb +++ b/actionpack/lib/action_dispatch/journey/router.rb @@ -109,9 +109,9 @@ module ActionDispatch routes.sort_by!(&:precedence) routes.map! { |r| - match_data = r.path.match(req.path_info) + match_data = r.path.match(req.path_info) path_parameters = r.defaults.dup - match_data.names.zip(match_data.captures) { |name,val| + match_data.names.zip(match_data.captures) { |name, val| path_parameters[name.to_sym] = Utils.unescape_uri(val) if val } [match_data, path_parameters, r] diff --git a/actionpack/lib/action_dispatch/journey/visitors.rb b/actionpack/lib/action_dispatch/journey/visitors.rb index 74f3c0617a..cda859cba4 100644 --- a/actionpack/lib/action_dispatch/journey/visitors.rb +++ b/actionpack/lib/action_dispatch/journey/visitors.rb @@ -22,7 +22,7 @@ module ActionDispatch @children = [] @parameters = [] - parts.each_with_index do |object,i| + parts.each_with_index do |object, i| case object when Journey::Format @children << i diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb index 6f4fab396a..4fc4df4463 100644 --- a/actionpack/lib/action_dispatch/middleware/cookies.rb +++ b/actionpack/lib/action_dispatch/middleware/cookies.rb @@ -332,13 +332,13 @@ module ActionDispatch def update_cookies_from_jar request_jar = @request.cookie_jar.instance_variable_get(:@cookies) - set_cookies = request_jar.reject { |k,_| @delete_cookies.key?(k) } + set_cookies = request_jar.reject { |k, _| @delete_cookies.key?(k) } @cookies.update set_cookies if set_cookies end def to_header - @cookies.map { |k,v| "#{escape(k)}=#{escape(v)}" }.join "; " + @cookies.map { |k, v| "#{escape(k)}=#{escape(v)}" }.join "; " end def handle_options(options) #:nodoc: diff --git a/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb b/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb index 99dc37c568..397f0a8b92 100644 --- a/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb +++ b/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb @@ -127,7 +127,7 @@ module ActionDispatch File.open(full_path, "r") do |file| start = [line - 3, 0].max lines = file.each_line.drop(start).take(6) - Hash[*(start+1..(lines.count+start)).zip(lines).flatten] + Hash[*(start + 1..(lines.count + start)).zip(lines).flatten] end end end diff --git a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb index 8409109ede..57d325a9d8 100644 --- a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb @@ -63,7 +63,7 @@ module ActionDispatch # Other useful options include :key, :secure and # :httponly. class CookieStore < AbstractStore - def initialize(app, options={}) + def initialize(app, options = {}) super(app, options.merge!(cookie_only: true)) end @@ -102,7 +102,7 @@ module ActionDispatch end end - def persistent_session_id!(data, sid=nil) + def persistent_session_id!(data, sid = nil) data ||= {} data["session_id"] ||= sid || generate_sid data diff --git a/actionpack/lib/action_dispatch/request/session.rb b/actionpack/lib/action_dispatch/request/session.rb index b883ca0f61..8b98009efc 100644 --- a/actionpack/lib/action_dispatch/request/session.rb +++ b/actionpack/lib/action_dispatch/request/session.rb @@ -53,7 +53,7 @@ module ActionDispatch } end - def []=(k,v); @delegate[k] = v; end + def []=(k, v); @delegate[k] = v; end def to_hash; @delegate.dup; end def values_at(*args); @delegate.values_at(*args); end end @@ -124,7 +124,7 @@ module ActionDispatch # Returns the session as Hash. def to_hash load_for_read! - @delegate.dup.delete_if { |_,v| v.nil? } + @delegate.dup.delete_if { |_, v| v.nil? } end # Updates the session with given Hash. @@ -162,7 +162,7 @@ module ActionDispatch # :bar # end # # => :bar - def fetch(key, default=Unspecified, &block) + def fetch(key, default = Unspecified, &block) load_for_read! if default == Unspecified @delegate.fetch(key.to_s, &block) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index c412484895..b39d367f7f 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -567,7 +567,7 @@ module ActionDispatch # [:format] # Allows you to specify the default value for optional +format+ # segment or disable it by supplying +false+. - def match(path, options=nil) + def match(path, options = nil) end # Mount a Rack-based application to be used within the application. diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb index 4f1aaeefc8..432b9bf4c1 100644 --- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb @@ -160,7 +160,7 @@ module ActionDispatch CACHE = { "path" => {}, "url" => {} } def self.get(action, type) - type = type.to_s + type = type.to_s CACHE[type].fetch(action) { build action, type } end @@ -266,7 +266,7 @@ module ActionDispatch args = [] - route = record_list.map { |parent| + route = record_list.map { |parent| case parent when Symbol, String parent.to_s @@ -304,7 +304,7 @@ module ActionDispatch private def get_method_for_class(klass) - name = @key_strategy.call klass.model_name + name = @key_strategy.call klass.model_name get_method_for_string name end diff --git a/actionpack/lib/action_dispatch/routing/redirection.rb b/actionpack/lib/action_dispatch/routing/redirection.rb index 87bcceccc0..4e2318a45e 100644 --- a/actionpack/lib/action_dispatch/routing/redirection.rb +++ b/actionpack/lib/action_dispatch/routing/redirection.rb @@ -61,15 +61,15 @@ module ActionDispatch end def escape(params) - Hash[params.map { |k,v| [k, Rack::Utils.escape(v)] }] + Hash[params.map { |k, v| [k, Rack::Utils.escape(v)] }] end def escape_fragment(params) - Hash[params.map { |k,v| [k, Journey::Router::Utils.escape_fragment(v)] }] + Hash[params.map { |k, v| [k, Journey::Router::Utils.escape_fragment(v)] }] end def escape_path(params) - Hash[params.map { |k,v| [k, Journey::Router::Utils.escape_path(v)] }] + Hash[params.map { |k, v| [k, Journey::Router::Utils.escape_path(v)] }] end end @@ -128,7 +128,7 @@ module ActionDispatch end def inspect - "redirect(#{status}, #{options.map { |k,v| "#{k}: #{v}" }.join(', ')})" + "redirect(#{status}, #{options.map { |k, v| "#{k}: #{v}" }.join(', ')})" end end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 326329c65f..5853adb110 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -70,7 +70,7 @@ module ActionDispatch private :routes def initialize - @routes = {} + @routes = {} @path_helpers = Set.new @url_helpers = Set.new @url_helpers_module = Module.new @@ -207,7 +207,7 @@ module ActionDispatch params = parameterize_args(args) { |missing_key| missing_keys << missing_key } - constraints = Hash[@route.requirements.merge(params).sort_by { |k,v| k.to_s }] + constraints = Hash[@route.requirements.merge(params).sort_by { |k, v| k.to_s }] message = "No route matches #{constraints.inspect}" message << ", missing required keys: #{missing_keys.sort.inspect}" @@ -646,11 +646,11 @@ module ActionDispatch # Generate the path indicated by the arguments, and return an array of # the keys that were not used to generate it. - def extra_keys(options, recall={}) + def extra_keys(options, recall = {}) generate_extras(options, recall).last end - def generate_extras(options, recall={}) + def generate_extras(options, recall = {}) route_key = options.delete :use_route path, params = generate(route_key, options, recall) return path, params.keys @@ -692,7 +692,7 @@ module ActionDispatch password = options.delete :password end - recall = options.delete(:_recall) { {} } + recall = options.delete(:_recall) { {} } original_script_name = options.delete(:original_script_name) script_name = find_script_name options diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index a2eaccd9ef..817737341c 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -50,7 +50,7 @@ module ActionDispatch # # # Asserts that the redirection matches the regular expression # assert_redirected_to %r(\Ahttp://example.org) - def assert_redirected_to(options = {}, message=nil) + def assert_redirected_to(options = {}, message = nil) assert_response(:redirect, message) return true if options === @response.location diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index e53bc6af12..454dcb9307 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -37,7 +37,7 @@ module ActionDispatch # # # Test a custom route # assert_recognizes({controller: 'items', action: 'show', id: '1'}, 'view/item1') - def assert_recognizes(expected_options, path, extras={}, msg=nil) + def assert_recognizes(expected_options, path, extras = {}, msg = nil) if path.is_a?(Hash) && path[:method].to_s == "all" [:get, :post, :put, :delete].each do |method| assert_recognizes(expected_options, path.merge(method: method), extras, msg) @@ -75,7 +75,7 @@ module ActionDispatch # # # Asserts that the generated route gives us our custom route # assert_generates "changesets/12", { controller: 'scm', action: 'show_diff', revision: "12" } - def assert_generates(expected_path, options, defaults={}, extras={}, message=nil) + def assert_generates(expected_path, options, defaults = {}, extras = {}, message = nil) if expected_path =~ %r{://} fail_on(URI::InvalidURIError, message) do uri = URI.parse(expected_path) @@ -119,7 +119,7 @@ module ActionDispatch # # # Tests a route with an HTTP method # assert_routing({ method: 'put', path: '/product/321' }, { controller: "product", action: "update", id: "321" }) - def assert_routing(path, options, defaults={}, extras={}, message=nil) + def assert_routing(path, options, defaults = {}, extras = {}, message = nil) assert_recognizes(options, path, extras, message) controller, default_controller = options[:controller], defaults[:controller] diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index e2ea96513c..101820fbb1 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -265,7 +265,7 @@ module ActionDispatch session.request(build_full_uri(path, request_env), request_env) @request_count += 1 - @request = ActionDispatch::Request.new(session.last_request.env) + @request = ActionDispatch::Request.new(session.last_request.env) response = _mock_session.last_response @response = ActionDispatch::TestResponse.from_response(response) @response.request = @request diff --git a/actionpack/test/abstract/collector_test.rb b/actionpack/test/abstract/collector_test.rb index 7fe19e6b10..1cd3526483 100644 --- a/actionpack/test/abstract/collector_test.rb +++ b/actionpack/test/abstract/collector_test.rb @@ -55,7 +55,7 @@ module AbstractController collector.js(:bar) { :baz } assert_equal [Mime[:html], [], nil], collector.responses[0] assert_equal [Mime[:text], [:foo], nil], collector.responses[1] - assert_equal [Mime[:js], [:bar]], collector.responses[2][0,2] + assert_equal [Mime[:js], [:bar]], collector.responses[2][0, 2] assert_equal :baz, collector.responses[2][2].call end end diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 6d28753947..11a9092527 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -351,7 +351,7 @@ class ResourcesController < ActionController::Base end class CommentsController < ResourcesController; end -class AccountsController < ResourcesController; end +class AccountsController < ResourcesController; end class ImagesController < ResourcesController; end # Skips the current run on Rubinius using Minitest::Assertions#skip diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 18490c7d73..fa8d9dc09a 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -58,7 +58,7 @@ class FragmentCachingTest < ActionController::TestCase def test_fragment_cache_key assert_equal "views/what a key", @controller.fragment_cache_key("what a key") assert_equal "views/test.host/fragment_caching_test/some_action", - @controller.fragment_cache_key(controller: "fragment_caching_test",action: "some_action") + @controller.fragment_cache_key(controller: "fragment_caching_test", action: "some_action") end def test_read_fragment_with_caching_enabled diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index a34878cee8..e0fa1fbab8 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -506,20 +506,20 @@ class FilterTest < ActionController::TestCase private def filter_one - @filters ||= [] - @filters << "filter_one" + @filters ||= [] + @filters << "filter_one" end def action_two - @filters << "action_two" + @filters << "action_two" end def non_yielding_action - @filters << "it didn't yield" + @filters << "it didn't yield" end def action_three - @filters << "action_three" + @filters << "action_three" end end @@ -911,7 +911,7 @@ class ControllerWithFilterInstance < PostsController end class ControllerWithProcFilter < PostsController - around_action(only: :no_raise) do |c,b| + around_action(only: :no_raise) do |c, b| c.instance_variable_set(:"@before", true) b.call c.instance_variable_set(:"@after", true) @@ -961,34 +961,34 @@ class YieldingAroundFiltersTest < ActionController::TestCase def test_base controller = PostsController - assert_nothing_raised { test_process(controller,"no_raise") } - assert_nothing_raised { test_process(controller,"raises_before") } - assert_nothing_raised { test_process(controller,"raises_after") } - assert_nothing_raised { test_process(controller,"no_action") } + assert_nothing_raised { test_process(controller, "no_raise") } + assert_nothing_raised { test_process(controller, "raises_before") } + assert_nothing_raised { test_process(controller, "raises_after") } + assert_nothing_raised { test_process(controller, "no_action") } end def test_with_symbol controller = ControllerWithSymbolAsFilter - assert_nothing_raised { test_process(controller,"no_raise") } - assert_raise(Before) { test_process(controller,"raises_before") } - assert_raise(After) { test_process(controller,"raises_after") } - assert_nothing_raised { test_process(controller,"no_raise") } + assert_nothing_raised { test_process(controller, "no_raise") } + assert_raise(Before) { test_process(controller, "raises_before") } + assert_raise(After) { test_process(controller, "raises_after") } + assert_nothing_raised { test_process(controller, "no_raise") } end def test_with_class controller = ControllerWithFilterClass - assert_nothing_raised { test_process(controller,"no_raise") } - assert_raise(After) { test_process(controller,"raises_after") } + assert_nothing_raised { test_process(controller, "no_raise") } + assert_raise(After) { test_process(controller, "raises_after") } end def test_with_instance controller = ControllerWithFilterInstance - assert_nothing_raised { test_process(controller,"no_raise") } - assert_raise(After) { test_process(controller,"raises_after") } + assert_nothing_raised { test_process(controller, "no_raise") } + assert_raise(After) { test_process(controller, "raises_after") } end def test_with_proc - test_process(ControllerWithProcFilter,"no_raise") + test_process(ControllerWithProcFilter, "no_raise") assert @controller.instance_variable_get(:@before) assert @controller.instance_variable_get(:@after) end @@ -997,25 +997,25 @@ class YieldingAroundFiltersTest < ActionController::TestCase controller = ControllerWithNestedFilters assert_nothing_raised do begin - test_process(controller,"raises_both") + test_process(controller, "raises_both") rescue Before, After end end assert_raise Before do begin - test_process(controller,"raises_both") + test_process(controller, "raises_both") rescue After end end end def test_action_order_with_all_action_types - test_process(ControllerWithAllTypesOfFilters,"no_raise") + test_process(ControllerWithAllTypesOfFilters, "no_raise") assert_equal "before around (before yield) around_again (before yield) around_again (after yield) after around (after yield)", @controller.instance_variable_get(:@ran_filter).join(" ") end def test_action_order_with_skip_action_method - test_process(ControllerWithTwoLessFilters,"no_raise") + test_process(ControllerWithTwoLessFilters, "no_raise") assert_equal "before around (before yield) around (after yield)", @controller.instance_variable_get(:@ran_filter).join(" ") end diff --git a/actionpack/test/controller/flash_hash_test.rb b/actionpack/test/controller/flash_hash_test.rb index 32f0db71f5..6b3abdd5be 100644 --- a/actionpack/test/controller/flash_hash_test.rb +++ b/actionpack/test/controller/flash_hash_test.rb @@ -102,8 +102,8 @@ module ActionDispatch @hash["foo"] = "bar" things = [] - @hash.each do |k,v| - things << [k,v] + @hash.each do |k, v| + things << [k, v] end assert_equal([%w{ hello world }, %w{ foo bar }].sort, things.sort) diff --git a/actionpack/test/controller/http_digest_authentication_test.rb b/actionpack/test/controller/http_digest_authentication_test.rb index 343b7b643d..0b59e123d7 100644 --- a/actionpack/test/controller/http_digest_authentication_test.rb +++ b/actionpack/test/controller/http_digest_authentication_test.rb @@ -7,7 +7,7 @@ class HttpDigestAuthenticationTest < ActionController::TestCase before_action :authenticate_with_request, only: :display USERS = { "lifo" => "world", "pretty" => "please", - "dhh" => ::Digest::MD5::hexdigest(["dhh","SuperSecret","secret"].join(":")) } + "dhh" => ::Digest::MD5::hexdigest(["dhh", "SuperSecret", "secret"].join(":")) } def index render plain: "Hello Secret" @@ -180,7 +180,7 @@ class HttpDigestAuthenticationTest < ActionController::TestCase test "authentication request with password stored as ha1 digest hash" do @request.env["HTTP_AUTHORIZATION"] = encode_credentials(username: "dhh", - password: ::Digest::MD5::hexdigest(["dhh","SuperSecret","secret"].join(":")), + password: ::Digest::MD5::hexdigest(["dhh", "SuperSecret", "secret"].join(":")), password_is_ha1: true) get :display diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 67a42989c2..8f8fc64dbd 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -273,7 +273,7 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest self.cookies["cookie_2"] = "oatmeal" get "/cookie_monster" assert_equal "cookie_1=; path=/\ncookie_3=chocolate; path=/", headers["Set-Cookie"] - assert_equal({ "cookie_1"=>"", "cookie_2"=>"oatmeal", "cookie_3"=>"chocolate" }, cookies.to_hash) + assert_equal({ "cookie_1" => "", "cookie_2" => "oatmeal", "cookie_3" => "chocolate" }, cookies.to_hash) end end @@ -283,14 +283,14 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest assert_response :success assert_equal "foo=bar; path=/", headers["Set-Cookie"] - assert_equal({ "foo"=>"bar" }, cookies.to_hash) + assert_equal({ "foo" => "bar" }, cookies.to_hash) get "/get_cookie" assert_response :success assert_equal "bar", body assert_equal nil, headers["Set-Cookie"] - assert_equal({ "foo"=>"bar" }, cookies.to_hash) + assert_equal({ "foo" => "bar" }, cookies.to_hash) end end @@ -302,14 +302,14 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest assert_response :success assert_equal "foo=bar; path=/", headers["Set-Cookie"] - assert_equal({ "foo"=>"bar" }, cookies.to_hash) + assert_equal({ "foo" => "bar" }, cookies.to_hash) get "/get_cookie" assert_response :success assert_equal "bar", body assert_equal nil, headers["Set-Cookie"] - assert_equal({ "foo"=>"bar" }, cookies.to_hash) + assert_equal({ "foo" => "bar" }, cookies.to_hash) end end @@ -916,7 +916,7 @@ class IntegrationRequestsWithSessionSetup < ActionDispatch::IntegrationTest def test_cookies_set_in_setup_are_persisted_through_the_session get "/foo" - assert_equal({ "user_name"=>"david" }, cookies.to_hash) + assert_equal({ "user_name" => "david" }, cookies.to_hash) end end diff --git a/actionpack/test/controller/new_base/render_streaming_test.rb b/actionpack/test/controller/new_base/render_streaming_test.rb index 5cd8f82323..64b799f826 100644 --- a/actionpack/test/controller/new_base/render_streaming_test.rb +++ b/actionpack/test/controller/new_base/render_streaming_test.rb @@ -104,7 +104,7 @@ module RenderStreaming assert_equal nil, headers["Transfer-Encoding"] end - def assert_streaming!(cache="no-cache") + def assert_streaming!(cache = "no-cache") assert_status 200 assert_equal nil, headers["Content-Length"] assert_equal "chunked", headers["Transfer-Encoding"] diff --git a/actionpack/test/controller/parameters/mutators_test.rb b/actionpack/test/controller/parameters/mutators_test.rb index e060e5180f..e61bbdbe13 100644 --- a/actionpack/test/controller/parameters/mutators_test.rb +++ b/actionpack/test/controller/parameters/mutators_test.rb @@ -45,11 +45,11 @@ class ParametersMutatorsTest < ActiveSupport::TestCase test "keep_if retains permitted status" do @params.permit! - assert @params.keep_if { |k,v| k == "person" }.permitted? + assert @params.keep_if { |k, v| k == "person" }.permitted? end test "keep_if retains unpermitted status" do - assert_not @params.keep_if { |k,v| k == "person" }.permitted? + assert_not @params.keep_if { |k, v| k == "person" }.permitted? end test "reject! retains permitted status" do diff --git a/actionpack/test/controller/parameters/parameters_permit_test.rb b/actionpack/test/controller/parameters/parameters_permit_test.rb index 728d8e1279..1cb7173aa0 100644 --- a/actionpack/test/controller/parameters/parameters_permit_test.rb +++ b/actionpack/test/controller/parameters/parameters_permit_test.rb @@ -28,7 +28,7 @@ class ParametersPermitTest < ActiveSupport::TestCase end def walk_permitted(params) - params.each do |k,v| + params.each do |k, v| case v when ActionController::Parameters walk_permitted v @@ -39,13 +39,13 @@ class ParametersPermitTest < ActiveSupport::TestCase end test "iteration should not impact permit" do - hash = { "foo"=>{ "bar"=>{ "0"=>{ "baz"=>"hello", "zot"=>"1" } } } } + hash = { "foo" => { "bar" => { "0" => { "baz" => "hello", "zot" => "1" } } } } params = ActionController::Parameters.new(hash) walk_permitted params sanitized = params[:foo].permit(bar: [:baz]) - assert_equal({ "0"=>{ "baz"=>"hello" } }, sanitized[:bar].to_unsafe_h) + assert_equal({ "0" => { "baz" => "hello" } }, sanitized[:bar].to_unsafe_h) end test "if nothing is permitted, the hash becomes empty" do @@ -322,8 +322,8 @@ class ParametersPermitTest < ActiveSupport::TestCase end test "to_unsafe_h returns unfiltered params even after accessing few keys" do - params = ActionController::Parameters.new("f"=>{ "language_facet"=>["Tibetan"] }) - expected = { "f"=>{ "language_facet"=>["Tibetan"] } } + params = ActionController::Parameters.new("f" => { "language_facet" => ["Tibetan"] }) + expected = { "f" => { "language_facet" => ["Tibetan"] } } assert params["f"].is_a? ActionController::Parameters assert_equal expected, params.to_unsafe_h diff --git a/actionpack/test/controller/render_json_test.rb b/actionpack/test/controller/render_json_test.rb index 213829bd9e..79552ec8f1 100644 --- a/actionpack/test/controller/render_json_test.rb +++ b/actionpack/test/controller/render_json_test.rb @@ -5,7 +5,7 @@ require "pathname" class RenderJsonTest < ActionController::TestCase class JsonRenderable - def as_json(options={}) + def as_json(options = {}) hash = { a: :b, c: :d, e: :f } hash.except!(*options[:except]) if options[:except] hash diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 76139d59e2..0c0f18f200 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -368,7 +368,7 @@ class ExpiresInRenderTest < ActionController::TestCase end def test_date_header_when_expires_in - time = Time.mktime(2011,10,30) + time = Time.mktime(2011, 10, 30) Time.stub :now, time do get :conditional_hello_with_expires_in assert_equal Time.now.httpdate, @response.headers["Date"] diff --git a/actionpack/test/controller/renderers_test.rb b/actionpack/test/controller/renderers_test.rb index 122f5be549..ccc700d79c 100644 --- a/actionpack/test/controller/renderers_test.rb +++ b/actionpack/test/controller/renderers_test.rb @@ -10,7 +10,7 @@ class RenderersTest < ActionController::TestCase end end class JsonRenderable - def as_json(options={}) + def as_json(options = {}) hash = { a: :b, c: :d, e: :f } hash.except!(*options[:except]) if options[:except] hash diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index b572e7e8d5..0b3dc6c41f 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -27,7 +27,7 @@ class ResourcesTest < ActionController::TestCase def test_override_paths_for_member_and_collection_methods collection_methods = { rss: :get, reorder: :post, csv: :post } - member_methods = { rss: :get, atom: :get, upload: :post, fix: :post } + member_methods = { rss: :get, atom: :get, upload: :post, fix: :post } path_names = { new: "nuevo", rss: "canal", fix: "corrigir" } with_restful_routing :messages, @@ -792,7 +792,7 @@ class ResourcesTest < ActionController::TestCase end assert_simply_restful_for :product_reviews, controller: "messages", as: "reviews", name_prefix: "product_", path_prefix: "products/1/", options: { product_id: "1" } - assert_simply_restful_for :tutor_reviews,controller: "comments", as: "reviews", name_prefix: "tutor_", path_prefix: "tutors/1/", options: { tutor_id: "1" } + assert_simply_restful_for :tutor_reviews, controller: "comments", as: "reviews", name_prefix: "tutor_", path_prefix: "tutors/1/", options: { tutor_id: "1" } end end @@ -1306,7 +1306,7 @@ class ResourcesTest < ActionController::TestCase end def assert_named_route(expected, route, options) - actual = @controller.send(route, options) rescue $!.class.name + actual = @controller.send(route, options) rescue $!.class.name assert_equal expected, actual, "Error on route: #{route}(#{options.inspect})" end diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 7be2ad2b28..56b39510bb 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -91,7 +91,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase end hash = ActiveSupport::JSON.decode get(URI("http://example.org/journey/faithfully-omg")) - assert_equal({ "artist"=>"journey", "song"=>"faithfully" }, hash) + assert_equal({ "artist" => "journey", "song" => "faithfully" }, hash) end def test_id_with_dash @@ -103,7 +103,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase end hash = ActiveSupport::JSON.decode get(URI("http://example.org/journey/faithfully-omg")) - assert_equal({ "id"=>"faithfully-omg" }, hash) + assert_equal({ "id" => "faithfully-omg" }, hash) end def test_dash_with_custom_regexp @@ -115,7 +115,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase end hash = ActiveSupport::JSON.decode get(URI("http://example.org/journey/123-omg")) - assert_equal({ "artist"=>"journey", "song"=>"123" }, hash) + assert_equal({ "artist" => "journey", "song" => "123" }, hash) assert_equal "Not Found", get(URI("http://example.org/journey/faithfully-omg")) end @@ -128,7 +128,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase end hash = ActiveSupport::JSON.decode get(URI("http://example.org/journey/omg-faithfully")) - assert_equal({ "artist"=>"journey", "song"=>"faithfully" }, hash) + assert_equal({ "artist" => "journey", "song" => "faithfully" }, hash) end def test_pre_dash_with_custom_regexp @@ -140,7 +140,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase end hash = ActiveSupport::JSON.decode get(URI("http://example.org/journey/omg-123")) - assert_equal({ "artist"=>"journey", "song"=>"123" }, hash) + assert_equal({ "artist" => "journey", "song" => "123" }, hash) assert_equal "Not Found", get(URI("http://example.org/journey/omg-faithfully")) end @@ -1931,7 +1931,7 @@ class RackMountIntegrationTests < ActiveSupport::TestCase get "clients" => "projects#index" get "ignorecase/geocode/:postalcode" => "geocode#show", :postalcode => /hx\d\d-\d[a-z]{2}/i - get "extended/geocode/:postalcode" => "geocode#show",:constraints => { + get "extended/geocode/:postalcode" => "geocode#show", :constraints => { postalcode: /# Postcode format \d{5} #Prefix (-\d{4})? #Suffix diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index 8dc565ac8d..a28283f4d6 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -180,7 +180,7 @@ class SendFileTest < ActionController::TestCase "file.zip" => "application/zip", "file.unk" => "application/octet-stream", "zip" => "application/octet-stream" - }.each do |filename,expected_type| + }.each do |filename, expected_type| get __method__, params: { filename: filename } assert_equal expected_type, response.content_type end diff --git a/actionpack/test/controller/test_case_test.rb b/actionpack/test/controller/test_case_test.rb index 33f11e67ef..55ceced30c 100644 --- a/actionpack/test/controller/test_case_test.rb +++ b/actionpack/test/controller/test_case_test.rb @@ -231,7 +231,7 @@ XML def test_document_body_and_params_with_post post :test_params, params: { id: 1 } - assert_equal({ "id"=>"1", "controller"=>"test_case_test/test", "action"=>"test_params" }, ::JSON.parse(@response.body)) + assert_equal({ "id" => "1", "controller" => "test_case_test/test", "action" => "test_params" }, ::JSON.parse(@response.body)) end def test_document_body_with_post @@ -651,7 +651,7 @@ XML def test_xhr_with_params get :test_params, params: { id: 1 }, xhr: true - assert_equal({ "id"=>"1", "controller"=>"test_case_test/test", "action"=>"test_params" }, ::JSON.parse(@response.body)) + assert_equal({ "id" => "1", "controller" => "test_case_test/test", "action" => "test_params" }, ::JSON.parse(@response.body)) end def test_xhr_with_session @@ -753,10 +753,10 @@ XML def test_multiple_mixed_method_process_should_scrub_rack_input post :test_params, params: { id: 1, foo: "an foo" } - assert_equal({ "id"=>"1", "foo" => "an foo", "controller"=>"test_case_test/test", "action"=>"test_params" }, ::JSON.parse(@response.body)) + assert_equal({ "id" => "1", "foo" => "an foo", "controller" => "test_case_test/test", "action" => "test_params" }, ::JSON.parse(@response.body)) get :test_params, params: { bar: "an bar" } - assert_equal({ "bar"=>"an bar", "controller"=>"test_case_test/test", "action"=>"test_params" }, ::JSON.parse(@response.body)) + assert_equal({ "bar" => "an bar", "controller" => "test_case_test/test", "action" => "test_params" }, ::JSON.parse(@response.body)) end %w(controller response request).each do |variable| diff --git a/actionpack/test/controller/url_for_integration_test.rb b/actionpack/test/controller/url_for_integration_test.rb index c7ea6c5ef6..f640e77b99 100644 --- a/actionpack/test/controller/url_for_integration_test.rb +++ b/actionpack/test/controller/url_for_integration_test.rb @@ -43,7 +43,7 @@ module ActionPack get "clients" => "projects#index" get "ignorecase/geocode/:postalcode" => "geocode#show", :postalcode => /hx\d\d-\d[a-z]{2}/i - get "extended/geocode/:postalcode" => "geocode#show",:constraints => { + get "extended/geocode/:postalcode" => "geocode#show", :constraints => { postalcode: /# Postcode format \d{5} #Prefix (-\d{4})? #Suffix @@ -73,99 +73,99 @@ module ActionPack end [ - ["/admin/users",[ { use_route: "admin_users" }]], - ["/admin/users",[ { controller: "admin/users" }]], - ["/admin/users",[ { controller: "admin/users", action: "index" }]], - ["/admin/users",[ { action: "index" }, { controller: "admin/users", action: "index" }, "/admin/users"]], - ["/admin/users",[ { controller: "users", action: "index" }, { controller: "admin/accounts", action: "show", id: "1" }, "/admin/accounts/show/1"]], - ["/people",[ { controller: "/people", action: "index" }, { controller: "admin/accounts", action: "foo", id: "bar" }, "/admin/accounts/foo/bar"]], - - ["/admin/posts",[ { controller: "admin/posts" }]], - ["/admin/posts/new",[ { controller: "admin/posts", action: "new" }]], - - ["/blog/2009",[ { controller: "posts", action: "show_date", year: 2009 }]], - ["/blog/2009/1",[ { controller: "posts", action: "show_date", year: 2009, month: 1 }]], - ["/blog/2009/1/1",[ { controller: "posts", action: "show_date", year: 2009, month: 1, day: 1 }]], - - ["/archive/2010",[ { controller: "archive", action: "index", year: "2010" }]], - ["/archive",[ { controller: "archive", action: "index" }]], - ["/archive?year=january",[ { controller: "archive", action: "index", year: "january" }]], - - ["/people",[ { controller: "people", action: "index" }]], - ["/people",[ { action: "index" }, { controller: "people", action: "index" }, "/people"]], - ["/people",[ { action: "index" }, { controller: "people", action: "show", id: "1" }, "/people/show/1"]], - ["/people",[ { controller: "people", action: "index" }, { controller: "people", action: "show", id: "1" }, "/people/show/1"]], - ["/people",[ {}, { controller: "people", action: "index" }, "/people"]], - ["/people/1",[ { controller: "people", action: "show" }, { controller: "people", action: "show", id: "1" }, "/people/show/1"]], - ["/people/new",[ { use_route: "new_person" }]], - ["/people/new",[ { controller: "people", action: "new" }]], - ["/people/1",[ { use_route: "person", id: "1" }]], - ["/people/1",[ { controller: "people", action: "show", id: "1" }]], - ["/people/1.xml",[ { controller: "people", action: "show", id: "1", format: "xml" }]], - ["/people/1",[ { controller: "people", action: "show", id: 1 }]], - ["/people/1",[ { controller: "people", action: "show", id: Model.new("1") }]], - ["/people/1",[ { action: "show", id: "1" }, { controller: "people", action: "index" }, "/people"]], - ["/people/1",[ { action: "show", id: 1 }, { controller: "people", action: "show", id: "1" }, "/people/show/1"]], - ["/people",[ { controller: "people", action: "index" }, { controller: "people", action: "show", id: "1" }, "/people/show/1"]], - ["/people/1",[ {}, { controller: "people", action: "show", id: "1" }, "/people/show/1"]], - ["/people/1",[ { controller: "people", action: "show" }, { controller: "people", action: "index", id: "1" }, "/people/index/1"]], - ["/people/1/edit",[ { controller: "people", action: "edit", id: "1" }]], - ["/people/1/edit.xml",[ { controller: "people", action: "edit", id: "1", format: "xml" }]], - ["/people/1/edit",[ { use_route: "edit_person", id: "1" }]], - ["/people/1?legacy=true",[ { controller: "people", action: "show", id: "1", legacy: "true" }]], - ["/people?legacy=true",[ { controller: "people", action: "index", legacy: "true" }]], - - ["/id_default/2",[ { controller: "foo", action: "id_default", id: "2" }]], - ["/id_default",[ { controller: "foo", action: "id_default", id: "1" }]], - ["/id_default",[ { controller: "foo", action: "id_default", id: 1 }]], - ["/id_default",[ { controller: "foo", action: "id_default" }]], - ["/optional/bar",[ { controller: "posts", action: "index", optional: "bar" }]], - ["/posts",[ { controller: "posts", action: "index" }]], - - ["/project",[ { controller: "project", action: "index" }]], - ["/projects/1",[ { controller: "project", action: "index", project_id: "1" }]], - ["/projects/1",[ { controller: "project", action: "index" }, { project_id: "1", controller: "project", action: "index" }, "/projects/1"]], - ["/projects/1",[ { use_route: "project", controller: "project", action: "index", project_id: "1" }]], - ["/projects/1",[ { use_route: "project", controller: "project", action: "index" }, { controller: "project", action: "index", project_id: "1" }, "/projects/1"]], - - ["/clients",[ { controller: "projects", action: "index" }]], - ["/clients?project_id=1",[ { controller: "projects", action: "index", project_id: "1" }]], - ["/clients",[ { controller: "projects", action: "index" }, { project_id: "1", controller: "project", action: "index" }, "/projects/1"]], - - ["/comment/20",[ { id: 20 }, { controller: "comments", action: "show" }, "/comments/show"]], - ["/comment/20",[ { controller: "comments", id: 20, action: "show" }]], - ["/comments/boo",[ { controller: "comments", action: "boo" }]], - - ["/ws/posts/show/1",[ { controller: "posts", action: "show", id: "1", ws: true }]], - ["/ws/posts",[ { controller: "posts", action: "index", ws: true }]], - - ["/account",[ { controller: "account", action: "subscription" }]], - ["/account/billing",[ { controller: "account", action: "billing" }]], - - ["/pages/1/notes/show/1",[ { page_id: "1", controller: "notes", action: "show", id: "1" }]], - ["/pages/1/notes/list",[ { page_id: "1", controller: "notes", action: "list" }]], - ["/pages/1/notes",[ { page_id: "1", controller: "notes", action: "index" }]], - ["/pages/1/notes",[ { page_id: "1", controller: "notes" }]], - ["/notes",[ { page_id: nil, controller: "notes" }]], - ["/notes",[ { controller: "notes" }]], - ["/notes/print",[ { controller: "notes", action: "print" }]], - ["/notes/print",[ {}, { controller: "notes", action: "print" }, "/notes/print"]], - - ["/notes/index/1",[ { controller: "notes" }, { controller: "notes", action: "index", id: "1" }, "/notes/index/1"]], - ["/notes/index/1",[ { controller: "notes" }, { controller: "notes", id: "1", action: "index" }, "/notes/index/1"]], - ["/notes/index/1",[ { action: "index" }, { controller: "notes", id: "1", action: "index" }, "/notes/index/1"]], - ["/notes/index/1",[ {}, { controller: "notes", id: "1", action: "index" }, "/notes/index/1"]], - ["/notes/show/1",[ {}, { controller: "notes", action: "show", id: "1" }, "/notes/show/1"]], - ["/posts",[ { controller: "posts" }, { controller: "notes", action: "show", id: "1" }, "/notes/show/1"]], - ["/notes/list",[ { action: "list" }, { controller: "notes", action: "show", id: "1" }, "/notes/show/1"]], - - ["/posts/ping",[ { controller: "posts", action: "ping" }]], - ["/posts/show/1",[ { controller: "posts", action: "show", id: "1" }]], - ["/posts/show/1",[ { controller: "posts", action: "show", id: "1", format: "" }]], - ["/posts",[ { controller: "posts" }]], - ["/posts",[ { controller: "posts", action: "index" }]], - ["/posts/create",[ { action: "create" }, { day: nil, month: nil, controller: "posts", action: "show_date" }, "/blog"]], - ["/posts?foo=bar",[ { controller: "posts", foo: "bar" }]], + ["/admin/users", [ { use_route: "admin_users" }]], + ["/admin/users", [ { controller: "admin/users" }]], + ["/admin/users", [ { controller: "admin/users", action: "index" }]], + ["/admin/users", [ { action: "index" }, { controller: "admin/users", action: "index" }, "/admin/users"]], + ["/admin/users", [ { controller: "users", action: "index" }, { controller: "admin/accounts", action: "show", id: "1" }, "/admin/accounts/show/1"]], + ["/people", [ { controller: "/people", action: "index" }, { controller: "admin/accounts", action: "foo", id: "bar" }, "/admin/accounts/foo/bar"]], + + ["/admin/posts", [ { controller: "admin/posts" }]], + ["/admin/posts/new", [ { controller: "admin/posts", action: "new" }]], + + ["/blog/2009", [ { controller: "posts", action: "show_date", year: 2009 }]], + ["/blog/2009/1", [ { controller: "posts", action: "show_date", year: 2009, month: 1 }]], + ["/blog/2009/1/1", [ { controller: "posts", action: "show_date", year: 2009, month: 1, day: 1 }]], + + ["/archive/2010", [ { controller: "archive", action: "index", year: "2010" }]], + ["/archive", [ { controller: "archive", action: "index" }]], + ["/archive?year=january", [ { controller: "archive", action: "index", year: "january" }]], + + ["/people", [ { controller: "people", action: "index" }]], + ["/people", [ { action: "index" }, { controller: "people", action: "index" }, "/people"]], + ["/people", [ { action: "index" }, { controller: "people", action: "show", id: "1" }, "/people/show/1"]], + ["/people", [ { controller: "people", action: "index" }, { controller: "people", action: "show", id: "1" }, "/people/show/1"]], + ["/people", [ {}, { controller: "people", action: "index" }, "/people"]], + ["/people/1", [ { controller: "people", action: "show" }, { controller: "people", action: "show", id: "1" }, "/people/show/1"]], + ["/people/new", [ { use_route: "new_person" }]], + ["/people/new", [ { controller: "people", action: "new" }]], + ["/people/1", [ { use_route: "person", id: "1" }]], + ["/people/1", [ { controller: "people", action: "show", id: "1" }]], + ["/people/1.xml", [ { controller: "people", action: "show", id: "1", format: "xml" }]], + ["/people/1", [ { controller: "people", action: "show", id: 1 }]], + ["/people/1", [ { controller: "people", action: "show", id: Model.new("1") }]], + ["/people/1", [ { action: "show", id: "1" }, { controller: "people", action: "index" }, "/people"]], + ["/people/1", [ { action: "show", id: 1 }, { controller: "people", action: "show", id: "1" }, "/people/show/1"]], + ["/people", [ { controller: "people", action: "index" }, { controller: "people", action: "show", id: "1" }, "/people/show/1"]], + ["/people/1", [ {}, { controller: "people", action: "show", id: "1" }, "/people/show/1"]], + ["/people/1", [ { controller: "people", action: "show" }, { controller: "people", action: "index", id: "1" }, "/people/index/1"]], + ["/people/1/edit", [ { controller: "people", action: "edit", id: "1" }]], + ["/people/1/edit.xml", [ { controller: "people", action: "edit", id: "1", format: "xml" }]], + ["/people/1/edit", [ { use_route: "edit_person", id: "1" }]], + ["/people/1?legacy=true", [ { controller: "people", action: "show", id: "1", legacy: "true" }]], + ["/people?legacy=true", [ { controller: "people", action: "index", legacy: "true" }]], + + ["/id_default/2", [ { controller: "foo", action: "id_default", id: "2" }]], + ["/id_default", [ { controller: "foo", action: "id_default", id: "1" }]], + ["/id_default", [ { controller: "foo", action: "id_default", id: 1 }]], + ["/id_default", [ { controller: "foo", action: "id_default" }]], + ["/optional/bar", [ { controller: "posts", action: "index", optional: "bar" }]], + ["/posts", [ { controller: "posts", action: "index" }]], + + ["/project", [ { controller: "project", action: "index" }]], + ["/projects/1", [ { controller: "project", action: "index", project_id: "1" }]], + ["/projects/1", [ { controller: "project", action: "index" }, { project_id: "1", controller: "project", action: "index" }, "/projects/1"]], + ["/projects/1", [ { use_route: "project", controller: "project", action: "index", project_id: "1" }]], + ["/projects/1", [ { use_route: "project", controller: "project", action: "index" }, { controller: "project", action: "index", project_id: "1" }, "/projects/1"]], + + ["/clients", [ { controller: "projects", action: "index" }]], + ["/clients?project_id=1", [ { controller: "projects", action: "index", project_id: "1" }]], + ["/clients", [ { controller: "projects", action: "index" }, { project_id: "1", controller: "project", action: "index" }, "/projects/1"]], + + ["/comment/20", [ { id: 20 }, { controller: "comments", action: "show" }, "/comments/show"]], + ["/comment/20", [ { controller: "comments", id: 20, action: "show" }]], + ["/comments/boo", [ { controller: "comments", action: "boo" }]], + + ["/ws/posts/show/1", [ { controller: "posts", action: "show", id: "1", ws: true }]], + ["/ws/posts", [ { controller: "posts", action: "index", ws: true }]], + + ["/account", [ { controller: "account", action: "subscription" }]], + ["/account/billing", [ { controller: "account", action: "billing" }]], + + ["/pages/1/notes/show/1", [ { page_id: "1", controller: "notes", action: "show", id: "1" }]], + ["/pages/1/notes/list", [ { page_id: "1", controller: "notes", action: "list" }]], + ["/pages/1/notes", [ { page_id: "1", controller: "notes", action: "index" }]], + ["/pages/1/notes", [ { page_id: "1", controller: "notes" }]], + ["/notes", [ { page_id: nil, controller: "notes" }]], + ["/notes", [ { controller: "notes" }]], + ["/notes/print", [ { controller: "notes", action: "print" }]], + ["/notes/print", [ {}, { controller: "notes", action: "print" }, "/notes/print"]], + + ["/notes/index/1", [ { controller: "notes" }, { controller: "notes", action: "index", id: "1" }, "/notes/index/1"]], + ["/notes/index/1", [ { controller: "notes" }, { controller: "notes", id: "1", action: "index" }, "/notes/index/1"]], + ["/notes/index/1", [ { action: "index" }, { controller: "notes", id: "1", action: "index" }, "/notes/index/1"]], + ["/notes/index/1", [ {}, { controller: "notes", id: "1", action: "index" }, "/notes/index/1"]], + ["/notes/show/1", [ {}, { controller: "notes", action: "show", id: "1" }, "/notes/show/1"]], + ["/posts", [ { controller: "posts" }, { controller: "notes", action: "show", id: "1" }, "/notes/show/1"]], + ["/notes/list", [ { action: "list" }, { controller: "notes", action: "show", id: "1" }, "/notes/show/1"]], + + ["/posts/ping", [ { controller: "posts", action: "ping" }]], + ["/posts/show/1", [ { controller: "posts", action: "show", id: "1" }]], + ["/posts/show/1", [ { controller: "posts", action: "show", id: "1", format: "" }]], + ["/posts", [ { controller: "posts" }]], + ["/posts", [ { controller: "posts", action: "index" }]], + ["/posts/create", [ { action: "create" }, { day: nil, month: nil, controller: "posts", action: "show_date" }, "/blog"]], + ["/posts?foo=bar", [ { controller: "posts", foo: "bar" }]], ["/posts?foo%5B%5D=bar&foo%5B%5D=baz", [{ controller: "posts", foo: ["bar", "baz"] }]], ["/posts?page=2", [{ controller: "posts", page: 2 }]], ["/posts?q%5Bfoo%5D%5Ba%5D=b", [{ controller: "posts", q: { foo: { a: "b" } } }]], diff --git a/actionpack/test/controller/url_for_test.rb b/actionpack/test/controller/url_for_test.rb index 8d7190365d..4b6f33c545 100644 --- a/actionpack/test/controller/url_for_test.rb +++ b/actionpack/test/controller/url_for_test.rb @@ -223,13 +223,13 @@ module AbstractController def test_trailing_slash add_host! options = { controller: "foo", trailing_slash: true, action: "bar", id: "33" } - assert_equal("http://www.basecamphq.com/foo/bar/33/", W.new.url_for(options) ) + assert_equal("http://www.basecamphq.com/foo/bar/33/", W.new.url_for(options)) end def test_trailing_slash_with_protocol add_host! - options = { trailing_slash: true,protocol: "https", controller: "foo", action: "bar", id: "33" } - assert_equal("https://www.basecamphq.com/foo/bar/33/", W.new.url_for(options) ) + options = { trailing_slash: true, protocol: "https", controller: "foo", action: "bar", id: "33" } + assert_equal("https://www.basecamphq.com/foo/bar/33/", W.new.url_for(options)) assert_equal "https://www.basecamphq.com/foo/bar/33/?query=string", W.new.url_for(options.merge(query: "string")) end @@ -238,7 +238,7 @@ module AbstractController assert_equal "/foo/", W.new.url_for(options.merge(only_path: true)) options.update(action: "bar", id: "33") assert_equal "/foo/bar/33/", W.new.url_for(options.merge(only_path: true)) - assert_equal "/foo/bar/33/?query=string", W.new.url_for(options.merge(query: "string",only_path: true)) + assert_equal "/foo/bar/33/?query=string", W.new.url_for(options.merge(query: "string", only_path: true)) end def test_trailing_slash_with_anchor @@ -423,7 +423,7 @@ module AbstractController first_class.default_url_options[:host] = first_host second_class.default_url_options[:host] = second_host - assert_equal first_host, first_class.default_url_options[:host] + assert_equal first_host, first_class.default_url_options[:host] assert_equal second_host, second_class.default_url_options[:host] end diff --git a/actionpack/test/dispatch/cookies_test.rb b/actionpack/test/dispatch/cookies_test.rb index 6dcd62572a..af3036d448 100644 --- a/actionpack/test/dispatch/cookies_test.rb +++ b/actionpack/test/dispatch/cookies_test.rb @@ -43,7 +43,7 @@ class CookieJarTest < ActiveSupport::TestCase def test_each request.cookie_jar["foo"] = :bar list = [] - request.cookie_jar.each do |k,v| + request.cookie_jar.each do |k, v| list << [k, v] end @@ -52,7 +52,7 @@ class CookieJarTest < ActiveSupport::TestCase def test_enumerable request.cookie_jar["foo"] = :bar - actual = request.cookie_jar.map { |k,v| [k.to_s, v.to_s] } + actual = request.cookie_jar.map { |k, v| [k.to_s, v.to_s] } assert_equal [["foo", "bar"]], actual end @@ -95,17 +95,17 @@ class CookiesTest < ActionController::TestCase end def authenticate_for_fourteen_days - cookies["user_name"] = { "value" => "david", "expires" => Time.utc(2005, 10, 10,5) } + cookies["user_name"] = { "value" => "david", "expires" => Time.utc(2005, 10, 10, 5) } head :ok end def authenticate_for_fourteen_days_with_symbols - cookies[:user_name] = { value: "david", expires: Time.utc(2005, 10, 10,5) } + cookies[:user_name] = { value: "david", expires: Time.utc(2005, 10, 10, 5) } head :ok end def set_multiple_cookies - cookies["user_name"] = { "value" => "david", "expires" => Time.utc(2005, 10, 10,5) } + cookies["user_name"] = { "value" => "david", "expires" => Time.utc(2005, 10, 10, 5) } cookies["login"] = "XJ-122" head :ok end @@ -205,7 +205,7 @@ class CookiesTest < ActionController::TestCase def delete_and_set_cookie cookies.delete :user_name - cookies[:user_name] = { value: "david", expires: Time.utc(2005, 10, 10,5) } + cookies[:user_name] = { value: "david", expires: Time.utc(2005, 10, 10, 5) } head :ok end diff --git a/actionpack/test/dispatch/debug_exceptions_test.rb b/actionpack/test/dispatch/debug_exceptions_test.rb index bff52f2a2b..ea477e8908 100644 --- a/actionpack/test/dispatch/debug_exceptions_test.rb +++ b/actionpack/test/dispatch/debug_exceptions_test.rb @@ -287,7 +287,7 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest test "does not show filtered parameters" do @app = DevelopmentApp - get "/", params: { "foo"=>"bar" }, headers: { "action_dispatch.show_exceptions" => true, + get "/", params: { "foo" => "bar" }, headers: { "action_dispatch.show_exceptions" => true, "action_dispatch.parameter_filter" => [:foo] } assert_response 500 assert_match(""foo"=>"[FILTERED]"", body) diff --git a/actionpack/test/dispatch/header_test.rb b/actionpack/test/dispatch/header_test.rb index 6febd5cb68..958450072e 100644 --- a/actionpack/test/dispatch/header_test.rb +++ b/actionpack/test/dispatch/header_test.rb @@ -155,8 +155,8 @@ class HeaderTest < ActiveSupport::TestCase headers = make_headers(env) headers["Referer"] = "http://example.com/" headers.merge! "CONTENT_TYPE" => "text/plain" - assert_equal({ "HTTP_REFERER"=>"http://example.com/", - "CONTENT_TYPE"=>"text/plain" }, env) + assert_equal({ "HTTP_REFERER" => "http://example.com/", + "CONTENT_TYPE" => "text/plain" }, env) end test "fetch exception" do diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb index e558efb88d..2ca03c535a 100644 --- a/actionpack/test/dispatch/mime_type_test.rb +++ b/actionpack/test/dispatch/mime_type_test.rb @@ -89,7 +89,7 @@ class MimeTypeTest < ActiveSupport::TestCase # (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1) test "parse other broken acceptlines" do accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, , pronto/1.00.00, sslvpn/1.00.00.00, */*" - expect = ["image/gif", "image/x-xbitmap", "image/jpeg","image/pjpeg", "application/x-shockwave-flash", "application/vnd.ms-excel", "application/vnd.ms-powerpoint", "application/msword", "pronto/1.00.00", "sslvpn/1.00.00.00", "*/*"] + expect = ["image/gif", "image/x-xbitmap", "image/jpeg", "image/pjpeg", "application/x-shockwave-flash", "application/vnd.ms-excel", "application/vnd.ms-powerpoint", "application/msword", "pronto/1.00.00", "sslvpn/1.00.00.00", "*/*"] assert_equal expect.map(&:to_s), Mime::Type.parse(accept).map(&:to_s) end diff --git a/actionpack/test/dispatch/reloader_test.rb b/actionpack/test/dispatch/reloader_test.rb index e74b8e40fd..db68549b84 100644 --- a/actionpack/test/dispatch/reloader_test.rb +++ b/actionpack/test/dispatch/reloader_test.rb @@ -178,7 +178,7 @@ class ReloaderTest < ActiveSupport::TestCase def test_cleanup_callbacks_are_called_on_exceptions cleaned = false assert_deprecated do - Reloader.to_cleanup { cleaned = true } + Reloader.to_cleanup { cleaned = true } end begin diff --git a/actionpack/test/dispatch/request/query_string_parsing_test.rb b/actionpack/test/dispatch/request/query_string_parsing_test.rb index 5c992be216..2499c33cef 100644 --- a/actionpack/test/dispatch/request/query_string_parsing_test.rb +++ b/actionpack/test/dispatch/request/query_string_parsing_test.rb @@ -97,7 +97,7 @@ class QueryStringParsingTest < ActionDispatch::IntegrationTest assert_parses({ "action" => { "foo" => { "bar" => nil } } }, "action[foo][bar]") assert_parses({ "action" => { "foo" => { "bar" => [] } } }, "action[foo][bar][]") assert_parses({ "action" => { "foo" => [] } }, "action[foo][]") - assert_parses({ "action"=>{ "foo"=>[{ "bar"=>nil }] } }, "action[foo][][bar]") + assert_parses({ "action" => { "foo" => [{ "bar" => nil }] } }, "action[foo][][bar]") end def test_array_parses_without_nil @@ -114,7 +114,7 @@ class QueryStringParsingTest < ActionDispatch::IntegrationTest assert_parses({ "action" => { "foo" => { "bar" => [nil] } } }, "action[foo][bar][]") assert_parses({ "action" => { "foo" => [nil] } }, "action[foo][]") assert_parses({ "action" => { "foo" => [{ "bar" => nil }] } }, "action[foo][][bar]") - assert_parses({ "action" => ["1",nil] }, "action[]=1&action[]") + assert_parses({ "action" => ["1", nil] }, "action[]=1&action[]") ensure ActionDispatch::Request::Utils.perform_deep_munge = old_perform_deep_munge end diff --git a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb index 5c7558e48d..1169bf0cdb 100644 --- a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb @@ -55,7 +55,7 @@ class UrlEncodedParamsParsingTest < ActionDispatch::IntegrationTest "products[second]=Pc", "=Save" ].join("&") - expected = { + expected = { "customers" => { "boston" => { "first" => { diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index 13a87b8976..2f41851598 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -581,7 +581,7 @@ class RequestCookie < BaseRequestTest # some Nokia phone browsers omit the space after the semicolon separator. # some developers have grown accustomed to using comma in cookie values. - request = stub_request("HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes") + request = stub_request("HTTP_COOKIE" => "_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes") assert_equal "c84ace847", request.cookies["_session_id"], request.cookies.inspect assert_equal "yes", request.cookies["is_admin"], request.cookies.inspect end @@ -596,7 +596,7 @@ class RequestParamsParsing < BaseRequestTest "rack.input" => StringIO.new("flamenco=love") ) - assert_equal({ "flamenco"=> "love" }, request.request_parameters) + assert_equal({ "flamenco" => "love" }, request.request_parameters) end test "doesnt interpret request uri as query string when missing" do @@ -774,8 +774,8 @@ class RequestMethod < BaseRequestTest ensure # Reset original acronym set ActiveSupport::Inflector.inflections do |inflect| - inflect.send(:instance_variable_set,"@acronyms",existing_acrnoyms) - inflect.send(:instance_variable_set,"@acronym_regex",existing_acrnoym_regex) + inflect.send(:instance_variable_set, "@acronyms", existing_acrnoyms) + inflect.send(:instance_variable_set, "@acronym_regex", existing_acrnoym_regex) end end end @@ -1072,14 +1072,14 @@ end class RequestParameterFilter < BaseRequestTest test "process parameter filter" do test_hashes = [ - [{ "foo"=>"bar" },{ "foo"=>"bar" },%w'food'], - [{ "foo"=>"bar" },{ "foo"=>"[FILTERED]" },%w'foo'], - [{ "foo"=>"bar", "bar"=>"foo" },{ "foo"=>"[FILTERED]", "bar"=>"foo" },%w'foo baz'], - [{ "foo"=>"bar", "baz"=>"foo" },{ "foo"=>"[FILTERED]", "baz"=>"[FILTERED]" },%w'foo baz'], - [{ "bar"=>{ "foo"=>"bar","bar"=>"foo" } },{ "bar"=>{ "foo"=>"[FILTERED]","bar"=>"foo" } },%w'fo'], - [{ "foo"=>{ "foo"=>"bar","bar"=>"foo" } },{ "foo"=>"[FILTERED]" },%w'f banana'], - [{ "deep"=>{ "cc"=>{ "code"=>"bar","bar"=>"foo" },"ss"=>{ "code"=>"bar" } } },{ "deep"=>{ "cc"=>{ "code"=>"[FILTERED]","bar"=>"foo" },"ss"=>{ "code"=>"bar" } } },%w'deep.cc.code'], - [{ "baz"=>[{ "foo"=>"baz" }, "1"] }, { "baz"=>[{ "foo"=>"[FILTERED]" }, "1"] }, [/foo/]]] + [{ "foo" => "bar" }, { "foo" => "bar" }, %w'food'], + [{ "foo" => "bar" }, { "foo" => "[FILTERED]" }, %w'foo'], + [{ "foo" => "bar", "bar" => "foo" }, { "foo" => "[FILTERED]", "bar" => "foo" }, %w'foo baz'], + [{ "foo" => "bar", "baz" => "foo" }, { "foo" => "[FILTERED]", "baz" => "[FILTERED]" }, %w'foo baz'], + [{ "bar" => { "foo" => "bar", "bar" => "foo" } }, { "bar" => { "foo" => "[FILTERED]", "bar" => "foo" } }, %w'fo'], + [{ "foo" => { "foo" => "bar", "bar" => "foo" } }, { "foo" => "[FILTERED]" }, %w'f banana'], + [{ "deep" => { "cc" => { "code" => "bar", "bar" => "foo" }, "ss" => { "code" => "bar" } } }, { "deep" => { "cc" => { "code" => "[FILTERED]", "bar" => "foo" }, "ss" => { "code" => "bar" } } }, %w'deep.cc.code'], + [{ "baz" => [{ "foo" => "baz" }, "1"] }, { "baz" => [{ "foo" => "[FILTERED]" }, "1"] }, [/foo/]]] test_hashes.each do |before_filter, after_filter, filter_words| parameter_filter = ActionDispatch::Http::ParameterFilter.new(filter_words) @@ -1091,8 +1091,8 @@ class RequestParameterFilter < BaseRequestTest } parameter_filter = ActionDispatch::Http::ParameterFilter.new(filter_words) - before_filter["barg"] = { :bargain=>"gain", "blah"=>"bar", "bar"=>{ "bargain"=>{ "blah"=>"foo" } } } - after_filter["barg"] = { :bargain=>"niag", "blah"=>"[FILTERED]", "bar"=>{ "bargain"=>{ "blah"=>"[FILTERED]" } } } + before_filter["barg"] = { :bargain => "gain", "blah" => "bar", "bar" => { "bargain" => { "blah" => "foo" } } } + after_filter["barg"] = { :bargain => "niag", "blah" => "[FILTERED]", "bar" => { "bargain" => { "blah" => "[FILTERED]" } } } assert_equal after_filter, parameter_filter.filter(before_filter) end diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 4e547ab7d5..400af42bac 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -131,7 +131,7 @@ class ResponseTest < ActiveSupport::TestCase def test_only_set_charset_still_defaults_to_text_html response = ActionDispatch::Response.new response.charset = "utf-16" - _,headers,_ = response.to_a + _, headers, _ = response.to_a assert_equal "text/html; charset=utf-16", headers["Content-Type"] end @@ -229,7 +229,7 @@ class ResponseTest < ActiveSupport::TestCase test "multiple cookies" do @response.set_cookie("user_name", value: "david", path: "/") - @response.set_cookie("login", value: "foo&bar", path: "/", expires: Time.utc(2005, 10, 10,5)) + @response.set_cookie("login", value: "foo&bar", path: "/", expires: Time.utc(2005, 10, 10, 5)) _status, headers, _body = @response.to_a assert_equal "user_name=david; path=/\nlogin=foo%26bar; path=/; expires=Mon, 10 Oct 2005 05:00:00 -0000", headers["Set-Cookie"] assert_equal({ "login" => "foo&bar", "user_name" => "david" }, @response.cookies) @@ -237,7 +237,7 @@ class ResponseTest < ActiveSupport::TestCase test "delete cookies" do @response.set_cookie("user_name", value: "david", path: "/") - @response.set_cookie("login", value: "foo&bar", path: "/", expires: Time.utc(2005, 10, 10,5)) + @response.set_cookie("login", value: "foo&bar", path: "/", expires: Time.utc(2005, 10, 10, 5)) @response.delete_cookie("login") assert_equal({ "user_name" => "david", "login" => nil }, @response.cookies) end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index c01065932a..92d323f292 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -1933,7 +1933,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest post :preview, on: :new end - resource :admin, path_names: { new: "novo" }, path: "administrador" do + resource :admin, path_names: { new: "novo" }, path: "administrador" do post :preview, on: :new end @@ -3736,7 +3736,7 @@ private https!(old_https) end - def verify_redirect(url, status=301) + def verify_redirect(url, status = 301) assert_equal status, @response.status assert_equal url, @response.headers["Location"] assert_equal expected_redirect_body(url), @response.body @@ -4163,7 +4163,7 @@ class TestRedirectInterpolation < ActionDispatch::IntegrationTest end private - def verify_redirect(url, status=301) + def verify_redirect(url, status = 301) assert_equal status, @response.status assert_equal url, @response.headers["Location"] assert_equal expected_redirect_body(url), @response.body @@ -4696,15 +4696,15 @@ class TestUrlGenerationErrors < ActionDispatch::IntegrationTest end test "url helpers raise message with mixed parameters when generation fails" do - url, missing = { action: "show", controller: "products", id: nil, "id"=>"url-tested" }, [:id] + url, missing = { action: "show", controller: "products", id: nil, "id" => "url-tested" }, [:id] message = "No route matches #{url.inspect}, possible unmatched constraints: #{missing.inspect}" # Optimized url helper - error = assert_raises(ActionController::UrlGenerationError) { product_path(nil, "id"=>"url-tested") } + error = assert_raises(ActionController::UrlGenerationError) { product_path(nil, "id" => "url-tested") } assert_equal message, error.message # Non-optimized url helper - error = assert_raises(ActionController::UrlGenerationError, message) { product_path(id: nil, "id"=>"url-tested") } + error = assert_raises(ActionController::UrlGenerationError, message) { product_path(id: nil, "id" => "url-tested") } assert_equal message, error.message end end diff --git a/actionpack/test/dispatch/static_test.rb b/actionpack/test/dispatch/static_test.rb index aca70e180c..cdb905f298 100644 --- a/actionpack/test/dispatch/static_test.rb +++ b/actionpack/test/dispatch/static_test.rb @@ -143,16 +143,16 @@ module StaticTests assert_equal "Accept-Encoding", response.headers["Vary"] assert_equal "gzip", response.headers["Content-Encoding"] - response = get(file_name, "HTTP_ACCEPT_ENCODING" => "Gzip") - assert_gzip file_name, response + response = get(file_name, "HTTP_ACCEPT_ENCODING" => "Gzip") + assert_gzip file_name, response - response = get(file_name, "HTTP_ACCEPT_ENCODING" => "GZIP") - assert_gzip file_name, response + response = get(file_name, "HTTP_ACCEPT_ENCODING" => "GZIP") + assert_gzip file_name, response - response = get(file_name, "HTTP_ACCEPT_ENCODING" => "compress;q=0.5, gzip;q=1.0") - assert_gzip file_name, response + response = get(file_name, "HTTP_ACCEPT_ENCODING" => "compress;q=0.5, gzip;q=1.0") + assert_gzip file_name, response - response = get(file_name, "HTTP_ACCEPT_ENCODING" => "") + response = get(file_name, "HTTP_ACCEPT_ENCODING" => "") assert_not_equal "gzip", response.headers["Content-Encoding"] end @@ -166,7 +166,7 @@ module StaticTests def test_serves_gzip_with_propper_content_type_fallback file_name = "/gzip/foo.zoo" response = get(file_name, "HTTP_ACCEPT_ENCODING" => "gzip") - assert_gzip file_name, response + assert_gzip file_name, response default_response = get(file_name) # no gzip assert_equal default_response.headers["Content-Type"], response.headers["Content-Type"] @@ -269,14 +269,14 @@ class StaticTest < ActiveSupport::TestCase filename = "shared.html.erb" assert File.exist?(File.join(@root, "..", filename)) env = { - "REQUEST_METHOD"=>"GET", - "REQUEST_PATH"=>"/..%2F#{filename}", - "PATH_INFO"=>"/..%2F#{filename}", - "REQUEST_URI"=>"/..%2F#{filename}", - "HTTP_VERSION"=>"HTTP/1.1", - "SERVER_NAME"=>"localhost", - "SERVER_PORT"=>"8080", - "QUERY_STRING"=>"" + "REQUEST_METHOD" => "GET", + "REQUEST_PATH" => "/..%2F#{filename}", + "PATH_INFO" => "/..%2F#{filename}", + "REQUEST_URI" => "/..%2F#{filename}", + "HTTP_VERSION" => "HTTP/1.1", + "SERVER_NAME" => "localhost", + "SERVER_PORT" => "8080", + "QUERY_STRING" => "" } assert_equal(DummyApp.call(nil), @app.call(env)) end diff --git a/actionpack/test/dispatch/uploaded_file_test.rb b/actionpack/test/dispatch/uploaded_file_test.rb index 60d0246a68..51680216e4 100644 --- a/actionpack/test/dispatch/uploaded_file_test.rb +++ b/actionpack/test/dispatch/uploaded_file_test.rb @@ -58,25 +58,25 @@ module ActionDispatch end def test_delegates_close_to_tempfile - tf = Class.new { def close(unlink_now=false); "thunderhorse" end } + tf = Class.new { def close(unlink_now = false); "thunderhorse" end } uf = Http::UploadedFile.new(tempfile: tf.new) assert_equal "thunderhorse", uf.close end def test_close_accepts_parameter - tf = Class.new { def close(unlink_now=false); "thunderhorse: #{unlink_now}" end } + tf = Class.new { def close(unlink_now = false); "thunderhorse: #{unlink_now}" end } uf = Http::UploadedFile.new(tempfile: tf.new) assert_equal "thunderhorse: true", uf.close(true) end def test_delegates_read_to_tempfile - tf = Class.new { def read(length=nil, buffer=nil); "thunderhorse" end } + tf = Class.new { def read(length = nil, buffer = nil); "thunderhorse" end } uf = Http::UploadedFile.new(tempfile: tf.new) assert_equal "thunderhorse", uf.read end def test_delegates_read_to_tempfile_with_params - tf = Class.new { def read(length=nil, buffer=nil); [length, buffer] end } + tf = Class.new { def read(length = nil, buffer = nil); [length, buffer] end } uf = Http::UploadedFile.new(tempfile: tf.new) assert_equal %w{ thunder horse }, uf.read(*%w{ thunder horse }) end diff --git a/actionpack/test/fixtures/session_autoload_test/session_autoload_test/foo.rb b/actionpack/test/fixtures/session_autoload_test/session_autoload_test/foo.rb index cd0be6d1b5..18fa5cd923 100644 --- a/actionpack/test/fixtures/session_autoload_test/session_autoload_test/foo.rb +++ b/actionpack/test/fixtures/session_autoload_test/session_autoload_test/foo.rb @@ -1,6 +1,6 @@ module SessionAutoloadTest class Foo - def initialize(bar="baz") + def initialize(bar = "baz") @bar = bar end def inspect diff --git a/actionpack/test/journey/gtg/builder_test.rb b/actionpack/test/journey/gtg/builder_test.rb index 2b314cdd4e..aa8427b265 100644 --- a/actionpack/test/journey/gtg/builder_test.rb +++ b/actionpack/test/journey/gtg/builder_test.rb @@ -5,18 +5,18 @@ module ActionDispatch module GTG class TestBuilder < ActiveSupport::TestCase def test_following_states_multi - table = tt ["a|a"] + table = tt ["a|a"] assert_equal 1, table.move([0], "a").length end def test_following_states_multi_regexp - table = tt [":a|b"] + table = tt [":a|b"] assert_equal 1, table.move([0], "fooo").length assert_equal 2, table.move([0], "b").length end def test_multi_path - table = tt ["/:a/d", "/b/c"] + table = tt ["/:a/d", "/b/c"] [ [1, "/"], @@ -38,7 +38,7 @@ module ActionDispatch /articles/:id(.:format) } - sim = NFA::Simulator.new table + sim = NFA::Simulator.new table match = sim.match "/articles/new" assert_equal 2, match.memos.length @@ -52,7 +52,7 @@ module ActionDispatch /articles/new(.:format) } - sim = NFA::Simulator.new table + sim = NFA::Simulator.new table match = sim.match "/articles/new" assert_equal 2, match.memos.length diff --git a/actionpack/test/journey/gtg/transition_table_test.rb b/actionpack/test/journey/gtg/transition_table_test.rb index 4c8b5032eb..c7315c0338 100644 --- a/actionpack/test/journey/gtg/transition_table_test.rb +++ b/actionpack/test/journey/gtg/transition_table_test.rb @@ -92,7 +92,7 @@ module ActionDispatch private def asts(paths) - parser = Journey::Parser.new + parser = Journey::Parser.new paths.map { |x| ast = parser.parse x ast.each { |n| n.memo = ast } diff --git a/actionpack/test/journey/nfa/simulator_test.rb b/actionpack/test/journey/nfa/simulator_test.rb index 183c892a53..38f99398cb 100644 --- a/actionpack/test/journey/nfa/simulator_test.rb +++ b/actionpack/test/journey/nfa/simulator_test.rb @@ -80,7 +80,7 @@ module ActionDispatch ast = Nodes::Or.new routes - nfa = Journey::NFA::Builder.new ast + nfa = Journey::NFA::Builder.new ast sim = Simulator.new nfa.transition_table md = sim.match "/articles" assert_equal [asts.first], md.memos diff --git a/actionpack/test/journey/nfa/transition_table_test.rb b/actionpack/test/journey/nfa/transition_table_test.rb index f3cf36a064..0bc6bc1cf8 100644 --- a/actionpack/test/journey/nfa/transition_table_test.rb +++ b/actionpack/test/journey/nfa/transition_table_test.rb @@ -53,10 +53,10 @@ module ActionDispatch end def test_alphabet - table = tt "a|:a" + table = tt "a|:a" assert_equal [/[^\.\/\?]+/, "a"], table.alphabet - table = tt "a|a" + table = tt "a|a" assert_equal ["a"], table.alphabet end diff --git a/actionpack/test/journey/route_test.rb b/actionpack/test/journey/route_test.rb index b6414fd101..d2a8163ffb 100644 --- a/actionpack/test/journey/route_test.rb +++ b/actionpack/test/journey/route_test.rb @@ -26,7 +26,7 @@ module ActionDispatch end def test_path_requirements_override_defaults - path = Path::Pattern.build(":name", { name: /love/ }, "/", true) + path = Path::Pattern.build(":name", { name: /love/ }, "/", true) defaults = { name: "tender" } route = Route.build("name", nil, path, {}, [], defaults) assert_equal(/love/, route.requirements[:name]) diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb index 7b5916eb72..f223a125a3 100644 --- a/actionpack/test/journey/router_test.rb +++ b/actionpack/test/journey/router_test.rb @@ -6,8 +6,8 @@ module ActionDispatch attr_reader :mapper, :routes, :route_set, :router def setup - @app = Routing::RouteSet::Dispatcher.new({}) - @route_set = ActionDispatch::Routing::RouteSet.new + @app = Routing::RouteSet::Dispatcher.new({}) + @route_set = ActionDispatch::Routing::RouteSet.new @routes = @route_set.router.routes @router = @route_set.router @formatter = @route_set.formatter @@ -116,7 +116,7 @@ module ActionDispatch end def test_clear_trailing_slash_from_script_name_on_root_unanchored_routes - app = lambda { |env| [200, {}, ["success!"]] } + app = lambda { |env| [200, {}, ["success!"]] } get "/weblog", to: app env = rack_env("SCRIPT_NAME" => "", "PATH_INFO" => "/weblog") @@ -233,7 +233,7 @@ module ActionDispatch nil, Hash[params], {}, - lambda { |k,v| parameterized << [k,v]; v }) + lambda { |k, v| parameterized << [k, v]; v }) assert_equal params.map(&:to_s).sort, parameterized.map(&:to_s).sort end @@ -289,15 +289,15 @@ module ActionDispatch relative_url_root: nil } redirection_parameters = { - "action"=>"show", + "action" => "show", } missing_key = "name" - missing_parameters ={ + missing_parameters = { missing_key => "task_1" } request_parameters = primarty_parameters.merge(redirection_parameters).merge(missing_parameters) - message = "No route matches #{Hash[request_parameters.sort_by { |k,v|k.to_s }].inspect}, missing required keys: #{[missing_key.to_sym].inspect}" + message = "No route matches #{Hash[request_parameters.sort_by { |k, v|k.to_s }].inspect}, missing required keys: #{[missing_key.to_sym].inspect}" error = assert_raises(ActionController::UrlGenerationError) do @formatter.generate( @@ -338,7 +338,7 @@ module ActionDispatch route = @routes.first env = rails_env "PATH_INFO" => request_path - called = false + called = false router.recognize(env) do |r, params| assert_equal route, r @@ -358,7 +358,7 @@ module ActionDispatch get "/:segment/*splat", to: "foo#bar" env = rails_env "PATH_INFO" => request_path - called = false + called = false route = @routes.first router.recognize(env) do |r, params| @@ -395,7 +395,7 @@ module ActionDispatch get "/books(/:action(.:format))", controller: "books" route = @routes.first - env = rails_env "PATH_INFO" => "/books/list.rss" + env = rails_env "PATH_INFO" => "/books/list.rss" expected = { controller: "books", action: "list", format: "rss" } called = false router.recognize(env) do |r, params| @@ -427,7 +427,7 @@ module ActionDispatch get "/books(/:action(.:format))", to: "foo#bar" env = rails_env "PATH_INFO" => "/books/list.rss", - "REQUEST_METHOD" => "HEAD" + "REQUEST_METHOD" => "HEAD" called = false router.recognize(env) do |r, params| diff --git a/actionpack/test/journey/routes_test.rb b/actionpack/test/journey/routes_test.rb index ca735ea022..d8db5ffad1 100644 --- a/actionpack/test/journey/routes_test.rb +++ b/actionpack/test/journey/routes_test.rb @@ -6,7 +6,7 @@ module ActionDispatch attr_reader :routes, :mapper def setup - @route_set = ActionDispatch::Routing::RouteSet.new + @route_set = ActionDispatch::Routing::RouteSet.new @routes = @route_set.router.routes @router = @route_set.router @mapper = ActionDispatch::Routing::Mapper.new @route_set diff --git a/actionpack/test/lib/controller/fake_models.rb b/actionpack/test/lib/controller/fake_models.rb index ce9522d12a..046b4167bb 100644 --- a/actionpack/test/lib/controller/fake_models.rb +++ b/actionpack/test/lib/controller/fake_models.rb @@ -6,7 +6,7 @@ class Customer < Struct.new(:name, :id) undef_method :to_json - def to_xml(options={}) + def to_xml(options = {}) if options[:builder] options[:builder].name name else @@ -14,7 +14,7 @@ class Customer < Struct.new(:name, :id) end end - def to_js(options={}) + def to_js(options = {}) "name: #{name.inspect}" end alias :to_text :to_js diff --git a/actionview/lib/action_view/context.rb b/actionview/lib/action_view/context.rb index ee263df484..31aa73a0cf 100644 --- a/actionview/lib/action_view/context.rb +++ b/actionview/lib/action_view/context.rb @@ -28,7 +28,7 @@ module ActionView # returns the correct buffer on +yield+. This is usually # overwritten by helpers to add more behavior. # :api: plugin - def _layout_for(name=nil) + def _layout_for(name = nil) name ||= :layout view_flow.get(name).html_safe end diff --git a/actionview/lib/action_view/flows.rb b/actionview/lib/action_view/flows.rb index 16874c1194..6d5f57a570 100644 --- a/actionview/lib/action_view/flows.rb +++ b/actionview/lib/action_view/flows.rb @@ -5,7 +5,7 @@ module ActionView attr_reader :content def initialize - @content = Hash.new { |h,k| h[k] = ActiveSupport::SafeBuffer.new } + @content = Hash.new { |h, k| h[k] = ActiveSupport::SafeBuffer.new } end # Called by _layout_for to read stored values. diff --git a/actionview/lib/action_view/helpers/asset_tag_helper.rb b/actionview/lib/action_view/helpers/asset_tag_helper.rb index 39fa11ccfd..4e4f4823e6 100644 --- a/actionview/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionview/lib/action_view/helpers/asset_tag_helper.rb @@ -168,7 +168,7 @@ module ActionView # # favicon_link_tag 'mb-icon.png', rel: 'apple-touch-icon', type: 'image/png' # # => - def favicon_link_tag(source="favicon.ico", options={}) + def favicon_link_tag(source = "favicon.ico", options = {}) tag("link", { rel: "shortcut icon", type: "image/x-icon", @@ -206,7 +206,7 @@ module ActionView # # => Icon # image_tag("/icons/icon.gif", data: { title: 'Rails Application' }) # # => - def image_tag(source, options={}) + def image_tag(source, options = {}) options = options.symbolize_keys check_for_image_tag_errors(options) diff --git a/actionview/lib/action_view/helpers/atom_feed_helper.rb b/actionview/lib/action_view/helpers/atom_feed_helper.rb index 09d243c46d..cef8098f67 100644 --- a/actionview/lib/action_view/helpers/atom_feed_helper.rb +++ b/actionview/lib/action_view/helpers/atom_feed_helper.rb @@ -103,7 +103,7 @@ module ActionView xml = options.delete(:xml) || eval("xml", block.binding) xml.instruct! if options[:instruct] - options[:instruct].each do |target,attrs| + options[:instruct].each do |target, attrs| if attrs.respond_to?(:keys) xml.instruct!(target, attrs) elsif attrs.respond_to?(:each) @@ -113,7 +113,7 @@ module ActionView end feed_opts = { "xml:lang" => options[:language] || "en-US", "xmlns" => "http://www.w3.org/2005/Atom" } - feed_opts.merge!(options).reject! { |k,v| !k.to_s.match(/^xml/) } + feed_opts.merge!(options).reject! { |k, v| !k.to_s.match(/^xml/) } xml.feed(feed_opts) do xml.id(options[:id] || "tag:#{request.host},#{options[:schema_date]}:#{request.fullpath.split(".")[0]}") diff --git a/actionview/lib/action_view/helpers/cache_helper.rb b/actionview/lib/action_view/helpers/cache_helper.rb index 5258a01144..87d341d862 100644 --- a/actionview/lib/action_view/helpers/cache_helper.rb +++ b/actionview/lib/action_view/helpers/cache_helper.rb @@ -218,7 +218,7 @@ module ActionView def fragment_name_with_digest(name, virtual_path) #:nodoc: virtual_path ||= @virtual_path if virtual_path - name = controller.url_for(name).split("://").last if name.is_a?(Hash) + name = controller.url_for(name).split("://").last if name.is_a?(Hash) digest = Digestor.digest name: virtual_path, finder: lookup_context, dependencies: view_cache_dependencies [ name, digest ] else diff --git a/actionview/lib/action_view/helpers/date_helper.rb b/actionview/lib/action_view/helpers/date_helper.rb index ea7259a25d..8ec351b360 100644 --- a/actionview/lib/action_view/helpers/date_helper.rb +++ b/actionview/lib/action_view/helpers/date_helper.rb @@ -98,7 +98,7 @@ module ActionView from_time = from_time.to_time if from_time.respond_to?(:to_time) to_time = to_time.to_time if to_time.respond_to?(:to_time) from_time, to_time = to_time, from_time if from_time > to_time - distance_in_minutes = ((to_time - from_time)/60.0).round + distance_in_minutes = ((to_time - from_time) / 60.0).round distance_in_seconds = (to_time - from_time).round I18n.with_options locale: options[:locale], scope: options[:scope] do |locale| diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb index 124a14f1d9..9bffe860db 100644 --- a/actionview/lib/action_view/helpers/form_helper.rb +++ b/actionview/lib/action_view/helpers/form_helper.rb @@ -1569,7 +1569,7 @@ module ActionView index = if options.has_key?(:index) options[:index] elsif defined?(@auto_index) - self.object_name = @object_name.to_s.sub(/\[\]$/,"") + self.object_name = @object_name.to_s.sub(/\[\]$/, "") @auto_index end @@ -1809,7 +1809,7 @@ module ActionView # post: # create: "Add %{model}" # - def submit(value=nil, options={}) + def submit(value = nil, options = {}) value, options = nil, value if value.is_a?(Hash) value ||= submit_default_value @template.submit_tag(value, options) diff --git a/actionview/lib/action_view/helpers/output_safety_helper.rb b/actionview/lib/action_view/helpers/output_safety_helper.rb index 8e63e59fac..9f1a890f6a 100644 --- a/actionview/lib/action_view/helpers/output_safety_helper.rb +++ b/actionview/lib/action_view/helpers/output_safety_helper.rb @@ -28,7 +28,7 @@ module ActionView #:nodoc: # safe_join([raw("

foo

"), raw("

bar

")], raw("
") # # => "

foo


bar

" # - def safe_join(array, sep=$,) + def safe_join(array, sep = $,) sep = ERB::Util.unwrapped_html_escape(sep) array.flatten.map! { |i| ERB::Util.unwrapped_html_escape(i) }.join(sep).html_safe diff --git a/actionview/lib/action_view/helpers/tags/base.rb b/actionview/lib/action_view/helpers/tags/base.rb index e3e3c8b109..cf8a6d6028 100644 --- a/actionview/lib/action_view/helpers/tags/base.rb +++ b/actionview/lib/action_view/helpers/tags/base.rb @@ -11,7 +11,7 @@ module ActionView @object_name, @method_name = object_name.to_s.dup, method_name.to_s.dup @template_object = template_object - @object_name.sub!(/\[\]$/,"") || @object_name.sub!(/\[\]\]$/,"]") + @object_name.sub!(/\[\]$/, "") || @object_name.sub!(/\[\]\]$/, "]") @object = retrieve_object(options.delete(:object)) @options = options @auto_index = Regexp.last_match ? retrieve_autoindex(Regexp.last_match.pre_match) : nil @@ -110,7 +110,7 @@ module ActionView end def sanitized_method_name - @sanitized_method_name ||= @method_name.sub(/\?$/,"") + @sanitized_method_name ||= @method_name.sub(/\?$/, "") end def sanitized_value(value) @@ -152,7 +152,7 @@ module ActionView end def name_and_id_index(options) - options.key?("index") ? options.delete("index") || "" : @auto_index + options.key?("index") ? options.delete("index") || "" : @auto_index end end end diff --git a/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb b/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb index 2a6bf49567..0359d4e65d 100644 --- a/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb +++ b/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb @@ -7,7 +7,7 @@ module ActionView include CollectionHelpers class CheckBoxBuilder < Builder # :nodoc: - def check_box(extra_html_options={}) + def check_box(extra_html_options = {}) html_options = extra_html_options.merge(@input_html_options) html_options[:multiple] = true @template_object.check_box(@object_name, @method_name, html_options, @value, nil) diff --git a/actionview/lib/action_view/helpers/tags/collection_helpers.rb b/actionview/lib/action_view/helpers/tags/collection_helpers.rb index 36575b2fd0..c8be392865 100644 --- a/actionview/lib/action_view/helpers/tags/collection_helpers.rb +++ b/actionview/lib/action_view/helpers/tags/collection_helpers.rb @@ -17,7 +17,7 @@ module ActionView @input_html_options = input_html_options end - def label(label_html_options={}, &block) + def label(label_html_options = {}, &block) html_options = @input_html_options.slice(:index, :namespace).merge(label_html_options) html_options[:for] ||= @input_html_options[:id] if @input_html_options[:id] diff --git a/actionview/lib/action_view/helpers/tags/collection_radio_buttons.rb b/actionview/lib/action_view/helpers/tags/collection_radio_buttons.rb index eed7941cd6..a5f72af9ff 100644 --- a/actionview/lib/action_view/helpers/tags/collection_radio_buttons.rb +++ b/actionview/lib/action_view/helpers/tags/collection_radio_buttons.rb @@ -7,7 +7,7 @@ module ActionView include CollectionHelpers class RadioButtonBuilder < Builder # :nodoc: - def radio_button(extra_html_options={}) + def radio_button(extra_html_options = {}) html_options = extra_html_options.merge(@input_html_options) @template_object.radio_button(@object_name, @method_name, @value, html_options) end diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb index 36b7515173..1277126995 100644 --- a/actionview/lib/action_view/helpers/url_helper.rb +++ b/actionview/lib/action_view/helpers/url_helper.rb @@ -563,7 +563,7 @@ module ActionView html_options = html_options.stringify_keys html_options["data-remote"] = "true".freeze if link_to_remote_options?(options) || link_to_remote_options?(html_options) - method = html_options.delete("method".freeze) + method = html_options.delete("method".freeze) add_method_to_attributes!(html_options, method) if method @@ -586,7 +586,7 @@ module ActionView html_options["data-method".freeze] = method end - def token_tag(token=nil, form_options: {}) + def token_tag(token = nil, form_options: {}) if token != false && protect_against_forgery? token ||= form_authenticity_token(form_options: form_options) tag(:input, type: "hidden", name: request_forgery_protection_token.to_s, value: token) diff --git a/actionview/lib/action_view/lookup_context.rb b/actionview/lib/action_view/lookup_context.rb index 9d6c762cc4..50faf1b8dd 100644 --- a/actionview/lib/action_view/lookup_context.rb +++ b/actionview/lib/action_view/lookup_context.rb @@ -204,7 +204,7 @@ module ActionView prefixes = prefixes.presence parts = name.to_s.split("/".freeze) parts.shift if parts.first.empty? - name = parts.pop + name = parts.pop return name, prefixes || [""] if parts.empty? diff --git a/actionview/lib/action_view/railtie.rb b/actionview/lib/action_view/railtie.rb index 42795ca2c7..68205cb720 100644 --- a/actionview/lib/action_view/railtie.rb +++ b/actionview/lib/action_view/railtie.rb @@ -23,7 +23,7 @@ module ActionView initializer "action_view.set_configs" do |app| ActiveSupport.on_load(:action_view) do - app.config.action_view.each do |k,v| + app.config.action_view.each do |k, v| send "#{k}=", v end end diff --git a/actionview/lib/action_view/renderer/partial_renderer.rb b/actionview/lib/action_view/renderer/partial_renderer.rb index c900da3277..bf338ec910 100644 --- a/actionview/lib/action_view/renderer/partial_renderer.rb +++ b/actionview/lib/action_view/renderer/partial_renderer.rb @@ -357,7 +357,7 @@ module ActionView # set to that string. Otherwise, the +options[:partial]+ object must # respond to +to_partial_path+ in order to setup the path. def setup(context, options, block) - @view = context + @view = context @options = options @block = block diff --git a/actionview/lib/action_view/rendering.rb b/actionview/lib/action_view/rendering.rb index 3ca7f9d220..b70e7239fc 100644 --- a/actionview/lib/action_view/rendering.rb +++ b/actionview/lib/action_view/rendering.rb @@ -113,7 +113,7 @@ module ActionView # Normalize args by converting render "foo" to render :action => "foo" and # render "foo/bar" to render :template => "foo/bar". # :api: private - def _normalize_args(action=nil, options={}) + def _normalize_args(action = nil, options = {}) options = super(action, options) case action when NilClass diff --git a/actionview/lib/action_view/template.rb b/actionview/lib/action_view/template.rb index 98571cf55e..2dcd6324db 100644 --- a/actionview/lib/action_view/template.rb +++ b/actionview/lib/action_view/template.rb @@ -151,7 +151,7 @@ module ActionView # This method is instrumented as "!render_template.action_view". Notice that # we use a bang in this instrumentation because you don't want to # consume this in production. This is only slow if it's being listened to. - def render(view, locals, buffer=nil, &block) + def render(view, locals, buffer = nil, &block) instrument_render_template do compile!(view) view.send(method_name, locals, buffer, &block) diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb index 5a2948d5a9..ed93ebc027 100644 --- a/actionview/lib/action_view/template/resolver.rb +++ b/actionview/lib/action_view/template/resolver.rb @@ -141,13 +141,13 @@ module ActionView end # Normalizes the arguments and passes it on to find_templates. - def find_all(name, prefix=nil, partial=false, details={}, key=nil, locals=[]) + def find_all(name, prefix = nil, partial = false, details = {}, key = nil, locals = []) cached(key, [name, prefix, partial], details, locals) do find_templates(name, prefix, partial, details) end end - def find_all_anywhere(name, prefix, partial=false, details={}, key=nil, locals=[]) + def find_all_anywhere(name, prefix, partial = false, details = {}, key = nil, locals = []) cached(key, [name, prefix, partial], details, locals) do find_templates(name, prefix, partial, details, true) end @@ -207,7 +207,7 @@ module ActionView EXTENSIONS = { locale: ".", formats: ".", variants: "+", handlers: "." } DEFAULT_PATTERN = ":prefix/:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}" - def initialize(pattern=nil) + def initialize(pattern = nil) @pattern = pattern || DEFAULT_PATTERN super() end @@ -297,7 +297,7 @@ module ActionView handler = Template.handler_for_extension(extension) format, variant = pieces.last.split(EXTENSIONS[:variants], 2) if pieces.last - format &&= Template::Types[format] + format &&= Template::Types[format] [handler, format, variant] end @@ -342,7 +342,7 @@ module ActionView # * :handlers - possible handlers (for example erb, haml, builder...) # class FileSystemResolver < PathResolver - def initialize(path, pattern=nil) + def initialize(path, pattern = nil) raise ArgumentError, "path already is a Resolver class" if path.is_a?(Resolver) super(pattern) @path = File.expand_path(path) diff --git a/actionview/lib/action_view/test_case.rb b/actionview/lib/action_view/test_case.rb index 3eb1ac0826..5fb7bb54b5 100644 --- a/actionview/lib/action_view/test_case.rb +++ b/actionview/lib/action_view/test_case.rb @@ -18,7 +18,7 @@ module ActionView end def controller_path=(path) - self.class.controller_path=(path) + self.class.controller_path = (path) end def initialize @@ -270,8 +270,8 @@ module ActionView end if routes && - ( routes.named_routes.route_defined?(selector) || - routes.mounted_helpers.method_defined?(selector) ) + (routes.named_routes.route_defined?(selector) || + routes.mounted_helpers.method_defined?(selector)) @controller.__send__(selector, *args) else super diff --git a/actionview/lib/action_view/testing/resolvers.rb b/actionview/lib/action_view/testing/resolvers.rb index f072664535..f4a7a9138c 100644 --- a/actionview/lib/action_view/testing/resolvers.rb +++ b/actionview/lib/action_view/testing/resolvers.rb @@ -8,7 +8,7 @@ module ActionView #:nodoc: class FixtureResolver < PathResolver attr_reader :hash - def initialize(hash = {}, pattern=nil) + def initialize(hash = {}, pattern = nil) super(pattern) @hash = hash end diff --git a/actionview/test/actionpack/controller/render_test.rb b/actionview/test/actionpack/controller/render_test.rb index cd89dceb45..b4a757d6b8 100644 --- a/actionview/test/actionpack/controller/render_test.rb +++ b/actionview/test/actionpack/controller/render_test.rb @@ -11,7 +11,7 @@ class Customer < Struct.new(:name, :id) undef_method :to_json - def to_xml(options={}) + def to_xml(options = {}) if options[:builder] options[:builder].name name else @@ -19,7 +19,7 @@ class Customer < Struct.new(:name, :id) end end - def to_js(options={}) + def to_js(options = {}) "name: #{name.inspect}" end alias :to_text :to_js diff --git a/actionview/test/activerecord/relation_cache_test.rb b/actionview/test/activerecord/relation_cache_test.rb index 880e80a8dc..43f7242ee9 100644 --- a/actionview/test/activerecord/relation_cache_test.rb +++ b/actionview/test/activerecord/relation_cache_test.rb @@ -1,6 +1,6 @@ require "active_record_unit" -class RelationCacheTest < ActionView::TestCase +class RelationCacheTest < ActionView::TestCase tests ActionView::Helpers::CacheHelper def setup diff --git a/actionview/test/lib/controller/fake_models.rb b/actionview/test/lib/controller/fake_models.rb index cc5f5c1d59..80649db88b 100644 --- a/actionview/test/lib/controller/fake_models.rb +++ b/actionview/test/lib/controller/fake_models.rb @@ -6,7 +6,7 @@ class Customer < Struct.new(:name, :id) undef_method :to_json - def to_xml(options={}) + def to_xml(options = {}) if options[:builder] options[:builder].name name else @@ -14,7 +14,7 @@ class Customer < Struct.new(:name, :id) end end - def to_js(options={}) + def to_js(options = {}) "name: #{name.inspect}" end alias :to_text :to_js diff --git a/actionview/test/template/date_helper_test.rb b/actionview/test/template/date_helper_test.rb index 44e5a8c346..a84ac18bee 100644 --- a/actionview/test/template/date_helper_test.rb +++ b/actionview/test/template/date_helper_test.rb @@ -18,7 +18,7 @@ class DateHelperTest < ActionView::TestCase end end - def assert_distance_of_time_in_words(from, to=nil) + def assert_distance_of_time_in_words(from, to = nil) to ||= from # 0..1 minute with :include_seconds => true @@ -167,9 +167,9 @@ class DateHelperTest < ActionView::TestCase def test_distance_in_words_with_integers assert_equal "1 minute", distance_of_time_in_words(59) - assert_equal "about 1 hour", distance_of_time_in_words(60*60) + assert_equal "about 1 hour", distance_of_time_in_words(60 * 60) assert_equal "1 minute", distance_of_time_in_words(0, 59) - assert_equal "about 1 hour", distance_of_time_in_words(60*60, 0) + assert_equal "about 1 hour", distance_of_time_in_words(60 * 60, 0) assert_equal "about 3 years", distance_of_time_in_words(10**8) assert_equal "about 3 years", distance_of_time_in_words(0, 10**8) end @@ -385,7 +385,7 @@ class DateHelperTest < ActionView::TestCase month_names = %w(Januar Februar Marts April Maj Juni Juli August September Oktober November December) expected = %(\n" assert_dom_equal expected, select_month(Time.mktime(2003, 8, 16), use_month_names: month_names) @@ -848,7 +848,7 @@ class DateHelperTest < ActionView::TestCase expected << %(\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n) expected << "\n" - expected << %(\n) expected << %(\n\n\n) expected << "\n" @@ -881,8 +881,8 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_no_start_year - expected = %(\n) + (Date.today.year - 5).upto(Date.today.year + 1) do |y| if y == Date.today.year expected << %(\n) else @@ -900,12 +900,12 @@ class DateHelperTest < ActionView::TestCase expected << "\n" assert_dom_equal expected, select_date( - Time.mktime(Date.today.year, 8, 16), end_year: Date.today.year+1, prefix: "date[first]" + Time.mktime(Date.today.year, 8, 16), end_year: Date.today.year + 1, prefix: "date[first]" ) end def test_select_date_with_no_end_year - expected = %(\n) 2003.upto(2008) do |y| if y == 2003 expected << %(\n) @@ -929,8 +929,8 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_no_start_or_end_year - expected = %(\n) + (Date.today.year - 5).upto(Date.today.year + 5) do |y| if y == Date.today.year expected << %(\n) else @@ -969,8 +969,8 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_zero_value_and_no_start_year - expected = %(\n) + (Date.today.year - 5).upto(Date.today.year + 1) { |y| expected << %(\n) } expected << "\n" expected << %(\n" - assert_dom_equal expected, select_date(0, end_year: Date.today.year+1, prefix: "date[first]") + assert_dom_equal expected, select_date(0, end_year: Date.today.year + 1, prefix: "date[first]") end def test_select_date_with_zero_value_and_no_end_year @@ -1002,8 +1002,8 @@ class DateHelperTest < ActionView::TestCase end def test_select_date_with_zero_value_and_no_start_and_end_year - expected = %(\n) + (Date.today.year - 5).upto(Date.today.year + 5) { |y| expected << %(\n) } expected << "\n" expected << %(\n) - (Date.today.year-5).upto(Date.today.year+5) { |y| expected << %(\n) } + expected = %(\n" expected << %(\n) - (Date.today.year-5).upto(Date.today.year+5) { |y| expected << %(\n) } + expected = %(\n" expected << %(\n) + expected = %(\n) expected << %(\n) expected << %(\n) @@ -1733,7 +1733,7 @@ class DateHelperTest < ActionView::TestCase end def test_select_time_with_custom_with_css_classes - expected = %(\n) + expected = %(\n) expected << %(\n) expected << %(\n) @@ -1851,7 +1851,7 @@ class DateHelperTest < ActionView::TestCase expected = "\n" - expected << %{\n} expected << %{\n\n\n\n\n\n\n\n\n\n\n\n} expected << "\n" @@ -1882,7 +1882,7 @@ class DateHelperTest < ActionView::TestCase expected = "\n" - expected << %{\n} expected << %{\n\n\n\n\n\n\n\n\n\n\n\n} expected << "\n" @@ -1901,7 +1901,7 @@ class DateHelperTest < ActionView::TestCase expected = "\n" - expected << %{\n} expected << %{\n\n\n\n\n\n\n\n\n\n\n\n} expected << "\n" @@ -2003,7 +2003,7 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Date.new(2004, 6, 15) - expected = %{\n} 1.upto(31) { |i| expected << %(\n) } expected << "\n" @@ -2011,7 +2011,7 @@ class DateHelperTest < ActionView::TestCase 1.upto(12) { |i| expected << %(\n) } expected << "\n" - expected << %{\n} 1999.upto(2009) { |i| expected << %(\n) } expected << "\n" @@ -2021,8 +2021,8 @@ class DateHelperTest < ActionView::TestCase def test_date_select_with_nil @post = Post.new - start_year = Time.now.year-5 - end_year = Time.now.year+5 + start_year = Time.now.year - 5 + end_year = Time.now.year + 5 expected = %{\n" @@ -2041,8 +2041,8 @@ class DateHelperTest < ActionView::TestCase def test_date_select_with_nil_and_blank @post = Post.new - start_year = Time.now.year-5 - end_year = Time.now.year+5 + start_year = Time.now.year - 5 + end_year = Time.now.year + 5 expected = %{' + "\n" - expected << %{\n} expected << "\n" start_year.upto(end_year) { |i| expected << %(\n) } expected << "\n" @@ -2084,8 +2084,8 @@ class DateHelperTest < ActionView::TestCase def test_date_select_with_nil_and_blank_and_discard_month @post = Post.new - start_year = Time.now.year-5 - end_year = Time.now.year+5 + start_year = Time.now.year - 5 + end_year = Time.now.year + 5 expected = %{\n) - (Date.today.year-5).upto(Date.today.year+1) { |y| expected << %(\n) } + expected = %(\n" expected << %(\n" - assert_dom_equal expected, select_date(0, end_year: Date.today.year+1, prefix: "date[first]") + assert_dom_equal expected, select_date(0, end_year: Date.today.year + 1, prefix: "date[first]") end def test_date_select_with_zero_value_and_no_end_year @@ -2936,8 +2936,8 @@ class DateHelperTest < ActionView::TestCase end def test_date_select_with_zero_value_and_no_start_and_end_year - expected = %(\n) + (Date.today.year - 5).upto(Date.today.year + 5) { |y| expected << %(\n) } expected << "\n" expected << %(\n) - (Date.today.year-5).upto(Date.today.year+5) { |y| expected << %(\n) } + expected = %(\n" expected << %(\n) - (Date.today.year-5).upto(Date.today.year+5) { |y| expected << %(\n) } + expected = %(\n" expected << %(', - check_box("post", "secret", "checked"=>"checked") + check_box("post", "secret", "checked" => "checked") ) end @@ -746,7 +746,7 @@ class FormHelperTest < ActionView::TestCase end def test_check_box_with_multiple_behavior - @post.comment_ids = [2,3] + @post.comment_ids = [2, 3] assert_dom_equal( '', check_box("post", "comment_ids", { multiple: true }, 1) @@ -758,7 +758,7 @@ class FormHelperTest < ActionView::TestCase end def test_check_box_with_multiple_behavior_and_index - @post.comment_ids = [2,3] + @post.comment_ids = [2, 3] assert_dom_equal( '', check_box("post", "comment_ids", { multiple: true, index: "foo" }, 1) @@ -1033,7 +1033,7 @@ class FormHelperTest < ActionView::TestCase def test_date_field_with_value_attr expected = %{} - value = Date.new(2013,6,29) + value = Date.new(2013, 6, 29) assert_dom_equal(expected, date_field("post", "written_on", value: value)) end @@ -1141,7 +1141,7 @@ class FormHelperTest < ActionView::TestCase def test_datetime_field_with_value_attr expected = %{} - value = DateTime.new(2013,6,29,13,37) + value = DateTime.new(2013, 6, 29, 13, 37) assert_dom_equal(expected, datetime_field("post", "written_on", value: value)) end @@ -1436,7 +1436,7 @@ class FormHelperTest < ActionView::TestCase ) assert_dom_equal( %{}, - text_field("post[]","title") + text_field("post[]", "title") ) assert_dom_equal( %{}, @@ -1559,10 +1559,10 @@ class FormHelperTest < ActionView::TestCase expected = whole_form("/posts", "new_post", "new_post") do "" + - "