Module: FixtureMe

Defined in:
lib/fixture_me.rb,
lib/fixture_me/version.rb

Defined Under Namespace

Classes: AddFixtures

Constant Summary collapse

VERSION =
"0.0.3"

Instance Method Summary collapse

Instance Method Details

#add_fixtureObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fixture_me.rb', line 5

def add_fixture
  hash = self.attributes
  md5 = Digest::MD5.hexdigest(hash.to_s)
  string = "#{md5}:\n"
  hash.each do |key,value|
    value.gsub!("\n","\n"+" "*4) if value.class == String
    string += " "*2 + "#{key.to_s}: #{value}\n" unless value.nil?
  end
  string += "\n"
  table_name = self.class.table_name
  file_name = table_name + ".yml"
  File.open("#{Dir.pwd}/test/fixtures/#{file_name}", 'a') do |out|
    out.write(string)
  end
end

#add_fixture_no_id_timestampsObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fixture_me.rb', line 22

def add_fixture_no_id_timestamps
  hash = self.attributes.delete_if { |k, v| ["created_at", "updated_at", "id"].include? k }
  md5 = Digest::MD5.hexdigest(hash.to_s)
  string = "#{md5}:\n"
  hash.each do |key,value|
    value.gsub!("\n","\n"+" "*4) if value.class == String
    string += " "*2 + "#{key.to_s}: #{value}\n" unless value.nil?
  end
  string += "\n"
  table_name = self.class.table_name
  file_name = table_name + ".yml"
  File.open("#{Dir.pwd}/test/fixtures/#{file_name}", 'a') do |out|
    out.write(string)
  end
end