assorted 0.0.2 → 0.0.3
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 +4 -4
- data/lib/assorted.rb +8 -0
- data/lib/assorted/scopes.rb +5 -5
- data/lib/assorted/version.rb +1 -1
- data/spec/lib/assorted/scopes_spec.rb +2 -2
- data/spec/lib/assorted_spec.rb +13 -0
- data/spec/support/active_record.rb +2 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e39934bb2ca6d839e3d8b1f07aab05a0eaf75396
|
4
|
+
data.tar.gz: 1fe1404fa394fb310b2e149a15253327d157e5de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 766d78c00956d8e60603f83c1260776a582c9edf6769dd0e0966f4ba2f95ea4de120dc4ea7d529660d04440cfae42f59914d47c81fa163bc7fc86294a883d0a0
|
7
|
+
data.tar.gz: bbf7007d6bde7097577c34e297d1357b099de1a5852a8567c2965ebe4a50d18f02aff5225e7161f28b8e8a25e3d09ccc84fdf2328d0a81dd6ff6d2e770d4bd00
|
data/lib/assorted.rb
CHANGED
@@ -3,6 +3,14 @@ require "active_record"
|
|
3
3
|
require "assorted/version"
|
4
4
|
require "assorted/scopes"
|
5
5
|
|
6
|
+
module Assorted
|
7
|
+
def self.options
|
8
|
+
@options ||= {
|
9
|
+
default_sort_column: :created_at,
|
10
|
+
}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
6
14
|
ActiveSupport.on_load(:active_record) do
|
7
15
|
extend Assorted::Scopes
|
8
16
|
end
|
data/lib/assorted/scopes.rb
CHANGED
@@ -8,8 +8,8 @@ module Assorted
|
|
8
8
|
sanitized_order(column, :desc)
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
11
|
+
def assorted(options)
|
12
|
+
assorted_options.merge!(options)
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
@@ -23,11 +23,11 @@ module Assorted
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def sorting_column
|
26
|
-
|
26
|
+
assorted_options[:default_sort_column] || Assorted.options[:default_sort_column]
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
@
|
29
|
+
def assorted_options
|
30
|
+
@assorted_options ||= {}
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
data/lib/assorted/version.rb
CHANGED
@@ -18,7 +18,7 @@ RSpec.describe Assorted::Scopes do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "prevents SQL injection attacks" do
|
21
|
-
|
21
|
+
ExampleRecord.create
|
22
22
|
injection_attempt = "created_at desc; delete * from example_records;"
|
23
23
|
|
24
24
|
expect { ExampleRecord.asc(injection_attempt) }.to raise_exception(ActiveRecord::StatementInvalid)
|
@@ -30,7 +30,7 @@ RSpec.describe Assorted::Scopes do
|
|
30
30
|
less = ExampleRecord.create(example_count: 1)
|
31
31
|
|
32
32
|
class ExampleRecord
|
33
|
-
|
33
|
+
assorted default_sort_column: :example_count
|
34
34
|
end
|
35
35
|
|
36
36
|
expect(ExampleRecord.asc).to eq([less, more])
|
data/spec/lib/assorted_spec.rb
CHANGED
@@ -4,4 +4,17 @@ RSpec.describe Assorted do
|
|
4
4
|
it "includes itself in ActiveRecord::Base" do
|
5
5
|
expect(ActiveRecord::Base.ancestors).to include(Assorted::Scopes)
|
6
6
|
end
|
7
|
+
|
8
|
+
describe "#options" do
|
9
|
+
it "defaults to sort with created_at" do
|
10
|
+
expect(Assorted.options[:default_sort_column]).to eq :created_at
|
11
|
+
end
|
12
|
+
|
13
|
+
it "remembers the new options given to it" do
|
14
|
+
Assorted.options[:foo] = :bar
|
15
|
+
|
16
|
+
expect(Assorted.options[:foo]).to eq(:bar)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
7
20
|
end
|
@@ -13,11 +13,10 @@ RSpec.configure do |config|
|
|
13
13
|
table.timestamps
|
14
14
|
end
|
15
15
|
|
16
|
-
original_sorting_column = ExampleRecord.send(:sorting_column)
|
17
|
-
|
18
16
|
example.run
|
19
17
|
|
20
|
-
ExampleRecord.
|
18
|
+
ExampleRecord.instance_variable_set(:@assorted_options, nil)
|
19
|
+
Assorted.instance_variable_set(:@options, nil)
|
21
20
|
|
22
21
|
raise ActiveRecord::Rollback
|
23
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assorted
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Byrne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|