<commit_before>require 'rails_helper'

describe Admin::FeedbackController, type: :controller do
  render_views

  shared_examples_for 'destroy feedback with feedback from own article' do
    it 'should destroy feedback' do
      id = feedback_from_own_article.id
      expect do
        delete 'destroy', params: { id: id }
      end.to change(Feedback, :count)
      expect do
        Feedback.find(feedback_from_own_article.id)
      end.to raise_error(ActiveRecord::RecordNotFound)
    end

    it 'should redirect to feedback from article' do
      delete 'destroy', params: { id: feedback_from_own_article.id }
      expect(response).to redirect_to(controller: 'admin/feedback', action: 'article', id: feedback_from_own_article.article.id)
    end
  end

  describe 'logged in admin user' do
    before(:each) do
      create(:blog)
      @admin = create(:user, :as_admin)
      sign_in @admin
    end

    def feedback_from_own_article
      @article ||= FactoryGirl.create(:article, user: @admin)
      @comment_own ||= FactoryGirl.create(:comment, article: @article)
    end

    def feedback_from_not_own_article
      @spam_comment_not_own ||= FactoryGirl.create(:spam_comment)
    end

    describe 'destroy action' do
      it_should_behave_like 'destroy feedback with feedback from own article'

      it "should destroy feedback from article doesn't own" do
        id = feedback_from_not_own_article.id
        expect do
          delete 'destroy', params: { id: id }
        end.to change(Feedback, :count)
        expect do
          Feedback.find(feedback_from_not_own_article.id)
        end.to raise_error(ActiveRecord::RecordNotFound)
        expect(response).to redirect_to(controller: 'admin/feedback', action: 'article', id: feedback_from_not_own_article.article.id)
      end
    end

    describe 'index security' do
      it 'should check domain of the only param' do
        expect { get :index, params: { only: 'evil_call' } }.not_to raise_error
        expect(assigns(:only_param)).to be_nil
      end
    end

    describe 'index' do
      let!(:spam) { create(:spam_comment) }
      let!(:unapproved) { create(:unconfirmed_comment) }
      let!(:presumed_ham) { create(:presumed_ham_comment) }
      let!(:presumed_spam) { create(:presumed_spam_comment) }
      let(:params) {}

      before(:each) { get :index, params: params }

      it { expect(response).to be_success }
      it { expect(response).to render_template('index') }

      context 'simple' do
        it { expect(assigns(:feedback).size).to eq(4) }
      end

      context 'unapproved' do
        let(:params) { { only: 'unapproved' } }
        it { expect(assigns(:feedback)).to match_array([unapproved, presumed_ham, presumed_spam]) }<commit_msg>Fix empty parameters in spec<commit_after>require 'rails_helper'

describe Admin::FeedbackController, type: :controller do
  render_views

  shared_examples_for 'destroy feedback with feedback from own article' do
    it 'should destroy feedback' do
      id = feedback_from_own_article.id
      expect do
        delete 'destroy', params: { id: id }
      end.to change(Feedback, :count)
      expect do
        Feedback.find(feedback_from_own_article.id)
      end.to raise_error(ActiveRecord::RecordNotFound)
    end

    it 'should redirect to feedback from article' do
      delete 'destroy', params: { id: feedback_from_own_article.id }
      expect(response).to redirect_to(controller: 'admin/feedback', action: 'article', id: feedback_from_own_article.article.id)
    end
  end

  describe 'logged in admin user' do
    before(:each) do
      create(:blog)
      @admin = create(:user, :as_admin)
      sign_in @admin
    end

    def feedback_from_own_article
      @article ||= FactoryGirl.create(:article, user: @admin)
      @comment_own ||= FactoryGirl.create(:comment, article: @article)
    end

    def feedback_from_not_own_article
      @spam_comment_not_own ||= FactoryGirl.create(:spam_comment)
    end

    describe 'destroy action' do
      it_should_behave_like 'destroy feedback with feedback from own article'

      it "should destroy feedback from article doesn't own" do
        id = feedback_from_not_own_article.id
        expect do
          delete 'destroy', params: { id: id }
        end.to change(Feedback, :count)
        expect do
          Feedback.find(feedback_from_not_own_article.id)
        end.to raise_error(ActiveRecord::RecordNotFound)
        expect(response).to redirect_to(controller: 'admin/feedback', action: 'article', id: feedback_from_not_own_article.article.id)
      end
    end

    describe 'index security' do
      it 'should check domain of the only param' do
        expect { get :index, params: { only: 'evil_call' } }.not_to raise_error
        expect(assigns(:only_param)).to be_nil
      end
    end

    describe 'index' do
      let!(:spam) { create(:spam_comment) }
      let!(:unapproved) { create(:unconfirmed_comment) }
      let!(:presumed_ham) { create(:presumed_ham_comment) }
      let!(:presumed_spam) { create(:presumed_spam_comment) }
      let(:params) { {} }

      before(:each) { get :index, params: params }

      it { expect(response).to be_success }
      it { expect(response).to render_template('index') }

      context 'simple' do
        it { expect(assigns(:feedback).size).to eq(4) }
      end

      context 'unapproved' do
        let(:params) { { only: 'unapproved' } }
        it { expect(assigns(:feedback)).to match_array([unapproved, presumed_ham, presumed_spam]) }
{'fraction_non_alphanumeric': 0.10262919310970081, 'fraction_numerical': 0.00036264732547597464, 'mean_word_length': 3.2074752097635395, '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': '5628120', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1626, 'n_words': 416}