aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2005-10-15 00:19:56 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2005-10-15 00:19:56 +0000
commit64fcb752f2c2f337918f74cd0cc6049a4cafb7a6 (patch)
treecc274a00c8d4eda38feaf8b872b680d0b227b6cd /activerecord/test
parent6a6df5f1e297a1b93233acbd851f123232ce1acf (diff)
downloadrails-64fcb752f2c2f337918f74cd0cc6049a4cafb7a6.tar.gz
rails-64fcb752f2c2f337918f74cd0cc6049a4cafb7a6.tar.bz2
rails-64fcb752f2c2f337918f74cd0cc6049a4cafb7a6.zip
r3618@sedna: jeremy | 2005-10-14 12:06:03 -0700
Branch for :join tainting r3631@sedna: jeremy | 2005-10-14 20:13:49 -0700 Introduce read-only records, object.readonly\!, object.readonly?, Foo.find(:all, :readonly => true). Foo.find(:all, :joins => '...') also implies :readonly => true. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2594 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-xactiverecord/test/readonly_test.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/activerecord/test/readonly_test.rb b/activerecord/test/readonly_test.rb
new file mode 100755
index 0000000000..cbab35b49a
--- /dev/null
+++ b/activerecord/test/readonly_test.rb
@@ -0,0 +1,31 @@
+require 'abstract_unit'
+require 'fixtures/topic'
+
+class ReadOnlyTest < Test::Unit::TestCase
+ fixtures :topics
+
+ def test_cant_save_readonly_record
+ topic = Topic.find(:first)
+ assert !topic.readonly?
+
+ topic.readonly!
+ assert topic.readonly?
+
+ assert_nothing_raised do
+ topic.content = 'Luscious forbidden fruit.'
+ end
+
+ assert_raise(ActiveRecord::ReadOnlyRecord) { topic.save }
+ assert_raise(ActiveRecord::ReadOnlyRecord) { topic.save! }
+ end
+
+ def test_find_with_readonly_option
+ Topic.find(:all).each { |t| assert !t.readonly? }
+ Topic.find(:all, :readonly => false).each { |t| assert !t.readonly? }
+ Topic.find(:all, :readonly => true).each { |t| assert t.readonly? }
+ end
+
+ def test_find_with_joins_option_implies_readonly
+ Topic.find(:all, :joins => '').each { |t| assert t.readonly? }
+ end
+end