brief_mail 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.
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Ignore hidden files by default:
2
+ .*
3
+ !.gitignore
4
+
5
+ Gemfile.lock
6
+
7
+ tmp
8
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gemspec:
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Sten Christoffer Eliesen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,152 @@
1
+ # BriefMail
2
+
3
+ BriefMail is a deployment notification mailer designed for Rails 3. The
4
+ deployment mail it sends out contains a short log and diff stat summary from
5
+ the source control management which also includes summaries for each git
6
+ submodule.
7
+
8
+ Currently only git source control management and capistrano deployment tool is
9
+ supported, but an abstraction layer (inspired by ActiveRecord) exists to
10
+ hopefully allow for easy integration with other tools.
11
+
12
+ ## Requirements
13
+
14
+ * Ruby 1.9.2+
15
+ * Rails 3
16
+ * Git
17
+ * Capistrano
18
+
19
+ Also, this gem has only been tested on Linux, so it will probably fail
20
+ miserably on other platforms.
21
+
22
+ ## Installation
23
+
24
+ Add this line to your application's Gemfile. Anywhere will be fine, but it is
25
+ best to put in a non-standard group to prevent it from being loaded into memory
26
+ automatically by Rails:
27
+
28
+ group :deployment do
29
+ gem 'brief_mail'
30
+ end
31
+
32
+ And then execute:
33
+
34
+ $ bundle
35
+
36
+ Or install it yourself as:
37
+
38
+ $ gem install brief_mail
39
+
40
+ ### With Capistrano deployment tool
41
+
42
+ In config/deploy.rb:
43
+
44
+ require 'brief_mail/capistrano'
45
+
46
+ set :brief_mail_config, {
47
+ # BriefMail config options.
48
+ }
49
+
50
+ If using multistage then different config options can be used for different
51
+ stages (obviously).
52
+
53
+ ## Configuration
54
+
55
+ The BriefMail config is a hash with the following options:
56
+
57
+ {
58
+ mailer: {
59
+ # Normal ActionMailer class config, e.g:
60
+ delivery_method: :smtp,
61
+ smtp_settings: {
62
+ address: "smtp.gmail.com",
63
+ port: 587,
64
+ user_name: "username@gmail.com",
65
+ password: "password",
66
+ authentication: :plain,
67
+ },
68
+ },
69
+
70
+ # Or just use sendmail for sending:
71
+ # mailer: {
72
+ # delivery_method: :sendmail,
73
+ # },
74
+
75
+ from: %(your.email@example.com),
76
+ recipients: %w(your.email@example.com another.email@example.com),
77
+ subject: %([DEPLOY] MyApp has been successfully deployed),
78
+ }
79
+
80
+ When using sendmail, `:from` can be omitted to let sendmail handle it.
81
+ `:subject` is not required.
82
+
83
+ Please see http://api.rubyonrails.org/classes/ActionMailer/Base.html for
84
+ ActionMailer config options.
85
+
86
+ When using git, a `git_format` option can be used to control the output of the
87
+ logs:
88
+
89
+ # This is the default:
90
+ git_format: %(* %ad %s%+b)
91
+
92
+ ### Source Control Management
93
+
94
+ The scm type should be automatically picked up via the deployment tool config,
95
+ so no extra configuration necessary. (As of writing this is quite moot since it
96
+ only supports git anyway, but it should be easy to support other scm types in
97
+ the future.)
98
+
99
+ ## Usage
100
+
101
+ When configured properly a mail will be sent out automatically after a
102
+ successful deployment.
103
+
104
+ For checking how the deploy mail will look (without configuring the mailer)
105
+ then the ActionMailer file delivery option can be used:
106
+
107
+ {
108
+ mailer: {
109
+ delivery_method: :file,
110
+ file_settings: {
111
+ location: File.dirname(__FILE__),
112
+ },
113
+
114
+ recipients: %(brief_mail.output),
115
+ }
116
+
117
+ This will write the mail to `brief_mail.output` in the same directory as the
118
+ config file instead of sending it as a mail.
119
+
120
+ ### Capistrano
121
+
122
+ To manually launch a mail (for e.g. testing):
123
+
124
+ cap deploy:send_notification
125
+
126
+ This is highly recommended, because if there is something wrong with the
127
+ configuration (or a bug is triggered) then the entire deployment will be
128
+ aborted and rolled back (by nature of capistrano).
129
+
130
+ ## Contributing
131
+
132
+ 1. Fork it
133
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
134
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
135
+ 4. Push to the branch (`git push origin my-new-feature`)
136
+ 5. Create new Pull Request
137
+
138
+ ## Credits
139
+
140
+ This gem was inspired by the lightweight mailer posted at
141
+ https://gist.github.com/955917, written by rtekie and John Lynch
142
+ (johnthethird), which is a Rails 3 port of the email notifier posted at
143
+ http://www.codeography.com/2010/03/24/simple-capistrano-email-notifier-for-rails.html
144
+ which is written by Christopher Sexton.
145
+
146
+ The AbstractionAdapters are inspired by ActiveRecord.
147
+
148
+ BriefMail is written by S. Christoffer Eliesen (http://github.com/sce).
149
+
150
+ ## License
151
+
152
+ See LICENSE.txt.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "lib"
6
+ t.libs << "test"
7
+ t.test_files = FileList['spec/**/*_test.rb'] + FileList['test/**/*_test.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task default: :test
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'brief_mail/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "brief_mail"
8
+ gem.version = BriefMail::VERSION
9
+ gem.authors = ["S. Christoffer Eliesen"]
10
+ gem.email = ["christoffer@eliesen.no"]
11
+ gem.description = %q{BriefMail sends you and your team mates a deployment summary after deploying with capistrano.}
12
+ gem.summary = %q{BriefMail sends you and your team mates a deployment summary after deploying with capistrano.}
13
+ gem.homepage = "http://github.com/sce/brief_mail"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "actionmailer", "~> 3.0"
21
+ gem.add_dependency "minitest", "~> 4.0"
22
+
23
+ gem.add_development_dependency "rake", "~> 0.9"
24
+ end
@@ -0,0 +1,14 @@
1
+ require 'brief_mail'
2
+
3
+ Capistrano::Configuration.instance.load do
4
+
5
+ namespace :deploy do
6
+ desc "Send email notification"
7
+ task :send_notification do
8
+ BriefMail::Mailer.deploy_notification(self).deliver
9
+ end
10
+ end
11
+
12
+ after :deploy, "deploy:send_notification"
13
+
14
+ end
@@ -0,0 +1,44 @@
1
+ module BriefMail
2
+ module ConfigAdapters
3
+ class AbstractAdapter
4
+
5
+ def initialize(config)
6
+ @config = config
7
+ end
8
+
9
+ %w(
10
+ scm
11
+ application
12
+ stage
13
+ previous_release
14
+ current_release
15
+ previous_revision
16
+ current_revision
17
+ ).each do |name|
18
+ define_method(name) do
19
+ #raise NotImplementedError
20
+ nil
21
+ end
22
+ end
23
+
24
+ # The config hash from the user.
25
+ def from_user
26
+ nil
27
+ end
28
+
29
+ def subject
30
+ @subject ||= (from_user || {})[:subject]
31
+ end
32
+
33
+ def mailer
34
+ @mailer ||= (from_user || {})[:mailer]
35
+ end
36
+
37
+ def recipients
38
+ @recipients ||= (from_user || {})[:recipients]
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+
@@ -0,0 +1,43 @@
1
+ module BriefMail
2
+ module ConfigAdapters
3
+ class Capistrano < AbstractAdapter
4
+
5
+ def initialize(cap_vars)
6
+ @cap_vars = cap_vars
7
+ end
8
+
9
+ def from_user
10
+ @cap_vars.fetch(:brief_mail_config)
11
+ end
12
+
13
+ def scm
14
+ @cap_vars.scm
15
+ end
16
+
17
+ def application
18
+ @cap_vars.application
19
+ end
20
+
21
+ def stage
22
+ @cap_vars.stage
23
+ end
24
+
25
+ def previous_release
26
+ @cap_vars.previous_release
27
+ end
28
+
29
+ def current_release
30
+ @cap_vars.current_release
31
+ end
32
+
33
+ def previous_revision
34
+ @cap_vars.previous_revision
35
+ end
36
+
37
+ def current_revision
38
+ @cap_vars.current_revision
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,16 @@
1
+ require 'brief_mail/config_adapters/abstract_adapter'
2
+ require 'brief_mail/config_adapters/capistrano'
3
+
4
+ module BriefMail
5
+ module ConfigAdapters
6
+
7
+ def self.adapter_for(config)
8
+ if defined? ::Capistrano::Configuration and config.is_a? ::Capistrano::Configuration::Namespaces::Namespace
9
+ Capistrano.new(config)
10
+ else
11
+ raise %(Unknown config adapter class: %s) % config.class
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,42 @@
1
+ require "action_mailer"
2
+
3
+ module BriefMail
4
+
5
+ # Note mail is sent from the machine doing the deployment, not from the remote host.
6
+ class Mailer < ActionMailer::Base
7
+
8
+ def self.load_config(config)
9
+ raise ArgumentError, %(:mailer config is required, and must behave like a Hash) unless config and config.respond_to?(:each_pair)
10
+
11
+ config.each_pair do |k, v|
12
+ assign = "#{k}="
13
+ if Mailer.respond_to?(assign)
14
+ Mailer.send(assign, v)
15
+ else
16
+ raise ArgumentError, %("%s" is an invalid ActionMailer config option) % k
17
+ end
18
+ end
19
+ end
20
+
21
+ def deploy_notification(config)
22
+ @config = ConfigAdapters.adapter_for(config)
23
+ @scm = SCMAdapters.adapter_for(@config.scm, @config)
24
+ Mailer.load_config(@config.mailer)
25
+
26
+ # Add lib directory for this gem to view path:
27
+ view_paths << File.expand_path("../../", __FILE__)
28
+
29
+ recipients = @config.recipients or raise %(One or more recipients are required.)
30
+ subj = @config.subject || %([DEPLOY] %s deployed to %s) % [@config.application, @config.stage]
31
+
32
+ mail( to: recipients, subject: subj ) do |format|
33
+ format.text do
34
+ render "brief_mail/views/deploy_notification.txt"
35
+ end
36
+ end
37
+
38
+ puts %(Sent mail to %s.) % [recipients].join(", ")
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,35 @@
1
+ module BriefMail
2
+ module SCMAdapters
3
+ class AbstractAdapter
4
+
5
+ def initialize(config)
6
+ @config = config
7
+ end
8
+
9
+ # The diff stat for the current repository, as string.
10
+ def diff_stat
11
+ nil
12
+ end
13
+
14
+ # The log for the current repository, as string.
15
+ def log
16
+ nil
17
+ end
18
+
19
+ # The diff stat for any subdirectories not directly contained within
20
+ # diff_stat for the current repository (e.g. git submodules) in the
21
+ # format "{ "sub-directory-name" => "diff_stat" }".
22
+ def subdirs_diff_stat
23
+ {}
24
+ end
25
+
26
+ # The log for any subdirectories not directly contained whithin
27
+ # log for the current repository (e.g. git submodules) in the format
28
+ # "{ "sub-directory-name" => "log" }".
29
+ def subdirs_log
30
+ {}
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,86 @@
1
+ module BriefMail
2
+ module SCMAdapters
3
+ class Git < AbstractAdapter
4
+
5
+ # Compact git format to use for log commands:
6
+ GIT_FORMAT = %(* %ad %s%+b).freeze
7
+
8
+ private
9
+
10
+ def initialize(config)
11
+ @config = config
12
+ end
13
+
14
+ def format
15
+ @config.from_user[:git_format] || GIT_FORMAT
16
+ end
17
+
18
+ # Returns array with name of submodule directories.
19
+ def submodule_dirs
20
+ # Implementation is a little hacky; we run a git command and parse the
21
+ # output.
22
+ cmd = %(git submodule)
23
+ %x(#{cmd}).split(/\n/).map {|line| line.split(" ")[1] }
24
+ end
25
+
26
+ # Returns the SHA-1 given submodule is at in given root repository SHA-1.
27
+ def submodule_sha_at(submodule_name, root_sha)
28
+ # Finding the SHA-1 that each submodule uses for a given commit is a
29
+ # little hacky; we run a git command and parse the output.
30
+ cmd = %(git ls-tree %s %s) % [root_sha, submodule_name]
31
+ %x(#{cmd}).split(" ")[2]
32
+ end
33
+
34
+ # Yield for each submodule previous_revision and current_revision for
35
+ # that submodule, and return as { "dir-name" => "yield output" } hash.
36
+ def submodule_command
37
+ submodule_dirs.inject({}) do |h, subm|
38
+ subm_prev = submodule_sha_at(subm, @config.previous_revision)
39
+ subm_cur = submodule_sha_at(subm, @config.current_revision)
40
+
41
+ Dir.chdir(subm) do
42
+ output = yield(subm_prev, subm_cur)
43
+ if output.strip =~ /.+/
44
+ h[subm] = output
45
+ end
46
+ end
47
+
48
+ h
49
+ end
50
+ end
51
+
52
+ public
53
+
54
+ def diff_stat
55
+ cmd = %(git diff %s.. --stat --color=never) % @config.previous_revision
56
+ %x(#{cmd})
57
+ end
58
+
59
+ def log
60
+ cmd = %(git log %s.. --pretty='%s' --date=short --reverse --color=never) %
61
+ [@config.previous_revision, format]
62
+
63
+ %x(#{cmd})
64
+ end
65
+
66
+ def subdirs_log
67
+ submodule_command do |prev_sha, cur_sha|
68
+ cmd = %(git log %s..%s --pretty='%s' --date=short --reverse --color=never) %
69
+ [prev_sha, cur_sha, format]
70
+
71
+ %x(#{cmd})
72
+ end
73
+ end
74
+
75
+ def subdirs_diff_stat
76
+ submodule_command do |prev_sha, cur_sha|
77
+ cmd = %(git diff %s..%s --stat --color=never) %
78
+ [prev_sha, cur_sha]
79
+
80
+ %x(#{cmd})
81
+ end
82
+ end
83
+
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,17 @@
1
+ require 'brief_mail/scm_adapters/abstract_adapter'
2
+ require 'brief_mail/scm_adapters/git'
3
+
4
+ module BriefMail
5
+ module SCMAdapters
6
+
7
+ def self.adapter_for(scm_name, config)
8
+ case scm_name.to_s
9
+ when /\Agit\z/i then Git.new(config)
10
+ else
11
+ raise %(Unknown scm adapter name: "%s") % scm_name.to_s
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+
@@ -0,0 +1,3 @@
1
+ module BriefMail
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,29 @@
1
+ <%= @config.application %> has been deployed to <%= @config.stage %> @ <%= Time.now %>.
2
+
3
+ ## Paths
4
+
5
+ Previous: <%= @config.previous_release %> @ <%= @config.previous_revision %>
6
+ Current: <%= @config.current_release %> @ <%= @config.current_revision %>
7
+
8
+ ## Commits since last deploy (most recent at bottom)
9
+
10
+ <%= raw @scm.log -%>
11
+
12
+ <% @scm.subdirs_log.each_pair do |dir, log| -%>
13
+ ### Directory <%= dir %>
14
+
15
+ <%= raw log -%>
16
+ <%- end -%>
17
+
18
+ ## Files changed since last deploy
19
+
20
+ <%= raw @scm.diff_stat -%>
21
+
22
+ <% @scm.subdirs_diff_stat.each_pair do |dir, stat| -%>
23
+ ### Directory <%= dir %>
24
+
25
+ <%= raw stat -%>
26
+ <%- end -%>
27
+
28
+ ---
29
+ This is an automatically generated deployment message from BriefMail.
data/lib/brief_mail.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "brief_mail/version"
2
+
3
+ require "brief_mail/config_adapters"
4
+ require "brief_mail/scm_adapters"
5
+ require "brief_mail/mailer"
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ class ConfigAdaptersAbstractAdapterTest < MiniTest::Unit::TestCase
4
+
5
+ def test_api
6
+ assert adapter = BriefMail::ConfigAdapters::AbstractAdapter.new(nil)
7
+
8
+ %w(
9
+ scm
10
+ application
11
+ stage
12
+ previous_release
13
+ current_release
14
+ previous_revision
15
+ current_revision
16
+
17
+ from_user
18
+ subject
19
+ mailer
20
+ recipients
21
+ ).each do |name|
22
+ assert adapter.respond_to?(name), %(Should respond to "%s" method) % name
23
+ assert adapter.send(name).nil?, %(Should return nil for "%s" method (was "%s")) % [name, adapter.send(name)]
24
+ end
25
+ end
26
+
27
+ def test_from_user_is_set
28
+ assert adapter = BriefMail::ConfigAdapters::AbstractAdapter.new(nil)
29
+
30
+ def adapter.from_user
31
+ { mailer: "mailer", subject: "subject", recipients: %w(one@example.com) }
32
+ end
33
+
34
+ assert_equal "subject", adapter.subject
35
+ assert_equal "mailer", adapter.mailer
36
+ assert_equal %w(one@example.com), adapter.recipients
37
+ end
38
+
39
+ end
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ class ConfigAdaptersCapistranoTest < MiniTest::Unit::TestCase
4
+
5
+ def test_api
6
+ cap_vars = MiniTest::Mock.new
7
+ assert adapter = BriefMail::ConfigAdapters::Capistrano.new(cap_vars)
8
+
9
+ %w(
10
+ scm
11
+ application
12
+ stage
13
+ previous_release
14
+ current_release
15
+ previous_revision
16
+ current_revision
17
+ ).each do |name|
18
+ assert adapter.respond_to?(name), %(Should respond to "%s" method) % name
19
+
20
+ cap_vars.expect(name.to_sym, name)
21
+ assert_equal name, adapter.send(name)
22
+ cap_vars.verify
23
+ end
24
+ end
25
+
26
+ def test_from_user_is_set
27
+ cap_vars = MiniTest::Mock.new
28
+ assert adapter = BriefMail::ConfigAdapters::Capistrano.new(cap_vars)
29
+
30
+ assert adapter.respond_to?(:from_user), %(Should respond to "from_user" method)
31
+
32
+ from_user = { subject: "subject", mailer: "mailer", recipients: %w(one@example.com) }
33
+
34
+ cap_vars.expect(:fetch, from_user, [:brief_mail_config])
35
+ assert_equal from_user[:subject], adapter.subject
36
+
37
+ cap_vars.expect(:fetch, from_user, [:brief_mail_config])
38
+ assert_equal from_user[:mailer], adapter.mailer
39
+
40
+ cap_vars.expect(:fetch, from_user, [:brief_mail_config])
41
+ assert_equal from_user[:recipients], adapter.recipients
42
+
43
+ cap_vars.verify
44
+ end
45
+
46
+ end
47
+
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ module Capistrano
4
+ module Configuration
5
+ module Namespaces
6
+ class Namespace
7
+ end
8
+ end
9
+ end
10
+ end
11
+
12
+ class MailerTest < MiniTest::Unit::TestCase
13
+
14
+ def test_deploy_notification
15
+ config = MiniTest::Mock.new
16
+ config.expect :is_a?, true, [Capistrano::Configuration::Namespaces::Namespace]
17
+ config.expect :scm, :git
18
+
19
+ config.expect :previous_release, "/tmp/prev"
20
+ config.expect :current_release, "/tmp/current"
21
+
22
+ # We use real revisions from this git repository during testing because
23
+ # MiniTest can't stub methods on non-existant instances. This means real
24
+ # git commands will be executed as well: Not optimal ...
25
+ 4.times { config.expect :previous_revision, "dd1afc4"}
26
+ config.expect :current_revision, "d461201"
27
+
28
+ 2.times { config.expect :stage, "test" }
29
+ 2.times { config.expect :application, "Test Application" }
30
+
31
+ from_user = { mailer: { delivery_method: :test }, recipients: %w(test@example.com) }
32
+ 4.times { config.expect(:fetch, from_user, [:brief_mail_config]) }
33
+
34
+ def Dir.chdir(*args)
35
+ yield if block_given?
36
+ end
37
+
38
+ mail = BriefMail::Mailer.deploy_notification(config)
39
+
40
+ config.verify
41
+
42
+ assert body = mail.body.to_s
43
+ assert_match /Test Application has been deploy to test/, body
44
+ assert_match /2012-09-29 Rakefile: Setup test environment with MiniTest/, body
45
+ assert_match /README\.md\s+\|\s+\d+ \++/, body
46
+ end
47
+
48
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ class SCMAdaptersAbstractAdapterTest < MiniTest::Unit::TestCase
4
+
5
+ def test_api
6
+ assert adapter = BriefMail::SCMAdapters::AbstractAdapter.new(nil)
7
+
8
+ %w( diff_stat log ).each do |name|
9
+ assert adapter.respond_to?(name), %(Should respond to "%s" method) % name
10
+ assert adapter.send(name).nil?
11
+ end
12
+
13
+ %w( subdirs_diff_stat subdirs_log ).each do |name|
14
+ assert adapter.respond_to?(name), %(Should respond to "%s" method) % name
15
+ assert_equal Hash.new, adapter.send(name)
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,75 @@
1
+ require 'test_helper'
2
+
3
+ class SCMAdaptersGitTest < MiniTest::Unit::TestCase
4
+
5
+ def test_api
6
+ config = MiniTest::Mock.new
7
+ assert adapter = BriefMail::SCMAdapters::Git.new(config)
8
+
9
+ %w( diff_stat log ).each do |name|
10
+ assert adapter.respond_to?(name), %(Should respond to "%s" method) % name
11
+ end
12
+
13
+ %w( subdirs_diff_stat subdirs_log ).each do |name|
14
+ assert adapter.respond_to?(name), %(Should respond to "%s" method) % name
15
+ end
16
+ end
17
+
18
+ def test_log
19
+ config = MiniTest::Mock.new
20
+ assert adapter = BriefMail::SCMAdapters::Git.new(config)
21
+
22
+ # %x() is syntatic sugar for backtick (`) method:
23
+ adapter.stub(:`, %(Command output)) do
24
+ config.expect :previous_revision, 1
25
+ config.expect :from_user, {}
26
+ assert_equal %(Command output), adapter.log
27
+ config.verify
28
+ end
29
+ end
30
+
31
+ def test_diff_stat
32
+ config = MiniTest::Mock.new
33
+ assert adapter = BriefMail::SCMAdapters::Git.new(config)
34
+
35
+ adapter.stub(:`, %(Command output)) do
36
+ config.expect :previous_revision, 1
37
+ assert_equal %(Command output), adapter.diff_stat
38
+ config.verify
39
+ end
40
+ end
41
+
42
+ def test_subdirs_diff_stat
43
+ config = MiniTest::Mock.new
44
+ assert adapter = BriefMail::SCMAdapters::Git.new(config)
45
+
46
+ def Dir.chdir(*args)
47
+ yield if block_given?
48
+ end
49
+
50
+ adapter.stub(:`, %(Command output)) do
51
+ config.expect :current_revision, 2
52
+ config.expect :previous_revision, 1
53
+ assert_equal({ "output" => "Command output"}, adapter.subdirs_diff_stat)
54
+ config.verify
55
+ end
56
+ end
57
+
58
+ def test_subdirs_log
59
+ config = MiniTest::Mock.new
60
+ assert adapter = BriefMail::SCMAdapters::Git.new(config)
61
+
62
+ def Dir.chdir(*args)
63
+ yield if block_given?
64
+ end
65
+
66
+ adapter.stub(:`, %(Command output)) do
67
+ config.expect :current_revision, 2
68
+ config.expect :previous_revision, 1
69
+ config.expect :from_user, {}
70
+ assert_equal({ "output" => "Command output"}, adapter.subdirs_log)
71
+ config.verify
72
+ end
73
+ end
74
+
75
+ end
@@ -0,0 +1,2 @@
1
+ require 'minitest/autorun'
2
+ require 'brief_mail'
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brief_mail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - S. Christoffer Eliesen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: actionmailer
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '4.0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '4.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '0.9'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ description: BriefMail sends you and your team mates a deployment summary after deploying
63
+ with capistrano.
64
+ email:
65
+ - christoffer@eliesen.no
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - brief_mail.gemspec
76
+ - lib/brief_mail.rb
77
+ - lib/brief_mail/capistrano.rb
78
+ - lib/brief_mail/config_adapters.rb
79
+ - lib/brief_mail/config_adapters/abstract_adapter.rb
80
+ - lib/brief_mail/config_adapters/capistrano.rb
81
+ - lib/brief_mail/mailer.rb
82
+ - lib/brief_mail/scm_adapters.rb
83
+ - lib/brief_mail/scm_adapters/abstract_adapter.rb
84
+ - lib/brief_mail/scm_adapters/git.rb
85
+ - lib/brief_mail/version.rb
86
+ - lib/brief_mail/views/deploy_notification.txt.erb
87
+ - test/brief_mail/config_adapters/abstract_adapter_test.rb
88
+ - test/brief_mail/config_adapters/capistrano_test.rb
89
+ - test/brief_mail/mailer_test.rb
90
+ - test/scm_adapters/abstract_adapter_test.rb
91
+ - test/scm_adapters/git_test.rb
92
+ - test/test_helper.rb
93
+ homepage: http://github.com/sce/brief_mail
94
+ licenses: []
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ segments:
106
+ - 0
107
+ hash: 1350458245436211571
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ segments:
115
+ - 0
116
+ hash: 1350458245436211571
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 1.8.24
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: BriefMail sends you and your team mates a deployment summary after deploying
123
+ with capistrano.
124
+ test_files:
125
+ - test/brief_mail/config_adapters/abstract_adapter_test.rb
126
+ - test/brief_mail/config_adapters/capistrano_test.rb
127
+ - test/brief_mail/mailer_test.rb
128
+ - test/scm_adapters/abstract_adapter_test.rb
129
+ - test/scm_adapters/git_test.rb
130
+ - test/test_helper.rb