mirror of https://github.com/rails/rails
Add `ActiveRecord::Relation#readonly?`
Indicates whether a relation was marked readonly.
This commit is contained in:
parent
9232363f4a
commit
d28e7c29a2
|
@ -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
|
* 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
|
structured (e.g., PostgreSQL +hstore+/+json+, or MySQL +json+) or declared serializable via
|
||||||
`ActiveRecord.store`.
|
`ActiveRecord.store`.
|
||||||
|
|
|
@ -1261,6 +1261,10 @@ module ActiveRecord
|
||||||
records.blank?
|
records.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def readonly?
|
||||||
|
readonly_value
|
||||||
|
end
|
||||||
|
|
||||||
def values
|
def values
|
||||||
@values.dup
|
@values.dup
|
||||||
end
|
end
|
||||||
|
|
|
@ -79,9 +79,11 @@ class ReadOnlyTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
def test_find_with_readonly_option
|
def test_find_with_readonly_option
|
||||||
Developer.all.each { |d| assert_not d.readonly? }
|
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(false).each { |d| assert_not d.readonly? }
|
||||||
Developer.readonly(true).each { |d| assert_predicate d, :readonly? }
|
Developer.readonly(true).each { |d| assert_predicate d, :readonly? }
|
||||||
Developer.readonly.each { |d| assert_predicate d, :readonly? }
|
Developer.readonly.each { |d| assert_predicate d, :readonly? }
|
||||||
|
Developer.readonly.tap { |rel| assert_predicate rel, :readonly? }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_find_with_joins_option_does_not_imply_readonly
|
def test_find_with_joins_option_does_not_imply_readonly
|
||||||
|
|
Loading…
Reference in New Issue