aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Donnet2015-01-16 12:43:50 +0100
committerLuc Donnet2015-01-16 12:43:50 +0100
commit4ce59945a30c29a3347c145e57fa496d55de1bfb (patch)
tree82bcc5330f4228a1ee611774b935a4d50713f340
parent834f8c18bd62d5fa60d6ff32a1f5470e477fbbcd (diff)
downloadchouette-core-4ce59945a30c29a3347c145e57fa496d55de1bfb.tar.bz2
Add spec for devise and upgrade versions of devise views
-rw-r--r--Gemfile.lock2
-rw-r--r--app/views/devise/registrations/edit.html.erb29
-rw-r--r--app/views/devise/sessions/new.html.erb20
-rw-r--r--app/views/layouts/_user_links.erb23
-rw-r--r--app/views/shared/_flash_messages.erb2
-rw-r--r--app/views/shared/_header.erb2
-rw-r--r--config/initializers/devise.rb2
-rw-r--r--config/locales/devise.en.yml21
-rw-r--r--config/locales/devise.fr.yml26
-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
12 files changed, 159 insertions, 69 deletions
diff --git a/Gemfile.lock b/Gemfile.lock
index ceee048e2..0e1882d6d 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -124,7 +124,7 @@ GEM
warden (~> 1.2.3)
devise-encryptable (0.2.0)
devise (>= 2.1.0)
- devise-i18n (0.10.3)
+ devise-i18n (0.11.3)
devise_invitable (1.4.0)
actionmailer (>= 3.2.6, < 5)
devise (>= 3.2.0)
diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb
index c11b37893..95dcbf382 100644
--- a/app/views/devise/registrations/edit.html.erb
+++ b/app/views/devise/registrations/edit.html.erb
@@ -1,21 +1,24 @@
<%= title_tag t('.title') %>
-<%= semantic_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |form| %>
- <%= form.inputs do %>
- <% if resource.respond_to?( :name) %>
- <%= form.input :name %>
+<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
+ <%= f.error_notification %>
+
+ <div class="form-inputs">
+ <%= f.input :email, required: true, autofocus: true %>
+ <%= f.input :name, required: true %>
+
+ <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
+ <p>Currently waiting confirmation for: <%= resource.unconfirmed_email %></p>
<% end %>
- <%= form.input :email %>
- <%= form.input :password, :as => :password %>
- <%= form.input :password_confirmation, :as => :password %>
- <%= form.input :current_password, :as => :password, :required => true %>
- <% end %>
+ <%= f.input :password, autocomplete: "off", required: false %>
+ <%= f.input :password_confirmation, required: false %>
+ <%= f.input :current_password, required: true %>
+ </div>
- <%= form.actions do %>
- <%= form.action :submit, :as => :button, :label => t('.commit') %>
- <%= form.action :cancel, :as => :link %>
- <% end %>
+ <div class="form-actions">
+ <%= f.button :submit %>
+ </div>
<% end %>
<% content_for :sidebar do %>
diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb
index bac1ad2f5..f0a2a26f4 100644
--- a/app/views/devise/sessions/new.html.erb
+++ b/app/views/devise/sessions/new.html.erb
@@ -11,11 +11,11 @@
<div class="col-md-4 login">
<div class="panel panel-default">
<div class="panel-body">
- <%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), :wrapper => "form_without_label", :form_class => 'session_new' ) do |form| %>
- <%= form.input :email, :label => false, :placeholder => t("helpers.label.user.email"), input_html: { :class => "form-control" } %>
+ <%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), :wrapper => "form_without_label", html: { :class => 'session_new' } ) do |form| %>
+ <%= form.input :email, :label => false, input_html: { :class => "form-control" } %>
<div class="row">
<div class="col-md-6">
- <%= form.input :password, :as => :password, :label => false, :placeholder => t("helpers.label.user.password"), input_html: { :class => "form-control" } %>
+ <%= form.input :password, :as => :password, :label => false, input_html: { :class => "form-control" } %>
</div>
<div class="col-md-6">
<%= form.button :submit, t("devise.sessions.new.commit"), :class => "btn-primary" %>
@@ -24,7 +24,7 @@
<div class="row options">
<div class="col-md-6">
<% if devise_mapping.rememberable? %>
- <%= form.input :remember_me, :as => :boolean, :label => false, :inline_label => t("helpers.label.user.remember_me") if devise_mapping.rememberable? %>
+ <%= form.input :remember_me, :as => :boolean if devise_mapping.rememberable? %>
<% end %>
</div>
<div class="col-md-6 new_password">
@@ -39,16 +39,16 @@
<div class="panel panel-default">
<div class="panel-heading"><%= t("devise.registrations.new.title") %></div>
<div class="panel-body">
- <%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :wrapper => "form_without_label", input_html: { class: "registration_new" } ) do |form| %>
+ <%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :wrapper => "form_without_label", html: { class: "registration_new" } ) do |form| %>
<%= form.simple_fields_for :organisation, Organisation.new do |organisation| %>
- <%= organisation.input :name, :label => false, :placeholder => t("helpers.label.user.organisation_name"), input_html: { :class => "form-control" } %>
+ <%= organisation.input :name, :label => false, input_html: { :class => "form-control" } %>
<% end %>
<% if resource.respond_to?( :name) %>
- <%= form.input :name, :label => false, :placeholder => t("helpers.label.user.name"), input_html: { :class => "form-control" } %>
+ <%= form.input :name, :label => false, input_html: { :class => "form-control" } %>
<% end %>
- <%= form.input :email, :label => false, :placeholder => t("helpers.label.user.email"), input_html: { :class => "form-control" } %>
- <%= form.input :password, :as => :password, :label => false, :placeholder => t("helpers.label.user.password"), input_html: { :class => "form-control" } %>
- <%= form.input :password_confirmation, :as => :password, :label => false, :placeholder => t("helpers.label.user.password_confirmation"), input_html: { :class => "form-control" } %>
+ <%= form.input :email, :label => false, input_html: { :class => "form-control" } %>
+ <%= form.input :password, :as => :password, :label => false, input_html: { :class => "form-control" } %>
+ <%= form.input :password_confirmation, :as => :password, :label => false, input_html: { :class => "form-control" } %>
<%= form.button :submit, t("devise.registrations.new.commit"), :class => "btn-info" %>
<% end %>
diff --git a/app/views/layouts/_user_links.erb b/app/views/layouts/_user_links.erb
deleted file mode 100644
index 404f52172..000000000
--- a/app/views/layouts/_user_links.erb
+++ /dev/null
@@ -1,23 +0,0 @@
-<ul class="user">
- <li class="home"><%= link_to t('layouts.home'), root_path %></li>
-
- <% if user_signed_in? %>
- <li> | </li>
- <li><%= link_to t('layouts.user.profile'), edit_user_registration_path %></li>
- <li> | </li>
- <li><%= link_to t('layouts.user.sign_out'), destroy_user_session_path, :method => :delete %></li>
- <% end %>
-
- <li> | </li>
- <li class="<%= language_class('fr') %>"><%= link_to_language :fr %></li>
- <li class="<%= language_class('en') %>"><%= link_to_language :en %></li>
- <li>
- <% if user_signed_in? && !help_page? %>
- <li> | </li>
- <li>
- <%= link_to help_path , :target => "chouette_help" do %>
- <span class="help"><%= t('layouts.help') %></span>
- <% end %>
- </li>
- <% end %>
-</ul>
diff --git a/app/views/shared/_flash_messages.erb b/app/views/shared/_flash_messages.erb
index bad859aa9..871a92397 100644
--- a/app/views/shared/_flash_messages.erb
+++ b/app/views/shared/_flash_messages.erb
@@ -1,5 +1,5 @@
<% flash.each do |type, message| %>
- <div class="alert <%= bootstrap_class_for(type) %> fade in">
+ <div class="alert <%= bootstrap_class_for(type) %> fade in" role="alert">
<button class="close" data-dismiss="alert">×</button>
<%= flash_message_for type, message %>
</div>
diff --git a/app/views/shared/_header.erb b/app/views/shared/_header.erb
index 380f5b520..e0d4e9c92 100644
--- a/app/views/shared/_header.erb
+++ b/app/views/shared/_header.erb
@@ -85,7 +85,7 @@
<li><%= link_to t('layouts.help'), help_path, :class =>("current" if help_page?), :target => "chouette_help" %></li>
<% if user_signed_in? %>
<li class="dropdown">
- <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="gravatar"><%= user_gravatar_image_tag(current_user, 16) %></span><%= truncate(current_user.name, :length => 20) %> <b class="caret"></b></a>
+ <a href="#" class="dropdown-toggle user_admin" data-toggle="dropdown"><span class="gravatar"><%= user_gravatar_image_tag(current_user, 16) %></span><%= truncate(current_user.name, :length => 20) %> <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><%= link_to t('layouts.user.profile'), edit_user_registration_path %></li>
<li><%= link_to t('layouts.user.sign_out'), destroy_user_session_path, :method => :delete %></li>
diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb
index 8177839bd..ce309ca84 100644
--- a/config/initializers/devise.rb
+++ b/config/initializers/devise.rb
@@ -280,7 +280,7 @@ end
Rails.application.config.to_prepare do
Devise::SessionsController.layout "devise"
- Devise::RegistrationsController.layout proc{ |controller| ( action_name == "edit") ? "application" : "devise" }
+ Devise::RegistrationsController.layout proc{ |controller| ( action_name == "edit" || action_name == "update") ? "application" : "devise" }
Devise::ConfirmationsController.layout "devise"
Devise::UnlocksController.layout "devise"
Devise::PasswordsController.layout "devise"
diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml
index d5c545342..d4cf9c525 100644
--- a/config/locales/devise.en.yml
+++ b/config/locales/devise.en.yml
@@ -40,13 +40,28 @@ validating conformance of data wrt Neptune (French standard NFP 99 506)."
sign_up: "Sign up"
new_password: Forget your password ?
new_confirmation: "Didn't receive confirmation instructions?"
- helpers:
- label:
+ simple_form:
+ labels:
user:
email: "Email"
- organisation_name: "Organisation name"
+ organisation:
+ name: "Organisation name"
name: Full name
password: Password
password_confirmation: Password confirmation
current_password: Current password
remember_me: Remember me
+ hints:
+ user:
+ edit:
+ password: "Leave it blank if you don't want to change it"
+ current_password: "We need your current password to confirm your changes"
+ placeholders:
+ user:
+ email: "Email"
+ organisation:
+ name: "Organisation name"
+ name: Full name
+ password: Password
+ password_confirmation: Password confirmation
+ current_password: Current password
diff --git a/config/locales/devise.fr.yml b/config/locales/devise.fr.yml
index 929aa682a..5f4b5089a 100644
--- a/config/locales/devise.fr.yml
+++ b/config/locales/devise.fr.yml
@@ -1,11 +1,6 @@
# Additional translations for devise forms
fr:
- activerecord:
- attributes:
- user:
- password: Mot de passe
- password_confirmation: Confirmation du mot de passe
devise:
sessions:
new:
@@ -46,13 +41,28 @@ norme Neptune (NFP 99 506)"
sign_up: "S'inscrire"
new_password: "Mot de passe oublié?"
new_confirmation: "Vous n'avez pas reçu les instructions de confirmation ?"
- helpers:
- label:
+ simple_form:
+ labels:
user:
email: "Email"
- organisation_name: "Nom de l'organisation"
+ organisation:
+ name: "Nom de l'organisation"
name: Nom complet
password: Mot de passe
password_confirmation: Confirmation du mot de passe
current_password: Mot de passe actuel
remember_me: Se souvenir de moi
+ hints:
+ user:
+ edit:
+ password: 'Laissez le vide si vous ne voulez pas le changer'
+ current_password: "Nous avons besoin de votre mot de passe pour confirmer les changements"
+ placeholders:
+ user:
+ email: "Email"
+ organisation:
+ name: "Nom de l'organisation"
+ name: Nom complet
+ password: Mot de passe
+ password_confirmation: Confirmation du mot de passe
+ current_password: Mot de passe actuel
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