git_repository_test.rb revision f458e516c452c779efc7fc8949edfc2092d3fb82
f79d43bbe70a01454049b77d6f15f6369744959eStéphane Graberrequire 'test_helper'
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano# Tests a git repository
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano#
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano# Author: Eugen Kuksa <eugenk@informatik.uni-bremen.de>
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcanoclass GitRepositoryTest < ActiveSupport::TestCase
9afe19d634946d50eab30e3b90cb5cebcde39eeaDaniel Lezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano context 'creating and deleting a repository' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano setup do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @path = '/tmp/ontohub/test/unit/git/repository'
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'create repository' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @path_new = "#{@path}_new"
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert !File.exists?(@path_new)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @repository_new = GitRepository.new(@path_new)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert File.exists?(@path_new)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert @repository_new.empty?
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
250b1eec71b074acdff1c5f6b5a1f0d7d2c20b77Stéphane Graber should 'delete repository' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @path_new = "#{@path}_new"
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @repository_new = GitRepository.new(@path_new)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert File.exists?(@path_new)
7f95145833bb24f54e037f73ecc37444d6635697Dwight Engen @repository_new.destroy
99e4008cad9e959b683c6f48411fcf15a92be3b5Michel Normand assert !File.exists?(@path_new)
99e4008cad9e959b683c6f48411fcf15a92be3b5Michel Normand end
99e4008cad9e959b683c6f48411fcf15a92be3b5Michel Normand end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano context 'existing repository' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano setup do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @path = '/tmp/ontohub/test/unit/git/repository'
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @repository = GitRepository.new(@path)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @userinfo = {
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano email: 'jan@jansson.com',
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano name: 'Jan Jansson',
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano time: Time.now
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano }
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
d5cf438682963ac84c3617941032ba623d4ac9b2Michel Normand teardown do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano FileUtils.rmtree(@path) if File.exists?(@path)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @path = nil
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @repository = nil
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano context 'using files' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano setup do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @filepath = 'path/file.txt'
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @content = 'Some content'
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @message = 'Some commit message'
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'create single commit of a file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @repository.commit_file(@userinfo, @content, @filepath, @message)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert @repository.path_exists?(@filepath)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_file(@filepath)[:name], @filepath.split('/')[-1]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_file(@filepath)[:content], @content
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_file('path/file.txt')[:mime_type], Mime::Type.lookup('text/plain')
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano assert_equal @repository.commit_message, @message
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano assert_equal @repository.commit_author[:name], @userinfo[:name]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.commit_author[:email], @userinfo[:email]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano # removed because of time zone issues
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano #assert_equal Time.at(@repository.commit_author[:time]), Time.gm(@userinfo[:time])
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'delete a file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @repository.commit_file(@userinfo, @content, @filepath, @message)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @repository.delete_file(@userinfo, @filepath)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert !@repository.path_exists?(@filepath)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'overwrite a file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano content2 = "#{@content}_2"
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano message2 = "#{@message}_2"
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano @repository.commit_file(@userinfo, @content, @filepath, @message)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano first_commit_oid = @repository.head_oid
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @repository.commit_file(@userinfo, content2, @filepath, message2)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert @repository.path_exists?(@filepath)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_file(@filepath)[:content], content2
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.commit_message(@repository.head_oid), message2
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_not_equal first_commit_oid, @repository.head_oid
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'reset state on empty repository with failing commit block' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert @repository.empty?
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_raise Exception do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @repository.commit_file(@userinfo, @content, @filepath, @message) do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano raise Exception
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano # it is actually empty, but in this test this can't be found out
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano #assert @repository.empty?
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano should 'reset state with failing commit block' do
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano first_commit_oid = @repository.commit_file(@userinfo, @content, @filepath, @message)
bb787bc51f0a272f6574fe359f0749302e67c550Matthias Brugger assert_equal first_commit_oid, @repository.head_oid
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_raise Exception do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano second_commit_oid = @repository.commit_file(@userinfo, "#{@content}!", @filepath, @message) do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano raise Exception
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano # it is actually equal, but in this test this can't be found out
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano #assert_equal first_commit_oid, @repository.head_oid
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi context 'using folders' do
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi setup do
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi @subfolder = 'path'
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @filepath1 = "#{@subfolder}/file1.txt"
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi @filepath2 = "#{@subfolder}/file2.txt"
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi @filepath3 = 'file3.txt'
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi @content = 'Some content'
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi @message1 = 'Some commit message1'
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi @message2 = 'Some commit message2'
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi @message3 = 'Some commit message3'
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi @commit_add1 = @repository.commit_file(@userinfo, @content, @filepath1, @message1)
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi @commit_add2 = @repository.commit_file(@userinfo, @content, @filepath2, @message2)
0478642a4349846ab8e76e318909886e795df92dFilippo Giunchedi @commit_add3 = @repository.commit_file(@userinfo, @content, @filepath3, @message3)
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano @commit_del1 = @repository.delete_file(@userinfo, @filepath1)
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano @commit_del2 = @repository.delete_file(@userinfo, @filepath2)
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano @commit_del3 = @repository.delete_file(@userinfo, @filepath3)
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano end
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano should 'read the right number of contents in the root folder after adding the first file' do
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano assert_equal @repository.folder_contents(@commit_add1).size, 1
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano end
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano
ac30d6a43245e0c50aad9e2ebfb88d80aaeea691Filippo Giunchedi should 'read the right contents in the root folder after adding the first file' do
ac30d6a43245e0c50aad9e2ebfb88d80aaeea691Filippo Giunchedi assert_equal @repository.folder_contents(@commit_add1), [{
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano type: :dir,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano name: @subfolder,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano path: @subfolder
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano }]
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano should 'read the right number of contents in the subfolder after adding the first file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_add1, @subfolder).size, 1
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano end
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano should 'read the right contents in the subfolder after adding the first file' do
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano assert_equal @repository.folder_contents(@commit_add1, @subfolder), [{
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano type: :file,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano name: @filepath1.split('/')[-1],
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano path: @filepath1
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano }]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right number of contents in the root folder after adding the second file' do
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano assert_equal @repository.folder_contents(@commit_add2).size, 1
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano end
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano should 'read the right contents in the root folder after adding the second file' do
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano assert_equal @repository.folder_contents(@commit_add2), [{
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano type: :dir,
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano name: @subfolder,
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano path: @subfolder
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano }]
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano end
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano should 'read the right number of contents in the subfolder after adding the second file' do
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano assert_equal @repository.folder_contents(@commit_add2, @subfolder).size, 2
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano end
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano
0d9f8e188c1c4832e4f6b9de646478947ae86877Daniel Lezcano should 'read the right contents in the subfolder after adding the second file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_add2, @subfolder), [{
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano type: :file,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano name: @filepath1.split('/')[-1],
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano path: @filepath1
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano },{
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand type: :file,
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand name: @filepath2.split('/')[-1],
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand path: @filepath2
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand }]
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand end
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right number of contents in the root folder after adding the third file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_add3).size, 2
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right contents in the root folder after adding the third file' do
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano assert_equal @repository.folder_contents(@commit_add3), [{
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano type: :dir,
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano name: @subfolder,
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano path: @subfolder
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano },{
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano type: :file,
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano name: @filepath3.split('/')[-1],
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano path: @filepath3
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano }]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right number of contents in the subfolder after adding the third file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_add3, @subfolder).size, 2
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right contents in the subfolder after adding the third file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_add3, @subfolder), [{
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano type: :file,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano name: @filepath1.split('/')[-1],
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano path: @filepath1
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano },{
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano type: :file,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano name: @filepath2.split('/')[-1],
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano path: @filepath2
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano }]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right number of contents in the root folder after deleting the first file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_del1).size, 2
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right contents in the root folder after deleting the first file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_del1), [{
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano type: :dir,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano name: @subfolder,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano path: @subfolder
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano },{
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano type: :file,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano name: @filepath3.split('/')[-1],
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano path: @filepath3
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano }]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right number of contents in the subfolder after deleting the first file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_del1, @subfolder).size, 1
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right contents in the subfolder after deleting the first file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_del1, @subfolder), [{
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano type: :file,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano name: @filepath2.split('/')[-1],
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano path: @filepath2
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano }]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f79d43bbe70a01454049b77d6f15f6369744959eStéphane Graber
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right number of contents in the root folder after deleting the second file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_del2).size, 1
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
c159cb963868d4646cf415abb064d8fd4b6ee848Daniel Lezcano
c159cb963868d4646cf415abb064d8fd4b6ee848Daniel Lezcano should 'read the right contents in the root folder after deleting the second file' do
c159cb963868d4646cf415abb064d8fd4b6ee848Daniel Lezcano assert_equal @repository.folder_contents(@commit_del2), [{
c159cb963868d4646cf415abb064d8fd4b6ee848Daniel Lezcano type: :file,
c159cb963868d4646cf415abb064d8fd4b6ee848Daniel Lezcano name: @filepath3.split('/')[-1],
f79d43bbe70a01454049b77d6f15f6369744959eStéphane Graber path: @filepath3
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano }]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'read the right number of contents in the root folder after deleting the third file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.folder_contents(@commit_del3).size, 0
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano should 'read the right contents in the root folder after deleting the third file' do
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano assert_equal @repository.folder_contents(@commit_del3), []
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano context 'getting the history of a file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano setup do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @filepath = 'path/to/file.txt'
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_add1 = @repository.commit_file(@userinfo, 'Some content1', @filepath, 'Add')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_change1 = @repository.commit_file(@userinfo, 'Some other content1', @filepath, 'Change')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_other1 = @repository.commit_file(@userinfo, 'Other content1', 'file2.txt', 'Other File: Add')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_delete1 = @repository.delete_file(@userinfo, @filepath)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_other2 = @repository.commit_file(@userinfo, 'Other content2', 'file2.txt', 'Other File: Change1')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_other3 = @repository.commit_file(@userinfo, 'Other content3', 'file2.txt', 'Other File: Change2')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_add2 = @repository.commit_file(@userinfo, 'Some content2', @filepath, 'Re-Add')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_change2 = @repository.commit_file(@userinfo, 'Some other content2', @filepath, 'Re-Change')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_delete2 = @repository.delete_file(@userinfo, @filepath)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the correct values in the history at the HEAD' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.entry_info_list(@filepath), [
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_delete2,
aa8d013ec5b09cd1cd904173d6234ef126eb2126Peter Simons @commit_change2,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_add2,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_delete1,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_change1,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_add1
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the correct values in the history a commit before the HEAD' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.entry_info_list(@filepath, @commit_change2), [
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_change2,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_add2,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_delete1,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_change1,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_add1
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the correct values in the history in the commit that changes another file' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.entry_info_list(@filepath, @commit_other3), [
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_delete1,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_change1,
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit_add1
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano ]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
aa8d013ec5b09cd1cd904173d6234ef126eb2126Peter Simons end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano context 'getting the list of changed files' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano setup do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @content1 = "Some\ncontent\nwith\nmany\nlines."
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @content2 = "Some\ncontent,\nwith\nmany\nlines."
f79d43bbe70a01454049b77d6f15f6369744959eStéphane Graber @filepath = 'path/to/file.xml'
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @file_extension = @filepath.split('.')[-1]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit1 = @repository.commit_file(@userinfo, @content1, @filepath, 'Message1')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit2 = @repository.commit_file(@userinfo, @content2, @filepath, 'Message2')
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano @commit3 = @repository.delete_file(@userinfo, @filepath)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'last commit be HEAD' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.is_head?(@commit3), true
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand end
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right file count when using the first commit' do
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand assert_equal @repository.get_changed_files(@commit1).size, 1
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand end
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right name in the list when using the first commit' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files(@commit1).first[:name], 'file.xml'
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the right path in the list when using the first commit' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files(@commit1).first[:path], @filepath
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the right type in the list when using the first commit' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files(@commit1).first[:type], :add
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right mime type in the list when using the first commit' do
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand assert_equal @repository.get_changed_files(@commit1).first[:mime_type], Mime::Type.lookup_by_extension(@file_extension)
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand end
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right mime category in the list when using the first commit' do
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand assert_equal @repository.get_changed_files(@commit1).first[:mime_category], 'application'
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand end
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right editable in the list when using the first commit' do
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand assert_equal @repository.get_changed_files(@commit1).first[:editable], true
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right file count when using a commit in the middle' do
6a22713f648be8bd21297f57d9b631eb4c537ffeDaniel Lezcano assert_equal @repository.get_changed_files(@commit2).size, 1
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand end
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right name in the list when using a commit in the middle' do
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand assert_equal @repository.get_changed_files(@commit2).first[:name], @filepath.split('/')[-1]
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand end
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right path in the list when using a commit in the middle' do
f79d43bbe70a01454049b77d6f15f6369744959eStéphane Graber assert_equal @repository.get_changed_files(@commit2).first[:path], @filepath
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right type in the list when using a commit in the middle' do
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand assert_equal @repository.get_changed_files(@commit2).first[:type], :change
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right mime type in the list when using a commit in the middle' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files(@commit2).first[:mime_type], Mime::Type.lookup_by_extension(@file_extension)
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the right mime category in the list when using a commit in the middle' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files(@commit2).first[:mime_category], 'application'
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand end
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right editable in the list when using a commit in the middle' do
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand assert_equal @repository.get_changed_files(@commit2).first[:editable], true
36b33520f67cd1a83be8031fccc3c2d7d7255e06Stéphane Graber end
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the right file count when using the HEAD' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files.size, 1
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right name in the list when using the HEAD' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files.first[:name], @filepath.split('/')[-1]
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the right path in the list when using the HEAD' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files.first[:path], @filepath
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand should 'have the right type in the list when using the HEAD' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files.first[:type], :delete
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the right mime type in the list when using the HEAD' do
a941cc0bf6c215079f56d68930370dcd8c6002afMichel Normand assert_equal @repository.get_changed_files.first[:mime_type], Mime::Type.lookup_by_extension(@file_extension)
b6d441f289eb03a1a6fe0662a14c26ecc852be21dlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the right mime category in the list when using the HEAD' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files.first[:mime_category], 'application'
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano should 'have the right editable in the list when using the HEAD' do
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano assert_equal @repository.get_changed_files.first[:editable], true
f1d8791c17f7e0f131de20d7bbc8836b992bd4dbdlezcano end
b0a33c1eb65d2c87e886c740a0dadd8ad5f8d87ddlezcano end
b0a33c1eb65d2c87e886c740a0dadd8ad5f8d87ddlezcano end
b0a33c1eb65d2c87e886c740a0dadd8ad5f8d87ddlezcanoend
b0a33c1eb65d2c87e886c740a0dadd8ad5f8d87ddlezcano