Sha256: ccf85bf3f37411b7d54d0b04ee51509e5214ffe1af129922bd67b2a758d7424c

Contents?: true

Size: 1.59 KB

Versions: 3

Compression:

Stored size: 1.59 KB

Contents

require 'spec_helper'

describe "Adding validation classes to form inputs" do
	
	# Required

	it "adds the 'required' class when an attribute is required" do
		# are we validating the model correctly?
		expect(Post.validators_on(:title).map(&:class)).to include ActiveRecord::Validations::PresenceValidator
		
		# are we adding the 'required' class?
		visit new_post_path
		within("#new_post") do
			expect(page).to have_css('input#post_title.required')
		end
	end

	it "doesn't add the 'required' class when an attribute is not required" do
		expect(Post.validators_on(:author_email).map(&:class)).not_to include ActiveRecord::Validations::PresenceValidator
		
		# are we adding the 'required' class?
		visit new_post_path
		within("#new_post") do
			expect(page).not_to have_css('input#post_author_email.required')
		end
	end


	# Numericality

	it "adds the 'number' class when a number is required" do
		# are we validating the model correctly?
		expect(Post.validators_on(:view_count).map(&:class)).to include ActiveModel::Validations::NumericalityValidator
		
		# are we adding the 'number' class?
		visit new_post_path
		within("#new_post") do
			expect(page).to have_css('input#post_view_count.number')
		end
	end

	it "doesn't add the 'number' class when a number is not required" do
		# are we validating the model correctly?
		expect(Post.validators_on(:author_email).map(&:class)).not_to include ActiveModel::Validations::NumericalityValidator
		
		# are we adding the 'number' class?
		visit new_post_path
		within("#new_post") do
			expect(page).not_to have_css('input#post_author_email.number')
		end
	end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
validation_sync-0.0.4 spec/features/form_validation_spec.rb
validation_sync-0.0.3 spec/features/form_validation_spec.rb
validation_sync-0.0.2 spec/features/form_validation_spec.rb