<commit_before>require 'spec_helper'

describe Acfs::Model::Attributes do
  let(:model) { Class.new.tap { |c| c.send :include, Acfs::Model }}

  describe '#initialize' do
    before { model.attribute :name, :string, default: 'John' }

    it 'should have attribute list' do
      expect(model.new.attributes).to include('name')
    end

    it 'should set default attributes' do
      expect(model.new.name).to be == 'John'
    end

    context 'with dynamic default value' do
      before do
        model.attribute :name, :string, default: 'John'
        model.attribute :mail, :string, default: -> { <EMAIL>" }
      end

      it 'should set dynamic default attributes' do
        expect(model.new.mail).to be == '<EMAIL>'
      end
    end
  end

  describe '#attributes' do
    before do
      model.attribute :name, :string, default: 'John'
      model.attribute :age, :integer, default: 25
    end

    it 'should return hash of all attributes' do
      expect(model.new.attributes).to be == {
          'name' => 'John',
          'age' => 25
      }
    end
  end

  describe '#_getter_' do
    before { model.attribute :name, :string, default: 'John' }

    it 'should return value' do
      mo = model.new
      mo.name = 'Paul'

      expect(mo.name).to be == 'Paul'
    end

    it 'should return default value' do
      expect(model.new.name).to be == 'John'
    end

    it 'should return matching ivar\'s value' do
      o = model.new
      o.instance_variable_set :@name, 'Johannes'

      expect(o.name).to be == 'Johannes'
    end
  end

  describe '#_setter_' do
    before do
      model.attribute :name, :string, default: 'John'
      model.attribute :age, :integer, default: '25'
    end

    it 'should set value' do
      o = model.new
      o.name = 'Paul'

      expect(o.name).to be == 'Paul'
    end

    it 'should set instance var' do
      o = model.new
      o.name = 'Paul'

      expect(o.instance_variable_get(:@name)).to be == 'Paul'
    end

    it 'should update attributes hash' do
      o = model.new
      o.name = 'Johannes'

      expect(o.attributes['name']).to be == 'Johannes'
    end

    it 'should cast values' do
      o = model.new
      o.age = "28"

      expect(o.age).to be == 28
    end
  end

  describe '.attribute' do
    it 'should add an attribute to model attribute list' do
      model.send :attribute, :name, :string

      expect(model.attributes).to be == { :name => '' }
    end

    it 'should accept a default value' do
      model.send :attribute, :name, :string, default: 'John'

      expect(model.attributes).to be == { :name => 'John' }
    end

    it 'should accept an symbolic type' do
      model.send :attribute, :age, :integer, default: '12'

      expect(model.attributes).to be == { :age => 12 }
    end

    it 'should accept an class type' do
      model.send :attribute, :age, Acfs::Model::Attributes::Integer, default: '12'

      expect(model.attributes).to be == { :age => 12 }
    end
  end
end
<commit_msg>Fix spec due to allowed nil attributes.<commit_after>require 'spec_helper'

describe Acfs::Model::Attributes do
  let(:model) { Class.new.tap { |c| c.send :include, Acfs::Model }}

  describe '#initialize' do
    before { model.attribute :name, :string, default: 'John' }

    it 'should have attribute list' do
      expect(model.new.attributes).to include('name')
    end

    it 'should set default attributes' do
      expect(model.new.name).to be == 'John'
    end

    context 'with dynamic default value' do
      before do
        model.attribute :name, :string, default: 'John'
        model.attribute :mail, :string, default: -> { <EMAIL>" }
      end

      it 'should set dynamic default attributes' do
        expect(model.new.mail).to be == '<EMAIL>'
      end
    end
  end

  describe '#attributes' do
    before do
      model.attribute :name, :string, default: 'John'
      model.attribute :age, :integer, default: 25
    end

    it 'should return hash of all attributes' do
      expect(model.new.attributes).to be == {
          'name' => 'John',
          'age' => 25
      }
    end
  end

  describe '#_getter_' do
    before { model.attribute :name, :string, default: 'John' }

    it 'should return value' do
      mo = model.new
      mo.name = 'Paul'

      expect(mo.name).to be == 'Paul'
    end

    it 'should return default value' do
      expect(model.new.name).to be == 'John'
    end

    it 'should return matching ivar\'s value' do
      o = model.new
      o.instance_variable_set :@name, 'Johannes'

      expect(o.name).to be == 'Johannes'
    end
  end

  describe '#_setter_' do
    before do
      model.attribute :name, :string, default: 'John'
      model.attribute :age, :integer, default: '25'
    end

    it 'should set value' do
      o = model.new
      o.name = 'Paul'

      expect(o.name).to be == 'Paul'
    end

    it 'should set instance var' do
      o = model.new
      o.name = 'Paul'

      expect(o.instance_variable_get(:@name)).to be == 'Paul'
    end

    it 'should update attributes hash' do
      o = model.new
      o.name = 'Johannes'

      expect(o.attributes['name']).to be == 'Johannes'
    end

    it 'should cast values' do
      o = model.new
      o.age = "28"

      expect(o.age).to be == 28
    end
  end

  describe '.attribute' do
    it 'should add an attribute to model attribute list' do
      model.send :attribute, :name, :string

      expect(model.attributes).to be == { :name => nil }
    end

    it 'should accept a default value' do
      model.send :attribute, :name, :string, default: 'John'

      expect(model.attributes).to be == { :name => 'John' }
    end

    it 'should accept an symbolic type' do
      model.send :attribute, :age, :integer, default: '12'

      expect(model.attributes).to be == { :age => 12 }
    end

    it 'should accept an class type' do
      model.send :attribute, :age, Acfs::Model::Attributes::Integer, default: '12'

      expect(model.attributes).to be == { :age => 12 }
    end
  end
end

{'fraction_non_alphanumeric': 0.12734517682218163, 'fraction_numerical': 0.005977087829985057, 'mean_word_length': 2.361607142857143, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '3204034', 'n_tokens_mistral': 1973, 'n_tokens_neox': 1878, 'n_words': 607}