ensl.org/spec/models/ban_spec.rb

80 lines
1.7 KiB
Ruby
Raw Normal View History

2015-05-22 13:16:31 +00:00
# == 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)
#
2015-08-15 18:23:42 +00:00
require "spec_helper"
2015-05-22 13:16:31 +00:00
describe Ban do
let!(:user) { create :user }
let(:ban) { Ban.new }
let!(:server) { create :server }
2015-05-22 13:16:31 +00:00
2015-08-15 18:23:42 +00:00
describe "#check_user" do
it "assigns user by user_name" do
ban.user_name = user.username
ban.check_user
2015-08-15 18:23:42 +00:00
expect(ban.user).to eq(user)
end
2015-05-22 13:16:31 +00:00
it "assigns user and server if user_name not present" do
ban.steamid = user.steamid
ban.addr = server.addr
ban.check_user
2015-08-15 18:23:42 +00:00
expect(ban.user).to eq(user)
expect(ban.server).to eq(server)
end
end
2015-05-22 13:16:31 +00:00
2015-08-15 18:23:42 +00:00
describe "Permissions" do
let!(:user) { create :user }
let!(:admin) { create :user, :admin }
let!(:server_user) { create :user }
let(:ban) { Ban.new }
2015-05-22 13:16:31 +00:00
2015-08-15 18:23:42 +00:00
describe "can_create?" do
it "returns true for admins" do
expect(ban.can_create? admin).to be_truthy
end
2015-08-15 18:23:42 +00:00
it "returns false for non-admins" do
expect(ban.can_create? user).to be_falsey
end
end
2015-08-15 18:23:42 +00:00
describe "can_destroy?" do
it "returns true for admin" do
expect(ban.can_destroy? admin).to be_truthy
end
2015-08-15 18:23:42 +00:00
it "returns false for non-admins" do
expect(ban.can_destroy? user).to be_falsey
end
end
2015-08-15 18:23:42 +00:00
describe "can_update?" do
it "returns true for admin" do
expect(ban.can_update? admin).to be_truthy
end
2015-08-15 18:23:42 +00:00
it "returns false for non-admins" do
expect(ban.can_update? user).to be_falsey
end
end
end
2015-05-22 13:16:31 +00:00
end