|
622 | 622 | end |
623 | 623 | end |
624 | 624 | end |
| 625 | + |
| 626 | + describe "GET #preview" do |
| 627 | + let(:skin_creator) { create(:user) } |
| 628 | + let(:other_user) { create(:user) } |
| 629 | + subject { get :preview, params: { id: skin.id } } |
| 630 | + |
| 631 | + shared_examples "a skin admins cannot preview" do |
| 632 | + before do |
| 633 | + fake_login_admin(admin) |
| 634 | + end |
| 635 | + |
| 636 | + context "when logged in as an admin with no role" do |
| 637 | + let(:admin) { create(:admin, roles: []) } |
| 638 | + |
| 639 | + it "redirects with an error" do |
| 640 | + subject |
| 641 | + # This actually redirects to the root path |
| 642 | + it_redirects_to_user_login_with_error |
| 643 | + end |
| 644 | + end |
| 645 | + |
| 646 | + Admin::VALID_ROLES.each do |role| |
| 647 | + context "when logged in as an admin with role #{role}" do |
| 648 | + let(:admin) { create(:admin, roles: [role]) } |
| 649 | + |
| 650 | + it "redirects with an error" do |
| 651 | + subject |
| 652 | + # This actually redirects to the root path |
| 653 | + it_redirects_to_user_login_with_error |
| 654 | + end |
| 655 | + end |
| 656 | + end |
| 657 | + end |
| 658 | + |
| 659 | + shared_examples "a skin guests cannot preview" do |
| 660 | + context "when not logged in" do |
| 661 | + it "errors and redirects to user_login" do |
| 662 | + subject |
| 663 | + it_redirects_to_user_login_with_error |
| 664 | + end |
| 665 | + end |
| 666 | + end |
| 667 | + |
| 668 | + shared_examples "a public skin that cannot be previewed" do |
| 669 | + context "when logged in as the skin creator" do |
| 670 | + it "errors and redirects to user_skins_path" do |
| 671 | + fake_login_known_user(skin.author) |
| 672 | + subject |
| 673 | + |
| 674 | + it_redirects_to_with_error(user_skins_path(skin.author), "Sorry, you can't preview that skin.") |
| 675 | + end |
| 676 | + end |
| 677 | + |
| 678 | + context "when logged in as a user who isn't the skin author" do |
| 679 | + it "errors and redirects to user_skins_path" do |
| 680 | + fake_login_known_user(other_user) |
| 681 | + subject |
| 682 | + |
| 683 | + it_redirects_to_with_error(user_skins_path(other_user), "Sorry, you can't preview that skin.") |
| 684 | + end |
| 685 | + end |
| 686 | + |
| 687 | + context "when logged in as an admin" do |
| 688 | + it_behaves_like "a skin admins cannot preview" |
| 689 | + end |
| 690 | + |
| 691 | + context "when not logged in" do |
| 692 | + it_behaves_like "a skin guests cannot preview" |
| 693 | + end |
| 694 | + end |
| 695 | + |
| 696 | + shared_examples "a non-public skin that cannot be previewed" do |
| 697 | + context "when logged in as the skin creator" do |
| 698 | + it "errors and redirects to user_skins_path" do |
| 699 | + fake_login_known_user(skin.author) |
| 700 | + subject |
| 701 | + |
| 702 | + it_redirects_to_with_error(user_skins_path(skin.author), "Sorry, you can't preview that skin.") |
| 703 | + end |
| 704 | + end |
| 705 | + |
| 706 | + context "when logged in as a user who isn't the skin author" do |
| 707 | + it "errors and redirects to user_path" do |
| 708 | + fake_login_known_user(other_user) |
| 709 | + subject |
| 710 | + |
| 711 | + it_redirects_to_with_error(user_path(other_user), "Sorry, you don't have permission to access the page you were trying to reach.") |
| 712 | + end |
| 713 | + end |
| 714 | + |
| 715 | + context "when logged in as an admin" do |
| 716 | + it_behaves_like "a skin admins cannot preview" |
| 717 | + end |
| 718 | + |
| 719 | + context "when not logged in" do |
| 720 | + it_behaves_like "a skin guests cannot preview" |
| 721 | + end |
| 722 | + end |
| 723 | + |
| 724 | + context "with workskin" do |
| 725 | + context "when workskin is public" do |
| 726 | + let(:skin) { create(:work_skin, :public, title: "Work Skin", author: skin_creator) } |
| 727 | + |
| 728 | + it_behaves_like "a public skin that cannot be previewed" |
| 729 | + end |
| 730 | + |
| 731 | + context "when workskin is not public" do |
| 732 | + let(:skin) { create(:work_skin, title: "Work Skin", author: skin_creator) } |
| 733 | + |
| 734 | + it_behaves_like "a non-public skin that cannot be previewed" |
| 735 | + end |
| 736 | + end |
| 737 | + |
| 738 | + context "with parent only site skin" do |
| 739 | + context "when site skin is public" do |
| 740 | + let(:skin) { create(:skin, :public, title: "Parent Only Site Skin", unusable: true, author: skin_creator) } |
| 741 | + |
| 742 | + it_behaves_like "a public skin that cannot be previewed" |
| 743 | + end |
| 744 | + |
| 745 | + context "when site skin is not public" do |
| 746 | + let(:skin) { create(:skin, title: "Parent Only Site Skin", unusable: true, author: skin_creator) } |
| 747 | + |
| 748 | + it_behaves_like "a non-public skin that cannot be previewed" |
| 749 | + end |
| 750 | + end |
| 751 | + |
| 752 | + context "with accessible site skin" do |
| 753 | + let(:success) { it_redirects_to_simple(tag_works_path(tag, site_skin: skin.id)) } |
| 754 | + let(:tag) { create(:canonical_fandom) } |
| 755 | + |
| 756 | + before do |
| 757 | + FilterCount.create!( |
| 758 | + filter: tag, |
| 759 | + public_works_count: 10, |
| 760 | + unhidden_works_count: 10 |
| 761 | + ) |
| 762 | + end |
| 763 | + |
| 764 | + context "when site skin is public" do |
| 765 | + let(:skin) { create(:skin, :public, title: "Accessible Site Skin", author: skin_creator) } |
| 766 | + |
| 767 | + context "when logged in as the skin creator" do |
| 768 | + it "succeeds" do |
| 769 | + fake_login_known_user(skin.author) |
| 770 | + subject |
| 771 | + success |
| 772 | + end |
| 773 | + end |
| 774 | + |
| 775 | + context "when logged in as a user who isn't the skin author" do |
| 776 | + it "succeeds" do |
| 777 | + fake_login |
| 778 | + subject |
| 779 | + success |
| 780 | + end |
| 781 | + end |
| 782 | + |
| 783 | + context "when logged in as an admin" do |
| 784 | + it_behaves_like "a skin admins cannot preview" |
| 785 | + end |
| 786 | + |
| 787 | + context "when not logged in" do |
| 788 | + it_behaves_like "a skin guests cannot preview" |
| 789 | + end |
| 790 | + end |
| 791 | + |
| 792 | + context "when site skin is not public" do |
| 793 | + let(:skin) { create(:skin, title: "Accessible Site Skin", author: skin_creator) } |
| 794 | + |
| 795 | + context "when logged in as the skin author" do |
| 796 | + it "succeeds" do |
| 797 | + fake_login_known_user(skin.author) |
| 798 | + subject |
| 799 | + success |
| 800 | + end |
| 801 | + end |
| 802 | + |
| 803 | + context "when logged in as a user who isn't the skin author" do |
| 804 | + it "redirects with an error" do |
| 805 | + fake_login_known_user(other_user) |
| 806 | + subject |
| 807 | + |
| 808 | + it_redirects_to_with_error(user_path(other_user), "Sorry, you don't have permission to access the page you were trying to reach.") |
| 809 | + end |
| 810 | + end |
| 811 | + |
| 812 | + context "when logged in as an admin" do |
| 813 | + it_behaves_like "a skin admins cannot preview" |
| 814 | + end |
| 815 | + |
| 816 | + context "when not logged in" do |
| 817 | + it_behaves_like "a skin guests cannot preview" |
| 818 | + end |
| 819 | + end |
| 820 | + end |
| 821 | + end |
625 | 822 | end |
0 commit comments