mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #24356 from denofevil/fixture_filename
provide file name for fixture ERB
This commit is contained in:
commit
7e976fd84d
2 changed files with 13 additions and 1 deletions
|
@ -52,9 +52,15 @@ module ActiveRecord
|
|||
end
|
||||
end
|
||||
|
||||
def prepare_erb(content)
|
||||
erb = ERB.new(content)
|
||||
erb.filename = @file
|
||||
erb
|
||||
end
|
||||
|
||||
def render(content)
|
||||
context = ActiveRecord::FixtureSet::RenderContext.create_subclass.new
|
||||
ERB.new(content).result(context.get_binding)
|
||||
prepare_erb(content).result(context.get_binding)
|
||||
end
|
||||
|
||||
# Validate our unmarshalled data.
|
||||
|
|
|
@ -135,6 +135,12 @@ END
|
|||
end
|
||||
end
|
||||
|
||||
def test_erb_filename
|
||||
filename = 'filename.yaml'
|
||||
erb = File.new(filename).send(:prepare_erb, "<% Rails.env %>\n")
|
||||
assert_equal erb.filename, filename
|
||||
end
|
||||
|
||||
private
|
||||
def tmp_yaml(name, contents)
|
||||
t = Tempfile.new name
|
||||
|
|
Loading…
Reference in a new issue