Skip to content

extract creneaux construction to separate service

Vincent Agnano requested to merge refactor/creneaux-builder-service into master

Created by: adipasquale

refactor preliminary to introduce new complexity with: https://trello.com/c/nb3LeyAY/833-ne-pas-afficher-les-cr%C3%A9neaux-pass%C3%A9s-dans-trouver-un-creneau-ceux-du-matin-du-jour-meme

this PR can be read commit by commit

  • Creneau.for_motif_and_lieu_from_date_range is extracted to a separate CreneauxBuilderService
  • split out this big method into smaller private ones
  • introduce parent BaseService with a single class method perform_with that makes it easier to call services and especially easier to mock calls to these services:

if you want to mock a call to CreneauxBuilderService.new(x).perform you have to write:

let(:creneaux) { [...] }
let(:creneaux_builder_service) { instance_double(CreneauxBuilderService) }
expect(CreneauxBuilderService).to receive(:new).with(x).and_return(creneaux_builder_service)
expect(creneaux_builder_service).to receive(:perform).and_return(creneaux)

whereas if you want to mock a call to CreneauxBuilderService.perform_with(x) you just have to write:

let(:creneaux) { [...] }
expect(CreneauxBuilderService)).to receive(:perform_with).with(x).and_return(creneaux)

Merge request reports