comments_controller_spec.rb revision b8a8f5a9b535f39bf9f1b00ec2983bd610bb2373
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomirequire 'spec_helper'
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomidescribe CommentsController do
f49f1c5fa6a9a55a194e5ada042df134907278f4Aki Tuomi
f49f1c5fa6a9a55a194e5ada042df134907278f4Aki Tuomi let(:ontology){ create :ontology }
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi let(:repository){ ontology.repository }
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi let(:user){ create :user }
285bfe946c2d54928b272270dd5eef9041b24271Timo Sirainen
b3a968f434cbb9e374ea3da0a7d493e20231a4aeAki Tuomi context 'not signed in' do
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi context 'on GET to index' do
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi context 'without comment' do
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi before do
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi get :index, :ontology_id => ontology.to_param, :repository_id => repository.to_param
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi end
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi it{ should respond_with :success }
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi it{ should render_template 'comments/index' }
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi end
cd24dc2196f7480d4793ca5d5f9f8d70741bc103Aki Tuomi
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi context 'with comment' do
452d0005a47c6872590346f5ea8b247974689ac9Aki Tuomi before do
c6108c1bfa10d5fcd1def9c6a23ebcd5204d1775Timo Sirainen comment = create :comment, :commentable => ontology
345f36ebc7dd445cfa3dbf157342d110cc74d7c7Aki Tuomi get :index, :ontology_id => ontology.to_param, :repository_id => repository.to_param
c6108c1bfa10d5fcd1def9c6a23ebcd5204d1775Timo Sirainen end
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi it{ should respond_with :success }
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi it{ should render_template 'comments/index' }
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi end
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi end
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi end
17fbd200b78112bd0d89e89598aa01cea72a74e5Martti Rannanjärvi
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi context 'signed in' do
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi before do
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi sign_in user
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi end
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi context 'on GET to index' do
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi context 'without comment' do
de1c645a79d42c37dffb7f52e9c643b6251fdcd0Aki Tuomi before do
7c9a9ac8cd5652f0e12a24b07c8559a7be0f5554Timo Sirainen get :index, :ontology_id => ontology.to_param, :repository_id => repository.to_param
de1c645a79d42c37dffb7f52e9c643b6251fdcd0Aki Tuomi end
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi
7e1a69e513739a7c12e3c5ec53dff1eb01b90524Aki Tuomi it{ should respond_with :success }
7e1a69e513739a7c12e3c5ec53dff1eb01b90524Aki Tuomi it{ should render_template 'comments/index' }
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi end
149299c7d5136a8fb425ef3cf8953026a1358002Timo Sirainen
7e1a69e513739a7c12e3c5ec53dff1eb01b90524Aki Tuomi context 'with comment' do
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi before do
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi comment = create :comment, :commentable => ontology
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi get :index, :ontology_id => ontology.to_param, :repository_id => repository.to_param
ff95c6488eb3239654ed7fd51ed787a6b2c44506Timo Sirainen end
f089a10e4816e772992346c9837ec10db3894c65Timo Sirainen
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi it{ should respond_with :success }
ff95c6488eb3239654ed7fd51ed787a6b2c44506Timo Sirainen it{ should render_template 'comments/index' }
ff95c6488eb3239654ed7fd51ed787a6b2c44506Timo Sirainen end
ff95c6488eb3239654ed7fd51ed787a6b2c44506Timo Sirainen
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi context 'on POST to delete' do
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi before do
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi comment = create :comment, :commentable => ontology, :user => user
ff95c6488eb3239654ed7fd51ed787a6b2c44506Timo Sirainen xhr :delete, :destroy, :ontology_id => ontology.to_param, :repository_id => repository.to_param, :id => comment.id
86ad487452c763152f3ff4dd4650512f3cecdc55Aki Tuomi end
86ad487452c763152f3ff4dd4650512f3cecdc55Aki Tuomi
86ad487452c763152f3ff4dd4650512f3cecdc55Aki Tuomi it{ should respond_with :success }
b3a968f434cbb9e374ea3da0a7d493e20231a4aeAki Tuomi end
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi end
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi context 'on POST to create' do
ff95c6488eb3239654ed7fd51ed787a6b2c44506Timo Sirainen context 'with too short text' do
86ad487452c763152f3ff4dd4650512f3cecdc55Aki Tuomi before do
86ad487452c763152f3ff4dd4650512f3cecdc55Aki Tuomi xhr :post, :create,
86ad487452c763152f3ff4dd4650512f3cecdc55Aki Tuomi ontology_id: ontology.to_param,
b3a968f434cbb9e374ea3da0a7d493e20231a4aeAki Tuomi repository_id: repository.to_param,
316cbe323513a0f20d1cf519fe9405e231d633e2Aki Tuomi comment: {text: 'foo'}
end
it{ should respond_with :unprocessable_entity }
end
context 'with too enough text' do
before do
xhr :post, :create,
ontology_id: ontology.to_param,
repository_id: repository.to_param,
comment: {text: 'fooo baaaaaaaaaaaaaaar'}
end
it{ should respond_with :success }
end
end
end
end