Skip to content
Browse files

add supermodel attr_accessibles to submodels, version bump

  • Loading branch information...
1 parent 25c3dbd commit 37638f572ca42907396d4a8a8a7f9b7ffc39a2e5 Hassan committed Jul 5, 2012
Showing with 11 additions and 1 deletion.
  1. +2 −0 lib/active_record/acts_as_relation.rb
  2. +1 −1 lib/version.rb
  3. +6 −0 spec/acts_as_relation_spec.rb
  4. +2 −0 spec/dummy/app/models/pen.rb
View
2 lib/active_record/acts_as_relation.rb
@@ -61,6 +61,8 @@ def self.included(base)
ignored = ["created_at", "updated_at", "#{association_name}_id", "#{association_name}_type", "#{association_name}"]
attributes_to_delegate = attributes + associations - ignored
base.send :define_acts_as_accessors, attributes_to_delegate, "#{name}"
+
+ base.attr_accessible.update(#{class_name}.attr_accessible)
end
def #{name}_with_autobuild
View
2 lib/version.rb
@@ -1,5 +1,5 @@
module ActiveRecord
module ActsAsRelation
- VERSION = "0.1.1"
+ VERSION = "0.1.2"
end
end
View
6 spec/acts_as_relation_spec.rb
@@ -71,6 +71,12 @@
end
end
+ it "have supermodel attr_accessibles as attr_accessibles" do
+ Pen.attr_accessible[:default].each do |a|
+ Pencil.attr_accessible[:default].should include(a)
+ end
+ end
+
it "should be findable" do
pen = Pen.create :name => 'RedPen', :price => 0.8, :color => 'red'
pen = Pen.find(pen.id)
View
2 spec/dummy/app/models/pen.rb
@@ -2,5 +2,7 @@ class Pen < ActiveRecord::Base
acts_as_superclass
acts_as :product, as: 'producible'
+ attr_accessible :name, :price, :color
+
validates_presence_of :color
end

0 comments on commit 37638f5

Please sign in to comment.
Something went wrong with that request. Please try again.