Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F461670
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, May 18, 1:07 PM
Size
4 KB
Mime Type
text/x-diff
Expires
Tue, May 20, 1:07 PM (1 d, 11 h)
Engine
blob
Format
Raw Data
Handle
220393
Attached To
rWEBDNS WebDNS (edet4)
View Options
diff --git a/test/factories/a.rb b/test/factories/a.rb
new file mode 100644
index 0000000..f270d1c
--- /dev/null
+++ b/test/factories/a.rb
@@ -0,0 +1,7 @@
+FactoryGirl.define do
+ factory :a do
+ domain
+ name { generate(:subdomain) }
+ content '1.2.3.4'
+ end
+end
diff --git a/test/factories/domain.rb b/test/factories/domain.rb
new file mode 100644
index 0000000..f216127
--- /dev/null
+++ b/test/factories/domain.rb
@@ -0,0 +1,7 @@
+FactoryGirl.define do
+ sequence(:domain) { |n| "example#{n}.com" }
+ factory :domain do
+ name { generate(:domain) }
+ type 'NATIVE'
+ end
+end
diff --git a/test/factories/record.rb b/test/factories/record.rb
new file mode 100644
index 0000000..558342d
--- /dev/null
+++ b/test/factories/record.rb
@@ -0,0 +1,3 @@
+FactoryGirl.define do
+ sequence(:subdomain) { |n| "sub-#{n}" }
+end
diff --git a/test/factories/soa.rb b/test/factories/soa.rb
new file mode 100644
index 0000000..0cb37d4
--- /dev/null
+++ b/test/factories/soa.rb
@@ -0,0 +1,5 @@
+FactoryGirl.define do
+ factory :soa, class: SOA do
+ serial 3
+ end
+end
diff --git a/test/models/a_test.rb b/test/models/a_test.rb
new file mode 100644
index 0000000..da078ee
--- /dev/null
+++ b/test/models/a_test.rb
@@ -0,0 +1,32 @@
+require 'test_helper'
+
+class ATest < ActiveSupport::TestCase
+ [
+ '0.0.0.0',
+ '1.2.3.4',
+ '255.255.255.255',
+ ].each { |ip|
+ test "content valid #{ip}" do
+ rec = build(:a, content: ip)
+ rec.valid?
+ assert_empty rec.errors[:content], "#{ip} should be valid!"
+ end
+ }
+
+ [
+ 'noip',
+ 'no ip',
+ '1.2',
+ '1.2.3.4.5',
+ '1.2.3.256',
+ '1.2.3.4/24',
+ '::1',
+ ].each { |ip|
+ test "content invalid #{ip}" do
+ rec = build(:a, content: ip)
+ rec.valid?
+ assert_not_empty rec.errors[:content], "#{name} should be invalid!"
+ end
+ }
+
+end
diff --git a/test/models/domain_test.rb b/test/models/domain_test.rb
new file mode 100644
index 0000000..986fbc4
--- /dev/null
+++ b/test/models/domain_test.rb
@@ -0,0 +1,47 @@
+require 'test_helper'
+
+class DomainTest < ActiveSupport::TestCase
+ def setup
+ @domain = build(:domain)
+ end
+
+ test 'automatic SOA creation' do
+ @domain.save!
+ @domain.reload
+ assert_not_nil @domain.soa
+ assert_equal 1, @domain.soa.serial
+ end
+
+ test 'increment serial on new record' do
+ @domain.save!
+ soa = @domain.soa
+
+ assert_serial_update soa do
+ www = A.new(name: 'www', domain: @domain, content: '1.2.3.4')
+ www.save!
+ end
+ end
+
+ test 'increment serial on record update' do
+ @domain.save!
+ www = A.new(name: 'www', domain: @domain, content: '1.2.3.4')
+ www.save!
+ soa = @domain.soa.reload
+
+ assert_serial_update soa do
+ www.content = '1.2.3.5'
+ www.save!
+ end
+ end
+
+ test 'increment serial on record destroy' do
+ @domain.save!
+ www = A.new(name: 'www', domain: @domain, content: '1.2.3.4')
+ www.save!
+ soa = @domain.soa.reload
+
+ assert_serial_update soa do
+ www.destroy!
+ end
+ end
+end
diff --git a/test/models/soa_test.rb b/test/models/soa_test.rb
new file mode 100644
index 0000000..3ad4cfa
--- /dev/null
+++ b/test/models/soa_test.rb
@@ -0,0 +1,25 @@
+require 'test_helper'
+
+class SOATest < ActiveSupport::TestCase
+ def setup
+ domain = create(:domain)
+ @record = domain.soa
+ end
+
+ test 'bump_serial!' do
+ @record.save!
+
+ assert_serial_update @record do
+ @record.bump_serial!
+ end
+ end
+
+ test 'updating attributes bumps serial' do
+ @record.save!
+
+ assert_serial_update @record do
+ @record.contact = 'admin@example.com'
+ @record.save!
+ end
+ end
+end
diff --git a/test/support/assertions.rb b/test/support/assertions.rb
new file mode 100644
index 0000000..b672f57
--- /dev/null
+++ b/test/support/assertions.rb
@@ -0,0 +1,13 @@
+module Assertions
+
+ def assert_serial_update(soa, message=nil)
+ soa.reload
+ assert_difference 'soa.serial', 1, message do
+ yield
+ soa.reload
+ end
+ end
+
+end
+
+ActiveSupport::TestCase.include Assertions
Event Timeline
Log In to Comment