Skip to content

Commit 8f201e7

Browse files
committed
dummy: rename numericality validation fields
1 parent a233770 commit 8f201e7

File tree

4 files changed

+25
-45
lines changed

4 files changed

+25
-45
lines changed

test/dummy/app/models/concerns/fields/validations/numericality.rb

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,55 +19,36 @@ def interpret_to(model, field_name, accessibility, options = {})
1919
end
2020

2121
class NumericalityOptions < FieldOptions
22-
attribute :lower_value, :float, default: 0.0
23-
attribute :upper_value, :float, default: 0.0
22+
attribute :lower_bound_check, :string, default: "disabled"
23+
attribute :upper_bound_check, :string, default: "disabled"
2424

25-
enum lower_bound: {
25+
attribute :lower_bound_value, :float, default: 0.0
26+
attribute :upper_bound_value, :float, default: 0.0
27+
28+
enum lower_bound_check: {
2629
disabled: "disabled",
2730
greater_than: "greater_than",
2831
greater_than_or_equal_to: "greater_than_or_equal_to"
29-
}, _prefix: :lower_bound
30-
enum upper_bound: {
32+
}, _prefix: :lower_bound_check
33+
enum upper_bound_check: {
3134
disabled: "disabled",
3235
less_than: "less_than",
3336
less_than_or_equal_to: "less_than_or_equal_to"
34-
}, _prefix: :upper_bound
35-
36-
attribute :lower_bound, :string, default: "disabled"
37-
attribute :upper_bound, :string, default: "disabled"
38-
39-
def greater_than=(value)
40-
self.lower_bound = "greater_than"
41-
self.lower_value = value
42-
end
43-
44-
def greater_than_or_equal_to=(value)
45-
self.lower_bound = "greater_than_or_equal_to"
46-
self.lower_value = value
47-
end
48-
49-
def less_than=(value)
50-
self.upper_bound = "less_than"
51-
self.upper_value = value
52-
end
53-
54-
def less_than_or_equal_to=(value)
55-
self.upper_bound = "less_than_or_equal_to"
56-
self.upper_value = value
57-
end
37+
}, _prefix: :upper_bound_check
5838

59-
validates :upper_value,
39+
validates :upper_bound_value,
6040
numericality: {
61-
greater_than: :lower_value
41+
greater_than: :lower_bound_value
6242
},
63-
if: proc { upper_bound != "disabled" && lower_bound != "disabled" }
43+
if: proc { upper_bound_check != "disabled" && lower_bound_check != "disabled" }
6444

6545
def interpret_to(model, field_name, _accessibility, _options = {})
6646
options = {}
67-
options[lower_bound] = lower_value unless lower_bound_disabled?
68-
options[upper_bound] = upper_value unless upper_bound_disabled?
47+
options[lower_bound_check] = lower_bound_value unless lower_bound_check_disabled?
48+
options[upper_bound_check] = upper_bound_value unless upper_bound_check_disabled?
6949
return if options.empty?
7050

51+
options.symbolize_keys!
7152
model.validates field_name, numericality: options, allow_blank: true
7253
end
7354
end

test/dummy/app/presenters/concerns/fields/presenter_for_number_field.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ module PresenterForNumberField
55
extend ActiveSupport::Concern
66

77
def min
8-
return if @model.validations.numericality.lower_bound_disabled?
8+
return if @model.validations.numericality.lower_bound_check_disabled?
99

10-
min = @model.validations.numericality.lower_value
10+
min = @model.validations.numericality.lower_bound_value
1111
integer_only? ? min.to_i : min
1212
end
1313

1414
def max
15-
return if @model.validations.numericality.upper_bound_disabled?
15+
return if @model.validations.numericality.upper_bound_check_disabled?
1616

17-
max = @model.validations.numericality.upper_value
17+
max = @model.validations.numericality.upper_bound_value
1818
integer_only? ? max.to_i : max
1919
end
2020

test/dummy/app/views/_form_core/validations/_numericality.html.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@
2222
<div class="field has-addons">
2323
<div class="control">
2424
<span class="select">
25-
<%= ff.select :lower_bound, options_for_enum_select(numericality.class, :lower_bound, numericality.lower_bound), {}, class: "select" %>
25+
<%= ff.select :lower_bound_check, options_for_enum_select(numericality.class, :lower_bound_check, numericality.lower_bound_check), {}, class: "select" %>
2626
</span>
2727
</div>
2828
<div class="control">
29-
<%= ff.number_field :lower_value, step: 0.01, class: "input" %>
29+
<%= ff.number_field :lower_bound_value, step: 0.01, class: "input" %>
3030
</div>
3131
</div>
3232

3333
<div class="field has-addons">
3434
<div class="control">
3535
<span class="select">
36-
<%= ff.select :upper_bound, options_for_enum_select(numericality.class, :upper_bound, numericality.upper_bound), {}, class: "select" %>
36+
<%= ff.select :upper_bound_check, options_for_enum_select(numericality.class, :upper_bound_check, numericality.upper_bound_check), {}, class: "select" %>
3737
</span>
3838
</div>
3939
<div class="control">
40-
<%= ff.number_field :upper_value, step: 0.01, class: "input" %>
40+
<%= ff.number_field :upper_bound_value, step: 0.01, class: "input" %>
4141
</div>
4242
</div>
4343
<% end %>

test/dummy/config/locales/form_core.en.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@ en:
5050
minimum: Minimum
5151
maximum: Maximum
5252
is: Equal
53-
lower_bounds:
53+
lower_bound_checks:
5454
disabled: 'Off'
5555
greater_than: '>'
5656
greater_than_or_equal_to: '>='
57-
upper_bounds:
57+
upper_bound_checks:
5858
disabled: 'Off'
5959
less_than: '<'
6060
less_than_or_equal_to: '<='
61-

0 commit comments

Comments
 (0)