Guest User

Untitled

a guest
Jun 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. # Create samples
  2. #
  3. # Look for column belongs_to_users
  4. # This should contain values like creator:user1, approver:user2, and so
  5. # on, where 'creator' and 'approver' are belongs_to relationships like:
  6. #
  7. # belongs_to :creator, :class_name => "User", :foreign_key => "creator_id"
  8. #
  9. # and 'user1', and 'user2' are existing username values.
  10. #
  11. # This step finds those users by username and adds them to the hash,
  12. # deleting 'belongs_to_users' and leaving all other values in place.
  13. Given /^the following samples?$/ do |table|
  14. table.hashes.each { |hash|
  15. if (owners = hash.delete('belongs_to_users'))
  16. owners.split(/, ?/).each do |pair|
  17. kind,owner = pair.split(/:/)
  18. hash[kind] = User.find_by_username(owner)
  19. end
  20. end
  21. Factory(:sample,hash)
  22. }
  23. end
Add Comment
Please, Sign In to add comment