Created
March 11, 2009 18:02
-
-
Save rainhead/77608 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/activerecord_base_without_table/lib/active_record/base_without_table.rb b/activerecord_base_without_table/lib/active_record/base_without_table.rb | |
index da6cdc8..429d121 100644 | |
--- a/activerecord_base_without_table/lib/active_record/base_without_table.rb | |
+++ b/activerecord_base_without_table/lib/active_record/base_without_table.rb | |
@@ -6,6 +6,9 @@ module ActiveRecord | |
errors.empty? | |
end | |
+ # Prevent AR from associating to this record by ID; we should be serialized instead. | |
+ private :quoted_id | |
+ | |
class << self | |
def columns() | |
@columns ||= [] | |
diff --git a/activerecord_base_without_table/test/active_record_base_without_table_test.rb b/activerecord_base_without_table/test/active_record_base_without_table_test.rb | |
index 4e36e11..26663ba 100644 | |
--- a/activerecord_base_without_table/test/active_record_base_without_table_test.rb | |
+++ b/activerecord_base_without_table/test/active_record_base_without_table_test.rb | |
@@ -7,6 +7,11 @@ class Person < ActiveRecord::BaseWithoutTable | |
validates_presence_of :name | |
end | |
+class House < ActiveRecord::BaseWithoutTable | |
+ column :person, :string | |
+ serialize :person | |
+end | |
+ | |
class ActiveRecordBaseWithoutTableTest < Test::Unit::TestCase | |
def test_default_value | |
assert_equal 4, Person.new.lucky_number | |
@@ -38,4 +43,15 @@ class ActiveRecordBaseWithoutTableTest < Test::Unit::TestCase | |
Person.column :new_column, :string | |
cached_variables.each { |v| assert_nil Person.instance_variable_get("@#{v}") } | |
end | |
+ | |
+ def test_serialization | |
+ h = House.new | |
+ p = Person.new | |
+ h.person = p | |
+ | |
+ assert_instance_of Person, h.person | |
+ quoted = h.connection.quote h.person, h.column_for_attribute('person') | |
+ assert_kind_of String, quoted | |
+ assert_match /---/, quoted | |
+ end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment