-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathcreate_spec.rb
70 lines (53 loc) · 1.86 KB
/
create_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
64
65
66
67
68
69
70
# frozen_string_literal: true
RSpec.describe Web::Controllers::Interviews::Create, type: :action do
subject { action.call(params) }
let(:action) { described_class.new(operation: operation) }
let(:operation) { ->(*) { Success(Vacancy.new(id: 123)) } }
let(:session) { { account: account } }
let(:account) { Account.new(id: 1) }
let(:params) do
{
'rack.session' => session,
interview: {
account_id: '1',
body_raw: 'test text here',
anonymous: 'true',
interview_rating: {
overall_impression: '3.0',
recommendation: '3.0'
}
},
company_id: company_id
}
end
let(:company_id) { '1' }
context 'when operation returns success result' do
let(:operation) { ->(*) { Success(Vacancy.new(id: 123)) } }
let(:success_flash) { 'Отзыв успешно создан.' }
it { expect(subject).to redirect_to '/companies/1/interviews' }
it 'shows flash message' do
subject
expect(action.exposures[:flash][:success]).to eq(success_flash)
end
end
context 'when operation returns failure result' do
let(:operation) { ->(*) { Failure(:error) } }
let(:flash_message) { 'Произошла ошибка, пожалуйста повторите позже' }
it { expect(subject).to redirect_to '/companies/1/interviews' }
it 'shows flash message' do
subject
expect(action.exposures[:flash][:fail]).to eq(flash_message)
end
end
context 'with real dependencies' do
subject { action.call(params) }
let(:account) { Fabricate(:account) }
let(:company_id) { Fabricate(:company).id }
let(:action) { described_class.new }
it { expect(subject).to redirect_to "/companies/#{company_id}/interviews" }
end
context 'when not authorised' do
let(:session) { {} }
it { expect(subject).to redirect_to '/' }
end
end