1 require File.dirname(__FILE__) + '/base'
3 describe YamlDb::Utils, " convert records utility method" do
5 ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true)
6 ActiveRecord::Base.connection = mock('connection')
9 it "turns an array with one record into a yaml chunk" do
10 YamlDb::Utils.chunk_records([ %w(a b) ]).should == <<EOYAML
16 it "turns an array with two records into a yaml chunk" do
17 YamlDb::Utils.chunk_records([ %w(a b), %w(x y) ]).should == <<EOYAML
25 it "returns an array of hash values using an array of ordered keys" do
26 YamlDb::Utils.unhash({ 'a' => 1, 'b' => 2 }, [ 'b', 'a' ]).should == [ 2, 1 ]
29 it "should unhash each hash an array using an array of ordered keys" do
30 YamlDb::Utils.unhash_records([ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ], [ 'b', 'a' ]).should == [ [ 2, 1 ], [ 4, 3 ] ]
33 it "should return true if it is a boolean type" do
34 YamlDb::Utils.is_boolean(true).should == true
35 YamlDb::Utils.is_boolean('true').should_not == true
38 it "should return an array of boolean columns" do
39 ActiveRecord::Base.connection.stub!(:columns).with('mytable').and_return([ mock('a',:name => 'a',:type => :string), mock('b', :name => 'b',:type => :boolean) ])
40 YamlDb::Utils.boolean_columns('mytable').should == ['b']
43 it "should quote the table name" do
44 ActiveRecord::Base.connection.should_receive(:quote_table_name).with('values').and_return('`values`')
45 YamlDb::Utils.quote_table('values').should == '`values`'