diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-02-27 11:25:15 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-02-27 11:25:15 -0800 |
commit | 26306420a6f483f23172d84176bf6aa57548651f (patch) | |
tree | f3968bf35da8e33ae98d2b63eaa2cc0e401fe794 | |
parent | bf3ddfa28da8ca837ddce8c6744a6c1fd9a51243 (diff) | |
parent | 14e697cf2a1f2a4d223463839f6748fca4658bcf (diff) | |
download | rails-26306420a6f483f23172d84176bf6aa57548651f.tar.gz rails-26306420a6f483f23172d84176bf6aa57548651f.tar.bz2 rails-26306420a6f483f23172d84176bf6aa57548651f.zip |
Merge branch 'master' into adequaterecord
* master:
modify model generator warning message. refs [#174c9f0]
Replace "data store" with database [ci skip]
Return a hash rather than array from fetch_multi
Fix concerning module reference [ci skip]
Fixes docs typo in nested resource path helpers [skip ci]
Fix some validators when used on model instance
Pass strings to demodulize method
pass strings to the underscore method
speed up `underscore` in cases that don't need to do anything
pass the class name to `tableize`
[ci skip] Update list of files extensions in rake notes guide
Fix controller test not resetting @_url_options
21 files changed, 86 insertions, 48 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 68b5213bfc..66cef08b1b 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1 +1,6 @@ +* Fix URL generation in controller tests with request-dependent + `default_url_options` methods. + + *Tony Wooster* + Please check [4-1-stable](https://github.com/rails/rails/blob/4-1-stable/actionpack/CHANGELOG.md) for previous changes. diff --git a/actionpack/lib/action_controller/metal/testing.rb b/actionpack/lib/action_controller/metal/testing.rb index 0377b8c4cf..dd8da4b5dc 100644 --- a/actionpack/lib/action_controller/metal/testing.rb +++ b/actionpack/lib/action_controller/metal/testing.rb @@ -17,7 +17,6 @@ module ActionController def recycle! @_url_options = nil - self.response_body = nil self.formats = nil self.params = nil end diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index cf11ce1a9b..8650b75400 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -568,6 +568,7 @@ module ActionController name = @request.parameters[:action] + @controller.recycle! @controller.process(name) if cookies = @request.env['action_dispatch.cookies'] diff --git a/actionpack/test/controller/test_case_test.rb b/actionpack/test/controller/test_case_test.rb index 5ff4a383ec..fbc10baf21 100644 --- a/actionpack/test/controller/test_case_test.rb +++ b/actionpack/test/controller/test_case_test.rb @@ -163,6 +163,29 @@ XML end end + class DefaultUrlOptionsCachingController < ActionController::Base + before_filter { @dynamic_opt = 'opt' } + + def test_url_options_reset + render text: url_for(params) + end + + def default_url_options + if defined?(@dynamic_opt) + super.merge dynamic_opt: @dynamic_opt + else + super + end + end + end + + def test_url_options_reset + @controller = DefaultUrlOptionsCachingController.new + get :test_url_options_reset + assert_nil @request.params['dynamic_opt'] + assert_match(/dynamic_opt=opt/, @response.body) + end + def test_raw_post_handling params = Hash[:page, {:name => 'page name'}, 'some key', 123] post :render_raw_post, params.dup diff --git a/activemodel/lib/active_model/conversion.rb b/activemodel/lib/active_model/conversion.rb index 0a19ef686d..374265f0d8 100644 --- a/activemodel/lib/active_model/conversion.rb +++ b/activemodel/lib/active_model/conversion.rb @@ -83,8 +83,8 @@ module ActiveModel # internal method and should not be accessed directly. def _to_partial_path #:nodoc: @_to_partial_path ||= begin - element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self)) - collection = ActiveSupport::Inflector.tableize(self) + element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(name)) + collection = ActiveSupport::Inflector.tableize(name) "#{collection}/#{element}".freeze end end diff --git a/activemodel/lib/active_model/validations/with.rb b/activemodel/lib/active_model/validations/with.rb index 16bd6670d1..7022f9bee5 100644 --- a/activemodel/lib/active_model/validations/with.rb +++ b/activemodel/lib/active_model/validations/with.rb @@ -139,6 +139,8 @@ module ActiveModel # class version of this method for more information. def validates_with(*args, &block) options = args.extract_options! + options[:class] = self.class + args.each do |klass| validator = klass.new(options, &block) validator.validate(self) diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb index bee8ece992..cfce8fb8e6 100644 --- a/activemodel/test/cases/validations_test.rb +++ b/activemodel/test/cases/validations_test.rb @@ -284,10 +284,11 @@ class ValidationsTest < ActiveModel::TestCase auto = Automobile.new assert auto.invalid? - assert_equal 2, auto.errors.size + assert_equal 3, auto.errors.size auto.make = 'Toyota' auto.model = 'Corolla' + auto.approved = '1' assert auto.valid? end diff --git a/activemodel/test/models/automobile.rb b/activemodel/test/models/automobile.rb index ece644c40c..4df2fe8b3a 100644 --- a/activemodel/test/models/automobile.rb +++ b/activemodel/test/models/automobile.rb @@ -3,10 +3,11 @@ class Automobile validate :validations - attr_accessor :make, :model + attr_accessor :make, :model, :approved def validations validates_presence_of :make validates_length_of :model, within: 2..10 + validates_acceptance_of :approved, allow_nil: false end end diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index b1b35ed940..203928fb3f 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -64,7 +64,7 @@ module ActiveRecord end # Returns true if this object hasn't been saved yet -- that is, a record - # for the object doesn't exist in the data store yet; otherwise, returns false. + # for the object doesn't exist in the database yet; otherwise, returns false. def new_record? sync_with_transaction_state @new_record diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 7be22309ea..38a761384e 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,8 @@ +* Change the signature of `fetch_multi` to return a hash rather than an + array. This makes it consistent with the output of `read_multi`. + + *Parker Selbert* + * Introduce `Concern#class_methods` as a sleek alternative to clunky `module ClassMethods`. Add `Kernel#concern` to define at the toplevel without chunky `module Foo; extend ActiveSupport::Concern` boilerplate. diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index 2b7f5943b5..a627fa8651 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -357,20 +357,19 @@ module ActiveSupport # # Options are passed to the underlying cache implementation. # - # Returns an array with the data for each of the names. For example: + # Returns a hash with the data for each of the names. For example: # # cache.write("bim", "bam") - # cache.fetch_multi("bim", "boom") {|key| key * 2 } - # # => ["bam", "boomboom"] + # cache.fetch_multi("bim", "boom") { |key| key * 2 } + # # => { "bam" => "bam", "boom" => "boomboom" } # def fetch_multi(*names) options = names.extract_options! options = merged_options(options) - results = read_multi(*names, options) - names.map do |name| - results.fetch(name) do + names.each_with_object({}) do |name, memo| + memo[name] = results.fetch(name) do value = yield name write(name, value, options) value diff --git a/activesupport/lib/active_support/core_ext/kernel/concern.rb b/activesupport/lib/active_support/core_ext/kernel/concern.rb index c200a78d36..bf72caa058 100644 --- a/activesupport/lib/active_support/core_ext/kernel/concern.rb +++ b/activesupport/lib/active_support/core_ext/kernel/concern.rb @@ -3,7 +3,7 @@ require 'active_support/core_ext/module/concerning' module Kernel # A shortcut to define a toplevel concern, not within a module. # - # See ActiveSupport::CoreExt::Module::Concerning for more. + # See Module::Concerning for more. def concern(topic, &module_definition) Object.concern topic, &module_definition end diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index b642d87d76..a270c4452f 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -89,6 +89,7 @@ module ActiveSupport # # 'SSLError'.underscore.camelize # => "SslError" def underscore(camel_cased_word) + return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/ word = camel_cased_word.to_s.gsub('::', '/') word.gsub!(/(?:([A-Za-z\d])|^)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" } word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2') diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index c3c65cf805..18923f61d1 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -297,20 +297,21 @@ module CacheStoreBehavior @cache.write('foo', 'bar') @cache.write('fud', 'biz') - values = @cache.fetch_multi('foo', 'fu', 'fud') {|value| value * 2 } + values = @cache.fetch_multi('foo', 'fu', 'fud') { |value| value * 2 } - assert_equal(["bar", "fufu", "biz"], values) - assert_equal("fufu", @cache.read('fu')) + assert_equal({ 'foo' => 'bar', 'fu' => 'fufu', 'fud' => 'biz' }, values) + assert_equal('fufu', @cache.read('fu')) end def test_multi_with_objects - foo = stub(:title => "FOO!", :cache_key => "foo") - bar = stub(:cache_key => "bar") + foo = stub(:title => 'FOO!', :cache_key => 'foo') + bar = stub(:cache_key => 'bar') - @cache.write('bar', "BAM!") + @cache.write('bar', 'BAM!') - values = @cache.fetch_multi(foo, bar) {|object| object.title } - assert_equal(["FOO!", "BAM!"], values) + values = @cache.fetch_multi(foo, bar) { |object| object.title } + + assert_equal({ foo => 'FOO!', bar => 'BAM!' }, values) end def test_read_and_write_compressed_small_data diff --git a/guides/source/command_line.md b/guides/source/command_line.md index 3b80faec7f..8949ef4c78 100644 --- a/guides/source/command_line.md +++ b/guides/source/command_line.md @@ -411,7 +411,7 @@ The `doc:` namespace has the tools to generate documentation for your app, API d ### `notes` -`rake notes` will search through your code for comments beginning with FIXME, OPTIMIZE or TODO. The search is done in files with extension `.builder`, `.rb`, `.erb`, `.haml` and `.slim` for both default and custom annotations. +`rake notes` will search through your code for comments beginning with FIXME, OPTIMIZE or TODO. The search is done in files with extension `.builder`, `.rb`, `.erb`, `.haml`, `.slim`, `.css`, `.scss`, `.js`, `.coffee`, `.rake`, `.sass` and `.less` for both default and custom annotations. ```bash $ rake notes diff --git a/guides/source/routing.md b/guides/source/routing.md index 9c495bf09d..eef618f28d 100644 --- a/guides/source/routing.md +++ b/guides/source/routing.md @@ -352,15 +352,15 @@ end The comments resource here will have the following routes generated for it: -| HTTP Verb | Path | Controller#Action | Named Helper | -| --------- | -------------------------------------- | ----------------- | ------------------- | -| GET | /posts/:post_id/comments(.:format) | comments#index | post_comments | -| POST | /posts/:post_id/comments(.:format) | comments#create | post_comments | -| GET | /posts/:post_id/comments/new(.:format) | comments#new | new_post_comment | -| GET | /sekret/comments/:id/edit(.:format) | comments#edit | edit_comment | -| GET | /sekret/comments/:id(.:format) | comments#show | comment | -| PATCH/PUT | /sekret/comments/:id(.:format) | comments#update | comment | -| DELETE | /sekret/comments/:id(.:format) | comments#destroy | comment | +| HTTP Verb | Path | Controller#Action | Named Helper | +| --------- | -------------------------------------- | ----------------- | --------------------- | +| GET | /posts/:post_id/comments(.:format) | comments#index | post_comments_path | +| POST | /posts/:post_id/comments(.:format) | comments#create | post_comments_path | +| GET | /posts/:post_id/comments/new(.:format) | comments#new | new_post_comment_path | +| GET | /sekret/comments/:id/edit(.:format) | comments#edit | edit_comment_path | +| GET | /sekret/comments/:id(.:format) | comments#show | comment_path | +| PATCH/PUT | /sekret/comments/:id(.:format) | comments#update | comment_path | +| DELETE | /sekret/comments/:id(.:format) | comments#destroy | comment_path | The `:shallow_prefix` option adds the specified parameter to the named helpers: @@ -374,15 +374,15 @@ end The comments resource here will have the following routes generated for it: -| HTTP Verb | Path | Controller#Action | Named Helper | -| --------- | -------------------------------------- | ----------------- | ------------------- | -| GET | /posts/:post_id/comments(.:format) | comments#index | post_comments | -| POST | /posts/:post_id/comments(.:format) | comments#create | post_comments | -| GET | /posts/:post_id/comments/new(.:format) | comments#new | new_post_comment | -| GET | /comments/:id/edit(.:format) | comments#edit | edit_sekret_comment | -| GET | /comments/:id(.:format) | comments#show | sekret_comment | -| PATCH/PUT | /comments/:id(.:format) | comments#update | sekret_comment | -| DELETE | /comments/:id(.:format) | comments#destroy | sekret_comment | +| HTTP Verb | Path | Controller#Action | Named Helper | +| --------- | -------------------------------------- | ----------------- | ------------------------ | +| GET | /posts/:post_id/comments(.:format) | comments#index | post_comments_path | +| POST | /posts/:post_id/comments(.:format) | comments#create | post_comments_path | +| GET | /posts/:post_id/comments/new(.:format) | comments#new | new_post_comment_path | +| GET | /comments/:id/edit(.:format) | comments#edit | edit_sekret_comment_path | +| GET | /comments/:id(.:format) | comments#show | sekret_comment_path | +| PATCH/PUT | /comments/:id(.:format) | comments#update | sekret_comment_path | +| DELETE | /comments/:id(.:format) | comments#destroy | sekret_comment_path | ### Routing concerns diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 5c54cdaa70..5661094d95 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -371,7 +371,7 @@ module Rails end def isolate_namespace(mod) - engine_name(generate_railtie_name(mod)) + engine_name(generate_railtie_name(mod.name)) self.routes.default_scope = { module: ActiveSupport::Inflector.underscore(mod.name) } self.isolated = true diff --git a/railties/lib/rails/generators/model_helpers.rb b/railties/lib/rails/generators/model_helpers.rb index c4f45d344b..42c646543e 100644 --- a/railties/lib/rails/generators/model_helpers.rb +++ b/railties/lib/rails/generators/model_helpers.rb @@ -3,7 +3,7 @@ require 'rails/generators/active_model' module Rails module Generators module ModelHelpers # :nodoc: - PLURAL_MODEL_NAME_WARN_MESSAGE = "The model name '%s' was recognized as a plural, using the singular '%s'. " \ + PLURAL_MODEL_NAME_WARN_MESSAGE = "[WARNING] The model name '%s' was recognized as a plural, using the singular '%s' instead. " \ "Override with --force-plural or setup custom inflection rules for this noun before running the generator." mattr_accessor :skip_warn diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index c63e0c0758..8d7e804bdc 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -183,8 +183,8 @@ module Rails end protected - def generate_railtie_name(class_or_module) - ActiveSupport::Inflector.underscore(class_or_module).tr("/", "_") + def generate_railtie_name(string) + ActiveSupport::Inflector.underscore(string).tr("/", "_") end # If the class method does not have a method, then send the method call diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index bdf51b457c..b67cf02d7b 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -38,7 +38,7 @@ class ModelGeneratorTest < Rails::Generators::TestCase content = run_generator ["accounts".freeze] assert_file "app/models/account.rb", /class Account < ActiveRecord::Base/ assert_file "test/models/account_test.rb", /class AccountTest/ - assert_match(/The model name 'accounts' was recognized as a plural, using the singular 'account'\. Override with --force-plural or setup custom inflection rules for this noun before running the generator\./, content) + assert_match(/\[WARNING\] The model name 'accounts' was recognized as a plural, using the singular 'account' instead\. Override with --force-plural or setup custom inflection rules for this noun before running the generator\./, content) end def test_model_with_underscored_parent_option diff --git a/railties/test/generators/resource_generator_test.rb b/railties/test/generators/resource_generator_test.rb index 55c8d92ee8..dcdff22152 100644 --- a/railties/test/generators/resource_generator_test.rb +++ b/railties/test/generators/resource_generator_test.rb @@ -63,19 +63,19 @@ class ResourceGeneratorTest < Rails::Generators::TestCase content = run_generator ["accounts".freeze] assert_file "app/models/account.rb", /class Account < ActiveRecord::Base/ assert_file "test/models/account_test.rb", /class AccountTest/ - assert_match(/The model name 'accounts' was recognized as a plural, using the singular 'account'\. Override with --force-plural or setup custom inflection rules for this noun before running the generator\./, content) + assert_match(/\[WARNING\] The model name 'accounts' was recognized as a plural, using the singular 'account' instead\. Override with --force-plural or setup custom inflection rules for this noun before running the generator\./, content) end def test_plural_names_can_be_forced content = run_generator ["accounts", "--force-plural"] assert_file "app/models/accounts.rb", /class Accounts < ActiveRecord::Base/ assert_file "test/models/accounts_test.rb", /class AccountsTest/ - assert_no_match(/Plural version of the model detected/, content) + assert_no_match(/\[WARNING\]/, content) end def test_mass_nouns_do_not_throw_warnings content = run_generator ["sheep".freeze] - assert_no_match(/Plural version of the model detected/, content) + assert_no_match(/\[WARNING\]/, content) end def test_route_is_removed_on_revoke |