Browse Source

Merge branch 'permissions'

Conflicts:
	Gemfile.lock
pull/1/head
Nicolae Claudius 13 years ago
parent
commit
869f68a9b9
  1. 5
      .gitignore
  2. 4
      Gemfile
  3. 45
      Gemfile.lock
  4. 5
      app/assets/stylesheets/overrides.css.erb
  5. 20
      app/controllers/aaaas_controller.rb
  6. 22
      app/controllers/as_controller.rb
  7. 17
      app/controllers/cnames_controller.rb
  8. 12
      app/controllers/domains_controller.rb
  9. 21
      app/controllers/mxes_controller.rb
  10. 23
      app/controllers/ns_controller.rb
  11. 9
      app/controllers/pages_controller.rb
  12. 21
      app/controllers/permissions_controller.rb
  13. 19
      app/controllers/records_controller.rb
  14. 25
      app/controllers/records_controller_common.rb
  15. 20
      app/controllers/soas_controller.rb
  16. 20
      app/controllers/srvs_controller.rb
  17. 20
      app/controllers/txts_controller.rb
  18. 2
      app/helpers/permissions_helper.rb
  19. 12
      app/models/ability.rb
  20. 48
      app/models/domain.rb
  21. 32
      app/models/permission.rb
  22. 5
      app/models/record.rb
  23. 5
      app/models/soa.rb
  24. 1
      app/models/tld.rb
  25. 16
      app/models/user.rb
  26. 4
      app/views/domains/_list_record_columns.html.erb
  27. 114
      config/initializers/cancan.rb
  28. 12
      config/initializers/squeel.rb
  29. 4
      config/routes.rb
  30. 12
      db/migrate/20111129180907_create_permissions.rb
  31. 15
      db/migrate/20120112175527_add_name_reversed_to_domains.rb
  32. 31
      db/migrate/20120115174339_add_userstamps_to_models.rb
  33. 23
      spec/controllers/aaaas_controller_spec.rb
  34. 23
      spec/controllers/as_controller_spec.rb
  35. 23
      spec/controllers/cnames_controller_spec.rb
  36. 5
      spec/controllers/dashboard_controller_spec.rb
  37. 57
      spec/controllers/domains_controller_spec.rb
  38. 37
      spec/controllers/hosts_controller_spec.rb
  39. 23
      spec/controllers/mxes_controller_spec.rb
  40. 23
      spec/controllers/ns_controller_spec.rb
  41. 5
      spec/controllers/pages_controller_spec.rb
  42. 41
      spec/controllers/records_controller_spec.rb
  43. 23
      spec/controllers/soas_controller_spec.rb
  44. 23
      spec/controllers/srvs_controller_spec.rb
  45. 23
      spec/controllers/txts_controller_spec.rb
  46. 6
      spec/factories.rb
  47. 15
      spec/helpers/aaaas_helper_spec.rb
  48. 15
      spec/helpers/as_helper_spec.rb
  49. 15
      spec/helpers/cnames_helper_spec.rb
  50. 15
      spec/helpers/dashboard_helper_spec.rb
  51. 15
      spec/helpers/domains_helper_spec.rb
  52. 15
      spec/helpers/hosts_helper_spec.rb
  53. 15
      spec/helpers/mxes_helper_spec.rb
  54. 15
      spec/helpers/ns_helper_spec.rb
  55. 15
      spec/helpers/pages_helper_spec.rb
  56. 15
      spec/helpers/records_helper_spec.rb
  57. 15
      spec/helpers/soas_helper_spec.rb
  58. 15
      spec/helpers/srvs_helper_spec.rb
  59. 15
      spec/helpers/txts_helper_spec.rb
  60. 62
      spec/models/ability_spec.rb
  61. 26
      spec/models/domain_spec.rb
  62. 15
      spec/models/permission_spec.rb
  63. 28
      spec/models/record_spec.rb
  64. 5
      spec/models/user_spec.rb
  65. 11
      spec/requests/aaaas_spec.rb
  66. 11
      spec/requests/as_spec.rb
  67. 11
      spec/requests/cnames_spec.rb
  68. 11
      spec/requests/domains_spec.rb
  69. 11
      spec/requests/hosts_spec.rb
  70. 11
      spec/requests/mxes_spec.rb
  71. 11
      spec/requests/ns_spec.rb
  72. 11
      spec/requests/records_spec.rb
  73. 11
      spec/requests/soas_spec.rb
  74. 11
      spec/requests/srvs_spec.rb
  75. 11
      spec/requests/txts_spec.rb
  76. 35
      spec/routing/permissions_routing_spec.rb
  77. 2
      spec/spec_helper.rb
  78. 2
      spec/support/rspec.rb
  79. 53
      spec/support/shared_context/data.rb
  80. 40
      spec/support/shared_examples/wiring_controller.rb
  81. 15
      spec/views/aaaas/edit.html.erb_spec.rb
  82. 14
      spec/views/aaaas/index.html.erb_spec.rb
  83. 15
      spec/views/aaaas/new.html.erb_spec.rb
  84. 11
      spec/views/aaaas/show.html.erb_spec.rb
  85. 15
      spec/views/as/edit.html.erb_spec.rb
  86. 14
      spec/views/as/index.html.erb_spec.rb
  87. 15
      spec/views/as/new.html.erb_spec.rb
  88. 11
      spec/views/as/show.html.erb_spec.rb
  89. 15
      spec/views/cnames/edit.html.erb_spec.rb
  90. 14
      spec/views/cnames/index.html.erb_spec.rb
  91. 15
      spec/views/cnames/new.html.erb_spec.rb
  92. 11
      spec/views/cnames/show.html.erb_spec.rb
  93. 15
      spec/views/domains/edit.html.erb_spec.rb
  94. 14
      spec/views/domains/index.html.erb_spec.rb
  95. 15
      spec/views/domains/new.html.erb_spec.rb
  96. 11
      spec/views/domains/show.html.erb_spec.rb
  97. 15
      spec/views/hosts/edit.html.erb_spec.rb
  98. 14
      spec/views/hosts/index.html.erb_spec.rb
  99. 15
      spec/views/hosts/new.html.erb_spec.rb
  100. 11
      spec/views/hosts/show.html.erb_spec.rb
  101. Some files were not shown because too many files have changed in this diff Show More

5
.gitignore vendored

@ -11,3 +11,8 @@ config/settings/*.local.yml
config/environments/*.local.yml config/environments/*.local.yml
config/settings.yml config/settings.yml
public/assets public/assets
spec/.views/
spec/.requests/
spec/.controllers/
spec/.helpers/
coverage

4
Gemfile

@ -9,8 +9,9 @@ gem 'rails', '3.1.1'
gem 'mysql2' gem 'mysql2'
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 'squeel', '~> 0.9.3'
gem 'sentient_user', '~> 0.3.2' gem 'sentient_user', '~> 0.3.2'
gem 'userstamp_basic', '~> 0.1.0'
gem 'active_scaffold', '~> 3.1.0', :git => 'https://github.com/activescaffold/active_scaffold.git' # :path => '/home/clyfe/dev/active_scaffold' gem 'active_scaffold', '~> 3.1.0', :git => 'https://github.com/activescaffold/active_scaffold.git' # :path => '/home/clyfe/dev/active_scaffold'
gem 'pjax_rails', '~> 0.1.10' gem 'pjax_rails', '~> 0.1.10'
gem 'validates_hostname', '~> 1.0.0', :git => 'https://github.com/KimNorgaard/validates_hostname.git' gem 'validates_hostname', '~> 1.0.0', :git => 'https://github.com/KimNorgaard/validates_hostname.git'
@ -46,6 +47,7 @@ end
group :test do group :test do
gem 'capybara', '~> 1.1.1' gem 'capybara', '~> 1.1.1'
gem 'database_cleaner', '~> 0.6.7' gem 'database_cleaner', '~> 0.6.7'
gem 'simplecov', :require => false
gem 'spork', '~> 0.9.0.rc' gem 'spork', '~> 0.9.0.rc'
gem 'rb-fsevent', '~> 0.4.3.1' gem 'rb-fsevent', '~> 0.4.3.1'
gem 'rb-inotify', '~> 0.8.8' gem 'rb-inotify', '~> 0.8.8'

45
Gemfile.lock

@ -6,9 +6,9 @@ GIT
GIT GIT
remote: https://github.com/activescaffold/active_scaffold.git remote: https://github.com/activescaffold/active_scaffold.git
revision: c2380071424210e6704fc278c677ae340caf8311 revision: 07cfb68c2d51e4372e94322afb55262aed394211
specs: specs:
active_scaffold (3.1.13) active_scaffold (3.1.15)
rails (~> 3.1.0) rails (~> 3.1.0)
GEM GEM
@ -62,7 +62,7 @@ GEM
rack-test (>= 0.5.4) rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0) selenium-webdriver (~> 2.0)
xpath (~> 0.1.4) xpath (~> 0.1.4)
childprocess (0.2.4) childprocess (0.3.0)
ffi (~> 1.0.6) ffi (~> 1.0.6)
chunky_png (1.2.5) chunky_png (1.2.5)
coffee-rails (3.1.1) coffee-rails (3.1.1)
@ -72,7 +72,7 @@ GEM
coffee-script-source coffee-script-source
execjs execjs
coffee-script-source (1.2.0) coffee-script-source (1.2.0)
compass (0.12.alpha.3) compass (0.12.alpha.4)
chunky_png (~> 1.2) chunky_png (~> 1.2)
fssm (>= 0.2.7) fssm (>= 0.2.7)
sass (~> 3.1) sass (~> 3.1)
@ -85,17 +85,17 @@ GEM
warden (~> 1.0.3) warden (~> 1.0.3)
diff-lcs (1.1.3) diff-lcs (1.1.3)
erubis (2.7.0) erubis (2.7.0)
execjs (1.2.13) execjs (1.3.0)
multi_json (~> 1.0) multi_json (~> 1.0)
factory_girl (2.3.2) factory_girl (2.4.2)
activesupport activesupport
factory_girl_rails (1.4.0) factory_girl_rails (1.5.0)
factory_girl (~> 2.3.0) factory_girl (~> 2.4.0)
railties (>= 3.0.0) railties (>= 3.0.0)
faker (1.0.1) faker (1.0.1)
i18n (~> 0.4) i18n (~> 0.4)
ffi (1.0.11) ffi (1.0.11)
fssm (0.2.7) fssm (0.2.8.1)
gem_plugin (0.2.3) gem_plugin (0.2.3)
guard (0.10.0) guard (0.10.0)
ffi (>= 0.5.0) ffi (>= 0.5.0)
@ -111,7 +111,7 @@ GEM
jquery-rails (1.0.19) jquery-rails (1.0.19)
railties (~> 3.0) railties (~> 3.0)
thor (~> 0.14) thor (~> 0.14)
json (1.6.4) json (1.6.5)
libnotify (0.5.9) libnotify (0.5.9)
libv8 (3.3.10.4) libv8 (3.3.10.4)
mail (2.3.0) mail (2.3.0)
@ -129,16 +129,18 @@ GEM
net-ssh (>= 1.99.1) net-ssh (>= 1.99.1)
net-sftp (2.0.5) net-sftp (2.0.5)
net-ssh (>= 2.0.9) net-ssh (>= 2.0.9)
net-ssh (2.2.1) net-ssh (2.3.0)
net-ssh-gateway (1.1.0) net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1) net-ssh (>= 1.99.1)
nilify_blanks (1.0.0) nilify_blanks (1.0.0)
activerecord (>= 3.0.0) activerecord (>= 3.0.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
nokogiri (1.5.0) nokogiri (1.5.0)
orm_adapter (0.0.5) orm_adapter (0.0.6)
pjax_rails (0.1.10) pjax_rails (0.1.10)
jquery-rails jquery-rails
polyamorous (0.5.0)
activerecord (~> 3.0)
polyglot (0.3.3) polyglot (0.3.3)
rack (1.3.6) rack (1.3.6)
rack-cache (1.1) rack-cache (1.1)
@ -192,17 +194,25 @@ GEM
railties (~> 3.1.0) railties (~> 3.1.0)
sass (~> 3.1.10) sass (~> 3.1.10)
tilt (~> 1.3.2) tilt (~> 1.3.2)
selenium-webdriver (2.15.0) selenium-webdriver (2.17.0)
childprocess (>= 0.2.1) childprocess (>= 0.2.5)
ffi (~> 1.0.9) ffi (~> 1.0.9)
multi_json (~> 1.0.4) multi_json (~> 1.0.4)
rubyzip rubyzip
sentient_user (0.3.2) sentient_user (0.3.2)
simplecov (0.5.4)
multi_json (~> 1.0.3)
simplecov-html (~> 0.5.3)
simplecov-html (0.5.3)
spork (0.9.0.rc9) spork (0.9.0.rc9)
sprockets (2.0.3) sprockets (2.0.3)
hike (~> 1.2) hike (~> 1.2)
rack (~> 1.0) rack (~> 1.0)
tilt (!= 1.3.0, ~> 1.1) tilt (!= 1.3.0, ~> 1.1)
squeel (0.9.3)
activerecord (~> 3.0)
activesupport (~> 3.0)
polyamorous (~> 0.5.0)
therubyracer (0.9.9) therubyracer (0.9.9)
libv8 (~> 3.3.10) libv8 (~> 3.3.10)
thor (0.14.6) thor (0.14.6)
@ -211,9 +221,11 @@ GEM
polyglot polyglot
polyglot (>= 0.3.1) polyglot (>= 0.3.1)
tzinfo (0.3.31) tzinfo (0.3.31)
uglifier (1.2.1) uglifier (1.2.2)
execjs (>= 0.3.0) execjs (>= 0.3.0)
multi_json (>= 1.0.2) multi_json (>= 1.0.2)
userstamp_basic (0.1.0)
sentient_user (>= 0.1.0)
warden (1.0.6) warden (1.0.6)
rack (>= 1.0) rack (>= 1.0)
xpath (0.1.4) xpath (0.1.4)
@ -251,7 +263,10 @@ DEPENDENCIES
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)
simplecov
spork (~> 0.9.0.rc) spork (~> 0.9.0.rc)
squeel (~> 0.9.3)
therubyracer therubyracer
uglifier uglifier
userstamp_basic (~> 0.1.0)
validates_hostname (~> 1.0.0)! validates_hostname (~> 1.0.0)!

5
app/assets/stylesheets/overrides.css.erb

@ -14,6 +14,11 @@
text-shadow: none; text-shadow: none;
} }
#main .block .content .active-scaffold th p {
font: bold 11px arial, sans-serif;
text-shadow: none;
}
body.errors #main .inner { body.errors #main .inner {
margin-top: 15px; margin-top: 15px;
} }

20
app/controllers/aaaas_controller.rb

@ -9,28 +9,20 @@ class AaaasController < ApplicationController
conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}} conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}}
conf.actions.exclude :show conf.actions.exclude :show
end end
before_filter :ensure_nested_under_domain include RecordsControllerCommon
protected protected
# override to use :mx_records instead of :records assoc # override to use :mx_records instead of :records assoc
def beginning_of_chain def beginning_of_chain
if nested? && nested.association && nested.association.collection? && nested.association.name == :records nested_via_records? ? nested.parent_scope.aaaa_records : super
nested.parent_scope.aaaa_records
else
super
end
end end
# override, we make our own sti logic # override, we make our own sti logic
def new_model def new_model
model = beginning_of_chain.new record = beginning_of_chain.new
model.name = nested_parent_record.name record.name = nested_parent_record.name
model before_create_save(record)
end record
# override to close create form after success
def render_parent?
nested_singular_association? # || params[:parent_sti]
end end
end end

22
app/controllers/as_controller.rb

@ -9,29 +9,21 @@ class AsController < ApplicationController
conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}} conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}}
conf.actions.exclude :show conf.actions.exclude :show
end end
before_filter :ensure_nested_under_domain include RecordsControllerCommon
protected protected
# override to use :mx_records instead of :records assoc # override to use :mx_records instead of :records assoc
def beginning_of_chain def beginning_of_chain
if nested? && nested.association && nested.association.collection? && nested.association.name == :records nested_via_records? ? nested.parent_scope.a_records : super
nested.parent_scope.a_records
else
super
end
end end
# override, we make our own sti logic # override, we make our own sti logic
def new_model def new_model
model = beginning_of_chain.new record = beginning_of_chain.new
model.name = nested_parent_record.name record.name = nested_parent_record.name
model.content = client_remote_ip if client_remote_ip.present? record.content = client_remote_ip if client_remote_ip.present?
model before_create_save(record)
end record
# override to close create form after success
def render_parent?
nested_singular_association? # || params[:parent_sti]
end end
end end

17
app/controllers/cnames_controller.rb

@ -10,27 +10,20 @@ class CnamesController < ApplicationController
conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}} conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}}
conf.actions.exclude :show conf.actions.exclude :show
end end
before_filter :ensure_nested_under_domain include RecordsControllerCommon
protected protected
# override to use :mx_records instead of :records assoc # override to use :mx_records instead of :records assoc
def beginning_of_chain def beginning_of_chain
if nested? && nested.association && nested.association.collection? && nested.association.name == :records nested_via_records? ? nested.parent_scope.cname_records : super
nested.parent_scope.cname_records
else
super
end
end end
# override, we make our own sti logic # override, we make our own sti logic
def new_model def new_model
model = beginning_of_chain.new record = beginning_of_chain.new
model before_create_save(record)
record
end end
# override to close create form after success
def render_parent?
nested_singular_association? # || params[:parent_sti]
end
end end

12
app/controllers/domains_controller.rb

@ -2,15 +2,16 @@ class DomainsController < ApplicationController
active_scaffold :domain do |conf| active_scaffold :domain do |conf|
conf.columns = [:name, :ip, :records, :soa_record, :ns_records] conf.columns = [:name, :ip, :records, :soa_record, :ns_records]
conf.list.columns = [:name, :records] conf.list.columns = [:name, :records, :permissions]
conf.create.columns = [:name, :ip, :soa_record, :ns_records] conf.create.columns = [:name, :ip, :soa_record, :ns_records]
conf.update.columns = [:name, :soa_record] conf.update.columns = [:name, :soa_record]
conf.columns[:name].description = 'Ex. "domain.com"' conf.columns[:name].description = 'Ex. "domain.com"'
conf.columns[:ip].description = 'Ex. "10.10.5.12", optional IP to associate your domain with' conf.columns[:ip].description = 'Ex. "10.10.5.12", optional IP to associate your domain with'
conf.columns[:ns_records].show_blank_record = false conf.columns[:ns_records].show_blank_record = false
conf.columns[:permissions].label = 'Sharing'
conf.actions.exclude :show conf.actions.exclude :show
conf.list.sorting = {:name => :asc} conf.list.sorting = {:name => :asc}
conf.create.link.label = "Add Domain" conf.create.link.label = 'Add Domain'
# conf.columns[:records].label = 'All Records' # conf.columns[:records].label = 'All Records'
end end
@ -22,8 +23,15 @@ class DomainsController < ApplicationController
@record.setup(current_user.email) @record.setup(current_user.email)
end end
def new_model
record = super
before_create_save(record)
record
end
def before_create_save(record) def before_create_save(record)
record.type = 'NATIVE' record.type = 'NATIVE'
record.user = record.parent_domain.present? ? record.parent_domain.user : current_user
end end
def after_create_save(record) def after_create_save(record)

21
app/controllers/mxes_controller.rb

@ -9,7 +9,7 @@ class MxesController < ApplicationController
conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}} conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}}
conf.actions.exclude :show conf.actions.exclude :show
end end
before_filter :ensure_nested_under_domain include RecordsControllerCommon
protected protected
@ -23,23 +23,14 @@ class MxesController < ApplicationController
# override to use :mx_records instead of :records assoc # override to use :mx_records instead of :records assoc
def beginning_of_chain def beginning_of_chain
if nested? && nested.association && nested.association.collection? && nested.association.name == :records nested_via_records? ? nested.parent_scope.mx_records : super
nested.parent_scope.mx_records
else
super
end
end end
# override, we make our own sti logic # override, we make our own sti logic
def new_model def new_model
model = beginning_of_chain.new record = beginning_of_chain.new
model.name = nested_parent_record.name record.name = nested_parent_record.name
model before_create_save(record)
record
end end
# override to close create form after success
def render_parent?
nested_singular_association? # || params[:parent_sti]
end
end end

23
app/controllers/ns_controller.rb

@ -9,30 +9,22 @@ class NsController < ApplicationController
conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}} conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}}
conf.actions.exclude :show conf.actions.exclude :show
end end
before_filter :ensure_nested_under_domain include RecordsControllerCommon
protected protected
# override to use :mx_records instead of :records assoc # override to use :mx_records instead of :records assoc
def beginning_of_chain def beginning_of_chain
if nested? && nested.association && nested.association.collection? && nested.association.name == :records nested_via_records? ? nested.parent_scope.ns_records : super
nested.parent_scope.ns_records
else
super
end
end end
# override, we make our own sti logic # override, we make our own sti logic
def new_model def new_model
model = beginning_of_chain.new record = beginning_of_chain.new
model.name = nested_parent_record.name record.name = nested_parent_record.name
model.content = Settings.ns.sample record.content = Settings.ns.sample
model before_create_save(record)
end record
# override to close create form after success
def render_parent?
nested_singular_association? # || params[:parent_sti]
end end
def after_update_save(record) def after_update_save(record)
@ -49,5 +41,4 @@ class NsController < ApplicationController
flash[:warning] = "All NS records deleted, no other nameservers are associated with this domain!" flash[:warning] = "All NS records deleted, no other nameservers are associated with this domain!"
end end
end end
end end

9
app/controllers/pages_controller.rb

@ -1,13 +1,8 @@
class PagesController < ApplicationController class PagesController < ApplicationController
skip_before_filter :authenticate_user! skip_before_filter :authenticate_user!
layout proc{|controller| layout proc{|controller|
if request.xhr? return false if request.xhr?
false user_signed_in? ? 'application' : 'public'
elsif user_signed_in?
'application'
else
'public'
end
} }
rescue_from ActionView::MissingTemplate do |exception| rescue_from ActionView::MissingTemplate do |exception|

21
app/controllers/permissions_controller.rb

@ -0,0 +1,21 @@
class PermissionsController < ApplicationController
active_scaffold :permission do |conf|
conf.actions.exclude :show, :search
conf.columns = [:domain, :user, :user_email]
conf.list.columns = [:domain, :user, :user_email]
conf.create.columns = [:domain, :user_email]
conf.update.columns = [:domain, :user_email]
conf.columns[:user_email].form_ui = :virtual
conf.columns[:user_email].description = 'user\'s email address, to share with. Ex. jhon.doe@domain.com'
conf.create.link.label = 'Share Domain'
# conf.columns[:user_email].search_sql = 'user.email'
# conf.columns[:user].search_sql = 'CONCAT(first_name, ' ', last_name)'
end
before_filter :ensure_nested_under_domain
protected
def beginning_of_chain
super.readonly(false)
end
end

19
app/controllers/records_controller.rb

@ -26,7 +26,8 @@ class RecordsController < ApplicationController
# conf.create.link.label = "Add Record" # conf.create.link.label = "Add Record"
conf.actions.exclude :show conf.actions.exclude :show
end end
before_filter :ensure_nested_under_domain, :except => 'modify' include RecordsControllerCommon
skip_before_filter :ensure_nested_under_domain, :only => 'modify'
skip_before_filter :authenticate_user!, :only => 'modify' skip_before_filter :authenticate_user!, :only => 'modify'
protect_from_forgery :except => 'modify' protect_from_forgery :except => 'modify'
skip_authorize_resource :only => :modify skip_authorize_resource :only => :modify
@ -37,15 +38,19 @@ class RecordsController < ApplicationController
# TODO: externalize # TODO: externalize
def modify def modify
@record = Record.where(:authentication_token => params[:authentication_token]).first! @record = Record.where(:authentication_token => params[:authentication_token]).first!
if @record.type != 'A' return render(:text => MODIFY_ERROR) if @record.type != 'A'
return render :text => MODIFY_ERROR
end
@record.content = params[:ip] || client_remote_ip @record.content = params[:ip] || client_remote_ip
@record.save! @record.save!
respond_with(@record) do |format| respond_with(@record) do |format|
format.html { format.html {render(:text => MODIFY_OK)}
render :text => MODIFY_OK end
}
end end
protected
def new_model
record = super
before_create_save(record)
record
end end
end end

25
app/controllers/records_controller_common.rb

@ -0,0 +1,25 @@
# some common bits of code for records related controllers
module RecordsControllerCommon
extend ActiveSupport::Concern
included do
before_filter :ensure_nested_under_domain
end
protected
def before_create_save(record)
record.domain = nested_parent_record
record.user = record.domain_user
end
def nested_via_records?
nested? && nested.association && nested.association.collection? && nested.association.name == :records
end
# override to close create form after success
# RecordsController is the only one that does not really need this
def render_parent?
nested_singular_association? # || params[:parent_sti]
end
end

20
app/controllers/soas_controller.rb

@ -7,30 +7,22 @@ class SoasController < ApplicationController
conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}} conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}}
conf.actions.exclude :delete, :show conf.actions.exclude :delete, :show
end end
before_filter :ensure_nested_under_domain include RecordsControllerCommon
protected protected
# override to use :mx_records instead of :records assoc
def beginning_of_chain def beginning_of_chain
super.readonly(false) (nested_via_records? ? nested.parent_scope.soa_records : super).readonly(false)
end end
# override, we make our own sti logic # override, we make our own sti logic
def new_model def new_model
model = beginning_of_chain record = beginning_of_chain.new
model.new before_create_save(record)
end record
# override to close create form after success
def render_parent?
nested_singular_association? # || params[:parent_sti]
end end
def after_update_save(record) def after_update_save(record)
unless @record.domain.ns_records.any? {|ns_record| @record.primary_ns == ns_record.content} flash.now[:warning] = "SOA record's primary NS is no longer among this domain's NS records" unless record.ns?
flash.now[:warning] = "SOA record's primary NS is no longer among this domain's NS records"
end end
end end
end

20
app/controllers/srvs_controller.rb

@ -9,7 +9,7 @@ class SrvsController < ApplicationController
conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}} conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}}
conf.actions.exclude :show conf.actions.exclude :show
end end
before_filter :ensure_nested_under_domain include RecordsControllerCommon
protected protected
@ -20,23 +20,15 @@ class SrvsController < ApplicationController
# override to use :mx_records instead of :records assoc # override to use :mx_records instead of :records assoc
def beginning_of_chain def beginning_of_chain
if nested? && nested.association && nested.association.collection? && nested.association.name == :records nested_via_records? ? nested.parent_scope.srv_records : super
nested.parent_scope.srv_records
else
super
end
end end
# override, we make our own sti logic # override, we make our own sti logic
def new_model def new_model
model = beginning_of_chain.new record = beginning_of_chain.new
model.name = nested_parent_record.name record.name = nested_parent_record.name
model before_create_save(record)
end record
# override to close create form after success
def render_parent?
nested_singular_association? # || params[:parent_sti]
end end
end end

20
app/controllers/txts_controller.rb

@ -9,28 +9,20 @@ class TxtsController < ApplicationController
conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}} conf.columns[:ttl].options = {:i18n_number => {:delimiter => ''}}
conf.actions.exclude :show conf.actions.exclude :show
end end
before_filter :ensure_nested_under_domain include RecordsControllerCommon
protected protected
# override to use :mx_records instead of :records assoc # override to use :mx_records instead of :records assoc
def beginning_of_chain def beginning_of_chain
if nested? && nested.association && nested.association.collection? && nested.association.name == :records nested_via_records? ? nested.parent_scope.txt_records : super
nested.parent_scope.txt_records
else
super
end
end end
# override, we make our own sti logic # override, we make our own sti logic
def new_model def new_model
model = beginning_of_chain.new record = beginning_of_chain.new
model.name = nested_parent_record.name record.name = nested_parent_record.name
model before_create_save(record)
end record
# override to close create form after success
def render_parent?
nested_singular_association? # || params[:parent_sti]
end end
end end

2
app/helpers/permissions_helper.rb

@ -0,0 +1,2 @@
module PermissionsHelper
end

12
app/models/ability.rb

@ -17,6 +17,18 @@ class Ability
# can manage his hosts # can manage his hosts
can :manage, A, :user_id => user.id #, :domain => {:name => Settings.host_domains} can :manage, A, :user_id => user.id #, :domain => {:name => Settings.host_domains}
# can manage permissions for his domains
can :manage, Permission, :domain => {:user_id => user.id}
# can manage shared domains and records
can :manage, Domain, :permissions.outer => {:user_id => user.id}
can :manage, Record, :domain => {:permissions.outer => {:user_id => user.id}}
# can manage shared domains and records descendants
for domain in user.permitted_domains
can :manage, Domain, :name_reversed.matches => "#{domain.name_reversed}.%" # descendants
can :manage, Record, :domain => {:name_reversed.matches => "#{domain.name_reversed}.%"} # descendant's
end
end end
# See the wiki for details: https://github.com/ryanb/cancan/wiki/Defining-Abilities # See the wiki for details: https://github.com/ryanb/cancan/wiki/Defining-Abilities

48
app/models/domain.rb

@ -1,14 +1,15 @@
require 'resolv'
class Domain < ActiveRecord::Base class Domain < ActiveRecord::Base
set_inheritance_column "sti_disabled" set_inheritance_column "sti_disabled"
nilify_blanks nilify_blanks
stampable
# optional IP for create form, results in a type A record # optional IP for create form, results in a type A record
attr_accessor :ip attr_accessor :ip
belongs_to :user, :inverse_of => :domain belongs_to :user, :inverse_of => :domain
has_many :records, :inverse_of => :domain, :dependent => :destroy has_many :records, :inverse_of => :domain, :dependent => :destroy
has_many :permissions, :inverse_of => :domain, :dependent => :destroy
has_many :permitted_users, :through => :permissions, :source => :user
cattr_reader :types cattr_reader :types
@@types = ['NATIVE', 'MASTER', 'SLAVE', 'SUPERSLAVE'] @@types = ['NATIVE', 'MASTER', 'SLAVE', 'SUPERSLAVE']
@ -50,15 +51,31 @@ class Domain < ActiveRecord::Base
# non-TLD validation # non-TLD validation
errors[:name] = "cannot be a TLD or a reserved domain" if Tld.include?(name) errors[:name] = "cannot be a TLD or a reserved domain" if Tld.include?(name)
# if parent domain is on our system, the user must own it # If parent domain is on our system, the user be permitted to manage current domain.
# He either owns parent, or is permitted to current domain or to an ancestor.
if parent_domain.present? && can_be_managed_by_current_user?
errors[:name] = "issue, the parent domain `#{parent_domain.name}` is registered to another user"
end
end
def parent_domain
return nil if name.nil?
@parent_domain ||= {}
@parent_domain[name] ||= begin
segments = name.split('.') segments = name.split('.')
if segments.size >= 2 if segments.size >= 2
parent = segments[1..-1].join('.') domain_name = segments[1..-1].join('.')
parent_domain = Domain.find_by_name(parent) Domain.find_by_name(domain_name)
if parent_domain.present? && parent_domain.user_id != user_id else
errors[:name] = "issue, the parent domain `#{parent}` is registered to another user" nil
end
end end
end end
# If current user present authorize it
# If current user not present, just allow (rake tasks etc)
def can_be_managed_by_current_user?
User.current.present? ? User.current.can?(:manage, self) : true
end end
def slave?; self.type == 'SLAVE' end def slave?; self.type == 'SLAVE' end
@ -67,6 +84,10 @@ class Domain < ActiveRecord::Base
a_records.build(:content => ip) if ip.present? a_records.build(:content => ip) if ip.present?
end end
before_save do
self.name_reversed = name.reverse if name_changed?
end
before_validation(:on => :update) do before_validation(:on => :update) do
if name_changed? if name_changed?
name_was_pattern = /#{Regexp.escape(name_was)}$/ name_was_pattern = /#{Regexp.escape(name_was)}$/
@ -104,6 +125,19 @@ class Domain < ActiveRecord::Base
scope :host_domains, where(:name => Settings.host_domains) scope :host_domains, where(:name => Settings.host_domains)
def subdomains
Domain.where(:name_reversed.matches => "#{name_reversed}.%")
end
def host_domain?
Settings.host_domains.include?(name)
end
# domain.has_ns?('129.168.0.1')
def has_ns?(ns)
ns_records.any? {|ns_record| ns_record.content == ns}
end
def setup(email) def setup(email)
build_soa_record build_soa_record
soa = soa_record soa = soa_record

32
app/models/permission.rb

@ -0,0 +1,32 @@
class Permission < ActiveRecord::Base
stampable
belongs_to :domain, :inverse_of => :permissions
belongs_to :user, :inverse_of => :permissions
validates :domain_id, :presence => true
validates :user_id, :presence => true, :uniqueness => {
:scope => :domain_id,
:message => "already is permitted"
}
validates :user, :presence => {
:if => lambda {@user_email.present?},
:message => "with given email was not found"
}
validate do
errors[:user] = 'cannot be yourself' if user_id == domain.user_id
end
def user_email
@user_email || user.try(:email)
end
def user_email=(email)
@user_email = email
self.user = User.find_by_email(email)
end
def to_label
user.try(:email) || @user_email || '-'
end
end

5
app/models/record.rb

@ -1,4 +1,6 @@
class Record < ActiveRecord::Base class Record < ActiveRecord::Base
stampable
belongs_to :domain, :inverse_of => :records belongs_to :domain, :inverse_of => :records
belongs_to :user, :inverse_of => :records belongs_to :user, :inverse_of => :records
@ -50,6 +52,9 @@ class Record < ActiveRecord::Base
end end
end end
delegate :host_domain?, :to => :domain
delegate :user, :to => :domain, :prefix => :domain
protected protected
def prepare_name! def prepare_name!

5
app/models/soa.rb

@ -64,6 +64,11 @@ class SOA < Record
save save
end end
# if SOA record's primary NS is among it's domain's NS records
def ns?
domain.has_ns?(primary_ns)
end
def to_label; "#{primary_ns} #{contact}" end def to_label; "#{primary_ns} #{contact}" end
private private

1
app/models/tld.rb

@ -23,4 +23,3 @@ class Tld
end end
end end

16
app/models/user.rb

@ -1,5 +1,7 @@
class User < ActiveRecord::Base class User < ActiveRecord::Base
include SentientUser include SentientUser
stampable
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :timeoutable and :omniauthable # :token_authenticatable, :encryptable, :timeoutable and :omniauthable
devise :database_authenticatable, devise :database_authenticatable,
@ -18,9 +20,23 @@ class User < ActiveRecord::Base
has_many :domains, :inverse_of => :user, :dependent => :destroy has_many :domains, :inverse_of => :user, :dependent => :destroy
has_many :records, :inverse_of => :user, :dependent => :destroy has_many :records, :inverse_of => :user, :dependent => :destroy
has_many :permissions, :inverse_of => :user, :dependent => :destroy
has_many :permitted_domains, :through => :permissions, :source => :domain
def name def name
"#{first_name} #{last_name}" "#{first_name} #{last_name}"
end end
delegate :can?, :cannot?, :to => :ability
def ability(options = {:reload => false})
options[:reload] ? _ability : (@ability ||= _ability)
end
protected
def _ability
Ability.new(:user => self)
end
end end

4
app/views/domains/_list_record_columns.html.erb

@ -9,9 +9,9 @@
<% column_value = 'Manage All Records (0)' if column_value == '-' %> <% column_value = 'Manage All Records (0)' if column_value == '-' %>
<%= authorized ? render_list_column(column_value, column, record) : column_value %> <%= authorized ? render_list_column(column_value, column, record) : column_value %>
</td> </td>
<% elsif column.name == :ns_records %> <% elsif column.name == :permissions %>
<td class="<%= column_class(column, column_value, record) %>" > <td class="<%= column_class(column, column_value, record) %>" >
<% column_value = 'Manage NS Records (0)' if column_value == '-' %> <% column_value = 'Permissions (0)' if column_value == '-' %>
<%= authorized ? render_list_column(column_value, column, record) : column_value %> <%= authorized ? render_list_column(column_value, column, record) : column_value %>
</td> </td>
<% else %> <% else %>

114
config/initializers/cancan.rb

@ -0,0 +1,114 @@
# https://gist.github.com/1523940
module CanCan
module ModelAdapters
class ActiveRecordAdapter < AbstractAdapter
def self.override_condition_matching?(subject, name, value)
name.kind_of?(Squeel::Nodes::Predicate) if defined? Squeel
end
def self.matches_condition?(subject, name, value)
subject_value = subject.send(name.expr)
method_name = name.method_name.to_s
if method_name.ends_with? "_any"
value.any? { |v| squeel_match? subject_value, method_name.sub("_any", ""), v }
elsif method_name.ends_with? "_all"
value.all? { |v| squeel_match? subject_value, method_name.sub("_all", ""), v }
else
squeel_match? subject_value, name.method_name, value
end
end
def self.squeel_match?(subject_value, method, value)
case method.to_sym
when :eq then subject_value == value
when :not_eq then subject_value != value
when :in then value.include?(subject_value)
when :not_in then !value.include?(subject_value)
when :lt then subject_value < value
when :lteq then subject_value <= value
when :gt then subject_value > value
when :gteq then subject_value >= value
when :matches then subject_value =~ Regexp.new("^" + Regexp.escape(value).gsub("%", ".*") + "$", true)
when :does_not_match then !squeel_match?(subject_value, :matches, value)
else raise NotImplemented, "The #{method} Squeel condition is not supported."
end
end
def tableized_conditions(conditions, model_class = @model_class)
return conditions unless conditions.kind_of? Hash
conditions.inject({}) do |result_hash, (name, value)|
name_sym = case name
when Symbol then name
when Squeel::Nodes::Join then name._name
when Squeel::Nodes::Predicate then name.expr
else raise name
end
if value.kind_of? Hash
reflection = model_class.reflect_on_association(name_sym)
association_class = reflection.class_name.constantize
name_sym = reflection.table_name.to_sym
value = tableized_conditions(value, association_class)
end
result_hash[name_sym] = value
result_hash
end
end
private
# override to fix overwrites
# do not write existing hashes using empty hashes
def merge_joins(base, add)
add.each do |name, nested|
if base[name].is_a?(Hash) && nested.present?
merge_joins(base[name], nested)
elsif !base[name].is_a?(Hash) || nested.present?
base[name] = nested
end
end
end
end
end
class Rule
# allow Squeel
def matches_conditions_hash?(subject, conditions = @conditions)
if conditions.empty?
true
else
if model_adapter(subject).override_conditions_hash_matching? subject, conditions
model_adapter(subject).matches_conditions_hash? subject, conditions
else
conditions.all? do |name, value|
if model_adapter(subject).override_condition_matching? subject, name, value
model_adapter(subject).matches_condition? subject, name, value
else
method_name = case name
when Symbol then name
when Squeel::Nodes::Join then name._name
when Squeel::Nodes::Predicate then name.expr
else raise name
end
attribute = subject.send(method_name)
if value.kind_of?(Hash)
if attribute.kind_of? Array
attribute.any? { |element| matches_conditions_hash? element, value }
else
!attribute.nil? && matches_conditions_hash?(attribute, value)
end
elsif value.kind_of?(Array) || value.kind_of?(Range)
value.include? attribute
else
attribute == value
end
end
end
end
end
end
end
end

12
config/initializers/squeel.rb

@ -0,0 +1,12 @@
Squeel.configure do |config|
# To load hash extensions (to allow for AND (&), OR (|), and NOT (-) against
# hashes of conditions)
config.load_core_extensions :hash
# To load symbol extensions (for a subset of the old MetaWhere functionality,
# via ARel predicate methods on Symbols: :name.matches, etc)
# config.load_core_extensions :symbol
# To load both hash and symbol extensions
config.load_core_extensions :hash, :symbol
end

4
config/routes.rb

@ -50,6 +50,10 @@ Entrydns::Application.routes.draw do
as_routes as_routes
end end
resources :permissions do
as_routes
end
get '/dashboard', :to => 'dashboard#index', :as => :dashboard get '/dashboard', :to => 'dashboard#index', :as => :dashboard
resources :pages, :only => :show resources :pages, :only => :show

12
db/migrate/20111129180907_create_permissions.rb

@ -0,0 +1,12 @@
class CreatePermissions < ActiveRecord::Migration
def change
create_table :permissions do |t|
t.references :domain # the domain to whom permission is being given
t.references :user # the user newly permitted to manage the domain
t.timestamps
end
add_index :permissions, :domain_id
add_index :permissions, :user_id
end
end

15
db/migrate/20120112175527_add_name_reversed_to_domains.rb

@ -0,0 +1,15 @@
class AddNameReversedToDomains < ActiveRecord::Migration
def up
# used for "%" search indexing in an ancestry fashion (materialized path pattern)
# http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html
add_column :domains, :name_reversed, :string, :limit => 255
execute "UPDATE domains SET name_reversed = REVERSE(name)"
change_column :domains, :name_reversed, :string, :limit => 255, :null => false
add_index :domains, :name_reversed
end
def down
remove_index :domains, :column => :name_reversed
remove_column :domains, :name_reversed
end
end

31
db/migrate/20120115174339_add_userstamps_to_models.rb

@ -0,0 +1,31 @@
class AddUserstampsToModels < ActiveRecord::Migration
def change
add_column :users, :created_by_id, :integer
add_column :users, :updated_by_id, :integer
execute "UPDATE users SET created_by_id = id, updated_by_id = id"
add_column :domains, :created_by_id, :integer
add_column :domains, :updated_by_id, :integer
execute "UPDATE domains SET created_by_id = user_id, updated_by_id = user_id"
add_column :records, :created_by_id, :integer
add_column :records, :updated_by_id, :integer
execute <<-SQL
UPDATE records
LEFT JOIN domains ON records.domain_id = domains.id
SET
records.created_by_id = IFNULL(records.user_id, domains.user_id),
records.updated_by_id = IFNULL(records.user_id, domains.user_id)
SQL
add_column :permissions, :created_by_id, :integer
add_column :permissions, :updated_by_id, :integer
execute <<-SQL
UPDATE permissions
LEFT JOIN domains ON permissions.domain_id = domains.id
SET
permissions.created_by_id = domains.user_id,
permissions.updated_by_id = domains.user_id
SQL
end
end

23
spec/controllers/aaaas_controller_spec.rb

@ -1,24 +1,11 @@
require 'spec_helper' require 'spec_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe AaaasController do describe AaaasController do
it_should_behave_like "wiring controller"
end
# TODO implement me
__END__
# This should return the minimal set of attributes required to create a valid # This should return the minimal set of attributes required to create a valid
# Aaaa. As you add validations to Aaaa, be sure to # Aaaa. As you add validations to Aaaa, be sure to

23
spec/controllers/as_controller_spec.rb

@ -1,24 +1,11 @@
require 'spec_helper' require 'spec_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe AsController do describe AsController do
it_should_behave_like "wiring controller"
end
# TODO implement me
__END__
# This should return the minimal set of attributes required to create a valid # This should return the minimal set of attributes required to create a valid
# A. As you add validations to A, be sure to # A. As you add validations to A, be sure to

23
spec/controllers/cnames_controller_spec.rb

@ -1,24 +1,11 @@
require 'spec_helper' require 'spec_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe CnamesController do describe CnamesController do
it_should_behave_like "wiring controller"
end
# TODO implement me
__END__
# This should return the minimal set of attributes required to create a valid # This should return the minimal set of attributes required to create a valid
# Cname. As you add validations to Cname, be sure to # Cname. As you add validations to Cname, be sure to

5
spec/controllers/dashboard_controller_spec.rb

@ -1,5 +0,0 @@
require 'spec_helper'
describe DashboardController do
end

57
spec/controllers/domains_controller_spec.rb

@ -1,25 +1,46 @@
require 'spec_helper' require 'spec_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe DomainsController do describe DomainsController do
context "wiring" do
include_context "data"
# a domain who's parent domain is not in our system
context "domain" do
before do
sign_in user
end
it "is wired with the current user by #new_model" do
@controller.send(:new_model).user.should == user
end
it "is wired with the current user by #before_create_save" do
domain = build(:domain)
@controller.send(:before_create_save, domain)
domain.user.should == user
end
end
# a domain who's parent domain is in our system
context "subdomain" do
before do
sign_in user2
end
it "is wired with the user of the parent domain by #before_create_save" do
subdomain = build(:domain, :user => user2, :name => "x.#{domain.name}")
@controller.send(:before_create_save, subdomain)
subdomain.user.should == user
end
end
end
end
# TODO implement me
__END__
# This should return the minimal set of attributes required to create a valid # This should return the minimal set of attributes required to create a valid
# Domain. As you add validations to Domain, be sure to # Domain. As you add validations to Domain, be sure to
# update the return value of this method accordingly. # update the return value of this method accordingly.

37
spec/controllers/hosts_controller_spec.rb

@ -1,24 +1,25 @@
require 'spec_helper' require 'spec_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe HostsController do describe HostsController do
include_context "data"
before do
sign_in user
@controller.stub(:nested_parent_record => host_domain)
end
it "#new_model is wired" do
@controller.send(:new_model).user.should == user
end
it "#before_create_save wires" do
@controller.send(:before_create_save, host_a_record)
host_a_record.user.should == user
end
end
# TODO implement me
__END__
# This should return the minimal set of attributes required to create a valid # This should return the minimal set of attributes required to create a valid
# Host. As you add validations to Host, be sure to # Host. As you add validations to Host, be sure to

23
spec/controllers/mxes_controller_spec.rb

@ -1,24 +1,11 @@
require 'spec_helper' require 'spec_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe MxesController do describe MxesController do
it_should_behave_like "wiring controller"
end
# TODO implement me
__END__
# This should return the minimal set of attributes required to create a valid # This should return the minimal set of attributes required to create a valid
# Mx. As you add validations to Mx, be sure to # Mx. As you add validations to Mx, be sure to

23
spec/controllers/ns_controller_spec.rb

@ -1,24 +1,11 @@
require 'spec_helper' require 'spec_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe NsController do describe NsController do
it_should_behave_like "wiring controller"
end
# TODO implement me
__END__
# This should return the minimal set of attributes required to create a valid # This should return the minimal set of attributes required to create a valid
# Ns. As you add validations to Ns, be sure to # Ns. As you add validations to Ns, be sure to

5
spec/controllers/pages_controller_spec.rb

@ -1,5 +0,0 @@
require 'spec_helper'
describe PagesController do
end

41
spec/controllers/records_controller_spec.rb

@ -1,38 +1,13 @@
require 'spec_helper' require 'spec_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe RecordsController do describe RecordsController do
it_should_behave_like "wiring controller"
# This should return the minimal set of attributes required to create a valid describe "PUT modify" do
# Record. As you add validations to Record, be sure to
# update the return value of this method accordingly.
def valid_attributes
{}
end
describe "PUT modify", :focus => true do
include_context "data" include_context "data"
before do before do
sign_in user sign_in user
controller.stub(:current_user).and_return(user)
end end
it "modifies @record when IP given" do it "modifies @record when IP given" do
@ -64,6 +39,18 @@ describe RecordsController do
end end
end
# TODO implement me
__END__
# This should return the minimal set of attributes required to create a valid
# Record. As you add validations to Record, be sure to
# update the return value of this method accordingly.
def valid_attributes
{}
end
describe "GET index" do describe "GET index" do
it "assigns all records as @records" do it "assigns all records as @records" do
record = Record.create! valid_attributes record = Record.create! valid_attributes

23
spec/controllers/soas_controller_spec.rb

@ -1,24 +1,11 @@
require 'spec_helper' require 'spec_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe SoasController do describe SoasController do
it_should_behave_like "wiring controller"
end
# TODO implement me
__END__
# This should return the minimal set of attributes required to create a valid # This should return the minimal set of attributes required to create a valid
# Soa. As you add validations to Soa, be sure to # Soa. As you add validations to Soa, be sure to

23
spec/controllers/srvs_controller_spec.rb

@ -1,24 +1,11 @@
require 'spec_helper' require 'spec_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe SrvsController do describe SrvsController do
it_should_behave_like "wiring controller"
end
# TODO implement me
__END__
# This should return the minimal set of attributes required to create a valid # This should return the minimal set of attributes required to create a valid
# Srv. As you add validations to Srv, be sure to # Srv. As you add validations to Srv, be sure to

23
spec/controllers/txts_controller_spec.rb

@ -1,24 +1,11 @@
require 'spec_helper' require 'spec_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
describe TxtsController do describe TxtsController do
it_should_behave_like "wiring controller"
end
# TODO implement me
__END__
# This should return the minimal set of attributes required to create a valid # This should return the minimal set of attributes required to create a valid
# Txt. As you add validations to Txt, be sure to # Txt. As you add validations to Txt, be sure to

6
spec/factories.rb

@ -10,6 +10,9 @@ FactoryGirl.define do
email email
password password
password_confirmation {password} password_confirmation {password}
after_create do |u|
u.confirm!
end
end end
factory :domain do factory :domain do
@ -33,4 +36,7 @@ FactoryGirl.define do
content {Faker::Internet.ip_v4_address} content {Faker::Internet.ip_v4_address}
end end
factory :permission do
end
end end

15
spec/helpers/aaaas_helper_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the AaaasHelper. For example:
#
# describe AaaasHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe AaaasHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

15
spec/helpers/as_helper_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the AsHelper. For example:
#
# describe AsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe AsHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

15
spec/helpers/cnames_helper_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the CnamesHelper. For example:
#
# describe CnamesHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe CnamesHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

15
spec/helpers/dashboard_helper_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the DashboardHelper. For example:
#
# describe DashboardHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe DashboardHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

15
spec/helpers/domains_helper_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the DomainsHelper. For example:
#
# describe DomainsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe DomainsHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

15
spec/helpers/hosts_helper_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the HostsHelper. For example:
#
# describe HostsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe HostsHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

15
spec/helpers/mxes_helper_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the MxesHelper. For example:
#
# describe MxesHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe MxesHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

15
spec/helpers/ns_helper_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the NsHelper. For example:
#
# describe NsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe NsHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

15
spec/helpers/pages_helper_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the PagesHelper. For example:
#
# describe PagesHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe PagesHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

15
spec/helpers/records_helper_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the RecordsHelper. For example:
#
# describe RecordsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe RecordsHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

15
spec/helpers/soas_helper_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the SoAsHelper. For example:
#
# describe SoAsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe SoasHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

15
spec/helpers/srvs_helper_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the SrvsHelper. For example:
#
# describe SrvsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe SrvsHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

15
spec/helpers/txts_helper_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the TxtsHelper. For example:
#
# describe TxtsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe TxtsHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

62
spec/models/ability_spec.rb

@ -5,23 +5,63 @@ require 'spec_helper'
describe Ability do describe Ability do
include_context "data" include_context "data"
context "basic" do
it "allows me to manage my domains and their records, and my hosts" do it "allows me to manage my domains and their records, and my hosts" do
ability.should be_able_to(:manage, domain) user.should be_able_to(:manage, domain)
ability.should be_able_to(:manage, a_record) user.should be_able_to(:manage, a_record)
ability.should be_able_to(:manage, soa_record) user.should be_able_to(:manage, soa_record)
ability.should_not be_able_to(:delete, soa_record) # SOA deleted only via parent user.should_not be_able_to(:delete, soa_record) # SOA deleted only via parent
ability.should be_able_to(:manage, host_a_record) user.should be_able_to(:manage, host_a_record)
end end
it "denies other user to manage my domains and their records" do it "denies other user to manage my domains and their records, and my hosts" do
other_user_ability.should_not be_able_to(:manage, domain) user2.should_not be_able_to(:manage, domain)
other_user_ability.should_not be_able_to(:manage, a_record) user2.should_not be_able_to(:manage, a_record)
other_user_ability.should_not be_able_to(:manage, soa_record) user2.should_not be_able_to(:manage, soa_record)
other_user_ability.should_not be_able_to(:manage, host_a_record) user2.should_not be_able_to(:manage, host_a_record)
end end
it "allows admin to manage other user's hosts" do it "allows admin to manage other user's hosts" do
admin_ability.should be_able_to(:manage, host_a_record) admin.should be_able_to(:manage, host_a_record)
end
end
context "permitted" do
before do
permission # ensure permission to domain
end
it "allows other user to manage user's domains and records, if permitted" do
user2.should be_able_to(:manage, domain)
user2.should be_able_to(:manage, a_record)
user2.should be_able_to(:manage, soa_record)
end
it "denies third user to manage user's permitted domains and records" do
user3.should_not be_able_to(:manage, domain)
user3.should_not be_able_to(:manage, a_record)
user3.should_not be_able_to(:manage, soa_record)
end
it "allows other user to manage user's permitted subdomains" do
user2.should be_able_to(:manage, subdomain)
user2.should be_able_to(:manage, subsubdomain)
end
it "denies third user to manage other user's permitted subdomains" do
user3.should_not be_able_to(:manage, subdomain)
user3.should_not be_able_to(:manage, subsubdomain)
end
end
context "permission" do
it "allows me to manage my domain's permissions" do
user.should be_able_to(:manage, permission)
end
it "denies other user to manage my domain's permissions" do
user2.should_not be_able_to(:manage, permission)
end
end end
end end

26
spec/models/domain_spec.rb

@ -46,6 +46,11 @@ describe Domain do
domain.should be_valid domain.should be_valid
end end
it "has parent_domain" do
subdomain = build(:domain, :user => user2, :name => "x.#{domain.name}")
subdomain.parent_domain.should == domain
end
it "validates ownership" do it "validates ownership" do
domain.name = 'co.uk' domain.name = 'co.uk'
domain.should have(1).errors_on(:name) domain.should have(1).errors_on(:name)
@ -53,9 +58,26 @@ describe Domain do
domain.name = 'clyfe.ro' domain.name = 'clyfe.ro'
domain.should be_valid domain.should be_valid
# stub a parent domain on another user account User.do_as(user) do
Domain.stub_chain('find_by_name.user_id').and_return(domain.user_id + 1) # stub a parent domain on another user account, with no permissions present
mock_domain = mock(:user_id => user3.id, :user => user3, :name => 'x')
domain.stub(:parent_domain).and_return(mock_domain)
domain.should have(1).errors_on(:name) domain.should have(1).errors_on(:name)
end end
end
it "queries domains corectly in index" do
permission3
query = Domain.accessible_by(user.ability(:reload => true))
wheres = query.where_values
joins = query.joins_values.map{|j| [j._name, j._type]}
wheres.should == ["(`domains`.`name_reversed` = '#{domain3.name_reversed}.%') OR ((`permissions`.`user_id` = #{user.id}) OR (`domains`.`user_id` = #{user.id}))"]
joins.should == [[:permissions, Arel::Nodes::OuterJoin]]
end
it "has reversed name" do
domain.name_reversed.should be_present
domain.name_reversed.should == domain.name.reverse
end
end end

15
spec/models/permission_spec.rb

@ -0,0 +1,15 @@
require 'spec_helper'
describe Permission do
include_context "data"
it "validates selfness" do
permission.user_id = permission.domain.user_id
permission.should have(1).error_on(:user)
end
it "validates unexsisting email" do
permission.user_email = "does.not@exist.in.db"
permission.should have(1).error_on(:user)
end
end

28
spec/models/record_spec.rb

@ -16,4 +16,32 @@ describe Record do
a_record.max_records_per_domain a_record.max_records_per_domain
a_record.should be_valid a_record.should be_valid
end end
def record_joins_expectations(joins)
# joins == [{:domain => Squeel(:permissions, outer)}]
joins.size.should == 1
joins.first.should be_an_instance_of(Hash)
domain_joins = joins.first[:domain]
domain_joins.size.should == 1
domain_joins.first[:domain]._name.should == :permissions
domain_joins.first[:domain]._type.should == Arel::Nodes::OuterJoin
end
it "queries records corectly in index" do
wheres = Record.accessible_by(user.ability).where_values
joins = Record.accessible_by(user.ability).joins_values
wheres.should == ["(`permissions`.`user_id` = #{user.id}) OR (`domains`.`user_id` = #{user.id})"]
record_joins_expectations(joins)
end
it "queries A records corectly in index" do
permission3
query = A.accessible_by(user.ability(:reload => true))
wheres = query.where_values
joins = query.joins_values
wheres.size.should == 2
wheres.second.should == "(`domains`.`name_reversed` = '#{domain3.name_reversed}.%') OR ((`permissions`.`user_id` = #{user.id}) OR ((`records`.`user_id` = #{user.id}) OR (`domains`.`user_id` = #{user.id})))"
record_joins_expectations(joins)
end
end end

5
spec/models/user_spec.rb

@ -1,5 +1,8 @@
require 'spec_helper' require 'spec_helper'
describe User do describe User do
pending "add some examples to (or delete) #{__FILE__}" include_context "data"
it "is valid" do
user.should be_valid
end
end end

11
spec/requests/aaaas_spec.rb

@ -1,11 +0,0 @@
require 'spec_helper'
describe "Aaaas" do
describe "GET /aaaas" do
it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
get aaaas_path
response.status.should be(200)
end
end
end

11
spec/requests/as_spec.rb

@ -1,11 +0,0 @@
require 'spec_helper'
describe "As" do
describe "GET /as" do
it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
get as_path
response.status.should be(200)
end
end
end

11
spec/requests/cnames_spec.rb

@ -1,11 +0,0 @@
require 'spec_helper'
describe "Cnames" do
describe "GET /cnames" do
it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
get cnames_path
response.status.should be(200)
end
end
end

11
spec/requests/domains_spec.rb

@ -1,11 +0,0 @@
require 'spec_helper'
describe "Domains" do
describe "GET /domains" do
it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
get domains_path
response.status.should be(200)
end
end
end

11
spec/requests/hosts_spec.rb

@ -1,11 +0,0 @@
require 'spec_helper'
describe "Hosts" do
describe "GET /hosts" do
it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
get hosts_path
response.status.should be(200)
end
end
end

11
spec/requests/mxes_spec.rb

@ -1,11 +0,0 @@
require 'spec_helper'
describe "Mxes" do
describe "GET /mxes" do
it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
get mxes_path
response.status.should be(200)
end
end
end

11
spec/requests/ns_spec.rb

@ -1,11 +0,0 @@
require 'spec_helper'
describe "Ns" do
describe "GET /ns" do
it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
get ns_index_path
response.status.should be(200)
end
end
end

11
spec/requests/records_spec.rb

@ -1,11 +0,0 @@
require 'spec_helper'
describe "Records" do
describe "GET /records" do
it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
get records_path
response.status.should be(200)
end
end
end

11
spec/requests/soas_spec.rb

@ -1,11 +0,0 @@
require 'spec_helper'
describe "Soas" do
describe "GET /soas" do
it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
get soas_path
response.status.should be(200)
end
end
end

11
spec/requests/srvs_spec.rb

@ -1,11 +0,0 @@
require 'spec_helper'
describe "Srvs" do
describe "GET /srvs" do
it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
get srvs_path
response.status.should be(200)
end
end
end

11
spec/requests/txts_spec.rb

@ -1,11 +0,0 @@
require 'spec_helper'
describe "Txts" do
describe "GET /txts" do
it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
get txts_path
response.status.should be(200)
end
end
end

35
spec/routing/permissions_routing_spec.rb

@ -0,0 +1,35 @@
require "spec_helper"
describe PermissionsController do
describe "routing" do
it "routes to #index" do
get("/permissions").should route_to("permissions#index")
end
it "routes to #new" do
get("/permissions/new").should route_to("permissions#new")
end
it "routes to #show" do
get("/permissions/1").should route_to("permissions#show", :id => "1")
end
it "routes to #edit" do
get("/permissions/1/edit").should route_to("permissions#edit", :id => "1")
end
it "routes to #create" do
post("/permissions").should route_to("permissions#create")
end
it "routes to #update" do
put("/permissions/1").should route_to("permissions#update", :id => "1")
end
it "routes to #destroy" do
delete("/permissions/1").should route_to("permissions#destroy", :id => "1")
end
end
end

2
spec/spec_helper.rb

@ -14,5 +14,7 @@ Spork.prefork do
end end
Spork.each_run do Spork.each_run do
require 'simplecov'
SimpleCov.start 'rails'
FactoryGirl.reload FactoryGirl.reload
end end

2
spec/support/rspec.rb

@ -1,6 +1,6 @@
RSpec.configure do |config| RSpec.configure do |config|
config.mock_with :rspec config.mock_with :rspec
config.use_transactional_fixtures = true config.use_transactional_fixtures = false
config.treat_symbols_as_metadata_keys_with_true_values = true config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus => true config.filter_run :focus => true

53
spec/support/shared_context/data.rb

@ -1,40 +1,35 @@
shared_context "data" do shared_context "data" do
let(:admin){create(:user)} # admin is a user that owns host domains
let(:user){create(:user)} # a regular user
let(:user2){create(:user)}
let(:user3){create(:user)}
let(:user){create(:user)} def make_domain(options)
let(:ability){Ability.new(:user => user)} domain = build(:domain, options)
let(:other_user){create(:user)}
let(:other_user_ability){Ability.new(:user => other_user)}
let(:domain){
domain = build(:domain, :user => user)
domain.setup(FactoryGirl.generate(:email)) domain.setup(FactoryGirl.generate(:email))
domain.save! domain.save!
domain.soa_record.update_serial! domain.soa_record.update_serial!
domain domain
} end
let(:a_record){create(:a, :content => '127.0.0.1', :domain => domain)}
let(:soa_record){domain.soa_record}
# admin is a user that owns host domains # user's domains
let(:admin){ let(:domain){make_domain(:user => user)}
admin_user = create(:user, let(:subdomain){make_domain(:name => "sub.#{domain.name}", :user => user)}
:first_name => 'admin', let(:subsubdomain){make_domain(:name => "sub.#{subdomain.name}", :user => user)}
:last_name => 'admin',
:email => 'admin@entrydns.net',
:confirmed_at => Time.now
)
admin_user.confirm!
admin_user
}
let(:admin_ability){Ability.new(:user => admin)}
let(:host_domain){ # third user's domains
domain = build(:domain, :user => admin, :name => Settings.host_domains.first) let(:domain3){make_domain(:user => user3)}
domain.setup(FactoryGirl.generate(:email)) let(:subdomain3){make_domain(:name => "sub.#{domain.name}", :user => user3)}
domain.save! let(:subsubdomain3){make_domain(:name => "sub.#{subdomain.name}", :user => user3)}
domain.soa_record.update_serial!
domain # admin's host domain (like entrydns.org)
} let(:host_domain){make_domain(:user => admin, :name => Settings.host_domains.first)}
let(:a_record){create(:a, :content => '127.0.0.1', :domain => domain)}
let(:soa_record){domain.soa_record}
let(:host_a_record){create(:a, :content => '127.0.0.1', :domain => host_domain, :user => user)} let(:host_a_record){create(:a, :content => '127.0.0.1', :domain => host_domain, :user => user)}
let(:permission){create(:permission, :domain => domain, :user => user2)}
let(:permission3){create(:permission, :domain => domain3, :user => user)}
end end

40
spec/support/shared_examples/wiring_controller.rb

@ -0,0 +1,40 @@
shared_examples_for "wiring controller" do
context "wiring" do
include_context "data"
let(:record){Record.new}
context "on owned domain" do
before do
sign_in user
@controller.stub(:nested_parent_record => domain)
end
it "#new_model is wired" do
@controller.send(:new_model).user.should == domain.user
end
it "#before_create_save wires" do
@controller.send(:before_create_save, record)
record.user.should == domain.user
end
end
context "on permitted domain" do
before do
sign_in user2
permission # touch to ensure creation
@controller.stub(:nested_parent_record => domain)
end
it "#new_model is wired" do
@controller.send(:new_model).user.should == domain.user
end
it "#before_create_save wires" do
@controller.send(:before_create_save, record)
record.user.should == domain.user
end
end
end
end

15
spec/views/aaaas/edit.html.erb_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
describe "aaaas/edit.html.erb" do
before(:each) do
@aaaa = assign(:aaaa, stub_model(Aaaa))
end
it "renders the edit aaaa form" do
render
# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "form", :action => aaaas_path(@aaaa), :method => "post" do
end
end
end

14
spec/views/aaaas/index.html.erb_spec.rb

@ -1,14 +0,0 @@
require 'spec_helper'
describe "aaaas/index.html.erb" do
before(:each) do
assign(:aaaas, [
stub_model(Aaaa),
stub_model(Aaaa)
])
end
it "renders a list of aaaas" do
render
end
end

15
spec/views/aaaas/new.html.erb_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
describe "aaaas/new.html.erb" do
before(:each) do
assign(:aaaa, stub_model(Aaaa).as_new_record)
end
it "renders new aaaa form" do
render
# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "form", :action => aaaas_path, :method => "post" do
end
end
end

11
spec/views/aaaas/show.html.erb_spec.rb

@ -1,11 +0,0 @@
require 'spec_helper'
describe "aaaas/show.html.erb" do
before(:each) do
@aaaa = assign(:aaaa, stub_model(Aaaa))
end
it "renders attributes in <p>" do
render
end
end

15
spec/views/as/edit.html.erb_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
describe "as/edit.html.erb" do
before(:each) do
@a = assign(:a, stub_model(A))
end
it "renders the edit a form" do
render
# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "form", :action => as_path(@a), :method => "post" do
end
end
end

14
spec/views/as/index.html.erb_spec.rb

@ -1,14 +0,0 @@
require 'spec_helper'
describe "as/index.html.erb" do
before(:each) do
assign(:as, [
stub_model(A),
stub_model(A)
])
end
it "renders a list of as" do
render
end
end

15
spec/views/as/new.html.erb_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
describe "as/new.html.erb" do
before(:each) do
assign(:a, stub_model(A).as_new_record)
end
it "renders new a form" do
render
# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "form", :action => as_path, :method => "post" do
end
end
end

11
spec/views/as/show.html.erb_spec.rb

@ -1,11 +0,0 @@
require 'spec_helper'
describe "as/show.html.erb" do
before(:each) do
@a = assign(:a, stub_model(A))
end
it "renders attributes in <p>" do
render
end
end

15
spec/views/cnames/edit.html.erb_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
describe "cnames/edit.html.erb" do
before(:each) do
@cname = assign(:cname, stub_model(Cname))
end
it "renders the edit cname form" do
render
# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "form", :action => cnames_path(@cname), :method => "post" do
end
end
end

14
spec/views/cnames/index.html.erb_spec.rb

@ -1,14 +0,0 @@
require 'spec_helper'
describe "cnames/index.html.erb" do
before(:each) do
assign(:cnames, [
stub_model(Cname),
stub_model(Cname)
])
end
it "renders a list of cnames" do
render
end
end

15
spec/views/cnames/new.html.erb_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
describe "cnames/new.html.erb" do
before(:each) do
assign(:cname, stub_model(Cname).as_new_record)
end
it "renders new cname form" do
render
# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "form", :action => cnames_path, :method => "post" do
end
end
end

11
spec/views/cnames/show.html.erb_spec.rb

@ -1,11 +0,0 @@
require 'spec_helper'
describe "cnames/show.html.erb" do
before(:each) do
@cname = assign(:cname, stub_model(Cname))
end
it "renders attributes in <p>" do
render
end
end

15
spec/views/domains/edit.html.erb_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
describe "domains/edit.html.erb" do
before(:each) do
@domain = assign(:domain, stub_model(Domain))
end
it "renders the edit domain form" do
render
# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "form", :action => domains_path(@domain), :method => "post" do
end
end
end

14
spec/views/domains/index.html.erb_spec.rb

@ -1,14 +0,0 @@
require 'spec_helper'
describe "domains/index.html.erb" do
before(:each) do
assign(:domains, [
stub_model(Domain),
stub_model(Domain)
])
end
it "renders a list of domains" do
render
end
end

15
spec/views/domains/new.html.erb_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
describe "domains/new.html.erb" do
before(:each) do
assign(:domain, stub_model(Domain).as_new_record)
end
it "renders new domain form" do
render
# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "form", :action => domains_path, :method => "post" do
end
end
end

11
spec/views/domains/show.html.erb_spec.rb

@ -1,11 +0,0 @@
require 'spec_helper'
describe "domains/show.html.erb" do
before(:each) do
@domain = assign(:domain, stub_model(Domain))
end
it "renders attributes in <p>" do
render
end
end

15
spec/views/hosts/edit.html.erb_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
describe "hosts/edit.html.erb" do
before(:each) do
@host = assign(:host, stub_model(Host))
end
it "renders the edit host form" do
render
# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "form", :action => hosts_path(@host), :method => "post" do
end
end
end

14
spec/views/hosts/index.html.erb_spec.rb

@ -1,14 +0,0 @@
require 'spec_helper'
describe "hosts/index.html.erb" do
before(:each) do
assign(:hosts, [
stub_model(Host),
stub_model(Host)
])
end
it "renders a list of hosts" do
render
end
end

15
spec/views/hosts/new.html.erb_spec.rb

@ -1,15 +0,0 @@
require 'spec_helper'
describe "hosts/new.html.erb" do
before(:each) do
assign(:host, stub_model(Host).as_new_record)
end
it "renders new host form" do
render
# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "form", :action => hosts_path, :method => "post" do
end
end
end

11
spec/views/hosts/show.html.erb_spec.rb

@ -1,11 +0,0 @@
require 'spec_helper'
describe "hosts/show.html.erb" do
before(:each) do
@host = assign(:host, stub_model(Host))
end
it "renders attributes in <p>" do
render
end
end

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save