diff --git a/lib/foundation_rails_helper/form_builder.rb b/lib/foundation_rails_helper/form_builder.rb index efda4ef..716f376 100644 --- a/lib/foundation_rails_helper/form_builder.rb +++ b/lib/foundation_rails_helper/form_builder.rb @@ -50,27 +50,30 @@ def radio_button(attribute, tag_value, options = {}) def password_field(attribute, options = {}) field attribute, options do |opts| - super(attribute, opts.merge(autocomplete: :off)) + opts[:autocomplete] ||= :off + super(attribute, opts) end end def datetime_select(attribute, options = {}, html_options = {}) field attribute, options, html_options do |html_opts| - super(attribute, options, html_opts.merge(autocomplete: :off)) + html_options[:autocomplete] ||= :off + super(attribute, options, html_opts) end end def date_select(attribute, options = {}, html_options = {}) field attribute, options, html_options do |html_opts| - super(attribute, options, html_opts.merge(autocomplete: :off)) + html_options[:autocomplete] ||= :off + super(attribute, options, html_opts) end end # rubocop:disable LineLength def time_zone_select(attribute, priorities = nil, options = {}, html_options = {}) field attribute, options, html_options do |html_opts| - super(attribute, priorities, options, - html_opts.merge(autocomplete: :off)) + html_options[:autocomplete] ||= :off + super(attribute, priorities, options, html_opts) end end # rubocop:enable LineLength diff --git a/spec/foundation_rails_helper/form_builder_spec.rb b/spec/foundation_rails_helper/form_builder_spec.rb index 381e8f1..4c7c23c 100644 --- a/spec/foundation_rails_helper/form_builder_spec.rb +++ b/spec/foundation_rails_helper/form_builder_spec.rb @@ -289,11 +289,26 @@ expect(node) .to have_css('label[for="author_password"]', text: "Password") expect(node) - .to have_css('input[type="password"][name="author[password]"]') + .to have_css('input[type="password"][name="author[password]"][autocomplete="off"]') expect(node.find_field("author_password").value).to be_nil end end + context "when autocomplete attribute is defined in password_field input" do + let(:options) { { autocomplete: "new-password" } } + + it "generates password_field input with autocomplete attribute" do + form_for(@author) do |builder| + node = Capybara.string builder.password_field(:password, options) + expect(node) + .to have_css('label[for="author_password"]', text: "Password") + expect(node) + .to have_css('input[type="password"][name="author[password]"][autocomplete="new-password"]') + expect(node.find_field("author_password").value).to be_nil + end + end + end + it "should generate email_field input" do form_for(@author) do |builder| node = Capybara.string builder.email_field(:email) @@ -468,7 +483,7 @@ expect(node) .to have_css('label[for="author_birthdate"]', text: "Birthdate") %w(1 2 3).each do |i| - expect(node).to have_css("select[name='author[birthdate(#{i}i)]']") + expect(node).to have_css("select[name='author[birthdate(#{i}i)]'][autocomplete='off']") end expect(node) .to have_css("#{select}1i #{option}[value=\"1969\"]") @@ -519,7 +534,7 @@ expect(node) .to have_css('label[for="author_birthdate"]', text: "Birthdate") %w(1 2 3 4 5).each do |i| - expect(node).to have_css("select[name='author[birthdate(#{i}i)]']") + expect(node).to have_css("select[name='author[birthdate(#{i}i)]'][autocomplete='off']") end expect(node).to have_css("#{select}1i #{option}[value=\"1969\"]") expect(node).to have_css("#{select}2i #{option}[value=\"6\"]") @@ -559,7 +574,7 @@ ) expect(node) .to have_css('label[for="author_time_zone"]', text: "Time zone") - expect(node).to have_css('select[name="author[time_zone]"]') + expect(node).to have_css('select[name="author[time_zone]"][autocomplete="off"]') expect(node) .to have_css('select[name="author[time_zone]"] option[value="Perth"]', text: "(GMT+08:00) Perth")