summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/band.rb4
-rw-r--r--spec/registration_spec.rb43
-rw-r--r--spec/support/band_factory.rb3
3 files changed, 36 insertions, 14 deletions
diff --git a/lib/band.rb b/lib/band.rb
index e75dd6e..59e7541 100644
--- a/lib/band.rb
+++ b/lib/band.rb
@@ -41,6 +41,10 @@ class Band
end
def validate!
+ if @name.nil? || @name.strip.empty?
+ errors << "Bandnavn mangler"
+ end
+
if @songs.length <= 0
errors << "Du må ha med minst én låt!"
end
diff --git a/spec/registration_spec.rb b/spec/registration_spec.rb
index db7db70..e4d5ff4 100644
--- a/spec/registration_spec.rb
+++ b/spec/registration_spec.rb
@@ -38,8 +38,9 @@ describe RegistrationApp do
end
context 'with a valid registration' do
+ let(:band_params) { create_band_params }
before :each do
- post '/submit', 'band' => create_band_params
+ post '/submit', 'band' => band_params
end
it 'should succeed' do
@@ -51,7 +52,7 @@ describe RegistrationApp do
end
it 'displays submitted data to user' do
- expect(last_response).to match(/Bandnavn\: Imbalance/)
+ expect(last_response).to match(/Bandnavn\: #{band_params['name']}/)
expect(last_response).to match(/Hjemsted\: Oslo/)
expect(last_response).to match(/Webside\: http\:\/\/imbalance.no/)
expect(last_response).to match(/Plateselskap\: Calculated Imperfection/)
@@ -75,29 +76,45 @@ describe RegistrationApp do
it "generates a PDF file" do
expect(Prawn::Document).to have_received('new').with({ :page_size => "A4" })
- expect(@doc_spy).to have_received('render_file').with("Imbalance.pdf")
+ expect(@doc_spy).to have_received('render_file').with("#{band_params['name']}.pdf")
end
it 'sends an 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/)
+ expect(message.subject).to match(/Registrering av band #{band_params['name']} til Norsk Urskog/)
end
end
- context 'with no songs' do
- before :each do
- post '/submit', 'band' => create_band_params(:songs => 0)
- end
+ shared_examples_for('form with errors') do |args|
+ let (:band_params) { create_band_params(args) }
- it 'should reject request and go back to the registration form' do
- expect(last_response.body).to match(/form id="registration-form"/)
- end
+ describe "form with errors" do
+ before :each do
+ post '/submit', 'band' => band_params
+ end
+
+ it 'should go back to the registration form' do
+ expect(last_response.body).to match(/form id="registration-form"/)
+ end
- it 'should display an error message' do
- expect(last_response.body).to include("Du må ha med minst én låt")
+ it 'should display an error message' do
+ expect(last_response.body).to include("Det er feil i skjemaet")
+ end
end
end
+
+ context 'with no songs' do
+ it_behaves_like('form with errors', {:songs => 0})
+ end
+
+ context 'without a band name' do
+ it_behaves_like('form with errors', {:name => ''})
+ end
+
+ context 'with a band name with only spaces' do
+ it_behaves_like('form with errors', {:name => ' '})
+ end
end
end
diff --git a/spec/support/band_factory.rb b/spec/support/band_factory.rb
index f14caf2..4bf9a15 100644
--- a/spec/support/band_factory.rb
+++ b/spec/support/band_factory.rb
@@ -2,12 +2,13 @@ module BandFactory
def create_band_params(options = {})
opts = {
:songs => 1,
+ :name => 'Band name'
}.merge(options)
num_songs = opts.delete(:songs)
params = {
- 'name' => 'Imbalance',
+ 'name' => opts[:name],
'city' => 'Oslo',
'website' => 'http://imbalance.no',
'label' => 'Calculated Imperfection',