|
19 | 19 | RUBY
|
20 | 20 | end
|
21 | 21 |
|
| 22 | + it 'registers an offense and corrects it with comment-like string and identifiers' do |
| 23 | + expect_offense(<<~RUBY) |
| 24 | + <<~SQL |
| 25 | + ^^^^^^ Use `<<~SQL.squish` instead of `<<~SQL`. |
| 26 | + SELECT * FROM posts |
| 27 | + WHERE [--another identifier!] = 1 |
| 28 | + AND "-- this is a name, not a comment" = '-- this is a string, not a comment' |
| 29 | + SQL |
| 30 | + RUBY |
| 31 | + |
| 32 | + expect_correction(<<~RUBY) |
| 33 | + <<~SQL.squish |
| 34 | + SELECT * FROM posts |
| 35 | + WHERE [--another identifier!] = 1 |
| 36 | + AND "-- this is a name, not a comment" = '-- this is a string, not a comment' |
| 37 | + SQL |
| 38 | + RUBY |
| 39 | + end |
| 40 | + |
22 | 41 | it 'does not register an offense' do
|
23 | 42 | expect_no_offenses(<<~RUBY)
|
24 | 43 | <<-SQL.squish
|
|
27 | 46 | SQL
|
28 | 47 | RUBY
|
29 | 48 | end
|
| 49 | + |
| 50 | + it 'does not register an offense due to comments' do |
| 51 | + expect_no_offenses(<<~RUBY) |
| 52 | + <<-SQL |
| 53 | + SELECT * FROM posts |
| 54 | + -- This is a comment, so squish can't be used |
| 55 | + WHERE id = 1 |
| 56 | + SQL |
| 57 | + RUBY |
| 58 | + end |
30 | 59 | end
|
31 | 60 |
|
32 | 61 | context 'with single line heredoc' do
|
|
45 | 74 | RUBY
|
46 | 75 | end
|
47 | 76 |
|
| 77 | + it 'registers an offense and corrects it with comment-like string and identifiers' do |
| 78 | + expect_offense(<<~RUBY) |
| 79 | + <<~SQL |
| 80 | + ^^^^^^ Use `<<~SQL.squish` instead of `<<~SQL`. |
| 81 | + SELECT * FROM posts WHERE [--another identifier!] = 1 AND "-- this is a name, not a comment" = '-- this is a string, not a comment'; |
| 82 | + SQL |
| 83 | + RUBY |
| 84 | + |
| 85 | + expect_correction(<<~RUBY) |
| 86 | + <<~SQL.squish |
| 87 | + SELECT * FROM posts WHERE [--another identifier!] = 1 AND "-- this is a name, not a comment" = '-- this is a string, not a comment'; |
| 88 | + SQL |
| 89 | + RUBY |
| 90 | + end |
| 91 | + |
48 | 92 | it 'does not register an offense' do
|
49 | 93 | expect_no_offenses(<<~RUBY)
|
50 | 94 | <<-SQL.squish
|
51 | 95 | SELECT * FROM posts;
|
52 | 96 | SQL
|
53 | 97 | RUBY
|
54 | 98 | end
|
| 99 | + |
| 100 | + it 'does not register an offense due to comments' do |
| 101 | + expect_no_offenses(<<~RUBY) |
| 102 | + <<-SQL |
| 103 | + -- This is a comment, so squish can't be used |
| 104 | + SQL |
| 105 | + RUBY |
| 106 | + end |
55 | 107 | end
|
56 | 108 |
|
57 | 109 | context 'with heredocs as method parameters' do
|
|
72 | 124 | RUBY
|
73 | 125 | end
|
74 | 126 |
|
| 127 | + it 'registers an offense and corrects it with comment-like string and identifiers' do |
| 128 | + expect_offense(<<~RUBY) |
| 129 | + execute(<<~SQL, "Post Load") |
| 130 | + ^^^^^^ Use `<<~SQL.squish` instead of `<<~SQL`. |
| 131 | + SELECT * FROM posts |
| 132 | + WHERE [--another identifier!] = 1 |
| 133 | + AND "-- this is a name, not a comment" = '-- this is a string, not a comment' |
| 134 | + SQL |
| 135 | + RUBY |
| 136 | + |
| 137 | + expect_correction(<<~RUBY) |
| 138 | + execute(<<~SQL.squish, "Post Load") |
| 139 | + SELECT * FROM posts |
| 140 | + WHERE [--another identifier!] = 1 |
| 141 | + AND "-- this is a name, not a comment" = '-- this is a string, not a comment' |
| 142 | + SQL |
| 143 | + RUBY |
| 144 | + end |
| 145 | + |
75 | 146 | it 'does not register an offense' do
|
76 | 147 | expect_no_offenses(<<~RUBY)
|
77 | 148 | execute(<<~SQL.squish, "Post Load")
|
|
80 | 151 | SQL
|
81 | 152 | RUBY
|
82 | 153 | end
|
| 154 | + |
| 155 | + it 'does not register an offense due to comments' do |
| 156 | + expect_no_offenses(<<~RUBY) |
| 157 | + execute(<<-SQL, "Post Load") |
| 158 | + SELECT * FROM posts |
| 159 | + -- This is a comment, so squish can't be used |
| 160 | + WHERE post_id = 1 |
| 161 | + SQL |
| 162 | + RUBY |
| 163 | + end |
83 | 164 | end
|
84 | 165 | end
|
0 commit comments