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.
51 lines
1.2 KiB
Ruby
51 lines
1.2 KiB
Ruby
require 'test_helper'
|
|
|
|
class PostFlagsControllerTest < ActionDispatch::IntegrationTest
|
|
context "The post flags controller" do
|
|
setup do
|
|
@user = create(:user, created_at: 2.weeks.ago)
|
|
end
|
|
|
|
context "new action" do
|
|
should "render" do
|
|
get_auth new_post_flag_path, @user
|
|
assert_response :success
|
|
end
|
|
end
|
|
|
|
context "index action" do
|
|
setup do
|
|
@post_flag = create(:post_flag, creator: @user)
|
|
end
|
|
|
|
should "render" do
|
|
get_auth post_flags_path, @user
|
|
assert_response :success
|
|
end
|
|
|
|
context "with search parameters" do
|
|
should "render" do
|
|
get_auth post_flags_path, @user, params: {:search => {:post_id => @post_flag.post_id}}
|
|
assert_response :success
|
|
end
|
|
end
|
|
end
|
|
|
|
context "create action" do
|
|
setup do
|
|
@user.as_current do
|
|
@post = create(:post)
|
|
end
|
|
end
|
|
|
|
should "create a new flag" do
|
|
assert_difference("PostFlag.count", 1) do
|
|
assert_difference("PostFlag.count") do
|
|
post_auth post_flags_path, @user, params: {:format => "js", :post_flag => {:post_id => @post.id, :reason => "xxx"}}
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|