persistent_enum 1.2.6 → 1.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/gem-push.yml +31 -0
- data/.github/workflows/test.yml +84 -0
- data/lib/persistent_enum/version.rb +1 -1
- data/lib/persistent_enum.rb +10 -2
- data/spec/support/helpers/database_helper.rb +12 -6
- metadata +4 -3
- data/.circleci/config.yml +0 -190
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0456dff106c050a619565ac971ca85003b9e37cab527e92ff35e31d8022667a
|
4
|
+
data.tar.gz: 34773166cd40c345af7e1734c66a28d9418d264744da9e8937d0200a4de88c91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d847f2b807bc1179866bfbba7cc3498e07869f5c81255df7a78a9f76ed86ffa1ecf36f3ec56e0c39924bd923caac9d40f679cad1f01efbaca7c8b51dcfe45944
|
7
|
+
data.tar.gz: 9d1e4034c3917f8828c567ba458a5e9046ece0aa07e3608a5ed1d75fad2d725045450d2a5e3443dfc25a3ee78a0316459bd27149ff8a4cab8d8df541ac5e88c9
|
@@ -0,0 +1,31 @@
|
|
1
|
+
name: Publish Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ "master" ]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
name: Build + Publish
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
permissions:
|
12
|
+
contents: read
|
13
|
+
packages: write
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v3
|
17
|
+
- name: Set up Ruby 2.7
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: 2.7
|
21
|
+
|
22
|
+
- name: Publish to RubyGems
|
23
|
+
run: |
|
24
|
+
mkdir -p $HOME/.gem
|
25
|
+
touch $HOME/.gem/credentials
|
26
|
+
chmod 0600 $HOME/.gem/credentials
|
27
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
28
|
+
gem build *.gemspec
|
29
|
+
gem push *.gem
|
30
|
+
env:
|
31
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
@@ -0,0 +1,84 @@
|
|
1
|
+
name: Run Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches: "**"
|
6
|
+
|
7
|
+
permissions:
|
8
|
+
contents: read
|
9
|
+
checks: write
|
10
|
+
pull-requests: write
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
test:
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
|
16
|
+
services:
|
17
|
+
mysql:
|
18
|
+
image: mysql:5.7
|
19
|
+
ports:
|
20
|
+
- "3306:3306"
|
21
|
+
env:
|
22
|
+
MYSQL_DATABASE: persistent_enum_test
|
23
|
+
MYSQL_USER: user
|
24
|
+
MYSQL_PASSWORD: password
|
25
|
+
MYSQL_ROOT_PASSWORD: rootpassword
|
26
|
+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
|
27
|
+
postgres:
|
28
|
+
image: postgres:13-alpine
|
29
|
+
ports:
|
30
|
+
- "5432:5432"
|
31
|
+
env:
|
32
|
+
POSTGRES_DB: persistent_enum_test
|
33
|
+
POSTGRES_USER: user
|
34
|
+
POSTGRES_PASSWORD: password
|
35
|
+
|
36
|
+
strategy:
|
37
|
+
fail-fast: false
|
38
|
+
matrix:
|
39
|
+
rails-version: ['5.2', '6.1', '7.0']
|
40
|
+
database: ['mysql', 'postgresql', 'sqlite']
|
41
|
+
include:
|
42
|
+
- database: mysql
|
43
|
+
database-url: "mysql2://user:password@127.0.0.1:3306/persistent_enum_test"
|
44
|
+
- database: postgresql
|
45
|
+
database-url: "postgres://user:password@localhost:5432/persistent_enum_test"
|
46
|
+
- database: sqlite
|
47
|
+
database-url: "sqlite3::memory:"
|
48
|
+
- rails-version: '5.2'
|
49
|
+
ruby-version: '2.7'
|
50
|
+
bundle-gemfile: gemfiles/rails_5_2.gemfile
|
51
|
+
- rails-version: '6.1'
|
52
|
+
ruby-version: '3.0'
|
53
|
+
bundle-gemfile: gemfiles/rails_6_1.gemfile
|
54
|
+
- rails-version: '7.0'
|
55
|
+
ruby-version: '3.2'
|
56
|
+
bundle-gemfile: gemfiles/rails_7_0.gemfile
|
57
|
+
|
58
|
+
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
59
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.bundle-gemfile }}
|
60
|
+
DATABASE_URL: ${{ matrix.database-url }}
|
61
|
+
TEST_DATABASE_ENVIRONMENT: ${{ matrix.database }}
|
62
|
+
|
63
|
+
steps:
|
64
|
+
- uses: actions/checkout@v3
|
65
|
+
- name: Set up Ruby
|
66
|
+
uses: ruby/setup-ruby@v1
|
67
|
+
with:
|
68
|
+
ruby-version: ${{ matrix.ruby-version }}
|
69
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
70
|
+
- name: Run tests
|
71
|
+
run: bundle exec rspec --profile 10 --format RspecJunitFormatter --out test_results/rspec.xml --format progress
|
72
|
+
- name: Upload result
|
73
|
+
uses: actions/upload-artifact@v3
|
74
|
+
if: always()
|
75
|
+
with:
|
76
|
+
name: rspec_{{ matrix.rails-version }}-${{ matrix.database }}.xml
|
77
|
+
path: test_results/rspec.xml
|
78
|
+
- name: Test Report
|
79
|
+
uses: dorny/test-reporter@v1
|
80
|
+
if: always()
|
81
|
+
with:
|
82
|
+
name: Rspec Tests - Rails ${{ matrix.rails-version }} - ${{ matrix.database }}
|
83
|
+
path: test_results/rspec.xml
|
84
|
+
reporter: java-junit
|
data/lib/persistent_enum.rb
CHANGED
@@ -16,6 +16,14 @@ module PersistentEnum
|
|
16
16
|
class EnumTableInvalid < RuntimeError; end
|
17
17
|
class MissingEnumTypeError < RuntimeError; end
|
18
18
|
|
19
|
+
MISSING_DATABASE_ERRORS =
|
20
|
+
begin
|
21
|
+
errs = [ActiveRecord::NoDatabaseError]
|
22
|
+
# Added with Rails 7
|
23
|
+
errs << ActiveRecord::DatabaseConnectionError if ActiveRecord.const_defined?(:DatabaseConnectionError)
|
24
|
+
errs.freeze
|
25
|
+
end
|
26
|
+
|
19
27
|
module ClassMethods
|
20
28
|
def acts_as_enum(required_constants, name_attr: :name, sql_enum_type: nil, &constant_init_block)
|
21
29
|
include ActsAsEnum
|
@@ -156,7 +164,7 @@ module PersistentEnum
|
|
156
164
|
else
|
157
165
|
puts "Database table for model #{model.name} doesn't exist, no constants cached."
|
158
166
|
end
|
159
|
-
rescue
|
167
|
+
rescue *MISSING_DATABASE_ERRORS
|
160
168
|
puts "Database for model #{model.name} doesn't exist, no constants cached."
|
161
169
|
end
|
162
170
|
|
@@ -180,7 +188,7 @@ module PersistentEnum
|
|
180
188
|
unless model.table_exists?
|
181
189
|
raise EnumTableInvalid.new("Database table for model #{model.name} doesn't exist")
|
182
190
|
end
|
183
|
-
rescue
|
191
|
+
rescue *MISSING_DATABASE_ERRORS
|
184
192
|
raise EnumTableInvalid.new("Database for model #{model.name} doesn't exist")
|
185
193
|
end
|
186
194
|
|
@@ -9,13 +9,19 @@ module DatabaseHelper
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.initialize_database
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
if (url = ENV['DATABASE_URL'])
|
13
|
+
db_config = url
|
14
|
+
else
|
15
|
+
db_config_path = File.join(File.dirname(__FILE__), '../config/database.yml')
|
16
|
+
db_config_data = File.read(db_config_path)
|
17
|
+
db_config_data = ERB.new(db_config_data).result
|
18
|
+
db_config = YAML.safe_load(db_config_data)
|
19
|
+
raise 'Test database configuration missing' unless db_config[db_env]
|
17
20
|
|
18
|
-
|
21
|
+
db_config = db_config[db_env]
|
22
|
+
end
|
23
|
+
|
24
|
+
ActiveRecord::Base.establish_connection(db_config)
|
19
25
|
|
20
26
|
if ENV['DEBUG']
|
21
27
|
ActiveRecord::Base.logger = Logger.new(STDERR)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: persistent_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iKnow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -185,7 +185,8 @@ executables: []
|
|
185
185
|
extensions: []
|
186
186
|
extra_rdoc_files: []
|
187
187
|
files:
|
188
|
-
- ".
|
188
|
+
- ".github/workflows/gem-push.yml"
|
189
|
+
- ".github/workflows/test.yml"
|
189
190
|
- ".gitignore"
|
190
191
|
- ".rspec"
|
191
192
|
- Appraisals
|
data/.circleci/config.yml
DELETED
@@ -1,190 +0,0 @@
|
|
1
|
-
version: 2.1
|
2
|
-
|
3
|
-
executors:
|
4
|
-
ruby-sqlite: &ruby
|
5
|
-
parameters: &ruby_params
|
6
|
-
ruby-version:
|
7
|
-
type: string
|
8
|
-
default: "2.7"
|
9
|
-
gemfile:
|
10
|
-
type: string
|
11
|
-
default: "Gemfile"
|
12
|
-
environment:
|
13
|
-
TEST_DATABASE_ENVIRONMENT: sqlite3
|
14
|
-
docker:
|
15
|
-
- &ruby_docker_ruby
|
16
|
-
image: circleci/ruby:<< parameters.ruby-version >>
|
17
|
-
environment:
|
18
|
-
BUNDLE_JOBS: 3
|
19
|
-
BUNDLE_RETRY: 3
|
20
|
-
BUNDLE_PATH: vendor/bundle
|
21
|
-
RAILS_ENV: test
|
22
|
-
BUNDLE_GEMFILE: << parameters.gemfile >>
|
23
|
-
ruby-pg:
|
24
|
-
<<: *ruby
|
25
|
-
parameters:
|
26
|
-
<<: *ruby_params
|
27
|
-
pg-version:
|
28
|
-
type: string
|
29
|
-
default: "12"
|
30
|
-
environment:
|
31
|
-
TEST_DATABASE_ENVIRONMENT: postgresql
|
32
|
-
PGHOST: 127.0.0.1
|
33
|
-
PGUSER: eikaiwa
|
34
|
-
docker:
|
35
|
-
- *ruby_docker_ruby
|
36
|
-
- image: circleci/postgres:<< parameters.pg-version >>-alpine
|
37
|
-
environment:
|
38
|
-
POSTGRES_USER: eikaiwa
|
39
|
-
POSTGRES_DB: persistent_enum_test
|
40
|
-
POSTGRES_PASSWORD: ""
|
41
|
-
ruby-mysql:
|
42
|
-
<<: *ruby
|
43
|
-
parameters:
|
44
|
-
<<: *ruby_params
|
45
|
-
mysql-version:
|
46
|
-
type: string
|
47
|
-
default: "5.7"
|
48
|
-
environment:
|
49
|
-
TEST_DATABASE_ENVIRONMENT: mysql2
|
50
|
-
MYSQL_HOST: 127.0.0.1
|
51
|
-
MYSQL_USER: root
|
52
|
-
docker:
|
53
|
-
- *ruby_docker_ruby
|
54
|
-
- image: circleci/mysql:<< parameters.mysql-version >>
|
55
|
-
environment:
|
56
|
-
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
57
|
-
MYSQL_ROOT_PASSWORD: ''
|
58
|
-
MYSQL_DATABASE: persistent_enum_test
|
59
|
-
|
60
|
-
jobs:
|
61
|
-
test:
|
62
|
-
parameters:
|
63
|
-
executor-name:
|
64
|
-
type: string
|
65
|
-
ruby-version:
|
66
|
-
type: string
|
67
|
-
gemfile:
|
68
|
-
type: string
|
69
|
-
database-steps:
|
70
|
-
type: steps
|
71
|
-
default: []
|
72
|
-
executor:
|
73
|
-
name: << parameters.executor-name >>
|
74
|
-
ruby-version: << parameters.ruby-version >>
|
75
|
-
gemfile: << parameters.gemfile >>
|
76
|
-
parallelism: 1
|
77
|
-
steps:
|
78
|
-
- checkout
|
79
|
-
|
80
|
-
- run:
|
81
|
-
# Remove the non-appraisal gemfile for safety: we never want to use it.
|
82
|
-
name: Prepare bundler
|
83
|
-
command: bundle -v && rm Gemfile
|
84
|
-
|
85
|
-
- run:
|
86
|
-
name: Compute a gemfile lock
|
87
|
-
command: bundle lock && cp "${BUNDLE_GEMFILE}.lock" /tmp/gem-lock
|
88
|
-
|
89
|
-
- restore_cache:
|
90
|
-
keys:
|
91
|
-
- persistent_enum-<< parameters.ruby-version >>-{{ checksum "/tmp/gem-lock" }}
|
92
|
-
- persistent_enum-
|
93
|
-
|
94
|
-
- run:
|
95
|
-
name: Bundle Install
|
96
|
-
command: bundle check || bundle install
|
97
|
-
|
98
|
-
- save_cache:
|
99
|
-
key: persistent_enum-<< parameters.ruby-version >>-{{ checksum "/tmp/gem-lock" }}
|
100
|
-
paths:
|
101
|
-
- vendor/bundle
|
102
|
-
|
103
|
-
- steps: << parameters.database-steps >>
|
104
|
-
|
105
|
-
- run:
|
106
|
-
name: Run rspec
|
107
|
-
command: bundle exec rspec --profile 10 --format RspecJunitFormatter --out test_results/rspec.xml --format progress
|
108
|
-
|
109
|
-
- store_test_results:
|
110
|
-
path: test_results
|
111
|
-
|
112
|
-
publish:
|
113
|
-
executor: ruby-sqlite
|
114
|
-
steps:
|
115
|
-
- checkout
|
116
|
-
- run:
|
117
|
-
name: Setup Rubygems
|
118
|
-
command: |
|
119
|
-
mkdir ~/.gem &&
|
120
|
-
echo -e "---\r\n:rubygems_api_key: $RUBYGEMS_API_KEY" > ~/.gem/credentials &&
|
121
|
-
chmod 0600 ~/.gem/credentials
|
122
|
-
- run:
|
123
|
-
name: Publish to Rubygems
|
124
|
-
command: |
|
125
|
-
gem build persistent_enum.gemspec
|
126
|
-
gem push persistent_enum-*.gem
|
127
|
-
|
128
|
-
workflows:
|
129
|
-
version: 2
|
130
|
-
build:
|
131
|
-
jobs:
|
132
|
-
- test:
|
133
|
-
name: 'ruby 2.7 rails 5.2 sqlite'
|
134
|
-
executor-name: ruby-sqlite
|
135
|
-
ruby-version: "2.7"
|
136
|
-
gemfile: gemfiles/rails_5_2.gemfile
|
137
|
-
- test:
|
138
|
-
name: 'ruby 3.0 rails 6.1 sqlite'
|
139
|
-
executor-name: ruby-sqlite
|
140
|
-
ruby-version: "3.0"
|
141
|
-
gemfile: gemfiles/rails_6_1.gemfile
|
142
|
-
- test:
|
143
|
-
name: 'ruby 3.0 rails 7.0 sqlite'
|
144
|
-
executor-name: ruby-sqlite
|
145
|
-
ruby-version: "3.0"
|
146
|
-
gemfile: gemfiles/rails_7_0.gemfile
|
147
|
-
- test:
|
148
|
-
name: 'ruby 2.7 rails 5.2 pg'
|
149
|
-
executor-name: ruby-pg
|
150
|
-
ruby-version: "2.7"
|
151
|
-
gemfile: gemfiles/rails_5_2.gemfile
|
152
|
-
database-steps: &pg_wait
|
153
|
-
- run: dockerize -wait tcp://localhost:5432 -timeout 1m
|
154
|
-
- test:
|
155
|
-
name: 'ruby 3.0 rails 6.1 pg'
|
156
|
-
executor-name: ruby-pg
|
157
|
-
ruby-version: "3.0"
|
158
|
-
gemfile: gemfiles/rails_6_1.gemfile
|
159
|
-
database-steps: *pg_wait
|
160
|
-
- test:
|
161
|
-
name: 'ruby 3.0 rails 7.0 pg'
|
162
|
-
executor-name: ruby-pg
|
163
|
-
ruby-version: "3.0"
|
164
|
-
gemfile: gemfiles/rails_7_0.gemfile
|
165
|
-
database-steps: *pg_wait
|
166
|
-
- test:
|
167
|
-
name: 'ruby 2.7 rails 5.2 mysql'
|
168
|
-
executor-name: ruby-mysql
|
169
|
-
ruby-version: "2.7"
|
170
|
-
gemfile: gemfiles/rails_5_2.gemfile
|
171
|
-
database-steps: &mysql_wait
|
172
|
-
- run: dockerize -wait tcp://localhost:3306 -timeout 1m
|
173
|
-
- test:
|
174
|
-
name: 'ruby 3.0 rails 6.1 mysql'
|
175
|
-
executor-name: ruby-mysql
|
176
|
-
ruby-version: "3.0"
|
177
|
-
gemfile: gemfiles/rails_6_1.gemfile
|
178
|
-
database-steps: *mysql_wait
|
179
|
-
- test:
|
180
|
-
name: 'ruby 3.0 rails 7.0 mysql'
|
181
|
-
executor-name: ruby-mysql
|
182
|
-
ruby-version: "3.0"
|
183
|
-
gemfile: gemfiles/rails_7_0.gemfile
|
184
|
-
database-steps: *mysql_wait
|
185
|
-
- publish:
|
186
|
-
filters:
|
187
|
-
branches:
|
188
|
-
only: master
|
189
|
-
tags:
|
190
|
-
ignore: /.*/
|