Files
danbooru/test/functional/news_updates_controller_test.rb
evazion b4ce2d83a6 models: remove belongs_to_creator macro.
The belongs_to_creator macro was used to initialize the creator_id field
to the CurrentUser. This made tests complicated because it meant you had
to create and set the current user every time you wanted to create an
object, when lead to the current user being set over and over again. It
also meant you had to constantly be aware of what the CurrentUser was in
many different contexts, which was often confusing. Setting creators
explicitly simplifies everything greatly.
2020-01-21 00:09:38 -06:00

59 lines
1.5 KiB
Ruby

require 'test_helper'
class NewsUpdatesControllerTest < ActionDispatch::IntegrationTest
context "the news updates controller" do
setup do
@admin = create(:admin_user)
as(@admin) do
@news_update = create(:news_update, creator: @admin)
end
end
context "index action" do
should "render" do
get_auth news_updates_path, @admin
assert_response :success
end
end
context "new action" do
should "render" do
get_auth new_news_update_path, @admin
assert_response :success
end
end
context "edit action" do
should "render" do
get_auth edit_news_update_path(@news_update), @admin
assert_response :success
end
end
context "update action" do
should "work" do
put_auth news_update_path(@news_update), @admin, params: {:news_update => {:message => "zzz"}}
assert_redirected_to(news_updates_path)
end
end
context "create action" do
should "work" do
assert_difference("NewsUpdate.count") do
post_auth news_updates_path, @admin, params: {:news_update => {:message => "zzz"}}
end
assert_redirected_to(news_updates_path)
end
end
context "destroy action" do
should "work" do
assert_difference("NewsUpdate.count", -1) do
delete_auth news_update_path(@news_update), @admin
end
assert_redirected_to(news_updates_path)
end
end
end
end