added some specs
This commit is contained in:
parent
097041c8d2
commit
05334e3bd0
|
@ -13,6 +13,6 @@ _paq.push(['setDocumentTitle', document.title]);
|
|||
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
||||
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
|
||||
})();
|
||||
<% else %>
|
||||
<% elsif !Rails.env.test? %>
|
||||
console.log("i track'd ur bich");
|
||||
<% end %>
|
|
@ -0,0 +1,6 @@
|
|||
FactoryGirl.define do
|
||||
factory :answer do |u|
|
||||
u.sequence(:content) { |n| "This is an answer. I'm number #{n}!" }
|
||||
u.user FactoryGirl.create(:user)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
FactoryGirl.define do
|
||||
factory :question do |u|
|
||||
u.sequence(:content) { |n| "#{QuestionGenerator.generate}#{n}" }
|
||||
u.author_is_anonymous true
|
||||
end
|
||||
end
|
|
@ -0,0 +1,43 @@
|
|||
include Warden::Test::Helpers
|
||||
Warden.test_mode!
|
||||
|
||||
# Feature: Ban users
|
||||
# As a user
|
||||
# I want to get banned
|
||||
# So I can't sign in anymore
|
||||
feature "Ban users", :devise do
|
||||
|
||||
after :each do
|
||||
Warden.test_reset!
|
||||
end
|
||||
|
||||
# Scenario: User gets banned
|
||||
# Given I am signed in
|
||||
# When I visit another page
|
||||
# And I am banned
|
||||
# Then I see the sign in page
|
||||
scenario "user gets banned", js: true do
|
||||
me = FactoryGirl.create :user
|
||||
|
||||
login_as me, scope: :user
|
||||
visit root_path
|
||||
expect(page).to have_text("Timeline")
|
||||
page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_1.png"), full: true
|
||||
|
||||
me.banned = true
|
||||
me.save
|
||||
click_link "Inbox"
|
||||
expect(current_path).to eq(new_user_session_path)
|
||||
page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_2.png"), full: true
|
||||
end
|
||||
|
||||
scenario 'user visits banned user profiles', js: true do
|
||||
evil_user = FactoryGirl.create :user
|
||||
evil_user.banned = true
|
||||
evil_user.save
|
||||
|
||||
visit show_user_profile_path(evil_user.screen_name)
|
||||
expect(page).to have_text('Banned'.upcase)
|
||||
page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_3.png"), full: true
|
||||
end
|
||||
end
|
|
@ -0,0 +1,124 @@
|
|||
include Warden::Test::Helpers
|
||||
Warden.test_mode!
|
||||
|
||||
# Feature: Answer questions
|
||||
# As a user
|
||||
# I want to go to the inbox
|
||||
# So I can answer and get new questions
|
||||
feature "Inbox", :devise do
|
||||
|
||||
after :each do
|
||||
Warden.test_reset!
|
||||
end
|
||||
|
||||
# Scenario: User answers a question
|
||||
# Given I am signed in
|
||||
# When I visit the inbox
|
||||
# And I have a question in my inbox
|
||||
# Then I can answer my question
|
||||
# And see the answer on my user profile
|
||||
scenario "user answers a question", js: true do
|
||||
me = FactoryGirl.create :user
|
||||
question = FactoryGirl.create :question
|
||||
Inbox.create question: question, user: me, new: true
|
||||
|
||||
login_as me, scope: :user
|
||||
visit root_path
|
||||
expect(page).to have_text('1 new question')
|
||||
page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_1.png"), full: true
|
||||
|
||||
click_link "Inbox"
|
||||
expect(page).to have_text(question.content)
|
||||
fill_in "ib-answer", with: Faker::Lorem.sentence
|
||||
page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_2.png"), full: true
|
||||
|
||||
click_button "Answer"
|
||||
wait_for_ajax
|
||||
expect(page).not_to have_text(question.content)
|
||||
page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_3.png"), full: true
|
||||
|
||||
visit show_user_profile_path(me.screen_name)
|
||||
expect(page).to have_text(question.content)
|
||||
page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_4.png"), full: true
|
||||
end
|
||||
|
||||
# Scenario: User generates new question
|
||||
# Given I am signed in
|
||||
# When I visit the inbox
|
||||
# And I click "Get new question"
|
||||
# Then I get a new question
|
||||
scenario 'user generates new question', js: true do
|
||||
me = FactoryGirl.create :user
|
||||
|
||||
login_as me, scope: :user
|
||||
visit inbox_path
|
||||
page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_1.png"), full: true
|
||||
|
||||
click_button "Get new question"
|
||||
wait_for_ajax
|
||||
expect(page).to have_text('Answer'.upcase)
|
||||
page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_2.png"), full: true
|
||||
end
|
||||
|
||||
=begin
|
||||
# Scenario: User deletes a question
|
||||
# Given I am signed in
|
||||
# When I visit the inbox
|
||||
# And I have a question in my inbox
|
||||
# And I delete the question
|
||||
# Then don't see it anymore in my inbox
|
||||
scenario "user deletes a question", js: true do
|
||||
me = FactoryGirl.create :user
|
||||
question = FactoryGirl.create :question
|
||||
Inbox.create question: question, user: me
|
||||
|
||||
login_as me, scope: :user
|
||||
visit inbox_path
|
||||
expect(page).to have_text(question.content)
|
||||
|
||||
click_button "Delete"
|
||||
expect(page).to have_text('Really delete?')
|
||||
page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_1.png"), full: true
|
||||
|
||||
# this apparently doesn't get triggered :(
|
||||
page.find('.sweet-alert').click_button 'Delete'
|
||||
wait_for_ajax
|
||||
|
||||
visit root_path
|
||||
visit inbox_path
|
||||
expect(page).not_to have_text(question.content)
|
||||
page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_2.png"), full: true
|
||||
end
|
||||
|
||||
# Scenario: User deletes all questions
|
||||
# Given I am signed in
|
||||
# When I visit the inbox
|
||||
# And I have a few questions in my inbox
|
||||
# And I click on "Delete all questions"
|
||||
# Then don't see them anymore in my inbox
|
||||
scenario "user deletes all questions", js: true do
|
||||
me = FactoryGirl.create :user
|
||||
5.times do
|
||||
question = FactoryGirl.create :question
|
||||
Inbox.create question: question, user: me
|
||||
end
|
||||
|
||||
login_as me, scope: :user
|
||||
visit inbox_path
|
||||
expect(page).to have_text('Answer'.upcase)
|
||||
|
||||
click_button "Delete all questions"
|
||||
expect(page).to have_text('Really delete 5 questions?')
|
||||
page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_1.png"), full: true
|
||||
|
||||
# this apparently doesn't get triggered :(
|
||||
page.find('.sweet-alert').click_button 'Delete'
|
||||
wait_for_ajax
|
||||
|
||||
visit root_path
|
||||
visit inbox_path
|
||||
page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_2.png"), full: true
|
||||
expect(page).not_to have_text('Answer'.upcase)
|
||||
end
|
||||
=end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Answer, :type => :model do
|
||||
before :each do
|
||||
@answer = Answer.new(
|
||||
content: 'This is an answer.',
|
||||
user: FactoryGirl.create(:user),
|
||||
question: FactoryGirl.create(:question)
|
||||
)
|
||||
end
|
||||
|
||||
subject { @answer }
|
||||
|
||||
it { should respond_to(:content) }
|
||||
|
||||
it '#content returns a string' do
|
||||
expect(@answer.content).to match 'This is an answer.'
|
||||
end
|
||||
end
|
|
@ -0,0 +1,35 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Question, :type => :model do
|
||||
before :each do
|
||||
@question = Question.new(
|
||||
content: 'Is this a question?',
|
||||
user: FactoryGirl.create(:user)
|
||||
)
|
||||
end
|
||||
|
||||
subject { @question }
|
||||
|
||||
it { should respond_to(:content) }
|
||||
|
||||
it '#content returns a string' do
|
||||
expect(@question.content).to match 'Is this a question?'
|
||||
end
|
||||
|
||||
it 'does not save questions longer than 255 characters' do
|
||||
@question.content = 'X' * 256
|
||||
expect{@question.save!}.to raise_error(ActiveRecord::RecordInvalid)
|
||||
end
|
||||
|
||||
it 'has many answers' do
|
||||
5.times { |i| Answer.create(content: "This is an answer. #{i}", user: FactoryGirl.create(:user), question: @question) }
|
||||
expect(@question.answer_count).to match 5
|
||||
end
|
||||
|
||||
it 'also deletes the answers when deleted' do
|
||||
5.times { |i| Answer.create(content: "This is an answer. #{i}", user: FactoryGirl.create(:user), question: @question) }
|
||||
first_answer_id = @question.answers.first.id
|
||||
@question.destroy
|
||||
expect{Answer.find(first_answer_id)}.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue