Refactored method SpawnMethods#apply_finder_options #5517

wants to merge 238 commits into


None yet

I refactored the SpawnMethods#apply_finder_options a bit. Two things I have done:

  • The options :conditions, :include, :extend cannot map directly on a method in Relation::QueryMethods. I made the subsitution explicit instead of filtering out the keys from the loop and performing the methods one by one after.
  • Extracted the filtering of the invalid and empty options for readability.

All ActiveRecord and Rails tests pass.


I'd like to deprecate the three options: :conditions, :include, :extend. This would mean a lot of (fairly simple) changes in code, test and documentation. Let me know what you think of this - I could add it to the PR.

robinroestenburg and others added some commits Mar 19, 2012
@robinroestenburg robinroestenburg Refactored method SpawnMethods#apply_finder_options 2339f63
@icco icco Fixes bug with schema dumper when using with Padrino. 57b3e6f
@icco icco From @dasch's recommendation. cfcdb5b
@esad esad Add a missing require for 'active_support/deprecation' in Module#depr…
@icco icco Not checking for nil is apparently a lot faster. 77f6c47
@seamusabshere seamusabshere Possibly clearer way of getting rid of ` and "
Incidentally it's also faster...
>> a = 'hello "id` world'; Benchmark.realtime { 500_000.times {'`"', "") } }
=> 0.7388770580291748 
>> a = 'hello "id` world'; Benchmark.realtime { 500_000.times { a.gsub(/[`"]/, "") } }
=> 1.7843739986419678
Prasath Venkatraman Changing active model dirty module helper method to more appropriate …
…method with helper #4903

Changing active model dirty module helper method to more appropriate method with helper with Active Support Helper #4903

Changing active model dirty module helper method to more appropriate method with helper with Active Support Helper typo fixed #4903
@Floppy Floppy Change FILENAME_MAX_SIZE in FileStore to 228.
In order that temp filenames generated from it will fit in 255 chars. See rails/rails#4907
@seamusabshere seamusabshere thanks to @jurriaan fcd81a9
@vatrai vatrai content_tag used instead string for option 4487001
@lest lest use content_tag in button_to helper 5eab54f
@jlxw jlxw logger.silence is deprecated b89eb29
@courtland courtland Fix deleting from a HABTM join table upon destroying an object of a m…
…odel with optimistic locking enabled. Issue #5332.
@courtland courtland Tests for removing a HABTM association when optimistic locking is ena…
@vatrai vatrai remove unused require from AS/core_ext/class/delegating_att.rb 6cfb711
@nertzy nertzy Remove ActiveModel::Naming#partial_path
It was deprecated in 3.2
@bionicpill bionicpill Adding comma to correct syntax in comment. 8d20d01
@rafaelfranca rafaelfranca Remove code duplication 29b8fc8
Charles Brian Quinn Updates ActionMailer Base summary and fixes space in code example. ab6edc5
@tenderlove tenderlove bigdecimal can be duped on Ruby 2.0 35cf0be
@tenderlove tenderlove search private and protected methods for convert_key 49099ea
@dburt dburt Correct description of ['migrated_at > ?', 1.week.ago] from "more tha…
…n a week ago" to "more recently than a week ago."
@vijaydev vijaydev guides location has changed [ci skip] 8b81374
@kennyj kennyj Add missing require 37b9385
@tenderlove tenderlove probably should require the objects we monkey patch. 6acb73e
@MarkDBlackwell MarkDBlackwell [ci skip] Make guides more readable & consistent ac0cad1
@schneems schneems fix rails server support of RAILS_ENV variable
When launching rails server from the command line with a rails environment specified such as `rails server RAILS_ENV=production` an error would occur since rails will try to use `RAILS_ENV=production` as it's server. 

When launching rails with a specified server such as thin `rails server thin RAILS_ENV=production` no error will be thrown, but rails will not start up in the specified environment.

This fixes both of those cases
@mhfs mhfs Remove blank line from generated migration 0fdcfbf
@dhh dhh We dont need to merge in the parameters as thats all being reset by t…
…he rack headers (and its causing problems for Strong Parameters attempt of wrapping request.parameters because it will change in testing)
@xuanxu xuanxu Fixed-width font fix for instance variable 800f975
@travisjeffery travisjeffery Generate Migration Thats Adds Removed Index
When generating a migration that removes a field with an index, the down
will add both the field and its index.
@tenderlove tenderlove split subscribers based on pattern type ced943b
@jonleighton jonleighton no need for lvar 37769e0
@jonleighton jonleighton no need for cast b0d2d45
@jonleighton jonleighton Remove valid_scope_name? check - use ruby
scope is syntactic sugar for defining a class method. Ruby allows
redefining methods but emits a warning when run with -w. So let's
not implement our own logic for this. Users should run with -w if they
want to be warned about redefined methods.
@jonleighton jonleighton Avoid obscure & thing 8994273
@tenderlove tenderlove push the autoloads up to requires 635999f
@tenderlove tenderlove start / finish events are sent by the instrumenter b73b368
@tenderlove tenderlove evented subscribers work 87441c2
@tenderlove tenderlove evented listeners can subscribe to any message 6648321
@tenderlove tenderlove remove duplicate requires. thanks @atambo b4d56ed
@mhfs mhfs Avoid another blank line in generated migration and remove assertion …
…as per @spastorino request
@jonleighton jonleighton Deprecate eager-evaluated scopes.
Don't use this:

    scope :red, where(color: 'red')
    default_scope where(color: 'red')

Use this:

    scope :red, -> { where(color: 'red') }
    default_scope { where(color: 'red') }

The former has numerous issues. It is a common newbie gotcha to do
the following:

    scope :recent, where(published_at: - 2.weeks)

Or a more subtle variant:

    scope :recent, -> { where(published_at: - 2.weeks) }
    scope :recent_red, recent.where(color: 'red')

Eager scopes are also very complex to implement within Active
Record, and there are still bugs. For example, the following does
not do what you expect:

    scope :remove_conditions, except(:where)
    where(...).remove_conditions # => still has conditions
@joegoggins joegoggins Adding documentation for ActiveRecord::Base.abstract_class to clarify…
… a particular usecase for this feature (to allow you to use inheritance in ActiveRecord without using the STI table name
@kucaahbe kucaahbe improvements in "caching_with_rails" guide 46d120f
adman65 [engines] [ci-skip] Add example of precompiling engine assets af30132
adman65 Update config.assets.initialize_on_precompile warning to include engi…
…ne side affects
Anton Lindqvist Fixed missing space bug introduces in rails/rails@9299bfd. c04c940
@schneems schneems match rails console environment support, to server
rails server takes `-e` as an argument to specify RAILS_ENV, rails console currently does not have the same interface. This commit fixes this disparity so developers can manually specify `RAILS_ENV` or can pass in an environment with a `-e`.
@tenderlove tenderlove properly namespace the fixture exception 7e5454e
@rafaelfranca rafaelfranca Use the new scope syntax 7837753
@lest lest deprecate Proc#bind that can cause symbol memory leak cf97707
Fabián Rodríguez [getting started][ci skip] fix link to the code eba167f
@carlosantoniodasilva carlosantoniodasilva Properly deprecate the block argument in AV FormBuilder
Commit 56089ca986c767763f29159c8de0aa1ebabfd4d2 introduced a backward
incompatible change by changing the method signature of the FormBuilder.
This brings back the same method signature warning in case someone gives
a block to the builder.

More info: rails/rails@56089ca#commitcomment-1116166
@tenderlove tenderlove chdir before globbing so that we don't need to escape directory names.
fixes #5521
@tenderlove tenderlove oops, forgot to commit the tests! 💣 f4469f2
@drogus drogus Fix tests, when creating rescue handler, we need to check for arity now
Before it was handled by Proc.bind, but since Proc.bind has been
deprecated, this is no longer the case and returned handler
needs to match rescuer.
@Mik-die Mik-die :foreign_key option should be on has_many side of association 3dc32da
@tpope tpope Return an actual boolean from xml_http_request? 30ff7e3
@lest lest fix HashWithIndifferentAccess.[] method aa58b92
Senthil A [ci skip] updated bin/rails code in Rails Initialization Process guide 41ca32a
@arunagw arunagw removed warning: shadowing outer local variable - exception 4f37d5a
@vijaydev vijaydev spacing fix in guide [ci skip] 0314022
@avakhov avakhov ActionController caching small String#split optimization b0de757
@avakhov avakhov Fix AC actions caching comment bd1510d
@waseem waseem Use one 'be'. e1767f7
@pmatsinopoulos pmatsinopoulos Testing Template and Layout Example f48f069
@schneems schneems document `-e` argument for rails console
this adds documentation for -e flag which sets the environment of the rails console like the `rails server` command.
@pmatsinopoulos pmatsinopoulos Small layout correction 3586718
@pmatsinopoulos pmatsinopoulos Testing layout gotcha when view renders partial 130b9ef
@fxn fxn Revert "Return an actual boolean from xml_http_request?"
Reason: This commit changes code that was committed some year
and a half ago. The original code is an ordinary predicate
that delegates straight to a boolean operator with no further
unnecessaru adorments, as clearly explained in #5329.

This change also may confuse users who may now believe they can
rely now on singletons, while predicates in Rails rely on
standard Ruby semantics for boolean values and guarantee no
singletons whatsover.

This reverts commit 6349791d5aaf652631b29f1371701fc2985fda83.
@phiggins phiggins Remove useless conditional. 56665d4
@fxn fxn restores example depicting the use of true or false in regular font
There was an example here that mentioned reload_plugins?
but it was deleted. This commit puts another example back.
@jamie jamie Allow a defining custom member field on resources
By default, resources routes are created with :resource/:id. A model
defining to_param can make prettier urls by using something more
readable than an integer ID, but since the route picks it up as :id you
wind up with awkward User.find_by_username(params[:id]) calls.

By overriding the key to be used in @request.params you can be more
obvious in your intent.
@ddefrenne ddefrenne Fixed typo in path 60b29e3
@ddefrenne ddefrenne Made it a bit more clear where to run rails/server 12fe8e1
@tenderlove tenderlove test against ruby features in order to fix tests on Ruby 2.0 56d3cda
@tenderlove tenderlove no need to freeze things all the time 461a287
@chendo chendo Remove 'needless boolean casting'.
"Predicates in Rails rely on standard Ruby semantics for boolean values
and guarantee no singletons whatsoever." - @fxn
Lukasz Sarnacki ActiveModel::Name does not inherit from string 9115ea0
@nashby nashby String#titleize works properly with smart quotes, closes #5584 5d831d9
@lest lest apply form_for namespace option to date_select dbc2001
@gutenye gutenye ActiveRecord::Coders::YAMLColumn#dump should raise an error
closes #2737


@carlosantoniodasilva carlosantoniodasilva Return the same session data object when setting session id b09ebfa
@guilleiguaran guilleiguaran sprockets-rails 1.0.0 was released, remove git dependency from Gemfile 3fb3307
@tenderlove tenderlove Don't depend on ivars. Thanks @fesplugas cb05d9b
@tenderlove tenderlove stop using *args in order to simplify our constructor fcaad2c
@tenderlove tenderlove eliminating a branch we do not need. thanks @jeremy 8b98e9c
@tenderlove tenderlove still need to ensure the path is a directory d4c640a
@tenderlove tenderlove favor composition over inheritance b7a484b
@tenderlove tenderlove favor composition over inheritance 0ffdd8c
@carlosantoniodasilva carlosantoniodasilva Remove warning added by my own commit 🔥
Commit: 7a0cf2f5294e8bcef547642435636b394340a3e4
@xuanxu xuanxu Missing generated query for pluck method.
(and changed the use of true for a more database agnostic example).
Lukasz Sarnacki added shallow_prefix option description in documantation
It is in response for confusion in issue #5301
@drogus drogus Don't ignore non Enumerable values passed to sanitize (closes #5585)
When someone accidentally passes a string to sanitize like:

sanitize("<span>foo</span>", :tags => "b")

there is no indication that it's the wrong way and span
will not be removed.
@avakhov avakhov Proc objects for caches_page no need controller object 45c240a
@franckverrot franckverrot Rails.initialized? can be called at any time without raising an excep…
…tion [Closes #2507]


* `Rails.initialized=` has been removed
* `Rails.initialized?` and `Rails.application.initialized?` are now
* delegating to `MyApp::Application.initialized?`
@jigfox jigfox adds delegetion for eof? to AD::Http::UploadedFile
if you want to read the file you may need to ask if there is something
to read from
@arunagw arunagw removed unused variables 2d19b85
@drogus drogus If partial is rendered in controller, grab format from template
Previously `rendered_format` was set only based on mime types
passed in Accept header, which was wrong if first type from
Accept was different than rendered partial. The fix is to simply
move setting rendered_format to the place where template
is available and grab format from the template. If it fails
we can fallback to formats passed by Accept header.
levi and others added some commits Mar 30, 2012
@levi levi Introduce minor spelling corrections and fix broken markup tag. eb402b3
@lest lest use `symbolize_keys` instead of `dup.symbolize_keys!` 6c5cab0
@jonleighton jonleighton recurse in read_attribute we get caching / don't duplicate code 08e9e35
@spastorino spastorino Remove the leading \n added by textarea on assert_select 24d6c1a
@jonleighton jonleighton Add Relation#find_by and Relation#find_by! 90862ac
@jonleighton jonleighton remove irrelevant references to ARel 46f0d0c
@jonleighton jonleighton Update guides to reflect 0a12a5f8169685915cbb7bf4d0a7bb482f7f2fd2 d01e884
@jonleighton jonleighton fix typo. thanks @nertzy f85298c
@jonleighton jonleighton whitespace ✂️ ed3cfe7
@jonleighton jonleighton fix test a5db62e
@jonleighton jonleighton clear up duplication between Persistence#destroy and Locking#destroy fb295e6
@plashchynski plashchynski validate attribute names in class and module attribute accessors 8001d8d
@jonleighton jonleighton Fix #5667. Preloading should ignore scoping. f68c371
@tenderlove tenderlove use tsort_each to avoid intermediary array 7fd83bf
@avakhov avakhov Remove AC::RenderError class second declaration 6fd272a
@avakhov avakhov Remove obsolete reader from AC::MethodNotAllowed exception class 80a4c81
@rafbm rafbm Reorder bits in the Layouts and Rendering guide 709a149
@arunagw arunagw warning removed: (...) interpreted as grouped expression 7b8228b
@arunagw arunagw No more BufferedLogger so it can be LoggerTest 82a2287
@spastorino spastorino Remove not needed requires a47c879
@tenderlove tenderlove use undef_method to avoid NameError exceptions all the time 66a279d
@nertzy nertzy Don't include deprecation in AM::Naming anymore ffea167
@arunagw arunagw no more deprecation required. a3c53b9
@arunagw arunagw warning removed: `&' interpreted as argument prefix be6264b
@avakhov avakhov Block version of label should wrapped in field_with_errors in case of…
… error
@drogus drogus Usage file in generators shouldn't be fetched only based on source_root
In case `source_roout` is not set, `default_source_root` is used,
which includes also `templates` directory. If there is no `templates`
directory, `default_source_root` is not available and USAGE will not
be displayed. USAGE should be also checked based on default
directory excluding `templates`.
Erich Menge :success includes the whole 200 range, not just 200.
  # File lib/rack/response.rb, line 114
114:       def successful?;    @status >= 200 && @status < 300;       end
@avakhov avakhov Tests :if option of force_ssl method 1f36ac7
@avakhov avakhov Small #label method refactoring, thanks @rafaelfranca 48d2768
@hardipe hardipe Useless/Confusing method definition removed 43dd8df
@vijaydev vijaydev copy editing [ci skip] 50db35d
@lest lest add type option to atom feed entry builder
closes #5672
@e2 e2 Correct invalid route example [ci skip] f91c10a
@shime shime update to current rack middleware stack e379cfe
@shime shime update purpose of middleware a9ee43b
@Mik-die Mik-die parse <css> block as code (used in engines guide) 43be731
@vijaydev vijaydev Revert "parse <css> block as code (used in engines guide) "
This reverts commit c46374a9d949004761d71570a4d703838c694e74.

Reason: Changed engines guide not to use a css tag. <plain> will do
just fine.
@vijaydev vijaydev fix formatting in engines guide; also removed a couple of non-existen…
…t images [ci skip]
@morgoth morgoth removed unnecessary block when using fetch f5f6a60
@Mik-die Mik-die wrong link to getting started guide 23fcd2b
@romanvbabenko romanvbabenko Unnecessary uniqueness & force mapping has been removed at BacktraceC…
@waseem waseem Remove unnecessary articles. 8724f94
@avakhov avakhov Remove non-obligatory params in AC respond_to examples 945837d
@bolshakov bolshakov Fix typo 3ca1d71
@jurriaan jurriaan Updated/changed useless tr/gsubs d78e58e
@tpope tpope DATABASE_URL allows omission of database.yml e22b447
@tiegz tiegz minor elsif/else typo fix 05255a9
@picandocodigo picandocodigo Fixed small typo 223d2ae
@tenderlove tenderlove use File.binread to pull in the schema cache 249a107
Sandip Ransing rails 4 will support ruby version 1.9.4 or higher 300a662
Sandip Ransing typo mistake fixed
correction to server stop statement added
@fxn fxn the file update checker now also detects removed files 8da801a
@ethanmick ethanmick Updated migrations.textile to change :integer on line 807 to :boolean…
…, as it was earlier in the example. :flag is a boolean, not an integer. (defaults to false)
@shime shime update ActionPack README links 07273b6
@shime shime update ActionPack README links e62f757
@shime shime added example, removed blank lines 73b758b
@shime shime removed deprecated methods and middlewares 2d2352e
@vijaydev vijaydev Revert "rails 4 will support ruby version 1.9.4 or higher"
This reverts commit 0a35acb8b89603a3135852742f206af82ed61b57.

Reason: Let's cross the bridge when we reach there.
@avakhov avakhov Fix AC responder example 51cb490
@jmazin jmazin Update activemodel rdoc links 3afc739
@vijaydev vijaydev Revert "update ActionPack README links"
This reverts commit aeb228c5be5e8a1e7d79ccaef3833f8f35b00046.

Reason: The links are meant to be consumed in the api and not on GitHub.
@vijaydev vijaydev Revert "update ActionPack README links"
This reverts commit aeb228c5be5e8a1e7d79ccaef3833f8f35b00046.

Reason: The links are meant to be consumed in the api and not on GitHub.
@oscardelben oscardelben No need to extend ActiveSupport::Extend here 3919653
@ahoward ahoward carefully and quickly merge url_for options 439bee0
@htanata htanata Improve config.assets.initialize_on_precompile guide. 8dfd341
Sandip Ransing Small improvements added to getting started 2c917a8
@ahoward ahoward url_for: avoid a nil check. unroll a loop. handle most common case 1st. 5d2c4de
@nprncbl nprncbl Optimistic locking: lock_version needed type information. cd5b8a9
@avakhov avakhov Add AC record identifier example with not-persisted object 6991245
@carlosantoniodasilva carlosantoniodasilva Initialize variables in file update checker to avoid warnings 6b5c190
@carlosantoniodasilva carlosantoniodasilva Remove not used require from as to avoid circular requires 8349062
@chuyeow chuyeow Fix slightly awkward English in Action Caching section of Caching Wit…
…h Rails guide.

In particular, removed "pages that require to restrict access somehow" and shortened "Action Caching works like Page Caching except for the fact that the incoming web request does go from the webserver to the Rails stack and Action Pack so that before filters can be run on it before the cache is served".
@vijaydev vijaydev Revert "Update activemodel rdoc links"
This reverts commit ddb987551357d30301ab8cd99f4580988fa83340.

Reason: The links must be relative so that they will work both in edge
and stable api sites.
@vijaydev vijaydev fix boolean value in guide [ci skip] 9244d79
@vijaydev vijaydev minor fixes [ci skip] 16fb230
@vijaydev vijaydev lets not show too much output and shadow the intention [ci skip] 72f2567
@fxn fxn documents the contract for the argument of AD::Routing::RouteSet#url_for 2b9045e
@rafaelfranca rafaelfranca Fix url_for when options is nil
RouteSet#url_for was modifying the options hash that belong to the
@fxn fxn revises requires of some AS deprecation files d6c873c
@rafaelfranca rafaelfranca Make url_for work when option is nil and default_url_options has
stringified keys
Sandip Ransing Improvement to migration guide ff77024
Sandip Ransing Where migration can get wrong help added c6ea93f
@romanvbabenko romanvbabenko Class variables has been fixed to Singleton instance variables at Rai…
…ls module
@khustochka khustochka Update Custom Exception Handler section of Internationalization guide
The previous example with just_raise_that_exception method
stopped working because MissingTranslation is not an instance of
Exception class any more, but has a +to_exception+ method.

Also the cleaner way is to re-raise only the desired exception, passing
 everything else to the default ExceptionHandler.

 Additionally this re-raising conflicts with Pluralization backend thus
 we have to add a check that certain missing translation keys should
 be ignored allowing the backend to fall back to the default
 pluralization rule.
@khustochka khustochka Better class name d579905
@rosenfeld rosenfeld Documents that ActiveRecord instances also support []/[]= methods for…
… reading/writing attributes

Only write_attribute and read_attribute were documented and there was no mention to this alternative.
@anildigital anildigital Fix 'Everyday Git' link b041d99
@lest lest pass default value as argument to fetch 8221998
@radar radar Don't use arel_table in published_and_commented example in querying g…
@avakhov avakhov Fix example action dispatch in mime type a9b7cef
@vijaydev vijaydev copy editing [ci skip] a8895e8
@vijaydev vijaydev Revert "Where migration can get wrong help added"
This reverts commit b11113f924d2eb2acbe836954d17a02163f45275.
@vijaydev vijaydev Revert "Documents that ActiveRecord instances also support []/[]= met…
…hods for reading/writing attributes"

This reverts commit a49fe6ec2cb9f22a3b18d7db5ae2ee90325e9d09.

Reason: The existing doc about using self[:attribute] is clear enough.
@lest lest use extract_options! in cycle helper 363815b
@vijaydev vijaydev avoid empty api pages 70de340
@vijaydev vijaydev fix markup error [ci skip] 16f8637
@fxn fxn revises the regexp used in titleize
The regexp used in titleize matches saxon genitive
and other contractions, only to call capitalize on
the captured text and have the apostrophe upcased
which yields the apostrophe itself. It is more
clear that the regexp matches just what it has to
@fxn fxn adds a new test case for titleize c504206

Messed up the branch when rebasing...sorry, will open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment