Created
January 26, 2016 20:40
-
-
Save EngineeredEdge/2a67e99e1f2cf280148b to your computer and use it in GitHub Desktop.
rspec for categories controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe Admin::CategoriesController do | |
render_views | |
before(:each) do | |
Factory(:blog) | |
#TODO Delete after removing fixtures | |
Profile.delete_all | |
henri = Factory(:user, :login => 'henri', :profile => Factory(:profile_admin, :label => Profile::ADMIN)) | |
request.session = { :user => henri.id } | |
end | |
it "test_index" do | |
get :index | |
assert_response :redirect, :action => 'index' | |
end | |
describe 'new category without id' do | |
before(:each) do | |
get :new | |
end | |
it 'should be success' do | |
response.should be_success | |
end | |
it 'should render template new' do | |
response.should render_template('new') | |
end | |
end | |
describe "test_edit" do | |
before(:each) do | |
get :edit, :id => Factory(:category).id | |
end | |
it 'should render template new' do | |
assert_template 'new' | |
assert_tag :tag => "table", | |
:attributes => { :id => "category_container" } | |
end | |
it 'should have valid category' do | |
assigns(:category).should_not be_nil | |
assert assigns(:category).valid? | |
assigns(:categories).should_not be_nil | |
end | |
end | |
it "test_update" do | |
post :edit, :id => Factory(:category).id | |
assert_response :redirect, :action => 'index' | |
end | |
describe "test_destroy with GET" do | |
before(:each) do | |
test_id = Factory(:category).id | |
assert_not_nil Category.find(test_id) | |
get :destroy, :id => test_id | |
end | |
it 'should render destroy template' do | |
assert_response :success | |
assert_template 'destroy' | |
end | |
end | |
it "test_destroy with POST" do | |
test_id = Factory(:category).id | |
assert_not_nil Category.find(test_id) | |
get :destroy, :id => test_id | |
post :destroy, :id => test_id | |
assert_response :redirect, :action => 'index' | |
assert_raise(ActiveRecord::RecordNotFound) { Category.find(test_id) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment