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. 54
      spec/controllers/hosts_controller_spec.rb
  13. 1
      spec/controllers/records_controller_spec.rb
  14. 25
      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!

54
spec/controllers/hosts_controller_spec.rb

@ -1,51 +1,65 @@
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
end
describe "GET index" do
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
end
describe "GET show" do
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
end
describe "GET new" do
describe "GET new" do
it "assigns a new host as @host" do
get :new
assigns(:host).should be_a_new(Host)
end
end
end
describe "GET edit" do
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
end
describe "POST create" do
describe "POST create" do
describe "with valid params" do
it "creates a new Host" do
expect {
@ -80,9 +94,9 @@ __END__
response.should render_template("new")
end
end
end
end
describe "PUT update" do
describe "PUT update" do
describe "with valid params" do
it "updates the requested host" do
host = Host.create! valid_attributes
@ -124,9 +138,9 @@ __END__
response.should render_template("edit")
end
end
end
end
describe "DELETE destroy" do
describe "DELETE destroy" do
it "destroys the requested host" do
host = Host.create! valid_attributes
expect {
@ -139,6 +153,6 @@ __END__
delete :destroy, :id => host.id.to_s
response.should redirect_to(hosts_url)
end
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

25
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}
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 == user
@controller.send(:new_model).user.should == domain.user
end
it "#before_create_save wires" do
@controller.send(:before_create_save, record)
record.user.should == user
record.user.should == domain.user
end
end
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