Nicolae Claudius
13 years ago
27 changed files with 634 additions and 6 deletions
@ -0,0 +1,34 @@
|
||||
class AsController < ApplicationController |
||||
active_scaffold :a do |conf| |
||||
conf.list.columns = [:name, :type, :content, :ttl, :prio, :change_date] |
||||
conf.create.columns = [:content, :ttl,] |
||||
conf.update.columns = [:content, :ttl] |
||||
conf.columns[:content].label = 'IP' |
||||
conf.columns[:content].description = 'Ex. 10.10.5.12' |
||||
conf.columns[:change_date].list_ui = :timestamp |
||||
conf.actions.exclude :show |
||||
end |
||||
before_filter :ensure_nested_under_domain |
||||
|
||||
protected |
||||
|
||||
# override to use :mx_records instead of :records assoc |
||||
def beginning_of_chain |
||||
if nested? && nested.association && nested.association.collection? && nested.association.name == :records |
||||
nested.parent_scope.a_records |
||||
else |
||||
super |
||||
end |
||||
end |
||||
|
||||
# override, we make our own sti logic |
||||
def new_model |
||||
model = beginning_of_chain |
||||
model.new |
||||
end |
||||
|
||||
# override to close create form after success |
||||
def render_parent? |
||||
nested_singular_association? # || params[:parent_sti] |
||||
end |
||||
end |
@ -0,0 +1,34 @@
|
||||
class CnamesController < ApplicationController |
||||
active_scaffold :cname do |conf| |
||||
conf.list.columns = [:name, :type, :content, :ttl, :prio, :change_date] |
||||
conf.create.columns = [:content, :ttl,] |
||||
conf.update.columns = [:content, :ttl] |
||||
conf.columns[:content].label = 'FQDN' |
||||
conf.columns[:content].description = 'Ex. host.domain.com' |
||||
conf.columns[:change_date].list_ui = :timestamp |
||||
conf.actions.exclude :show |
||||
end |
||||
before_filter :ensure_nested_under_domain |
||||
|
||||
protected |
||||
|
||||
# override to use :mx_records instead of :records assoc |
||||
def beginning_of_chain |
||||
if nested? && nested.association && nested.association.collection? && nested.association.name == :records |
||||
nested.parent_scope.cname_records |
||||
else |
||||
super |
||||
end |
||||
end |
||||
|
||||
# override, we make our own sti logic |
||||
def new_model |
||||
model = beginning_of_chain |
||||
model.new |
||||
end |
||||
|
||||
# override to close create form after success |
||||
def render_parent? |
||||
nested_singular_association? # || params[:parent_sti] |
||||
end |
||||
end |
@ -0,0 +1,157 @@
|
||||
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 |
||||
|
||||
# This should return the minimal set of attributes required to create a valid |
||||
# A. As you add validations to A, be sure to |
||||
# update the return value of this method accordingly. |
||||
def valid_attributes |
||||
{} |
||||
end |
||||
|
||||
describe "GET index" do |
||||
it "assigns all as as @as" do |
||||
a = A.create! valid_attributes |
||||
get :index |
||||
assigns(:as).should eq([a]) |
||||
end |
||||
end |
||||
|
||||
describe "GET show" do |
||||
it "assigns the requested a as @a" do |
||||
a = A.create! valid_attributes |
||||
get :show, :id => a.id.to_s |
||||
assigns(:a).should eq(a) |
||||
end |
||||
end |
||||
|
||||
describe "GET new" do |
||||
it "assigns a new a as @a" do |
||||
get :new |
||||
assigns(:a).should be_a_new(A) |
||||
end |
||||
end |
||||
|
||||
describe "GET edit" do |
||||
it "assigns the requested a as @a" do |
||||
a = A.create! valid_attributes |
||||
get :edit, :id => a.id.to_s |
||||
assigns(:a).should eq(a) |
||||
end |
||||
end |
||||
|
||||
describe "POST create" do |
||||
describe "with valid params" do |
||||
it "creates a new A" do |
||||
expect { |
||||
post :create, :a => valid_attributes |
||||
}.to change(A, :count).by(1) |
||||
end |
||||
|
||||
it "assigns a newly created a as @a" do |
||||
post :create, :a => valid_attributes |
||||
assigns(:a).should be_a(A) |
||||
assigns(:a).should be_persisted |
||||
end |
||||
|
||||
it "redirects to the created a" do |
||||
post :create, :a => valid_attributes |
||||
response.should redirect_to(A.last) |
||||
end |
||||
end |
||||
|
||||
describe "with invalid params" do |
||||
it "assigns a newly created but unsaved a as @a" do |
||||
# Trigger the behavior that occurs when invalid params are submitted |
||||
A.any_instance.stub(:save).and_return(false) |
||||
post :create, :a => {} |
||||
assigns(:a).should be_a_new(A) |
||||
end |
||||
|
||||
it "re-renders the 'new' template" do |
||||
# Trigger the behavior that occurs when invalid params are submitted |
||||
A.any_instance.stub(:save).and_return(false) |
||||
post :create, :a => {} |
||||
response.should render_template("new") |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe "PUT update" do |
||||
describe "with valid params" do |
||||
it "updates the requested a" do |
||||
a = A.create! valid_attributes |
||||
# Assuming there are no other as in the database, this |
||||
# specifies that the A created on the previous line |
||||
# receives the :update_attributes message with whatever params are |
||||
# submitted in the request. |
||||
A.any_instance.should_receive(:update_attributes).with({'these' => 'params'}) |
||||
put :update, :id => a.id, :a => {'these' => 'params'} |
||||
end |
||||
|
||||
it "assigns the requested a as @a" do |
||||
a = A.create! valid_attributes |
||||
put :update, :id => a.id, :a => valid_attributes |
||||
assigns(:a).should eq(a) |
||||
end |
||||
|
||||
it "redirects to the a" do |
||||
a = A.create! valid_attributes |
||||
put :update, :id => a.id, :a => valid_attributes |
||||
response.should redirect_to(a) |
||||
end |
||||
end |
||||
|
||||
describe "with invalid params" do |
||||
it "assigns the a as @a" do |
||||
a = A.create! valid_attributes |
||||
# Trigger the behavior that occurs when invalid params are submitted |
||||
A.any_instance.stub(:save).and_return(false) |
||||
put :update, :id => a.id.to_s, :a => {} |
||||
assigns(:a).should eq(a) |
||||
end |
||||
|
||||
it "re-renders the 'edit' template" do |
||||
a = A.create! valid_attributes |
||||
# Trigger the behavior that occurs when invalid params are submitted |
||||
A.any_instance.stub(:save).and_return(false) |
||||
put :update, :id => a.id.to_s, :a => {} |
||||
response.should render_template("edit") |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe "DELETE destroy" do |
||||
it "destroys the requested a" do |
||||
a = A.create! valid_attributes |
||||
expect { |
||||
delete :destroy, :id => a.id.to_s |
||||
}.to change(A, :count).by(-1) |
||||
end |
||||
|
||||
it "redirects to the as list" do |
||||
a = A.create! valid_attributes |
||||
delete :destroy, :id => a.id.to_s |
||||
response.should redirect_to(as_url) |
||||
end |
||||
end |
||||
|
||||
end |
@ -0,0 +1,157 @@
|
||||
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 |
||||
|
||||
# This should return the minimal set of attributes required to create a valid |
||||
# Cname. As you add validations to Cname, be sure to |
||||
# update the return value of this method accordingly. |
||||
def valid_attributes |
||||
{} |
||||
end |
||||
|
||||
describe "GET index" do |
||||
it "assigns all cnames as @cnames" do |
||||
cname = Cname.create! valid_attributes |
||||
get :index |
||||
assigns(:cnames).should eq([cname]) |
||||
end |
||||
end |
||||
|
||||
describe "GET show" do |
||||
it "assigns the requested cname as @cname" do |
||||
cname = Cname.create! valid_attributes |
||||
get :show, :id => cname.id.to_s |
||||
assigns(:cname).should eq(cname) |
||||
end |
||||
end |
||||
|
||||
describe "GET new" do |
||||
it "assigns a new cname as @cname" do |
||||
get :new |
||||
assigns(:cname).should be_a_new(Cname) |
||||
end |
||||
end |
||||
|
||||
describe "GET edit" do |
||||
it "assigns the requested cname as @cname" do |
||||
cname = Cname.create! valid_attributes |
||||
get :edit, :id => cname.id.to_s |
||||
assigns(:cname).should eq(cname) |
||||
end |
||||
end |
||||
|
||||
describe "POST create" do |
||||
describe "with valid params" do |
||||
it "creates a new Cname" do |
||||
expect { |
||||
post :create, :cname => valid_attributes |
||||
}.to change(Cname, :count).by(1) |
||||
end |
||||
|
||||
it "assigns a newly created cname as @cname" do |
||||
post :create, :cname => valid_attributes |
||||
assigns(:cname).should be_a(Cname) |
||||
assigns(:cname).should be_persisted |
||||
end |
||||
|
||||
it "redirects to the created cname" do |
||||
post :create, :cname => valid_attributes |
||||
response.should redirect_to(Cname.last) |
||||
end |
||||
end |
||||
|
||||
describe "with invalid params" do |
||||
it "assigns a newly created but unsaved cname as @cname" do |
||||
# Trigger the behavior that occurs when invalid params are submitted |
||||
Cname.any_instance.stub(:save).and_return(false) |
||||
post :create, :cname => {} |
||||
assigns(:cname).should be_a_new(Cname) |
||||
end |
||||
|
||||
it "re-renders the 'new' template" do |
||||
# Trigger the behavior that occurs when invalid params are submitted |
||||
Cname.any_instance.stub(:save).and_return(false) |
||||
post :create, :cname => {} |
||||
response.should render_template("new") |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe "PUT update" do |
||||
describe "with valid params" do |
||||
it "updates the requested cname" do |
||||
cname = Cname.create! valid_attributes |
||||
# Assuming there are no other cnames in the database, this |
||||
# specifies that the Cname created on the previous line |
||||
# receives the :update_attributes message with whatever params are |
||||
# submitted in the request. |
||||
Cname.any_instance.should_receive(:update_attributes).with({'these' => 'params'}) |
||||
put :update, :id => cname.id, :cname => {'these' => 'params'} |
||||
end |
||||
|
||||
it "assigns the requested cname as @cname" do |
||||
cname = Cname.create! valid_attributes |
||||
put :update, :id => cname.id, :cname => valid_attributes |
||||
assigns(:cname).should eq(cname) |
||||
end |
||||
|
||||
it "redirects to the cname" do |
||||
cname = Cname.create! valid_attributes |
||||
put :update, :id => cname.id, :cname => valid_attributes |
||||
response.should redirect_to(cname) |
||||
end |
||||
end |
||||
|
||||
describe "with invalid params" do |
||||
it "assigns the cname as @cname" do |
||||
cname = Cname.create! valid_attributes |
||||
# Trigger the behavior that occurs when invalid params are submitted |
||||
Cname.any_instance.stub(:save).and_return(false) |
||||
put :update, :id => cname.id.to_s, :cname => {} |
||||
assigns(:cname).should eq(cname) |
||||
end |
||||
|
||||
it "re-renders the 'edit' template" do |
||||
cname = Cname.create! valid_attributes |
||||
# Trigger the behavior that occurs when invalid params are submitted |
||||
Cname.any_instance.stub(:save).and_return(false) |
||||
put :update, :id => cname.id.to_s, :cname => {} |
||||
response.should render_template("edit") |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe "DELETE destroy" do |
||||
it "destroys the requested cname" do |
||||
cname = Cname.create! valid_attributes |
||||
expect { |
||||
delete :destroy, :id => cname.id.to_s |
||||
}.to change(Cname, :count).by(-1) |
||||
end |
||||
|
||||
it "redirects to the cnames list" do |
||||
cname = Cname.create! valid_attributes |
||||
delete :destroy, :id => cname.id.to_s |
||||
response.should redirect_to(cnames_url) |
||||
end |
||||
end |
||||
|
||||
end |
@ -0,0 +1,15 @@
|
||||
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 |
@ -0,0 +1,15 @@
|
||||
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 |
@ -0,0 +1,11 @@
|
||||
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 |
@ -0,0 +1,11 @@
|
||||
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 |
@ -0,0 +1,35 @@
|
||||
require "spec_helper" |
||||
|
||||
describe AsController do |
||||
describe "routing" do |
||||
|
||||
it "routes to #index" do |
||||
get("/as").should route_to("as#index") |
||||
end |
||||
|
||||
it "routes to #new" do |
||||
get("/as/new").should route_to("as#new") |
||||
end |
||||
|
||||
it "routes to #show" do |
||||
get("/as/1").should route_to("as#show", :id => "1") |
||||
end |
||||
|
||||
it "routes to #edit" do |
||||
get("/as/1/edit").should route_to("as#edit", :id => "1") |
||||
end |
||||
|
||||
it "routes to #create" do |
||||
post("/as").should route_to("as#create") |
||||
end |
||||
|
||||
it "routes to #update" do |
||||
put("/as/1").should route_to("as#update", :id => "1") |
||||
end |
||||
|
||||
it "routes to #destroy" do |
||||
delete("/as/1").should route_to("as#destroy", :id => "1") |
||||
end |
||||
|
||||
end |
||||
end |
@ -0,0 +1,35 @@
|
||||
require "spec_helper" |
||||
|
||||
describe CnamesController do |
||||
describe "routing" do |
||||
|
||||
it "routes to #index" do |
||||
get("/cnames").should route_to("cnames#index") |
||||
end |
||||
|
||||
it "routes to #new" do |
||||
get("/cnames/new").should route_to("cnames#new") |
||||
end |
||||
|
||||
it "routes to #show" do |
||||
get("/cnames/1").should route_to("cnames#show", :id => "1") |
||||
end |
||||
|
||||
it "routes to #edit" do |
||||
get("/cnames/1/edit").should route_to("cnames#edit", :id => "1") |
||||
end |
||||
|
||||
it "routes to #create" do |
||||
post("/cnames").should route_to("cnames#create") |
||||
end |
||||
|
||||
it "routes to #update" do |
||||
put("/cnames/1").should route_to("cnames#update", :id => "1") |
||||
end |
||||
|
||||
it "routes to #destroy" do |
||||
delete("/cnames/1").should route_to("cnames#destroy", :id => "1") |
||||
end |
||||
|
||||
end |
||||
end |
@ -0,0 +1,15 @@
|
||||
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 |
@ -0,0 +1,14 @@
|
||||
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 |
@ -0,0 +1,15 @@
|
||||
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 |
@ -0,0 +1,11 @@
|
||||
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 |
@ -0,0 +1,15 @@
|
||||
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 |
@ -0,0 +1,14 @@
|
||||
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 |
@ -0,0 +1,15 @@
|
||||
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 |
Loading…
Reference in new issue