Browse Source

spec, ensurances, tweaks

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
722a99a120
  1. 16
      Gemfile
  2. 19
      Gemfile.lock
  3. 32
      Guardfile
  4. 10
      app/controllers/domains_controller.rb
  5. 10
      app/models/domain.rb
  6. 18
      app/models/soa.rb
  7. 25
      config/database.yml.mysql.sample
  8. 4
      db/seeds.rb
  9. 25
      spec/factories.rb
  10. 2
      spec/helpers/soas_helper_spec.rb
  11. 5
      spec/models/domain_spec.rb
  12. 8
      spec/spec_helper.rb
  13. 8
      spec/support/rspec.rb

16
Gemfile

@ -5,15 +5,8 @@ gem 'rails', '3.1.1.rc1'
# Bundle edge Rails instead: # Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git' # gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do # gem 'pg'
gem 'sqlite3' gem 'mysql2'
end
group :production do
# gem 'pg'
gem 'mysql2'
end
gem 'devise', '~> 1.4.5' gem 'devise', '~> 1.4.5'
gem 'cancan', '~> 1.6.5' gem 'cancan', '~> 1.6.5'
# gem "meta_where", "~> 1.0" # squeel ? # gem "meta_where", "~> 1.0" # squeel ?
@ -41,9 +34,12 @@ gem 'jquery-rails'
gem 'rspec-rails', '~> 2.6.1', :group => [:test, :development] gem 'rspec-rails', '~> 2.6.1', :group => [:test, :development]
group :test do group :test do
gem 'forgery','~> 0.3.12' gem 'faker','~> 1.0.1'
gem 'factory_girl_rails', '~> 1.2' gem 'factory_girl_rails', '~> 1.2'
gem 'capybara', '~> 1.1.1' gem 'capybara', '~> 1.1.1'
gem 'database_cleaner', '~> 0.6.7' gem 'database_cleaner', '~> 0.6.7'
gem 'spork', '~> 0.9.0.rc' gem 'spork', '~> 0.9.0.rc'
gem 'rb-fsevent', '~> 0.4.3.1'
gem 'guard-rspec', '~> 0.4.5'
gem 'guard-spork', '~> 0.3.0'
end end

19
Gemfile.lock

@ -87,10 +87,17 @@ GEM
factory_girl_rails (1.2.0) factory_girl_rails (1.2.0)
factory_girl (~> 2.1.0) factory_girl (~> 2.1.0)
railties (>= 3.0.0) railties (>= 3.0.0)
faker (1.0.1)
i18n (~> 0.4)
ffi (1.0.9) ffi (1.0.9)
forgery (0.3.12)
nokogiri (~> 1.4)
fssm (0.2.7) fssm (0.2.7)
guard (0.8.4)
thor (~> 0.14.6)
guard-rspec (0.4.5)
guard (>= 0.4.0)
guard-spork (0.3.0)
guard (>= 0.8.2)
spork (>= 0.8.4)
highline (1.6.2) highline (1.6.2)
hike (1.2.1) hike (1.2.1)
i18n (0.6.0) i18n (0.6.0)
@ -148,6 +155,7 @@ GEM
rdoc (~> 3.4) rdoc (~> 3.4)
thor (~> 0.14.6) thor (~> 0.14.6)
rake (0.9.2) rake (0.9.2)
rb-fsevent (0.4.3.1)
rdoc (3.9.4) rdoc (3.9.4)
rspec (2.6.0) rspec (2.6.0)
rspec-core (~> 2.6.0) rspec-core (~> 2.6.0)
@ -181,7 +189,6 @@ GEM
hike (~> 1.2) hike (~> 1.2)
rack (~> 1.0) rack (~> 1.0)
tilt (~> 1.1, != 1.3.0) tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.4)
therubyracer (0.9.8) therubyracer (0.9.8)
libv8 (~> 3.3.10) libv8 (~> 3.3.10)
thor (0.14.6) thor (0.14.6)
@ -211,18 +218,20 @@ DEPENDENCIES
database_cleaner (~> 0.6.7) database_cleaner (~> 0.6.7)
devise (~> 1.4.5) devise (~> 1.4.5)
factory_girl_rails (~> 1.2) factory_girl_rails (~> 1.2)
forgery (~> 0.3.12) faker (~> 1.0.1)
guard-rspec (~> 0.4.5)
guard-spork (~> 0.3.0)
jquery-rails jquery-rails
mysql2 mysql2
nilify_blanks (~> 1.0.0) nilify_blanks (~> 1.0.0)
pjax_rails (~> 0.1.10) pjax_rails (~> 0.1.10)
rails (= 3.1.1.rc1) rails (= 3.1.1.rc1)
rails_config (~> 0.2.4) rails_config (~> 0.2.4)
rb-fsevent (~> 0.4.3.1)
rspec-rails (~> 2.6.1) rspec-rails (~> 2.6.1)
sass-rails (~> 3.1.0) sass-rails (~> 3.1.0)
sentient_user (~> 0.3.2) sentient_user (~> 0.3.2)
spork (~> 0.9.0.rc) spork (~> 0.9.0.rc)
sqlite3
therubyracer therubyracer
uglifier uglifier
validates_hostname (~> 1.0.0)! validates_hostname (~> 1.0.0)!

32
Guardfile

@ -0,0 +1,32 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb')
watch('test/test_helper.rb')
watch(%r{^spec/support/.+\.rb$})
end
guard 'rspec', :version => 2, :cli => '--drb', :all_on_start => false, :all_after_pass => false do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('spec/spec_helper.rb') { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara request specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
end

10
app/controllers/domains_controller.rb

@ -30,4 +30,14 @@ class DomainsController < ApplicationController
@record.reload @record.reload
end end
def before_update_save(record) # just to make sure of params tampering
record.type = 'NATIVE'
end
def after_update_save(record)
if @record.nam_changed?
flash[:warning] = "Changing the name of a domain migrates all it's records to the new name!"
end
end
end end

10
app/models/domain.rb

@ -41,6 +41,16 @@ class Domain < ActiveRecord::Base
a_records.build(:content => ip) if ip.present? a_records.build(:content => ip) if ip.present?
end end
before_validation(:on => :update) do
if name_changed?
soa_record.reset_serial
# soa_record.name = soa_record.name.gsub(/#{name_was}$/, name)
for record in records
record.name = record.name.gsub(/#{name_was}$/, name)
end
end
end
def setup(email) def setup(email)
build_soa_record build_soa_record
soa = soa_record soa = soa_record

18
app/models/soa.rb

@ -20,6 +20,7 @@ class SOA < Record
before_validation :assemble_content before_validation :assemble_content
before_update :update_serial before_update :update_serial
after_initialize :disassemble_content after_initialize :disassemble_content
before_validation do before_validation do
self.primary_ns ||= domain.ns_records.first.content self.primary_ns ||= domain.ns_records.first.content
end end
@ -50,8 +51,12 @@ class SOA < Record
# generation, that gets triggered by updating the change_date # generation, that gets triggered by updating the change_date
def update_serial def update_serial
return if self.content_changed? return if self.content_changed?
date_serial = Time.now.strftime( "%Y%m%d00" ).to_i compute_serial
@serial = (@serial.nil? || date_serial > @serial) ? date_serial : @serial + 1 end
def reset_serial
@serial = nil
compute_serial
end end
# Same as #update_serial and saves the record # Same as #update_serial and saves the record
@ -76,9 +81,12 @@ class SOA < Record
end end
def name_equals_domain_name? def name_equals_domain_name?
unless name == domain.name errors.add :name, "must be equal to domain's name" unless name == domain.name
errors.add :name, "must be equal to domain's name" end
end
def compute_serial
date_serial = Time.now.strftime( "%Y%m%d00" ).to_i
@serial = (@serial.nil? || date_serial > @serial) ? date_serial : @serial + 1
end end
end end

25
config/database.yml.sample → config/database.yml.mysql.sample

@ -1,22 +1,25 @@
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development: development:
adapter: sqlite3 adapter: mysql2
database: db/development.sqlite3 encoding: utf8
reconnect: false
database: entrydns_development
pool: 5 pool: 5
timeout: 5000 username: root
password: root
host: localhost
# Warning: The database defined as "test" will be erased and # Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake". # re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production. # Do not set this db to the same as development or production.
test: test:
adapter: sqlite3 adapter: mysql2
database: db/test.sqlite3 encoding: utf8
reconnect: false
database: entrydns_test
pool: 5 pool: 5
timeout: 5000 username: root
password: root
host: localhost
production: production:
adapter: mysql2 adapter: mysql2

4
db/seeds.rb

@ -1,4 +1,6 @@
user = User.create :email => 'user@app.com', user = User.create(
:email => 'user@app.com',
:password => 'useruser', :password => 'useruser',
:password_confirmation => 'useruser' :password_confirmation => 'useruser'
)
user.confirm! user.confirm!

25
spec/factories.rb

@ -1,12 +1,37 @@
FactoryGirl.define do FactoryGirl.define do
sequence(:email){|n| "#{Faker::Internet.user_name}#{n}@example.com"}
sequence(:password){|n| "password#{n}"}
sequence(:domain_name){|n| "#{n}#{Faker::Internet.domain_name}"}
factory :user do factory :user do
email
password
password_confirmation {password}
end end
factory :domain do factory :domain do
name {FactoryGirl.generate(:domain_name)}
type 'NATIVE'
association :soa_record, :factory => :soa_record, :method => :build
ns_records do |ns_records|
ns1 = ns_records.association(:ns_record, :method => :build)
ns2 = ns_records.association(:ns_record, :method => :build)
ns1.content = Settings.ns.first
ns2.content = (Settings.ns - [ns1.content]).sample
[ns1, ns2]
end
end end
factory :record do factory :record do
end end
factory :soa_record, :class => 'SOA' do
contact {Faker::Internet.email}
end
factory :ns_record, :class => 'NS' do
content {Settings.ns.sample}
end
end end

2
spec/helpers/so_as_helper_spec.rb → spec/helpers/soas_helper_spec.rb

@ -10,6 +10,6 @@ require 'spec_helper'
# end # end
# end # end
# end # end
describe SoAsHelper do describe SoasHelper do
pending "add some examples to (or delete) #{__FILE__}" pending "add some examples to (or delete) #{__FILE__}"
end end

5
spec/models/domain_spec.rb

@ -1,5 +1,8 @@
require 'spec_helper' require 'spec_helper'
describe Domain do describe Domain do
pending "add some examples to (or delete) #{__FILE__}" let(:domain){Factory(:domain)}
it "is" do
domain.should be_valid
end
end end

8
spec/spec_helper.rb

@ -7,12 +7,10 @@ Spork.prefork do
require 'rspec/rails' require 'rspec/rails'
require 'capybara/rspec' require 'capybara/rspec'
RSpec.configure do |config| Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
config.mock_with :rspec Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
config.use_transactional_fixtures = true
end
end end
Spork.each_run do Spork.each_run do
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} FactoryGirl.reload
end end

8
spec/support/rspec.rb

@ -0,0 +1,8 @@
RSpec.configure do |config|
config.mock_with :rspec
config.use_transactional_fixtures = true
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
end
Loading…
Cancel
Save