Skip to content
Open
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
13 changes: 8 additions & 5 deletions lib/foundation_rails_helper/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 19 additions & 4 deletions spec/foundation_rails_helper/form_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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\"]")
Expand Down Expand Up @@ -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\"]")
Expand Down Expand Up @@ -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")
Expand Down