|
89 | 89 | end
|
90 | 90 | end
|
91 | 91 |
|
92 |
| - shared_examples 'updates the parent when :touch is not set' do |
| 92 | + shared_examples 'updates the parent when :touch is false' do |
93 | 93 | it 'does not update updated_at on parent' do
|
94 | 94 | entrance
|
95 | 95 | update_time
|
|
130 | 130 |
|
131 | 131 | include_examples 'updates the child'
|
132 | 132 | include_examples 'updates the parent when :touch is true'
|
133 |
| - include_examples 'updates the parent when :touch is not set' |
| 133 | + include_examples 'updates the parent when :touch is false' |
134 | 134 |
|
135 | 135 | context 'when also updating an additional field' do
|
136 | 136 | it 'persists the update to the additional field' do
|
|
701 | 701 | end
|
702 | 702 | end
|
703 | 703 | end
|
| 704 | + |
| 705 | + describe "when saving a document" do |
| 706 | + |
| 707 | + let!(:start_time) { Timecop.freeze(Time.at(Time.now.to_i)) } |
| 708 | + |
| 709 | + let(:update_time) do |
| 710 | + Timecop.freeze(Time.at(Time.now.to_i) + 2) |
| 711 | + end |
| 712 | + |
| 713 | + after do |
| 714 | + Timecop.return |
| 715 | + end |
| 716 | + |
| 717 | + context "when only using the root document" do |
| 718 | + |
| 719 | + shared_examples "timeless is cleared" do |
| 720 | + it "clears the timeless option" do |
| 721 | + expect(doc.timeless?).to be false |
| 722 | + end |
| 723 | + end |
| 724 | + |
| 725 | + shared_examples "touches the document" do |
| 726 | + it "touches the document" do |
| 727 | + expect(doc.created_at).to eq(start_time) |
| 728 | + expect(doc.updated_at).to eq(start_time) |
| 729 | + end |
| 730 | + end |
| 731 | + |
| 732 | + shared_examples "updates the document" do |
| 733 | + it "updates the document" do |
| 734 | + expect(doc.created_at).to eq(start_time) |
| 735 | + expect(doc.updated_at).to eq(update_time) |
| 736 | + end |
| 737 | + end |
| 738 | + |
| 739 | + let(:doc) { Dokument.new } |
| 740 | + |
| 741 | + context "when saving a new document" do |
| 742 | + |
| 743 | + context "when not passing a touch option" do |
| 744 | + |
| 745 | + before do |
| 746 | + doc.save! |
| 747 | + end |
| 748 | + |
| 749 | + include_examples "touches the document" |
| 750 | + include_examples "timeless is cleared" |
| 751 | + end |
| 752 | + |
| 753 | + context "when passing touch: true" do |
| 754 | + |
| 755 | + before do |
| 756 | + doc.save!(touch: true) |
| 757 | + end |
| 758 | + |
| 759 | + include_examples "touches the document" |
| 760 | + include_examples "timeless is cleared" |
| 761 | + end |
| 762 | + |
| 763 | + context "when passing touch: false" do |
| 764 | + |
| 765 | + before do |
| 766 | + doc.save!(touch: false) |
| 767 | + end |
| 768 | + |
| 769 | + include_examples "touches the document" |
| 770 | + include_examples "timeless is cleared" |
| 771 | + end |
| 772 | + end |
| 773 | + |
| 774 | + context "when updating a document" do |
| 775 | + before do |
| 776 | + doc.save! |
| 777 | + doc.title = "title" |
| 778 | + update_time |
| 779 | + end |
| 780 | + |
| 781 | + context "when not passing a touch option" do |
| 782 | + |
| 783 | + before do |
| 784 | + doc.save! |
| 785 | + end |
| 786 | + |
| 787 | + include_examples "updates the document" |
| 788 | + include_examples "timeless is cleared" |
| 789 | + end |
| 790 | + |
| 791 | + context "when passing touch: true" do |
| 792 | + |
| 793 | + before do |
| 794 | + doc.save!(touch: true) |
| 795 | + end |
| 796 | + |
| 797 | + include_examples "updates the document" |
| 798 | + include_examples "timeless is cleared" |
| 799 | + end |
| 800 | + |
| 801 | + context "when passing touch: false" do |
| 802 | + |
| 803 | + before do |
| 804 | + doc.save!(touch: false) |
| 805 | + end |
| 806 | + |
| 807 | + include_examples "touches the document" |
| 808 | + include_examples "timeless is cleared" |
| 809 | + end |
| 810 | + end |
| 811 | + end |
| 812 | + |
| 813 | + context "when saving embedded associations with cascadable callbacks" do |
| 814 | + |
| 815 | + shared_examples "timeless is cleared" do |
| 816 | + it "clears the timeless option" do |
| 817 | + expect(book.timeless?).to be false |
| 818 | + expect(book.covers.first.timeless?).to be false |
| 819 | + end |
| 820 | + end |
| 821 | + |
| 822 | + shared_examples "touches the document" do |
| 823 | + it "touches the document" do |
| 824 | + expect(book.created_at).to eq(start_time) |
| 825 | + expect(book.updated_at).to eq(start_time) |
| 826 | + end |
| 827 | + end |
| 828 | + |
| 829 | + shared_examples "updates the document" do |
| 830 | + it "updates the document" do |
| 831 | + expect(book.created_at).to eq(start_time) |
| 832 | + expect(book.updated_at).to eq(update_time) |
| 833 | + end |
| 834 | + end |
| 835 | + |
| 836 | + shared_examples "touches the children" do |
| 837 | + it "touches the children" do |
| 838 | + expect(book.covers.first.created_at).to eq(start_time) |
| 839 | + expect(book.covers.first.updated_at).to eq(start_time) |
| 840 | + end |
| 841 | + end |
| 842 | + |
| 843 | + shared_examples "updates the children" do |
| 844 | + it "updates the children" do |
| 845 | + expect(book.covers.first.created_at).to eq(start_time) |
| 846 | + expect(book.covers.first.updated_at).to eq(update_time) |
| 847 | + end |
| 848 | + end |
| 849 | + |
| 850 | + let(:book) do |
| 851 | + Book.new(covers: [ cover ]) |
| 852 | + end |
| 853 | + |
| 854 | + let(:cover) do |
| 855 | + Cover.new |
| 856 | + end |
| 857 | + |
| 858 | + context "when saving a new document" do |
| 859 | + |
| 860 | + context "when not passing a touch option" do |
| 861 | + |
| 862 | + before do |
| 863 | + book.save! |
| 864 | + end |
| 865 | + |
| 866 | + include_examples "touches the document" |
| 867 | + include_examples "touches the children" |
| 868 | + include_examples "timeless is cleared" |
| 869 | + end |
| 870 | + |
| 871 | + context "when passing touch: true" do |
| 872 | + |
| 873 | + before do |
| 874 | + book.save!(touch: true) |
| 875 | + end |
| 876 | + |
| 877 | + include_examples "touches the document" |
| 878 | + include_examples "touches the children" |
| 879 | + include_examples "timeless is cleared" |
| 880 | + end |
| 881 | + |
| 882 | + context "when passing touch: false" do |
| 883 | + |
| 884 | + before do |
| 885 | + book.save!(touch: false) |
| 886 | + end |
| 887 | + |
| 888 | + include_examples "touches the document" |
| 889 | + include_examples "touches the children" |
| 890 | + include_examples "timeless is cleared" |
| 891 | + end |
| 892 | + end |
| 893 | + |
| 894 | + context "when updating a document" do |
| 895 | + before do |
| 896 | + book.save! |
| 897 | + book.title = "title" |
| 898 | + book.covers.first.title = "title" |
| 899 | + update_time |
| 900 | + end |
| 901 | + |
| 902 | + context "when not passing a touch option" do |
| 903 | + |
| 904 | + before do |
| 905 | + book.save! |
| 906 | + end |
| 907 | + |
| 908 | + include_examples "updates the document" |
| 909 | + include_examples "updates the children" |
| 910 | + include_examples "timeless is cleared" |
| 911 | + end |
| 912 | + |
| 913 | + context "when passing touch: true" do |
| 914 | + |
| 915 | + before do |
| 916 | + book.save!(touch: true) |
| 917 | + end |
| 918 | + |
| 919 | + include_examples "updates the document" |
| 920 | + include_examples "updates the children" |
| 921 | + include_examples "timeless is cleared" |
| 922 | + end |
| 923 | + |
| 924 | + context "when passing touch: false" do |
| 925 | + |
| 926 | + before do |
| 927 | + book.save!(touch: false) |
| 928 | + end |
| 929 | + |
| 930 | + include_examples "touches the document" |
| 931 | + include_examples "touches the children" |
| 932 | + include_examples "timeless is cleared" |
| 933 | + end |
| 934 | + end |
| 935 | + end |
| 936 | + end |
704 | 937 | end
|
0 commit comments