Skip to content
Snippets Groups Projects
Commit a3462cf3 authored by luap42's avatar luap42
Browse files

Add tests

parent 31390b73
No related merge requests found
class ModWarningController < ApplicationController
before_action :authenticate_user!
before_action :verify_moderator, only: [:log, :new, :create]
before_action :set_warning, only: [:current, :approve]
......@@ -10,7 +9,7 @@ class ModWarningController < ApplicationController
end
def approve
return not_found if @warning.is_suspension
return not_found if @warning.suspension_active?
if params[:approve_checkbox].nil?
@failed_to_click_checkbox = true
......
require 'test_helper'
class ModWarningControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
class ModWarningControllerTest < ActionController::TestCase
include Devise::Test::ControllerHelpers
test 'should require authentication to access pages' do
sign_out :user
[:log, :new].each do |path|
get path, params: { user_id: users(:standard_user).id }
assert_response(404)
end
end
test 'should require moderator status to access pages' do
sign_in users(:standard_user)
[:log, :new].each do |path|
get path, params: { user_id: users(:standard_user).id }
assert_response(404)
end
end
test 'suspended user should redirect to current warning page' do
sign_in users(:standard_user)
mod_warnings(:first_warning).update(active: true)
current_controller = @controller
@controller = CategoriesController.new
get :homepage
@controller = current_controller
assert_redirected_to '/warning'
mod_warnings(:first_warning).update(active: false)
end
test 'warned user should be able to accept warning' do
sign_in users(:standard_user)
@warning = mod_warnings(:first_warning)
@warning.update(active: true)
post :approve, params: { approve_checkbox: true }
@warning.reload
assert !@warning.active
end
test 'suspended user should not be able to accept pending suspension' do
sign_in users(:standard_user)
@warning = mod_warnings(:third_warning)
@warning.update(active: true)
post :approve, params: { approve_checkbox: true }
@warning.reload
assert @warning.active
end
test 'suspended user should be able to accept outdated suspension' do
sign_in users(:standard_user)
@warning = mod_warnings(:second_warning)
@warning.update(active: true)
post :approve, params: { approve_checkbox: true }
@warning.reload
assert !@warning.active
end
end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
first_warning:
community_user: sample_standard_user
body: NOBODY EXPECTS THE SPANISH INQUISITION
is_suspension: false
active: false
author: moderator
second_warning:
community_user: sample_standard_user
body: NOBODY EXPECTS THE SPANISH INQUISITION!
is_suspension: true
suspension_end: 2000-01-01T00:00:00.000000Z
active: false
author: moderator
third_warning:
community_user: sample_standard_user
body: NOBODY EXPECTS THE SPANISH INQUISITION!!!
is_suspension: true
suspension_end: 5000-01-01T00:00:00.000000Z
active: false
author: moderator
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment