aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/log_subscriber_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Omit BEGIN/COMMIT statements for empty transactionsEugene Kenny2018-08-131-0/+1
| | | | | | | | | | | | | | | | | | | | | | If a transaction is opened and closed without any queries being run, we can safely omit the `BEGIN` and `COMMIT` statements, as they only exist to modify the connection's behaviour inside the transaction. This removes the overhead of those statements when saving a record with no changes, which makes workarounds like `save if changed?` unnecessary. This implementation buffers transactions inside the transaction manager and materializes them the next time the connection is used. For this to work, the adapter needs to guard all connection use with a call to `materialize_transactions`. Because of this, adapters must opt in to get this new behaviour by implementing `supports_lazy_transactions?`. If `raw_connection` is used to get a reference to the underlying database connection, the behaviour is disabled and transactions are opened eagerly, as we can't know how the connection will be used. However when the connection is checked back into the pool, we can assume that the application won't use the reference again and reenable lazy transactions. This prevents a single `raw_connection` call from disabling lazy transactions for the lifetime of the connection.
* Don't expose configuration for a test.Kasper Timm Hansen2018-07-281-2/+3
| | | | Clean up some concepts in the code while we're here.
* Avoid logging ActiveRecord::LogSubscriber as the query source when the ↵lsylvester2018-07-281-0/+13
| | | | source is ignored (#33455)
* Log call site for all queriesOlivier Lacan2017-12-131-2/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This new ActiveRecord configuration option allows you to easily pinpoint what line of application code is triggering SQL queries in the development log by appending below each SQL statement log the line of Ruby code that triggered it. It’s useful with N+1 issues, and to locate stray queries. By default this new option ignores Rails and Ruby code in order to surface only callers from your application Ruby code or your gems. It is enabled on newly generated Rails 5.2 applications and can be enabled on existing Rails applications: ```ruby Rails.application.configure do # ... config.active_record.verbose_query_logs = true end ``` The `rails app:upgrade` task will also add it to `config/development.rb`. This feature purposely avoids coupling with ActiveSupport::BacktraceCleaner since ActiveRecord can be used without ActiveRecord. This decision can be reverted in the future to allow more configurable backtraces (the exclusion of gem callers for example).
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* 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
|
* Set non 0 value to logger not to be affected by Ruby versionsYasuo Honda2017-05-171-23/+23
| | | | Addresses #29021
* Should escape meta characters in regexpRyuta Kamizono2017-05-071-8/+8
|
* Stop creating duplicate Struct instancesJon Moss2017-04-281-23/+15
| | | | | | Just use one `Event` class. Reduces duplication, makes the tests easier to read. It might seem like each tests needs a different kind of Struct, since we make a new one for each test case.
* applies remaining conventions across the projectXavier Noria2016-08-061-1/+1
|
* remove redundant curlies from hash argumentsXavier Noria2016-08-061-4/+4
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-5/+5
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Fix ActiveRecord::LogSubscriber edge caseJon Moss2016-05-101-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If an attribute was of the binary type, and also was a Hash, it would previously not be logged, and instead raise an error saying that `bytesize` was not defined for the `attribute.value` (a `Hash`). Now, as is done on 4-2-stable, the attribute's database value is `bytesize`d, and then logged out to the terminal. Reproduction script: ```ruby require 'active_record' require 'minitest/autorun' require 'logger' ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') ActiveRecord::Base.logger = Logger.new(STDOUT) ActiveRecord::Schema.define do create_table :posts, force: true do |t| t.binary :preferences end end class Post < ActiveRecord::Base serialize :preferences end class BugTest < Minitest::Test def test_24955 Post.create!(preferences: {a: 1}) assert_equal 1, Post.count end end ```
* `test_binary_data_is_not_logged` is for prepared statements loggingRyuta Kamizono2015-11-051-1/+1
|
* Improve sql logging coloration in `ActiveRecord::LogSubscriber`.Peter Boling2015-07-171-0/+98
| | | | | | | | | | | | | | | | | | | | | | | - Improves coloring for statements like: # Become WHITE SELECT * FROM ( SELECT * FROM mytable FOR UPDATE ) ss WHERE col1 = 5; LOCK TABLE table_name IN ACCESS EXCLUSIVE MODE; # Becomes RED ROLLBACK - Reinstates the coloration of the `payload[:name]`. Instead of simple alternating colors, adds meaning: - `MAGENTA` for `"SQL"` or `blank?` payload names - `CYAN` for Model Load/Exists - Introduces specs for sql coloration. - Introduces specs for payload name coloration. GH#20885
* Remove Relation#bind_paramsSean Griffin2015-01-271-8/+0
| | | | | | | | `bound_attributes` is now used universally across the board, removing the need for the conversion layer. These changes are mostly mechanical, with the exception of the log subscriber. Additional, we had to implement `hash` on the attribute objects, so they could be used as a key for query caching.
* Stop special casing null binary data in loggingSean Griffin2015-01-101-7/+0
| | | | | | There's very little value in logging "<NULL binary data>" instead of just "nil". I'd like to remove the column from the equation entirely, and this case is preventing us from doing so.
* Fix exception when logging SQL w/ nil binary value.James Coleman2014-05-021-0/+7
|
* Don't skip tests if we don't need to.Rafael Mendonça França2013-11-081-6/+6
| | | | | | | We can conditional define the tests depending on the adapter or connection. Lets keep the skip for fail tests that need to be fixed.
* log the sql that is actually sent to the databaseNeeraj Singh2013-06-191-0/+7
| | | | | | | | | | | | If I have a query that produces sql `WHERE "users"."name" = 'a b'` then in the log all the whitespace is being squeezed. So the sql that is printed in the log is `WHERE "users"."name" = 'a b'`. This can be confusing. This commit fixes it by ensuring that whitespace is not squeezed. fixes #10982
* Ignore binds payload with nil column in AR log subscriberCarlos Antonio da Silva2013-01-081-16/+26
| | | | | | | | | | | | | Some tests were raising the following error: Could not log "sql.active_record" event. NoMethodError: undefined method `type' for nil:NilClass` Due to the way binds were being logged, the column info was considered always present, but that is not true for some of the tests listed in the issue. Closes #8806.
* Address test_binary_data_is_not_logged with Oracle databaseYasuo Honda2012-12-191-2/+1
| | | | | | The number of sql statement logged depends on each database adapter implementation. Also, this test does not depends on how many sql statement executed.
* Skip binary data with binds test for mysql2, fix buildCarlos Antonio da Silva2012-12-141-0/+2
| | | | | | | Mysql2 doesn't support binds, which means no binds payload is set when logging, so the logic to render binary data differently here doesn't work. Introduced in 99d142a9375f9ba1960863b3cc745265aa9a14df.
* Do not log the binding values for binary columns.Matthew M. Boedicker2012-12-141-0/+8
| | | | They tend to be large and not very useful in the log.
* Remove ActiveRecord::Base.to_aJon Leighton2012-08-031-6/+6
| | | | | On reflection, it seems like a bit of a weird method to have on ActiveRecord::Base, and it shouldn't be needed most of the time anyway.
* ActiveRecord::Base.all returns a Relation.Jon Leighton2012-07-271-6/+6
| | | | | | | | | | | Previously it returned an Array. If you want an array, call e.g. `Post.to_a` rather than `Post.all`. This is more explicit. In most cases this should not break existing code, since Relations use method_missing to delegate unknown methods to #to_a anyway.
* Remove IdentityMapCarlos Antonio da Silva2012-03-131-12/+0
|
* remove more uses of deprecated logger methodsAaron Patterson2011-12-191-1/+1
|
* Fix broken test_exists_query_logging from the table_exists? changeJon Leighton2011-12-081-0/+1
|
* Log instrumentation name for exists? queriesJon Guymon2011-06-221-0/+8
|
* please use ruby -I lib:test path/to/test.rb, or export RUBY_OPTAaron Patterson2011-06-061-1/+1
|
* Refactor Active Record test connection setup. Please see the ↵Jon Leighton2011-06-041-1/+1
| | | | RUNNING_UNIT_TESTS file for details, but essentially you can now configure things in test/config.yml. You can also run tests directly via the command line, e.g. ruby path/to/test.rb (no rake needed, uses default db connection from test/config.yml). This will help us fix the CI by enabling us to isolate the different Rails versions to different databases.
* Fix failing AR test.José Valim2011-05-021-0/+12
|
* Disable IdentityMap in log tests, it's not important and when running tests ↵Emilio Tagua2011-04-051-0/+3
| | | | | | rake task it logs more messages in the tested buffer. Signed-off-by: José Valim <jose.valim@gmail.com>
* sql logger ignores schema statementsAaron Patterson2011-03-281-0/+27
|
* Move runtime back to the Thread.currentJosé Valim2010-07-261-0/+4
|
* Move runtime back to connection.José Valim2010-07-251-4/+0
|
* Revert the previous three commits.José Valim2010-07-251-0/+4
| | | | | | * AS::Notifications#instrument should not measure anything, it is not its responsibility; * Adding another argument to AS::Notifications#instrument API needs to be properly discussed;
* use a hash to collect optional statistics about the instrumentationAaron Patterson2010-07-251-4/+0
|
* runtime should be properly initialized.José Valim2010-07-251-0/+4
|
* Make use of severity levelsSantiago Pastorino2010-07-201-2/+3
| | | | Signed-off-by: José Valim <jose.valim@gmail.com>
* Fix a failing test in Railtie and properly define all severity levels in ↵José Valim2010-07-201-4/+2
| | | | MockLogger for LogSubscriber.
* Test added, we shouldn't log sql calls when logger is not on debug? modeSantiago Pastorino2010-07-201-0/+17
|
* mocking out debing? call in the MockLoggerAaron Patterson2010-07-191-0/+2
|
* activerecord tests should inherit from ActiveRecord::TestCaseAaron Patterson2010-07-141-1/+1
|
* Move Rails::LogSubscriber to ActiveSupport::LogSubscriber, allowing ↵José Valim2010-06-241-5/+4
| | | | frameworks like ActiveRecord and ActiveResource to log outsude Rails::Application [#4816 state:resolved]
* assert log output match in case insensitive mode to avoid failure when ↵Raimonds Simanovskis2010-06-041-2/+2
| | | | quoted table name is in uppercase (when using Oracle)
* cleaning up a bunch of parse time warnings in AR [#4186 state:resolved]Aaron Patterson2010-03-151-5/+5
| | | | Signed-off-by: wycats <wycats@gmail.com>
* Somehow this fixes the AR tests when ran with rake. I should probably figure ↵Carl Lerche2010-03-041-1/+1
| | | | out why.