2015-05-14 16:27:12 +00:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: servers
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# name :string(255)
|
|
|
|
# description :string(255)
|
|
|
|
# dns :string(255)
|
|
|
|
# ip :string(255)
|
|
|
|
# port :string(255)
|
|
|
|
# password :string(255)
|
|
|
|
# irc :string(255)
|
|
|
|
# user_id :integer
|
|
|
|
# official :boolean
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
# map :string(255)
|
|
|
|
# players :integer
|
|
|
|
# max_players :integer
|
|
|
|
# ping :string(255)
|
|
|
|
# version :integer
|
|
|
|
# domain :integer default(0), not null
|
|
|
|
# reservation :string(255)
|
|
|
|
# recording :string(255)
|
|
|
|
# idle :datetime
|
|
|
|
# default_id :integer
|
|
|
|
# active :boolean default(TRUE), not null
|
|
|
|
# recordable_type :string(255)
|
|
|
|
# recordable_id :integer
|
|
|
|
# category_id :integer
|
|
|
|
#
|
|
|
|
|
2015-08-15 18:23:42 +00:00
|
|
|
require "spec_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
|