From f47421f2a058a5ca845969e8d15be2028c3e6972 Mon Sep 17 00:00:00 2001 From: Eric Steele Date: Sat, 15 Mar 2014 21:49:04 -0400 Subject: Extend fixture label replacement to allow string interpolation Allows fixtures to use their $LABEL as part of a string instead of limiting use to the entire value. mark: first_name: $LABEL username: $LABEL1973 email: $LABEL@$LABELmail.com users(:mark).first_name # => mark users(:mark).username # => mark1973 users(:mark).email # => mark@markmail.com --- activerecord/lib/active_record/fixtures.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/fixtures.rb') diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 59467636d7..6f134bbef8 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -361,6 +361,7 @@ module ActiveRecord # geeksomnia: # name: Geeksomnia's Account # subdomain: $LABEL + # email: $LABEL@email.com # # Also, sometimes (like when porting older join table fixtures) you'll need # to be able to get a hold of the identifier for a given label. ERB @@ -627,7 +628,7 @@ module ActiveRecord # interpolate the fixture label row.each do |key, value| - row[key] = label if "$LABEL" == value + row[key] = value.gsub("$LABEL", label) if value.is_a?(String) end # generate a primary key if necessary -- cgit v1.2.3