-
-
-

<%= t("debates.index.showing") %>

- <%= render 'order_selector' %> -
-
- +
+ +
+ <% if @tag_filter %> +

+ <%= t("debates.index.filter_topic", + number: @debates.size, + topic: @tag_filter).html_safe %> +

+ <% else %> +

<%= t("debates.index.select_topic") %>

+
+ +
+ <% end %> +
+ +
+
<%= t("debates.index.select_order") %>
+
+ +
+
- -
-
-

- <%= t("debates.index.filter_topic", - number: "N", - topic: "topic").html_safe %> -

-
diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 83177bda8..071c61081 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -32,7 +32,7 @@ <%= link_to t("layouts.header.welcome"), root_path %>
- <%= link_to t("layouts.header.debates"), debates_path, class: ("active" if current_page?(controller: "debates")) %> + <%= link_to t("layouts.header.debates"), debates_path, class: ("active" if current_page?(controller: "/debates")) %>
<%= link_to t("layouts.header.initiatives"), "#" %> diff --git a/app/views/mailer/email_verification.html.erb b/app/views/mailer/email_verification.html.erb new file mode 100644 index 000000000..a57a5b0dc --- /dev/null +++ b/app/views/mailer/email_verification.html.erb @@ -0,0 +1,15 @@ + + +

+ <%= t("mailers.email_verification.title") %> +

+ +

+ <%= t("mailers.email_verification.instructions_html", + verification_link: link_to( + t('mailers.email_verification.click_here_to_verify'), + email_url(email_verification_token: @token))) %> +

+ + + diff --git a/app/views/shared/_errors.html.erb b/app/views/shared/_errors.html.erb index 180fd2388..b3935d770 100644 --- a/app/views/shared/_errors.html.erb +++ b/app/views/shared/_errors.html.erb @@ -1,8 +1,14 @@ <% if resource.errors.any? %>
- - <%= pluralize resource.errors.count, t("form.error"), t("form.errors") %> - <%= t("form.not_saved", resource: t("form.#{resource.class.to_s.downcase}")) %> - + + <%= pluralize resource.errors.count, t("form.error"), t("form.errors") %> + + <% if local_assigns[:message].present? %> + <%= message %> + <% else %> + <%= t("form.not_saved", resource: t("form.#{resource.class.to_s.downcase}")) %> + <% end %> + +
<% end %> \ No newline at end of file diff --git a/app/views/verification/email/_form.html.erb b/app/views/verification/email/_form.html.erb new file mode 100644 index 000000000..94039e5e2 --- /dev/null +++ b/app/views/verification/email/_form.html.erb @@ -0,0 +1,4 @@ +<%= form_for Email.new(verified_user), url: email_path, method: :post do |f| %> + <%= hidden_field_tag :recipient, verified_user.email %> + <%= f.submit t('verification.email.form.submit_button') %> +<% end %> \ No newline at end of file diff --git a/app/views/verification/letter/new.html.erb b/app/views/verification/letter/new.html.erb new file mode 100644 index 000000000..ab1d3070e --- /dev/null +++ b/app/views/verification/letter/new.html.erb @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/app/views/verification/residence/_errors.html.erb b/app/views/verification/residence/_errors.html.erb new file mode 100644 index 000000000..cc64d9fbc --- /dev/null +++ b/app/views/verification/residence/_errors.html.erb @@ -0,0 +1,12 @@ +<% if @residence.errors[:residence_in_madrid].present? %> + +
+ <%= t('verification.residence.new.error_verifying_census') %> + <%= mail_to "tec.gobiernoabierto@madrid.es" %> +
+ +<% else %> + <%= render 'shared/errors', + resource: @residence, + message: t('verification.residence.new.form_errors') %> +<% end %> \ No newline at end of file diff --git a/app/views/verification/residence/new.html.erb b/app/views/verification/residence/new.html.erb new file mode 100644 index 000000000..83e1b6f73 --- /dev/null +++ b/app/views/verification/residence/new.html.erb @@ -0,0 +1,19 @@ + \ No newline at end of file diff --git a/app/views/verification/sms/_form.html.erb b/app/views/verification/sms/_form.html.erb new file mode 100644 index 000000000..efa0f74b8 --- /dev/null +++ b/app/views/verification/sms/_form.html.erb @@ -0,0 +1,5 @@ +<%= form_for sms, url: sms_path do |f| %> + <%= render 'shared/errors', resource: sms %> + <%= f.hidden_field :phone %> + <%= f.submit t('verification.sms.form.submit_button') %> +<% end %> \ No newline at end of file diff --git a/app/views/verification/sms/edit.html.erb b/app/views/verification/sms/edit.html.erb new file mode 100644 index 000000000..89fbef5ff --- /dev/null +++ b/app/views/verification/sms/edit.html.erb @@ -0,0 +1,16 @@ + \ No newline at end of file diff --git a/app/views/verification/sms/new.html.erb b/app/views/verification/sms/new.html.erb new file mode 100644 index 000000000..eec63f6c6 --- /dev/null +++ b/app/views/verification/sms/new.html.erb @@ -0,0 +1,14 @@ + \ No newline at end of file diff --git a/app/views/verification/verified_user/show.html.erb b/app/views/verification/verified_user/show.html.erb new file mode 100644 index 000000000..bb61e8546 --- /dev/null +++ b/app/views/verification/verified_user/show.html.erb @@ -0,0 +1,49 @@ + \ No newline at end of file diff --git a/config/deploy.rb b/config/deploy.rb index eda66bc08..6233229d8 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -8,7 +8,7 @@ end set :rails_env, fetch(:stage) -set :rvm_ruby_version, '2.2.2' +set :rvm_ruby_version, '2.2.3' set :rvm_type, :user set :application, 'participacion' diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index d45c73d9b..c1991cd64 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -24,6 +24,7 @@ data: - config/locales/%{locale}.yml - config/locales/admin.%{locale}.yml - config/locales/moderation.%{locale}.yml + - config/locales/verification.%{locale}.yml - config/locales/mailers.%{locale}.yml - config/locales/devise_views.%{locale}.yml - config/locales/responders.%{locale}.yml diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 01ef3e663..a6dfa75c0 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -9,3 +9,4 @@ Rails.application.config.assets.version = '1.0' # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. # Rails.application.config.assets.precompile += %w( search.js ) +Rails.application.config.assets.precompile += %w( ckeditor/* ) diff --git a/config/locales/activemodel.en.yml b/config/locales/activemodel.en.yml new file mode 100644 index 000000000..edf91fdc4 --- /dev/null +++ b/config/locales/activemodel.en.yml @@ -0,0 +1,16 @@ +en: + activemodel: + models: + 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' \ No newline at end of file diff --git a/config/locales/activemodel.es.yml b/config/locales/activemodel.es.yml new file mode 100644 index 000000000..f72fdd385 --- /dev/null +++ b/config/locales/activemodel.es.yml @@ -0,0 +1,16 @@ +es: + activemodel: + models: + 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' \ No newline at end of file diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index 94b1fa0c9..e78d86512 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -7,6 +7,7 @@ en: user: User vote: Vote organization: Organization + residence: Residencia attributes: comment: body: Comment diff --git a/config/locales/en.yml b/config/locales/en.yml index 48cb717b6..148eaed88 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -52,15 +52,18 @@ en: accept_terms: I accept the privacy policy and the legal terms user: account debate: debate + sms: phone debates: index: create_debate: Create a debate - showing: You are seeing debates + select_order: Order by orders: created_at: newest total_votes: most voted likes: best rated + select_topic: "Filter by topic:" filter_topic: "You are seeing %{number} debates with the topic '%{topic}'" + all: All debate: debate: Debate comments: @@ -149,6 +152,9 @@ en: phone_number_label: "Phone number" organization_name_label: "Organization name" notifications: Notifications + level_two_user: You are a level 2 user + level_three_user: You are a level 3 user + verify_my_account: Verify my account simple_captcha: placeholder: "Enter the image value" label: "Enter the code in the box" diff --git a/config/locales/es.yml b/config/locales/es.yml index 76015f4c8..4b4816047 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -52,15 +52,18 @@ es: accept_terms: Acepto la política de privacidad y el aviso legal user: la cuenta debate: el debate + sms: el teléfono debates: index: create_debate: Crea un debate - showing: "Estás viendo los debates" + select_order: Ordenar por orders: created_at: "más nuevos" total_votes: "más votados" likes: mejor valorados + select_topic: "Filtrar por tema:" filter_topic: "Estás viendo %{number} debates con el tema '%{topic}'" + all: Todos debate: debate: Debate comments: @@ -149,6 +152,9 @@ es: phone_number_label: "Teléfono" organization_name_label: "Nombre de la organización" notifications: Notificaciones + level_two_user: Eres un usuario verificado de nivel 2 + level_three_user: Eres un usuario verificado de nivel 3 + verify_my_account: Verificar mi cuenta simple_captcha: placeholder: "Introduce el texto de la imagen" label: "Introduce el texto en la caja" diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index d0550aca9..4e3eeeab3 100644 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -3,8 +3,13 @@ en: comment: hi: Hello title: New comment on your debate - new_comment_by_html: "There'is a new comment by on" + new_comment_by_html: "There is a new comment by %{commenter} on" reply: hi: Hello title: New reply on your comment new_reply_by_html: "There'is a new reply by %{commenter} to your comment on" + email_verification: + title: Please verify yourself + instructions_html: "We need to verify you using this email, which we got from the Census. %{verification_link}" + click_here_to_verify: "Please click here to verify yourself" + diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index 8efa1dc22..a6491f032 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -8,3 +8,7 @@ es: hi: Hola title: Nueva respuesta a tu comentario new_reply_by_html: "Hay una nueva respuesta de %{commenter} a tu comentario en" + email_verification: + title: Por favor verifícate + instructions_html: "Vamos a proceder a verificar tu cuenta en la aplicación de participación ciudadana utilizando esta cuenta de correo que sacamos del padrón. %{verification_link}." + click_here_to_verify: "Por favor pulsa este enlace para verificarte" diff --git a/config/locales/rails.es.yml b/config/locales/rails.es.yml index f29361c45..9a6e698d2 100644 --- a/config/locales/rails.es.yml +++ b/config/locales/rails.es.yml @@ -125,6 +125,7 @@ es: too_short: es demasiado corto (%{count} caracteres mínimo) wrong_length: no tiene la longitud correcta (%{count} caracteres exactos) other_than: debe ser distinto de %{count} + invalid_date: "no es una fecha valida" template: body: 'Se encontraron problemas con los siguientes campos:' header: diff --git a/config/locales/verification.en.yml b/config/locales/verification.en.yml new file mode 100644 index 000000000..f9b2db4fb --- /dev/null +++ b/config/locales/verification.en.yml @@ -0,0 +1,72 @@ +en: + verification: + residence: + new: + title: 'Verify residence' + document_type: + spanish_id: 'Spanish ID' + passport: 'Passport' + residence_card: 'Residence card' + form_errors: 'prevented your residence verification' + error_verifying_census: 'The census of the city of Madrid could not verify your information. Pero revise de information and try again or get in touch with us.' + create: + flash: + success: 'Residence verified' + alert: + verify_attemps_left: 'You have reached the maximum number of Census verification tries' + unconfirmed_residency: 'You have not yet confirmed your residence' + sms: + new: + title: Phone verification + submit_button: Send + create: + flash: + success: 'Enter the confirmation code we have sent your phone' + edit: + title: Security code confirmation + resend_sms_text: You have not received the confirmation code in your phone? + resend_sms_link: Click here to send the confirmation code again + submit_button: Send + update: + error: 'Incorrect confirmation code' + flash: + level_three: + success: 'Correct code. You are now a verified user' + level_two: + success: 'Correct code' + form: + submit_button: Send + alert: + verify_attemps_left: 'You have reached the maximum number of sms verification tries' + email: + show: + flash: + success: 'You are now a verified user' + alert: + failure: 'Incorrect verification code' + create: + flash: + success: "We have send you a confirmation email to your email account: %{email}" + alert: + failure: "There was a problem sending you an email to your account" + form: + submit_button: Send + letter: + new: + title: Final Verification + explanation: 'To completely verify your account we need to go to one of these offices or send you a letter with a special code to your home address' + submit_button: 'Send me a letter' + create: + flash: + success: "You will receive a letter to your home address in the next couple of days" + alert: + failure: "We could not verify your address with the Census please try again later" + alert: + unconfirmed_personal_data: 'You have not yet confirmed your personal data' + verified_user: + show: + title: Available information + email_title: Emails + phone_title: Phones + use_another_phone: Use another phone + diff --git a/config/locales/verification.es.yml b/config/locales/verification.es.yml new file mode 100644 index 000000000..b9cda6aed --- /dev/null +++ b/config/locales/verification.es.yml @@ -0,0 +1,71 @@ +es: + verification: + residence: + new: + title: 'Verificar residencia' + document_type: + spanish_id: 'DNI' + passport: 'Pasaporte' + residence_card: 'Tarjeta de residencia' + form_errors: 'evitaron verificar tu residencia' + error_verifying_census: 'El Padrón de Madrid no pudo verificar tu información. Revisa la información ó ponte en contacto con nosotros.' + create: + flash: + success: 'Residencia verificada' + alert: + verify_attemps_left: 'Has llegado al máximo número de intentos de verificar tu residencia.' + unconfirmed_residency: 'Aún no has verificado tu residencia' + sms: + new: + title: Verificación de teléfono móvil + submit_button: Enviar + create: + flash: + success: 'Introduce el código de confirmación que te hemos enviado por mensaje de texto' + edit: + title: 'Confirmación de código de seguridad' + resend_sms_text: '¿No has recibido un mensaje de texto con tu código de confirmación?' + resend_sms_link: 'Haz click aquí para volver a enviártelo' + submit_button: Enviar + update: + error: 'Código de confirmación incorrecto' + flash: + level_three: + success: 'Código correcto. Ya eres un usuario verificado' + level_two: + success: 'Código incorrecto' + form: + submit_button: Enviar + alert: + verify_attemps_left: 'Has llegado al máximo número de intentos de verificar tu teléfono.' + email: + show: + flash: + success: 'Eres un usuario verificado' + alert: + failure: 'Código de verificación incorrecto' + create: + flash: + success: "Te hemos enviado un email de confirmación a tu cuenta: %{email}" + alert: + failure: "Hubo un problema enviándote un email a tu cuenta" + form: + submit_button: Enviar + letter: + new: + title: Final Verification + explanation: 'To completely verify your account we need to go to one of these offices or send you a letter with a special code to your home address' + submit_button: 'Send me a letter' + create: + flash: + success: "You will receive a letter to your home address in the next couple of days" + alert: + failure: "We could not verify your address with the Census please try again later" + alert: + unconfirmed_personal_data: 'You have not yet confirmed your personal data' + verified_user: + show: + title: Información disponible + email_title: Emails + phone_title: Teléfonos + use_another_phone: Utilizar otro teléfono diff --git a/config/routes.rb b/config/routes.rb index eb3953ea9..2e6a23cb7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -42,10 +42,13 @@ Rails.application.routes.draw do end resource :account, controller: "account", only: [:show, :update] - resource :stats, only: [:show] - namespace :api do - resource :stats, only: [:show] + scope module: :verification do + resource :residence, controller: "residence", only: [:new, :create] + resource :sms, controller: "sms", only: [:new, :create, :edit, :update] + resource :verified_user, controller: "verified_user", only: [:show] + resource :email, controller: "email", only: [:new, :show, :create] + resource :letter, controller: "letter", only: [:new, :create] end namespace :admin do @@ -110,6 +113,12 @@ Rails.application.routes.draw do end end + resource :stats, only: [:show] + + namespace :api do + resource :stats, only: [:show] + end + # Example of regular route: # get 'products/:id' => 'catalog#view' diff --git a/db/migrate/20150819193457_add_sms_verification_code_to_users.rb b/db/migrate/20150819193457_add_sms_verification_code_to_users.rb new file mode 100644 index 000000000..d886a5ad6 --- /dev/null +++ b/db/migrate/20150819193457_add_sms_verification_code_to_users.rb @@ -0,0 +1,6 @@ +class AddSmsVerificationCodeToUsers < ActiveRecord::Migration + def change + add_column :users, :sms_verification_code, :string + add_column :users, :sms_verified_at, :datetime + end +end diff --git a/db/migrate/20150819203410_add_phone_to_users.rb b/db/migrate/20150819203410_add_phone_to_users.rb new file mode 100644 index 000000000..7f94bae93 --- /dev/null +++ b/db/migrate/20150819203410_add_phone_to_users.rb @@ -0,0 +1,5 @@ +class AddPhoneToUsers < ActiveRecord::Migration + def change + add_column :users, :phone, :string + end +end diff --git a/db/migrate/20150822095305_create_verified_users.rb b/db/migrate/20150822095305_create_verified_users.rb new file mode 100644 index 000000000..bb0c54042 --- /dev/null +++ b/db/migrate/20150822095305_create_verified_users.rb @@ -0,0 +1,14 @@ +class CreateVerifiedUsers < ActiveRecord::Migration + def change + unless ActiveRecord::Base.connection.table_exists? 'verified_users' + create_table :verified_users do |t| + t.string :document_number + t.string :document_type + t.string :phone + t.string :email + + t.timestamps null: false + end + end + end +end diff --git a/db/migrate/20150822100557_add_document_to_users.rb b/db/migrate/20150822100557_add_document_to_users.rb new file mode 100644 index 000000000..48259c417 --- /dev/null +++ b/db/migrate/20150822100557_add_document_to_users.rb @@ -0,0 +1,6 @@ +class AddDocumentToUsers < ActiveRecord::Migration + def change + add_column :users, :document_number, :string + add_column :users, :document_type, :string + end +end diff --git a/db/migrate/20150822132547_add_residence_verified_at_to_users.rb b/db/migrate/20150822132547_add_residence_verified_at_to_users.rb new file mode 100644 index 000000000..65750fe82 --- /dev/null +++ b/db/migrate/20150822132547_add_residence_verified_at_to_users.rb @@ -0,0 +1,5 @@ +class AddResidenceVerifiedAtToUsers < ActiveRecord::Migration + def change + add_column :users, :residence_verified_at, :datetime + end +end diff --git a/db/migrate/20150823111403_add_letter_to_users.rb b/db/migrate/20150823111403_add_letter_to_users.rb new file mode 100644 index 000000000..bdb7c8684 --- /dev/null +++ b/db/migrate/20150823111403_add_letter_to_users.rb @@ -0,0 +1,6 @@ +class AddLetterToUsers < ActiveRecord::Migration + def change + add_column :users, :letter_requested, :boolean, default: false + add_column :users, :letter_sent_at, :datetime + end +end diff --git a/db/migrate/20150823114519_add_email_verified_at_to_users.rb b/db/migrate/20150823114519_add_email_verified_at_to_users.rb new file mode 100644 index 000000000..69a6b6ec1 --- /dev/null +++ b/db/migrate/20150823114519_add_email_verified_at_to_users.rb @@ -0,0 +1,5 @@ +class AddEmailVerifiedAtToUsers < ActiveRecord::Migration + def change + add_column :users, :email_verified_at, :datetime + end +end diff --git a/db/migrate/20150823121109_add_email_verification_to_users.rb b/db/migrate/20150823121109_add_email_verification_to_users.rb new file mode 100644 index 000000000..4342cc174 --- /dev/null +++ b/db/migrate/20150823121109_add_email_verification_to_users.rb @@ -0,0 +1,6 @@ +class AddEmailVerificationToUsers < ActiveRecord::Migration + def change + add_column :users, :email_verification_token, :string + add_column :users, :email_for_verification, :string + end +end diff --git a/db/migrate/20150824110104_add_verified_user_sms_verified_at_to_users.rb b/db/migrate/20150824110104_add_verified_user_sms_verified_at_to_users.rb new file mode 100644 index 000000000..06d8f47d0 --- /dev/null +++ b/db/migrate/20150824110104_add_verified_user_sms_verified_at_to_users.rb @@ -0,0 +1,5 @@ +class AddVerifiedUserSmsVerifiedAtToUsers < ActiveRecord::Migration + def change + add_column :users, :verified_user_sms_verified_at, :datetime + end +end diff --git a/db/migrate/20150825165517_add_sms_tried_to_users.rb b/db/migrate/20150825165517_add_sms_tried_to_users.rb new file mode 100644 index 000000000..280ab5b15 --- /dev/null +++ b/db/migrate/20150825165517_add_sms_tried_to_users.rb @@ -0,0 +1,5 @@ +class AddSmsTriedToUsers < ActiveRecord::Migration + def change + add_column :users, :sms_tries, :integer, default: 0 + end +end diff --git a/db/migrate/20150825175647_add_residence_verification_tries_to_users.rb b/db/migrate/20150825175647_add_residence_verification_tries_to_users.rb new file mode 100644 index 000000000..fb8a9ed6c --- /dev/null +++ b/db/migrate/20150825175647_add_residence_verification_tries_to_users.rb @@ -0,0 +1,5 @@ +class AddResidenceVerificationTriesToUsers < ActiveRecord::Migration + def change + add_column :users, :residence_verification_tries, :integer, default: 0 + end +end diff --git a/db/migrate/20150825201922_create_addresses.rb b/db/migrate/20150825201922_create_addresses.rb new file mode 100644 index 000000000..f3bc11ec2 --- /dev/null +++ b/db/migrate/20150825201922_create_addresses.rb @@ -0,0 +1,23 @@ +class CreateAddresses < ActiveRecord::Migration + def change + create_table :addresses 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.timestamps null: false + end + end +end diff --git a/db/migrate/20150826182010_refactor_verification_columns.rb b/db/migrate/20150826182010_refactor_verification_columns.rb new file mode 100644 index 000000000..1133d323e --- /dev/null +++ b/db/migrate/20150826182010_refactor_verification_columns.rb @@ -0,0 +1,20 @@ +class RefactorVerificationColumns < ActiveRecord::Migration + def change + rename_column :users, :sms_verification_code, :sms_confirmation_code + + remove_column :users, :sms_verified_at + remove_column :users, :email_verified_at + remove_column :users, :email_for_verification + remove_column :users, :verified_user_sms_verified_at + add_column :users, :verified_at, :datetime + + remove_column :users, :phone + add_column :users, :unconfirmed_phone, :string + add_column :users, :confirmed_phone, :string + + remove_column :users, :letter_requested + add_column :users, :letter_requested_at, :datetime + + rename_column :users, :sms_tries, :sms_confirmation_tries + end +end diff --git a/db/schema.rb b/db/schema.rb index 0da2f7c6a..fd22d3092 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -16,6 +16,26 @@ ActiveRecord::Schema.define(version: 20150828085718) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + 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 @@ -47,8 +67,8 @@ ActiveRecord::Schema.define(version: 20150828085718) do t.integer "rgt" t.datetime "created_at" t.datetime "updated_at" - t.integer "children_count", default: 0 t.datetime "hidden_at" + t.integer "children_count", default: 0 t.integer "flags_count", default: 0 t.datetime "ignored_flag_at" t.integer "moderator_id" @@ -70,14 +90,14 @@ ActiveRecord::Schema.define(version: 20150828085718) do t.string "title", limit: 80 t.text "description" t.integer "author_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.datetime "hidden_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "visit_id" + t.datetime "hidden_at" t.integer "flags_count", default: 0 - t.integer "cached_votes_total", default: 0 - t.integer "cached_votes_up", default: 0 - t.integer "cached_votes_down", default: 0 + t.integer "cached_votes_total", default: 0 + t.integer "cached_votes_up", default: 0 + t.integer "cached_votes_down", default: 0 t.datetime "ignored_flag_at" t.integer "comments_count", default: 0 t.datetime "confirmed_hide_at" @@ -161,29 +181,41 @@ ActiveRecord::Schema.define(version: 20150828085718) 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 "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" t.string "unconfirmed_email" - t.boolean "email_on_debate_comment", default: false - t.boolean "email_on_comment_reply", default: false + t.boolean "email_on_debate_comment", default: false + t.boolean "email_on_comment_reply", default: false + t.string "phone_number", limit: 30 t.string "official_position" - t.integer "official_level", default: 0 + t.integer "official_level", default: 0 t.datetime "hidden_at" - t.string "phone_number", limit: 30 + t.string "sms_confirmation_code" t.string "username" + t.string "document_number" + t.string "document_type" + t.datetime "residence_verified_at" + t.datetime "letter_sent_at" + t.string "email_verification_token" + t.integer "sms_confirmation_tries", default: 0 + t.integer "residence_verification_tries", default: 0 + t.datetime "verified_at" + t.string "unconfirmed_phone" + t.string "confirmed_phone" + t.datetime "letter_requested_at" t.datetime "confirmed_hide_at" end @@ -192,6 +224,15 @@ ActiveRecord::Schema.define(version: 20150828085718) do add_index "users", ["hidden_at"], name: "index_users_on_hidden_at", using: :btree add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree + create_table "verified_users", force: :cascade do |t| + t.string "document_number" + t.string "document_type" + t.string "phone" + t.string "email" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "visits", id: :uuid, default: nil, force: :cascade do |t| t.uuid "visitor_id" t.string "ip" diff --git a/lib/active_model/dates.rb b/lib/active_model/dates.rb new file mode 100644 index 000000000..a519e3840 --- /dev/null +++ b/lib/active_model/dates.rb @@ -0,0 +1,25 @@ +module ActiveModel::Dates + + def parse_date(field, attrs) + day, month, year = attrs["#{field}(1i)"], + attrs["#{field}(2i)"], + attrs["#{field}(3i)"] + + return nil unless day.present? && month.present? && year.present? + Date.new(day.to_i, month.to_i, year.to_i) + end + + def remove_date(field, attrs) + attrs.except("#{field}(1i)", "#{field}(2i)", "#{field}(3i)") + end + + def date_to_string(date) + date.strftime("%d-%m-%Y") + end + + def string_to_date(value) + day, month, year = value.split("-") + Date.new(year.to_i, month.to_i, day.to_i) + end + +end \ No newline at end of file diff --git a/lib/census_api.rb b/lib/census_api.rb new file mode 100644 index 000000000..ac5a88d08 --- /dev/null +++ b/lib/census_api.rb @@ -0,0 +1,58 @@ +class CensusApi + attr_accessor :client, :citizen, :response + + def initialize(citizen) + @citizen = citizen + end + + def client + @client = Savon.client(wsdl: Rails.application.secrets.padron_end_point) + end + + def response + return stubbed_response unless end_point_available? + client.call(:get_habita_datos, message: request).body + end + + def request + { request: + { codigo_institucion: Rails.application.secrets.institution_code, + codigo_portal: Rails.application.secrets.portal_name, + codigo_usuario: Rails.application.secrets.user_code, + documento: citizen.document_number, + tipo_documento: citizen.document_type, + codigo_idioma: 102, + nivel: 3 }} + end + + def data + response[:get_habita_datos_response][:get_habita_datos_return] + end + + def date_of_birth + data[:datos_habitante][:item][:fecha_nacimiento_string] + end + + 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? + + citizen.date_of_birth == date_of_birth && + citizen.postal_code == postal_code + end + + def end_point_available? + Rails.env.staging? || Rails.env.production? + 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"}}}}} + end +end diff --git a/lib/sms_api.rb b/lib/sms_api.rb new file mode 100644 index 000000000..886ed7f34 --- /dev/null +++ b/lib/sms_api.rb @@ -0,0 +1,44 @@ +require 'open-uri' +class SMSApi + attr_accessor :client + + def initialize + @client = Savon.client(wsdl: url) + end + + def url + return "" unless end_point_available? + open(Rails.application.secrets.sms_end_point).base_uri.to_s + end + + def authorization + Base64.encode64("#{Rails.application.secrets.sms_username}:#{Rails.application.secrets.sms_password}") + end + + def sms_deliver(phone, code) + return stubbed_response unless end_point_available? + + response = client.call(:enviar_sms_simples, message: request(phone, code)) + success?(response) + end + + def request(phone, code) + { autorizacion: authorization, + destinatarios: { destinatario: phone }, + texto_mensaje: "Código de verificación: #{code}", + solicita_notificacion: "All" } + end + + def success?(response) + response.body[:respuesta_sms][:respuesta_servicio_externo][:texto_respuesta] == "Success" + end + + def end_point_available? + Rails.env.staging? || Rails.env.production? + end + + def stubbed_response + {:respuesta_sms=>{:identificador_mensaje=>"1234567", :fecha_respuesta=>"Thu, 20 Aug 2015 16:28:05 +0200", :respuesta_pasarela=>{:codigo_pasarela=>"0000", :descripcion_pasarela=>"Operación ejecutada correctamente."}, :respuesta_servicio_externo=>{:codigo_respuesta=>"1000", :texto_respuesta=>"Success"}}} + end + +end diff --git a/lib/verification.rb b/lib/verification.rb new file mode 100644 index 000000000..2e784d65c --- /dev/null +++ b/lib/verification.rb @@ -0,0 +1,20 @@ +module Verification + + def residence_verified? + residence_verified_at.present? + end + + def sms_verified? + confirmed_phone.present? + end + + def level_two_verified? + residence_verified? && sms_verified? + end + + def level_three_verified? + verified_at.present? + end + + +end \ No newline at end of file diff --git a/spec/factories.rb b/spec/factories.rb index 3e355499a..a9bff4ac1 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -20,6 +20,33 @@ FactoryGirl.define do uid "MyString" end + factory :residence do + document_number '12345678Z' + document_type 1 + date_of_birth Date.new(1980, 12, 31) + postal_code "28013" + end + + factory :sms do + phone "699999999" + end + + factory :letter do + user + address + end + + factory :address do + street_type "Calle" + street "Alcalá" + number "1" + end + + factory :verified_user do + document_number '12345678Z' + document_type 'dni' + end + factory :debate do sequence(:title) { |n| "Debate #{n} title" } description 'Debate description' diff --git a/spec/features/comments_spec.rb b/spec/features/comments_spec.rb index 0986412bc..9814a4b33 100644 --- a/spec/features/comments_spec.rb +++ b/spec/features/comments_spec.rb @@ -59,7 +59,7 @@ feature 'Comments' do login_as(user) visit debate_path(debate) - fill_in 'comment_body', with: 'Have you thought about...?' + fill_in "comment-body-debate_#{debate.id}", with: 'Have you thought about...?' click_button 'Publish comment' within "#comments" do @@ -91,7 +91,7 @@ feature 'Comments' do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in 'comment_body', with: 'It will be done next week.' + fill_in "comment-body-comment_#{comment.id}", with: 'It will be done next week.' click_button 'Publish reply' end @@ -178,8 +178,8 @@ feature 'Comments' do login_as(moderator.user) visit debate_path(debate) - fill_in "comment_body", with: "I am moderating!" - check "comment_as_moderator" + fill_in "comment-body-debate_#{debate.id}", with: "I am moderating!" + check "comment-as-moderator-debate_#{debate.id}" click_button "Publish comment" within "#comments" do @@ -203,8 +203,8 @@ feature 'Comments' do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment_body", with: "I am moderating!" - check "comment_as_moderator" + fill_in "comment-body-comment_#{comment.id}", with: "I am moderating!" + check "comment-as-moderator-comment_#{comment.id}" click_button 'Publish reply' end @@ -237,8 +237,8 @@ feature 'Comments' do login_as(admin.user) visit debate_path(debate) - fill_in "comment_body", with: "I am your Admin!" - check "comment_as_administrator" + fill_in "comment-body-debate_#{debate.id}", with: "I am your Admin!" + check "comment-as-administrator-debate_#{debate.id}" click_button "Publish comment" within "#comments" do @@ -262,8 +262,8 @@ feature 'Comments' do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment_body", with: "Top of the world!" - check "comment_as_administrator" + fill_in "comment-body-comment_#{comment.id}", with: "Top of the world!" + check "comment-as-administrator-comment_#{comment.id}" click_button 'Publish reply' end diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 3f01bd312..da966f7a3 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -407,4 +407,34 @@ feature 'Debates' do expect(@most_liked_debate.title).to appear_before(@most_voted_debate.title) end end + + feature 'Debates can be filtered by tags', :js do + let!(:debate1) { create(:debate, tag_list: ["Deporte", "Corrupción"]) } + let!(:debate2) { create(:debate, tag_list: ["Deporte", "Fiestas populares"]) } + let!(:debate3) { create(:debate, tag_list: ["Corrupción", "Fiestas populares"]) } + + scenario 'By default no tag filter is applied' do + visit debates_path + + expect(page).to have_content('Filter by topic') + expect(page).not_to have_content('with the topic') + expect(page).to have_selector('#debates .debate', count: 3) + end + + scenario 'Debates are filtered by single tag' do + visit debates_path + + select('Deporte', from: 'tag-filter') + + expect(page).not_to have_content('Filter by topic') + expect(page).not_to have_select('tag-filter') + expect(page).to have_content('with the topic') + expect(current_url).to include('tag=Deporte') + + expect(page).to have_selector('#debates .debate', count: 2) + expect(page).to_not have_content(debate3.title) + expect(page).to have_content(debate1.title) + expect(page).to have_content(debate2.title) + end + end end diff --git a/spec/features/moderation/comments_spec.rb b/spec/features/moderation/comments_spec.rb index 6c2689f0e..4fdef5c10 100644 --- a/spec/features/moderation/comments_spec.rb +++ b/spec/features/moderation/comments_spec.rb @@ -4,7 +4,7 @@ feature 'Moderate Comments' do feature 'Hiding Comments' do - scenario 'Hide', :js do + scenario 'Hide without children hides the comment completely', :js do citizen = create(:user) moderator = create(:moderator) @@ -23,7 +23,7 @@ feature 'Moderate Comments' do visit debate_path(debate) expect(page).to have_css('.comment', count: 1) - expect(page).to have_content('This comment has been deleted') + expect(page).to_not have_content('This comment has been deleted') expect(page).to_not have_content('SPAM') end diff --git a/spec/features/verification/email_spec.rb b/spec/features/verification/email_spec.rb new file mode 100644 index 000000000..c886e4ff6 --- /dev/null +++ b/spec/features/verification/email_spec.rb @@ -0,0 +1,65 @@ +require 'rails_helper' + +feature 'Verify email' do + + scenario 'Verify' do + user = create(:user, + residence_verified_at: Time.now, + document_number: '12345678Z', + document_type: 'dni') + + verified_user = create(:verified_user, + document_number: '12345678Z', + document_type: 'dni', + email: 'rock@example.com') + + login_as(user) + + visit verified_user_path + + within("#verified_user_#{verified_user.id}_email") do + expect(page).to have_content 'rock@example.com' + click_button "Send" + end + + expect(page).to have_content 'We have send you a confirmation email to your email account: rock@example.com' + + sent_token = /.*email_verification_token=(.*)".*/.match(ActionMailer::Base.deliveries.last.body.to_s)[1] + visit email_path(email_verification_token: sent_token) + + expect(page).to have_content "You are now a verified user" + + expect(page).to_not have_link "Verify my account" + expect(page).to have_content "You are a level 3 user" + end + + scenario "Errors on token verification" do + user = create(:user, residence_verified_at: Time.now) + + login_as(user) + visit email_path(email_verification_token: "1234") + + expect(page).to have_content "Incorrect verification code" + end + + scenario "Errors on sending confirmation email" do + user = create(:user, + residence_verified_at: Time.now, + document_number: '12345678Z', + document_type: 'dni') + + verified_user = create(:verified_user, + document_number: '12345678Z', + document_type: 'dni', + email: 'rock@example.com') + + login_as(user) + + visit verified_user_path + + verified_user.destroy + click_button "Send" + + expect(page).to have_content "There was a problem sending you an email to your account" + end +end \ No newline at end of file diff --git a/spec/features/verification/letter_spec.rb b/spec/features/verification/letter_spec.rb new file mode 100644 index 000000000..fa4a451db --- /dev/null +++ b/spec/features/verification/letter_spec.rb @@ -0,0 +1,60 @@ +require 'rails_helper' + +feature 'Verify Letter' do + + scenario 'Send letter level 2 verified with phone' do + user = create(:user, residence_verified_at: Time.now, confirmed_phone: "611111111") + + login_as(user) + visit new_letter_path + + click_button "Send me a letter" + + expect(page).to have_content "You will receive a letter to your home address" + end + + scenario "Error accessing address from CensusApi" do + user = create(:user, residence_verified_at: Time.now, confirmed_phone: "611111111") + + login_as(user) + visit new_letter_path + + allow_any_instance_of(CensusApi).to receive(:address).and_return(nil) + + click_button "Send me a letter" + + expect(page).to have_content "We could not verify your address with the Census please try again later" + end + + scenario 'Send letter level 2 user verified with email' do + user = create(:user, residence_verified_at: Time.now, confirmed_phone: "611111111") + + login_as(user) + visit new_letter_path + + click_button "Send me a letter" + + expect(page).to have_content "You will receive a letter to your home address" + end + + scenario "Deny access unless verified residence" do + user = create(:user) + + login_as(user) + visit new_letter_path + + expect(page).to have_content 'You have not yet confirmed your residence' + expect(URI.parse(current_url).path).to eq(new_residence_path) + end + + scenario "Deny access unless verified phone/email" do + user = create(:user, residence_verified_at: Time.now) + + login_as(user) + visit new_letter_path + + expect(page).to have_content 'You have not yet confirmed your personal data' + expect(URI.parse(current_url).path).to eq(new_sms_path) + end + +end diff --git a/spec/features/verification/level_three_verification_spec.rb b/spec/features/verification/level_three_verification_spec.rb new file mode 100644 index 000000000..617065379 --- /dev/null +++ b/spec/features/verification/level_three_verification_spec.rb @@ -0,0 +1,113 @@ +require 'rails_helper' + +feature 'Level three verification' do + scenario 'Verification with residency and verified sms' do + user = create(:user) + + verified_user = create(:verified_user, + document_number: '12345678Z', + document_type: '1', + phone: '611111111') + + login_as(user) + + visit account_path + click_link 'Verify my account' + + select 'Spanish ID', from: 'residence_document_type' + fill_in 'residence_document_number', with: "12345678Z" + select_date '31-December-1980', from: 'residence_date_of_birth' + fill_in 'residence_postal_code', with: '28013' + + click_button 'Verify' + + expect(page).to have_content 'Residence verified' + + within("#verified_user_#{verified_user.id}_phone") do + click_button "Send" + end + + expect(page).to have_content 'Security code confirmation' + + user = user.reload + fill_in 'sms_confirmation_code', with: user.sms_confirmation_code + click_button 'Send' + + expect(page).to have_content 'Correct code' + + expect(page).to have_content "You are now a verified user" + + expect(page).to_not have_link "Verify my account" + expect(page).to have_content "You are a level 3 user" + end + + scenario 'Verification with residency and verified email' do + user = create(:user) + + verified_user = create(:verified_user, + document_number: '12345678Z', + document_type: '1', + email: 'rock@example.com') + + login_as(user) + + visit account_path + click_link 'Verify my account' + + select 'Spanish ID', from: 'residence_document_type' + fill_in 'residence_document_number', with: "12345678Z" + select_date '31-December-1980', from: 'residence_date_of_birth' + fill_in 'residence_postal_code', with: '28013' + + click_button 'Verify' + + expect(page).to have_content 'Residence verified' + + within("#verified_user_#{verified_user.id}_email") do + click_button "Send" + end + + expect(page).to have_content 'We have send you a confirmation email to your email account: rock@example.com' + + sent_token = /.*email_verification_token=(.*)".*/.match(ActionMailer::Base.deliveries.last.body.to_s)[1] + visit email_path(email_verification_token: sent_token) + + expect(page).to have_content "You are now a verified user" + + expect(page).to_not have_link "Verify my account" + expect(page).to have_content "You are a level 3 user" + end + + scenario 'Verification with residency and sms and letter' do + + user = create(:user) + login_as(user) + + visit account_path + click_link 'Verify my account' + + select 'Spanish ID', from: 'residence_document_type' + fill_in 'residence_document_number', with: "12345678Z" + select_date '31-December-1980', from: 'residence_date_of_birth' + fill_in 'residence_postal_code', with: '28013' + + click_button 'Verify' + + expect(page).to have_content 'Residence verified' + + fill_in 'sms_phone', with: "611111111" + click_button 'Send' + + expect(page).to have_content 'Security code confirmation' + + user = user.reload + fill_in 'sms_confirmation_code', with: user.sms_confirmation_code + click_button 'Send' + + expect(page).to have_content 'Correct code' + + click_button "Send me a letter" + + expect(page).to have_content "You will receive a letter to your home address" + end +end \ No newline at end of file diff --git a/spec/features/verification/level_two_verification_spec.rb b/spec/features/verification/level_two_verification_spec.rb new file mode 100644 index 000000000..8358d33fe --- /dev/null +++ b/spec/features/verification/level_two_verification_spec.rb @@ -0,0 +1,33 @@ +require 'rails_helper' + +feature 'Level two verification' do + + scenario 'Verification with residency and sms' do + user = create(:user) + login_as(user) + + visit account_path + click_link 'Verify my account' + + select 'Spanish ID', from: 'residence_document_type' + fill_in 'residence_document_number', with: "12345678Z" + select_date '31-December-1980', from: 'residence_date_of_birth' + fill_in 'residence_postal_code', with: '28013' + + click_button 'Verify' + + expect(page).to have_content 'Residence verified' + + fill_in 'sms_phone', with: "611111111" + click_button 'Send' + + expect(page).to have_content 'Security code confirmation' + + user = user.reload + fill_in 'sms_confirmation_code', with: user.sms_confirmation_code + click_button 'Send' + + expect(page).to have_content 'Correct code' + end + +end \ No newline at end of file diff --git a/spec/features/verification/residence_spec.rb b/spec/features/verification/residence_spec.rb new file mode 100644 index 000000000..95f25ed2b --- /dev/null +++ b/spec/features/verification/residence_spec.rb @@ -0,0 +1,80 @@ +require 'rails_helper' + +feature 'Residence' do + + scenario 'Verify resident in Madrid' do + user = create(:user) + login_as(user) + + visit account_path + click_link 'Verify my account' + + fill_in 'residence_document_number', with: "12345678Z" + select 'Spanish ID', from: 'residence_document_type' + select_date '31-December-1980', from: 'residence_date_of_birth' + fill_in 'residence_postal_code', with: '28013' + + click_button 'Verify' + + expect(page).to have_content 'Residence verified' + end + + scenario 'Error on verify' do + user = create(:user) + login_as(user) + + visit account_path + click_link 'Verify my account' + + click_button 'Verify' + + expect(page).to have_content /\d errors? prevented your residence verification/ + end + + scenario 'Error on Madrid census' do + user = create(:user) + login_as(user) + + visit account_path + click_link 'Verify my account' + + fill_in 'residence_document_number', with: "12345678Z" + select 'Spanish ID', from: 'residence_document_type' + select '1997', from: 'residence_date_of_birth_1i' + select 'January', from: 'residence_date_of_birth_2i' + select '1', from: 'residence_date_of_birth_3i' + fill_in 'residence_postal_code', with: '28013' + + click_button 'Verify' + + expect(page).to have_content 'The census of the city of Madrid could not verify your information' + end + + scenario '5 tries allowed' do + user = create(:user) + login_as(user) + + visit account_path + click_link 'Verify my account' + + 5.times do + fill_in 'residence_document_number', with: "12345678Z" + select 'Spanish ID', from: 'residence_document_type' + select '1997', from: 'residence_date_of_birth_1i' + select 'January', from: 'residence_date_of_birth_2i' + select '1', from: 'residence_date_of_birth_3i' + fill_in 'residence_postal_code', with: '28013' + + click_button 'Verify' + expect(page).to have_content 'The census of the city of Madrid could not verify your information' + end + + click_button 'Verify' + expect(page).to have_content 'You have reached the maximum number of Census verification tries' + expect(URI.parse(current_url).path).to eq(account_path) + + visit new_residence_path + expect(page).to have_content 'You have reached the maximum number of Census verification tries' + expect(URI.parse(current_url).path).to eq(account_path) + end +end \ No newline at end of file diff --git a/spec/features/verification/sms_spec.rb b/spec/features/verification/sms_spec.rb new file mode 100644 index 000000000..e445b3a27 --- /dev/null +++ b/spec/features/verification/sms_spec.rb @@ -0,0 +1,80 @@ +require 'rails_helper' + +feature 'SMS Verification' do + + scenario 'Verify' do + user = create(:user, residence_verified_at: Time.now) + login_as(user) + + visit new_sms_path + + fill_in 'sms_phone', with: "611111111" + click_button 'Send' + + expect(page).to have_content 'Security code confirmation' + + user = user.reload + fill_in 'sms_confirmation_code', with: user.sms_confirmation_code + click_button 'Send' + + expect(page).to have_content 'Correct code' + end + + scenario 'Errors on phone number' do + user = create(:user, residence_verified_at: Time.now) + login_as(user) + + visit new_sms_path + + click_button 'Send' + + expect(page).to have_content error_message + end + + scenario 'Errors on verification code' do + user = create(:user, residence_verified_at: Time.now) + login_as(user) + + visit new_sms_path + + fill_in 'sms_phone', with: "611111111" + click_button 'Send' + + expect(page).to have_content 'Security code confirmation' + + click_button 'Send' + + expect(page).to have_content 'Incorrect confirmation code' + end + + scenario 'Deny access unless residency verified' do + user = create(:user) + login_as(user) + + visit new_sms_path + + expect(page).to have_content 'You have not yet confirmed your residence' + expect(URI.parse(current_url).path).to eq(new_residence_path) + end + + scenario '3 tries allowed' do + user = create(:user, residence_verified_at: Time.now) + login_as(user) + + visit new_sms_path + + 3.times do + fill_in 'sms_phone', with: "611111111" + click_button 'Send' + click_link 'Click here to send the confirmation code again' + end + + expect(page).to have_content 'You have reached the maximum number of sms verification tries' + expect(URI.parse(current_url).path).to eq(account_path) + + visit new_sms_path + expect(page).to have_content 'You have reached the maximum number of sms verification tries' + expect(URI.parse(current_url).path).to eq(account_path) + end + +end \ No newline at end of file diff --git a/spec/features/verification/verified_user_spec.rb b/spec/features/verification/verified_user_spec.rb new file mode 100644 index 000000000..ce28ce80f --- /dev/null +++ b/spec/features/verification/verified_user_spec.rb @@ -0,0 +1,132 @@ +require 'rails_helper' + +feature 'Verified users' do + + scenario "Verified emails" do + user = create(:user, + residence_verified_at: Time.now, + document_number: '12345678Z', + document_type: '2') + + create(:verified_user, + document_number: '12345678Z', + document_type: '2', + email: 'rock@example.com') + + create(:verified_user, + document_number: '12345678Z', + document_type: '2', + email: 'roll@example.com') + + create(:verified_user, + document_number: '99999999R', + document_type: '2', + email: 'another@example.com') + + login_as(user) + visit verified_user_path + + expect(page).to have_content 'rock@example.com' + expect(page).to have_content 'roll@example.com' + end + + scenario "Verified phones" do + user = create(:user, + residence_verified_at: Time.now, + document_number: '12345678Z', + document_type: '2') + + create(:verified_user, + document_number: '12345678Z', + document_type: '2', + phone: '611111111') + + create(:verified_user, + document_number: '12345678Z', + document_type: '2', + email: '622222222') + + create(:verified_user, + document_number: '99999999R', + document_type: '2', + email: '633333333') + + login_as(user) + visit verified_user_path + + expect(page).to have_content '611111111' + expect(page).to have_content '622222222' + end + + scenario "Select a verified email" do + user = create(:user, + residence_verified_at: Time.now, + document_number: '12345678Z', + document_type: '2') + + verified_user = create(:verified_user, + document_number: '12345678Z', + document_type: '2', + email: 'rock@example.com') + + login_as(user) + visit verified_user_path + + within("#verified_user_#{verified_user.id}_email") do + click_button "Send" + end + + expect(page).to have_content 'We have send you a confirmation email to your email account: rock@example.com' + expect(URI.parse(current_url).path).to eq(account_path) + end + + scenario "Select a verified phone" do + user = create(:user, + residence_verified_at: Time.now, + document_number: '12345678Z', + document_type: '2') + + verified_user = create(:verified_user, + document_number: '12345678Z', + document_type: '2', + phone: '611111111') + + login_as(user) + visit verified_user_path + + within("#verified_user_#{verified_user.id}_phone") do + click_button "Send" + end + + expect(page).to have_content 'Enter the confirmation code' + end + + scenario "Continue without selecting any verified information" do + user = create(:user, + residence_verified_at: Time.now, + document_number: '12345678Z', + document_type: '2') + + create(:verified_user, + document_number: '12345678Z', + document_type: '2', + phone: '611111111') + + login_as(user) + visit verified_user_path + + click_link "Use another phone" + + expect(URI.parse(current_url).path).to eq(new_sms_path) + end + + scenario "No verified information" do + user = create(:user, residence_verified_at: Time.now) + + login_as(user) + visit verified_user_path + + expect(URI.parse(current_url).path).to eq(new_sms_path) + end + +end \ No newline at end of file diff --git a/spec/models/letter_spec.rb b/spec/models/letter_spec.rb new file mode 100644 index 000000000..e5e871d7c --- /dev/null +++ b/spec/models/letter_spec.rb @@ -0,0 +1,59 @@ +require 'rails_helper' + +describe 'Letter' do + + let(:user) { create(:user) } + + describe "validations" do + + let(:letter) { build(:letter) } + + it "should be valid" do + expect(letter).to be_valid + end + + it "should not be valid without a user" do + letter.user = nil + 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 + + before(:each) do + letter = Letter.new(user: user) + letter.save + user.reload + end + + it "should update letter_requested" do + 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 + +end \ No newline at end of file diff --git a/spec/models/residence_spec.rb b/spec/models/residence_spec.rb new file mode 100644 index 000000000..66eb34951 --- /dev/null +++ b/spec/models/residence_spec.rb @@ -0,0 +1,52 @@ +require 'rails_helper' + +describe Residence do + + let(:residence) { build(:residence) } + + describe "validations" do + + it "should be valid" do + expect(residence).to be_valid + end + + 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"}) + 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.valid? + expect(residence.errors[:date_of_birth]).to include("can't be blank") + end + end + + it "should validate uniquness of document_number" do + user = create(:user) + residence.user = user + residence.save + + residence2 = build(:residence) + + residence.valid? + expect(residence.errors[:document_number]).to include("Already in use") + end + end + + describe "save" do + + it "should store document number and type" do + user = create(:user) + residence.user = user + residence.save + + user.reload + expect(user.document_number).to eq('12345678Z') + expect(user.document_type).to eq("1") + end + + end + +end \ No newline at end of file diff --git a/spec/models/sms_spec.rb b/spec/models/sms_spec.rb new file mode 100644 index 000000000..bdcd2d739 --- /dev/null +++ b/spec/models/sms_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +describe Sms do + it "should be valid" do + sms = build(: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") + expect(sms).to_not be_valid + end + +end \ No newline at end of file diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 12d6affd3..5773293cd 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -30,7 +30,7 @@ module CommonActions login_as(user2) visit debate_path(debate) - fill_in 'comment_body', with: 'Have you thought about...?' + fill_in "comment-body-debate_#{debate.id}", with: 'Have you thought about...?' click_button 'Publish comment' expect(page).to have_content 'Have you thought about...?' end @@ -45,7 +45,7 @@ module CommonActions click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in 'comment_body', with: 'It will be done next week.' + fill_in "comment-body-comment_#{comment.id}", with: 'It will be done next week.' click_button 'Publish reply' end expect(page).to have_content 'It will be done next week.' @@ -80,4 +80,12 @@ module CommonActions def expect_to_be_signed_in expect(find('.top-bar')).to have_content 'My account' end + + def select_date(values, selector) + selector = selector[:from] + day, month, year = values.split("-") + select day, from: "#{selector}_3i" + select month, from: "#{selector}_2i" + select year, from: "#{selector}_1i" + end end