Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalise falsey values to nil to prevent lang="false" #1021

Merged
merged 3 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
useful summary for people upgrading their application, not a replication
of the commit log.

## Unreleased
* Normalise falsey values to nil for subscription links component (PR #1021)

## 17.21.0

* Add tests for email feedback form (PR #1017)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

hide_heading ||= false

email_signup_link_text_locale = local_assigns[:email_signup_link_text_locale]
feed_link_text_locale = local_assigns[:feed_link_text_locale]
email_signup_link_text_locale = local_assigns[:email_signup_link_text_locale].presence
feed_link_text_locale = local_assigns[:feed_link_text_locale].presence
%>
<% if sl_helper.component_data_is_valid? %>
<%= tag.section class: css_classes, data: data do %>
Expand Down
37 changes: 34 additions & 3 deletions spec/components/subscription_links_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ def component_name
render_component(
email_signup_link: 'email-signup',
email_signup_link_text: 'Get email!',
email_signup_link_text_locale: 'en',
email_signup_link_text_locale: 'es',
feed_link: 'singapore.atom',
feed_link_text: 'View feed!',
feed_link_text_locale: 'en',
feed_link_text_locale: 'fr',
)
assert_select ".gem-c-subscription-links__link[lang='en']", 2
assert_select ".gem-c-subscription-links__link[lang='es']", 1
assert_select ".gem-c-subscription-links__link[lang='fr']", 1
end

it "no lang attribute is added when not set" do
Expand All @@ -123,4 +124,34 @@ def component_name
)
assert_select ".gem-c-subscription-links__link[lang]", false
end

it "no lang attribute set when locale is set but empty" do
render_component(
email_signup_link: 'email-signup',
email_signup_link_text_locale: '',
feed_link: 'singapore.atom',
feed_link_text_locale: '',
)
assert_select ".gem-c-subscription-links__link[lang]", false
end

it "no lang attribute set when locale is false" do
render_component(
email_signup_link: 'email-signup',
email_signup_link_text_locale: false,
feed_link: 'singapore.atom',
feed_link_text_locale: false,
)
assert_select ".gem-c-subscription-links__link[lang]", false
end

it "no lang attribute set when locale is nil" do
render_component(
email_signup_link: 'email-signup',
email_signup_link_text_locale: nil,
feed_link: 'singapore.atom',
feed_link_text_locale: nil,
)
assert_select ".gem-c-subscription-links__link[lang]", false
end
end