active_record_inherit_assoc 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 68f5c1fa10a139e363086482ac9016918c6a9cc2
4
+ data.tar.gz: 4bbd75ce69f53018564f83dacf7d4f305d3e57d0
5
+ SHA512:
6
+ metadata.gz: d09953245b3770aeaeaf21c29bb5d1a940abdacae4c8f15356b2aab5af1134f5043fa90011d4b0e208f6c89b80489654147bfbe3c63d56c6728ed6978b619322
7
+ data.tar.gz: c69f7e24d708a3dd0f68b86715119068c9eabdac447046c8fcb87af4ccf37c62975b306fee004b5e0d29d6dce33b0bbc7f77ad922788137b69e4f296b91683be
@@ -1,16 +1,8 @@
1
1
  script: "bundle exec rake test"
2
2
  rvm:
3
- - 1.8.7
4
3
  - 1.9.3
5
4
  - 2.0
5
+ - 2.1.1
6
6
  gemfile:
7
- - gemfiles/rails2.3.gemfile
8
- - gemfiles/rails3.0.gemfile
9
- - gemfiles/rails3.1.gemfile
10
7
  - gemfiles/rails3.2.gemfile
11
- matrix:
12
- exclude:
13
- - rvm: 2.0
14
- gemfile: gemfiles/rails2.3.gemfile
15
- - rvm: 2.0
16
- gemfile: gemfiles/rails3.0.gemfile
8
+ - gemfiles/rails4.gemfile
data/Appraisals CHANGED
@@ -1,15 +1,7 @@
1
- appraise "rails2.3" do
2
- gem "activerecord", "~> 2.3.14", :require => 'active_record'
3
- end
4
-
5
- appraise "rails3.0" do
6
- gem "activerecord", "~> 3.0.15", :require => 'active_record'
7
- end
8
-
9
- appraise "rails3.1" do
10
- gem "activerecord", "~> 3.1.0", :require => 'active_record'
11
- end
12
-
13
1
  appraise "rails3.2" do
14
2
  gem "activerecord", "~> 3.2.0", :require => 'active_record'
15
3
  end
4
+
5
+ appraise "rails4" do
6
+ gem "activerecord", "~> 4.0", :require => 'active_record'
7
+ end
data/Gemfile CHANGED
@@ -1,8 +1,9 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'appraisal'
5
+ gem 'minitest'
6
+ gem 'appraisal', '< 1'
6
7
  gem 'rake'
7
8
  gem 'rails'
8
9
  gem 'bundler'
@@ -12,5 +13,7 @@ gem 'shoulda'
12
13
  gem 'jeweler'
13
14
  gem 'ruby-debug', :platforms => :ruby_18
14
15
  gem 'debugger', :platforms => :ruby_19
16
+ gem 'byebug', :platforms => [:ruby_20, :ruby_21]
15
17
  gem 'test-unit', '>=2.5.1'
16
18
  gem 'activerecord', :require => 'active_record'
19
+ gem "activesupport"
@@ -1,13 +1,13 @@
1
1
  $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
2
  name = "active_record_inherit_assoc"
3
3
 
4
- Gem::Specification.new name, "1.1.0" do |s|
4
+ Gem::Specification.new name, "2.0.0" do |s|
5
5
  s.summary = "Attribute inheritance for AR associations"
6
6
  s.authors = ["Ben Osheroff"]
7
7
  s.email = ["ben@gimbo.net"]
8
8
  s.files = `git ls-files`.split("\n")
9
9
  s.license = "Apache License Version 2.0"
10
10
  s.homepage = "http://github.com/zendesk/#{name}"
11
- s.add_runtime_dependency "activerecord"
11
+ s.add_runtime_dependency "activerecord", ">=3.2.0", "< 5"
12
12
  end
13
13
 
@@ -1,8 +1,9 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source :rubygems
3
+ source "https://rubygems.org"
4
4
 
5
- gem "appraisal"
5
+ gem "minitest"
6
+ gem "appraisal", "< 1"
6
7
  gem "rake"
7
8
  gem "rails"
8
9
  gem "bundler"
@@ -12,7 +13,9 @@ gem "shoulda"
12
13
  gem "jeweler"
13
14
  gem "ruby-debug", :platforms=>:ruby_18
14
15
  gem "debugger", :platforms=>:ruby_19
16
+ gem "byebug", :platforms=>[:ruby_20, :ruby_21]
15
17
  gem "test-unit", ">=2.5.1"
18
+ gem "activesupport"
16
19
  gem "activerecord", "~> 3.2.0", :require=>"active_record"
17
20
 
18
21
  gemspec :path=>"../"
@@ -1,18 +1,18 @@
1
1
  PATH
2
- remote: /Users/staugaard/code/active_record_inherit_assoc
2
+ remote: ../
3
3
  specs:
4
- active_record_inherit_assoc (1.1.0)
5
- activerecord
4
+ active_record_inherit_assoc (2.0.0)
5
+ activerecord (>= 3.2.0, < 5)
6
6
 
7
7
  GEM
8
- remote: http://rubygems.org/
8
+ remote: https://rubygems.org/
9
9
  specs:
10
- actionmailer (3.2.13)
11
- actionpack (= 3.2.13)
12
- mail (~> 2.5.3)
13
- actionpack (3.2.13)
14
- activemodel (= 3.2.13)
15
- activesupport (= 3.2.13)
10
+ actionmailer (3.2.18)
11
+ actionpack (= 3.2.18)
12
+ mail (~> 2.5.4)
13
+ actionpack (3.2.18)
14
+ activemodel (= 3.2.18)
15
+ activesupport (= 3.2.18)
16
16
  builder (~> 3.0.0)
17
17
  erubis (~> 2.7.0)
18
18
  journey (~> 1.0.4)
@@ -20,93 +20,138 @@ GEM
20
20
  rack-cache (~> 1.2)
21
21
  rack-test (~> 0.6.1)
22
22
  sprockets (~> 2.2.1)
23
- activemodel (3.2.13)
24
- activesupport (= 3.2.13)
23
+ activemodel (3.2.18)
24
+ activesupport (= 3.2.18)
25
25
  builder (~> 3.0.0)
26
- activerecord (3.2.13)
27
- activemodel (= 3.2.13)
28
- activesupport (= 3.2.13)
26
+ activerecord (3.2.18)
27
+ activemodel (= 3.2.18)
28
+ activesupport (= 3.2.18)
29
29
  arel (~> 3.0.2)
30
30
  tzinfo (~> 0.3.29)
31
- activesupport (3.2.13)
32
- i18n (= 0.6.1)
31
+ activeresource (3.2.18)
32
+ activemodel (= 3.2.18)
33
+ activesupport (= 3.2.18)
34
+ activesupport (3.2.18)
35
+ i18n (~> 0.6, >= 0.6.4)
33
36
  multi_json (~> 1.0)
37
+ addressable (2.3.6)
34
38
  appraisal (0.5.2)
35
39
  bundler
36
40
  rake
37
- arel (3.0.2)
38
- bourne (1.4.0)
39
- mocha (~> 0.13.2)
41
+ arel (3.0.3)
40
42
  builder (3.0.4)
41
- bump (0.4.1)
42
- columnize (0.3.6)
43
- debugger (1.5.0)
43
+ bump (0.5.0)
44
+ byebug (3.1.2)
45
+ columnize (~> 0.8)
46
+ debugger-linecache (~> 1.2)
47
+ columnize (0.8.9)
48
+ debugger (1.6.8)
44
49
  columnize (>= 0.3.1)
45
50
  debugger-linecache (~> 1.2.0)
46
- debugger-ruby_core_source (~> 1.2.0)
51
+ debugger-ruby_core_source (~> 1.3.5)
47
52
  debugger-linecache (1.2.0)
48
- debugger-ruby_core_source (1.2.0)
53
+ debugger-ruby_core_source (1.3.5)
54
+ descendants_tracker (0.0.4)
55
+ thread_safe (~> 0.3, >= 0.3.1)
49
56
  erubis (2.7.0)
50
- git (1.2.5)
51
- hike (1.2.2)
52
- i18n (0.6.1)
53
- jeweler (1.8.4)
54
- bundler (~> 1.0)
57
+ faraday (0.9.0)
58
+ multipart-post (>= 1.2, < 3)
59
+ git (1.2.7)
60
+ github_api (0.11.3)
61
+ addressable (~> 2.3)
62
+ descendants_tracker (~> 0.0.1)
63
+ faraday (~> 0.8, < 0.10)
64
+ hashie (>= 1.2)
65
+ multi_json (>= 1.7.5, < 2.0)
66
+ nokogiri (~> 1.6.0)
67
+ oauth2
68
+ hashie (3.1.0)
69
+ highline (1.6.21)
70
+ hike (1.2.3)
71
+ i18n (0.6.9)
72
+ jeweler (2.0.1)
73
+ builder
74
+ bundler (>= 1.0)
55
75
  git (>= 1.2.5)
76
+ github_api
77
+ highline (>= 1.6.15)
78
+ nokogiri (>= 1.5.10)
56
79
  rake
57
80
  rdoc
58
81
  journey (1.0.4)
59
- json (1.7.7)
82
+ json (1.8.1)
83
+ jwt (1.0.0)
60
84
  linecache (0.46)
61
85
  rbx-require-relative (> 0.0.4)
62
- mail (2.5.3)
63
- i18n (>= 0.4.0)
86
+ mail (2.5.4)
64
87
  mime-types (~> 1.16)
65
88
  treetop (~> 1.4.8)
66
- metaclass (0.0.1)
67
- mime-types (1.23)
68
- mocha (0.13.3)
69
- metaclass (~> 0.0.1)
70
- multi_json (1.7.2)
71
- polyglot (0.3.3)
89
+ mime-types (1.25.1)
90
+ mini_portile (0.6.0)
91
+ minitest (5.3.5)
92
+ multi_json (1.10.1)
93
+ multi_xml (0.5.5)
94
+ multipart-post (2.0.0)
95
+ nokogiri (1.6.2.1)
96
+ mini_portile (= 0.6.0)
97
+ oauth2 (0.9.4)
98
+ faraday (>= 0.8, < 0.10)
99
+ jwt (~> 1.0)
100
+ multi_json (~> 1.3)
101
+ multi_xml (~> 0.5)
102
+ rack (~> 1.2)
103
+ polyglot (0.3.5)
72
104
  rack (1.4.5)
73
105
  rack-cache (1.2)
74
106
  rack (>= 0.4)
107
+ rack-ssl (1.3.4)
108
+ rack
75
109
  rack-test (0.6.2)
76
110
  rack (>= 1.0)
77
- rails (0.9.5)
78
- actionmailer (>= 0.6.1)
79
- actionpack (>= 1.4.0)
80
- activerecord (>= 1.6.0)
81
- rake (>= 0.4.15)
82
- rake (10.0.4)
111
+ rails (3.2.18)
112
+ actionmailer (= 3.2.18)
113
+ actionpack (= 3.2.18)
114
+ activerecord (= 3.2.18)
115
+ activeresource (= 3.2.18)
116
+ activesupport (= 3.2.18)
117
+ bundler (~> 1.0)
118
+ railties (= 3.2.18)
119
+ railties (3.2.18)
120
+ actionpack (= 3.2.18)
121
+ activesupport (= 3.2.18)
122
+ rack-ssl (~> 1.3.2)
123
+ rake (>= 0.8.7)
124
+ rdoc (~> 3.4)
125
+ thor (>= 0.14.6, < 2.0)
126
+ rake (10.3.2)
83
127
  rbx-require-relative (0.0.9)
84
- rdoc (4.0.1)
128
+ rdoc (3.12.2)
85
129
  json (~> 1.4)
86
130
  ruby-debug (0.10.4)
87
131
  columnize (>= 0.1)
88
132
  ruby-debug-base (~> 0.10.4.0)
89
133
  ruby-debug-base (0.10.4)
90
134
  linecache (>= 0.3)
91
- shoulda (3.4.0)
135
+ shoulda (3.5.0)
92
136
  shoulda-context (~> 1.0, >= 1.0.1)
93
- shoulda-matchers (~> 1.0, >= 1.4.1)
94
- shoulda-context (1.1.1)
95
- shoulda-matchers (1.5.6)
137
+ shoulda-matchers (>= 1.4.1, < 3.0)
138
+ shoulda-context (1.2.1)
139
+ shoulda-matchers (2.6.1)
96
140
  activesupport (>= 3.0.0)
97
- bourne (~> 1.3)
98
141
  sprockets (2.2.2)
99
142
  hike (~> 1.2)
100
143
  multi_json (~> 1.0)
101
144
  rack (~> 1.0)
102
145
  tilt (~> 1.1, != 1.3.0)
103
- sqlite3 (1.3.7)
104
- test-unit (2.5.4)
105
- tilt (1.4.0)
106
- treetop (1.4.12)
146
+ sqlite3 (1.3.9)
147
+ test-unit (2.5.5)
148
+ thor (0.19.1)
149
+ thread_safe (0.3.4)
150
+ tilt (1.4.1)
151
+ treetop (1.4.15)
107
152
  polyglot
108
153
  polyglot (>= 0.3.1)
109
- tzinfo (0.3.37)
154
+ tzinfo (0.3.39)
110
155
 
111
156
  PLATFORMS
112
157
  ruby
@@ -114,11 +159,14 @@ PLATFORMS
114
159
  DEPENDENCIES
115
160
  active_record_inherit_assoc!
116
161
  activerecord (~> 3.2.0)
117
- appraisal
162
+ activesupport
163
+ appraisal (< 1)
118
164
  bump
119
165
  bundler
166
+ byebug
120
167
  debugger
121
168
  jeweler
169
+ minitest
122
170
  rails
123
171
  rake
124
172
  ruby-debug
@@ -1,8 +1,9 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source :rubygems
3
+ source "https://rubygems.org"
4
4
 
5
- gem "appraisal"
5
+ gem "minitest"
6
+ gem "appraisal", "< 1"
6
7
  gem "rake"
7
8
  gem "rails"
8
9
  gem "bundler"
@@ -12,7 +13,9 @@ gem "shoulda"
12
13
  gem "jeweler"
13
14
  gem "ruby-debug", :platforms=>:ruby_18
14
15
  gem "debugger", :platforms=>:ruby_19
16
+ gem "byebug", :platforms=>[:ruby_20, :ruby_21]
15
17
  gem "test-unit", ">=2.5.1"
16
- gem "activerecord", "~> 2.3.14", :require=>"active_record"
18
+ gem "activesupport"
19
+ gem "activerecord", "~> 4.0", :require=>"active_record"
17
20
 
18
21
  gemspec :path=>"../"
@@ -0,0 +1,174 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ active_record_inherit_assoc (2.0.0)
5
+ activerecord (>= 3.2.0, < 5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionmailer (4.1.2)
11
+ actionpack (= 4.1.2)
12
+ actionview (= 4.1.2)
13
+ mail (~> 2.5.4)
14
+ actionpack (4.1.2)
15
+ actionview (= 4.1.2)
16
+ activesupport (= 4.1.2)
17
+ rack (~> 1.5.2)
18
+ rack-test (~> 0.6.2)
19
+ actionview (4.1.2)
20
+ activesupport (= 4.1.2)
21
+ builder (~> 3.1)
22
+ erubis (~> 2.7.0)
23
+ activemodel (4.1.2)
24
+ activesupport (= 4.1.2)
25
+ builder (~> 3.1)
26
+ activerecord (4.1.2)
27
+ activemodel (= 4.1.2)
28
+ activesupport (= 4.1.2)
29
+ arel (~> 5.0.0)
30
+ activesupport (4.1.2)
31
+ i18n (~> 0.6, >= 0.6.9)
32
+ json (~> 1.7, >= 1.7.7)
33
+ minitest (~> 5.1)
34
+ thread_safe (~> 0.1)
35
+ tzinfo (~> 1.1)
36
+ addressable (2.3.6)
37
+ appraisal (0.5.2)
38
+ bundler
39
+ rake
40
+ arel (5.0.1.20140414130214)
41
+ builder (3.2.2)
42
+ bump (0.5.0)
43
+ byebug (3.1.2)
44
+ columnize (~> 0.8)
45
+ debugger-linecache (~> 1.2)
46
+ columnize (0.8.9)
47
+ debugger (1.6.8)
48
+ columnize (>= 0.3.1)
49
+ debugger-linecache (~> 1.2.0)
50
+ debugger-ruby_core_source (~> 1.3.5)
51
+ debugger-linecache (1.2.0)
52
+ debugger-ruby_core_source (1.3.5)
53
+ descendants_tracker (0.0.4)
54
+ thread_safe (~> 0.3, >= 0.3.1)
55
+ erubis (2.7.0)
56
+ faraday (0.9.0)
57
+ multipart-post (>= 1.2, < 3)
58
+ git (1.2.7)
59
+ github_api (0.11.3)
60
+ addressable (~> 2.3)
61
+ descendants_tracker (~> 0.0.1)
62
+ faraday (~> 0.8, < 0.10)
63
+ hashie (>= 1.2)
64
+ multi_json (>= 1.7.5, < 2.0)
65
+ nokogiri (~> 1.6.0)
66
+ oauth2
67
+ hashie (3.1.0)
68
+ highline (1.6.21)
69
+ hike (1.2.3)
70
+ i18n (0.6.9)
71
+ jeweler (2.0.1)
72
+ builder
73
+ bundler (>= 1.0)
74
+ git (>= 1.2.5)
75
+ github_api
76
+ highline (>= 1.6.15)
77
+ nokogiri (>= 1.5.10)
78
+ rake
79
+ rdoc
80
+ json (1.8.1)
81
+ jwt (1.0.0)
82
+ linecache (0.46)
83
+ rbx-require-relative (> 0.0.4)
84
+ mail (2.5.4)
85
+ mime-types (~> 1.16)
86
+ treetop (~> 1.4.8)
87
+ mime-types (1.25.1)
88
+ mini_portile (0.6.0)
89
+ minitest (5.3.5)
90
+ multi_json (1.10.1)
91
+ multi_xml (0.5.5)
92
+ multipart-post (2.0.0)
93
+ nokogiri (1.6.2.1)
94
+ mini_portile (= 0.6.0)
95
+ oauth2 (0.9.4)
96
+ faraday (>= 0.8, < 0.10)
97
+ jwt (~> 1.0)
98
+ multi_json (~> 1.3)
99
+ multi_xml (~> 0.5)
100
+ rack (~> 1.2)
101
+ polyglot (0.3.5)
102
+ rack (1.5.2)
103
+ rack-test (0.6.2)
104
+ rack (>= 1.0)
105
+ rails (4.1.2)
106
+ actionmailer (= 4.1.2)
107
+ actionpack (= 4.1.2)
108
+ actionview (= 4.1.2)
109
+ activemodel (= 4.1.2)
110
+ activerecord (= 4.1.2)
111
+ activesupport (= 4.1.2)
112
+ bundler (>= 1.3.0, < 2.0)
113
+ railties (= 4.1.2)
114
+ sprockets-rails (~> 2.0)
115
+ railties (4.1.2)
116
+ actionpack (= 4.1.2)
117
+ activesupport (= 4.1.2)
118
+ rake (>= 0.8.7)
119
+ thor (>= 0.18.1, < 2.0)
120
+ rake (10.3.2)
121
+ rbx-require-relative (0.0.9)
122
+ rdoc (4.1.1)
123
+ json (~> 1.4)
124
+ ruby-debug (0.10.4)
125
+ columnize (>= 0.1)
126
+ ruby-debug-base (~> 0.10.4.0)
127
+ ruby-debug-base (0.10.4)
128
+ linecache (>= 0.3)
129
+ shoulda (3.5.0)
130
+ shoulda-context (~> 1.0, >= 1.0.1)
131
+ shoulda-matchers (>= 1.4.1, < 3.0)
132
+ shoulda-context (1.2.1)
133
+ shoulda-matchers (2.6.1)
134
+ activesupport (>= 3.0.0)
135
+ sprockets (2.12.1)
136
+ hike (~> 1.2)
137
+ multi_json (~> 1.0)
138
+ rack (~> 1.0)
139
+ tilt (~> 1.1, != 1.3.0)
140
+ sprockets-rails (2.1.3)
141
+ actionpack (>= 3.0)
142
+ activesupport (>= 3.0)
143
+ sprockets (~> 2.8)
144
+ sqlite3 (1.3.9)
145
+ test-unit (2.5.5)
146
+ thor (0.19.1)
147
+ thread_safe (0.3.4)
148
+ tilt (1.4.1)
149
+ treetop (1.4.15)
150
+ polyglot
151
+ polyglot (>= 0.3.1)
152
+ tzinfo (1.2.1)
153
+ thread_safe (~> 0.1)
154
+
155
+ PLATFORMS
156
+ ruby
157
+
158
+ DEPENDENCIES
159
+ active_record_inherit_assoc!
160
+ activerecord (~> 4.0)
161
+ activesupport
162
+ appraisal (< 1)
163
+ bump
164
+ bundler
165
+ byebug
166
+ debugger
167
+ jeweler
168
+ minitest
169
+ rails
170
+ rake
171
+ ruby-debug
172
+ shoulda
173
+ sqlite3
174
+ test-unit (>= 2.5.1)
@@ -1,9 +1,30 @@
1
1
  require 'active_record'
2
2
 
3
- if ActiveRecord::VERSION::STRING < "3.1"
4
- require 'active_record_inherit_assoc/ar_23_and_30'
3
+ if ActiveRecord::VERSION::MAJOR < 4
4
+ ActiveRecord::Associations::Builder::HasMany.valid_options << :inherit
5
+ ActiveRecord::Associations::Builder::HasOne.valid_options << :inherit
6
+ ActiveRecord::Associations::Builder::BelongsTo.valid_options << :inherit
5
7
  else
6
- require 'active_record_inherit_assoc/ar_31_and_32'
8
+ ActiveRecord::Associations::Builder::Association.valid_options << :inherit
9
+ end
10
+
11
+ ActiveRecord::Associations::Association.class_eval do
12
+ def association_scope_with_value_inheritance
13
+ if inherited_attributes = attribute_inheritance_hash
14
+ association_scope_without_value_inheritance.where(inherited_attributes)
15
+ else
16
+ association_scope_without_value_inheritance
17
+ end
18
+ end
19
+
20
+ alias_method_chain :association_scope, :value_inheritance
21
+
22
+ private
23
+
24
+ def attribute_inheritance_hash
25
+ return nil unless reflection.options[:inherit]
26
+ Array(reflection.options[:inherit]).inject({}) { |hash, obj| hash[obj] = owner.send(obj) ; hash }
27
+ end
7
28
  end
8
29
 
9
30
  class ActiveRecord::Base
@@ -2,8 +2,14 @@ require 'bundler'
2
2
  Bundler.setup
3
3
  Bundler.require
4
4
 
5
+ if ActiveRecord::VERSION::MAJOR == 4
6
+ # voodoo!
7
+ require 'minitest/autorun'
8
+ end
9
+
5
10
  require 'active_support/test_case'
6
11
 
12
+
7
13
  ActiveRecord::Base.establish_connection(
8
14
  :adapter => "sqlite3",
9
15
  :database => ":memory:"
@@ -5,7 +5,9 @@ class TestInheritAssoc < ActiveSupport::TestCase
5
5
  has_many :others, :inherit => :account_id
6
6
  has_one :third, :inherit => :account_id
7
7
  has_many :fourths, :inherit => [:account_id, :blah_id]
8
- has_many :conditional_others, :inherit => :account_id, :conditions => {:val => "foo"}, :class_name => "Other"
8
+ if ActiveRecord::VERSION::MAJOR < 4
9
+ has_many :conditional_others, :inherit => :account_id, :conditions => {:val => "foo"}, :class_name => "Other"
10
+ end
9
11
  end
10
12
 
11
13
  class Other < ActiveRecord::Base
@@ -32,16 +34,31 @@ class TestInheritAssoc < ActiveSupport::TestCase
32
34
  assert_equal 2, @main.others.size
33
35
  end
34
36
 
35
- should "set conditions on find" do
36
- assert_equal 2, @main.others.find(:all).size
37
- end
37
+ if ActiveRecord::VERSION::MAJOR < 4
38
+ should "set conditions on find" do
39
+ assert_equal 2, @main.others.find(:all).size
40
+ end
38
41
 
39
- should "merge conditions on find" do
40
- assert_equal 1, @main.others.all(:conditions => "val = 'foo'").size
41
- end
42
+ should "merge conditions on find" do
43
+ assert_equal 1, @main.others.all(:conditions => "val = 'foo'").size
44
+ end
45
+
46
+ should "merge conditions" do
47
+ assert_equal 1, @main.conditional_others.size
48
+ end
49
+ else
50
+ should "set conditions on find" do
51
+ assert_equal 2, @main.others.all.size
52
+ end
53
+
54
+ should "merge conditions on find" do
55
+ assert_equal 1, @main.others.all.where("val = 'foo'").size
56
+ end
57
+
58
+ should_eventually "merge conditions" do
59
+ assert_equal 1, @main.conditional_others.size
60
+ end
42
61
 
43
- should "merge conditions" do
44
- assert_equal 1, @main.conditional_others.size
45
62
  end
46
63
  end
47
64
 
@@ -95,5 +112,4 @@ class TestInheritAssoc < ActiveSupport::TestCase
95
112
  other = main.create_third
96
113
  assert_equal main.account_id, other.account_id
97
114
  end
98
-
99
115
  end
metadata CHANGED
@@ -1,32 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_inherit_assoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ben Osheroff
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-02 00:00:00.000000000 Z
11
+ date: 2014-07-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
19
+ version: 3.2.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5'
22
23
  type: :runtime
23
24
  prerelease: false
24
25
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.0
30
+ - - "<"
28
31
  - !ruby/object:Gem::Version
29
- version: '0'
32
+ version: '5'
30
33
  description:
31
34
  email:
32
35
  - ben@gimbo.net
@@ -34,25 +37,19 @@ executables: []
34
37
  extensions: []
35
38
  extra_rdoc_files: []
36
39
  files:
37
- - .gitignore
38
- - .travis.yml
40
+ - ".gitignore"
41
+ - ".travis.yml"
39
42
  - Appraisals
40
43
  - Gemfile
41
44
  - LICENSE
42
45
  - README.md
43
46
  - Rakefile
44
47
  - active_record_inherit_assoc.gemspec
45
- - gemfiles/rails2.3.gemfile
46
- - gemfiles/rails2.3.gemfile.lock
47
- - gemfiles/rails3.0.gemfile
48
- - gemfiles/rails3.0.gemfile.lock
49
- - gemfiles/rails3.1.gemfile
50
- - gemfiles/rails3.1.gemfile.lock
51
48
  - gemfiles/rails3.2.gemfile
52
49
  - gemfiles/rails3.2.gemfile.lock
50
+ - gemfiles/rails4.gemfile
51
+ - gemfiles/rails4.gemfile.lock
53
52
  - lib/active_record_inherit_assoc.rb
54
- - lib/active_record_inherit_assoc/ar_23_and_30.rb
55
- - lib/active_record_inherit_assoc/ar_31_and_32.rb
56
53
  - test/helper.rb
57
54
  - test/schema.rb
58
55
  - test/test_belongs_to_association.rb
@@ -60,32 +57,25 @@ files:
60
57
  homepage: http://github.com/zendesk/active_record_inherit_assoc
61
58
  licenses:
62
59
  - Apache License Version 2.0
60
+ metadata: {}
63
61
  post_install_message:
64
62
  rdoc_options: []
65
63
  require_paths:
66
64
  - lib
67
65
  required_ruby_version: !ruby/object:Gem::Requirement
68
- none: false
69
66
  requirements:
70
- - - ! '>='
67
+ - - ">="
71
68
  - !ruby/object:Gem::Version
72
69
  version: '0'
73
- segments:
74
- - 0
75
- hash: 738801861665246186
76
70
  required_rubygems_version: !ruby/object:Gem::Requirement
77
- none: false
78
71
  requirements:
79
- - - ! '>='
72
+ - - ">="
80
73
  - !ruby/object:Gem::Version
81
74
  version: '0'
82
- segments:
83
- - 0
84
- hash: 738801861665246186
85
75
  requirements: []
86
76
  rubyforge_project:
87
- rubygems_version: 1.8.25
77
+ rubygems_version: 2.2.2
88
78
  signing_key:
89
- specification_version: 3
79
+ specification_version: 4
90
80
  summary: Attribute inheritance for AR associations
91
81
  test_files: []
@@ -1,81 +0,0 @@
1
- PATH
2
- remote: /Users/staugaard/code/active_record_inherit_assoc
3
- specs:
4
- active_record_inherit_assoc (1.1.0)
5
- activerecord
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- actionmailer (2.3.18)
11
- actionpack (= 2.3.18)
12
- actionpack (2.3.18)
13
- activesupport (= 2.3.18)
14
- rack (~> 1.1.0)
15
- activerecord (2.3.18)
16
- activesupport (= 2.3.18)
17
- activeresource (2.3.18)
18
- activesupport (= 2.3.18)
19
- activesupport (2.3.18)
20
- appraisal (0.5.2)
21
- bundler
22
- rake
23
- bump (0.4.1)
24
- columnize (0.3.6)
25
- debugger (1.5.0)
26
- columnize (>= 0.3.1)
27
- debugger-linecache (~> 1.2.0)
28
- debugger-ruby_core_source (~> 1.2.0)
29
- debugger-linecache (1.2.0)
30
- debugger-ruby_core_source (1.2.0)
31
- git (1.2.5)
32
- jeweler (1.8.4)
33
- bundler (~> 1.0)
34
- git (>= 1.2.5)
35
- rake
36
- rdoc
37
- json (1.7.7)
38
- linecache (0.46)
39
- rbx-require-relative (> 0.0.4)
40
- rack (1.1.6)
41
- rails (2.3.18)
42
- actionmailer (= 2.3.18)
43
- actionpack (= 2.3.18)
44
- activerecord (= 2.3.18)
45
- activeresource (= 2.3.18)
46
- activesupport (= 2.3.18)
47
- rake (>= 0.8.3)
48
- rake (10.0.4)
49
- rbx-require-relative (0.0.9)
50
- rdoc (4.0.1)
51
- json (~> 1.4)
52
- ruby-debug (0.10.4)
53
- columnize (>= 0.1)
54
- ruby-debug-base (~> 0.10.4.0)
55
- ruby-debug-base (0.10.4)
56
- linecache (>= 0.3)
57
- shoulda (3.0.1)
58
- shoulda-context (~> 1.0.0)
59
- shoulda-matchers (~> 1.0.0)
60
- shoulda-context (1.0.2)
61
- shoulda-matchers (1.0.0)
62
- sqlite3 (1.3.7)
63
- test-unit (2.5.4)
64
-
65
- PLATFORMS
66
- ruby
67
-
68
- DEPENDENCIES
69
- active_record_inherit_assoc!
70
- activerecord (~> 2.3.14)
71
- appraisal
72
- bump
73
- bundler
74
- debugger
75
- jeweler
76
- rails
77
- rake
78
- ruby-debug
79
- shoulda
80
- sqlite3
81
- test-unit (>= 2.5.1)
@@ -1,18 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source :rubygems
4
-
5
- gem "appraisal"
6
- gem "rake"
7
- gem "rails"
8
- gem "bundler"
9
- gem "bump"
10
- gem "sqlite3"
11
- gem "shoulda"
12
- gem "jeweler"
13
- gem "ruby-debug", :platforms=>:ruby_18
14
- gem "debugger", :platforms=>:ruby_19
15
- gem "test-unit", ">=2.5.1"
16
- gem "activerecord", "~> 3.0.15", :require=>"active_record"
17
-
18
- gemspec :path=>"../"
@@ -1,120 +0,0 @@
1
- PATH
2
- remote: /Users/staugaard/code/active_record_inherit_assoc
3
- specs:
4
- active_record_inherit_assoc (1.1.0)
5
- activerecord
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- abstract (1.0.0)
11
- actionmailer (3.0.20)
12
- actionpack (= 3.0.20)
13
- mail (~> 2.2.19)
14
- actionpack (3.0.20)
15
- activemodel (= 3.0.20)
16
- activesupport (= 3.0.20)
17
- builder (~> 2.1.2)
18
- erubis (~> 2.6.6)
19
- i18n (~> 0.5.0)
20
- rack (~> 1.2.5)
21
- rack-mount (~> 0.6.14)
22
- rack-test (~> 0.5.7)
23
- tzinfo (~> 0.3.23)
24
- activemodel (3.0.20)
25
- activesupport (= 3.0.20)
26
- builder (~> 2.1.2)
27
- i18n (~> 0.5.0)
28
- activerecord (3.0.20)
29
- activemodel (= 3.0.20)
30
- activesupport (= 3.0.20)
31
- arel (~> 2.0.10)
32
- tzinfo (~> 0.3.23)
33
- activesupport (3.0.20)
34
- appraisal (0.5.2)
35
- bundler
36
- rake
37
- arel (2.0.10)
38
- bourne (1.4.0)
39
- mocha (~> 0.13.2)
40
- builder (2.1.2)
41
- bump (0.4.1)
42
- columnize (0.3.6)
43
- debugger (1.5.0)
44
- columnize (>= 0.3.1)
45
- debugger-linecache (~> 1.2.0)
46
- debugger-ruby_core_source (~> 1.2.0)
47
- debugger-linecache (1.2.0)
48
- debugger-ruby_core_source (1.2.0)
49
- erubis (2.6.6)
50
- abstract (>= 1.0.0)
51
- git (1.2.5)
52
- i18n (0.5.0)
53
- jeweler (1.8.4)
54
- bundler (~> 1.0)
55
- git (>= 1.2.5)
56
- rake
57
- rdoc
58
- json (1.7.7)
59
- linecache (0.46)
60
- rbx-require-relative (> 0.0.4)
61
- mail (2.2.19)
62
- activesupport (>= 2.3.6)
63
- i18n (>= 0.4.0)
64
- mime-types (~> 1.16)
65
- treetop (~> 1.4.8)
66
- metaclass (0.0.1)
67
- mime-types (1.23)
68
- mocha (0.13.3)
69
- metaclass (~> 0.0.1)
70
- polyglot (0.3.3)
71
- rack (1.2.8)
72
- rack-mount (0.6.14)
73
- rack (>= 1.0.0)
74
- rack-test (0.5.7)
75
- rack (>= 1.0)
76
- rails (0.9.5)
77
- actionmailer (>= 0.6.1)
78
- actionpack (>= 1.4.0)
79
- activerecord (>= 1.6.0)
80
- rake (>= 0.4.15)
81
- rake (10.0.4)
82
- rbx-require-relative (0.0.9)
83
- rdoc (4.0.1)
84
- json (~> 1.4)
85
- ruby-debug (0.10.4)
86
- columnize (>= 0.1)
87
- ruby-debug-base (~> 0.10.4.0)
88
- ruby-debug-base (0.10.4)
89
- linecache (>= 0.3)
90
- shoulda (3.4.0)
91
- shoulda-context (~> 1.0, >= 1.0.1)
92
- shoulda-matchers (~> 1.0, >= 1.4.1)
93
- shoulda-context (1.1.1)
94
- shoulda-matchers (1.5.6)
95
- activesupport (>= 3.0.0)
96
- bourne (~> 1.3)
97
- sqlite3 (1.3.7)
98
- test-unit (2.5.4)
99
- treetop (1.4.12)
100
- polyglot
101
- polyglot (>= 0.3.1)
102
- tzinfo (0.3.37)
103
-
104
- PLATFORMS
105
- ruby
106
-
107
- DEPENDENCIES
108
- active_record_inherit_assoc!
109
- activerecord (~> 3.0.15)
110
- appraisal
111
- bump
112
- bundler
113
- debugger
114
- jeweler
115
- rails
116
- rake
117
- ruby-debug
118
- shoulda
119
- sqlite3
120
- test-unit (>= 2.5.1)
@@ -1,18 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source :rubygems
4
-
5
- gem "appraisal"
6
- gem "rake"
7
- gem "rails"
8
- gem "bundler"
9
- gem "bump"
10
- gem "sqlite3"
11
- gem "shoulda"
12
- gem "jeweler"
13
- gem "ruby-debug", :platforms=>:ruby_18
14
- gem "debugger", :platforms=>:ruby_19
15
- gem "test-unit", ">=2.5.1"
16
- gem "activerecord", "~> 3.1.0", :require=>"active_record"
17
-
18
- gemspec :path=>"../"
@@ -1,128 +0,0 @@
1
- PATH
2
- remote: /Users/staugaard/code/active_record_inherit_assoc
3
- specs:
4
- active_record_inherit_assoc (1.1.0)
5
- activerecord
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- actionmailer (3.1.12)
11
- actionpack (= 3.1.12)
12
- mail (~> 2.4.4)
13
- actionpack (3.1.12)
14
- activemodel (= 3.1.12)
15
- activesupport (= 3.1.12)
16
- builder (~> 3.0.0)
17
- erubis (~> 2.7.0)
18
- i18n (~> 0.6)
19
- rack (~> 1.3.6)
20
- rack-cache (~> 1.2)
21
- rack-mount (~> 0.8.2)
22
- rack-test (~> 0.6.1)
23
- sprockets (~> 2.0.4)
24
- activemodel (3.1.12)
25
- activesupport (= 3.1.12)
26
- builder (~> 3.0.0)
27
- i18n (~> 0.6)
28
- activerecord (3.1.12)
29
- activemodel (= 3.1.12)
30
- activesupport (= 3.1.12)
31
- arel (~> 2.2.3)
32
- tzinfo (~> 0.3.29)
33
- activesupport (3.1.12)
34
- multi_json (~> 1.0)
35
- appraisal (0.5.2)
36
- bundler
37
- rake
38
- arel (2.2.3)
39
- bourne (1.4.0)
40
- mocha (~> 0.13.2)
41
- builder (3.0.4)
42
- bump (0.4.1)
43
- columnize (0.3.6)
44
- debugger (1.5.0)
45
- columnize (>= 0.3.1)
46
- debugger-linecache (~> 1.2.0)
47
- debugger-ruby_core_source (~> 1.2.0)
48
- debugger-linecache (1.2.0)
49
- debugger-ruby_core_source (1.2.0)
50
- erubis (2.7.0)
51
- git (1.2.5)
52
- hike (1.2.2)
53
- i18n (0.6.4)
54
- jeweler (1.8.4)
55
- bundler (~> 1.0)
56
- git (>= 1.2.5)
57
- rake
58
- rdoc
59
- json (1.7.7)
60
- linecache (0.46)
61
- rbx-require-relative (> 0.0.4)
62
- mail (2.4.4)
63
- i18n (>= 0.4.0)
64
- mime-types (~> 1.16)
65
- treetop (~> 1.4.8)
66
- metaclass (0.0.1)
67
- mime-types (1.23)
68
- mocha (0.13.3)
69
- metaclass (~> 0.0.1)
70
- multi_json (1.7.2)
71
- polyglot (0.3.3)
72
- rack (1.3.10)
73
- rack-cache (1.2)
74
- rack (>= 0.4)
75
- rack-mount (0.8.3)
76
- rack (>= 1.0.0)
77
- rack-test (0.6.2)
78
- rack (>= 1.0)
79
- rails (0.9.5)
80
- actionmailer (>= 0.6.1)
81
- actionpack (>= 1.4.0)
82
- activerecord (>= 1.6.0)
83
- rake (>= 0.4.15)
84
- rake (10.0.4)
85
- rbx-require-relative (0.0.9)
86
- rdoc (4.0.1)
87
- json (~> 1.4)
88
- ruby-debug (0.10.4)
89
- columnize (>= 0.1)
90
- ruby-debug-base (~> 0.10.4.0)
91
- ruby-debug-base (0.10.4)
92
- linecache (>= 0.3)
93
- shoulda (3.4.0)
94
- shoulda-context (~> 1.0, >= 1.0.1)
95
- shoulda-matchers (~> 1.0, >= 1.4.1)
96
- shoulda-context (1.1.1)
97
- shoulda-matchers (1.5.6)
98
- activesupport (>= 3.0.0)
99
- bourne (~> 1.3)
100
- sprockets (2.0.4)
101
- hike (~> 1.2)
102
- rack (~> 1.0)
103
- tilt (~> 1.1, != 1.3.0)
104
- sqlite3 (1.3.7)
105
- test-unit (2.5.4)
106
- tilt (1.4.0)
107
- treetop (1.4.12)
108
- polyglot
109
- polyglot (>= 0.3.1)
110
- tzinfo (0.3.37)
111
-
112
- PLATFORMS
113
- ruby
114
-
115
- DEPENDENCIES
116
- active_record_inherit_assoc!
117
- activerecord (~> 3.1.0)
118
- appraisal
119
- bump
120
- bundler
121
- debugger
122
- jeweler
123
- rails
124
- rake
125
- ruby-debug
126
- shoulda
127
- sqlite3
128
- test-unit (>= 2.5.1)
@@ -1,75 +0,0 @@
1
- require 'active_record'
2
- require 'active_record/base'
3
- require 'active_record/reflection'
4
- require 'active_record/associations/association_proxy'
5
- require 'active_record/associations/association_collection'
6
-
7
- ActiveRecord::Base.valid_keys_for_has_many_association << :inherit
8
- ActiveRecord::Base.valid_keys_for_has_one_association << :inherit
9
- ActiveRecord::Base.valid_keys_for_belongs_to_association << :inherit
10
-
11
- module ActiveRecord
12
- module Associations
13
- AssociationProxy.class_eval do
14
- def conditions_with_value_inheritance
15
- return conditions_without_value_inheritance unless @reflection.klass.respond_to?(:sanitize_sql) # ActiveHash TODO test this!
16
- copied_merge_conditions(attribute_inheritance_hash, conditions_without_value_inheritance)
17
- end
18
-
19
- alias_method_chain :conditions, :value_inheritance
20
-
21
- private
22
-
23
- # copied from activerecord 2.3 to fix compatability with 3.0
24
- # Merges conditions so that the result is a valid +condition+
25
- def copied_merge_conditions(*conditions)
26
- segments = []
27
-
28
- conditions.each do |condition|
29
- unless condition.blank?
30
- sql = sanitize_sql(condition)
31
- segments << sql unless sql.blank?
32
- end
33
- end
34
-
35
- "(#{segments.join(') AND (')})" unless segments.empty?
36
- end
37
-
38
- def attribute_inheritance_hash
39
- return {} unless @reflection.options[:inherit]
40
- Array(@reflection.options[:inherit]).inject({}) { |hash, obj| hash[obj] = @owner.send(obj) ; hash }
41
- end
42
- end
43
-
44
- AssociationCollection.class_eval do
45
- # this is *maybe* not the correct place to patch in, but it covers all the cases
46
- # without having to patch build, create, create!, etc
47
- def add_record_to_target_with_callbacks_with_value_inheritance(record, &block)
48
- attribute_inheritance_hash.each do |k, v|
49
- record[k] = v
50
- end
51
- add_record_to_target_with_callbacks_without_value_inheritance(record, &block)
52
- end
53
-
54
- alias_method_chain :add_record_to_target_with_callbacks, :value_inheritance
55
- end
56
-
57
- HasOneAssociation.class_eval do
58
- def create_with_value_inheritance(attrs = {}, replace_existing = true)
59
- attrs ||= {}
60
- create_without_value_inheritance(attribute_inheritance_hash.merge(attrs), replace_existing)
61
- end
62
-
63
- def create_with_value_inheritance!(attrs = {}, replace_existing = true)
64
- attrs ||= {}
65
- create_without_value_inheritance!(attribute_inheritance_hash.merge(attrs), replace_existing)
66
- end
67
-
68
- def build_with_value_inheritance(attrs = {}, replace_existing = true)
69
- attrs ||= {}
70
- build_without_value_inheritance(attribute_inheritance_hash.merge(attrs), replace_existing)
71
- end
72
- [:create, :create!, :build].each { |sym| alias_method_chain sym, :value_inheritance }
73
- end
74
- end
75
- end
@@ -1,22 +0,0 @@
1
- require 'active_record'
2
-
3
- ActiveRecord::Associations::Builder::HasMany.valid_options << :inherit
4
- ActiveRecord::Associations::Builder::HasOne.valid_options << :inherit
5
- ActiveRecord::Associations::Builder::BelongsTo.valid_options << :inherit
6
-
7
- ActiveRecord::Associations::Association.class_eval do
8
- def association_scope_with_value_inheritance
9
- if inherited_attributes = attribute_inheritance_hash
10
- association_scope_without_value_inheritance.where(inherited_attributes)
11
- else
12
- association_scope_without_value_inheritance
13
- end
14
- end
15
-
16
- alias_method_chain :association_scope, :value_inheritance
17
-
18
- def attribute_inheritance_hash
19
- return nil unless reflection.options[:inherit]
20
- Array(reflection.options[:inherit]).inject({}) { |hash, obj| hash[obj] = owner.send(obj) ; hash }
21
- end
22
- end