Module: ModelHelper

Defined in:
lib/watirmark/cucumber/model_helper.rb

Instance Method Summary collapse

Instance Method Details

#add_model_debug_values(table) ⇒ Object



2
3
4
5
6
# File 'lib/watirmark/cucumber/model_helper.rb', line 2

def add_model_debug_values(table)
  table.raw.each do |row|
    DebugModelValues[row[0]][row[1]] = row[2]
  end
end

#update_model(model, table) ⇒ Object



8
9
10
# File 'lib/watirmark/cucumber/model_helper.rb', line 8

def update_model(model, table)
  model.update(hash_record(table))
end

#with_model(model, table) ⇒ Object

Perform an action using a models and update the models if that action is successful



22
23
24
25
26
27
# File 'lib/watirmark/cucumber/model_helper.rb', line 22

def with_model(model, table)
  orig_model = model.clone
  update_model(model, table)
  yield
  model.update(orig_model.to_h)
end

#with_updated_model(model, table) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/watirmark/cucumber/model_helper.rb', line 12

def with_updated_model(model, table)
  unless model.includes?(hash_record(table))
    update_model(model, table)
    yield
    Watirmark.logger.info "Updated models '#{model.model_name}':\n#{hash_record(table).inspect}"
  end
end