|
1 |
| -require 'spec_helper' |
| 1 | +require "spec_helper" |
2 | 2 |
|
3 | 3 | describe AbuseReport do
|
4 | 4 | context "when report is not spam" do
|
|
9 | 9 | end
|
10 | 10 |
|
11 | 11 | context "comment missing" do
|
12 |
| - let(:report_without_comment) {build(:abuse_report, comment: nil)} |
| 12 | + let(:report_without_comment) { build(:abuse_report, comment: nil) } |
13 | 13 | it "is invalid" do
|
14 | 14 | expect(report_without_comment.save).to be_falsey
|
15 | 15 | expect(report_without_comment.errors[:comment]).not_to be_empty
|
|
328 | 328 |
|
329 | 329 | context "when report is spam" do
|
330 | 330 | let(:legit_user) { create(:user) }
|
331 |
| - let(:spam_report) { build(:abuse_report, username: 'viagra-test-123') } |
332 |
| - let!(:safe_report) { build(:abuse_report, username: 'viagra-test-123', email: legit_user.email) } |
| 331 | + let(:spam_report) { build(:abuse_report, username: "viagra-test-123") } |
| 332 | + let!(:safe_report) { build(:abuse_report, username: "viagra-test-123", email: legit_user.email) } |
333 | 333 |
|
334 | 334 | before do
|
335 | 335 | allow(Akismetor).to receive(:spam?).and_return(true)
|
|
380 | 380 | .to have_enqueued_job
|
381 | 381 | end
|
382 | 382 | end
|
| 383 | + |
| 384 | + describe "#creator_ids" do |
| 385 | + it "returns no creator ids for non-work URLs" do |
| 386 | + allow(subject).to receive(:url).and_return("http://archiveofourown.org/users/someone/") |
| 387 | + |
| 388 | + expect(subject.creator_ids).to be_nil |
| 389 | + end |
| 390 | + |
| 391 | + it "returns no creator ids for comment sub-URLs" do |
| 392 | + allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/123/comments/") |
| 393 | + |
| 394 | + expect(subject.creator_ids).to be_nil |
| 395 | + end |
| 396 | + |
| 397 | + context "for work URLs" do |
| 398 | + it "returns deletedwork for a work that doesn't exist" do |
| 399 | + allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/000/") |
| 400 | + |
| 401 | + expect(subject.creator_ids).to eq("deletedwork") |
| 402 | + end |
| 403 | + |
| 404 | + context "for a single creator" do |
| 405 | + let(:work) { create(:work) } |
| 406 | + |
| 407 | + it "returns a single creator id" do |
| 408 | + allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/#{work.id}/") |
| 409 | + |
| 410 | + expect(subject.creator_ids).to eq(work.users.first.id.to_s) |
| 411 | + end |
| 412 | + end |
| 413 | + |
| 414 | + context "for an anonymous work" do |
| 415 | + let(:anonymous_collection) { create(:anonymous_collection) } |
| 416 | + let(:work) { create(:work, collections: [anonymous_collection]) } |
| 417 | + |
| 418 | + it "returns a single creator id" do |
| 419 | + allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/#{work.id}/") |
| 420 | + |
| 421 | + expect(subject.creator_ids).to eq(work.users.first.id.to_s) |
| 422 | + end |
| 423 | + end |
| 424 | + |
| 425 | + context "for an unrevealed work" do |
| 426 | + let(:unrevealed_collection) { create(:unrevealed_collection) } |
| 427 | + let(:work) { create(:work, collections: [unrevealed_collection]) } |
| 428 | + |
| 429 | + it "returns a single creator id" do |
| 430 | + allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/#{work.id}/") |
| 431 | + |
| 432 | + expect(subject.creator_ids).to eq(work.users.first.id.to_s) |
| 433 | + end |
| 434 | + end |
| 435 | + |
| 436 | + context "for multiple pseuds of one creator" do |
| 437 | + let(:user) { create(:user) } |
| 438 | + let(:pseud) { create(:pseud, user: user) } |
| 439 | + let(:work) { create(:work, authors: [pseud, user.default_pseud]) } |
| 440 | + |
| 441 | + it "returns a single creator id" do |
| 442 | + allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/#{work.id}/") |
| 443 | + |
| 444 | + expect(subject.creator_ids).to eq(user.id.to_s) |
| 445 | + end |
| 446 | + end |
| 447 | + |
| 448 | + context "for multiple creators" do |
| 449 | + let(:user1) { create(:user, id: 10) } |
| 450 | + let(:user2) { create(:user, id: 11) } |
| 451 | + let(:work) { create(:work, authors: [user2.default_pseud, user1.default_pseud]) } |
| 452 | + |
| 453 | + it "returns a sorted list of creator ids" do |
| 454 | + allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/#{work.id}/") |
| 455 | + |
| 456 | + expect(subject.creator_ids).to eq("#{user1.id}, #{user2.id}") |
| 457 | + end |
| 458 | + end |
| 459 | + |
| 460 | + context "for an invited co-creator that hasn't accepted yet" do |
| 461 | + let(:user) { create(:user) } |
| 462 | + let(:invited) { create(:user) } |
| 463 | + let(:work) { create(:work, authors: [user.default_pseud, invited.default_pseud]) } |
| 464 | + let(:creatorship) { work.creatorships.last } |
| 465 | + |
| 466 | + before do |
| 467 | + creatorship.approved = false |
| 468 | + creatorship.save!(validate: false) |
| 469 | + end |
| 470 | + |
| 471 | + it "returns only the creator" do |
| 472 | + allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/#{work.id}/") |
| 473 | + |
| 474 | + expect(subject.creator_ids).to eq(user.id.to_s) |
| 475 | + end |
| 476 | + end |
| 477 | + end |
| 478 | + |
| 479 | + context "for an orphaned work" do |
| 480 | + let!(:orphan_account) { create(:user, login: "orphan_account") } |
| 481 | + let(:orphaneer) { create(:user, id: 20) } |
| 482 | + let(:work) { create(:work, authors: [orphaneer.default_pseud]) } |
| 483 | + |
| 484 | + context "recently orphaned" do |
| 485 | + before do |
| 486 | + Creatorship.orphan([orphaneer.default_pseud], [work], false) |
| 487 | + end |
| 488 | + |
| 489 | + it "returns orphanedwork and the original creator" do |
| 490 | + allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/#{work.id}/") |
| 491 | + |
| 492 | + expect(subject.creator_ids).to eq("orphanedwork, #{orphaneer.id}") |
| 493 | + end |
| 494 | + end |
| 495 | + |
| 496 | + context "orphaned a long time ago" do |
| 497 | + before do |
| 498 | + Creatorship.orphan([orphaneer.default_pseud], [work], false) |
| 499 | + work.original_creators.destroy_all |
| 500 | + end |
| 501 | + |
| 502 | + it "returns orphanedwork" do |
| 503 | + allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/#{work.id}/") |
| 504 | + |
| 505 | + expect(subject.creator_ids).to eq("orphanedwork") |
| 506 | + end |
| 507 | + end |
| 508 | + |
| 509 | + context "partially orphaned" do |
| 510 | + let(:cocreator) { create(:user, id: 21) } |
| 511 | + let(:work) { create(:work, authors: [cocreator.default_pseud, orphaneer.default_pseud]) } |
| 512 | + |
| 513 | + before do |
| 514 | + Creatorship.orphan([orphaneer.default_pseud], [work], false) |
| 515 | + end |
| 516 | + |
| 517 | + it "returns a sorted list of orphanedwork, the co-creator and the original creator" do |
| 518 | + allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/#{work.id}/") |
| 519 | + |
| 520 | + expect(subject.creator_ids).to eq("orphanedwork, #{orphaneer.id}, #{cocreator.id}") |
| 521 | + end |
| 522 | + end |
| 523 | + end |
| 524 | + end |
383 | 525 | end
|
0 commit comments