Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove class method :duplicatable.

  • Loading branch information...
commit 1c3eac5a3f5486de8e752d39267d222544b861d0 1 parent a967a7b
@haihappen authored
View
2  README.md
@@ -32,7 +32,7 @@ class Tag < ActiveRecord::Base
end
class Comment < ActiveRecord::Base
- self.duplicatable = false
+ before_duplication { false }
end
# Duplicates non-copyrighted posts and tags as well, but ignores comments.
View
14 lib/activerecord-duplicate/active_record/duplicate.rb
@@ -6,16 +6,13 @@ module Duplicate
included do
class_attribute :_duplicatable_attributes
- class_attribute :_duplicatable
attr_accessor :duplication_parent
include ActiveRecord::Duplicate::Callbacks
end
- def duplicate
- return unless self.class.duplicatable
-
+ def duplicate
dup.tap do |duplicate|
attributes.each do |key, value|
value = case true
@@ -67,15 +64,6 @@ def attr_duplicatable(*attributes)
self._duplicatable_attributes = attributes.map(&:to_sym) if attributes.present?
self._duplicatable_attributes || []
end
-
- def duplicatable=(duplicatable)
- self._duplicatable = duplicatable unless duplicatable.nil?
- self.duplicatable
- end
-
- def duplicatable
- self._duplicatable.nil? ? true : !!self._duplicatable
- end
end
end
end
View
8 spec/acts_as_duplicator_spec.rb
@@ -18,11 +18,13 @@
end
- describe :duplicatable do
+ describe 'before_duplication { false }' do
it 'marks associations as non-duplicatable' do
- klass.duplicatable = false
+ klass.instance_eval do
+ before_duplication { false }
+ end
- klass.duplicatable.must_equal(false)
+ klass.new.duplicate.must_equal(false)
end
end
View
2  spec/integration_spec.rb
@@ -52,7 +52,7 @@ def increase_counter
end
class Comment < ActiveRecord::Base
- self.duplicatable = false
+ before_duplication { false }
belongs_to :post
has_many :ratings, as: :parent
Please sign in to comment.
Something went wrong with that request. Please try again.