Guest User

Untitled

a guest
Jun 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. ## unit test
  2. require 'test/test_helper'
  3.  
  4. class PageTest < ActiveSupport::TestCase
  5. def test_invalid_if_any_field_empty
  6. page = Page.new
  7. assert !page.valid?
  8. assert page.errors.invalid?(:title)
  9. assert page.errors.invalid?(:body)
  10. end
  11. def test_valid_fields
  12. page = pages(:valid_page) #arg is the name of the fixture
  13. assert page.valid?
  14. end
  15. end
  16.  
  17. ## fixture
  18. valid_page:
  19. id: 1
  20. title: Welcome Page
  21. permalink: welcome-page
  22. body: Welcome to the welcome page.
  23.  
  24. invalid_page_short_title:
  25. id: 2
  26. title: a
  27. permalink: a
  28. body: The title is shorter than 3 characters
  29.  
  30. valid_with_auto_permalink:
  31. id: 3
  32. title: Another page, but without a permalink
  33. body: No permalink is given so it should be automatically generated
Add Comment
Please, Sign In to add comment