mongoid-normalize-strings 0.1.0 → 0.1.1

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: 09316e83b81f79f4ab988a563f2c0329dd16edd7
4
- data.tar.gz: 3667ea07595b313ce0bf91d0bae2f290c3230858
3
+ metadata.gz: 9b9be0339d3e3d5e725d876319b9f7e0edaea3fd
4
+ data.tar.gz: 747ecbfb2499bbf8f4c87e9855917170e365c185
5
5
  SHA512:
6
- metadata.gz: a69f52d9a15d765050d1ec8829011ae2662eff1387104810f6d44f044b8ccc0a5db28fea69bce8cdd0cc74c546ee3f90f0cfdc7cad7e5efd158c0c84aa697c11
7
- data.tar.gz: 7c4e9e931a38e563a40b126a369c96dee396c33e6d52bc711f8eff909f6ceba39b15ad8741e2b7d3ec86ce8b4110dcb773c8f126e33da08824c9ed820d88755c
6
+ metadata.gz: 7aa5176a0c512f6ecb87bea7ba82c45d60fb4657b3d2656ab227ce6b597d30f7875dec3667c6cb6241efb6e87f2bd8747d9f051ddc4c9daa7c59edd04f1478a5
7
+ data.tar.gz: e172ac25a50d3dc73a457c5104e0c7d5120a2d9d36bbb2a4b1de8a8577edbb63443e234487d682d07adc86fc8fa9ef29fc46d66a678a677785d1b89553af8a6a
data/README.md CHANGED
@@ -19,13 +19,17 @@ Or install it yourself as:
19
19
  ## Usage
20
20
 
21
21
  ```ruby
22
- class Person
22
+ class City
23
23
  include Mongoid::Document
24
24
  include Mongoid::NormalizeStrings
25
25
 
26
26
  field :name, type: String
27
27
  normalize :name
28
28
  end
29
+
30
+ city = City.create(name: 'Córdoba')
31
+ city.name # => 'Córdoba'
32
+ city.name_normalized # => 'cordoba'
29
33
  ```
30
34
 
31
35
  ## Contributing
@@ -17,7 +17,13 @@ module Mongoid
17
17
  # Returns normalized_fields Class intance variable
18
18
  #
19
19
  def normalized_fields
20
- self.superclass == Object ? @normalized_fields : self.superclass.normalized_fields
20
+ normalized_fields = (@normalized_fields || Set.new)
21
+
22
+ if self.superclass.methods.include? :normalized_fields
23
+ normalized_fields + self.superclass.normalized_fields
24
+ else
25
+ normalized_fields
26
+ end
21
27
  end
22
28
  end
23
29
 
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module NormalizeStrings
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -9,23 +9,48 @@ describe Mongoid::NormalizeStrings do
9
9
  normalize :name
10
10
  end
11
11
 
12
- it 'normalize fields after create' do
13
- city = City.create(name: 'Córdoba')
14
- expect(city.name_normalized).to eq('cordoba')
15
- end
12
+ describe 'hooks' do
13
+ it 'normalize fields after create' do
14
+ city = City.create(name: 'Córdoba')
15
+ expect(city.name_normalized).to eq('cordoba')
16
+ end
16
17
 
17
- it 'normalize fields after save' do
18
- city = City.create(name: 'Córdoba')
19
- city.name = 'Ávila'
20
- city.save
21
- expect(city.reload.name_normalized).to eq('avila')
18
+ it 'normalize fields after save' do
19
+ city = City.create(name: 'Córdoba')
20
+ city.name = 'Ávila'
21
+ city.save
22
+ expect(city.reload.name_normalized).to eq('avila')
23
+ end
22
24
  end
23
25
 
24
- it 'support one level of heritage' do
25
- class Aux < City
26
+ describe 'inheritance' do
27
+ context 'when superclass has normalized_fields' do
28
+ it 'return superclass + class normalized fields' do
29
+ class MyCity < City
30
+ field :state
31
+ normalize :state
32
+ end
33
+
34
+ expect(City.normalized_fields).to match_array([:name])
35
+ expect(MyCity.normalized_fields).to match_array([:name, :state])
36
+ end
26
37
  end
27
38
 
28
- expect(City.normalized_fields).to match_array([:name])
29
- expect(Aux.normalized_fields).to match_array([:name])
39
+ context 'when superclass has not normalized_fields' do
40
+ it 'return class normalized_fields' do
41
+ class A
42
+ include Mongoid::Document
43
+ end
44
+
45
+ class B < A
46
+ include Mongoid::NormalizeStrings
47
+
48
+ field :name
49
+ normalize :name
50
+ end
51
+
52
+ expect(B.normalized_fields).to match_array([:name])
53
+ end
54
+ end
30
55
  end
31
56
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-normalize-strings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Jurado