From dec2a712149128e433459300e2471c8ccb8bede0 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius Date: Wed, 5 Oct 2011 09:27:36 -0700 Subject: [PATCH] txt --- app/controllers/records_controller.rb | 2 +- app/controllers/txts_controller.rb | 34 +++++ app/helpers/txts_helper.rb | 2 + app/models/txt.rb | 2 + config/routes.rb | 4 + spec/controllers/txts_controller_spec.rb | 157 +++++++++++++++++++++++ spec/helpers/txts_helper_spec.rb | 15 +++ spec/requests/txts_spec.rb | 11 ++ spec/routing/txts_routing_spec.rb | 35 +++++ spec/views/txts/edit.html.erb_spec.rb | 15 +++ spec/views/txts/index.html.erb_spec.rb | 14 ++ spec/views/txts/new.html.erb_spec.rb | 15 +++ spec/views/txts/show.html.erb_spec.rb | 11 ++ 13 files changed, 316 insertions(+), 1 deletion(-) create mode 100644 app/controllers/txts_controller.rb create mode 100644 app/helpers/txts_helper.rb create mode 100644 spec/controllers/txts_controller_spec.rb create mode 100644 spec/helpers/txts_helper_spec.rb create mode 100644 spec/requests/txts_spec.rb create mode 100644 spec/routing/txts_routing_spec.rb create mode 100644 spec/views/txts/edit.html.erb_spec.rb create mode 100644 spec/views/txts/index.html.erb_spec.rb create mode 100644 spec/views/txts/new.html.erb_spec.rb create mode 100644 spec/views/txts/show.html.erb_spec.rb diff --git a/app/controllers/records_controller.rb b/app/controllers/records_controller.rb index d774d86..e0dbd7e 100644 --- a/app/controllers/records_controller.rb +++ b/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 diff --git a/app/controllers/txts_controller.rb b/app/controllers/txts_controller.rb new file mode 100644 index 0000000..416368b --- /dev/null +++ b/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 \ No newline at end of file diff --git a/app/helpers/txts_helper.rb b/app/helpers/txts_helper.rb new file mode 100644 index 0000000..e94a08f --- /dev/null +++ b/app/helpers/txts_helper.rb @@ -0,0 +1,2 @@ +module TxtsHelper +end \ No newline at end of file diff --git a/app/models/txt.rb b/app/models/txt.rb index 64af818..e4ae3bb 100644 --- a/app/models/txt.rb +++ b/app/models/txt.rb @@ -12,3 +12,5 @@ class TXT < Record validate :content, :presence => true end + +Txt = TXT diff --git a/config/routes.rb b/config/routes.rb index 7d39616..e31f9b4 100644 --- a/config/routes.rb +++ b/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' diff --git a/spec/controllers/txts_controller_spec.rb b/spec/controllers/txts_controller_spec.rb new file mode 100644 index 0000000..ec61e32 --- /dev/null +++ b/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 diff --git a/spec/helpers/txts_helper_spec.rb b/spec/helpers/txts_helper_spec.rb new file mode 100644 index 0000000..409a0f4 --- /dev/null +++ b/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 diff --git a/spec/requests/txts_spec.rb b/spec/requests/txts_spec.rb new file mode 100644 index 0000000..992f5a8 --- /dev/null +++ b/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 diff --git a/spec/routing/txts_routing_spec.rb b/spec/routing/txts_routing_spec.rb new file mode 100644 index 0000000..7093445 --- /dev/null +++ b/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 diff --git a/spec/views/txts/edit.html.erb_spec.rb b/spec/views/txts/edit.html.erb_spec.rb new file mode 100644 index 0000000..cd82cc3 --- /dev/null +++ b/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 diff --git a/spec/views/txts/index.html.erb_spec.rb b/spec/views/txts/index.html.erb_spec.rb new file mode 100644 index 0000000..14daaf8 --- /dev/null +++ b/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 diff --git a/spec/views/txts/new.html.erb_spec.rb b/spec/views/txts/new.html.erb_spec.rb new file mode 100644 index 0000000..ca881bc --- /dev/null +++ b/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 diff --git a/spec/views/txts/show.html.erb_spec.rb b/spec/views/txts/show.html.erb_spec.rb new file mode 100644 index 0000000..d03b339 --- /dev/null +++ b/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

" do + render + end +end