Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide file name for fixture ERB #24356

Merged
merged 1 commit into from
Mar 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion activerecord/lib/active_record/fixture_set/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ def raw_rows
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.
Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/fixture_set/file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ def test_extracts_model_class_from_config_row
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
Expand Down