order_as_specified 1.3 → 1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +4 -247
- data/.travis.yml +10 -3
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -0
- data/README.md +13 -2
- data/lib/order_as_specified.rb +8 -5
- data/lib/order_as_specified/error.rb +2 -0
- data/lib/order_as_specified/version.rb +3 -1
- data/order_as_specified.gemspec +12 -11
- data/spec/config/test_setup_migration.rb +4 -3
- data/spec/order_as_specified_spec.rb +2 -0
- data/spec/postgresql_spec.rb +22 -10
- data/spec/shared/order_as_specified_examples.rb +11 -5
- data/spec/spec_helper.rb +10 -2
- data/spec/sqlite3_spec.rb +2 -0
- data/spec/support/application_record.rb +5 -0
- data/spec/support/association_test_class.rb +3 -1
- data/spec/support/test_class.rb +3 -1
- metadata +52 -52
- data/.overcommit.yml +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 810fb1d84c1606e6a005b15d822d6758a93caf1ae53b9df6a695ff8d2e024582
|
4
|
+
data.tar.gz: ce7d3be0ef5a951a65bb1e5ceae0aa07ec3e0957fc844a6ecd2d0ca02af9170d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e8e491197afaf309031af8d7eb7869d1acdd2884ef776e6440a137a5288601993164ddc31815a42703407d18d51f73c917577cc80dbde2c742f7b6b7e06ab10
|
7
|
+
data.tar.gz: d8437b518f99ae3a9d6f75069e927b1a677772957d6868c9d3a24f49dd956c3a66f62f31174ae5796447a0b6806b1c15294ad94591ddddf415ca0a6c24ba190e
|
data/.rubocop.yml
CHANGED
@@ -1,260 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Enabled: false
|
4
|
-
|
5
|
-
AccessorMethodName:
|
6
|
-
Enabled: false
|
7
|
-
|
8
|
-
Alias:
|
9
|
-
Enabled: false
|
1
|
+
require:
|
2
|
+
- rubocop/rspec/focused
|
10
3
|
|
11
4
|
AllCops:
|
12
|
-
|
13
|
-
|
14
|
-
AmbiguousOperator:
|
15
|
-
Enabled: false
|
16
|
-
|
17
|
-
AmbiguousRegexpLiteral:
|
18
|
-
Enabled: false
|
19
|
-
|
20
|
-
ArrayJoin:
|
21
|
-
Enabled: false
|
22
|
-
|
23
|
-
AsciiComments:
|
24
|
-
Enabled: false
|
25
|
-
|
26
|
-
AsciiIdentifiers:
|
27
|
-
Enabled: false
|
28
|
-
|
29
|
-
AssignmentInCondition:
|
30
|
-
Enabled: true
|
31
|
-
|
32
|
-
Attr:
|
33
|
-
Enabled: false
|
34
|
-
|
35
|
-
BlockNesting:
|
36
|
-
Enabled: false
|
37
|
-
|
38
|
-
BracesAroundHashParameters:
|
39
|
-
Enabled: false
|
40
|
-
|
41
|
-
CaseEquality:
|
42
|
-
Enabled: false
|
43
|
-
|
44
|
-
CharacterLiteral:
|
45
|
-
Enabled: false
|
46
|
-
|
47
|
-
ClassLength:
|
48
|
-
Enabled: false
|
49
|
-
|
50
|
-
ClassVars:
|
51
|
-
Enabled: false
|
52
|
-
|
53
|
-
CollectionMethods:
|
54
|
-
PreferredMethods:
|
55
|
-
find: detect
|
56
|
-
reduce: inject
|
57
|
-
collect: map
|
58
|
-
find_all: select
|
59
|
-
|
60
|
-
ColonMethodCall:
|
61
|
-
Enabled: false
|
62
|
-
|
63
|
-
CommentAnnotation:
|
64
|
-
Enabled: false
|
65
|
-
|
66
|
-
ConditionPosition:
|
67
|
-
Enabled: false
|
68
|
-
|
69
|
-
CyclomaticComplexity:
|
70
|
-
Enabled: false
|
71
|
-
|
72
|
-
Delegate:
|
73
|
-
Enabled: false
|
74
|
-
|
75
|
-
DeprecatedClassMethods:
|
76
|
-
Enabled: false
|
5
|
+
TargetRubyVersion: 2.3
|
77
6
|
|
78
|
-
|
79
|
-
Enabled: false
|
80
|
-
|
81
|
-
Documentation:
|
7
|
+
AbcSize:
|
82
8
|
Enabled: false
|
83
9
|
|
84
10
|
DotPosition:
|
85
11
|
EnforcedStyle: trailing
|
86
12
|
|
87
|
-
DoubleNegation:
|
88
|
-
Enabled: false
|
89
|
-
|
90
|
-
ElseLayout:
|
91
|
-
Enabled: false
|
92
|
-
|
93
|
-
EmptyLiteral:
|
94
|
-
Enabled: false
|
95
|
-
|
96
|
-
Encoding:
|
97
|
-
Enabled: false
|
98
|
-
|
99
|
-
EvenOdd:
|
100
|
-
Enabled: false
|
101
|
-
|
102
|
-
FileName:
|
103
|
-
Enabled: false
|
104
|
-
|
105
|
-
FlipFlop:
|
106
|
-
Enabled: false
|
107
|
-
|
108
|
-
FormatString:
|
109
|
-
Enabled: false
|
110
|
-
|
111
|
-
GlobalVars:
|
112
|
-
Enabled: false
|
113
|
-
|
114
|
-
GuardClause:
|
115
|
-
Enabled: false
|
116
|
-
|
117
|
-
HandleExceptions:
|
118
|
-
Enabled: false
|
119
|
-
|
120
|
-
IfUnlessModifier:
|
121
|
-
Enabled: false
|
122
|
-
|
123
|
-
IfWithSemicolon:
|
124
|
-
Enabled: false
|
125
|
-
|
126
|
-
InvalidCharacterLiteral:
|
127
|
-
Enabled: false
|
128
|
-
|
129
|
-
Lambda:
|
130
|
-
Enabled: false
|
131
|
-
|
132
|
-
LambdaCall:
|
133
|
-
Enabled: false
|
134
|
-
|
135
|
-
LineEndConcatenation:
|
136
|
-
Enabled: false
|
137
|
-
|
138
|
-
LineLength:
|
139
|
-
Max: 80
|
140
|
-
|
141
|
-
LiteralInCondition:
|
142
|
-
Enabled: false
|
143
|
-
|
144
|
-
LiteralInInterpolation:
|
145
|
-
Enabled: false
|
146
|
-
|
147
|
-
Loop:
|
148
|
-
Enabled: false
|
149
|
-
|
150
13
|
MethodLength:
|
151
14
|
Enabled: false
|
152
15
|
|
153
|
-
ModuleFunction:
|
154
|
-
Enabled: false
|
155
|
-
|
156
|
-
NegatedIf:
|
157
|
-
Enabled: false
|
158
|
-
|
159
|
-
NegatedWhile:
|
160
|
-
Enabled: false
|
161
|
-
|
162
|
-
Next:
|
163
|
-
Enabled: false
|
164
|
-
|
165
|
-
NilComparison:
|
166
|
-
Enabled: false
|
167
|
-
|
168
|
-
Not:
|
169
|
-
Enabled: false
|
170
|
-
|
171
|
-
NumericLiterals:
|
172
|
-
Enabled: false
|
173
|
-
|
174
|
-
OneLineConditional:
|
175
|
-
Enabled: false
|
176
|
-
|
177
|
-
OpMethod:
|
178
|
-
Enabled: false
|
179
|
-
|
180
|
-
ParameterLists:
|
181
|
-
Enabled: false
|
182
|
-
|
183
|
-
ParenthesesAsGroupedExpression:
|
184
|
-
Enabled: false
|
185
|
-
|
186
|
-
PercentLiteralDelimiters:
|
187
|
-
PreferredDelimiters:
|
188
|
-
'%': '{}'
|
189
|
-
|
190
|
-
PerceivedComplexity:
|
191
|
-
Enabled: false
|
192
|
-
|
193
|
-
PerlBackrefs:
|
194
|
-
Enabled: false
|
195
|
-
|
196
|
-
PredicateName:
|
197
|
-
Enabled: false
|
198
|
-
|
199
|
-
Proc:
|
200
|
-
Enabled: false
|
201
|
-
|
202
|
-
RaiseArgs:
|
203
|
-
Enabled: false
|
204
|
-
|
205
|
-
RedundantReturn:
|
206
|
-
AllowMultipleReturnValues: true
|
207
|
-
|
208
|
-
RegexpLiteral:
|
209
|
-
Enabled: false
|
210
|
-
|
211
|
-
RequireParentheses:
|
212
|
-
Enabled: false
|
213
|
-
|
214
|
-
SelfAssignment:
|
215
|
-
Enabled: false
|
216
|
-
|
217
|
-
SignalException:
|
218
|
-
EnforcedStyle: only_raise
|
219
|
-
|
220
|
-
SingleLineBlockParams:
|
221
|
-
Enabled: false
|
222
|
-
|
223
|
-
SingleLineMethods:
|
224
|
-
Enabled: false
|
225
|
-
|
226
|
-
SpecialGlobalVars:
|
227
|
-
Enabled: false
|
228
|
-
|
229
16
|
StringLiterals:
|
230
17
|
EnforcedStyle: double_quotes
|
231
|
-
|
232
|
-
Style/MultilineBlockChain:
|
233
|
-
Enabled: false
|
234
|
-
|
235
|
-
VariableInterpolation:
|
236
|
-
Enabled: false
|
237
|
-
|
238
|
-
TrailingComma:
|
239
|
-
Enabled: false
|
240
|
-
|
241
|
-
TrivialAccessors:
|
242
|
-
Enabled: false
|
243
|
-
|
244
|
-
UnderscorePrefixedVariableName:
|
245
|
-
Enabled: false
|
246
|
-
|
247
|
-
VariableInterpolation:
|
248
|
-
Enabled: false
|
249
|
-
|
250
|
-
Void:
|
251
|
-
Enabled: false
|
252
|
-
|
253
|
-
WhenThen:
|
254
|
-
Enabled: false
|
255
|
-
|
256
|
-
WhileUntilModifier:
|
257
|
-
Enabled: false
|
258
|
-
|
259
|
-
WordArray:
|
260
|
-
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,19 +1,26 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
3
|
- 2.2.5
|
4
|
-
- 2.
|
4
|
+
- 2.5.1
|
5
5
|
before_script:
|
6
6
|
- psql -c 'create database order_as_specified_test;' -U postgres
|
7
|
-
|
7
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
8
|
+
- chmod +x ./cc-test-reporter
|
9
|
+
- ./cc-test-reporter before-build
|
10
|
+
script:
|
11
|
+
- bundle exec rspec
|
12
|
+
- bundle exec rubocop
|
13
|
+
after_script:
|
14
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
8
15
|
addons:
|
9
16
|
postgresql: "9.3"
|
10
17
|
code_climate:
|
11
18
|
repo_token: 781c439d68cbb928316deaec1c7136f98423e1db87238f99cbc95183de94df9e
|
12
19
|
env:
|
13
20
|
matrix:
|
14
|
-
- AR_VERSION="~> 4.2.0"
|
15
21
|
- AR_VERSION="~> 5.0.0"
|
16
22
|
- AR_VERSION="~> 5.1.0"
|
23
|
+
- AR_VERSION="~> 5.2.0"
|
17
24
|
notifications:
|
18
25
|
email: false
|
19
26
|
hipchat:
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# 1.4
|
2
|
+
|
3
|
+
This release removes deprecation warnings for ActiveRecord 5.2 users, and drops
|
4
|
+
support for ActiveRecord 4.x. Many thanks to
|
5
|
+
[George Protacio-Karaszi](https://github.com/GeorgeKaraszi) for pointing out
|
6
|
+
this issue!
|
7
|
+
|
1
8
|
# 1.3
|
2
9
|
|
3
10
|
This release adds support for ActiveRecord 5.1. Many thanks to
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -156,6 +156,18 @@ databases do not have good or consistent support for ordering with `NULL` values
|
|
156
156
|
in an arbitrary order, so we don't permit this behavior instead of allowing an
|
157
157
|
unexpected result.
|
158
158
|
|
159
|
+
## Limitations
|
160
|
+
|
161
|
+
Databases may have limitations on the underlying number of fields you can have
|
162
|
+
in an `ORDER BY` clause. For example, in PostgreSQL if you pass in more than
|
163
|
+
1664 list elements you'll [receive this error](https://github.com/panorama-ed/order_as_specified/issues/34):
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
PG::ProgramLimitExceeded: ERROR: target lists can have at most 1664 entries
|
167
|
+
```
|
168
|
+
|
169
|
+
That's a database limitation that this gem cannot avoid, unfortunately.
|
170
|
+
|
159
171
|
## Documentation
|
160
172
|
|
161
173
|
We have documentation on [RubyDoc](http://www.rubydoc.info/github/panorama-ed/order_as_specified/master).
|
@@ -169,8 +181,7 @@ We have documentation on [RubyDoc](http://www.rubydoc.info/github/panorama-ed/or
|
|
169
181
|
5. Create a new Pull Request
|
170
182
|
|
171
183
|
**Make sure your changes have appropriate tests (`bundle exec rspec`)
|
172
|
-
and conform to the Rubocop style specified.**
|
173
|
-
[overcommit](https://github.com/causes/overcommit) to enforce good code.
|
184
|
+
and conform to the Rubocop style specified.**
|
174
185
|
|
175
186
|
## License
|
176
187
|
|
data/lib/order_as_specified.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "order_as_specified/version"
|
2
4
|
require "order_as_specified/error"
|
3
5
|
|
@@ -5,7 +7,6 @@ require "order_as_specified/error"
|
|
5
7
|
# the database in an arbitrary order, without having to store anything extra
|
6
8
|
# in the database. Simply `extend` it into your class and then you can use the
|
7
9
|
# `order_as_specified` class method.
|
8
|
-
|
9
10
|
module OrderAsSpecified
|
10
11
|
# @param hash [Hash] the ActiveRecord arguments hash
|
11
12
|
# @return [ActiveRecord::Relation] the objects, ordered as specified
|
@@ -27,10 +28,12 @@ module OrderAsSpecified
|
|
27
28
|
"#{table}.#{attribute}=#{db_connection.quote(value)}"
|
28
29
|
end
|
29
30
|
|
30
|
-
scope = order(conditions.map { |cond| "#{cond} DESC" }.join(", "))
|
31
|
+
scope = order(Arel.sql(conditions.map { |cond| "#{cond} DESC" }.join(", ")))
|
31
32
|
|
32
33
|
if distinct_on
|
33
|
-
scope = scope.select(
|
34
|
+
scope = scope.select(
|
35
|
+
Arel.sql("DISTINCT ON (#{conditions.join(', ')}) #{table}.*")
|
36
|
+
)
|
34
37
|
end
|
35
38
|
|
36
39
|
scope
|
@@ -44,13 +47,13 @@ module OrderAsSpecified
|
|
44
47
|
# @param table [String/Symbol] the name of the table, default: the class table
|
45
48
|
# @param hash [Hash] the ActiveRecord-style arguments, such as:
|
46
49
|
# { other_objects: { id: [1, 5, 3] } }
|
47
|
-
def extract_params(table = table_name
|
50
|
+
def extract_params(hash, table = table_name)
|
48
51
|
raise "Could not parse params" unless hash.size == 1
|
49
52
|
|
50
53
|
key, val = hash.first
|
51
54
|
|
52
55
|
if val.is_a? Hash
|
53
|
-
extract_params(key,
|
56
|
+
extract_params(hash[key], key)
|
54
57
|
else
|
55
58
|
{
|
56
59
|
table: table,
|
data/order_as_specified.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require "order_as_specified/version"
|
5
6
|
|
@@ -19,14 +20,14 @@ Gem::Specification.new do |spec|
|
|
19
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
21
|
spec.require_paths = ["lib"]
|
21
22
|
|
22
|
-
spec.add_dependency "activerecord", ">=
|
23
|
+
spec.add_dependency "activerecord", ">= 5.0.0"
|
23
24
|
|
24
|
-
spec.add_development_dependency "bundler"
|
25
|
-
spec.add_development_dependency "
|
26
|
-
spec.add_development_dependency "
|
27
|
-
spec.add_development_dependency "
|
28
|
-
spec.add_development_dependency "
|
29
|
-
spec.add_development_dependency "rspec-
|
30
|
-
spec.add_development_dependency "
|
31
|
-
spec.add_development_dependency "sqlite3"
|
25
|
+
spec.add_development_dependency "bundler"
|
26
|
+
spec.add_development_dependency "pg"
|
27
|
+
spec.add_development_dependency "rspec"
|
28
|
+
spec.add_development_dependency "rspec-rails"
|
29
|
+
spec.add_development_dependency "rubocop"
|
30
|
+
spec.add_development_dependency "rubocop-rspec-focused"
|
31
|
+
spec.add_development_dependency "simplecov"
|
32
|
+
spec.add_development_dependency "sqlite3"
|
32
33
|
end
|
@@ -1,10 +1,11 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
VersionedMigration = ActiveRecord::Migration[ActiveRecord::Migration.current_version] # rubocop:disable Metrics/LineLength
|
2
4
|
|
3
5
|
class TestSetupMigration < VersionedMigration
|
4
6
|
def up
|
5
7
|
db_connection = ActiveRecord::Base.connection
|
6
|
-
return if db_connection.try(:
|
7
|
-
db_connection.try(:data_source_exists?,:test_classes) # AR > 5.0
|
8
|
+
return if db_connection.try(:data_source_exists?, :test_classes)
|
8
9
|
|
9
10
|
create_table :test_classes do |t|
|
10
11
|
t.string :field
|
data/spec/postgresql_spec.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
require "shared/order_as_specified_examples"
|
3
5
|
require "config/test_setup_migration"
|
4
6
|
|
7
|
+
# rubocop:disable Metrics/BlockLength
|
5
8
|
RSpec.describe "PostgreSQL" do
|
6
9
|
before :all do
|
7
10
|
ActiveRecord::Base.establish_connection(:postgresql_test)
|
@@ -21,8 +24,8 @@ RSpec.describe "PostgreSQL" do
|
|
21
24
|
end
|
22
25
|
|
23
26
|
let(:shuffled_objects) do
|
24
|
-
fields = 3
|
25
|
-
5
|
27
|
+
fields = Array.new(3) { |i| "Field #{i}" } * 2
|
28
|
+
Array.new(5) { |i| TestClass.create(field: fields[i]) }.shuffle
|
26
29
|
end
|
27
30
|
|
28
31
|
it "returns distinct objects" do
|
@@ -33,13 +36,16 @@ RSpec.describe "PostgreSQL" do
|
|
33
36
|
before(:each) { TestClass.create(field: "foo") }
|
34
37
|
|
35
38
|
it "sanitizes column values" do
|
36
|
-
# Attempt to inject code to add a 'hi' field to each record. If the SQL
|
37
|
-
# are properly sanitized, the code will be ignored and the
|
38
|
-
# instances will not respond to #hi. If not, the code
|
39
|
-
# each of the returned model instances will have a #hi
|
40
|
-
# new field.
|
39
|
+
# Attempt to inject code to add a 'hi' field to each record. If the SQL
|
40
|
+
# inputs are properly sanitized, the code will be ignored and the
|
41
|
+
# returned model instances will not respond to #hi. If not, the code
|
42
|
+
# will execute and each of the returned model instances will have a #hi
|
43
|
+
# method to access the new field.
|
41
44
|
bad_value = "foo') field, 'hi'::varchar AS hi FROM test_classes --"
|
42
|
-
record = TestClass.order_as_specified(
|
45
|
+
record = TestClass.order_as_specified(
|
46
|
+
distinct_on: true,
|
47
|
+
field: [bad_value]
|
48
|
+
).to_a.first
|
43
49
|
expect(record).to_not respond_to(:hi)
|
44
50
|
end
|
45
51
|
|
@@ -48,11 +54,17 @@ RSpec.describe "PostgreSQL" do
|
|
48
54
|
quoted_table = AssociationTestClass.connection.quote_table_name(table)
|
49
55
|
|
50
56
|
column = "id"
|
51
|
-
quoted_column = AssociationTestClass.
|
57
|
+
quoted_column = AssociationTestClass.
|
58
|
+
connection.
|
59
|
+
quote_column_name(column)
|
52
60
|
|
53
|
-
sql = TestClass.order_as_specified(
|
61
|
+
sql = TestClass.order_as_specified(
|
62
|
+
distinct_on: true,
|
63
|
+
table => { column => ["foo"] }
|
64
|
+
).to_sql
|
54
65
|
expect(sql).to include("DISTINCT ON (#{quoted_table}.#{quoted_column}")
|
55
66
|
end
|
56
67
|
end
|
57
68
|
end
|
58
69
|
end
|
70
|
+
# rubocop:enable Metrics/BlockLength
|
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "support/application_record"
|
1
4
|
require "support/test_class"
|
2
5
|
require "support/association_test_class"
|
3
6
|
|
7
|
+
# rubocop:disable Metrics/BlockLength
|
4
8
|
RSpec.shared_examples ".order_as_specified" do
|
5
9
|
# Clean up after each test. This is a lot lighter for these few tests than
|
6
10
|
# trying to wrangle with RSpec-Rails to get transactional tests to work.
|
@@ -10,7 +14,7 @@ RSpec.shared_examples ".order_as_specified" do
|
|
10
14
|
end
|
11
15
|
|
12
16
|
let(:shuffled_objects) do
|
13
|
-
5
|
17
|
+
Array.new(5) { |i| TestClass.create(field: "Field #{i}") }.shuffle
|
14
18
|
end
|
15
19
|
let(:shuffled_object_fields) { shuffled_objects.map(&:field) }
|
16
20
|
let(:shuffled_object_ids) { shuffled_objects.map(&:id) }
|
@@ -50,7 +54,7 @@ RSpec.shared_examples ".order_as_specified" do
|
|
50
54
|
|
51
55
|
context "when the order includes nil" do
|
52
56
|
let(:shuffled_objects) do
|
53
|
-
5
|
57
|
+
Array.new(5) do |i|
|
54
58
|
TestClass.create(field: (i == 0 ? nil : "Field #{i}"))
|
55
59
|
end.shuffle
|
56
60
|
end
|
@@ -102,15 +106,16 @@ RSpec.shared_examples ".order_as_specified" do
|
|
102
106
|
end
|
103
107
|
|
104
108
|
it "sanitizes column values" do
|
105
|
-
# Verify that the result set includes two records when using good column
|
109
|
+
# Verify that the result set includes two records when using good column
|
110
|
+
# value.
|
106
111
|
good_value = "foo"
|
107
112
|
records = TestClass.order_as_specified(field: [good_value]).to_a
|
108
113
|
expect(records.count).to eq(2)
|
109
114
|
|
110
115
|
# Attempt to inject a LIMIT clause into the query. If the SQL inputs are
|
111
116
|
# properly sanitized, it will be ignored and the returned result set will
|
112
|
-
# include two records. If not, the LIMIT clause will execute and the
|
113
|
-
# set will include just one record.
|
117
|
+
# include two records. If not, the LIMIT clause will execute and the
|
118
|
+
# result set will include just one record.
|
114
119
|
bad_value = "' LIMIT 1 --"
|
115
120
|
records = TestClass.order_as_specified(field: [bad_value]).to_a
|
116
121
|
expect(records.count).to eq(2)
|
@@ -128,3 +133,4 @@ RSpec.shared_examples ".order_as_specified" do
|
|
128
133
|
end
|
129
134
|
end
|
130
135
|
end
|
136
|
+
# rubocop:enable Metrics/BlockLength
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
if ENV["TRAVIS"] == "true"
|
4
|
+
require "simplecov"
|
5
|
+
SimpleCov.start
|
6
|
+
SimpleCov.start do
|
7
|
+
# Omit the spec directory from being counted in code coverage calculations.
|
8
|
+
add_filter "/spec/"
|
9
|
+
end
|
10
|
+
end
|
3
11
|
|
4
12
|
require "active_record"
|
5
13
|
|
data/spec/sqlite3_spec.rb
CHANGED
data/spec/support/test_class.rb
CHANGED
metadata
CHANGED
@@ -1,141 +1,141 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: order_as_specified
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Evelyn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 5.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: pg
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rspec-rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rubocop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: rspec-
|
98
|
+
name: rubocop-rspec-focused
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: simplecov
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '0
|
117
|
+
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '0
|
124
|
+
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: sqlite3
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
131
|
+
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
138
|
+
version: '0'
|
139
139
|
description: Obtain ActiveRecord results with a custom ordering with no need to store
|
140
140
|
anything in the database.
|
141
141
|
email:
|
@@ -144,10 +144,9 @@ executables: []
|
|
144
144
|
extensions: []
|
145
145
|
extra_rdoc_files: []
|
146
146
|
files:
|
147
|
-
- .gitignore
|
148
|
-
- .
|
149
|
-
- .
|
150
|
-
- .travis.yml
|
147
|
+
- ".gitignore"
|
148
|
+
- ".rubocop.yml"
|
149
|
+
- ".travis.yml"
|
151
150
|
- CHANGELOG.md
|
152
151
|
- Gemfile
|
153
152
|
- LICENSE.txt
|
@@ -163,6 +162,7 @@ files:
|
|
163
162
|
- spec/shared/order_as_specified_examples.rb
|
164
163
|
- spec/spec_helper.rb
|
165
164
|
- spec/sqlite3_spec.rb
|
165
|
+
- spec/support/application_record.rb
|
166
166
|
- spec/support/association_test_class.rb
|
167
167
|
- spec/support/test_class.rb
|
168
168
|
homepage: https://github.com/panorama-ed/order_as_specified
|
@@ -175,17 +175,17 @@ require_paths:
|
|
175
175
|
- lib
|
176
176
|
required_ruby_version: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
|
-
- -
|
178
|
+
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
181
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
182
|
requirements:
|
183
|
-
- -
|
183
|
+
- - ">="
|
184
184
|
- !ruby/object:Gem::Version
|
185
185
|
version: '0'
|
186
186
|
requirements: []
|
187
187
|
rubyforge_project:
|
188
|
-
rubygems_version: 2.
|
188
|
+
rubygems_version: 2.7.6
|
189
189
|
signing_key:
|
190
190
|
specification_version: 4
|
191
191
|
summary: Add arbitrary ordering to ActiveRecord queries.
|
@@ -197,6 +197,6 @@ test_files:
|
|
197
197
|
- spec/shared/order_as_specified_examples.rb
|
198
198
|
- spec/spec_helper.rb
|
199
199
|
- spec/sqlite3_spec.rb
|
200
|
+
- spec/support/application_record.rb
|
200
201
|
- spec/support/association_test_class.rb
|
201
202
|
- spec/support/test_class.rb
|
202
|
-
has_rdoc:
|