X-Git-Url: https://projects.mako.cc/source/selectricity-live/blobdiff_plain/5637ec97922038fa7a7cfe9f8aa13b1e3002abcd..90a5a1b95e6ec0b5f9aa2db522215463a2909920:/vendor/plugins/yaml_db/spec/yaml_utils_spec.rb diff --git a/vendor/plugins/yaml_db/spec/yaml_utils_spec.rb b/vendor/plugins/yaml_db/spec/yaml_utils_spec.rb new file mode 100644 index 0000000..19d6fd7 --- /dev/null +++ b/vendor/plugins/yaml_db/spec/yaml_utils_spec.rb @@ -0,0 +1,47 @@ +require File.dirname(__FILE__) + '/base' + +describe YamlDb::Utils, " convert records utility method" do + before do + ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true) + ActiveRecord::Base.connection = mock('connection') + end + + it "turns an array with one record into a yaml chunk" do + YamlDb::Utils.chunk_records([ %w(a b) ]).should == < 1, 'b' => 2 }, [ 'b', 'a' ]).should == [ 2, 1 ] + end + + it "should unhash each hash an array using an array of ordered keys" do + YamlDb::Utils.unhash_records([ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ], [ 'b', 'a' ]).should == [ [ 2, 1 ], [ 4, 3 ] ] + end + + it "should return true if it is a boolean type" do + YamlDb::Utils.is_boolean(true).should == true + YamlDb::Utils.is_boolean('true').should_not == true + end + + it "should return an array of boolean columns" do + ActiveRecord::Base.connection.stub!(:columns).with('mytable').and_return([ mock('a',:name => 'a',:type => :string), mock('b', :name => 'b',:type => :boolean) ]) + YamlDb::Utils.boolean_columns('mytable').should == ['b'] + end + + it "should quote the table name" do + ActiveRecord::Base.connection.should_receive(:quote_table_name).with('values').and_return('`values`') + YamlDb::Utils.quote_table('values').should == '`values`' + end +end