aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuc Donnet2015-01-16 12:43:50 +0100
committerLuc Donnet2015-01-16 12:43:50 +0100
commit4ce59945a30c29a3347c145e57fa496d55de1bfb (patch)
tree82bcc5330f4228a1ee611774b935a4d50713f340 /spec
parent834f8c18bd62d5fa60d6ff32a1f5470e477fbbcd (diff)
downloadchouette-core-4ce59945a30c29a3347c145e57fa496d55de1bfb.tar.bz2
Add spec for devise and upgrade versions of devise views
Diffstat (limited to 'spec')
-rw-r--r--spec/features/users/sign_in_spec.rb54
-rw-r--r--spec/features/users/sign_out_spec.rb26
-rw-r--r--spec/support/helpers/session_helpers.rb21
3 files changed, 93 insertions, 8 deletions
diff --git a/spec/features/users/sign_in_spec.rb b/spec/features/users/sign_in_spec.rb
new file mode 100644
index 000000000..f6cd1caf4
--- /dev/null
+++ b/spec/features/users/sign_in_spec.rb
@@ -0,0 +1,54 @@
+require 'spec_helper'
+
+# 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
+ # Given I do not exist as a user
+ # When I sign in with valid credentials
+ # Then I see an invalid credentials message
+ scenario 'user cannot sign in if not registered' do
+ signin('test@example.com', 'please123')
+ expect(page).to have_content I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'email'
+ 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' do
+ user = create(:user)
+ user.confirm!
+ 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' do
+ user = create(:user)
+ user.confirm!
+ signin('invalid@email.com', user.password)
+ expect(page).to have_content I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'email'
+ 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' do
+ user = create(:user)
+ user.confirm!
+ signin(user.email, 'invalidpass')
+ expect(page).to have_content I18n.t 'devise.failure.invalid', authentication_keys: 'email'
+ end
+
+end
diff --git a/spec/features/users/sign_out_spec.rb b/spec/features/users/sign_out_spec.rb
new file mode 100644
index 000000000..91310089c
--- /dev/null
+++ b/spec/features/users/sign_out_spec.rb
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+require 'spec_helper'
+
+# 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' do
+ user = FactoryGirl.create(:user)
+ user.confirm!
+ signin(user.email, user.password)
+ expect(page).to have_content I18n.t 'devise.sessions.signed_in'
+ click_link user.name
+ click_link 'Déconnexion'
+ expect(page).to have_content I18n.t 'devise.sessions.signed_out'
+ end
+
+end
+
+
diff --git a/spec/support/helpers/session_helpers.rb b/spec/support/helpers/session_helpers.rb
index 14f3747ba..b92c5f0a1 100644
--- a/spec/support/helpers/session_helpers.rb
+++ b/spec/support/helpers/session_helpers.rb
@@ -2,18 +2,23 @@ module Features
module SessionHelpers
def sign_up_with(email, password, confirmation)
visit new_user_session_path
- fill_in '#registration_new #user_email', with: email
- fill_in 'Password', with: password
- fill_in 'Password confirmation', :with => confirmation
- click_button 'Sign up'
+ within(".registration_new") do
+ fill_in 'user_organisation_attributes_name', with: "Cityway"
+ fill_in 'user_name', with: "User"
+ fill_in 'user_email', with: email
+ fill_in 'user_password', with: password
+ fill_in 'user_password_confirmation', :with => confirmation
+ end
+ click_button 'S\'inscrire'
end
def signin(email, password)
visit new_user_session_path
- # save_and_open_page
- fill_in '#session_new #user_email', with: email
- fill_in 'Password', with: password
- click_button 'Sign in'
+ within(".session_new") do
+ fill_in 'user_email', with: email
+ fill_in 'user_password', with: password
+ end
+ click_button 'Se connecter'
end
end
end