Commit 4624c4a8ce86390069f32be70428ec431f9a9129

Authored by Cyril Mougel
1 parent 76d3d2f8
Exists in master and in 1 other branch production

little refactoring to move all action about ProblemDestroy in ProblemDestroy class fix #208

app/controllers/errs_controller.rb
... ... @@ -114,10 +114,8 @@ class ErrsController < ApplicationController
114 114 end
115 115  
116 116 def destroy_several
117   - @selected_problems.each{|problem|
118   - ProblemDestroy.new(problem).execute
119   - }
120   - flash[:notice] = "#{pluralize(@selected_problems.count, 'err has', 'errs have')} been deleted."
  117 + nb_problem_destroy = ProblemDestroy.execute(@selected_problems)
  118 + flash[:notice] = "#{pluralize(nb_problem_destroy, 'err has', 'errs have')} been deleted."
121 119 redirect_to :back
122 120 end
123 121  
... ...
app/interactors/problem_destroy.rb
... ... @@ -12,6 +12,20 @@ class ProblemDestroy
12 12 problem.delete
13 13 end
14 14  
  15 + ##
  16 + # Destroy all problem pass in args
  17 + #
  18 + # @params [ Array[Problem] ] problems the list of problem need to be delete
  19 + # can be a single Problem
  20 + # @return [ Integer ]
  21 + # the number of problem destroy
  22 + #
  23 + def self.execute(problems)
  24 + Array(problems).each{ |problem|
  25 + ProblemDestroy.new(problem).execute
  26 + }.count
  27 + end
  28 +
15 29 private
16 30  
17 31 def errs_id
... ...