ar_merge 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -1
- data/Gemfile.lock +1 -1
- data/Readme.md +0 -4
- data/gemfiles/activerecord_2.3.gemfile.lock +1 -1
- data/gemfiles/activerecord_3.2.gemfile.lock +1 -1
- data/gemfiles/activerecord_4.0.gemfile.lock +1 -1
- data/lib/ar_merge.rb +7 -7
- data/lib/ar_merge/version.rb +1 -1
- data/spec/ar_merge_spec.rb +3 -5
- metadata +4 -4
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
data/lib/ar_merge.rb
CHANGED
@@ -9,14 +9,14 @@ module ARMerge
|
|
9
9
|
|
10
10
|
#merge associations
|
11
11
|
(options[:associations]||[]).each do |association_name|
|
12
|
-
other.send(association_name)
|
13
|
-
send(association_name) << associated
|
14
|
-
end
|
12
|
+
send(association_name).concat other.send(association_name)
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
if ActiveRecord::VERSION::MAJOR < 4
|
15
|
+
#update counters, this is very basic/hacky/not secure for customized counters...
|
16
|
+
counter = "#{association_name}_count"
|
17
|
+
next unless other.respond_to?(counter) and respond_to?("#{counter}=")
|
18
|
+
self.class.update_counters(id, counter => other.send(counter))
|
19
|
+
end
|
20
20
|
end
|
21
21
|
|
22
22
|
#merge attributes
|
data/lib/ar_merge/version.rb
CHANGED
data/spec/ar_merge_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe ARMerge do
|
|
7
7
|
@u2 = User.create!(:name=>'y')
|
8
8
|
end
|
9
9
|
|
10
|
-
describe
|
10
|
+
describe "removal" do
|
11
11
|
it "removes the merged user" do
|
12
12
|
@user.merge!(@u2)
|
13
13
|
lambda{@u2.reload}.should raise_error(ActiveRecord::RecordNotFound)
|
@@ -19,7 +19,7 @@ describe ARMerge do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe
|
22
|
+
describe "attributes" do
|
23
23
|
it "merges and overtakes attributes" do
|
24
24
|
@user.name = ''
|
25
25
|
@user.merge!(@u2,:attributes=>['name'])
|
@@ -32,7 +32,7 @@ describe ARMerge do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
describe
|
35
|
+
describe "associations" do
|
36
36
|
before do
|
37
37
|
Movie.delete_all
|
38
38
|
@user.movies << Movie.new
|
@@ -50,7 +50,6 @@ describe ARMerge do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it "keeps counters in sync" do
|
53
|
-
pending if ActiveRecord::VERSION::MAJOR == 4
|
54
53
|
user, merged_user = CountingUser.create!, CountingUser.create!
|
55
54
|
user.movies_count.should == 0
|
56
55
|
merged_user.movies << Movie.new
|
@@ -105,6 +104,5 @@ describe ARMerge do
|
|
105
104
|
ARMerge::VERSION.should_not == ActiveRecord::VERSION
|
106
105
|
defined?(ActiveRecord::Version).should == nil
|
107
106
|
defined?(ActiveRecord::Base::Version).should == nil
|
108
|
-
defined?(ActiveRecord::Base::VERSION).should == nil
|
109
107
|
end
|
110
108
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar_merge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -66,7 +66,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
66
|
version: '0'
|
67
67
|
segments:
|
68
68
|
- 0
|
69
|
-
hash: -
|
69
|
+
hash: -3638300009276460742
|
70
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
71
|
none: false
|
72
72
|
requirements:
|
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
version: '0'
|
76
76
|
segments:
|
77
77
|
- 0
|
78
|
-
hash: -
|
78
|
+
hash: -3638300009276460742
|
79
79
|
requirements: []
|
80
80
|
rubyforge_project:
|
81
81
|
rubygems_version: 1.8.25
|