Skip to content

Commit

Permalink
Refactor test ParamsTask attributes to have more meaningful names
Browse files Browse the repository at this point in the history
  • Loading branch information
lavoiesl committed Jun 7, 2024
1 parent c1e972a commit 4e7c7ce
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
12 changes: 6 additions & 6 deletions test/dummy/app/tasks/maintenance/params_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ class ParamsTask < MaintenanceTasks::Task
validates_inclusion_of :boolean_dropdown_attr, within: [true, false], allow_nil: true

# Dropdown options with unsupported scenarios
attribute :text_integer_attr, :integer
attribute :text_integer_attr2, :integer
attribute :text_integer_attr3, :integer
attribute :text_integer_attr_proc_no_arg, :integer
attribute :text_integer_attr_undefined_symbol, :integer
attribute :text_integer_attr_unbounded_range, :integer

validates_inclusion_of :text_integer_attr, in: proc { [100, 200, 300] }, allow_nil: true
validates_inclusion_of :text_integer_attr2, in: :undefined_symbol, allow_nil: true
validates_inclusion_of :text_integer_attr3, in: (100..), allow_nil: true
validates_inclusion_of :text_integer_attr_proc_no_arg, in: proc { [100, 200, 300] }, allow_nil: true
validates_inclusion_of :text_integer_attr_undefined_symbol, in: :undefined_symbol, allow_nil: true
validates_inclusion_of :text_integer_attr_unbounded_range, in: (100..), allow_nil: true

class << self
attr_accessor :fast_task
Expand Down
17 changes: 12 additions & 5 deletions test/helpers/maintenance_tasks/tasks_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,19 @@ class TasksHelperTest < ActionView::TestCase
end

test "#resolve_inclusion_value resolves inclusion validator for task attributes" do
assert_match "Select a value", markup("integer_dropdown_attr").squish

assert_match "Select a value", markup("boolean_dropdown_attr").squish
[
"integer_dropdown_attr",
"boolean_dropdown_attr",
].each do |attribute|
assert_match "Select a value", markup(attribute).squish
end

["text_integer_attr", "text_integer_attr2", "text_integer_attr3"].each do |text_integer_attr|
refute_match "Select a value", markup(text_integer_attr).squish
[
"text_integer_attr_proc_no_arg",
"text_integer_attr_undefined_symbol",
"text_integer_attr_unbounded_range",
].each do |attribute|
refute_match "Select a value", markup(attribute).squish
end
end

Expand Down
6 changes: 3 additions & 3 deletions test/models/maintenance_tasks/task_data_show_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ class TaskDataShowTest < ActiveSupport::TestCase
"boolean_attr",
"integer_dropdown_attr",
"boolean_dropdown_attr",
"text_integer_attr",
"text_integer_attr2",
"text_integer_attr3",
"text_integer_attr_proc_no_arg",
"text_integer_attr_undefined_symbol",
"text_integer_attr_unbounded_range",
],
TaskDataShow.new("Maintenance::ParamsTask").parameter_names,
)
Expand Down
6 changes: 5 additions & 1 deletion test/system/maintenance_tasks/tasks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ class TasksTest < ApplicationSystemTestCase
boolean_dropdown_field_options = boolean_dropdown_field.find_all("option").map { |option| option[:value] }
assert_equal(["", "true", "false"], boolean_dropdown_field_options)

["text_integer_attr", "text_integer_attr2", "text_integer_attr3"].each do |text_integer_attr|
[
"text_integer_attr_proc_no_arg",
"text_integer_attr_undefined_symbol",
"text_integer_attr_unbounded_range",
].each do |text_integer_attr|
text_integer_dropdown_field = page.find_field("task[#{text_integer_attr}]")
assert_equal("input", text_integer_dropdown_field.tag_name)
assert_equal("number", text_integer_dropdown_field[:type])
Expand Down

0 comments on commit 4e7c7ce

Please sign in to comment.