<commit_before>require 'spec_helper'

describe Seymour::Distributable do

  class DistributableActivity
    include Seymour::Distributable
    audience :users, :admin
    audience :events,       :batch_size => 100
    audience :soccer_teams, :feed => "TeamFeed"
    audience :followers,    :feed => %w[ DashboardFeed EmailDigest ]

    AUDIENCES = [:users, :admin, :soccer_teams, :events, :followers]

    AUDIENCES.each do |audience_name|
      attr_writer audience_name

      define_method(audience_name) do
        instance_variable_get("@#{audience_name}") || []
      end
    end
  end

  describe "class methods" do
    describe "audience" do
      it "should list audience names" do
        audience_names = DistributableActivity.audience_names
        audience_names.should include(:users)
        audience_names.should include(:admin)
        audience_names.should include(:soccer_teams)
        audience_names.should include(:events)
      end

      it "should list activity feed classes" do
        feed_class_names = DistributableActivity.feed_class_names
        feed_class_names.should include('UserFeed')
        feed_class_names.should include('AdminFeed')
        feed_class_names.should include('TeamFeed')
        feed_class_names.should include('EventFeed')
      end

      it "should support multiple feeds for an audience" do
        DistributableActivity.audience_names.should include(:followers)
        DistributableActivity.feed_class_names.should include("DashboardFeed")
        DistributableActivity.feed_class_names.should include("EmailDigest")
      end

    end

    describe "feeding" do
      let(:activity) { DistributableActivity.new }

      before(:each) do
        @user   = mock_model(User)
        @admin  = mock_model(User)
        activity.users = [@user]
        activity.admin = [@admin]
      end

      describe "feeds_for" do
        it "should build feed for each audience member" do
          DistributableActivity.feeds_for(activity).size.should == 2
        end

        it "should assign owner to correct feed type" do
          feed_1, feed_2 = DistributableActivity.feeds_for(activity)
          feed_1.should be_a(UserFeed)
          feed_1.owner.should == @user
          feed_2.should be_a(AdminFeed)
          feed_2.owner.should == @admin
        end

        it "should use default batch size if iterating on arel scope" do
          activity.users = User.scoped
          activity.users.should_receive(:find_each).with(:batch_size => 500)
          DistributableActivity.feeds_for(activity)
        end
<commit_msg>Update distributable specs relying on non-deterministic ordering of audience hash; good catch @niuage<commit_after>require 'spec_helper'

describe Seymour::Distributable do

  class DistributableActivity
    include Seymour::Distributable
    audience :users, :admin
    audience :events,       :batch_size => 100
    audience :soccer_teams, :feed => "TeamFeed"
    audience :followers,    :feed => %w[ DashboardFeed EmailDigest ]

    AUDIENCES = [:users, :admin, :soccer_teams, :events, :followers]

    AUDIENCES.each do |audience_name|
      attr_writer audience_name

      define_method(audience_name) do
        instance_variable_get("@#{audience_name}") || []
      end
    end
  end

  describe "class methods" do
    describe "audience" do
      it "should list audience names" do
        audience_names = DistributableActivity.audience_names
        audience_names.should include(:users)
        audience_names.should include(:admin)
        audience_names.should include(:soccer_teams)
        audience_names.should include(:events)
      end

      it "should list activity feed classes" do
        feed_class_names = DistributableActivity.feed_class_names
        feed_class_names.should include('UserFeed')
        feed_class_names.should include('AdminFeed')
        feed_class_names.should include('TeamFeed')
        feed_class_names.should include('EventFeed')
      end

      it "should support multiple feeds for an audience" do
        DistributableActivity.audience_names.should include(:followers)
        DistributableActivity.feed_class_names.should include("DashboardFeed")
        DistributableActivity.feed_class_names.should include("EmailDigest")
      end

    end

    describe "feeding" do
      let(:activity) { DistributableActivity.new }

      before(:each) do
        @user   = mock_model(User)
        @admin  = mock_model(User)
        activity.users = [@user]
        activity.admin = [@admin]
      end

      describe "feeds_for" do
        it "should build feed for each audience member" do
          DistributableActivity.feeds_for(activity).size.should == 2
        end

        it "should return all assigned feed types" do
          feed_classes = DistributableActivity.feeds_for(activity).map(&:class)
          feed_classes.should include(UserFeed)
          feed_classes.should include(AdminFeed)
        end

        it "should assign owners to correct feed type" do
          feeds = DistributableActivity.feeds_for(activity)
          user_feed   = feeds.detect { |feed| feed.is_a?(UserFeed) }
          admin_feed  = feeds.detect { |feed| feed.is_a?(AdminFeed) }

          user_feed.owner.should  == @user
          admin_feed.owner.should == @admin
        end

        it "should use default batch size if iterating on arel scope" do
          activity.users = User.scoped
          activity.users.should_receive(:find_each).with(:batch_size => 500)
          DistributableActivity.feeds_for(activity)
        end

{'fraction_non_alphanumeric': 0.08154815481548155, 'fraction_numerical': 0.0036003600360036, 'mean_word_length': 2.8934828311142256, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '4804407', 'n_tokens_mistral': 1605, 'n_tokens_neox': 1571, 'n_words': 374}