mirror of
https://github.com/zhigang1992/tsemple.git
synced 2026-04-29 13:15:25 +08:00
Remove asert_login_required
This commit is contained in:
@@ -6,9 +6,8 @@ class NotificationsControllerTest < ActionController::TestCase
|
||||
create(:notification, user: user, subject: create(:comment), name: 'comment')
|
||||
create(:notification, user: user, subject: create(:comment), name: 'mention')
|
||||
|
||||
assert_login_required(user) do
|
||||
get :index
|
||||
end
|
||||
login_as user
|
||||
get :index
|
||||
assert_response :success, @response.body
|
||||
end
|
||||
|
||||
@@ -36,10 +35,9 @@ class NotificationsControllerTest < ActionController::TestCase
|
||||
test "should destroy notification" do
|
||||
user = create(:user)
|
||||
notification = create(:notification, user: user)
|
||||
login_as user
|
||||
assert_difference "user.notifications.count", -1 do
|
||||
assert_login_required(user) do
|
||||
xhr :delete, :destroy, id: notification
|
||||
end
|
||||
xhr :delete, :destroy, id: notification
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -21,17 +21,15 @@ class TopicsControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
test "should get new page" do
|
||||
assert_login_required do
|
||||
get :new
|
||||
end
|
||||
login_as create(:user)
|
||||
get :new
|
||||
assert_response :success, @response.body
|
||||
end
|
||||
|
||||
test "should create topic" do
|
||||
login_as create(:user)
|
||||
assert_difference "Topic.count" do
|
||||
assert_login_required do
|
||||
post :create, topic: attributes_for(:topic)
|
||||
end
|
||||
post :create, topic: attributes_for(:topic)
|
||||
end
|
||||
topic = Topic.last
|
||||
assert_equal topic.user, topic.user
|
||||
@@ -40,17 +38,15 @@ class TopicsControllerTest < ActionController::TestCase
|
||||
|
||||
test "should edit topic" do
|
||||
topic = create(:topic)
|
||||
assert_login_required topic.user do
|
||||
get :edit, id: topic
|
||||
end
|
||||
login_as topic.user
|
||||
get :edit, id: topic
|
||||
assert_response :success, @response.body
|
||||
end
|
||||
|
||||
test "should update topic" do
|
||||
topic = create(:topic)
|
||||
assert_login_required topic.user do
|
||||
patch :update, id: topic, topic: { title: 'change', body: 'change' }
|
||||
end
|
||||
login_as topic.user
|
||||
patch :update, id: topic, topic: { title: 'change', body: 'change' }
|
||||
topic.reload
|
||||
assert_equal 'change', topic.title
|
||||
assert_equal 'change', topic.body
|
||||
|
||||
@@ -13,12 +13,4 @@ class ActiveSupport::TestCase
|
||||
@controller.send method, *args
|
||||
end
|
||||
end
|
||||
|
||||
def assert_login_required(user = create(:user))
|
||||
logout
|
||||
yield
|
||||
assert_redirected_to login_url
|
||||
login_as user
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user