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
|
RSpec.describe ExportsController, :type => :controller do
login_user
let(:workbench) { create :workbench }
let(:export) { create(:netex_export, workbench: workbench, referential: first_referential) }
describe 'GET #new' do
it 'should be successful if authorized' do
get :new, workbench_id: workbench.id
expect(response).to be_success
end
it 'should be unsuccessful unless authorized' do
remove_permissions('exports.create', from_user: @user, save: true)
get :new, workbench_id: workbench.id
expect(response).not_to be_success
end
end
describe "POST #create" do
let(:params){ {name: "foo"} }
let(:request){ post :create, workbench_id: workbench.id, export: params }
it 'should create no objects' do
expect{request}.to_not change{Export::Netex.count}
end
context "with full params" do
let(:params){{
name: "foo",
type: "Export::Netex",
duration: 12,
export_type: :full,
referential_id: first_referential.id
}}
it 'should be successful' do
expect{request}.to change{Export::Netex.count}.by(1)
end
it "displays a flash message" do
request
expect(controller).to set_flash[:notice].to(
I18n.t('flash.exports.create.notice')
)
end
end
context "with missing options" do
let(:params){{
name: "foo",
type: "Export::Workgroup"
}}
it 'should be unsuccessful' do
expect{request}.to change{Export::Netex.count}.by(0)
end
end
context "with all options" do
let(:params){{
name: "foo",
type: "Export::Workgroup",
duration: 90,
referential_id: first_referential.id
}}
it 'should be successful' do
expect{request}.to change{Export::Workgroup.count}.by(1)
end
end
context "with wrong type" do
let(:params){{
name: "foo",
type: "Export::Foo"
}}
it 'should be unsuccessful' do
expect{request}.to raise_error ActiveRecord::SubclassNotFound
end
end
end
describe 'POST #upload' do
context "with the token" do
it 'should be successful' do
post :upload, workbench_id: workbench.id, id: export.id, token: export.token_upload
expect(response).to be_success
end
end
context "without the token" do
it 'should be unsuccessful' do
post :upload, workbench_id: workbench.id, id: export.id, token: "foo"
expect(response).to_not be_success
end
end
end
end
|