sanger / sequencescape

Web based LIMS
MIT License
80 stars 32 forks source link

Y24-130 - Fix asset controller test for NPG actions with Rails 6.1 defaults #4138

Open dasunpubudumal opened 2 weeks ago

dasunpubudumal commented 2 weeks ago

Describe the Housekeeping

We have been using Rails 5.0 as our defaults, and are in the process of upgrading it to 6.1. The story that started the process of migrating the defaults to Rails 6.1 is https://github.com/sanger/sequencescape/issues/4005. Note that upgrading the Rails version in the Gemfile to 6.1 - which we did in https://github.com/sanger/sequencescape/issues/4006 - does not necessarily upgrade the Framework Defaults to 6.1. We need to update config/application.rb file's config.load_defaults value to 6.1, and it was done in https://github.com/sanger/sequencescape/issues/4005.

There were certain tests failing, including one Minitest, and we fixed them except for one test, which is spec/controllers/npg_actions/assets_controller_spec.rb:181.

The reason that this test fails is described below.

Take the following code snippet from app/models/batch_request.rb, which is the join table associating the Batch model and the Request model with a one-to-many relationship. The snippet is from the before_validation callback that is assigned to the BatchRequest model.

before_validation(if: :requires_position?, unless: :position?) do |record|
  record.position = (record.batch.batch_requests.filter_map(&:position).max || 0) + 1
end

Note: Since this is part of the validation process, any failure for this callback would inevitably lead to a failure to persist a batch_request record, thereby failing to create an association between a given batch and a request.

The purpose of this story is to investigate why this occur and provide a fix for the issue.

Furthermore, it might be beneficial to setup an actual use-case for this NPG action and invoke the endpoint that the test tries to invoke. This might help to localise whether if the issue is only within the test context.


Update: Please refer to the comments in https://github.com/sanger/sequencescape/issues/4138#issuecomment-2163397002 as well.

Blocking issues Describe any other issues or tickets that may be blocking this change.

Additional context Add any other context about the problem here.

TWJW-SANGER commented 2 weeks ago

Thanks Dasun.

I would add the following summary from the meeting. Feel free to correct if I've got things wrong.

For this story we require:

If we believe the current endpoint behavior is incorrect we will create another story to implement the correct behavior.

If the endpoint behaviour between Rails versions is consistent we can either rework the test so it works in Rails 6 or comment it out for re-implementation in another story.

If the endpoint behaviour between Rails versions is not consistent then we will need to take a view on possible options to correct or mitigate this.

It should be possible to test the endpoint under different Rails versions using the UAT environment, having set up the requests & batches manually.