From d76e8dbc99d39b6cb53b8a139da8c53cccda5cd9 Mon Sep 17 00:00:00 2001 From: Dmitri Garbuzov Date: Thu, 5 Aug 2010 16:32:40 -0400 Subject: [PATCH] Removed unused routes, cleaned up rspec routing tests --- app/controllers/choices_controller.rb | 2 +- app/controllers/densities_controller.rb | 1 + app/controllers/questions_controller.rb | 2 +- app/controllers/visitors_controller.rb | 1 + config/routes.rb | 36 +++++++++++++----------------------- spec/controllers/visitors_controller_spec.rb | 107 ----------------------------------------------------------------------------------------------------------- spec/routing/choices_routing_spec.rb | 24 ------------------------ spec/routing/prompts_routing_spec.rb | 48 +----------------------------------------------- spec/routing/questions_routing_spec.rb | 14 -------------- spec/routing/visitors_routing_spec.rb | 58 ---------------------------------------------------------- spec/views/visitors/edit.html.erb_spec.rb | 24 ------------------------ spec/views/visitors/index.html.erb_spec.rb | 27 --------------------------- spec/views/visitors/new.html.erb_spec.rb | 24 ------------------------ spec/views/visitors/show.html.erb_spec.rb | 19 ------------------- 14 files changed, 18 insertions(+), 369 deletions(-) delete mode 100644 spec/views/visitors/edit.html.erb_spec.rb delete mode 100644 spec/views/visitors/index.html.erb_spec.rb delete mode 100644 spec/views/visitors/new.html.erb_spec.rb delete mode 100644 spec/views/visitors/show.html.erb_spec.rb diff --git a/app/controllers/choices_controller.rb b/app/controllers/choices_controller.rb index f8de18d..a3ff6df 100644 --- a/app/controllers/choices_controller.rb +++ b/app/controllers/choices_controller.rb @@ -1,6 +1,6 @@ class ChoicesController < InheritedResources::Base respond_to :xml, :json - actions :show, :index, :create, :update + actions :show, :index, :create, :update, :new belongs_to :question has_scope :active, :boolean => true, :only => :index diff --git a/app/controllers/densities_controller.rb b/app/controllers/densities_controller.rb index bd4525a..35a143f 100644 --- a/app/controllers/densities_controller.rb +++ b/app/controllers/densities_controller.rb @@ -1,6 +1,7 @@ class DensitiesController < InheritedResources::Base respond_to :xml, :json before_filter :authenticate + actions :index def index if params[:question_id] diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index e97e2b4..e971ae9 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -1,7 +1,7 @@ require 'fastercsv' class QuestionsController < InheritedResources::Base - actions :all, :except => [ :show ] + actions :all, :except => [ :show, :edit, :delete ] before_filter :authenticate respond_to :xml, :json respond_to :csv, :only => :export #leave the option for xml export here diff --git a/app/controllers/visitors_controller.rb b/app/controllers/visitors_controller.rb index ec390b3..3897caf 100644 --- a/app/controllers/visitors_controller.rb +++ b/app/controllers/visitors_controller.rb @@ -1,6 +1,7 @@ class VisitorsController < InheritedResources::Base respond_to :xml, :json before_filter :authenticate + actions :none def objects_by_session_ids session_ids = params[:session_ids] diff --git a/config/routes.rb b/config/routes.rb index 4eafed9..5e56577 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,32 +1,22 @@ ActionController::Routing::Routes.draw do |map| - #map.resources :clicks - map.resources :densities - map.resources :visitors, :collection => {:objects_by_session_ids => :post}, :member => {:votes => :get} - map.resources :questions, :member => { :object_info_totals_by_date => :get, - :object_info_by_visitor_id => :get, - :export => :post, - :activate => :put, - :suspend => :put}, + map.resources :densities, :only => :index + map.resources :visitors, :only => :none, + :collection => {:objects_by_session_ids => :post}, + :member => {:votes => :get} + map.resources :questions, :except => [:edit, :destroy], + :member => {:object_info_totals_by_date => :get, + :object_info_by_visitor_id => :get, + :export => :post} , :collection => {:all_num_votes_by_visitor_id => :get, :all_object_info_totals_by_date => :get, :object_info_totals_by_question_id => :get, :recent_votes_by_question_id => :get} do |question| - question.resources :items - question.resources :prompts, :member => {:skip => :post, :vote => :post}, - :collection => {:single => :get, :index => :get} - question.resources :choices, :member => {:flag => :put, :votes => :get} - end - map.resources :algorithms - map.connect "/questions/:question_id/prompts/:id/vote/:index", :controller => 'prompts', :action => 'vote' + question.resources :prompts, :only => :show, + :member => {:skip => :post, :vote => :post} + question.resources :choices, :only => [:show, :index, :create, :update, :new], + :member => {:flag => :put, :votes => :get} + end - - - - map.learn '/learn', :controller => 'home', :action => 'learn' - map.api '/api', :controller => 'home', :action => 'api' - map.about '/about', :controller => 'home', :action => 'about' map.root :controller => "clearance/sessions", :action => "new" - # rake routes - # http://guides.rubyonrails.org/routing.html end diff --git a/spec/controllers/visitors_controller_spec.rb b/spec/controllers/visitors_controller_spec.rb index 72cab92..61da1eb 100644 --- a/spec/controllers/visitors_controller_spec.rb +++ b/spec/controllers/visitors_controller_spec.rb @@ -1,112 +1,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe VisitorsController do - #Inherited resources has some issues with rspec, so this test case is not complete. - # OTOH Inherited resources is largely unit tested, so this is not a huge issue - - before do - controller.should_receive(:authenticate).with(no_args).once.and_return(true) - end - - def mock_visitor(stubs={}) - @mock_visitor ||= mock_model(Visitor, stubs) - end - - describe "GET index" do - it "assigns all visitors as @visitors" do - Visitor.stub!(:find).with(:all).and_return([mock_visitor]) - get :index - assigns[:visitors].should == [mock_visitor] - end - end - - describe "GET show" do - it "assigns the requested visitor as @visitor" do - Visitor.stub!(:find).with("37").and_return(mock_visitor) - get :show, :id => "37" - assigns[:visitor].should equal(mock_visitor) - end - end - - describe "GET new" do - it "assigns a new visitor as @visitor" do - Visitor.stub!(:new).and_return(mock_visitor) - get :new - assigns[:visitor].should equal(mock_visitor) - end - end - - describe "GET edit" do - it "assigns the requested visitor as @visitor" do - Visitor.stub!(:find).with("37").and_return(mock_visitor) - get :edit, :id => "37" - assigns[:visitor].should equal(mock_visitor) - end - end - - describe "POST create" do - - describe "with valid params" do - it "assigns a newly created visitor as @visitor" do - Visitor.stub!(:new).with({'these' => 'params'}).and_return(mock_visitor(:save => true)) - post :create, :visitor => {:these => 'params'} - assigns[:visitor].should equal(mock_visitor) - end - - end - - describe "with invalid params" do - it "assigns a newly created but unsaved visitor as @visitor" do - Visitor.stub!(:new).with({'these' => 'params'}).and_return(mock_visitor(:save => false)) - post :create, :visitor => {:these => 'params'} - assigns[:visitor].should equal(mock_visitor) - end - - end - - end - - describe "PUT update" do - - describe "with valid params" do - it "updates the requested visitor" do - Visitor.should_receive(:find).with("37").and_return(mock_visitor) - mock_visitor.should_receive(:update_attributes).with({'these' => 'params'}) - put :update, :id => "37", :visitor => {:these => 'params'} - end - - it "assigns the requested visitor as @visitor" do - Visitor.stub!(:find).and_return(mock_visitor(:update_attributes => true)) - put :update, :id => "1" - assigns[:visitor].should equal(mock_visitor) - end - - end - - describe "with invalid params" do - it "updates the requested visitor" do - Visitor.should_receive(:find).with("37").and_return(mock_visitor) - mock_visitor.should_receive(:update_attributes).with({'these' => 'params'}) - put :update, :id => "37", :visitor => {:these => 'params'} - end - - it "assigns the visitor as @visitor" do - Visitor.stub!(:find).and_return(mock_visitor(:update_attributes => false)) - put :update, :id => "1" - assigns[:visitor].should equal(mock_visitor) - end - - end - - end - - describe "DELETE destroy" do - it "destroys the requested visitor" do - Visitor.should_receive(:find).with("37").and_return(mock_visitor) - mock_visitor.should_receive(:destroy) - delete :destroy, :id => "37" - end - - end end diff --git a/spec/routing/choices_routing_spec.rb b/spec/routing/choices_routing_spec.rb index 89f5e85..40de29a 100644 --- a/spec/routing/choices_routing_spec.rb +++ b/spec/routing/choices_routing_spec.rb @@ -16,18 +16,10 @@ describe ChoicesController do route_for(:controller => "choices", :action => "index", :question_id => @q.id.to_s).should == "/questions/#{@q.id}/choices" end - it "maps #new" do - route_for(:controller => "choices", :action => "new", :question_id => @q.id.to_s).should == "/questions/#{@q.id}/choices/new" - end - it "maps #show" do route_for(:controller => "choices", :action => "show", :id => "1", :question_id => @q.id.to_s).should == "/questions/#{@q.id}/choices/1" end - it "maps #edit" do - route_for(:controller => "choices", :action => "edit", :id => "1", :question_id => @q.id.to_s).should == "/questions/#{@q.id}/choices/1/edit" - end - it "maps #create" do route_for(:controller => "choices", :action => "create", :question_id => @q.id.to_s).should == {:path => "/questions/#{@q.id}/choices", :method => :post} end @@ -35,10 +27,6 @@ describe ChoicesController do it "maps #update" do route_for(:controller => "choices", :action => "update", :id => "1", :question_id => @q.id.to_s).should == {:path =>"/questions/#{@q.id}/choices/1", :method => :put} end - - it "maps #destroy" do - route_for(:controller => "choices", :action => "destroy", :id => "1", :question_id => @q.id.to_s).should == {:path =>"/questions/#{@q.id}/choices/1", :method => :delete} - end end describe "route recognition" do @@ -46,10 +34,6 @@ describe ChoicesController do params_from(:get, "/questions/#{@q.id.to_s}/choices").should == {:controller => "choices", :action => "index", :question_id => @q.id.to_s} end - it "generates params for #new" do - params_from(:get, "/questions/#{@q.id}/choices/new").should == {:controller => "choices", :action => "new", :question_id => @q.id.to_s} - end - it "generates params for #create" do params_from(:post, "/questions/#{@q.id}/choices").should == {:controller => "choices", :action => "create", :question_id => @q.id.to_s} end @@ -58,16 +42,8 @@ describe ChoicesController do params_from(:get, "/questions/#{@q.id}/choices/1").should == {:controller => "choices", :action => "show", :id => "1", :question_id => @q.id.to_s} end - it "generates params for #edit" do - params_from(:get, "/questions/#{@q.id}/choices/1/edit").should == {:controller => "choices", :action => "edit", :id => "1", :question_id => @q.id.to_s} - end - it "generates params for #update" do params_from(:put, "/questions/#{@q.id}/choices/1").should == {:controller => "choices", :action => "update", :id => "1", :question_id => @q.id.to_s} end - - it "generates params for #destroy" do - params_from(:delete, "/questions/#{@q.id}/choices/1").should == {:controller => "choices", :action => "destroy", :id => "1", :question_id => @q.id.to_s} - end end end diff --git a/spec/routing/prompts_routing_spec.rb b/spec/routing/prompts_routing_spec.rb index 03f9d7b..767743b 100644 --- a/spec/routing/prompts_routing_spec.rb +++ b/spec/routing/prompts_routing_spec.rb @@ -13,62 +13,16 @@ describe PromptsController do end describe "route generation" do - it "maps #index" do - route_for(:controller => "prompts", :action => "index", :question_id => @q.id.to_s).should == "/questions/#{@q.id}/prompts/index" - end - - it "maps #new" do - route_for(:controller => "prompts", :action => "new", :question_id => @q.id.to_s).should == "/questions/#{@q.id}/prompts/new" - end - it "maps #show" do route_for(:controller => "prompts", :action => "show", :id => "1", :question_id => @q.id.to_s).should == "/questions/#{@q.id}/prompts/1" end - it "maps #edit" do - route_for(:controller => "prompts", :action => "edit", :id => "1", :question_id => @q.id.to_s).should == "/questions/#{@q.id}/prompts/1/edit" - end - - it "maps #create" do - route_for(:controller => "prompts", :action => "create", :question_id => @q.id.to_s).should == {:path => "/questions/#{@q.id}/prompts", :method => :post} - end - - it "maps #update" do - route_for(:controller => "prompts", :action => "update", :id => "1", :question_id => @q.id.to_s).should == {:path =>"/questions/#{@q.id}/prompts/1", :method => :put} - end - - it "maps #destroy" do - route_for(:controller => "prompts", :action => "destroy", :id => "1", :question_id => @q.id.to_s).should == {:path =>"/questions/#{@q.id}/prompts/1", :method => :delete} - end end describe "route recognition" do - it "generates params for #index" do - params_from(:get, "/questions/#{@q.id}/prompts").should == {:controller => "prompts", :action => "index", :question_id => @q.id.to_s} - end - - it "generates params for #new" do - params_from(:get, "/questions/#{@q.id}/prompts/new").should == {:controller => "prompts", :action => "new", :question_id => @q.id.to_s} - end - - it "generates params for #create" do - params_from(:post, "/questions/#{@q.id}/prompts").should == {:controller => "prompts", :action => "create", :question_id => @q.id.to_s} - end - it "generates params for #show" do params_from(:get, "/questions/#{@q.id}/prompts/1").should == {:controller => "prompts", :action => "show", :id => "1", :question_id => @q.id.to_s} end - - it "generates params for #edit" do - params_from(:get, "/questions/#{@q.id}/prompts/1/edit").should == {:controller => "prompts", :action => "edit", :id => "1", :question_id => @q.id.to_s} - end - - it "generates params for #update" do - params_from(:put, "/questions/#{@q.id}/prompts/1").should == {:controller => "prompts", :action => "update", :id => "1", :question_id => @q.id.to_s} - end - - it "generates params for #destroy" do - params_from(:delete, "/questions/#{@q.id}/prompts/1").should == {:controller => "prompts", :action => "destroy", :id => "1", :question_id => @q.id.to_s} - end end + end diff --git a/spec/routing/questions_routing_spec.rb b/spec/routing/questions_routing_spec.rb index 078df86..c582640 100644 --- a/spec/routing/questions_routing_spec.rb +++ b/spec/routing/questions_routing_spec.rb @@ -14,10 +14,6 @@ describe QuestionsController do route_for(:controller => "questions", :action => "show", :id => "1").should == "/questions/1" end - it "maps #edit" do - route_for(:controller => "questions", :action => "edit", :id => "1").should == "/questions/1/edit" - end - it "maps #create" do route_for(:controller => "questions", :action => "create").should == {:path => "/questions", :method => :post} end @@ -26,9 +22,6 @@ describe QuestionsController do route_for(:controller => "questions", :action => "update", :id => "1").should == {:path =>"/questions/1", :method => :put} end - it "maps #destroy" do - route_for(:controller => "questions", :action => "destroy", :id => "1").should == {:path =>"/questions/1", :method => :delete} - end end describe "route recognition" do @@ -48,16 +41,9 @@ describe QuestionsController do params_from(:get, "/questions/1").should == {:controller => "questions", :action => "show", :id => "1"} end - it "generates params for #edit" do - params_from(:get, "/questions/1/edit").should == {:controller => "questions", :action => "edit", :id => "1"} - end - it "generates params for #update" do params_from(:put, "/questions/1").should == {:controller => "questions", :action => "update", :id => "1"} end - it "generates params for #destroy" do - params_from(:delete, "/questions/1").should == {:controller => "questions", :action => "destroy", :id => "1"} - end end end diff --git a/spec/routing/visitors_routing_spec.rb b/spec/routing/visitors_routing_spec.rb index e1e04a9..61da1eb 100644 --- a/spec/routing/visitors_routing_spec.rb +++ b/spec/routing/visitors_routing_spec.rb @@ -1,63 +1,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe VisitorsController do - describe "route generation" do - it "maps #index" do - route_for(:controller => "visitors", :action => "index").should == "/visitors" - end - it "maps #new" do - route_for(:controller => "visitors", :action => "new").should == "/visitors/new" - end - - it "maps #show" do - route_for(:controller => "visitors", :action => "show", :id => "1").should == "/visitors/1" - end - - it "maps #edit" do - route_for(:controller => "visitors", :action => "edit", :id => "1").should == "/visitors/1/edit" - end - - it "maps #create" do - route_for(:controller => "visitors", :action => "create").should == {:path => "/visitors", :method => :post} - end - - it "maps #update" do - route_for(:controller => "visitors", :action => "update", :id => "1").should == {:path =>"/visitors/1", :method => :put} - end - - it "maps #destroy" do - route_for(:controller => "visitors", :action => "destroy", :id => "1").should == {:path =>"/visitors/1", :method => :delete} - end - end - - describe "route recognition" do - it "generates params for #index" do - params_from(:get, "/visitors").should == {:controller => "visitors", :action => "index"} - end - - it "generates params for #new" do - params_from(:get, "/visitors/new").should == {:controller => "visitors", :action => "new"} - end - - it "generates params for #create" do - params_from(:post, "/visitors").should == {:controller => "visitors", :action => "create"} - end - - it "generates params for #show" do - params_from(:get, "/visitors/1").should == {:controller => "visitors", :action => "show", :id => "1"} - end - - it "generates params for #edit" do - params_from(:get, "/visitors/1/edit").should == {:controller => "visitors", :action => "edit", :id => "1"} - end - - it "generates params for #update" do - params_from(:put, "/visitors/1").should == {:controller => "visitors", :action => "update", :id => "1"} - end - - it "generates params for #destroy" do - params_from(:delete, "/visitors/1").should == {:controller => "visitors", :action => "destroy", :id => "1"} - end - end end diff --git a/spec/views/visitors/edit.html.erb_spec.rb b/spec/views/visitors/edit.html.erb_spec.rb deleted file mode 100644 index 77eb16c..0000000 --- a/spec/views/visitors/edit.html.erb_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') - -describe "/visitors/edit.html.erb" do - include VisitorsHelper - - before(:each) do - assigns[:visitor] = @visitor = stub_model(Visitor, - :new_record? => false, - :site_id => 1, - :identifier => "value for identifier", - :tracking => "value for tracking" - ) - end - - it "renders the edit visitor form" do - render - - response.should have_tag("form[action=#{visitor_path(@visitor)}][method=post]") do - with_tag('input#visitor_site_id[name=?]', "visitor[site_id]") - with_tag('input#visitor_identifier[name=?]', "visitor[identifier]") - with_tag('textarea#visitor_tracking[name=?]', "visitor[tracking]") - end - end -end diff --git a/spec/views/visitors/index.html.erb_spec.rb b/spec/views/visitors/index.html.erb_spec.rb deleted file mode 100644 index 9c4960a..0000000 --- a/spec/views/visitors/index.html.erb_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') - -describe "/visitors/index.html.erb" do - include VisitorsHelper - - before(:each) do - assigns[:visitors] = [ - stub_model(Visitor, - :site_id => 1, - :identifier => "value for identifier", - :tracking => "value for tracking" - ), - stub_model(Visitor, - :site_id => 1, - :identifier => "value for identifier", - :tracking => "value for tracking" - ) - ] - end - - it "renders a list of visitors" do - render - response.should have_tag("tr>td", 1.to_s, 2) - response.should have_tag("tr>td", "value for identifier".to_s, 2) - response.should have_tag("tr>td", "value for tracking".to_s, 2) - end -end diff --git a/spec/views/visitors/new.html.erb_spec.rb b/spec/views/visitors/new.html.erb_spec.rb deleted file mode 100644 index 5002925..0000000 --- a/spec/views/visitors/new.html.erb_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') - -describe "/visitors/new.html.erb" do - include VisitorsHelper - - before(:each) do - assigns[:visitor] = stub_model(Visitor, - :new_record? => true, - :site_id => 1, - :identifier => "value for identifier", - :tracking => "value for tracking" - ) - end - - it "renders new visitor form" do - render - - response.should have_tag("form[action=?][method=post]", visitors_path) do - with_tag("input#visitor_site_id[name=?]", "visitor[site_id]") - with_tag("input#visitor_identifier[name=?]", "visitor[identifier]") - with_tag("textarea#visitor_tracking[name=?]", "visitor[tracking]") - end - end -end diff --git a/spec/views/visitors/show.html.erb_spec.rb b/spec/views/visitors/show.html.erb_spec.rb deleted file mode 100644 index 5d47b88..0000000 --- a/spec/views/visitors/show.html.erb_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') - -describe "/visitors/show.html.erb" do - include VisitorsHelper - before(:each) do - assigns[:visitor] = @visitor = stub_model(Visitor, - :site_id => 1, - :identifier => "value for identifier", - :tracking => "value for tracking" - ) - end - - it "renders attributes in

" do - render - response.should have_text(/1/) - response.should have_text(/value\ for\ identifier/) - response.should have_text(/value\ for\ tracking/) - end -end -- libgit2 0.21.2