capybara - Testing HTML 5 form validations when using simple_form Rails -


i'm using devise , simple_form todo list app . , have following code users/edit.html.erb

<%= content_for :title,'edit profile' %> <h2>edit profile</h2> <%= simple_form_for current_user, class: 'form-horizontal' |f| %>   <%= f.input :nick_name %>   <%= f.submit 'update profile' %> <% end %> 

my user.rb looks :

class user < activerecord::base    devise :database_authenticatable, :registerable,      :recoverable, :rememberable, :trackable, :validatable  attr_accessible :email,:nick_name, :password, :password_confirmation, :remember_me  validates :nick_name, presence: true    # other fields validated devise  has_many :lists , dependent: :destroy end 

now, when click on submit button empty nick_name field ,i popup kind of alert . it's not normal browser alert ,i think html5 feature . message please fill out field popup below empty field . have disabled javascript, still shows same message . nick_name input field :

<input class="string required" id="user_nick_name" name="user[nick_name]" required="required" size="50" type="text"> 

now, when remove presence validation nick_name in model , popup doesn't appear .when validation line commented out ,

<input class="string optional" id="user_nick_name" name="user[nick_name]" size="50" type="text"> 

is simple_form doing behind scenes magic ?

since popup doesnt show trace of html code , how test validation in capybara/rspec ?

actually can test finding html attribute required="required" following code example:

expect(page).to have_xpath("//input[@required='required']") 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -