diff options
author | Dennis Ushakov <dennis.ushakov@gmail.com> | 2016-03-22 13:28:42 +0300 |
---|---|---|
committer | Dennis Ushakov <dennis.ushakov@gmail.com> | 2016-03-30 12:32:39 +0300 |
commit | 32045717e6bb62d9f3bec6e003dd6c4a74369ae2 (patch) | |
tree | 2fcaefb9f3cdadb07a9fca5c032e43ece33caf8c /activerecord | |
parent | bedb00aeb9c57649f63f5dd50692129aba3aecfe (diff) | |
download | rails-32045717e6bb62d9f3bec6e003dd6c4a74369ae2.tar.gz rails-32045717e6bb62d9f3bec6e003dd6c4a74369ae2.tar.bz2 rails-32045717e6bb62d9f3bec6e003dd6c4a74369ae2.zip |
provide file name for fixture ERB
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/fixture_set/file.rb | 8 | ||||
-rw-r--r-- | activerecord/test/cases/fixture_set/file_test.rb | 6 |
2 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/fixture_set/file.rb b/activerecord/lib/active_record/fixture_set/file.rb index f969556c50..e4a44244e2 100644 --- a/activerecord/lib/active_record/fixture_set/file.rb +++ b/activerecord/lib/active_record/fixture_set/file.rb @@ -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. diff --git a/activerecord/test/cases/fixture_set/file_test.rb b/activerecord/test/cases/fixture_set/file_test.rb index 242e7a9bec..e64b90507e 100644 --- a/activerecord/test/cases/fixture_set/file_test.rb +++ b/activerecord/test/cases/fixture_set/file_test.rb @@ -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 |