summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2015-10-10 15:16:13 +0200
committerHarald Eilertsen <haraldei@anduin.net>2015-10-10 15:18:54 +0200
commitd9696a5eb4aa8638b757ca95b4cc2a4d5b8ae4f6 (patch)
tree94859f172dbc3ecf831d13aab9263696793df122 /spec
parent2b664060f45efd7329b53f87f83cc764a5a53bdb (diff)
downloadnorsk-urskog-registrations-d9696a5eb4aa8638b757ca95b4cc2a4d5b8ae4f6.tar.gz
norsk-urskog-registrations-d9696a5eb4aa8638b757ca95b4cc2a4d5b8ae4f6.tar.bz2
norsk-urskog-registrations-d9696a5eb4aa8638b757ca95b4cc2a4d5b8ae4f6.zip
Reject bands with no name
Diffstat (limited to 'spec')
-rw-r--r--spec/registration_spec.rb43
-rw-r--r--spec/support/band_factory.rb3
2 files changed, 32 insertions, 14 deletions
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',