-
-
Notifications
You must be signed in to change notification settings - Fork 195
/
info_request_spec.rb
102 lines (85 loc) · 2.96 KB
/
info_request_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
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
require 'spec_helper'
require_dependency 'project/export/info_request'
RSpec.describe Project::Export::InfoRequest do
include Rails.application.routes.url_helpers
include LinkToHelper
let(:project) { FactoryBot.build(:project) }
let(:key_set) { FactoryBot.build(:dataset_key_set, resource: project) }
let!(:dataset_key) { FactoryBot.create(:dataset_key, key_set: key_set) }
let(:contributor) { FactoryBot.build(:user) }
let(:public_body) { FactoryBot.build(:public_body) }
let(:info_request) do
FactoryBot.build(:info_request, public_body: public_body)
end
let(:instance) { described_class.new(project, info_request) }
describe '#data' do
subject(:data) { instance.data }
shared_context 'with non-project classification' do
before do
info_request.described_state = 'successful'
end
end
shared_context 'with project classification' do
let(:url) do
request_url(info_request, host: AlaveteliConfiguration.domain)
end
before do
FactoryBot.create(
:project_submission,
:for_classification,
project: project,
info_request: info_request,
user: contributor
)
end
end
shared_context 'with project extraction' do
before do
FactoryBot.create(
:project_submission,
:for_extraction,
project: project,
info_request: info_request,
user: contributor
)
end
end
context 'when info request has been classified outside of projects' do
include_context 'with non-project classification'
it 'uses project owner as latest status contributor' do
expect(data[:latest_status_contributor]).to eq project.owner.name
end
end
context 'when info request has been classified' do
include_context 'with project classification'
it 'shows classification and contributor' do
is_expected.to eq(
request_url: url,
request_title: info_request.title,
public_body_name: public_body.name,
request_owner: info_request.user.name,
latest_status_contributor: contributor.name,
status: info_request.described_state,
:dataset_contributor => nil,
'Were there any errors?' => nil
)
end
end
context 'when info request has been classified and extracted' do
include_context 'with project classification'
include_context 'with project extraction'
it 'shows extracted values and contributor' do
is_expected.to eq(
:request_url => url,
:request_title => info_request.title,
:public_body_name => public_body.name,
:request_owner => info_request.user.name,
:latest_status_contributor => contributor.name,
:status => info_request.described_state,
:dataset_contributor => contributor.name,
'Were there any errors?' => '1'
)
end
end
end
end