Skip to content

Instantly share code, notes, and snippets.

@rainhead
Created March 12, 2009 22:40
Show Gist options
  • Save rainhead/78328 to your computer and use it in GitHub Desktop.
Save rainhead/78328 to your computer and use it in GitHub Desktop.
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 429d121..c6af6eb 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
@@ -1,6 +1,8 @@
module ActiveRecord
class BaseWithoutTable < Base
self.abstract_class = true
+ class_inheritable_array :columns
+ self.columns = []
def create_or_update
errors.empty?
@@ -10,10 +12,6 @@ module ActiveRecord
private :quoted_id
class << self
- def columns()
- @columns ||= []
- end
-
def column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
reset_column_information
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 26663ba..ed3b949 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,10 @@ class Person < ActiveRecord::BaseWithoutTable
validates_presence_of :name
end
+class Employee < Person
+ column :salary, :integer
+end
+
class House < ActiveRecord::BaseWithoutTable
column :person, :string
serialize :person
@@ -54,4 +58,13 @@ class ActiveRecordBaseWithoutTableTest < Test::Unit::TestCase
assert_kind_of String, quoted
assert_match /---/, quoted
end
+
+ def test_inheritance
+ e = Employee.new
+ e.salary = 5000
+ e.name = "Enoch Root"
+
+ assert_equal "Enoch Root", e.name
+ assert_equal 5000, e.salary
+ end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment