enum_help 0.0.17 → 0.0.18

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
- SHA1:
3
- metadata.gz: 130730a1ec4c32004257bbe7546178ca2ca3471f
4
- data.tar.gz: 7b23d6acc6e7bb1da3a6d4d0072e9393b1f0c516
2
+ SHA256:
3
+ metadata.gz: 6b1fb56c71d55485d1b9c413179c4ec402c4b3ea0b3e9ee362b213122f6fdc6c
4
+ data.tar.gz: 2e105e8b000e82fc026ebf56aecbd1de97ac944b8f20294615af88efaf95c49c
5
5
  SHA512:
6
- metadata.gz: 7055d72e832d0c0f8bb9ca85d09845c70fdfa7652729e87f3cf326c5354895a882ff6d9bbca56249adeb99d25cddd03deb2ebcb67c4d4fe1542cdbaa50124e4e
7
- data.tar.gz: 09a863d5f602f332def876357162829754c273e839fef703da6a256c1795f193063e85ee5696a82732aa005338ade9b25b7cc6dfd11fb74564cffbce437666fc
6
+ metadata.gz: e4f0adcc0a7829ad4d44449eb930e76eed390ea39037f34fabcd640bff615a02ce0b63f6910264f532798381b58527eabf4392b64b77957bce28faf05f494a8a
7
+ data.tar.gz: ca449b158ab5a0c9a487e95300d0ad91b8581afda1dd28373bd29fb03ceb6a1d94977c0cb0a0ab38fbff462ce34f9807fb22467833313396e493cfdb387df5e5
@@ -0,0 +1,44 @@
1
+ name: CI
2
+
3
+ on:
4
+ - push
5
+ - pull_request
6
+
7
+ jobs:
8
+ test:
9
+ runs-on: ubuntu-latest
10
+ strategy:
11
+ fail-fast: false
12
+ matrix:
13
+ ruby-version:
14
+ - head
15
+ - 3.1
16
+ - "3.0"
17
+ - 2.7
18
+ - 2.6
19
+ rails-version:
20
+ - "edge"
21
+ - "~> 7.0.1"
22
+ - "~> 6.1.4"
23
+ - "~> 6.0.4"
24
+ - "~> 5.2.6"
25
+ exclude:
26
+ - ruby-version: head
27
+ rails-version: "~> 5.2.6"
28
+ - ruby-version: 3.1
29
+ rails-version: "~> 5.2.6"
30
+ - ruby-version: "3.0"
31
+ rails-version: "~> 5.2.6"
32
+ - ruby-version: 2.6
33
+ rails-version: "edge"
34
+ - ruby-version: 2.6
35
+ rails-version: "~> 7.0.1"
36
+ env:
37
+ RAILS_VERSION: "${{ matrix.rails-version }}"
38
+ steps:
39
+ - uses: actions/checkout@v2
40
+ - uses: ruby/setup-ruby@v1
41
+ with:
42
+ ruby-version: "${{ matrix.ruby-version }}"
43
+ bundler-cache: true
44
+ - run: bundle exec rspec
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --profile 3
3
+ --format documentation
data/Gemfile CHANGED
@@ -2,3 +2,17 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in enum_help.gemspec
4
4
  gemspec
5
+
6
+ gem 'bundler'
7
+ gem 'rake'
8
+ gem 'rspec'
9
+ gem 'sqlite3'
10
+
11
+ case version = ENV['RAILS_VERSION']
12
+ when nil
13
+ gem 'rails', '~> 7.0'
14
+ when 'edge'
15
+ gem 'rails', github: 'rails/rails'
16
+ else
17
+ gem 'rails', version
18
+ end
data/README.md CHANGED
@@ -88,7 +88,7 @@ In `_form.html.erb` using `simple_form`:
88
88
  <%= f.input :status %>
89
89
  ```
90
90
 
91
- This will generate select field with translations automaticlly.
91
+ This will generate select field with translations automatically.
92
92
 
93
93
  And if you want to generate select except some values, then you can pass a collection option.
94
94
 
@@ -106,7 +106,7 @@ e.g.
106
106
  <%= f.input :status, as: :string %>
107
107
  ```
108
108
 
109
- From version 0.0.10, enum_help can automaticlly generate radio buttons with i18n labels.
109
+ From version 0.0.10, enum_help can automatically generate radio buttons with i18n labels.
110
110
 
111
111
  e.g.
112
112
  ```erb
@@ -133,7 +133,7 @@ zh-cn:
133
133
 
134
134
  ## Notice
135
135
  If you want to use enum feature, field of your table can't be named with `reference`.
136
- When it is named with 'reference' and define enum in model file, there will be raise an error as below:
136
+ When it is named with 'reference' and define enum in model file, there will be raised an error as below:
137
137
 
138
138
  NoMethodError: super: no superclass method `enum' for...
139
139
 
@@ -146,6 +146,7 @@ Thanks for all the [contributors](https://github.com/zmbacker/enum_help/graphs/c
146
146
 
147
147
  1. Fork it ( http://github.com/zmbacker/enum_help/fork )
148
148
  2. Create your feature branch (`git checkout -b my-new-feature`)
149
- 3. Commit your changes (`git commit -am 'Add some feature'`)
150
- 4. Push to the branch (`git push origin my-new-feature`)
151
- 5. Create new Pull Request
149
+ 3. Run test `rspec`
150
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
151
+ 5. Push to the branch (`git push origin my-new-feature`)
152
+ 6. Create new Pull Request
data/Rakefile CHANGED
@@ -1 +1,2 @@
1
1
  require "bundler/gem_tasks"
2
+ task :default => :spec
data/enum_help.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'enum_help/version'
4
+ require "enum_help/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "enum_help"
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["zm.backer@gmail.com"]
11
11
  spec.summary = %q{ Extends of ActiveRecord::Enum, which can used in simple_form and internationalization }
12
12
  spec.description = %q{ Help ActiveRecord::Enum feature to work fine with I18n and simple_form. }
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/zmbacker/enum_help"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -18,8 +18,5 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.5"
22
- spec.add_development_dependency "rake"
23
-
24
21
  spec.add_dependency "activesupport", ">= 3.0.0"
25
22
  end
@@ -2,12 +2,26 @@ module EnumHelp
2
2
 
3
3
  module I18n
4
4
 
5
- # overwrite the enum method
6
- def enum( definitions )
7
- super( definitions )
8
- definitions.each do |name, _|
9
- Helper.define_attr_i18n_method(self, name)
10
- Helper.define_collection_i18n_method(self, name)
5
+ if ActiveRecord::VERSION::MAJOR == 7
6
+ # overwrite the enum method
7
+ def enum(name = nil, values = nil, **options)
8
+ super(name, values, **options)
9
+
10
+ definitions = options.slice!(:_prefix, :_suffix, :_scopes, :_default)
11
+ definitions.each do |name, _|
12
+ Helper.define_attr_i18n_method(self, name)
13
+ Helper.define_collection_i18n_method(self, name)
14
+ end
15
+ end
16
+ end
17
+ if ActiveRecord::VERSION::MAJOR < 7
18
+ # overwrite the enum method
19
+ def enum( definitions )
20
+ super( definitions )
21
+ definitions.each do |name, _|
22
+ Helper.define_attr_i18n_method(self, name)
23
+ Helper.define_collection_i18n_method(self, name)
24
+ end
11
25
  end
12
26
  end
13
27
 
@@ -1,3 +1,3 @@
1
1
  module EnumHelp
2
- VERSION = "0.0.17"
2
+ VERSION = "0.0.18"
3
3
  end
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+
3
+ EnumHelp::Railtie.initializers.each(&:run)
4
+
5
+ class User < ActiveRecord::Base
6
+ if ActiveRecord.version < Gem::Version.new('6.1')
7
+ enum gender: [:male, :female]
8
+ else
9
+ enum gender: [:male, :female], _default: :male
10
+ end
11
+
12
+ enum status: %i[normal disable]
13
+ end
14
+
15
+ RSpec.describe EnumHelp::I18n do
16
+ describe '#enum' do
17
+ context 'With hash definitions' do
18
+ it 'responds defined _i18n method' do
19
+ expect(User.new).to respond_to("gender_i18n")
20
+ end
21
+
22
+ it 'responds defined genders_i18n method' do
23
+ expect(User).to respond_to("genders_i18n")
24
+ end
25
+ end
26
+
27
+ context 'With array definitions' do
28
+ it 'responds defined _i18n method' do
29
+ expect(User.new).to respond_to("status_i18n")
30
+ end
31
+
32
+ it 'responds defined status_i18n method' do
33
+ expect(User).to respond_to("statuses_i18n")
34
+ end
35
+ end
36
+ end
37
+
38
+ describe '#enum_key_i18n' do
39
+ describe 'user.gender' do
40
+ let(:gender) { "female" }
41
+ let(:user) { User.create(gender: gender) }
42
+
43
+
44
+ subject { user.gender_i18n }
45
+
46
+ context 'lang is zh-CN' do
47
+ before { I18n.locale = :"zh-CN" }
48
+
49
+ it { expect(I18n.locale).to eq :"zh-CN" }
50
+
51
+ context 'gender is male' do
52
+ let(:gender) { 'male' }
53
+ it { is_expected.to eq '男' }
54
+ end
55
+
56
+ context 'gender is female' do
57
+ let(:gender) { 'female' }
58
+ it { is_expected.to eq '女' }
59
+ end
60
+ end
61
+
62
+ context 'lang is en' do
63
+ before { I18n.locale = :en }
64
+
65
+ it { expect(I18n.locale).to eq :en }
66
+
67
+ context 'gender is male' do
68
+ let(:gender) { 'male' }
69
+ it { is_expected.to eq 'Male' }
70
+ end
71
+
72
+ context 'gender is female' do
73
+ let(:gender) { 'female' }
74
+ it { is_expected.to eq 'Female' }
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ describe '#enum_keys_i18n' do
81
+ subject { User.genders_i18n }
82
+
83
+ context 'lang is zh-CN' do
84
+ before { I18n.locale = :"zh-CN" }
85
+
86
+ it { expect(I18n.locale).to eq :"zh-CN" }
87
+ it { is_expected.to eq({"male"=>"男", "female"=>"女"}) }
88
+ end
89
+
90
+ context 'lang is en' do
91
+ before { I18n.locale = :en }
92
+
93
+ it { expect(I18n.locale).to eq :en }
94
+ it { is_expected.to eq({"male"=>"Male", "female"=>"Female"}) }
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,16 @@
1
+ zh-CN:
2
+ activerecord:
3
+ models:
4
+ user: "User"
5
+ attributes:
6
+ user:
7
+ id: "ID"
8
+ gender: "Gender"
9
+ enums:
10
+ user:
11
+ gender:
12
+ male: "Male"
13
+ female: "Female"
14
+ status:
15
+ normal: "Normal"
16
+ disable: "Disable"
@@ -0,0 +1,16 @@
1
+ zh-CN:
2
+ activerecord:
3
+ models:
4
+ user: "用户"
5
+ attributes:
6
+ user:
7
+ id: "ID"
8
+ gender: "性别"
9
+ enums:
10
+ user:
11
+ gender:
12
+ male: "男"
13
+ female: "女"
14
+ status:
15
+ normal: "正常"
16
+ disable: "禁用"
@@ -0,0 +1,15 @@
1
+ require "bundler/setup"
2
+
3
+ require "rspec"
4
+
5
+ require "rails"
6
+ require "active_record"
7
+
8
+ Bundler.require
9
+
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
+
12
+ I18n.load_path += Dir["#{File.dirname(__FILE__)}/fixtures/locales/*.yml"]
13
+ I18n.enforce_available_locales = false
14
+
15
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
@@ -0,0 +1,17 @@
1
+ ActiveRecord::Base.configurations = { "test"=> {"adapter"=>"sqlite3", "database"=>":memory:"} }
2
+ ActiveRecord::Base.establish_connection :test
3
+
4
+ version = "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
5
+ class CreateAllTables < ActiveRecord::Migration[version]
6
+ def change
7
+ create_table :users do |t|
8
+ t.integer :gender, null: false, default: 0, limit: 1
9
+ t.integer :status, null: false, default: 0, limit: 1
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
15
+
16
+ ActiveRecord::Migration.verbose = false
17
+ CreateAllTables.new.change
metadata CHANGED
@@ -1,43 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enum_help
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lester Zhao
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-03 00:00:00.000000000 Z
11
+ date: 2022-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.5'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.5'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
13
  - !ruby/object:Gem::Dependency
42
14
  name: activesupport
43
15
  requirement: !ruby/object:Gem::Requirement
@@ -60,7 +32,9 @@ executables: []
60
32
  extensions: []
61
33
  extra_rdoc_files: []
62
34
  files:
35
+ - ".github/workflows/ci.yml"
63
36
  - ".gitignore"
37
+ - ".rspec"
64
38
  - Gemfile
65
39
  - LICENSE.txt
66
40
  - README.md
@@ -71,11 +45,16 @@ files:
71
45
  - lib/enum_help/railtie.rb
72
46
  - lib/enum_help/simple_form.rb
73
47
  - lib/enum_help/version.rb
74
- homepage: ''
48
+ - spec/enum_i18n_help_spec.rb
49
+ - spec/fixtures/locales/en.yml
50
+ - spec/fixtures/locales/zh-CN.yml
51
+ - spec/spec_helper.rb
52
+ - spec/support/setup_database.rb
53
+ homepage: https://github.com/zmbacker/enum_help
75
54
  licenses:
76
55
  - MIT
77
56
  metadata: {}
78
- post_install_message:
57
+ post_install_message:
79
58
  rdoc_options: []
80
59
  require_paths:
81
60
  - lib
@@ -90,9 +69,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
69
  - !ruby/object:Gem::Version
91
70
  version: '0'
92
71
  requirements: []
93
- rubyforge_project:
94
- rubygems_version: 2.2.2
95
- signing_key:
72
+ rubygems_version: 3.1.6
73
+ signing_key:
96
74
  specification_version: 4
97
75
  summary: Extends of ActiveRecord::Enum, which can used in simple_form and internationalization
98
- test_files: []
76
+ test_files:
77
+ - spec/enum_i18n_help_spec.rb
78
+ - spec/fixtures/locales/en.yml
79
+ - spec/fixtures/locales/zh-CN.yml
80
+ - spec/spec_helper.rb
81
+ - spec/support/setup_database.rb