<commit_before>require 'spec_helper'

describe ActivityMigrator, :legacy_migration => true, :type => :legacy_migration do
  describe ".migrate" do
    before do
      UserMigrator.new.migrate
      WorkspaceMigrator.new.migrate
      InstanceMigrator.new.migrate
      HadoopInstanceMigrator.new.migrate
      WorkfileMigrator.new.migrate
    end

    context "migrating activities that reference datasets" do
      before do
        InstanceAccountMigrator.new.migrate
        ActivityMigrator.new.migrate
      end

      it "creates new events for all legacy activities" do
        Events::Base.count.should > 0
      end

      it "copies SOURCE TABLE CREATED data fields from the legacy activity" do
        event = Events::SOURCE_TABLE_CREATED.find(event_id_for('10002'))

        event.workspace.should be_instance_of(Workspace)
        event.actor.should be_instance_of(User)
        event.dataset.should be_a(Dataset)
        event.created_at.to_s.should == "2012-03-07 17:59:20 UTC"
      end

      it "copies WORKSPACE_ADD_HDFS_AS_EXT_TABLE fields from the legacy activity" do
        event = Events::WORKSPACE_ADD_HDFS_AS_EXT_TABLE.find(event_id_for('10718'))
        event.workspace.should be_instance_of(Workspace)
        event.actor.should be_instance_of(User)
        event.dataset.should be_a(Dataset)
        event.hdfs_file.should be_a(HdfsFileReference)
        event.hdfs_file.hadoop_instance_id.should_not be_nil
        event.hdfs_file.path.should == "/data/Top_1_000_Songs_To_Hear_Before_You_Die.csv"
      end

      it "copies IMPORT SUCCESS activities" do
        event = Events::IMPORT_SUCCESS.find(event_id_for('10177'))
        event.workspace.should be_a(Workspace)
        event.workspace.name.should == "ws"
        event.actor.should be_a(User)
        event.actor.username.should == "edcadmin"
        event.dataset.should be_a(Dataset)
        event.dataset.name.should == "sixrows33columns"
        event.additional_data[:filename].should == "sixrows33columns.csv"
        event.additional_data[:import_type].should == "file"
      end

      it "copies IMPORT FAILURE activities" do
        event = Events::IMPORT_FAILED.find(event_id_for('10368'))
        event.workspace.should be_a(Workspace)
        event.workspace.name.should == "active_public"
        event.actor.should be_a(User)
        event.actor.username.should == "edcadmin"
        event.additional_data[:filename].should == "SFO 2011 Annual Survey.csv"
        event.additional_data[:import_type].should == "file"
        event.additional_data[:destination_table].should == "sfo_2011_annual_survey"
        event.additional_data[:error_message].should == "[ERROR: invalid input syntax for type double precision: \"1,909.00\"\n  Where: COPY sfo_2011_annual_survey, line 3851, column runid]"
      end
    end

    context "migrating activities that do not reference datasets" do
      before do
        ActivityMigrator.new.migrate
      end

      it "copies PUBLIC WORKSPACE CREATED data fields from the legacy activity" do
        event = Events::PUBLIC_WORKSPACE_CREATED.find(event_id_for('10158'))

        event.workspace.should be_instance_of(Workspace)
        event.actor.should be_instance_of(User)
      end

      it "copied WORKSPACE_ARCHIVED data fields from the legacy activity" do
        event = Events::WORKSPACE_ARCHIVED.find(event_id_for('10304'))

        event.workspace.should be_instance_of(Workspace)
        event.actor.should be_instance_of(User)
      end

      it "copies PRIVATE WORKSPACE CREATED data fields from the legacy activity" do
        event = Events::PRIVATE_WORKSPACE_CREATED.find(event_id_for('10401'))

        event.workspace.should be_instance_of(Workspace)
        event.actor.should be_instance_of(User)
      end<commit_msg>Update legacy.sql and activity_migrator_spec with WORKSPACE_ARCHIVED.  No actual code changes needed since generic case in activity_stream_event_mapper handles this event. [#29788303]<commit_after>require 'spec_helper'

describe ActivityMigrator, :legacy_migration => true, :type => :legacy_migration do
  describe ".migrate" do
    before do
      UserMigrator.new.migrate
      WorkspaceMigrator.new.migrate
      InstanceMigrator.new.migrate
      HadoopInstanceMigrator.new.migrate
      WorkfileMigrator.new.migrate
    end

    context "migrating activities that reference datasets" do
      before do
        InstanceAccountMigrator.new.migrate
        ActivityMigrator.new.migrate
      end

      it "creates new events for all legacy activities" do
        Events::Base.count.should > 0
      end

      it "copies SOURCE TABLE CREATED data fields from the legacy activity" do
        event = Events::SOURCE_TABLE_CREATED.find(event_id_for('10002'))

        event.workspace.should be_instance_of(Workspace)
        event.actor.should be_instance_of(User)
        event.dataset.should be_a(Dataset)
        event.created_at.to_s.should == "2012-03-07 17:59:20 UTC"
      end

      it "copies WORKSPACE_ADD_HDFS_AS_EXT_TABLE fields from the legacy activity" do
        event = Events::WORKSPACE_ADD_HDFS_AS_EXT_TABLE.find(event_id_for('10718'))
        event.workspace.should be_instance_of(Workspace)
        event.actor.should be_instance_of(User)
        event.dataset.should be_a(Dataset)
        event.hdfs_file.should be_a(HdfsFileReference)
        event.hdfs_file.hadoop_instance_id.should_not be_nil
        event.hdfs_file.path.should == "/data/Top_1_000_Songs_To_Hear_Before_You_Die.csv"
      end

      it "copies IMPORT SUCCESS activities" do
        event = Events::IMPORT_SUCCESS.find(event_id_for('10177'))
        event.workspace.should be_a(Workspace)
        event.workspace.name.should == "ws"
        event.actor.should be_a(User)
        event.actor.username.should == "edcadmin"
        event.dataset.should be_a(Dataset)
        event.dataset.name.should == "sixrows33columns"
        event.additional_data[:filename].should == "sixrows33columns.csv"
        event.additional_data[:import_type].should == "file"
      end

      it "copies IMPORT FAILURE activities" do
        event = Events::IMPORT_FAILED.find(event_id_for('10368'))
        event.workspace.should be_a(Workspace)
        event.workspace.name.should == "active_public"
        event.actor.should be_a(User)
        event.actor.username.should == "edcadmin"
        event.additional_data[:filename].should == "SFO 2011 Annual Survey.csv"
        event.additional_data[:import_type].should == "file"
        event.additional_data[:destination_table].should == "sfo_2011_annual_survey"
        event.additional_data[:error_message].should == "[ERROR: invalid input syntax for type double precision: \"1,909.00\"\n  Where: COPY sfo_2011_annual_survey, line 3851, column runid]"
      end
    end

    context "migrating activities that do not reference datasets" do
      before do
        ActivityMigrator.new.migrate
      end

      it "copies PUBLIC WORKSPACE CREATED data fields from the legacy activity" do
        event = Events::PUBLIC_WORKSPACE_CREATED.find(event_id_for('10158'))

        event.workspace.should be_instance_of(Workspace)
        event.actor.should be_instance_of(User)
      end

      it "copied WORKSPACE_ARCHIVED data fields from the legacy activity" do
        event = Events::WORKSPACE_ARCHIVED.find(event_id_for('10304'))

        event.workspace.should be_instance_of(Workspace)
        event.actor.should be_instance_of(User)
      end

      it "copied WORKSPACE_ARCHIVED data fields from the legacy activity" do
        event = Events::WORKSPACE_ARCHIVED.find(event_id_for('10304'))

        event.workspace.should be_instance_of(Workspace)
        event.actor.should be_instance_of(User)
      end

      it "copied WORKSPACE_UNARCHIVED data fields from the legacy activity" do
        Events::WORKSPACE_UNARCHIVED.count.should == 1
        event = Events::WORKSPACE_UNARCHIVED.find(event_id_for('10721'))

        event.workspace.should be_instance_of(Workspace)
        event.actor.should be_instance_of(User)
      end

      it "copies PRIVATE WORKSPACE CREATED data fields from the legacy activity" do
        event = Events::PRIVATE_WORKSPACE_CREATED.find(event_id_for('10401'))

        event.workspace.should be_instance_of(Workspace)
        event.actor.should be_instance_of(User)
      end
{'fraction_non_alphanumeric': 0.08536731994709632, 'fraction_numerical': 0.021522183479620056, 'mean_word_length': 3.2766066838046273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5995143', 'n_tokens_mistral': 2680, 'n_tokens_neox': 2556, 'n_words': 514}