<commit_before>require 'spec_helper'

# a dummy class to include the module into
class SqliteExtension
  include SQL::Sqlite
end

describe "SQLite3 Extensions" do
  before do
    @se = SqliteExtension.new
  end

  it 'should support schema-level transactions' do
    @se.supports_schema_transactions?.should be(true)
  end

  it 'should support the serial column attribute' do
    @se.supports_serial?.should be(true)
  end

  it 'should create a table object from the name' do
    table = mock('SQLite3 Table')
    SQL::Sqlite::Table.should_receive(:new).with(@se, 'users').and_return(table)

    @se.table('users').should == table
  end

  describe 'recreating the database' do
    before do
      uri = mock('URI', :path => '/foo/bar.db')
      @se.instance_variable_set('@uri', uri)
    end

    it 'should rm the db file' do
      @se.should_receive(:system).with('rm /foo/bar.db')
      @se.recreate_database
    end

  end

  describe 'Table' do
    before do
      @cs1 = mock('Column Struct')
      @cs2 = mock('Column Struct')
      @adapter = mock('adapter')
      @adapter.stub!(:table_info).with('users').and_return([@cs1, @cs2])

      @col1 = mock('SQLite3 Column')
      @col2 = mock('SQLite3 Column')
    end

    it 'should initialize columns by querying the table' do
      SQL::Sqlite::Column.should_receive(:new).with(@cs1).and_return(@col1)
      SQL::Sqlite::Column.should_receive(:new).with(@cs2).and_return(@col2)
      @adapter.should_receive(:table_info).with('users').and_return([@cs1,@cs2])
      SQL::Sqlite::Table.new(@adapter, 'users')
    end

    it 'should create SQLite3 Column objects from the returned column structs' do
      SQL::Sqlite::Column.should_receive(:new).with(@cs1).and_return(@col1)
      SQL::Sqlite::Column.should_receive(:new).with(@cs2).and_return(@col2)
      SQL::Sqlite::Table.new(@adapter, 'users')
    end

    it 'should set the @columns to the looked-up columns' do<commit_msg>Fix spec failure caused by using FileUtils.rm_f<commit_after>require 'spec_helper'

# a dummy class to include the module into
class SqliteExtension
  include SQL::Sqlite
end

describe "SQLite3 Extensions" do
  before do
    @se = SqliteExtension.new
  end

  it 'should support schema-level transactions' do
    @se.supports_schema_transactions?.should be(true)
  end

  it 'should support the serial column attribute' do
    @se.supports_serial?.should be(true)
  end

  it 'should create a table object from the name' do
    table = mock('SQLite3 Table')
    SQL::Sqlite::Table.should_receive(:new).with(@se, 'users').and_return(table)

    @se.table('users').should == table
  end

  describe 'recreating the database' do
    before do
      uri = mock('URI', :path => '/foo/bar.db')
      @se.instance_variable_set('@uri', uri)
    end

    it 'should rm the db file' do
      FileUtils.should_receive(:rm_f).with('/foo/bar.db')
      @se.recreate_database
    end

  end

  describe 'Table' do
    before do
      @cs1 = mock('Column Struct')
      @cs2 = mock('Column Struct')
      @adapter = mock('adapter')
      @adapter.stub!(:table_info).with('users').and_return([@cs1, @cs2])

      @col1 = mock('SQLite3 Column')
      @col2 = mock('SQLite3 Column')
    end

    it 'should initialize columns by querying the table' do
      SQL::Sqlite::Column.should_receive(:new).with(@cs1).and_return(@col1)
      SQL::Sqlite::Column.should_receive(:new).with(@cs2).and_return(@col2)
      @adapter.should_receive(:table_info).with('users').and_return([@cs1,@cs2])
      SQL::Sqlite::Table.new(@adapter, 'users')
    end

    it 'should create SQLite3 Column objects from the returned column structs' do
      SQL::Sqlite::Column.should_receive(:new).with(@cs1).and_return(@col1)
      SQL::Sqlite::Column.should_receive(:new).with(@cs2).and_return(@col2)
      SQL::Sqlite::Table.new(@adapter, 'users')
    end

    it 'should set the @columns to the looked-up columns' do
{'fraction_non_alphanumeric': 0.13690932311621967, 'fraction_numerical': 0.010727969348659003, 'mean_word_length': 3.7123947051744888, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4028028', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1255, 'n_words': 308}