allow '1' or true for acceptance validation. #18439
While pairing on a project this morning we were confused as to why this code kept failing:
# user.rb class User < ActiveRecord::Base attr_accessor :terms_and_conditions validates_acceptance_of :terms_and_conditions end
describe User do it "is valid" do user = User.new(terms_and_conditions: true) expect(user).to be_valid end end
After looking through the source we found that the default value is: "1". This seems nonintuitive. To make this test pass we had to change our code to this:
# user.rb class User attr_accessor :terms_and_conditions validates_acceptance_of :terms_and_conditions, accept: true end
This Pull Request changes the default accept from "1" to ["1", true]. Allowing you to specify an array of options. It supports single values as well for backwards compatibility.
The text was updated successfully, but these errors were encountered: