Updated

app/controllers/admin / debate_outcomes_controller.rb

B
49 lines of codes
7 methods
3.3 complexity/method
17 churn
23.43 complexity
28 duplications
class Admin::DebateOutcomesController < Admin::AdminController
  1. Admin::DebateOutcomesController assumes too much for instance variable '@debate_outcome'
  2. Admin::DebateOutcomesController assumes too much for instance variable '@petition'
  3. Admin::DebateOutcomesController has no descriptive comment
before_action :fetch_petition before_action :fetch_debate_outcome rescue_from ActiveRecord::RecordNotUnique do @debate_outcome = @petition.debate_outcome(true) and update end def show render 'admin/petitions/show' end def update
  1. Similar code found in 3 nodes Locations: 0 1 2
if @debate_outcome.update(debate_outcome_params) if send_email_to_petitioners? EmailDebateOutcomesJob.run_later_tonight(petition: @petition) message = :email_sent_overnight else message = :debate_outcome_updated end redirect_to [:admin, @petition], notice: message else render 'admin/petitions/show' end end private def fetch_petition @petition = Petition.debateable.find(params[:petition_id]) end def fetch_debate_outcome @debate_outcome = @petition.debate_outcome || @petition.build_debate_outcome end def debate_outcome_params params.require(:debate_outcome).permit(*debate_outcome_attributes) end def debate_outcome_attributes %i[debated_on overview transcript_url video_url debate_pack_url debated commons_image] end def send_email_to_petitioners? params.key?(:save_and_email) end end