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
Eileen Uchitelle f39d72d526 Add ability to prevent writes to a database
This PR adds the ability to prevent writes to a database even if the
database user is able to write (ie the database is a primary and not a
replica).

This is useful for a few reasons: 1) when converting your database from
a single db to a primary/replica setup - you can fix all the writes on
reads early on, 2) when we implement automatic database switching or
when an app is manually switching connections this feature can be used
to ensure reads are reading and writes are writing. We want to make sure
we raise if we ever try to write in read mode, regardless of database
type and 3) for local development if you don't want to set up multiple
databases but do want to support rw/ro queries.

This should be used in conjunction with `connected_to` in write mode.
For example:

```
ActiveRecord::Base.connected_to(role: :writing) do
  Dog.connection.while_preventing_writes do
    Dog.create! # will raise because we're preventing writes
  end
end

ActiveRecord::Base.connected_to(role: :reading) do
  Dog.connection.while_preventing_writes do
    Dog.first # will not raise because we're not writing
  end
end
```
2018-11-30 09:28:04 -05:00
..
adapters Add ability to prevent writes to a database 2018-11-30 09:28:04 -05:00
arel Arel: Implemented DB-aware NULL-safe comparison (#34451) 2018-11-15 14:49:55 -05:00
associations More exercise singular association query 2018-11-28 03:34:20 +09:00
attribute_methods Add AR::Base.base_class? predicate 2018-04-02 14:34:32 +03:00
coders
connection_adapters Make connection handler per thread instead of per fiber 2018-11-20 16:02:40 -05:00
connection_specification Refactors Active Record connection management 2018-08-30 10:06:45 -04:00
fixture_set
migration Merge pull request #23593 from meinac/add_index_option_for_change_table 2018-10-01 10:39:03 +09:00
relation Arel: Implemented DB-aware NULL-safe comparison (#34451) 2018-11-15 14:49:55 -05:00
scoping Fix the scoping with query methods in the scope block 2018-11-30 05:50:40 +09:00
tasks assert_called_with should require args argument 2018-10-25 21:29:39 +03:00
type Enable Performance/UnfreezeString cop 2018-09-23 08:56:55 +09:00
validations Fix CustomCops/AssertNot to allow it to have failure message 2018-05-13 11:32:47 +09:00
adapter_test.rb When running exec_query MySQL always returns ActiveRecord::Result 2018-11-25 22:10:18 +07:00
aggregations_test.rb
ar_schema_test.rb Replace assert ! with assert_not 2018-04-19 08:11:33 -04:00
associations_test.rb Change the empty block style to have space inside of the block 2018-09-25 13:19:35 -04:00
attribute_decorators_test.rb
attribute_methods_test.rb Allow aliased attributes in update 2018-11-29 14:49:17 -05:00
attributes_test.rb Make a deep copy of the _default_attributes in column_defaults 2018-09-20 00:03:15 -04:00
autosave_association_test.rb Call define_attribute_methods before assert_no_queries to address CI flakiness 2018-10-09 03:46:22 +09:00
base_test.rb Add ability to prevent writes to a database 2018-11-30 09:28:04 -05:00
batches_test.rb Change the empty block style to have space inside of the block 2018-09-25 13:19:35 -04:00
binary_test.rb Enable Performance/UnfreezeString cop 2018-09-23 08:56:55 +09:00
bind_parameter_test.rb Checking boundable not only IN clause but also NOT IN clause 2018-11-03 14:54:57 +09:00
boolean_test.rb Ensure casting by boolean attribute when querying 2018-05-29 05:22:31 +09:00
cache_key_test.rb Do not silently fail to generate a cache_version 2018-10-17 11:05:05 -05:00
calculations_test.rb Redact SQL in errors 2018-11-22 13:53:23 -05:00
callbacks_test.rb Change the empty block style to have space inside of the block 2018-09-25 13:19:35 -04: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 Change the empty block style to have space inside of the block 2018-09-25 13:19:35 -04:00
core_test.rb Fix inspect with non-primary key id attribute 2018-11-06 01:51:52 +00:00
counter_cache_test.rb Fix touch option to behave consistently with Persistence#touch method 2018-06-18 19:08:41 +09:00
custom_locking_test.rb
database_statements_test.rb
date_test.rb
date_time_precision_test.rb Apply time column precision on assignment 2018-03-11 18:19:20 +00:00
date_time_test.rb
defaults_test.rb Support default expression for MySQL 2018-10-25 18:11:22 +09:00
dirty_test.rb Use assert_no_queries not to ignore BEGIN/COMMIT queries 2018-10-05 04:11:13 +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 Raises error when attempting to modify enum values 2018-11-23 23:55:31 +00:00
errors_test.rb
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 Implement AR#inspect using ParamterFilter. 2018-10-19 14:16:03 +09:00
finder_respond_to_test.rb Change the empty block style to have space inside of the block 2018-09-25 13:19:35 -04:00
finder_test.rb Make implicit order column configurable 2018-11-26 16:19:52 -08:00
fixtures_test.rb Don't pass unused connection to FixtureSet.new 2018-11-03 21:38:19 +09:00
forbidden_attributes_protection_test.rb
habtm_destroy_order_test.rb Use assert_empty and assert_not_empty 2018-01-25 23:32:59 -05:00
helper.rb Support default expression for MySQL 2018-10-25 18:11:22 +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 Enable Layout/EmptyLinesAroundBlockBody to reduce review cost in the future 2018-07-12 21:29:48 +09:00
instrumentation_test.rb Cached columns_hash fields should be excluded from ResultSet#column_types 2018-11-27 16:30:26 +03:00
integration_test.rb add test for cache_version precision 2018-10-07 08:07:56 +11:00
invalid_connection_test.rb
invertible_migration_test.rb Fix transaction reverting for migrations 2018-09-26 23:40:42 +03:00
json_attribute_test.rb
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
legacy_configurations_test.rb Refactors Active Record connection management 2018-08-30 10:06:45 -04: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 Add an :if_not_exists option to create_table 2018-11-08 15:26:07 +02: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
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 Use assert_no_queries not to ignore BEGIN/COMMIT queries 2018-10-05 04:11:13 +09:00
pooled_connections_test.rb
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 Fix query cache for multiple connections 2018-11-20 17:48:48 -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 Improve tests for ActiveRecord::ConnectionAdapters::ConnectionPool configurations. 2018-08-19 23:07:04 +08:00
reflection_test.rb Replace assert ! with assert_not 2018-04-19 08:11:33 -04:00
relation_test.rb Escape table name so that it can be used in regular expression 2018-10-04 11:56:00 +01:00
relations_test.rb Generate delegation methods to named scope in the definition time 2018-10-09 13:03:08 +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 Deprecate expand_hash_conditions_for_aggregates 2018-01-29 21:35:30 +09:00
schema_dumper_test.rb Support expression indexes for MySQL 2018-10-25 18:09:02 +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 Address intermittent CI failure due to non-determined sort order 2018-08-19 12:22:46 +09:00
statement_cache_test.rb Autocorrect refute RuboCop violations 2018-04-03 22:35:49 -04: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 Omit BEGIN/COMMIT statements for empty transactions 2018-08-13 16:51:54 +01:00
test_fixtures_test.rb
time_precision_test.rb Apply time column precision on assignment 2018-03-11 18:19:20 +00: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 Change the empty block style to have space inside of the block 2018-09-25 13:19:35 -04:00
type_test.rb
types_test.rb
unconnected_test.rb Fix CustomCops/AssertNot to allow it to have failure message 2018-05-13 11:32:47 +09:00
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 Fix numericality validator not to be affected by custom getter 2018-08-13 23:28:46 +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