Skip to content

Instantly share code, notes, and snippets.

@hrumhrumble
Created March 10, 2016 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrumhrumble/c64ab3ccb8b0f42ca4e7 to your computer and use it in GitHub Desktop.
Save hrumhrumble/c64ab3ccb8b0f42ca4e7 to your computer and use it in GitHub Desktop.
require 'rails_helper'
include Auth
feature 'Comments' do
let(:user) { create(:user) }
let(:comment) { build(:comment) }
context 'User' do
before(:each) { sign_in(user) }
scenario 'can add comments to question', js: true do
question = create(:question, user: user)
visit question_path(question)
add_comment(comment.content)
within '.comments' do
expect(page).to have_content(user.name)
expect(page).to have_content(comment.content)
end
end
scenario 'can add comments to posts', js: true do
post = create(:post)
visit category_post_path(post.category, post)
add_comment(comment.content)
within '.comments' do
expect(page).to have_content(user.name)
expect(page).to have_content(comment.content)
end
end
scenario "can't add empty comments to question", js: true do
question = create(:question, user: user)
visit question_path(question)
add_comment('')
within '.comments' do
expect(page).to_not have_content(user.name)
expect(page).to_not have_content(comment.content)
end
end
scenario "can't add empty comments to posts", js: true do
category = create(:category)
post = create(:post, category: category)
visit category_post_path(category, post)
add_comment('')
within '.comments' do
expect(page).to_not have_content(user.name)
expect(page).to_not have_content(comment.content)
end
end
def add_comment(content)
page.execute_script("$('#content').focus()")
page.execute_script("$('#content').trumbowyg('html', '#{content}')")
find('input[type=submit]').click
end
end
context 'Guest' do
scenario "can't add comments to question" do
question = create(:question, user: user)
visit question_path(question)
expect(page).to_not have_selector('#content')
end
scenario "can't add comments to posts" do
category = create(:category)
post = create(:post, category: category)
visit category_post_path(category, post)
expect(page).to_not have_selector('#content')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment