Browse Source

permission-aware wiring

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
79bc417fab
  1. 3
      app/controllers/aaaas_controller.rb
  2. 3
      app/controllers/as_controller.rb
  3. 3
      app/controllers/cnames_controller.rb
  4. 3
      app/controllers/mxes_controller.rb
  5. 3
      app/controllers/ns_controller.rb
  6. 3
      app/controllers/records_controller.rb
  7. 3
      app/controllers/soas_controller.rb
  8. 3
      app/controllers/srvs_controller.rb
  9. 3
      app/controllers/txts_controller.rb
  10. 4
      app/models/domain.rb
  11. 3
      app/models/record.rb
  12. 226
      spec/controllers/hosts_controller_spec.rb
  13. 1
      spec/controllers/records_controller_spec.rb
  14. 41
      spec/support/shared_examples/wiring_controller.rb

3
app/controllers/aaaas_controller.rb

@ -27,7 +27,8 @@ class AaaasController < ApplicationController
end
def before_create_save(record)
record.user = current_user
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success

3
app/controllers/as_controller.rb

@ -28,7 +28,8 @@ class AsController < ApplicationController
end
def before_create_save(record)
record.user = current_user
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success

3
app/controllers/cnames_controller.rb

@ -27,7 +27,8 @@ class CnamesController < ApplicationController
end
def before_create_save(record)
record.user = current_user
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success

3
app/controllers/mxes_controller.rb

@ -35,7 +35,8 @@ class MxesController < ApplicationController
end
def before_create_save(record)
record.user = current_user
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success

3
app/controllers/ns_controller.rb

@ -28,7 +28,8 @@ class NsController < ApplicationController
end
def before_create_save(record)
record.user = current_user
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success

3
app/controllers/records_controller.rb

@ -55,7 +55,8 @@ class RecordsController < ApplicationController
end
def before_create_save(record)
record.user = current_user
record.domain = nested_parent_record
record.user = record.domain_user
end
end

3
app/controllers/soas_controller.rb

@ -23,7 +23,8 @@ class SoasController < ApplicationController
end
def before_create_save(record)
record.user = current_user
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success

3
app/controllers/srvs_controller.rb

@ -32,7 +32,8 @@ class SrvsController < ApplicationController
end
def before_create_save(record)
record.user = current_user
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success

3
app/controllers/txts_controller.rb

@ -27,7 +27,8 @@ class TxtsController < ApplicationController
end
def before_create_save(record)
record.user = current_user
record.domain = nested_parent_record
record.user = record.domain_user
end
# override to close create form after success

4
app/models/domain.rb

@ -116,6 +116,10 @@ class Domain < ActiveRecord::Base
scope :host_domains, where(:name => Settings.host_domains)
def host_domain?
Settings.host_domains.include?(name)
end
def setup(email)
build_soa_record
soa = soa_record

3
app/models/record.rb

@ -50,6 +50,9 @@ class Record < ActiveRecord::Base
end
end
delegate :host_domain?, :to => :domain
delegate :user, :to => :domain, :prefix => :domain
protected
def prepare_name!

226
spec/controllers/hosts_controller_spec.rb

@ -1,144 +1,158 @@
require 'spec_helper'
describe HostsController do
it_should_behave_like "wiring controller"
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
# Host. As you add validations to Host, be sure to
# update the return value of this method accordingly.
def valid_attributes
{}
# This should return the minimal set of attributes required to create a valid
# Host. As you add validations to Host, be sure to
# update the return value of this method accordingly.
def valid_attributes
{}
end
describe "GET index" do
it "assigns all hosts as @hosts" do
host = Host.create! valid_attributes
get :index
assigns(:hosts).should eq([host])
end
end
describe "GET index" do
it "assigns all hosts as @hosts" do
host = Host.create! valid_attributes
get :index
assigns(:hosts).should eq([host])
end
describe "GET show" do
it "assigns the requested host as @host" do
host = Host.create! valid_attributes
get :show, :id => host.id.to_s
assigns(:host).should eq(host)
end
end
describe "GET show" do
it "assigns the requested host as @host" do
host = Host.create! valid_attributes
get :show, :id => host.id.to_s
assigns(:host).should eq(host)
end
describe "GET new" do
it "assigns a new host as @host" do
get :new
assigns(:host).should be_a_new(Host)
end
end
describe "GET new" do
it "assigns a new host as @host" do
get :new
assigns(:host).should be_a_new(Host)
end
describe "GET edit" do
it "assigns the requested host as @host" do
host = Host.create! valid_attributes
get :edit, :id => host.id.to_s
assigns(:host).should eq(host)
end
end
describe "GET edit" do
it "assigns the requested host as @host" do
host = Host.create! valid_attributes
get :edit, :id => host.id.to_s
assigns(:host).should eq(host)
describe "POST create" do
describe "with valid params" do
it "creates a new Host" do
expect {
post :create, :host => valid_attributes
}.to change(Host, :count).by(1)
end
end
describe "POST create" do
describe "with valid params" do
it "creates a new Host" do
expect {
post :create, :host => valid_attributes
}.to change(Host, :count).by(1)
end
it "assigns a newly created host as @host" do
post :create, :host => valid_attributes
assigns(:host).should be_a(Host)
assigns(:host).should be_persisted
end
it "assigns a newly created host as @host" do
post :create, :host => valid_attributes
assigns(:host).should be_a(Host)
assigns(:host).should be_persisted
end
it "redirects to the created host" do
post :create, :host => valid_attributes
response.should redirect_to(Host.last)
end
end
it "redirects to the created host" do
post :create, :host => valid_attributes
response.should redirect_to(Host.last)
end
describe "with invalid params" do
it "assigns a newly created but unsaved host as @host" do
# Trigger the behavior that occurs when invalid params are submitted
Host.any_instance.stub(:save).and_return(false)
post :create, :host => {}
assigns(:host).should be_a_new(Host)
end
describe "with invalid params" do
it "assigns a newly created but unsaved host as @host" do
# Trigger the behavior that occurs when invalid params are submitted
Host.any_instance.stub(:save).and_return(false)
post :create, :host => {}
assigns(:host).should be_a_new(Host)
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
Host.any_instance.stub(:save).and_return(false)
post :create, :host => {}
response.should render_template("new")
end
it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
Host.any_instance.stub(:save).and_return(false)
post :create, :host => {}
response.should render_template("new")
end
end
end
describe "PUT update" do
describe "with valid params" do
it "updates the requested host" do
host = Host.create! valid_attributes
# Assuming there are no other hosts in the database, this
# specifies that the Host created on the previous line
# receives the :update_attributes message with whatever params are
# submitted in the request.
Host.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
put :update, :id => host.id, :host => {'these' => 'params'}
end
describe "PUT update" do
describe "with valid params" do
it "updates the requested host" do
host = Host.create! valid_attributes
# Assuming there are no other hosts in the database, this
# specifies that the Host created on the previous line
# receives the :update_attributes message with whatever params are
# submitted in the request.
Host.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
put :update, :id => host.id, :host => {'these' => 'params'}
end
it "assigns the requested host as @host" do
host = Host.create! valid_attributes
put :update, :id => host.id, :host => valid_attributes
assigns(:host).should eq(host)
end
it "redirects to the host" do
host = Host.create! valid_attributes
put :update, :id => host.id, :host => valid_attributes
response.should redirect_to(host)
end
it "assigns the requested host as @host" do
host = Host.create! valid_attributes
put :update, :id => host.id, :host => valid_attributes
assigns(:host).should eq(host)
end
describe "with invalid params" do
it "assigns the host as @host" do
host = Host.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Host.any_instance.stub(:save).and_return(false)
put :update, :id => host.id.to_s, :host => {}
assigns(:host).should eq(host)
end
it "re-renders the 'edit' template" do
host = Host.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Host.any_instance.stub(:save).and_return(false)
put :update, :id => host.id.to_s, :host => {}
response.should render_template("edit")
end
it "redirects to the host" do
host = Host.create! valid_attributes
put :update, :id => host.id, :host => valid_attributes
response.should redirect_to(host)
end
end
describe "DELETE destroy" do
it "destroys the requested host" do
describe "with invalid params" do
it "assigns the host as @host" do
host = Host.create! valid_attributes
expect {
delete :destroy, :id => host.id.to_s
}.to change(Host, :count).by(-1)
# Trigger the behavior that occurs when invalid params are submitted
Host.any_instance.stub(:save).and_return(false)
put :update, :id => host.id.to_s, :host => {}
assigns(:host).should eq(host)
end
it "redirects to the hosts list" do
it "re-renders the 'edit' template" do
host = Host.create! valid_attributes
delete :destroy, :id => host.id.to_s
response.should redirect_to(hosts_url)
# Trigger the behavior that occurs when invalid params are submitted
Host.any_instance.stub(:save).and_return(false)
put :update, :id => host.id.to_s, :host => {}
response.should render_template("edit")
end
end
end
describe "DELETE destroy" do
it "destroys the requested host" do
host = Host.create! valid_attributes
expect {
delete :destroy, :id => host.id.to_s
}.to change(Host, :count).by(-1)
end
it "redirects to the hosts list" do
host = Host.create! valid_attributes
delete :destroy, :id => host.id.to_s
response.should redirect_to(hosts_url)
end
end
end

1
spec/controllers/records_controller_spec.rb

@ -8,7 +8,6 @@ describe RecordsController do
before do
sign_in user
controller.stub(:current_user).and_return(user)
end
it "modifies @record when IP given" do

41
spec/support/shared_examples/wiring_controller.rb

@ -1,21 +1,40 @@
shared_examples_for "wiring controller" do
context "wiring" do
include_context "data"
let(:record){Record.new}
before do
sign_in user
@controller.stub(:nested_parent_record => domain)
end
it "#new_model is wired" do
@controller.send(:new_model).user.should == user
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
it "#before_create_save wires" do
@controller.send(:before_create_save, record)
record.user.should == user
context "on permitted domain" do
before do
sign_in other_user
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
Loading…
Cancel
Save