enumerize 0.8.0 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/.travis.yml +27 -12
- data/CHANGELOG.md +141 -0
- data/Gemfile +5 -21
- data/Gemfile.global +20 -0
- data/Gemfile.mongo_mapper +7 -0
- data/Gemfile.rails42 +7 -0
- data/Gemfile.rails51 +7 -0
- data/README.md +185 -9
- data/Rakefile +2 -4
- data/enumerize.gemspec +1 -0
- data/lib/enumerize/activerecord.rb +68 -27
- data/lib/enumerize/attribute.rb +42 -10
- data/lib/enumerize/base.rb +28 -17
- data/lib/enumerize/hooks/formtastic.rb +3 -8
- data/lib/enumerize/hooks/sequel_dataset.rb +15 -0
- data/lib/enumerize/hooks/simple_form.rb +5 -11
- data/lib/enumerize/hooks/uniqueness.rb +3 -8
- data/lib/enumerize/integrations/rspec/matcher.rb +107 -26
- data/lib/enumerize/mongoid.rb +13 -0
- data/lib/enumerize/predicatable.rb +7 -16
- data/lib/enumerize/predicates.rb +3 -1
- data/lib/enumerize/scope/activerecord.rb +37 -0
- data/lib/enumerize/scope/mongoid.rb +35 -0
- data/lib/enumerize/scope/sequel.rb +40 -0
- data/lib/enumerize/sequel.rb +57 -0
- data/lib/enumerize/set.rb +18 -8
- data/lib/enumerize/value.rb +10 -9
- data/lib/enumerize/version.rb +3 -1
- data/lib/enumerize.rb +23 -1
- data/spec/enumerize/integrations/rspec/matcher_spec.rb +258 -0
- data/spec/spec_helper.rb +28 -0
- data/test/activerecord_test.rb +238 -10
- data/test/attribute_test.rb +22 -0
- data/test/base_test.rb +7 -7
- data/test/formtastic_test.rb +3 -12
- data/test/mongo_mapper_test.rb +7 -1
- data/test/mongoid_test.rb +63 -7
- data/test/multiple_test.rb +21 -0
- data/test/predicates_test.rb +6 -0
- data/test/sequel_test.rb +291 -0
- data/test/set_test.rb +14 -0
- data/test/simple_form_test.rb +0 -1
- data/test/support/mock_controller.rb +4 -0
- data/test/support/view_test_helper.rb +4 -0
- data/test/test_helper.rb +23 -2
- data/test/value_test.rb +51 -21
- metadata +40 -9
- data/Gemfile.rails4 +0 -23
- data/lib/enumerize/form_helper.rb +0 -23
- data/test/rspec_matcher_test.rb +0 -76
- data/test/rspec_spec.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5a43e5546fd78ed42c35abfccc3314e52b7671f
|
4
|
+
data.tar.gz: 727be0571656833f27ee73ff8d65d6455c7511e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88cfa3f67475bf8d18279b7f53124051237c3a5bfe302e88860f5c405834cd95ebe9cfca67eb0d721c52ca746a15458cf284d2a376b049ede0b6b69379f667a6
|
7
|
+
data.tar.gz: f57a1bca5a058f2074d834968418865455f4e0ccf3aa2441064f05cb5901a4eb8ec4776cd2e95c938635a41659723679108d873caa338e8487879e91fbcafb25
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.travis.yml
CHANGED
@@ -1,19 +1,34 @@
|
|
1
1
|
language: ruby
|
2
|
+
sudo: false
|
2
3
|
services:
|
4
|
+
- postgresql
|
3
5
|
- mongodb
|
4
|
-
before_install:
|
5
|
-
- gem install bundler
|
6
6
|
gemfile:
|
7
7
|
- Gemfile
|
8
|
-
- Gemfile.
|
8
|
+
- Gemfile.rails42
|
9
|
+
- Gemfile.rails51
|
10
|
+
- Gemfile.mongo_mapper
|
9
11
|
rvm:
|
10
|
-
-
|
11
|
-
- 2.
|
12
|
-
- 2.1
|
13
|
-
- jruby-
|
12
|
+
- 2.2.7
|
13
|
+
- 2.3.3
|
14
|
+
- 2.4.1
|
15
|
+
- jruby-9.1.8.0
|
16
|
+
env:
|
17
|
+
global:
|
18
|
+
- DB_USER=postgres
|
19
|
+
- DB_PASS=
|
20
|
+
matrix:
|
21
|
+
- DB=sqlite3
|
22
|
+
- DB=postgresql
|
23
|
+
matrix:
|
24
|
+
fast_finish: true
|
25
|
+
allow_failures:
|
26
|
+
- rvm: jruby-9.1.8.0
|
27
|
+
exclude:
|
28
|
+
- gemfile: Gemfile.mongo_mapper
|
29
|
+
env: DB=postgresql
|
30
|
+
branches:
|
31
|
+
only:
|
32
|
+
- master
|
14
33
|
notifications:
|
15
|
-
email:
|
16
|
-
recipients:
|
17
|
-
- lest@brainspec.com
|
18
|
-
- nashby@brainspec.com
|
19
|
-
- dreamfall@brainspec.com
|
34
|
+
email: false
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,144 @@
|
|
1
|
+
## master
|
2
|
+
|
3
|
+
### enhancements
|
4
|
+
|
5
|
+
### bug fix
|
6
|
+
|
7
|
+
## 2.1.2 (May 18, 2017)
|
8
|
+
|
9
|
+
### bug fix
|
10
|
+
|
11
|
+
* Support YAML serialization for the custom AR type. (by [@lest](https://github.com/lest))
|
12
|
+
|
13
|
+
## 2.1.1 (May 1, 2017)
|
14
|
+
|
15
|
+
### enhancements
|
16
|
+
|
17
|
+
* Run tests with multiple DBs (SQLite and PostgreSQL). (by [tkawa](https://github.com/tkawa))
|
18
|
+
|
19
|
+
### bug fix
|
20
|
+
|
21
|
+
* Support deserialize and Rails 4.2 methods in the custom AR::Type class. (by [@lest](https://github.com/lest))
|
22
|
+
* Support dumping custom AR type to JSON. (by [@lest](https://github.com/lest))
|
23
|
+
|
24
|
+
## 2.1.0 (March 31, 2017)
|
25
|
+
|
26
|
+
### enhancements
|
27
|
+
|
28
|
+
* Support Active Record types serialization. (by [@lest](https://github.com/lest))
|
29
|
+
|
30
|
+
## 2.0.1 (October 18, 2016)
|
31
|
+
|
32
|
+
### bug fix
|
33
|
+
|
34
|
+
* Support enumerized attributes in #update_all on relation objects. (by [@lest](https://github.com/lest))
|
35
|
+
|
36
|
+
## 2.0.0 (August 10, 2016)
|
37
|
+
|
38
|
+
### enhancements
|
39
|
+
|
40
|
+
* Drop support for Ruby older than 2.2. Support only Ruby 2.2+. (by [@nashby](https://github.com/nashby))
|
41
|
+
* Drop support for Rails 4.0 and 4.1. Support only Rails 4.2 and newer. (by [@lest](https://github.com/lest))
|
42
|
+
* Support Rails 5.0. (by [@nashby](https://github.com/nashby) and [@lest](https://github.com/lest))
|
43
|
+
* Allow to pass enumerize values to `ActiveRecord#update_all` (by [@DmitryTsepelev](https://github.com/DmitryTsepelev) and [@ianwhite](https://github.com/ianwhite))
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
User.update_all(status: :blocked)
|
47
|
+
```
|
48
|
+
|
49
|
+
### bug fix
|
50
|
+
|
51
|
+
* Rescue MissingAttributeError on attribute writing. (by [@embs](https://github.com/embs))
|
52
|
+
* Fix presence validation for multiple attributes when the list contains a blank string. (by [@smoriwaki](https://github.com/smoriwaki))
|
53
|
+
* Replace deprecated alias_method_chain with Module#prepend. (by [@koenpunt](https://github.com/koenpunt) and [@akm](https://github.com/akm))
|
54
|
+
* Make it compatible with `globalize` gem. (by [@falm](https://github.com/falm))
|
55
|
+
* Prevent method getter from being called when no default_value is being set. (by [@arjan0307](https://github.com/arjan0307))
|
56
|
+
|
57
|
+
## 1.1.1 (January 25, 2016)
|
58
|
+
|
59
|
+
### bug fix
|
60
|
+
|
61
|
+
* Fix exception when using predicate methods and enumerized values have dash in it. (by [@nashby](https://github.com/nashby))
|
62
|
+
|
63
|
+
## 1.1.0 (November 15, 2015)
|
64
|
+
|
65
|
+
### enhancements
|
66
|
+
* Add Sequel support. (by [@mrbrdo](https://github.com/mrbrdo))
|
67
|
+
* Add qualifiers to RSpec matcher. (by [@maurogeorge](https://github.com/maurogeorge))
|
68
|
+
* Support hash in the RSpec matcher. (by [@maurogeorge](https://github.com/maurogeorge))
|
69
|
+
|
70
|
+
### bug fix
|
71
|
+
|
72
|
+
## 1.0.0 (August 2, 2015)
|
73
|
+
|
74
|
+
### enhancements
|
75
|
+
* Add `texts` method for getting an array of text values of the enumerized field with multiple type. (by [@huynhquancam](https://github.com/huynhquancam))
|
76
|
+
* Drop Rails 3.2 support. (by [@nashby](https://github.com/nashby))
|
77
|
+
|
78
|
+
### bug fix
|
79
|
+
|
80
|
+
* Fix conflicts when Active Record and Mongoid are used at the same time. (by [@matsu911](https://github.com/matsu911))
|
81
|
+
|
82
|
+
## 0.11.0 (March 29, 2015) ##
|
83
|
+
|
84
|
+
### enhancements
|
85
|
+
* Add ability to set default value for enumerized field with multiple type. (by [@nashby](https://github.com/nashby))
|
86
|
+
* Support Rails 4.2. (by [@lest](https://github.com/lest))
|
87
|
+
|
88
|
+
### bug fix
|
89
|
+
* Use Mongoid's `:in` method for generated scopes, fix chained scopes. (by [@nashby](https://github.com/nashby))
|
90
|
+
* Use `after_initialize` callback to set default value in Mongoid documents. (by [@nashby](https://github.com/nashby))
|
91
|
+
|
92
|
+
## 0.10.1 (March 4, 2015) ##
|
93
|
+
|
94
|
+
### bug fix
|
95
|
+
|
96
|
+
* Use method_missing instead of defining singleton class methods to allow Marshal serialization (by [@lest](https://github.com/lest))
|
97
|
+
|
98
|
+
## 0.10.0 (February 17, 2015) ##
|
99
|
+
|
100
|
+
### enhancements
|
101
|
+
|
102
|
+
* Add scopes support to mongoid documents (by [@nashby](https://github.com/nashby))
|
103
|
+
* Use underscore.humanize in #text to make use of Inflector acronyms (by [@mintuhouse](https://github.com/mintuhouse))
|
104
|
+
* Raise an exception when :scope option is used together with :multiple option (by [@maurogeorge](https://github.com/maurogeorge))
|
105
|
+
* Use alias_method_chain instead of overriding Class#inherited (by [@yuroyoro](https://github.com/yuroyoro))
|
106
|
+
* Shortcut methods to retrieve enumerize values (by [@CyborgMaster](https://github.com/CyborgMaster))
|
107
|
+
* Extend equality operator to support comparing with symbols and custom values (e.g. integers) (by [@CyborgMaster](https://github.com/CyborgMaster))
|
108
|
+
|
109
|
+
## 0.9.0 (December 11, 2014) ##
|
110
|
+
|
111
|
+
### enhancements
|
112
|
+
|
113
|
+
* Add :value_class option (by [@lest](https://github.com/lest))
|
114
|
+
* Use 'defaults' scope in the localization file for the attributes that used across several models. This will help to avoid conflicting keys with model names and attribute names. Example:
|
115
|
+
|
116
|
+
```yml
|
117
|
+
en:
|
118
|
+
enumerize:
|
119
|
+
defaults:
|
120
|
+
sex:
|
121
|
+
male: Male
|
122
|
+
female: Female
|
123
|
+
```
|
124
|
+
|
125
|
+
You still can use the old solution without "default" scope:
|
126
|
+
|
127
|
+
```yml
|
128
|
+
en:
|
129
|
+
enumerize:
|
130
|
+
sex:
|
131
|
+
male: Male
|
132
|
+
female: Female
|
133
|
+
```
|
134
|
+
(by [@nashby](https://github.com/nashby))
|
135
|
+
|
136
|
+
### bug fix
|
137
|
+
* Store values for validation using string keys (by [@nagyt234](https://github.com/nagyt234))
|
138
|
+
* Store custom values for multiple attributes (by [@lest](https://github.com/lest))
|
139
|
+
* Support validations after using AR#becomes (by [@lest](https://github.com/lest))
|
140
|
+
* Do not try to set attribute for not selected attributes (by [@dany1468](https://github.com/dany1468))
|
141
|
+
|
1
142
|
## 0.8.0 (March 4, 2014) ##
|
2
143
|
|
3
144
|
### enhancements
|
data/Gemfile
CHANGED
@@ -1,23 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
gemspec
|
4
|
-
|
5
|
-
gem 'rake'
|
6
|
-
gem 'minitest', '~> 4.1'
|
7
|
-
gem 'rspec', :require => false
|
8
|
-
|
9
|
-
gem 'rails', '~> 3.2.0', :require => false
|
10
|
-
gem 'sqlite3', :platform => [:ruby, :mswin, :mingw]
|
11
|
-
gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
|
12
|
-
|
13
|
-
platforms :rbx do
|
14
|
-
gem 'rubysl', '~> 2.0'
|
15
|
-
gem 'psych'
|
16
|
-
gem 'rubinius-developer_tools'
|
17
|
-
gem 'rubysl-test-unit'
|
18
|
-
end
|
1
|
+
eval_gemfile('Gemfile.global')
|
19
2
|
|
3
|
+
gem 'minitest', '~> 5.8'
|
4
|
+
gem 'rails', '5.0.2', require: false
|
5
|
+
gem 'activerecord-jdbcsqlite3-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'rails-5', platform: :jruby
|
6
|
+
gem 'activerecord-jdbcpostgresql-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'rails-5', platform: :jruby
|
20
7
|
gem 'mongoid'
|
21
|
-
gem 'mongo_mapper'
|
22
|
-
gem 'simple_form'
|
23
|
-
gem 'formtastic'
|
data/Gemfile.global
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
gem 'rake'
|
6
|
+
gem 'rspec', :require => false
|
7
|
+
|
8
|
+
gem 'sqlite3', :platform => [:ruby, :mswin, :mingw]
|
9
|
+
gem 'pg', :platform => [:ruby, :mswin, :mingw]
|
10
|
+
gem 'sequel'
|
11
|
+
|
12
|
+
platforms :rbx do
|
13
|
+
gem 'rubysl', '~> 2.0'
|
14
|
+
gem 'psych'
|
15
|
+
gem 'rubinius-developer_tools'
|
16
|
+
gem 'rubysl-test-unit'
|
17
|
+
end
|
18
|
+
|
19
|
+
gem 'simple_form'
|
20
|
+
gem 'formtastic'
|
data/Gemfile.rails42
ADDED
data/Gemfile.rails51
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
eval_gemfile('Gemfile.global')
|
2
|
+
|
3
|
+
gem 'minitest', '~> 5.8'
|
4
|
+
gem 'rails', '5.1.0.rc1', require: false
|
5
|
+
gem 'activerecord-jdbcsqlite3-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'rails-5', platform: :jruby
|
6
|
+
gem 'activerecord-jdbcpostgresql-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'rails-5', platform: :jruby
|
7
|
+
gem 'mongoid', github: 'mongodb/mongoid'
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# Enumerize [![TravisCI](https://secure.travis-ci.org/brainspec/enumerize.
|
1
|
+
# Enumerize [![TravisCI](https://secure.travis-ci.org/brainspec/enumerize.svg?branch=master)](http://travis-ci.org/brainspec/enumerize) [![Gemnasium](https://gemnasium.com/brainspec/enumerize.svg)](https://gemnasium.com/brainspec/enumerize)
|
2
2
|
|
3
|
-
Enumerated attributes with I18n and ActiveRecord/Mongoid/MongoMapper support
|
3
|
+
Enumerated attributes with I18n and ActiveRecord/Mongoid/MongoMapper/Sequel support
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -34,6 +34,17 @@ Note that enumerized values are just identificators so if you want to use multi-
|
|
34
34
|
ActiveRecord:
|
35
35
|
|
36
36
|
```ruby
|
37
|
+
class CreateUsers < ActiveRecord::Migration
|
38
|
+
def change
|
39
|
+
create_table :users do |t|
|
40
|
+
t.string :sex
|
41
|
+
t.string :role
|
42
|
+
|
43
|
+
t.timestamps
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
37
48
|
class User < ActiveRecord::Base
|
38
49
|
extend Enumerize
|
39
50
|
|
@@ -78,17 +89,18 @@ en:
|
|
78
89
|
female: "Female"
|
79
90
|
```
|
80
91
|
|
81
|
-
or if you use `sex` attribute across several models you can use
|
92
|
+
or if you use `sex` attribute across several models you can use `defaults` scope:
|
82
93
|
|
83
94
|
```ruby
|
84
95
|
en:
|
85
96
|
enumerize:
|
86
|
-
|
87
|
-
|
88
|
-
|
97
|
+
defaults:
|
98
|
+
sex:
|
99
|
+
male: "Male"
|
100
|
+
female: "Female"
|
89
101
|
```
|
90
102
|
|
91
|
-
You can also pass `i18n_scope` option to specify scope (or array of scopes)
|
103
|
+
You can also pass `i18n_scope` option to specify scope (or array of scopes) storing the translations.
|
92
104
|
|
93
105
|
|
94
106
|
```ruby
|
@@ -168,6 +180,7 @@ user.sex = 'male'
|
|
168
180
|
user.male? # => true
|
169
181
|
user.female? # => false
|
170
182
|
```
|
183
|
+
:warning: If `enumerize` is used with Mongoid, it's not recommended to use `"writer"` as a field value since `writer?` is defined by Mongoid. [See more](https://github.com/brainspec/enumerize/issues/235). :warning:
|
171
184
|
|
172
185
|
Using prefix:
|
173
186
|
|
@@ -239,6 +252,8 @@ User.having_status(:blocked).with_sex(:male, :female)
|
|
239
252
|
# SELECT "users".* FROM "users" WHERE "users"."status" IN (2) AND "users"."sex" IN ('male', 'female')
|
240
253
|
```
|
241
254
|
|
255
|
+
:warning: It is not possible to define a scope when using the `:multiple` option. :warning:
|
256
|
+
|
242
257
|
Array-like attributes with plain ruby objects:
|
243
258
|
|
244
259
|
```ruby
|
@@ -264,6 +279,24 @@ class User < ActiveRecord::Base
|
|
264
279
|
end
|
265
280
|
```
|
266
281
|
|
282
|
+
get an array of all text values:
|
283
|
+
|
284
|
+
```ruby
|
285
|
+
@user.interests.texts # shortcut for @user.interests.map(&:text)
|
286
|
+
```
|
287
|
+
|
288
|
+
Also, the reader method can be overridden, referencing the enumerized attribute value using `super`:
|
289
|
+
|
290
|
+
```ruby
|
291
|
+
def sex
|
292
|
+
if current_user.admin?
|
293
|
+
"Super#{super}"
|
294
|
+
else
|
295
|
+
super
|
296
|
+
end
|
297
|
+
end
|
298
|
+
```
|
299
|
+
|
267
300
|
### SimpleForm
|
268
301
|
|
269
302
|
If you are using SimpleForm gem you don't need to specify input type (`:select` by default) and collection:
|
@@ -308,12 +341,155 @@ Also you can use builtin RSpec matcher:
|
|
308
341
|
class User
|
309
342
|
extend Enumerize
|
310
343
|
|
311
|
-
enumerize :sex, in: [:male, :female]
|
344
|
+
enumerize :sex, in: [:male, :female]
|
345
|
+
end
|
346
|
+
|
347
|
+
describe User do
|
348
|
+
it { should enumerize(:sex) }
|
349
|
+
|
350
|
+
# or with RSpec 3 expect syntax
|
351
|
+
it { is_expected.to enumerize(:sex) }
|
352
|
+
end
|
353
|
+
```
|
354
|
+
|
355
|
+
#### Qualifiers
|
356
|
+
|
357
|
+
##### in
|
358
|
+
|
359
|
+
Use `in` to test usage of the `:in` option.
|
360
|
+
|
361
|
+
```ruby
|
362
|
+
class User
|
363
|
+
extend Enumerize
|
364
|
+
|
365
|
+
enumerize :sex, in: [:male, :female]
|
312
366
|
end
|
313
367
|
|
314
368
|
describe User do
|
315
369
|
it { should enumerize(:sex).in(:male, :female) }
|
316
|
-
|
370
|
+
end
|
371
|
+
```
|
372
|
+
|
373
|
+
You can test enumerized attribute value using custom values with the `in`
|
374
|
+
qualifier.
|
375
|
+
|
376
|
+
```ruby
|
377
|
+
class User
|
378
|
+
extend Enumerize
|
379
|
+
|
380
|
+
enumerize :sex, in: { male: 0, female: 1 }
|
381
|
+
end
|
382
|
+
|
383
|
+
describe User do
|
384
|
+
it { should enumerize(:sex).in(male: 0, female: 1) }
|
385
|
+
end
|
386
|
+
```
|
387
|
+
|
388
|
+
##### with_default
|
389
|
+
|
390
|
+
Use `with_default` to test usage of the `:default` option.
|
391
|
+
|
392
|
+
```ruby
|
393
|
+
class User
|
394
|
+
extend Enumerize
|
395
|
+
|
396
|
+
enumerize :sex, in: [:male, :female], default: :female
|
397
|
+
end
|
398
|
+
|
399
|
+
describe User do
|
400
|
+
it { should enumerize(:sex).in(:male, :female).with_default(:female) }
|
401
|
+
end
|
402
|
+
```
|
403
|
+
|
404
|
+
##### with_i18n_scope
|
405
|
+
|
406
|
+
Use `with_i18n_scope` to test usage of the `:i18n_scope` option.
|
407
|
+
|
408
|
+
```ruby
|
409
|
+
class User
|
410
|
+
extend Enumerize
|
411
|
+
|
412
|
+
enumerize :sex, in: [:male, :female], i18n_scope: 'sex'
|
413
|
+
end
|
414
|
+
|
415
|
+
describe User do
|
416
|
+
it { should enumerize(:sex).in(:male, :female).with_i18n_scope('sex') }
|
417
|
+
end
|
418
|
+
```
|
419
|
+
|
420
|
+
##### with_predicates
|
421
|
+
|
422
|
+
Use `with_predicates` to test usage of the `:predicates` option.
|
423
|
+
|
424
|
+
```ruby
|
425
|
+
class User
|
426
|
+
extend Enumerize
|
427
|
+
|
428
|
+
enumerize :sex, in: [:male, :female], predicates: true
|
429
|
+
end
|
430
|
+
|
431
|
+
describe User do
|
432
|
+
it { should enumerize(:sex).in(:male, :female).with_predicates(true) }
|
433
|
+
end
|
434
|
+
```
|
435
|
+
|
436
|
+
You can text prefixed predicates with the `with_predicates` qualifiers.
|
437
|
+
|
438
|
+
```ruby
|
439
|
+
class User
|
440
|
+
extend Enumerize
|
441
|
+
|
442
|
+
enumerize :sex, in: [:male, :female], predicates: { prefix: true }
|
443
|
+
end
|
444
|
+
|
445
|
+
describe User do
|
446
|
+
it { should enumerize(:sex).in(:male, :female).with_predicates(prefix: true) }
|
447
|
+
end
|
448
|
+
```
|
449
|
+
|
450
|
+
##### with_scope
|
451
|
+
|
452
|
+
Use `with_scope` to test usage of the `:scope` option.
|
453
|
+
|
454
|
+
```ruby
|
455
|
+
class User
|
456
|
+
extend Enumerize
|
457
|
+
|
458
|
+
enumerize :sex, in: [:male, :female], scope: true
|
459
|
+
end
|
460
|
+
|
461
|
+
describe User do
|
462
|
+
it { should enumerize(:sex).in(:male, :female).with_scope(true) }
|
463
|
+
end
|
464
|
+
```
|
465
|
+
|
466
|
+
You can text custom scope with the `with_scope` qualifiers.
|
467
|
+
|
468
|
+
```ruby
|
469
|
+
class User
|
470
|
+
extend Enumerize
|
471
|
+
|
472
|
+
enumerize :sex, in: [:male, :female], scope: :having_sex
|
473
|
+
end
|
474
|
+
|
475
|
+
describe User do
|
476
|
+
it { should enumerize(:sex).in(:male, :female).with_scope(scope: :having_sex) }
|
477
|
+
end
|
478
|
+
```
|
479
|
+
|
480
|
+
##### with_multiple
|
481
|
+
|
482
|
+
Use `with_multiple` to test usage of the `:multiple` option.
|
483
|
+
|
484
|
+
```ruby
|
485
|
+
class User
|
486
|
+
extend Enumerize
|
487
|
+
|
488
|
+
enumerize :sex, in: [:male, :female], multiple: true
|
489
|
+
end
|
490
|
+
|
491
|
+
describe User do
|
492
|
+
it { should enumerize(:sex).in(:male, :female).with_multiple(true) }
|
317
493
|
end
|
318
494
|
```
|
319
495
|
|
data/Rakefile
CHANGED
data/enumerize.gemspec
CHANGED
@@ -4,6 +4,7 @@ require File.expand_path('../lib/enumerize/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Sergey Nartimov"]
|
6
6
|
gem.email = "team@brainspec.com"
|
7
|
+
gem.licenses = ['MIT']
|
7
8
|
gem.description = %q{Enumerated attributes with I18n and ActiveRecord/Mongoid/MongoMapper support}
|
8
9
|
gem.summary = %q{Enumerated attributes with I18n and ActiveRecord/Mongoid/MongoMapper support}
|
9
10
|
gem.homepage = "https://github.com/brainspec/enumerize"
|