diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 5e4a72f9..8ef9101e 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,8 +1,8 @@ FactoryGirl.define do factory :user do |u| - u.screen_name { Faker::Internet.user_name 0..16, %w(_) } - u.email { Faker::Internet.email } - u.password { "P4s5w0rD" } + u.sequence(:screen_name) { |n| "#{Faker::Internet.user_name 0..12, %w(_)}#{n}" } + u.sequence(:email) { |n| "#{n}#{Faker::Internet.email}" } + u.password "P4s5w0rD" u.display_name { Faker::Name.name } end end diff --git a/spec/features/users/sign_in_spec.rb b/spec/features/users/sign_in_spec.rb new file mode 100644 index 00000000..b4bfa3a3 --- /dev/null +++ b/spec/features/users/sign_in_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/features/users/sign_out_spec.rb b/spec/features/users/sign_out_spec.rb new file mode 100644 index 00000000..db7ec517 --- /dev/null +++ b/spec/features/users/sign_out_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/features/users/user_show_spec.rb b/spec/features/users/user_show_spec.rb index 4cf00539..c13fc750 100644 --- a/spec/features/users/user_show_spec.rb +++ b/spec/features/users/user_show_spec.rb @@ -1,20 +1,64 @@ -require 'rails_helper' +include Warden::Test::Helpers +Warden.test_mode! -feature "User", :type => :feature do - before do - @user1 = create(:user) - @user2 = create(:user) +# Feature: User profile page +# As a user +# I want to visit my user profile page +# So I can see my personal account data +feature "User profile page", :devise do + + after :each do + Warden.test_reset! end - scenario "gets asked a question", js: true do - visit "/@#{@user1.screen_name}" + # Scenario: User sees own profile + # 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 fill_in "qb-question", with: Faker::Lorem.sentence click_button "Ask" wait_for_ajax - page.driver.render Rails.root.join("tmp/#{Time.now.to_i}_2.png"), full: true expect(page).to have_text("Question asked successfully.")