Skip to content

Commit

Permalink
add some script tests (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
johrstrom authored Sep 13, 2021
1 parent 570cfc8 commit 2da001f
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions test/integration/scripts_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# frozen_string_literal: true

require 'test_helper'

class ProjectsTest < ActionDispatch::IntegrationTest
def new_project(dir, type: 'Maya')
params = {
project: {
name: ('a'..'z').to_a.shuffle[0,8].join,
description: 'test project',
directory: dir,
project_type: type
}
}

post projects_path, params: params
# for some reason you need to get the id before you follow redirect
id = @response.location.to_s.split('/').last

follow_redirect!
assert_response :success

id
end

def script_params(overrides: {})
# TODO: looks like the controller only validates the frames. everything else is required in the js
{
script: {
frames: '1-10'
}.deep_merge!(overrides)
}
end

test 'maya project creates maya script' do
Dir.mktmpdir do |tmpdir|
id = new_project(tmpdir)
get project_path(id)
assert_response :success

get new_project_script_path(id)
assert_response :success

post project_scripts_path(id), params: script_params
follow_redirect!
assert_response :success

assert_select 'div.alert-success', 1
assert_select 'div.alert-danger', 0

assert_select 'tbody tr', 1
assert_equal 1, Project.find(id).scripts.length
assert_equal true, Project.find(id).scripts[0].is_a?(MayaScript)
end
end

test 'vray project creates vray script' do
Dir.mktmpdir do |tmpdir|
id = new_project(tmpdir, type: 'vray')
get project_path(id)
assert_response :success

get new_project_script_path(id)
assert_response :success

post project_scripts_path(id), params: script_params
follow_redirect!
assert_response :success

assert_select 'div.alert-success', 1
assert_select 'div.alert-danger', 0

assert_select 'tbody tr', 1
assert_equal 1, Project.find(id).scripts.length
assert_equal true, Project.find(id).scripts[0].is_a?(VRayScript)
end
end
end

0 comments on commit 2da001f

Please sign in to comment.