<commit_before>require File.dirname(__FILE__) + "/spec_helper"

describe SafeMigrations::MigrationExt do
  describe "when there is no safety assurance" do
    it "should not let you run remove_column" do
      expect {
        ActiveRecord::Migration.remove_column :some_table, :some_column
      }.to raise_error(SafeMigrations::UnsafeRemoveColumn)
    end

    describe "rename_table" do
      it "should fail" do
        expect {
          ActiveRecord::Migration.rename_table :old_name, :new_name
        }.to raise_error(SafeMigrations::UnsafeRenameTable)
      end
    end

    describe "rename_column" do
      it "should fail" do
        expect {
          ActiveRecord::Migration.rename_column :old_name, :new_name
        }.to raise_error(SafeMigrations::UnsafeRenameColumn)<commit_msg>Test that safe migrations are allowed<commit_after>require File.dirname(__FILE__) + "/spec_helper"

describe SafeMigrations::MigrationExt do
  SAFE_MIGRATIONS = [
    :add_column,
    :add_reference,
    :add_timestamps,
    :create_table,
    :create_join_table,
    :drop_table,
    :drop_join_table
  ]

  describe "when there is no safety assurance" do

    SAFE_MIGRATIONS.each do |migration_method_name|
      eval <<TEST
        it "allows #{migration_method_name}" do
          mock(ActiveRecord::Migration).method_missing_without_safety(:#{migration_method_name})
          ActiveRecord::Migration.#{migration_method_name}
        end
TEST
    end

    it "should not let you run remove_column" do
      expect {
        ActiveRecord::Migration.remove_column :some_table, :some_column
      }.to raise_error(SafeMigrations::UnsafeRemoveColumn)
    end

    describe "rename_table" do
      it "should fail" do
        expect {
          ActiveRecord::Migration.rename_table :old_name, :new_name
        }.to raise_error(SafeMigrations::UnsafeRenameTable)
      end
    end

    describe "rename_column" do
      it "should fail" do
        expect {
          ActiveRecord::Migration.rename_column :old_name, :new_name
        }.to raise_error(SafeMigrations::UnsafeRenameColumn)
{'fraction_non_alphanumeric': 0.08113298127700432, 'fraction_numerical': 0.0, 'mean_word_length': 3.296907216494845, 'pattern_counts': {'":': 0, '<': 5, '<?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': '333663', 'n_tokens_mistral': 635, 'n_tokens_neox': 633, 'n_words': 140}