summaryrefslogtreecommitdiffstats
path: root/spec/registration_spec.rb
blob: 2911f6a4d65e52e5e9b2e681d216cab52d98f59e (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
require "prawn"

describe RegistrationApp do
  include Rack::Test::Methods

  def app
    RegistrationApp
  end

  describe 'GET index' do
    before :each do
      get '/'
    end

    it 'should succeed' do
      expect(last_response).to be_ok
    end

    it 'displays the registration form' do
      expect(last_response.body).to match /form id="registration-form"/
    end

    it 'displays the add member button' do
      expect(last_response.body).to match /id="add-member-button"/
    end

    it 'displays the add song button' do
      expect(last_response.body).to match /id="add-song-button"/
    end
  end

  describe 'POST submit' do
    include Mail::Matchers

    before :each do
      Mail::TestMailer.deliveries.clear
    end

    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
      end

      it 'should succeed' do
        expect(last_response).to be_ok
      end

      it 'displays submitted data to user' do
        expect(last_response).to match /Bandnavn\: Imbalance/
        expect(last_response).to match /Hjemsted\: Oslo/
        expect(last_response).to match /Webside\: http\:\/\/imbalance.no/
        expect(last_response).to match /Plateselskap\: Calculated Imperfection/
        expect(last_response).to match /Kort bio\: Thrash metal from Norway/

        expect(last_response).to match /Kontaktperson: Harald Eilertsen/
        expect(last_response).to match /Kontaktadresse: Gamleveien 13\n1289 Snufstad/
        expect(last_response).to match /Telefon: 98765432/
        expect(last_response).to match /Epost: mail@imbalance\.no/

        expect(last_response).to match /Harald Eilertsen, Bass\/Vocals/
        expect(last_response).to match /Welle, Drums/
        expect(last_response).to match /Thormodr, Guitar/

        expect(last_response).to match /Bestial by Nature/
        expect(last_response).to match /Spilletid: 02:80/
        expect(last_response).to match /Utøvere: Harald Eilertsen, Thormod Steinert, Lars Welle/
        expect(last_response).to match /Låtskrivere: Harald Eilertsen, Thormod Steinert/
        expect(last_response).to match /Merknad: Rævrukkje rum kjurr!/
      end

      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")
      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/
      end
    end
  end
end