schema_associations 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/README.md +11 -8
- data/gemfiles/Gemfile.rails-4.0 +4 -0
- data/lib/schema_associations/active_record/associations.rb +11 -3
- data/lib/schema_associations/version.rb +1 -1
- data/runspecs +20 -3
- data/schema_associations.gemspec +2 -2
- data/spec/association_spec.rb +68 -6
- data/spec/spec_helper.rb +4 -6
- metadata +5 -5
- data/gemfiles/Gemfile.rails-3.2.lock +0 -118
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70205c74f75ca21daa67a8f61fe2d1d929c31190
|
4
|
+
data.tar.gz: 361d1fad6225d77f2a3c082a07ab455275c1c9d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4404428e7c93f5afe933a10ff82dbed3c4b9dafb3bb9b9540559d24517c5e8bad1fd5a8299ef82f8e5a0f275ae11af617b0bb39051349470a42fa61cac196005
|
7
|
+
data.tar.gz: 6fc59f166f9732dfd794b844e631cf037c1afb8e944b308b2cba25df2538866a260598238239e9c8eb93f4d11c6d72fa470048a90b82d3a60f43631cef5f0fcc
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SchemaAssociations
|
2
2
|
|
3
|
-
|
3
|
+
SchemaAssociations is an ActiveRecord extension that keeps your model class
|
4
4
|
definitions simpler and more DRY, by automatically defining associations based
|
5
5
|
on the database schema.
|
6
6
|
|
@@ -68,7 +68,7 @@ SchemaAssociations::ActiveRecord#schema_associations, such as:
|
|
68
68
|
schema_associations :concise_names => false
|
69
69
|
end
|
70
70
|
|
71
|
-
See the[SchemaAssociations::Confg](http://rubydoc.info/gems/schema_associations/SchemaAssociations/Config) for the available options.
|
71
|
+
See the [SchemaAssociations::Confg RDOC](http://rubydoc.info/gems/schema_associations/SchemaAssociations/Config) for the available options.
|
72
72
|
|
73
73
|
### This seems cool, but I'm worried about too much automagic
|
74
74
|
|
@@ -318,12 +318,11 @@ use cases that you logged).
|
|
318
318
|
## Compatibility
|
319
319
|
|
320
320
|
SchemaAssociations supports all combinations of:
|
321
|
-
* rails 3.2
|
322
|
-
* MRI ruby 1.9.2 or 1.9.3
|
323
321
|
|
322
|
+
* Rails 3.2 or rails 4.0
|
323
|
+
* MRI ruby 1.9.3 or 2.0.0
|
324
324
|
|
325
|
-
Note: As of version 1.0.0, ruby 1.8.7 and rails < 3.2 are no longer supported.
|
326
|
-
The last version to support them is 0.1.2
|
325
|
+
Note: As of version 1.0.0, ruby 1.8.7 and rails < 3.2 are no longer supported. As of version 1.2.0, ruby 1.9.2 is no longer supported.
|
327
326
|
|
328
327
|
## Installation
|
329
328
|
|
@@ -350,11 +349,15 @@ specific file or example (rather than running the full suite) you can do, e.g.
|
|
350
349
|
|
351
350
|
$ ./runspecs [other options] --rspec -- spec/association_spec.rb -e 'base'
|
352
351
|
|
353
|
-
|
354
|
-
coverage/index.html -- it should be at 100% coverage.
|
352
|
+
Code coverage results will be in coverage/index.html -- it should be at 100% coverage.
|
355
353
|
|
356
354
|
## Release notes:
|
357
355
|
|
356
|
+
### 1.2.0
|
357
|
+
|
358
|
+
* Works with Rails 4, thanks to [@tovodeverett](https://github.com/tovodeverett)
|
359
|
+
* Test against MRI ruby 2.0.0; no longer test against 1.9.2
|
360
|
+
|
358
361
|
### 1.1.0
|
359
362
|
|
360
363
|
* New feature: `config.table_prefix_map`
|
@@ -10,7 +10,7 @@ module SchemaAssociations
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def initialize_with_schema_associations(klass, *args)
|
13
|
-
klass.send :_load_schema_associations_associations
|
13
|
+
klass.send :_load_schema_associations_associations unless klass.nil?
|
14
14
|
initialize_without_schema_associations(klass, *args)
|
15
15
|
end
|
16
16
|
end
|
@@ -134,13 +134,21 @@ module SchemaAssociations
|
|
134
134
|
macro = :has_many
|
135
135
|
name = names[:has_many]
|
136
136
|
if connection.columns(referencing_table_name).any?{ |col| col.name == 'position' }
|
137
|
-
|
137
|
+
if ::ActiveRecord::VERSION::MAJOR.to_i < 4
|
138
|
+
opts[:order] = :position
|
139
|
+
else
|
140
|
+
scope_block = lambda { order :position }
|
141
|
+
end
|
138
142
|
end
|
139
143
|
end
|
140
144
|
end
|
141
145
|
if (_filter_association(macro, name) && !_method_exists?(name))
|
142
146
|
logger.info "[schema_associations] #{self.name || self.table_name.classify}.#{macro} #{name.inspect}, #{opts.inspect[1...-1]}"
|
143
|
-
|
147
|
+
if ::ActiveRecord::VERSION::MAJOR.to_i < 4
|
148
|
+
send macro, name, opts.dup
|
149
|
+
else
|
150
|
+
send macro, name, scope_block, opts.dup
|
151
|
+
end
|
144
152
|
end
|
145
153
|
end
|
146
154
|
|
data/runspecs
CHANGED
@@ -6,7 +6,7 @@ require 'shellwords'
|
|
6
6
|
require 'tempfile'
|
7
7
|
|
8
8
|
RUBY_VERSIONS = %W[1.9.3 2.0.0]
|
9
|
-
RAILS_VERSIONS = %W[3.2]
|
9
|
+
RAILS_VERSIONS = %W[3.2 4.0]
|
10
10
|
|
11
11
|
o = OpenStruct.new
|
12
12
|
o.ruby_versions = RUBY_VERSIONS
|
@@ -51,11 +51,28 @@ Combo = Struct.new(:ruby, :rails)
|
|
51
51
|
|
52
52
|
combos = o.ruby_versions.product(o.rails_versions).map{|product| Combo.new(*product)}.select {|combo|
|
53
53
|
case
|
54
|
-
when combo.rails >= "3.2" && combo.ruby <= "1.8.7" then false
|
54
|
+
when combo.rails >= "3.2" && combo.ruby <= "1.8.7" then false # no longer happens, just keeping it as an example
|
55
55
|
else true
|
56
56
|
end
|
57
57
|
}
|
58
58
|
|
59
|
+
if system("which -s rvm")
|
60
|
+
# using rvm
|
61
|
+
def ruby_version_selector(ruby)
|
62
|
+
"rvm #{ruby} do"
|
63
|
+
end
|
64
|
+
else
|
65
|
+
# using rbenv. remove current version from path and current gem path
|
66
|
+
# so that forked shell will respect RBENV_VERSION variable
|
67
|
+
ENV['PATH'] = ENV['PATH'].split(':').reject{|dir| dir =~ %r{/rbenv/versions/}}.join(':')
|
68
|
+
ENV['GEM_PATH'] = nil
|
69
|
+
|
70
|
+
def ruby_version_selector(ruby)
|
71
|
+
@versions ||= `rbenv versions --bare`.split
|
72
|
+
version = @versions.select{|v| v.start_with? ruby}.last || abort("no ruby version '#{ruby}' installed in rbenv")
|
73
|
+
"RBENV_VERSION=#{version}"
|
74
|
+
end
|
75
|
+
end
|
59
76
|
|
60
77
|
GEMFILES_DIR = File.expand_path('../gemfiles', __FILE__)
|
61
78
|
errs = []
|
@@ -74,7 +91,7 @@ combos.each_with_index do |combo, n|
|
|
74
91
|
"bundle exec rake spec"
|
75
92
|
end
|
76
93
|
|
77
|
-
command = %Q{BUNDLE_GEMFILE="#{File.join(GEMFILES_DIR, "Gemfile.rails-#{rails}")}"
|
94
|
+
command = %Q{BUNDLE_GEMFILE="#{File.join(GEMFILES_DIR, "Gemfile.rails-#{rails}")}" #{ruby_version_selector(ruby)} #{cmd} #{Shellwords.join(ARGV)}}
|
78
95
|
|
79
96
|
puts "\n\n*** ruby version #{ruby} - rails version #{rails} [#{n+1} of #{combos.size}]\n\n#{command}"
|
80
97
|
|
data/schema_associations.gemspec
CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
-
s.add_dependency("schema_plus")
|
23
|
-
|
22
|
+
s.add_dependency("schema_plus", ">= 1.2.0")
|
23
|
+
|
24
24
|
s.add_development_dependency("rake")
|
25
25
|
s.add_development_dependency("rdoc")
|
26
26
|
s.add_development_dependency("rspec")
|
data/spec/association_spec.rb
CHANGED
@@ -329,12 +329,36 @@ describe ActiveRecord::Base do
|
|
329
329
|
)
|
330
330
|
class HappyPost < ActiveRecord::Base ; self.table_name = 'wooga_posts' ; end
|
331
331
|
class HappyComment < ActiveRecord::Base ; self.table_name = 'wooga_comments' ; end
|
332
|
-
Kernel.warn HappyPost.reflect_on_all_associations.inspect
|
332
|
+
# Kernel.warn HappyPost.reflect_on_all_associations.inspect
|
333
333
|
HappyComment.reflect_on_association(:post).class_name.should == "HappyPost"
|
334
334
|
HappyPost.reflect_on_association(:comments).class_name.should == "HappyComment"
|
335
335
|
end
|
336
336
|
end
|
337
337
|
|
338
|
+
context "without position" do
|
339
|
+
before(:each) do
|
340
|
+
create_tables(
|
341
|
+
"posts", {}, {},
|
342
|
+
"comments", {}, { :post_id => {} }
|
343
|
+
)
|
344
|
+
class Post < ActiveRecord::Base ; end
|
345
|
+
class Comment < ActiveRecord::Base ; end
|
346
|
+
end
|
347
|
+
it "should create unordered has_many association" do
|
348
|
+
reflection = Post.reflect_on_association(:comments)
|
349
|
+
reflection.should_not be_nil
|
350
|
+
reflection.macro.should == :has_many
|
351
|
+
reflection.options[:class_name].should == "Comment"
|
352
|
+
reflection.options[:foreign_key].should == "post_id"
|
353
|
+
reflection.options[:inverse_of].should == :post
|
354
|
+
if ::ActiveRecord::VERSION::MAJOR.to_i < 4
|
355
|
+
reflection.options[:order].should be_nil
|
356
|
+
else
|
357
|
+
reflection.scope.should be_nil
|
358
|
+
end
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
338
362
|
context "with position" do
|
339
363
|
before(:each) do
|
340
364
|
create_tables(
|
@@ -351,7 +375,48 @@ describe ActiveRecord::Base do
|
|
351
375
|
reflection.options[:class_name].should == "Comment"
|
352
376
|
reflection.options[:foreign_key].should == "post_id"
|
353
377
|
reflection.options[:inverse_of].should == :post
|
354
|
-
|
378
|
+
if ::ActiveRecord::VERSION::MAJOR.to_i < 4
|
379
|
+
reflection.options[:order].to_s.should == "position"
|
380
|
+
else
|
381
|
+
reflection.scope.should_not be_nil
|
382
|
+
scope_tester = Object.new
|
383
|
+
expect(scope_tester).to receive(:order).with(:position)
|
384
|
+
scope_tester.instance_exec(&reflection.scope)
|
385
|
+
end
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
context "with scope that doesn't use include" do
|
390
|
+
before(:each) do
|
391
|
+
create_tables(
|
392
|
+
"posts", {}, {},
|
393
|
+
"comments", {}, { :post_id => {}, :position => {} }
|
394
|
+
)
|
395
|
+
class Post < ActiveRecord::Base ; end
|
396
|
+
class Comment < ActiveRecord::Base
|
397
|
+
scope :simple_scope, lambda { order(:id) }
|
398
|
+
end
|
399
|
+
end
|
400
|
+
it "should create viable scope" do
|
401
|
+
relation = Comment.simple_scope
|
402
|
+
expect { relation.to_a }.to_not raise_error
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
context "with scope that uses include" do
|
407
|
+
before(:each) do
|
408
|
+
create_tables(
|
409
|
+
"posts", {}, {},
|
410
|
+
"comments", {}, { :post_id => {}, :position => {} }
|
411
|
+
)
|
412
|
+
class Post < ActiveRecord::Base ; end
|
413
|
+
class Comment < ActiveRecord::Base
|
414
|
+
scope :simple_scope, lambda { order(:id).includes(:post) }
|
415
|
+
end
|
416
|
+
end
|
417
|
+
it "should create viable scope" do
|
418
|
+
relation = Comment.simple_scope
|
419
|
+
expect { relation.to_a }.to_not raise_error
|
355
420
|
end
|
356
421
|
end
|
357
422
|
|
@@ -552,11 +617,8 @@ describe ActiveRecord::Base do
|
|
552
617
|
end
|
553
618
|
|
554
619
|
it "should define associations before needed by relation" do
|
555
|
-
Post.joins(:comments).
|
556
|
-
expect { Post.joins(:comments).all }.to_not raise_error
|
557
|
-
|
620
|
+
expect { Post.joins(:comments).to_a }.to_not raise_error
|
558
621
|
end
|
559
|
-
|
560
622
|
end
|
561
623
|
end
|
562
624
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
SimpleCov.start "gem"
|
5
|
-
end
|
1
|
+
require 'simplecov'
|
2
|
+
require 'simplecov-gem-adapter'
|
3
|
+
SimpleCov.start "gem"
|
6
4
|
|
7
5
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
6
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
@@ -27,4 +25,4 @@ def remove_all_models
|
|
27
25
|
end
|
28
26
|
end
|
29
27
|
|
30
|
-
SimpleCov.command_name
|
28
|
+
SimpleCov.command_name "[Ruby #{RUBY_VERSION} - ActiveRecord #{::ActiveRecord::VERSION::STRING}]"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_associations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ronen Barzel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: schema_plus
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 1.2.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 1.2.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,7 +127,7 @@ files:
|
|
127
127
|
- README.md
|
128
128
|
- Rakefile
|
129
129
|
- gemfiles/Gemfile.rails-3.2
|
130
|
-
- gemfiles/Gemfile.rails-
|
130
|
+
- gemfiles/Gemfile.rails-4.0
|
131
131
|
- init.rb
|
132
132
|
- lib/schema_associations.rb
|
133
133
|
- lib/schema_associations/active_record/associations.rb
|
@@ -1,118 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: /Users/ronen/github/schema_associations
|
3
|
-
specs:
|
4
|
-
schema_associations (1.0.1)
|
5
|
-
schema_plus
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: http://rubygems.org/
|
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)
|
16
|
-
builder (~> 3.0.0)
|
17
|
-
erubis (~> 2.7.0)
|
18
|
-
journey (~> 1.0.4)
|
19
|
-
rack (~> 1.4.5)
|
20
|
-
rack-cache (~> 1.2)
|
21
|
-
rack-test (~> 0.6.1)
|
22
|
-
sprockets (~> 2.2.1)
|
23
|
-
activemodel (3.2.13)
|
24
|
-
activesupport (= 3.2.13)
|
25
|
-
builder (~> 3.0.0)
|
26
|
-
activerecord (3.2.13)
|
27
|
-
activemodel (= 3.2.13)
|
28
|
-
activesupport (= 3.2.13)
|
29
|
-
arel (~> 3.0.2)
|
30
|
-
tzinfo (~> 0.3.29)
|
31
|
-
activeresource (3.2.13)
|
32
|
-
activemodel (= 3.2.13)
|
33
|
-
activesupport (= 3.2.13)
|
34
|
-
activesupport (3.2.13)
|
35
|
-
i18n (= 0.6.1)
|
36
|
-
multi_json (~> 1.0)
|
37
|
-
arel (3.0.2)
|
38
|
-
builder (3.0.4)
|
39
|
-
diff-lcs (1.2.4)
|
40
|
-
erubis (2.7.0)
|
41
|
-
hike (1.2.2)
|
42
|
-
i18n (0.6.1)
|
43
|
-
journey (1.0.4)
|
44
|
-
json (1.8.0)
|
45
|
-
mail (2.5.4)
|
46
|
-
mime-types (~> 1.16)
|
47
|
-
treetop (~> 1.4.8)
|
48
|
-
mime-types (1.23)
|
49
|
-
multi_json (1.7.4)
|
50
|
-
polyglot (0.3.3)
|
51
|
-
rack (1.4.5)
|
52
|
-
rack-cache (1.2)
|
53
|
-
rack (>= 0.4)
|
54
|
-
rack-ssl (1.3.3)
|
55
|
-
rack
|
56
|
-
rack-test (0.6.2)
|
57
|
-
rack (>= 1.0)
|
58
|
-
rails (3.2.13)
|
59
|
-
actionmailer (= 3.2.13)
|
60
|
-
actionpack (= 3.2.13)
|
61
|
-
activerecord (= 3.2.13)
|
62
|
-
activeresource (= 3.2.13)
|
63
|
-
activesupport (= 3.2.13)
|
64
|
-
bundler (~> 1.0)
|
65
|
-
railties (= 3.2.13)
|
66
|
-
railties (3.2.13)
|
67
|
-
actionpack (= 3.2.13)
|
68
|
-
activesupport (= 3.2.13)
|
69
|
-
rack-ssl (~> 1.3.2)
|
70
|
-
rake (>= 0.8.7)
|
71
|
-
rdoc (~> 3.4)
|
72
|
-
thor (>= 0.14.6, < 2.0)
|
73
|
-
rake (10.0.4)
|
74
|
-
rdoc (3.12.2)
|
75
|
-
json (~> 1.4)
|
76
|
-
rspec (2.13.0)
|
77
|
-
rspec-core (~> 2.13.0)
|
78
|
-
rspec-expectations (~> 2.13.0)
|
79
|
-
rspec-mocks (~> 2.13.0)
|
80
|
-
rspec-core (2.13.1)
|
81
|
-
rspec-expectations (2.13.0)
|
82
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
83
|
-
rspec-mocks (2.13.1)
|
84
|
-
schema_plus (1.1.2)
|
85
|
-
rails (>= 3.2)
|
86
|
-
valuable
|
87
|
-
simplecov (0.7.1)
|
88
|
-
multi_json (~> 1.0)
|
89
|
-
simplecov-html (~> 0.7.1)
|
90
|
-
simplecov-gem-adapter (1.0.1)
|
91
|
-
simplecov
|
92
|
-
simplecov-html (0.7.1)
|
93
|
-
sprockets (2.2.2)
|
94
|
-
hike (~> 1.2)
|
95
|
-
multi_json (~> 1.0)
|
96
|
-
rack (~> 1.0)
|
97
|
-
tilt (~> 1.1, != 1.3.0)
|
98
|
-
sqlite3 (1.3.7)
|
99
|
-
thor (0.18.1)
|
100
|
-
tilt (1.4.1)
|
101
|
-
treetop (1.4.12)
|
102
|
-
polyglot
|
103
|
-
polyglot (>= 0.3.1)
|
104
|
-
tzinfo (0.3.37)
|
105
|
-
valuable (0.9.8)
|
106
|
-
|
107
|
-
PLATFORMS
|
108
|
-
ruby
|
109
|
-
|
110
|
-
DEPENDENCIES
|
111
|
-
rails (~> 3.2.0)
|
112
|
-
rake
|
113
|
-
rdoc
|
114
|
-
rspec
|
115
|
-
schema_associations!
|
116
|
-
simplecov
|
117
|
-
simplecov-gem-adapter
|
118
|
-
sqlite3
|