activerecord-duplicate 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +10 -2
- data/README.md +1 -1
- data/activerecord-duplicate.gemspec +1 -1
- data/lib/activerecord-duplicate/duplicate.rb +2 -1
- data/spec/acts_as_duplicator_spec.rb +18 -0
- data/spec/integration_spec.rb +27 -3
- metadata +14 -14
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
|
-
|
1
|
+
## 0.6.1 (April 25, 2012)
|
2
|
+
* `attr_duplicatable` works more like `attr_accessible`, e.g it allows multiple calls and respects whitelisted attributes from the parent STI class. Should fix #1.
|
2
3
|
|
3
|
-
|
4
|
+
## 0.6.0 (April 24, 2012)
|
5
|
+
|
6
|
+
* Associations must be declared explicit as duplicatable as well, e.g:
|
7
|
+
```ruby
|
8
|
+
belongs_to :posts
|
9
|
+
|
10
|
+
attr_duplicatable :text, :posts
|
11
|
+
```
|
4
12
|
|
5
13
|
* Without specifying `attr_duplicatable`, all attributes (except the primary-key) and associations will be duplicated automatically.
|
6
14
|
This allows you to skip the `attr_duplicatable` declarations completely, if you don't have special requirements.
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# activerecord-duplicate [](http://travis-ci.org/haihappen/activerecord-duplicate)
|
2
2
|
|
3
3
|
Duplicating ActiveRecords is easy again. All you have to do:
|
4
4
|
|
@@ -67,7 +67,8 @@ module ActiveRecord::Duplicate
|
|
67
67
|
|
68
68
|
module ClassMethods
|
69
69
|
def attr_duplicatable(*attributes)
|
70
|
-
self._duplicatable_attributes
|
70
|
+
self._duplicatable_attributes ||= []
|
71
|
+
self._duplicatable_attributes = _duplicatable_attributes | attributes.map(&:to_sym) if attributes.present?
|
71
72
|
self._duplicatable_attributes
|
72
73
|
end
|
73
74
|
|
@@ -23,6 +23,24 @@ describe ActiveRecord::Duplicate do
|
|
23
23
|
|
24
24
|
klass.attr_duplicatable.must_equal([:created_at, :updated_at])
|
25
25
|
end
|
26
|
+
|
27
|
+
|
28
|
+
it 'allows multiple calls' do
|
29
|
+
klass.attr_duplicatable(:created_at)
|
30
|
+
klass.attr_duplicatable(:updated_at)
|
31
|
+
|
32
|
+
klass.attr_duplicatable.must_equal([:created_at, :updated_at])
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
it '' do
|
37
|
+
klass.attr_duplicatable(:created_at)
|
38
|
+
|
39
|
+
sti_klass = Class.new(klass)
|
40
|
+
sti_klass.attr_duplicatable(:updated_at)
|
41
|
+
|
42
|
+
sti_klass.attr_duplicatable.must_equal([:created_at, :updated_at])
|
43
|
+
end
|
26
44
|
end
|
27
45
|
|
28
46
|
|
data/spec/integration_spec.rb
CHANGED
@@ -7,9 +7,11 @@ describe 'Integration' do
|
|
7
7
|
|
8
8
|
create_table :posts do |t|
|
9
9
|
t.belongs_to :blog
|
10
|
+
t.string :type
|
10
11
|
t.string :title
|
11
12
|
t.text :content
|
12
13
|
t.boolean :is_copyrighted
|
14
|
+
t.string :url
|
13
15
|
t.timestamp :published_at
|
14
16
|
end
|
15
17
|
|
@@ -40,9 +42,17 @@ describe 'Integration' do
|
|
40
42
|
has_many :comments
|
41
43
|
has_many :ratings, as: :parent
|
42
44
|
|
43
|
-
attr_duplicatable :title, :
|
45
|
+
attr_duplicatable :title, :blog, :ratings
|
44
46
|
|
45
47
|
validates :title, presence: true, uniqueness: true
|
48
|
+
|
49
|
+
class Video < Post
|
50
|
+
attr_duplicatable :url
|
51
|
+
end
|
52
|
+
|
53
|
+
class Text < Post
|
54
|
+
attr_duplicatable :content
|
55
|
+
end
|
46
56
|
end
|
47
57
|
|
48
58
|
class Comment < ActiveRecord::Base
|
@@ -90,6 +100,21 @@ describe 'Integration' do
|
|
90
100
|
end
|
91
101
|
|
92
102
|
|
103
|
+
it 'works with STI classes too' do
|
104
|
+
blog.posts << Post::Video.new(title: 'My Video Post', url: 'http://youtube.com')
|
105
|
+
blog.posts << Post::Text.new(title: 'My Text Post', content: 'text')
|
106
|
+
|
107
|
+
Post.attr_duplicatable.must_equal([:title, :blog, :ratings])
|
108
|
+
Post::Video.attr_duplicatable.must_equal([:title, :blog, :ratings, :url])
|
109
|
+
Post::Text.attr_duplicatable.must_equal([:title, :blog, :ratings, :content])
|
110
|
+
|
111
|
+
subject.save!
|
112
|
+
|
113
|
+
Blog.count.must_equal(2)
|
114
|
+
Post.count.must_equal(4)
|
115
|
+
end
|
116
|
+
|
117
|
+
|
93
118
|
it 'sets blog association' do
|
94
119
|
%w[Sample Blog Post].each do |title|
|
95
120
|
post = blog.posts.create!(title: title)
|
@@ -123,12 +148,11 @@ describe 'Integration' do
|
|
123
148
|
|
124
149
|
|
125
150
|
it 'ignores posts published_at timestamp' do
|
126
|
-
post = blog.posts.create!(title: 'Post',
|
151
|
+
post = blog.posts.create!(title: 'Post', published_at: Time.now)
|
127
152
|
rating = post.ratings.create!(value: 5)
|
128
153
|
|
129
154
|
post = subject.posts.first
|
130
155
|
post.wont_be_nil
|
131
|
-
post.content.must_equal('Lorem')
|
132
156
|
post.published_at.must_be_nil
|
133
157
|
|
134
158
|
subject.save!
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-duplicate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &70166658693380 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70166658693380
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: minitest
|
27
|
-
requirement: &
|
27
|
+
requirement: &70166658692980 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70166658692980
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: purdytest
|
38
|
-
requirement: &
|
38
|
+
requirement: &70166658692520 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70166658692520
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rails
|
49
|
-
requirement: &
|
49
|
+
requirement: &70166658692020 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '3.1'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70166658692020
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &70166658691600 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70166658691600
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: sqlite3
|
71
|
-
requirement: &
|
71
|
+
requirement: &70166658691140 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70166658691140
|
80
80
|
description: Duplicating ActiveRecords is easy again.
|
81
81
|
email: uher.mario@gmail.com
|
82
82
|
executables: []
|