require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb') describe "Admin::<%= @controller if @controller %>Controller" do # START NOT LOGGED IN describe "when not logged in" do # START GET index describe "GET index" do before do get "/admin/<%= @pluralized %>" end it "should not display the <%= @pluralized %> index page" do assert_admin_not_logged_in end end # END GET index # START GET new describe "GET new" do before do get "/admin/<%= @pluralized %>/new" end it "should not display the <%= @pluralized %> new page" do assert_admin_not_logged_in end end # END GET new # START POST create describe "Post create" do before do post "/admin/<%= @pluralized %>/create", :<%= @singular %> => <%= @model %>.make.attributes end it "should not return the created text" do assert_admin_not_logged_in end end # END POST create # START GET edit describe "GET edit" do before do @<%= @singular %> = <%= @model %>.make! get "/admin/<%= @pluralized %>/edit/#{@<%= @singular %>.to_param}" end it "should not display the <%= @pluralized %> edit page" do assert_admin_not_logged_in end end # END GET edit # START PUT update describe "PUT update" do before do @<%= @singular %> = <%= @model %>.make! put "/admin/<%= @pluralized %>/update/#{@<%= @singular %>.to_param}", :<%= @singular %> => <%= @model %>.make.attributes end it "should not return the updated text" do assert_admin_not_logged_in end end # END PUT update # START DELETE destroy describe "on DELETE destroy" do before do @<%= @singular %> = <%= @model %>.make! delete "/admin/<%= @pluralized %>/destroy/#{@<%= @singular %>.to_param}" end it "should not return the destroyed text" do assert_admin_not_logged_in end end # END DELETE destroy end # END NOT LOGGED IN # START LOGGED IN describe "when logged in" do before do @account = Account.make! login_as_admin(@account) end # START GET index describe "GET index" do before do get "/admin/<%= @pluralized %>" end it "should display the <%= @pluralized %> index page" do assert ok? assert_equal 200, status assert_equal "/admin/<%= @pluralized %>", path end end # END GET index # START GET new describe "GET new" do before do get "/admin/<%= @pluralized %>/new" end it "should display the <%= @pluralized %> new page" do assert ok? assert_equal 200, status assert_equal "/admin/<%= @pluralized %>/new", path end end # END GET new # START POST create describe "POST create" do before do @<%= @singular %>_count = <%= @model %>.count post "/admin/<%= @pluralized %>/create", :<%= @singular %> => <%= @model %>.make.attributes end it "should redirect to the edit page" do assert_equal 302, status assert location.include?("/admin/<%= @pluralized %>/edit/#{<%= @model %>.last.to_param}") end it "should create a <%= @singular %>" do assert_equal @<%= @singular %>_count + 1, <%= @model %>.count end end # END POST create # START GET edit describe "GET edit" do before do @<%= @singular %> = <%= @model %>.make! get "/admin/<%= @pluralized %>/edit/#{@<%= @singular %>.to_param}" end it "should display the <%= @pluralized %> edit page" do assert ok? assert_equal 200, status assert_equal "/admin/<%= @pluralized %>/edit/#{@<%= @singular %>.to_param}", path end end # END GET edit # START PUT update describe "PUT update" do before do @<%= @singular %> = <%= @model %>.make! @<%= @singular %>_count = <%= @model %>.count put "/admin/<%= @pluralized %>/update/#{@<%= @singular %>.to_param}", :<%= @singular %> => <%= @model %>.make.attributes @<%= @singular %>.reload end it "should redirect to the edit page" do assert_equal 302, status assert location.include?("/admin/<%= @pluralized %>/edit/#{@<%= @singular %>.to_param}") end it "should not create a new a <%= @singular %>" do assert_equal @<%= @singular %>_count, <%= @model %>.count end end # END PUT update # START DELETE destroy describe "DELETE destroy" do before do @<%= @singular %> = <%= @model %>.make! @<%= @singular %>_count = <%= @model %>.count delete "/admin/<%= @pluralized %>/destroy/#{@<%= @singular %>.to_param}" end it "should redirect to the index page" do assert_equal 302, status end it "should destroy a <%= @singular %>" do assert_equal @<%= @singular %>_count - 1, <%= @model %>.count end end # END DELETE destroy end # END LOGGED IN end