|
322 | 322 | RUBY
|
323 | 323 | end
|
324 | 324 | end
|
| 325 | + |
| 326 | + context 'when using File.join with a local variable' do |
| 327 | + it 'does not register an offense' do |
| 328 | + expect_no_offenses(<<~RUBY) |
| 329 | + default_path = '/models' |
| 330 | + File.join(Rails.root, 'app', default_path) |
| 331 | + RUBY |
| 332 | + end |
| 333 | + end |
| 334 | + |
| 335 | + context 'when using File.join with an instance variable' do |
| 336 | + it 'does not register an offense' do |
| 337 | + expect_no_offenses(<<~RUBY) |
| 338 | + File.join(Rails.root, 'app', @default_path) |
| 339 | + RUBY |
| 340 | + end |
| 341 | + end |
| 342 | + |
| 343 | + context 'when using File.join with a class variable' do |
| 344 | + it 'does not register an offense' do |
| 345 | + expect_no_offenses(<<~RUBY) |
| 346 | + File.join(Rails.root, 'app', @@default_path) |
| 347 | + RUBY |
| 348 | + end |
| 349 | + end |
| 350 | + |
| 351 | + context 'when using File.join with a global variable' do |
| 352 | + it 'does not register an offense' do |
| 353 | + expect_no_offenses(<<~RUBY) |
| 354 | + File.join(Rails.root, 'app', $default_path) |
| 355 | + RUBY |
| 356 | + end |
| 357 | + end |
| 358 | + |
| 359 | + context 'when using File.join with a constant' do |
| 360 | + it 'does not register an offense' do |
| 361 | + expect_no_offenses(<<~RUBY) |
| 362 | + File.join(Rails.root, 'app', DEFAULT_PATH) |
| 363 | + RUBY |
| 364 | + end |
| 365 | + end |
| 366 | + |
| 367 | + context 'when using Rails.root.join with a local variable' do |
| 368 | + it 'does not register an offense' do |
| 369 | + expect_no_offenses(<<~RUBY) |
| 370 | + default_path = '/models' |
| 371 | + Rails.root.join(Rails.root, 'app', default_path) |
| 372 | + RUBY |
| 373 | + end |
| 374 | + end |
| 375 | + |
| 376 | + context 'when using Rails.root.join with an instance variable' do |
| 377 | + it 'does not register an offense' do |
| 378 | + expect_no_offenses(<<~RUBY) |
| 379 | + Rails.root.join(Rails.root, 'app', @default_path) |
| 380 | + RUBY |
| 381 | + end |
| 382 | + end |
| 383 | + |
| 384 | + context 'when using Rails.root.join with a class variable' do |
| 385 | + it 'does not register an offense' do |
| 386 | + expect_no_offenses(<<~RUBY) |
| 387 | + Rails.root.join(Rails.root, 'app', @@default_path) |
| 388 | + RUBY |
| 389 | + end |
| 390 | + end |
| 391 | + |
| 392 | + context 'when using Rails.root.join with a global variable' do |
| 393 | + it 'does not register an offense' do |
| 394 | + expect_no_offenses(<<~RUBY) |
| 395 | + Rails.root.join(Rails.root, 'app', $default_path) |
| 396 | + RUBY |
| 397 | + end |
| 398 | + end |
| 399 | + |
| 400 | + context 'when using Rails.root.join with a constant' do |
| 401 | + it 'does not register an offense' do |
| 402 | + expect_no_offenses(<<~RUBY) |
| 403 | + Rails.root.join(Rails.root, 'app', DEFAULT_PATH) |
| 404 | + RUBY |
| 405 | + end |
| 406 | + end |
| 407 | + |
| 408 | + context 'when using Rails.root.join with a leading slash' do |
| 409 | + it 'does not register an offense' do |
| 410 | + expect_no_offenses(<<~RUBY) |
| 411 | + Rails.root.join('/app/models') |
| 412 | + RUBY |
| 413 | + end |
| 414 | + end |
| 415 | + |
| 416 | + context 'when using Rails.root.join with mixed leading and normal path strings' do |
| 417 | + it 'does not register an offense' do |
| 418 | + expect_no_offenses(<<~RUBY) |
| 419 | + Rails.root.join('/app', 'models') |
| 420 | + RUBY |
| 421 | + end |
| 422 | + end |
| 423 | + |
| 424 | + context 'when using Rails.root.join with mixed normal and leading path strings' do |
| 425 | + it 'does not register an offense' do |
| 426 | + expect_no_offenses(<<~RUBY) |
| 427 | + Rails.root.join('app', '/models') |
| 428 | + RUBY |
| 429 | + end |
| 430 | + end |
| 431 | + |
| 432 | + context 'when using Rails.root.join with multiple slashes in a path' do |
| 433 | + it 'does not register an offense' do |
| 434 | + expect_no_offenses(<<~RUBY) |
| 435 | + Rails.root.join('public//', 'assets') |
| 436 | + RUBY |
| 437 | + end |
| 438 | + end |
| 439 | + |
| 440 | + context 'when using File.join with multiple slashes in a path' do |
| 441 | + it 'does not register an offense' do |
| 442 | + expect_no_offenses(<<~RUBY) |
| 443 | + File.join(Rails.root, 'public//', 'assets') |
| 444 | + RUBY |
| 445 | + end |
| 446 | + end |
325 | 447 | end
|
326 | 448 |
|
327 | 449 | context 'when EnforcedStyle is `arguments`' do
|
|
592 | 714 | RUBY
|
593 | 715 | end
|
594 | 716 | end
|
| 717 | + |
| 718 | + context 'when using Rails.root.join with a leading slash' do |
| 719 | + it 'does not register an offense' do |
| 720 | + expect_no_offenses(<<~RUBY) |
| 721 | + Rails.root.join('/app/models') |
| 722 | + RUBY |
| 723 | + end |
| 724 | + end |
| 725 | + |
| 726 | + context 'when using Rails.root.join with mixed leading and normal path strings' do |
| 727 | + it 'does not register an offense' do |
| 728 | + expect_no_offenses(<<~RUBY) |
| 729 | + Rails.root.join('/app', 'models') |
| 730 | + RUBY |
| 731 | + end |
| 732 | + end |
| 733 | + |
| 734 | + context 'when using Rails.root.join with mixed normal and leading path strings' do |
| 735 | + it 'does not register an offense' do |
| 736 | + expect_no_offenses(<<~RUBY) |
| 737 | + Rails.root.join('app', '/models') |
| 738 | + RUBY |
| 739 | + end |
| 740 | + end |
| 741 | + |
| 742 | + context 'when using Rails.root.join with multiple slashes in a path' do |
| 743 | + it 'does not register an offense' do |
| 744 | + expect_no_offenses(<<~RUBY) |
| 745 | + Rails.root.join('public//', 'assets') |
| 746 | + RUBY |
| 747 | + end |
| 748 | + end |
| 749 | + |
| 750 | + context 'when using File.join with multiple slashes in a path' do |
| 751 | + it 'does not register an offense' do |
| 752 | + expect_no_offenses(<<~RUBY) |
| 753 | + File.join(Rails.root, 'public//', 'assets') |
| 754 | + RUBY |
| 755 | + end |
| 756 | + end |
595 | 757 | end
|
596 | 758 | end
|
0 commit comments