gitdocs 0.5.0.pre6 → 0.5.0.pre7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/.gitignore +1 -0
- data/.haml-lint.yml +3 -0
- data/.jslint.yml +84 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG +11 -0
- data/README.md +6 -2
- data/Rakefile +22 -3
- data/gitdocs.gemspec +36 -29
- data/lib/gitdocs.rb +5 -2
- data/lib/gitdocs/cli.rb +31 -8
- data/lib/gitdocs/configuration.rb +95 -49
- data/lib/gitdocs/manager.rb +36 -28
- data/lib/gitdocs/migration/001_create_shares.rb +2 -0
- data/lib/gitdocs/migration/002_add_remote_branch.rb +2 -0
- data/lib/gitdocs/migration/003_create_configs.rb +2 -0
- data/lib/gitdocs/migration/004_add_index_for_path.rb +4 -0
- data/lib/gitdocs/migration/005_add_start_web_frontend.rb +2 -0
- data/lib/gitdocs/migration/006_add_web_port_to_config.rb +2 -0
- data/lib/gitdocs/migration/007_add_sync_type.rb +11 -0
- data/lib/gitdocs/notifier.rb +89 -6
- data/lib/gitdocs/public/img/file.png +0 -0
- data/lib/gitdocs/public/img/folder.png +0 -0
- data/lib/gitdocs/public/js/app.js +26 -11
- data/lib/gitdocs/public/js/edit.js +3 -3
- data/lib/gitdocs/public/js/settings.js +8 -5
- data/lib/gitdocs/public/js/util.js +21 -20
- data/lib/gitdocs/rendering.rb +14 -9
- data/lib/gitdocs/repository.rb +180 -216
- data/lib/gitdocs/repository/path.rb +166 -0
- data/lib/gitdocs/runner.rb +22 -65
- data/lib/gitdocs/search.rb +35 -0
- data/lib/gitdocs/server.rb +123 -86
- data/lib/gitdocs/version.rb +1 -1
- data/lib/gitdocs/views/_header.haml +6 -6
- data/lib/gitdocs/views/app.haml +17 -17
- data/lib/gitdocs/views/dir.haml +10 -10
- data/lib/gitdocs/views/edit.haml +8 -9
- data/lib/gitdocs/views/file.haml +1 -1
- data/lib/gitdocs/views/home.haml +4 -4
- data/lib/gitdocs/views/revisions.haml +6 -6
- data/lib/gitdocs/views/search.haml +6 -6
- data/lib/gitdocs/views/settings.haml +23 -16
- data/test/.rubocop.yml +13 -0
- data/test/integration/browse_test.rb +149 -0
- data/test/integration/full_sync_test.rb +3 -11
- data/test/integration/share_management_test.rb +59 -10
- data/test/integration/status_test.rb +2 -0
- data/test/integration/test_helper.rb +40 -7
- data/test/unit/configuration_test.rb +82 -0
- data/test/unit/notifier_test.rb +165 -0
- data/test/unit/repository_path_test.rb +368 -0
- data/test/{repository_test.rb → unit/repository_test.rb} +426 -245
- data/test/unit/runner_test.rb +122 -0
- data/test/unit/search_test.rb +52 -0
- data/test/{test_helper.rb → unit/test_helper.rb} +5 -0
- metadata +138 -41
- data/lib/gitdocs/docfile.rb +0 -23
- data/test/configuration_test.rb +0 -41
- data/test/notifier_test.rb +0 -68
- data/test/runner_test.rb +0 -123
data/lib/gitdocs/docfile.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module Gitdocs
|
2
|
-
class Docfile
|
3
|
-
attr_accessor :parent
|
4
|
-
attr_reader :path, :name
|
5
|
-
|
6
|
-
def initialize(path)
|
7
|
-
@path = path
|
8
|
-
@parent = File.dirname(path)
|
9
|
-
@name = File.basename(path)
|
10
|
-
end
|
11
|
-
|
12
|
-
# within?("parent", "/root/path") => "/root/path/parent"
|
13
|
-
def within?(dir, root)
|
14
|
-
expanded_root = File.expand_path(dir, root)
|
15
|
-
File.expand_path(@parent, root) == expanded_root ||
|
16
|
-
File.expand_path(@path, root).include?(expanded_root)
|
17
|
-
end
|
18
|
-
|
19
|
-
def dir?
|
20
|
-
File.directory?(@path)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/test/configuration_test.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
|
3
|
-
|
4
|
-
describe 'gitdocs configuration' do
|
5
|
-
before do
|
6
|
-
ENV['TEST'] = 'true'
|
7
|
-
ShellTools.capture { @config = Gitdocs::Configuration.new('/tmp/gitdocs') }
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'has sensible default config root' do
|
11
|
-
assert_equal '/tmp/gitdocs', @config.config_root
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'can retrieve empty shares' do
|
15
|
-
assert_equal [], @config.shares
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'can have a path added' do
|
19
|
-
@config.add_path('/my/../my/path') # normalized test
|
20
|
-
assert_equal '/my/path', @config.shares.first.path
|
21
|
-
assert_equal 15.0, @config.shares.first.polling_interval
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'can have a path removed' do
|
25
|
-
@config.add_path('/my/path')
|
26
|
-
@config.add_path('/my/path/2')
|
27
|
-
@config.remove_path('/my/../my/path/2') # normalized test
|
28
|
-
assert_equal ['/my/path'], @config.shares.map(&:path)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'can clear paths' do
|
32
|
-
@config.add_path('/my/path')
|
33
|
-
@config.add_path('/my/path/2')
|
34
|
-
@config.clear
|
35
|
-
assert_equal [], @config.shares.map(&:path)
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'can normalize paths' do
|
39
|
-
assert_equal File.expand_path('../test_helper.rb', Dir.pwd), @config.normalize_path('../test_helper.rb')
|
40
|
-
end
|
41
|
-
end
|
data/test/notifier_test.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
require File.expand_path('../test_helper', __FILE__)
|
3
|
-
|
4
|
-
describe Gitdocs::Notifier do
|
5
|
-
let(:notifier) { Gitdocs::Notifier.new(show_notifications) }
|
6
|
-
|
7
|
-
describe '#info' do
|
8
|
-
subject { notifier.info('title', 'message') }
|
9
|
-
|
10
|
-
describe 'without notifications' do
|
11
|
-
let(:show_notifications) { false }
|
12
|
-
before { notifier.expects(:puts).with('title: message') }
|
13
|
-
it { subject }
|
14
|
-
end
|
15
|
-
|
16
|
-
describe 'with notifications' do
|
17
|
-
let(:show_notifications) { true }
|
18
|
-
before do
|
19
|
-
Guard::Notifier.expects(:turn_on)
|
20
|
-
Guard::Notifier.expects(:notify)
|
21
|
-
.with(
|
22
|
-
'message',
|
23
|
-
title: 'title',
|
24
|
-
image: File.expand_path('../../lib/img/icon.png', __FILE__)
|
25
|
-
)
|
26
|
-
end
|
27
|
-
it { subject }
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe '#warn' do
|
32
|
-
subject { notifier.warn('title', 'message') }
|
33
|
-
|
34
|
-
describe 'without notifications' do
|
35
|
-
let(:show_notifications) { false }
|
36
|
-
before { Kernel.expects(:warn).with('title: message') }
|
37
|
-
it { subject }
|
38
|
-
end
|
39
|
-
|
40
|
-
describe 'with notifications' do
|
41
|
-
let(:show_notifications) { true }
|
42
|
-
before do
|
43
|
-
Guard::Notifier.expects(:turn_on)
|
44
|
-
Guard::Notifier.expects(:notify).with('message', title: 'title',)
|
45
|
-
end
|
46
|
-
it { subject }
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe '#error' do
|
51
|
-
subject { notifier.error('title', 'message') }
|
52
|
-
|
53
|
-
describe 'without notifications' do
|
54
|
-
let(:show_notifications) { false }
|
55
|
-
before { Kernel.expects(:warn).with('title: message') }
|
56
|
-
it { subject }
|
57
|
-
end
|
58
|
-
|
59
|
-
describe 'with notifications' do
|
60
|
-
let(:show_notifications) { true }
|
61
|
-
before do
|
62
|
-
Guard::Notifier.expects(:turn_on)
|
63
|
-
Guard::Notifier.expects(:notify).with('message', title: 'title', image: :failure)
|
64
|
-
end
|
65
|
-
it { subject }
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
data/test/runner_test.rb
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
|
3
|
-
describe 'gitdocs runner' do
|
4
|
-
let(:runner) { Gitdocs::Runner.new(share)}
|
5
|
-
|
6
|
-
let(:share) { stub(polling_interval: 1, notification: true) }
|
7
|
-
let(:notifier) { stub }
|
8
|
-
let(:repository) { stub(root: 'root_path') }
|
9
|
-
before do
|
10
|
-
Gitdocs::Notifier.stubs(:new).with(true).returns(notifier)
|
11
|
-
Gitdocs::Repository.stubs(:new).with(share).returns(repository)
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '#root' do
|
15
|
-
subject { runner.root }
|
16
|
-
it { subject.must_equal 'root_path' }
|
17
|
-
end
|
18
|
-
|
19
|
-
describe '#sync_changes' do
|
20
|
-
subject { runner.sync_changes }
|
21
|
-
|
22
|
-
before { repository.expects(:pull).returns(pull_result) }
|
23
|
-
|
24
|
-
describe 'when invalid' do
|
25
|
-
let(:pull_result) { nil }
|
26
|
-
it { subject.must_equal nil }
|
27
|
-
end
|
28
|
-
|
29
|
-
describe 'when no remote present' do
|
30
|
-
let(:pull_result) { :no_remote }
|
31
|
-
it { subject.must_equal nil }
|
32
|
-
end
|
33
|
-
|
34
|
-
describe 'when merge is conflicted' do
|
35
|
-
let(:pull_result) { ['file'] }
|
36
|
-
before do
|
37
|
-
notifier.expects(:warn).with(
|
38
|
-
'There were some conflicts',
|
39
|
-
"* file"
|
40
|
-
)
|
41
|
-
runner.expects(:push_changes)
|
42
|
-
end
|
43
|
-
it { subject.must_equal nil }
|
44
|
-
end
|
45
|
-
|
46
|
-
describe 'when merge is ok' do
|
47
|
-
let(:pull_result) { :ok }
|
48
|
-
before do
|
49
|
-
runner.instance_variable_set(:@last_synced_revision, :oid)
|
50
|
-
repository.stubs(:current_oid).returns(:next_oid)
|
51
|
-
repository.stubs(:author_count).with(:oid).returns('Alice' => 1, 'Bob' => 2)
|
52
|
-
notifier.expects(:info).with(
|
53
|
-
'Updated with 3 changes',
|
54
|
-
"In 'root_path':\n* Alice (1 change)\n* Bob (2 changes)"
|
55
|
-
)
|
56
|
-
runner.expects(:push_changes)
|
57
|
-
end
|
58
|
-
it { subject.must_equal nil }
|
59
|
-
it { subject ; runner.instance_variable_get(:@last_synced_revision).must_equal :next_oid }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe '#push_changes' do
|
64
|
-
subject { runner.push_changes }
|
65
|
-
|
66
|
-
before do
|
67
|
-
repository.expects(:commit)
|
68
|
-
.with('Auto-commit from gitdocs')
|
69
|
-
.returns(push_result)
|
70
|
-
repository.expects(:push)
|
71
|
-
.returns(push_result)
|
72
|
-
end
|
73
|
-
|
74
|
-
describe 'when invalid' do
|
75
|
-
let(:push_result) { nil }
|
76
|
-
it { subject.must_equal nil }
|
77
|
-
end
|
78
|
-
|
79
|
-
describe 'when no remote present' do
|
80
|
-
let(:push_result) { :no_remote }
|
81
|
-
it { subject.must_equal nil }
|
82
|
-
end
|
83
|
-
|
84
|
-
describe 'when nothing happened' do
|
85
|
-
let(:push_result) { :nothing }
|
86
|
-
it { subject.must_equal nil }
|
87
|
-
end
|
88
|
-
|
89
|
-
describe 'when there is an error' do
|
90
|
-
let(:push_result) { 'error' }
|
91
|
-
before do
|
92
|
-
notifier.expects(:error)
|
93
|
-
.with('BAD Could not push changes in root_path', 'error')
|
94
|
-
end
|
95
|
-
it { subject.must_equal nil }
|
96
|
-
end
|
97
|
-
|
98
|
-
describe 'when push is conflicted' do
|
99
|
-
let(:push_result) { :conflict }
|
100
|
-
before do
|
101
|
-
notifier.expects(:warn)
|
102
|
-
.with('There was a conflict in root_path, retrying', '')
|
103
|
-
end
|
104
|
-
it { subject.must_equal nil }
|
105
|
-
end
|
106
|
-
|
107
|
-
describe 'when push is ok' do
|
108
|
-
let(:push_result) { :ok }
|
109
|
-
before do
|
110
|
-
runner.instance_variable_set(:@last_synced_revision, :oid)
|
111
|
-
repository.stubs(:current_oid)
|
112
|
-
.returns(:next_oid)
|
113
|
-
repository.stubs(:author_count)
|
114
|
-
.with(:oid)
|
115
|
-
.returns('Alice' => 1, 'Bob' => 2)
|
116
|
-
notifier.expects(:info)
|
117
|
-
.with('Pushed 3 changes', "'root_path' has been pushed")
|
118
|
-
end
|
119
|
-
it { subject.must_equal nil }
|
120
|
-
it { subject ; runner.instance_variable_get(:@last_synced_revision).must_equal :next_oid }
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|