edge_rider 0.3.3 → 1.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.
- checksums.yaml +7 -0
- data/.travis.yml +28 -31
- data/CHANGELOG.md +18 -0
- data/{gemfiles/Gemfile.3.2.mysql2 → Gemfile.3.2.mysql2} +1 -1
- data/{gemfiles/Gemfile.3.2.mysql2.lock → Gemfile.3.2.mysql2.lock} +3 -3
- data/{gemfiles/Gemfile.4.2.mysql2 → Gemfile.4.2.mysql2} +1 -1
- data/{gemfiles/Gemfile.4.2.mysql2.lock → Gemfile.4.2.mysql2.lock} +3 -3
- data/{gemfiles/Gemfile.4.2.pg → Gemfile.4.2.pg} +1 -1
- data/{gemfiles/Gemfile.4.2.pg.lock → Gemfile.4.2.pg.lock} +3 -3
- data/{gemfiles/Gemfile.5.1.mysql2 → Gemfile.5.2.mysql2} +3 -2
- data/{gemfiles/Gemfile.5.1.mysql2.lock → Gemfile.5.2.mysql2.lock} +19 -17
- data/Gemfile.5.2.pg +16 -0
- data/{gemfiles/Gemfile.5.1.pg.lock → Gemfile.5.2.pg.lock} +19 -17
- data/{gemfiles/Gemfile.5.1.pg → Gemfile.6.0.pg} +2 -2
- data/Gemfile.6.0.pg.lock +64 -0
- data/README.md +21 -42
- data/Rakefile +1 -1
- data/lib/edge_rider.rb +0 -1
- data/lib/edge_rider/collect_column.rb +8 -15
- data/lib/edge_rider/origin_class.rb +2 -10
- data/lib/edge_rider/scoped.rb +1 -1
- data/lib/edge_rider/to_id_query.rb +1 -1
- data/lib/edge_rider/traverse_association.rb +2 -2
- data/lib/edge_rider/util.rb +8 -15
- data/lib/edge_rider/version.rb +1 -1
- data/spec/edge_rider/collect_column_spec.rb +21 -21
- data/spec/edge_rider/collect_ids_spec.rb +16 -16
- data/spec/edge_rider/origin_class_spec.rb +9 -9
- data/spec/edge_rider/preload_associations_spec.rb +3 -3
- data/spec/edge_rider/scoped_spec.rb +17 -19
- data/spec/edge_rider/to_id_query_spec.rb +12 -12
- data/spec/edge_rider/traverse_association_spec.rb +47 -53
- data/spec/support/database.rb +1 -1
- data/spec/support/models.rb +14 -18
- metadata +46 -69
- data/gemfiles/Gemfile.2.3.mysql2 +0 -16
- data/gemfiles/Gemfile.2.3.mysql2.lock +0 -37
- data/lib/edge_rider/to_sql.rb +0 -13
- data/spec/edge_rider/to_sql_spec.rb +0 -14
data/README.md
CHANGED
@@ -31,13 +31,13 @@ Say we have a `Post` model and each `Post` belongs to an author:
|
|
31
31
|
|
32
32
|
To turn a relation of posts into a relation of its authors:
|
33
33
|
|
34
|
-
posts = Post.where(:
|
34
|
+
posts = Post.where(archived: false)
|
35
35
|
authors = posts.traverse_association(:author)
|
36
36
|
|
37
37
|
You can traverse multiple associations in a single call.
|
38
38
|
E.g. to turn a relation of posts into a relation of all posts of their authors:
|
39
39
|
|
40
|
-
posts = Post.where(:
|
40
|
+
posts = Post.where(archived: false)
|
41
41
|
posts_by_same_authors = posts.traverse_association(:author, :posts)
|
42
42
|
|
43
43
|
*Implementation note:* The traversal is achieved internally by collecting all foreign keys in the current relation
|
@@ -56,10 +56,10 @@ its ID.
|
|
56
56
|
Edge Rider has a better way. Your relations gain a method `#collect_ids` that will
|
57
57
|
fetch all IDs in a single query without instantiating a single ActiveRecord object:
|
58
58
|
|
59
|
-
posts = Post.where(:
|
59
|
+
posts = Post.where(archived: false)
|
60
60
|
post_ids = posts.collect_ids
|
61
61
|
|
62
|
-
*Implementation note:*
|
62
|
+
*Implementation note:* `#collect_ids` delegates to [`#pluck`](https://apidock.com/rails/ActiveRecord/Calculations/pluck),
|
63
63
|
which can be used for the same purpose.
|
64
64
|
|
65
65
|
|
@@ -76,7 +76,7 @@ any kind of argument that can be turned into a list of IDs:
|
|
76
76
|
|
77
77
|
For this use case Edge Rider defines `#collect_ids` on many different types:
|
78
78
|
|
79
|
-
Post.where(:
|
79
|
+
Post.where(id: [1, 2]).collect_ids # => [1, 2]
|
80
80
|
[Post.find(1), Post.find(2)].collect_ids # => [1, 2]
|
81
81
|
Post.find(1).collect_ids # => [1]
|
82
82
|
[1, 2, 3].collect_ids # => [1, 2, 3]
|
@@ -89,7 +89,7 @@ You can now write `Post.by_author` from the example above without a single `if`
|
|
89
89
|
belongs_to :author
|
90
90
|
|
91
91
|
def self.for_author(author_or_authors)
|
92
|
-
where(:
|
92
|
+
where(author_id: author_or_authors.collect_ids)
|
93
93
|
end
|
94
94
|
|
95
95
|
end
|
@@ -106,42 +106,23 @@ its column value.
|
|
106
106
|
Edge Rider has a better way. Your relations gain a method `#collect_column` that will
|
107
107
|
fetch all column values in a single query without instantiating a single ActiveRecord object:
|
108
108
|
|
109
|
-
posts = Post.where(:
|
109
|
+
posts = Post.where(archived: false)
|
110
110
|
subjects = posts.collect_column(:subject)
|
111
111
|
|
112
|
-
*Implementation note:*
|
112
|
+
*Implementation note:* `#collect_column` delegates to [`#pluck`](https://apidock.com/rails/ActiveRecord/Calculations/pluck),
|
113
113
|
which can be used for the same effect.
|
114
114
|
|
115
115
|
#### Collect unique values in a relation's column
|
116
116
|
|
117
|
-
If you only care about *unique* values, use the
|
117
|
+
If you only care about *unique* values, use the `distinct: true` option:
|
118
118
|
|
119
|
-
posts = Post.where(:
|
120
|
-
distinct_subjects = posts.collect_column(:subject, :
|
119
|
+
posts = Post.where(archived: false)
|
120
|
+
distinct_subjects = posts.collect_column(:subject, distinct: true)
|
121
121
|
|
122
122
|
With this options duplicates are discarded by the database before making their way into Ruby.
|
123
123
|
|
124
|
-
*Implementation note:*
|
125
|
-
which can be used for the same effect.
|
126
|
-
|
127
|
-
|
128
|
-
### Retrieve the SQL a relation would produce
|
129
|
-
|
130
|
-
Sometimes it is useful to ask a relation which SQL query it would trigger,
|
131
|
-
if it was evaluated right now. For this, Edge Rider gives your relations a method
|
132
|
-
`#to_sql`:
|
133
|
-
|
134
|
-
# Rails 2 scope
|
135
|
-
Post.scoped(:conditions => { :id => [1, 2] }).to_sql
|
136
|
-
# => "SELECT `posts`.* FROM `posts` WHERE `posts.id` IN (1, 2)"
|
137
|
-
|
138
|
-
# Rails 3 relation
|
139
|
-
Post.where(:id => [1, 2]).to_sql
|
140
|
-
# => "SELECT `posts`.* FROM `posts` WHERE `posts.id` IN (1, 2)"
|
141
|
-
|
142
|
-
*Implementation note*: Rails 3+ implements `#to_sql`. Edge Rider backports this method to Rails 2 so you can use it
|
143
|
-
regardless of your Rails version.
|
144
|
-
|
124
|
+
*Implementation note:* The `:distinct` option is implemented with [`#uniq`](https://apidock.com/rails/ActiveRecord/QueryMethods/uniq)
|
125
|
+
or [`#distinct`](https://apidock.com/rails/ActiveRecord/QueryMethods/distinct) which can be used for the same effect.
|
145
126
|
|
146
127
|
### Simplify a complex relation for better chainability
|
147
128
|
|
@@ -155,7 +136,7 @@ mashes together strings that mostly happen to look like a MySQL query in the end
|
|
155
136
|
|
156
137
|
Edge Rider gives your relations a new method `#to_id_query`:
|
157
138
|
|
158
|
-
Site.joins(
|
139
|
+
Site.joins(user).where(:users: { name: 'Bruce' }).to_id_query
|
159
140
|
|
160
141
|
`#to_id_query` will immediately run an SQL query where it collects all the IDs that match your relation:
|
161
142
|
|
@@ -173,9 +154,9 @@ Sometimes you want to fetch associations for records that you already instantiat
|
|
173
154
|
Edge Rider gives your model classes a method `.preload_associations`. The method can be used to preload associations for loaded objects like this:
|
174
155
|
|
175
156
|
@user = User.find(params[:id])
|
176
|
-
User.preload_associations [@user], { :
|
157
|
+
User.preload_associations [@user], { threads: { posts: :author }, messages: :sender }
|
177
158
|
|
178
|
-
*Implementation note*: Rails
|
159
|
+
*Implementation note*: Rails 3.0 already has a method [`.preload_associations`](https://apidock.com/rails/ActiveRecord/AssociationPreload/ClassMethods/preload_associations)
|
179
160
|
which Edge Rider merely makes public. Edge Rider ports this method forward to Rails 3.1+.
|
180
161
|
|
181
162
|
|
@@ -188,7 +169,7 @@ This is useful e.g. to perform unscoped record look-up.
|
|
188
169
|
Post.recent.origin_class
|
189
170
|
# => Post
|
190
171
|
|
191
|
-
Note that `#origin_class` it roughly equivalent to the blockless form of [`unscoped`](
|
172
|
+
Note that `#origin_class` it roughly equivalent to the blockless form of [`unscoped`](https://apidock.com/rails/ActiveRecord/Scoping/Default/ClassMethods/unscoped) from Rails 3.2+,
|
192
173
|
but it works consistently across all Rails versions.
|
193
174
|
|
194
175
|
|
@@ -202,8 +183,8 @@ across all versions of Rails.
|
|
202
183
|
User.scoped # just calls User.all in Rails 4
|
203
184
|
User.active.scoped(conditions: { admin: true })
|
204
185
|
|
205
|
-
*Implementation note*: Rails
|
206
|
-
[`.scoped`](
|
186
|
+
*Implementation note*: Rails 3 already have a method
|
187
|
+
[`.scoped`](https://apidock.com/rails/ActiveRecord/Scoping/Named/ClassMethods/scoped) which Edge Rider does not touch. Rails 4 has removed this method and
|
207
188
|
splits its functionality into the query methods known from Rails 3 (`.where`,
|
208
189
|
`.order` etc.) and an `.all` method that just returns a scope.
|
209
190
|
|
@@ -227,10 +208,10 @@ Development
|
|
227
208
|
-----------
|
228
209
|
|
229
210
|
- There are tests in `spec`. We only accept PRs with tests.
|
230
|
-
- We currently develop using Ruby
|
211
|
+
- We currently develop using the Ruby version in `.ruby-version`. It is required to change the Ruby Version to cover all Rails version or just use Travis CI.
|
231
212
|
- Put your database credentials into `spec/support/database.yml`. There's a `database.sample.yml` you can use as a template.
|
232
213
|
- Create a database `edge_rider_test` in both MySQL and PostgreSQL.
|
233
|
-
- There are gem bundles in
|
214
|
+
- There are gem bundles in the project root for each combination of ActiveRecord version and database type that we support.
|
234
215
|
- You can bundle all test applications by saying `bundle exec rake matrix:install`
|
235
216
|
- You can run specs from the project root by saying `bundle exec rake matrix:spec`. This will run all gemfiles compatible with your current Ruby.
|
236
217
|
|
@@ -245,5 +226,3 @@ Credits
|
|
245
226
|
-------
|
246
227
|
|
247
228
|
Henning Koch from [makandra](http://makandra.com/)
|
248
|
-
|
249
|
-
|
data/Rakefile
CHANGED
data/lib/edge_rider.rb
CHANGED
@@ -4,23 +4,16 @@ module EdgeRider
|
|
4
4
|
def collect_column(column_name, find_options = {})
|
5
5
|
distinct = find_options.delete(:distinct)
|
6
6
|
qualified_column_name = EdgeRider::Util.qualify_column_name(self, column_name)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
7
|
+
|
8
|
+
scope = scoped({})
|
9
|
+
if distinct
|
10
|
+
if ActiveRecord::VERSION::MAJOR < 5
|
11
|
+
scope = scope.uniq
|
12
|
+
else
|
13
|
+
scope = scope.distinct
|
15
14
|
end
|
16
|
-
scope.pluck(qualified_column_name)
|
17
|
-
else # Rails 2
|
18
|
-
select = distinct ? "DISTINCT #{qualified_column_name}" : qualified_column_name
|
19
|
-
query = scoped(find_options.merge(:select => select)).to_sql
|
20
|
-
raw_values = connection.select_values(query)
|
21
|
-
column = columns_hash[column_name.to_s] or raise "Could not retrieve column information: #{column_name}"
|
22
|
-
raw_values.collect { |value| column.type_cast(value) }
|
23
15
|
end
|
16
|
+
scope.pluck(qualified_column_name)
|
24
17
|
end
|
25
18
|
|
26
19
|
ActiveRecord::Base.extend(self)
|
@@ -3,16 +3,8 @@ module EdgeRider
|
|
3
3
|
|
4
4
|
def origin_class
|
5
5
|
scope = scoped({})
|
6
|
-
|
7
|
-
|
8
|
-
while scope.respond_to?(:proxy_scope, true)
|
9
|
-
scope = scope.proxy_scope
|
10
|
-
end
|
11
|
-
else
|
12
|
-
# Rails 3
|
13
|
-
while scope.respond_to?(:klass, true)
|
14
|
-
scope = scope.klass
|
15
|
-
end
|
6
|
+
while scope.respond_to?(:klass, true)
|
7
|
+
scope = scope.klass
|
16
8
|
end
|
17
9
|
scope
|
18
10
|
end
|
data/lib/edge_rider/scoped.rb
CHANGED
@@ -18,8 +18,8 @@ module EdgeRider
|
|
18
18
|
raise NotImplementedError if reflection.options[:conditions] or (reflection.respond_to?(:scope) && reflection.scope)
|
19
19
|
|
20
20
|
if reflection.macro == :belongs_to # belongs_to
|
21
|
-
ids = scope.collect_column(foreign_key, :
|
22
|
-
scope = EdgeRider::Util.exclusive_query(reflection.klass, :
|
21
|
+
ids = scope.collect_column(foreign_key, distinct: true)
|
22
|
+
scope = EdgeRider::Util.exclusive_query(reflection.klass, id: ids)
|
23
23
|
elsif reflection.macro == :has_many || reflection.macro == :has_one
|
24
24
|
if reflection.through_reflection # has_many :through
|
25
25
|
scope = scope.traverse_association(reflection.through_reflection.name, reflection.source_reflection.name)
|
data/lib/edge_rider/util.rb
CHANGED
@@ -21,13 +21,7 @@ module EdgeRider
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def exclusive_query(model, conditions)
|
24
|
-
|
25
|
-
model.send(:with_exclusive_scope) do
|
26
|
-
model.scoped(:conditions => conditions)
|
27
|
-
end
|
28
|
-
else
|
29
|
-
model.unscoped.where(conditions)
|
30
|
-
end
|
24
|
+
model.unscoped.where(conditions)
|
31
25
|
end
|
32
26
|
|
33
27
|
def scope?(object)
|
@@ -35,13 +29,16 @@ module EdgeRider
|
|
35
29
|
end
|
36
30
|
|
37
31
|
def define_scope(klass, name, lambda)
|
38
|
-
if ActiveRecord::VERSION::MAJOR
|
39
|
-
|
40
|
-
klass.send scope_definition, name, lambda
|
32
|
+
if ActiveRecord::VERSION::MAJOR == 3
|
33
|
+
klass.send :scope, name, lambda
|
41
34
|
else
|
42
35
|
klass.send :scope, name, lambda { |*args|
|
43
36
|
options = lambda.call(*args)
|
44
|
-
|
37
|
+
if ActiveRecord::VERSION::MAJOR < 6
|
38
|
+
klass.scoped(options.slice :conditions)
|
39
|
+
else
|
40
|
+
scoped(options.slice :conditions)
|
41
|
+
end
|
45
42
|
}
|
46
43
|
end
|
47
44
|
end
|
@@ -63,10 +60,6 @@ module EdgeRider
|
|
63
60
|
ActiveRecord::VERSION::MAJOR
|
64
61
|
end
|
65
62
|
|
66
|
-
def activerecord2?
|
67
|
-
active_record_version < 3
|
68
|
-
end
|
69
|
-
|
70
63
|
def rspec_version
|
71
64
|
if defined?(Spec)
|
72
65
|
1
|
data/lib/edge_rider/version.rb
CHANGED
@@ -5,16 +5,16 @@ describe EdgeRider::CollectColumn do
|
|
5
5
|
describe '#collect_column' do
|
6
6
|
|
7
7
|
it 'should collect the given value from a scope' do
|
8
|
-
Forum.create!(:
|
9
|
-
Forum.create!(:
|
10
|
-
Forum.create!(:
|
11
|
-
scope = Forum.scoped(:
|
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
12
|
scope.collect_column(:name).should =~ ['Name 2', 'Name 3']
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should collect the given value from an ActiveRecord class' do
|
16
|
-
Forum.create!(:
|
17
|
-
Forum.create!(:
|
16
|
+
Forum.create!(id: 1, name: 'Name 1')
|
17
|
+
Forum.create!(id: 2, name: 'Name 2')
|
18
18
|
Forum.collect_column(:name).should =~ ['Name 1', 'Name 2']
|
19
19
|
end
|
20
20
|
|
@@ -24,23 +24,23 @@ describe EdgeRider::CollectColumn do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should not instantiate ActiveRecord objects when collecting values' do
|
27
|
-
Forum.create!(:
|
27
|
+
Forum.create!(name: 'Name')
|
28
28
|
Forum.should_not_receive(:new)
|
29
29
|
Forum.collect_column(:name).should == ['Name']
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'should qualify the column name to resolve any ambiguities' do
|
33
|
-
expect { Topic.scoped(:
|
33
|
+
expect { Topic.scoped(joins: :forum).collect_column(:id) }.to_not raise_error
|
34
34
|
end
|
35
35
|
|
36
36
|
context 'with :distinct option' do
|
37
37
|
|
38
38
|
it 'should return unique values' do
|
39
|
-
Forum.create!(:
|
40
|
-
Forum.create!(:
|
41
|
-
Forum.create!(:
|
42
|
-
scope = Forum.scoped(:
|
43
|
-
scope.collect_column(:name, :
|
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
44
|
end
|
45
45
|
|
46
46
|
end
|
@@ -49,8 +49,8 @@ describe EdgeRider::CollectColumn do
|
|
49
49
|
|
50
50
|
it 'should collect the given value' do
|
51
51
|
topic = Topic.create!
|
52
|
-
post = Post.create!(:
|
53
|
-
post = Post.create!(:
|
52
|
+
post = Post.create!(topic: topic, id: 1)
|
53
|
+
post = Post.create!(topic: topic, id: 2)
|
54
54
|
topic.reload
|
55
55
|
topic.posts.to_a
|
56
56
|
topic.posts.collect_column(:id).should =~ [1,2]
|
@@ -58,21 +58,21 @@ describe EdgeRider::CollectColumn do
|
|
58
58
|
|
59
59
|
it 'should return values when further restricted with an anonymous scope' do
|
60
60
|
topic = Topic.create!
|
61
|
-
post = Post.create!(:
|
62
|
-
post = Post.create!(:
|
61
|
+
post = Post.create!(topic: topic, id: 1)
|
62
|
+
post = Post.create!(topic: topic, id: 2)
|
63
63
|
topic.reload
|
64
64
|
topic.posts.to_a
|
65
65
|
if topic.posts.respond_to?(:where)
|
66
|
-
topic.posts.where(:
|
66
|
+
topic.posts.where(id: [1]).collect_ids.should =~ [1]
|
67
67
|
else
|
68
|
-
topic.posts.scoped(:
|
68
|
+
topic.posts.scoped(conditions: {id: [1]}).collect_column(:id).should =~ [1]
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'should return values when further restricted with a named scope' do
|
73
73
|
topic = Topic.create!
|
74
|
-
post = Post.create!(:
|
75
|
-
post = Post.create!(:
|
74
|
+
post = Post.create!(topic: topic, id: 1)
|
75
|
+
post = Post.create!(topic: topic, id: 2)
|
76
76
|
topic.reload
|
77
77
|
topic.posts.to_a
|
78
78
|
topic.posts.these([1]).collect_column(:id).should =~ [1]
|
@@ -7,8 +7,8 @@ describe EdgeRider::CollectIds do
|
|
7
7
|
context 'when called on an ActiveRecord class' do
|
8
8
|
|
9
9
|
it 'should return the ids for all records of that class' do
|
10
|
-
Forum.create!(:
|
11
|
-
Forum.create!(:
|
10
|
+
Forum.create!(id: 1)
|
11
|
+
Forum.create!(id: 2)
|
12
12
|
Forum.collect_ids.should =~ [1, 2]
|
13
13
|
end
|
14
14
|
|
@@ -17,10 +17,10 @@ describe EdgeRider::CollectIds do
|
|
17
17
|
context 'when called on a scope' do
|
18
18
|
|
19
19
|
it 'should return the ids for all records matching that scope' do
|
20
|
-
Forum.create!(:
|
21
|
-
Forum.create!(:
|
22
|
-
Forum.create!(:
|
23
|
-
scope = Forum.scoped(:
|
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
24
|
scope.collect_ids.should =~ [2, 3]
|
25
25
|
end
|
26
26
|
|
@@ -53,8 +53,8 @@ describe EdgeRider::CollectIds do
|
|
53
53
|
context 'when called on an array of ActiveRecords' do
|
54
54
|
|
55
55
|
it 'should return the ids collected from that list' do
|
56
|
-
forum_1 = Forum.create!(:
|
57
|
-
forum_2 = Forum.create!(:
|
56
|
+
forum_1 = Forum.create!(id: 1)
|
57
|
+
forum_2 = Forum.create!(id: 2)
|
58
58
|
[forum_1, forum_2].collect_ids.should =~ [1, 2]
|
59
59
|
end
|
60
60
|
|
@@ -72,8 +72,8 @@ describe EdgeRider::CollectIds do
|
|
72
72
|
|
73
73
|
it 'should return the ids' do
|
74
74
|
topic = Topic.create!
|
75
|
-
post = Post.create!(:
|
76
|
-
post = Post.create!(:
|
75
|
+
post = Post.create!(topic: topic, id: 1)
|
76
|
+
post = Post.create!(topic: topic, id: 2)
|
77
77
|
topic.reload
|
78
78
|
topic.posts.to_a
|
79
79
|
topic.posts.collect_ids.should =~ [1,2]
|
@@ -81,21 +81,21 @@ describe EdgeRider::CollectIds do
|
|
81
81
|
|
82
82
|
it 'should return ids when further restricted with an anonymous scope' do
|
83
83
|
topic = Topic.create!
|
84
|
-
post = Post.create!(:
|
85
|
-
post = Post.create!(:
|
84
|
+
post = Post.create!(topic: topic, id: 1)
|
85
|
+
post = Post.create!(topic: topic, id: 2)
|
86
86
|
topic.reload
|
87
87
|
topic.posts.to_a
|
88
88
|
if topic.posts.respond_to?(:where)
|
89
|
-
topic.posts.where(:
|
89
|
+
topic.posts.where(id: [1]).collect_ids.should =~ [1]
|
90
90
|
else
|
91
|
-
topic.posts.scoped(:
|
91
|
+
topic.posts.scoped(conditions: {id: [1]}).collect_ids.should =~ [1]
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
95
|
it 'should return ids when further restricted with a named scope' do
|
96
96
|
topic = Topic.create!
|
97
|
-
post = Post.create!(:
|
98
|
-
post = Post.create!(:
|
97
|
+
post = Post.create!(topic: topic, id: 1)
|
98
|
+
post = Post.create!(topic: topic, id: 2)
|
99
99
|
topic.reload
|
100
100
|
topic.posts.to_a
|
101
101
|
topic.posts.these([1]).collect_ids.should =~ [1]
|