<%= f.submit t("devise_views.users.registrations.new.submit"), class: "button expanded" %>
diff --git a/app/views/verification/residence/new.html.erb b/app/views/verification/residence/new.html.erb
index b528598f9..a0d9b955e 100644
--- a/app/views/verification/residence/new.html.erb
+++ b/app/views/verification/residence/new.html.erb
@@ -69,12 +69,9 @@
<%= f.check_box :terms_of_service,
- title: t("verification.residence.new.accept_terms_text_title"),
label: t("verification.residence.new.accept_terms_text",
- terms_url: link_to(t("verification.residence.new.terms"),
- page_path("census_terms"),
- title: t("shared.target_blank"),
- target: "_blank")) %>
+ terms_url: new_window_link_to(t("verification.residence.new.terms"),
+ page_path("census_terms"))) %>
diff --git a/config/locales/en/devise_views.yml b/config/locales/en/devise_views.yml
index 7e184e028..85e95184f 100644
--- a/config/locales/en/devise_views.yml
+++ b/config/locales/en/devise_views.yml
@@ -103,7 +103,6 @@ en:
submit: Register
terms: By registering you accept the %{terms}
terms_link: terms and conditions of use
- terms_title: By registering you accept the terms and conditions of use
title: Register
username_is_available: Username available
username_is_not_available: Username already in use
diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml
index 0be47b5a9..4f58a19c3 100644
--- a/config/locales/en/general.yml
+++ b/config/locales/en/general.yml
@@ -143,7 +143,6 @@ en:
poll_ended: "Cannot be changed if voting has already ended"
form:
accept_terms: I agree to the %{policy} and the %{conditions}
- accept_terms_title: I agree to the Privacy Policy and the Terms and conditions of use
conditions: Terms and conditions of use
debate: Debate
direct_message: private message
diff --git a/config/locales/en/verification.yml b/config/locales/en/verification.yml
index 7b6ac56ee..7e6d33f79 100644
--- a/config/locales/en/verification.yml
+++ b/config/locales/en/verification.yml
@@ -46,7 +46,6 @@ en:
success: Residence verified
new:
accept_terms_text: I accept %{terms_url} of the Census
- accept_terms_text_title: I accept the terms and conditions of access of the Census
document_number: Document number
document_number_help_title: Help
document_number_help_text: "
DNI: 12345678A
Passport: AAA000001
Residence card: X1234567P"
diff --git a/config/locales/es/devise_views.yml b/config/locales/es/devise_views.yml
index da16e7421..5e3d5a40e 100644
--- a/config/locales/es/devise_views.yml
+++ b/config/locales/es/devise_views.yml
@@ -103,7 +103,6 @@ es:
submit: Registrarse
terms: Al registrarte aceptas las %{terms}
terms_link: condiciones de uso
- terms_title: Al registrarte aceptas las condiciones de uso
title: Registrarse
username_is_available: Nombre de usuario disponible
username_is_not_available: Nombre de usuario ya existente
diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml
index e40c5b43d..dd2380dbd 100644
--- a/config/locales/es/general.yml
+++ b/config/locales/es/general.yml
@@ -143,7 +143,6 @@ es:
poll_ended: "No puede ser cambiada si la votación ha acabado"
form:
accept_terms: Acepto la %{policy} y las %{conditions}
- accept_terms_title: Acepto la Política de privacidad y las Condiciones de uso
conditions: Condiciones de uso
debate: el debate
direct_message: el mensaje privado
diff --git a/config/locales/es/verification.yml b/config/locales/es/verification.yml
index 4f52a3d5a..75d909f11 100644
--- a/config/locales/es/verification.yml
+++ b/config/locales/es/verification.yml
@@ -46,7 +46,6 @@ es:
success: Residencia verificada
new:
accept_terms_text: Acepto %{terms_url} al Padrón
- accept_terms_text_title: Acepto los términos de acceso al Padrón
document_number: Número de documento
document_number_help_title: Ayuda
document_number_help_text: "
DNI: 12345678A
Pasaporte: AAA000001
Tarjeta de residencia: X1234567P"
diff --git a/lib/consul_form_builder.rb b/lib/consul_form_builder.rb
index e9868185e..620a0886c 100644
--- a/lib/consul_form_builder.rb
+++ b/lib/consul_form_builder.rb
@@ -23,7 +23,7 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder
if options[:label] == false
super
else
- label = tag.span sanitize(label_text(attribute, options[:label])), class: "checkbox"
+ label = tag.span sanitized_label_text(attribute, options[:label]), class: "checkbox"
super(attribute, options.merge(
label: label,
@@ -51,7 +51,7 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder
if text == false
super
else
- super(attribute, sanitize(label_text(attribute, text)), options)
+ super(attribute, sanitized_label_text(attribute, text), options)
end
end
@@ -68,6 +68,14 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder
end
end
+ def sanitized_label_text(attribute, text)
+ sanitize(label_text(attribute, text), attributes: allowed_attributes)
+ end
+
+ def allowed_attributes
+ self.class.sanitized_allowed_attributes + ["target"]
+ end
+
def label_options_for(options)
label_options = options[:label_options] || {}
diff --git a/spec/components/shared/agree_with_terms_of_service_field_component_spec.rb b/spec/components/shared/agree_with_terms_of_service_field_component_spec.rb
new file mode 100644
index 000000000..455346b7f
--- /dev/null
+++ b/spec/components/shared/agree_with_terms_of_service_field_component_spec.rb
@@ -0,0 +1,30 @@
+require "rails_helper"
+
+describe Shared::AgreeWithTermsOfServiceFieldComponent do
+ before do
+ dummy_model = Class.new do
+ include ActiveModel::Model
+ attr_accessor :terms_of_service
+ end
+
+ stub_const("DummyModel", dummy_model)
+ end
+
+ let(:form) { ConsulFormBuilder.new(:dummy, DummyModel.new, ApplicationController.new.view_context, {}) }
+ let(:component) { Shared::AgreeWithTermsOfServiceFieldComponent.new(form) }
+
+ it "contains links that open in a new window" do
+ render_inline component
+
+ expect(page).to have_css "a[target=_blank]", count: 2
+ end
+
+ it "contains links indicating they open in a new window" do
+ render_inline component
+
+ expect(page).to have_link count: 2
+ expect(page).to have_link "Privacy Policy"
+ expect(page).to have_link "Terms and conditions of use"
+ expect(page).to have_link " (link opens in new window)", count: 2
+ end
+end
diff --git a/spec/lib/consul_form_builder_spec.rb b/spec/lib/consul_form_builder_spec.rb
index d8d9adf5f..db57847d2 100644
--- a/spec/lib/consul_form_builder_spec.rb
+++ b/spec/lib/consul_form_builder_spec.rb
@@ -13,6 +13,17 @@ describe ConsulFormBuilder do
let(:builder) { ConsulFormBuilder.new(:dummy, DummyModel.new, ApplicationController.new.view_context, {}) }
+ describe "label" do
+ it "accepts links that open in a new window in its content" do
+ render builder.text_field(:title, label: 'My
title')
+
+ expect(page).to have_link count: 1
+ expect(page).to have_link "title"
+ expect(page).to have_link "New tab"
+ expect(page).to have_css "a[target=_blank]"
+ end
+ end
+
describe "hints" do
it "does not generate hints by default" do
render builder.text_field(:title)
diff --git a/spec/system/verification/residence_spec.rb b/spec/system/verification/residence_spec.rb
index c54e44fee..3603d4ba9 100644
--- a/spec/system/verification/residence_spec.rb
+++ b/spec/system/verification/residence_spec.rb
@@ -164,8 +164,9 @@ describe "Residence" do
login_as(create(:user))
visit new_residence_path
- click_link "the terms and conditions of access"
- expect(page).to have_content "Terms and conditions of access of the Census"
+ within_window(window_opened_by { click_link "the terms and conditions of access" }) do
+ expect(page).to have_content "Terms and conditions of access of the Census"
+ end
end
end