<commit_before>RSpec.describe PassagesController, type: :controller do

  let(:valid_attributes) {
    {
        title: 'title',
        text: 'passage text',
        duration: '1234'
    }
  }

  let(:invalid_attributes) {
    {
        title: 'title',
        duration: 1234
    }
  }

  let(:passages) {
    [
        {
            title: 'Climate Change', text: 'climate change passage', start_time: DateTime.now, close_time: (DateTime.now+2), duration: '1'
        }
    ]
  }

  before(:each) do
    stub_logged_in(true)
  end

  describe 'POST #create' do

    context 'with valid params' do
      it 'redirects to the created passage' do
        post :create, params: {passage: valid_attributes}
        expect(response).to redirect_to(passages_path)
        expect(flash[:success]).to match('Passage was successfully created.')
      end
    end

    context 'with invalid params' do
      it "returns a success response (i.e. to display the 'new' template)" do
        post :create, params: {passage: invalid_attributes}
        expect(response).to redirect_to(new_passage_path)
        expect(flash[:danger]).to match("Text can't be blank")
      end
    end
  end

  describe 'DELETE #destroy' do

    before(:each) do
      @passages = Passage.create!(passages)
    end

    after(:each) do
      @passages.each(&:delete)
    end

    context 'with passage id' do
      it 'should delete the passage' do
        passage_find_by = Passage.find_by(title: 'Climate Change')
        delete :destroy, params: {id: passage_find_by.id}

        expect(Passage.find_by(title: 'Climate Change')).to eq(nil)
        expect(response).to redirect_to(passages_path)
      end
    end
  end

  describe 'filter methods' do

    describe 'GET #drafts' do
      context 'Admin' do

        before(:each) do
          user = double('User', admin: true)
          stub_current_user(user)
        end
        context 'When the request is generated withing the tabs' do

          it 'should give all the yet to open passages' do
            get :drafts, params: {from_tab: true}
            expect(response).to be_success
            expect(flash[:danger]).to be_nil
            should render_template('passages/admin/passages_pane',)
          end
<commit_msg> [Surajit] Fixed destroy passage spec<commit_after>RSpec.describe PassagesController, type: :controller do

  let(:valid_attributes) {
    {
        title: 'title',
        text: 'passage text',
        duration: '1234'
    }
  }

  let(:invalid_attributes) {
    {
        title: 'title',
        duration: 1234
    }
  }

  let(:passages) {
    [
        {
            title: 'Climate Change', text: 'climate change passage', start_time: DateTime.now, close_time: (DateTime.now+2), duration: '1'
        }
    ]
  }

  before(:each) do
    stub_logged_in(true)
  end

  describe 'POST #create' do

    context 'with valid params' do
      it 'redirects to the created passage' do
        post :create, params: {passage: valid_attributes}
        expect(response).to redirect_to(passages_path)
        expect(flash[:success]).to match('Passage was successfully created.')
      end
    end

    context 'with invalid params' do
      it "returns a success response (i.e. to display the 'new' template)" do
        post :create, params: {passage: invalid_attributes}
        expect(response).to redirect_to(new_passage_path)
        expect(flash[:danger]).to match("Text can't be blank")
      end
    end
  end

  describe 'DELETE #destroy' do
    context 'with passage id' do
      it 'should delete the passage' do
        @passages = Passage.create!(passages)

        passage_find_by = Passage.find_by(title: 'Climate Change')
        delete :destroy, params: {id: passage_find_by.id}

        expect(Passage.find_by(title: 'Climate Change')).to eq(nil)
        expect(response).to redirect_to(passages_path)

        @passages.each(&:delete)
      end
    end

  end

  describe 'filter methods' do

    describe 'GET #drafts' do
      context 'Admin' do

        before(:each) do
          user = double('User', admin: true)
          stub_current_user(user)
        end
        context 'When the request is generated withing the tabs' do

          it 'should give all the yet to open passages' do
            get :drafts, params: {from_tab: true}
            expect(response).to be_success
            expect(flash[:danger]).to be_nil
            should render_template('passages/admin/passages_pane',)
          end

{'fraction_non_alphanumeric': 0.10265565721937067, 'fraction_numerical': 0.004463289444320465, 'mean_word_length': 2.442396313364055, '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': '4322943', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1324, 'n_words': 381}