Class: DataObjectFactory

Inherits:
Object
  • Object
show all
Includes:
DataFactory, Foundry
Defined in:
lib/test-factory/data_object.rb

Overview

The Superclass for all of your data objects.

Direct Known Subclasses

DataObject

Instance Method Summary collapse

Methods included from DataFactory

#checkbox_setting, #collection, #edit_fields, #edit_item_fields, #fill_out, #fill_out_item, #get_or_select, #get_or_select!, #ordered_fill, #ordered_item_fill, #requires, #set_options

Methods included from Foundry

#create, #make, #on, #visit, #wait_until

Instance Method Details

#data_object_copyObject

Since Data Objects are not “Marshallable”, and they generally contain lots of types of data in their instance variables, we have this method. This will create and return a ‘deep copy’ of the data object as well as any and all nested data objects and collections it contains.

Please note that this method will fail if you are putting Data Objects into Arrays or Hashes instead of into Collection classes



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/test-factory/data_object.rb', line 31

def data_object_copy
  opts = {}
  self.instance_variables.each do |var|
    key = var.to_s.gsub('@','').to_sym
    orig_val = instance_variable_get var
    opts[key] = case
                  when orig_val.kind_of?(CollectionsFactory)
                    orig_val.copy
                  when orig_val.instance_of?(Array) || orig_val.instance_of?(Hash)
                    Marshal::load(Marshal.dump(orig_val))
                  when orig_val.kind_of?(DataObject)
                    orig_val.data_object_copy
                  else
                    orig_val
                end
  end
  self.class.new(@browser, opts)
end