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:
parent
7725cd59b4
commit
162f04d789
4 changed files with 24 additions and 16 deletions
|
@ -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
5
test/factories/acls.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
FactoryGirl.define do
|
||||
factory :acl do
|
||||
sequence(:k) { |n| "Key #{n}" }
|
||||
end
|
||||
end
|
13
test/fixtures/acls.yml
vendored
13
test/fixtures/acls.yml
vendored
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue