enumerize 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +16 -6
- data/CHANGELOG.md +11 -0
- data/Gemfile +3 -2
- data/Gemfile.global +1 -0
- data/Gemfile.mongo_mapper +3 -2
- data/Gemfile.rails42 +3 -2
- data/Gemfile.rails51 +7 -0
- data/lib/enumerize/activerecord.rb +12 -0
- data/lib/enumerize/version.rb +3 -1
- data/test/activerecord_test.rb +45 -6
- data/test/base_test.rb +5 -5
- data/test/mongo_mapper_test.rb +1 -1
- data/test/mongoid_test.rb +1 -1
- data/test/sequel_test.rb +2 -2
- data/test/support/mock_controller.rb +4 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcc222d35f7bc7e96f344ebac473c10324a42bd9
|
4
|
+
data.tar.gz: 4509894cf1723e3df5403c8c93108c316b1ffbb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1237ba9ede67eefc02b235ec0b74ff2bc6774f89479c22e0e5733dba911b487449bf24e49e82a3be2623cfb432198d6cedf59425f26fab11e36c8c11c073769
|
7
|
+
data.tar.gz: 98234b48c034f98cdd43e2379b8ad277dbad8d68088b3cabdfffe71767584028be87ead75629db81fc036862743e16bb5554c680f75d3aa22e814fada961c113
|
data/.travis.yml
CHANGED
@@ -1,22 +1,32 @@
|
|
1
1
|
language: ruby
|
2
2
|
sudo: false
|
3
3
|
services:
|
4
|
+
- postgresql
|
4
5
|
- mongodb
|
5
6
|
gemfile:
|
6
7
|
- Gemfile
|
7
8
|
- Gemfile.rails42
|
9
|
+
- Gemfile.rails51
|
8
10
|
- Gemfile.mongo_mapper
|
9
11
|
rvm:
|
10
|
-
- 2.2.
|
12
|
+
- 2.2.7
|
11
13
|
- 2.3.3
|
12
|
-
-
|
13
|
-
- jruby-9.1.
|
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
|
14
23
|
matrix:
|
24
|
+
fast_finish: true
|
15
25
|
allow_failures:
|
16
|
-
-
|
17
|
-
|
26
|
+
- rvm: jruby-9.1.8.0
|
27
|
+
exclude:
|
18
28
|
- gemfile: Gemfile.mongo_mapper
|
19
|
-
|
29
|
+
env: DB=postgresql
|
20
30
|
branches:
|
21
31
|
only:
|
22
32
|
- master
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,17 @@
|
|
4
4
|
|
5
5
|
### bug fix
|
6
6
|
|
7
|
+
## 2.1.1 (May 1, 2017)
|
8
|
+
|
9
|
+
### enhancements
|
10
|
+
|
11
|
+
* Run tests with multiple DBs (SQLite and PostgreSQL). (by [tkawa](https://github.com/tkawa))
|
12
|
+
|
13
|
+
### bug fix
|
14
|
+
|
15
|
+
* Support deserialize and Rails 4.2 methods in the custom AR::Type class. (by [@lest](https://github.com/lest))
|
16
|
+
* Support dumping custom AR type to JSON. (by [@lest](https://github.com/lest))
|
17
|
+
|
7
18
|
## 2.1.0 (March 31, 2017)
|
8
19
|
|
9
20
|
### enhancements
|
data/Gemfile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
eval_gemfile('Gemfile.global')
|
2
2
|
|
3
3
|
gem 'minitest', '~> 5.8'
|
4
|
-
gem 'rails', '5.0.
|
4
|
+
gem 'rails', '5.0.2', require: false
|
5
5
|
gem 'activerecord-jdbcsqlite3-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'rails-5', platform: :jruby
|
6
|
-
gem '
|
6
|
+
gem 'activerecord-jdbcpostgresql-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'rails-5', platform: :jruby
|
7
|
+
gem 'mongoid'
|
data/Gemfile.global
CHANGED
data/Gemfile.mongo_mapper
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
eval_gemfile('Gemfile.global')
|
2
2
|
|
3
3
|
gem 'minitest', '~> 5.8'
|
4
|
-
gem 'rails', '4.2.
|
5
|
-
gem 'activerecord-jdbcsqlite3-adapter', :
|
4
|
+
gem 'rails', '4.2.8', :require => false
|
5
|
+
gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
|
6
|
+
gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
|
6
7
|
gem 'mongo_mapper'
|
data/Gemfile.rails42
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
eval_gemfile('Gemfile.global')
|
2
2
|
|
3
3
|
gem 'minitest', '~> 5.8'
|
4
|
-
gem 'rails', '4.2.
|
5
|
-
gem 'activerecord-jdbcsqlite3-adapter', :
|
4
|
+
gem 'rails', '4.2.8', :require => false
|
5
|
+
gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
|
6
|
+
gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
|
6
7
|
gem 'mongoid', '~> 5.0'
|
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'
|
@@ -78,6 +78,18 @@ module Enumerize
|
|
78
78
|
v = @attr.find_value(value)
|
79
79
|
v && v.value
|
80
80
|
end
|
81
|
+
|
82
|
+
alias type_cast_for_database serialize
|
83
|
+
|
84
|
+
def deserialize(value)
|
85
|
+
@attr.find_value(value)
|
86
|
+
end
|
87
|
+
|
88
|
+
alias type_cast_from_database deserialize
|
89
|
+
|
90
|
+
def as_json(options = nil)
|
91
|
+
{attr: @attr.name, subtype: @subtype}.as_json(options)
|
92
|
+
end
|
81
93
|
end
|
82
94
|
end
|
83
95
|
end
|
data/lib/enumerize/version.rb
CHANGED
data/test/activerecord_test.rb
CHANGED
@@ -1,11 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
require 'active_record'
|
3
5
|
require 'logger'
|
4
6
|
|
7
|
+
db = (ENV['DB'] || 'sqlite3').to_sym
|
8
|
+
|
5
9
|
silence_warnings do
|
6
10
|
ActiveRecord::Migration.verbose = false
|
7
11
|
ActiveRecord::Base.logger = Logger.new(nil)
|
8
|
-
ActiveRecord::Base.
|
12
|
+
ActiveRecord::Base.configurations = {
|
13
|
+
'sqlite3' => {
|
14
|
+
'adapter' => 'sqlite3',
|
15
|
+
'database' => ':memory:'
|
16
|
+
},
|
17
|
+
'postgresql' => {
|
18
|
+
'adapter' => 'postgresql',
|
19
|
+
'username' => ENV['DB_USER'],
|
20
|
+
'password' => ENV['DB_PASSD'],
|
21
|
+
'database' => 'enumerize_test'
|
22
|
+
},
|
23
|
+
'postgresql_master' => {
|
24
|
+
'adapter' => 'postgresql',
|
25
|
+
'username' => ENV['DB_USER'],
|
26
|
+
'password' => ENV['DB_PASS'],
|
27
|
+
'database' => 'template1',
|
28
|
+
'schema_search_path' => 'public'
|
29
|
+
}
|
30
|
+
}
|
31
|
+
if db == :postgresql
|
32
|
+
ActiveRecord::Base.establish_connection(:postgresql_master)
|
33
|
+
ActiveRecord::Base.connection.recreate_database('enumerize_test')
|
34
|
+
end
|
35
|
+
|
36
|
+
ActiveRecord::Base.establish_connection(db)
|
9
37
|
end
|
10
38
|
|
11
39
|
ActiveRecord::Base.connection.instance_eval do
|
@@ -79,7 +107,7 @@ describe Enumerize::ActiveRecordSupport do
|
|
79
107
|
it 'sets nil if invalid value is passed' do
|
80
108
|
user = User.new
|
81
109
|
user.sex = :invalid
|
82
|
-
user.sex.
|
110
|
+
user.sex.must_be_nil
|
83
111
|
end
|
84
112
|
|
85
113
|
it 'saves value' do
|
@@ -181,7 +209,7 @@ describe Enumerize::ActiveRecordSupport do
|
|
181
209
|
it 'stores nil when empty string assigned' do
|
182
210
|
user = User.new
|
183
211
|
user.role = ''
|
184
|
-
user.read_attribute(:role).
|
212
|
+
user.read_attribute(:role).must_be_nil
|
185
213
|
end
|
186
214
|
|
187
215
|
it 'supports multiple attributes' do
|
@@ -379,6 +407,14 @@ describe Enumerize::ActiveRecordSupport do
|
|
379
407
|
assert_equal [1, 2], YAML.load(user.changes.to_yaml)[:status]
|
380
408
|
end
|
381
409
|
|
410
|
+
it 'does not change by the practical same value' do
|
411
|
+
user = User.create!(status: 'active')
|
412
|
+
user.reload
|
413
|
+
user.status = 'active'
|
414
|
+
|
415
|
+
user.changes.must_be_empty
|
416
|
+
end
|
417
|
+
|
382
418
|
it 'allows using update_all' do
|
383
419
|
User.delete_all
|
384
420
|
|
@@ -467,15 +503,18 @@ describe Enumerize::ActiveRecordSupport do
|
|
467
503
|
|
468
504
|
User.update_all(status: :foo)
|
469
505
|
user.reload
|
470
|
-
user.status.
|
506
|
+
user.status.must_be_nil
|
471
507
|
end
|
472
508
|
|
473
509
|
it 'supports AR types serialization' do
|
474
|
-
User.delete_all
|
475
|
-
|
476
510
|
type = User.type_for_attribute('status')
|
477
511
|
type.must_be_instance_of Enumerize::ActiveRecordSupport::Type
|
478
512
|
serialized = type.serialize('blocked')
|
479
513
|
serialized.must_equal 2
|
480
514
|
end
|
515
|
+
|
516
|
+
it 'has AR type itself JSON serializable' do
|
517
|
+
type = User.type_for_attribute('status')
|
518
|
+
type.as_json['attr'].must_equal 'status'
|
519
|
+
end
|
481
520
|
end
|
data/test/base_test.rb
CHANGED
@@ -15,7 +15,7 @@ describe Enumerize::Base do
|
|
15
15
|
|
16
16
|
it 'returns nil when not set' do
|
17
17
|
klass.enumerize(:foo, :in => [:a, :b])
|
18
|
-
object.foo.
|
18
|
+
object.foo.must_be_nil
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'returns value that was set' do
|
@@ -37,7 +37,7 @@ describe Enumerize::Base do
|
|
37
37
|
it 'returns nil as translation when value is nil' do
|
38
38
|
store_translations(:en, :enumerize => {:foo => {:a => 'a text'}}) do
|
39
39
|
klass.enumerize(:foo, :in => [:a, :b])
|
40
|
-
object.foo_text.
|
40
|
+
object.foo_text.must_be_nil
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -120,7 +120,7 @@ describe Enumerize::Base do
|
|
120
120
|
klass.enumerize(:foo, :in => %w[a b])
|
121
121
|
subklass.enumerize(:bar, :in => %w[c d])
|
122
122
|
|
123
|
-
klass.enumerized_attributes[:bar].
|
123
|
+
klass.enumerized_attributes[:bar].must_be_nil
|
124
124
|
end
|
125
125
|
|
126
126
|
it 'adds new parent class attributes to subclass' do
|
@@ -132,7 +132,7 @@ describe Enumerize::Base do
|
|
132
132
|
it 'stores nil value' do
|
133
133
|
klass.enumerize(:foo, :in => [:a, :b])
|
134
134
|
object.foo = nil
|
135
|
-
object.instance_variable_get(:@foo).
|
135
|
+
object.instance_variable_get(:@foo).must_be_nil
|
136
136
|
end
|
137
137
|
|
138
138
|
it 'casts value to string for validation' do
|
@@ -144,7 +144,7 @@ describe Enumerize::Base do
|
|
144
144
|
it "doesn't cast nil to string for validation" do
|
145
145
|
klass.enumerize(:foo, :in => [:a, :b])
|
146
146
|
object.foo = nil
|
147
|
-
object.read_attribute_for_validation(:foo).
|
147
|
+
object.read_attribute_for_validation(:foo).must_be_nil
|
148
148
|
end
|
149
149
|
|
150
150
|
it 'calls super in the accessor method' do
|
data/test/mongo_mapper_test.rb
CHANGED
data/test/mongoid_test.rb
CHANGED
data/test/sequel_test.rb
CHANGED
@@ -71,7 +71,7 @@ module SequelTest
|
|
71
71
|
it 'sets nil if invalid value is passed' do
|
72
72
|
user = User.new
|
73
73
|
user.sex = :invalid
|
74
|
-
user.sex.
|
74
|
+
user.sex.must_be_nil
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'saves value' do
|
@@ -147,7 +147,7 @@ module SequelTest
|
|
147
147
|
it 'stores nil when empty string assigned' do
|
148
148
|
user = User.new
|
149
149
|
user.role = ''
|
150
|
-
user.values[:role].
|
150
|
+
user.values[:role].must_be_nil
|
151
151
|
end
|
152
152
|
|
153
153
|
it 'supports multiple attributes' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enumerize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Nartimov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- Gemfile.global
|
40
40
|
- Gemfile.mongo_mapper
|
41
41
|
- Gemfile.rails42
|
42
|
+
- Gemfile.rails51
|
42
43
|
- MIT-LICENSE
|
43
44
|
- README.md
|
44
45
|
- Rakefile
|