pages_controller_spec.rb
上传用户:netsea168
上传日期:2022-07-22
资源大小:4652k
文件大小:2k
- require File.dirname(__FILE__) + '/../../spec_helper'
- describe Admin::PagesController do
- before do
- request.session = { :user => users(:tobi).id }
- end
- describe '#index' do
- it 'should response success' do
- get :index
- response.should be_success
- assert_template 'index'
- assert_not_nil assigns(:pages)
- end
- it 'should response success with :page args' do
- get :index, :page => 1
- response.should be_success
- assert_template 'index'
- assert_not_nil assigns(:pages)
- end
- end
- it "test_show" do
- get :show, :id => contents(:first_page).id
- assert_response :success
- assert_template "show"
- assert_not_nil assigns(:page)
- assert_equal contents(:first_page), assigns(:page)
- end
- it "test_new" do
- get :new
- assert_response :success
- assert_template "new"
- assert_not_nil assigns(:page)
- assert_equal users(:tobi), assigns(:page).user
- assert_equal TextFilter.find_by_name(this_blog.text_filter), assigns(:page).text_filter
- post :new, :page => { :name => "new_page", :title => "New Page Title",
- :body => "Emphasis _mine_, arguments *strong*" }
- new_page = Page.find(:first, :order => "id DESC")
- assert_equal "new_page", new_page.name
- assert_response :redirect, :action => "show", :id => new_page.id
- # XXX: The flash is currently being made available improperly to tests (scoop)
- #assert_equal "Page was successfully created.", flash[:notice]
- end
- it "test_edit" do
- get :edit, :id => contents(:markdown_page).id
- assert_response :success
- assert_template "edit"
- assert_not_nil assigns(:page)
- assert_equal contents(:markdown_page), assigns(:page)
- post :edit, :id => contents(:markdown_page).id, :page => { :name => "markdown-page", :title => "Markdown Page",
- :body => "Adding a [link](http://www.typosphere.org/) here" }
- assert_response :redirect, :action => "show", :id => contents(:markdown_page).id
- # XXX: The flash is currently being made available improperly to tests (scoop)
- #assert_equal "Page was successfully updated.", flash[:notice]
- end
- it "test_destroy" do
- post :destroy, :id => contents(:another_page).id
- assert_response :redirect, :action => "list"
- assert_raise(ActiveRecord::RecordNotFound) { Page.find(contents(:another_page).id) }
- end
- end