comments_controller_test.rb revision 38dab3b63e2730b443590a53de93e085659efe25
486N/Arequire 'test_helper'
486N/A
486N/Aclass CommentsControllerTest < ActionController::TestCase
486N/A
911N/A should route(:get, "/ontologies/ontology_id/comments").to(:controller=> :comments, :action => :index, :ontology_id => 'ontology_id')
851N/A should route(:post, "/ontologies/ontology_id/comments").to(:controller=> :comments, :action => :create, :ontology_id => 'ontology_id')
486N/A
486N/A context 'ontology' do
486N/A setup do
486N/A @ontology = FactoryGirl.create :ontology
486N/A @user = FactoryGirl.create :user
486N/A end
486N/A
486N/A context 'not signed in' do
486N/A
486N/A context 'on GET to index' do
486N/A context 'without comment' do
486N/A setup do
486N/A get :index, :ontology_id => @ontology.to_param
486N/A end
486N/A
486N/A should respond_with :success
486N/A should render_template 'comments/index'
486N/A end
486N/A
486N/A context 'with comment' do
486N/A setup do
486N/A @comment = FactoryGirl.create :comment, :commentable => @ontology
486N/A get :index, :ontology_id => @ontology.to_param
486N/A end
486N/A
486N/A should respond_with :success
486N/A should render_template 'comments/index'
486N/A end
486N/A end
493N/A end
486N/A
486N/A context 'signed in' do
493N/A
486N/A setup do
911N/A sign_in @user
911N/A end
911N/A
911N/A context 'on GET to index' do
486N/A context 'without comment' do
486N/A setup do
486N/A get :index, :ontology_id => @ontology.to_param
486N/A end
486N/A
486N/A should respond_with :success
493N/A should render_template 'comments/index'
493N/A end
493N/A
493N/A context 'with comment' do
486N/A setup do
851N/A @comment = FactoryGirl.create :comment, :commentable => @ontology
851N/A get :index, :ontology_id => @ontology.to_param
486N/A end
486N/A
486N/A should respond_with :success
851N/A should render_template 'comments/index'
851N/A end
context 'on POST to delete' do
setup do
@comment = FactoryGirl.create :comment, :commentable => @ontology, :user => @user
xhr :delete, :destroy, :ontology_id => @ontology.to_param, :id => @comment.id
end
should respond_with :success
end
end
context 'on POST to create' do
context 'with too short text' do
setup do
xhr :post, :create,
ontology_id: @ontology.to_param,
comment: {text: 'foo'}
end
should respond_with :unprocessable_entity
end
context 'with too enough text' do
setup do
xhr :post, :create,
ontology_id: @ontology.to_param,
comment: {text: 'fooo baaaaaaaaaaaaaaar'}
end
should respond_with :success
end
end
end
end
end