Skip to content

Commit

Permalink
Merge pull request #2034 from MushroomObserver/2033-project-violation…
Browse files Browse the repository at this point in the history
…s-error

Project.location nil Error
  • Loading branch information
JoeCohen committed Mar 17, 2024
2 parents 05382aa + 36099e1 commit d669ad8
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 6 deletions.
26 changes: 22 additions & 4 deletions app/helpers/projects_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ def violation_table_headers(project)
nil, # column for checkbox
"#{:CONSTRAINTS.l}:",
"#{:DATES.l}: #{project.date_range}",
"Lat: #{project.location.north} to #{project.location.south}",
"Lon: #{project.location.west} to #{project.location.east} ",
location_link(project.location.display_name, project.location,
nil, false),
violation_latitude_header(project),
violation_longitude_header(project),
violation_location_header(project),
nil # column for observation.user
]
end
Expand Down Expand Up @@ -45,6 +44,25 @@ def violations_submit_text(project)

private

def violation_latitude_header(project)
return :form_violations_latitude_none.l unless project.location

"Lat: #{project.location.north} to #{project.location.south}"
end

def violation_longitude_header(project)
return :form_violations_longitude_none.l unless project.location

"Lon: #{project.location.west} to #{project.location.east}"
end

def violation_location_header(project)
return :form_violations_location_none.t unless project.location

location_link(project.location.display_name, project.location,
nil, false)
end

def violation_checkbox(form:, project:, obs:)
if violation_checkbox_viewers(project, obs).include?(User.current.id)
form.check_box("remove_#{obs.id}")
Expand Down
2 changes: 2 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ def in_range_observations
# Obs lat/lon is outside Project.location exor
# Obs location is not a subset of Project.location
def out_of_area_observations
return [] if location.nil?

obs_geoloc_outside_project_location.to_a.union(
obs_without_geoloc_location_not_contained_in_location
)
Expand Down
5 changes: 4 additions & 1 deletion config/locales/en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3249,9 +3249,12 @@
show_project_user_group: User Group
show_project_violation_count: Project has [count] constraint violation(s)

# project/violations/edit
# project/violations/index
form_violations_help: Check the Observations to be removed, then Submit
violations_index_title: "[:CONSTRAINT_VIOLATIONS]"
form_violations_latitude_none: "Lat: Any"
form_violations_location_none: "[:LOCATION]: Any"
form_violations_longitude_none: "Lon: Any"
form_violations_remove_selected: Remove Selected
form_violations_show_project: Show Project

Expand Down
22 changes: 22 additions & 0 deletions test/controllers/projects/violations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,28 @@ def test_index_by_non_member
)
end

def test_index_project_without_location
project = projects(:unlimited_project)
assert_nil(project.location, "Test need Project lacking a Location")
user = project.user

login(user.login)
get(:index, params: { project_id: project.id })

assert_select(
"#project_violations_form",
{ text: /#{:form_violations_latitude_none.l}/ }
)
assert_select(
"#project_violations_form",
{ text: /#{:form_violations_longitude_none.l}/ }
)
assert_select(
"#project_violations_form",
{ text: /#{:form_violations_location_none.l}/ }
)
end

def test_update
project = projects(:falmouth_2023_09_project)
violations = project.violations
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/projects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ unlimited_project:
<<: *DEFAULTS
start_date: nil
end_date: nil
location: nil
observations: peltigera_obs, agaricus_campestris_obs, boletus_edulis_obs

pinned_date_range_project:
Expand All @@ -222,7 +223,6 @@ rolf_project:
user_group: katrina_only

# includes observations that violate date and or location constraints

# members: roy
falmouth_2023_09_project:
<<: *DEFAULTS
Expand Down
7 changes: 7 additions & 0 deletions test/models/project_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ def assert_in_range_observations(project,
assert_equal(expect, project.in_range_observations.count)
end

def test_out_of_area_observations
project = projects(:falmouth_2023_09_project)
assert_equal(2, project.out_of_area_observations.size)

assert_empty(projects(:unlimited_project).out_of_area_observations)
end

def test_place_name
proj = projects(:eol_project)
loc = locations(:albion)
Expand Down

0 comments on commit d669ad8

Please sign in to comment.