Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
Basic mail reporting and development tools
Browse files Browse the repository at this point in the history
- Added basic email reporting classes
- [TODO] Integrate into harvest_utils
- Added Guard automatic testing gem
  • Loading branch information
nomadicoder committed Mar 20, 2015
1 parent 2d452c8 commit cbd9063
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ group :development, :test do
gem "factory_girl_rails", "~> 4.4.1"
gem "jettywrapper"
gem "pry-rails"
gem "guard-rspec"
end

group :test do
Expand Down
38 changes: 38 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ GEM
sass (>= 3.2.19)
builder (3.2.2)
cancancan (1.10.1)
celluloid (0.16.0)
timers (~> 4.0.0)
childprocess (0.5.5)
ffi (~> 1.0, >= 1.0.11)
coderay (1.1.0)
Expand Down Expand Up @@ -118,9 +120,25 @@ GEM
faraday (>= 0.7.4, < 0.10)
fastercsv (1.5.5)
ffi (1.9.6)
formatador (0.2.5)
guard (2.12.5)
formatador (>= 0.2.4)
listen (~> 2.7)
lumberjack (~> 1.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.9.12)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.1)
guard-rspec (4.5.0)
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
haml (4.0.6)
tilt
hike (1.2.3)
hitimes (1.2.2)
hooks (0.3.6)
uber (~> 0.0.4)
htmlentities (4.3.3)
Expand Down Expand Up @@ -194,7 +212,12 @@ GEM
rdf-turtle (~> 1.1, >= 1.1.5)
sparql (~> 1.1, >= 1.1.4)
sparql-client (~> 1.1, >= 1.1.3)
listen (2.9.0)
celluloid (>= 0.15.2)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
logger (1.2.8)
lumberjack (1.0.9)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
Expand All @@ -204,6 +227,7 @@ GEM
minitest (5.5.1)
multi_json (1.11.0)
multipart-post (2.0.0)
nenv (0.2.0)
net-http-persistent (2.9.4)
netrc (0.10.3)
nokogiri (1.6.6.2)
Expand All @@ -212,6 +236,9 @@ GEM
activesupport (>= 3.2.18)
i18n
nokogiri
notiffany (0.0.6)
nenv (~> 0.1)
shellany (~> 0.0)
om (3.1.0)
activemodel
activesupport
Expand Down Expand Up @@ -246,6 +273,9 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
rb-fsevent (0.9.4)
rb-inotify (0.9.5)
ffi (>= 0.5.0)
rdf (1.1.9)
link_header (~> 0.0, >= 0.0.8)
rdf-aggregate-repo (1.1.0)
Expand Down Expand Up @@ -297,6 +327,10 @@ GEM
netrc (~> 0.7)
rsolr (1.0.11)
builder (>= 2.1.2)
rspec (3.2.0)
rspec-core (~> 3.2.0)
rspec-expectations (~> 3.2.0)
rspec-mocks (~> 3.2.0)
rspec-core (3.2.1)
rspec-support (~> 3.2.0)
rspec-expectations (3.2.0)
Expand Down Expand Up @@ -334,6 +368,7 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
shellany (0.0.1)
simplecov (0.9.2)
docile (~> 1.1.0)
multi_json (~> 1.0)
Expand Down Expand Up @@ -376,6 +411,8 @@ GEM
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
timers (4.0.1)
hitimes
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
Expand Down Expand Up @@ -405,6 +442,7 @@ DEPENDENCIES
devise
devise-guests (~> 0.3)
factory_girl_rails (~> 4.4.1)
guard-rspec
hydra (= 7.1.0)
jbuilder (~> 2.0)
jettywrapper
Expand Down
130 changes: 130 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features)

## Uncomment to clear the screen before every task
# clearing :on

## Guard internally checks for changes in the Guardfile and exits.
## If you want Guard to automatically start up again, run guard in a
## shell loop, e.g.:
##
## $ while bundle exec guard; do echo "Restarting Guard..."; done
##
## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
#
# $ mkdir config
# $ mv Guardfile config/
# $ ln -s config/Guardfile .
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"

# Note: The cmd option is now required due to the increasing number of ways
# rspec may be run, below are examples of the most common uses.
# * bundler: 'bundle exec rspec'
# * bundler binstubs: 'bin/rspec'
# * spring: 'bin/rspec' (This will use spring if running and you have
# installed the spring binstubs per the docs)
# * zeus: 'zeus rspec' (requires the server to be started separately)
# * 'just' rspec: 'rspec'

guard :rspec, cmd: "bundle exec rspec" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)

# Feel free to open issues for suggestions and improvements

# RSpec files
rspec = dsl.rspec
watch(rspec.spec_helper) { rspec.spec_dir }
watch(rspec.spec_support) { rspec.spec_dir }
watch(rspec.spec_files)

# Ruby files
ruby = dsl.ruby
dsl.watch_spec_files_for(ruby.lib_files)

# Rails files
rails = dsl.rails(view_extensions: %w(erb haml slim))
dsl.watch_spec_files_for(rails.app_files)
dsl.watch_spec_files_for(rails.views)

watch(rails.controllers) do |m|
[
rspec.spec.("routing/#{m[1]}_routing"),
rspec.spec.("controllers/#{m[1]}_controller"),
rspec.spec.("acceptance/#{m[1]}")
]
end

# Rails config changes
watch(rails.spec_helper) { rspec.spec_dir }
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }

# Capybara features specs
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }

# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
end
end

# Note: The cmd option is now required due to the increasing number of ways
# rspec may be run, below are examples of the most common uses.
# * bundler: 'bundle exec rspec'
# * bundler binstubs: 'bin/rspec'
# * spring: 'bin/rspec' (This will use spring if running and you have
# installed the spring binstubs per the docs)
# * zeus: 'zeus rspec' (requires the server to be started separately)
# * 'just' rspec: 'rspec'

guard :rspec, cmd: "bundle exec rspec" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)

# Feel free to open issues for suggestions and improvements

# RSpec files
rspec = dsl.rspec
watch(rspec.spec_helper) { rspec.spec_dir }
watch(rspec.spec_support) { rspec.spec_dir }
watch(rspec.spec_files)

# Ruby files
ruby = dsl.ruby
dsl.watch_spec_files_for(ruby.lib_files)

# Rails files
rails = dsl.rails(view_extensions: %w(erb haml slim))
dsl.watch_spec_files_for(rails.app_files)
dsl.watch_spec_files_for(rails.views)

watch(rails.controllers) do |m|
[
rspec.spec.("routing/#{m[1]}_routing"),
rspec.spec.("controllers/#{m[1]}_controller"),
rspec.spec.("acceptance/#{m[1]}")
]
end

# Rails config changes
watch(rails.spec_helper) { rspec.spec_dir }
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }

# Capybara features specs
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }

# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
end
end
22 changes: 22 additions & 0 deletions app/mailers/harvest_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class HarvestMailer < ActionMailer::Base
default from: "from@example.com",
to: "dplah@example.edu"

def harvest_complete_email(provider)
@provider = provider
subject_text = "Harvest of #{provider.set} Completed"
m = mail(to: provider.email, subject: subject_text).deliver
end

def conversion_complete_email(provider)
@provider = provider
subject_text = "Conversion of #{provider.set} Completed"
m = mail(to: provider.email, subject: subject_text).deliver
end

def ingest_complete_email(provider)
@provider = provider
subject_text = "Ingest of #{provider.set} Completed"
m = mail(to: provider.email, subject: subject_text).deliver
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Conversion of your collection completed
1 change: 1 addition & 0 deletions app/views/harvest_mailer/harvest_complete_email.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Harvest of your collection completed
1 change: 1 addition & 0 deletions app/views/harvest_mailer/ingest_complete_email.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ingest of your collection completed
3 changes: 3 additions & 0 deletions spec/factories/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
set "setname"
provider_id_prefix "prvdr"
contributing_institution "The Contributing Instition"
email "provider@example.com"
end

factory :provider_small_collection, class: Provider do
Expand All @@ -21,6 +22,7 @@
set "alycc-voice"
provider_id_prefix "lycoming"
contributing_institution "POWER Library"
email "lycoming@example.com"
end

factory :provider_transient_records, class: Provider do
Expand All @@ -42,6 +44,7 @@
metadata_prefix "oai_dc"
set "alycc-voice"
sequence(:provider_id_prefix) { |n| "lycoming#{n}" }
sequence(:provider_id_prefix) { |n| "lycoming#{n}@example.com" }
contributing_institution "POWER Library"
end
end
30 changes: 30 additions & 0 deletions spec/mailers/harvest_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require "rails_helper"

RSpec.describe HarvestMailer, type: :mailer do
let(:provider) { FactoryGirl.build(:provider_small_collection) }

before :each do
ActionMailer::Base.deliveries = []
end

it "should deliver a successful harvest email" do
mail = HarvestMailer.harvest_complete_email(provider)
expect(ActionMailer::Base.deliveries.size).to eq 1
expect(mail.to).to include(provider.email)
expect(mail.subject).to match /Harvest of #{provider.set} Completed/
end

it "should deliver a successful conversion email" do
mail = HarvestMailer.conversion_complete_email(provider)
expect(ActionMailer::Base.deliveries.size).to eq 1
expect(mail.to).to include(provider.email)
expect(mail.subject).to match /Conversion of #{provider.set} Completed/
end

it "should deliver a successful ingest eamil" do
mail = HarvestMailer.ingest_complete_email(provider)
expect(ActionMailer::Base.deliveries.size).to eq 1
expect(mail.to).to include(provider.email)
expect(mail.subject).to match /Ingest of #{provider.set} Completed/
end
end
4 changes: 4 additions & 0 deletions spec/mailers/previews/harvest_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Preview all emails at http://localhost:3000/rails/mailers/harvest_mailer
class HarvestMailerPreview < ActionMailer::Preview

end

0 comments on commit cbd9063

Please sign in to comment.