<commit_before>require_relative '../spec_helper'

describe PwfmtFormat do
  describe '.persist' do
    fixtures :documents
    let(:doc) { Document.all.first }
    let(:field) { 'document_description' }

    shared_examples_for 'format persistence' do
      subject { PwfmtFormat.all.first }

      its(:target_id) { should eq doc.id }
      its(:field) { should eq field }
      its(:format) { should eq 'textile' }
    end

    context 'when not exists' do
      it 'inserted' do
        expect { PwfmtFormat.persist(doc, field, 'textile') }.to change { PwfmtFormat.count }.by(1)
      end
      describe 'values cofirmation' do
        before do
          PwfmtFormat.persist(doc, field, 'textile')
        end
        it_behaves_like 'format persistence'
      end
    end
    context 'when already exists' do
      before do
        PwfmtFormat.create(target_id: doc.id,
                           field: field,
                           format: 'markdown')
      end

      it 'not inserted' do
        expect { PwfmtFormat.persist(doc, field, 'textile') }.not_to change { PwfmtFormat.count }
      end
      describe 'values cofirmation' do
        before do
          PwfmtFormat.persist(doc, field, 'textile')
        end
        it_behaves_like 'format persistence'
      end
    end
  end
<commit_msg>Update description<commit_after>require_relative '../spec_helper'

describe PwfmtFormat do
  describe '.persist' do
    fixtures :documents
    let(:doc) { Document.all.first }
    let(:field) { 'document_description' }

    shared_examples_for 'format persistence' do
      subject { PwfmtFormat.all.first }

      its(:target_id) { should eq doc.id }
      its(:field) { should eq field }
      its(:format) { should eq 'textile' }
    end

    context 'when not exists' do
      it 'inserted' do
        expect { PwfmtFormat.persist(doc, field, 'textile') }.to change { PwfmtFormat.count }.by(1)
      end
      describe 'attribute values' do
        before do
          PwfmtFormat.persist(doc, field, 'textile')
        end
        it_behaves_like 'format persistence'
      end
    end
    context 'when already exists' do
      before do
        PwfmtFormat.create(target_id: doc.id,
                           field: field,
                           format: 'markdown')
      end

      it 'not inserted' do
        expect { PwfmtFormat.persist(doc, field, 'textile') }.not_to change { PwfmtFormat.count }
      end
      describe 'attribute values' do
        before do
          PwfmtFormat.persist(doc, field, 'textile')
        end
        it_behaves_like 'format persistence'
      end
    end
  end

{'fraction_non_alphanumeric': 0.09135896459840122, 'fraction_numerical': 0.0007613247049866769, 'mean_word_length': 2.1285714285714286, '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': '5878470', 'n_tokens_mistral': 810, 'n_tokens_neox': 781, 'n_words': 215}