Style guide updates to specs

This commit is contained in:
Luke Barratt 2015-08-15 19:23:42 +01:00
parent b11db192d7
commit f778ab6d5d
8 changed files with 77 additions and 67 deletions

View file

@ -17,4 +17,3 @@ describe Api::V1::MapsController do
end
end
end

View file

@ -18,4 +18,3 @@ describe Api::V1::ServersController do
end
end
end

View file

@ -94,4 +94,3 @@ describe Api::V1::UsersController do
end
end
end

View file

@ -15,17 +15,18 @@
# ip :string(255)
#
require 'spec_helper'
require "spec_helper"
describe Ban do
let!(:user) { create :user }
let(:ban) { Ban.new }
let!(:server) { create :server }
describe '#check_user' do
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
@ -33,46 +34,46 @@ describe Ban 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
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
describe "can_create?" do
it "returns true for admins" do
expect(ban.can_create? admin).to be_truthy
end
it 'returns false for non-admins' do
it "returns false for non-admins" do
expect(ban.can_create? user).to be_falsey
end
end
describe 'can_destroy?' do
it 'returns true for admin' do
describe "can_destroy?" do
it "returns true for admin" do
expect(ban.can_destroy? admin).to be_truthy
end
it 'returns false for non-admins' do
it "returns false for non-admins" do
expect(ban.can_destroy? user).to be_falsey
end
end
describe 'can_update?' do
it 'returns true for admin' do
describe "can_update?" do
it "returns true for admin" do
expect(ban.can_update? admin).to be_truthy
end
it 'returns false for non-admins' do
it "returns false for non-admins" do
expect(ban.can_update? user).to be_falsey
end
end
end
end

View file

@ -15,51 +15,51 @@
# text_parsed :text
#
require 'spec_helper'
require "spec_helper"
describe 'User' do
describe 'Permissions' do
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
describe "can_show?" do
it "returns true for author" do
issue.author = user
expect(issue.can_show? user).to be_truthy
end
it 'returns true for admin' do
it "returns true for admin" do
expect(issue.can_show? admin).to be_truthy
end
it 'returns false if neither admin nor author' do
it "returns false if neither admin nor author" do
expect(issue.can_show? user).to be_falsey
end
end
describe 'can_create?' do
describe "can_create?" do
it "returns true" do
expect(issue.can_create? nil).to be_truthy
end
end
describe 'can_update?' do
it 'returns true for admin' do
describe "can_update?" do
it "returns true for admin" do
expect(issue.can_update? admin).to be_truthy
end
it 'returns false for non-admin' do
it "returns false for non-admin" do
expect(issue.can_update? user).to be_falsey
end
end
describe 'can_destroy?' do
it 'returns true for admin' do
describe "can_destroy?" do
it "returns true for admin" do
expect(issue.can_destroy? admin).to be_truthy
end
it 'returns false for non-admin' do
it "returns false for non-admin" do
expect(issue.can_destroy? user).to be_falsey
end
end

View file

@ -14,15 +14,15 @@
# text_parsed :text
#
require 'spec_helper'
require "spec_helper"
describe Message do
let!(:user) { create :user }
describe 'create' do
describe "create" do
let(:message) { build :message }
it 'creates a new message' do
it "creates a new message" do
expect(message.valid?).to eq(true)
expect do
message.save!
@ -30,35 +30,34 @@ describe Message do
end
end
describe 'Permissions' do
describe "Permissions" do
let(:message) { Message.new }
describe 'can_create?' do
it 'returns true for user' do
describe "can_create?" do
it "returns true for user" do
expect(message.can_create?(user)).to be_truthy
end
it 'returns false if user is banned' do
it "returns false if user is banned" do
create :ban, :mute, user: user
expect(message.can_create?(user)).to be_falsey
end
end
describe 'can_show?' do
describe "can_show?" do
let!(:message) { create :message }
it 'returns true if sender' do
it "returns true if sender" do
expect(message.can_show?(message.sender)).to be_truthy
end
it 'returns true if receiver' do
it "returns true if receiver" do
expect(message.can_show?(message.recipient)).to be_truthy
end
it 'returns false if neither sender nor receiver' do
it "returns false if neither sender nor receiver" do
expect(message.can_show?(user)).to be_falsey
end
end
end
end

View file

@ -30,69 +30,76 @@
# category_id :integer
#
require 'spec_helper'
require "spec_helper"
describe Server do
describe 'create' do
it 'sets category to 45 if domain is NS2' 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
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'
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')
expect(server.addr).to eq("1.1.1.1:8000")
end
end
describe 'to_s' do
it 'returns server name' do
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
describe "Permissions" do
let!(:user) { create :user }
let!(:admin) { create :user, :admin }
let!(:server_user) {create :user }
let!(:server_user) { create :user }
let!(:server) { create :server, user: server_user }
describe 'can_create?' do
it 'returns true for non-admins' do
describe "can_create?" do
it "returns true for non-admins" do
expect(server.can_create? user).to be_truthy
end
end
describe 'can_destroy?' do
it 'returns true for admin' do
describe "can_destroy?" do
it "returns true for admin" do
expect(server.can_destroy? admin).to eq(true)
end
it 'returns false for non-admins' do
it "returns false for non-admins" do
expect(server.can_destroy? user).to eq(false)
end
end
describe 'can_update?' do
it 'returns true for admin' do
describe "can_update?" do
it "returns true for admin" do
expect(server.can_update? admin).to eq(true)
end
it 'returns true if server belongs to user' do
it "returns true if server belongs to user" do
expect(server.can_update? server_user).to eq(true)
end
it 'returns false for non-admins' do
it "returns false for non-admins" do
expect(server.can_update? user).to eq(false)
end
end
end
end

View file

@ -32,12 +32,18 @@ describe User do
end
it "returns true if user is banned" do
ban = Ban.create! ban_type: Ban::TYPE_SITE, expiry: Time.now + 10.days, user_name: user.username
Ban.create!(ban_type: Ban::TYPE_SITE,
expiry: Time.now + 10.days,
user_name: user.username)
expect(user.banned?).to be_truthy
end
it "returns true for specific bans" do
ban = Ban.create! ban_type: Ban::TYPE_MUTE, expiry: Time.now + 10.days, user_name: user.username
Ban.create!(ban_type: Ban::TYPE_MUTE,
expiry: Time.now + 10.days,
user_name: user.username)
expect(user.banned? Ban::TYPE_MUTE).to be_truthy
end
end