comments_test.rb revision a5015ca9daa067f062e9e373c3dfafd5631560d9
0N/Arequire 'integration_test_helper'
2362N/A
0N/Aclass CommentsTest < ActionController::IntegrationTest
0N/A
0N/A setup do
0N/A @ontology = FactoryGirl.create(:ontology_version).ontology
2362N/A @ontology.state = 'done'
0N/A @ontology.save
2362N/A @user = FactoryGirl.create :user
0N/A
0N/A # Add user as owner to the ontology
0N/A FactoryGirl.create :permission, subject: @user, item: @ontology.repository
0N/A login_as @user, :scope => :user
0N/A end
0N/A
0N/A test 'create a comment' do
0N/A comment_text = 'very loooooooong comment'
0N/A
0N/A visit ontology_comments_path(@ontology)
0N/A find_link "Log out"
2362N/A
2362N/A # zero comments at the beginning
2362N/A assert_equal 0, all('.comments > ol > li').count
0N/A
0N/A within '#new_comment' do
0N/A # fill in the autocomplete input
0N/A fill_in 'Text', with: 'Lorem'
0N/A click_button 'Create Comment'
0N/A end
0N/A
0N/A # is the text too short?
0N/A assert_equal "is too short (minimum is 10 characters)", find(".help-inline").text
0N/A
0N/A within '#new_comment' do
0N/A # fill in the autocomplete input
0N/A fill_in 'Text', with: comment_text
0N/A click_button 'Create Comment'
0N/A end
0N/A
0N/A # wait for the comment to be inserted
0N/A comment_li = find '.comments > ol > li'
0N/A
0N/A # success message
0N/A assert_equal "Thanks for your comment.", find("#new_comment").text
0N/A
0N/A # author and timestamp
0N/A assert_match /#{@user.to_s} wrote a few seconds ago/, comment_li.text
0N/A
0N/A # comment text
0N/A assert comment_li.text.include?(comment_text)
0N/A end
0N/A
test 'delete a comment' do
comment = FactoryGirl.create :comment, commentable: @ontology
visit ontology_comments_path(@ontology)
# does one comment exist?
assert_equal 1, all('.comments > ol > li').count
within '.comments' do
# delete the comment
click_link 'delete'
end
# is the comment deleted?
assert page.has_no_css?('.comments > ol > li')
end
end