Skip to content

Commit

Permalink
removes unnecessary address from users
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoorai2000 committed Sep 26, 2015
1 parent 39d1c3d commit fbb5db8
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 115 deletions.
3 changes: 0 additions & 3 deletions app/models/address.rb

This file was deleted.

1 change: 0 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class User < ActiveRecord::Base
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases

has_one :address
has_one :administrator
has_one :moderator
has_one :organization
Expand Down
37 changes: 2 additions & 35 deletions app/models/verification/letter.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
class Verification::Letter
include ActiveModel::Model

attr_accessor :user, :address, :verification_code
attr_accessor :user, :verification_code

validates :user, presence: true
validates :address, presence: true
validate :correct_address

def save
valid? &&
letter_requested! &&
update_user_address
end

def address
@address ||= CensusApi.new(user).address
letter_requested!
end

def letter_requested!
Expand All @@ -37,32 +30,6 @@ def validate_correct_code
user.letter_verification_code == verification_code
end

def correct_address
errors.add(:address, I18n.t('verification.letter.errors.address_not_found')) unless
address.present?
end

def update_user_address
user.address = Address.new(parsed_address)
user.save
end

def parsed_address
{ postal_code: address[:codigo_postal],
street: address[:nombre_via],
street_type: address[:sigla_via],
number: address[:numero_via],
number_type: address[:nominal_via],
letter: address[:letra_via],
portal: address[:portal],
stairway: address[:escalera],
floor: address[:planta],
door: address[:puerta],
km: address[:km],
neighbourhood: address[:nombre_barrio],
district: address[:nombre_distrito] }
end

def increase_letter_verification_tries
user.update(letter_verification_tries: user.letter_verification_tries += 1)
end
Expand Down
3 changes: 0 additions & 3 deletions config/locales/verification.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ en:
success_html: "Thank you for requesting a maximum security code in a few days we will send it to the address on your census data."
offices: "Oficinas de Atención al Ciudadano"
offices_url: "http://www.madrid.es/portales/munimadrid/es/Inicio/El-Ayuntamiento/Atencion-al-ciudadano/Oficinas-de-Atencion-al-Ciudadano?vgnextfmt=default&vgnextchannel=5b99cde2e09a4310VgnVCM1000000b205a0aRCRD"
alert:
failure: "We could not verify your address with the Census please try again later"
edit:
title: "Empieza a participar"
confirmation_code: "Introduce aquí el código de máxima seguridad cuando recibas tu carta"
Expand All @@ -91,7 +89,6 @@ en:
errors:
letter_not_sent: "We have not sent you the letter with the code yet"
incorect_code: "Incorrect confirmation code"
address_not_found: "Address not found"
verified_user:
show:
title: "Available information"
Expand Down
3 changes: 0 additions & 3 deletions config/locales/verification.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ es:
success_html: "Gracias por solicitar tu <b>código de máxima seguridad (solo necesario para las votaciones finales)</b>, en unos días te lo enviaremos a la dirección que figura en tus datos del padrón. Recuerda que puedes ahorrar el envío recogiendo tu código en cualquiera de las %{offices}."
offices: "Oficinas de Atención al Ciudadano"
offices_url: "http://www.madrid.es/portales/munimadrid/es/Inicio/El-Ayuntamiento/Atencion-al-ciudadano/Oficinas-de-Atencion-al-Ciudadano?vgnextfmt=default&vgnextchannel=5b99cde2e09a4310VgnVCM1000000b205a0aRCRD"
alert:
failure: "No podemos verificar tu dirección con el Padrón, por favor inténtalo otra vez más tarde"
edit:
title: "Empieza a participar"
confirmation_code: "Introduce aquí el código de máxima seguridad cuando recibas tu carta"
Expand All @@ -91,7 +89,6 @@ es:
errors:
letter_not_sent: "Aún no te hemos enviado la carta con el código"
incorect_code: "Código de verificación incorrecto"
address_not_found: "No se ha encontrado una dirección"
verified_user:
show:
title: "Información disponible"
Expand Down
27 changes: 27 additions & 0 deletions db/migrate/20150926113052_drop_addresses_table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class DropAddressesTable < ActiveRecord::Migration
def self.up
drop_table :addresses
end

def self.down
create_table "addresses", force: :cascade do |t|
t.integer "user_id"
t.string "street"
t.string "street_type"
t.string "number"
t.string "number_type"
t.string "letter"
t.string "portal"
t.string "stairway"
t.string "floor"
t.string "door"
t.string "km"
t.string "neighbourhood"
t.string "district"
t.string "postal_code"
t.string "toponymy"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end
end
22 changes: 1 addition & 21 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150921095553) do
ActiveRecord::Schema.define(version: 20150926113052) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -28,26 +28,6 @@
add_index "activities", ["actionable_id", "actionable_type"], name: "index_activities_on_actionable_id_and_actionable_type", using: :btree
add_index "activities", ["user_id"], name: "index_activities_on_user_id", using: :btree

create_table "addresses", force: :cascade do |t|
t.integer "user_id"
t.string "street"
t.string "street_type"
t.string "number"
t.string "number_type"
t.string "letter"
t.string "portal"
t.string "stairway"
t.string "floor"
t.string "door"
t.string "km"
t.string "neighbourhood"
t.string "district"
t.string "postal_code"
t.string "toponymy"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "administrators", force: :cascade do |t|
t.integer "user_id"
end
Expand Down
6 changes: 1 addition & 5 deletions lib/census_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ def postal_code
data[:datos_vivienda][:item][:codigo_postal]
end

def address
response[:get_habita_datos_response][:get_habita_datos_return][:datos_vivienda][:item]
end

def valid?
return false unless data[:datos_habitante][:item].present?

Expand All @@ -53,6 +49,6 @@ def end_point_available?
end

def stubbed_response
{:get_habita_datos_response=>{:get_habita_datos_return=>{:hay_errores=>false, :datos_habitante=>{:item=>{:fecha_nacimiento_string=>"31-12-1980", :identificador_documento=>"12345678Z", }}, :datos_vivienda=>{:item=>{:codigo_postal=>"28013", :escalera=>"4", :km=>"0", :letra_via=>"B", :nombre_barrio=>"JUSTICIA", :nombre_distrito=>"CENTRO", :nombre_via=>"ALCALÁ", :nominal_via=>"NUM", :numero_via=>"1", :planta=>"PB", :portal=>"1", :puerta=>"DR", :sigla_via=>"CALLE"}}}}}
{:get_habita_datos_response=>{:get_habita_datos_return=>{:hay_errores=>false, :datos_habitante=>{:item=>{:fecha_nacimiento_string=>"31-12-1980", :identificador_documento=>"12345678Z", }}, :datos_vivienda=>{:item=>{:codigo_postal=>"28013"}}}}}
end
end
7 changes: 0 additions & 7 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@

factory :verification_letter, class: Verification::Letter do
user
address
end

factory :lock do
Expand All @@ -67,12 +66,6 @@
locked_until Time.now
end

factory :address do
street_type "Calle"
street "Alcalá"
number "1"
end

factory :verified_user do
document_number '12345678Z'
document_type 'dni'
Expand Down
15 changes: 0 additions & 15 deletions spec/features/verification/letter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,6 @@
expect(page).to have_content "Incorrect confirmation code"
end

scenario "Error accessing address from CensusApi" do
user = create(:user, residence_verified_at: Time.now,
confirmed_phone: "611111111",
letter_sent_at: 1.day.ago)

login_as(user)
visit new_letter_path

allow_any_instance_of(CensusApi).to receive(:address).and_return(nil)

click_button "Send me a letter with the code"

expect(page).to have_content "We could not verify your address with the Census please try again later"
end

scenario "Deny access unless verified residence" do
user = create(:user)

Expand Down
22 changes: 0 additions & 22 deletions spec/models/letter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
expect(letter).to_not be_valid
end

it "should not be valid without an address" do
letter.address = {}
expect(letter).to_not be_valid
end

end

describe "save" do
Expand All @@ -36,23 +31,6 @@
expect(user.letter_requested_at).to be
end

it "should update address" do
expect(user.address).to have_attributes({
postal_code: "28013",
street: "ALCALÁ",
street_type: "CALLE",
number: "1",
number_type: "NUM",
letter: "B",
portal: "1",
stairway: "4",
floor: "PB",
door: "DR",
km: "0",
neighbourhood: "JUSTICIA",
district: "CENTRO"
})
end
end

describe "#verified?" do
Expand Down

0 comments on commit fbb5db8

Please sign in to comment.