2015-05-14 16:27:12 +00:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: servers
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
2020-03-31 17:27:34 +00:00
|
|
|
# active :boolean default(TRUE), not null
|
2015-05-14 16:27:12 +00:00
|
|
|
# description :string(255)
|
|
|
|
# dns :string(255)
|
2020-03-31 17:27:34 +00:00
|
|
|
# domain :integer default(0), not null
|
2020-03-18 03:38:17 +00:00
|
|
|
# idle :datetime
|
2015-05-14 16:27:12 +00:00
|
|
|
# ip :string(255)
|
|
|
|
# irc :string(255)
|
|
|
|
# map :string(255)
|
|
|
|
# max_players :integer
|
2020-03-18 03:38:17 +00:00
|
|
|
# name :string(255)
|
|
|
|
# official :boolean
|
|
|
|
# password :string(255)
|
2015-05-14 16:27:12 +00:00
|
|
|
# ping :string(255)
|
2020-03-18 03:38:17 +00:00
|
|
|
# players :integer
|
|
|
|
# port :string(255)
|
|
|
|
# recordable_type :string(255)
|
2015-05-14 16:27:12 +00:00
|
|
|
# recording :string(255)
|
2020-03-18 03:38:17 +00:00
|
|
|
# reservation :string(255)
|
|
|
|
# version :integer
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
# category_id :integer
|
2015-05-14 16:27:12 +00:00
|
|
|
# default_id :integer
|
|
|
|
# recordable_id :integer
|
2020-03-18 03:38:17 +00:00
|
|
|
# user_id :integer
|
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_servers_on_default_id (default_id)
|
|
|
|
# index_servers_on_players_and_domain (players,domain)
|
|
|
|
# index_servers_on_user_id (user_id)
|
2015-05-14 16:27:12 +00:00
|
|
|
#
|
|
|
|
|
2019-10-17 18:29:15 +00:00
|
|
|
require "rails_helper"
|
2015-05-14 16:27:12 +00:00
|
|
|
|
|
|
|
describe Server do
|
2015-08-15 18:23:42 +00:00
|
|
|
describe "create" do
|
|
|
|
it "sets category to 45 if domain is NS2" do
|
2015-08-15 11:50:28 +00:00
|
|
|
server = create :server, domain: Server::DOMAIN_NS2
|
2015-08-15 18:23:42 +00:00
|
|
|
|
2015-08-15 11:50:28 +00:00
|
|
|
expect(server.category_id).to eq(45)
|
|
|
|
end
|
2015-08-15 18:23:42 +00:00
|
|
|
|
|
|
|
it "sets category to 44 if domain is not NS2" do
|
2015-08-15 11:50:28 +00:00
|
|
|
server = create :server, domain: Server::DOMAIN_HLDS
|
2015-08-15 18:23:42 +00:00
|
|
|
|
2015-08-15 11:50:28 +00:00
|
|
|
expect(server.category_id).to eq(44)
|
|
|
|
end
|
|
|
|
end
|
2015-05-14 16:27:12 +00:00
|
|
|
|
2015-08-15 18:23:42 +00:00
|
|
|
describe "addr" do
|
|
|
|
it "returns properly formatted IP and port number" do
|
|
|
|
ip = "1.1.1.1"
|
|
|
|
port = "8000"
|
2015-08-15 11:50:28 +00:00
|
|
|
server = create :server, ip: ip, port: port
|
2015-08-15 18:23:42 +00:00
|
|
|
|
|
|
|
expect(server.addr).to eq("1.1.1.1:8000")
|
2015-08-15 11:50:28 +00:00
|
|
|
end
|
|
|
|
end
|
2015-05-14 16:27:12 +00:00
|
|
|
|
2015-08-15 18:23:42 +00:00
|
|
|
describe "to_s" do
|
|
|
|
it "returns server name" do
|
2015-08-15 11:50:28 +00:00
|
|
|
server_name = "Foo"
|
|
|
|
server = create :server, name: server_name
|
2015-08-15 18:23:42 +00:00
|
|
|
|
2015-08-15 11:50:28 +00:00
|
|
|
expect(server.to_s).to eq(server_name)
|
|
|
|
end
|
|
|
|
end
|
2015-05-14 16:27:12 +00:00
|
|
|
|
2015-08-15 18:23:42 +00:00
|
|
|
describe "Permissions" do
|
2015-08-15 11:50:28 +00:00
|
|
|
let!(:user) { create :user }
|
|
|
|
let!(:admin) { create :user, :admin }
|
2015-08-15 18:23:42 +00:00
|
|
|
let!(:server_user) { create :user }
|
2015-08-15 11:50:28 +00:00
|
|
|
let!(:server) { create :server, user: server_user }
|
2015-05-14 16:27:12 +00:00
|
|
|
|
2015-08-15 18:23:42 +00:00
|
|
|
describe "can_create?" do
|
|
|
|
it "returns true for non-admins" do
|
2015-08-15 11:50:28 +00:00
|
|
|
expect(server.can_create? user).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
2015-05-14 16:27:12 +00:00
|
|
|
|
2015-08-15 18:23:42 +00:00
|
|
|
describe "can_destroy?" do
|
|
|
|
it "returns true for admin" do
|
2015-08-15 11:50:28 +00:00
|
|
|
expect(server.can_destroy? admin).to eq(true)
|
|
|
|
end
|
2015-08-15 18:23:42 +00:00
|
|
|
|
|
|
|
it "returns false for non-admins" do
|
2015-08-15 11:50:28 +00:00
|
|
|
expect(server.can_destroy? user).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
2015-05-14 16:27:12 +00:00
|
|
|
|
2015-08-15 18:23:42 +00:00
|
|
|
describe "can_update?" do
|
|
|
|
it "returns true for admin" do
|
2015-08-15 11:50:28 +00:00
|
|
|
expect(server.can_update? admin).to eq(true)
|
|
|
|
end
|
2015-08-15 18:23:42 +00:00
|
|
|
|
|
|
|
it "returns true if server belongs to user" do
|
2015-08-15 11:50:28 +00:00
|
|
|
expect(server.can_update? server_user).to eq(true)
|
|
|
|
end
|
2015-08-15 18:23:42 +00:00
|
|
|
|
|
|
|
it "returns false for non-admins" do
|
2015-08-15 11:50:28 +00:00
|
|
|
expect(server.can_update? user).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-05-14 16:27:12 +00:00
|
|
|
end
|