aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
Commit message (Collapse)AuthorAgeFilesLines
...
| * | | Handle aliased attributes in AR::Relation#select, #order, etc.Tsutomu Kuroda2014-01-292-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | With this we can write `Model#select(:aliased)`, `Model#order(:aliased)`, `Model#reoder(aliased: :desc)`, etc. Supplementary work to 54122067acaad39b277a5363c6d11d6804c7bf6b.
| * | | Fix indent on test case [ci skip]Carlos Antonio da Silva2014-01-281-2/+2
| | | |
| * | | use the new clear_validators! api everywhere to reset validators in testsKuldeep Aggarwal2014-01-282-3/+3
| | | |
| * | | Merge pull request #13785 from kuldeepaggarwal/fix-find_with_multiple_idsYves Senn2014-01-241-7/+24
| |\ \ \ | | | | | | | | | | Fix `ActiveRecord::RecordNotFound` error message with custom primary key
| | * | | Fix `ActiveRecord::RecordNotFound` error message with custom primary keyKuldeep Aggarwal2014-01-251-7/+24
| | | | |
| * | | | Remove unused assignment to fix warnings in enum test.Vipul A M2014-01-241-1/+0
| |/ / /
| * | | Calling reset on a collection association should unload the assocationKelsey Schlarman2014-01-211-0/+9
| | | | | | | | | | | | | | | | Need to define #reset on CollectionProxy.
| * | | Ensure AR #second, #third, etc. finders work through associationsJason Meller2014-01-216-72/+109
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes two regressions introduced in cafe31a078 where newly created finder methods #second, #third, #forth, and #fifth caused a NoMethodError error on reload associations and where we were pulling the wrong element out of cached associations. Examples: some_book.authors.reload.second # Before # => NoMethodError: undefined method 'first' for nil:NilClass # After # => #<Author id: 2, name: "Sally Second", ...> some_book.first.authors.first some_book.first.authors.second # Before # => #<Author id: 1, name: "Freddy First", ...> # => #<Author id: 1, name: "Freddy First", ...> # After # => #<Author id: 1, name: "Freddy First", ...> # => #<Author id: 2, name: "Sally Second", ...> Fixes #13783.
| * | | Merge pull request #13776 from rails/dirty-enumRafael Mendonça França2014-01-213-0/+74
| |\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implement the Dirty API with the Enum feature correctly. Conflicts: activerecord/CHANGELOG.md
| | * | | Add more tests for the dirty feature for enumsRafael Mendonça França2014-01-213-0/+34
| | | | |
| | * | | Make enum feature work with dirty methodsRafael Mendonça França2014-01-211-0/+40
| | | | | | | | | | | | | | | | | | | | | | | | | To make this possible we have to override the save_changed_attribute hook.
| * | | | `has_one` and `belongs_to` accessors don't add ORDER BY to the queries anymore.Rafael Mendonça França2014-01-212-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since Rails 4.0, we add an ORDER BY in the `first` method to ensure consistent results among different database engines. But for singular associations this behavior is not needed since we will have one record to return. As this ORDER BY option can lead some performance issues we are removing it for singular associations accessors. Fixes #12623.
| * | | | prepend table name for `Relation#select` columns.Yves Senn2014-01-211-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes a bug where `select(:id)` combined with `joins()` raised: ``` ActiveRecord::StatementInvalid: SQLite3::SQLException: ambiguous column name: id: SELECT id, authors.author_address_id FROM "posts" INNER JOIN "authors" ON "authors"."id" = "posts"."author_id" ORDER BY posts.id LIMIT 3 ``` The `select_values` are still String and Symbols because other parts (mainly calculations.rb) rely on that fact. /cc @tenderlove
| * | | | Fail early with "Primary key not included in the custom select clause" in ↵Alexander Balashov2014-01-211-1/+3
| |/ / / | | | | | | | | | | | | | | | | find_in_batches Before this patch find_in_batches raises this error only on second iteration. So you will know about the problem only when you get the batch size threshold.
| * | | Ensure #second acts like #first AR finderJason Meller2014-01-206-26/+123
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit bring the famous ordinal Array instance methods defined in ActiveSupport into ActiveRecord as fully-fledged finders. These finders ensure a default ascending order of the table's primary key, and utilize the OFFSET SQL verb to locate the user's desired record. If an offset is defined in the query, calling #second adds to the offset to get the actual desired record. Fixes #13743.
| * | | Merge pull request #13745 from nextgearcapital/masterRafael Mendonça França2014-01-192-0/+4
| |\ \ \ | | | | | | | | | | set encoding for pipe to binary mode
| | * | | set encoding to binmode for pipeAnna Carey2014-01-172-0/+4
| | | | |
| * | | | Restore ActiveRecord states after a rollback for models w/o callbacksGodfrey Chan2014-01-181-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes a regression (#13744) that was caused by 67d8bb9. In 67d8bb9, we introduced lazy rollback for records, such that the record's internal states and attributes are not restored immediately after a transaction rollback, but deferred until they are first accessed. This optimization is only performed when the model does not have any transactional callbacks (e.g. `after_commit` and `after_create`). Unfortunately, the models used to test the affected codepaths all comes with some sort of transactional callbacks. Therefore this codepath remains largely untested until now and as a result there are a few issues in the implementation that remains hidden until now. First, the `sync_with_transaction_state` (or more accurately, `update_attributes_from_transaction_state`) would perform the synchronization prematurely before a transaction is finalized (i.e. comitted or rolled back). As a result, when the actuall rollback happens, the record will incorrectly assumes that its internal states match the transaction state, and neglect to perform the restore. Second, `update_attributes_from_transaction_state` calls `committed!` in some cases. This in turns checks for the `destroyed?` state which also requires synchronization with the transaction stae, which causes an infnite recurrsion. This fix works by deferring the synchronization until the transaction has been finalized (addressing the first point), and also unrolled the `committed!` and `rolledback!` logic in-place (addressing the second point). It should be noted that the primary purpose of the `committed!` and `rolledback!` methods are to trigger the relevant transactional callbacks. Since this code path is only entered when there are no transactional callbacks on the model, this shouldn't be necessary. By unrolling the method calls, the intention here (to restore the states when necessary) becomes more clear.
* | | | | Merge branch 'master' into adequaterecordAaron Patterson2014-01-171-0/+6
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: fix exception translation translate exceptions on prepared statement failure test to ensure bad prepared statements raise a StatementInvalid exception
| * | | | test to ensure bad prepared statements raise a StatementInvalid exceptionAaron Patterson2014-01-171-0/+6
| |/ / /
* | | | fixing explain tests for sqlite3Aaron Patterson2014-01-171-13/+13
| | | |
* | | | Merge branch 'master' into adequaterecordAaron Patterson2014-01-172-176/+153
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: Fix eager load of Serializers on Active Model Consistence in the block style Remove warnings on Ruby 2.1 Only some dynamic finders are deprecated. clean up security guide: his => their [ci skip] Remove warning Extract a method to simplify setup code Use minitest's skip rather than conditionals + early returns Move AR test classes inside the test case Do not set up a variable used only in two tests No need for instance vars on single tests Cleanup duplicated setup of callbacks in transactions tests No need to use #send with public methods Update deprecation warning to give more information about caller Update changelog Avoid scanning multiple render calls as a single match. Improve ERB dependency detection.
| * | | Extract a method to simplify setup codeCarlos Antonio da Silva2014-01-161-23/+27
| | | |
| * | | Use minitest's skip rather than conditionals + early returnsCarlos Antonio da Silva2014-01-161-47/+38
| | | |
| * | | Move AR test classes inside the test caseCarlos Antonio da Silva2014-01-161-38/+46
| | | |
| * | | Do not set up a variable used only in two testsCarlos Antonio da Silva2014-01-161-15/+18
| | | | | | | | | | | | | | | | | | | | Just create a local variable whenever we need the record, rather than doing an extra find for every test on the setup method.
| * | | No need for instance vars on single testsCarlos Antonio da Silva2014-01-161-8/+8
| | | |
| * | | Cleanup duplicated setup of callbacks in transactions testsCarlos Antonio da Silva2014-01-161-48/+19
| | | |
| * | | No need to use #send with public methodsCarlos Antonio da Silva2014-01-161-10/+10
| | | |
* | | | change query strategy based on adapterAaron Patterson2014-01-161-1/+0
| | | |
* | | | Merge branch 'master' into adequaterecordAaron Patterson2014-01-1612-54/+117
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: Make AR::Base#touch fire the after_commit and after_rollback callbacks Fix test for cache_key + touched Revert "methods are defined right after the module_eval, so we don't need to do" Revert "Don't remove trailing slash from PATH_INFO for mounted apps" Add failing test for #13369 reset column information after fiddling with `Encoding.default_internal` we have `with_env_tz` as global test helper. Remove duplicate. isolate class attribute assignment in `migration_test.rb` use `teardown` for cleanup, not `setup`. tests without transactional fixtures need to cleanup afterwards. no need to `return skip` in tests. `skip` is enough. methods are defined right after the module_eval, so we don't need to do any line number maths Get rid of unused TransactionError constant Avoid converting :on option to array twice when defining commit/rollback callbacks Unify changelog entries about single quotes [ci skip] Use single quotes in generated files
| * | | Make AR::Base#touch fire the after_commit and after_rollback callbacksHarry Brundage2014-01-163-2/+63
| | | |
| * | | Fix test for cache_key + touchedCarlos Antonio da Silva2014-01-161-9/+9
| | | | | | | | | | | | | | | | | | | | Ensure the child can actually be touched. The `Bulb` model has no timestamp column, thus trying to touch it would return `nil`.
| * | | reset column information after fiddling with `Encoding.default_internal`Yves Senn2014-01-161-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This solves order depndent problems in `base_test.rb`. The leaked column information crashed test cases using the `Weird` class later on: ``` 2) Error: BasicsTest#test_group_weirds_by_from: SyntaxError: /Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:387: invalid hex escape ... attribute_before_type_cast("\x{A4CA}\x{A4DE}\x{A4A8}", *arg... ... ^ /Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:387: invalid hex escape ...te_before_type_cast("\x{A4CA}\x{A4DE}\x{A4A8}", *args) ... ^ /Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:387: invalid hex escape ...e_type_cast("\x{A4CA}\x{A4DE}\x{A4A8}", *args) ... ^ /Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:385:in `module_eval' /Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:385:in `define_proxy_call' /Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:294:in `block in define_attribute_method' /Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:285:in `each' /Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:285:in `define_attribute_method' /Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:252:in `block in define_attribute_methods' /Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:252:in `each' /Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:252:in `define_attribute_methods' /Users/senny/Projects/rails/activerecord/lib/active_record/attribute_methods.rb:72:in `block in define_attribute_methods' /Users/senny/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/mutex_m.rb:73:in `synchronize' /Users/senny/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/mutex_m.rb:73:in `mu_synchronize' /Users/senny/Projects/rails/activerecord/lib/active_record/attribute_methods.rb:69:in `define_attribute_methods' /Users/senny/Projects/rails/activerecord/lib/active_record/attribute_methods.rb:174:in `method_missing' /Users/senny/Projects/rails/activerecord/lib/active_record/attribute_assignment.rb:45:in `public_send' /Users/senny/Projects/rails/activerecord/lib/active_record/attribute_assignment.rb:45:in `_assign_attribute' /Users/senny/Projects/rails/activerecord/lib/active_record/attribute_assignment.rb:32:in `block in assign_attributes' /Users/senny/Projects/rails/activerecord/lib/active_record/attribute_assignment.rb:26:in `each' /Users/senny/Projects/rails/activerecord/lib/active_record/attribute_assignment.rb:26:in `assign_attributes' /Users/senny/Projects/rails/activerecord/lib/active_record/core.rb:458:in `init_attributes' /Users/senny/Projects/rails/activerecord/lib/active_record/core.rb:191:in `initialize' /Users/senny/Projects/rails/activerecord/lib/active_record/inheritance.rb:30:in `new' /Users/senny/Projects/rails/activerecord/lib/active_record/inheritance.rb:30:in `new' /Users/senny/Projects/rails/activerecord/lib/active_record/persistence.rb:33:in `create' test/cases/base_test.rb:646:in `test_group_weirds_by_from' ```
| * | | we have `with_env_tz` as global test helper. Remove duplicate.Yves Senn2014-01-162-14/+0
| | | |
| * | | isolate class attribute assignment in `migration_test.rb`Yves Senn2014-01-161-22/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This makes the tests inside `migration_test.rb` order independent. The assignments to `Reminder.table_name_prefix` and `Reminder.table_name_suffix` previously leaked and had impact on following test cases. This patch isolates the assignments on a throw-away subclass.
| * | | use `teardown` for cleanup, not `setup`.Yves Senn2014-01-161-5/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This solves order dependent issues where the last test leaked the query cache state. This resulted in the following error: ``` QueryCacheExpiryTest#test_cache_is_expired_by_habtm_delete [test/cases/query_cache_test.rb:275]: not all expectations were satisfied unsatisfied expectations: - expected exactly twice, invoked once: #<ActiveRecord::ConnectionAdapters::SQLite3Adapter:0x7f93e0c65838>.clear_query_cache(any_parameters) ```
| * | | tests without transactional fixtures need to cleanup afterwards.Yves Senn2014-01-161-0/+7
| | | | | | | | | | | | | | | | This fixes test order issues.
| * | | no need to `return skip` in tests. `skip` is enough.Yves Senn2014-01-164-4/+4
| | | |
* | | | use a params hash so we know what bind parameters are usedAaron Patterson2014-01-151-15/+16
| | | |
* | | | some databases do not have bind params (mysql2) so take that in to accountAaron Patterson2014-01-141-2/+6
| | | |
* | | | Merge branch 'master' into set_bindsAaron Patterson2014-01-142-15/+2
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: rm dup code Conflicts: activerecord/test/cases/relations_test.rb
| * | | rm dup codeAaron Patterson2014-01-141-13/+0
| | | | | | | | | | | | | | | | https://github.com/rails/rails/blob/e64a83cdbd3ce836f3339c600c1006b20c23d8fd/activerecord/test/cases/relation/merging_test.rb#L80-91
| * | | "string" isn't a valid column type for ActiveRecordAaron Patterson2014-01-141-1/+1
| | | | | | | | | | | | | | | | | | | | Conflicts: activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
* | | | test bind value equalityAaron Patterson2014-01-141-2/+2
| | | |
* | | | match against bind valuesAaron Patterson2014-01-141-2/+2
| | | |
* | | | fix statement cache executionAaron Patterson2014-01-141-7/+6
| | | |
* | | | fix cache class interfaceAaron Patterson2014-01-141-17/+9
| | | |
* | | | drop the dual encodings tableAaron Patterson2014-01-141-2/+2
| | | |
* | | | `where` makes bind values, so stop manually creating themAaron Patterson2014-01-141-11/+3
| | | |