Skip to content

Instantly share code, notes, and snippets.

@elegantcoder
Created September 16, 2016 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elegantcoder/125a411dec4e79c8e370c53083f6ffec to your computer and use it in GitHub Desktop.
Save elegantcoder/125a411dec4e79c8e370c53083f6ffec to your computer and use it in GitHub Desktop.
for generating Rails test fixture
require 'yaml'
def active_record_2_yaml(active_record)
hash = Array.wrap(active_record).as_json.reduce({}) {|memo, item|
memo["id_#{item['id']}"] = item
memo
}
hash.to_yaml
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment