<commit_before>
class OrderMock < ActiveRecord::Base
  self.table_name = :order
  percentize :discount, :surcharge, validate: {less_or_equal_than: 100}
end

RSpec.describe OrderMock do

  describe 'initialization' do
    subject { described_class }

    it 'should be possible to instantiate' do
      expect {
        subject.new
      }.not_to raise_error
    end

  end

  describe 'percentize' do

    let(:percentage) { Percentage.new 50 }

    it 'should return 0 percent for discount and surcharge' do
      expect(subject.discount).to be_a Percentage
      expect(subject.surcharge).to be_a Percentage
    end

    it 'should be possible to assign numeric' do
      subject.discount = 50
      expect(subject.discount).to eq percentage
    end

    context 'with invalid percentage' do
      it 'should not be valid' do
        subject.discount = 200
        expect(subject).not_to be_valid
      end

      it 'should not be valid with negative percentage' do
        subject.discount = -1
        expect(subject).not_to be_valid
      end
    end

  end



end<commit_msg>Added some more specs for active record extension<commit_after>
class OrderMock < ActiveRecord::Base
  self.table_name = :order
  percentize :discount, :surcharge, validate: {less_or_equal_than: 100}
end

class OrderMockWithoutValidations < ActiveRecord::Base
  self.table_name = :order
  percentize :discount, validate: false
end

class OrderMockWithPostFix < ActiveRecord::Base
  self.table_name = :order
  percentize :discount, postfix: 'percent'
end

RSpec.describe OrderMock do

  describe 'initialization' do
    subject { described_class }

    it 'should be possible to instantiate' do
      expect {
        subject.new
      }.not_to raise_error
    end

  end

  describe 'percentize' do

    let(:percentage) { Percentage.new 50 }

    it 'should return 0 percent for discount and surcharge' do
      expect(subject.discount).to be_a Percentage
      expect(subject.surcharge).to be_a Percentage
    end

    it 'should be possible to assign numeric' do
      subject.discount = 50
      expect(subject.discount).to eq percentage
    end

    it 'should persist the values' do
      subject.discount = 20
      subject.surcharge = 35
      expect{subject.save!}.not_to raise_error
      expect(OrderMock.first.discount).to eq Percentage.new(20)
    end

    context 'with invalid percentage' do
      it 'should not be valid' do
        subject.discount = 200
        expect(subject).not_to be_valid
      end

      it 'should not be valid with negative percentage' do
        subject.discount = -1
        expect(subject).not_to be_valid
      end
    end

    context 'with postfix' do
      subject { OrderMockWithPostFix.new discount: 30 }

      it 'should respond to the method name with postfix' do
        expect(subject.respond_to?(:discount_percent)).to be_truthy
      end

      it 'should keep the original accessor' do
        expect(subject.discount).to be_a BigDecimal
      end
    end

    context 'disabled validation' do
      subject { OrderMockWithoutValidations.new }
      it 'should skip the validations' do
        expect(subject).to be_valid
      end
    end

  end



end
{'fraction_non_alphanumeric': 0.06666666666666667, 'fraction_numerical': 0.01001564945226917, 'mean_word_length': 2.7733175914994095, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4247502', 'n_tokens_mistral': 988, 'n_tokens_neox': 910, 'n_words': 299}