activerecord_search 1.1 → 1.2

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: 4097ce555cccbec53cd5f509e4cefb0ecb2b9788
4
- data.tar.gz: 0f786b63db16062d4c6c828a8d49efda9f837fd8
3
+ metadata.gz: 9e2c93dbe1323a94e591f66c8d2ef01fe4b7b785
4
+ data.tar.gz: 613ab3f4dac8d3c880d6d7fbf6167c3fed214900
5
5
  SHA512:
6
- metadata.gz: b5a4af78db0a81edf120b93b4424561875fc8b1554cd8ea858e73a0a4d72977bfe6d029ce6bbe630754ffbb87d2e27093fa2dd80bab362a5ca1f73a8a931e36e
7
- data.tar.gz: 1bfee0662dcc85db4dfbaab983d606782b4f9efbb17f81e9ba51b46dc65fa50235702fd0483f4616224f61752bebf9d937e2693685e95cc6ce21929c4fc1d49f
6
+ metadata.gz: 5e37f2ebeb442713a0da8dc5abc193388f04a7f132e2e9cdc4c0f349e57372b688ebaa7b48e81c95f3decdce7e4bf5a4ada9615a798ed51b5c0591634cc27e23
7
+ data.tar.gz: a734dc59fba81b519def9addc0eee30463f30ecf6845051710cdbf0dccf97bd8414586fd25e315f46ef2a9ed68cc6288c5d4c0674cf379d38bf84bc949ac50fb
@@ -1,6 +1,6 @@
1
1
  require 'activerecord_search/term'
2
2
  require 'activerecord_search/railtie'
3
3
 
4
- def Search(*args)
5
- ActiverecordSearch::Term.new(*args)
4
+ def Search(condition)
5
+ ActiverecordSearch::Term.new(condition) unless condition.nil?
6
6
  end
@@ -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
- if @pattern.nil?
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, expected_arel_class = Arel::Nodes::Matches|
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 expected_arel_class
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
- it_should_behave_like 'generates the correct query', { foo: Search(nil) }, 'foo', nil, Arel::Nodes::Equality
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_search
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.1'
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Novak