File: statics_controller_test.rb

package info (click to toggle)
ruby-graphql 2.5.19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,868 kB
  • sloc: ruby: 80,420; ansic: 1,808; yacc: 845; javascript: 480; makefile: 6
file content (31 lines) | stat: -rw-r--r-- 1,094 bytes parent folder | download
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
# frozen_string_literal: true
require "test_helper"

class DashboardStaticsControllerTest < ActionDispatch::IntegrationTest
  def test_it_serves_assets
    get graphql_dashboard.static_path("dashboard.css")
    assert_includes response.body, "#header-icon {"
    assert_equal response.headers["Cache-Control"], "max-age=31556952, public"
  end

  def test_it_doesnt_trigger_csrf_failure
    original_forgery_protection = ActionController::Base.allow_forgery_protection
    ActionController::Base.allow_forgery_protection = true
    get graphql_dashboard.static_path("dashboard.js")
    assert_equal 200, response.status
  ensure
    ActionController::Base.allow_forgery_protection = original_forgery_protection
  end

  def test_it_responds_404_for_others
    get graphql_dashboard.static_path("other.rb")
    assert_equal 404, response.status

    assert_raises ActionController::UrlGenerationError do
      graphql_dashboard.static_path("invalid~char.js")
    end

    get graphql_dashboard.static_path("invalid-char.js").sub("-char", "~char")
    assert_equal 404, response.status
  end
end