<commit_before>require 'spec_helper'

describe Opinionated::Admin::PostsController do
  let(:user) { create :user }

  before do
    sign_in_as user
  end

  describe '#create' do
    let(:new_post) { Opinionated::Post.last }

    it {
      expect {
        post :create, post: { title: 'meh' }
      }.to change(Opinionated::Post, :count).by(1)
    }

    context 'published == true' do
      it 'sets the post to published state' do
        post :create, post: { title: 'meh', published: 'true' }
        expect(new_post.published?).to be_true
      end
    end

    context 'published != true' do
      it 'sets the post to the draft state' do
        post :create, post: { title: 'meh', published: 'false' }
        expect(new_post.draft?).to be_true
      end
    end
  end

  describe '#update' do
    let(:post) { create(:post) }

    it 'updates title' do
      put :update, id: post.id, post: { title: 'Hey!' }
      post.reload
      expect(post.title).to eq 'Hey!'
    end

    describe 'publish state' do
      context 'published == true' do
        it 'sets the post to published state' do
          put :update, id: post.id, post: { published: 'true' }
          expect(post.reload.published?).to be_true
        end
      end

      context 'published != true' do
        let(:post) { create(:post, :published) }

        it 'sets the post to the draft state' do
          put :update, id: post.id, post: { published: 'false' }
          expect(post.reload.draft?).to be_true
        end
      end
    end
  end
end<commit_msg>edit title in post controller spec<commit_after>require 'spec_helper'

describe Opinionated::Admin::PostsController do
  let(:user) { create :user }

  before do
    sign_in_as user
  end

  describe '#create' do
    let(:new_post) { Opinionated::Post.last }

    it {
      expect {
        post :create, post: { title: 'meh' }
      }.to change(Opinionated::Post, :count).by(1)
    }

    context 'published == true' do
      it 'sets the post to published state' do
        post :create, post: { title: 'meh', published: 'true' }
        expect(new_post.published?).to be_true
      end
    end

    context 'published != true' do
      it 'sets the post to the draft state' do
        post :create, post: { title: 'meh', published: 'false' }
        expect(new_post.draft?).to be_true
      end
    end
  end

  describe '#update' do
    let(:post) { create(:post) }

    it 'updates title' do
      put :update, id: post.id, post: { title: 'Hey!' }
      post.reload
      expect(post.title).to eq 'Hey!'
    end

    describe 'publish state' do
      context 'published == true' do
        it 'sets the post to published state' do
          put :update, id: post.id, post: { title: 'meh', published: 'true' }
          expect(post.reload.published?).to be_true
        end
      end

      context 'published != true' do
        let(:post) { create(:post, :published) }

        it 'sets the post to the draft state' do
          put :update, id: post.id, post: { title: 'meh', published: 'false' }
          expect(post.reload.draft?).to be_true
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12057416267942583, 'fraction_numerical': 0.0006379585326953748, 'mean_word_length': 2.2734864300626305, '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': '5525119', 'n_tokens_mistral': 1010, 'n_tokens_neox': 965, 'n_words': 316}