Class: DatashiftJourney::StateJumperController

Inherits:
ApplicationController show all
Defined in:
app/controllers/datashift_journey/state_jumper_controller.rb

Instance Method Summary collapse

Instance Method Details

#build_and_displayObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/datashift_journey/state_jumper_controller.rb', line 22

def build_and_display
  state =   params['state']
  factory = params['factory']

  plan = if factory
           # Get weird problems with factories with has_many associations, when they've already been used,
           # so while obviously not very efficient, this seems to prevent that issue
           FactoryGirl.reload

           Rails.logger.debug("Building StateJumper #{DatashiftJourney.journey_plan_class} from [#{factory}]")

           FactoryGirl.create(factory)
         else
           DatashiftJourney.journey_plan_class.create(state: state)
         end

  if plan.state != state
    plan.skip_fwd(state.to_sym) until !plan.can_skip_fwd? || plan.state == state
  end

  plan.update_attribute(:state, state) if plan.state != state

  Rails.logger.debug("Jumping to STATE [#{plan.state}]")

  redirect_to(datashift_journey.journey_plan_state_path(state, plan)) && return
end