From abf3fef1e68eb89173b76a8bb3afcdda3f05f0a3 Mon Sep 17 00:00:00 2001 From: kennyj Date: Wed, 8 May 2013 01:24:50 +0900 Subject: Fixed a bug in when using has_many association with :inverse_of option and UUID primary key. --- activerecord/CHANGELOG.md | 5 +++ .../associations/collection_association.rb | 6 ++-- .../test/cases/adapters/postgresql/uuid_test.rb | 40 ++++++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 341e85c59e..54d5b4b165 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,8 @@ +* Fixed a bug in `ActiveRecord::Associations::CollectionAssociation#find_by_scan` when using has_many association with :inverse_of option and UUID primary key. + Fixes #10450. + + *kennyj* + * Confirm a record has not already been destroyed before decrementing counter cache. *Ben Tucker* diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 2a00ac1386..756c7c87ff 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -583,14 +583,14 @@ module ActiveRecord # specified, then #find scans the entire collection. def find_by_scan(*args) expects_array = args.first.kind_of?(Array) - ids = args.flatten.compact.map{ |arg| arg.to_i }.uniq + ids = args.flatten.compact.map{ |arg| arg.to_s }.uniq if ids.size == 1 id = ids.first - record = load_target.detect { |r| id == r.id } + record = load_target.detect { |r| id == r.id.to_s } expects_array ? [ record ] : record else - load_target.select { |r| ids.include?(r.id) } + load_target.select { |r| ids.include?(r.id.to_s) } end end diff --git a/activerecord/test/cases/adapters/postgresql/uuid_test.rb b/activerecord/test/cases/adapters/postgresql/uuid_test.rb index b573d48807..e4cf5d2ef6 100644 --- a/activerecord/test/cases/adapters/postgresql/uuid_test.rb +++ b/activerecord/test/cases/adapters/postgresql/uuid_test.rb @@ -93,3 +93,43 @@ class PostgresqlUUIDTestNilDefault < ActiveRecord::TestCase assert_nil col_desc["default"] end end + +class PostgresqlUUIDTestInverseOf < ActiveRecord::TestCase + class UuidPost < ActiveRecord::Base + self.table_name = 'pg_uuid_posts' + has_many :uuid_comments, inverse_of: :uuid_post + end + + class UuidComment < ActiveRecord::Base + self.table_name = 'pg_uuid_comments' + belongs_to :uuid_post + end + + def setup + @connection = ActiveRecord::Base.connection + @connection.reconnect! + + @connection.transaction do + @connection.create_table('pg_uuid_posts', id: :uuid) do |t| + t.string 'title' + end + @connection.create_table('pg_uuid_comments', id: :uuid) do |t| + t.uuid :uuid_post_id, default: 'uuid_generate_v4()' + t.string 'content' + end + end + end + + def teardown + @connection.transaction do + @connection.execute 'drop table if exists pg_uuid_comments' + @connection.execute 'drop table if exists pg_uuid_posts' + end + end + + def test_collection_association_with_uuid + post = UuidPost.create! + comment = post.uuid_comments.create! + assert post.uuid_comments.find(comment.id) + end +end -- cgit v1.2.3 From fa0cff484a8f0c99480b7545fc77610009723147 Mon Sep 17 00:00:00 2001 From: wangjohn Date: Tue, 28 May 2013 00:57:02 -0400 Subject: Adding documentation to +polymorphic_url+ concerning the options that it inherits from +url_for+. The way that +polymorhpic_url+ is built allows it to have options like +:anchor+, +:script_name+, etc. but this is currently not documented. --- .../lib/action_dispatch/routing/polymorphic_routes.rb | 13 +++++++++++++ actionpack/lib/action_view/helpers/url_helper.rb | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb index 6d3f8da932..2fb03f2712 100644 --- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb @@ -74,6 +74,19 @@ module ActionDispatch # * :routing_type - Allowed values are :path or :url. # Default is :url. # + # Also includes all the options from url_for. These include such + # things as :anchor or :trailing_slash. Example usage + # is given below: + # + # polymorphic_url([blog, post], anchor: 'my_anchor') + # # => "http://example.com/blogs/1/posts/1#my_anchor" + # polymorphic_url([blog, post], anchor: 'my_anchor', script_name: "/my_app") + # # => "http://example.com/my_app/blogs/1/posts/1#my_anchor" + # + # For all of these options, see the documentation for url_for. + # + # ==== Functionality + # # # an Article record # polymorphic_url(record) # same as article_url(record) # diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 8a83f6f356..b4d6fe8a55 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -92,8 +92,9 @@ module ActionView # ==== Data attributes # # * confirm: 'question?' - This will allow the unobtrusive JavaScript - # driver to prompt with the question specified. If the user accepts, the link is - # processed normally, otherwise no action is taken. + # driver to prompt with the question specified (in this case, the + # resulting text would be question?. If the user accepts, the + # link is processed normally, otherwise no action is taken. # * :disable_with - Value of this parameter will be # used as the value for a disabled version of the submit # button when the form is submitted. This feature is provided -- cgit v1.2.3 From 926c4b95e49cc65a1d7420392c95d2193b099965 Mon Sep 17 00:00:00 2001 From: wangjohn Date: Thu, 21 Mar 2013 17:10:17 -0400 Subject: Raising an error when nil or non-hash is passed to update_attributes. --- activerecord/CHANGELOG.md | 10 ++++++++++ activerecord/lib/active_record/attribute_assignment.rb | 4 +++- activerecord/test/cases/attribute_methods_test.rb | 2 +- activerecord/test/cases/persistence_test.rb | 15 +++++++++++---- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index e38d8aecf5..980d132051 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,13 @@ +* Calling `update_attributes` will now throw an `ArgumentError` whenever it + gets a `nil` argument. More specifically, it will throw an error if the + argument that it gets passed does not respond to to `stringify_keys`. + + `Example:` + + @my_comment.update_attributes() # => raises ArgumentError + + *John Wang* + * Remove Oracle / Sqlserver / Firebird database tasks that were deprecated in 4.0. *kennyj* diff --git a/activerecord/lib/active_record/attribute_assignment.rb b/activerecord/lib/active_record/attribute_assignment.rb index 75377bba57..53ce5f4952 100644 --- a/activerecord/lib/active_record/attribute_assignment.rb +++ b/activerecord/lib/active_record/attribute_assignment.rb @@ -13,7 +13,9 @@ module ActiveRecord # of this method is +false+ an ActiveModel::ForbiddenAttributesError # exception is raised. def assign_attributes(new_attributes) - return if new_attributes.blank? + if !new_attributes.respond_to?(:stringify_keys) + raise ArgumentError, "When assigning attributes, you must pass a hash as an argument." + end attributes = new_attributes.stringify_keys multi_parameter_attributes = [] diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index ee0150558d..a3a7d338d1 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -92,7 +92,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase def test_set_attributes_without_hash topic = Topic.new - assert_nothing_raised { topic.attributes = '' } + assert_raise(ArgumentError) { topic.attributes = '' } end def test_integers_as_nil diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index 30dc2a34c6..6cd3e2154e 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -419,10 +419,6 @@ class PersistenceTest < ActiveRecord::TestCase assert !Topic.find(1).approved? end - def test_update_attribute_does_not_choke_on_nil - assert Topic.find(1).update(nil) - end - def test_update_attribute_for_readonly_attribute minivan = Minivan.find('m1') assert_raises(ActiveRecord::ActiveRecordError) { minivan.update_attribute(:color, 'black') } @@ -701,6 +697,17 @@ class PersistenceTest < ActiveRecord::TestCase assert_equal topic.title, Topic.find(1234).title end + def test_update_attributes_parameters + topic = Topic.find(1) + assert_nothing_raised do + topic.update_attributes({}) + end + + assert_raises(ArgumentError) do + topic.update_attributes(nil) + end + end + def test_update! Reply.validates_presence_of(:title) reply = Reply.find(2) -- cgit v1.2.3 From 51e165808b8fdb0323d50aa7de973303224b7c7b Mon Sep 17 00:00:00 2001 From: kennyj Date: Wed, 10 Jul 2013 00:56:55 +0900 Subject: Fix typo. --- activerecord/test/cases/schema_dumper_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb index a48ae1036f..32f86f9c88 100644 --- a/activerecord/test/cases/schema_dumper_test.rb +++ b/activerecord/test/cases/schema_dumper_test.rb @@ -299,7 +299,7 @@ class SchemaDumperTest < ActiveRecord::TestCase def test_schema_dump_includes_uuid_shorthand_definition output = standard_dump - if %r{create_table "poistgresql_uuids"} =~ output + if %r{create_table "postgresql_uuids"} =~ output assert_match %r{t.uuid "guid"}, output end end -- cgit v1.2.3 From 4734e4ed3181bf8c8dca959078b7e6295e702719 Mon Sep 17 00:00:00 2001 From: kennyj Date: Wed, 10 Jul 2013 02:14:38 +0900 Subject: Migration dump UUID default functions to schema.rb. Fixes #10751. --- activerecord/CHANGELOG.md | 5 +++++ .../lib/active_record/connection_adapters/postgresql_adapter.rb | 9 ++++++--- activerecord/test/cases/adapters/postgresql/uuid_test.rb | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 1eb2f2d130..13c7bb85d0 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,8 @@ +* Migration dump UUID default functions to schema.rb. + Fixes #10751. + + *kennyj* + * Remove extra select and update queries on save/touch/destroy ActiveRecord model with belongs to reflection with option `touch: true`. diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 98126249df..5a9d93ef57 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -45,16 +45,18 @@ module ActiveRecord module ConnectionAdapters # PostgreSQL-specific extensions to column definitions in a table. class PostgreSQLColumn < Column #:nodoc: - attr_accessor :array + attr_accessor :array, :default_function # Instantiates a new PostgreSQL column definition in a table. def initialize(name, default, oid_type, sql_type = nil, null = true) @oid_type = oid_type + default_value = self.class.extract_value_from_default(default) + @default_function = default if !default_value && default && default =~ /.+\(.*\)/ if sql_type =~ /\[\]$/ @array = true - super(name, self.class.extract_value_from_default(default), sql_type[0..sql_type.length - 3], null) + super(name, default_value, sql_type[0..sql_type.length - 3], null) else @array = false - super(name, self.class.extract_value_from_default(default), sql_type, null) + super(name, default_value, sql_type, null) end end @@ -435,6 +437,7 @@ module ActiveRecord def prepare_column_options(column, types) spec = super spec[:array] = 'true' if column.respond_to?(:array) && column.array + spec[:default] = "\"#{column.default_function}\"" if column.respond_to?(:default_function) && column.default_function spec end diff --git a/activerecord/test/cases/adapters/postgresql/uuid_test.rb b/activerecord/test/cases/adapters/postgresql/uuid_test.rb index b573d48807..20d7254b82 100644 --- a/activerecord/test/cases/adapters/postgresql/uuid_test.rb +++ b/activerecord/test/cases/adapters/postgresql/uuid_test.rb @@ -61,6 +61,7 @@ class PostgresqlUUIDTest < ActiveRecord::TestCase schema = StringIO.new ActiveRecord::SchemaDumper.dump(@connection, schema) assert_match(/\bcreate_table "pg_uuids", id: :uuid\b/, schema.string) + assert_match(/t\.uuid "other_uuid", default: "uuid_generate_v4\(\)"/, schema.string) end end -- cgit v1.2.3 From f9e60c74b665954407f7de3265ae6996fc5e4635 Mon Sep 17 00:00:00 2001 From: Bogdan Gusiev Date: Thu, 18 Jul 2013 10:48:53 +0300 Subject: Disable ability to iterate over a Range of TimeWithZone --- activesupport/lib/active_support/core_ext/range.rb | 1 + .../lib/active_support/core_ext/range/each.rb | 24 ++++++++++++++++++++++ activesupport/test/core_ext/range_ext_test.rb | 22 ++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 activesupport/lib/active_support/core_ext/range/each.rb diff --git a/activesupport/lib/active_support/core_ext/range.rb b/activesupport/lib/active_support/core_ext/range.rb index 1d8b1ede5a..9368e81235 100644 --- a/activesupport/lib/active_support/core_ext/range.rb +++ b/activesupport/lib/active_support/core_ext/range.rb @@ -1,3 +1,4 @@ require 'active_support/core_ext/range/conversions' require 'active_support/core_ext/range/include_range' require 'active_support/core_ext/range/overlaps' +require 'active_support/core_ext/range/each' diff --git a/activesupport/lib/active_support/core_ext/range/each.rb b/activesupport/lib/active_support/core_ext/range/each.rb new file mode 100644 index 0000000000..d51ea2e944 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/range/each.rb @@ -0,0 +1,24 @@ +require 'active_support/core_ext/module/aliasing' +require 'active_support/core_ext/object/acts_like' + +class Range #:nodoc: + + def each_with_time_with_zone(&block) + ensure_iteration_allowed + each_without_time_with_zone(&block) + end + alias_method_chain :each, :time_with_zone + + def step_with_time_with_zone(n = 1, &block) + ensure_iteration_allowed + step_without_time_with_zone(n, &block) + end + alias_method_chain :step, :time_with_zone + + private + def ensure_iteration_allowed + if first.acts_like?(:time) + raise TypeError, "can't iterate from #{first.class}" + end + end +end diff --git a/activesupport/test/core_ext/range_ext_test.rb b/activesupport/test/core_ext/range_ext_test.rb index 2f8723a074..854b0a38bd 100644 --- a/activesupport/test/core_ext/range_ext_test.rb +++ b/activesupport/test/core_ext/range_ext_test.rb @@ -90,4 +90,26 @@ class RangeTest < ActiveSupport::TestCase time_range_2 = Time.utc(2005, 12, 10, 17, 31)..Time.utc(2005, 12, 10, 18, 00) assert !time_range_1.overlaps?(time_range_2) end + + def test_each_on_time_with_zone + twz = ActiveSupport::TimeWithZone.new(nil, ActiveSupport::TimeZone['Eastern Time (US & Canada)'] , Time.utc(2006,11,28,10,30)) + assert_raises TypeError do + ((twz - 1.hour)..twz).each {} + end + end + + def test_step_on_time_with_zone + twz = ActiveSupport::TimeWithZone.new(nil, ActiveSupport::TimeZone['Eastern Time (US & Canada)'] , Time.utc(2006,11,28,10,30)) + assert_raises TypeError do + ((twz - 1.hour)..twz).step(1) {} + end + end + + def test_include_on_time_with_zone + twz = ActiveSupport::TimeWithZone.new(nil, ActiveSupport::TimeZone['Eastern Time (US & Canada)'] , Time.utc(2006,11,28,10,30)) + assert_raises TypeError do + ((twz - 1.hour)..twz).include?(twz) + end + end + end -- cgit v1.2.3 From 9f82fb3f63015bbbd643bc624a49d98e97803681 Mon Sep 17 00:00:00 2001 From: wangjohn Date: Thu, 22 Aug 2013 17:18:46 -0400 Subject: Creating options for schema dumper. These options make it easier to change the config from ActiveRecord::Base to use something else inside of the SchemaDumper. --- activerecord/lib/active_record/schema_dumper.rb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb index 1181cc739e..8986d255cd 100644 --- a/activerecord/lib/active_record/schema_dumper.rb +++ b/activerecord/lib/active_record/schema_dumper.rb @@ -17,9 +17,19 @@ module ActiveRecord cattr_accessor :ignore_tables @@ignore_tables = [] - def self.dump(connection=ActiveRecord::Base.connection, stream=STDOUT) - new(connection).dump(stream) - stream + class << self + def dump(connection=ActiveRecord::Base.connection, stream=STDOUT, config = ActiveRecord::Base) + new(connection, generate_options(config)).dump(stream) + stream + end + + private + def generate_options(config) + { + table_name_prefix: config.table_name_prefix, + table_name_suffix: config.table_name_suffix + } + end end def dump(stream) @@ -32,10 +42,11 @@ module ActiveRecord private - def initialize(connection) + def initialize(connection, options = {}) @connection = connection @types = @connection.native_database_types @version = Migrator::current_version rescue nil + @options = options end def header(stream) @@ -201,7 +212,7 @@ HEADER end def remove_prefix_and_suffix(table) - table.gsub(/^(#{ActiveRecord::Base.table_name_prefix})(.+)(#{ActiveRecord::Base.table_name_suffix})$/, "\\2") + table.gsub(/^(#{@options[:table_name_prefix]})(.+)(#{@options[:table_name_suffix]})$/, "\\2") end end end -- cgit v1.2.3 From 5c224de9e110763ec7a0f01f5b604bcf81f40bfb Mon Sep 17 00:00:00 2001 From: Bogdan Gusiev Date: Wed, 28 Aug 2013 11:13:11 +0300 Subject: Rewrite journey routes formatter for performance --- actionpack/lib/action_dispatch/journey/visitors.rb | 46 +++++++++++----------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/actionpack/lib/action_dispatch/journey/visitors.rb b/actionpack/lib/action_dispatch/journey/visitors.rb index 0a8cb1b4d4..1fea8344e7 100644 --- a/actionpack/lib/action_dispatch/journey/visitors.rb +++ b/actionpack/lib/action_dispatch/journey/visitors.rb @@ -84,44 +84,44 @@ module ActionDispatch # Used for formatting urls (url_for) class Formatter < Visitor # :nodoc: - attr_reader :options, :consumed + attr_reader :options def initialize(options) @options = options - @consumed = {} end private - def visit_GROUP(node) - if consumed == options - nil - else - route = visit(node.left) - route.include?("\0") ? nil : route + def visit(node, optional = false) + case node.type + when :LITERAL, :SLASH, :DOT + node.left + when :STAR + visit(node.left) + when :GROUP + visit(node.left, true) + when :CAT + visit_CAT(node, optional) + when :SYMBOL + visit_SYMBOL(node) end end - def terminal(node) - node.left - end - - def binary(node) - [visit(node.left), visit(node.right)].join - end - - def nary(node) - node.children.map { |c| visit(c) }.join + def visit_CAT(node, optional) + left = visit(node.left, optional) + right = visit(node.right, optional) + if optional && !(right && left) + "" + else + left + right + end end def visit_SYMBOL(node) - key = node.to_sym - - if value = options[key] - consumed[key] = value + if value = options[node.to_sym] Router::Utils.escape_path(value) else - "\0" + nil end end end -- cgit v1.2.3 From 21e68853fd7470eada2b970e58e5d8ed05098246 Mon Sep 17 00:00:00 2001 From: wangjohn Date: Thu, 29 Aug 2013 00:33:23 -0500 Subject: Small refactoring changes to generators. Made a method name clearer (added a bang to the end to show that it mutates arguments) and extracted indentation into its own method. --- railties/lib/rails/generators/rails/app/app_generator.rb | 4 ++-- .../rails/generators/rails/controller/controller_generator.rb | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 041bfcb733..a336fd47f7 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -341,7 +341,7 @@ module Rails def handle_rails_rc! unless argv.delete("--no-rc") - insert_railsrc(railsrc) + insert_railsrc_into_argv!(railsrc) end end @@ -353,7 +353,7 @@ module Rails end end - def insert_railsrc(railsrc) + def insert_railsrc_into_argv!(railsrc) if File.exist?(railsrc) extra_args_string = File.read(railsrc) extra_args = extra_args_string.split(/\n+/).map {|l| l.split}.flatten diff --git a/railties/lib/rails/generators/rails/controller/controller_generator.rb b/railties/lib/rails/generators/rails/controller/controller_generator.rb index 822f35fb42..11dc598161 100644 --- a/railties/lib/rails/generators/rails/controller/controller_generator.rb +++ b/railties/lib/rails/generators/rails/controller/controller_generator.rb @@ -32,23 +32,27 @@ module Rails # namespace :foo do # namespace :bar do namespace_ladder = class_path.each_with_index.map do |ns, i| - %{#{" " * i * 2}namespace :#{ns} do\n } + %{#{indent(i)}namespace :#{ns} do\n } end.join # Create route # get "baz/index" - route = %{#{" " * depth * 2}get "#{file_name}/#{action}"\n} + route = %{#{indent(depth)}get "#{file_name}/#{action}"\n} # Create `end` ladder # end # end end_ladder = (1..depth).reverse_each.map do |i| - "#{" " * i * 2}end\n" + "#{indent(i)}end\n" end.join # Combine the 3 parts to generate complete route entry namespace_ladder + route + end_ladder end + + def indent(depth) + " " * depth * 2 + end end end end -- cgit v1.2.3 From d6efc1edc1ac8f0bd2cef76f0eb8e512c36f9932 Mon Sep 17 00:00:00 2001 From: claudiob Date: Sat, 14 Sep 2013 10:27:14 -0700 Subject: Remove unused AV helper fixtures from e10a2531 Several fixtures for helpers are removed. They were introduced in ActionView by @strzalek but never referenced in any test. --- actionview/test/fixtures/helpers/fun/games_helper.rb | 5 ----- actionview/test/fixtures/helpers/fun/pdf_helper.rb | 5 ----- actionview/test/fixtures/helpers/just_me_helper.rb | 3 --- actionview/test/fixtures/helpers/me_too_helper.rb | 3 --- 4 files changed, 16 deletions(-) delete mode 100644 actionview/test/fixtures/helpers/fun/games_helper.rb delete mode 100644 actionview/test/fixtures/helpers/fun/pdf_helper.rb delete mode 100644 actionview/test/fixtures/helpers/just_me_helper.rb delete mode 100644 actionview/test/fixtures/helpers/me_too_helper.rb diff --git a/actionview/test/fixtures/helpers/fun/games_helper.rb b/actionview/test/fixtures/helpers/fun/games_helper.rb deleted file mode 100644 index 3b7adce086..0000000000 --- a/actionview/test/fixtures/helpers/fun/games_helper.rb +++ /dev/null @@ -1,5 +0,0 @@ -module Fun - module GamesHelper - def stratego() "Iz guuut!" end - end -end \ No newline at end of file diff --git a/actionview/test/fixtures/helpers/fun/pdf_helper.rb b/actionview/test/fixtures/helpers/fun/pdf_helper.rb deleted file mode 100644 index 0171be8500..0000000000 --- a/actionview/test/fixtures/helpers/fun/pdf_helper.rb +++ /dev/null @@ -1,5 +0,0 @@ -module Fun - module PdfHelper - def foobar() 'baz' end - end -end diff --git a/actionview/test/fixtures/helpers/just_me_helper.rb b/actionview/test/fixtures/helpers/just_me_helper.rb deleted file mode 100644 index b140a7b9b4..0000000000 --- a/actionview/test/fixtures/helpers/just_me_helper.rb +++ /dev/null @@ -1,3 +0,0 @@ -module JustMeHelper - def me() "mine!" end -end \ No newline at end of file diff --git a/actionview/test/fixtures/helpers/me_too_helper.rb b/actionview/test/fixtures/helpers/me_too_helper.rb deleted file mode 100644 index ce56042143..0000000000 --- a/actionview/test/fixtures/helpers/me_too_helper.rb +++ /dev/null @@ -1,3 +0,0 @@ -module MeTooHelper - def me() "me too!" end -end \ No newline at end of file -- cgit v1.2.3 From 0f3124dd85b21abd7e1a5705f8574b62a6e46138 Mon Sep 17 00:00:00 2001 From: Jonathan Baudanza Date: Wed, 18 Sep 2013 19:01:59 -0700 Subject: NullSessionHash#destroy should be a no-op Previously it was raising a NilException --- .../lib/action_controller/metal/request_forgery_protection.rb | 3 +++ actionpack/test/controller/request_forgery_protection_test.rb | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/actionpack/lib/action_controller/metal/request_forgery_protection.rb b/actionpack/lib/action_controller/metal/request_forgery_protection.rb index 573c739da4..bd64b1f812 100644 --- a/actionpack/lib/action_controller/metal/request_forgery_protection.rb +++ b/actionpack/lib/action_controller/metal/request_forgery_protection.rb @@ -124,6 +124,9 @@ module ActionController #:nodoc: @loaded = true end + # no-op + def destroy; end + def exists? true end diff --git a/actionpack/test/controller/request_forgery_protection_test.rb b/actionpack/test/controller/request_forgery_protection_test.rb index c272e785c2..727db79241 100644 --- a/actionpack/test/controller/request_forgery_protection_test.rb +++ b/actionpack/test/controller/request_forgery_protection_test.rb @@ -78,6 +78,11 @@ class RequestForgeryProtectionControllerUsingNullSession < ActionController::Bas cookies.encrypted[:foo] = 'bar' render :nothing => true end + + def try_to_reset_session + reset_session + render :nothing => true + end end class FreeCookieController < RequestForgeryProtectionControllerUsingResetSession @@ -320,6 +325,11 @@ class RequestForgeryProtectionControllerUsingNullSessionTest < ActionController: post :encrypted assert_response :ok end + + test 'should allow reset_session' do + post :try_to_reset_session + assert_response :ok + end end class RequestForgeryProtectionControllerUsingExceptionTest < ActionController::TestCase -- cgit v1.2.3 From f76340e42b56dc09b42c2e9c209bb5c5d6869fac Mon Sep 17 00:00:00 2001 From: kennyj Date: Thu, 19 Sep 2013 12:37:35 +0900 Subject: Remove 1.8 compatible code --- actionpack/lib/action_dispatch/journey/router/utils.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionpack/lib/action_dispatch/journey/router/utils.rb b/actionpack/lib/action_dispatch/journey/router/utils.rb index 80011597aa..810f86db2f 100644 --- a/actionpack/lib/action_dispatch/journey/router/utils.rb +++ b/actionpack/lib/action_dispatch/journey/router/utils.rb @@ -36,7 +36,7 @@ module ActionDispatch UNSAFE_FRAGMENT = Regexp.new("[^#{safe_fragment}]", false).freeze end - Parser = URI.const_defined?(:Parser) ? URI::Parser.new : URI + Parser = URI::Parser.new def self.escape_path(path) Parser.escape(path.to_s, UriEscape::UNSAFE_SEGMENT) -- cgit v1.2.3 From 77e79ecd92acd43a282566e5d297b8e74dc14f05 Mon Sep 17 00:00:00 2001 From: Daniel Schierbeck Date: Mon, 15 Jul 2013 15:59:18 +0200 Subject: Bust the template digest cache key when details are changed Since the lookup details will influence which template is resolved, they need to be included in the cache key -- otherwise two different templates may erroneously share the same digest value. --- actionview/CHANGELOG.md | 6 ++++++ actionview/lib/action_view/digestor.rb | 5 ++++- actionview/test/template/digestor_test.rb | 30 +++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index 53142a835e..03fd6e7413 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -13,6 +13,12 @@ *Josh Lauer*, *Justin Ridgewell* +* Fixed a bug where the lookup details were not being taken into account + when caching the digest of a template - changes to the details now + cause a different cache key to be used. + + *Daniel Schierbeck* + * Added an `extname` hash option for `javascript_include_tag` method. Before: diff --git a/actionview/lib/action_view/digestor.rb b/actionview/lib/action_view/digestor.rb index 95c3200c81..af158a630b 100644 --- a/actionview/lib/action_view/digestor.rb +++ b/actionview/lib/action_view/digestor.rb @@ -10,7 +10,10 @@ module ActionView class << self def digest(name, format, finder, options = {}) - cache_key = ([name, format] + Array.wrap(options[:dependencies])).join('.') + details_key = finder.details_key.hash + dependencies = Array.wrap(options[:dependencies]) + cache_key = ([name, details_key, format] + dependencies).join('.') + # this is a correctly done double-checked locking idiom # (ThreadSafe::Cache's lookups have volatile semantics) @@cache[cache_key] || @@digest_monitor.synchronize do diff --git a/actionview/test/template/digestor_test.rb b/actionview/test/template/digestor_test.rb index c6608e214a..0f6b14a57d 100644 --- a/actionview/test/template/digestor_test.rb +++ b/actionview/test/template/digestor_test.rb @@ -15,6 +15,16 @@ end class FixtureFinder FIXTURES_DIR = "#{File.dirname(__FILE__)}/../fixtures/digestor" + attr_reader :details + + def initialize + @details = {} + end + + def details_key + details.hash + end + def find(logical_name, keys, partial, options) FixtureTemplate.new("digestor/#{partial ? logical_name.gsub(%r|/([^/]+)$|, '/_\1') : logical_name}.#{options[:formats].first}.erb") end @@ -140,6 +150,20 @@ class TemplateDigestorTest < ActionView::TestCase end end + def test_details_are_included_in_cache_key + # Cache the template digest. + old_digest = digest("events/_event") + + # Change the template; the cached digest remains unchanged. + change_template("events/_event") + + # The details are changed, so a new cache key is generated. + finder.details[:foo] = "bar" + + # The cache is busted. + assert_not_equal old_digest, digest("events/_event") + end + def test_extra_whitespace_in_render_partial assert_digest_difference("messages/edit") do change_template("messages/_form") @@ -220,7 +244,11 @@ class TemplateDigestorTest < ActionView::TestCase end def digest(template_name, options={}) - ActionView::Digestor.digest(template_name, :html, FixtureFinder.new, options) + ActionView::Digestor.digest(template_name, :html, finder, options) + end + + def finder + @finder ||= FixtureFinder.new end def change_template(template_name) -- cgit v1.2.3 From 1dacfbabf3bb1e0a9057dd2a016b1804e7fa38c0 Mon Sep 17 00:00:00 2001 From: Derek Prior Date: Fri, 26 Apr 2013 14:30:29 -0400 Subject: Fix incorrect assert_redirected_to failure message In some instances, `assert_redirected_to` assertion was returning an incorrect and misleading failure message when the assertion failed. This was due to a disconnect in how the assertion computes the redirect string for the failure message and how `redirect_to` computes the string that is actually used for redirection. I made the `_compute_redirect_to_loaction` method used by `redirect_to` public and call that from the method `assert_redirect_to` uses to calculate the URL. The reveals a new test failure due to the regex used by `_compute_redirect_to_location` allow `_` in the URL scheme. --- actionpack/CHANGELOG.md | 5 +++ .../lib/action_controller/metal/redirecting.rb | 39 +++++++++++----------- .../action_dispatch/testing/assertions/response.rb | 20 +++-------- .../test/controller/action_pack_assertions_test.rb | 18 ++++++++++ 4 files changed, 48 insertions(+), 34 deletions(-) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 63a208dbcf..a7ad07afd9 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,8 @@ +* Fix incorrect `assert_redirected_to` failure message for protocol-relative + URLs. + + *Derek Prior* + * Fix an issue where router can't recognize downcased url encoding path. Fixes #12269 diff --git a/actionpack/lib/action_controller/metal/redirecting.rb b/actionpack/lib/action_controller/metal/redirecting.rb index e9031f3fac..f07b19c5da 100644 --- a/actionpack/lib/action_controller/metal/redirecting.rb +++ b/actionpack/lib/action_controller/metal/redirecting.rb @@ -71,6 +71,26 @@ module ActionController self.response_body = "You are being redirected." end + def _compute_redirect_to_location(options) #:nodoc: + case options + # The scheme name consist of a letter followed by any combination of + # letters, digits, and the plus ("+"), period ("."), or hyphen ("-") + # characters; and is terminated by a colon (":"). + # See http://tools.ietf.org/html/rfc3986#section-3.1 + # The protocol relative scheme starts with a double slash "//". + when %r{\A(\w[\w+.-]*:|//).*} + options + when String + request.protocol + request.host_with_port + options + when :back + request.headers["Referer"] or raise RedirectBackError + when Proc + _compute_redirect_to_location options.call + else + url_for(options) + end.delete("\0\r\n") + end + private def _extract_redirect_to_status(options, response_status) if options.is_a?(Hash) && options.key?(:status) @@ -81,24 +101,5 @@ module ActionController 302 end end - - def _compute_redirect_to_location(options) - case options - # The scheme name consist of a letter followed by any combination of - # letters, digits, and the plus ("+"), period ("."), or hyphen ("-") - # characters; and is terminated by a colon (":"). - # The protocol relative scheme starts with a double slash "//" - when %r{\A(\w[\w+.-]*:|//).*} - options - when String - request.protocol + request.host_with_port + options - when :back - request.headers["Referer"] or raise RedirectBackError - when Proc - _compute_redirect_to_location options.call - else - url_for(options) - end.delete("\0\r\n") - end end end diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index 44ed0ac1f3..93f9fab9c2 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -67,21 +67,11 @@ module ActionDispatch end def normalize_argument_to_redirection(fragment) - normalized = case fragment - when Regexp - fragment - when %r{^\w[A-Za-z\d+.-]*:.*} - fragment - when String - @request.protocol + @request.host_with_port + fragment - when :back - raise RedirectBackError unless refer = @request.headers["Referer"] - refer - else - @controller.url_for(fragment) - end - - normalized.respond_to?(:delete) ? normalized.delete("\0\r\n") : normalized + if Regexp === fragment + fragment + else + @controller._compute_redirect_to_location(fragment) + end end end end diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 22a410db94..ba4cffcd3e 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -39,6 +39,8 @@ class ActionPackAssertionsController < ActionController::Base def redirect_external() redirect_to "http://www.rubyonrails.org"; end + def redirect_external_protocol_relative() redirect_to "//www.rubyonrails.org"; end + def response404() head '404 AWOL' end def response500() head '500 Sorry' end @@ -258,6 +260,19 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase end end + def test_assert_redirect_failure_message_with_protocol_relative_url + begin + process :redirect_external_protocol_relative + assert_redirected_to "/foo" + rescue ActiveSupport::TestCase::Assertion => ex + assert_no_match( + /#{request.protocol}#{request.host}\/\/www.rubyonrails.org/, + ex.message, + 'protocol relative url was incorrectly normalized' + ) + end + end + def test_template_objects_exist process :assign_this assert !@controller.instance_variable_defined?(:"@hi") @@ -309,6 +324,9 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase process :redirect_external assert_equal 'http://www.rubyonrails.org', @response.redirect_url + + process :redirect_external_protocol_relative + assert_equal '//www.rubyonrails.org', @response.redirect_url end def test_no_redirect_url -- cgit v1.2.3 From a78c10d3c787c56106353eb025ebb93ffcdb7bac Mon Sep 17 00:00:00 2001 From: Derek Prior Date: Thu, 19 Sep 2013 09:17:15 -0400 Subject: Fix regex used to find URI schemes in redirect_to The previous regex was allowing `_` in the URI scheme, which is not allowed by RFC 3986. This change brings the regex in line with the RFC. --- actionpack/CHANGELOG.md | 5 +++++ actionpack/lib/action_controller/metal/redirecting.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index a7ad07afd9..b0b75f6909 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,8 @@ +* Fix regex used to detect URI schemes in `redirect_to` to be consistent with + RFC 3986. + + *Derek Prior* + * Fix incorrect `assert_redirected_to` failure message for protocol-relative URLs. diff --git a/actionpack/lib/action_controller/metal/redirecting.rb b/actionpack/lib/action_controller/metal/redirecting.rb index f07b19c5da..ab14a61b97 100644 --- a/actionpack/lib/action_controller/metal/redirecting.rb +++ b/actionpack/lib/action_controller/metal/redirecting.rb @@ -78,7 +78,7 @@ module ActionController # characters; and is terminated by a colon (":"). # See http://tools.ietf.org/html/rfc3986#section-3.1 # The protocol relative scheme starts with a double slash "//". - when %r{\A(\w[\w+.-]*:|//).*} + when /\A([a-z][a-z\d\-+\.]*:|\/\/).*/i options when String request.protocol + request.host_with_port + options -- cgit v1.2.3 From 8b8f8cf41cdbaf6bf540e6d12f6989bd6bc534a9 Mon Sep 17 00:00:00 2001 From: Gaurish Sharma Date: Fri, 20 Sep 2013 10:16:19 +0530 Subject: Run Tests against JRuby master Many of the failing tests in rails test suite fail because of missing encoding support, example #11739 And according to recent announcement, lot of encoding issues have been fixed in current master. http://ruby.11.x6.nabble.com/Big-encoding-patches-landed-on-master-td4993719.html So lets test against JRuby master & incase there are still bugs. it would be easier to report them to JRuby. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7f5b2095e3..26268b1b5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ before_install: rvm: - 1.9.3 - 2.0.0 - - jruby-19mode + - jruby-head - rbx-19mode env: - "GEM=railties" -- cgit v1.2.3 From ebe3d5b1066b339daf2778be76e76e70f5205ab2 Mon Sep 17 00:00:00 2001 From: Gaurish Sharma Date: Fri, 20 Sep 2013 10:23:00 +0530 Subject: Allow failures in jruby-head --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 26268b1b5e..f0e9d570f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ env: - "GEM=ar:postgresql" matrix: allow_failures: - - rvm: jruby-19mode + - rvm: jruby-head - rvm: rbx-19mode notifications: email: false -- cgit v1.2.3 From 5923ae63210e4ab639a82a7ff20b4fad73ff76bb Mon Sep 17 00:00:00 2001 From: Hitendra Singh Date: Fri, 20 Sep 2013 11:07:41 +0530 Subject: Drying up method_missing code --- activesupport/lib/active_support/multibyte/chars.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb index a42e7f6542..3c0cf9f137 100644 --- a/activesupport/lib/active_support/multibyte/chars.rb +++ b/activesupport/lib/active_support/multibyte/chars.rb @@ -56,11 +56,10 @@ module ActiveSupport #:nodoc: # Forward all undefined methods to the wrapped string. def method_missing(method, *args, &block) + result = @wrapped_string.__send__(method, *args, &block) if method.to_s =~ /!$/ - result = @wrapped_string.__send__(method, *args, &block) self if result else - result = @wrapped_string.__send__(method, *args, &block) result.kind_of?(String) ? chars(result) : result end end -- cgit v1.2.3 From 1afe1aeba528249fc6be8bda4dad6a4dd243646d Mon Sep 17 00:00:00 2001 From: Hitendra Singh Date: Fri, 20 Sep 2013 12:37:51 +0530 Subject: Initializing Codepoint object with default values --- activesupport/bin/generate_tables | 6 ------ activesupport/lib/active_support/multibyte/unicode.rb | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/activesupport/bin/generate_tables b/activesupport/bin/generate_tables index 5fefa429df..f39e89b7d0 100755 --- a/activesupport/bin/generate_tables +++ b/activesupport/bin/generate_tables @@ -28,12 +28,6 @@ module ActiveSupport def initialize @ucd = Unicode::UnicodeDatabase.new - - default = Codepoint.new - default.combining_class = 0 - default.uppercase_mapping = 0 - default.lowercase_mapping = 0 - @ucd.codepoints = Hash.new(default) end def parse_codepoints(line) diff --git a/activesupport/lib/active_support/multibyte/unicode.rb b/activesupport/lib/active_support/multibyte/unicode.rb index 04e6b71580..1845c6ae38 100644 --- a/activesupport/lib/active_support/multibyte/unicode.rb +++ b/activesupport/lib/active_support/multibyte/unicode.rb @@ -287,6 +287,13 @@ module ActiveSupport class Codepoint attr_accessor :code, :combining_class, :decomp_type, :decomp_mapping, :uppercase_mapping, :lowercase_mapping + # Initializing Codepoint object with default values + def initialize + @combining_class = 0 + @uppercase_mapping = 0 + @lowercase_mapping = 0 + end + def swapcase_mapping uppercase_mapping > 0 ? uppercase_mapping : lowercase_mapping end -- cgit v1.2.3 From 76d36458eadcb32c233f44065fccfbbef9a58119 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Fri, 20 Sep 2013 09:50:07 +0200 Subject: mention controller test base class in testing guide. [ci skip] --- guides/source/testing.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/guides/source/testing.md b/guides/source/testing.md index 5b8829b89a..50115607c9 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -438,10 +438,12 @@ Now that we have used Rails scaffold generator for our `Post` resource, it has a Let me take you through one such test, `test_should_get_index` from the file `posts_controller_test.rb`. ```ruby -test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:posts) +class PostsControllerTest < ActionController::TestCase + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:posts) + end end ``` -- cgit v1.2.3 From d2824a347fd827bb0af3c16ffed5a3608b358ffc Mon Sep 17 00:00:00 2001 From: Daniel Schierbeck Date: Thu, 19 Sep 2013 11:03:58 +0200 Subject: Allow attaching to AS::Notifications namespace up front Before, you were required to attach *after* adding the methods to the class, since the attachment process needed the methods to be present. With this change, any new method will also be attached to the configured namespace. --- activesupport/CHANGELOG.md | 27 +++++++++++++++++ activesupport/lib/active_support/subscriber.rb | 27 +++++++++++++++-- activesupport/test/subscriber_test.rb | 40 ++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 activesupport/test/subscriber_test.rb diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 9ab81c73c8..08c4573b14 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,30 @@ +* Allow attaching event subscribers to ActiveSupport::Notifications namespaces + before they're defined. Essentially, this means instead of this: + + class JokeSubscriber < ActiveSupport::Subscriber + def sql(event) + puts "A rabbi and a priest walk into a bar..." + end + + # This call needs to happen *after* defining the methods. + attach_to "active_record" + end + + You can do this: + + class JokeSubscriber < ActiveSupport::Subscriber + # This is much easier to read! + attach_to "active_record" + + def sql(event) + puts "A rabbi and a priest walk into a bar..." + end + end + + This should make it easier to read and understand these subscribers. + + *Daniel Schierbeck* + * Add `Date#middle_of_day`, `DateTime#middle_of_day` and `Time#middle_of_day` methods. Also added `midday`, `noon`, `at_midday`, `at_noon` and `at_middle_of_day` as aliases. diff --git a/activesupport/lib/active_support/subscriber.rb b/activesupport/lib/active_support/subscriber.rb index 34c6f900c1..f2966f23fc 100644 --- a/activesupport/lib/active_support/subscriber.rb +++ b/activesupport/lib/active_support/subscriber.rb @@ -31,18 +31,41 @@ module ActiveSupport # Attach the subscriber to a namespace. def attach_to(namespace, subscriber=new, notifier=ActiveSupport::Notifications) + @namespace = namespace + @subscriber = subscriber + @notifier = notifier + subscribers << subscriber + # Add event subscribers for all existing methods on the class. subscriber.public_methods(false).each do |event| - next if %w{ start finish }.include?(event.to_s) + add_event_subscriber(event) + end + end - notifier.subscribe("#{event}.#{namespace}", subscriber) + # Adds event subscribers for all new methods added to the class. + def method_added(event) + # Only public methods are added as subscribers, and only if a notifier + # has been set up. This means that subscribers will only be set up for + # classes that call #attach_to. + if public_method_defined?(event) && notifier + add_event_subscriber(event) end end def subscribers @@subscribers ||= [] end + + protected + + attr_reader :subscriber, :notifier, :namespace + + def add_event_subscriber(event) + return if %w{ start finish }.include?(event.to_s) + + notifier.subscribe("#{event}.#{namespace}", subscriber) + end end def initialize diff --git a/activesupport/test/subscriber_test.rb b/activesupport/test/subscriber_test.rb new file mode 100644 index 0000000000..253411aa3d --- /dev/null +++ b/activesupport/test/subscriber_test.rb @@ -0,0 +1,40 @@ +require 'abstract_unit' +require 'active_support/subscriber' + +class TestSubscriber < ActiveSupport::Subscriber + attach_to :doodle + + cattr_reader :event + + def self.clear + @@event = nil + end + + def open_party(event) + @@event = event + end + + private + + def private_party(event) + @@event = event + end +end + +class SubscriberTest < ActiveSupport::TestCase + def setup + TestSubscriber.clear + end + + def test_attaches_subscribers + ActiveSupport::Notifications.instrument("open_party.doodle") + + assert_equal "open_party.doodle", TestSubscriber.event.name + end + + def test_does_not_attach_private_methods + ActiveSupport::Notifications.instrument("private_party.doodle") + + assert_nil TestSubscriber.event + end +end -- cgit v1.2.3 From 67153243e8cfee89a5e50e8c9f6d8732c0c0ae8e Mon Sep 17 00:00:00 2001 From: Gary Rennie Date: Fri, 20 Sep 2013 11:37:01 +0100 Subject: Fix: Remove broken link on rails 3 guide As raised in https://github.com/rails/rails/issues/12300 [ci skip] --- guides/source/3_0_release_notes.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/guides/source/3_0_release_notes.md b/guides/source/3_0_release_notes.md index d398cd680c..cf9d694de7 100644 --- a/guides/source/3_0_release_notes.md +++ b/guides/source/3_0_release_notes.md @@ -73,8 +73,6 @@ You can see an example of how that works at [Rails Upgrade is now an Official Pl Aside from Rails Upgrade tool, if you need more help, there are people on IRC and [rubyonrails-talk](http://groups.google.com/group/rubyonrails-talk) that are probably doing the same thing, possibly hitting the same issues. Be sure to blog your own experiences when upgrading so others can benefit from your knowledge! -More information - [The Path to Rails 3: Approaching the upgrade](http://omgbloglol.com/post/353978923/the-path-to-rails-3-approaching-the-upgrade) - Creating a Rails 3.0 application -------------------------------- -- cgit v1.2.3 From 135a1b4e41909e34148841f8c265e71022c5160d Mon Sep 17 00:00:00 2001 From: douglascalhoun Date: Sat, 21 Sep 2013 03:59:48 -0700 Subject: Removes redundant into text Looks like a remnant sentence fragment from the 3.2 guide. --- guides/source/command_line.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/guides/source/command_line.md b/guides/source/command_line.md index 6f792be8ae..ef645c3d2d 100644 --- a/guides/source/command_line.md +++ b/guides/source/command_line.md @@ -1,8 +1,6 @@ The Rails Command Line ====================== -Rails comes with every command line tool you'll need to - After reading this guide, you will know: * How to create a Rails application. -- cgit v1.2.3 From 4f0f5fc8b9bdc13f0aa37012443f6ea3c03a60e0 Mon Sep 17 00:00:00 2001 From: kennyj Date: Thu, 19 Sep 2013 12:58:11 +0900 Subject: [ci skip] Add some comment about downcase url encoded string. --- actionpack/lib/action_dispatch/journey/router/utils.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/actionpack/lib/action_dispatch/journey/router/utils.rb b/actionpack/lib/action_dispatch/journey/router/utils.rb index 810f86db2f..1edf86cd88 100644 --- a/actionpack/lib/action_dispatch/journey/router/utils.rb +++ b/actionpack/lib/action_dispatch/journey/router/utils.rb @@ -7,11 +7,13 @@ module ActionDispatch # Normalizes URI path. # # Strips off trailing slash and ensures there is a leading slash. + # Also converts downcase url encoded string to uppercase. # # normalize_path("/foo") # => "/foo" # normalize_path("/foo/") # => "/foo" # normalize_path("foo") # => "/foo" # normalize_path("") # => "/" + # normalize_path("/%ab") # => "/%AB" def self.normalize_path(path) path = "/#{path}" path.squeeze!('/') -- cgit v1.2.3 From 448aa840cb3897fdb2e96c59cc49f0a853972c01 Mon Sep 17 00:00:00 2001 From: Juanito Fatas Date: Sun, 22 Sep 2013 02:26:07 +0800 Subject: [ci skip] Fix a typo in Engines.md. --- guides/source/engines.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/source/engines.md b/guides/source/engines.md index ec51fb9234..48d2949539 100644 --- a/guides/source/engines.md +++ b/guides/source/engines.md @@ -950,7 +950,7 @@ INFO. Remember that in order to use languages like Sass or CoffeeScript, you sho There are some situations where your engine's assets are not required by the host application. For example, say that you've created an admin functionality that only exists for your engine. In this case, the host application doesn't need to require `admin.css` -or `admin.js`. Only the gem's admin layout needs these assets. It doesn't make sense for the host app to include `"blorg/admin.css"` in it's stylesheets. In this situation, you should explicitly define these assets for precompilation. +or `admin.js`. Only the gem's admin layout needs these assets. It doesn't make sense for the host app to include `"blorgh/admin.css"` in it's stylesheets. In this situation, you should explicitly define these assets for precompilation. This tells sprockets to add your engine assets when `rake assets:precompile` is ran. You can define assets for precompilation in `engine.rb` -- cgit v1.2.3 From 5adb4a4dc26b113f7087e70463ce6ea121e65eb0 Mon Sep 17 00:00:00 2001 From: kennyj Date: Sun, 22 Sep 2013 03:48:50 +0900 Subject: Fix typo. This test isn't executed in even postgresql. --- activerecord/test/cases/schema_dumper_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb index a48ae1036f..32f86f9c88 100644 --- a/activerecord/test/cases/schema_dumper_test.rb +++ b/activerecord/test/cases/schema_dumper_test.rb @@ -299,7 +299,7 @@ class SchemaDumperTest < ActiveRecord::TestCase def test_schema_dump_includes_uuid_shorthand_definition output = standard_dump - if %r{create_table "poistgresql_uuids"} =~ output + if %r{create_table "postgresql_uuids"} =~ output assert_match %r{t.uuid "guid"}, output end end -- cgit v1.2.3 From f7b294fcea8cad72231f13e9226cc18cda1cf43f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 21 Sep 2013 16:06:58 -0300 Subject: Add back options argument in the ActiveRecord::Base.initialize method This will make easier to hook protected_attributes gem in our code without making that gem fragile to change in Rails code base. Closes #12243 --- activerecord/lib/active_record/core.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 5e6fee52f7..7a1069fead 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -163,7 +163,7 @@ module ActiveRecord # ==== Example: # # Instantiates a single new object # User.new(first_name: 'Jamie') - def initialize(attributes = nil) + def initialize(attributes = nil, options = {}) defaults = self.class.column_defaults.dup defaults.each { |k, v| defaults[k] = v.dup if v.duplicable? } @@ -176,7 +176,9 @@ module ActiveRecord ensure_proper_type populate_with_current_scope_attributes - assign_attributes(attributes) if attributes + # +options+ argument is only needed to make protected_attributes gem easier to hook. + # Remove it when we drop support to this gem. + init_attributes(attributes, options) if attributes yield self if block_given? run_callbacks :initialize unless _initialize_callbacks.empty? @@ -432,5 +434,11 @@ module ActiveRecord @changed_attributes[attr] = orig_value if _field_changed?(attr, orig_value, @attributes[attr]) end end + + # This method is needed to make protected_attributes gem easier to hook. + # Remove it when we drop support to this gem. + def init_attributes(attributes, options) + assign_attributes(attributes) + end end end -- cgit v1.2.3 From 8e41af93a39cacbc813e66d38b05ffc98d412209 Mon Sep 17 00:00:00 2001 From: Juanito Fatas Date: Sun, 22 Sep 2013 16:09:43 +0800 Subject: [ci skip] Add a type modifier in migrations.md. --- guides/source/migrations.md | 1 + 1 file changed, 1 insertion(+) diff --git a/guides/source/migrations.md b/guides/source/migrations.md index 3c512e0390..1c858069f3 100644 --- a/guides/source/migrations.md +++ b/guides/source/migrations.md @@ -301,6 +301,7 @@ braces. You can use the following modifiers: * `precision` Defines the precision for the `decimal` fields * `scale` Defines the scale for the `decimal` fields * `polymorphic` Adds a `type` column for `belongs_to` associations +* `null` Allows or disallows `NULL` values in the column. For instance, running -- cgit v1.2.3 From 53d1779b67bc49cdcf8a60ac4607f9e4f2e66cda Mon Sep 17 00:00:00 2001 From: Juanito Fatas Date: Sun, 22 Sep 2013 19:00:38 +0800 Subject: [ci skip] Add missing migrate step in generating comment resource section. --- guides/source/engines.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/guides/source/engines.md b/guides/source/engines.md index 48d2949539..c71b728ef7 100644 --- a/guides/source/engines.md +++ b/guides/source/engines.md @@ -307,7 +307,11 @@ create test/models/blorgh/comment_test.rb create test/fixtures/blorgh/comments.yml ``` -This generator call will generate just the necessary model files it needs, namespacing the files under a `blorgh` directory and creating a model class called `Blorgh::Comment`. +This generator call will generate just the necessary model files it needs, namespacing the files under a `blorgh` directory and creating a model class called `Blorgh::Comment`. Now run the migration to create our blorgh_comments table: + +```bash +$ rake db:migrate +``` To show the comments on a post, edit `app/views/blorgh/posts/show.html.erb` and add this line before the "Edit" link: -- cgit v1.2.3 From 73b6095e13ef6be47fcabd65fcdd9c814bb9b375 Mon Sep 17 00:00:00 2001 From: Gaurish Sharma Date: Sun, 2 Jun 2013 18:24:07 +0530 Subject: Add notes about database connection pool [ci skip] --- guides/source/configuring.md | 11 +++++++++++ .../rails/app/templates/config/databases/postgresql.yml | 2 ++ 2 files changed, 13 insertions(+) diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 5f170474ee..c499cd0727 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -759,4 +759,15 @@ Since the connection pooling is handled inside of Active Record by default, all Any one request will check out a connection the first time it requires access to the database, after which it will check the connection back in, at the end of the request, meaning that the additional connection slot will be available again for the next request in the queue. +If you try to use more connections than are available, Active Record will block +and wait for a connection from the pool. When it cannot get connection, a timeout +error similar to given below will be thrown. + +```ruby +ActiveRecord::ConnectionTimeoutError - could not obtain a database connection within 5 seconds. The max pool size is currently 5; consider increasing it: +``` + +If you get the above error, you might want to increase the size of connection +pool by incrementing the `pool` option in `database.yml` + NOTE. If you have enabled `Rails.threadsafe!` mode then there could be a chance that several threads may be accessing multiple connections simultaneously. So depending on your current request load, you could very well have multiple threads contending for a limited amount of connections. diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml index eb569b7dab..0194dce6f3 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml @@ -55,6 +55,8 @@ production: adapter: postgresql encoding: unicode database: <%= app_name %>_production + # For details on connection pooling, see rails configration guide + # http://guides.rubyonrails.org/configuring.html#database-pooling pool: 5 username: <%= app_name %> password: -- cgit v1.2.3 From 70ff2568508151b89880b372f0f23fd328bd7027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sun, 22 Sep 2013 14:41:54 -0300 Subject: Give the credits [ci skip] --- activerecord/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 970e78b853..702182b8fd 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -15,6 +15,8 @@ Post.all.to_a.sort_by(&:id) + *Aaron Patterson* + * Fix: joins association, with defined in the scope block constraints by using several where constraints and at least of them is not `Arel::Nodes::Equality`, generates invalid SQL expression. -- cgit v1.2.3 From 0b0ac5d917ccfe3e48bc75456dbccf48de7f33d0 Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Sun, 22 Sep 2013 16:37:12 +0300 Subject: handle `:namespace` form option in collection labels --- actionview/CHANGELOG.md | 4 +++ .../action_view/helpers/tags/collection_helpers.rb | 3 +- actionview/lib/action_view/helpers/tags/label.rb | 1 + actionview/test/template/form_helper_test.rb | 36 ++++++++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index 03fd6e7413..1d91fdfe8d 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,7 @@ +* Handle `:namespace` form option in collection labels + + *Vasiliy Ermolovich* + * Fix `form_for` when both `namespace` and `as` options are present `as` option no longer overwrites `namespace` option when generating diff --git a/actionview/lib/action_view/helpers/tags/collection_helpers.rb b/actionview/lib/action_view/helpers/tags/collection_helpers.rb index 388dcf1f13..787039c82e 100644 --- a/actionview/lib/action_view/helpers/tags/collection_helpers.rb +++ b/actionview/lib/action_view/helpers/tags/collection_helpers.rb @@ -18,7 +18,8 @@ module ActionView end def label(label_html_options={}, &block) - @template_object.label(@object_name, @sanitized_attribute_name, @text, label_html_options, &block) + html_options = label_html_options.merge(@input_html_options) + @template_object.label(@object_name, @sanitized_attribute_name, @text, html_options, &block) end end diff --git a/actionview/lib/action_view/helpers/tags/label.rb b/actionview/lib/action_view/helpers/tags/label.rb index 35d3ba8434..180aa9ac27 100644 --- a/actionview/lib/action_view/helpers/tags/label.rb +++ b/actionview/lib/action_view/helpers/tags/label.rb @@ -30,6 +30,7 @@ module ActionView add_default_name_and_id_for_value(tag_value, name_and_id) options.delete("index") options.delete("namespace") + options.delete("multiple") options["for"] = name_and_id["id"] unless options.key?("for") if block_given? diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index 944884c9dd..3e8a2468ed 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -1282,6 +1282,24 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_form_with_namespace_and_with_collection_radio_buttons + post = Post.new + def post.active; false; end + + form_for(post, namespace: 'foo') do |f| + concat f.collection_radio_buttons(:active, [true, false], :to_s, :to_s) + end + + expected = whole_form("/posts", "foo_new_post", "new_post") do + "" + + "" + + "" + + "" + end + + assert_dom_equal expected, output_buffer + end + def test_form_for_with_collection_check_boxes post = Post.new def post.tag_ids; [1, 3]; end @@ -1361,6 +1379,24 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_form_with_namespace_and_with_collection_check_boxes + post = Post.new + def post.tag_ids; [1]; end + collection = [[1, "Tag 1"]] + + form_for(post, namespace: 'foo') do |f| + concat f.collection_check_boxes(:tag_ids, collection, :first, :last) + end + + expected = whole_form("/posts", "foo_new_post", "new_post") do + "" + + "" + + "" + end + + assert_dom_equal expected, output_buffer + end + def test_form_for_with_file_field_generate_multipart Post.send :attr_accessor, :file -- cgit v1.2.3 From 5f98bb402b657f785e6bf1a49e83d44c6d3aa062 Mon Sep 17 00:00:00 2001 From: schneems Date: Tue, 18 Jun 2013 15:24:00 -0500 Subject: Only output Server logs in Development Right now when you start a server via `rails s`, the logger gets extended so that it logs to the file system and also to stdout. This extension behavior is not "intelligent" and if the default logger is already set to output to stdout, then the contents will be received twice. To capture logs in accordance with http://www.12factor.net/logs some platforms require the logs to be sent to standard out. If a logger is set to stdout, and the server is started using `rails server` instead of another method (i.e. `thin start` etc.) then the app will produce double logs. This PR fixes the issue by only extending the logger to standard out in the development environment. So that in production you don't get double logs like this: ``` ActionView::Template::Error (wrong number of arguments (5 for 4)): 1: <% lang_index = 0 %> 2:
3: