diff --git a/test/factories/domain.rb b/test/factories/domain.rb index 0da1225..20e6af5 100644 --- a/test/factories/domain.rb +++ b/test/factories/domain.rb @@ -1,36 +1,39 @@ FactoryGirl.define do sequence(:domain) { |n| "example#{n}.com" } + sequence(:v4_gen_arpa_domain) { |n| "2.0.#{n}.in-addr.arpa" } + sequence(:v6_gen_arpa_domain) { |n| "#{(n % 16).to_s(16)}.b.d.0.1.0.0.2.ip6.arpa" } + factory :domain do group name { generate(:domain) } serial_strategy Strategies::Date type 'NATIVE' end factory :slave, parent: :domain do type 'SLAVE' master '1.2.3.4' end factory :date_domain, class: Domain do group name { generate(:domain) } serial_strategy Strategies::Date type 'NATIVE' end factory :v4_arpa_domain, parent: :domain do - name '2.0.192.in-addr.arpa' + name { generate(:v4_gen_arpa_domain) } end factory :v6_arpa_domain, parent: :domain do - name '8.b.d.0.1.0.0.2.ip6.arpa' + name { generate(:v6_gen_arpa_domain) } end factory :domain_with_subscriptions, parent: :domain do association :group, factory: :group_with_users after(:create) do |domain| Subscription.create(domain: domain, user:domain.group.users.first) end end end diff --git a/test/models/ptr_test.rb b/test/models/ptr_test.rb index 6468f15..82ddf84 100644 --- a/test/models/ptr_test.rb +++ b/test/models/ptr_test.rb @@ -1,50 +1,50 @@ require 'test_helper' class PTRTest < ActiveSupport::TestCase class V4PTRTest < ActiveSupport::TestCase setup do @record = build(:v4_ptr) end test 'save' do @record.save assert_empty @record.errors end test 'guess record' do - @record.name = '192.0.2.1' + @record.name = @record.domain.name.split(".")[0..-3].reverse.join(".") + ".1" assert @record.save - assert_equal '1.2.0.192.in-addr.arpa', @record.name + assert_equal @record.name, "1." + @record.domain.name end test 'chop terminating dot' do @record.content = 'with-dot.example.com.' @record.save! @record.reload assert_equal 'with-dot.example.com', @record.content end end class V6PTRTest < ActiveSupport::TestCase setup do @record = build(:v6_ptr) end test 'save' do @record.save assert_empty @record.errors end test 'guess record' do - @record.name = '2001:db8::2' + @record.name = '2001:db' + @record.domain.name.split(".")[0] + '::2' assert @record.save - assert_equal '2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa', + assert_equal '2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.' + @record.domain.name, @record.name end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 315306f..e657e45 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,11 +1,12 @@ ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' +require 'factory_girl_rails' Dir[Rails.root.join('test/support/*.rb')].each { |f| require f } module ActiveSupport class TestCase include FactoryGirl::Syntax::Methods end end