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?
params.require(:account).permit(:phone_number, :email_on_debate_comment, :email_on_comment_reply, organization_attributes: [:name])
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

View File

@@ -12,7 +12,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
private
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

View File

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

View File

@@ -16,19 +16,12 @@
<%= f.fields_for :organization do |fo| %>
<%= fo.text_field :name, autofocus: true, placeholder: t("account.show.organization_name_label") %>
<% end %>
<%= f.text_field :phone_number, placeholder: t("account.show.phone_number_label") %>
<% else %>
<%= 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>
<%= f.text_field :username, placeholder: t("account.show.username_label") %>
<% end %>
<%= f.text_field :phone_number, placeholder: t("account.show.phone_number_label") %>
</div>
<div class="small-12 medium-6 column">

View File

@@ -6,15 +6,8 @@
<%= render 'shared/errors', resource: resource %>
<div class="row">
<div class="small-12 column">
<%= f.text_field :first_name, autofocus: true,
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.text_field :username, placeholder: t("devise_views.users.registrations.new.username_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",
placeholder: t("devise_views.users.registrations.new.password_label") %>

View File

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

View File

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

View File

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

View File

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

View File

@@ -120,12 +120,9 @@ en:
change_credentials_link: "Change my credentials"
avatar: "Avatar"
personal: "Personal data"
first_name_label: "First Name"
last_name_label: "Last Name"
username_label: "Username"
phone_number_label: "Phone number"
organization_name_label: "Organization name"
use_nickname_label: "Use nickname"
nickname_label: "Nickname"
notifications: Notifications
simple_captcha:
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"
avatar: "Avatar"
personal: "Datos personales"
first_name_label: "Nombre"
last_name_label: "Apellidos"
username_label: "Nombre de usuario"
phone_number_label: "Teléfono"
organization_name_label: "Nombre de la organización"
use_nickname_label: "Usar pseudónimo"
nickname_label: "Pseudónimo"
notifications: Notificaciones
simple_captcha:
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.
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
enable_extension "plpgsql"
@@ -130,20 +130,17 @@ ActiveRecord::Schema.define(version: 20150819135933) do
t.string "last_sign_in_ip"
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
t.boolean "email_on_debate_comment", default: false
t.boolean "email_on_comment_reply", default: false
t.string "official_position"
t.integer "official_level", default: 0
t.string "phone_number", limit: 30
t.datetime "hidden_at"
t.string "phone_number", limit: 30
t.string "username"
end
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree

View File

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

View File

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

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
feature 'Admin officials' 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)
@admin = create(:administrator)
login_as(@admin.user)

View File

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

View File

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

View File

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

View File

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