Convert ACL fixture to a factory, and add some tests

The fixture was unused, so I took the opportunity to put in a couple
of basic model tests.
This commit is contained in:
Andy Allan 2016-10-26 09:15:56 +01:00
parent 7725cd59b4
commit 162f04d789
4 changed files with 24 additions and 16 deletions

View file

@ -1,4 +1,6 @@
class Acl < ActiveRecord::Base
validates :k, :presence => true
def self.match(address, domain = nil)
if domain
Acl.where("address >>= ? OR domain = ?", address, domain)

5
test/factories/acls.rb Normal file
View file

@ -0,0 +1,5 @@
FactoryGirl.define do
factory :acl do
sequence(:k) { |n| "Key #{n}" }
end
end

View file

@ -1,13 +0,0 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
one:
address: 1
netmask: 1
k: MyText
v: MyText
two:
address: 1
netmask: 1
k: MyText
v: MyText

View file

@ -1,8 +1,22 @@
require "test_helper"
class AclTest < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth
assert true
def test_k_required
acl = create(:acl)
assert acl.valid?
acl.k = nil
assert !acl.valid?
end
def test_no_account_creation_by_subnet
assert !Acl.no_account_creation("192.168.1.1")
create(:acl, :address => "192.168.0.0/16", :k => "no_account_creation")
assert Acl.no_account_creation("192.168.1.1")
end
def test_no_account_creation_by_domain
assert !Acl.no_account_creation("192.168.1.1", "example.com")
create(:acl, :domain => "example.com", :k => "no_account_creation")
assert Acl.no_account_creation("192.168.1.1", "example.com")
end
end