Browse Source

txt

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
dec2a71214
  1. 2
      app/controllers/records_controller.rb
  2. 34
      app/controllers/txts_controller.rb
  3. 2
      app/helpers/txts_helper.rb
  4. 2
      app/models/txt.rb
  5. 4
      config/routes.rb
  6. 157
      spec/controllers/txts_controller_spec.rb
  7. 15
      spec/helpers/txts_helper_spec.rb
  8. 11
      spec/requests/txts_spec.rb
  9. 35
      spec/routing/txts_routing_spec.rb
  10. 15
      spec/views/txts/edit.html.erb_spec.rb
  11. 14
      spec/views/txts/index.html.erb_spec.rb
  12. 15
      spec/views/txts/new.html.erb_spec.rb
  13. 11
      spec/views/txts/show.html.erb_spec.rb

2
app/controllers/records_controller.rb

@ -16,7 +16,7 @@ class RecordsController < ApplicationController
end
active_scaffold :record do |conf|
conf.sti_children = [:SOA, :NS, :MX, :A, :CNAME]
conf.sti_children = [:SOA, :NS, :MX, :A, :CNAME, :TXT]
conf.columns = [:name, :type, :content, :ttl, :prio, :change_date]
conf.columns[:change_date].list_ui = :timestamp
conf.actions.exclude :show

34
app/controllers/txts_controller.rb

@ -0,0 +1,34 @@
class TxtsController < ApplicationController
active_scaffold :txt do |conf|
conf.list.columns = [:name, :type, :content, :ttl, :prio, :change_date]
conf.create.columns = [:name, :content, :ttl]
conf.update.columns = [:name, :content, :ttl]
# conf.columns[:content].label = 'Content'
# conf.columns[:content].description = 'Ex. can be many things'
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.txt_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

2
app/helpers/txts_helper.rb

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

2
app/models/txt.rb

@ -12,3 +12,5 @@ class TXT < Record
validate :content, :presence => true
end
Txt = TXT

4
config/routes.rb

@ -29,6 +29,10 @@ Simpledns::Application.routes.draw do
resources :cnames do
as_routes
end
resources :txts do
as_routes
end
get '/dashboard', :to => 'dashboard#index', :as => :dashboard
root :to => 'home#index'

157
spec/controllers/txts_controller_spec.rb

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

15
spec/helpers/txts_helper_spec.rb

@ -0,0 +1,15 @@
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

11
spec/requests/txts_spec.rb

@ -0,0 +1,11 @@
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/txts_routing_spec.rb

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

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

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

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

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

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

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

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

@ -0,0 +1,11 @@
require 'spec_helper'
describe "txts/show.html.erb" do
before(:each) do
@txt = assign(:txt, stub_model(Txt))
end
it "renders attributes in <p>" do
render
end
end
Loading…
Cancel
Save