Skip to content

Make the interpolated collection validation accept exactly one saved scenario. #202

@aaccensi

Description

@aaccensi

Bug Description

Validation for interpolated collections should expect exactly 1 saved scenario and now it check for 1 or more.


Steps to Reproduce

  1. Make the following curl call (or equivalent with your test data):
curl -X POST "http://localhost:3000/api/v1/collections" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $ETM_API_TOKEN" \
  -d '{"title":"Interpolated collection", "version":"latest", "saved_scenario_ids":[6,2], "interpolation":true}'
  1. Observe that there is no error
  2. Additionally you can observe the repercussion of this unexpected collection in the frontend by going to the listed collections in MyETM.

Expected interaction

It should raise an error


Proposed solutions

Change this code in app/models/collection.rb

 def validate_interpolated
    # Ensure interpolated collections (AKA transition paths) have no saved scenarios
    active_saved_scenarios = collection_saved_scenarios.reject(&:marked_for_destruction?)
    if self.interpolated? && active_saved_scenarios.size > 1
      errors.add(:scenarios, "interpolated collections cannot have more than 1 saved scenario")
    end
  end

To:

 def validate_interpolated
    # Ensure interpolated collections (AKA transition paths) have one saved scenario
    active_saved_scenarios = collection_saved_scenarios.reject(&:marked_for_destruction?)
    if self.interpolated? && active_saved_scenarios.size != 1
      errors.add(:scenarios, "interpolated collections must have exactly 1 saved scenario")
    end
  end

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions