eac_rails_utils 0.10.1 → 0.11.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper.rb +5 -1
  3. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder.rb +10 -2
  4. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/association_select_field.rb +1 -1
  5. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/common_text_fields.rb +1 -1
  6. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/currency_field.rb +1 -1
  7. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/date_field.rb +1 -1
  8. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/fields_for.rb +1 -1
  9. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/file_field.rb +1 -1
  10. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/radio_select_field.rb +1 -1
  11. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/searchable_association_field.rb +1 -1
  12. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/select_field.rb +3 -2
  13. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/time_field.rb +1 -1
  14. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/year_month_field.rb +1 -1
  15. data/app/helpers/eac_rails_utils/data_table_helper.rb +13 -0
  16. data/{lib/eac → app/helpers/eac_rails_utils}/data_table_helper/column.rb +1 -1
  17. data/{lib/eac → app/helpers/eac_rails_utils}/data_table_helper/data_table.rb +2 -2
  18. data/{lib/eac → app/helpers/eac_rails_utils}/data_table_helper/setup.rb +2 -2
  19. data/app/helpers/eac_rails_utils/links_helper.rb +5 -5
  20. data/{lib/eac → app/helpers/eac_rails_utils}/menus_helper.rb +5 -1
  21. data/{lib/eac → app/helpers/eac_rails_utils}/menus_helper/bootstrap_gui_builder.rb +1 -1
  22. data/{lib/eac → app/helpers/eac_rails_utils}/menus_helper/data_builder.rb +1 -1
  23. data/{lib/eac → app/helpers/eac_rails_utils}/menus_helper/gui_builder.rb +1 -1
  24. data/{lib/eac → app/validators/eac_rails_utils}/cpf_validator.rb +1 -1
  25. data/{lib/eac → app/validators/eac_rails_utils}/no_presence_validator.rb +1 -1
  26. data/config/locales/en.yml +8 -0
  27. data/config/locales/pt-BR.yml +8 -0
  28. data/lib/eac_rails_utils.rb +2 -39
  29. data/lib/eac_rails_utils/engine.rb +2 -0
  30. data/lib/{eac → eac_rails_utils}/htmlbeautifier.rb +1 -1
  31. data/lib/eac_rails_utils/models.rb +9 -0
  32. data/lib/eac_rails_utils/models/attribute_required.rb +43 -0
  33. data/lib/eac_rails_utils/models/fetch_errors.rb +92 -0
  34. data/lib/eac_rails_utils/models/inequality_queries.rb +39 -0
  35. data/lib/eac_rails_utils/models/tableless.rb +97 -0
  36. data/lib/eac_rails_utils/models/test_utils.rb +65 -0
  37. data/lib/eac_rails_utils/patches.rb +9 -0
  38. data/lib/eac_rails_utils/patches/action_controller_base.rb +2 -0
  39. data/lib/eac_rails_utils/patches/active_model_associations.rb +40 -0
  40. data/lib/eac_rails_utils/version.rb +1 -1
  41. data/test/dummy/app/assets/config/manifest.js +3 -0
  42. data/test/dummy/app/models/user.rb +4 -0
  43. data/test/dummy/config/application.rb +1 -1
  44. data/test/{lib/eac → helpers/eac_rails_utils}/common_form_helper_test.rb +2 -2
  45. data/test/{lib/eac → helpers/eac_rails_utils}/data_table_test_helper_test.rb +2 -2
  46. data/test/{app/helpers → helpers}/eac_rails_utils/formatter_helper_test.rb +0 -0
  47. data/test/lib/eac_rails_utils/{patches/model_attribute_required_test.rb → models/attribute_required_test.rb} +1 -0
  48. data/test/lib/eac_rails_utils/models/fetch_errors_test.rb +80 -0
  49. data/test/lib/eac_rails_utils/models/tableless_test.rb +25 -0
  50. data/test/{lib/eac → validators}/cpf_validator_test.rb +2 -2
  51. metadata +69 -66
  52. data/lib/eac/data_table_helper.rb +0 -13
  53. data/lib/eac/inequality_queries.rb +0 -37
  54. data/lib/eac/model.rb +0 -90
  55. data/lib/eac/test_utils.rb +0 -61
  56. data/lib/eac_rails_utils/patches/model_attribute_required.rb +0 -34
  57. data/lib/eac_rails_utils/patches/ofx_parser.rb +0 -43
  58. data/lib/eac_rails_utils/tableless_model.rb +0 -92
  59. data/test/lib/eac/model_test.rb +0 -78
  60. data/test/lib/eac/source_target_fixtures_test_files/a.source.html +0 -1
  61. data/test/lib/eac/source_target_fixtures_test_files/a.target.yaml +0 -1
  62. data/test/lib/eac/source_target_fixtures_test_files/b.source.html +0 -1
  63. data/test/lib/eac/source_target_fixtures_test_files/c.target.yaml +0 -1
  64. data/test/lib/eac_rails_utils/tableless_model_test.rb +0 -23
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ module EacRailsUtils
6
+ module Models
7
+ class TablelessTest < ActiveSupport::TestCase
8
+ class Stub < ::EacRailsUtils::Models::Tableless
9
+ attribute :tempo, DateTime
10
+ end
11
+
12
+ test 'date time array values' do
13
+ stub = Stub.new('tempo(1i)' => '9', 'tempo(2i)' => '10', 'tempo(3i)' => '11',
14
+ 'tempo(4i)' => '12', 'tempo(5i)' => '13', 'tempo(6i)' => '14')
15
+ assert stub.tempo.is_a?(DateTime), "Class: |#{stub.tempo.class}|, Value: |#{stub.tempo}|"
16
+ assert_equal 9, stub.tempo.year, 'Year'
17
+ assert_equal 10, stub.tempo.month, 'Month'
18
+ assert_equal 11, stub.tempo.day, 'Day'
19
+ assert_equal 12, stub.tempo.hour, 'Hour'
20
+ assert_equal 13, stub.tempo.minute, 'Minute'
21
+ assert_equal 14, stub.tempo.second, 'Second'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -2,14 +2,14 @@
2
2
 
3
3
  require 'test_helper'
4
4
 
5
- module Eac
5
+ module EacRailsUtils
6
6
  class CpfValidatorTest < ActiveSupport::TestCase
7
7
  class M1
8
8
  include ActiveModel::Model
9
9
 
10
10
  attr_accessor :cpf
11
11
 
12
- validates :cpf, 'eac/cpf' => true, allow_nil: true
12
+ validates :cpf, 'eac_rails_utils/cpf' => true, allow_nil: true
13
13
  end
14
14
 
15
15
  def setup
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_rails_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.11.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: 2020-05-12 00:00:00.000000000 Z
11
+ date: 2020-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel-associations
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.2
19
+ version: '0.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.2
26
+ version: '0.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bootstrap-sass
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,33 +39,39 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: 3.3.6
41
41
  - !ruby/object:Gem::Dependency
42
- name: htmlbeautifier
42
+ name: eac_ruby_utils
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.33'
45
48
  - - ">="
46
49
  - !ruby/object:Gem::Version
47
- version: 1.1.1
50
+ version: 0.33.1
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '0.33'
52
58
  - - ">="
53
59
  - !ruby/object:Gem::Version
54
- version: 1.1.1
60
+ version: 0.33.1
55
61
  - !ruby/object:Gem::Dependency
56
- name: ofx-parser
62
+ name: htmlbeautifier
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - ">="
60
66
  - !ruby/object:Gem::Version
61
- version: 1.1.0
67
+ version: 1.1.1
62
68
  type: :runtime
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
72
  - - ">="
67
73
  - !ruby/object:Gem::Version
68
- version: 1.1.0
74
+ version: 1.1.1
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: rails
71
77
  requirement: !ruby/object:Gem::Requirement
@@ -143,9 +149,34 @@ extensions: []
143
149
  extra_rdoc_files: []
144
150
  files:
145
151
  - Rakefile
152
+ - app/helpers/eac_rails_utils/common_form_helper.rb
153
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder.rb
154
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/association_select_field.rb
155
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/common_text_fields.rb
156
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/currency_field.rb
157
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/date_field.rb
158
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/fields_for.rb
159
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/file_field.rb
160
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
161
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/searchable_association_field.rb
162
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
163
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/time_field.rb
164
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/year_month_field.rb
165
+ - app/helpers/eac_rails_utils/data_table_helper.rb
166
+ - app/helpers/eac_rails_utils/data_table_helper/column.rb
167
+ - app/helpers/eac_rails_utils/data_table_helper/data_table.rb
168
+ - app/helpers/eac_rails_utils/data_table_helper/setup.rb
146
169
  - app/helpers/eac_rails_utils/formatter_helper.rb
147
170
  - app/helpers/eac_rails_utils/links_helper.rb
171
+ - app/helpers/eac_rails_utils/menus_helper.rb
172
+ - app/helpers/eac_rails_utils/menus_helper/bootstrap_gui_builder.rb
173
+ - app/helpers/eac_rails_utils/menus_helper/data_builder.rb
174
+ - app/helpers/eac_rails_utils/menus_helper/gui_builder.rb
148
175
  - app/helpers/eac_rails_utils/open_graph_protocol_helper.rb
176
+ - app/validators/eac_rails_utils/cpf_validator.rb
177
+ - app/validators/eac_rails_utils/no_presence_validator.rb
178
+ - config/locales/en.yml
179
+ - config/locales/pt-BR.yml
149
180
  - lib/assets/javascripts/currency_field.js
150
181
  - lib/assets/javascripts/eac_rails_utils.js
151
182
  - lib/assets/javascripts/input_searchable.js
@@ -157,42 +188,21 @@ files:
157
188
  - lib/assets/stylesheets/eac_rails_utils.scss
158
189
  - lib/assets/stylesheets/jmenu.scss
159
190
  - lib/assets/stylesheets/jquery.dataTables.min.css
160
- - lib/eac/common_form_helper.rb
161
- - lib/eac/common_form_helper/form_builder.rb
162
- - lib/eac/common_form_helper/form_builder/association_select_field.rb
163
- - lib/eac/common_form_helper/form_builder/common_text_fields.rb
164
- - lib/eac/common_form_helper/form_builder/currency_field.rb
165
- - lib/eac/common_form_helper/form_builder/date_field.rb
166
- - lib/eac/common_form_helper/form_builder/fields_for.rb
167
- - lib/eac/common_form_helper/form_builder/file_field.rb
168
- - lib/eac/common_form_helper/form_builder/radio_select_field.rb
169
- - lib/eac/common_form_helper/form_builder/searchable_association_field.rb
170
- - lib/eac/common_form_helper/form_builder/select_field.rb
171
- - lib/eac/common_form_helper/form_builder/time_field.rb
172
- - lib/eac/common_form_helper/form_builder/year_month_field.rb
173
- - lib/eac/cpf_validator.rb
174
- - lib/eac/data_table_helper.rb
175
- - lib/eac/data_table_helper/column.rb
176
- - lib/eac/data_table_helper/data_table.rb
177
- - lib/eac/data_table_helper/setup.rb
178
- - lib/eac/htmlbeautifier.rb
179
- - lib/eac/inequality_queries.rb
180
- - lib/eac/menus_helper.rb
181
- - lib/eac/menus_helper/bootstrap_gui_builder.rb
182
- - lib/eac/menus_helper/data_builder.rb
183
- - lib/eac/menus_helper/gui_builder.rb
184
- - lib/eac/model.rb
185
- - lib/eac/no_presence_validator.rb
186
- - lib/eac/test_utils.rb
187
191
  - lib/eac_rails_utils.rb
188
192
  - lib/eac_rails_utils/engine.rb
193
+ - lib/eac_rails_utils/htmlbeautifier.rb
194
+ - lib/eac_rails_utils/models.rb
195
+ - lib/eac_rails_utils/models/attribute_required.rb
196
+ - lib/eac_rails_utils/models/fetch_errors.rb
197
+ - lib/eac_rails_utils/models/inequality_queries.rb
198
+ - lib/eac_rails_utils/models/tableless.rb
199
+ - lib/eac_rails_utils/models/test_utils.rb
200
+ - lib/eac_rails_utils/patches.rb
189
201
  - lib/eac_rails_utils/patches/action_controller_base.rb
190
- - lib/eac_rails_utils/patches/model_attribute_required.rb
191
- - lib/eac_rails_utils/patches/ofx_parser.rb
192
- - lib/eac_rails_utils/tableless_model.rb
202
+ - lib/eac_rails_utils/patches/active_model_associations.rb
193
203
  - lib/eac_rails_utils/version.rb
194
- - test/app/helpers/eac_rails_utils/formatter_helper_test.rb
195
204
  - test/dummy/Rakefile
205
+ - test/dummy/app/assets/config/manifest.js
196
206
  - test/dummy/app/models/job.rb
197
207
  - test/dummy/app/models/user.rb
198
208
  - test/dummy/config.ru
@@ -208,17 +218,14 @@ files:
208
218
  - test/dummy/db/migrate/20160415143123_create_jobs.rb
209
219
  - test/dummy/db/migrate/20160415143229_add_job_to_users.rb
210
220
  - test/dummy/db/schema.rb
211
- - test/lib/eac/common_form_helper_test.rb
212
- - test/lib/eac/cpf_validator_test.rb
213
- - test/lib/eac/data_table_test_helper_test.rb
214
- - test/lib/eac/model_test.rb
215
- - test/lib/eac/source_target_fixtures_test_files/a.source.html
216
- - test/lib/eac/source_target_fixtures_test_files/a.target.yaml
217
- - test/lib/eac/source_target_fixtures_test_files/b.source.html
218
- - test/lib/eac/source_target_fixtures_test_files/c.target.yaml
219
- - test/lib/eac_rails_utils/patches/model_attribute_required_test.rb
220
- - test/lib/eac_rails_utils/tableless_model_test.rb
221
+ - test/helpers/eac_rails_utils/common_form_helper_test.rb
222
+ - test/helpers/eac_rails_utils/data_table_test_helper_test.rb
223
+ - test/helpers/eac_rails_utils/formatter_helper_test.rb
224
+ - test/lib/eac_rails_utils/models/attribute_required_test.rb
225
+ - test/lib/eac_rails_utils/models/fetch_errors_test.rb
226
+ - test/lib/eac_rails_utils/models/tableless_test.rb
221
227
  - test/test_helper.rb
228
+ - test/validators/cpf_validator_test.rb
222
229
  homepage:
223
230
  licenses: []
224
231
  metadata: {}
@@ -237,8 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
244
  - !ruby/object:Gem::Version
238
245
  version: '0'
239
246
  requirements: []
240
- rubyforge_project:
241
- rubygems_version: 2.7.7
247
+ rubygems_version: 3.0.8
242
248
  signing_key:
243
249
  specification_version: 4
244
250
  summary: Código reutilizável para as aplicações Rails da E.A.C..
@@ -259,15 +265,12 @@ test_files:
259
265
  - test/dummy/db/migrate/20160415125333_create_users.rb
260
266
  - test/dummy/app/models/job.rb
261
267
  - test/dummy/app/models/user.rb
268
+ - test/dummy/app/assets/config/manifest.js
262
269
  - test/test_helper.rb
263
- - test/app/helpers/eac_rails_utils/formatter_helper_test.rb
264
- - test/lib/eac_rails_utils/patches/model_attribute_required_test.rb
265
- - test/lib/eac_rails_utils/tableless_model_test.rb
266
- - test/lib/eac/common_form_helper_test.rb
267
- - test/lib/eac/data_table_test_helper_test.rb
268
- - test/lib/eac/cpf_validator_test.rb
269
- - test/lib/eac/source_target_fixtures_test_files/c.target.yaml
270
- - test/lib/eac/source_target_fixtures_test_files/b.source.html
271
- - test/lib/eac/source_target_fixtures_test_files/a.target.yaml
272
- - test/lib/eac/source_target_fixtures_test_files/a.source.html
273
- - test/lib/eac/model_test.rb
270
+ - test/validators/cpf_validator_test.rb
271
+ - test/helpers/eac_rails_utils/common_form_helper_test.rb
272
+ - test/helpers/eac_rails_utils/data_table_test_helper_test.rb
273
+ - test/helpers/eac_rails_utils/formatter_helper_test.rb
274
+ - test/lib/eac_rails_utils/models/attribute_required_test.rb
275
+ - test/lib/eac_rails_utils/models/tableless_test.rb
276
+ - test/lib/eac_rails_utils/models/fetch_errors_test.rb
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_dependency 'eac/data_table_helper/column'
4
- require_dependency 'eac/data_table_helper/setup'
5
- require_dependency 'eac/data_table_helper/data_table'
6
-
7
- module Eac
8
- module DataTableHelper
9
- def data_table(dataset, &block)
10
- ::Eac::DataTableHelper::DataTable.new(self, dataset, &block).output
11
- end
12
- end
13
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Eac
4
- # == Example:
5
- #
6
- # Note: model Product has a attribute "foo" Date, Time or Number:
7
- #
8
- # class Product
9
- # include ::Eac::InequalityQueries
10
- #
11
- # add_inequality_queries(:foo)
12
- # end
13
- #
14
- # This add the following scopes:
15
- #
16
- # Product.by_foo_gt(value) # Equivalent to Product.where("foo > ?", value)
17
- # Product.by_foo_gteq(value) # Equivalent to Product.where("foo >= ?", value)
18
- # Product.by_foo_lt(value) # Equivalent to Product.where("foo < ?", value)
19
- # Product.by_foo_lteq(value) # Equivalent to Product.where("foo <= ?", value)
20
- module InequalityQueries
21
- class << self
22
- def included(base)
23
- base.extend(ClassMethods)
24
- end
25
- end
26
-
27
- module ClassMethods
28
- def add_inequality_queries(attribute)
29
- %w[gt gteq lt lteq].each do |ineq|
30
- scope "by_#{attribute}_#{ineq}", lambda { |v|
31
- where(arel_table[attribute].send(ineq, v))
32
- }
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,90 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Eac
4
- module Model
5
- # Adiciona as mensagens de erro de record. As mensagens de uma coluna X em record
6
- # serão adicionadas na coluna X em self. Se options[:default_column] for especificado
7
- # as mensagens da coluna X de record em que X não existe em self serão adicionadas
8
- # na coluna options[:default_column].
9
- # Um array de colunas pode ser passado em options[:skip] de colunas em record que não
10
- # terão suas falhas adicionadas.
11
- def fetch_record_errors(record, options = {})
12
- record.errors.keys.each do |column|
13
- fetch_column_errors(record, column, column, options)
14
- end
15
- end
16
-
17
- # Similar a fetch_record_errors, mas torna possível especificar, através de mapping,
18
- # colunas-alvo em self com nomes diferentes das colunas-fonte em record.
19
- # mapping tem o formato { record_column => self_column }.
20
- def fetch_record_errors_by_mapping(record, mapping, options = {})
21
- mapping.each do |record_column, self_column|
22
- fetch_column_errors(record, record_column, self_column, options)
23
- end
24
- end
25
-
26
- def fetch_column_errors(record, record_column, self_column, options = {})
27
- return if options[:skip]&.include?(record_column)
28
-
29
- record.errors[record_column].each do |message|
30
- fetch_error_column_message(self_column, message, options[:default_column],
31
- "#{record.class.human_attribute_name(record_column)}: ")
32
- end
33
- end
34
-
35
- # Verifica se uma coluna existe.
36
- def column?(column)
37
- respond_to?(column) && respond_to?("#{column}=")
38
- end
39
-
40
- def save_or_raise
41
- raise "Falha ao tentar salvar #{self.class.name}: #{errors_to_string}" unless save
42
-
43
- self
44
- end
45
-
46
- private
47
-
48
- def fetch_error_column_message(column, message, default_column, default_column_message_prefix)
49
- build_self_columns_messages(column, message, default_column,
50
- default_column_message_prefix).each do |k, v|
51
- if column?(k)
52
- add_error_message(k, v)
53
- break
54
- end
55
- end
56
- end
57
-
58
- # Adiciona uma mensagem de erro a uma coluna somente se a coluna
59
- # ainda não a possui
60
- def add_error_message(column, message)
61
- return if errors[column].include?(message)
62
-
63
- errors.add(column, message)
64
- end
65
-
66
- # Produz uma lista de campos-mensagens, em ordem de preferência,
67
- # que podem receber uma mensagem de falha.
68
- def build_self_columns_messages(column, message, default_column,
69
- default_column_message_prefix)
70
- r = { column => message }
71
- m = /^(.+)_id$/.match(column)
72
- if m
73
- r[m[1]] = message
74
- else
75
- r["#{column}_id"] = message
76
- end
77
- r[default_column] = "#{default_column_message_prefix}#{message}" if default_column
78
- r
79
- end
80
-
81
- def errors_to_string
82
- b = ''
83
- errors.messages.each do |field, messages|
84
- b += ' / ' if b != ''
85
- b += field.to_s + ': ' + messages.to_s
86
- end
87
- b
88
- end
89
- end
90
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Eac
4
- module TestUtils
5
- # Add more helper methods to be used by all tests here...
6
- def valid_invalid_column_values_test(record, column, valid_values, invalid_values)
7
- valid_values.each do |v|
8
- record.send("#{column}=", v)
9
- assert record.valid?, "#{record.errors.messages}, #{column} = #{v.inspect} should be valid"
10
- end
11
- invalid_values.each do |v|
12
- record.send("#{column}=", v)
13
- assert_not record.valid?, "#{column} = #{v.inspect} should be invalid"
14
- end
15
- end
16
-
17
- # Verifica falhas em campos específicos de um record
18
- def assert_record_errors(record, fields_without_error, fields_with_error)
19
- fields_without_error.each do |c|
20
- assert record.errors[c].empty?, "Column: #{c} should not have errors (#{record.errors[c]})"
21
- end
22
- fields_with_error. each do |c|
23
- assert_not record.errors[c].empty?, "Column: #{c} should have errors"
24
- end
25
- end
26
-
27
- # Verifica, campo por campo, se invalida o registro.
28
- def assert_column_changes(ppp, expected_valid_result, changes)
29
- changes.each do |k, v|
30
- ppp.send("#{k}=", v)
31
- assert_equal expected_valid_result, ppp.valid?,
32
- "\"#{k}\" change should be " + (expected_valid_result ? 'valid' : 'invalid')
33
- assert_not ppp.errors[k].empty? unless expected_valid_result
34
- ppp.restore_attributes
35
- end
36
- end
37
-
38
- # Ex.: attrs = {a: 1, b: 2} resulta em
39
- # [{a: nil, b: nil}, {a: 1, b: nil}, {a: nil, b: 2}, {a: 1, b: 2}].
40
- def all_combinations(attrs)
41
- combs = [{}]
42
- attrs.each do |attr_name, value|
43
- combs = all_combinations_new_combination(attr_name, value, combs)
44
- end
45
- combs
46
- end
47
-
48
- def all_combinations_new_combination(attr_name, value, combs)
49
- new_comb = []
50
- assert_not value.nil?, "#{attr_name}=#{value}"
51
- [nil, value].each do |vv|
52
- combs.each do |c|
53
- cc = c.dup
54
- cc[attr_name] = vv
55
- new_comb << cc
56
- end
57
- end
58
- new_comb
59
- end
60
- end
61
- end