aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
Commit message (Collapse)AuthorAgeFilesLines
...
| * | | Restore the override of numeric attributes properlyRyuta Kamizono2016-12-221-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | `attribute :world_population, :integer` is not a same with default decimal without scale type unless #26302 is merged. Should be `attribute :world_population, :big_integer` for now.
| * | | Extract `NumericData` model for testsRyuta Kamizono2016-09-271-0/+3
| | | | | | | | | | | | | | | | Currently `NumericData` model is defined some places.
* | | | Add missing `delegate :extending, to: :all`Ryuta Kamizono2017-06-011-0/+2
| | | |
* | | | Merge pull request #29098 from kamipo/fix_association_with_extension_issuesMatthew Draper2017-05-302-1/+11
|\ \ \ \ | | | | | | | | | | | | | | | Fix association with extension issues
| * | | | Fix association with extension issuesRyuta Kamizono2017-05-282-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes the following issues. * `association_scope` doesn't include `default_scope`. Should use `scope` instead. * We can't use `method_missing` for customizing existing method. * We can't use `relation_delegate_class` for sharing extensions. Should extend per association.
* | | | | Merge pull request #28969 from ↵Matthew Draper2017-05-281-1/+1
|\ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | kamipo/refactor_enum_to_use_value_instead_of_label Refactor enum to use `value` instead of `label` in the scope
| * | | | | Refactor enum to use `value` instead of `label` in the scopeRyuta Kamizono2017-05-071-1/+1
| |/ / / /
* | | | | Merge pull request #29003 from kamipo/delegate_ast_and_locked_to_arel_explicitlyMatthew Draper2017-05-281-0/+9
|\ \ \ \ \ | | | | | | | | | | | | Delegate `ast` and `locked` to `arel` explicitly
| * | | | | Delegate `ast` and `locked` to `arel` explicitlyRyuta Kamizono2017-05-061-0/+9
| |/ / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently `ast` and `locked` are used in the internal but delegating to `arel` is depend on `method_missing`. If a model class is defined these methods, `select_all` will be broken. It should be delegated to `arel` explicitly.
* / / / / Enable extending even if scope returns nilRyuta Kamizono2017-05-241-1/+1
|/ / / /
* | | | Add type caster to `RuntimeReflection#alias_name`Jon Moss2017-05-022-1/+2
| | | | | | | | | | | | | | | | | | | | Since we have been using this `Arel::Table` since 111ccc832bc977b15af12c14e7ca078dad2d4373, in order to properly handle queries, it's important that we properly type cast arguments.
* | | | Remove useless test caseRyuta Kamizono2017-04-261-8/+0
| | | | | | | | | | | | | | | | | | | | Cannot call private methods in `@klass` against `CollectionProxy` (inherites `Relation`) because using `public_send` in `method_missing`.
* | | | Mixin `CollectionProxy::DelegateExtending` after `ClassSpecificRelation`Ryuta Kamizono2017-04-221-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `ClassSpecificRelation` has `method_missing` and the `method_missing` is called first. if an associated class has the missing method in a relation, never reach to the `method_missing` in the `CollectionProxy`. I extracted `DelegateExtending` and included it to the delegate class that including `ClassSpecificRelation` to fix the issue. Fixes https://github.com/rails/rails/pull/28246#issuecomment-296033784.
* | | | Add a test case for #20802Ryuta Kamizono2017-04-131-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | The issue #20802 has been fixed in cc0b566. Closes #20802.
* | | | Fix extension method with dirty target in has_many associationsRyuta Kamizono2017-03-201-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Extension methods should not delegate to `scope` to respect dirty target on `CollectionProxy`. Fixes #28419.
* | | | Fix inspection behavior when the :id column is not primary keynamusyaka2017-02-091-0/+2
| |/ / |/| |
* | | Correct spellingBenjamin Fleischer2017-02-051-1/+1
| | | | | | | | | | | | | | | | | | | | | ``` go get -u github.com/client9/misspell/cmd/misspell misspell -w -error -source=text . ```
* | | Chain scope constraints should respect own table aliasRyuta Kamizono2017-02-013-0/+12
| | | | | | | | | | | | Fixes #27666.
* | | Deprecate reflection class name to accept a classKir Shatrov2017-01-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | The idea of `class_name` as an option of reflection is that passing a string would allow us to lazy autoload the class. Using `belongs_to :client, class_name: Customer` is eagerloading models more than necessary and creating possible circular dependencies.
* | | Privatize unneededly protected methods in Active RecordAkira Matsuda2017-01-051-3/+1
| | |
* | | `self.` is not needed when calling its own instance methodAkira Matsuda2017-01-051-1/+1
| | | | | | | | | | | | Actually, private methods cannot be called with `self.`, so it's not just redundant, it's a bad habit in Ruby
* | | Raise error when has_many through is defined before through associationChris Holmes2017-01-041-0/+6
| | | | | | | | | | | | | | | | | | | | | https://github.com/rails/rails/issues/26834 This change raises an error if a has_many through association is defined before the through association.
* | | Merge pull request #27335 from kamipo/remove_duplicated_model_definitionSean Griffin2017-01-031-0/+3
|\ \ \ | | | | | | | | Remove duplicated model class definitions in `test/cases/base_test.rb`
| * | | Remove duplicated model class definitions in `test/cases/base_test.rb`Ryuta Kamizono2016-12-121-0/+3
| | | |
* | | | Replace sleep with synchronizationMatthew Draper2017-01-021-1/+1
| | | |
* | | | Should not update children when the parent creation with no reasonRyuta Kamizono2016-12-291-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This issue was introduced with d849f42 to solve #19782. However, we can solve #19782 without causing the issue. It is enough to save only when necessary. Fixes #27338.
* | | | Privatize unneededly protected methods in Active Record testsAkira Matsuda2016-12-243-3/+3
| | | |
* | | | fix #create_fixtures when equal table names in different databasesJulia Lopez2016-12-211-0/+5
|/ / /
* | | Deprecate the behavior of AR::Dirty inside of after_(create|update|save) ↵Sean Griffin2016-11-011-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | callbacks We pretty frequently get bug reports that "dirty is broken inside of after callbacks". Intuitively they are correct. You'd expect `Model.after_save { puts changed? }; model.save` to do the same thing as `model.save; puts model.changed?`, but it does not. However, changing this goes much farther than just making the behavior more intuitive. There are a _ton_ of places inside of AR that can be drastically simplified with this change. Specifically, autosave associations, timestamps, touch, counter cache, and just about anything else in AR that works with callbacks have code to try to avoid "double save" bugs which we will be able to flat out remove with this change. We introduce two new sets of methods, both with names that are meant to be more explicit than dirty. The first set maintains the old behavior, and their names are meant to center that they are about changes that occurred during the save that just happened. They are equivalent to `previous_changes` when called outside of after callbacks, or once the deprecation cycle moves. The second set is the new behavior. Their names imply that they are talking about changes from the database representation. The fact that this is what we really care about became clear when looking at `BelongsTo.touch_record` when tests were failing. I'm unsure that this set of methods should be in the public API. Outside of after callbacks, they are equivalent to the existing methods on dirty. Dirty itself is not deprecated, nor are the methods inside of it. They will only emit the warning when called inside of after callbacks. The scope of this breakage is pretty large, but the migration path is simple. Given how much this can improve our codebase, and considering that it makes our API more intuitive, I think it's worth doing.
* | | Add more rubocop rules about whitespacesRafael Mendonça França2016-10-294-15/+15
| | |
* | | Don't skip in-memory insertion of associations when loaded in validateSean Griffin2016-09-291-6/+0
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This was caused by 6d0d83a33f59d9415685852cf77818c41e2e2700. While the bug it's trying to fix is handled if the association is loaded in an after_(create|save) callback, it doesn't handle any cases that load the association before the persistence takes place (validation, or before_* filters). Instead of caring about the timing of persistence, we can just ensure that we're not double adding the record instead. The test from that commit actually broke, but it was not because the bug has been re-introduced. It was because `Bulb` in our test suite is doing funky things that look like STI but isn't STI, so equality comparison didn't happen as the loaded model was of a different class. Fixes #26661.
* | Add tests for ActiveRecord::Enum#enum when suffix specifiedYosuke Kabuto2016-09-121-0/+1
| | | | | | | | Make name of attribute medium instead of normal
* | Merge pull request #24099 from k0kubun/preserve-readonlyRafael Mendonça França2016-08-181-0/+1
|\ \ | | | | | | | | | Preserve readonly flag only for readonly association
| * | Preserve readonly flag only for readonly associationTakashi Kokubun2016-07-301-0/+1
| | | | | | | | | | | | Fixes #24093
* | | Add three new rubocop rulesRafael Mendonça França2016-08-1610-32/+32
| | | | | | | | | | | | | | | | | | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* | | code gardening: removes redundant selfsXavier Noria2016-08-082-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | A few have been left for aesthetic reasons, but have made a pass and removed most of them. Note that if the method `foo` returns an array, `foo << 1` is a regular push, nothing to do with assignments, so no self required.
* | | Add `Style/EmptyLines` in `.rubocop.yml` and remove extra empty linesRyuta Kamizono2016-08-071-1/+0
| | |
* | | applies remaining conventions across the projectXavier Noria2016-08-068-13/+4
| | |
* | | normalizes indentation and whitespace across the projectXavier Noria2016-08-068-27/+26
| | |
* | | remove redundant curlies from hash argumentsXavier Noria2016-08-061-1/+1
| | |
* | | modernizes hash syntax in activerecordXavier Noria2016-08-0662-536/+535
| | |
* | | applies new string literal convention in activerecord/testXavier Noria2016-08-0658-307/+307
| | | | | | | | | | | | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* | | Don't assume all hashes are from multiparameter assignment in `composed_of`Sean Griffin2016-08-051-0/+1
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | So this bug is kinda funky. The code path is basically "if we weren't passed an instance of the class we compose to, and we have a converter, call that". Ignoring the hash case for a moment, everything after that was roughly intended to be the "else" clause, meaning that we are expected to have an instance of the class we compose to. Really, we should be blowing up in that case, as we can give a much better error message than what they user will likely get (e.g. `NameError: No method first for String` or something). Still, Ruby is duck typed, so if the object you're assigning responds to the same methods as the type you compose to, knock yourself out. The hash case was added in 36e9be8 to remove a bunch of special cased code from multiparameter assignment. I wrongly assumed that the only time we'd get a hash there is in that case. Multiparameter assignment will construct a very specific hash though, where the keys are integers, and we will have a set of keys covering `1..part.size` exactly. I'm pretty sure this could actually be passed around as an array, but that's a different story. Really I should convert this to something like `class MultiParameterAssignment < Hash; end`, which I might do soon. However for a change that I'm willing to backport to 4-2-stable, this is what I want to go with for the time being. Fixes #25978
* | Merge pull request #25767 from ↵Rafael França2016-07-271-0/+6
|\ \ | | | | | | | | | | | | kamipo/association_name_is_the_same_as_join_table_name Correctly return `associated_table` when `associated_with?` is true
| * | Correctly return `associated_table` when `associated_with?` is trueRyuta Kamizono2016-07-101-0/+6
| | | | | | | | | | | | | | | | | | | | | `AssociationQueryHandler` requires `association` initialized `TableMetadata` even if `table_name == arel_table.name`. Fixes #25689.
* | | Oracle TIMESTAMP sql type is associated with Rails `DateTime` type nowYasuo Honda2016-07-201-6/+0
|/ / | | | | | | | | | | - Refer https://github.com/rsim/oracle-enhanced/pull/845 Remove `set_date_columns` which has been deprecated in Oracle enhanced adapter - Refer https://github.com/rsim/oracle-enhanced/pull/869
* / Ensure hashes can be passed to attributes using `composed_of`Sean Griffin2016-05-311-1/+6
|/ | | | | | | | | | | This behavior was broken by 36e9be85. When the value is assigned directly, either through mass assignment or directly assigning a hash, the hash gets passed through to this writer method directly. While this is intended to handle certain cases, when an explicit converter has been provided, we should continue to use that instead. The positioning of the added guard caused the new behavior to override that case. Fixes #25210
* Fix undefined method `owners' for NullPreloader:ClassLadislav Smola2016-04-063-1/+11
| | | | | | | | | | | | | | * Fix undefined method `owners' for NullPreloader:Class Fixing undefined method `owners' for ActiveRecord::Associations::Preloader::NullPreloader:Class * Use Ruby 1.9 hash format Use Ruby 1.9 hash format #24192 [Rafael Mendonça França + Ladislav Smola]
* Fix `warning: method redefined; discarding old female`Ryuta Kamizono2016-03-121-3/+0
| | | | | | | | | | | ``` $ ARCONN=mysql2 be ruby -w -Itest test/cases/scoping/default_scoping_test.rb Using mysql2 /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/scoping/named.rb:158: warning: method redefined; discarding old female /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/scoping/named.rb:158: warning: previous definition of female was here /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/scoping/named.rb:158: warning: method redefined; discarding old male /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/scoping/named.rb:158: warning: previous definition of male was here ```
* Execute default_scope defined by abstract class within the scope of subclassMehmet Emin İNAÇ2016-03-081-0/+13
|