<commit_before>require 'spec_helper'

describe Api::FeedsController do

  before :each do
    @user = FactoryGirl.create :user

    @feed1 = FactoryGirl.create :feed
    @feed2 = FactoryGirl.create :feed
    @feed3 = FactoryGirl.create :feed

    @entry_1_1 = FactoryGirl.build :entry, feed_id: @feed1.id
    @entry_1_2 = FactoryGirl.build :entry, feed_id: @feed1.id
    @feed1.entries << @entry_1_1 << @entry_1_2
    @entry2 = FactoryGirl.build :entry, feed_id: @feed2.id
    @feed2.entries << @entry2

    @user.subscribe @feed1.fetch_url
    @user.subscribe @feed3.fetch_url

    @folder1 = FactoryGirl.build :folder, user_id: @user.id
    @folder2 = FactoryGirl.create :folder
    @user.folders << @folder1

    login_user_for_unit @user
  end

  context 'GET index' do

    context 'all feeds' do

      it 'returns success' do
        get :index, format: :json
        response.should be_success
      end

      it 'assigns to @feeds only feeds owned by the user' do
        get :index, format: :json
        assigns(:feeds).should eq [@feed1]
      end

      it 'assigns to @feeds only feeds with unread entries' do
        get :index, format: :json
        assigns(:feeds).should eq [@feed1]
      end

      it 'assigns to @feeds all feeds if requested' do
        get :index, include_read: 'true', format: :json
        assigns(:feeds).should eq [@feed1, @feed3]
      end
    end

    context 'feeds in a folder' do

      it 'returns success' do
        get :index, folder_id: @folder1.id, format: :json
        response.should be_success
      end

      it 'assigns to @folder the correct folder' do
        get :index, folder_id: @folder1.id, format: :json
        assigns(:folder).should eq @folder1
      end

      it 'assigns to @feeds only feeds with unread entries' do
        get :index, folder_id: @folder1.id, format: :json
        assigns(:feeds).should eq [@feed1]
      end

      it 'assigns to @feeds all feeds if requested' do
        get :index, folder_id: @folder1.id, include_read: 'true', format: :json
        feeds = assigns(:feeds)
        feeds.count.should eq 2
        feeds.should include @feed1
        feeds.should include @feed3
      end

      it 'returns 404 if user does not own folder'
    end
  end

  context 'GET show' do

    it 'assigns to @feed the correct feed' do
      get :show, id: @feed1.id, format: :json
      assigns(:feed).should eq @feed1
    end

    it 'returns a 404 for a feed the user is not suscribed to' do
      get :show, id: @feed2.id, format: :json
      response.status.should eq 404
    end

    it 'returns a 404 for a non-existing feed' do
      get :show, id: 1234567890, format: :json
      response.status.should eq 404
    end

  end

  context 'PATCH update' do
<commit_msg>Fixed unit tests for FeedsController#index<commit_after>require 'spec_helper'

describe Api::FeedsController do

  before :each do
    @user = FactoryGirl.create :user

    @feed1 = FactoryGirl.create :feed
    @feed2 = FactoryGirl.create :feed
    @feed3 = FactoryGirl.create :feed

    @entry_1_1 = FactoryGirl.build :entry, feed_id: @feed1.id
    @entry_1_2 = FactoryGirl.build :entry, feed_id: @feed1.id
    @feed1.entries << @entry_1_1 << @entry_1_2
    @entry2 = FactoryGirl.build :entry, feed_id: @feed2.id
    @feed2.entries << @entry2

    @user.subscribe @feed1.fetch_url
    @user.subscribe @feed3.fetch_url

    @folder1 = FactoryGirl.build :folder, user_id: @user.id
    @folder2 = FactoryGirl.create :folder
    @user.folders << @folder1
    @folder1.feeds << @feed1 << @feed3

    login_user_for_unit @user
  end

  context 'GET index' do

    context 'all feeds' do

      it 'returns success' do
        get :index, format: :json
        response.should be_success
      end

      it 'assigns to @feeds only feeds owned by the user' do
        get :index, format: :json
        assigns(:feeds).should eq [@feed1]
      end

      it 'assigns to @feeds only feeds with unread entries' do
        get :index, format: :json
        assigns(:feeds).should eq [@feed1]
      end

      it 'assigns to @feeds all feeds if requested' do
        get :index, include_read: 'true', format: :json
        assigns(:feeds).should eq [@feed1, @feed3]
      end
    end

    context 'feeds in a folder' do

      it 'returns success' do
        get :index, folder_id: @folder1.id, format: :json
        response.should be_success
      end

      it 'assigns to @folder the correct folder' do
        get :index, folder_id: @folder1.id, format: :json
        assigns(:folder).should eq @folder1
      end

      it 'assigns to @feeds only feeds with unread entries' do
        get :index, folder_id: @folder1.id, format: :json
        assigns(:feeds).should eq [@feed1]
      end

      it 'assigns to @feeds all feeds if requested' do
        get :index, folder_id: @folder1.id, include_read: 'true', format: :json
        feeds = assigns(:feeds)
        feeds.count.should eq 2
        feeds.should include @feed1
        feeds.should include @feed3
      end

      it 'returns 404 if user does not own folder' do
        get :index, folder_id: @folder2.id, format: :json
        response.status.should eq 404
      end
    end
  end

  context 'GET show' do

    it 'assigns to @feed the correct feed' do
      get :show, id: @feed1.id, format: :json
      assigns(:feed).should eq @feed1
    end

    it 'returns a 404 for a feed the user is not suscribed to' do
      get :show, id: @feed2.id, format: :json
      response.status.should eq 404
    end

    it 'returns a 404 for a non-existing feed' do
      get :show, id: 1234567890, format: :json
      response.status.should eq 404
    end

  end

  context 'PATCH update' do

{'fraction_non_alphanumeric': 0.09559726363795826, 'fraction_numerical': 0.023680056130503422, 'mean_word_length': 2.508923076923077, 'pattern_counts': {'":': 0, '<': 23, '<?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': '6876218', 'n_tokens_mistral': 1951, 'n_tokens_neox': 1811, 'n_words': 620}