|
1033 | 1033 | RUBY |
1034 | 1034 | end |
1035 | 1035 | end |
| 1036 | + |
| 1037 | + context 'with redirect assertions' do |
| 1038 | + it 'registers an offense when using `assert_redirected_to` with a path' do |
| 1039 | + expect_offense(<<~RUBY) |
| 1040 | + assert_redirected_to '/users' |
| 1041 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(response).to redirect_to('/users')`. |
| 1042 | + RUBY |
| 1043 | + |
| 1044 | + expect_correction(<<~RUBY) |
| 1045 | + expect(response).to redirect_to('/users') |
| 1046 | + RUBY |
| 1047 | + end |
| 1048 | + |
| 1049 | + # rubocop:disable Layout/LineLength |
| 1050 | + it 'registers an offense when using `assert_redirected_to` with parentheses' do |
| 1051 | + # rubocop:enable Layout/LineLength |
| 1052 | + expect_offense(<<~RUBY) |
| 1053 | + assert_redirected_to('/users') |
| 1054 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(response).to redirect_to('/users')`. |
| 1055 | + RUBY |
| 1056 | + |
| 1057 | + expect_correction(<<~RUBY) |
| 1058 | + expect(response).to redirect_to('/users') |
| 1059 | + RUBY |
| 1060 | + end |
| 1061 | + |
| 1062 | + it 'registers an offense when using `assert_redirected_to` with ' \ |
| 1063 | + 'controller and action' do |
| 1064 | + expect_offense(<<~RUBY) |
| 1065 | + assert_redirected_to controller: 'users', action: 'show' |
| 1066 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(response).to redirect_to(controller: 'users', action: 'show')`. |
| 1067 | + RUBY |
| 1068 | + |
| 1069 | + expect_correction(<<~RUBY) |
| 1070 | + expect(response).to redirect_to(controller: 'users', action: 'show') |
| 1071 | + RUBY |
| 1072 | + end |
| 1073 | + |
| 1074 | + it 'registers an offense when using `assert_redirected_to` with ' \ |
| 1075 | + 'failure message' do |
| 1076 | + expect_offense(<<~RUBY) |
| 1077 | + assert_redirected_to '/users', "expected redirect to users" |
| 1078 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(response).to(redirect_to('/users'), "expected redirect to users")`. |
| 1079 | + RUBY |
| 1080 | + |
| 1081 | + expect_correction(<<~RUBY) |
| 1082 | + expect(response).to(redirect_to('/users'), "expected redirect to users") |
| 1083 | + RUBY |
| 1084 | + end |
| 1085 | + |
| 1086 | + it 'registers an offense when using `assert_redirected_to` with ' \ |
| 1087 | + 'multi-line arguments' do |
| 1088 | + expect_offense(<<~RUBY) |
| 1089 | + assert_redirected_to('/users', |
| 1090 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(response).to(redirect_to('/users'), "expected redirect to users")`. |
| 1091 | + "expected redirect to users") |
| 1092 | + RUBY |
| 1093 | + |
| 1094 | + expect_correction(<<~RUBY) |
| 1095 | + expect(response).to(redirect_to('/users'), "expected redirect to users") |
| 1096 | + RUBY |
| 1097 | + end |
| 1098 | + |
| 1099 | + it 'registers an offense when using `assert_redirected_to` with ' \ |
| 1100 | + 'a URL' do |
| 1101 | + expect_offense(<<~RUBY) |
| 1102 | + assert_redirected_to 'http://example.com/users' |
| 1103 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(response).to redirect_to('http://example.com/users')`. |
| 1104 | + RUBY |
| 1105 | + |
| 1106 | + expect_correction(<<~RUBY) |
| 1107 | + expect(response).to redirect_to('http://example.com/users') |
| 1108 | + RUBY |
| 1109 | + end |
| 1110 | + |
| 1111 | + it 'registers an offense when using `assert_redirected_to` with ' \ |
| 1112 | + 'a named route' do |
| 1113 | + expect_offense(<<~RUBY) |
| 1114 | + assert_redirected_to users_path |
| 1115 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(response).to redirect_to(users_path)`. |
| 1116 | + RUBY |
| 1117 | + |
| 1118 | + expect_correction(<<~RUBY) |
| 1119 | + expect(response).to redirect_to(users_path) |
| 1120 | + RUBY |
| 1121 | + end |
| 1122 | + |
| 1123 | + it 'does not register an offense when using ' \ |
| 1124 | + '`expect(response).to redirect_to`' do |
| 1125 | + expect_no_offenses(<<~RUBY) |
| 1126 | + expect(response).to redirect_to('/users') |
| 1127 | + RUBY |
| 1128 | + end |
| 1129 | + |
| 1130 | + it 'does not register an offense when using ' \ |
| 1131 | + '`expect(response).to redirect_to` with controller and action' do |
| 1132 | + expect_no_offenses(<<~RUBY) |
| 1133 | + expect(response).to redirect_to(controller: 'users', action: 'show') |
| 1134 | + RUBY |
| 1135 | + end |
| 1136 | + end |
1036 | 1137 | end |
0 commit comments