<commit_before>require './spec/spec_helper'
require "./lib/mass_insert"
require "./spec/dummy_models/test"

describe "Model" do

  before :each do
    @values, @options  = [], {}
    @value_hash = {
      :name    => "some_name",
      :email   => "some_email",
      :age     => 20,
      :active  => true,
      :checked => true
    }
    User.delete_all
  end

  context "when is used without options" do
    it "should save 5 record into users table" do
      5.times{ @values << @value_hash }
      User.mass_insert(@values, @options)
      User.count.should eq(5)
    end

    it "should save if values cointains 1200 records" do
      1200.times{ @values << @value_hash }
      User.mass_insert(@values, @options)
      User.count.should eq(1200)
    end
  end

  context "when is used with options" do
    context "when the table name doesn't exit" do
      it "should not save any record" do
        5.times{ @values << @value_hash }
        @options.merge!(:table_name => "countries")
        lambda{ User.mass_insert(@values, @options) }.should raise_exception
      end
    end

    context "when the class name not inherit from ActiveRecord" do
      it "should not save any record" do
        5.times{ @values << @value_hash }
        @options.merge!(:class_name => Test)
        lambda{ User.mass_insert(@values, @options) }.should raise_exception
      end
    end
  end<commit_msg>Adding specs to test value hashes with string keys<commit_after>require './spec/spec_helper'
require "./lib/mass_insert"
require "./spec/dummy_models/test"

describe "Model" do

  before :each do
    @values, @options  = [], {}
    @value_hash = {
      :name    => "some_name",
      :email   => "some_email",
      :age     => 20,
      :active  => true,
      :checked => true
    }
    User.delete_all
  end

  context "when is used without options" do
    context "when value hashes have string keys" do
      before :each do
        value_hash = {
          "name"    => "some_name",
          "email"   => "some_email",
          "age"     => 20,
          "active"  => true,
          "checked" => true
        }
        5.times{ @values << value_hash }
        User.mass_insert(@values, @options)
      end

      it "should save correct values" do
        User.first.name.should eq("some_name")
      end

      it "should have saved 5 records" do
        User.count.should eq(5)
      end
    end

    context "when value hashes have symbol keys" do
      before :each do
        5.times{ @values << @value_hash }
        User.mass_insert(@values, @options)
      end

      it "should save correct values" do
        User.first.age.should eq(20)
      end

      it "should have saved 5 records" do
        User.count.should eq(5)
      end
    end

    context "when value hashes have symbol and string keys" do
      before :each do
        value_hash = {
          "name"    => "some_name",
          :email    => "some_email",
          "age"     => 20,
          :active   => true,
          "checked" => true
        }
        5.times{ @values << value_hash }
        User.mass_insert(@values, @options)
      end

      it "should save correct values" do
        User.first.email.should eq("some_email")
      end

      it "should have saved 5 records" do
        User.count.should eq(5)
      end
    end

    it "should save if values cointains 1200 records" do
      1200.times{ @values << @value_hash }
      User.mass_insert(@values, @options)
      User.count.should eq(1200)
    end
  end

  context "when is used with options" do
    context "when the table name doesn't exit" do
      it "should not save any record" do
        5.times{ @values << @value_hash }
        @options.merge!(:table_name => "countries")
        lambda{ User.mass_insert(@values, @options) }.should raise_exception
      end
    end

    context "when the class name not inherit from ActiveRecord" do
      it "should not save any record" do
        5.times{ @values << @value_hash }
        @options.merge!(:class_name => Test)
        lambda{ User.mass_insert(@values, @options) }.should raise_exception
      end
    end
  end
{'fraction_non_alphanumeric': 0.10890609874152953, 'fraction_numerical': 0.012100677637947725, 'mean_word_length': 2.135811836115326, 'pattern_counts': {'":': 0, '<': 23, '<?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': '6874281', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1234, 'n_words': 391}