module CucumberFactory::Switcher

Public Instance Methods

assign_attributes(model, attributes) click to toggle source
# File lib/cucumber_factory/switcher.rb, line 22
def assign_attributes(model, attributes)
  if active_record_version < 3
    model.send(:attributes=, attributes, false) # ignore attr_accessible
  elsif active_record_version < 4
    model.send(:assign_attributes, attributes, :without_protection => true)
  else
    model.send(:assign_attributes, attributes)
  end
end
find_last(klass) click to toggle source
# File lib/cucumber_factory/switcher.rb, line 5
def find_last(klass)
  # Don't use class.last, in sqlite that is not always the last inserted element
  # If created_at is available prefer it over id as column for ordering so that we can handle UUIDs
  primary_key = klass.primary_key
  has_numeric_primary_key = klass.columns_hash[primary_key].type == :integer
  order_column = if has_numeric_primary_key || !klass.column_names.include?('created_at')
    primary_key
  else
    "created_at, #{primary_key}"
  end
  if active_record_version < 4
    klass.find(:last, :order => order_column)
  else
    klass.order(order_column).last
  end
end

Private Instance Methods

active_record_version() click to toggle source
# File lib/cucumber_factory/switcher.rb, line 34
def active_record_version
  ActiveRecord::VERSION::MAJOR
end