|
444 | 444 | RUBY
|
445 | 445 | end
|
446 | 446 | end
|
| 447 | + |
| 448 | + context 'when File.join wraps Rails.root.join with string arguments' do |
| 449 | + it 'registers an offense once' do |
| 450 | + expect_offense(<<~RUBY) |
| 451 | + File.join(Rails.root.join('app', 'models'), 'user.rb') |
| 452 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to').to_s`. |
| 453 | + RUBY |
| 454 | + |
| 455 | + expect_correction(<<~RUBY) |
| 456 | + Rails.root.join('app/models/user.rb').to_s |
| 457 | + RUBY |
| 458 | + end |
| 459 | + end |
| 460 | + |
| 461 | + context 'when File.join wraps Rails.root.join with non-string arguments' do |
| 462 | + it 'registers an offense once' do |
| 463 | + expect_offense(<<~RUBY) |
| 464 | + File.join(Rails.root.join('app/models'), 'user.rb') |
| 465 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to').to_s`. |
| 466 | + RUBY |
| 467 | + |
| 468 | + expect_correction(<<~RUBY) |
| 469 | + Rails.root.join('app/models/user.rb').to_s |
| 470 | + RUBY |
| 471 | + end |
| 472 | + end |
| 473 | + |
| 474 | + context 'when File.join wraps Rails.root.join with non-string arguments and path starting with `/`' do |
| 475 | + it 'registers an offense once' do |
| 476 | + expect_offense(<<~RUBY) |
| 477 | + File.join(Rails.root.join('app/models'), '/vehicle' '/car.rb') |
| 478 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to').to_s`. |
| 479 | + RUBY |
| 480 | + |
| 481 | + expect_correction(<<~RUBY) |
| 482 | + Rails.root.join('app/models/vehicle/car.rb').to_s |
| 483 | + RUBY |
| 484 | + end |
| 485 | + end |
| 486 | + |
| 487 | + context 'when File.join wraps Rails.root.join with string arguments and .to_s' do |
| 488 | + it 'registers an offense once' do |
| 489 | + expect_offense(<<~RUBY) |
| 490 | + File.join(Rails.root.join('app', 'models').to_s, 'user.rb') |
| 491 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to').to_s`. |
| 492 | + RUBY |
| 493 | + |
| 494 | + expect_correction(<<~RUBY) |
| 495 | + Rails.root.join('app/models/user.rb').to_s |
| 496 | + RUBY |
| 497 | + end |
| 498 | + end |
| 499 | + |
| 500 | + context 'when File.join wraps Rails.root.join with non-string arguments and .to_s' do |
| 501 | + it 'registers an offense once' do |
| 502 | + expect_offense(<<~RUBY) |
| 503 | + File.join(Rails.root.join('app/models').to_s, 'user.rb') |
| 504 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to').to_s`. |
| 505 | + RUBY |
| 506 | + |
| 507 | + expect_correction(<<~RUBY) |
| 508 | + Rails.root.join('app/models/user.rb').to_s |
| 509 | + RUBY |
| 510 | + end |
| 511 | + end |
| 512 | + |
| 513 | + context 'when File.join wraps Rails.root.join with non-string arguments and path starting with `/` and .to_s' do |
| 514 | + it 'registers an offense once' do |
| 515 | + expect_offense(<<~RUBY) |
| 516 | + File.join(Rails.root.join('app/models').to_s, '/vehicle' '/car.rb') |
| 517 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to').to_s`. |
| 518 | + RUBY |
| 519 | + |
| 520 | + expect_correction(<<~RUBY) |
| 521 | + Rails.root.join('app/models/vehicle/car.rb').to_s |
| 522 | + RUBY |
| 523 | + end |
| 524 | + end |
| 525 | + |
| 526 | + context 'when using nested File.join with Rails.root with string arguments' do |
| 527 | + it 'registers an offense once' do |
| 528 | + expect_offense(<<~RUBY) |
| 529 | + File.join(File.join(Rails.root, 'app', 'models'), 'user.rb') |
| 530 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to').to_s`. |
| 531 | + RUBY |
| 532 | + |
| 533 | + expect_correction(<<~RUBY) |
| 534 | + Rails.root.join('app/models/user.rb').to_s |
| 535 | + RUBY |
| 536 | + end |
| 537 | + end |
| 538 | + |
| 539 | + context 'when using nested File.join with Rails.root with non-string arguments' do |
| 540 | + it 'registers an offense once' do |
| 541 | + expect_offense(<<~RUBY) |
| 542 | + File.join(File.join(Rails.root, 'app/models'), 'user.rb') |
| 543 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to').to_s`. |
| 544 | + RUBY |
| 545 | + |
| 546 | + expect_correction(<<~RUBY) |
| 547 | + Rails.root.join('app/models/user.rb').to_s |
| 548 | + RUBY |
| 549 | + end |
| 550 | + end |
| 551 | + |
| 552 | + context 'when using nested File.join with Rails.root with non-string arguments and path starting with `/`' do |
| 553 | + it 'registers an offense once' do |
| 554 | + expect_offense(<<~RUBY) |
| 555 | + File.join(File.join(Rails.root, '/app/models'), '/user.rb') |
| 556 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to').to_s`. |
| 557 | + RUBY |
| 558 | + |
| 559 | + expect_correction(<<~RUBY) |
| 560 | + Rails.root.join('app/models/user.rb').to_s |
| 561 | + RUBY |
| 562 | + end |
| 563 | + end |
447 | 564 | end
|
448 | 565 |
|
449 | 566 | context 'when EnforcedStyle is `arguments`' do
|
|
754 | 871 | RUBY
|
755 | 872 | end
|
756 | 873 | end
|
| 874 | + |
| 875 | + context 'when File.join wraps Rails.root.join with string arguments' do |
| 876 | + it 'registers an offense once' do |
| 877 | + expect_offense(<<~RUBY) |
| 878 | + File.join(Rails.root.join('app', 'models'), 'user.rb') |
| 879 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to').to_s`. |
| 880 | + RUBY |
| 881 | + |
| 882 | + expect_correction(<<~RUBY) |
| 883 | + Rails.root.join('app', 'models', 'user.rb').to_s |
| 884 | + RUBY |
| 885 | + end |
| 886 | + end |
| 887 | + |
| 888 | + context 'when File.join wraps Rails.root.join with non-string arguments' do |
| 889 | + it 'registers an offense once' do |
| 890 | + expect_offense(<<~RUBY) |
| 891 | + File.join(Rails.root.join('app/models'), 'user.rb') |
| 892 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to').to_s`. |
| 893 | + RUBY |
| 894 | + |
| 895 | + expect_correction(<<~RUBY) |
| 896 | + Rails.root.join('app', "models", 'user.rb').to_s |
| 897 | + RUBY |
| 898 | + end |
| 899 | + end |
| 900 | + |
| 901 | + context 'when File.join wraps Rails.root.join with non-string arguments and path starting with `/`' do |
| 902 | + it 'registers an offense once' do |
| 903 | + expect_offense(<<~RUBY) |
| 904 | + File.join(Rails.root.join('app/models'), '/vehicle' '/car.rb') |
| 905 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to').to_s`. |
| 906 | + RUBY |
| 907 | + |
| 908 | + expect_correction(<<~RUBY) |
| 909 | + Rails.root.join('app', "models", 'vehicle', 'car.rb').to_s |
| 910 | + RUBY |
| 911 | + end |
| 912 | + end |
| 913 | + |
| 914 | + context 'when File.join wraps Rails.root.join with string arguments and .to_s' do |
| 915 | + it 'registers an offense once' do |
| 916 | + expect_offense(<<~RUBY) |
| 917 | + File.join(Rails.root.join('app', 'models').to_s, 'user.rb') |
| 918 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to').to_s`. |
| 919 | + RUBY |
| 920 | + |
| 921 | + expect_correction(<<~RUBY) |
| 922 | + Rails.root.join('app', 'models', 'user.rb').to_s |
| 923 | + RUBY |
| 924 | + end |
| 925 | + end |
| 926 | + |
| 927 | + context 'when File.join wraps Rails.root.join with non-string arguments and .to_s' do |
| 928 | + it 'registers an offense once' do |
| 929 | + expect_offense(<<~RUBY) |
| 930 | + File.join(Rails.root.join('app/models').to_s, 'user.rb') |
| 931 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to').to_s`. |
| 932 | + RUBY |
| 933 | + |
| 934 | + expect_correction(<<~RUBY) |
| 935 | + Rails.root.join('app', "models", 'user.rb').to_s |
| 936 | + RUBY |
| 937 | + end |
| 938 | + end |
| 939 | + |
| 940 | + context 'when File.join wraps Rails.root.join with non-string arguments and path starting with `/` and .to_s' do |
| 941 | + it 'registers an offense once' do |
| 942 | + expect_offense(<<~RUBY) |
| 943 | + File.join(Rails.root.join('app/models').to_s, '/vehicle' '/car.rb') |
| 944 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to').to_s`. |
| 945 | + RUBY |
| 946 | + |
| 947 | + expect_correction(<<~RUBY) |
| 948 | + Rails.root.join('app', "models", 'vehicle', 'car.rb').to_s |
| 949 | + RUBY |
| 950 | + end |
| 951 | + end |
| 952 | + |
| 953 | + context 'when using nested File.join with Rails.root with string arguments' do |
| 954 | + it 'registers an offense once' do |
| 955 | + expect_offense(<<~RUBY) |
| 956 | + File.join(File.join(Rails.root, 'app', 'models'), 'user.rb') |
| 957 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to').to_s`. |
| 958 | + RUBY |
| 959 | + |
| 960 | + expect_correction(<<~RUBY) |
| 961 | + Rails.root.join("app", "models", 'user.rb').to_s |
| 962 | + RUBY |
| 963 | + end |
| 964 | + end |
| 965 | + |
| 966 | + context 'when using nested File.join with Rails.root with non-string arguments' do |
| 967 | + it 'registers an offense once' do |
| 968 | + expect_offense(<<~RUBY) |
| 969 | + File.join(File.join(Rails.root, 'app/models'), 'user.rb') |
| 970 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to').to_s`. |
| 971 | + RUBY |
| 972 | + |
| 973 | + expect_correction(<<~RUBY) |
| 974 | + Rails.root.join("app", "models", 'user.rb').to_s |
| 975 | + RUBY |
| 976 | + end |
| 977 | + end |
| 978 | + |
| 979 | + context 'when using nested File.join with Rails.root with non-string arguments and path starting with `/`' do |
| 980 | + it 'registers an offense once' do |
| 981 | + expect_offense(<<~RUBY) |
| 982 | + File.join(File.join(Rails.root, '/app/models'), '/user.rb') |
| 983 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to').to_s`. |
| 984 | + RUBY |
| 985 | + |
| 986 | + expect_correction(<<~RUBY) |
| 987 | + Rails.root.join("app", "models", 'user.rb').to_s |
| 988 | + RUBY |
| 989 | + end |
| 990 | + end |
757 | 991 | end
|
758 | 992 | end
|
0 commit comments