deep_cloneable 1.2.3 → 1.2.4

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/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.3
1
+ 1.2.4
@@ -1,49 +1,41 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{deep_cloneable}
8
- s.version = "1.2.3"
8
+ s.version = "1.2.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Reinier de Lange"]
12
- s.date = %q{2011-02-27}
12
+ s.date = %q{2011-06-15}
13
13
  s.description = %q{Extends the functionality of ActiveRecord::Base#clone to perform a deep clone that includes user specified associations. }
14
14
  s.email = %q{r.j.delange@nedforce.nl}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "deep_cloneable.gemspec",
27
- "init.rb",
28
- "lib/deep_cloneable.rb",
29
- "test/database.yml",
30
- "test/schema.rb",
31
- "test/test_deep_cloneable.rb",
32
- "test/test_helper.rb"
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "deep_cloneable.gemspec",
26
+ "init.rb",
27
+ "lib/deep_cloneable.rb",
28
+ "test/database.yml",
29
+ "test/schema.rb",
30
+ "test/test_deep_cloneable.rb",
31
+ "test/test_helper.rb"
33
32
  ]
34
33
  s.homepage = %q{http://github.com/moiristo/deep_cloneable}
35
- s.rdoc_options = ["--charset=UTF-8"]
36
34
  s.require_paths = ["lib"]
37
- s.rubygems_version = %q{1.3.7}
35
+ s.rubygems_version = %q{1.6.2}
38
36
  s.summary = %q{This gem gives every ActiveRecord::Base object the possibility to do a deep clone.}
39
- s.test_files = [
40
- "test/schema.rb",
41
- "test/test_deep_cloneable.rb",
42
- "test/test_helper.rb"
43
- ]
44
37
 
45
38
  if s.respond_to? :specification_version then
46
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
39
  s.specification_version = 3
48
40
 
49
41
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -73,6 +73,8 @@ class ActiveRecord::Base
73
73
  opts.merge!(:dictionary => dict) if dict
74
74
 
75
75
  association_reflection = self.class.reflect_on_association(association)
76
+ raise AssociationNotFoundException.new("#{self.class}##{association}") if association_reflection.nil?
77
+
76
78
  cloned_object = case association_reflection.macro
77
79
  when :belongs_to, :has_one
78
80
  self.send(association) && self.send(association).clone(opts)
@@ -83,6 +85,7 @@ class ActiveRecord::Base
83
85
 
84
86
  self.send(association).collect do |obj|
85
87
  tmp = obj.clone(opts)
88
+ tmp.send("#{association_reflection.primary_key_name.to_s}=", nil)
86
89
  tmp.send("#{reverse_association_name.to_s}=", kopy) if reverse_association_name
87
90
  tmp
88
91
  end
@@ -93,6 +96,8 @@ class ActiveRecord::Base
93
96
 
94
97
  return kopy
95
98
  end
99
+
100
+ class AssociationNotFoundException < StandardError; end
96
101
  end
97
102
 
98
103
  include DeepCloneable
@@ -38,4 +38,14 @@ ActiveRecord::Schema.define(:version => 1) do
38
38
  create_table :humen, :force => true do |t|
39
39
  t.column :name, :string
40
40
  end
41
+
42
+ create_table :chickens, :force => true do |t|
43
+ t.column :name, :string
44
+ end
45
+
46
+ create_table :ownerships, :force => true do |t|
47
+ t.column :human_id, :integer
48
+ t.column :chicken_id, :integer
49
+ end
50
+
41
51
  end
@@ -133,7 +133,19 @@ class TestDeepCloneable < Test::Unit::TestCase
133
133
  clone_human_2 = @human.clone :include => [:pigs]
134
134
  assert clone_human_2.save
135
135
  assert_equal 1, clone_human_2.pigs.count
136
- end
136
+ end
137
137
 
138
+ def test_should_clone_many_to_many_associations
139
+ @human = Animal::Human.create :name => "Michael"
140
+ @human2 = Animal::Human.create :name => "Jack"
141
+ @chicken1 = Animal::Chicken.create :name => 'Chick1'
142
+ @chicken2 = Animal::Chicken.create :name => 'Chick2'
143
+ @human.chickens << [@chicken1, @chicken2]
144
+ @human2.chickens << [@chicken1, @chicken2]
145
+
146
+ clone_human = @human.clone :include => :ownerships
147
+ assert clone_human.save
148
+ assert_equal 2, clone_human.chickens.count
149
+ end
138
150
 
139
151
  end
@@ -12,10 +12,25 @@ require File.dirname(__FILE__) + '/../init.rb'
12
12
  module Animal
13
13
  class Human < ActiveRecord::Base
14
14
  has_many :pigs
15
+
16
+ has_many :ownerships
17
+ has_many :chickens, :through => :ownerships
15
18
  end
16
19
  class Pig < ActiveRecord::Base
17
20
  belongs_to :human
18
21
  end
22
+
23
+ class Chicken < ActiveRecord::Base
24
+ has_many :ownerships
25
+ has_many :humans, :through => :ownerships
26
+ end
27
+
28
+ class Ownership < ActiveRecord::Base
29
+ belongs_to :human
30
+ belongs_to :chicken
31
+
32
+ validates_uniqueness_of :chicken_id, :scope => :human_id
33
+ end
19
34
  end
20
35
 
21
36
  class GoldPiece < ActiveRecord::Base; belongs_to :treasure end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deep_cloneable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 3
10
- version: 1.2.3
9
+ - 4
10
+ version: 1.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Reinier de Lange
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-27 00:00:00 +01:00
18
+ date: 2011-06-15 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -30,7 +30,6 @@ extra_rdoc_files:
30
30
  - README.rdoc
31
31
  files:
32
32
  - .document
33
- - .gitignore
34
33
  - LICENSE
35
34
  - README.rdoc
36
35
  - Rakefile
@@ -47,8 +46,8 @@ homepage: http://github.com/moiristo/deep_cloneable
47
46
  licenses: []
48
47
 
49
48
  post_install_message:
50
- rdoc_options:
51
- - --charset=UTF-8
49
+ rdoc_options: []
50
+
52
51
  require_paths:
53
52
  - lib
54
53
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -72,11 +71,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
71
  requirements: []
73
72
 
74
73
  rubyforge_project:
75
- rubygems_version: 1.3.7
74
+ rubygems_version: 1.6.2
76
75
  signing_key:
77
76
  specification_version: 3
78
77
  summary: This gem gives every ActiveRecord::Base object the possibility to do a deep clone.
79
- test_files:
80
- - test/schema.rb
81
- - test/test_deep_cloneable.rb
82
- - test/test_helper.rb
78
+ test_files: []
79
+
data/.gitignore DELETED
@@ -1,23 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
22
-
23
- test/debug.log