activerecord-duplicate 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,14 @@
1
- # 0.6.0 (April 24, 2012)
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
- * Associations must be declared explicit as duplicatable as well, e.g. `belongs_to :posts; attr_duplicatable :text, :posts`.
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
- ## activerecord-duplicate [![Build Status](https://secure.travis-ci.org/haihappen/activerecord-duplicate.png)](http://travis-ci.org/haihappen/activerecord-duplicate)
1
+ # activerecord-duplicate [![Build Status](https://secure.travis-ci.org/haihappen/activerecord-duplicate.png)](http://travis-ci.org/haihappen/activerecord-duplicate)
2
2
 
3
3
  Duplicating ActiveRecords is easy again. All you have to do:
4
4
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'activerecord-duplicate'
3
- gem.version = '0.6.0'
3
+ gem.version = '0.6.1'
4
4
  gem.authors = 'Mario Uher'
5
5
  gem.email = 'uher.mario@gmail.com'
6
6
  gem.description = gem.summary = 'Duplicating ActiveRecords is easy again.'
@@ -67,7 +67,8 @@ module ActiveRecord::Duplicate
67
67
 
68
68
  module ClassMethods
69
69
  def attr_duplicatable(*attributes)
70
- self._duplicatable_attributes = attributes.map(&:to_sym) if attributes.present?
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
 
@@ -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, :content, :blog, :ratings
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', content: 'Lorem', published_at: Time.now)
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.0
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-24 00:00:00.000000000 Z
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: &70185001321060 !ruby/object:Gem::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: *70185001321060
24
+ version_requirements: *70166658693380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: minitest
27
- requirement: &70185001320660 !ruby/object:Gem::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: *70185001320660
35
+ version_requirements: *70166658692980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: purdytest
38
- requirement: &70185001369300 !ruby/object:Gem::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: *70185001369300
46
+ version_requirements: *70166658692520
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rails
49
- requirement: &70185001368800 !ruby/object:Gem::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: *70185001368800
57
+ version_requirements: *70166658692020
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &70185001368380 !ruby/object:Gem::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: *70185001368380
68
+ version_requirements: *70166658691600
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
- requirement: &70185001367920 !ruby/object:Gem::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: *70185001367920
79
+ version_requirements: *70166658691140
80
80
  description: Duplicating ActiveRecords is easy again.
81
81
  email: uher.mario@gmail.com
82
82
  executables: []