I’ve been using the excellent fixture_replacement plugin for several months now and greatly prefer it over traditional fixtures (yes, even foxy fixtures). fixture_replacement2 adds even more goodness to the party. However, I ran into a problem today when trying to use default_xxx
methods in my example_data.rb file:
module FixtureReplacement attributes_for :course do |c| c.name = "Geometry" c.transcript = default_transcript end attributes_for :transcript do |e| e.name = "Joe's Transcript" end end
In “fixture_replacement language” this says that new courses should receive a default name of “Geometry” and should also receive a new transcript with a default name of “Joe’s Transcript.” The example above follows the format given in the fixture_replacement README. When I attempt to use this config file in my Rails 2.0.2 project, though, I get this error:
NameError: undefined local variable or method `default_transcript' for FixtureReplacement:Module at top level in example_data.rb at line 7 ...
Why can’t it find default_transcript
? I have no idea. Digging into the source code reveals that default_transcript
is added to the FixtureReplacement module at runtime, but for some reason it doesn’t ever show up as being available for calling. I don’t have the time or inclination to dig further, but I did find a workaround by changing:
c.transcript = default_transcript
to…
c.transcript = c.default_transcript
This makes fixture_replacement happy and all my tests pass. I submitted a patch so hopefully this wrinkle will be ironed out soon. But this should get you by until then.