yadisk-client 1.10.2 → 1.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +14 -0
  3. data/.github/workflows/CI.yml +50 -0
  4. data/Gemfile.lock +12 -1
  5. data/README.md +5 -2
  6. data/lib/yadisk/resources/disk.rb +5 -6
  7. data/lib/yadisk/version.rb +2 -2
  8. data/spec/lib/yadisk/client_spec.rb +4 -8
  9. data/spec/lib/yadisk/disk_spec.rb +220 -217
  10. data/spec/lib/yadisk/operation_spec.rb +18 -0
  11. data/spec/lib/yadisk/public_spec.rb +31 -37
  12. data/spec/lib/yadisk/trash_spec.rb +27 -56
  13. data/spec/spec_helper.rb +15 -1
  14. data/spec/vcr/disk/{POST_copy.yml → copy.yml} +10 -8
  15. data/spec/vcr/disk/create_dir.yml +52 -0
  16. data/spec/vcr/disk/{PUT_create_dir.yml → create_dir_error_409.yml} +10 -6
  17. data/spec/vcr/disk/{DELETE_delete.yml → delete.yml} +3 -3
  18. data/spec/vcr/{operations/GET_status.yml → disk/download.yml} +4 -4
  19. data/spec/vcr/disk/get_meta.yml +52 -0
  20. data/spec/vcr/disk/info.yml +57 -0
  21. data/spec/vcr/disk/last_uploaded.yml +52 -0
  22. data/spec/vcr/disk/list_files.yml +52 -0
  23. data/spec/vcr/disk/list_public.yml +52 -0
  24. data/spec/vcr/disk/{POST_move.yml → move.yml} +10 -8
  25. data/spec/vcr/disk/{PUT_publish.yml → publish.yml} +4 -4
  26. data/spec/vcr/disk/{PUT_unpublish.yml → unpublish.yml} +4 -4
  27. data/spec/vcr/disk/update_meta.yml +54 -0
  28. data/spec/vcr/disk/{GET_get_meta.yml → upload.yml} +5 -5
  29. data/spec/vcr/disk/{POST_upload_by_url.yml → upload_by_url.yml} +4 -4
  30. data/spec/vcr/disk/upload_from_file.yml +111 -0
  31. data/spec/vcr/{disk/GET_download.yml → operation/status.yml} +4 -4
  32. data/spec/vcr/{disk/GET_list_public.yml → public/link.yml} +4 -4
  33. data/spec/vcr/public/meta.yml +52 -0
  34. data/spec/vcr/public/save.yml +52 -0
  35. data/spec/vcr/trash/{DELETE_delete.yml → delete.yml} +3 -3
  36. data/spec/vcr/trash/list.yml +52 -0
  37. data/spec/vcr/trash/{PUT_restore.yml → restore.yml} +6 -5
  38. data/spec/vcr_setup.rb +0 -4
  39. data/yadisk.gemspec +8 -0
  40. metadata +133 -23
  41. data/spec/lib/yadisk/errors_spec.rb +0 -16
  42. data/spec/lib/yadisk/operations_spec.rb +0 -23
  43. data/spec/vcr/disk/ERROR_info.yml +0 -48
  44. data/spec/vcr/disk/GET_info.yml +0 -52
  45. data/spec/vcr/disk/GET_upload.yml +0 -48
  46. data/spec/vcr/disk/PATCH_update_meta.yml +0 -54
  47. data/spec/vcr/trash/DELETE_delete_error.yml +0 -49
  48. data/spec/vcr/trash/GET_list.yml +0 -51
@@ -2,224 +2,227 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- # e2e vars
6
- # test_file_path = "spec/test_data/test_file.txt"
7
- test_file_name = "remote_file.txt"
8
- test_upload_link = ""
9
-
10
5
  # rubocop:disable Metrics/BlockLength
11
- describe Yadisk::Client do
12
- # TODO: refactor by separating test cases - HOW TO DO THIS ?
13
- # TODO: describe > context > it
14
- context "#disk" do
15
- it "#info", :vcr do
16
- name = "disk/GET_info"
17
- VCR.use_cassette(name, allow_playback_repeats: true) do
18
- resp = @yandex.disk.info
19
- CassetteHelpers::Use.new(name) do |c|
20
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk")
21
- expect(c.code).to eq(200)
22
- expect(c.method).to eq("get")
23
- end
24
- expect(resp).to be_instance_of(Yadisk::Disk)
25
- end
26
- end
27
-
28
- it "#upload", :vcr do
29
- name = "disk/GET_upload"
30
- VCR.use_cassette(name, allow_playback_repeats: true) do
31
- resp = @yandex.disk.upload(path: test_file_name)
32
- test_upload_link = resp.href
33
- CassetteHelpers::Use.new(name) do |c|
34
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/resources/upload?path=remote_file.txt")
35
- expect(c.code).to eq(200)
36
- expect(c.method).to eq("get")
37
- end
38
- expect(resp).to be_instance_of(Yadisk::ResourceUploadLink)
39
- end
40
- end
41
-
42
- # it "#upload_from_file", :vcr do
43
- # name = "disk/PUT_upload_from_file"
44
- # VCR.use_cassette(name, allow_playback_repeats: true) do
45
- # @yandex.disk.upload_from_file(upload_link: test_upload_link, src: test_file_path)
46
- # CassetteHelpers::Use.new(name) do |c|
47
- # expect(c.url).to eq(upload_link)
48
- # expect(c.code).to eq(201)
49
- # expect(c.method).to eq("put")
50
- # end
51
- # end
52
- # end
53
-
54
- it "#upload_by_url", :vcr do
55
- name = "disk/POST_upload_by_url"
56
- VCR.use_cassette(name, allow_playback_repeats: true) do
57
- path = "uploaded_by_url.png"
58
- link = "https://www.example.com/image.png"
59
- @yandex.disk.upload_by_url(path: path, url: link)
60
-
61
- CassetteHelpers::Use.new(name) do |c|
62
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/resources/upload?path=#{path}&url=#{link}")
63
- expect(c.code).to eq(202)
64
- expect(c.method).to eq("post")
65
- end
66
- end
67
- end
68
-
69
- it "#get_meta", :vcr do
70
- name = "disk/GET_get_meta"
71
- VCR.use_cassette(name, allow_playback_repeats: true) do
72
- resp = @yandex.disk.get_meta(path: "remote_file.txt")
73
- CassetteHelpers::Use.new(name) do |c|
74
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/resources?path=/remote_file.txt")
75
- expect(c.code).to eq(200)
76
- expect(c.method).to eq("get")
77
- end
78
- expect(resp).to be_instance_of(Yadisk::Resource)
79
- end
80
- end
81
-
82
- it "#update_meta", :vcr do
83
- name = "disk/PATCH_update_meta"
84
- VCR.use_cassette(name, allow_playback_repeats: true) do
85
- resp = @yandex.disk.update_meta(path: "remote_file.txt", key_one: "value_1", key_two: "value_2")
86
- CassetteHelpers::Use.new(name) do |c|
87
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/resources")
88
- expect(c.code).to eq(200)
89
- expect(c.method).to eq("patch")
90
- end
91
- expect(resp).to be_instance_of(Yadisk::Resource)
92
- end
93
- end
94
-
95
- it "#create_dir", :vcr do
96
- name = "disk/PUT_create_dir"
97
- VCR.use_cassette(name, allow_playback_repeats: true) do
98
- resp = @yandex.disk.create_dir(path: "test_dir")
99
- CassetteHelpers::Use.new(name) do |c|
100
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/resources")
101
- expect(c.code).to eq(200)
102
- expect(c.method).to eq("get")
103
- end
104
- expect(resp).to be_instance_of(Yadisk::Link)
105
- end
106
- end
107
-
108
- it "#copy", :vcr do
109
- name = "disk/POST_copy"
110
- VCR.use_cassette(name, allow_playback_repeats: true) do
111
- resp = @yandex.disk.copy(from: "remote_file.txt", to: "remote_file_copy.txt")
112
- CassetteHelpers::Use.new(name) do |c|
113
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/resources/copy")
114
- expect(c.code).to eq(200)
115
- expect(c.method).to eq("post")
116
- end
117
- expect(resp).to be_instance_of(Yadisk::Link)
118
- end
119
- end
120
-
121
- it "#download", :vcr do
122
- name = "disk/GET_download"
123
- VCR.use_cassette(name, allow_playback_repeats: true) do
124
- resp = @yandex.disk.download(path: "remote_file.txt")
125
- CassetteHelpers::Use.new(name) do |c|
126
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/resources")
127
- expect(c.code).to eq(200)
128
- expect(c.method).to eq("get")
129
- end
130
- expect(resp).to be_instance_of(Yadisk::Link)
131
- end
132
- end
133
-
134
- # it "#list_files", :vcr do
135
- # name = "disk/GET_list_files"
136
- # VCR.use_cassette(name, allow_playback_repeats: true) do
137
- # @yandex.disk.list_files
138
- # CassetteHelpers::Use.new(name) do |c|
139
- # expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/resources")
140
- # expect(c.code).to eq(200)
141
- # expect(c.method).to eq("get")
142
- # end
143
- # expect(resp).to be_instance_of(Yadisk::Disk)
144
- # end
145
- # end
146
-
147
- # TODO: filter sensitive data
148
- # it "#last_uploaded", :vcr do
149
- # name = "disk/GET_last_uploaded"
150
- # VCR.use_cassette(name, allow_playback_repeats: true) do
151
- # resp = @yandex.disk.last_uploaded
152
- # CassetteHelpers::Use.new(name) do |c|
153
- # expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/resources")
154
- # expect(c.code).to eq(200)
155
- # expect(c.method).to eq("get")
156
- # end
157
- # expect(resp).to be_instance_of(Yadisk::Collection)
158
- # end
159
- # end
160
-
161
- it "#move", :vcr do
162
- name = "disk/POST_move"
163
- VCR.use_cassette(name, allow_playback_repeats: true) do
164
- resp = @yandex.disk.move(from: "remote_file_copy.txt", to: "remote_file_new_name.txt")
165
- CassetteHelpers::Use.new(name) do |c|
166
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/resources/move")
167
- expect(c.code).to eq(200)
168
- expect(c.method).to eq("post")
169
- end
170
- expect(resp).to be_instance_of(Yadisk::Link)
171
- end
172
- end
173
-
174
- it "#list_public", :vcr do
175
- name = "disk/GET_list_public"
176
- VCR.use_cassette(name, allow_playback_repeats: true) do
177
- resp = @yandex.disk.list_public
178
- CassetteHelpers::Use.new(name) do |c|
179
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/resources/public")
180
- expect(c.code).to eq(200)
181
- expect(c.meth).to eq("get")
182
- end
183
- expect(resp).to be_instance_of(Yadisk::Collection)
184
- end
185
- end
186
-
187
- it "#publish", :vcr do
188
- name = "disk/PUT_publish"
189
- VCR.use_cassette(name, allow_playback_repeats: true) do
190
- resp = @yandex.disk.publish(path: test_file_name)
191
- CassetteHelpers::Use.new(name) do |c|
192
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/resources/publish")
193
- expect(c.code).to eq(200)
194
- expect(c.method).to eq("put")
195
- end
196
- expect(resp).to be_instance_of(Yadisk::Link)
197
- end
198
- end
199
-
200
- it "#unpublish", :vcr do
201
- name = "disk/PUT_unpublish"
202
- VCR.use_cassette(name, allow_playback_repeats: true) do
203
- resp = @yandex.disk.unpublish(path: test_file_name)
204
- CassetteHelpers::Use.new(name).url do |c|
205
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/resources/unpublish")
206
- expect(c.code).to eq(200)
207
- expect(c.method).to eq("put")
208
- end
209
- expect(resp).to be_instance_of(Yadisk::Link)
210
- end
211
- end
212
-
213
- it "#delete", :vcr do
214
- name = "disk/DELETE_delete"
215
- VCR.use_cassette(name, allow_playback_repeats: true) do
216
- @yandex.disk.delete(path: test_file_name)
217
- CassetteHelpers::Use.new(name).url do |c|
218
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/resources?path=remote_file.txt")
219
- expect(c.code).to eq(204)
220
- expect(c.method).to eq("delete")
221
- end
222
- end
6
+ RSpec.describe "#disk" do
7
+ describe ".info" do
8
+ context "when params is OK" do
9
+ subject {
10
+ VCR.use_cassette("disk/info") do
11
+ @yandex.disk.info
12
+ end
13
+ }
14
+
15
+ it { expect(subject).to be_instance_of Yadisk::Disk }
16
+ it { expect(subject.is_paid).to be(true).or be(false) }
17
+ end
18
+ end
19
+
20
+ describe ".create_dir" do
21
+ context "when creating a directory is OK" do
22
+ subject {
23
+ VCR.use_cassette("disk/create_dir") do
24
+ @yandex.disk.create_dir path: "yadisk_created_dir"
25
+ end
26
+ }
27
+
28
+ it { expect(subject).to be_an Yadisk::Link }
29
+ it { expect(subject.href).to eq "https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2Fyadisk_created_dir" }
30
+ end
31
+
32
+ context "when dir already exists" do
33
+ subject {
34
+ VCR.use_cassette("disk/create_dir_error_409") do
35
+ @yandex.disk.create_dir path: "yadisk_created_dir"
36
+ end
37
+ }
38
+
39
+ it { expect(subject.error).to eq "DiskPathPointsToExistentDirectoryError" }
40
+ end
41
+ end
42
+
43
+ describe ".upload" do
44
+ context "when params is OK" do
45
+ subject {
46
+ VCR.use_cassette("disk/upload") do
47
+ @yandex.disk.upload(path: "yadisk_upload_here")
48
+ end
49
+ }
50
+
51
+ it { expect(subject).to be_an Yadisk::ResourceUploadLink }
52
+ it { expect(subject.operation_id).to be_an String }
53
+ it { expect(subject.href).to match %r{/uploader9x.disk.yandex.net:443/upload-target/} }
54
+ end
55
+ end
56
+
57
+ describe ".upload_from_file" do
58
+ context "when params is OK" do
59
+ subject {
60
+ VCR.use_cassette("disk/upload_from_file") do
61
+ @yandex.disk.upload_from_file(
62
+ upload_link: "https://uploader9x.disk.yandex.net:443/upload-target/20221018T144311.680.utd.6n9ay2kos10pewsoun8tlx7gf-k7o.674502",
63
+ src: "LICENSE"
64
+ )
65
+ end
66
+ }
67
+
68
+ it { expect(subject).to be true }
69
+ end
70
+ end
71
+
72
+ describe ".upload_by_url" do
73
+ context "when params is OK" do
74
+ subject {
75
+ VCR.use_cassette("disk/upload_by_url") do
76
+ @yandex.disk.upload_by_url(path: "yadisk_test_png.png", url: "https://www.fnordware.com/superpng/pnggrad8rgb.png")
77
+ end
78
+ }
79
+
80
+ it { expect(subject).to be_an Yadisk::Link }
81
+ it { expect(subject.href).to be_an String }
82
+ end
83
+ end
84
+
85
+ describe ".update_meta" do
86
+ context "when params is OK" do
87
+ subject {
88
+ VCR.use_cassette("disk/update_meta") do
89
+ @yandex.disk.update_meta(path: "yadisk_test_png.png", key: "value")
90
+ end
91
+ }
92
+
93
+ it { expect(subject).to be_an Yadisk::Resource }
94
+ it { expect(subject.custom_properties.key).to eq "value" }
95
+ end
96
+ end
97
+
98
+ describe ".get_meta" do
99
+ context "when params is OK" do
100
+ subject {
101
+ VCR.use_cassette("disk/get_meta") do
102
+ @yandex.disk.get_meta(path: "yadisk_test_png.png")
103
+ end
104
+ }
105
+
106
+ it { expect(subject).to be_an Yadisk::Resource }
107
+ it { expect(subject.custom_properties.key).to eq "value" }
108
+ end
109
+ end
110
+
111
+ describe ".copy" do
112
+ context "when params is OK" do
113
+ subject {
114
+ VCR.use_cassette("disk/copy") do
115
+ @yandex.disk.copy(from: "yadisk_test_png.png", to: "yadisk_test_png_copy.png")
116
+ end
117
+ }
118
+
119
+ it { expect(subject).to be_an Yadisk::Link }
120
+ it { expect(subject.href).to be_an String }
121
+ end
122
+ end
123
+
124
+ describe ".download" do
125
+ context "when params is OK" do
126
+ subject {
127
+ VCR.use_cassette("disk/download") do
128
+ @yandex.disk.download(path: "yadisk_test_png_copy.png")
129
+ end
130
+ }
131
+
132
+ it { expect(subject).to be_an Yadisk::Link }
133
+ it { expect(subject.href).to be_an String }
134
+ it { expect(subject.href).not_to be nil }
135
+ end
136
+ end
137
+
138
+ describe ".list_files" do
139
+ let(:limit) { "1" }
140
+ context "with limit param" do
141
+ subject {
142
+ VCR.use_cassette("disk/list_files") do
143
+ @yandex.disk.list_files(limit: limit)
144
+ end
145
+ }
146
+
147
+ it { expect(subject).to be_an Yadisk::Collection }
148
+ it { expect(subject.data.first).to be_an Yadisk::Resource }
149
+ end
150
+ end
151
+
152
+ describe ".last_uploaded" do
153
+ context "whith limit param" do
154
+ subject {
155
+ VCR.use_cassette("disk/last_uploaded") do
156
+ @yandex.disk.last_uploaded(limit: 1)
157
+ end
158
+ }
159
+
160
+ it { expect(subject).to be_an Yadisk::Collection }
161
+ it { expect(subject.data.first).to be_an Yadisk::Resource }
162
+ end
163
+ end
164
+
165
+ describe ".move" do
166
+ context "when params is OK" do
167
+ subject {
168
+ VCR.use_cassette("disk/move") do
169
+ @yandex.disk.move(from: "yadisk_test_png_copy.png", to: "yadisk.png")
170
+ end
171
+ }
172
+
173
+ it { expect(subject).to be_an Yadisk::Link }
174
+ it { expect(subject.href).to be_an String }
175
+ end
176
+ end
177
+
178
+ describe ".list_public" do
179
+ context "whit limit param" do
180
+ subject {
181
+ VCR.use_cassette("disk/list_public") do
182
+ @yandex.disk.list_public(limit: 1)
183
+ end
184
+ }
185
+
186
+ it { expect(subject).to be_an Yadisk::Collection }
187
+ it { expect(subject.data.first).to be_an Yadisk::PublicResource }
188
+ end
189
+ end
190
+
191
+ describe ".publish" do
192
+ context "when params is OK" do
193
+ subject {
194
+ VCR.use_cassette("disk/publish") do
195
+ @yandex.disk.publish(path: "yadisk.png")
196
+ end
197
+ }
198
+
199
+ it { expect(subject).to be_an Yadisk::Link }
200
+ it { expect(subject.href).to be_an String }
201
+ end
202
+ end
203
+
204
+ describe ".unpublish" do
205
+ context "when params is OK" do
206
+ subject {
207
+ VCR.use_cassette("disk/unpublish") do
208
+ @yandex.disk.unpublish(path: "yadisk.png")
209
+ end
210
+ }
211
+
212
+ it { expect(subject).to be_an Yadisk::Link }
213
+ it { expect(subject.href).to be_an String }
214
+ end
215
+ end
216
+
217
+ describe ".delete" do
218
+ context "when params is OK" do
219
+ subject {
220
+ VCR.use_cassette("disk/delete") do
221
+ @yandex.disk.delete(path: "yadisk_test_png.png")
222
+ end
223
+ }
224
+
225
+ it { expect(subject).to be_an Yadisk::Object }
223
226
  end
224
227
  end
225
228
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe "#operation" do
6
+ describe ".status" do
7
+ context "when params is OK" do
8
+ subject {
9
+ VCR.use_cassette("operation/status") do
10
+ @yandex.operation.status operation_id: "78ccc91b3a034a941a72dde1ae92fbf26d0facf9bad941eee9b432f4abdfdd1e"
11
+ end
12
+ }
13
+
14
+ it { expect(subject).to be_an String }
15
+ it { expect(subject).to eq "success" }
16
+ end
17
+ end
18
+ end
@@ -2,50 +2,44 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- # TODO: make specs code cleaner
6
- # TODO: describe > context > it
7
- describe Yadisk::Client do
8
- context "#public" do
9
- it "#meta", :vcr do
10
- name = "public/GET_meta"
11
- VCR.use_cassette(name, allow_playback_repeats: true) do
12
- url = "https://disk.yandex.ru/d/Th-o2SkdjoALxA"
13
- resp = @yandex.public_resource.meta(public_url: url)
14
- CassetteHelpers::Use.new(name) do |c|
15
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/operations/#{id}")
16
- expect(c.code).to eq(200)
17
- expect(c.method).to eq("get")
5
+ # rubocop:disable Metrics/BlockLength
6
+ RSpec.describe "#public" do
7
+ let(:public_url) { "https://disk.yandex.ru/d/XzWAb9JaK605ig" }
8
+
9
+ describe ".meta" do
10
+ context "when params is OK" do
11
+ subject {
12
+ VCR.use_cassette("public/meta") do
13
+ @yandex.public_resource.meta public_url: public_url
18
14
  end
19
- expect(resp).to be_instance_of(Yadisk::PublicResource)
20
- end
15
+ }
16
+
17
+ it { expect(subject).to be_an Yadisk::PublicResource }
21
18
  end
19
+ end
22
20
 
23
- it "#link", :vcr do
24
- name = "public/GET_link"
25
- VCR.use_cassette(name, allow_playback_repeats: true) do
26
- url = "https://disk.yandex.ru/d/Th-o2SkdjoALxA"
27
- resp = @yandex.public_resource.link(public_url: url)
28
- CassetteHelpers::Use.new(name) do |c|
29
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/operations/#{id}")
30
- expect(c.code).to eq(200)
31
- expect(c.method).to eq("get")
21
+ describe ".link" do
22
+ context "when params is OK" do
23
+ subject {
24
+ VCR.use_cassette("public/link") do
25
+ @yandex.public_resource.link public_url: public_url
32
26
  end
33
- expect(resp).to be_instance_of(Yadisk::Link)
34
- end
27
+ }
28
+
29
+ it { expect(subject).to be_an Yadisk::Link }
35
30
  end
31
+ end
36
32
 
37
- it "#save", :vcr do
38
- name = "public/POST_save"
39
- VCR.use_cassette(name, allow_playback_repeats: true) do
40
- url = "https://disk.yandex.ru/d/Th-o2SkdjoALxA"
41
- resp = @yandex.public_resource.save(public_url: url)
42
- CassetteHelpers::Use.new(name) do |c|
43
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/operations/#{id}")
44
- expect(c.code).to eq(200)
45
- expect(c.method).to eq("post")
33
+ describe ".save" do
34
+ context "when params is OK" do
35
+ subject {
36
+ VCR.use_cassette("public/save") do
37
+ @yandex.public_resource.save public_url: public_url
46
38
  end
47
- expect(resp).to be_instance_of(Yadisk::Link)
48
- end
39
+ }
40
+
41
+ it { expect(subject).to be_an Yadisk::Link }
49
42
  end
50
43
  end
51
44
  end
45
+ # rubocop:enable Metrics/BlockLength
@@ -2,71 +2,42 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe Yadisk::Client do
6
- let(:file_path) { "trash:/remote_path.txt_05572eeb69f47093eac51b40f1513d3bddff1b6c" }
7
- context "#trash" do
8
- it "#list - all", :vcr do
9
- name = "trash/GET_list"
10
- VCR.use_cassette(name, allow_playback_repeats: true) do
11
- resp = @yandex.trash.list(path: "/")
12
- CassetteHelpers::Use.new(name).url do |c|
13
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/trash/resources")
14
- expect(c.code).to eq(200)
15
- expect(c.method).to eq("get")
5
+ # rubocop:disable Metrics/BlockLength
6
+ RSpec.describe "#trash" do
7
+ describe ".delete" do
8
+ context "when params is OK" do
9
+ subject {
10
+ VCR.use_cassette("trash/delete") do
11
+ @yandex.trash.delete path: "yadisk_created_dir_12b63824b98bc5eb70d25c703cfc3224a46e6896"
16
12
  end
17
- expect(resp).to be_instance_of(Yadisk::TrashResource)
18
- end
19
- end
13
+ }
20
14
 
21
- it "#list - single file", :vcr do
22
- name = "trash/GET_list"
23
- VCR.use_cassette(name, allow_playback_repeats: true) do
24
- resp = @yandex.trash.list(path: file_path)
25
- CassetteHelpers::Use.new(name).url do |c|
26
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/trash/resources")
27
- expect(c.code).to eq(200)
28
- expect(c.method).to eq("get")
29
- end
30
- expect(resp).to be_instance_of(Yadisk::TrashResource)
31
- end
15
+ it { expect(subject).to be_an Yadisk::Link }
32
16
  end
17
+ end
33
18
 
34
- it "#restore", :vcr do
35
- name = "trash/PUT_restore"
36
- VCR.use_cassette(name, allow_playback_repeats: true) do
37
- resp = @yandex.trash.restore(path: file_path)
38
- CassetteHelpers::Use.new(name).url do |c|
39
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/resources?path=remote_path.txt")
40
- expect(c.code).to eq(204)
41
- expect(c.method).to eq("put")
19
+ describe ".list" do
20
+ context "when params is OK" do
21
+ subject {
22
+ VCR.use_cassette("trash/list") do
23
+ @yandex.trash.list path: ""
42
24
  end
43
- expect(resp).to be_instance_of(Yadisk::Link)
44
- end
45
- end
25
+ }
46
26
 
47
- it "#delete - ok", :vcr do
48
- name = "trash/DELETE_delete"
49
- VCR.use_cassette(name, allow_playback_repeats: true) do
50
- resp = @yandex.trash.delete(path: "trash:/remote_file.txt_f7fc32168f3b30e60994fd2e82af7d230dab5c91")
51
- CassetteHelpers::Use.new(name) do |c|
52
- expect(c.url).to eq("https://cloud-api.yandex.net/v1/disk/trash/resources")
53
- expect(c.code).to eq(200)
54
- expect(c.method).to eq("delete")
55
- end
56
- expect(resp).to be_instance_of(Yadisk::Link)
57
- end
27
+ it { expect(subject).to be_an Yadisk::TrashResource }
58
28
  end
29
+ end
59
30
 
60
- # if error raised
61
- describe "#delete - DiskNotFoundError" do
62
- let(:request) { @yandex.trash.delete(path: file_path) }
63
- it "#delete - file not found", :vcr do
64
- name = "trash/DELETE_delete_error"
65
- VCR.use_cassette(name, allow_playback_repeats: true) do
66
- expect { request }.to raise_error(Yadisk::Error)
67
- .with_message(/DiskNotFoundError/)
31
+ describe ".restore" do
32
+ context "when params is OK" do
33
+ subject {
34
+ VCR.use_cassette("trash/restore") do
35
+ @yandex.trash.restore path: "yadisk_created_dir_857c8d0feba033c7559ade2c7c07fef3ae41c046"
68
36
  end
69
- end
37
+ }
38
+
39
+ it { expect(subject).to be_an Yadisk::Link }
70
40
  end
71
41
  end
72
42
  end
43
+ # rubocop:enable Metrics/BlockLength