mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-27 04:51:14 +00:00
commit
f419c6ddd9
25 changed files with 360 additions and 222 deletions
|
@ -27,7 +27,7 @@ Features:
|
|||
- Map database
|
||||
- Votable polls
|
||||
- Twitter feed
|
||||
- Server database and RCON interface
|
||||
- Server database
|
||||
- Log file parsing (partially complete)
|
||||
|
||||
## Contributors
|
||||
|
|
|
@ -8,10 +8,6 @@ class BansController < ApplicationController
|
|||
def show
|
||||
end
|
||||
|
||||
def refresh
|
||||
Ban.refresh
|
||||
end
|
||||
|
||||
def new
|
||||
@ban = Ban.new
|
||||
raise AccessError unless @ban.can_create? cuser
|
||||
|
|
|
@ -1,128 +0,0 @@
|
|||
class PluginController < ApplicationController
|
||||
def esi
|
||||
buffer = []
|
||||
out = []
|
||||
buffer << Time.now.utc.to_i
|
||||
buffer << "1.2"
|
||||
buffer << params[:ch] ? params[:ch] : ""
|
||||
out << "#ESI#"
|
||||
out << Verification.verify(buffer.join)
|
||||
out << buffer.join("\r")
|
||||
render_out out
|
||||
end
|
||||
|
||||
def user
|
||||
buffer = []
|
||||
out = []
|
||||
|
||||
if ban = Ban.first(:conditions => ["expiry > UTC_TIMESTAMP() AND steamid = ? AND ban_type = ?", params[:id], Ban::TYPE_SERVER])
|
||||
out << "#USER#"
|
||||
out << "BANNED"
|
||||
out << ban.expiry.utc.to_i
|
||||
out << ban.reason
|
||||
out << "\r\r\r\r\r\r\r"
|
||||
elsif user = User.first(:conditions => {:steamid => params[:id]})
|
||||
teamer = (user.team ? user.teamers.active.of_team(user.team).first : nil)
|
||||
icon = 0
|
||||
rank = "User"
|
||||
if Group.find(Group::DONORS).users.exists?(user)
|
||||
rank = "Donor"
|
||||
icon = icon | 1
|
||||
end
|
||||
if Group.find(Group::CHAMPIONS).users.exists?(user)
|
||||
icon = icon | 2
|
||||
end
|
||||
if user.ref?
|
||||
rank = "Referee"
|
||||
icon = icon | 4
|
||||
end
|
||||
if user.admin?
|
||||
rank = "Admin"
|
||||
icon = icon | 8
|
||||
end
|
||||
|
||||
buffer << user.steamid
|
||||
buffer << user.username
|
||||
buffer << user.lastip
|
||||
buffer << (user.team ? Verification.uncrap(user.team.to_s) : "No Team")
|
||||
buffer << user.id
|
||||
buffer << user.team_id
|
||||
buffer << rank
|
||||
buffer << (teamer ? teamer.ranks[teamer.rank] : "")
|
||||
buffer << icon
|
||||
buffer << params[:ch] ? params[:ch] : ""
|
||||
buffer << (user.can_play? ? "1" : "0")
|
||||
|
||||
out << "#USER#"
|
||||
out << Verification.verify(buffer.join)
|
||||
out << buffer.join("\r")
|
||||
else
|
||||
out << "#FAIL#"
|
||||
end
|
||||
|
||||
render_out out
|
||||
end
|
||||
|
||||
#def admin
|
||||
# areq = AdminRequest.new
|
||||
# areq.addr = params[:addr]
|
||||
# areq.pwd = params[:pwd]
|
||||
# areq.msg = params[:msg]
|
||||
# areq.player = params[:player]
|
||||
# areq.user_id = params[:user]
|
||||
# areq.save!
|
||||
# render :text => "Ok"
|
||||
#end
|
||||
|
||||
def ban
|
||||
ban = Ban.new
|
||||
ban.steamid = params[:id]
|
||||
ban.ts = params[:ts]
|
||||
ban.sign = params[:sign]
|
||||
ban.expiry = DateTime.now.ago(-(params[:len].to_i*60))
|
||||
ban.addr = params[:addr]
|
||||
ban.reason = params[:reason]
|
||||
ban.ban_type = Ban::TYPE_SERVER
|
||||
ban.save!
|
||||
|
||||
render :text => "Ok"
|
||||
end
|
||||
|
||||
def hltv_req
|
||||
if params[:game].to_i > 0
|
||||
if match = Match.first(:conditions => {:id => params[:game]})
|
||||
match.hltv_record params[:addr], params[:pwd]
|
||||
hltv = match.hltv
|
||||
else
|
||||
render :text => t(:matches_notfound)
|
||||
end
|
||||
else
|
||||
hltv = Server.hltvs.active.unreserved_now.unreserved_hltv_around(DateTime.now).first unless hltv
|
||||
render :text => t(:hltv_notavailable) unless hltv
|
||||
|
||||
hltv.recording = params[:game]
|
||||
hltv.reservation = params[:addr]
|
||||
hltv.pwd = params[:pwd]
|
||||
hltv.save!
|
||||
end
|
||||
|
||||
render :text => t(:hltv_sent)
|
||||
end
|
||||
|
||||
def hltv_move
|
||||
Server.move params[:addr], params[:newaddr], params[:newpwd]
|
||||
render :text => t(:hltv_movedd) + params[:newaddr]
|
||||
end
|
||||
|
||||
def hltv_stop
|
||||
Server.stop params[:addr]
|
||||
render :text => t(:hltv_stopped)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def render_out out
|
||||
@text = out.join("\r")
|
||||
render :layout => false
|
||||
end
|
||||
end
|
|
@ -15,6 +15,7 @@ class ShoutmsgsController < ApplicationController
|
|||
|
||||
def create
|
||||
@shoutmsg = Shoutmsg.new params[:shoutmsg]
|
||||
puts @shoutmsg
|
||||
@shoutmsg.user = cuser
|
||||
raise AccessError unless @shoutmsg.can_create? cuser
|
||||
|
||||
|
|
|
@ -27,13 +27,12 @@ class Ban < ActiveRecord::Base
|
|||
VENT_BANS = "tmp/bans.txt"
|
||||
|
||||
attr_protected :id, :created_at, :updated_at
|
||||
attr_accessor :ts, :sign, :len, :user_name
|
||||
attr_accessor :len, :user_name
|
||||
|
||||
scope :ordered, order: "created_at DESC"
|
||||
scope :effective, conditions: "expiry > UTC_TIMESTAMP()"
|
||||
scope :ineffective, conditions: "expiry < UTC_TIMESTAMP()"
|
||||
|
||||
validate :validate_ts
|
||||
validate :validate_type
|
||||
validate :validate_ventban
|
||||
validates_format_of :steamid, with: /\A([0-9]{1,10}:){2}[0-9]{1,10}\Z/, allow_blank: true
|
||||
|
@ -58,12 +57,6 @@ class Ban < ActiveRecord::Base
|
|||
TYPE_GATHER => "Gather"}
|
||||
end
|
||||
|
||||
def validate_ts
|
||||
if ts and Verification.verify(steamid + ts.to_s) != sign
|
||||
errors.add :ts, I18n.t(:wrong_verification_code)
|
||||
end
|
||||
end
|
||||
|
||||
def validate_type
|
||||
errors.add :ban_type, I18n.t(:invalid_ban_type) unless types.include? ban_type
|
||||
end
|
||||
|
@ -94,12 +87,4 @@ class Ban < ActiveRecord::Base
|
|||
def can_destroy? cuser
|
||||
cuser and cuser.admin?
|
||||
end
|
||||
|
||||
def self.refresh
|
||||
#file = File.new(VENT_BANS, "w")
|
||||
#Ban.all(:conditions => ["ban_type = ? AND expiry > UTC_TIMESTAMP()", TYPE_VENT]).each do |ban|
|
||||
# file.write "#{ban.ip},,,"
|
||||
#end
|
||||
#file.close
|
||||
end
|
||||
end
|
||||
|
|
|
@ -99,8 +99,8 @@ class Issue < ActiveRecord::Base
|
|||
cuser and !cuser.nil? and ((author == cuser) or cuser.admin?)
|
||||
end
|
||||
|
||||
def can_create? cuser, params = {}
|
||||
Verification.contain params, [:title, :category_id, :text]
|
||||
def can_create? cuser
|
||||
true
|
||||
end
|
||||
|
||||
def can_update? cuser
|
||||
|
|
|
@ -21,8 +21,6 @@ class Log < ActiveRecord::Base
|
|||
attr_accessor :text
|
||||
|
||||
DOMAIN_LOG = 1
|
||||
DOMAIN_RCON_COMMAND = 2
|
||||
DOMAIN_RCON_RESPONSE = 3
|
||||
DOMAIN_INFO = 4
|
||||
|
||||
TEAM_MARINES = 1
|
||||
|
@ -52,10 +50,6 @@ class Log < ActiveRecord::Base
|
|||
belongs_to :actor, :class_name => "Rounder"
|
||||
belongs_to :target, :class_name => "Rounder"
|
||||
|
||||
# def domains
|
||||
# return {DOMAIN_LOG => "HL Log", DOMAIN_RCON_COMMAND => "Rcon Command Log", DOMAIN_RCON_RESPONSE => "Rcon Response Log", DOMAIN_INFO => "Action Log"}
|
||||
# end
|
||||
|
||||
def since
|
||||
(created_at - round.start).to_i
|
||||
end
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
# dns :string(255)
|
||||
# ip :string(255)
|
||||
# port :string(255)
|
||||
# rcon :string(255)
|
||||
# password :string(255)
|
||||
# irc :string(255)
|
||||
# user_id :integer
|
||||
|
@ -44,7 +43,7 @@ class Server < ActiveRecord::Base
|
|||
attr_protected :id, :user_id, :updated_at, :created_at, :map, :players, :maxplayers, :ping, :version
|
||||
|
||||
validates_length_of [:name, :dns,], :in => 1..30
|
||||
validates_length_of [:rcon, :password, :irc], :maximum => 30, :allow_blank => true
|
||||
validates_length_of [:password, :irc], :maximum => 30, :allow_blank => true
|
||||
validates_length_of :description, :maximum => 255, :allow_blank => true
|
||||
validates_format_of :ip, :with => /\A[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\z/
|
||||
validates_format_of :port, :with => /\A[0-9]{1,5}\z/
|
||||
|
@ -81,7 +80,6 @@ class Server < ActiveRecord::Base
|
|||
non_versioned_columns << 'dns'
|
||||
non_versioned_columns << 'ip'
|
||||
non_versioned_columns << 'port'
|
||||
non_versioned_columns << 'rcon'
|
||||
non_versioned_columns << 'password'
|
||||
non_versioned_columns << 'irc'
|
||||
non_versioned_columns << 'user_id'
|
||||
|
|
|
@ -5,5 +5,5 @@
|
|||
</p>
|
||||
|
||||
<p>
|
||||
<%= namelink message.sender %> on <em><%= longdate message.created_at %></em>
|
||||
</p>
|
||||
To: <%= namelink message.recipient %> From: <%= namelink message.sender %> on <em><%= longdate message.created_at %></em></em>
|
||||
</p>
|
|
@ -16,10 +16,6 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields horizontal">
|
||||
<%= f.label :rcon %>
|
||||
<%= f.text_field :rcon %>
|
||||
</div>
|
||||
<div class="fields horizontal">
|
||||
<%= f.label :password %>
|
||||
<%= f.text_field :password %>
|
||||
|
|
|
@ -6,6 +6,9 @@ base: &db
|
|||
username: <%= ENV['MYSQL_USERNAME'] %>
|
||||
password: <%= ENV['MYSQL_PASSWORD'] %>
|
||||
pool: <%= Integer(ENV['MYSQL_CONNECTION_POOL'] || 8) %>
|
||||
wait_timeout: 90
|
||||
reconnect: true
|
||||
|
||||
|
||||
development:
|
||||
<<: *db
|
||||
|
|
|
@ -111,13 +111,6 @@ Ensl::Application.routes.draw do
|
|||
match 'movies/preview'
|
||||
match 'movies/snapshot'
|
||||
|
||||
match 'plugin/esi'
|
||||
match 'plugin/user'
|
||||
match 'plugin/ban'
|
||||
match 'plugin/hltv_req'
|
||||
match 'plugin/hltv_move'
|
||||
match 'plugin/hltv_stop'
|
||||
|
||||
match 'users/forgot'
|
||||
match 'users/recover'
|
||||
match 'users/agenda'
|
||||
|
|
9
db/migrate/20150518162749_remove_rcon_from_servers.rb
Normal file
9
db/migrate/20150518162749_remove_rcon_from_servers.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
class RemoveRconFromServers < ActiveRecord::Migration
|
||||
def up
|
||||
remove_column :servers, :rcon
|
||||
end
|
||||
|
||||
def down
|
||||
add_column :servers, :rcon, :string
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20141010193221) do
|
||||
ActiveRecord::Schema.define(:version => 20150518162749) do
|
||||
|
||||
create_table "admin_requests", :force => true do |t|
|
||||
t.string "addr"
|
||||
|
@ -722,7 +722,6 @@ ActiveRecord::Schema.define(:version => 20141010193221) do
|
|||
t.string "dns"
|
||||
t.string "ip"
|
||||
t.string "port"
|
||||
t.string "rcon"
|
||||
t.string "password"
|
||||
t.string "irc"
|
||||
t.integer "user_id"
|
||||
|
|
|
@ -1,53 +1,8 @@
|
|||
module Verification
|
||||
def Verification.verify input
|
||||
md5 = Digest::MD5.hexdigest("9WvcZ9hX" + input + "KF7L4luQ").upcase.split(//)
|
||||
chars = ["A", "B", "C", "D", "E", "F"]
|
||||
nums = []
|
||||
lastPos = md5[31].to_i
|
||||
result = ""
|
||||
|
||||
for i in 0..9
|
||||
pos = md5[i].to_i
|
||||
|
||||
if pos == 0
|
||||
pos = lastPos ** (i % 4)
|
||||
elsif (pos % 4) == 0
|
||||
pos = pos * lastPos + i
|
||||
elsif (pos % 3) == 0
|
||||
pos = pos ** (i % 4)
|
||||
elsif (pos % 2) == 0
|
||||
pos = pos * i + pos
|
||||
end
|
||||
|
||||
pos = (pos > 31) ? (pos % 32) : pos
|
||||
curChar = md5[31 - pos]
|
||||
curNum = curChar.to_i
|
||||
|
||||
if nums.include? curNum
|
||||
if curNum == 0
|
||||
curChar = chars[pos % 6]
|
||||
else
|
||||
curChar = (pos % 10).to_s
|
||||
end
|
||||
curNum = curChar.to_i
|
||||
end
|
||||
|
||||
nums << curNum
|
||||
result << curChar
|
||||
lastPos = pos
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
def Verification.uncrap str
|
||||
str.to_s.gsub(/[^A-Za-z0-9_\-]/, "")
|
||||
end
|
||||
|
||||
def Verification.match_addr str
|
||||
str.to_s.match(/(([0-9]{1,3}\.){3}[0-9]{1,3}):?([0-9]{0,5})/)[0]
|
||||
end
|
||||
|
||||
def Verification.random_string len
|
||||
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
|
||||
str = ""
|
||||
|
|
23
spec/factories/ban.rb
Normal file
23
spec/factories/ban.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
FactoryGirl.define do
|
||||
factory :ban do
|
||||
ban_type Ban::TYPE_SITE
|
||||
expiry Date.today + 1
|
||||
# Hack because of the awkward way bans are created (requires user_name)
|
||||
before(:create) do |ban|
|
||||
if ban.user.nil?
|
||||
user = create :user
|
||||
ban.user_name = user.username
|
||||
else
|
||||
ban.user_name = ban.user.username
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
trait :mute do
|
||||
ban_type Ban::TYPE_MUTE
|
||||
end
|
||||
|
||||
trait :expired do
|
||||
expiry Date.yesterday - 1
|
||||
end
|
||||
end
|
8
spec/factories/issue.rb
Normal file
8
spec/factories/issue.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
FactoryGirl.define do
|
||||
factory :issue do
|
||||
sequence(:title) { |n| "Issue title #{n}" }
|
||||
sequence(:text) { |n| "Issue Text #{n}" }
|
||||
status Issue::STATUS_OPEN
|
||||
association :author, factory: :user
|
||||
end
|
||||
end
|
9
spec/factories/message.rb
Normal file
9
spec/factories/message.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
FactoryGirl.define do
|
||||
factory :message do
|
||||
association :sender, factory: :user
|
||||
association :recipient, factory: :user
|
||||
sequence(:text) { |n| "text-#{n}" }
|
||||
sequence(:title) { |n| "title-#{n}" }
|
||||
sequence(:text_parsed) { |n| "text-#{n}" }
|
||||
end
|
||||
end
|
50
spec/features/issues/issues_spec.rb
Normal file
50
spec/features/issues/issues_spec.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'Issues' do
|
||||
let!(:user) { create :user }
|
||||
|
||||
scenario 'creation' do
|
||||
sign_in_as user
|
||||
click_link 'Agenda'
|
||||
click_link 'Issues'
|
||||
click_link 'New issue'
|
||||
expect(page).to have_content('New Issue')
|
||||
issue_title = 'My Problem'
|
||||
issue_description = "There's a fly in my soup"
|
||||
fill_in 'Title', with: issue_title
|
||||
fill_in 'Text', with: issue_description
|
||||
click_button 'Submit'
|
||||
expect(page).to have_content('Issue was successfully created.')
|
||||
expect(page).to have_content(issue_title)
|
||||
expect(page).to have_content(issue_description)
|
||||
end
|
||||
|
||||
feature 'adminstration' do
|
||||
let!(:admin) { create :user, :admin }
|
||||
let!(:issue) { create :issue, author: user }
|
||||
|
||||
scenario 'issue management' do
|
||||
sign_in_as admin
|
||||
click_link 'Admin'
|
||||
click_link 'Issues (1)'
|
||||
within '#open' do
|
||||
expect(page).to have_content(issue.title)
|
||||
expect(page).to have_content(issue.author.username)
|
||||
end
|
||||
visit edit_issue_path(issue)
|
||||
expect(page).to have_content('Editing Issue')
|
||||
solution = "Use a baseball bat"
|
||||
fill_in "Title", with: "Foo"
|
||||
fill_in "Text", with: "Bar"
|
||||
fill_in "Solution", with: solution
|
||||
select 'Solved', from: 'Status'
|
||||
click_button 'Submit'
|
||||
expect(page).to have_content('Issue was successfully updated.')
|
||||
visit issues_path
|
||||
within '#solved' do
|
||||
expect(page).to have_content("Foo")
|
||||
expect(page).to have_content(issue.author.username)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
59
spec/features/messages/user_messages.rb
Normal file
59
spec/features/messages/user_messages.rb
Normal file
|
@ -0,0 +1,59 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'Message creation' do
|
||||
let!(:sender) { create :user }
|
||||
let!(:recipient) { create :user }
|
||||
|
||||
background do
|
||||
sign_in_as sender
|
||||
end
|
||||
|
||||
scenario 'User creates a message' do
|
||||
visit root_path
|
||||
within '.links' do
|
||||
click_link 'Messages'
|
||||
end
|
||||
expect(page).to have_content('Sent (0)')
|
||||
visit user_path(recipient)
|
||||
expect(page).to have_content(recipient.username)
|
||||
click_link 'Send PM'
|
||||
expect(page).to have_content('New Message')
|
||||
title = "This is my title"
|
||||
message = "This is my message"
|
||||
fill_in 'Title', with: title
|
||||
fill_in 'Text', with: message
|
||||
click_button 'Send Message'
|
||||
expect(page).to have_content('Message was successfully sent.')
|
||||
expect(page).to have_content(title)
|
||||
expect(page).to have_content(message)
|
||||
within '.links' do
|
||||
click_link 'Messages'
|
||||
end
|
||||
expect(page).to have_content('Sent (1)')
|
||||
within '#sent' do
|
||||
expect(page).to have_content(title)
|
||||
expect(page).to have_content(message)
|
||||
expect(page).to have_content(sender.username)
|
||||
expect(page).to have_content(recipient.username)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature 'Message receiving' do
|
||||
let!(:message) { create :message }
|
||||
|
||||
background do
|
||||
sign_in_as message.recipient
|
||||
end
|
||||
|
||||
scenario 'User receives a message' do
|
||||
visit root_path
|
||||
within '.links' do
|
||||
expect(page).to have_content('(1)')
|
||||
click_link 'Messages'
|
||||
end
|
||||
expect(page).to have_content(message.title)
|
||||
expect(page).to have_content(message.text)
|
||||
expect(page).to have_content(message.sender.username)
|
||||
end
|
||||
end
|
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
|
60
spec/models/issue_spec.rb
Normal file
60
spec/models/issue_spec.rb
Normal file
|
@ -0,0 +1,60 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: issues
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# title :string(255)
|
||||
# status :integer
|
||||
# assigned_id :integer
|
||||
# category_id :integer
|
||||
# text :text
|
||||
# author_id :integer
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# solution :text
|
||||
# text_parsed :text
|
||||
#
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'User' do
|
||||
describe 'Permissions' do
|
||||
let!(:user) { create :user }
|
||||
let!(:admin) { create :user, :admin }
|
||||
let(:issue) { Issue.new }
|
||||
|
||||
describe 'can_show?' do
|
||||
it 'returns true for author' do
|
||||
issue.author = user
|
||||
expect(issue.can_show? user).to be_true
|
||||
end
|
||||
it 'returns true for admin' do
|
||||
expect(issue.can_show? admin).to be_true
|
||||
end
|
||||
it 'returns false if neither admin nor author' do
|
||||
expect(issue.can_show? user).to be_false
|
||||
end
|
||||
end
|
||||
describe 'can_create?' do
|
||||
it "returns true" do
|
||||
expect(issue.can_create? nil).to be_true
|
||||
end
|
||||
end
|
||||
describe 'can_update?' do
|
||||
it 'returns true for admin' do
|
||||
expect(issue.can_update? admin).to be_true
|
||||
end
|
||||
it 'returns false for non-admin' do
|
||||
expect(issue.can_update? user).to be_false
|
||||
end
|
||||
end
|
||||
describe 'can_destroy?' do
|
||||
it 'returns true for admin' do
|
||||
expect(issue.can_destroy? admin).to be_true
|
||||
end
|
||||
it 'returns false for non-admin' do
|
||||
expect(issue.can_destroy? user).to be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
57
spec/models/message_spec.rb
Normal file
57
spec/models/message_spec.rb
Normal file
|
@ -0,0 +1,57 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: messages
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# sender_type :string(255)
|
||||
# sender_id :integer
|
||||
# recipient_type :string(255)
|
||||
# recipient_id :integer
|
||||
# title :string(255)
|
||||
# text :text
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# text_parsed :text
|
||||
#
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Message do
|
||||
let!(:user) { create :user }
|
||||
|
||||
describe 'create' do
|
||||
let(:message) { build :message }
|
||||
it 'creates a new message' do
|
||||
expect(message.valid?).to be_true
|
||||
expect do
|
||||
message.save!
|
||||
end.to change(Message, :count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Permissions' do
|
||||
let(:message) { Message.new }
|
||||
describe 'can_create?' do
|
||||
it 'returns true for user' do
|
||||
expect(message.can_create?(user)).to be_true
|
||||
end
|
||||
it 'returns false if user is banned' do
|
||||
create :ban, :mute, user: user
|
||||
expect(message.can_create?(user)).to be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'can_show?' do
|
||||
let!(:message) { create :message }
|
||||
it 'returns true if sender' do
|
||||
expect(message.can_show?(message.sender)).to be_true
|
||||
end
|
||||
it 'returns true if receiver' do
|
||||
expect(message.can_show?(message.recipient)).to be_true
|
||||
end
|
||||
it 'returns false if neither sender nor receiver' do
|
||||
expect(message.can_show?(user)).to be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -8,7 +8,6 @@
|
|||
# dns :string(255)
|
||||
# ip :string(255)
|
||||
# port :string(255)
|
||||
# rcon :string(255)
|
||||
# password :string(255)
|
||||
# irc :string(255)
|
||||
# user_id :integer
|
||||
|
|
|
@ -4,7 +4,6 @@ module Features
|
|||
dns = 'ServerDns.com'
|
||||
ip = '192.168.1.1'
|
||||
port = '8000'
|
||||
rcon = 'whatsrcon'
|
||||
password = 'secret'
|
||||
name = 'MyNsServer'
|
||||
description = 'My NS Server'
|
||||
|
|
Loading…
Reference in a new issue