schema_associations 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -23,3 +23,5 @@ pkg
23
23
  *.log
24
24
  *.sqlite3
25
25
  Gemfile.lock
26
+ gemfiles/*.lock
27
+ gemfiles/**/*.lock
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ gemfile:
5
+ - gemfiles/Gemfile.rails-3.2
6
+ notifications:
7
+ recipients:
8
+ - michal.lomnicki@gmail.com
9
+ - ronen@barzel.org
data/README.rdoc CHANGED
@@ -1,22 +1,30 @@
1
1
  = SchemaAssociations
2
2
 
3
+ SchemaAssiciations is an ActiveRecord extension that keeps your model class
4
+ definitions simpler and more DRY, by automatically defining associations
5
+ based on the database schema.
6
+
7
+ {<img src="https://secure.travis-ci.org/lomba/schema_associations.png"/>}[http://travis-ci.org/lomba/schema_associations]
8
+ {<img src="https://gemnasium.com/lomba/schema_associations.png" alt="Dependency Status" />}[https://gemnasium.com/lomba/schema_associations]
9
+
3
10
  == Overview
4
11
 
5
- One of the great things about Rails (ActiveRecord, in particular) is that it
6
- inspects the database and automatically defines accessors for all your
12
+ One of the great things about Rails (ActiveRecord, in particular) is that
13
+ it inspects the database and automatically defines accessors for all your
7
14
  columns, keeping your model class definitions simple and DRY. That's great
8
15
  for simple data columns, but where it falls down is when your table
9
16
  contains references to other tables: then the "accessors" you need are the
10
- +belongs_to+, +has_one+, +has_many+, and +has_and_belongs_to_many+
11
- associations -- and you need to put them into your model class definitions
12
- by hand. In fact, for every relation, you need to define two associations, such as
17
+ associations defined using +belongs_to+, +has_one+, +has_many+, and
18
+ +has_and_belongs_to_many+ -- and you need to put them into your model class
19
+ definitions by hand. In fact, for every relation, you need to define two
20
+ associations each listing its inverse, such as
13
21
 
14
22
  class Post < ActiveRecord::Base
15
- has_many :commens
23
+ has_many :comments, :inverse_of => :post
16
24
  end
17
25
 
18
26
  class Comment < ActiveReocrd::Base
19
- belongs_to :post
27
+ belongs_to :post, :inverse_of => :comments
20
28
  end
21
29
 
22
30
  ....which isn't so DRY.
@@ -42,7 +50,7 @@ Then all you need for your models is:
42
50
  class Comment < ActiveRecord::Base
43
51
  end
44
52
 
45
- and SchemaAssociations defines the appropriate associations under the hood
53
+ and SchemaAssociations defines the appropriate associations under the hood.
46
54
 
47
55
  === What if I want something special?
48
56
 
@@ -88,7 +96,7 @@ relationship using standard naming conventions:
88
96
  t.integer post_id
89
97
  end
90
98
 
91
- # models:
99
+ # schema_associations defines:
92
100
 
93
101
  class Post < ActiveRecord::Base
94
102
  has_many :comments
@@ -106,7 +114,7 @@ For a one-to-one relationship:
106
114
  t.integer post_id, :index => :unique # (using the :index option provided by schema_plus )
107
115
  end
108
116
 
109
- # models:
117
+ # schema_associations defines:
110
118
 
111
119
  class Post < ActiveRecord::Base
112
120
  has_one :comment
@@ -125,6 +133,8 @@ And for many-to-many relationships:
125
133
  integer :member_id
126
134
  end
127
135
 
136
+ # schema_associations defines:
137
+
128
138
  class Group < ActiveReocrd::Base
129
139
  has_and_belongs_to_many :members
130
140
  end
@@ -264,8 +274,10 @@ use cases that you logged).
264
274
  == Compatibility
265
275
 
266
276
  SchemaAssociations supports all combinations of:
267
- * rails 2.3, 3.0 or 3.1 (prerelease)
268
- * MRI ruby 1.8.7 or 1.9.2
277
+ * rails 3.2
278
+ * MRI ruby 1.9.2 or 1.9.3
279
+
280
+ Note: As of version 1.0.0, ruby 1.8.7 and rails < 3.2 are no longer supported. The last version to support them is 0.1.2
269
281
 
270
282
  == Installation
271
283
 
@@ -287,13 +299,21 @@ full combo of tests, after you've forked & cloned:
287
299
  $ ./runspecs --install # do this once to install gem dependencies for all versions (slow)
288
300
  $ ./runspecs # as many times as you like
289
301
 
290
- See <tt>./runspecs --help</tt> for other options. You can also pick a specific version of rails and ruby to use, such as:
291
- $ rvm use 1.9.2
292
- $ export SCHEMA_ASSOCIATIONS_RAILS_VERSION=3.1
293
- $ bundle update rails --local
294
- $ rake spec
302
+ See <tt>./runspecs --help</tt> for more options. In particular, to run
303
+ rspec on a specific file or example (rather than running the full suite)
304
+ you can do, e.g.
305
+
306
+ $ ./runspecs [other options] --rspec -- spec/association_spec.rb -e 'base'
307
+
308
+ If you're running ruby 1.9, code coverage results will be in coverage/index.html -- it should be at 100% coverage.
309
+
310
+ == Release notes:
311
+
312
+ === 1.0.0
313
+
314
+ * Use :inverse_of in generated associations
295
315
 
296
- If you're running ruby 1.9.2, code coverage results will be in coverage/index.html -- it should be at 100% coverage.
316
+ * Drop support for ruby 1.8.7 and rails < 3.2
297
317
 
298
318
  == History
299
319
 
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ end
9
9
 
10
10
  task :default => :spec
11
11
 
12
- require 'rake/rdoctask'
12
+ require 'rdoc/task'
13
13
  Rake::RDocTask.new do |rdoc|
14
14
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
15
15
 
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec :path => File.expand_path('../..', __FILE__)
4
+ gem "rails", "~> 3.2.0"
@@ -0,0 +1,119 @@
1
+ PATH
2
+ remote: /Users/ronen/github/schema_associations
3
+ specs:
4
+ schema_associations (0.1.2)
5
+ schema_plus
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actionmailer (3.2.11)
11
+ actionpack (= 3.2.11)
12
+ mail (~> 2.4.4)
13
+ actionpack (3.2.11)
14
+ activemodel (= 3.2.11)
15
+ activesupport (= 3.2.11)
16
+ builder (~> 3.0.0)
17
+ erubis (~> 2.7.0)
18
+ journey (~> 1.0.4)
19
+ rack (~> 1.4.0)
20
+ rack-cache (~> 1.2)
21
+ rack-test (~> 0.6.1)
22
+ sprockets (~> 2.2.1)
23
+ activemodel (3.2.11)
24
+ activesupport (= 3.2.11)
25
+ builder (~> 3.0.0)
26
+ activerecord (3.2.11)
27
+ activemodel (= 3.2.11)
28
+ activesupport (= 3.2.11)
29
+ arel (~> 3.0.2)
30
+ tzinfo (~> 0.3.29)
31
+ activeresource (3.2.11)
32
+ activemodel (= 3.2.11)
33
+ activesupport (= 3.2.11)
34
+ activesupport (3.2.11)
35
+ i18n (~> 0.6)
36
+ multi_json (~> 1.0)
37
+ arel (3.0.2)
38
+ builder (3.0.4)
39
+ diff-lcs (1.1.3)
40
+ erubis (2.7.0)
41
+ hike (1.2.1)
42
+ i18n (0.6.1)
43
+ journey (1.0.4)
44
+ json (1.7.6)
45
+ mail (2.4.4)
46
+ i18n (>= 0.4.0)
47
+ mime-types (~> 1.16)
48
+ treetop (~> 1.4.8)
49
+ mime-types (1.19)
50
+ multi_json (1.5.0)
51
+ polyglot (0.3.3)
52
+ rack (1.4.4)
53
+ rack-cache (1.2)
54
+ rack (>= 0.4)
55
+ rack-ssl (1.3.2)
56
+ rack
57
+ rack-test (0.6.2)
58
+ rack (>= 1.0)
59
+ rails (3.2.11)
60
+ actionmailer (= 3.2.11)
61
+ actionpack (= 3.2.11)
62
+ activerecord (= 3.2.11)
63
+ activeresource (= 3.2.11)
64
+ activesupport (= 3.2.11)
65
+ bundler (~> 1.0)
66
+ railties (= 3.2.11)
67
+ railties (3.2.11)
68
+ actionpack (= 3.2.11)
69
+ activesupport (= 3.2.11)
70
+ rack-ssl (~> 1.3.2)
71
+ rake (>= 0.8.7)
72
+ rdoc (~> 3.4)
73
+ thor (>= 0.14.6, < 2.0)
74
+ rake (10.0.3)
75
+ rdoc (3.12)
76
+ json (~> 1.4)
77
+ rspec (2.12.0)
78
+ rspec-core (~> 2.12.0)
79
+ rspec-expectations (~> 2.12.0)
80
+ rspec-mocks (~> 2.12.0)
81
+ rspec-core (2.12.2)
82
+ rspec-expectations (2.12.1)
83
+ diff-lcs (~> 1.1.3)
84
+ rspec-mocks (2.12.1)
85
+ schema_plus (1.0.0)
86
+ rails (>= 3.2)
87
+ valuable
88
+ simplecov (0.7.1)
89
+ multi_json (~> 1.0)
90
+ simplecov-html (~> 0.7.1)
91
+ simplecov-gem-adapter (1.0.1)
92
+ simplecov
93
+ simplecov-html (0.7.1)
94
+ sprockets (2.2.2)
95
+ hike (~> 1.2)
96
+ multi_json (~> 1.0)
97
+ rack (~> 1.0)
98
+ tilt (~> 1.1, != 1.3.0)
99
+ sqlite3 (1.3.7)
100
+ thor (0.16.0)
101
+ tilt (1.3.3)
102
+ treetop (1.4.12)
103
+ polyglot
104
+ polyglot (>= 0.3.1)
105
+ tzinfo (0.3.35)
106
+ valuable (0.9.6)
107
+
108
+ PLATFORMS
109
+ ruby
110
+
111
+ DEPENDENCIES
112
+ rails (~> 3.2.0)
113
+ rake
114
+ rdoc
115
+ rspec
116
+ schema_associations!
117
+ simplecov
118
+ simplecov-gem-adapter
119
+ sqlite3
@@ -114,8 +114,14 @@ module SchemaAssociations
114
114
  when :belongs_to
115
115
  name = names[:belongs_to]
116
116
  opts = {:class_name => references_class_name, :foreign_key => column_name}
117
+ if connection.indexes(fk.references_table_name, "#{fk.references_table_name} Indexes").any?{|index| index.unique && index.columns == [column_name]}
118
+ opts[:inverse_of] = names[:has_one]
119
+ else
120
+ opts[:inverse_of] = names[:has_many]
121
+ end
122
+
117
123
  when :has_one_or_many
118
- opts = {:class_name => referencing_class_name, :foreign_key => column_name}
124
+ opts = {:class_name => referencing_class_name, :foreign_key => column_name, :inverse_of => names[:belongs_to]}
119
125
  # use connection.indexes and connection.colums rather than class
120
126
  # methods of the referencing class because using the class
121
127
  # methods would require getting the class -- which might trigger
@@ -1,3 +1,3 @@
1
1
  module SchemaAssociations
2
- VERSION = "0.1.2"
2
+ VERSION = "1.0.0"
3
3
  end
data/runspecs CHANGED
@@ -2,20 +2,27 @@
2
2
 
3
3
  require 'optparse'
4
4
  require 'ostruct'
5
+ require 'shellwords'
6
+ require 'tempfile'
5
7
 
6
- PROJECT = File.basename(File.expand_path('..', __FILE__))
7
-
8
- RUBY_VERSIONS = %W[1.8.7 1.9.2]
9
- RAILS_VERSIONS = %W[2.3 3.0 3.1]
8
+ RUBY_VERSIONS = %W[1.9.2 1.9.3]
9
+ RAILS_VERSIONS = %W[3.2]
10
10
 
11
11
  o = OpenStruct.new
12
12
  o.ruby_versions = RUBY_VERSIONS
13
13
  o.rails_versions = RAILS_VERSIONS
14
- o.run_cmd = "rake spec"
15
14
 
16
15
  OptionParser.new do |opts|
17
16
  opts.banner = "Usage: #{$0} [options]"
18
17
 
18
+ opts.on("-n", "--dry-run", "Do a dry run without executing actions") do |v|
19
+ o.dry_run = true
20
+ end
21
+
22
+ opts.on("--update", "Update gem dependencies") do |v|
23
+ o.update = v
24
+ end
25
+
19
26
  opts.on("--install", "Install gem dependencies") do |v|
20
27
  o.install = v
21
28
  end
@@ -33,26 +40,51 @@ OptionParser.new do |opts|
33
40
  o.rails_versions = [RAILS_VERSIONS.last]
34
41
  end
35
42
 
43
+ opts.on("--rspec", "run rspec rather than rake") do |v|
44
+ o.rspec = v
45
+ end
46
+
36
47
  end.parse!
37
48
 
38
- cmds = if o.install
39
- ['bundle update']
40
- else
41
- ['bundle update --local rails | grep rails', o.run_cmd]
42
- end
43
-
44
- n = 1
45
- total = o.ruby_versions.size * o.rails_versions.size
46
- o.ruby_versions.each do |ruby|
47
- o.rails_versions.each do |rails|
48
- puts "\n\n*** ruby version #{ruby} - rails version #{rails} [#{n} of #{total}]\n\n"
49
- n += 1
50
- allcmds = []
51
- allcmds << "rvm use #{ruby}"
52
- allcmds << "export #{PROJECT.upcase}_RAILS_VERSION=#{rails}"
53
- allcmds += cmds
54
- allcmds << 'exit'
55
- system %Q{echo '#{allcmds.join(' \n ')}' | bash -i} or abort "aborting #{$0}"
49
+
50
+ Combo = Struct.new(:ruby, :rails)
51
+
52
+ combos = o.ruby_versions.product(o.rails_versions).map{|product| Combo.new(*product)}.select {|combo|
53
+ case
54
+ when combo.rails >= "3.2" && combo.ruby <= "1.8.7" then false
55
+ else true
56
56
  end
57
- end
57
+ }
58
+
59
+
60
+ GEMFILES_DIR = File.expand_path('../gemfiles', __FILE__)
61
+ errs = []
62
+ combos.each_with_index do |combo, n|
63
+ ruby = combo.ruby
64
+ rails = combo.rails
65
+
66
+ cmd = case
67
+ when o.update
68
+ "bundle update"
69
+ when o.install
70
+ "bundle install"
71
+ when o.rspec
72
+ "bundle exec rspec"
73
+ else
74
+ "bundle exec rake spec"
75
+ end
76
+
77
+ command = %Q{BUNDLE_GEMFILE="#{File.join(GEMFILES_DIR, "Gemfile.rails-#{rails}")}" rvm #{ruby} do #{cmd} #{Shellwords.join(ARGV)}}
58
78
 
79
+ puts "\n\n*** ruby version #{ruby} - rails version #{rails} [#{n+1} of #{combos.size}]\n\n#{command}"
80
+
81
+ next if o.dry_run
82
+
83
+ Tempfile.open('runspecs') do |file|
84
+ system("(#{command}) 2>&1 | tee #{file.path}")
85
+ file.rewind
86
+ errs << "ruby #{ruby}, rails #{rails}" if file.readlines.grep(/^Failed examples/).any?
87
+ end
88
+ end
89
+ puts errs.any? ? "\n*** #{errs.size} failures:\n\t#{errs.join("\n\t")}" : "\n*** #{combos.size > 1 ? 'all versions' : 'spec'} succeeded ***" unless o.dry_run
90
+ exit !errs.any?
@@ -21,20 +21,11 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.add_dependency("schema_plus")
23
23
 
24
- case ENV['SCHEMA_ASSOCIATIONS_RAILS_VERSION']
25
- when '2.3'
26
- s.add_development_dependency("rails", "~> 2.3")
27
- when '3.0'
28
- s.add_development_dependency("rails", "~> 3.0")
29
- when '3.1'
30
- s.add_development_dependency("rails", ">= 3.1.0.pre1")
31
- end
32
-
33
- s.add_development_dependency("rake", "~> 0.8.7")
24
+ s.add_development_dependency("rake")
25
+ s.add_development_dependency("rdoc")
34
26
  s.add_development_dependency("rspec")
35
27
  s.add_development_dependency("sqlite3")
36
28
  s.add_development_dependency("simplecov")
37
29
  s.add_development_dependency("simplecov-gem-adapter")
38
- s.add_development_dependency("ruby-debug19") if RUBY_VERSION >= "1.9.2"
39
30
  end
40
31
 
@@ -17,17 +17,13 @@ describe ActiveRecord::Base do
17
17
  class Comment < ActiveRecord::Base ; end
18
18
  end
19
19
 
20
- after(:each) do
21
- Comment.destroy_all
22
- Post.destroy_all
23
- end
24
-
25
20
  it "should create belongs_to association when reflecting on it" do
26
21
  reflection = Comment.reflect_on_association(:post)
27
22
  reflection.should_not be_nil
28
23
  reflection.macro.should == :belongs_to
29
24
  reflection.options[:class_name].should == "Post"
30
25
  reflection.options[:foreign_key].should == "post_id"
26
+ reflection.options[:inverse_of].should == :comments
31
27
  end
32
28
 
33
29
  it "should create association when reflecting on all associations" do
@@ -36,6 +32,7 @@ describe ActiveRecord::Base do
36
32
  reflection.macro.should == :belongs_to
37
33
  reflection.options[:class_name].should == "Post"
38
34
  reflection.options[:foreign_key].should == "post_id"
35
+ reflection.options[:inverse_of].should == :comments
39
36
  end
40
37
 
41
38
  it "should create association when accessing it" do
@@ -56,24 +53,10 @@ describe ActiveRecord::Base do
56
53
  reflection.macro.should == :has_many
57
54
  reflection.options[:class_name].should == "Comment"
58
55
  reflection.options[:foreign_key].should == "post_id"
56
+ reflection.options[:inverse_of].should == :post
59
57
  end
60
58
  it "shouldn't raise an exception when model is instantiated" do
61
- expect { Post.new }.should_not raise_error
62
- end
63
- end
64
-
65
- it "should override auto_create negatively" do
66
- with_associations_auto_create(true) do
67
- create_tables(
68
- "posts", {}, {},
69
- "comments", {}, { :post_id => {} }
70
- )
71
- class Post < ActiveRecord::Base
72
- schema_associations :auto_create => false
73
- end
74
- class Comment < ActiveRecord::Base ; end
75
- Post.reflect_on_association(:comments).should be_nil
76
- Comment.reflect_on_association(:post).should_not be_nil
59
+ expect { Post.new }.to_not raise_error
77
60
  end
78
61
  end
79
62
 
@@ -178,33 +161,51 @@ describe ActiveRecord::Base do
178
161
 
179
162
  end
180
163
 
181
- it "should override auto_create positively explicitly" do
182
- with_associations_auto_create(false) do
183
- create_tables(
184
- "posts", {}, {},
185
- "comments", {}, { :post_id => {} }
186
- )
187
- class Post < ActiveRecord::Base
188
- schema_associations :auto_create => true
164
+ context "overrides" do
165
+ it "should override auto_create negatively" do
166
+ with_associations_auto_create(true) do
167
+ create_tables(
168
+ "posts", {}, {},
169
+ "comments", {}, { :post_id => {} }
170
+ )
171
+ class Post < ActiveRecord::Base
172
+ schema_associations :auto_create => false
173
+ end
174
+ class Comment < ActiveRecord::Base ; end
175
+ Post.reflect_on_association(:comments).should be_nil
176
+ Comment.reflect_on_association(:post).should_not be_nil
189
177
  end
190
- class Comment < ActiveRecord::Base ; end
191
- Post.reflect_on_association(:comments).should_not be_nil
192
- Comment.reflect_on_association(:post).should be_nil
193
178
  end
194
- end
195
179
 
196
- it "should override auto_create positively implicitly" do
197
- with_associations_auto_create(false) do
198
- create_tables(
199
- "posts", {}, {},
200
- "comments", {}, { :post_id => {} }
201
- )
202
- class Post < ActiveRecord::Base
203
- schema_associations
180
+
181
+ it "should override auto_create positively explicitly" do
182
+ with_associations_auto_create(false) do
183
+ create_tables(
184
+ "posts", {}, {},
185
+ "comments", {}, { :post_id => {} }
186
+ )
187
+ class Post < ActiveRecord::Base
188
+ schema_associations :auto_create => true
189
+ end
190
+ class Comment < ActiveRecord::Base ; end
191
+ Post.reflect_on_association(:comments).should_not be_nil
192
+ Comment.reflect_on_association(:post).should be_nil
193
+ end
194
+ end
195
+
196
+ it "should override auto_create positively implicitly" do
197
+ with_associations_auto_create(false) do
198
+ create_tables(
199
+ "posts", {}, {},
200
+ "comments", {}, { :post_id => {} }
201
+ )
202
+ class Post < ActiveRecord::Base
203
+ schema_associations
204
+ end
205
+ class Comment < ActiveRecord::Base ; end
206
+ Post.reflect_on_association(:comments).should_not be_nil
207
+ Comment.reflect_on_association(:post).should be_nil
204
208
  end
205
- class Comment < ActiveRecord::Base ; end
206
- Post.reflect_on_association(:comments).should_not be_nil
207
- Comment.reflect_on_association(:post).should be_nil
208
209
  end
209
210
  end
210
211
 
@@ -224,6 +225,7 @@ describe ActiveRecord::Base do
224
225
  reflection.macro.should == :has_one
225
226
  reflection.options[:class_name].should == "Comment"
226
227
  reflection.options[:foreign_key].should == "post_id"
228
+ reflection.options[:inverse_of].should == :post
227
229
  end
228
230
  end
229
231
 
@@ -242,6 +244,7 @@ describe ActiveRecord::Base do
242
244
  reflection.macro.should == :belongs_to
243
245
  reflection.options[:class_name].should == "Post"
244
246
  reflection.options[:foreign_key].should == "subject_post_id"
247
+ reflection.options[:inverse_of].should == :comments_as_subject
245
248
  end
246
249
 
247
250
  it "should name has_many using 'as column'" do
@@ -250,6 +253,7 @@ describe ActiveRecord::Base do
250
253
  reflection.macro.should == :has_many
251
254
  reflection.options[:class_name].should == "Comment"
252
255
  reflection.options[:foreign_key].should == "subject_post_id"
256
+ reflection.options[:inverse_of].should == :subject_post
253
257
  end
254
258
  end
255
259
 
@@ -268,6 +272,7 @@ describe ActiveRecord::Base do
268
272
  reflection.macro.should == :belongs_to
269
273
  reflection.options[:class_name].should == "Post"
270
274
  reflection.options[:foreign_key].should == "post_cited"
275
+ reflection.options[:inverse_of].should == :comments_as_cited
271
276
  end
272
277
 
273
278
  it "should name has_many using 'as column'" do
@@ -276,6 +281,7 @@ describe ActiveRecord::Base do
276
281
  reflection.macro.should == :has_many
277
282
  reflection.options[:class_name].should == "Comment"
278
283
  reflection.options[:foreign_key].should == "post_cited"
284
+ reflection.options[:inverse_of].should == :post_cited
279
285
  end
280
286
  end
281
287
 
@@ -294,6 +300,7 @@ describe ActiveRecord::Base do
294
300
  reflection.macro.should == :belongs_to
295
301
  reflection.options[:class_name].should == "Post"
296
302
  reflection.options[:foreign_key].should == "subject"
303
+ reflection.options[:inverse_of].should == :comments_as_subject
297
304
  end
298
305
 
299
306
  it "should name has_many using 'as column'" do
@@ -302,6 +309,7 @@ describe ActiveRecord::Base do
302
309
  reflection.macro.should == :has_many
303
310
  reflection.options[:class_name].should == "Comment"
304
311
  reflection.options[:foreign_key].should == "subject"
312
+ reflection.options[:inverse_of].should == :subject
305
313
  end
306
314
  end
307
315
 
@@ -321,6 +329,7 @@ describe ActiveRecord::Base do
321
329
  reflection.macro.should == :has_many
322
330
  reflection.options[:class_name].should == "Comment"
323
331
  reflection.options[:foreign_key].should == "post_id"
332
+ reflection.options[:inverse_of].should == :post
324
333
  reflection.options[:order].to_s.should == "position"
325
334
  end
326
335
  end
@@ -389,6 +398,7 @@ describe ActiveRecord::Base do
389
398
  reflection.macro.should == :has_many
390
399
  reflection.options[:class_name].should == "PostComment"
391
400
  reflection.options[:foreign_key].should == "post_id"
401
+ reflection.options[:inverse_of].should == :post
392
402
  end
393
403
  end
394
404
 
@@ -400,6 +410,7 @@ describe ActiveRecord::Base do
400
410
  reflection.macro.should == :has_many
401
411
  reflection.options[:class_name].should == "CommentPost"
402
412
  reflection.options[:foreign_key].should == "post_id"
413
+ reflection.options[:inverse_of].should == :post
403
414
  end
404
415
  end
405
416
 
@@ -411,6 +422,7 @@ describe ActiveRecord::Base do
411
422
  reflection.macro.should == :has_many
412
423
  reflection.options[:class_name].should == "BlogPageComment"
413
424
  reflection.options[:foreign_key].should == "blog_page_post_id"
425
+ reflection.options[:inverse_of].should == :post
414
426
  end
415
427
  end
416
428
 
@@ -422,6 +434,7 @@ describe ActiveRecord::Base do
422
434
  reflection.macro.should == :has_many
423
435
  reflection.options[:class_name].should == "PostComment"
424
436
  reflection.options[:foreign_key].should == "post_id"
437
+ reflection.options[:inverse_of].should == :post
425
438
  reflection = Post.reflect_on_association(:comments)
426
439
  reflection.should be_nil
427
440
  end
@@ -435,6 +448,7 @@ describe ActiveRecord::Base do
435
448
  reflection.macro.should == :has_many
436
449
  reflection.options[:class_name].should == "PostComment"
437
450
  reflection.options[:foreign_key].should == "post_id"
451
+ reflection.options[:inverse_of].should == :post
438
452
  reflection = Post.reflect_on_association(:post_comments)
439
453
  reflection.should be_nil
440
454
  end
@@ -518,7 +532,7 @@ describe ActiveRecord::Base do
518
532
 
519
533
  it "should define associations before needed by relation" do
520
534
  Post.joins(:comments).all
521
- expect { Post.joins(:comments).all }.should_not raise_error
535
+ expect { Post.joins(:comments).all }.to_not raise_error
522
536
 
523
537
  end
524
538
 
data/spec/spec_helper.rb CHANGED
@@ -22,6 +22,7 @@ def remove_all_models
22
22
  next unless c.ancestors.include? ActiveRecord::Base
23
23
  next if c == ActiveRecord::Base
24
24
  next if c.name.blank?
25
+ c.destroy_all rescue nil
25
26
  ActiveSupport::Dependencies.remove_constant c.name
26
27
  end
27
28
  end
metadata CHANGED
@@ -1,112 +1,148 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: schema_associations
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
4
5
  prerelease:
5
- version: 0.1.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Ronen Barzel
9
- - "Micha\xC5\x82 \xC5\x81omnicki"
9
+ - Michał Łomnicki
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2011-08-02 00:00:00 -07:00
15
- default_executable:
16
- dependencies:
17
- - !ruby/object:Gem::Dependency
13
+ date: 2013-01-21 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
18
16
  name: schema_plus
19
- prerelease: false
20
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
21
18
  none: false
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
25
- version: "0"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
26
23
  type: :runtime
27
- version_requirements: *id001
28
- - !ruby/object:Gem::Dependency
29
- name: rake
30
24
  prerelease: false
31
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: !ruby/object:Gem::Requirement
32
26
  none: false
33
- requirements:
34
- - - ~>
35
- - !ruby/object:Gem::Version
36
- version: 0.8.7
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rake
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
37
39
  type: :development
38
- version_requirements: *id002
39
- - !ruby/object:Gem::Dependency
40
- name: rspec
41
40
  prerelease: false
42
- requirement: &id003 !ruby/object:Gem::Requirement
41
+ version_requirements: !ruby/object:Gem::Requirement
43
42
  none: false
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: "0"
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rdoc
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
48
55
  type: :development
49
- version_requirements: *id003
50
- - !ruby/object:Gem::Dependency
51
- name: sqlite3
52
56
  prerelease: false
53
- requirement: &id004 !ruby/object:Gem::Requirement
57
+ version_requirements: !ruby/object:Gem::Requirement
54
58
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- version: "0"
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rspec
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
59
71
  type: :development
60
- version_requirements: *id004
61
- - !ruby/object:Gem::Dependency
62
- name: simplecov
63
72
  prerelease: false
64
- requirement: &id005 !ruby/object:Gem::Requirement
73
+ version_requirements: !ruby/object:Gem::Requirement
65
74
  none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: "0"
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: sqlite3
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
70
87
  type: :development
71
- version_requirements: *id005
72
- - !ruby/object:Gem::Dependency
73
- name: simplecov-gem-adapter
74
88
  prerelease: false
75
- requirement: &id006 !ruby/object:Gem::Requirement
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: simplecov
97
+ requirement: !ruby/object:Gem::Requirement
76
98
  none: false
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: "0"
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
81
103
  type: :development
82
- version_requirements: *id006
83
- - !ruby/object:Gem::Dependency
84
- name: ruby-debug19
85
104
  prerelease: false
86
- requirement: &id007 !ruby/object:Gem::Requirement
105
+ version_requirements: !ruby/object:Gem::Requirement
87
106
  none: false
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- version: "0"
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov-gem-adapter
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
92
119
  type: :development
93
- version_requirements: *id007
94
- description: SchemaAssociations extends ActiveRecord to automatically create associations by inspecting the database schema. This is more more DRY than the standard behavior, for which in addition to specifying the foreign key in the migration, you must also specify complementary associations in two model files (e.g. a :belongs_to and a :has_many).
95
- email:
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ description: SchemaAssociations extends ActiveRecord to automatically create associations
128
+ by inspecting the database schema. This is more more DRY than the standard behavior,
129
+ for which in addition to specifying the foreign key in the migration, you must also
130
+ specify complementary associations in two model files (e.g. a :belongs_to and a
131
+ :has_many).
132
+ email:
96
133
  - ronen@barzel.org
97
134
  - michal.lomnicki@gmail.com
98
135
  executables: []
99
-
100
136
  extensions: []
101
-
102
137
  extra_rdoc_files: []
103
-
104
- files:
138
+ files:
105
139
  - .gitignore
106
- - Gemfile
140
+ - .travis.yml
107
141
  - MIT-LICENSE
108
142
  - README.rdoc
109
143
  - Rakefile
144
+ - gemfiles/Gemfile.rails-3.2
145
+ - gemfiles/Gemfile.rails-3.2.lock
110
146
  - init.rb
111
147
  - lib/schema_associations.rb
112
148
  - lib/schema_associations/active_record/associations.rb
@@ -117,35 +153,33 @@ files:
117
153
  - spec/association_spec.rb
118
154
  - spec/connection.rb
119
155
  - spec/spec_helper.rb
120
- has_rdoc: true
121
156
  homepage: https://github.com/lomba/schema_associations
122
157
  licenses: []
123
-
124
158
  post_install_message:
125
159
  rdoc_options: []
126
-
127
- require_paths:
160
+ require_paths:
128
161
  - lib
129
- required_ruby_version: !ruby/object:Gem::Requirement
162
+ required_ruby_version: !ruby/object:Gem::Requirement
130
163
  none: false
131
- requirements:
132
- - - ">="
133
- - !ruby/object:Gem::Version
134
- version: "0"
135
- required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ! '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
169
  none: false
137
- requirements:
138
- - - ">="
139
- - !ruby/object:Gem::Version
140
- version: "0"
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
141
174
  requirements: []
142
-
143
175
  rubyforge_project: schema_associations
144
- rubygems_version: 1.6.2
176
+ rubygems_version: 1.8.24
145
177
  signing_key:
146
178
  specification_version: 3
147
- summary: ActiveRecord extension that automatically (DRY) creates associations based on the schema
148
- test_files:
179
+ summary: ActiveRecord extension that automatically (DRY) creates associations based
180
+ on the schema
181
+ test_files:
149
182
  - spec/association_spec.rb
150
183
  - spec/connection.rb
151
184
  - spec/spec_helper.rb
185
+ has_rdoc:
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gemspec