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,29 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EdgeRider::ToIdQuery do
4
-
5
- describe '#to_id_query' do
6
-
7
- it 'should simplify a scope to a IN query that selects IDs' do
8
- Forum.create!(:id => 1, :name => 'Name 1')
9
- Forum.create!(:id => 2, :name => 'Name 2')
10
- Forum.create!(:id => 3, :name => 'Name 2')
11
- scope = Forum.scoped(:conditions => { :name => 'Name 2' })
12
- scope.to_id_query.to_sql.should =~ EdgeRider::Development.selects_star_with_conditions_pattern('forums', /["`]?forums["`]?\.["`]?id["`]? IN \(2,\s*3\)/)
13
- end
14
-
15
- it 'should resolve and lose any JOINs' do
16
- Forum.create!(:id => 1, :name => 'A')
17
- Forum.create!(:id => 2, :name => 'B')
18
- Forum.create!(:id => 3, :name => 'A')
19
- Topic.create!(:id => 100, :forum_id => 1)
20
- Topic.create!(:id => 101, :forum_id => 1)
21
- Topic.create!(:id => 102, :forum_id => 2)
22
- Topic.create!(:id => 103, :forum_id => 3)
23
- scope = Topic.scoped(:joins => :forum, :conditions => "forums.name = 'A'")
24
- scope.to_id_query.to_sql.should =~ EdgeRider::Development.selects_star_with_conditions_pattern('topics', /["`]?topics["`]?\.["`]?id["`]? IN \(100,\s*101,\s*103\)/)
25
- end
26
-
27
- end
28
-
29
- end
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EdgeRider::ToSql do
4
-
5
- describe '#to_sql' do
6
-
7
- it "should return the SQL the scope would produce" do
8
- scope = Forum.scoped(:conditions => { :name => 'Name' })
9
- scope.to_sql.should =~ EdgeRider::Development.selects_star_with_conditions_pattern('forums', /["`]?forums["`]?\.["`]?name["`]? = 'Name'/)
10
- end
11
-
12
- end
13
-
14
- end
@@ -1,134 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EdgeRider::TraverseAssociation do
4
-
5
- describe '#traverse_association' do
6
-
7
- it 'should traverse a belongs_to associations' do
8
- forum_1 = Forum.create!
9
- forum_2 = Forum.create!
10
- forum_3 = Forum.create!
11
- topic_1 = Topic.create!(:forum => forum_1)
12
- topic_2 = Topic.create!(:forum => forum_1)
13
- topic_3 = Topic.create!(:forum => forum_2)
14
- topic_4 = Topic.create!(:forum => forum_3)
15
- scope = Topic.scoped(:conditions => { :id => [ topic_2.id, topic_4.id ] })
16
- traversed_scope = scope.traverse_association(:forum)
17
- EdgeRider::Util.scope?(traversed_scope).should == true
18
- traversed_scope.to_a.should =~ [forum_1, forum_3]
19
- end
20
-
21
- it 'should raise an error when traversing a belongs_to association with conditions, until this is implemented' do
22
- forum = Forum.create!(:trashed => true)
23
- topic = Topic.create(:forum => forum)
24
-
25
- scope = Topic.scoped(:conditions => { :id => topic.id })
26
- expect { scope.traverse_association(:active_forum) }.to raise_error(NotImplementedError)
27
- end
28
-
29
- it 'should traverse a belongs_to association with conditions'
30
-
31
- it 'should traverse multiple belongs_to associations in different model classes' do
32
- forum_1 = Forum.create!
33
- forum_2 = Forum.create!
34
- forum_3 = Forum.create!
35
- topic_1 = Topic.create!(:forum => forum_1)
36
- topic_2 = Topic.create!(:forum => forum_2)
37
- topic_3 = Topic.create!(:forum => forum_3)
38
- post_1 = Post.create!(:topic => topic_1)
39
- post_2 = Post.create!(:topic => topic_2)
40
- post_3 = Post.create!(:topic => topic_3)
41
- scope = Post.scoped(:conditions => { :id => [post_1.id, post_3.id] })
42
- traversed_scope = scope.traverse_association(:topic, :forum)
43
- EdgeRider::Util.scope?(traversed_scope).should == true
44
- traversed_scope.to_a.should =~ [forum_1, forum_3]
45
- end
46
-
47
- it 'should traverse one or more has_many associations' do
48
- forum_1 = Forum.create!
49
- forum_2 = Forum.create!
50
- forum_3 = Forum.create!
51
- topic_1 = Topic.create!(:forum => forum_1)
52
- topic_2 = Topic.create!(:forum => forum_2)
53
- topic_3 = Topic.create!(:forum => forum_3)
54
- post_1 = Post.create!(:topic => topic_1)
55
- post_2 = Post.create!(:topic => topic_2)
56
- post_3a = Post.create!(:topic => topic_3)
57
- post_3b = Post.create!(:topic => topic_3)
58
- scope = Forum.scoped(:conditions => { :id => [forum_1.id, forum_3.id] })
59
- traversed_scope = scope.traverse_association(:topics, :posts)
60
- EdgeRider::Util.scope?(traversed_scope).should == true
61
- traversed_scope.to_a.should =~ [post_1, post_3a, post_3b]
62
- end
63
-
64
- # in Rails 4, conditions on a scope are expressed as a lambda parameter
65
- it 'should raise an error when traversing a has_many association with conditions, until this is implemented' do
66
- forum = Forum.create!
67
- topic = Topic.create(:forum => forum, :trashed => true)
68
-
69
- scope = Forum.scoped(:conditions => { :id => forum.id })
70
- expect { scope.traverse_association(:active_topics) }.to raise_error(NotImplementedError)
71
- end
72
-
73
- it 'should traverse a has_many association with conditions'
74
-
75
- it 'should traverse a has_many :through association' do
76
- forum_1 = Forum.create!
77
- forum_2 = Forum.create!
78
- forum_3 = Forum.create!
79
- topic_1 = Topic.create!(:forum => forum_1)
80
- topic_2 = Topic.create!(:forum => forum_2)
81
- topic_3 = Topic.create!(:forum => forum_3)
82
- post_1 = Post.create!(:topic => topic_1)
83
- post_2 = Post.create!(:topic => topic_2)
84
- post_3a = Post.create!(:topic => topic_3)
85
- post_3b = Post.create!(:topic => topic_3)
86
- scope = Forum.scoped(:conditions => { :id => [forum_1.id, forum_3.id] })
87
- traversed_scope = scope.traverse_association(:posts)
88
- EdgeRider::Util.scope?(traversed_scope).should == true
89
- traversed_scope.to_a.should =~ [post_1, post_3a, post_3b]
90
- end
91
-
92
- it 'should traverse a has_one association' do
93
- user_1 = User.create!
94
- user_2 = User.create!
95
- user_3 = User.create!
96
- profile_1 = Profile.create!(:user => user_1)
97
- profile_2 = Profile.create!(:user => user_2)
98
- profile_3 = Profile.create!(:user => user_3)
99
- scope = User.scoped(:conditions => { :id => [user_2.id, user_3.id] })
100
- traversed_scope = scope.traverse_association(:profile)
101
- EdgeRider::Util.scope?(traversed_scope).should == true
102
- traversed_scope.to_a.should =~ [profile_2, profile_3]
103
- end
104
-
105
- it 'should raise an error when traversing a has_many association with conditions, until this is implemented' do
106
- user = User.create!
107
- profile = Profile.create(:user => user, :trashed => true)
108
-
109
- scope = User.scoped(:conditions => { :id => user.id })
110
- expect { scope.traverse_association(:active_profile) }.to raise_error(NotImplementedError)
111
- end
112
-
113
- it 'should traverse a has_one association with conditions'
114
-
115
- it 'should traverse up and down the same edges' do
116
- forum_1 = Forum.create!
117
- forum_2 = Forum.create!
118
- forum_3 = Forum.create!
119
- topic_1 = Topic.create!(:forum => forum_1)
120
- topic_2 = Topic.create!(:forum => forum_2)
121
- topic_3 = Topic.create!(:forum => forum_3)
122
- post_1 = Post.create!(:topic => topic_1)
123
- post_2 = Post.create!(:topic => topic_2)
124
- post_3a = Post.create!(:topic => topic_3)
125
- post_3b = Post.create!(:topic => topic_3)
126
- scope = Post.scoped(:conditions => { :id => [post_3a.id] })
127
- traversed_scope = scope.traverse_association(:topic, :forum, :topics, :posts)
128
- EdgeRider::Util.scope?(traversed_scope).should == true
129
- traversed_scope.to_a.should =~ [post_3a, post_3b]
130
- end
131
-
132
- end
133
-
134
- end
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EdgeRider::Util do
4
-
5
- end
data/spec/spec_helper.rb DELETED
@@ -1,12 +0,0 @@
1
- $: << File.join(File.dirname(__FILE__), "/../lib" )
2
-
3
- require 'edge_rider'
4
- require 'edge_rider/development'
5
- require 'database_cleaner'
6
- require 'gemika'
7
-
8
- # Requires supporting files with custom matchers and macros, etc in ./support/ and its subdirectories.
9
- Dir["#{File.dirname(__FILE__)}/support/*.rb"].sort.each {|f| require f}
10
-
11
- Gemika::RSpec.configure_clean_database_before_example
12
- Gemika::RSpec.configure_should_syntax
@@ -1,34 +0,0 @@
1
- Gemika::Database.new.rewrite_schema! do
2
-
3
- create_table :forums do |t|
4
- t.string :name
5
- t.boolean :trashed
6
- end
7
-
8
- create_table :topics do |t|
9
- t.string :subject
10
- t.references :forum
11
- t.references :author
12
- t.boolean :trashed
13
- end
14
-
15
- create_table :posts do |t|
16
- t.text :body
17
- t.references :topic
18
- t.references :author
19
- t.boolean :trashed
20
- t.timestamps
21
- end
22
-
23
- create_table :users do |t|
24
- t.string :email
25
- t.boolean :trashed
26
- end
27
-
28
- create_table :profiles do |t|
29
- t.references :user
30
- t.text :hobbies
31
- t.boolean :trashed
32
- end
33
-
34
- end
@@ -1,10 +0,0 @@
1
- mysql:
2
- database: edge_rider_test
3
- host: localhost
4
- username: root
5
- password: secret
6
-
7
- postgresql:
8
- database: edge_rider_test
9
- user:
10
- password:
@@ -1,9 +0,0 @@
1
- mysql:
2
- database: edge_rider_test
3
- username: travis
4
- password:
5
-
6
- postgresql:
7
- database: edge_rider_test
8
- user: postgres
9
- password:
@@ -1,92 +0,0 @@
1
- require 'has_defaults'
2
-
3
- # Since our specs are mostly about working with IDs, this module can be
4
- # included in an ActiveRecord model class to allow setting the :id attribute
5
- # on create. This is forbidden by default.
6
- # http://stackoverflow.com/questions/431617/overriding-id-on-create-in-activerecord
7
- module AllowSettingIdOnCreate
8
-
9
- module RemoveIdFromProtectedAttributes
10
- def attributes_protected_by_default
11
- super - ['id']
12
- end
13
- end
14
-
15
- def self.included(base)
16
- if ActiveRecord::VERSION::MAJOR < 3 # Rails 2 has this as an instance method
17
- base.send(:include, RemoveIdFromProtectedAttributes)
18
- else # Rails 3 has this as a class method
19
- base.send(:extend, RemoveIdFromProtectedAttributes)
20
- end
21
- end
22
-
23
- end
24
-
25
-
26
-
27
-
28
- class Forum < ActiveRecord::Base
29
- include AllowSettingIdOnCreate
30
-
31
- has_many :topics
32
- has_many :posts, :through => :topics
33
- EdgeRider::Util.define_association self, :has_many, :active_topics,
34
- :conditions => { :trashed => false }, :class_name => 'Topic'
35
-
36
- has_defaults :trashed => false
37
-
38
- end
39
-
40
-
41
- class Post < ActiveRecord::Base
42
- include AllowSettingIdOnCreate
43
-
44
- belongs_to :topic
45
- belongs_to :author, :class_name => 'User'
46
-
47
- has_defaults :trashed => false
48
-
49
- EdgeRider::Util.define_scope self, :these, lambda { |array| { :conditions => { :id => array } } }
50
-
51
- end
52
-
53
-
54
- class Profile < ActiveRecord::Base
55
- include AllowSettingIdOnCreate
56
-
57
- belongs_to :user
58
-
59
- has_defaults :trashed => false
60
-
61
- end
62
-
63
-
64
- class Topic < ActiveRecord::Base
65
- include AllowSettingIdOnCreate
66
-
67
- belongs_to :forum
68
- EdgeRider::Util.define_association self, :belongs_to, :active_forum,
69
- :conditions => { :trashed => false }, :class_name => 'Forum'
70
-
71
- has_many :posts
72
- belongs_to :author, :class_name => 'User'
73
- has_many :post_authors, :through => :posts
74
-
75
- has_defaults :trashed => false
76
-
77
- end
78
-
79
-
80
- class User < ActiveRecord::Base
81
- include AllowSettingIdOnCreate
82
-
83
- has_many :posts
84
- has_many :topics
85
-
86
- has_one :profile
87
- EdgeRider::Util.define_association self, :has_one, :active_profile,
88
- :conditions => { :trashed => false }, :class_name => 'Profile'
89
-
90
- has_defaults :trashed => false
91
-
92
- end