Skip to content

Commit 58883a5

Browse files
authored
Merge pull request rails#51371 from theodorton/relation-test-readonly
Add `ActiveRecord::Relation#readonly?`
2 parents 9232363 + d28e7c2 commit 58883a5

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

activerecord/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* Add `ActiveRecord::Relation.readonly?`
2+
3+
Reflects if the relation has been marked as readonly.
4+
5+
*Theodor Tonum*
6+
17
* Improve `ActiveRecord::Store` to raise a descriptive exception if the column is not either
28
structured (e.g., PostgreSQL +hstore+/+json+, or MySQL +json+) or declared serializable via
39
`ActiveRecord.store`.

activerecord/lib/active_record/relation.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,10 @@ def blank?
12611261
records.blank?
12621262
end
12631263

1264+
def readonly?
1265+
readonly_value
1266+
end
1267+
12641268
def values
12651269
@values.dup
12661270
end

activerecord/test/cases/readonly_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ def test_cant_update_columns_readonly_record
7979

8080
def test_find_with_readonly_option
8181
Developer.all.each { |d| assert_not d.readonly? }
82+
Developer.all.tap { |rel| assert_not rel.readonly? }
8283
Developer.readonly(false).each { |d| assert_not d.readonly? }
8384
Developer.readonly(true).each { |d| assert_predicate d, :readonly? }
8485
Developer.readonly.each { |d| assert_predicate d, :readonly? }
86+
Developer.readonly.tap { |rel| assert_predicate rel, :readonly? }
8587
end
8688

8789
def test_find_with_joins_option_does_not_imply_readonly

0 commit comments

Comments
 (0)