|
461 | 461 | end |
462 | 462 |
|
463 | 463 | describe '#edit_user_link' do |
464 | | - let(:current_user) { FactoryBot.create :user, email: 'admin@example.com' } |
465 | | - let(:gravatar_image_tag) { '<img alt="" src="https://secure.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=30" />' } |
466 | | - |
467 | | - subject { helper.edit_user_link } |
468 | | - |
469 | | - before do |
470 | | - expect(helper).to receive(:_current_user).at_least(:once) { current_user } |
| 464 | + it "don't include email column" do |
| 465 | + allow(helper).to receive(:_current_user).and_return(FactoryBot.create(:player)) |
| 466 | + result = helper.edit_user_link |
| 467 | + expect(result).to eq nil |
471 | 468 | end |
472 | 469 |
|
473 | | - context 'without email column' do |
474 | | - let(:current_user) { FactoryBot.create :player } |
475 | | - |
476 | | - it { should be_nil } |
| 470 | + it 'include email column' do |
| 471 | + allow(helper).to receive(:_current_user).and_return(FactoryBot.create(:user)) |
| 472 | + result = helper.edit_user_link |
| 473 | + expect(result).to match('href') |
477 | 474 | end |
478 | 475 |
|
479 | | - context 'gravatar enabled' do |
480 | | - before do |
481 | | - RailsAdmin.config { |config| config.show_gravatar = true } |
482 | | - end |
483 | | - |
484 | | - it { should match 'href' } |
485 | | - it { should match %r{href=".[^"]+/admin/user\?action_name=edit&id=#{current_user.id}"} } |
486 | | - |
487 | | - it { should include 'gravatar' } |
488 | | - it { should include gravatar_image_tag } |
489 | | - |
490 | | - it { should include current_user.email } |
| 476 | + it 'show gravatar' do |
| 477 | + allow(helper).to receive(:_current_user).and_return(FactoryBot.create(:user)) |
| 478 | + result = helper.edit_user_link |
| 479 | + expect(result).to include('gravatar') |
491 | 480 | end |
492 | 481 |
|
493 | | - context 'gravatar disabled' do |
494 | | - before do |
495 | | - RailsAdmin.config { |config| config.show_gravatar = false } |
| 482 | + it "don't show gravatar" do |
| 483 | + RailsAdmin.config do |config| |
| 484 | + config.show_gravatar = false |
496 | 485 | end |
497 | 486 |
|
498 | | - it { should_not include 'gravatar' } |
| 487 | + allow(helper).to receive(:_current_user).and_return(FactoryBot.create(:user)) |
| 488 | + result = helper.edit_user_link |
| 489 | + expect(result).not_to include('gravatar') |
499 | 490 | end |
500 | 491 |
|
501 | | - context 'when the user is not authorized to perform edit, gravatar enabled' do |
| 492 | + context 'when the user is not authorized to perform edit' do |
| 493 | + let(:user) { FactoryBot.create(:user) } |
502 | 494 | before do |
503 | | - RailsAdmin.config { |config| config.show_gravatar = true } |
504 | 495 | allow_any_instance_of(RailsAdmin::Config::Actions::Edit).to receive(:authorized?).and_return(false) |
| 496 | + allow(helper).to receive(:_current_user).and_return(user) |
505 | 497 | end |
506 | 498 |
|
507 | | - it { should_not match 'href' } |
508 | | - |
509 | | - it { should include 'gravatar' } |
510 | | - it { should include gravatar_image_tag } |
511 | | - |
512 | | - it { should include current_user.email } |
513 | | - end |
514 | | - |
515 | | - context 'when the user is not authorized to perform edit, gravatar disabled' do |
516 | | - before do |
517 | | - RailsAdmin.config { |config| config.show_gravatar = false } |
518 | | - allow_any_instance_of(RailsAdmin::Config::Actions::Edit).to receive(:authorized?).and_return(false) |
| 499 | + it 'show gravatar and email without a link' do |
| 500 | + result = helper.edit_user_link |
| 501 | + expect(result).to include('gravatar') |
| 502 | + expect(result).to include(user.email) |
| 503 | + expect(result).not_to match('href') |
519 | 504 | end |
520 | 505 |
|
521 | | - it { should_not match 'href' } |
522 | | - |
523 | | - it { should_not include 'gravatar' } |
| 506 | + it 'without gravatar and email without a link' do |
| 507 | + RailsAdmin.config do |config| |
| 508 | + config.show_gravatar = false |
| 509 | + end |
524 | 510 |
|
525 | | - it { should include current_user.email } |
526 | | - it { should include "<span>#{current_user.email}</span>" } |
| 511 | + result = helper.edit_user_link |
| 512 | + expect(result).not_to include('gravatar') |
| 513 | + expect(result).not_to match('href') |
| 514 | + expect(result).to include(user.email) |
| 515 | + expect(result).to match('<span class="nav-link"><span>'+user.email+'</span></span>') |
| 516 | + end |
527 | 517 | end |
528 | 518 | end |
529 | 519 | end |
|
0 commit comments