Merge pull request #51371 from theodorton/relation-test-readonly

Add `ActiveRecord::Relation#readonly?`
This commit is contained in:
Rafael Mendonça França 2024-05-27 16:39:30 -04:00 committed by GitHub
commit 58883a5f8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 0 deletions

@ -1,3 +1,9 @@
* Add `ActiveRecord::Relation.readonly?`
Reflects if the relation has been marked as readonly.
*Theodor Tonum*
* Improve `ActiveRecord::Store` to raise a descriptive exception if the column is not either
structured (e.g., PostgreSQL +hstore+/+json+, or MySQL +json+) or declared serializable via
`ActiveRecord.store`.

@ -1261,6 +1261,10 @@ def blank?
records.blank?
end
def readonly?
readonly_value
end
def values
@values.dup
end

@ -79,9 +79,11 @@ def test_cant_update_columns_readonly_record
def test_find_with_readonly_option
Developer.all.each { |d| assert_not d.readonly? }
Developer.all.tap { |rel| assert_not rel.readonly? }
Developer.readonly(false).each { |d| assert_not d.readonly? }
Developer.readonly(true).each { |d| assert_predicate d, :readonly? }
Developer.readonly.each { |d| assert_predicate d, :readonly? }
Developer.readonly.tap { |rel| assert_predicate rel, :readonly? }
end
def test_find_with_joins_option_does_not_imply_readonly