tracks/vendor/plugins/yaml_db/spec/yaml_load_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

88 lines
4.3 KiB
Ruby

require File.dirname(__FILE__) + '/base'
describe YamlDb::Load do
before do
ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true)
ActiveRecord::Base.connection = mock('connection')
ActiveRecord::Base.connection.stub!(:transaction).and_yield
end
before(:each) do
@io = StringIO.new
end
it "should truncate the table" do
ActiveRecord::Base.connection.stub!(:execute).with("TRUNCATE mytable").and_return(true)
ActiveRecord::Base.connection.should_not_receive(:execute).with("DELETE FROM mytable")
YamlDb::Load.truncate_table('mytable')
end
it "should delete the table if truncate throws an exception" do
ActiveRecord::Base.connection.should_receive(:execute).with("TRUNCATE mytable").and_raise()
ActiveRecord::Base.connection.should_receive(:execute).with("DELETE FROM mytable").and_return(true)
YamlDb::Load.truncate_table('mytable')
end
it "should insert records into a table" do
ActiveRecord::Base.connection.stub!(:quote_column_name).with('a').and_return('a')
ActiveRecord::Base.connection.stub!(:quote_column_name).with('b').and_return('b')
ActiveRecord::Base.connection.stub!(:quote).with(1).and_return("'1'")
ActiveRecord::Base.connection.stub!(:quote).with(2).and_return("'2'")
ActiveRecord::Base.connection.stub!(:quote).with(3).and_return("'3'")
ActiveRecord::Base.connection.stub!(:quote).with(4).and_return("'4'")
ActiveRecord::Base.connection.should_receive(:execute).with("INSERT INTO mytable (a,b) VALUES ('1','2')")
ActiveRecord::Base.connection.should_receive(:execute).with("INSERT INTO mytable (a,b) VALUES ('3','4')")
YamlDb::Load.load_records('mytable', ['a', 'b'], [[1, 2], [3, 4]])
end
it "should quote column names that correspond to sql keywords" do
ActiveRecord::Base.connection.stub!(:quote_column_name).with('a').and_return('a')
ActiveRecord::Base.connection.stub!(:quote_column_name).with('count').and_return('"count"')
ActiveRecord::Base.connection.stub!(:quote).with(1).and_return("'1'")
ActiveRecord::Base.connection.stub!(:quote).with(2).and_return("'2'")
ActiveRecord::Base.connection.stub!(:quote).with(3).and_return("'3'")
ActiveRecord::Base.connection.stub!(:quote).with(4).and_return("'4'")
ActiveRecord::Base.connection.should_receive(:execute).with("INSERT INTO mytable (a,\"count\") VALUES ('1','2')")
ActiveRecord::Base.connection.should_receive(:execute).with("INSERT INTO mytable (a,\"count\") VALUES ('3','4')")
YamlDb::Load.load_records('mytable', ['a', 'count'], [[1, 2], [3, 4]])
end
it "should truncate the table and then load the records into the table" do
YamlDb::Load.should_receive(:truncate_table).with('mytable')
YamlDb::Load.should_receive(:load_records).with('mytable', ['a', 'b'], [[1, 2], [3, 4]])
YamlDb::Load.should_receive(:reset_pk_sequence!).with('mytable')
YamlDb::Load.load_table('mytable', { 'columns' => [ 'a', 'b' ], 'records' => [[1, 2], [3, 4]] })
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]] })
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
it "should call reset pk sequence if the connection adapter is postgres" do
module ActiveRecord; module ConnectionAdapters; class PostgreSQLAdapter; end; end; end;
ActiveRecord::Base.connection.stub!(:kind_of?).with(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter).and_return(true)
ActiveRecord::Base.connection.should_receive(:reset_pk_sequence!).with('mytable')
YamlDb::Load.reset_pk_sequence!('mytable')
end
it "should not call reset_pk_sequence if the connection adapter is not postgres" do
module ActiveRecord; module ConnectionAdapters; class PostgreSQLAdapter; end; end; end;
ActiveRecord::Base.connection.stub!(:kind_of?).with(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter).and_return(false)
ActiveRecord::Base.connection.should_not_receive(:reset_pk_sequence!)
YamlDb::Load.reset_pk_sequence!('mytable')
end
end