Merge branch 'master' into deploy

This commit is contained in:
rgarcia
2015-08-21 19:00:22 +02:00
20 changed files with 46 additions and 124 deletions

View File

@@ -26,7 +26,7 @@ class AccountController < ApplicationController
if @account.organization? if @account.organization?
params.require(:account).permit(:phone_number, :email_on_debate_comment, :email_on_comment_reply, organization_attributes: [:name]) params.require(:account).permit(:phone_number, :email_on_debate_comment, :email_on_comment_reply, organization_attributes: [:name])
else else
params.require(:account).permit(:first_name, :last_name, :phone_number, :nickname, :use_nickname, :email_on_debate_comment, :email_on_comment_reply) params.require(:account).permit(:username, :email_on_debate_comment, :email_on_comment_reply)
end end
end end

View File

@@ -12,7 +12,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
private private
def sign_up_params def sign_up_params
params.require(:user).permit(:first_name, :last_name, :email, :phone_number, :password, :password_confirmation, :use_nickname, :nickname, :captcha, :captcha_key) params.require(:user).permit(:username, :email, :password, :password_confirmation, :captcha, :captcha_key)
end end
end end

View File

@@ -11,9 +11,7 @@ class User < ActiveRecord::Base
has_one :moderator has_one :moderator
has_one :organization has_one :organization
validates :first_name, presence: true, if: :use_first_name? validates :username, presence: true, unless: :organization?
validates :last_name, presence: true, if: :use_last_name?
validates :nickname, presence: true, if: :use_nickname?
validates :official_level, inclusion: {in: 0..5} validates :official_level, inclusion: {in: 0..5}
validates_associated :organization, message: false validates_associated :organization, message: false
@@ -27,9 +25,7 @@ class User < ActiveRecord::Base
scope :officials, -> { where("official_level > 0") } scope :officials, -> { where("official_level > 0") }
def name def name
return nickname if use_nickname? organization? ? organization.name : username
return organization.name if organization?
"#{first_name} #{last_name}"
end end
def debate_votes(debates) def debate_votes(debates)
@@ -70,12 +66,4 @@ class User < ActiveRecord::Base
e.present? ? where(email: e) : none e.present? ? where(email: e) : none
end end
private
def use_first_name?
!organization? && !use_nickname?
end
def use_last_name?
use_first_name?
end
end end

View File

@@ -16,19 +16,12 @@
<%= f.fields_for :organization do |fo| %> <%= f.fields_for :organization do |fo| %>
<%= fo.text_field :name, autofocus: true, placeholder: t("account.show.organization_name_label") %> <%= fo.text_field :name, autofocus: true, placeholder: t("account.show.organization_name_label") %>
<% end %> <% end %>
<%= f.text_field :phone_number, placeholder: t("account.show.phone_number_label") %>
<% else %> <% else %>
<%= f.text_field :username, placeholder: t("account.show.username_label") %>
<%= f.text_field :first_name, placeholder: t("account.show.first_name_label") %>
<%= f.text_field :last_name, placeholder: t("account.show.last_name_label") %>
<%= f.text_field :nickname, placeholder: t("account.show.nickname_label") %>
<%= f.check_box :use_nickname, label: false %>
<span class="checkbox"><%= t("account.show.use_nickname_label") %></span>
<% end %> <% end %>
<%= f.text_field :phone_number, placeholder: t("account.show.phone_number_label") %>
</div> </div>
<div class="small-12 medium-6 column"> <div class="small-12 medium-6 column">

View File

@@ -6,15 +6,8 @@
<%= render 'shared/errors', resource: resource %> <%= render 'shared/errors', resource: resource %>
<div class="row"> <div class="row">
<div class="small-12 column"> <div class="small-12 column">
<%= f.text_field :first_name, autofocus: true, <%= f.text_field :username, placeholder: t("devise_views.users.registrations.new.username_label") %>
placeholder: t("devise_views.users.registrations.new.first_name_label") %>
<%= f.text_field :last_name, placeholder: t("devise_views.users.registrations.new.last_name_label") %>
<%= f.email_field :email, placeholder: t("devise_views.users.registrations.new.email_label") %> <%= f.email_field :email, placeholder: t("devise_views.users.registrations.new.email_label") %>
<%= f.text_field :nickname, placeholder: t("devise_views.users.registrations.new.nickname_label") %>
<%= f.check_box :use_nickname, label: t("devise_views.users.registrations.new.use_nickname_label") %>
<%= f.text_field :phone_number, placeholder: t("devise_views.users.registrations.new.phone_number_label") %>
<%= f.password_field :password, autocomplete: "off", <%= f.password_field :password, autocomplete: "off",
placeholder: t("devise_views.users.registrations.new.password_label") %> placeholder: t("devise_views.users.registrations.new.password_label") %>

View File

@@ -18,9 +18,7 @@ en:
title: Title title: Title
user: user:
email: Email email: Email
first_name: "First name" username: Username
last_name: "Last name"
nickname: Nickname
password: Password password: Password
phone_number: Phone number phone_number: Phone number
official_position: Official position official_position: Official position

View File

@@ -18,9 +18,7 @@ es:
title: Título title: Título
user: user:
email: Correo electrónico email: Correo electrónico
first_name: Nombre username: Nombre de usuario
last_name: Apellidos
nickname: Pseudónimo
password: Contraseña password: Contraseña
phone_number: Teléfono phone_number: Teléfono
official_position: Cargo público official_position: Cargo público

View File

@@ -50,12 +50,8 @@ en:
back_link: "Back" back_link: "Back"
new: new:
title: "Sign up" title: "Sign up"
first_name_label: "First name" username_label: "Username to use publicly"
last_name_label: "Last name"
nickname_label: "Nickname"
use_nickname_label: "Use nickname"
email_label: "Email" email_label: "Email"
phone_number_label: "Phone number"
password_label: "Password" password_label: "Password"
password_confirmation_label: "Confirm password" password_confirmation_label: "Confirm password"
submit: "Sign up" submit: "Sign up"

View File

@@ -50,12 +50,8 @@ es:
back_link: "Atrás" back_link: "Atrás"
new: new:
title: "Registrarse" title: "Registrarse"
first_name_label: "Nombre" username_label: "Nombre a utilizar públicamente"
last_name_label: "Apellidos"
nickname_label: "Pseudónimo"
use_nickname_label: "Usar pseudónimo"
email_label: "Email" email_label: "Email"
phone_number_label: "Teléfono"
password_label: "Contraseña" password_label: "Contraseña"
password_confirmation_label: "Confirmar contraseña" password_confirmation_label: "Confirmar contraseña"
submit: "Registrarse" submit: "Registrarse"

View File

@@ -120,12 +120,9 @@ en:
change_credentials_link: "Change my credentials" change_credentials_link: "Change my credentials"
avatar: "Avatar" avatar: "Avatar"
personal: "Personal data" personal: "Personal data"
first_name_label: "First Name" username_label: "Username"
last_name_label: "Last Name"
phone_number_label: "Phone number" phone_number_label: "Phone number"
organization_name_label: "Organization name" organization_name_label: "Organization name"
use_nickname_label: "Use nickname"
nickname_label: "Nickname"
notifications: Notifications notifications: Notifications
simple_captcha: simple_captcha:
placeholder: "Enter the image value" placeholder: "Enter the image value"

View File

@@ -120,12 +120,9 @@ es:
email_on_comment_reply_label: "Recibir un email cuando alguien contesta a mis comentarios" email_on_comment_reply_label: "Recibir un email cuando alguien contesta a mis comentarios"
avatar: "Avatar" avatar: "Avatar"
personal: "Datos personales" personal: "Datos personales"
first_name_label: "Nombre" username_label: "Nombre de usuario"
last_name_label: "Apellidos"
phone_number_label: "Teléfono" phone_number_label: "Teléfono"
organization_name_label: "Nombre de la organización" organization_name_label: "Nombre de la organización"
use_nickname_label: "Usar pseudónimo"
nickname_label: "Pseudónimo"
notifications: Notificaciones notifications: Notificaciones
simple_captcha: simple_captcha:
placeholder: "Introduce el texto de la imagen" placeholder: "Introduce el texto de la imagen"

View File

@@ -0,0 +1,10 @@
class ChangesUserRegistrationsFields < ActiveRecord::Migration
def change
add_column :users, :username, :string
remove_column :users, :first_name, :string
remove_column :users, :last_name, :string
remove_column :users, :nickname, :string
remove_column :users, :use_nickname, :boolean, default: false, null: false
end
end

View File

@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150819135933) do ActiveRecord::Schema.define(version: 20150821130019) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -130,20 +130,17 @@ ActiveRecord::Schema.define(version: 20150819135933) do
t.string "last_sign_in_ip" t.string "last_sign_in_ip"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.string "first_name"
t.string "last_name"
t.string "confirmation_token" t.string "confirmation_token"
t.datetime "confirmed_at" t.datetime "confirmed_at"
t.datetime "confirmation_sent_at" t.datetime "confirmation_sent_at"
t.string "unconfirmed_email" t.string "unconfirmed_email"
t.string "nickname"
t.boolean "use_nickname", default: false, null: false
t.boolean "email_on_debate_comment", default: false t.boolean "email_on_debate_comment", default: false
t.boolean "email_on_comment_reply", default: false t.boolean "email_on_comment_reply", default: false
t.string "official_position" t.string "official_position"
t.integer "official_level", default: 0 t.integer "official_level", default: 0
t.string "phone_number", limit: 30
t.datetime "hidden_at" t.datetime "hidden_at"
t.string "phone_number", limit: 30
t.string "username"
end end
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree

View File

@@ -1,8 +1,7 @@
FactoryGirl.define do FactoryGirl.define do
factory :user do factory :user do
first_name 'Manuela' username 'Manuela'
last_name 'Carmena'
sequence(:email) { |n| "manuela#{n}@madrid.es" } sequence(:email) { |n| "manuela#{n}@madrid.es" }
password 'judgmentday' password 'judgmentday'
confirmed_at { Time.now } confirmed_at { Time.now }

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
feature 'Account' do feature 'Account' do
background do background do
@user = create(:user, first_name: "Manuela", last_name: "Colau") @user = create(:user, username: "Manuela Colau")
login_as(@user) login_as(@user)
end end
@@ -14,8 +14,7 @@ feature 'Account' do
expect(current_path).to eq(account_path) expect(current_path).to eq(account_path)
expect(page).to have_selector("input[value='Manuela']") expect(page).to have_selector("input[value='Manuela Colau']")
expect(page).to have_selector("input[value='Colau']")
expect(page).to have_selector(avatar('Manuela Colau'), count: 1) expect(page).to have_selector(avatar('Manuela Colau'), count: 1)
end end
@@ -25,8 +24,7 @@ feature 'Account' do
visit account_path visit account_path
expect(page).to have_selector("input[value='Manuela Corp']") expect(page).to have_selector("input[value='Manuela Corp']")
expect(page).to_not have_selector("input[value='Manuela']") expect(page).to_not have_selector("input[value='Manuela Colau']")
expect(page).to_not have_selector("input[value='Colau']")
expect(page).to have_selector(avatar('Manuela Corp'), count: 1) expect(page).to have_selector(avatar('Manuela Corp'), count: 1)
end end
@@ -34,8 +32,7 @@ feature 'Account' do
scenario 'Edit' do scenario 'Edit' do
visit account_path visit account_path
fill_in 'account_first_name', with: 'Larry' fill_in 'account_username', with: 'Larry Bird'
fill_in 'account_last_name', with: 'Bird'
check 'account_email_on_debate_comment' check 'account_email_on_debate_comment'
check 'account_email_on_comment_reply' check 'account_email_on_comment_reply'
click_button 'Save changes' click_button 'Save changes'
@@ -44,8 +41,7 @@ feature 'Account' do
visit account_path visit account_path
expect(page).to have_selector("input[value='Larry']") expect(page).to have_selector("input[value='Larry Bird']")
expect(page).to have_selector("input[value='Bird']")
expect(page).to have_selector("input[id='account_email_on_debate_comment'][value='1']") expect(page).to have_selector("input[id='account_email_on_debate_comment'][value='1']")
expect(page).to have_selector("input[id='account_email_on_comment_reply'][value='1']") expect(page).to have_selector("input[id='account_email_on_comment_reply'][value='1']")
end end
@@ -71,7 +67,7 @@ feature 'Account' do
scenario "Errors on edit" do scenario "Errors on edit" do
visit account_path visit account_path
fill_in 'account_first_name', with: '' fill_in 'account_username', with: ''
click_button 'Save changes' click_button 'Save changes'
expect(page).to have_content error_message expect(page).to have_content error_message

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
feature 'Admin officials' do feature 'Admin officials' do
background do background do
@citizen = create(:user, first_name: "Citizen", last_name: "Kane") @citizen = create(:user, username: "Citizen Kane")
@official = create(:user, official_position: "Mayor", official_level: 5) @official = create(:user, official_position: "Mayor", official_level: 5)
@admin = create(:administrator) @admin = create(:administrator)
login_as(@admin.user) login_as(@admin.user)

View File

@@ -80,8 +80,8 @@ feature 'Comments' do
end end
scenario 'Reply', :js do scenario 'Reply', :js do
citizen = create(:user, first_name: 'Ana') citizen = create(:user, username: 'Ana')
manuela = create(:user, first_name: 'Manuela') manuela = create(:user, username: 'Manuela')
debate = create(:debate) debate = create(:debate)
comment = create(:comment, commentable: debate, user: citizen) comment = create(:comment, commentable: debate, user: citizen)

View File

@@ -6,8 +6,7 @@ feature 'Users' do
visit '/' visit '/'
click_link 'Sign up' click_link 'Sign up'
fill_in 'user_first_name', with: 'Manuela' fill_in 'user_username', with: 'Manuela Carmena'
fill_in 'user_last_name', with: 'Carmena'
fill_in 'user_email', with: 'manuela@madrid.es' fill_in 'user_email', with: 'manuela@madrid.es'
fill_in 'user_password', with: 'judgementday' fill_in 'user_password', with: 'judgementday'
fill_in 'user_password_confirmation', with: 'judgementday' fill_in 'user_password_confirmation', with: 'judgementday'

View File

@@ -30,6 +30,12 @@ describe User do
expect(subject).to be_valid expect(subject).to be_valid
end end
describe "#name" do
it "is the username when the user is not an organization" do
expect(subject.name).to eq(subject.username)
end
end
describe 'preferences' do describe 'preferences' do
describe 'email_on_debate_comment' do describe 'email_on_debate_comment' do
it 'should be false by default' do it 'should be false by default' do
@@ -44,45 +50,6 @@ describe User do
end end
end 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
describe "administrator?" do describe "administrator?" do
it "is false when the user is not an admin" do it "is false when the user is not an admin" do
expect(subject.administrator?).to be false expect(subject.administrator?).to be false
@@ -152,9 +119,8 @@ describe User do
expect(subject.organization.name).to eq('org') expect(subject.organization.name).to eq('org')
end end
it "deactivates the validation of first_name and last_name, and activates the validation of organization" do it "deactivates the validation of username, and activates the validation of organization" do
subject.first_name = nil subject.username = nil
subject.last_name = nil
expect(subject).to be_valid expect(subject).to be_valid
subject.organization.name= nil subject.organization.name= nil

View File

@@ -4,8 +4,7 @@ module CommonActions
visit '/' visit '/'
click_link 'Sign up' click_link 'Sign up'
fill_in 'user_first_name', with: 'Manuela' fill_in 'user_username', with: 'Manuela Carmena'
fill_in 'user_last_name', with: 'Carmena'
fill_in 'user_email', with: 'manuela@madrid.es' fill_in 'user_email', with: 'manuela@madrid.es'
fill_in 'user_password', with: 'judgementday' fill_in 'user_password', with: 'judgementday'
fill_in 'user_password_confirmation', with: 'judgementday' fill_in 'user_password_confirmation', with: 'judgementday'