enumerize 0.3.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -1
  3. data/.rspec +2 -0
  4. data/.travis.yml +38 -11
  5. data/CHANGELOG.md +258 -0
  6. data/Gemfile +5 -11
  7. data/Gemfile.global +20 -0
  8. data/Gemfile.mongo_mapper +7 -0
  9. data/Gemfile.rails42 +7 -0
  10. data/Gemfile.rails50 +7 -0
  11. data/Gemfile.rails52 +7 -0
  12. data/README.md +405 -17
  13. data/Rakefile +7 -1
  14. data/enumerize.gemspec +6 -3
  15. data/lib/enumerize/activemodel.rb +47 -0
  16. data/lib/enumerize/activerecord.rb +127 -2
  17. data/lib/enumerize/attribute.rb +167 -7
  18. data/lib/enumerize/attribute_map.rb +4 -0
  19. data/lib/enumerize/base.rb +60 -61
  20. data/lib/enumerize/hooks/formtastic.rb +11 -12
  21. data/lib/enumerize/hooks/sequel_dataset.rb +17 -0
  22. data/lib/enumerize/hooks/simple_form.rb +21 -8
  23. data/lib/enumerize/hooks/uniqueness.rb +22 -0
  24. data/lib/enumerize/integrations/rails_admin.rb +18 -0
  25. data/lib/enumerize/integrations/rspec/matcher.rb +161 -0
  26. data/lib/enumerize/integrations/rspec.rb +19 -0
  27. data/lib/enumerize/module.rb +33 -0
  28. data/lib/enumerize/module_attributes.rb +3 -2
  29. data/lib/enumerize/mongoid.rb +29 -0
  30. data/lib/enumerize/predicatable.rb +23 -0
  31. data/lib/enumerize/predicates.rb +76 -0
  32. data/lib/enumerize/scope/activerecord.rb +49 -0
  33. data/lib/enumerize/scope/mongoid.rb +46 -0
  34. data/lib/enumerize/scope/sequel.rb +52 -0
  35. data/lib/enumerize/sequel.rb +62 -0
  36. data/lib/enumerize/set.rb +81 -0
  37. data/lib/enumerize/utils.rb +12 -0
  38. data/lib/enumerize/value.rb +19 -46
  39. data/lib/enumerize/version.rb +3 -1
  40. data/lib/enumerize.rb +56 -4
  41. data/lib/sequel/plugins/enumerize.rb +18 -0
  42. data/spec/enumerize/integrations/rspec/matcher_spec.rb +260 -0
  43. data/spec/spec_helper.rb +30 -0
  44. data/test/activemodel_test.rb +114 -0
  45. data/test/activerecord_test.rb +542 -8
  46. data/test/attribute_map_test.rb +2 -0
  47. data/test/attribute_test.rb +102 -4
  48. data/test/base_test.rb +61 -39
  49. data/test/formtastic_test.rb +102 -17
  50. data/test/module_attributes_test.rb +25 -2
  51. data/test/mongo_mapper_test.rb +84 -0
  52. data/test/mongoid_test.rb +98 -7
  53. data/test/multiple_test.rb +59 -0
  54. data/test/predicates_test.rb +65 -0
  55. data/test/rails_admin_test.rb +27 -0
  56. data/test/sequel_test.rb +341 -0
  57. data/test/set_test.rb +166 -0
  58. data/test/simple_form_test.rb +110 -4
  59. data/test/support/mock_controller.rb +11 -1
  60. data/test/support/shared_enums.rb +43 -0
  61. data/test/support/view_test_helper.rb +6 -0
  62. data/test/test_helper.rb +25 -6
  63. data/test/value_test.rb +102 -13
  64. metadata +62 -28
  65. data/gemfiles/Gemfile-ar-3.1.x +0 -13
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9f6c56fc7c04faa02a4b4e4c137d3e3b743426d040e3f58bb79377d2c896d98f
4
+ data.tar.gz: 1e1842411f2b914b6142d071e84c435f17dfdac0f87a61eb9bf0a45a469a7780
5
+ SHA512:
6
+ metadata.gz: b3c9a1fd651070c324e04f26dcf0539ed6d1a8666878106875b78acc00d6219c5525349e0f3557aa43eb6625986322063117f06f8162922b9ae1b91544593d10
7
+ data.tar.gz: 4f070511d3e8d06e13eef610b73b4e40b5db8bd73c7282aec5cf1203de78b09e323248ce9627b82a8c8ab0a8688a4e0e05ac6d4bf1659c3e5ff69cb86c435745
data/.gitignore CHANGED
@@ -2,14 +2,18 @@
2
2
  *.rbc
3
3
  .bundle
4
4
  .config
5
+ .ruby-version
5
6
  .yardoc
6
- Gemfile.lock
7
+ .idea/
8
+ enumerize.iml
9
+ Gemfile*.lock
7
10
  gemfiles/Gemfile-*.lock
8
11
  InstalledFiles
9
12
  _yardoc
10
13
  coverage
11
14
  doc/
12
15
  lib/bundler/man
16
+ log/*
13
17
  pkg
14
18
  rdoc
15
19
  spec/reports
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml CHANGED
@@ -1,15 +1,42 @@
1
1
  language: ruby
2
- before_install:
3
- - gem install bundler
4
- rvm:
5
- - 1.9.2
6
- - 1.9.3
2
+ sudo: false
3
+ services:
4
+ - postgresql
5
+ - mongodb
7
6
  gemfile:
8
- - gemfiles/Gemfile-ar-3.1.x
9
7
  - Gemfile
8
+ - Gemfile.rails42
9
+ - Gemfile.rails50
10
+ - Gemfile.rails52
11
+ - Gemfile.mongo_mapper
12
+ rvm:
13
+ - 2.2.9
14
+ - 2.3.6
15
+ - 2.4.3
16
+ - 2.5.0
17
+ - jruby-9.1.14.0
18
+ before_install:
19
+ # Rubygems > 3.0.0 no longer supported rubies < 2.3
20
+ - gem install "rubygems-update:<3.0.0" --no-document && update_rubygems
21
+ # Bundler 2.0 is not supported by Rails < 5
22
+ - gem list -i bundler -v '>= 2.0.0' && rvm @global do gem uninstall bundler -x || true
23
+ - gem install bundler -v '< 2'
24
+ env:
25
+ global:
26
+ - DB_USER=postgres
27
+ - DB_PASS=
28
+ matrix:
29
+ - DB=sqlite3
30
+ - DB=postgresql
31
+ matrix:
32
+ fast_finish: true
33
+ allow_failures:
34
+ - rvm: jruby-9.1.14.0
35
+ exclude:
36
+ - gemfile: Gemfile.mongo_mapper
37
+ env: DB=postgresql
38
+ branches:
39
+ only:
40
+ - master
10
41
  notifications:
11
- email:
12
- recipients:
13
- - lest@brainspec.com
14
- - nashby@brainspec.com
15
- - dreamfall@brainspec.com
42
+ email: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,261 @@
1
+ ## master
2
+
3
+ ### enhancements
4
+
5
+ ### bug fix
6
+
7
+ ## 2.3.1 (May 2, 2019)
8
+
9
+ ### enhancements
10
+
11
+ * Add ability to skip validations by passing `:skip_validations` option. (by [@chumakoff](https://github.com/chumakoff))
12
+ * Add option `scope: shallow` to extend scopes based on enumerized attribute values (by [@moofkit](https://github.com/moofkit/))
13
+
14
+ ### bug fix
15
+
16
+ * Fix issue with ActiveRecord and Mongoid `reload` method when enumberized attributes weren't synced from DB. (by [@nashby](https://github.com/nashby) and [@FunkyloverOne](https://github.com/FunkyloverOne))
17
+ * Fix issue with ActiveRecord `reload` method not working for ActiveRecord::Store attributes due to `1b776c`. (by [@rickcsong](https://github.com/rickcsong))
18
+
19
+ ## 2.2.2 (March 6, 2018)
20
+
21
+ ### bug fix
22
+
23
+ * Support non-ActiveModel objects in SimpleForm/Formtastic integration. (by [@nashby](https://github.com/nashby))
24
+
25
+ ## 2.2.1 (February 15, 2018)
26
+
27
+ ### bug fix
28
+
29
+ * Fix issue with SimpleForm/Formtastic forms without object. (by [@nashby](https://github.com/nashby))
30
+
31
+ ## 2.2.0 (February 13, 2018)
32
+
33
+ ### enhancements
34
+
35
+ * Add integration with active_interaction. (by [@runephilosof](https://github.com/runephilosof))
36
+ * Allow using `plugin :enumerize` with Sequel. (by [@jnylen](https://github.com/jnylen))
37
+ * Support ActiveModel::Attributes from Rails 5.2. (by [@troter](https://github.com/troter))
38
+ * Support Sequel 5.2.0. (by [@troter](https://github.com/troter))
39
+
40
+ ### bug fix
41
+
42
+ * Fix RailsAdmin integration when enumerated field used on edit form and enumerated value wasn't set. (by [@nashby](https://github.com/nashby))
43
+ * Fallback to a raw passed value instead of nil if AR type can't find value in the attribute. (by [@nashby](https://github.com/nashby))
44
+
45
+ ## 2.1.2 (May 18, 2017)
46
+
47
+ ### bug fix
48
+
49
+ * Support YAML serialization for the custom AR type. (by [@lest](https://github.com/lest))
50
+
51
+ ## 2.1.1 (May 1, 2017)
52
+
53
+ ### enhancements
54
+
55
+ * Run tests with multiple DBs (SQLite and PostgreSQL). (by [tkawa](https://github.com/tkawa))
56
+
57
+ ### bug fix
58
+
59
+ * Support deserialize and Rails 4.2 methods in the custom AR::Type class. (by [@lest](https://github.com/lest))
60
+ * Support dumping custom AR type to JSON. (by [@lest](https://github.com/lest))
61
+
62
+ ## 2.1.0 (March 31, 2017)
63
+
64
+ ### enhancements
65
+
66
+ * Support Active Record types serialization. (by [@lest](https://github.com/lest))
67
+
68
+ ## 2.0.1 (October 18, 2016)
69
+
70
+ ### bug fix
71
+
72
+ * Support enumerized attributes in #update_all on relation objects. (by [@lest](https://github.com/lest))
73
+
74
+ ## 2.0.0 (August 10, 2016)
75
+
76
+ ### enhancements
77
+
78
+ * Drop support for Ruby older than 2.2. Support only Ruby 2.2+. (by [@nashby](https://github.com/nashby))
79
+ * Drop support for Rails 4.0 and 4.1. Support only Rails 4.2 and newer. (by [@lest](https://github.com/lest))
80
+ * Support Rails 5.0. (by [@nashby](https://github.com/nashby) and [@lest](https://github.com/lest))
81
+ * Allow to pass enumerize values to `ActiveRecord#update_all` (by [@DmitryTsepelev](https://github.com/DmitryTsepelev) and [@ianwhite](https://github.com/ianwhite))
82
+
83
+ ```ruby
84
+ User.update_all(status: :blocked)
85
+ ```
86
+
87
+ ### bug fix
88
+
89
+ * Rescue MissingAttributeError on attribute writing. (by [@embs](https://github.com/embs))
90
+ * Fix presence validation for multiple attributes when the list contains a blank string. (by [@smoriwaki](https://github.com/smoriwaki))
91
+ * Replace deprecated alias_method_chain with Module#prepend. (by [@koenpunt](https://github.com/koenpunt) and [@akm](https://github.com/akm))
92
+ * Make it compatible with `globalize` gem. (by [@falm](https://github.com/falm))
93
+ * Prevent method getter from being called when no default_value is being set. (by [@arjan0307](https://github.com/arjan0307))
94
+
95
+ ## 1.1.1 (January 25, 2016)
96
+
97
+ ### bug fix
98
+
99
+ * Fix exception when using predicate methods and enumerized values have dash in it. (by [@nashby](https://github.com/nashby))
100
+
101
+ ## 1.1.0 (November 15, 2015)
102
+
103
+ ### enhancements
104
+ * Add Sequel support. (by [@mrbrdo](https://github.com/mrbrdo))
105
+ * Add qualifiers to RSpec matcher. (by [@maurogeorge](https://github.com/maurogeorge))
106
+ * Support hash in the RSpec matcher. (by [@maurogeorge](https://github.com/maurogeorge))
107
+
108
+ ### bug fix
109
+
110
+ ## 1.0.0 (August 2, 2015)
111
+
112
+ ### enhancements
113
+ * Add `texts` method for getting an array of text values of the enumerized field with multiple type. (by [@huynhquancam](https://github.com/huynhquancam))
114
+ * Drop Rails 3.2 support. (by [@nashby](https://github.com/nashby))
115
+
116
+ ### bug fix
117
+
118
+ * Fix conflicts when Active Record and Mongoid are used at the same time. (by [@matsu911](https://github.com/matsu911))
119
+
120
+ ## 0.11.0 (March 29, 2015) ##
121
+
122
+ ### enhancements
123
+ * Add ability to set default value for enumerized field with multiple type. (by [@nashby](https://github.com/nashby))
124
+ * Support Rails 4.2. (by [@lest](https://github.com/lest))
125
+
126
+ ### bug fix
127
+ * Use Mongoid's `:in` method for generated scopes, fix chained scopes. (by [@nashby](https://github.com/nashby))
128
+ * Use `after_initialize` callback to set default value in Mongoid documents. (by [@nashby](https://github.com/nashby))
129
+
130
+ ## 0.10.1 (March 4, 2015) ##
131
+
132
+ ### bug fix
133
+
134
+ * Use method_missing instead of defining singleton class methods to allow Marshal serialization (by [@lest](https://github.com/lest))
135
+
136
+ ## 0.10.0 (February 17, 2015) ##
137
+
138
+ ### enhancements
139
+
140
+ * Add scopes support to mongoid documents (by [@nashby](https://github.com/nashby))
141
+ * Use underscore.humanize in #text to make use of Inflector acronyms (by [@mintuhouse](https://github.com/mintuhouse))
142
+ * Raise an exception when :scope option is used together with :multiple option (by [@maurogeorge](https://github.com/maurogeorge))
143
+ * Use alias_method_chain instead of overriding Class#inherited (by [@yuroyoro](https://github.com/yuroyoro))
144
+ * Shortcut methods to retrieve enumerize values (by [@CyborgMaster](https://github.com/CyborgMaster))
145
+ * Extend equality operator to support comparing with symbols and custom values (e.g. integers) (by [@CyborgMaster](https://github.com/CyborgMaster))
146
+
147
+ ## 0.9.0 (December 11, 2014) ##
148
+
149
+ ### enhancements
150
+
151
+ * Add :value_class option (by [@lest](https://github.com/lest))
152
+ * 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:
153
+
154
+ ```yml
155
+ en:
156
+ enumerize:
157
+ defaults:
158
+ sex:
159
+ male: Male
160
+ female: Female
161
+ ```
162
+
163
+ You still can use the old solution without "default" scope:
164
+
165
+ ```yml
166
+ en:
167
+ enumerize:
168
+ sex:
169
+ male: Male
170
+ female: Female
171
+ ```
172
+ (by [@nashby](https://github.com/nashby))
173
+
174
+ ### bug fix
175
+ * Store values for validation using string keys (by [@nagyt234](https://github.com/nagyt234))
176
+ * Store custom values for multiple attributes (by [@lest](https://github.com/lest))
177
+ * Support validations after using AR#becomes (by [@lest](https://github.com/lest))
178
+ * Do not try to set attribute for not selected attributes (by [@dany1468](https://github.com/dany1468))
179
+
180
+ ## 0.8.0 (March 4, 2014) ##
181
+
182
+ ### enhancements
183
+ * Integration with SimpleForm's `input_field` (by [@nashby](https://github.com/nashby))
184
+ * Support multiple attributes in Active Record #becomes method (by [@lest](https://github.com/lest))
185
+ * Add ability to specify localization scope with `i18n_scope` option (by [@dreamfall](https://github.com/dreamfall))
186
+
187
+ ### bug fix
188
+ * Fix Rails Admin integration when custom values are used (by [@brenes](https://github.com/brenes))
189
+ * Fix RSpec integration using enumerize with Spring (by [@winston](https://github.com/winston))
190
+ * Return proper RSpec failure message for enumerized attribute with default value (by [@nashby](https://github.com/nashby))
191
+ * Return proper RSpec description for enumerized attribute without default value (by [@andreygerasimchuk](https://github.com/andreygerasimchuk))
192
+ * Do not try to set default value for not selected attributes (by [@nashby](https://github.com/nashby))
193
+ * Fix uniqueness validation with Active Record (by [@lest](https://github.com/lest))
194
+ * Fix loading of attributes with multiple: true in mongoid (by [glebtv](https://github.com/glebtv))
195
+ * Serialize value as scalar type (by [@ka8725](https://github.com/ka8725))
196
+
197
+ ## 0.7.0 (August 21, 2013) ##
198
+
199
+ ### enhancements
200
+ * Give priority to model specific translation definition. See example [here](https://github.com/brainspec/enumerize/pull/96) (by [@labocho](https://github.com/labocho))
201
+ * Allow lambda in default value (by [@adie](https://github.com/adie))
202
+ * Add predicate methods to the multiple attributes (by [@nashby](https://github.com/nashby))
203
+ * Add RSpec matcher (by [@nashby](https://github.com/nashby))
204
+ * Add `*_value` method that returns actual value of the enumerized attribute (useful for attributes with custom values)
205
+ (by [@tkyowa](https://github.com/tkyowa))
206
+
207
+ ### bug fix
208
+ * Make validation work when `write_attribute` is using for setting enumerized values (by [@nashby](https://github.com/nashby))
209
+ * Validates enumerized values when enumeration is included via module
210
+ (by [@nashby](https://github.com/nashby)) and (by [@lest](https://github.com/lest))
211
+
212
+ ## 0.6.1 (May 20, 2013) ##
213
+
214
+ ### bug fix
215
+ * Don't raise error when enumerized attribute is already defined. (by [@lest](https://github.com/lest))
216
+
217
+ ## 0.6.0 (May 16, 2013) ##
218
+
219
+ ### enhancements
220
+ * Use inclusion error message for invalid values (by [@lest](https://github.com/lest))
221
+ * Add `:only` and `except` options to the `Attribute#options` method. (by [@thehappycoder](https://github.com/thehappycoder) and [@randoum](https://github.com/randoum))
222
+ * ActiveRecord scopes. (by [@lest](https://github.com/lest), [@banyan](https://github.com/banyan) and [@nashby](https://github.com/nashby))
223
+ * Support for RailsAdmin (by [@drewda](https://github.com/drewda))
224
+
225
+ ### bug fix
226
+ * Return correct default value for enumerized attribute using `default_scope` with generated scope [@nashby](https://github.com/nashby)
227
+ * Allow either key or value as valid (by [aghull](https://github.com/aghull) and [@lest](https://github.com/lest))
228
+ * Use default enum value from db column (by [@lest](https://github.com/lest))
229
+
230
+ ## 0.5.1 (December 10, 2012) ##
231
+
232
+ ### bug fix
233
+
234
+ * Always return Enumerize::Set for multiple attributes (by [@nashby](https://github.com/nashby))
235
+
236
+ ## 0.5.0 (October 31, 2012) ##
237
+
238
+ The previous method of adding enumerize to a class was deprecated. Please use
239
+ `extend Enumerize` instead of `include Enumerize`.
240
+
241
+ ### enhancements
242
+ * SimpleForm support for multiple attributes. (by [@nashby](https://github.com/nashby))
243
+ * Formtastic support for multiple attributes. (by [@nashby](https://github.com/nashby))
244
+ * Array-like multiple attributes. (by [@lest](https://github.com/lest))
245
+
246
+ ## 0.4.0 (September 6, 2012) ##
247
+
248
+ Legacy support was dropped. The following versions are supported:
249
+
250
+ * Ruby 1.9.3+ (including JRuby and Rubinius)
251
+ * Rails 3.2+
252
+ * Formtastic 2.2+
253
+ * SimpleForm 2+
254
+ * Mongoid 3+
255
+
256
+ ### enhancements
257
+ * Ability to define predicate methods on enumerized object. (by [@lest](https://github.com/lest))
258
+
1
259
  ## 0.3.0 (July 9, 2012) ##
2
260
 
3
261
  ### enhancements
data/Gemfile CHANGED
@@ -1,13 +1,7 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- gem 'rake'
6
- gem 'minitest', '~> 3.1'
7
-
8
- gem 'activerecord', '~> 3.2.0'
9
- gem 'sqlite3'
1
+ eval_gemfile('Gemfile.global')
10
2
 
3
+ gem 'minitest', '~> 5.8'
4
+ gem 'rails', '5.1.4', require: false
5
+ gem 'activerecord-jdbcsqlite3-adapter', '~> 51.0', platform: :jruby
6
+ gem 'activerecord-jdbcpostgresql-adapter', '~> 51.0', platform: :jruby
11
7
  gem 'mongoid'
12
- gem 'simple_form'
13
- 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', '~> 1.3.6', :platform => [:ruby, :mswin, :mingw]
9
+ gem 'pg', '~> 0.21.0', :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'
@@ -0,0 +1,7 @@
1
+ eval_gemfile('Gemfile.global')
2
+
3
+ gem 'minitest', '~> 5.8'
4
+ gem 'rails', '4.2.8', :require => false
5
+ gem 'activerecord-jdbcsqlite3-adapter', '~> 1.3.0', platform: :jruby
6
+ gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.0', platform: :jruby
7
+ gem 'mongo_mapper'
data/Gemfile.rails42 ADDED
@@ -0,0 +1,7 @@
1
+ eval_gemfile('Gemfile.global')
2
+
3
+ gem 'minitest', '~> 5.8'
4
+ gem 'rails', '4.2.8', :require => false
5
+ gem 'activerecord-jdbcsqlite3-adapter', '~> 1.3.0', platform: :jruby
6
+ gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.0', platform: :jruby
7
+ gem 'mongoid', '~> 5.0'
data/Gemfile.rails50 ADDED
@@ -0,0 +1,7 @@
1
+ eval_gemfile('Gemfile.global')
2
+
3
+ gem 'minitest', '~> 5.8'
4
+ gem 'rails', '5.0.6', require: false
5
+ gem 'activerecord-jdbcsqlite3-adapter', '~> 51.0', platform: :jruby
6
+ gem 'activerecord-jdbcpostgresql-adapter', '~> 51.0', platform: :jruby
7
+ gem 'mongoid'
data/Gemfile.rails52 ADDED
@@ -0,0 +1,7 @@
1
+ eval_gemfile('Gemfile.global')
2
+
3
+ gem 'minitest', '~> 5.8'
4
+ gem 'rails', '5.2.0.rc1', require: false
5
+ gem 'activerecord-jdbcsqlite3-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'master', platform: :jruby
6
+ gem 'activerecord-jdbcpostgresql-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'master', platform: :jruby
7
+ gem 'mongoid', github: 'mongodb/mongoid'