social_snippet 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +8 -8
  2. data/.travis.yml +11 -4
  3. data/README.md +6 -6
  4. data/Rakefile +19 -1
  5. data/lib/social_snippet.rb +11 -0
  6. data/lib/social_snippet/api/install_repository_api.rb +23 -82
  7. data/lib/social_snippet/api/manifest_api.rb +3 -3
  8. data/lib/social_snippet/api/update_repository_api.rb +34 -35
  9. data/lib/social_snippet/command_line/sspm/sub_commands/install_command.rb +7 -7
  10. data/lib/social_snippet/config.rb +18 -8
  11. data/lib/social_snippet/core.rb +13 -0
  12. data/lib/social_snippet/document.rb +2 -0
  13. data/lib/social_snippet/document_backend.rb +2 -0
  14. data/lib/social_snippet/document_backend/yaml_document.rb +252 -0
  15. data/lib/social_snippet/document_backend/yaml_document/query.rb +45 -0
  16. data/lib/social_snippet/repository.rb +2 -2
  17. data/lib/social_snippet/repository/driver_factory.rb +42 -0
  18. data/lib/social_snippet/repository/drivers.rb +3 -2
  19. data/lib/social_snippet/repository/drivers/driver_base.rb +100 -0
  20. data/lib/social_snippet/repository/drivers/entry.rb +11 -0
  21. data/lib/social_snippet/repository/drivers/git_driver.rb +100 -0
  22. data/lib/social_snippet/repository/models.rb +15 -0
  23. data/lib/social_snippet/repository/models/package.rb +97 -0
  24. data/lib/social_snippet/repository/models/repository.rb +94 -0
  25. data/lib/social_snippet/repository/repository_manager.rb +79 -67
  26. data/lib/social_snippet/resolvers/base_resolver.rb +13 -17
  27. data/lib/social_snippet/rspec/test_document.rb +305 -0
  28. data/lib/social_snippet/rspec/test_driver.rb +76 -0
  29. data/lib/social_snippet/rspec/test_storage.rb +459 -0
  30. data/lib/social_snippet/storage.rb +1 -0
  31. data/lib/social_snippet/storage_backend.rb +3 -0
  32. data/lib/social_snippet/storage_backend/file_system_storage.rb +71 -0
  33. data/lib/social_snippet/storage_backend/storage_base.rb +35 -0
  34. data/lib/social_snippet/version.rb +8 -3
  35. data/spec/helpers/codeclimate_helper.rb +1 -1
  36. data/spec/helpers/fakefs_helper.rb +10 -0
  37. data/spec/helpers/social_snippet_helper.rb +117 -0
  38. data/spec/lib/api/insert_snippet_spec.rb +95 -2
  39. data/spec/lib/api/update_repository_spec.rb +196 -0
  40. data/spec/lib/command_line/sspm_install_spec.rb +169 -180
  41. data/spec/lib/command_line/sspm_update_spec.rb +56 -0
  42. data/spec/lib/config_spec.rb +6 -8
  43. data/spec/lib/core_spec.rb +21 -38
  44. data/spec/lib/file_system_storage_spec.rb +170 -0
  45. data/spec/lib/insert_resolver_spec.rb +15 -2
  46. data/spec/lib/registry_client_spec.rb +6 -9
  47. data/spec/lib/repository/driver_base_spec.rb +89 -0
  48. data/spec/lib/repository/git_driver_spec.rb +10 -0
  49. data/spec/lib/repository/package_spec.rb +172 -0
  50. data/spec/lib/repository/repository_factory_spec.rb +67 -22
  51. data/spec/lib/repository/repository_manager_spec.rb +71 -114
  52. data/spec/lib/repository/repository_spec.rb +191 -0
  53. data/spec/lib/yaml_document_spec.rb +14 -0
  54. data/spec/spec_helper.rb +8 -93
  55. data/test/config_test.rb +6 -7
  56. data/test/driver_base_test.rb +201 -0
  57. data/test/git_driver_test.rb +51 -0
  58. data/test/insert_snippet_test.rb +256 -349
  59. data/test/repository_manager_test.rb +7 -16
  60. data/test/yaml_document_test.rb +97 -0
  61. metadata +44 -16
  62. data/lib/social_snippet/repository/drivers/base_repository.rb +0 -189
  63. data/lib/social_snippet/repository/drivers/git_repository.rb +0 -74
  64. data/lib/social_snippet/repository/repository_factory.rb +0 -59
  65. data/lib/social_snippet/repository/repository_installer.rb +0 -85
  66. data/spec/lib/repository/base_repository_spec.rb +0 -104
  67. data/spec/lib/repository/git_repository_spec.rb +0 -83
  68. data/spec/lib/repository/repository_installer_spec.rb +0 -63
  69. data/test/base_repository_test.rb +0 -375
  70. data/test/git_repository_test.rb +0 -114
@@ -1,375 +0,0 @@
1
- require "spec_helper"
2
-
3
- module SocialSnippet::Repository::Drivers
4
-
5
- describe BaseRepository do
6
-
7
- describe "version" do
8
-
9
- context "new path/to/repo" do
10
-
11
- let(:repo) { BaseRepository.new('/path/to/repo') }
12
-
13
- context "version only cases" do
14
-
15
- context "has 0.0.1" do
16
-
17
- before do
18
- allow(repo).to receive(:refs).and_return([
19
- '0.0.1',
20
- ])
21
- end
22
-
23
- describe "versions" do
24
- let(:result) { repo.versions }
25
- it { expect(result.length).to eq 1 }
26
- it { expect(result).to include '0.0.1' }
27
- end # versions
28
-
29
- describe "latest_version" do
30
- it { expect(repo.latest_version).to eq '0.0.1' }
31
- it { expect(repo.latest_version('0')).to eq '0.0.1' }
32
- it { expect(repo.latest_version('0.0')).to eq '0.0.1' }
33
- it { expect(repo.latest_version('0.0.1')).to eq '0.0.1' }
34
- it { expect(repo.latest_version('1.0')).to be_nil }
35
- end # latest_version
36
-
37
- end # has 0.0.1
38
-
39
- context "has 0.0.1, 0.0.2, 0.0.3, 1.0.0" do
40
-
41
- before do
42
- allow(repo).to receive(:refs).and_return([
43
- '0.0.1',
44
- '0.0.2',
45
- '0.0.3',
46
- '1.0.0',
47
- ])
48
- end
49
-
50
- describe "versions" do
51
-
52
- let(:result) { repo.versions }
53
-
54
- it { expect(result.length).to eq 4 }
55
-
56
- context "check result" do
57
- subject { result }
58
- it { should include '0.0.1' }
59
- it { should include '0.0.2' }
60
- it { should include '0.0.3' }
61
- it { should include '1.0.0' }
62
- end
63
-
64
- end # versions
65
-
66
- describe "latest_version" do
67
- it { expect(repo.latest_version).to eq '1.0.0' }
68
- it { expect(repo.latest_version('0')).to eq '0.0.3' }
69
- it { expect(repo.latest_version('0.0')).to eq '0.0.3' }
70
- it { expect(repo.latest_version('1')).to eq '1.0.0' }
71
- it { expect(repo.latest_version('0.1')).to be_nil }
72
- end # latest_version
73
-
74
- end # has 0.0.1, 0.0.2, 0.0.3, 1.0.0
75
-
76
- context "has 1.2.3, 100.2.300, 123.456.789" do
77
-
78
- before do
79
- allow(repo).to receive(:refs).and_return([
80
- '1.2.3',
81
- '100.2.300',
82
- '123.456.789',
83
- ])
84
- end
85
-
86
- describe "versions" do
87
-
88
- let(:result) { repo.versions }
89
-
90
- it { expect(result.length).to eq 3 }
91
-
92
- context "check result" do
93
- subject { result }
94
- it { should include '1.2.3' }
95
- it { should include '100.2.300' }
96
- it { should include '123.456.789' }
97
- end
98
-
99
- end # versions
100
-
101
- describe "latest_version" do
102
- it { expect(repo.latest_version).to eq '123.456.789' }
103
- it { expect(repo.latest_version('0')).to be_nil }
104
- it { expect(repo.latest_version('0.0')).to be_nil }
105
- it { expect(repo.latest_version('1')).to eq '1.2.3' }
106
- it { expect(repo.latest_version('100')).to eq '100.2.300' }
107
- it { expect(repo.latest_version('100.2')).to eq '100.2.300' }
108
- it { expect(repo.latest_version('123')).to eq '123.456.789' }
109
- it { expect(repo.latest_version('123.456')).to eq '123.456.789' }
110
- end # latest_version
111
-
112
- end # has 1.2.3, 100.2.300, 123.456.789
113
-
114
- end # version only cases
115
-
116
- context "include not version cases" do
117
-
118
- context "has master, develop, 0.0.1, 0.1.0, 1.0.0" do
119
-
120
- before do
121
- allow(repo).to receive(:refs).and_return([
122
- 'master',
123
- 'develop',
124
- '0.0.1',
125
- '0.1.0',
126
- '1.0.0',
127
- ])
128
- end
129
-
130
- describe "versions" do
131
- let(:result) { repo.versions }
132
-
133
- it { expect(result.length).to eq 3 }
134
-
135
- context "check result" do
136
- subject { result }
137
- it { should include '0.0.1' }
138
- it { should include '0.1.0' }
139
- it { should include '1.0.0' }
140
- end
141
- end # versions
142
-
143
- describe "latest_version" do
144
- it { expect(repo.latest_version).to eq '1.0.0' }
145
- it { expect(repo.latest_version('0')).to eq '0.1.0' }
146
- it { expect(repo.latest_version('0.0')).to eq '0.0.1' }
147
- it { expect(repo.latest_version('1')).to eq '1.0.0' }
148
- it { expect(repo.latest_version('100')).to be_nil }
149
- it { expect(repo.latest_version('100.2')).to be_nil }
150
- it { expect(repo.latest_version('123')).to be_nil}
151
- it { expect(repo.latest_version('123.456')).to be_nil }
152
- it { expect(repo.latest_version('master')).to be_nil }
153
- it { expect(repo.latest_version('develop')).to be_nil }
154
- end # latest_version
155
-
156
- end # has master, develop, 0.0.1, 0.1.0, 1.0.0
157
-
158
- context "has master, feature/0.0.1, 0.0.1/test, 001, 0.0, 1, 1.2.3" do
159
-
160
- before do
161
- allow(repo).to receive(:refs).and_return([
162
- 'master',
163
- 'feature/0.0.1',
164
- '0.0.1/test',
165
- '001',
166
- '0.0',
167
- '1',
168
- '1.2.3',
169
- ])
170
- end
171
-
172
- describe "versions" do
173
-
174
- let(:result) { repo.versions }
175
-
176
- it { expect(result.length).to eq 1 }
177
- it { expect(result).to include '1.2.3' }
178
-
179
- end # versions
180
-
181
- describe "latest_version" do
182
- it { expect(repo.latest_version).to eq '1.2.3' }
183
- it { expect(repo.latest_version('0')).to be_nil }
184
- it { expect(repo.latest_version('0.0')).to be_nil }
185
- it { expect(repo.latest_version('1')).to eq '1.2.3' }
186
- it { expect(repo.latest_version('100')).to be_nil }
187
- it { expect(repo.latest_version('100.2')).to be_nil }
188
- it { expect(repo.latest_version('123')).to be_nil}
189
- it { expect(repo.latest_version('123.456')).to be_nil }
190
- it { expect(repo.latest_version('master')).to be_nil }
191
- it { expect(repo.latest_version('develop')).to be_nil }
192
- end # latest_version
193
-
194
- end # has master, feature/0.0.1, 0.0.1/test, 001, 0.0, 1, 1.2.3
195
-
196
- end # include not version cases
197
-
198
- end # new path/to/repo
199
-
200
- end # versions
201
-
202
- describe "cache test" do
203
-
204
- let(:commit_id) { "thisisdummyyyyy" }
205
-
206
- context "there is a repo" do
207
-
208
- before do
209
- FileUtils.mkdir_p "/path/to/repo_1"
210
- FileUtils.mkdir_p "/path/to/repo_1/.git"
211
- FileUtils.touch "/path/to/repo_1/snippet.json"
212
-
213
- File.write "/path/to/repo_1/snippet.json", [
214
- '{',
215
- ' "name": "repo_1",',
216
- ' "desc": "this is repo_1",',
217
- ' "language": "Ruby"',
218
- '}',
219
- ].join($/)
220
- end
221
-
222
- context "create repo_1 instance" do
223
-
224
- let(:cache_path) { "/path/to/cache" }
225
- before { FileUtils.mkdir_p(cache_path) }
226
-
227
- let(:instance) do
228
- repo = BaseRepository.new("/path/to/repo_1")
229
- repo.load_snippet_json
230
- return repo
231
- end
232
-
233
- context "name" do
234
- subject { instance.name }
235
- it { should eq "repo_1" }
236
- end
237
-
238
- context "create cache" do
239
- before do
240
- expect(instance).to receive(:commit_id).and_return commit_id
241
- instance.create_cache(cache_path)
242
- end
243
-
244
- context "snippet.json" do
245
- let(:result) { JSON.parse File.read "#{cache_path}/repo_1/#{commit_id[0..7]}/snippet.json" }
246
- it { expect(result["name"]).to eq "repo_1" }
247
- it { expect(result["desc"]).to eq "this is repo_1" }
248
- it { expect(result["language"]).to eq "Ruby" }
249
- end
250
-
251
- end # create cache
252
-
253
- end # create repo_1 instance
254
-
255
- end # there is a repo
256
-
257
- context "there are three repos" do
258
-
259
- before do
260
- # create repo_1
261
- FileUtils.mkdir_p "/path/to/repo_1"
262
- FileUtils.mkdir_p "/path/to/repo_1/.git"
263
- FileUtils.touch "/path/to/repo_1/snippet.json"
264
- File.write "/path/to/repo_1/snippet.json", [
265
- '{',
266
- ' "name": "repo_1",',
267
- ' "desc": "this is repo_1",',
268
- ' "language": "Ruby"',
269
- '}',
270
- ].join($/)
271
-
272
- # create repo_b
273
- FileUtils.mkdir_p "/path/to/repo_b"
274
- FileUtils.mkdir_p "/path/to/repo_b/.git"
275
- FileUtils.touch "/path/to/repo_b/snippet.json"
276
- File.write "/path/to/repo_b/snippet.json", [
277
- '{',
278
- ' "name": "repo_b",',
279
- ' "desc": "this is repo_b",',
280
- ' "language": "Ruby"',
281
- '}',
282
- ].join($/)
283
-
284
- # create repo_3
285
- FileUtils.mkdir_p "/path/to/repo_3"
286
- FileUtils.mkdir_p "/path/to/repo_3/.git"
287
- FileUtils.touch "/path/to/repo_3/snippet.json"
288
- File.write "/path/to/repo_3/snippet.json", [
289
- '{',
290
- ' "name": "repo_3",',
291
- ' "desc": "this is repo_3",',
292
- ' "language": "Ruby"',
293
- '}',
294
- ].join($/)
295
- end # before
296
-
297
- context "create three instances" do
298
-
299
- let(:instance_1) { BaseRepository.new("/path/to/repo_1") }
300
- let(:instance_b) { BaseRepository.new("/path/to/repo_b") }
301
- let(:instance_3) { BaseRepository.new("/path/to/repo_3") }
302
-
303
- before do
304
- instance_1.load_snippet_json
305
- instance_b.load_snippet_json
306
- instance_3.load_snippet_json
307
- end
308
-
309
- context "name" do
310
- it { expect(instance_1.name).to eq "repo_1" }
311
- it { expect(instance_b.name).to eq "repo_b" }
312
- it { expect(instance_3.name).to eq "repo_3" }
313
- end
314
-
315
- context "create cache" do
316
-
317
- # create cache dir
318
- let(:cache_path) { "/path/to/cache" }
319
- before { FileUtils.mkdir_p(cache_path) }
320
-
321
- before do
322
- expect(instance_1).to receive(:commit_id).and_return commit_id
323
- expect(instance_b).to receive(:commit_id).and_return commit_id
324
- expect(instance_3).to receive(:commit_id).and_return commit_id
325
- end
326
-
327
- before do
328
- instance_1.create_cache(cache_path)
329
- instance_b.create_cache(cache_path)
330
- instance_3.create_cache(cache_path)
331
- end
332
-
333
- context "snippet.json" do
334
-
335
- context "repo_1" do
336
- let(:result) do
337
- JSON.parse File.read "#{cache_path}/repo_1/#{commit_id[0..7]}/snippet.json"
338
- end
339
- it { expect(result["name"]).to eq "repo_1" }
340
- it { expect(result["desc"]).to eq "this is repo_1" }
341
- it { expect(result["language"]).to eq "Ruby" }
342
- end
343
-
344
- context "repo_b" do
345
- let(:result) do
346
- JSON.parse File.read "#{cache_path}/repo_b/#{commit_id[0..7]}/snippet.json"
347
- end
348
- it { expect(result["name"]).to eq "repo_b" }
349
- it { expect(result["desc"]).to eq "this is repo_b" }
350
- it { expect(result["language"]).to eq "Ruby" }
351
- end
352
-
353
- context "repo_3" do
354
- let(:result) do
355
- JSON.parse File.read "#{cache_path}/repo_3/#{commit_id[0..7]}/snippet.json"
356
- end
357
- it { expect(result["name"]).to eq "repo_3" }
358
- it { expect(result["desc"]).to eq "this is repo_3" }
359
- it { expect(result["language"]).to eq "Ruby" }
360
- end
361
-
362
- end # snippet.json
363
-
364
- end # create cache
365
-
366
- end # create three instances
367
-
368
- end # there are three repos
369
-
370
- end # .new
371
-
372
- end # BaseRepository
373
-
374
- end # SocialSnippet::Repository
375
-
@@ -1,114 +0,0 @@
1
- require "spec_helper"
2
-
3
- module ::SocialSnippet::Repository
4
-
5
- describe Drivers::GitRepository do
6
-
7
- class FakeClass; end
8
-
9
- def create_fake_instance
10
- FakeClass.new
11
- end
12
-
13
- def create_branch(name)
14
- branch = create_fake_instance
15
- allow(branch).to receive(:name).and_return "refs/remotes/origin/#{name}"
16
- branch
17
- end
18
-
19
- def create_tag(name)
20
- branch = create_fake_instance
21
- allow(branch).to receive(:name).and_return "refs/tags/#{name}"
22
- branch
23
- end
24
-
25
- before do
26
- class FakeDriver < Drivers::GitRepository; end
27
- allow(Rugged::Repository).to receive(:new) do
28
- rugged_repo = create_fake_instance
29
-
30
- allow(rugged_repo).to receive(:references).and_return [
31
- create_branch("master"),
32
- create_branch("develop"),
33
- create_tag("0.0.1"),
34
- create_tag("0.0.2"),
35
- ]
36
- rugged_repo
37
- end
38
- @repo = FakeDriver.new("/path/to/repo")
39
- end
40
-
41
- describe "#refs" do
42
- it { expect(@repo.refs.length).to eq 4 }
43
- it { expect(@repo.refs).to include "master" }
44
- it { expect(@repo.refs).to include "develop" }
45
- it { expect(@repo.refs).to include "0.0.1" }
46
- it { expect(@repo.refs).to include "0.0.2" }
47
- end
48
-
49
- describe "#remote_refs" do
50
- it { expect(@repo.remote_refs.length).to eq 2 }
51
- it { expect(@repo.remote_refs).to include "master" }
52
- it { expect(@repo.remote_refs).to include "develop" }
53
- it { expect(@repo.remote_refs).to_not include "0.0.1" }
54
- it { expect(@repo.remote_refs).to_not include "0.0.2" }
55
- end
56
-
57
- end
58
-
59
- describe Drivers::GitRepository, :without_fakefs => true do
60
-
61
- before do
62
- disable_fakefs
63
- make_fake_home
64
- end
65
-
66
- before do
67
- @curdir = Dir.pwd
68
- @tmpdir = Dir.mktmpdir
69
- Dir.chdir @tmpdir
70
- end
71
-
72
- after do
73
- Dir.chdir @curdir
74
- FileUtils.rm_r @tmpdir
75
- end
76
-
77
- context "clone example-repo" do
78
- before do
79
- @cloned_repo = RepositoryFactory.clone "git://github.com/social-snippet/example-repo"
80
- end
81
-
82
- context "checkout 1.0.0" do
83
- before do
84
- @cloned_repo.checkout "1.0.0"
85
- end
86
-
87
- context "load snippet json" do
88
- before do
89
- @cloned_repo.load_snippet_json
90
- end
91
-
92
- context "create cache" do
93
-
94
- before do
95
- @cloned_repo.create_cache("./cache")
96
- end
97
-
98
- it do
99
- expect(@cloned_repo.commit_id).to eq "efa58ecae07cf3d063ae75fa97fce164c56d205a"
100
- end
101
-
102
- it do
103
- expect(File.exists?("#{@cloned_repo.cache_path}")).to be_truthy
104
- end
105
-
106
- end
107
- end
108
- end
109
-
110
- end # clone example-repo
111
-
112
- end # Drivers::GitRepository
113
-
114
- end # ::SocialSnippet::Repository