I18n support for cukes. Use i18n for labels login, register and 'forgot password'.

pull/1270/head
Markus Kahl 11 years ago
parent 08a0b5e18c
commit ca256f28a7
  1. 89
      config/initializers/i18n_in_cukes.rb
  2. 6
      config/locales/en.yml
  3. 4
      features/session/user_session.feature
  4. 2
      features/support/login_steps.rb
  5. 2
      features/users/lost_password.feature
  6. 8
      features/users/user_auth.feature
  7. 2
      features/users/user_registration.feature

@ -0,0 +1,89 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
##
# The following bit of code patches rspec to accept i18n codes in all finders and when looking for text.
# This way labels don't have to be hardcoded which means they can be changed without breaking tests.
# Examples:
#
# Given I click on "t:account.delete"
# When I follow "t:label_register"
# And I press "t:button_login"
#
# Where the i18n file contains the following:
#
# en:
# label_register: "Sign up"
# label_button_login: "Sign in"
#
# account:
# delete: "Delete account"
#
if Rails.env.test?
require 'capybara'
require 'capybara/rspec/matchers'
Capybara::Node::Finders.module_eval do
def find_with_i18n(*args)
i18n = args[1]
if args.size >= 2 && i18n.is_a?(String) && i18n =~ /^t:[^\s]/
begin
args[1] = I18n.t(i18n.split(":").last)
find_without_i18n(*args)
rescue Capybara::ElementNotFound
# perhaps it was not intended to be an i18n code after all
args[1] = i18n
find_without_i18n(*args)
end
else
find_without_i18n(*args)
end
end
alias_method_chain :find, :i18n
end
Capybara::RSpecMatchers::HaveText.module_eval do
def matches_with_i18n?(actual)
if content.is_a?(String) && content =~ /^t:[^\s]/
i18n = content
@content = I18n.t(i18n.split(":").last)
matches_without_i18n?(actual) || begin
# perhaps it was not intended to be an i18n code after all
@content = i18n
matches_without_i18n?(actual)
end
else
matches_without_i18n?(actual)
end
end
alias_method_chain :matches?, :i18n
end
end

@ -359,7 +359,7 @@ en:
button_list: "List"
button_lock: "Lock"
button_log_time: "Log time"
button_login: "Login"
button_login: "Sign in"
button_move: "Move"
button_move_and_follow: "Move and follow"
button_quote: "Quote"
@ -804,7 +804,7 @@ en:
label_overall_activity: "Overall activity"
label_overall_spent_time: "Overall spent time"
label_overview: "Overview"
label_password_lost: "Lost password"
label_password_lost: "Forgot your password?"
label_password_rule_lowercase: "Lowercase"
label_password_rule_numeric: "Numeric Characters"
label_password_rule_special: "Special Characters"
@ -838,7 +838,7 @@ en:
label_query_plural: "Custom queries"
label_query_menu_item: "Query menu item"
label_read: "Read..."
label_register: "Register"
label_register: "Create a new account"
label_register_with_developer: "Register as developer"
label_registered_on: "Registered on"
label_registration_activation_by_email: "account activation by email"

@ -36,7 +36,7 @@ Feature: User session
Then I should be on the login page
When I fill in "bob" for "username" within "#login-form"
And I fill in "adminADMIN!" for "password" within "#login-form"
And I click on "Login" within "#login-form"
And I click on "t:button_login" within "#login-form"
And I go to the my account page
Then I should be on the my account page
@ -45,7 +45,7 @@ Feature: User session
Then I should be on the login page
When I fill in "bob" for "username" within "#login-form"
And I fill in "adminADMIN!" for "password" within "#login-form"
And I click on "Login" within "#login-form"
And I click on "t:button_login" within "#login-form"
Then I should be on the my account page
Scenario: Autologin works if enabled

@ -34,7 +34,7 @@ module LoginSteps
within('#login-form') do
fill_in User.human_attribute_name(:login), :with => login
fill_in 'Password', :with => password
click_button 'Login'
click_button 't:button_login'
end
end
end

@ -37,7 +37,7 @@ Feature: Lost Password
Scenario: Set a new password using lost password link
And I am on the login page
When I follow "Lost password" within "#login-form"
When I follow "t:label_password_lost" within "#login-form"
And I fill in "johndoe@example.com" for "Email"
And I press "Submit"
Then I should see "has been sent to you"

@ -49,7 +49,7 @@
Feature: User Authentication
@javascript
@javascript
Scenario: A user gets a error message if the false credentials are filled in
Given I am logged in as "joe"
Then I should see "Invalid user or password"
@ -58,14 +58,14 @@ Then I should see "Invalid user or password"
Scenario: A user is able to login successfully with provided credentials
Given I am on the login page
And I am admin
Then I should see "Admin" within "#top-menu-items"
Then I should see "Admin" within "#top-menu-items"
@javascript
Scenario: Lost password notification mail will not be sent in case incorrect mail is given
Given I am on the login page
And I open the "Openproject Admin" menu
And I follow "Lost password" within "#login-form"
And I follow "t:label_password_lost" within "#login-form"
Then I should be on the lost password page
And I fill in "mail" with "bilbo@shire.com"
And I click on "Submit"
Then I should see "Unknown user"
Then I should see "Unknown user"

@ -51,7 +51,7 @@ Feature: User Registration
Background:
Given I am on the homepage
And I open the "Sign in" menu
And I follow "Register" within "#top-menu-items"
And I follow "t:label_register" within "#top-menu-items"
Then I should be on the registration page
Scenario: A user can register successfully after filling in the registration form

Loading…
Cancel
Save