Merge pull request #285 from AyuntamientoMadrid/verification-namespace

Verification namespace
This commit is contained in:
Raimond Garcia
2015-08-29 12:54:57 +02:00
23 changed files with 64 additions and 60 deletions

View File

@@ -4,7 +4,7 @@ class Verification::EmailController < ApplicationController
skip_authorization_check
def show
if Email.find(current_user, params[:email_verification_token])
if Verification::Email.find(current_user, params[:email_verification_token])
current_user.update(verified_at: Time.now)
redirect_to account_path, notice: t('verification.email.show.flash.success')
else
@@ -13,7 +13,7 @@ class Verification::EmailController < ApplicationController
end
def create
@email = Email.new(@verified_user)
@email = Verification::Email.new(@verified_user)
if @email.save
current_user.reload
Mailer.email_verification(current_user, @email.recipient, @email.encrypted_token).deliver_now

View File

@@ -5,11 +5,11 @@ class Verification::LetterController < ApplicationController
skip_authorization_check
def new
@letter = Letter.new(user: current_user)
@letter = Verification::Letter.new(user: current_user)
end
def create
@letter = Letter.new(user: current_user)
@letter = Verification::Letter.new(user: current_user)
if @letter.save
redirect_to account_path, notice: t('verification.letter.create.flash.success')
else

View File

@@ -4,11 +4,11 @@ class Verification::ResidenceController < ApplicationController
skip_authorization_check
def new
@residence = Residence.new
@residence = Verification::Residence.new
end
def create
@residence = Residence.new(residence_params.merge(user: current_user))
@residence = Verification::Residence.new(residence_params.merge(user: current_user))
if @residence.save
redirect_to verified_user_path, notice: t('verification.residence.create.flash.success')
else

View File

@@ -6,11 +6,11 @@ class Verification::SmsController < ApplicationController
skip_authorization_check
def new
@sms = Sms.new(phone: params[:phone])
@sms = Verification::Sms.new(phone: params[:phone])
end
def create
@sms = Sms.new(sms_params.merge(user: current_user))
@sms = Verification::Sms.new(sms_params.merge(user: current_user))
if @sms.save
redirect_to edit_sms_path, notice: t('verification.sms.create.flash.success')
else
@@ -19,11 +19,11 @@ class Verification::SmsController < ApplicationController
end
def edit
@sms = Sms.new
@sms = Verification::Sms.new
end
def update
@sms = Sms.new(sms_params.merge(user: current_user))
@sms = Verification::Sms.new(sms_params.merge(user: current_user))
if @sms.verify?
current_user.update(confirmed_phone: current_user.unconfirmed_phone)

View File

@@ -1,4 +1,4 @@
class Email
class Verification::Email
include ActiveModel::Model
attr_accessor :verified_user, :recipient, :plain_token, :encrypted_token

View File

@@ -1,4 +1,4 @@
class Letter
class Verification::Letter
include ActiveModel::Model
attr_accessor :user, :address

View File

@@ -1,4 +1,4 @@
class Residence
class Verification::Residence
include ActiveModel::Model
include ActiveModel::Dates

View File

@@ -1,4 +1,4 @@
class Sms
class Verification::Sms
include ActiveModel::Model
attr_accessor :user, :phone, :confirmation_code

View File

@@ -1,4 +1,4 @@
<%= form_for Email.new(verified_user), url: email_path, method: :post do |f| %>
<%= form_for Verification::Email.new(verified_user), as: "email", url: email_path, method: :post do |f| %>
<%= hidden_field_tag :recipient, verified_user.email %>
<%= f.submit t('verification.email.form.submit_button') %>
<% end %>

View File

@@ -7,7 +7,7 @@
<%= t('verification.letter.new.explanation') %>
</div>
<%= form_for @letter, url: letter_path do |f| %>
<%= form_for @letter, as: "letter", url: letter_path do |f| %>
<%= render 'shared/errors', resource: @letter %>
<%= f.submit t('verification.letter.new.submit_button') %>
<% end %>

View File

@@ -3,7 +3,7 @@
<h1 class="inline-block"><%= t('verification.residence.new.title') %></h1>
<%= form_for @residence, url: residence_path do |f| %>
<%= form_for @residence, as: "residence", url: residence_path do |f| %>
<%= render 'errors' %>
<%= f.select :document_type, document_types, prompt: "" %>

View File

@@ -1,4 +1,4 @@
<%= form_for sms, url: sms_path do |f| %>
<%= form_for sms, as: "sms", url: sms_path do |f| %>
<%= render 'shared/errors', resource: sms %>
<%= f.hidden_field :phone %>
<%= f.submit t('verification.sms.form.submit_button') %>

View File

@@ -3,7 +3,7 @@
<h1 class="inline-block"><%= t('verification.sms.edit.title') %></h1>
<%= form_for @sms, url: sms_path, method: :put do |f| %>
<%= form_for @sms, as: "sms", url: sms_path, method: :put do |f| %>
<p><%= @error %></p>
<%= f.text_field :confirmation_code %>

View File

@@ -3,7 +3,7 @@
<h1 class="inline-block"><%= t('verification.sms.new.title') %></h1>
<%= form_for @sms, url: sms_path do |f| %>
<%= form_for @sms, as: "sms", url: sms_path do |f| %>
<%= render 'shared/errors', resource: @sms %>
<%= f.text_field :phone %>

View File

@@ -32,7 +32,7 @@
<%= verified_user.phone %>
</span>
<span style="float:left;padding-left:30px">
<%= render '/verification/sms/form', sms: Sms.new(phone: verified_user.phone) %>
<%= render '/verification/sms/form', sms: Verification::Sms.new(phone: verified_user.phone) %>
</span>
</li>
<br/><br/><br/>

View File

@@ -97,6 +97,7 @@ ignore_missing:
## Consider these keys used:
ignore_unused:
- 'activerecord.*'
- 'activemodel.*'
- 'admin.organizations.index.filter.*'
- 'unauthorized.*'
- 'simple_captcha.*'

View File

@@ -1,16 +1,18 @@
en:
activemodel:
models:
residence: Residence
sms: SMS
verification:
residence: Residence
sms: SMS
attributes:
residence:
document_type: Document type
document_number: Document number(including letter)
date_of_birth: Date of birth
postal_code: Postal code
sms:
phone: 'Phone'
confirmation_code: 'Confirmation code'
email:
recipient: 'Email'
verification:
residence:
document_type: Document type
document_number: Document number(including letter)
date_of_birth: Date of birth
postal_code: Postal code
sms:
phone: 'Phone'
confirmation_code: 'Confirmation code'
email:
recipient: 'Email'

View File

@@ -1,16 +1,18 @@
es:
activemodel:
models:
residence: Residencia
sms: SMS
verification:
residence: Residencia
sms: SMS
attributes:
residence:
document_type: Tipo documento
document_number: Numero de documento (incluida letra)
date_of_birth: Fecha de nacimiento
postal_code: 'Código postal'
sms:
phone: 'Teléfono'
confirmation_code: 'Código de confirmación'
email:
recipient: 'Email'
verification:
residence:
document_type: Tipo documento
document_number: Numero de documento (incluida letra)
date_of_birth: Fecha de nacimiento
postal_code: 'Código postal'
sms:
phone: 'Teléfono'
confirmation_code: 'Código de confirmación'
email:
recipient: 'Email'

View File

@@ -7,7 +7,6 @@ en:
user: User
vote: Vote
organization: Organization
residence: Residencia
attributes:
comment:
body: Comment

View File

@@ -20,18 +20,18 @@ FactoryGirl.define do
uid "MyString"
end
factory :residence do
factory :verification_residence, class: Verification::Residence do
document_number '12345678Z'
document_type 1
date_of_birth Date.new(1980, 12, 31)
postal_code "28013"
end
factory :sms do
factory :verification_sms, class: Verification::Sms do
phone "699999999"
end
factory :letter do
factory :verification_letter, class: Verification::Letter do
user
address
end

View File

@@ -1,12 +1,12 @@
require 'rails_helper'
describe 'Letter' do
describe 'Verification::Letter' do
let(:user) { create(:user) }
describe "validations" do
let(:letter) { build(:letter) }
let(:letter) { build(:verification_letter) }
it "should be valid" do
expect(letter).to be_valid
@@ -27,7 +27,7 @@ describe 'Letter' do
describe "save" do
before(:each) do
letter = Letter.new(user: user)
letter = Verification::Letter.new(user: user)
letter.save
user.reload
end

View File

@@ -1,8 +1,8 @@
require 'rails_helper'
describe Residence do
describe Verification::Residence do
let(:residence) { build(:residence) }
let(:residence) { build(:verification_residence) }
describe "validations" do
@@ -12,12 +12,12 @@ describe Residence do
describe "dates" do
it "should be valid with a valid date of birth" do
residence = Residence.new({"date_of_birth(3i)"=>"1", "date_of_birth(2i)"=>"1", "date_of_birth(1i)"=>"1980"})
residence = Verification::Residence.new({"date_of_birth(3i)"=>"1", "date_of_birth(2i)"=>"1", "date_of_birth(1i)"=>"1980"})
expect(residence.errors[:date_of_birth].size).to eq(0)
end
it "should not be valid without a date of birth" do
residence = Residence.new({"date_of_birth(3i)"=>"", "date_of_birth(2i)"=>"", "date_of_birth(1i)"=>""})
residence = Verification::Residence.new({"date_of_birth(3i)"=>"", "date_of_birth(2i)"=>"", "date_of_birth(1i)"=>""})
residence.valid?
expect(residence.errors[:date_of_birth]).to include("can't be blank")
end
@@ -28,7 +28,7 @@ describe Residence do
residence.user = user
residence.save
residence2 = build(:residence)
residence2 = build(:verification_residence)
residence.valid?
expect(residence.errors[:document_number]).to include("Already in use")

View File

@@ -1,14 +1,14 @@
require 'rails_helper'
describe Sms do
describe Verification::Sms do
it "should be valid" do
sms = build(:sms)
sms = build(:verification_sms)
expect(sms).to be_valid
end
it "should validate uniqness of phone" do
user = create(:user, confirmed_phone: "699999999")
sms = Sms.new(phone: "699999999")
sms = Verification::Sms.new(phone: "699999999")
expect(sms).to_not be_valid
end