<commit_before>require 'spec_helper'

describe User do

  subject { User.make }

  before(:all) do
    User.delete_all

    subject.feeds = (0..4).map do |num|
      Feed.new(name: "Some Feed #{num}", default: true)
    end
  end

  after(:all) { User.delete_all }


  describe 'Persistence' do

    it { should be_valid }
    it { should embed_many(:feeds) }

  end

  describe '#to_label' do

    before(:all) do
      subject.name = 'Foo'
      subject.username = 'Bar'
      subject.email = '<EMAIL>'
    end

    context 'with name' do
      its(:to_label) { should == 'Foo' }
    end

    context 'without name' do
      before { subject.name = nil }
      its(:to_label) { should == 'Bar' }
    end

    context 'without name, without username' do
      before { subject.name = nil; subject.username = nil }
      its(:to_label) { should == '<EMAIL>' }
    end

  end

  describe '#default_sources and #all_sources' do

    it "should be a list of feed slugs" do
      (subject.default_sources + subject.all_sources).each do |src|
        src.should =~ /^Some-Feed-[0-4]$/
      end
    end

    it "#default_sources should only include feeds with the default flag" do
      subject.default_sources.size.should == 5
      subject.all_sources.size.should == 5

      feed = subject.feeds.last
      feed.default = false
      feed.save

      subject.default_sources.size.should == 4
      subject.all_sources.size.should == 5
    end

  end

  describe '#update!' do

    it "should call update on each feed" do
      subject.feeds.each{|f| f.should_receive(:update!)}
      subject.update!
    end

    context "with a deleted feed" do

      before do
        3.times { Article.make user: subject, source: 'Foo' }
        subject.articles.size.should == 3
        subject.update!
        subject.reload
      end

      its(:articles) { should be_empty }

    end

  end

  describe '#feed' do

    subject { User.make_unsaved }

    before(:all) do
      subject.feeds = [Feed.make_unsaved]
      subject.save!

      @id = subject.feeds.last.id
    end

    after(:all) do
      subject.destroy
    end

    it 'should find a user feed with corresponding id' do
      subject.feed(@id).should be_present
    end

    it 'should return nil if no feed found' do
      subject.feed(BSON::ObjectId.new).should be_blank
    end

  end

end
<commit_msg>Fixed User spec<commit_after>require 'spec_helper'

describe User do

  subject { User.make }

  before(:all) do
    User.delete_all

     (0..4).each do |num|
       subject.feeds << Feed.new(name: "Some Feed #{num}", default: true)
    end
  end

  after(:all) { User.delete_all }


  describe 'Persistence' do

    it { should be_valid }
    it { should embed_many(:feeds) }

  end

  describe '#to_label' do

    before(:all) do
      subject.name = 'Foo'
      subject.username = 'Bar'
      subject.email = '<EMAIL>'
    end

    context 'with name' do
      its(:to_label) { should == 'Foo' }
    end

    context 'without name' do
      before { subject.name = nil }
      its(:to_label) { should == 'Bar' }
    end

    context 'without name, without username' do
      before { subject.name = nil; subject.username = nil }
      its(:to_label) { should == '<EMAIL>' }
    end

  end

  describe '#default_sources and #all_sources' do

    it "should be a list of feed slugs" do
      (subject.default_sources + subject.all_sources).each do |src|
        src.should =~ /^Some-Feed-[0-4]$/
      end
    end

    it "#default_sources should only include feeds with the default flag" do
      subject.default_sources.size.should == 5
      subject.all_sources.size.should == 5

      feed = subject.feeds.last
      feed.default = false
      feed.save

      subject.default_sources.size.should == 4
      subject.all_sources.size.should == 5
    end

  end

  describe '#update!' do

    it "should call update on each feed" do
      subject.feeds.each{|f| f.should_receive(:update!)}
      subject.update!
    end

    context "with a deleted feed" do

      before do
        3.times { Article.make user: subject, source: 'Foo' }
        subject.articles.size.should == 3
        subject.update!
        subject.reload
      end

      its(:articles) { should be_empty }

    end

  end

  describe '#feed' do

    subject { User.make_unsaved }

    before(:all) do
      Daemons::Job.stub!(:queue)
      subject.feeds = [Feed.make_unsaved]
      subject.save!

      @id = subject.feeds.last.id
    end

    after(:all) do
      subject.destroy
    end

    it 'should find a user feed with corresponding id' do
      subject.feed(@id).should be_present
    end

    it 'should return nil if no feed found' do
      subject.feed(BSON::ObjectId.new).should be_blank
    end

  end

end

{'fraction_non_alphanumeric': 0.10809674027339643, 'fraction_numerical': 0.004206098843322818, 'mean_word_length': 2.277739490006892, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '3592568', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1468, 'n_words': 427}