Skip to content
Browse files

Do not delegate association columns

  • Loading branch information...
1 parent b031f45 commit 635ca56cfca63894ddb0f47e340cd8f57d8a78e8 @simeonwillbanks simeonwillbanks committed May 3, 2012
Showing with 5 additions and 0 deletions.
  1. +1 −0 lib/delegate_all_for.rb
  2. +4 −0 spec/delegate_all_for/delegate_all_for_spec.rb
View
1 lib/delegate_all_for.rb
@@ -28,6 +28,7 @@ def delegate_all_for(*attr_names)
class_eval(%{delegate :#{m}, :to => :#{association_name}})
end
(reflection.klass.column_names - exclude_columns).each do |column_name|
+ next if column_name =~ /_id$/
class_eval <<-eoruby, __FILE__, __LINE__ + 1
delegate :#{column_name}, :to => :#{association_name}
delegate :#{column_name}=, :to => :#{association_name}
View
4 spec/delegate_all_for/delegate_all_for_spec.rb
@@ -39,6 +39,10 @@ def two; 'parent' end
its(:four) { should == 'four' }
its(:extra) { should be_true }
its(:two) { should == 'parent' }
+
+ it 'does not delegate to association attributes' do
+ lambda { subject.parent_id }.should raise_error NoMethodError
+ end
end
context 'guards against user error' do

0 comments on commit 635ca56

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