class Balboa::Interactor::Command::FillPunchCommand

Constants

PunchCreationError
SUCCESS_MESSAGE
TIME_TEMPLATE

Public Class Methods

new(schedule, project) click to toggle source
# File lib/balboa/interactor/command/fill_punch_command.rb, line 16
def initialize(schedule, project)
  @schedule = schedule
  @project = project
end

Public Instance Methods

execute(date) click to toggle source
# File lib/balboa/interactor/command/fill_punch_command.rb, line 21
def execute(date)
  visit_new_punch_path

  fill_first_shift(date)

  visit_new_punch_path

  fill_second_shift(date)
end

Private Instance Methods

confirm() click to toggle source
# File lib/balboa/interactor/command/fill_punch_command.rb, line 54
def confirm
  click_button 'Criar Punch'

  raise PunchCreationError unless body[SUCCESS_MESSAGE]
end
fill_first_shift(date) click to toggle source
# File lib/balboa/interactor/command/fill_punch_command.rb, line 37
def fill_first_shift(date)
  fill_form(date, @schedule.start_at, @schedule.lunch_at)
end
fill_form(date, start_time, finish_time) click to toggle source
# File lib/balboa/interactor/command/fill_punch_command.rb, line 45
def fill_form(date, start_time, finish_time)
  fill_in 'punch[from_time]', with: TIME_TEMPLATE % start_time
  fill_in 'punch[to_time]', with: TIME_TEMPLATE % finish_time
  fill_in 'punch[when_day]', with: date.to_s
  select @project, from: 'punch[project_id]'

  confirm
end
fill_second_shift(date) click to toggle source
# File lib/balboa/interactor/command/fill_punch_command.rb, line 41
def fill_second_shift(date)
  fill_form(date, @schedule.restart_at, @schedule.leave_at)
end
visit_new_punch_path() click to toggle source
# File lib/balboa/interactor/command/fill_punch_command.rb, line 33
def visit_new_punch_path
  visit('/punches/new')
end