<commit_before>require 'pathname'

__dir__ = Pathname(__FILE__).dirname.expand_path
require __dir__.parent.parent + 'spec_helper'
require __dir__ + 'spec_helper'


describe SailBoat do
  before :all do
    @model      = SailBoat.new
    @model.name = 'Float'
    @model.should be_valid_for_presence_test
  end

  describe "without name" do
    before :all do
      @model.name = nil
    end

    it "has validates_is_present for name thanks to :nullable => false" do
      @model.should_not be_valid_for_presence_test
      @model.errors.on(:name).should include('Name must not be blank')
    end
  end
end



describe "Automatic Validation from Property Definition" do
  it "should auto add a validates_length for maximum size on String properties" do
    # max length test max=10
    boat = SailBoat.new
    boat.valid_for_length_test_1?.should == true  #no minimum length
    boat.description = 'ABCDEFGHIJK' #11
    boat.valid_for_length_test_1?.should == false
    boat.errors.on(:description).should include('Description must be less than 10 characters long')
    boat.description = 'ABCDEFGHIJ' #10
    boat.valid_for_length_test_1?.should == true
  end

  it "should auto add validates_length within a range when option :length
      or :size is a range" do
    # Range test notes = 2..10
    boat = SailBoat.new
    boat.should be_valid_for_length_test_2
    boat.notes = 'AB' #2
    boat.should be_valid_for_length_test_2
    boat.notes = 'ABCDEFGHIJK' #11
    boat.should_not be_valid_for_length_test_2
    boat.errors.on(:notes).should include('Notes must be between 2 and 10 characters long')
    boat.notes = 'ABCDEFGHIJ' #10
    boat.should be_valid_for_length_test_2
  end

  it "should auto add a validates_format if the :format option is given" do
    # format test - format = /A\d{4}\z/   on code<commit_msg>[dm-validations] New spec example group for automatically inferred length validation<commit_after>require 'pathname'

__dir__ = Pathname(__FILE__).dirname.expand_path
require __dir__.parent.parent + 'spec_helper'
require __dir__ + 'spec_helper'


describe SailBoat do
  before :all do
    @model      = SailBoat.new
    @model.name = 'Float'
    @model.should be_valid_for_presence_test
  end

  describe "without name" do
    before :all do
      @model.name = nil
    end

    # has validates_is_present for name thanks to :nullable => false
    it "is invalid" do
      @model.should_not be_valid_for_presence_test
      @model.errors.on(:name).should include('Name must not be blank')
    end
  end
end


describe SailBoat do
  before :all do
    @model      = SailBoat.new
    @model.should be_valid_for_length_test_1
  end

  describe "with 11 characters long description" do
    before :all do
      @model.description = 'ABCDEFGHIJK' #11
    end

    # validates_length is inferred from property's :length option
    it "is invalid" do
      @model.should_not be_valid_for_length_test_1
      @model.errors.on(:description).should include('Description must be less than 10 characters long')
    end
  end
end


describe "Automatic Validation from Property Definition" do
  it "should auto add validates_length within a range when option :length
      or :size is a range" do
    # Range test notes = 2..10
    boat = SailBoat.new
    boat.should be_valid_for_length_test_2
    boat.notes = 'AB' #2
    boat.should be_valid_for_length_test_2
    boat.notes = 'ABCDEFGHIJK' #11
    boat.should_not be_valid_for_length_test_2
    boat.errors.on(:notes).should include('Notes must be between 2 and 10 characters long')
    boat.notes = 'ABCDEFGHIJ' #10
    boat.should be_valid_for_length_test_2
  end

  it "should auto add a validates_format if the :format option is given" do
    # format test - format = /A\d{4}\z/   on code
{'fraction_non_alphanumeric': 0.07741420590582601, 'fraction_numerical': 0.013567438148443736, 'mean_word_length': 3.4497041420118344, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1691157', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1194, 'n_words': 366}