<commit_before>require 'rails_helper'

RSpec.describe Article::Post, type: :model do
  describe '.published' do
    let!(:published_post)   { FactoryGirl.create(:article_post, :published) }
    let!(:future_post)      { FactoryGirl.create(:article_post, :future_published) }
    let!(:unpublished_post) { FactoryGirl.create(:article_post) }

    subject { Article::Post.published }

    it { is_expected.to     include(published_post) }
    it { is_expected.not_to include(future_post, unpublished_post) }
  end

  describe '.featured' do
    let!(:featured_post)             { FactoryGirl.create(:article_post, :published, :featured) }
    let!(:future_featured_post)      { FactoryGirl.create(:article_post, :future_published, :featured) }
    let!(:unpublished_featured_post) { FactoryGirl.create(:article_post, :featured) }
    let!(:unfeatured_post)           { FactoryGirl.create(:article_post, :published) }

    subject { Article::Post.featured }

    it { is_expected.to     include(featured_post) }
    it { is_expected.not_to include(future_featured_post, unpublished_featured_post, unfeatured_post) }
  end

  describe '#headline' do
    subject { FactoryGirl.build(:article_post) }

    context 'when present and unique' do
      it { is_expected.to be_valid }
    end

    context 'when missing' do
      before { subject.assign_attributes(headline: nil) }
      it     { is_expected.not_to be_valid }
    end

    context 'when not unique' do
      let!(:post) { FactoryGirl.create(:article_post) }
      before      { subject.assign_attributes(headline: post.headline) }
      it          { is_expected.not_to be_valid }
    end
  end

  describe '#subhead' do
    subject { FactoryGirl.build(:article_post) }

    context 'when present' do
      it { is_expected.to be_valid }
    end

    context 'when missing' do
      before { subject.assign_attributes(subhead: nil) }
      it     { is_expected.not_to be_valid }
    end
  end

  describe '#body' do
    subject { FactoryGirl.build(:article_post) }

    context 'when present' do
      it { is_expected.to be_valid }
    end

    context 'when missing' do
      before { subject.assign_attributes(body: nil) }
      it     { is_expected.not_to be_valid }
    end
  end

  describe '#column' do
    subject { FactoryGirl.build(:article_post) }

    context 'when present' do
      it { is_expected.to be_valid }
    end

    context 'when missing' do
      before { subject.assign_attributes(column: nil) }
      it     { is_expected.not_to be_valid }
    end
  end

  describe '#author' do
    subject { FactoryGirl.build(:article_post) }

    context 'when present' do
      it { is_expected.to be_valid }
    end

    context 'when missing' do
      before { subject.assign_attributes(author: nil) }
      it     { is_expected.not_to be_valid }
    end
  end

  describe '#to_s' do
    let(:post) { FactoryGirl.build(:article_post) }
    subject    { post.to_s }
    it         { is_expected.to eql(post.headline) }
  end

  describe '#featured_image' do
    subject { FactoryGirl.build(:article_post) }

    context 'when present' do
      it { is_expected.to be_valid }
    end

    context 'when missing' do
      before { subject.assign_attributes(featured_image: nil) }
      it     { is_expected.not_to be_valid }
    end
  end
end<commit_msg>Refactor duplicated Article::Post spec subjects<commit_after>require 'rails_helper'

RSpec.describe Article::Post, type: :model do
  subject { FactoryGirl.build(:article_post) }

  describe '.published' do
    let!(:published_post)   { FactoryGirl.create(:article_post, :published) }
    let!(:future_post)      { FactoryGirl.create(:article_post, :future_published) }
    let!(:unpublished_post) { FactoryGirl.create(:article_post) }

    subject { Article::Post.published }

    it { is_expected.to     include(published_post) }
    it { is_expected.not_to include(future_post, unpublished_post) }
  end

  describe '.featured' do
    let!(:featured_post)             { FactoryGirl.create(:article_post, :published, :featured) }
    let!(:future_featured_post)      { FactoryGirl.create(:article_post, :future_published, :featured) }
    let!(:unpublished_featured_post) { FactoryGirl.create(:article_post, :featured) }
    let!(:unfeatured_post)           { FactoryGirl.create(:article_post, :published) }

    subject { Article::Post.featured }

    it { is_expected.to     include(featured_post) }
    it { is_expected.not_to include(future_featured_post, unpublished_featured_post, unfeatured_post) }
  end

  describe '#headline' do
    context 'when present and unique' do
      it { is_expected.to be_valid }
    end

    context 'when missing' do
      before { subject.assign_attributes(headline: nil) }
      it     { is_expected.not_to be_valid }
    end

    context 'when not unique' do
      let!(:post) { FactoryGirl.create(:article_post) }
      before      { subject.assign_attributes(headline: post.headline) }
      it          { is_expected.not_to be_valid }
    end
  end

  describe '#subhead' do
    context 'when present' do
      it { is_expected.to be_valid }
    end

    context 'when missing' do
      before { subject.assign_attributes(subhead: nil) }
      it     { is_expected.not_to be_valid }
    end
  end

  describe '#body' do
    context 'when present' do
      it { is_expected.to be_valid }
    end

    context 'when missing' do
      before { subject.assign_attributes(body: nil) }
      it     { is_expected.not_to be_valid }
    end
  end

  describe '#column' do
    context 'when present' do
      it { is_expected.to be_valid }
    end

    context 'when missing' do
      before { subject.assign_attributes(column: nil) }
      it     { is_expected.not_to be_valid }
    end
  end

  describe '#author' do
    context 'when present' do
      it { is_expected.to be_valid }
    end

    context 'when missing' do
      before { subject.assign_attributes(author: nil) }
      it     { is_expected.not_to be_valid }
    end
  end

  describe '#featured_image' do
    context 'when present' do
      it { is_expected.to be_valid }
    end

    context 'when missing' do
      before { subject.assign_attributes(featured_image: nil) }
      it     { is_expected.not_to be_valid }
    end
  end

  describe '#to_s' do
    let(:post) { FactoryGirl.build(:article_post) }
    subject    { post.to_s }
    it         { is_expected.to eql(post.headline) }
  end
end
{'fraction_non_alphanumeric': 0.09800871188550093, 'fraction_numerical': 0.0, 'mean_word_length': 2.9465930018416207, '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': '5264773', 'n_tokens_mistral': 2073, 'n_tokens_neox': 1993, 'n_words': 461}