mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-27 04:51:14 +00:00
Added tests for bans
This commit is contained in:
parent
5829226948
commit
20c9bd6550
1 changed files with 73 additions and 0 deletions
73
spec/models/ban_spec.rb
Normal file
73
spec/models/ban_spec.rb
Normal file
|
@ -0,0 +1,73 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: bans
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# steamid :string(255)
|
||||
# user_id :integer
|
||||
# addr :string(255)
|
||||
# server_id :integer
|
||||
# expiry :datetime
|
||||
# reason :string(255)
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# ban_type :integer
|
||||
# ip :string(255)
|
||||
#
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Ban do
|
||||
let!(:user) { create :user }
|
||||
let(:ban) { Ban.new }
|
||||
let!(:server) { create :server }
|
||||
|
||||
describe '#check_user' do
|
||||
it "assigns user by user_name" do
|
||||
ban.user_name = user.username
|
||||
ban.check_user
|
||||
expect(ban.user).to eq(user)
|
||||
end
|
||||
it "assigns user and server if user_name not present" do
|
||||
ban.steamid = user.steamid
|
||||
ban.addr = server.addr
|
||||
ban.check_user
|
||||
expect(ban.user).to eq(user)
|
||||
expect(ban.server).to eq(server)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Permissions' do
|
||||
let!(:user) { create :user }
|
||||
let!(:admin) { create :user, :admin }
|
||||
let!(:server_user) { create :user }
|
||||
let(:ban) { Ban.new }
|
||||
|
||||
describe 'can_create?' do
|
||||
it 'returns true for admins' do
|
||||
expect(ban.can_create? admin).to be_true
|
||||
end
|
||||
it 'returns false for non-admins' do
|
||||
expect(ban.can_create? user).to be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'can_destroy?' do
|
||||
it 'returns true for admin' do
|
||||
expect(ban.can_destroy? admin).to be_true
|
||||
end
|
||||
it 'returns false for non-admins' do
|
||||
expect(ban.can_destroy? user).to be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'can_update?' do
|
||||
it 'returns true for admin' do
|
||||
expect(ban.can_update? admin).to be_true
|
||||
end
|
||||
it 'returns false for non-admins' do
|
||||
expect(ban.can_update? user).to be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue