edge_rider 1.0.0 → 2.1.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.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +104 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +29 -5
- data/Gemfile +1 -0
- data/Gemfile.4.2.mysql2 +4 -2
- data/Gemfile.4.2.mysql2.lock +35 -21
- data/Gemfile.4.2.pg +3 -1
- data/Gemfile.4.2.pg.lock +33 -19
- data/Gemfile.5.2.mysql2 +4 -2
- data/Gemfile.5.2.mysql2.lock +21 -7
- data/Gemfile.5.2.pg +3 -1
- data/Gemfile.5.2.pg.lock +19 -5
- data/{Gemfile.6.0.pg → Gemfile.6.1.pg} +4 -2
- data/Gemfile.6.1.pg.lock +82 -0
- data/{Gemfile.3.2.mysql2 → Gemfile.7.0.pg} +7 -6
- data/Gemfile.7.0.pg.lock +78 -0
- data/Gemfile.lock +1 -0
- data/README.md +86 -60
- data/edge_rider.gemspec +25 -15
- data/lib/edge_rider/preload_associations.rb +15 -13
- data/lib/edge_rider/traverse_association.rb +7 -3
- data/lib/edge_rider/util.rb +1 -1
- data/lib/edge_rider/version.rb +1 -1
- metadata +19 -28
- data/.travis.yml +0 -63
- data/Gemfile.3.2.mysql2.lock +0 -62
- data/Gemfile.6.0.pg.lock +0 -64
- data/spec/edge_rider/collect_column_spec.rb +0 -85
- data/spec/edge_rider/collect_ids_spec.rb +0 -108
- data/spec/edge_rider/origin_class_spec.rb +0 -32
- data/spec/edge_rider/preload_associations_spec.rb +0 -15
- data/spec/edge_rider/scoped_spec.rb +0 -53
- data/spec/edge_rider/to_id_query_spec.rb +0 -29
- data/spec/edge_rider/traverse_association_spec.rb +0 -128
- data/spec/edge_rider/util_spec.rb +0 -5
- data/spec/spec_helper.rb +0 -12
- data/spec/support/database.rb +0 -34
- data/spec/support/database.sample.yml +0 -10
- data/spec/support/database.travis.yml +0 -9
- data/spec/support/models.rb +0 -88
data/Gemfile.3.2.mysql2.lock
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
edge_rider (0.3.3)
|
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.17.3
|
data/Gemfile.6.0.pg.lock
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
edge_rider (0.3.3)
|
5
|
-
activerecord
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
activemodel (6.0.0.rc1)
|
11
|
-
activesupport (= 6.0.0.rc1)
|
12
|
-
activerecord (6.0.0.rc1)
|
13
|
-
activemodel (= 6.0.0.rc1)
|
14
|
-
activesupport (= 6.0.0.rc1)
|
15
|
-
activesupport (6.0.0.rc1)
|
16
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
-
i18n (>= 0.7, < 2)
|
18
|
-
minitest (~> 5.1)
|
19
|
-
tzinfo (~> 1.1)
|
20
|
-
zeitwerk (~> 2.1, >= 2.1.4)
|
21
|
-
concurrent-ruby (1.1.5)
|
22
|
-
database_cleaner (1.7.0)
|
23
|
-
diff-lcs (1.3)
|
24
|
-
gemika (0.3.4)
|
25
|
-
has_defaults (0.4.4)
|
26
|
-
activerecord
|
27
|
-
i18n (1.6.0)
|
28
|
-
concurrent-ruby (~> 1.0)
|
29
|
-
minitest (5.11.3)
|
30
|
-
pg (1.1.4)
|
31
|
-
rake (12.3.2)
|
32
|
-
rspec (3.8.0)
|
33
|
-
rspec-core (~> 3.8.0)
|
34
|
-
rspec-expectations (~> 3.8.0)
|
35
|
-
rspec-mocks (~> 3.8.0)
|
36
|
-
rspec-core (3.8.0)
|
37
|
-
rspec-support (~> 3.8.0)
|
38
|
-
rspec-expectations (3.8.2)
|
39
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
-
rspec-support (~> 3.8.0)
|
41
|
-
rspec-mocks (3.8.0)
|
42
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
-
rspec-support (~> 3.8.0)
|
44
|
-
rspec-support (3.8.0)
|
45
|
-
thread_safe (0.3.6)
|
46
|
-
tzinfo (1.2.5)
|
47
|
-
thread_safe (~> 0.1)
|
48
|
-
zeitwerk (2.1.6)
|
49
|
-
|
50
|
-
PLATFORMS
|
51
|
-
ruby
|
52
|
-
|
53
|
-
DEPENDENCIES
|
54
|
-
activerecord (~> 6.0.0.rc1)
|
55
|
-
database_cleaner
|
56
|
-
edge_rider!
|
57
|
-
gemika
|
58
|
-
has_defaults
|
59
|
-
pg
|
60
|
-
rake
|
61
|
-
rspec
|
62
|
-
|
63
|
-
BUNDLED WITH
|
64
|
-
1.17.3
|
@@ -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,53 +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
|
-
EdgeRider::Util.scope?( Forum.scoped ).should == true
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns a scope when called with an empty hash' do
|
11
|
-
EdgeRider::Util.scope?( Forum.scoped({}) ).should == true
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'respects conditions' do
|
15
|
-
trashed = Forum.create! trashed: true
|
16
|
-
active = Forum.create! trashed: false
|
17
|
-
|
18
|
-
Forum.scoped(conditions: { trashed: true }).to_a.should == [ trashed ]
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'respects order' do
|
22
|
-
c = Forum.create! name: 'Chemikalien'
|
23
|
-
a = Forum.create! name: 'Allegorie'
|
24
|
-
b = Forum.create! name: 'Botanisch'
|
25
|
-
|
26
|
-
Forum.scoped(order: 'name ASC').to_a.should == [ a, b, c ]
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'can be used to add conditions to an existing scope chain' do
|
30
|
-
bulldog = Forum.create! name: 'bulldog', trashed: false
|
31
|
-
trashed = Forum.create! name: 'maneuver', trashed: true
|
32
|
-
trashed_bulldog = Forum.create! name: 'bulldog', trashed: true
|
33
|
-
|
34
|
-
Forum.
|
35
|
-
scoped(conditions: { trashed: true }).
|
36
|
-
scoped(conditions: { name: 'bulldog' }).to_a.should == [ trashed_bulldog ]
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'can be used to add conditions to a has_many association' do
|
40
|
-
forum = Forum.create!
|
41
|
-
thema = Topic.create! subject: 'Thema', trashed: false, forum: forum
|
42
|
-
other_topic = Topic.create! subject: 'Other', trashed: false, forum: forum
|
43
|
-
trashed_thema = Topic.create! subject: 'Thema', trashed: true, forum: forum
|
44
|
-
|
45
|
-
has_many_scope = forum.active_topics
|
46
|
-
# In Rails 3, #scoped on associations does not take parameters but turns
|
47
|
-
# an association into a real scope.
|
48
|
-
has_many_scope = has_many_scope.scoped if ActiveRecord::VERSION::MAJOR == 3
|
49
|
-
has_many_scope.scoped(conditions: { subject: 'Thema' }).to_a.should =~ [ thema ]
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
@@ -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,128 +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 multiple belongs_to associations in different model classes' do
|
30
|
-
forum_1 = Forum.create!
|
31
|
-
forum_2 = Forum.create!
|
32
|
-
forum_3 = Forum.create!
|
33
|
-
topic_1 = Topic.create!(forum: forum_1)
|
34
|
-
topic_2 = Topic.create!(forum: forum_2)
|
35
|
-
topic_3 = Topic.create!(forum: forum_3)
|
36
|
-
post_1 = Post.create!(topic: topic_1)
|
37
|
-
post_2 = Post.create!(topic: topic_2)
|
38
|
-
post_3 = Post.create!(topic: topic_3)
|
39
|
-
scope = Post.scoped(conditions: { id: [post_1.id, post_3.id] })
|
40
|
-
traversed_scope = scope.traverse_association(:topic, :forum)
|
41
|
-
EdgeRider::Util.scope?(traversed_scope).should == true
|
42
|
-
traversed_scope.to_a.should =~ [forum_1, forum_3]
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should traverse one or more has_many associations' do
|
46
|
-
forum_1 = Forum.create!
|
47
|
-
forum_2 = Forum.create!
|
48
|
-
forum_3 = Forum.create!
|
49
|
-
topic_1 = Topic.create!(forum: forum_1)
|
50
|
-
topic_2 = Topic.create!(forum: forum_2)
|
51
|
-
topic_3 = Topic.create!(forum: forum_3)
|
52
|
-
post_1 = Post.create!(topic: topic_1)
|
53
|
-
post_2 = Post.create!(topic: topic_2)
|
54
|
-
post_3a = Post.create!(topic: topic_3)
|
55
|
-
post_3b = Post.create!(topic: topic_3)
|
56
|
-
scope = Forum.scoped(conditions: { id: [forum_1.id, forum_3.id] })
|
57
|
-
traversed_scope = scope.traverse_association(:topics, :posts)
|
58
|
-
EdgeRider::Util.scope?(traversed_scope).should == true
|
59
|
-
traversed_scope.to_a.should =~ [post_1, post_3a, post_3b]
|
60
|
-
end
|
61
|
-
|
62
|
-
# in Rails 4, conditions on a scope are expressed as a lambda parameter
|
63
|
-
it 'should raise an error when traversing a has_many association with conditions, until this is implemented' do
|
64
|
-
forum = Forum.create!
|
65
|
-
topic = Topic.create(forum: forum, trashed: true)
|
66
|
-
|
67
|
-
scope = Forum.scoped(conditions: { id: forum.id })
|
68
|
-
expect { scope.traverse_association(:active_topics) }.to raise_error(NotImplementedError)
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'should traverse a has_many :through association' do
|
72
|
-
forum_1 = Forum.create!
|
73
|
-
forum_2 = Forum.create!
|
74
|
-
forum_3 = Forum.create!
|
75
|
-
topic_1 = Topic.create!(forum: forum_1)
|
76
|
-
topic_2 = Topic.create!(forum: forum_2)
|
77
|
-
topic_3 = Topic.create!(forum: forum_3)
|
78
|
-
post_1 = Post.create!(topic: topic_1)
|
79
|
-
post_2 = Post.create!(topic: topic_2)
|
80
|
-
post_3a = Post.create!(topic: topic_3)
|
81
|
-
post_3b = Post.create!(topic: topic_3)
|
82
|
-
scope = Forum.scoped(conditions: { id: [forum_1.id, forum_3.id] })
|
83
|
-
traversed_scope = scope.traverse_association(:posts)
|
84
|
-
EdgeRider::Util.scope?(traversed_scope).should == true
|
85
|
-
traversed_scope.to_a.should =~ [post_1, post_3a, post_3b]
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'should traverse a has_one association' do
|
89
|
-
user_1 = User.create!
|
90
|
-
user_2 = User.create!
|
91
|
-
user_3 = User.create!
|
92
|
-
profile_1 = Profile.create!(user: user_1)
|
93
|
-
profile_2 = Profile.create!(user: user_2)
|
94
|
-
profile_3 = Profile.create!(user: user_3)
|
95
|
-
scope = User.scoped(conditions: { id: [user_2.id, user_3.id] })
|
96
|
-
traversed_scope = scope.traverse_association(:profile)
|
97
|
-
EdgeRider::Util.scope?(traversed_scope).should == true
|
98
|
-
traversed_scope.to_a.should =~ [profile_2, profile_3]
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'should raise an error when traversing a has_many association with conditions, until this is implemented' do
|
102
|
-
user = User.create!
|
103
|
-
profile = Profile.create(user: user, trashed: true)
|
104
|
-
|
105
|
-
scope = User.scoped(conditions: { id: user.id })
|
106
|
-
expect { scope.traverse_association(:active_profile) }.to raise_error(NotImplementedError)
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'should traverse up and down the same edges' do
|
110
|
-
forum_1 = Forum.create!
|
111
|
-
forum_2 = Forum.create!
|
112
|
-
forum_3 = Forum.create!
|
113
|
-
topic_1 = Topic.create!(forum: forum_1)
|
114
|
-
topic_2 = Topic.create!(forum: forum_2)
|
115
|
-
topic_3 = Topic.create!(forum: forum_3)
|
116
|
-
post_1 = Post.create!(topic: topic_1)
|
117
|
-
post_2 = Post.create!(topic: topic_2)
|
118
|
-
post_3a = Post.create!(topic: topic_3)
|
119
|
-
post_3b = Post.create!(topic: topic_3)
|
120
|
-
scope = Post.scoped(conditions: { id: [post_3a.id] })
|
121
|
-
traversed_scope = scope.traverse_association(:topic, :forum, :topics, :posts)
|
122
|
-
EdgeRider::Util.scope?(traversed_scope).should == true
|
123
|
-
traversed_scope.to_a.should =~ [post_3a, post_3b]
|
124
|
-
end
|
125
|
-
|
126
|
-
end
|
127
|
-
|
128
|
-
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
|
data/spec/support/database.rb
DELETED
@@ -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 null: true
|
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
|