Skip to content

Instantly share code, notes, and snippets.

@jamesmacaulay
Created March 8, 2011 22:58
Show Gist options
  • Save jamesmacaulay/861291 to your computer and use it in GitHub Desktop.
Save jamesmacaulay/861291 to your computer and use it in GitHub Desktop.
get the fixture label of a given record
# fixture_label_of_record(shops(:snowdevil))
# => "snowdevil"
class ActiveSupport::TestCase
def fixture_label_of_record(record)
yaml_file = fixture_path + record.class.table_name + '.yml'
labels = YAML.load(File.read(yaml_file)).keys
labels.find {|l| Fixtures.identify(l) == record[record.class.primary_key]}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment