eac_rails_utils 0.13.0 → 0.13.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +0 -11
- data/lib/eac_rails_utils/patches/active_model_associations.rb +23 -27
- data/lib/eac_rails_utils/patches/rails_4/active_record_associations_association_scope.rb +23 -0
- data/lib/eac_rails_utils/patches/rails_4.rb +18 -0
- data/lib/eac_rails_utils/patches/rails_5_2/active_model_association_method_fix.rb +38 -0
- data/lib/eac_rails_utils/patches/rails_5_2.rb +18 -0
- data/lib/eac_rails_utils/version.rb +1 -1
- metadata +10 -80
- data/test/dummy/Rakefile +0 -8
- data/test/dummy/app/assets/config/manifest.js +0 -3
- data/test/dummy/app/models/job.rb +0 -6
- data/test/dummy/app/models/user.rb +0 -9
- data/test/dummy/bin/rails +0 -6
- data/test/dummy/config/application.rb +0 -14
- data/test/dummy/config/boot.rb +0 -6
- data/test/dummy/config/database.yml +0 -5
- data/test/dummy/config/environment.rb +0 -7
- data/test/dummy/config/environments/test.rb +0 -44
- data/test/dummy/config/locales/pt-BR.yml +0 -38
- data/test/dummy/config/routes.rb +0 -10
- data/test/dummy/config/secrets.yml +0 -22
- data/test/dummy/config.ru +0 -6
- data/test/dummy/db/migrate/20160415125333_create_users.rb +0 -13
- data/test/dummy/db/migrate/20160415143123_create_jobs.rb +0 -11
- data/test/dummy/db/migrate/20160415143229_add_job_to_users.rb +0 -9
- data/test/dummy/db/schema.rb +0 -25
- data/test/helpers/eac_rails_utils/data_table_test_helper_test.rb +0 -44
- data/test/helpers/eac_rails_utils/formatter_helper_test.rb +0 -21
- data/test/lib/eac_rails_utils/models/fetch_errors_test.rb +0 -80
- data/test/test_helper.rb +0 -13
- data/test/validators/cpf_validator_test.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 843754871487598961a71d16871da8c3556d9d0097f0869838311d56c4e82df8
|
4
|
+
data.tar.gz: e5a72c9640c9c6aba5f720bbb1204371c0f63ffdf5309f497e537b0a74406721
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb890220eb07ca6a06e54a31d877779c043070b502d1a724236e5ea82c07839508487fe6effa5197d48928d1103eff5fd56d81dd8d54a3138a7c5404bf52057d
|
7
|
+
data.tar.gz: 94d56786e02f5fd2c3d3d4a7b42cb36ea9d601bf1e89828a1670477f36ce7d36e8d164b3028c709bbdca8f7123aa8971cadd2d03861179e7b0cdde4cc70fe679
|
data/Rakefile
CHANGED
@@ -7,14 +7,3 @@ rescue LoadError
|
|
7
7
|
end
|
8
8
|
|
9
9
|
Bundler::GemHelper.install_tasks
|
10
|
-
|
11
|
-
require 'rake/testtask'
|
12
|
-
|
13
|
-
Rake::TestTask.new(:test) do |t|
|
14
|
-
t.libs << 'lib'
|
15
|
-
t.libs << 'test'
|
16
|
-
t.pattern = 'test/**/*_test.rb'
|
17
|
-
t.verbose = false
|
18
|
-
end
|
19
|
-
|
20
|
-
task default: :test
|
@@ -1,38 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'active_model/associations/hooks'
|
4
3
|
require 'activemodel/associations'
|
5
|
-
|
6
|
-
|
7
|
-
module Patches
|
8
|
-
module ActiveModelAssociations
|
9
|
-
module ScopeExtensionPatch
|
10
|
-
def add_constraints(scope, owner, association_klass, *extra_args)
|
11
|
-
if extra_args.any?
|
12
|
-
refl = extra_args.first
|
13
|
-
if refl.options[:active_model]
|
14
|
-
target_ids = refl.options[:target_ids]
|
15
|
-
return scope.where(id: owner[target_ids])
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
super
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
4
|
+
require 'eac_rails_utils/patches/rails_4'
|
5
|
+
require 'eac_rails_utils/patches/rails_5_2'
|
25
6
|
|
26
7
|
module ActiveModel
|
27
8
|
module Associations
|
28
9
|
module Hooks
|
29
|
-
|
30
|
-
|
10
|
+
class << self
|
11
|
+
def init
|
12
|
+
init_rails_4 if ::EacRailsUtils::Patches::Rails4.enabled?
|
13
|
+
init_rails_5_2 if ::EacRailsUtils::Patches::Rails52.enabled?
|
14
|
+
end
|
15
|
+
|
16
|
+
def init_rails_4
|
17
|
+
ActiveSupport.on_load(:active_record) do
|
18
|
+
ActiveRecord::Associations::AssociationScope.prepend(
|
19
|
+
::EacRailsUtils::Patches::Rails4.ActiveRecordAssociationsAssociationScope
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
31
23
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
24
|
+
def init_rails_5_2
|
25
|
+
rails_5_2_fix_activemodel_associations_methods
|
26
|
+
end
|
27
|
+
|
28
|
+
def rails_5_2_fix_activemodel_associations_methods
|
29
|
+
%i[belongs_to has_many].each do |method|
|
30
|
+
::EacRailsUtils::Patches::Rails52::ActiveModelAssociationMethodFix.new(method)
|
31
|
+
end
|
36
32
|
end
|
37
33
|
end
|
38
34
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'activemodel/associations'
|
4
|
+
|
5
|
+
module EacRailsUtils
|
6
|
+
module Patches
|
7
|
+
module Rails4
|
8
|
+
module ActiveRecordAssociationsAssociationScope
|
9
|
+
def add_constraints(scope, owner, association_klass, *extra_args)
|
10
|
+
if extra_args.any?
|
11
|
+
refl = extra_args.first
|
12
|
+
if refl.options[:active_model]
|
13
|
+
target_ids = refl.options[:target_ids]
|
14
|
+
return scope.where(id: owner[target_ids])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_model/associations/hooks'
|
4
|
+
require 'eac_ruby_utils/require_sub'
|
5
|
+
|
6
|
+
module EacRailsUtils
|
7
|
+
module Patches
|
8
|
+
module Rails4
|
9
|
+
::EacRubyUtils.require_sub __FILE__
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def enabled?
|
13
|
+
::Rails.version < '5'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'activemodel/associations'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
|
6
|
+
module EacRailsUtils
|
7
|
+
module Patches
|
8
|
+
module Rails52
|
9
|
+
class ActiveModelAssociationMethodFix
|
10
|
+
common_constructor :method_name do
|
11
|
+
perform
|
12
|
+
end
|
13
|
+
|
14
|
+
def original_method_new_name
|
15
|
+
"original_#{method_name}".to_sym
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def the_module
|
21
|
+
::ActiveModel::Associations::ClassMethods
|
22
|
+
end
|
23
|
+
|
24
|
+
def perform
|
25
|
+
patch = self
|
26
|
+
the_module.class_eval do
|
27
|
+
alias_method patch.original_method_new_name, patch.method_name
|
28
|
+
remove_method patch.method_name
|
29
|
+
|
30
|
+
define_method patch.method_name do |name, scope = nil, **options, &extension|
|
31
|
+
send(patch.original_method_new_name, name, scope, options, &extension)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_model/associations/hooks'
|
4
|
+
require 'eac_ruby_utils/require_sub'
|
5
|
+
|
6
|
+
module EacRailsUtils
|
7
|
+
module Patches
|
8
|
+
module Rails52
|
9
|
+
::EacRubyUtils.require_sub __FILE__
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def enabled?
|
13
|
+
::Rails.version >= '5.2'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eac_rails_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- E.A.C.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel-associations
|
@@ -115,47 +115,19 @@ dependencies:
|
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '0'
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
|
-
name:
|
118
|
+
name: eac_rails_gem_support
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
121
|
- - "~>"
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version: '0.
|
124
|
-
type: :development
|
125
|
-
prerelease: false
|
126
|
-
version_requirements: !ruby/object:Gem::Requirement
|
127
|
-
requirements:
|
128
|
-
- - "~>"
|
129
|
-
- !ruby/object:Gem::Version
|
130
|
-
version: '0.2'
|
131
|
-
- !ruby/object:Gem::Dependency
|
132
|
-
name: rspec-rails
|
133
|
-
requirement: !ruby/object:Gem::Requirement
|
134
|
-
requirements:
|
135
|
-
- - ">="
|
136
|
-
- !ruby/object:Gem::Version
|
137
|
-
version: '0'
|
138
|
-
type: :development
|
139
|
-
prerelease: false
|
140
|
-
version_requirements: !ruby/object:Gem::Requirement
|
141
|
-
requirements:
|
142
|
-
- - ">="
|
143
|
-
- !ruby/object:Gem::Version
|
144
|
-
version: '0'
|
145
|
-
- !ruby/object:Gem::Dependency
|
146
|
-
name: sqlite3
|
147
|
-
requirement: !ruby/object:Gem::Requirement
|
148
|
-
requirements:
|
149
|
-
- - "~>"
|
150
|
-
- !ruby/object:Gem::Version
|
151
|
-
version: 1.3.13
|
123
|
+
version: '0.4'
|
152
124
|
type: :development
|
153
125
|
prerelease: false
|
154
126
|
version_requirements: !ruby/object:Gem::Requirement
|
155
127
|
requirements:
|
156
128
|
- - "~>"
|
157
129
|
- !ruby/object:Gem::Version
|
158
|
-
version:
|
130
|
+
version: '0.4'
|
159
131
|
description:
|
160
132
|
email:
|
161
133
|
executables: []
|
@@ -223,30 +195,11 @@ files:
|
|
223
195
|
- lib/eac_rails_utils/patches.rb
|
224
196
|
- lib/eac_rails_utils/patches/action_controller_base.rb
|
225
197
|
- lib/eac_rails_utils/patches/active_model_associations.rb
|
198
|
+
- lib/eac_rails_utils/patches/rails_4.rb
|
199
|
+
- lib/eac_rails_utils/patches/rails_4/active_record_associations_association_scope.rb
|
200
|
+
- lib/eac_rails_utils/patches/rails_5_2.rb
|
201
|
+
- lib/eac_rails_utils/patches/rails_5_2/active_model_association_method_fix.rb
|
226
202
|
- lib/eac_rails_utils/version.rb
|
227
|
-
- test/dummy/Rakefile
|
228
|
-
- test/dummy/app/assets/config/manifest.js
|
229
|
-
- test/dummy/app/models/job.rb
|
230
|
-
- test/dummy/app/models/user.rb
|
231
|
-
- test/dummy/bin/rails
|
232
|
-
- test/dummy/config.ru
|
233
|
-
- test/dummy/config/application.rb
|
234
|
-
- test/dummy/config/boot.rb
|
235
|
-
- test/dummy/config/database.yml
|
236
|
-
- test/dummy/config/environment.rb
|
237
|
-
- test/dummy/config/environments/test.rb
|
238
|
-
- test/dummy/config/locales/pt-BR.yml
|
239
|
-
- test/dummy/config/routes.rb
|
240
|
-
- test/dummy/config/secrets.yml
|
241
|
-
- test/dummy/db/migrate/20160415125333_create_users.rb
|
242
|
-
- test/dummy/db/migrate/20160415143123_create_jobs.rb
|
243
|
-
- test/dummy/db/migrate/20160415143229_add_job_to_users.rb
|
244
|
-
- test/dummy/db/schema.rb
|
245
|
-
- test/helpers/eac_rails_utils/data_table_test_helper_test.rb
|
246
|
-
- test/helpers/eac_rails_utils/formatter_helper_test.rb
|
247
|
-
- test/lib/eac_rails_utils/models/fetch_errors_test.rb
|
248
|
-
- test/test_helper.rb
|
249
|
-
- test/validators/cpf_validator_test.rb
|
250
203
|
homepage:
|
251
204
|
licenses: []
|
252
205
|
metadata: {}
|
@@ -269,27 +222,4 @@ rubygems_version: 3.1.6
|
|
269
222
|
signing_key:
|
270
223
|
specification_version: 4
|
271
224
|
summary: Código reutilizável para as aplicações Rails da E.A.C..
|
272
|
-
test_files:
|
273
|
-
- test/dummy/Rakefile
|
274
|
-
- test/dummy/config.ru
|
275
|
-
- test/dummy/config/boot.rb
|
276
|
-
- test/dummy/config/database.yml
|
277
|
-
- test/dummy/config/secrets.yml
|
278
|
-
- test/dummy/config/locales/pt-BR.yml
|
279
|
-
- test/dummy/config/application.rb
|
280
|
-
- test/dummy/config/environments/test.rb
|
281
|
-
- test/dummy/config/environment.rb
|
282
|
-
- test/dummy/config/routes.rb
|
283
|
-
- test/dummy/db/schema.rb
|
284
|
-
- test/dummy/db/migrate/20160415143123_create_jobs.rb
|
285
|
-
- test/dummy/db/migrate/20160415143229_add_job_to_users.rb
|
286
|
-
- test/dummy/db/migrate/20160415125333_create_users.rb
|
287
|
-
- test/dummy/app/models/job.rb
|
288
|
-
- test/dummy/app/models/user.rb
|
289
|
-
- test/dummy/app/assets/config/manifest.js
|
290
|
-
- test/dummy/bin/rails
|
291
|
-
- test/test_helper.rb
|
292
|
-
- test/validators/cpf_validator_test.rb
|
293
|
-
- test/helpers/eac_rails_utils/data_table_test_helper_test.rb
|
294
|
-
- test/helpers/eac_rails_utils/formatter_helper_test.rb
|
295
|
-
- test/lib/eac_rails_utils/models/fetch_errors_test.rb
|
225
|
+
test_files: []
|
data/test/dummy/Rakefile
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
4
|
-
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
5
|
-
|
6
|
-
require File.expand_path('config/application', __dir__)
|
7
|
-
|
8
|
-
Rails.application.load_tasks
|
data/test/dummy/bin/rails
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require File.expand_path('boot', __dir__)
|
4
|
-
|
5
|
-
require 'rails/all'
|
6
|
-
|
7
|
-
Bundler.require(*Rails.groups)
|
8
|
-
require 'eac_rails_utils'
|
9
|
-
|
10
|
-
module Dummy
|
11
|
-
class Application < Rails::Application
|
12
|
-
config.active_record.raise_in_transactional_callbacks = true if ::Rails.version < '5'
|
13
|
-
end
|
14
|
-
end
|
data/test/dummy/config/boot.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
Rails.application.configure do
|
4
|
-
# Settings specified here will take precedence over those in config/application.rb.
|
5
|
-
|
6
|
-
# The test environment is used exclusively to run your application's
|
7
|
-
# test suite. You never need to work with it otherwise. Remember that
|
8
|
-
# your test database is "scratch space" for the test suite and is wiped
|
9
|
-
# and recreated between test runs. Don't rely on the data there!
|
10
|
-
config.cache_classes = true
|
11
|
-
|
12
|
-
# Do not eager load code on boot. This avoids loading your whole application
|
13
|
-
# just for the purpose of running a single test. If you are using a tool that
|
14
|
-
# preloads Rails for running tests, you may have to set it to true.
|
15
|
-
config.eager_load = false
|
16
|
-
|
17
|
-
# Configure static file server for tests with Cache-Control for performance.
|
18
|
-
config.serve_static_files = true
|
19
|
-
config.static_cache_control = 'public, max-age=3600'
|
20
|
-
|
21
|
-
# Show full error reports and disable caching.
|
22
|
-
config.consider_all_requests_local = true
|
23
|
-
config.action_controller.perform_caching = false
|
24
|
-
|
25
|
-
# Raise exceptions instead of rendering exception templates.
|
26
|
-
config.action_dispatch.show_exceptions = false
|
27
|
-
|
28
|
-
# Disable request forgery protection in test environment.
|
29
|
-
config.action_controller.allow_forgery_protection = false
|
30
|
-
|
31
|
-
# Tell Action Mailer not to deliver emails to the real world.
|
32
|
-
# The :test delivery method accumulates sent emails in the
|
33
|
-
# ActionMailer::Base.deliveries array.
|
34
|
-
config.action_mailer.delivery_method = :test
|
35
|
-
|
36
|
-
# Randomize the order test cases are executed.
|
37
|
-
config.active_support.test_order = :random
|
38
|
-
|
39
|
-
# Print deprecation notices to the stderr.
|
40
|
-
config.active_support.deprecation = :stderr
|
41
|
-
|
42
|
-
# Raises error for missing translations
|
43
|
-
# config.action_view.raise_on_missing_translations = true
|
44
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
pt-BR:
|
2
|
-
eac:
|
3
|
-
listable:
|
4
|
-
eac/listable_test/stub:
|
5
|
-
inteiro:
|
6
|
-
a:
|
7
|
-
label: Inteiro A
|
8
|
-
description: Inteiro A Descr.
|
9
|
-
b:
|
10
|
-
label: Inteiro BB
|
11
|
-
description: Inteiro BB Descr.
|
12
|
-
c:
|
13
|
-
label: Inteiro CCC
|
14
|
-
description: Inteiro CCC Descr.
|
15
|
-
cadeia:
|
16
|
-
a:
|
17
|
-
label: Cadeia AAA
|
18
|
-
description: Cadeia AAA Descr.
|
19
|
-
b:
|
20
|
-
label: Cadeia BB
|
21
|
-
description: Cadeia BB Descr.
|
22
|
-
c:
|
23
|
-
label: Cadeia C
|
24
|
-
description: Cadeia C Descr.
|
25
|
-
code:
|
26
|
-
a:
|
27
|
-
label: Código A
|
28
|
-
description: Código A Descr.
|
29
|
-
b:
|
30
|
-
label: Código B
|
31
|
-
description: Código B Descr.
|
32
|
-
type:
|
33
|
-
a:
|
34
|
-
label: Tipo A
|
35
|
-
description: Tipo A Descr.
|
36
|
-
b:
|
37
|
-
label: Tipo B
|
38
|
-
description: Tipo B Descr.
|
data/test/dummy/config/routes.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# Be sure to restart your server when you modify this file.
|
2
|
-
|
3
|
-
# Your secret key is used for verifying the integrity of signed cookies.
|
4
|
-
# If you change this key, all old signed cookies will become invalid!
|
5
|
-
|
6
|
-
# Make sure the secret is at least 30 characters and all random,
|
7
|
-
# no regular words or you'll be exposed to dictionary attacks.
|
8
|
-
# You can use `rake secret` to generate a secure secret key.
|
9
|
-
|
10
|
-
# Make sure the secrets in this file are kept private
|
11
|
-
# if you're sharing your code publicly.
|
12
|
-
|
13
|
-
development:
|
14
|
-
secret_key_base: 50d3bce23e309d961dafde3edfa89be2713718a5e2fb75b6c3e1f61826230921535243d2f221b8cecebeaceccb574a1e74fbbf3b89a9d53758ac988950f1753c
|
15
|
-
|
16
|
-
test:
|
17
|
-
secret_key_base: 75f37392ef7726b50b4ce117bd6a7eca7cdc299608e256f7ca163b14032559217364d41b7c091483ce02179a18c956f6e076331a611c0500f2862f83979a6c16
|
18
|
-
|
19
|
-
# Do not keep production secrets in the repository,
|
20
|
-
# instead read values from the environment.
|
21
|
-
production:
|
22
|
-
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
|
data/test/dummy/config.ru
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class CreateUsers < (
|
4
|
-
Rails.version < '5' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
|
5
|
-
)
|
6
|
-
def change
|
7
|
-
create_table :users do |t|
|
8
|
-
t.string :name
|
9
|
-
t.string :email
|
10
|
-
t.string :password
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/test/dummy/db/schema.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# This file is auto-generated from the current state of the database. Instead
|
3
|
-
# of editing this file, please use the migrations feature of Active Record to
|
4
|
-
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
-
#
|
6
|
-
# Note that this schema.rb definition is the authoritative source for your
|
7
|
-
# database schema. If you need to create the application database on another
|
8
|
-
# system, you should be using db:schema:load, not running all the migrations
|
9
|
-
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
-
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
-
#
|
12
|
-
# It's strongly recommended that you check this file into your version control system.
|
13
|
-
|
14
|
-
ActiveRecord::Schema.define(version: 20_160_415_143_229) do
|
15
|
-
create_table 'jobs', force: :cascade do |t|
|
16
|
-
t.string 'name'
|
17
|
-
end
|
18
|
-
|
19
|
-
create_table 'users', force: :cascade do |t|
|
20
|
-
t.string 'name'
|
21
|
-
t.string 'email'
|
22
|
-
t.string 'password'
|
23
|
-
t.integer 'job_id'
|
24
|
-
end
|
25
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
module EacRailsUtils
|
6
|
-
class DataTableTestHelperTest < ActionView::TestCase
|
7
|
-
include ::EacRailsUtils::DataTableHelper
|
8
|
-
|
9
|
-
class Person
|
10
|
-
attr_reader :name, :age, :job
|
11
|
-
|
12
|
-
def initialize(name, age, job)
|
13
|
-
@name = name
|
14
|
-
@age = age
|
15
|
-
@job = job
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class Job
|
20
|
-
attr_reader :name, :id
|
21
|
-
|
22
|
-
def initialize(name)
|
23
|
-
@name = name
|
24
|
-
@id = SecureRandom.random_number(100_000)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_data_table
|
29
|
-
ds = []
|
30
|
-
ds << Person.new('Fulano', 15, Job.new('Padeiro'))
|
31
|
-
ds << Person.new('Sicrano', 25, nil)
|
32
|
-
|
33
|
-
data_table(ds) do |s|
|
34
|
-
s.paging = false
|
35
|
-
s.column('Name', 'name')
|
36
|
-
s.column('Age', 'age')
|
37
|
-
s.column('Name + Age') { |v| "#{v.name} + #{v.age}" }
|
38
|
-
s.column('Job', 'job')
|
39
|
-
s.column('Job ID', 'job.id')
|
40
|
-
s.column('Job ID + 10', 'job.id') { |_v| + 10 }
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
module EacRailsUtils
|
6
|
-
class FormatterHelperTest < ActionView::TestCase
|
7
|
-
include ::EacRailsUtils::FormatterHelper
|
8
|
-
|
9
|
-
test 'should convert BRL currency to float' do
|
10
|
-
brl_currency = { a: '1', b: '1,2', c: '1,23', d: '123.456.789,01',
|
11
|
-
e: 'R$1,23', f: 'R$ 123.4,56' }
|
12
|
-
float_currency = { a: 1, b: 1.2, c: 1.23, d: 123_456_789.01,
|
13
|
-
e: 1.23, f: 123_4.56 }
|
14
|
-
|
15
|
-
brl_currency.each do |k, v|
|
16
|
-
assert_equal float_currency[k], brl_currency_to_float(v),
|
17
|
-
"#{v} should be #{float_currency[k]}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
module EacRailsUtils
|
6
|
-
module Models
|
7
|
-
class FetchErrorsTest < ActiveSupport::TestCase
|
8
|
-
class M1
|
9
|
-
include ActiveModel::Model
|
10
|
-
include EacRailsUtils::Models::FetchErrors
|
11
|
-
attr_accessor :name, :age, :account, :country_id, :other
|
12
|
-
end
|
13
|
-
|
14
|
-
class M2
|
15
|
-
include ActiveModel::Model
|
16
|
-
attr_accessor :name, :myage, :account_id, :country
|
17
|
-
|
18
|
-
validate :my_validate
|
19
|
-
|
20
|
-
def my_validate
|
21
|
-
errors.add(:name, 'NAME_ERROR')
|
22
|
-
errors.add(:myage, 'MYAGE_ERROR')
|
23
|
-
errors.add(:account_id, 'ACCOUNT_ID_ERROR')
|
24
|
-
errors.add(:country, 'COUNTRY_ERROR')
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def setup
|
29
|
-
reset_m1
|
30
|
-
reset_m2
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_fetch_column_errors
|
34
|
-
@m1.fetch_column_errors(@m2, :myage, :age)
|
35
|
-
assert_equal @m2.errors[:myage], @m1.errors[:age]
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_fetch_record_errors
|
39
|
-
@m1.fetch_record_errors(@m2)
|
40
|
-
{ name: :name, account_id: :account, country: :country_id }.each do |c2, c1|
|
41
|
-
assert_equal @m2.errors[c2], @m1.errors[c1], "c2: #{c2}, c1: #{c1}"
|
42
|
-
end
|
43
|
-
assert @m1.errors[:age].empty?
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_fetch_record_errors_with_default_column
|
47
|
-
@m1.fetch_record_errors(@m2, default_column: :other)
|
48
|
-
assert_equal @m2.errors[:name], @m1.errors[:name]
|
49
|
-
assert @m1.errors[:age].empty?
|
50
|
-
assert_equal ['Myage: MYAGE_ERROR'], @m1.errors[:other]
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_fetch_record_errors_with_skip_option
|
54
|
-
@m1.fetch_record_errors(@m2, skip: [:name])
|
55
|
-
assert @m1.errors[:name].empty?
|
56
|
-
assert @m1.errors[:age].empty?
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_fetch_record_errors_by_mapping
|
60
|
-
@m1.fetch_record_errors_by_mapping(@m2, name: :name, myage: :age)
|
61
|
-
assert_equal @m2.errors[:name], @m1.errors[:name]
|
62
|
-
assert_equal @m2.errors[:myage], @m1.errors[:age]
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def reset_m1
|
68
|
-
@m1 = M1.new
|
69
|
-
assert @m1.errors.empty?
|
70
|
-
end
|
71
|
-
|
72
|
-
def reset_m2
|
73
|
-
@m2 = M2.new
|
74
|
-
assert_not @m2.valid?
|
75
|
-
assert_not @m2.errors[:name].empty?
|
76
|
-
assert_not @m2.errors[:myage].empty?
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
ENV['RAILS_ENV'] = 'test'
|
4
|
-
require File.expand_path('../test/dummy/config/environment.rb', __dir__)
|
5
|
-
require 'rails/test_help'
|
6
|
-
|
7
|
-
module ActiveSupport
|
8
|
-
class TestCase
|
9
|
-
def reset_test_database
|
10
|
-
ActiveRecord::Tasks::DatabaseTasks.load_schema_current(:ruby, ENV['SCHEMA'])
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
module EacRailsUtils
|
6
|
-
class CpfValidatorTest < ActiveSupport::TestCase
|
7
|
-
class M1
|
8
|
-
include ActiveModel::Model
|
9
|
-
|
10
|
-
attr_accessor :cpf
|
11
|
-
|
12
|
-
validates :cpf, 'eac_rails_utils/cpf' => true, allow_nil: true
|
13
|
-
end
|
14
|
-
|
15
|
-
def setup
|
16
|
-
@record = M1.new
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_valid_cpfs
|
20
|
-
['85630275305', '66244374487', nil].each do |v|
|
21
|
-
@record.cpf = v
|
22
|
-
@record.valid?
|
23
|
-
assert_equal [], @record.errors[:cpf], "CPF: \"#{v}\""
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_invalid_cpfs
|
28
|
-
['', ' ', 'abc', '856.302.753-05', '662.443.744-87', '85630275304'].each do |v|
|
29
|
-
@record.cpf = v
|
30
|
-
@record.valid?
|
31
|
-
assert_not_equal [], @record.errors[:cpf], "CPF: \"#{v}\""
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|