aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/persistence_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Assert deprecationlulalala2019-03-311-2/+2
|
* Restore an ability that class level `update` without giving idsRyuta Kamizono2019-01-021-0/+14
| | | | | | | | | | | | | | | | | | That ability was introduced at #11898 as `Relation#update` without giving ids, so the ability on the class level is not documented and not tested. c83e30d which fixes #33470 has lost two undocumented abilities. One has fixed at 5c65688, but I missed the ability on the class level. Removing any feature should not be suddenly happened in a stable version even if that is not documented. I've restored the ability and added test case to avoid any regression in the future. Fixes #34743.
* Use `assert_no_queries` not to ignore BEGIN/COMMIT queriesRyuta Kamizono2018-10-051-7/+5
| | | | | | | | | `test_update_does_not_run_sql_if_record_has_not_changed` would pass without #18501 since `assert_queries` ignores BEGIN/COMMIT unless `ignore_none: true` is given. Since #32647, empty BEGIN/COMMIT is ommited. So we no longer need to use `assert_queries(0)` to ignore BEGIN/COMMIT in the queries.
* `Persistence#increment!` requires an attribute argument which is incrementedRyuta Kamizono2018-09-241-0/+5
|
* Extract `{update,delete}_all_test.rb` from `persistence_test.rb` and ↵Ryuta Kamizono2018-09-161-155/+12
| | | | | | | | `relations_test.rb` `persistence_test.rb` and `relations_test.rb` have too many lines, so I'd like to extract relation around tests to dedicated files before newly test added.
* Fix `touch` option to behave consistently with `Persistence#touch` methodRyuta Kamizono2018-06-181-10/+42
| | | | | | | | | | | | | | | | `touch` option was added to `increment!` (#27660) and `update_counters` (#26995). But that option behaves inconsistently with `Persistence#touch` method. If `touch` option is passed attribute names, it won't update update_at/on attributes unlike `Persistence#touch` method. Due to changed from `Persistence#touch` to `increment!` with `touch` option, #31405 has a regression that `counter_cache` with `touch` option which is passed attribute names won't update update_at/on attributes. I think that the inconsistency is not intended. To get back consistency, ensure that `touch` option updates update_at/on attributes.
* Fix `CustomCops/AssertNot` to allow it to have failure messageRyuta Kamizono2018-05-131-2/+2
| | | | Follow up of #32605.
* `becomes` should clear the mutation tracker which is created in ↵Ryuta Kamizono2018-05-111-0/+11
| | | | | | | | | | | | | | | | `after_initialize` `becomes` creates new object and copies attributes from the receiver. If new object has mutation tracker which is created in `after_initialize`, it should be cleared since it is for discarded attributes. But if the receiver doesn't have mutation tracker yet, it will not be cleared properly. It should be cleared regardless of whether the receiver has mutation tracker or not. Fixes #32867.
* Replace `assert !` with `assert_not`Daniel Colson2018-04-191-1/+1
| | | | | This autocorrects the violations after adding a custom cop in 3305c78dcd.
* Deprecate update_attributes and update_attributes!Eddie Lebow2018-02-171-39/+16
| | | | Closes #31998
* Invoke `load_schema` in `_default_attributes`Ryuta Kamizono2018-02-061-0/+7
| | | | | | | | | | | | | Currently `_default_attributes` doesn't work unless `load_schema` is called before. The `MissingAttributeError` is caused by `reload_schema_from_cache` is invoked by `serialize`. I added `load_schema` in `_default_attributes` to `_default_attributes` works without any dependency like `attribute_types` etc. Closes #31905.
* Remove extra whitespaceDaniel Colson2018-01-251-1/+1
|
* Use assert_empty and assert_not_emptyDaniel Colson2018-01-251-1/+1
|
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-33/+33
|
* Ignores a default subclass when `becomes(Parent)`Leonel Galan2018-01-221-0/+16
| | | | | | | | | | | Fixes issue described in #30399: A default value on the inheritance column prevented `child.becomes(Parent)` to return an instance of `Parent` as expected, instead it returns an instance of the default subclass. The change was introduced by #17169 and it was meant to affect initialization, alone. Where `Parent.new` is expected to return an instance of the default subclass.
* Don't allow destroyed object mutation after `save` or `save!` is calledRyuta Kamizono2018-01-151-2/+24
| | | | | | | | | | Currently `object.save` will unfreeze the object, due to `changes_applied` replaces frozen `@attributes` to new `@attributes`. Since originally destroyed objects are not allowed to be mutated, `save` and `save!` should not return success in that case. Fixes #28563.
* save attributes changed by callbacks after update_attributeMike Busch2017-12-221-0/+3
| | | | | | | | update_attribute previously stopped execution, before saving and before running callbacks, if the record's attributes hadn't changed. [The documentation](http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-update_attribute) says that "Callbacks are invoked", which was not happening if the persisted attributes hadn't changed.
* Using subselect for `delete_all` with `limit` or `offset`Ryuta Kamizono2017-12-191-0/+20
| | | | | | Arel doesn't support subselect generation for DELETE unlike UPDATE yet, but we already have that generation in connection adapters. We can simply use the subselect generated by that one.
* Using subselect generated by the connection adapter for `update_all` with ↵Ryuta Kamizono2017-12-191-7/+16
| | | | | | | | | | | `offset` Most RDBMS (except SQLite) requires subselect for UPDATE with OFFSET, but Arel doesn't support executable subselect generation for MySQL's UPDATE yet. We need to use the subselect generated by the connection adapter for now, it works well. Fixes #30148.
* Add failing testChris Salzberg2017-12-171-3/+8
|
* Modify test to correctly pass attributes hashChris Salzberg2017-12-151-4/+7
|
* Remove unnecessary scopingRyuta Kamizono2017-12-011-1/+1
|
* Class level `update` and `destroy` checks all the records exist before ↵Ryuta Kamizono2017-12-011-4/+37
| | | | | making changes (#31306) It makes more sense than ignoring invalid IDs.
* Maintain raising `RecordNotFound` for class level `update` and` destroy`Ryuta Kamizono2017-12-011-2/+12
| | | | | | | | | | | In 35836019, class level `update` and `destroy` suppressed `RecordNotFound` to ensure returning affected objects. But `RecordNotFound` is a common exception caught by a `rescue_from` handler. So changing the behavior when a typical `params[:id]` is passed has a compatibility problem. The previous behavior should not be changed. Fixes #31301.
* Ensure `apply_join_dependency` for `update_all` and `delete_all` if ↵Ryuta Kamizono2017-11-061-19/+30
| | | | | | | | | | eager-loading is needed If a relation has eager-loading values, `count` and `exists?` works properly, but `update_all` and `delete_all` doesn't work due to missing `apply_join_dependency`. It should be applied to work consistently. Fixes #28863.
* Ensure returning affected objects for class level `update` and `destroy`Ryuta Kamizono2017-09-181-10/+10
| | | | | | | Class level `update` and `destroy` are using `find` in the internal, so it will raise `RecordNotFound` if given ids cannot find an object even though the method already affect (update or destroy) to any objects. These methods should return affected objects even in that case.
* Add test cases that class level `destroy`, `delete`, and `update` are ↵Ryuta Kamizono2017-08-181-3/+33
| | | | | | | affected by scoping (#29997) I tried to change the expectation in #29976, but it is expected behavior at least for now. So I added the test cases to prevent anyone change the expectation.
* Merge remote-tracking branch 'origin/master' into unlock-minitestRafael Mendonça França2017-08-011-0/+9
|\
| * Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
| |
| * `Persistence#delete` should not be affected by scopingRyuta Kamizono2017-07-181-0/+7
| | | | | | | | | | `self.class.delete` is delegated to `all` and `all` is affected by scoping. It should use `unscoped` to not be affected by that.
| * Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | | | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
| * Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
| |
* | Use existing class in PersistenceTest::SaveTestAlex Kitchens2017-06-011-21/+7
|/ | | | | | | | | | | Creating a new class for widgets was causing failing tests because it clashed with other widget classes. This test does not need to create its own class, so I changed it to an existing class. ``` ARCONN=mysql2 bin/test --seed 25364 test/cases/*test.rb -n \ "/^(?:PrimaryKeyIntegerTest#(?:test_primary_key_with_serial_integer_are_automatically_numbered)|PersistenceTest::SaveTest#(?:test_save_touch_false))$/" ```
* Replace \Z to \zRyuta Kamizono2017-04-241-1/+1
| | | | \Z was a mistake of \z. Replace \Z to \z to prevent newly \Z added.
* Add the touch option to ActiveRecord#increment! and decrement!akihiro172017-01-141-0/+16
| | | | | Supports the `touch` option from update_counters. The default behavior is not to update timestamp columns.
* fixing update_all and delete_all when chained with left_joins. fixes #27192Diego Plentz2016-11-271-0/+22
|
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-1/+1
|
* Return true if attribute is not changed for update_attributePrathamesh Sonpatki2016-09-231-3/+3
| | | | | | | | | | | | | | - If the attribute is not changed, then update_attribute does not run SQL query, this effectively means that no change was made to the attribute. - This change was made in https://github.com/rails/rails/commit/0fcd4cf5 to avoid a SQL call. - But the change resulted into `nil` being returned when there was no change in the attribute value. - This commit corrects the behavior to return true if there is no change in attribute value. This is same as previous behavior of Rails 4.2 plus benefit of no additional SQL call. - Fixes #26593.
* Add three new rubocop rulesRafael Mendonça França2016-08-161-1/+1
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* Fix broken alignments caused by auto-correct commit 411ccbdRyuta Kamizono2016-08-101-1/+2
| | | | Hash syntax auto-correcting breaks alignments. 411ccbdab2608c62aabdb320d52cb02d446bb39c
* remove redundant curlies from hash argumentsXavier Noria2016-08-061-10/+8
|
* modernizes hash syntax in activerecordXavier Noria2016-08-061-9/+9
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-95/+95
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Typos in AR testsAkira Matsuda2016-02-031-1/+1
|
* `ActiveRecord::Base#becomes` should copy the errorsVokhmin Alexey V2015-12-141-1/+20
|
* Fix test failuresSean Griffin2015-11-071-0/+1
| | | | | The previous commit changes the state of the class, and while we are cleaning up the database, I forgot to clean up the class
* Ensure `#reset_column_information` clears child classes as wellSean Griffin2015-11-071-0/+12
| | | | | | | | | | | | | | I've added a redundant test for this under the attributes API as well, as that also causes this bug to manifest through public API (and demonstrates that calling `reset_column_information` on the child classes would be insufficient) Since children of a class should always share a table with their parent, just reloading the schema from the cache should be sufficient here. `reload_schema_from_cache` should probably become public and `# :nodoc:`, but I'd rather avoid the git churn here. Fixes #22057
* Deprecate exception#original_exception in favor of exception#causeYuki Nishijima2015-11-031-1/+2
|
* Make #increment! and #decrement! methods concurency safeBogdan Gusiev2015-10-051-0/+9
|
* Deprecate passing conditions to AR::Relation destroy_all and delete_all methodsWojciech Wnętrzak2015-09-061-1/+1
|