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

Add tests

parent 31390b73
Branches
Tags
No related merge requests found
class ModWarningController < ApplicationController class ModWarningController < ApplicationController
before_action :authenticate_user!
before_action :verify_moderator, only: [:log, :new, :create] before_action :verify_moderator, only: [:log, :new, :create]
before_action :set_warning, only: [:current, :approve] before_action :set_warning, only: [:current, :approve]
...@@ -10,7 +9,7 @@ class ModWarningController < ApplicationController ...@@ -10,7 +9,7 @@ class ModWarningController < ApplicationController
end end
def approve def approve
return not_found if @warning.is_suspension return not_found if @warning.suspension_active?
if params[:approve_checkbox].nil? if params[:approve_checkbox].nil?
@failed_to_click_checkbox = true @failed_to_click_checkbox = true
......
require 'test_helper' require 'test_helper'
class ModWarningControllerTest < ActionDispatch::IntegrationTest class ModWarningControllerTest < ActionController::TestCase
# test "the truth" do include Devise::Test::ControllerHelpers
# assert true
# end 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 end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html # 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 first_warning:
# model remove the '{}' from the fixture names and add the columns immediately community_user: sample_standard_user
# below each fixture, per the syntax in the comments below body: NOBODY EXPECTS THE SPANISH INQUISITION
# is_suspension: false
one: {} active: false
# column: value author: moderator
#
two: {} second_warning:
# column: value 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 to comment