|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +RSpec.describe RuboCop::Cop::Rails::UnusedRenderContent, :config do |
| 4 | + it 'does not register an offense when specifying body content with a status that takes a body' do |
| 5 | + expect_no_offenses(<<~RUBY) |
| 6 | + render status: :ok, plain: 'Ruby!' |
| 7 | + RUBY |
| 8 | + end |
| 9 | + |
| 10 | + it 'does not register an offense when no body content is specified with a status that does not take a body' do |
| 11 | + expect_no_offenses(<<~RUBY) |
| 12 | + render status: :no_content |
| 13 | + RUBY |
| 14 | + end |
| 15 | + |
| 16 | + it 'registers an offense when specifying status: :continue and a positional string argument' do |
| 17 | + expect_offense(<<~RUBY) |
| 18 | + render 'foo', status: :continue |
| 19 | + ^^^^^ Do not specify body content for a response with a non-content status code |
| 20 | + RUBY |
| 21 | + end |
| 22 | + |
| 23 | + it 'registers an offense when specifying status: :switching_protocols and a positional symbol argument across ' \ |
| 24 | + 'multiple lines' do |
| 25 | + expect_offense(<<~RUBY) |
| 26 | + render( |
| 27 | + :foo, |
| 28 | + ^^^^ Do not specify body content for a response with a non-content status code |
| 29 | + status: :switching_protocols |
| 30 | + ) |
| 31 | + RUBY |
| 32 | + end |
| 33 | + |
| 34 | + it 'registers an offense when specifying status: :processing and an :action option as the last argument' do |
| 35 | + expect_offense(<<~RUBY) |
| 36 | + render status: :processing, action: :foo |
| 37 | + ^^^^^^^^^^^^ Do not specify body content for a response with a non-content status code |
| 38 | + RUBY |
| 39 | + end |
| 40 | + |
| 41 | + it 'registers an offense when specifying status: :early_hints and a :body option as the first argument' do |
| 42 | + expect_offense(<<~RUBY) |
| 43 | + render body: 'foo', status: :early_hints |
| 44 | + ^^^^^^^^^^^ Do not specify body content for a response with a non-content status code |
| 45 | + RUBY |
| 46 | + end |
| 47 | + |
| 48 | + it 'registers an offense when specifying status: :no_content and a :content_type option between other options' do |
| 49 | + expect_offense(<<~RUBY) |
| 50 | + render status: :no_content, content_type: 'foo', another: 'option' |
| 51 | + ^^^^^^^^^^^^^^^^^^^ Do not specify body content for a response with a non-content status code |
| 52 | + RUBY |
| 53 | + end |
| 54 | + |
| 55 | + it 'registers an offense when specifying status: :reset_content and a :file option' do |
| 56 | + expect_offense(<<~RUBY) |
| 57 | + render status: :reset_content, file: 'foo' |
| 58 | + ^^^^^^^^^^^ Do not specify body content for a response with a non-content status code |
| 59 | + RUBY |
| 60 | + end |
| 61 | + |
| 62 | + it 'registers an offense when specifying status: :not_modified and a :html option' do |
| 63 | + expect_offense(<<~RUBY) |
| 64 | + render status: :not_modified, html: 'foo' |
| 65 | + ^^^^^^^^^^^ Do not specify body content for a response with a non-content status code |
| 66 | + RUBY |
| 67 | + end |
| 68 | + |
| 69 | + it 'registers an offense when specifying status: 100 and a :inline option' do |
| 70 | + expect_offense(<<~RUBY) |
| 71 | + render status: 100, inline: 'foo' |
| 72 | + ^^^^^^^^^^^^^ Do not specify body content for a response with a non-content status code |
| 73 | + RUBY |
| 74 | + end |
| 75 | + |
| 76 | + it 'registers an offense when specifying status: 101 and a :json option' do |
| 77 | + expect_offense(<<~RUBY) |
| 78 | + render status: 101, json: 'foo' |
| 79 | + ^^^^^^^^^^^ Do not specify body content for a response with a non-content status code |
| 80 | + RUBY |
| 81 | + end |
| 82 | + |
| 83 | + it 'registers an offense when specifying status: 102 and a :js option' do |
| 84 | + expect_offense(<<~RUBY) |
| 85 | + render status: 102, js: 'foo' |
| 86 | + ^^^^^^^^^ Do not specify body content for a response with a non-content status code |
| 87 | + RUBY |
| 88 | + end |
| 89 | + |
| 90 | + it 'registers an offense when specifying status: 103 and a :layout option' do |
| 91 | + expect_offense(<<~RUBY) |
| 92 | + render status: 103, layout: 'foo' |
| 93 | + ^^^^^^^^^^^^^ Do not specify body content for a response with a non-content status code |
| 94 | + RUBY |
| 95 | + end |
| 96 | + |
| 97 | + it 'registers an offense when specifying status: 204 and a :plain option' do |
| 98 | + expect_offense(<<~RUBY) |
| 99 | + render status: 204, plain: 'foo' |
| 100 | + ^^^^^^^^^^^^ Do not specify body content for a response with a non-content status code |
| 101 | + RUBY |
| 102 | + end |
| 103 | + |
| 104 | + it 'registers an offense when specifying status: 205 and a :raw option' do |
| 105 | + expect_offense(<<~RUBY) |
| 106 | + render status: 205, raw: 'foo' |
| 107 | + ^^^^^^^^^^ Do not specify body content for a response with a non-content status code |
| 108 | + RUBY |
| 109 | + end |
| 110 | + |
| 111 | + it 'registers an offense when specifying status: 304 and a :template option' do |
| 112 | + expect_offense(<<~RUBY) |
| 113 | + render status: 304, template: 'foo' |
| 114 | + ^^^^^^^^^^^^^^^ Do not specify body content for a response with a non-content status code |
| 115 | + RUBY |
| 116 | + end |
| 117 | + |
| 118 | + it 'registers an offense when specifying status: 304 and a :text option' do |
| 119 | + expect_offense(<<~RUBY) |
| 120 | + render status: 304, text: 'foo' |
| 121 | + ^^^^^^^^^^^ Do not specify body content for a response with a non-content status code |
| 122 | + RUBY |
| 123 | + end |
| 124 | + |
| 125 | + it 'registers an offense when specifying status: 304 and a :xml option' do |
| 126 | + expect_offense(<<~RUBY) |
| 127 | + render status: 304, xml: 'foo' |
| 128 | + ^^^^^^^^^^ Do not specify body content for a response with a non-content status code |
| 129 | + RUBY |
| 130 | + end |
| 131 | +end |
0 commit comments