From a4f650b760e6eb1f9023a3626eb6766e65d31bbf Mon Sep 17 00:00:00 2001 From: Tomasz Gieniusz Date: Fri, 19 Oct 2012 20:27:41 +0200 Subject: [PATCH] testing file content gathering --- lib/git_stats/git_data/commit.rb | 2 +- lib/git_stats/git_data/repo.rb | 2 +- spec/integration/activity_spec.rb | 2 +- spec/integration/author_spec.rb | 4 ++-- spec/integration/file_spec.rb | 30 ++++++++++++++++++++++++++++++ spec/integration/repo_spec.rb | 6 +++--- spec/integration/test_repo | 2 +- 7 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 spec/integration/file_spec.rb diff --git a/lib/git_stats/git_data/commit.rb b/lib/git_stats/git_data/commit.rb index 5bcc5b292..1641113b0 100644 --- a/lib/git_stats/git_data/commit.rb +++ b/lib/git_stats/git_data/commit.rb @@ -10,7 +10,7 @@ module GitStats def files @files ||= repo.run_and_parse("git ls-tree -r #{self.hash}").map do |file| Blob.new(repo: repo, filename: file[:filename], hash: file[:hash]) - end + end.extend(ByFieldFinder) end def files_by_extension diff --git a/lib/git_stats/git_data/repo.rb b/lib/git_stats/git_data/repo.rb index e8e3a8562..049df3084 100644 --- a/lib/git_stats/git_data/repo.rb +++ b/lib/git_stats/git_data/repo.rb @@ -27,7 +27,7 @@ module GitStats date = DateTime.parse(date) Commit.new(repo: self, hash: hash, stamp: stamp, date: date, author: author) - end.sort_by! { |e| e.date } + end.sort_by! { |e| e.date }.extend(ByFieldFinder) end def last_commit diff --git a/spec/integration/activity_spec.rb b/spec/integration/activity_spec.rb index 6c5b0488f..5af77d778 100644 --- a/spec/integration/activity_spec.rb +++ b/spec/integration/activity_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe GitStats::GitData::Activity do - let(:repo) { build(:test_repo, last_commit_hash: '45677ee') } + let(:repo) { build(:test_repo, last_commit_hash: '872955c') } let(:activity) { repo.activity } it 'should count commits by hour' do diff --git a/spec/integration/author_spec.rb b/spec/integration/author_spec.rb index 7f4789870..e33070c66 100644 --- a/spec/integration/author_spec.rb +++ b/spec/integration/author_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' describe GitStats::GitData::Activity do - let(:repo) { build(:test_repo, last_commit_hash: '45677ee') } + let(:repo) { build(:test_repo, last_commit_hash: '872955c') } let(:tg) { repo.authors.by_email('tomasz.gieniusz@gmail.com') } let(:jd) { repo.authors.by_email('john.doe@gmail.com') } it 'should filter commits to author' do - tg.commits.map(&:hash).should =~ %w(b3b4f81 d60b5ec ab47ef8 2c11f5e c87ecf9 b621a5d 4e7d0e9 45677ee) + tg.commits.map(&:hash).should =~ %w(b3b4f81 d60b5ec ab47ef8 2c11f5e c87ecf9 b621a5d 4e7d0e9 872955c) jd.commits.map(&:hash).should =~ %w(fd66657 81e8bef) end diff --git a/spec/integration/file_spec.rb b/spec/integration/file_spec.rb new file mode 100644 index 000000000..9db6127e5 --- /dev/null +++ b/spec/integration/file_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe GitStats::GitData::Repo do + let(:repo) { build(:test_repo, last_commit_hash: '872955c') } + + it 'should gather all files in repo' do + repo.files.map(&:filename).should =~ %w(long_second.haml long.txt second.txt test2.rb test.rb test.txt) + end + + it 'should retrieve correct file content for old file' do + repo.commits.by_hash('c87ecf9').files.by_filename('test.txt').content.should == "bb + + + +test +" + end + + it 'should retrieve correct file content for the newest file' do + file = repo.files.by_filename('test.txt') + file.content.should == "bb + +testtest + +test +" + end + + +end \ No newline at end of file diff --git a/spec/integration/repo_spec.rb b/spec/integration/repo_spec.rb index 6e2067457..7d2bae606 100644 --- a/spec/integration/repo_spec.rb +++ b/spec/integration/repo_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe GitStats::GitData::Repo do - let(:repo) { build(:test_repo, last_commit_hash: '45677ee') } + let(:repo) { build(:test_repo, last_commit_hash: '872955c') } it 'should gather all authors' do repo.authors.should =~ [ @@ -11,7 +11,7 @@ describe GitStats::GitData::Repo do end it 'should gather all commits sorted by date' do - repo.commits.map(&:hash).should =~ %w(b3b4f81 d60b5ec ab47ef8 2c11f5e c87ecf9 b621a5d fd66657 81e8bef 4e7d0e9 45677ee) + repo.commits.map(&:hash).should =~ %w(b3b4f81 d60b5ec ab47ef8 2c11f5e c87ecf9 b621a5d fd66657 81e8bef 4e7d0e9 872955c) end it 'should return project name from dir' do @@ -19,7 +19,7 @@ describe GitStats::GitData::Repo do end it 'should return project version as last commit hash' do - repo.project_version.should == '45677ee' + repo.project_version.should == '872955c' end it 'should count files in repo' do diff --git a/spec/integration/test_repo b/spec/integration/test_repo index 45677ee1e..872955c3a 160000 --- a/spec/integration/test_repo +++ b/spec/integration/test_repo @@ -1 +1 @@ -Subproject commit 45677ee1ececcf2e8eab452f8af2c7a3e30e65d9 +Subproject commit 872955c3a6a4be4d7ae9b2dd4bea659979f0b457