added a few more specs

This commit is contained in:
nilsding 2014-12-07 12:42:03 +01:00
parent 1f8de9cd78
commit be78c449a0
4 changed files with 119 additions and 11 deletions

View File

@ -1,8 +1,8 @@
FactoryGirl.define do FactoryGirl.define do
factory :user do |u| factory :user do |u|
u.screen_name { Faker::Internet.user_name 0..16, %w(_) } u.sequence(:screen_name) { |n| "#{Faker::Internet.user_name 0..12, %w(_)}#{n}" }
u.email { Faker::Internet.email } u.sequence(:email) { |n| "#{n}#{Faker::Internet.email}" }
u.password { "P4s5w0rD" } u.password "P4s5w0rD"
u.display_name { Faker::Name.name } u.display_name { Faker::Name.name }
end end
end end

View File

@ -0,0 +1,45 @@
# Feature: Sign in
# As a user
# I want to sign in
# So I can visit protected areas of the site
feature 'Sign in', :devise do
scenario 'user cannot sign in if not registered', js: true do
user = FactoryGirl.build(:user)
signin(user.screen_name, user.password)
expect(page).to have_content I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'login'
end
# Scenario: User can sign in with valid credentials
# Given I exist as a user
# And I am not signed in
# When I sign in with valid credentials
# Then I see a success message
scenario 'user can sign in with valid credentials', js: true do
user = FactoryGirl.create(:user)
signin(user.email, user.password)
expect(page).to have_content I18n.t 'devise.sessions.signed_in'
end
# Scenario: User cannot sign in with wrong email
# Given I exist as a user
# And I am not signed in
# When I sign in with a wrong email
# Then I see an invalid email message
scenario 'user cannot sign in with wrong email', js: true do
user = FactoryGirl.create(:user)
signin('invalid@email.com', user.password)
expect(page).to have_content I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'login'
end
# Scenario: User cannot sign in with wrong password
# Given I exist as a user
# And I am not signed in
# When I sign in with a wrong password
# Then I see an invalid password message
scenario 'user cannot sign in with wrong password', js: true do
user = FactoryGirl.create(:user)
signin(user.email, 'what the fuck is my p4s5w0rD again?')
expect(page).to have_content I18n.t 'devise.failure.invalid', authentication_keys: 'login'
end
end

View File

@ -0,0 +1,19 @@
# Feature: Sign out
# As a user
# I want to sign out
# So I can protect my account from unauthorized access
feature 'Sign out', :devise do
# Scenario: User signs out successfully
# Given I am signed in
# When I sign out
# Then I see a signed out message
scenario 'user signs out successfully', js: true do
user = FactoryGirl.create(:user)
signin(user.email, user.password)
expect(page).to have_content I18n.t 'devise.sessions.signed_in'
click_link user.screen_name
click_link 'Logout'
expect(page).to have_content I18n.t 'devise.sessions.signed_out'
end
end

View File

@ -1,20 +1,64 @@
require 'rails_helper' include Warden::Test::Helpers
Warden.test_mode!
feature "User", :type => :feature do # Feature: User profile page
before do # As a user
@user1 = create(:user) # I want to visit my user profile page
@user2 = create(:user) # So I can see my personal account data
feature "User profile page", :devise do
after :each do
Warden.test_reset!
end end
scenario "gets asked a question", js: true do # Scenario: User sees own profile
visit "/@#{@user1.screen_name}" # Given I am signed in
# When I visit the user profile page
# Then I see my own screen name and follower count
scenario 'user sees own profile', js: true do
user = FactoryGirl.create(:user)
login_as(user, :scope => :user)
visit show_user_profile_path(user.screen_name)
expect(page).to have_content user.screen_name
expect(page).to have_content user.follower_count
end
# Scenario: User sees another user's profile
# Given I am signed in
# When I visit another user's profile
# Then I see that user's screen name and follower count
scenario "user sees another user's profile", js: true do
me = FactoryGirl.create(:user)
other = FactoryGirl.create(:user)
login_as me, scope: :user
visit show_user_profile_path(other.screen_name)
expect(page).to have_content other.screen_name
expect(page).to have_content other.follower_count
end
# Scenario: User gets asked a question
# Given I am signed in
# When I visit another user's profile
# And I fill something in the question box
# And I click on "Ask"
# Then I see "Question asked successfully."
scenario "user gets asked a question", js: true do
me = FactoryGirl.create(:user)
other = FactoryGirl.create(:user)
login_as me, scope: :user
visit show_user_profile_path(other.screen_name)
page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_1.png"), full: true page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_1.png"), full: true
fill_in "qb-question", with: Faker::Lorem.sentence fill_in "qb-question", with: Faker::Lorem.sentence
click_button "Ask" click_button "Ask"
wait_for_ajax wait_for_ajax
page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_2.png"), full: true page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_2.png"), full: true
expect(page).to have_text("Question asked successfully.") expect(page).to have_text("Question asked successfully.")