summaryrefslogtreecommitdiffstats
path: root/spec/support/band_factory.rb
blob: 56993fa41fc2f53549b772d4a1233073d988f03c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
module BandFactory
  def create_band_params(options = {})
    opts = {
      :songs => 1,
      :name => 'Band name',
      :city => 'Somewhere',
      :website => 'http://bandsite.com',
      :label => 'A Record Label',
      :bio => 'A short bio about the band',
      :contact_name => 'Contact Name',
      :contact_addr => "Streetname 666\n1234Someplace Nice",
      :contact_phone => '98765432',
      :contact_email => 'band@example.com',
      :members => [
        { :name => 'Member 1', :instrument => 'Instrument 1', :age => '24' },
        { :name => 'Member 2', :instrument => 'Instrument 2', :age => '0' },
        { :name => 'Member 3', :instrument => '', :age => '' },
      ],
    }.merge(options)

    num_songs = opts.delete(:songs)

    params = {
      'name' => opts[:name],
      'city' => opts[:city],
      'website' => opts[:website],
      'label' => opts[:label],
      'shortbio' => opts[:bio],
      'contact' => {
        'name' => opts[:contact_name],
        'addr' => opts[:contact_addr],
        'phone' => opts[:contact_phone],
        'email' => opts[:contact_email]
      },
      'members' => {},
      'songs' => {}
    }

    (1..opts[:members].length).each do |i|
      params['members'][i.to_s] = {}
      params['members'][i.to_s]['name'] = opts[:members][i-1][:name]
      params['members'][i.to_s]['instrument'] = opts[:members][i-1][:instrument]
      params['members'][i.to_s]['age'] = opts[:members][i-1][:age]
    end

    (1..num_songs).each do |i|
      num = i.to_s
      params['songs'][num] = create_song_params
    end

    params
  end

  def create_song_params
    {
      'title' => 'A song title',
      'time' => '02:30',
      'isrc' => '',
      'performers' => "Performer 1\nPerformer 2\nPerformer 3",
      'composers' => "Composer 1\nComposer 2",
      'notes' => 'Some notes'
    }
  end
end