diff --git a/Gemfile b/Gemfile index a0e612360..d96ea4e03 100644 --- a/Gemfile +++ b/Gemfile @@ -51,6 +51,7 @@ group :development, :test do gem 'launchy' gem 'quiet_assets' gem 'letter_opener_web', '~> 1.2.0' + gem 'i18n-tasks' end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index e1390d4ab..bc4dd1e27 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -94,6 +94,10 @@ GEM docile (1.1.5) domain_name (0.5.24) unf (>= 0.0.5, < 1.0.0) + easy_translate (0.5.0) + json + thread + thread_safe erubis (2.7.0) execjs (2.5.2) factory_girl (4.5.0) @@ -106,9 +110,18 @@ GEM sass (>= 3.3.0, < 3.5) globalid (0.3.5) activesupport (>= 4.1.0) + highline (1.7.3) http-cookie (1.0.2) domain_name (~> 0.5) i18n (0.7.0) + i18n-tasks (0.8.6) + activesupport + easy_translate (>= 0.5.0) + erubis + highline + i18n + term-ansicolor + terminal-table (>= 1.5.1) jbuilder (2.3.1) activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) @@ -221,7 +234,9 @@ GEM sprockets (>= 2.8, < 4.0) term-ansicolor (1.3.2) tins (~> 1.0) + terminal-table (1.5.2) thor (0.19.1) + thread (0.2.2) thread_safe (0.3.5) tilt (1.4.1) tins (1.5.4) @@ -264,6 +279,7 @@ DEPENDENCIES devise factory_girl_rails foundation-rails + i18n-tasks jbuilder (~> 2.0) jquery-rails launchy @@ -283,4 +299,4 @@ DEPENDENCIES web-console (~> 2.0) BUNDLED WITH - 1.10.5 + 1.10.6 diff --git a/app/assets/images/auth_bg.jpg b/app/assets/images/auth_bg.jpg new file mode 100644 index 000000000..3dd6271a5 Binary files /dev/null and b/app/assets/images/auth_bg.jpg differ diff --git a/app/assets/images/logo_madrid_white.png b/app/assets/images/logo_madrid_white.png new file mode 100644 index 000000000..927514733 Binary files /dev/null and b/app/assets/images/logo_madrid_white.png differ diff --git a/app/assets/stylesheets/debates.scss b/app/assets/stylesheets/debates.scss index dfaf4629f..d8fabd59d 100644 --- a/app/assets/stylesheets/debates.scss +++ b/app/assets/stylesheets/debates.scss @@ -673,14 +673,45 @@ header { // 08.1. Login // - - - - - - - - - - - - +.auth-page { + background: url('auth_bg.jpg'); + margin-top: $line-height; + + @media (min-width: 480px) { + margin-top: $line-height*2; + } + + h1 { + + a { + color: white; + font-family: 'Lato'; + font-size: rem-calc(20); + font-weight: lighter; + line-height: $line-height*4; + padding-left: rem-calc(6); + + span { + font-size: rem-calc(16); + font-weight: lighter; + vertical-align: top; + } + + @media (min-width: 480px) { + font-size: rem-calc(30); + span { + font-size: rem-calc(20); + } + } + } + } +} + .auth { - background: $background; - box-shadow: 0px -4px 5px $background; min-height: $line-height*20; .panel { background: white; - margin-top: $line-height*2; h1 { font-size: rem-calc(30); @@ -725,7 +756,6 @@ form { } } - // 10. Alerts // - - - - - - - - - - - - - - - - - - - - - - - - - @@ -755,5 +785,3 @@ form { color: $alert-color; } } - - diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index fa626ece9..494068476 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -17,7 +17,7 @@ class AccountController < ApplicationController end def account_params - params.require(:account).permit(:first_name, :last_name) + params.require(:account).permit(:first_name, :last_name, :nickname, :use_nickname) end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ccf812e34..7551f3f1a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base respond_to :html before_action :set_locale + layout :set_layout # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. @@ -22,8 +23,17 @@ class ApplicationController < ActionController::Base I18n.locale = session[:locale] end + def set_layout + if devise_controller? + "devise" + else + "application" + end + end + def verify_captcha?(resource) return true unless recaptcha_keys? verify_recaptcha(model: resource) end + end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index c0113de42..4991cdf70 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -15,7 +15,7 @@ class RegistrationsController < Devise::RegistrationsController private def sign_up_params - params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation) + params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :use_nickname, :nickname) end -end \ No newline at end of file +end diff --git a/app/models/user.rb b/app/models/user.rb index 55f70bb2e..17573eaa7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,8 +4,12 @@ class User < ActiveRecord::Base acts_as_voter + validates :first_name, presence: true, unless: :use_nickname? + validates :last_name, presence: true, unless: :use_nickname? + validates :nickname, presence: true, if: :use_nickname? + def name - "#{first_name} #{last_name}" + use_nickname? ? nickname : "#{first_name} #{last_name}" end def votes_on_debates(debates_ids = []) diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index b3d45d967..da568a9b9 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -1,11 +1,20 @@

<%= t("account.show.title") %>

<%= form_for @account, as: :account, url: account_path do |f| %> + <%= f.label :first_name, t("account.show.first_name_label") %> <%= f.text_field :first_name %> <%= f.label :last_name, t("account.show.last_name_label") %> <%= f.text_field :last_name %> +
+ <%= f.check_box :use_nickname %> + <%= t("account.show.use_nickname_label") %> +
+ + <%= f.label :nickname, t("account.show.nickname_label") %> + <%= f.text_field :nickname %> + <%= f.submit t("account.show.save_changes_submit"), class: "button radius" %> <% end %> diff --git a/app/views/devise/confirmations/new.html.erb b/app/views/devise/confirmations/new.html.erb index 065ea4383..8379bfeb4 100644 --- a/app/views/devise/confirmations/new.html.erb +++ b/app/views/devise/confirmations/new.html.erb @@ -1,16 +1,24 @@ -

<%= t("devise_views.confirmations.title") %>

+
+
+
+

<%= t("devise_views.confirmations.title") %>

-<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> - <%= devise_error_messages! %> + <%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> + <%= devise_error_messages! %> -
- <%= f.label :email, t("devise_views.confirmations.email_label") %>
- <%= f.email_field :email, autofocus: true, value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> +
+
+ <%= f.label :email, t("devise_views.confirmations.email_label") %> + <%= f.email_field :email, autofocus: true, placeholder: t("devise_views.confirmations.email_label"), value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> +
+ +
+ <%= f.submit(t("devise_views.confirmations.submit"), class: "button radius expand") %> +
+
+ <% end %> + + <%= render "devise/shared/links" %> +
- -
- <%= f.submit(t("devise_views.confirmations.submit"), class: "button radius") %> -
-<% end %> - -<%= render "devise/shared/links" %> +
\ No newline at end of file diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb index 8a70d0362..b09e0435a 100644 --- a/app/views/devise/passwords/new.html.erb +++ b/app/views/devise/passwords/new.html.erb @@ -1,28 +1,22 @@ -
-
-
-
-

<%= t("devise_views.passwords.new.title") %>

+
+
+
+

<%= t("devise_views.passwords.new.title") %>

+ <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> + <%= devise_error_messages! %> +
+
+ <%= f.label :email, t("devise_views.passwords.new.email_label") %> + <%= f.email_field :email, autofocus: true, placeholder: t("devise_views.passwords.new.email_label") %> +
- <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> - <%= devise_error_messages! %> +
+ <%= f.submit t("devise_views.passwords.new.send_submit"), class: "button radius expand" %> +
+
+ <% end %> -
-
- <%= f.label :email, t("devise_views.passwords.new.email_label") %> - <%= f.email_field :email, autofocus: true, placeholder: t("devise_views.passwords.new.email_label") %> -
-
- -
-
- <%= f.submit t("devise_views.passwords.new.send_submit"), class: "button radius" %> -
-
- <% end %> - - <%= render "devise/shared/links" %> -
-
-
+ <%= render "devise/shared/links" %> +
+
\ No newline at end of file diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index ebeae271b..c7cd839a2 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -21,6 +21,20 @@
+
+
+ <%= f.check_box :use_nickname %> + <%= t("devise_views.registrations.new.use_nickname_label") %> +
+
+ +
+
+ <%= f.label :nickname, t("devise_views.registrations.new.nickname_label") %> + <%= f.text_field :nickname, placeholder: t("devise_views.registrations.new.nickname_label") %> +
+
+
<%= f.label :email, t("devise_views.registrations.new.email_label") %> @@ -58,4 +72,4 @@
- \ No newline at end of file + diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index fbe91ca68..1ff533073 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -1,42 +1,34 @@ -
-
-
-
-

<%= t("devise_views.sessions.new.title") %>

+
+
+
+

<%= t("devise_views.sessions.new.title") %>

- <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> -
-
- <%= f.label :email, t("devise_views.sessions.new.email_label") %> - <%= f.email_field :email, autofocus: true, placeholder: t("devise_views.sessions.new.email_label") %> -
-
+ <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> +
+
+ <%= f.label :email, t("devise_views.sessions.new.email_label") %> + <%= f.email_field :email, autofocus: true, placeholder: t("devise_views.sessions.new.email_label") %> +
-
-
- <%= f.label :password, t("devise_views.sessions.new.password_label") %> - <%= f.password_field :password, autocomplete: "off", placeholder: t("devise_views.sessions.new.password_label") %> -
-
+
+ <%= f.label :password, t("devise_views.sessions.new.password_label") %> + <%= f.password_field :password, autocomplete: "off", placeholder: t("devise_views.sessions.new.password_label") %> +
- <% if devise_mapping.rememberable? -%> -
-
- <%= f.check_box :remember_me %> - <%= f.label :remember_me, t("devise_views.sessions.new.remember_me") %> -
-
- <% end -%> - -
-
- <%= f.submit(t("devise_views.sessions.new.submit"), class: "button radius expand") %> -
-
- <% end %> - - <%= render "devise/shared/links" %> + <% if devise_mapping.rememberable? -%> +
+ <%= f.check_box :remember_me %> + <%= f.label :remember_me, t("devise_views.sessions.new.remember_me") %>
+ <% end -%> + +
+ <%= f.submit(t("devise_views.sessions.new.submit"), class: "button radius expand") %> +
+ <% end %> + + <%= render "devise/shared/links" %>
+
\ No newline at end of file diff --git a/app/views/layouts/devise.html.erb b/app/views/layouts/devise.html.erb new file mode 100644 index 000000000..fe73e5553 --- /dev/null +++ b/app/views/layouts/devise.html.erb @@ -0,0 +1,39 @@ + + + + + + + <%= content_for?(:title) ? yield(:title) : "Participación" %> + <%= stylesheet_link_tag "application" %> + <%= javascript_include_tag "vendor/modernizr" %> + <%= javascript_include_tag "application", 'data-turbolinks-track' => true %> + <%= csrf_meta_tags %> + + + + + + <% if notice %> +

<%= notice %>

+ <% end %> + + <% if alert %> +

<%= alert %>

+ <% end %> + +
+
+

+ <%= link_to root_path do %> + <%= image_tag('logo_madrid_white.png', class: 'left', size: '96x96') %> + <%= t("layouts.header.open_gov", open: "#{t('layouts.header.open')}").html_safe %> | <%= t("layouts.header.participation") %> + <% end %> +

+
+
+ + <%= yield %> + + + \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index 4055e45b6..cc325bc6c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -20,6 +20,11 @@ module Participacion # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] config.i18n.default_locale = :es + config.i18n.available_locales = [:en, :es] + + # Add the new directories to the locales load path + config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')] + config.assets.paths << Rails.root.join("app", "assets", "fonts") # Do not swallow errors in after_commit/after_rollback callbacks. diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml new file mode 100644 index 000000000..f9b28d6a2 --- /dev/null +++ b/config/i18n-tasks.yml @@ -0,0 +1,106 @@ +# i18n-tasks finds and manages missing and unused translations: https://github.com/glebm/i18n-tasks + +# The "main" locale. +base_locale: en +## All available locales are inferred from the data by default. Alternatively, specify them explicitly: +# locales: [es, fr] +## Reporting locale, default: en. Available: en, ru. +# internal_locale: en + +# Read and write translations. +data: + ## Translations are read from the file system. Supported format: YAML, JSON. + ## Provide a custom adapter: + # adapter: I18n::Tasks::Data::FileSystem + + # Locale files or `File.find` patterns where translations are read from: + read: + ## Default: + # - config/locales/%{locale}.yml + ## More files: + # - config/locales/**/*.%{locale}.yml + ## Another gem (replace %#= with %=): + # - "<%#= %x[bundle show vagrant].chomp %>/templates/locales/%{locale}.yml" + - config/locales/%{locale}.yml + - config/locales/devise_views.%{locale}.yml + - config/locales/responders.%{locale}.yml + + # Locale files to write new keys to, based on a list of key pattern => file rules. Matched from top to bottom: + # `i18n-tasks normalize -p` will force move the keys according to these rules + write: + ## For example, write devise and simple form keys to their respective files: + # - ['{devise, simple_form}.*', 'config/locales/\1.%{locale}.yml'] + ## Catch-all default: + # - config/locales/%{locale}.yml + + ## Specify the router (see Readme for details). Valid values: conservative_router, pattern_router, or a custom class. + # router: convervative_router + + yaml: + write: + # do not wrap lines at 80 characters + line_width: -1 + + ## Pretty-print JSON: + # json: + # write: + # indent: ' ' + # space: ' ' + # object_nl: "\n" + # array_nl: "\n" + +# Find translate calls +search: + ## Paths or `File.find` patterns to search in: + # paths: + # - app/ + + ## Root directories for relative keys resolution. + # relative_roots: + # - app/controllers + # - app/helpers + # - app/mailers + # - app/presenters + # - app/views + + ## Files or `File.fnmatch` patterns to exclude from search. Some files are always excluded regardless of this setting: + ## %w(*.jpg *.png *.gif *.svg *.ico *.eot *.otf *.ttf *.woff *.woff2 *.pdf *.css *.sass *.scss *.less *.yml *.json) + exclude: + - app/assets/images + - app/assets/fonts + + ## Alternatively, the only files or `File.fnmatch patterns` to search in `paths`: + ## If specified, this settings takes priority over `exclude`, but `exclude` still applies. + # include: ["*.rb", "*.html.slim"] + + ## Default scanner finds t() and I18n.t() calls. + # scanner: I18n::Tasks::Scanners::PatternWithScopeScanner + +## Google Translate +# translation: +# # Get an API key and set billing info at https://code.google.com/apis/console to use Google Translate +# api_key: "AbC-dEf5" + +## Do not consider these keys missing: +# ignore_missing: +# - 'errors.messages.{accepted,blank,invalid,too_short,too_long}' +# - '{devise,simple_form}.*' + +## Consider these keys used: +# ignore_unused: +# - 'activerecord.attributes.*' +# - '{devise,kaminari,will_paginate}.*' +# - 'simple_form.{yes,no}' +# - 'simple_form.{placeholders,hints,labels}.*' +# - 'simple_form.{error_notification,required}.:' + +## Exclude these keys from the `i18n-tasks eq-base' report: +# ignore_eq_base: +# all: +# - common.ok +# fr,es: +# - common.brand + +## Ignore these keys completely: +# ignore: +# - kaminari.* diff --git a/config/initializers/i18n.rb b/config/initializers/i18n.rb deleted file mode 100644 index 9aa77cd8b..000000000 --- a/config/initializers/i18n.rb +++ /dev/null @@ -1,6 +0,0 @@ -I18n.available_locales = [:en, :es] - -I18n.default_locale = :es - -# Add the new directories to the locales load path -I18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')] diff --git a/config/locales/devise_views.en.yml b/config/locales/devise_views.en.yml index d07d487ad..7675a204e 100644 --- a/config/locales/devise_views.en.yml +++ b/config/locales/devise_views.en.yml @@ -56,6 +56,8 @@ en: title: "Sign up" first_name_label: "First name" last_name_label: "Last name" + nickname_label: "Nickname" + use_nickname_label: "Use nickname" email_label: "Email" password_label: "Password" min_length: "(%{min} characters minimum)" diff --git a/config/locales/devise_views.es.yml b/config/locales/devise_views.es.yml index 1fa6fe880..63e3159e0 100644 --- a/config/locales/devise_views.es.yml +++ b/config/locales/devise_views.es.yml @@ -55,7 +55,9 @@ es: new: title: "Registrarse" first_name_label: "Nombre" - last_name_label: "Apellido" + last_name_label: "Apellidos" + nickname_label: "Pseudónimo" + use_nickname_label: "Usar pseudónimo" email_label: "Email" password_label: "Contraseña" min_length: "(mínimo %{min} caracteres)" @@ -80,4 +82,4 @@ es: signin_with_provider: "Entrar con %{provider}" new_password: "¿Olvidaste tu contraseña?" new_confirmation: "¿No has recibido instrucciones para confirmar tu cuenta?" - new_unlock: "¿No has recibido instrucciones para desbloquear?" \ No newline at end of file + new_unlock: "¿No has recibido instrucciones para desbloquear?" diff --git a/config/locales/en.yml b/config/locales/en.yml index 2a8562a6e..7fdf7a214 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -20,9 +20,6 @@ en: votes: votes comment: Comment comments: Comments - agree: I agree - disagree: I disagree - leave_comment: Comment form: error: error errors: errors @@ -48,7 +45,7 @@ en: new: publish_new: Publish new debate back_link: Back - recommendations_tite: Tips for creating a debate + recommendations_title: Tips for creating a debate recommendation_one: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore" recommendation_two: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore" recommendation_three: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore" @@ -61,12 +58,18 @@ en: agree: I agree disagree: I disagree supports: Supports - notice_thanks: "Thanks for voting." - notice_already_registered: "Your vote is already registered." account: show: title: "My account" save_changes_submit: "Save changes" + change_credentials_link: "Change my credentials" + first_name_label: "First Name" + last_name_label: "Last Name" + use_nickname_label: "Use nickname" + nickname_label: "Nickname" + recaptcha: + errors: + verification_failed: "The captcha verification failed" shared: tags_cloud: tags: Tags diff --git a/config/locales/es.yml b/config/locales/es.yml index d5869b284..9bbdde6b6 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -20,9 +20,6 @@ es: votes: votos comment: Comentario comments: Comentarios - agree: Estoy de acuerdo - disagree: No estoy de acuerdo - leave_comment: Comentar form: error: error errors: errores @@ -61,12 +58,19 @@ es: agree: Estoy de acuerdo disagree: No estoy de acuerdo supports: Apoyos - notice_thanks: "Gracias por votar." - notice_already_registered: "Tu voto ya ha sido registrado." account: show: title: "Mi cuenta" save_changes_submit: "Guardar cambios" + change_credentials_link: "Cambiar mi contraseña" + first_name_label: "Nombre" + last_name_label: "Apellidos" + use_nickname_label: "Usar pseudónimo" + nickname_label: "Pseudónimo" + recaptcha: + errors: + verification_failed: "La verificación por captcha falló" shared: tags_cloud: tags: Etiquetas + diff --git a/config/locales/responders.en.yml b/config/locales/responders.en.yml index cd0d93fe8..41c13a326 100644 --- a/config/locales/responders.en.yml +++ b/config/locales/responders.en.yml @@ -4,12 +4,12 @@ en: create: notice: '%{resource_name} was successfully created.' # alert: '%{resource_name} could not be created.' - update: - notice: '%{resource_name} was successfully updated.' + # update: + # notice: '%{resource_name} was successfully updated.' # alert: '%{resource_name} could not be updated.' - destroy: - notice: '%{resource_name} was successfully destroyed.' - alert: '%{resource_name} could not be destroyed.' + # destroy: + # notice: '%{resource_name} was successfully destroyed.' + # alert: '%{resource_name} could not be destroyed.' save_changes: notice: "Saved" diff --git a/config/locales/responders.es.yml b/config/locales/responders.es.yml index ad8012f9e..e11fbccbc 100644 --- a/config/locales/responders.es.yml +++ b/config/locales/responders.es.yml @@ -3,10 +3,10 @@ es: actions: create: notice: "%{resource_name} creado correctamente." - update: - notice: "%{resource_name} actualizado correctamente." - destroy: - notice: "%{resource_name} borrado correctamente." - alert: "%{resource_name} no ha podido ser borrado." + # update: + # notice: "%{resource_name} actualizado correctamente." + # destroy: + # notice: "%{resource_name} borrado correctamente." + # alert: "%{resource_name} no ha podido ser borrado." save_changes: notice: "Cambios guardados" diff --git a/db/migrate/20150806135245_add_nickname_to_user.rb b/db/migrate/20150806135245_add_nickname_to_user.rb new file mode 100644 index 000000000..06bf046f9 --- /dev/null +++ b/db/migrate/20150806135245_add_nickname_to_user.rb @@ -0,0 +1,5 @@ +class AddNicknameToUser < ActiveRecord::Migration + def change + add_column :users, :nickname, :string + end +end diff --git a/db/migrate/20150806140048_add_use_nickname_to_users.rb b/db/migrate/20150806140048_add_use_nickname_to_users.rb new file mode 100644 index 000000000..032a791cd --- /dev/null +++ b/db/migrate/20150806140048_add_use_nickname_to_users.rb @@ -0,0 +1,5 @@ +class AddUseNicknameToUsers < ActiveRecord::Migration + def change + add_column :users, :use_nickname, :boolean, null: false, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index f75de4884..e5f6f9c0a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150806111435) do +ActiveRecord::Schema.define(version: 20150806140048) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -62,24 +62,26 @@ ActiveRecord::Schema.define(version: 20150806111435) do add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree create_table "users", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "first_name" t.string "last_name" t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" t.string "unconfirmed_email" + t.string "nickname" + t.boolean "use_nickname", default: false, null: false end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree diff --git a/spec/i18n_spec.rb b/spec/i18n_spec.rb new file mode 100644 index 000000000..5237b7240 --- /dev/null +++ b/spec/i18n_spec.rb @@ -0,0 +1,17 @@ +require 'i18n/tasks' + +RSpec.describe 'I18n' do + let(:i18n) { I18n::Tasks::BaseTask.new } + let(:missing_keys) { i18n.missing_keys } + let(:unused_keys) { i18n.unused_keys } + + it 'does not have missing keys' do + expect(missing_keys).to be_empty, + "Missing #{missing_keys.leaves.count} i18n keys, run `i18n-tasks missing' to show them" + end + + it 'does not have unused keys' do + expect(unused_keys).to be_empty, + "#{unused_keys.leaves.count} unused i18n keys, run `i18n-tasks unused' to show them" + end +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 77b6755dc..0a7665127 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -2,11 +2,11 @@ require 'rails_helper' describe User do - before(:each) do - @user = create(:user) - end - describe "#votes_on_debates" do + before(:each) do + @user = create(:user) + end + it "should return {} if no debate" do expect(@user.votes_on_debates()).to eq({}) expect(@user.votes_on_debates([])).to eq({}) @@ -27,4 +27,50 @@ describe User do expect(voted[debate3.id]).to eq(false) end end + + subject { build(:user) } + + it "is valid" do + expect(subject).to be_valid + end + + describe 'use_nickname' do + describe 'when true' do + before { subject.use_nickname = true } + + it "activates the validation of nickname" do + subject.nickname = nil + expect(subject).to_not be_valid + + subject.nickname = "dredd" + expect(subject).to be_valid + end + + it "calculates the name using the nickname" do + subject.nickname = "dredd" + expect(subject.name).to eq("dredd") + end + end + + describe 'when false' do + before { subject.use_nickname = false } + + it "activates the validation of first_name and last_name" do + subject.first_name = nil + subject.last_name = nil + expect(subject).to_not be_valid + + subject.first_name = "Joseph" + subject.last_name = "Dredd" + expect(subject).to be_valid + end + + it "calculates the name using first_name and last_name" do + subject.first_name = "Joseph" + subject.last_name = "Dredd" + expect(subject.name).to eq("Joseph Dredd") + end + end + end + end