tracks/vendor/plugins/yaml_db/spec/yaml_dump_spec.rb
bsag 0380d1b15a Merge branch 'master' of /Users/jackie/Sites/tracks_svn into svn-tracking
Up to r881

* 'master' of /Users/jackie/Sites/tracks_svn: (22 commits)
  Added .gitconfig
  Added yaml_db plugin: http://opensource.heroku.com/
  applied patch from Eric from #732
  fixes #730 restores ability to delete user from user management page
  fixes #724 where editing todos truncates the project name of the todo when the project name contains quotes (")
  Applied patch from Eric Pallen whcih automatically converts url's to links. Thanks Eric!
  explain that yaml cannot yet be used for backup as importing is not implemented yet. from mailinglist.
  hopefully fixes #727.Changes the check on running animation to finished animation
  regenerate compressed js and cleanup whitespace
  turns out that getElementsByClassName is removed from prototype and it therfore falls back to the function of the browser which has different semantics. Found here http://www.prototypejs.org/api/utility/getElementsByClassName
  forgot to create a new compressed js from the previous js changes
  in the stats page you can downdrill to see the active todos in a certain week from the running time charts. This patch adds the option to see all active todos from the selected week and older.
  fix #727. Adds a check to prevent expand/collapse while a previous expand/collaps is still animating
  fixed small problem where updating a todo from mobile resulted in an error becase source_view was nil
  fixes #726. Thanks Eric Pallen for the fix. The mobile view showed active todos from completed projects while the home page does not.
  merges changes from tracks1.6 to trunk
  prepares trunk for 1.6 release
  fixes #713. Adds behavior for edit/star/delete/check buttons of todo even if there is no todo to show. This makes sure that the behaviors are present when you add a new todo through AJAX.
  fixes #718. The link included the number of actions which resulted from last commit
  removed some more whitespace to reduce the download of the mobile view.
  ...
2008-06-15 09:50:05 +01:00

89 lines
2.7 KiB
Ruby

require File.dirname(__FILE__) + '/base'
describe YamlDb::Dump do
before do
File.stub!(:new).with('dump.yml', 'w').and_return(StringIO.new)
ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true)
ActiveRecord::Base.connection = mock('connection')
ActiveRecord::Base.connection.stub!(:tables).and_return([ 'mytable' ])
ActiveRecord::Base.connection.stub!(:columns).with('mytable').and_return([ mock('a',:name => 'a'), mock('b', :name => 'b') ])
ActiveRecord::Base.connection.stub!(:select_one).and_return({"count"=>"2"})
ActiveRecord::Base.connection.stub!(:select_all).and_return([ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ])
end
before(:each) do
@io = StringIO.new
end
it "should return a formatted string" do
YamlDb::Dump.table_record_header(@io)
@io.rewind
@io.read.should == " records: \n"
end
it "should return a list of column names" do
YamlDb::Dump.table_column_names('mytable').should == [ 'a', 'b' ]
end
it "should return the total number of records in a table" do
YamlDb::Dump.table_record_count('mytable').should == 2
end
it "should return a yaml string that contains a table header and column names" do
YamlDb::Dump.stub!(:table_column_names).with('mytable').and_return([ 'a', 'b' ])
YamlDb::Dump.dump_table_columns(@io, 'mytable')
@io.rewind
@io.read.should == <<EOYAML
---
mytable:
columns:
- a
- b
EOYAML
end
it "should return all records from the database and return them when there is only 1 page" do
YamlDb::Dump.each_table_page('mytable') do |records|
records.should == [ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ]
end
end
it "should paginate records from the database and return them" do
ActiveRecord::Base.connection.stub!(:select_all).and_return([ { 'a' => 1, 'b' => 2 } ], [ { 'a' => 3, 'b' => 4 } ])
records = [ ]
YamlDb::Dump.each_table_page('mytable', 1) do |page|
page.size.should == 1
records.concat(page)
end
records.should == [ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ]
end
it "should return dump the records for a table in yaml to a given io stream" do
YamlDb::Dump.dump_table_records(@io, 'mytable')
@io.rewind
@io.read.should == <<EOYAML
records:
- - 1
- 2
- - 3
- 4
EOYAML
end
it "should dump a table's contents to yaml" do
YamlDb::Dump.should_receive(:dump_table_columns)
YamlDb::Dump.should_receive(:dump_table_records)
YamlDb::Dump.dump_table(@io, 'mytable')
end
it "should not dump a table's contents when the record count is zero" do
YamlDb::Dump.stub!(:table_record_count).with('mytable').and_return(0)
YamlDb::Dump.should_not_receive(:dump_table_columns)
YamlDb::Dump.should_not_receive(:dump_table_records)
YamlDb::Dump.dump_table(@io, 'mytable')
end
end