Guest User

Untitled

a guest
May 24th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. # THIS STUFF IS JUST TO MAKE THE ABOVE WORK.
  2.  
  3. require 'acts_as_fu'
  4. require 'fixjour'
  5. require 'test/unit'
  6.  
  7. ##
  8. # BEGIN SETUP
  9. build_model(:users) do
  10. string :name
  11. end
  12.  
  13. build_model(:articles) do
  14. string :name
  15. string :body
  16. boolean :posted, :default => true
  17. integer :user_id
  18.  
  19. belongs_to :user
  20. end
  21. # END SETUP
  22. ##
  23.  
  24. # Need this for "scenario builders"
  25. Fixjour.allow_redundancy!
  26.  
  27. # The sauce (it could be cleaner, but whatevz for now)
  28. def Fixjour.define(object, options={}, &block)
  29. if builder = options[:from]
  30. name = builder.is_a?(Symbol) ? builder : Fixjour.send(:name_for, builder)
  31. Fixjour.define_builder(options[:from], :as => object) do |klass, overrides|
  32. # klass is NOT to be used in this case
  33. instance = send("new_#{name}")
  34. instance_exec(instance, &block)
  35. overrides.each { |key, val| instance[key] = val }
  36. instance
  37. end
  38. else
  39. Fixjour.define_builder(object, options) do |klass, overrides|
  40. instance = klass.new
  41. instance_exec(instance, &block)
  42. overrides.each { |key, val| instance[key] = val }
  43. instance
  44. end
  45. end
  46. end
Add Comment
Please, Sign In to add comment