1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/cases
Matt Yoho f41825809c Add Relation#annotate for SQL commenting
This patch has two main portions:

1. Add SQL comment support to Arel via Arel::Nodes::Comment.
2. Implement a Relation#annotate method on top of that.

== Adding SQL comment support

Adds a new Arel::Nodes::Comment node that represents an optional SQL
comment and teachers the relevant visitors how to handle it.

Comment nodes may be added to the basic CRUD statement nodes and set
through any of the four (Select|Insert|Update|Delete)Manager objects.

For example:

    manager = Arel::UpdateManager.new
    manager.table table
    manager.comment("annotation")
    manager.to_sql # UPDATE "users" /* annotation */

This new node type will be used by ActiveRecord::Relation to enable
query annotation via SQL comments.

== Implementing the Relation#annotate method

Implements `ActiveRecord::Relation#annotate`, which accepts a comment
string that will be appeneded to any queries generated by the relation.

Some examples:

    relation = Post.where(id: 123).annotate("metadata string")
    relation.first
    # SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123
    # LIMIT 1 /* metadata string */

    class Tag < ActiveRecord::Base
      scope :foo_annotated, -> { annotate("foo") }
    end
    Tag.foo_annotated.annotate("bar").first
    # SELECT "tags".* FROM "tags" LIMIT 1 /* foo */ /* bar */

Also wires up the plumbing so this works with `#update_all` and
`#delete_all` as well.

This feature is useful for instrumentation and general analysis of
queries generated at runtime.
2019-03-21 20:30:56 -07:00
..
adapters Add Relation#annotate for SQL commenting 2019-03-21 20:30:56 -07:00
arel Add Relation#annotate for SQL commenting 2019-03-21 20:30:56 -07:00
associations Remove unnecessary current_adapter?(:OracleAdapter) for index length 2019-03-03 13:48:23 +00:00
attribute_methods Add AR::Base.base_class? predicate 2018-04-02 14:34:32 +03:00
coders
connection_adapters Revert "Remove Marshal support from SchemaCache" 2019-03-13 14:17:31 -04:00
connection_specification Refactors Active Record connection management 2018-08-30 10:06:45 -04:00
fixture_set
migration Just inherit ForeignKeyChangeColumnTest for with prefix/suffix tests 2019-03-07 11:35:00 +09:00
relation Add Relation#annotate for SQL commenting 2019-03-21 20:30:56 -07:00
scoping Add Relation#annotate for SQL commenting 2019-03-21 20:30:56 -07:00
tasks Reset connection_handlers to default when any test dirties that 2019-03-05 21:12:19 +09:00
type Fix year value when casting a multiparameter time hash 2019-01-21 09:23:12 +00:00
validations Merge pull request #35424 from Korri/validation-rules-locale-fallback 2019-03-11 21:47:38 -04:00
adapter_test.rb Make truncate_tables to bulk statements 2019-03-17 09:37:08 +09:00
aggregations_test.rb No need to handle if FrozenError is available 2018-12-23 13:26:20 +00:00
ar_schema_test.rb Make t.timestamps with precision by default 2019-01-26 22:49:14 +09:00
associations_test.rb Add Relation#annotate for SQL commenting 2019-03-21 20:30:56 -07:00
attribute_decorators_test.rb
attribute_methods_test.rb Give GeneratedAttributeMethods module a name 2019-03-13 10:34:15 +09:00
attributes_test.rb Document option forwarding in ActiveRecord::Base.attribute 2019-03-20 15:05:31 -04:00
autosave_association_test.rb Fixed autosave association test typo 2019-03-09 21:37:30 +05:30
base_test.rb More exercise test cases for order by table name qualified column name 2019-02-21 03:51:20 +09:00
batches_test.rb Enable Lint/UselessAssignment cop to avoid unused variable warnings (#34904) 2019-01-09 18:09:01 +09:00
binary_test.rb Enable Performance/UnfreezeString cop 2018-09-23 08:56:55 +09:00
bind_parameter_test.rb Don't expose internal type_casted_binds method 2019-03-19 02:28:09 +09:00
boolean_test.rb Ensure casting by boolean attribute when querying 2018-05-29 05:22:31 +09:00
cache_key_test.rb PostgreSQL: Use native timestamp decoders of pg-1.1 2019-01-26 20:30:43 +01:00
calculations_test.rb Merge pull request #35361 from jvillarejo/fix_wrong_size_query_with_distinct_select 2019-02-27 01:04:20 +09:00
callbacks_test.rb Module#{define_method,alias_method,undef_method,remove_method} become public since Ruby 2.5 2018-12-21 01:39:18 +09:00
clone_test.rb Fix CustomCops/AssertNot to allow it to have failure message 2018-05-13 11:32:47 +09:00
collection_cache_key_test.rb Fix Collection cache key with limit and custom select (PG:AmbigousColumn: Error) 2018-10-15 20:38:12 -03:00
column_alias_test.rb
column_definition_test.rb
comment_test.rb
connection_management_test.rb Change the empty block style to have space inside of the block 2018-09-25 13:19:35 -04:00
connection_pool_test.rb Enable Style/RedundantBegin cop to avoid newly adding redundant begin block 2018-12-21 06:12:42 +09:00
core_test.rb Fix inspect with non-primary key id attribute 2018-11-06 01:51:52 +00:00
counter_cache_test.rb Enable Lint/UselessAssignment cop to avoid unused variable warnings (#34904) 2019-01-09 18:09:01 +09:00
custom_locking_test.rb
database_configurations_test.rb Improve errors and handling of hashes for database configurations 2019-02-14 08:25:52 -05:00
database_selector_test.rb Fix DatabaseSelector test that fails sometimes 2019-02-12 12:26:09 -05:00
database_statements_test.rb
date_test.rb Rails DateTime type is mapped to Oracle TIMESTAMP since Rails 5.0 2019-03-03 04:55:17 +00:00
date_time_precision_test.rb Test that no datetime precision isn't truncated on assignment 2019-02-27 03:20:35 +09:00
date_time_test.rb
defaults_test.rb Support default expression for MySQL 2018-10-25 18:11:22 +09:00
dirty_test.rb Ensure update_all series cares about optimistic locking 2019-02-25 20:14:56 +09:00
disconnected_test.rb
dup_test.rb Fix CustomCops/AssertNot to allow it to have failure message 2018-05-13 11:32:47 +09:00
enum_test.rb ✂️ 2019-02-27 05:54:02 +09:00
errors_test.rb Enable Style/RedundantBegin cop to avoid newly adding redundant begin block 2018-12-21 06:12:42 +09:00
explain_subscriber_test.rb Permit list usage cleanup and clearer documentation 2018-08-27 09:51:46 -04:00
explain_test.rb Remove usage of strip_heredoc in the framework in favor of <<~ 2018-02-16 19:28:30 -05:00
filter_attributes_test.rb Enable Style/RedundantBegin cop to avoid newly adding redundant begin block 2018-12-21 06:12:42 +09:00
finder_respond_to_test.rb Module#{define_method,alias_method,undef_method,remove_method} become public since Ruby 2.5 2018-12-21 01:39:18 +09:00
finder_test.rb Fix random CI failure due to non-deterministic sorting order 2019-03-11 03:56:50 +09:00
fixtures_test.rb SQLite3: Make fixture loading to bulk statements 2019-03-17 13:12:25 +09:00
forbidden_attributes_protection_test.rb Remove duplicated protected params definitions 2019-02-24 19:50:53 +09:00
habtm_destroy_order_test.rb Enable Style/RedundantBegin cop to avoid newly adding redundant begin block 2018-12-21 06:12:42 +09:00
helper.rb Support Optimizer Hints 2019-03-16 18:44:55 +09:00
hot_compatibility_test.rb Test prepared statement cache only if prepared statements is enabled 2018-11-09 00:32:36 +09:00
i18n_test.rb
inheritance_test.rb Don't cache find_by statements on STI subclasses 2019-02-27 03:40:53 +09:00
insert_all_test.rb Bulk Insert: Reuse indexes for unique_by 2019-03-20 13:28:18 +01:00
instrumentation_test.rb Add insert_all to ActiveRecord models (#35077) 2019-03-05 11:16:44 -08:00
integration_test.rb Remove ability to specify a timestamp name for #cache_key 2019-01-17 16:08:32 -05:00
invalid_connection_test.rb
invertible_migration_test.rb Support Optimizer Hints 2019-03-16 18:44:55 +09:00
json_attribute_test.rb Use :string instead of :text for JsonAttributeTest 2017-12-06 08:42:51 +09:00
json_serialization_test.rb Use respond_to test helpers 2018-01-25 23:32:58 -05:00
json_shared_test_cases.rb Deprecate update_attributes and update_attributes! 2018-02-17 13:58:54 -08:00
locking_test.rb Fix touch option to behave consistently with Persistence#touch method 2018-06-18 19:08:41 +09:00
log_subscriber_test.rb Omit BEGIN/COMMIT statements for empty transactions 2018-08-13 16:51:54 +01:00
migration_test.rb Remove MigrationTest#test_create_table_with_custom_sequence_name 2019-03-11 12:33:02 +00:00
migrator_test.rb Remove meaningless ActiveRecord::MigrationContext.new(old_path) in ensure block 2018-09-17 19:53:02 +09:00
mixin_test.rb
modules_test.rb Fix CustomCops/AssertNot to allow it to have failure message 2018-05-13 11:32:47 +09:00
multiparameter_attributes_test.rb Autocorrect refute RuboCop violations 2018-04-03 22:35:49 -04:00
multiple_db_test.rb Enable Style/RedundantBegin cop to avoid newly adding redundant begin block 2018-12-21 06:12:42 +09:00
nested_attributes_test.rb Fixes #33610 2018-09-11 00:13:09 -07:00
nested_attributes_with_callbacks_test.rb Use assert_predicate and assert_not_predicate 2018-01-25 23:32:59 -05:00
null_relation_test.rb Call load_schema before assert_no_queries 2018-10-10 09:50:22 +09:00
numeric_data_test.rb Ensure casting by decimal attribute when querying 2018-11-12 03:39:28 +09:00
persistence_test.rb Restore an ability that class level update without giving ids 2019-01-02 06:23:52 +09:00
pooled_connections_test.rb Enable Style/RedundantBegin cop to avoid newly adding redundant begin block 2018-12-21 06:12:42 +09:00
primary_keys_test.rb SQLite 3.7.16+ returns the order of the primary key columns 2018-11-25 23:08:25 +00:00
query_cache_test.rb Invalidate query cache for all connections in the current thread 2019-02-01 16:05:25 -05:00
quoting_test.rb Normalize time value not to be affected by summer time 2018-07-25 09:46:39 +09:00
readonly_test.rb Replace assert ! with assert_not 2018-04-19 08:11:33 -04:00
reaper_test.rb fix activerecord reaper_test 2019-01-02 17:55:48 -05:00
reflection_test.rb Replace assert ! with assert_not 2018-04-19 08:11:33 -04:00
relation_test.rb Add Relation#annotate for SQL commenting 2019-03-21 20:30:56 -07:00
relations_test.rb Delegate only query method to relation as with except 2019-03-07 19:11:43 +09:00
reload_models_test.rb
reserved_word_test.rb Use assert_predicate and assert_not_predicate 2018-01-25 23:32:59 -05:00
result_test.rb Deprecate ActiveRecord::Result#to_hash in favor of #to_a 2018-09-18 16:40:10 -04:00
sanitize_test.rb Quote empty ranges like other empty enumerables 2019-03-07 19:22:29 -05:00
schema_dumper_test.rb Allow changing text and blob size without giving the limit option 2019-01-29 06:49:32 +09:00
schema_loading_test.rb
secure_token_test.rb
serialization_test.rb Replace assert ! with assert_not 2018-04-19 08:11:33 -04:00
serialized_attribute_test.rb Remove unused requires 2019-03-01 16:49:38 +09:00
statement_cache_test.rb activerecord: Fix statement cache for strictly cast attributes 2019-01-23 14:49:42 -05:00
statement_invalid_test.rb Redact SQL in errors 2018-11-22 13:53:23 -05:00
store_test.rb Update prefix and allow suffix options for store accessors 2018-06-12 07:10:09 -07:00
suppressor_test.rb Change the empty block style to have space inside of the block 2018-09-25 13:19:35 -04:00
test_case.rb No need to handle if FrozenError is available 2018-12-23 13:26:20 +00:00
test_fixtures_test.rb
time_precision_test.rb Test that no datetime precision isn't truncated on assignment 2019-02-27 03:20:35 +09:00
timestamp_test.rb Fix CustomCops/AssertNot to allow it to have failure message 2018-05-13 11:32:47 +09:00
touch_later_test.rb Use assert_no_queries not to ignore BEGIN/COMMIT queries 2018-10-05 04:11:13 +09:00
transaction_callbacks_test.rb Always add records to parent of nested transaction 2018-11-07 13:32:49 +00:00
transaction_isolation_test.rb Change the empty block style to have space inside of the block 2018-09-25 13:19:35 -04:00
transactions_test.rb Remove deprecated #set_state from the transaction object 2019-01-17 16:08:33 -05:00
type_test.rb
types_test.rb
unconnected_test.rb Clean up AR's isolated test runner 2019-03-05 02:02:41 +10:30
unsafe_raw_sql_test.rb whitelist NULLS { FIRST | LAST } in order clauses 2018-03-06 02:27:16 +01:00
validations_repair_helper.rb
validations_test.rb Add test case for ce48b5a366 2018-12-18 11:18:18 +09:00
view_test.rb Bump the minimum version of PostgreSQL to 9.3 2018-11-25 13:13:08 +00:00
yaml_serialization_test.rb Use assert_predicate and assert_not_predicate 2018-01-25 23:32:59 -05:00