news_posts_controller_test.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. require 'test_helper'
  2. class NewsPostsControllerTest < ActionDispatch::IntegrationTest
  3. setup do
  4. @news_post = news_posts(:one)
  5. @course = courses(:one)
  6. @teacher = users(:daniel)
  7. log_in_as @teacher
  8. end
  9. test "should create news_post" do
  10. assert_difference('NewsPost.count') do
  11. post news_posts_url, params: { news_post: { content: @news_post.content, name: @news_post.name, news_feed_id: @course.id, news_feed_type: 'Course' } }
  12. end
  13. assert_redirected_to @course
  14. end
  15. test "should get show" do
  16. get news_post_url(@news_post)
  17. assert_response :success
  18. end
  19. test "should get edit" do
  20. get edit_news_post_url(@news_post)
  21. assert_response :success
  22. end
  23. test "should update news_post" do
  24. patch news_post_url(@news_post), params: { news_post: { content: @news_post.content, name: 'New Name' } }
  25. assert_equal 'New Name', @news_post.reload.name
  26. assert_redirected_to @news_post
  27. end
  28. test "should destroy news_post" do
  29. assert_difference('NewsPost.count', -1) do
  30. delete news_post_url(@news_post)
  31. end
  32. assert_redirected_to news_posts_url
  33. end
  34. end