activerecord_search 1.1 → 1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/activerecord_search.rb +2 -2
- data/lib/activerecord_search/term.rb +2 -6
- data/spec/lib/activerecord_search_spec.rb +5 -3
- 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: 9e2c93dbe1323a94e591f66c8d2ef01fe4b7b785
|
4
|
+
data.tar.gz: 613ab3f4dac8d3c880d6d7fbf6167c3fed214900
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e37f2ebeb442713a0da8dc5abc193388f04a7f132e2e9cdc4c0f349e57372b688ebaa7b48e81c95f3decdce7e4bf5a4ada9615a798ed51b5c0591634cc27e23
|
7
|
+
data.tar.gz: a734dc59fba81b519def9addc0eee30463f30ecf6845051710cdbf0dccf97bd8414586fd25e315f46ef2a9ed68cc6288c5d4c0674cf379d38bf84bc949ac50fb
|
data/lib/activerecord_search.rb
CHANGED
@@ -3,7 +3,7 @@ module ActiverecordSearch
|
|
3
3
|
def initialize(condition)
|
4
4
|
@pattern = case condition
|
5
5
|
when nil
|
6
|
-
nil
|
6
|
+
raise "Condition can't be nil"
|
7
7
|
when Hash
|
8
8
|
key, value = condition.first if condition.length == 1
|
9
9
|
case key.to_sym
|
@@ -22,11 +22,7 @@ module ActiverecordSearch
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def match(attribute)
|
25
|
-
|
26
|
-
attribute.eq(nil)
|
27
|
-
else
|
28
|
-
attribute.matches(@pattern)
|
29
|
-
end
|
25
|
+
attribute.matches(@pattern)
|
30
26
|
end
|
31
27
|
end
|
32
28
|
end
|
@@ -6,13 +6,13 @@ end
|
|
6
6
|
describe ActiverecordSearch do
|
7
7
|
let(:relation) { ActiveRecord::Relation.new(User, Arel::Table.new('users')) }
|
8
8
|
|
9
|
-
shared_examples_for 'generates the correct query' do |condition, attribute, pattern
|
9
|
+
shared_examples_for 'generates the correct query' do |condition, attribute, pattern|
|
10
10
|
let(:arel_nodes) { relation.where(condition).where_values }
|
11
11
|
let(:arel_node) { arel_nodes.first }
|
12
12
|
|
13
13
|
it 'returns a Arel::Nodes::Matches node' do
|
14
14
|
expect(arel_nodes.length).to eq 1
|
15
|
-
expect(arel_node).to be_an
|
15
|
+
expect(arel_node).to be_an Arel::Nodes::Matches
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'matches on the specified attribute' do
|
@@ -41,7 +41,9 @@ describe ActiverecordSearch do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
describe 'nil values' do
|
44
|
-
|
44
|
+
it 'should return nil if nil is passed in' do
|
45
|
+
expect(Search(nil)).to be_nil
|
46
|
+
end
|
45
47
|
end
|
46
48
|
|
47
49
|
describe 'exceptions' do
|