mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-11-15 09:21:25 +00:00
Added ns server specs
This commit is contained in:
parent
8630fe4d81
commit
49ac4dcc2a
9 changed files with 224 additions and 0 deletions
12
spec/factories/group.rb
Normal file
12
spec/factories/group.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
FactoryGirl.define do
|
||||
factory :group do
|
||||
sequence(:id) { |n| n + 100 } # Preserve first 100
|
||||
sequence(:name) { |n| "Group#{n}" }
|
||||
association :founder, factory: :user
|
||||
end
|
||||
|
||||
trait :admin do
|
||||
name "Admins"
|
||||
id Group::ADMINS
|
||||
end
|
||||
end
|
5
spec/factories/grouper.rb
Normal file
5
spec/factories/grouper.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
FactoryGirl.define do
|
||||
factory :grouper do
|
||||
sequence(:task) { |n| "Task#{n}" }
|
||||
end
|
||||
end
|
8
spec/factories/server.rb
Normal file
8
spec/factories/server.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
FactoryGirl.define do
|
||||
factory :server do
|
||||
sequence(:name) { |n| "ServerName#{n}" }
|
||||
sequence(:dns) { |n| "DNS#{n}" }
|
||||
sequence(:ip) { |n| "192.168.#{n % 255}.#{n}" }
|
||||
sequence(:port) { |n| "#{1000 + n}" }
|
||||
end
|
||||
end
|
|
@ -13,6 +13,13 @@ FactoryGirl.define do
|
|||
create(:profile, user: user)
|
||||
end
|
||||
|
||||
trait :admin do
|
||||
after(:create) do |user|
|
||||
group = create(:group, :admin)
|
||||
create :grouper, user: user, group: group
|
||||
end
|
||||
end
|
||||
|
||||
factory :user_with_team do
|
||||
after(:create) do |user|
|
||||
create(:team, founder: user)
|
||||
|
|
30
spec/features/servers/server_administration.rb
Normal file
30
spec/features/servers/server_administration.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'Server Administration' do
|
||||
let!(:admin) { create :user, :admin }
|
||||
|
||||
background do
|
||||
sign_in_as admin
|
||||
end
|
||||
|
||||
scenario 'creating a server' do
|
||||
visit servers_path
|
||||
expect(page).to have_content('Listing Servers')
|
||||
click_link 'New server'
|
||||
test_server_creation_and_editing
|
||||
visit servers_path
|
||||
expect(page).to have_content Server.last.name
|
||||
end
|
||||
|
||||
feature 'Server deletion' do
|
||||
let!(:server) { create :server }
|
||||
scenario 'deleting a server' do
|
||||
visit servers_path
|
||||
expect(page).to have_content(server.name)
|
||||
visit server_path(server)
|
||||
click_link 'Delete Server'
|
||||
visit servers_path
|
||||
expect(page).to_not have_content(server.name)
|
||||
end
|
||||
end
|
||||
end
|
14
spec/features/servers/user_servers.rb
Normal file
14
spec/features/servers/user_servers.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'User created servers' do
|
||||
let!(:user) { create :user }
|
||||
|
||||
background do
|
||||
sign_in_as user
|
||||
end
|
||||
|
||||
scenario 'Creating and updating a server' do
|
||||
visit new_server_path
|
||||
test_server_creation_and_editing
|
||||
end
|
||||
end
|
98
spec/models/server_spec.rb
Normal file
98
spec/models/server_spec.rb
Normal file
|
@ -0,0 +1,98 @@
|
|||
# == 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)
|
||||
# rcon :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
|
||||
#
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Server do
|
||||
describe 'create' do
|
||||
it 'sets category to 45 if domain is NS2' do
|
||||
server = create :server, domain: Server::DOMAIN_NS2
|
||||
expect(server.category_id).to eq(45)
|
||||
end
|
||||
it 'sets category to 44 if domain is not NS2' do
|
||||
server = create :server, domain: Server::DOMAIN_HLDS
|
||||
expect(server.category_id).to eq(44)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'addr' do
|
||||
it 'returns properly formatted IP and port number' do
|
||||
ip = '1.1.1.1'
|
||||
port = '8000'
|
||||
server = create :server, ip: ip, port: port
|
||||
expect(server.addr).to eq('1.1.1.1:8000')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'to_s' do
|
||||
it 'returns server name' do
|
||||
server_name = "Foo"
|
||||
server = create :server, name: server_name
|
||||
expect(server.to_s).to eq(server_name)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Permissions' do
|
||||
let!(:user) { create :user }
|
||||
let!(:admin) { create :user, :admin }
|
||||
let!(:server_user) {create :user }
|
||||
let!(:server) { create :server, user: server_user }
|
||||
|
||||
describe 'can_create?' do
|
||||
it 'returns true for non-admins' do
|
||||
expect(server.can_create? user).to be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'can_destroy?' do
|
||||
it 'returns true for admin' do
|
||||
expect(server.can_destroy? admin).to be_true
|
||||
end
|
||||
it 'returns false for non-admins' do
|
||||
expect(server.can_destroy? user).to be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'can_update?' do
|
||||
it 'returns true for admin' do
|
||||
expect(server.can_update? admin).to be_true
|
||||
end
|
||||
it 'returns true if server belongs to user' do
|
||||
expect(server.can_update? server_user).to be_true
|
||||
end
|
||||
it 'returns false for non-admins' do
|
||||
expect(server.can_update? user).to be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -26,6 +26,7 @@ RSpec.configure do |config|
|
|||
config.include FactoryGirl::Syntax::Methods
|
||||
config.include Controllers::JsonHelpers, type: :controller
|
||||
config.include Features::FormHelpers, type: :feature
|
||||
config.include Features::ServerHelpers, type: :feature
|
||||
config.include Features::SessionHelpers, type: :feature
|
||||
|
||||
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||
|
|
49
spec/support/features/server_helpers.rb
Normal file
49
spec/support/features/server_helpers.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
module Features
|
||||
module ServerHelpers
|
||||
def test_server_creation_and_editing
|
||||
dns = 'ServerDns.com'
|
||||
ip = '192.168.1.1'
|
||||
port = '8000'
|
||||
rcon = 'whatsrcon'
|
||||
password = 'secret'
|
||||
name = 'MyNsServer'
|
||||
description = 'My NS Server'
|
||||
irc = '#some_channel'
|
||||
|
||||
visit new_server_path
|
||||
fill_in 'Dns', with: dns
|
||||
fill_in 'server_ip', with: ip
|
||||
fill_in 'server_port', with: port
|
||||
fill_in 'Password', with: password
|
||||
fill_in 'Name', with: name
|
||||
fill_in 'Description', with: description
|
||||
fill_in 'Irc', with: irc
|
||||
check 'Available for officials?'
|
||||
click_button 'Save'
|
||||
|
||||
expect(page).to have_content(dns)
|
||||
expect(page).to have_content("#{ip}:#{port}")
|
||||
expect(page).to have_content(password)
|
||||
expect(page).to have_content(irc)
|
||||
expect(page).to have_content(description)
|
||||
|
||||
click_link 'Edit Server'
|
||||
|
||||
fill_in 'Dns', with: "#{dns}2"
|
||||
fill_in 'server_ip', with: "192.168.1.2"
|
||||
fill_in 'server_port', with: "8001"
|
||||
fill_in 'Password', with: "#{password}2"
|
||||
fill_in 'Name', with: "#{name}2"
|
||||
fill_in 'Description', with: "#{description}2"
|
||||
fill_in 'Irc', with: "#{irc}2"
|
||||
check 'Available for officials?'
|
||||
click_button 'Save'
|
||||
|
||||
expect(page).to have_content("192.168.1.2:8001")
|
||||
expect(page).to have_content("#{dns}2")
|
||||
expect(page).to have_content("#{password}2")
|
||||
expect(page).to have_content("#{irc}2")
|
||||
expect(page).to have_content("#{description}2")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue