edge_rider 0.3.2 → 2.0.0

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.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +99 -0
  3. data/.rspec +1 -0
  4. data/.ruby-version +1 -1
  5. data/CHANGELOG.md +45 -0
  6. data/Gemfile +1 -0
  7. data/{gemfiles/Gemfile.4.2.mysql2 → Gemfile.4.2.mysql2} +4 -3
  8. data/{gemfiles/Gemfile.4.2.mysql2.lock → Gemfile.4.2.mysql2.lock} +32 -22
  9. data/{gemfiles/Gemfile.4.2.pg → Gemfile.4.2.pg} +3 -2
  10. data/{gemfiles/Gemfile.4.2.pg.lock → Gemfile.4.2.pg.lock} +30 -20
  11. data/Gemfile.5.2.mysql2 +17 -0
  12. data/{gemfiles/Gemfile.5.1.mysql2.lock → Gemfile.5.2.mysql2.lock} +34 -22
  13. data/{gemfiles/Gemfile.5.1.mysql2 → Gemfile.5.2.pg} +7 -5
  14. data/{gemfiles/Gemfile.5.1.pg.lock → Gemfile.5.2.pg.lock} +32 -20
  15. data/{gemfiles/Gemfile.5.1.pg → Gemfile.6.1.pg} +4 -3
  16. data/Gemfile.6.1.pg.lock +78 -0
  17. data/Gemfile.lock +1 -0
  18. data/README.md +96 -91
  19. data/Rakefile +1 -1
  20. data/edge_rider.gemspec +24 -15
  21. data/lib/edge_rider/collect_column.rb +8 -15
  22. data/lib/edge_rider/origin_class.rb +2 -10
  23. data/lib/edge_rider/preload_associations.rb +7 -0
  24. data/lib/edge_rider/scoped.rb +1 -1
  25. data/lib/edge_rider/to_id_query.rb +1 -1
  26. data/lib/edge_rider/traverse_association.rb +9 -5
  27. data/lib/edge_rider/util.rb +18 -19
  28. data/lib/edge_rider/version.rb +1 -1
  29. data/lib/edge_rider.rb +0 -1
  30. metadata +24 -37
  31. data/.travis.yml +0 -68
  32. data/gemfiles/Gemfile.2.3.mysql2 +0 -16
  33. data/gemfiles/Gemfile.2.3.mysql2.lock +0 -37
  34. data/gemfiles/Gemfile.3.2.mysql2 +0 -16
  35. data/gemfiles/Gemfile.3.2.mysql2.lock +0 -62
  36. data/lib/edge_rider/to_sql.rb +0 -13
  37. data/spec/edge_rider/collect_column_spec.rb +0 -85
  38. data/spec/edge_rider/collect_ids_spec.rb +0 -108
  39. data/spec/edge_rider/origin_class_spec.rb +0 -32
  40. data/spec/edge_rider/preload_associations_spec.rb +0 -15
  41. data/spec/edge_rider/scoped_spec.rb +0 -55
  42. data/spec/edge_rider/to_id_query_spec.rb +0 -29
  43. data/spec/edge_rider/to_sql_spec.rb +0 -14
  44. data/spec/edge_rider/traverse_association_spec.rb +0 -134
  45. data/spec/edge_rider/util_spec.rb +0 -5
  46. data/spec/spec_helper.rb +0 -12
  47. data/spec/support/database.rb +0 -34
  48. data/spec/support/database.sample.yml +0 -10
  49. data/spec/support/database.travis.yml +0 -9
  50. data/spec/support/models.rb +0 -92
@@ -1,16 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Runtime dependencies
4
- gem 'activerecord', '=2.3.18'
5
- gem 'mysql2', '= 0.2.20'
6
- gem 'i18n', '=0.6.11' # 0.7 no longer builds for Ruby 1.8.7
7
-
8
- # Development dependencies
9
- gem 'rake', '=10.0.4'
10
- gem 'database_cleaner'
11
- gem 'rspec', '~> 1.3.0'
12
- gem 'has_defaults' # used by test models
13
- gem 'gemika', '>= 0.2.0'
14
-
15
- # Gem under test
16
- gem 'edge_rider', :path => '..'
@@ -1,37 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- edge_rider (0.3.2)
5
- activerecord
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activerecord (2.3.18)
11
- activesupport (= 2.3.18)
12
- activesupport (2.3.18)
13
- database_cleaner (1.0.1)
14
- gemika (0.3.2)
15
- has_defaults (0.4.4)
16
- activerecord
17
- i18n (0.6.11)
18
- mysql2 (0.2.20)
19
- rake (10.0.4)
20
- rspec (1.3.2)
21
-
22
- PLATFORMS
23
- ruby
24
-
25
- DEPENDENCIES
26
- activerecord (= 2.3.18)
27
- database_cleaner
28
- edge_rider!
29
- gemika (>= 0.2.0)
30
- has_defaults
31
- i18n (= 0.6.11)
32
- mysql2 (= 0.2.20)
33
- rake (= 10.0.4)
34
- rspec (~> 1.3.0)
35
-
36
- BUNDLED WITH
37
- 1.12.5
@@ -1,16 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Runtime dependencies
4
- gem 'activerecord', '=3.2.22'
5
- gem 'mysql2', '= 0.3.17'
6
- gem 'i18n', '=0.6.11' # 0.7 no longer builds for Ruby 1.8.7
7
-
8
- # Development dependencies
9
- gem 'rake', '=10.0.4'
10
- gem 'database_cleaner'
11
- gem 'rspec', '~> 3.4'
12
- gem 'has_defaults' # used by test models
13
- gem 'gemika', '>= 0.2.0'
14
-
15
- # Gem under test
16
- gem 'edge_rider', :path => '..'
@@ -1,62 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- edge_rider (0.3.2)
5
- activerecord
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (3.2.22)
11
- activesupport (= 3.2.22)
12
- builder (~> 3.0.0)
13
- activerecord (3.2.22)
14
- activemodel (= 3.2.22)
15
- activesupport (= 3.2.22)
16
- arel (~> 3.0.2)
17
- tzinfo (~> 0.3.29)
18
- activesupport (3.2.22)
19
- i18n (~> 0.6, >= 0.6.4)
20
- multi_json (~> 1.0)
21
- arel (3.0.3)
22
- builder (3.0.4)
23
- database_cleaner (1.0.1)
24
- diff-lcs (1.2.5)
25
- gemika (0.3.2)
26
- has_defaults (0.4.4)
27
- activerecord
28
- i18n (0.6.11)
29
- multi_json (1.12.1)
30
- mysql2 (0.3.17)
31
- rake (10.0.4)
32
- rspec (3.5.0)
33
- rspec-core (~> 3.5.0)
34
- rspec-expectations (~> 3.5.0)
35
- rspec-mocks (~> 3.5.0)
36
- rspec-core (3.5.3)
37
- rspec-support (~> 3.5.0)
38
- rspec-expectations (3.5.0)
39
- diff-lcs (>= 1.2.0, < 2.0)
40
- rspec-support (~> 3.5.0)
41
- rspec-mocks (3.5.0)
42
- diff-lcs (>= 1.2.0, < 2.0)
43
- rspec-support (~> 3.5.0)
44
- rspec-support (3.5.0)
45
- tzinfo (0.3.51)
46
-
47
- PLATFORMS
48
- ruby
49
-
50
- DEPENDENCIES
51
- activerecord (= 3.2.22)
52
- database_cleaner
53
- edge_rider!
54
- gemika (>= 0.2.0)
55
- has_defaults
56
- i18n (= 0.6.11)
57
- mysql2 (= 0.3.17)
58
- rake (= 10.0.4)
59
- rspec (~> 3.4)
60
-
61
- BUNDLED WITH
62
- 1.12.5
@@ -1,13 +0,0 @@
1
- module EdgeRider
2
- module ToSql
3
-
4
- def to_sql
5
- construct_finder_sql({})
6
- end
7
-
8
- if Util.activerecord2?
9
- ActiveRecord::Base.extend(self)
10
- end
11
-
12
- end
13
- end
@@ -1,85 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EdgeRider::CollectColumn do
4
-
5
- describe '#collect_column' do
6
-
7
- it 'should collect the given value from a scope' do
8
- Forum.create!(:id => 1, :name => 'Name 1')
9
- Forum.create!(:id => 2, :name => 'Name 2')
10
- Forum.create!(:id => 3, :name => 'Name 3')
11
- scope = Forum.scoped(:conditions => { :id => [2, 3] })
12
- scope.collect_column(:name).should =~ ['Name 2', 'Name 3']
13
- end
14
-
15
- it 'should collect the given value from an ActiveRecord class' do
16
- Forum.create!(:id => 1, :name => 'Name 1')
17
- Forum.create!(:id => 2, :name => 'Name 2')
18
- Forum.collect_column(:name).should =~ ['Name 1', 'Name 2']
19
- end
20
-
21
- it 'should cast the collected value to their equivalent Ruby type' do
22
- Post.create!
23
- Post.collect_column(:created_at).first.should be_a(Time)
24
- end
25
-
26
- it 'should not instantiate ActiveRecord objects when collecting values' do
27
- Forum.create!(:name => 'Name')
28
- Forum.should_not_receive(:new)
29
- Forum.collect_column(:name).should == ['Name']
30
- end
31
-
32
- it 'should qualify the column name to resolve any ambiguities' do
33
- expect { Topic.scoped(:joins => :forum).collect_column(:id) }.to_not raise_error
34
- end
35
-
36
- context 'with :distinct option' do
37
-
38
- it 'should return unique values' do
39
- Forum.create!(:id => 1, :name => 'Name 1')
40
- Forum.create!(:id => 2, :name => 'Name 2')
41
- Forum.create!(:id => 3, :name => 'Name 2')
42
- scope = Forum.scoped(:conditions => { :id => [2, 3] })
43
- scope.collect_column(:name, :distinct => true).should =~ ['Name 2']
44
- end
45
-
46
- end
47
-
48
- context 'when called on a has many association' do
49
-
50
- it 'should collect the given value' do
51
- topic = Topic.create!
52
- post = Post.create!(:topic => topic, :id => 1)
53
- post = Post.create!(:topic => topic, :id => 2)
54
- topic.reload
55
- topic.posts.to_a
56
- topic.posts.collect_column(:id).should =~ [1,2]
57
- end
58
-
59
- it 'should return values when further restricted with an anonymous scope' do
60
- topic = Topic.create!
61
- post = Post.create!(:topic => topic, :id => 1)
62
- post = Post.create!(:topic => topic, :id => 2)
63
- topic.reload
64
- topic.posts.to_a
65
- if topic.posts.respond_to?(:where)
66
- topic.posts.where(:id => [1]).collect_ids.should =~ [1]
67
- else
68
- topic.posts.scoped(:conditions => {:id => [1]}).collect_column(:id).should =~ [1]
69
- end
70
- end
71
-
72
- it 'should return values when further restricted with a named scope' do
73
- topic = Topic.create!
74
- post = Post.create!(:topic => topic, :id => 1)
75
- post = Post.create!(:topic => topic, :id => 2)
76
- topic.reload
77
- topic.posts.to_a
78
- topic.posts.these([1]).collect_column(:id).should =~ [1]
79
- end
80
-
81
- end
82
-
83
- end
84
-
85
- end
@@ -1,108 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EdgeRider::CollectIds do
4
-
5
- describe '#collect_ids' do
6
-
7
- context 'when called on an ActiveRecord class' do
8
-
9
- it 'should return the ids for all records of that class' do
10
- Forum.create!(:id => 1)
11
- Forum.create!(:id => 2)
12
- Forum.collect_ids.should =~ [1, 2]
13
- end
14
-
15
- end
16
-
17
- context 'when called on a scope' do
18
-
19
- it 'should return the ids for all records matching that scope' do
20
- Forum.create!(:id => 1, :name => 'Name 1')
21
- Forum.create!(:id => 2, :name => 'Name 2')
22
- Forum.create!(:id => 3, :name => 'Name 2')
23
- scope = Forum.scoped(:conditions => { :name => 'Name 2' })
24
- scope.collect_ids.should =~ [2, 3]
25
- end
26
-
27
- end
28
-
29
- context 'when called on an Integer' do
30
-
31
- it 'should return the number as an array with a single element' do
32
- 5.collect_ids.should == [5]
33
- end
34
-
35
- end
36
-
37
- context 'when called on another scalar value' do
38
-
39
- it 'should not be defined' do
40
- expect { "foo".collect_ids }.to raise_error(NoMethodError)
41
- end
42
-
43
- end
44
-
45
- context 'when called on an array of Integers' do
46
-
47
- it 'should return the list itself' do
48
- [1, 3].collect_ids.should == [1, 3]
49
- end
50
-
51
- end
52
-
53
- context 'when called on an array of ActiveRecords' do
54
-
55
- it 'should return the ids collected from that list' do
56
- forum_1 = Forum.create!(:id => 1)
57
- forum_2 = Forum.create!(:id => 2)
58
- [forum_1, forum_2].collect_ids.should =~ [1, 2]
59
- end
60
-
61
- end
62
-
63
- context 'when called on an array of other values' do
64
-
65
- it 'should raise an error' do
66
- expect { [1, 'foo', 3].collect_ids }.to raise_error(EdgeRider::CollectIds::Uncollectable)
67
- end
68
-
69
- end
70
-
71
- context 'when called on a has many association' do
72
-
73
- it 'should return the ids' do
74
- topic = Topic.create!
75
- post = Post.create!(:topic => topic, :id => 1)
76
- post = Post.create!(:topic => topic, :id => 2)
77
- topic.reload
78
- topic.posts.to_a
79
- topic.posts.collect_ids.should =~ [1,2]
80
- end
81
-
82
- it 'should return ids when further restricted with an anonymous scope' do
83
- topic = Topic.create!
84
- post = Post.create!(:topic => topic, :id => 1)
85
- post = Post.create!(:topic => topic, :id => 2)
86
- topic.reload
87
- topic.posts.to_a
88
- if topic.posts.respond_to?(:where)
89
- topic.posts.where(:id => [1]).collect_ids.should =~ [1]
90
- else
91
- topic.posts.scoped(:conditions => {:id => [1]}).collect_ids.should =~ [1]
92
- end
93
- end
94
-
95
- it 'should return ids when further restricted with a named scope' do
96
- topic = Topic.create!
97
- post = Post.create!(:topic => topic, :id => 1)
98
- post = Post.create!(:topic => topic, :id => 2)
99
- topic.reload
100
- topic.posts.to_a
101
- topic.posts.these([1]).collect_ids.should =~ [1]
102
- end
103
-
104
- end
105
-
106
- end
107
-
108
- end
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EdgeRider::OriginClass do
4
-
5
- describe '#origin_class' do
6
-
7
- it "should return the class a scope is based on" do
8
- Forum.create!(:id => 1)
9
- Forum.create!(:id => 2)
10
- scope = Forum.scoped(:conditions => { :id => [1] })
11
- scope.origin_class.should == Forum
12
- scope.origin_class.collect_ids.should == [1, 2]
13
- end
14
-
15
- it "should return the class a scope chain is based on" do
16
- Forum.create!(:id => 1, :name => 'A')
17
- Forum.create!(:id => 2, :name => 'B')
18
- Forum.create!(:id => 3, :name => 'C')
19
- scope_chain = Forum.scoped(:conditions => { :id => [1, 2] }).scoped(:conditions => { :name => ['A', 'B'] })
20
- scope_chain.origin_class.should == Forum
21
- scope_chain.origin_class.collect_ids.should == [1, 2, 3]
22
- end
23
-
24
- it "should return itself when called on an ActiveRecord class" do
25
- Forum.create!(:id => 1)
26
- Forum.create!(:id => 2)
27
- Forum.origin_class.should == Forum
28
- Forum.origin_class.collect_ids.should == [1, 2]
29
- end
30
- end
31
-
32
- end
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EdgeRider::PreloadAssociations do
4
-
5
- it 'should preload the given named associations so they are no longer fetched lazily' do
6
- forum = Forum.create!
7
- topic = Topic.create!(:forum => forum)
8
- post = Post.create!(:topic => topic)
9
- Forum.preload_associations([forum], :topics => :posts)
10
- Topic.should_not_receive(:new)
11
- Post.should_not_receive(:new)
12
- forum.topics.collect(&:posts)
13
- end
14
-
15
- end
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EdgeRider::Scoped do
4
- describe 'scoped' do
5
-
6
- it 'returns a scope when called without parameters' do
7
- unless EdgeRider::Util.activerecord2? # Rails 2 cannot do this
8
- EdgeRider::Util.scope?( Forum.scoped ).should == true
9
- end
10
- end
11
-
12
- it 'returns a scope when called with an empty hash' do
13
- EdgeRider::Util.scope?( Forum.scoped({}) ).should == true
14
- end
15
-
16
- it 'respects conditions' do
17
- trashed = Forum.create! :trashed => true
18
- active = Forum.create! :trashed => false
19
-
20
- Forum.scoped(:conditions => { :trashed => true }).to_a.should == [ trashed ]
21
- end
22
-
23
- it 'respects order' do
24
- c = Forum.create! :name => 'Chemikalien'
25
- a = Forum.create! :name => 'Allegorie'
26
- b = Forum.create! :name => 'Botanisch'
27
-
28
- Forum.scoped(:order => 'name ASC').to_a.should == [ a, b, c ]
29
- end
30
-
31
- it 'can be used to add conditions to an existing scope chain' do
32
- bulldog = Forum.create! :name => 'bulldog', :trashed => false
33
- trashed = Forum.create! :name => 'maneuver', :trashed => true
34
- trashed_bulldog = Forum.create! :name => 'bulldog', :trashed => true
35
-
36
- Forum.
37
- scoped(:conditions => { :trashed => true }).
38
- scoped(:conditions => { :name => 'bulldog' }).to_a.should == [ trashed_bulldog ]
39
- end
40
-
41
- it 'can be used to add conditions to a has_many association' do
42
- forum = Forum.create!
43
- thema = Topic.create! :subject => 'Thema', :trashed => false, :forum => forum
44
- other_topic = Topic.create! :subject => 'Other', :trashed => false, :forum => forum
45
- trashed_thema = Topic.create! :subject => 'Thema', :trashed => true, :forum => forum
46
-
47
- has_many_scope = forum.active_topics
48
- # In Rails 3, #scoped on associations does not take parameters but turns
49
- # an association into a real scope.
50
- has_many_scope = has_many_scope.scoped if ActiveRecord::VERSION::MAJOR == 3
51
- has_many_scope.scoped(:conditions => { :subject => 'Thema' }).to_a.should =~ [ thema ]
52
- end
53
-
54
- end
55
- end