code_junkie

How do you mock params when testing a Rails model's setter?

Nov 10th, 2011
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. def new_task_attributes=(task_attributes)
  2. task_attributes.each do |attributes|
  3. tasks.build(attributes)
  4. end
  5. end
  6.  
  7. def test_adding_task_to_project
  8. p = Project.new
  9. params = {"new_tasks_attributes" => [{ "name" => "paint fence"}]}
  10. p.new_tasks_attributes=(params)
  11. p.save
  12. assert p.tasks.length == 1
  13. end
  14.  
  15. def test_adding_task_to_project
  16. p = Project.new
  17. new_tasks_attributes = [{ "name" => "paint fence"}]
  18. p.new_tasks_attributes = (new_tasks_attributes)
  19. p.save
  20. assert p.tasks.length == 1
  21. end
Add Comment
Please, Sign In to add comment