summaryrefslogtreecommitdiffstats
path: root/spec/registration_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/registration_spec.rb')
-rw-r--r--spec/registration_spec.rb43
1 files changed, 30 insertions, 13 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