Sha256: e166ac623324ca655398d512a5b4a40c779535418c51e76d318deb13cd48ad39

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

require File.dirname(__FILE__) + '/base'
require 'active_support/core_ext/kernel/debugger'

describe YamlDb::Load do
	before do
		SerializationHelper::Utils.stub!(:quote_table).with('mytable').and_return('mytable')

		silence_warnings { ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true) }
		ActiveRecord::Base.stub(:connection).and_return(stub('connection').as_null_object)
		ActiveRecord::Base.connection.stub!(:transaction).and_yield
	end

	before(:each) do
		@io = StringIO.new
    end
    

	it "should call load structure for each document in the file" do
		YAML.should_receive(:load_documents).with(@io).and_yield({ 'mytable' => { 
					'columns' => [ 'a', 'b' ], 
					'records' => [[1, 2], [3, 4]] 
				} } )
		YamlDb::Load.should_receive(:load_table).with('mytable', { 'columns' => [ 'a', 'b' ], 'records' => [[1, 2], [3, 4]] },true)
		YamlDb::Load.load(@io)
	end

	it "should not call load structure when the document in the file contains no records" do
		YAML.should_receive(:load_documents).with(@io).and_yield({ 'mytable' => nil })
		YamlDb::Load.should_not_receive(:load_table)
		YamlDb::Load.load(@io)
	end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yaml_db_improved-1.0.1 spec/yaml_load_spec.rb
yaml_db_improved-1.0.0 spec/yaml_load_spec.rb