summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2015-10-05 20:12:42 +0200
committerHarald Eilertsen <haraldei@anduin.net>2015-10-05 20:12:42 +0200
commit696be9ff4d6a6f7e3286cba14df4e4f449d31bb6 (patch)
tree5d2558089d94bf728ae2a43eb37f5f6d355df3f5 /spec
parent412e15ee69b89f964ab6a991c6986e6860552cce (diff)
downloadnorsk-urskog-registrations-696be9ff4d6a6f7e3286cba14df4e4f449d31bb6.tar.gz
norsk-urskog-registrations-696be9ff4d6a6f7e3286cba14df4e4f449d31bb6.tar.bz2
norsk-urskog-registrations-696be9ff4d6a6f7e3286cba14df4e4f449d31bb6.zip
Refactor generation of band params for test into factory.
Diffstat (limited to 'spec')
-rw-r--r--spec/registration_spec.rb43
-rw-r--r--spec/spec_helper.rb7
-rw-r--r--spec/support/band_factory.rb59
3 files changed, 67 insertions, 42 deletions
diff --git a/spec/registration_spec.rb b/spec/registration_spec.rb
index 2911f6a..be4e6f7 100644
--- a/spec/registration_spec.rb
+++ b/spec/registration_spec.rb
@@ -38,52 +38,11 @@ describe RegistrationApp do
context 'with a valid registration' do
before :each do
- params = {
- 'name' => 'Imbalance',
- 'city' => 'Oslo',
- 'website' => 'http://imbalance.no',
- 'label' => 'Calculated Imperfection',
- 'shortbio' => 'Thrash metal from Norway',
- 'contact' => {
- 'name' => 'Harald Eilertsen',
- 'addr' => "Gamleveien 13\n1289 Snufstad",
- 'phone' => '98765432',
- 'email' => 'mail@imbalance.no'
- },
- 'members' => {
- '1' => {
- 'name' => 'Harald Eilertsen',
- 'instrument' => 'Bass/Vocals',
- 'age' => ''
- },
- '2' => {
- 'name' => 'Welle',
- 'instrument' => 'Drums',
- 'age' => ''
- },
- '3' => {
- 'name' => 'Thormodr',
- 'instrument' => 'Guitar',
- 'age' => ''
- }
- },
- 'songs' => {
- '1' => {
- 'title' => 'Bestial by Nature',
- 'time' => '02:80',
- 'isrc' => '',
- 'performers' => "Harald Eilertsen\nThormod Steinert\nLars Welle",
- 'composers' => "Harald Eilertsen\nThormod Steinert",
- 'notes' => 'Rævrukkje rum kjurr!'
- }
- }
- }
-
@doc_spy = spy("Prawn::Document")
allow(Prawn::Document).to receive('new') { @doc_spy }
allow(@doc_spy).to receive('render_file')
- post '/submit', 'band' => params
+ post '/submit', 'band' => create_band_params
end
it 'should succeed' do
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 7947e06..1e7a791 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,8 +1,15 @@
+ENV['RACK_ENV'] = 'test'
+
require_relative '../registration'
+require_relative 'support/band_factory'
require 'rspec'
require 'rack/test'
require 'mail'
+RSpec.configure do |config|
+ config.include BandFactory
+end
+
Mail.defaults do
delivery_method :test # in practice you'd do this in spec_helper.rb
end
diff --git a/spec/support/band_factory.rb b/spec/support/band_factory.rb
new file mode 100644
index 0000000..f14caf2
--- /dev/null
+++ b/spec/support/band_factory.rb
@@ -0,0 +1,59 @@
+module BandFactory
+ def create_band_params(options = {})
+ opts = {
+ :songs => 1,
+ }.merge(options)
+
+ num_songs = opts.delete(:songs)
+
+ params = {
+ 'name' => 'Imbalance',
+ 'city' => 'Oslo',
+ 'website' => 'http://imbalance.no',
+ 'label' => 'Calculated Imperfection',
+ 'shortbio' => 'Thrash metal from Norway',
+ 'contact' => {
+ 'name' => 'Harald Eilertsen',
+ 'addr' => "Gamleveien 13\n1289 Snufstad",
+ 'phone' => '98765432',
+ 'email' => 'mail@imbalance.no'
+ },
+ 'members' => {
+ '1' => {
+ 'name' => 'Harald Eilertsen',
+ 'instrument' => 'Bass/Vocals',
+ 'age' => ''
+ },
+ '2' => {
+ 'name' => 'Welle',
+ 'instrument' => 'Drums',
+ 'age' => ''
+ },
+ '3' => {
+ 'name' => 'Thormodr',
+ 'instrument' => 'Guitar',
+ 'age' => ''
+ }
+ },
+ 'songs' => {}
+ }
+
+ (1..num_songs).each do |i|
+ num = i.to_s
+ params['songs'][num] = create_song_params
+ end
+
+ params
+ end
+
+ def create_song_params
+ {
+ 'title' => 'Bestial by Nature',
+ 'time' => '02:80',
+ 'isrc' => '',
+ 'performers' => "Harald Eilertsen\nThormod Steinert\nLars Welle",
+ 'composers' => "Harald Eilertsen\nThormod Steinert",
+ 'notes' => 'Rævrukkje rum kjurr!'
+ }
+ end
+end