<commit_before>require 'rails_helper'

RSpec.describe ApiController, type: :controller do
  after(:example) do
    sign_out
  end

  context 'Not Logined' do
    it 'has a 302 status code' do
      post :new, { firewood: attributes_for(:normal_message) }
      expect(response.status).to eq(302)
    end
  end

  context 'Logined with normal User' do
    describe 'POST #new' do
      it 'has a 200 status code' do
        sign_in :user
        post :new, { firewood: attributes_for(:normal_message) }
        expect(response.status).to eq(200)
      end
    end
  end
end<commit_msg>add clean redis after controller test example to remove side effect among tests<commit_after>require 'rails_helper'

RSpec.describe ApiController, type: :controller do
  after(:example) do
    sign_out
  end

  context 'Not Logined' do
    it 'has a 302 status code' do
      post :new, firewood: attributes_for(:normal_message)
      expect(response.status).to eq(302)
    end
  end

  context 'Logined with normal User' do
    before(:example) do
      sign_in :user
    end

    after(:example) do
      $redis.zremrangebyrank("#{$servername}:fws", 0, 0)
    end

    describe 'POST #new' do
      it 'has a 200 status code' do
        post :new, firewood: attributes_for(:normal_message)
        expect(response.status).to eq(200)
      end

      it 'create new firewood' do
        expect do
          post :new, firewood: attributes_for(:normal_message)
        end.to change(Firewood, :count).by(1)

        expect($redis.zrevrange("#{$servername}:fws", 0, 500).size).to eq(1)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09649122807017543, 'fraction_numerical': 0.020050125313283207, 'mean_word_length': 2.8668280871670704, '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': '3939706', 'n_tokens_mistral': 535, 'n_tokens_neox': 498, 'n_words': 157}