added yaml_db plugin
[selectricity-live] / vendor / plugins / yaml_db / spec / yaml_utils_spec.rb
1 require File.dirname(__FILE__) + '/base'
2
3 describe YamlDb::Utils, " convert records utility method" do
4         before do
5                 ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true)
6                 ActiveRecord::Base.connection = mock('connection')
7         end
8
9         it "turns an array with one record into a yaml chunk" do
10                 YamlDb::Utils.chunk_records([ %w(a b) ]).should == <<EOYAML
11   - - a
12     - b
13 EOYAML
14         end
15
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
18   - - a
19     - b
20   - - x
21     - y
22 EOYAML
23         end
24
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 ]
27         end
28
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 ] ]
31         end
32
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
36         end
37
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']
41         end
42
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`'
46         end
47 end

Benjamin Mako Hill || Want to submit a patch?