<commit_before>require 'spec_helper'
describe Served::Resource::Validatable do
  subject do
    Class.new do
      include Served::Resource::Validatable
      attribute :presence,     presence: true
      attribute :numericality, numericality: true
      attribute :format,       format: /[a-z]+/
      attribute :inclusion,    inclusion: { in: %w{foo bar}}

      def self.name
        "TheClass"
      end

      def initialize(*args)
      end
    end
  end

  describe 'validations' do

    it 'should validate presence' do
      instance = subject.new(presence: 'foo')
      instance.validate
      expect(instance.errors[:presence]).to be_empty
      instance = subject.new
      instance.validate
      expect(instance.errors[:presence]).to_not be_empty
    end

    it 'should validate numericality' do
      instance = subject.new(numericality: '1')
      instance.validate
      expect(instance.errors[:numericality]).to be_empty
      instance = subject.new(numericality: 'a')
      instance.validate
      expect(instance.errors[:numericality]).to_not be_empty
    end

    it 'should validate format' do
      instance = subject.new(format: 'abcd')
      instance.validate
      expect(instance.errors[:format]).to be_empty
      instance = subject.new(format: '1234')
      instance.validate
      expect(instance.errors[:format]).to_not be_empty
    end

    it 'should validate inclusion' do
      instance = subject.new(inclusion: 'foo')
      instance.validate
      expect(instance.errors[:inclusion]).to be_empty
      instance = subject.new(inclusion: 'a')
      instance.validate
      expect(instance.errors[:inclusion]).to_not be_empty
    end

  end
end<commit_msg>update validatable spec<commit_after>require 'spec_helper'
describe Served::Resource::Validatable do
  subject do
    Class.new do
      include Served::Resource::Validatable
      attribute :presence,     presence: true
      attribute :numericality, numericality: true
      attribute :format,       format: /[a-z]+/
      attribute :inclusion,    inclusion: { in: %w{foo bar}}

      def self.name
        "TheClass"
      end

      def initialize(*args)
      end
    end
  end

  describe 'validations' do

    it 'should validate presence' do
      instance = subject.new(presence: 'foo')
      instance.valid?
      expect(instance.errors[:presence]).to be_empty
      instance = subject.new
      instance.valid?
      expect(instance.errors[:presence]).to_not be_empty
    end

    it 'should validate numericality' do
      instance = subject.new(numericality: '1')
      instance.valid?
      expect(instance.errors[:numericality]).to be_empty
      instance = subject.new(numericality: 'a')
      instance.valid?
      expect(instance.errors[:numericality]).to_not be_empty
    end

    it 'should validate format' do
      instance = subject.new(format: 'abcd')
      instance.valid?
      expect(instance.errors[:format]).to be_empty
      instance = subject.new(format: '1234')
      instance.valid?
      expect(instance.errors[:format]).to_not be_empty
    end

    it 'should validate inclusion' do
      instance = subject.new(inclusion: 'foo')
      instance.valid?
      expect(instance.errors[:inclusion]).to be_empty
      instance = subject.new(inclusion: 'a')
      instance.valid?
      expect(instance.errors[:inclusion]).to_not be_empty
    end

  end
end
{'fraction_non_alphanumeric': 0.1025489033787789, 'fraction_numerical': 0.002963841138114997, 'mean_word_length': 2.8748564867967854, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1536667', 'n_tokens_mistral': 974, 'n_tokens_neox': 953, 'n_words': 229}