Created
March 8, 2011 22:58
-
-
Save jamesmacaulay/861291 to your computer and use it in GitHub Desktop.
get the fixture label of a given record
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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