1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class ProjectsTest < ActionDispatch ::IntegrationTest
6
+ def new_project ( dir , type : 'Maya' )
7
+ params = {
8
+ project : {
9
+ name : ( 'a' ..'z' ) . to_a . shuffle [ 0 , 8 ] . join ,
10
+ description : 'test project' ,
11
+ directory : dir ,
12
+ project_type : type
13
+ }
14
+ }
15
+
16
+ post projects_path , params : params
17
+ # for some reason you need to get the id before you follow redirect
18
+ id = @response . location . to_s . split ( '/' ) . last
19
+
20
+ follow_redirect!
21
+ assert_response :success
22
+
23
+ id
24
+ end
25
+
26
+ def script_params ( overrides : { } )
27
+ # TODO: looks like the controller only validates the frames. everything else is required in the js
28
+ {
29
+ script : {
30
+ frames : '1-10'
31
+ } . deep_merge! ( overrides )
32
+ }
33
+ end
34
+
35
+ test 'maya project creates maya script' do
36
+ Dir . mktmpdir do |tmpdir |
37
+ id = new_project ( tmpdir )
38
+ get project_path ( id )
39
+ assert_response :success
40
+
41
+ get new_project_script_path ( id )
42
+ assert_response :success
43
+
44
+ post project_scripts_path ( id ) , params : script_params
45
+ follow_redirect!
46
+ assert_response :success
47
+
48
+ assert_select 'div.alert-success' , 1
49
+ assert_select 'div.alert-danger' , 0
50
+
51
+ assert_select 'tbody tr' , 1
52
+ assert_equal 1 , Project . find ( id ) . scripts . length
53
+ assert_equal true , Project . find ( id ) . scripts [ 0 ] . is_a? ( MayaScript )
54
+ end
55
+ end
56
+
57
+ test 'vray project creates vray script' do
58
+ Dir . mktmpdir do |tmpdir |
59
+ id = new_project ( tmpdir , type : 'vray' )
60
+ get project_path ( id )
61
+ assert_response :success
62
+
63
+ get new_project_script_path ( id )
64
+ assert_response :success
65
+
66
+ post project_scripts_path ( id ) , params : script_params
67
+ follow_redirect!
68
+ assert_response :success
69
+
70
+ assert_select 'div.alert-success' , 1
71
+ assert_select 'div.alert-danger' , 0
72
+
73
+ assert_select 'tbody tr' , 1
74
+ assert_equal 1 , Project . find ( id ) . scripts . length
75
+ assert_equal true , Project . find ( id ) . scripts [ 0 ] . is_a? ( VRayScript )
76
+ end
77
+ end
78
+ end
0 commit comments