summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Gemfile9
-rw-r--r--Gemfile.lock6
-rw-r--r--lib/band.rb1
-rw-r--r--lib/registration.rb13
-rw-r--r--registration.rb4
-rw-r--r--spec/registration_spec.rb13
-rw-r--r--spec/spec_helper.rb5
7 files changed, 47 insertions, 4 deletions
diff --git a/Gemfile b/Gemfile
index 5ec35cb..766cd53 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,5 +1,10 @@
source "https://rubygems.org"
gem "sinatra"
-gem "rspec"
-gem "rack-test"
+gem "mail"
+
+group :development, :test do
+ gem 'byebug'
+ gem "rspec"
+ gem "rack-test"
+end
diff --git a/Gemfile.lock b/Gemfile.lock
index cc8a85b..4a18b9f 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,7 +1,11 @@
GEM
remote: https://rubygems.org/
specs:
+ byebug (6.0.2)
diff-lcs (1.2.5)
+ mail (2.6.3)
+ mime-types (>= 1.16, < 3)
+ mime-types (2.6.2)
rack (1.6.4)
rack-protection (1.5.3)
rack
@@ -30,6 +34,8 @@ PLATFORMS
ruby
DEPENDENCIES
+ byebug
+ mail
rack-test
rspec
sinatra
diff --git a/lib/band.rb b/lib/band.rb
index 44d1e7c..22778ff 100644
--- a/lib/band.rb
+++ b/lib/band.rb
@@ -11,6 +11,7 @@ class Band
@website = params['website']
@label = params['label']
@short_bio = params['shortbio']
+
@contact = Contact.new(params['contact'])
@members = []
diff --git a/lib/registration.rb b/lib/registration.rb
new file mode 100644
index 0000000..5a31ca0
--- /dev/null
+++ b/lib/registration.rb
@@ -0,0 +1,13 @@
+require 'band'
+require 'mail'
+
+def send_registration_emails_for(band)
+ mail = Mail.new
+ mail.charset = 'UTF-8'
+ mail.to = 'haraldei@anduin.net'
+ mail.from = @band.contact.email
+ mail.subject = "Registrering av band #{@band.name} til Norsk Urskog"
+ mail.body = 'Neijassådu!'
+
+ mail.deliver!
+end
diff --git a/registration.rb b/registration.rb
index 9fae54f..f599bfd 100644
--- a/registration.rb
+++ b/registration.rb
@@ -1,5 +1,5 @@
require 'sinatra/base'
-require_relative 'lib/band'
+require_relative 'lib/registration'
class RegistrationApp < Sinatra::Base
@@ -11,7 +11,7 @@ class RegistrationApp < Sinatra::Base
if request.form_data?
#p request['band']
@band = Band.new(request['band'])
-
+ send_registration_emails_for @band
erb :submitted
end
end
diff --git a/spec/registration_spec.rb b/spec/registration_spec.rb
index 5f398c0..ed95fae 100644
--- a/spec/registration_spec.rb
+++ b/spec/registration_spec.rb
@@ -28,6 +28,12 @@ describe RegistrationApp do
end
describe 'POST submit' do
+ include Mail::Matchers
+
+ before :each do
+ Mail::TestMailer.deliveries.clear
+ end
+
context 'with a valid registration' do
before :each do
params = {
@@ -99,6 +105,13 @@ describe RegistrationApp do
expect(last_response).to match /Låtskrivere: Harald Eilertsen, Thormod Steinert/
expect(last_response).to match /Merknad: Rævrukkje rum kjurr!/
end
+
+ it 'sends and email to Norsk Urskog' do
+ message = Mail::TestMailer.deliveries.first
+ expect(Mail::TestMailer.deliveries).not_to be_empty
+ expect(message.to).to include('haraldei@anduin.net')
+ expect(message.subject).to match /Registrering av band Imbalance til Norsk Urskog/
+ end
end
end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index c7171e6..7947e06 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,3 +1,8 @@
require_relative '../registration'
require 'rspec'
require 'rack/test'
+require 'mail'
+
+Mail.defaults do
+ delivery_method :test # in practice you'd do this in spec_helper.rb
+end