sample_filter 0.1.2 → 0.1.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ff44fc9766880a8b45d35e772878b18a58299f0
|
4
|
+
data.tar.gz: 231830605bfaa85837008a3d88fe04582e9932bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d924464af0cbf329af95928d4e9306008cec317ef299e18384add3064754fbe41186bbe407bebb39948dc719539f79303088731d81dc279d375816f72434e943
|
7
|
+
data.tar.gz: e1cbde05ab4f0666da76de65fd2802232a2652bd22673b6bf191f390ecaba58ae109a5859897bdddc4da02f53ba0d69951ac4912c1a3a41bc4e895d0d0ff8ea0
|
@@ -45,7 +45,11 @@ module SampleFilter
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def list_query(ar_rel, field, value)
|
48
|
-
|
48
|
+
if valid_json?(value) && JSON.parse(value).class.name == 'Array'
|
49
|
+
ar_rel.where("#{field} IN (?)", JSON.parse(value))
|
50
|
+
else
|
51
|
+
ar_rel.where("#{field} = ?", value)
|
52
|
+
end
|
49
53
|
end
|
50
54
|
|
51
55
|
def sorting_query(ar_rel, field, value)
|
@@ -56,5 +60,11 @@ module SampleFilter
|
|
56
60
|
|
57
61
|
ar_rel.order("#{column} #{direction}")
|
58
62
|
end
|
63
|
+
|
64
|
+
def valid_json?(json)
|
65
|
+
JSON.parse(json)
|
66
|
+
rescue StandardError
|
67
|
+
false
|
68
|
+
end
|
59
69
|
end
|
60
70
|
end
|
@@ -6,8 +6,8 @@ context 'initialize params set with valid attributes' do
|
|
6
6
|
'created_at' => {'type' => 'date', default_value: {from: '09.11.2016', to: '17.11.2017'}},
|
7
7
|
kind: {
|
8
8
|
type: 'list',
|
9
|
-
values: {red: 1, 'green' => '2'},
|
10
|
-
default_value: 2
|
9
|
+
values: {red: 1, 'green' => '2', red_and_green: [1, 2]},
|
10
|
+
default_value: [1,2]
|
11
11
|
},
|
12
12
|
status: {
|
13
13
|
type: :list,
|
@@ -34,7 +34,7 @@ context 'initialize params set with valid attributes' do
|
|
34
34
|
expect(subject.title).to be_nil
|
35
35
|
expect(subject.amount).to be_nil
|
36
36
|
expect(subject.created_at).to eq({from: '09.11.2016', to: '17.11.2017'})
|
37
|
-
expect(subject.kind).to eq('2')
|
37
|
+
expect(subject.kind).to eq('[1, 2]')
|
38
38
|
expect(subject.status).to eq('unconfirm')
|
39
39
|
expect(subject.confirmed).to eq('f')
|
40
40
|
expect(subject.sort).to eq('id_desc')
|
@@ -52,7 +52,7 @@ context 'initialize params set with valid attributes' do
|
|
52
52
|
|
53
53
|
it 'should return values' do
|
54
54
|
expect(subject.values_for('created_at')).to be_nil
|
55
|
-
expect(subject.values_for(:kind)).to eq({'red' => 1, 'green' => '2'})
|
55
|
+
expect(subject.values_for(:kind)).to eq({'red' => 1, 'green' => '2', 'red_and_green' => [1, 2]})
|
56
56
|
expect(subject.values_for(:status)).to eq(['confirm', 'unconfirm'])
|
57
57
|
expect(subject.values_for(:sort)).to eq(['id', 'title', 'amount'])
|
58
58
|
end
|
@@ -10,7 +10,7 @@ context 'filtered entities' do
|
|
10
10
|
'created_at' => {'type' => 'date'},
|
11
11
|
kind: {
|
12
12
|
type: 'list',
|
13
|
-
values: {red: 1, 'green' => '2'}
|
13
|
+
values: {red: 1, 'green' => '2', red_and_green: [1, 2]}
|
14
14
|
},
|
15
15
|
status: {
|
16
16
|
type: :list,
|
@@ -58,6 +58,7 @@ context 'filtered entities' do
|
|
58
58
|
expect(Entity.filtered(ActionController::Parameters.new({kind: 2})).map(&:id)).to eq([entity2.id])
|
59
59
|
expect(Entity.filtered(ActionController::Parameters.new({kind: 4})).map(&:id)).to eq([entity3.id])
|
60
60
|
expect(Entity.filtered(ActionController::Parameters.new({kind: ''})).map(&:id)).to eq(full_list)
|
61
|
+
expect(Entity.filtered(ActionController::Parameters.new({kind: '[1,2]'})).map(&:id)).to eq([entity1.id, entity2.id, entity4.id, entity5.id])
|
61
62
|
|
62
63
|
expect(Entity.filtered(ActionController::Parameters.new({status: 'confirm'})).map(&:id)).to eq([entity1.id, entity2.id, entity4.id, entity5.id])
|
63
64
|
expect(Entity.filtered(ActionController::Parameters.new({status: :unconfirm})).map(&:id)).to eq([entity3.id])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sample_filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ilia
|
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: rails
|
@@ -80,7 +80,8 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description: SampleFilter is a Rails Engine plugin that makes to filter and sort ActiveRecord
|
84
|
+
lists
|
84
85
|
email:
|
85
86
|
- piryazevilia@gmail.com
|
86
87
|
executables: []
|
@@ -2698,7 +2699,7 @@ rubyforge_project:
|
|
2698
2699
|
rubygems_version: 2.6.13
|
2699
2700
|
signing_key:
|
2700
2701
|
specification_version: 4
|
2701
|
-
summary:
|
2702
|
+
summary: Engine plugin that makes to filter
|
2702
2703
|
test_files:
|
2703
2704
|
- spec/ar_helper.rb
|
2704
2705
|
- spec/dummy/app/assets/config/manifest.js
|