aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models/contact.rb
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-06-22 00:25:23 -0300
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-06-22 08:28:03 -0300
commit965b779eb2877c47f3bf5fe945c8f24dd576c3cd (patch)
tree795e98b14ff88d1a3c973050e1a3825886e4c11a /activerecord/test/models/contact.rb
parent70d3625760aac9994790bd023f1b5060fe1d06c5 (diff)
downloadrails-965b779eb2877c47f3bf5fe945c8f24dd576c3cd.tar.gz
rails-965b779eb2877c47f3bf5fe945c8f24dd576c3cd.tar.bz2
rails-965b779eb2877c47f3bf5fe945c8f24dd576c3cd.zip
Add some coverage for AR serialization with serializable_hash
ActiveRecord json/xml serialization should use as base serializable_hash, provided by ActiveModel. Add some more coverage around options :only and :except for both json and xml serialization.
Diffstat (limited to 'activerecord/test/models/contact.rb')
-rw-r--r--activerecord/test/models/contact.rb49
1 files changed, 32 insertions, 17 deletions
diff --git a/activerecord/test/models/contact.rb b/activerecord/test/models/contact.rb
index 3d15c7fbed..a1cb8d62b6 100644
--- a/activerecord/test/models/contact.rb
+++ b/activerecord/test/models/contact.rb
@@ -1,25 +1,40 @@
-class Contact < ActiveRecord::Base
- establish_connection(:adapter => 'fake')
+module ContactFakeColumns
+ def self.extended(base)
+ base.class_eval do
+ establish_connection(:adapter => 'fake')
+
+ connection.tables = [table_name]
+ connection.primary_keys = {
+ table_name => 'id'
+ }
+
+ column :name, :string
+ column :age, :integer
+ column :avatar, :binary
+ column :created_at, :datetime
+ column :awesome, :boolean
+ column :preferences, :string
+ column :alternative_id, :integer
+
+ serialize :preferences
- connection.tables = ['contacts']
- connection.primary_keys = {
- 'contacts' => 'id'
- }
+ belongs_to :alternative, :class_name => 'Contact'
+ end
+ end
# mock out self.columns so no pesky db is needed for these tests
- def self.column(name, sql_type = nil, options = {})
- connection.merge_column('contacts', name, sql_type, options)
+ def column(name, sql_type = nil, options = {})
+ connection.merge_column(table_name, name, sql_type, options)
end
+end
- column :name, :string
- column :age, :integer
- column :avatar, :binary
- column :created_at, :datetime
- column :awesome, :boolean
- column :preferences, :string
- column :alternative_id, :integer
+class Contact < ActiveRecord::Base
+ extend ContactFakeColumns
+end
- serialize :preferences
+class ContactSti < ActiveRecord::Base
+ extend ContactFakeColumns
+ column :type, :string
- belongs_to :alternative, :class_name => 'Contact'
+ def type; 'ContactSti' end
end