Loading large amounts of text data in fixtures

I am trying to load the contents of XML files into a mediumtext field
from a fixture.

heres my fixture so far, with some erb to help me out.

<%
def load_owl(name)
data = File.read("#{RAILS_ROOT}/spec/fixtures/#{name}_owl.xml")
data.gsub!("\n", ‘’)
“!str #{data}”
end
%>

wine:
name: Wine
body: <%= load_owl(:wine) %>

teams:
name: Teams
body: <%= load_owl(:teams) %>

pizza:
name: Pizza
body: <%= load_owl(:pizza) %>


This worked for Wine and Teams, but pizza has screwed the pooch. All I
get is YAML parse errors, which are very hard to pinpoint.

So if anyone has a better idea about how to do a basic YAML escape on a
something 4000 lines of XML, that would be very useful. Any ideas?

Well, I never solved this, but came up with a workaround. Since I don’t
need these fixtures to have any association linkage I just added a
method to my spec helper:

def get_owl(name)
returning Owl.find_or_initialize_by_name(name) do |owl|
if owl.new_record?
owl.name = name
owl.body =
File.read("#{RAILS_ROOT}/spec/fixtures/#{name}_owl.xml")
owl.save
end
end
end

Seems to work well enough for my needs.

Alex W. wrote:

I am trying to load the contents of XML files into a mediumtext field
from a fixture.

heres my fixture so far, with some erb to help me out.

<%
def load_owl(name)
data = File.read("#{RAILS_ROOT}/spec/fixtures/#{name}_owl.xml")
data.gsub!("\n", ‘’)
“!str #{data}”
end
%>

wine:
name: Wine
body: <%= load_owl(:wine) %>

teams:
name: Teams
body: <%= load_owl(:teams) %>

pizza:
name: Pizza
body: <%= load_owl(:pizza) %>