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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e11fc29306be657be93429d810d7d38d15633f7
4
- data.tar.gz: 2d2f0590533e31c71432f9f1a35e0cf8e8120f50
3
+ metadata.gz: fcc222d35f7bc7e96f344ebac473c10324a42bd9
4
+ data.tar.gz: 4509894cf1723e3df5403c8c93108c316b1ffbb1
5
5
  SHA512:
6
- metadata.gz: d1a583881a025b925000573c7602bbdd118485544c4fa5f3b08cc740c12e780b297013b5ccee04b4d49a1d9fbb93e7691ac0cc5f9c203fefc587cba9f35cccc3
7
- data.tar.gz: 738971e9f0f3b253df6ae23c9d36fdf628b543cfafc8304b90b871f896b131ff491d35a1b92e81f6d34b4f3d69f97afa7798ddf6adb80a99a9835c0ed410c084
6
+ metadata.gz: b1237ba9ede67eefc02b235ec0b74ff2bc6774f89479c22e0e5733dba911b487449bf24e49e82a3be2623cfb432198d6cedf59425f26fab11e36c8c11c073769
7
+ data.tar.gz: 98234b48c034f98cdd43e2379b8ad277dbad8d68088b3cabdfffe71767584028be87ead75629db81fc036862743e16bb5554c680f75d3aa22e814fada961c113
@@ -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.6
12
+ - 2.2.7
11
13
  - 2.3.3
12
- - ruby-head
13
- - jruby-9.1.6.0
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
- - gemfile: Gemfile.rails42
17
- rvm: ruby-head
26
+ - rvm: jruby-9.1.8.0
27
+ exclude:
18
28
  - gemfile: Gemfile.mongo_mapper
19
- rvm: ruby-head
29
+ env: DB=postgresql
20
30
  branches:
21
31
  only:
22
32
  - master
@@ -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.0', require: false
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 'mongoid', github: 'mongodb/mongoid'
6
+ gem 'activerecord-jdbcpostgresql-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'rails-5', platform: :jruby
7
+ gem 'mongoid'
@@ -6,6 +6,7 @@ gem 'rake'
6
6
  gem 'rspec', :require => false
7
7
 
8
8
  gem 'sqlite3', :platform => [:ruby, :mswin, :mingw]
9
+ gem 'pg', :platform => [:ruby, :mswin, :mingw]
9
10
  gem 'sequel'
10
11
 
11
12
  platforms :rbx do
@@ -1,6 +1,7 @@
1
1
  eval_gemfile('Gemfile.global')
2
2
 
3
3
  gem 'minitest', '~> 5.8'
4
- gem 'rails', '4.2.7', :require => false
5
- gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
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'
@@ -1,6 +1,7 @@
1
1
  eval_gemfile('Gemfile.global')
2
2
 
3
3
  gem 'minitest', '~> 5.8'
4
- gem 'rails', '4.2.7', :require => false
5
- gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
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'
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Enumerize
2
- VERSION = "2.1.0"
4
+ VERSION = '2.1.1'
3
5
  end
@@ -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.establish_connection(:adapter => "sqlite3", :database => ":memory:")
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.must_equal nil
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).must_equal nil
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.must_equal nil
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
@@ -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.must_equal nil
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.must_equal nil
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].must_equal nil
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).must_equal nil
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).must_equal nil
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
@@ -29,7 +29,7 @@ describe Enumerize do
29
29
  it 'sets nil if invalid value is passed' do
30
30
  user = model.new
31
31
  user.sex = :invalid
32
- user.sex.must_equal nil
32
+ user.sex.must_be_nil
33
33
  end
34
34
 
35
35
  it 'saves value' do
@@ -32,7 +32,7 @@ describe Enumerize do
32
32
  it 'sets nil if invalid value is passed' do
33
33
  user = model.new
34
34
  user.sex = :invalid
35
- user.sex.must_equal nil
35
+ user.sex.must_be_nil
36
36
  end
37
37
 
38
38
  it 'saves value' do
@@ -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.must_equal nil
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].must_equal nil
150
+ user.values[:role].must_be_nil
151
151
  end
152
152
 
153
153
  it 'supports multiple attributes' do
@@ -22,4 +22,8 @@ class MockController
22
22
  end
23
23
 
24
24
  def hash_for_users_path(*); end
25
+
26
+ def polymorphic_mappings
27
+ {}
28
+ end
25
29
  end
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.0
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-03-31 00:00:00.000000000 Z
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