/
sections_controller_spec.rb
63 lines (53 loc) · 1.79 KB
/
sections_controller_spec.rb
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
require 'rails_helper'
describe SectionsController do
before do
@event = create(:event)
@user = create(:user)
@event.organizers << @user
sign_in @user
end
describe "#create" do
it "makes a new section for the event" do
expect {
post :create, event_id: @event.id
}.to change(@event.sections, :count).by(1)
end
it "initializes the section with a default name" do
post :create, event_id: @event.id
expect(Section.last.name).to eq('New Section')
end
end
describe "#update" do
before do
@section = @event.sections.create(name: 'Fantasy Island')
end
it 'changes the section' do
put :update, event_id: @event.id, id: @section.id, section: {name: 'Scrabble Sands'}
expect(@section.reload.name).to eq('Scrabble Sands')
expect(response).to be_success
end
it 'does not respect invalid params' do
put :update, event_id: @event.id, id: @section.id, section: {name: 'Scrabble Sands', event_id: 1}
expect(@section.reload.event_id).to eq(@event.id)
end
end
describe "#destroy" do
before do
@section = @event.sections.create(name: 'Fantasy Island')
end
it 'removes the section' do
expect {
delete :destroy, event_id: @event.id, id: @section.id
}.to change(@event.sections, :count).by(-1)
expect(Section.find_by(id: @section.id)).to be_nil
end
end
describe "#arrange" do
it 'tells the section arranger to arrange sections for this event' do
fake_section_arranger = instance_double(SectionArranger)
expect(fake_section_arranger).to receive(:arrange).with('any')
expect(SectionArranger).to receive(:new).with(@event).and_return(fake_section_arranger)
post :arrange, event_id: @event.id, checked_in_to: 'any'
end
end
end