Module: AttachmentTestHelper

Defined in:
lib/attachment_test_helper.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) binary_to_yaml(filename)

Converts a binary file to YAML for use in test fixtures.



19
20
21
22
# File 'lib/attachment_test_helper.rb', line 19

def binary_to_yaml(filename)
  data = File.open(filename,'rb').read
  "!binary | #{[data].pack('m').gsub(/\n/,"\n   ")}\n"
end

- (Object) fixture_data(name)

Converts a binary file to YAML for use in test fixtures. The name is relative to the test/fixtures directory.



14
15
16
# File 'lib/attachment_test_helper.rb', line 14

def fixture_data(name)
  binary_to_yaml(File.dirname(__FILE__)+"/../test/fixtures/#{name}")
end

- (Object) load_file(name)

Load a file into the db as LO and return the OID



4
5
6
7
8
9
10
# File 'lib/attachment_test_helper.rb', line 4

def load_file(name)
  conn = ActiveRecord::Base.connection.raw_connection
  conn.exec "BEGIN"
  loid = conn.lo_import(File.dirname(__FILE__)+"/../test/fixtures/#{name}")
  conn.exec "COMMIT"
  return loid
end