assorted 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/assorted/scopes.rb +11 -6
- data/lib/assorted/version.rb +1 -1
- data/spec/lib/assorted/scopes_spec.rb +3 -1
- data/spec/support/active_record.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c1b25bd61cd38f3d4f8bca37962bdcf283c833c
|
4
|
+
data.tar.gz: cc009513f6595ba60033fefda3d7b623186adbfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81f2402794924d399d317d5ad99331e527648c083a64cdc70a13d231e7710f70bc51f6d37feca7aab5acc385621a070a0711511945745918d8a6a0e852cc618d
|
7
|
+
data.tar.gz: 7eda1d0e7e2169655a90d79d173c5f8aa41595653c957a3f2766eb22bdde8b803860b9e40459cf0888e8706c7c190be9c23af820390b0fbe8236105c5edf591b
|
data/lib/assorted/scopes.rb
CHANGED
@@ -8,12 +8,8 @@ module Assorted
|
|
8
8
|
sanitized_order(column, :desc)
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
def sorting_column=(column)
|
16
|
-
@sorting_column = column
|
11
|
+
def set_sorting_column(column)
|
12
|
+
self.sorting_column = column
|
17
13
|
end
|
18
14
|
|
19
15
|
private
|
@@ -25,5 +21,14 @@ module Assorted
|
|
25
21
|
raise ActiveRecord::StatementInvalid, "Unknown column #{column}"
|
26
22
|
end
|
27
23
|
end
|
24
|
+
|
25
|
+
def sorting_column
|
26
|
+
@sorting_column ||= :created_at
|
27
|
+
end
|
28
|
+
|
29
|
+
def sorting_column=(column)
|
30
|
+
@sorting_column = column
|
31
|
+
end
|
32
|
+
|
28
33
|
end
|
29
34
|
end
|
data/lib/assorted/version.rb
CHANGED
@@ -29,7 +29,9 @@ RSpec.describe Assorted::Scopes do
|
|
29
29
|
more = ExampleRecord.create(example_count: 2)
|
30
30
|
less = ExampleRecord.create(example_count: 1)
|
31
31
|
|
32
|
-
ExampleRecord
|
32
|
+
class ExampleRecord
|
33
|
+
set_sorting_column :example_count
|
34
|
+
end
|
33
35
|
|
34
36
|
expect(ExampleRecord.asc).to eq([less, more])
|
35
37
|
expect(ExampleRecord.desc).to eq([more, less])
|
@@ -13,11 +13,11 @@ RSpec.configure do |config|
|
|
13
13
|
table.timestamps
|
14
14
|
end
|
15
15
|
|
16
|
-
original_sorting_column = ExampleRecord.sorting_column
|
16
|
+
original_sorting_column = ExampleRecord.send(:sorting_column)
|
17
17
|
|
18
18
|
example.run
|
19
19
|
|
20
|
-
ExampleRecord.sorting_column
|
20
|
+
ExampleRecord.send(:sorting_column=, original_sorting_column)
|
21
21
|
|
22
22
|
raise ActiveRecord::Rollback
|
23
23
|
end
|