|
801 | 801 | context.unset(:name)
|
802 | 802 | end
|
803 | 803 |
|
804 |
| - it "unsets the first existing field" do |
805 |
| - expect(depeche_mode.reload.name).to be_nil |
806 |
| - end |
807 |
| - |
808 |
| - it "unsets the last existing field" do |
809 |
| - expect(new_order.reload.name).to be_nil |
| 804 | + it "unsets the fields from all documents" do |
| 805 | + depeche_mode.reload |
| 806 | + new_order.reload |
| 807 | + expect(depeche_mode.name).to be_nil |
| 808 | + expect(depeche_mode.years).to_not be_nil |
| 809 | + expect(new_order.name).to be_nil |
| 810 | + expect(new_order.years).to_not be_nil |
810 | 811 | end
|
811 | 812 | end
|
812 | 813 |
|
813 | 814 | context "when the field is aliased" do
|
814 |
| - |
815 | 815 | before do
|
816 | 816 | context.unset(:years)
|
817 | 817 | end
|
818 | 818 |
|
819 |
| - it "unsets the first existing field" do |
820 |
| - expect(depeche_mode.reload.years).to be_nil |
821 |
| - end |
822 |
| - |
823 |
| - it "unsets the last existing field" do |
824 |
| - expect(new_order.reload.years).to be_nil |
| 819 | + it "unsets the fields from all documents" do |
| 820 | + depeche_mode.reload |
| 821 | + new_order.reload |
| 822 | + expect(depeche_mode.name).to_not be_nil |
| 823 | + expect(depeche_mode.years).to be_nil |
| 824 | + expect(new_order.name).to_not be_nil |
| 825 | + expect(new_order.years).to be_nil |
825 | 826 | end
|
826 | 827 | end
|
827 | 828 | end
|
828 | 829 |
|
829 | 830 | context "when unsetting multiple fields" do
|
830 | 831 |
|
831 | 832 | let!(:new_order) do
|
832 |
| - Band.create(name: "New Order", genres: [ "electro", "dub" ], years: 10) |
| 833 | + Band.create(name: "New Order", genres: %w[electro dub], years: 10, |
| 834 | + likes: 200, rating: 4.3, origin: 'Space') |
833 | 835 | end
|
834 | 836 |
|
835 | 837 | let(:criteria) do
|
|
846 | 848 | context.unset(:name, :genres)
|
847 | 849 | end
|
848 | 850 |
|
849 |
| - it "unsets name field" do |
850 |
| - expect(new_order.reload.name).to be_nil |
851 |
| - end |
852 |
| - |
853 |
| - it "unsets genres field" do |
854 |
| - expect(new_order.reload.genres).to be_nil |
| 851 | + it "unsets the specified fields" do |
| 852 | + new_order.reload |
| 853 | + expect(new_order.name).to be_nil |
| 854 | + expect(new_order.genres).to be_nil |
| 855 | + expect(new_order.years).to_not be_nil |
| 856 | + expect(new_order.likes).to_not be_nil |
| 857 | + expect(new_order.rating).to_not be_nil |
855 | 858 | end
|
856 | 859 | end
|
857 | 860 |
|
|
861 | 864 | context.unset(:name, :years)
|
862 | 865 | end
|
863 | 866 |
|
864 |
| - it "unsets the unaliased field" do |
865 |
| - expect(new_order.reload.name).to be_nil |
| 867 | + it "unsets the specified fields" do |
| 868 | + new_order.reload |
| 869 | + expect(new_order.name).to be_nil |
| 870 | + expect(new_order.genres).to_not be_nil |
| 871 | + expect(new_order.years).to be_nil |
| 872 | + expect(new_order.likes).to_not be_nil |
| 873 | + expect(new_order.rating).to_not be_nil |
| 874 | + end |
| 875 | + end |
| 876 | + |
| 877 | + context "when using Hash arguments" do |
| 878 | + |
| 879 | + before do |
| 880 | + context.unset({ years: true, likes: "" }, { rating: false, origin: nil }) |
| 881 | + end |
| 882 | + |
| 883 | + it "unsets the specified fields" do |
| 884 | + new_order.reload |
| 885 | + expect(new_order.name).to_not be_nil |
| 886 | + expect(new_order.genres).to_not be_nil |
| 887 | + expect(new_order.years).to be_nil |
| 888 | + expect(new_order.likes).to be_nil |
| 889 | + expect(new_order.rating).to be_nil |
| 890 | + expect(new_order.origin).to be_nil |
| 891 | + end |
| 892 | + end |
| 893 | + |
| 894 | + context "when mixing argument types" do |
| 895 | + |
| 896 | + before do |
| 897 | + context.unset(:name, [:years], { likes: "" }, { rating: false }) |
866 | 898 | end
|
867 | 899 |
|
868 |
| - it "unsets the aliased field" do |
869 |
| - expect(new_order.reload.years).to be_nil |
| 900 | + it "unsets the specified fields" do |
| 901 | + new_order.reload |
| 902 | + expect(new_order.name).to be_nil |
| 903 | + expect(new_order.genres).to_not be_nil |
| 904 | + expect(new_order.years).to be_nil |
| 905 | + expect(new_order.likes).to be_nil |
| 906 | + expect(new_order.rating).to be_nil |
870 | 907 | end
|
871 | 908 | end
|
872 | 909 | end
|
|
895 | 932 | end
|
896 | 933 |
|
897 | 934 | it "unsets the unaliased field" do
|
898 |
| - expect(depeche_mode.reload.name).to be_nil |
| 935 | + depeche_mode.reload |
| 936 | + expect(depeche_mode.name).to be_nil |
| 937 | + expect(depeche_mode.years).to_not be_nil |
899 | 938 | end
|
900 | 939 | end
|
901 | 940 | end
|
|
0 commit comments