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

describe "Column" do

  before(:all) do
      class User < ::ActiveRecord::Base ; end
  end
    
  let(:migration) { ::ActiveRecord::Migration }

  context "JSON serialization" do
    before(:each) do
      create_table(User, :login => { :index => true})
      @login = User.columns.find{|column| column.name == "login"}
    end
    it "works properly" do
      if "#{::ActiveRecord::VERSION::MAJOR}.#{::ActiveRecord::VERSION::MINOR}".to_r <= "4.1".to_r
        expect(JSON.parse(@login.to_json)).to include("name" => "login", "type" => "string")
      else
        expect(JSON.parse(@login.to_json)).to include("name" => "login", "sql_type" => "character varying")
      end
    end
  end

  context "regarding indexes" do

    context "if not unique" do

      before (:each) do 
        create_table(User, :login => { :index => true})
        @login = User.columns.find{|column| column.name == "login"}
      end

      it "should report not unique" do
        expect(@login).not_to be_unique
      end

      it "should report nil unique scope" do
        create_table(User, :login => { :index => true})
        expect(@login.unique_scope).to be_nil
      end
    end

    context "if unique single column" do
      before (:each) do 
        create_table(User, :login => { :index => :unique})<commit_msg>conform spec to mysql string type<commit_after>require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "Column" do

  before(:all) do
      class User < ::ActiveRecord::Base ; end
  end
    
  let(:migration) { ::ActiveRecord::Migration }

  context "JSON serialization" do
    before(:each) do
      create_table(User, :login => { :index => true})
      @login = User.columns.find{|column| column.name == "login"}
    end
    it "works properly" do
      type = case
             when "#{::ActiveRecord::VERSION::MAJOR}.#{::ActiveRecord::VERSION::MINOR}".to_r <= "4.1".to_r
               { "type" => "string" }
             when SchemaDev::Rspec::Helpers.mysql?
               { "sql_type" => "varchar(255)" }
             else
               { "sql_type" => "character varying" }
             end
      expect(JSON.parse(@login.to_json)).to include(type.merge("name" => "login"))
    end
  end

  context "regarding indexes" do

    context "if not unique" do

      before (:each) do 
        create_table(User, :login => { :index => true})
        @login = User.columns.find{|column| column.name == "login"}
      end

      it "should report not unique" do
        expect(@login).not_to be_unique
      end

      it "should report nil unique scope" do
        create_table(User, :login => { :index => true})
        expect(@login.unique_scope).to be_nil
      end
    end

    context "if unique single column" do
      before (:each) do 
        create_table(User, :login => { :index => :unique})
{'fraction_non_alphanumeric': 0.14614065180102917, 'fraction_numerical': 0.0024013722126929675, 'mean_word_length': 2.645, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, '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': '2534909', 'n_tokens_mistral': 908, 'n_tokens_neox': 879, 'n_words': 227}