require File.dirname(__FILE__) + '/../test_helper' class RepositoryTest < ActiveSupport::TestCase fixtures :repositories, :changes, :changesets def setup RetroCM.reload end def test_crud rep1 = Repository::Subversion.new(:name => 'Some Repos', :path => '/home/svn') assert(rep1.save) rep2 = Repository::Subversion.find(rep1.id) assert_equal(rep1.name, rep2.name) rep2.name = 'New name' assert(rep2.save) assert_not_equal(rep1.name, rep2.name) rep1.reload assert_equal(rep1.name, rep2.name) assert(rep1.destroy) end def test_presence_validations rep = Repository::Subversion.new assert(!rep.save) assert_not_nil(rep.errors[:name]) assert_not_nil(rep.errors[:path]) assert_equal(2, rep.errors.size) end def test_uniqueness_validations rep1 = repositories(:public) rep2 = Repository::Subversion.new(:name => rep1.name.dup, :path => rep1.path.dup) assert(!rep2.save) assert_not_nil(rep2.errors[:name]) assert_not_nil(rep2.errors[:path]) assert_equal(2, rep2.errors.size) end def test_repository_synchronization return unless check_repository_testable repos = repositories(:public) repos.changesets.destroy(333) # Drop the invalid one changesets = repos.changesets.dup repos.changesets.destroy_all assert_equal(0, repos.changesets.count) repos.sync_changesets assert_equal(changesets.size, repos.changesets.count) changesets.each do |cs| ref = repos.changesets.find_by_revision(cs.revision) assert_not_equal(cs.id, ref.id) assert_equal(cs.log, ref.log) assert_equal(cs.author, ref.author) assert_equal(cs.changes.collect(&:path).sort, ref.changes.collect(&:path).sort) end end def test_latest_revision return unless check_repository_testable repos = repositories(:public) assert_equal(`svnlook youngest #{repos.path}`.chomp.to_i, # Should not use to_i? repos.latest_revision) end def test_unified_diff return unless check_repository_testable repos = repositories(:public) path = "retrospectiva/script/weird.rb" assert_equal(<<-EOD, repos.unified_diff(path, "3", "4")) --- Revision 3 +++ Revision 4 @@ -1,2 +1,10 @@ -# Do somethiing weird -# ... \\ No newline at end of file +###################### +# Changes: +# +# - fixed typo +# +#################### +# +# Do something weird +# ... +# \\ No newline at end of file EOD invalid_version = "100000" assert_equal("", repos.unified_diff(path, "4", invalid_version)) binary_file = "retrospectiva/public/images/rss.png" assert_equal("", repos.unified_diff(binary_file, "8", "9")) nonexistence_file = "nonexistence" assert_equal("", repos.unified_diff(nonexistence_file, "1", "2")) end def test_history return unless check_repository_testable repos = repositories(:public) path = "retrospectiva/config/environment.rb" assert_equal([4, 3], repos.history(path)) # Should be ["4", "3"]? assert_equal([4, 3], repos.history(path, "4")) # Should be ["4", "3"]? assert_equal([3], repos.history(path, "3")) # Should be ["3"]? assert_equal([3], repos.history(path, 3)) # Should be ["3"]? assert_equal([], repos.history(path, "2")) # Should raise? end end