Sha256: dcff806abf2397500d80bbb20f3c414c299bdadaf960f0a4b48b5deee7ab552e
Contents?: true
Size: 782 Bytes
Versions: 6
Compression:
Stored size: 782 Bytes
Contents
$sequence_counter = 0 def sequence(pattern) # pattern.gsub(/\{\{sequence\}\}/) do pattern.gsub(/\{\{sequence\}\}/) do "JH" $sequence_counter += 1 end end def attrs(table) case table when :user { role_id: 123, first_name: sequence("First {{sequence}}"), last_name: sequence("Last {{sequence}}"), access_level: "viewable" } when :unique_user { first_name: sequence("First {{sequence}}"), last_name: sequence("Last {{sequence}}") } else raise ArgumentError, "Invalid table for factory: #{table.inspect}" end end def create(table) table_name = table.to_s.pluralize id = Simple::SQL.insert(table_name, attrs(table)) Simple::SQL.ask("SELECT * FROM #{table_name} WHERE id=$1", id, into: OpenStruct) end
Version data entries
6 entries across 6 versions & 1 rubygems