| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  | require "patch" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-18 15:11:11 -08:00
										 |  |  | RSpec.describe Patch do | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  |   describe "#create" do | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "with a simple patch" do | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       subject(:patch) { described_class.create(:p2, nil) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-13 09:43:09 +01:00
										 |  |  |       it { is_expected.to be_a ExternalPatch } | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  |       it { is_expected.to be_external } | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       it(:strip) { expect(patch.strip).to eq(:p2) } | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "with a string patch" do | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       subject(:patch) { described_class.create(:p0, "foo") } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-13 09:43:09 +01:00
										 |  |  |       it { is_expected.to be_a StringPatch } | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       it(:strip) { expect(patch.strip).to eq(:p0) } | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "with a string patch without strip" do | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       subject(:patch) { described_class.create("foo", nil) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-13 09:43:09 +01:00
										 |  |  |       it { is_expected.to be_a StringPatch } | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       it(:strip) { expect(patch.strip).to eq(:p1) } | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "with a data patch" do | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       subject(:patch) { described_class.create(:p0, :DATA) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-13 09:43:09 +01:00
										 |  |  |       it { is_expected.to be_a DATAPatch } | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       it(:strip) { expect(patch.strip).to eq(:p0) } | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "with a data patch without strip" do | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       subject(:patch) { described_class.create(:DATA, nil) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-13 09:43:09 +01:00
										 |  |  |       it { is_expected.to be_a DATAPatch } | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       it(:strip) { expect(patch.strip).to eq(:p1) } | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "raises an error for unknown values" do | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       expect do | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  |         described_class.create(Object.new) | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       end.to raise_error(ArgumentError) | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       expect do | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  |         described_class.create(Object.new, Object.new) | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       end.to raise_error(ArgumentError) | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#patch_files" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |     subject(:patch) { described_class.create(:p2, nil) } | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "when the patch is empty" do | 
					
						
							| 
									
										
										
										
											2024-07-14 11:42:22 -04:00
										 |  |  |       it(:resource) { expect(patch.resource).to be_a Resource::Patch } | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       it { expect(patch.patch_files).to eq(patch.resource.patch_files) } | 
					
						
							|  |  |  |       it { expect(patch.patch_files).to eq([]) } | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns applied patch files" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       patch.resource.apply("patch1.diff") | 
					
						
							|  |  |  |       expect(patch.patch_files).to eq(["patch1.diff"]) | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       patch.resource.apply("patch2.diff", "patch3.diff") | 
					
						
							|  |  |  |       expect(patch.patch_files).to eq(["patch1.diff", "patch2.diff", "patch3.diff"]) | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       patch.resource.apply(["patch4.diff", "patch5.diff"]) | 
					
						
							|  |  |  |       expect(patch.patch_files.count).to eq(5) | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       patch.resource.apply("patch4.diff", ["patch5.diff", "patch6.diff"], "patch7.diff") | 
					
						
							|  |  |  |       expect(patch.patch_files.count).to eq(7) | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |   describe EmbeddedPatch do | 
					
						
							|  |  |  |     describe "#new" do | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       subject(:patch) { described_class.new(:p1) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       it(:inspect) { expect(patch.inspect).to eq("#<EmbeddedPatch: :p1>") } | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |   describe ExternalPatch do | 
					
						
							|  |  |  |     subject(:patch) { described_class.new(:p1) { url "file:///my.patch" } } | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |     describe "#url" do | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       it(:url) { expect(patch.url).to eq("file:///my.patch") } | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |     describe "#inspect" do | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       it(:inspect) { expect(patch.inspect).to eq('#<ExternalPatch: :p1 "file:///my.patch">') } | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |     describe "#cached_download" do | 
					
						
							|  |  |  |       before do | 
					
						
							|  |  |  |         allow(patch.resource).to receive(:cached_download).and_return("/tmp/foo.tar.gz") | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-17 22:47:37 -07:00
										 |  |  |       it(:cached_download) { expect(patch.cached_download).to eq("/tmp/foo.tar.gz") } | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-02-15 15:19:06 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | end |