Skip to content

Commit

Permalink
Projects dates default to Any
Browse files Browse the repository at this point in the history
Responds to @mo-nathan's comment
#1658 (comment)
  • Loading branch information
JoeCohen committed Dec 24, 2023
1 parent fb9af83 commit 06035e3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def show
def new
image_ivars
@project = Project.new
@project_dates_any = false
@project_dates_any = true
end

# Form to edit a project
Expand Down
10 changes: 8 additions & 2 deletions test/controllers/projects_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,17 @@ def test_add_project

assert_select(
"input[type=radio][id=project_dates_any_true]", { count: 1 },
"Missing radio button to make project dates a range"
"Missing radio button to make project dates any dates"
)
assert_select(
"input[type=radio][id=project_dates_any_false]", { count: 1 },
"Missing radio button to make project dates any dates"
"Missing radio button to make project dates a range"
)

assert_select(
"input[type=radio][id=project_dates_any_true][checked=checked]",
{ count: 1 },
"'Any' dates radio button should be checked by default"
)
end

Expand Down
27 changes: 15 additions & 12 deletions test/integration/capybara/projects_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
class ProjectsIntegrationTest < CapybaraIntegrationTestCase
def test_add_project_dates
login(mary)
title = "Super International Fungal Foray"
title = "Ongoing Project Any Dates"

# ----- Add project, default dates
visit(projects_path)
click_on(:list_projects_add_project.l)
fill_in("project_title", with: title)
fill_in(:WHERE.l, with: locations(:unknown_location).name)
assert_selector(
"input[type='radio'][id='project_dates_any_false'][checked='checked']"
"input[type='radio'][id='project_dates_any_true'][checked='checked']"
)
assert_selector("input[type='radio'][id='project_dates_any_false']")

Expand All @@ -23,30 +23,33 @@ def test_add_project_dates
end

project = Project.find_by_title(title)
assert_equal(Time.zone.today, project.start_date,
"Project Start Date should default to current date")
assert_equal(Time.zone.today, project.end_date,
"Project End Date should default to current date")

# ----- Add project, any dates
title = "Ongoing Project Any Dates"
assert_nil(project.start_date, "Project Start Date should be nil")
assert_nil(project.end_date, "Project Start Date should be nil")

# ----- Add project, specified date range
title = "Super International Fungal Foray"
visit(projects_path)
click_on(:list_projects_add_project.l)
fill_in("project_title", with: title)
fill_in(:WHERE.l, with: locations(:unknown_location).name)
choose("project_dates_any_true")
choose("project_dates_any_false")
assert_selector(
"input[type='radio'][id='project_dates_any_true'][checked='checked']"
"input[type='radio'][id='project_dates_any_false'][checked='checked']"
)

default_start_and_end_date = Time.zone.today

assert_difference("Project.count", 1, "Failed to created Project") do
click_on("Create")
end

project = Project.find_by_title(title)
assert_equal(title, project.title)
assert_nil(project.start_date, "Project Start Date should be nil")
assert_nil(project.end_date, "Project Start Date should be nil")
assert_equal(project.start_date, default_start_and_end_date,
"Project Start Date should be today")
assert_equal(project.end_date, default_start_and_end_date,
"Project End Date should be today")
end

def test_project_change_to_any_dates
Expand Down

0 comments on commit 06035e3

Please sign in to comment.