capistrano-template 0.0.1

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.
Files changed (33) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +22 -0
  5. data/.rubocop_todo.yml +8 -0
  6. data/.travis.yml +4 -0
  7. data/.versions.conf +4 -0
  8. data/CHANGELOG.md +0 -0
  9. data/Gemfile +9 -0
  10. data/LICENSE.txt +22 -0
  11. data/README.md +66 -0
  12. data/Rakefile +16 -0
  13. data/capistrano-template.gemspec +35 -0
  14. data/lib/capistrano/capistrano_plugin_template.rb +5 -0
  15. data/lib/capistrano/template.rb +11 -0
  16. data/lib/capistrano/template/helpers/dsl.rb +61 -0
  17. data/lib/capistrano/template/helpers/paths_lookup.rb +33 -0
  18. data/lib/capistrano/template/helpers/renderer.rb +30 -0
  19. data/lib/capistrano/template/helpers/template_digester.rb +19 -0
  20. data/lib/capistrano/template/helpers/uploader.rb +94 -0
  21. data/lib/capistrano/template/tasks/template_defaults.cap +13 -0
  22. data/lib/capistrano/template/version.rb +5 -0
  23. data/spec/integration/capistrano/template/helpers/dsl_spec.rb +117 -0
  24. data/spec/integration/capistrano/template/helpers/paths_lookup_spec.rb +46 -0
  25. data/spec/integration/capistrano/template/helpers/uploader_spec.rb +100 -0
  26. data/spec/spec_helper.rb +42 -0
  27. data/spec/unit/capistrano/template/helpers/dsl_spec.rb +60 -0
  28. data/spec/unit/capistrano/template/helpers/paths_lookup_spec.rb +54 -0
  29. data/spec/unit/capistrano/template/helpers/renderer_spec.rb +43 -0
  30. data/spec/unit/capistrano/template/helpers/template_digester_spec.rb +36 -0
  31. data/spec/unit/capistrano/template/helpers/uploader_spec.rb +103 -0
  32. data/spec/unit/capistrano/template_spec.rb +7 -0
  33. metadata +186 -0
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ module Capistrano
4
+ module Template
5
+ module Helpers
6
+ describe Renderer do
7
+
8
+ subject do
9
+ Renderer.new(template_name, context, reader: reader)
10
+ end
11
+
12
+ let(:context) { OpenStruct.new(var1: 'my', var2: 'content') }
13
+ let(:template_name) { 'my_template' }
14
+ let(:reader) { double(read: template_content) }
15
+ let(:template_content) { '<%=var1%> -- <%=var2%>' }
16
+
17
+ describe '#as_str' do
18
+
19
+ it 'renders a erb template' do
20
+ expect(subject.as_str).to eq('my -- content')
21
+ end
22
+
23
+ end
24
+
25
+ describe '#as_io' do
26
+ it 'returns a StringIo' do
27
+ expect(subject.as_io).to be_kind_of StringIO
28
+ end
29
+ end
30
+
31
+ describe '.new' do
32
+
33
+ it 'is a delegator' do
34
+ expect(context).to receive(:call_it).with(1, 2, 3)
35
+ subject.call_it(1, 2, 3)
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ module Capistrano
4
+ module Template
5
+ module Helpers
6
+ describe TemplateDigester do
7
+
8
+ subject do
9
+ TemplateDigester.new(renderer, digest_algo)
10
+ end
11
+
12
+ let(:text) { 'my very long text' }
13
+ let(:renderer) { OpenStruct.new(as_str: text) }
14
+ let(:digest_algo) { ->(data) { Digest::MD5.hexdigest(data) } }
15
+
16
+ describe '#digest' do
17
+
18
+ it 'uses digest_algo to create a digest' do
19
+ expect(subject.digest).to eq(digest_algo.call(text))
20
+ end
21
+
22
+ end
23
+
24
+ describe '.new' do
25
+
26
+ it 'is a delegator' do
27
+ expect(renderer).to receive(:call_it).with(1, 2, 3)
28
+ subject.call_it(1, 2, 3)
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,103 @@
1
+ require 'spec_helper'
2
+
3
+ module Capistrano
4
+ module Template
5
+ module Helpers
6
+ describe Uploader do
7
+
8
+ subject do
9
+ Uploader.new(
10
+ remote_filename_expented,
11
+ upload_handler,
12
+ mode: 0640,
13
+ mode_test_cmd: mode_test_cmd,
14
+ digest: digest,
15
+ digest_cmd: digest_cmd,
16
+ io: as_io
17
+ )
18
+ end
19
+
20
+ let(:upload_handler) do
21
+ OpenStruct.new(host: 'localhost').tap do |cont|
22
+ allow(cont).to receive(:info)
23
+ allow(cont).to receive(:error)
24
+ end
25
+
26
+ end
27
+
28
+ let(:rendered_template_content) { 'some text' }
29
+ let(:as_io) { StringIO.new(rendered_template_content) }
30
+ let(:template_name) { 'my_template' }
31
+
32
+ let(:remote_filename_expented) { '/var/www/shared/config/database.yml' }
33
+
34
+ let(:digest) { Digest::MD5.hexdigest(rendered_template_content) }
35
+ let(:digest_cmd) { %Q(echo "%<digest>s %<path>s" | md5sum -c --status) }
36
+ let(:mode_test_cmd) { %Q{ [ "Z$(printf "%%.4o" 0$(stat -c "%%a" %<path>s 2>/dev/null || stat -f "%%A" %<path>s))" != "Z%<mode>s" ] } }
37
+
38
+ describe '#upload_as_file' do
39
+
40
+ it 'uploads changed files' do
41
+ allow(subject).to receive(:file_changed?).and_return true
42
+ expect(upload_handler).to receive(:upload!).with(as_io, remote_filename_expented)
43
+ subject.upload_as_file
44
+ end
45
+
46
+ it 'does not upload unchanged files' do
47
+ allow(subject).to receive(:file_changed?).and_return false
48
+
49
+ expect(upload_handler).not_to receive(:upload!)
50
+
51
+ subject.upload_as_file
52
+ end
53
+
54
+ end
55
+
56
+ describe '#set_mode' do
57
+ it 'sets the mode for the remote file' do
58
+ allow(subject).to receive(:permission_changed?).and_return true
59
+ expect(upload_handler).to receive(:execute).with('chmod', '0640', remote_filename_expented)
60
+ subject.set_mode
61
+ end
62
+
63
+ it 'sets not the mode for the remote file when nothing changed' do
64
+ allow(subject).to receive(:permission_changed?).and_return false
65
+ expect(upload_handler).not_to receive(:execute)
66
+ subject.set_mode
67
+ end
68
+ end
69
+
70
+ describe '#file_changed?' do
71
+ it 'uses the "digest_cmd" to check file changes' do
72
+ expect(subject).to receive(:__check__).with(%Q(echo "#{digest} /var/www/shared/config/database.yml" | md5sum -c --status))
73
+
74
+ subject.file_changed?
75
+ end
76
+
77
+ it 'replaces "<digest>"' do
78
+ subject.digest_cmd = '%<digest>s'
79
+ expect(subject).to receive(:__check__).with(digest)
80
+
81
+ subject.file_changed?
82
+ end
83
+
84
+ it 'replaces "<path>"' do
85
+ subject.digest_cmd = '%<path>s'
86
+ expect(subject).to receive(:__check__).with(remote_filename_expented)
87
+
88
+ subject.file_changed?
89
+ end
90
+ end
91
+
92
+ describe '#permission_changed?' do
93
+ it 'checks the actual file permissions' do
94
+ expect(subject).to receive(:__check__).with(mode_test_cmd % { mode: '0640', path: remote_filename_expented })
95
+
96
+ subject.permission_changed?
97
+ end
98
+ end
99
+
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capistrano::Template do
4
+ it 'should have a version number' do
5
+ Capistrano::Template::VERSION.should_not be_nil
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-template
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dieter Späth
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.99.0.rc1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 2.99.0.rc1
69
+ - !ruby/object:Gem::Dependency
70
+ name: fuubar
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-remote
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: |-
112
+ A capistrano 3 plugin that aids in rendering erb templates and
113
+ uploads the content to the server if the file does not exists at
114
+ the remote host or the content did change
115
+ email:
116
+ - d.spaeth@faber.de
117
+ executables: []
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - ".gitignore"
122
+ - ".rspec"
123
+ - ".rubocop.yml"
124
+ - ".rubocop_todo.yml"
125
+ - ".travis.yml"
126
+ - ".versions.conf"
127
+ - CHANGELOG.md
128
+ - Gemfile
129
+ - LICENSE.txt
130
+ - README.md
131
+ - Rakefile
132
+ - capistrano-template.gemspec
133
+ - lib/capistrano/capistrano_plugin_template.rb
134
+ - lib/capistrano/template.rb
135
+ - lib/capistrano/template/helpers/dsl.rb
136
+ - lib/capistrano/template/helpers/paths_lookup.rb
137
+ - lib/capistrano/template/helpers/renderer.rb
138
+ - lib/capistrano/template/helpers/template_digester.rb
139
+ - lib/capistrano/template/helpers/uploader.rb
140
+ - lib/capistrano/template/tasks/template_defaults.cap
141
+ - lib/capistrano/template/version.rb
142
+ - spec/integration/capistrano/template/helpers/dsl_spec.rb
143
+ - spec/integration/capistrano/template/helpers/paths_lookup_spec.rb
144
+ - spec/integration/capistrano/template/helpers/uploader_spec.rb
145
+ - spec/spec_helper.rb
146
+ - spec/unit/capistrano/template/helpers/dsl_spec.rb
147
+ - spec/unit/capistrano/template/helpers/paths_lookup_spec.rb
148
+ - spec/unit/capistrano/template/helpers/renderer_spec.rb
149
+ - spec/unit/capistrano/template/helpers/template_digester_spec.rb
150
+ - spec/unit/capistrano/template/helpers/uploader_spec.rb
151
+ - spec/unit/capistrano/template_spec.rb
152
+ homepage: ''
153
+ licenses:
154
+ - MIT
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: 2.0.0
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.2.1
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: Erb-Template rendering and upload for capistrano 3
176
+ test_files:
177
+ - spec/integration/capistrano/template/helpers/dsl_spec.rb
178
+ - spec/integration/capistrano/template/helpers/paths_lookup_spec.rb
179
+ - spec/integration/capistrano/template/helpers/uploader_spec.rb
180
+ - spec/spec_helper.rb
181
+ - spec/unit/capistrano/template/helpers/dsl_spec.rb
182
+ - spec/unit/capistrano/template/helpers/paths_lookup_spec.rb
183
+ - spec/unit/capistrano/template/helpers/renderer_spec.rb
184
+ - spec/unit/capistrano/template/helpers/template_digester_spec.rb
185
+ - spec/unit/capistrano/template/helpers/uploader_spec.rb
186
+ - spec/unit/capistrano/template_spec.rb