-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathuser_scripts_controller_test.rb
50 lines (44 loc) · 1.77 KB
/
user_scripts_controller_test.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
require 'test_helper'
class UserScriptsControllerTest < ActionDispatch::IntegrationTest
include ActiveJob::TestHelper
test 'anon users are prompted to login' do
get '/user-scripts'
assert_response :success
assert_includes response.body, I18n.t('user_scripts.index.login_required')
end
test "untrusted logged-in users can't see form to submit scripts" do
sign_in
get '/user-scripts'
assert_response :forbidden
assert_includes response.body, I18n.t('user_scripts.index.not_enough_permissions')
end
test 'trusted users can see form' do
sign_in trusted: true
get '/user-scripts'
assert_response :success
assert_includes response.body, I18n.t('user_scripts.index.script_url')
assert_includes response.body, I18n.t('user_scripts.index.script_name')
end
test "untrusted users can't POST to #create" do
sign_in
post '/user-scripts.json', params: { name: 'some_benchmark', url: 'http://script.com', sha: 'asdsadsad' }
assert_response :forbidden
assert_equal BenchmarkType.where(category: 'some_benchmark', from_user: true).count, 0
end
test 'trusted users can POST to #create' do
sign_in trusted: true
Net::HTTP.stubs(:get).returns(<<~RUBY)
def xzczx
puts 45
end
RUBY
assert_enqueued_with(job: RunUserBench) do
VCR.use_cassette('github ruby 6ffef8d459') do
post '/user-scripts.json', params: { name: 'some_benchmark', url: 'http://script.com/script.rb', sha: '6ffef8d459' }
end
end
assert_response :success
assert_equal response.body, I18n.t('user_scripts.index.successful_submit', links: '<a href="/ruby/ruby/commits?result_type=some_benchmark">some_benchmark</a>')
assert_equal BenchmarkType.where(category: 'some_benchmark', from_user: true).count, 1
end
end