<commit_before>require 'spec_helper'

describe 'refresh feeds' do

  before :each do
    # Ensure no actual HTTP calls are made
    RestClient.stub get: true

    @user = FactoryGirl.create :user
    @feed1 = FactoryGirl.create :feed
    @user.feeds << @feed1
    @entry1 = FactoryGirl.build :entry, feed_id: @feed1.id
    @feed1.entries << @entry1

    login_user_for_feature @user
    visit feeds_path
    read_feed @feed1.id
  end

  it 'hides refresh button until a feed is selected', js: true do
    visit feeds_path
    page.should have_css 'a#refresh-feed.hidden', visible: false
  end

  it 'shows refresh button when a feed is selected', js: true do
    page.should_not have_css 'a#refresh-feed.hidden', visible: false
    page.should have_css 'a#refresh-feed'
  end

  it 'refreshes a single feed', js: true do
    # Page should have current entries for the feed
    page.should have_content @entry1.title

    # Refresh feed
    entry2 = FactoryGirl.build :entry, feed_id: @feed1.id
    FeedClient.should_receive(:fetch).with @feed1.id
    @feed1.entries << entry2
    find('a#refresh-feed').click

    # Page should have the new entries for the feed
    page.should have_content @entry1.title
    page.should have_content entry2.title
  end

  it 'only shows unread entries when refreshing a single feed'

  it 'refreshes all subscribed feeds', js: true do
    feed2 = FactoryGirl.create :feed
    @user.feeds << feed2
    entry2 = FactoryGirl.build :entry, feed_id: feed2.id
    feed2.entries << entry2

    visit feeds_path
    # Click on "Read all subscriptions" within the "All subscriptions" folder
    within '#sidebar li#folder-all' do
      # Open "All subscriptions" folder
      find("a[data-target='#feeds-all']").click
      # Click on "Read all subscriptions"
      find('li#folder-all-all-feeds > a').click
    end
<commit_msg>Added acceptance test to ensure that after refreshing a single feed, only unread entries are shown by default.<commit_after>require 'spec_helper'

describe 'refresh feeds' do

  before :each do
    # Ensure no actual HTTP calls are made
    RestClient.stub get: true

    @user = FactoryGirl.create :user
    @feed1 = FactoryGirl.create :feed
    @entry1 = FactoryGirl.build :entry, feed_id: @feed1.id
    @feed1.entries << @entry1
    @user.feeds << @feed1

    login_user_for_feature @user
    visit feeds_path
    read_feed @feed1.id
  end

  it 'hides refresh button until a feed is selected', js: true do
    visit feeds_path
    page.should have_css 'a#refresh-feed.hidden', visible: false
  end

  it 'shows refresh button when a feed is selected', js: true do
    page.should_not have_css 'a#refresh-feed.hidden', visible: false
    page.should have_css 'a#refresh-feed'
  end

  it 'refreshes a single feed', js: true do
    # Page should have current entries for the feed
    page.should have_content @entry1.title

    # Refresh feed
    entry2 = FactoryGirl.build :entry, feed_id: @feed1.id
    FeedClient.should_receive(:fetch).with @feed1.id
    @feed1.entries << entry2
    find('a#refresh-feed').click

    # Page should have the new entries for the feed
    page.should have_content @entry1.title
    page.should have_content entry2.title
  end

  it 'only shows unread entries when refreshing a single feed', js: true do
    entry2 = FactoryGirl.build :entry, feed_id: @feed1.id
    @feed1.entries << entry2
    # @entry1 is read, entry2 is unread
    entry_state1 = EntryState.where(user_id: @user.id, entry_id: @entry1.id).first
    entry_state1.read = true
    entry_state1.save!
    # When refreshing the feed, fetch the new unread entry3
    entry3 = FactoryGirl.build :entry, feed_id: @feed1.id
    FeedClient.stub :fetch do
      @feed1.entries << entry3
    end

    read_feed @feed1.id
    find('a#refresh-feed').click

    # entry2 and entry3 should appear, @entry1 should not appear because it's already read
    page.should_not have_content @entry1.title
    page.should have_content entry2.title
    page.should have_content entry3.title
  end

  it 'refreshes all subscribed feeds', js: true do
    feed2 = FactoryGirl.create :feed
    @user.feeds << feed2
    entry2 = FactoryGirl.build :entry, feed_id: feed2.id
    feed2.entries << entry2

    visit feeds_path
    # Click on "Read all subscriptions" within the "All subscriptions" folder
    within '#sidebar li#folder-all' do
      # Open "All subscriptions" folder
      find("a[data-target='#feeds-all']").click
      # Click on "Read all subscriptions"
      find('li#folder-all-all-feeds > a').click
    end

{'fraction_non_alphanumeric': 0.0898506151142355, 'fraction_numerical': 0.014059753954305799, 'mean_word_length': 3.287193973634652, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 5, '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': '5544927', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1411, 'n_words': 463}