social_snippet-registry_core 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +15 -0
  2. data/.components +9 -0
  3. data/.gitignore +18 -0
  4. data/.travis.yml +26 -0
  5. data/Gemfile +17 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +31 -0
  8. data/Rakefile +15 -0
  9. data/config.ru +9 -0
  10. data/config/apps.rb +26 -0
  11. data/config/boot.rb +50 -0
  12. data/config/database.rb +45 -0
  13. data/lib/social_snippet/registry/webapi.rb +5 -0
  14. data/lib/social_snippet/registry/webapi/controllers/v0/repositories_controller.rb +37 -0
  15. data/lib/social_snippet/registry/webapi/controllers/v0/token_controller.rb +13 -0
  16. data/lib/social_snippet/registry/webapi/controllers/v0/user_controller.rb +49 -0
  17. data/lib/social_snippet/registry/webapi/helpers/repository_helper.rb +18 -0
  18. data/lib/social_snippet/registry/webapi/helpers/url_helper.rb +29 -0
  19. data/lib/social_snippet/registry/webapi/models/repository.rb +75 -0
  20. data/lib/social_snippet/registry/webapi/models/user_account.rb +30 -0
  21. data/lib/social_snippet/registry/webapi/webapi_base.rb +12 -0
  22. data/lib/social_snippet/registry/webapi/webapi_v0.rb +3 -0
  23. data/lib/social_snippet/registry_core.rb +8 -0
  24. data/lib/social_snippet/registry_core/common_helpers.rb +11 -0
  25. data/lib/social_snippet/registry_core/config_helpers.rb +95 -0
  26. data/lib/social_snippet/registry_core/fetcher.rb +3 -0
  27. data/lib/social_snippet/registry_core/fetcher/fetcher_base.rb +19 -0
  28. data/lib/social_snippet/registry_core/fetcher/github_fetcher.rb +69 -0
  29. data/lib/social_snippet/registry_core/version.rb +5 -0
  30. data/lib/social_snippet/registry_core/version_helpers.rb +21 -0
  31. data/social_snippet-registry_core.gemspec +36 -0
  32. data/spec/spec_helper.rb +9 -0
  33. data/spec/spec_helpers/database_cleaner_helper.rb +18 -0
  34. data/spec/spec_helpers/factory_girl_helper.rb +9 -0
  35. data/spec/spec_helpers/rack_test_helper.rb +18 -0
  36. data/spec/webapi/controllers/v0/repositories_controller_spec.rb +232 -0
  37. data/spec/webapi/helpers/url_helper_spec.rb +49 -0
  38. data/spec/webapi/models/repository_spec.rb +72 -0
  39. metadata +256 -0
@@ -0,0 +1,18 @@
1
+ require "rack/test"
2
+
3
+ RSpec.configure do |config|
4
+ config.include Rack::Test::Methods
5
+ end
6
+
7
+ # You can use this method to custom specify a Rack app
8
+ # you want rack-test to invoke:
9
+ #
10
+ # app Hoge::App
11
+ # app Hoge::App.tap { |a| }
12
+ # app(Hoge::App) do
13
+ # set :foo, :bar
14
+ # end
15
+ def app(app = nil, &blk)
16
+ @app ||= block_given? ? app.instance_eval(&blk) : app
17
+ @app ||= Padrino.application
18
+ end
@@ -0,0 +1,232 @@
1
+ require "spec_helper"
2
+
3
+ describe SocialSnippet::Registry::WebAPI::WebAPIv0 do
4
+
5
+ describe "repository_controller" do
6
+
7
+ app SocialSnippet::Registry::WebAPI::WebAPIv0
8
+
9
+ let(:api_version) { '/v0' }
10
+
11
+ context "add my-repo" do
12
+
13
+ before do
14
+ FactoryGirl.define do
15
+ factory "my-repo", :class => Repository do
16
+ name "my-repo"
17
+ desc "This is my repository"
18
+ url "git://github.com/user/my-repo.git"
19
+ end
20
+ end # define my-repo
21
+
22
+ FactoryGirl.create "my-repo"
23
+ end # prepare my-repo
24
+
25
+ context "get repositories/my-repo" do
26
+
27
+ before { get "#{api_version}/repositories/my-repo" }
28
+ it { expect(last_response).to be_ok }
29
+
30
+ context "check result" do
31
+ let(:result) { JSON.parse(last_response.body) }
32
+ it { expect(result["name"]).to eq "my-repo" }
33
+ it { expect(result["url"]).to eq "git://github.com/user/my-repo.git" }
34
+ it { expect(result["desc"]).to eq "This is my repository" }
35
+ it { expect(result["dependencies"]).to be_empty }
36
+ end
37
+
38
+ end
39
+
40
+ context "get repositories" do
41
+
42
+ before do
43
+ get "#{api_version}/repositories"
44
+ end
45
+
46
+ it { expect(last_response).to be_ok }
47
+
48
+ context "check result json" do
49
+ let(:result) { JSON.parse(last_response.body) }
50
+ it { expect(result.length).to eq 1 }
51
+ it { expect(result[0]["name"]).to eq "my-repo" }
52
+ it { expect(result[0]["url"]).to eq "git://github.com/user/my-repo.git" }
53
+ it { expect(result[0]["desc"]).to eq "This is my repository" }
54
+ end # check result json
55
+
56
+ end # get repositories
57
+
58
+ context "add new-repo" do
59
+
60
+ context "post repositories" do
61
+
62
+ let(:new_repo_url_raw) { "git://github.com/user/new-repo" }
63
+ let(:new_repo_url) { URI.encode_www_form_component new_repo_url_raw }
64
+
65
+ before do
66
+ allow_any_instance_of(::SocialSnippet::Registry::WebAPI::WebAPIv0).to receive(:create_fetcher) do
67
+ class Dummy; end
68
+ dummy = Dummy.new
69
+ allow(dummy).to receive(:snippet_json) do |_|
70
+ {
71
+ "name" => "new-repo",
72
+ "desc" => "This is new repo",
73
+ "language" => "C++",
74
+ "main" => "src",
75
+ "dependencies" => {
76
+ "my-repo" => "1.0.0",
77
+ },
78
+ }
79
+ end
80
+ dummy
81
+ end
82
+ end # clone dummy repo
83
+
84
+ context "post by json params" do
85
+
86
+ before do
87
+ # TODO: check without token
88
+ header "X-CSRF-TOKEN", "dummy-token"
89
+ data = {
90
+ "url" => new_repo_url_raw,
91
+ }
92
+ post(
93
+ "#{api_version}/repositories",
94
+ data.to_json,
95
+ {
96
+ "CONTENT_TYPE" => "application/json",
97
+ "rack.session" => {
98
+ :csrf => "dummy-token",
99
+ },
100
+ },
101
+ )
102
+ end
103
+
104
+ it "", :current => true do; end # TODO: remove
105
+
106
+ it { expect(last_response).to be_ok }
107
+
108
+ context "check result model" do
109
+
110
+ let(:repo) { Repository.find_by(:name => "new-repo") }
111
+ it { expect(repo.name).to eq "new-repo" }
112
+ it { expect(repo.url).to eq "git://github.com/user/new-repo.git" }
113
+
114
+ end # check result model
115
+
116
+ context "with query" do
117
+
118
+ context "get repositories?q=new" do
119
+
120
+ before { get "#{api_version}/repositories?q=new" }
121
+
122
+ it { expect(last_response).to be_ok }
123
+
124
+ context "check result json" do
125
+ let(:result) { JSON.parse(last_response.body) }
126
+ it { expect(result.length).to eq 1 }
127
+ it { expect(result[0]["name"]).to eq "new-repo" }
128
+ it { expect(result[0]["url"]).to eq "git://github.com/user/new-repo.git" }
129
+ it { expect(result[0]["desc"]).to eq "This is new repo" }
130
+ end
131
+
132
+ end # get repositories?q=new
133
+
134
+ context "get repositories?q=my" do
135
+
136
+ before { get "#{api_version}/repositories?q=my" }
137
+
138
+ it { expect(last_response).to be_ok }
139
+
140
+ context "check result json" do
141
+ let(:result) { JSON.parse(last_response.body) }
142
+ it { expect(result.length).to eq 1 }
143
+ it { expect(result[0]["name"]).to eq "my-repo" }
144
+ it { expect(result[0]["url"]).to eq "git://github.com/user/my-repo.git" }
145
+ it { expect(result[0]["desc"]).to eq "This is my repository" }
146
+ end
147
+
148
+ end # get repositories?q=new
149
+
150
+ end # with query
151
+
152
+ end # post by query params
153
+
154
+ context "post by query params" do
155
+
156
+ before do
157
+ # TODO: check without token
158
+ header "X-CSRF-TOKEN", "dummy-token"
159
+ post(
160
+ "#{api_version}/repositories?url=#{new_repo_url}",
161
+ {
162
+ },
163
+ {
164
+ "rack.session" => {
165
+ :csrf => "dummy-token",
166
+ },
167
+ }
168
+ )
169
+ end
170
+
171
+ it { expect(last_response).to be_ok }
172
+
173
+ context "check result model" do
174
+
175
+ let(:repo) do
176
+ Repository.find_by(:name => "new-repo")
177
+ end
178
+
179
+ it { expect(repo.name).to eq "new-repo" }
180
+ it { expect(repo.url).to eq "git://github.com/user/new-repo.git" }
181
+ it { expect(repo.dependencies).to_not be_empty }
182
+ it { expect(repo.dependencies.length).to eq 1 }
183
+
184
+ end # check result model
185
+
186
+ context "with query" do
187
+
188
+ context "get repositories?q=new" do
189
+
190
+ before { get "#{api_version}/repositories?q=new" }
191
+
192
+ it { expect(last_response).to be_ok }
193
+
194
+ context "check result json" do
195
+ let(:result) { JSON.parse(last_response.body) }
196
+ it { expect(result.length).to eq 1 }
197
+ it { expect(result[0]["name"]).to eq "new-repo" }
198
+ it { expect(result[0]["url"]).to eq "git://github.com/user/new-repo.git" }
199
+ it { expect(result[0]["desc"]).to eq "This is new repo" }
200
+ end
201
+
202
+ end # get repositories?q=new
203
+
204
+ context "get repositories?q=my" do
205
+
206
+ before { get "#{api_version}/repositories?q=my" }
207
+
208
+ it { expect(last_response).to be_ok }
209
+
210
+ context "check result json" do
211
+ let(:result) { JSON.parse(last_response.body) }
212
+ it { expect(result.length).to eq 1 }
213
+ it { expect(result[0]["name"]).to eq "my-repo" }
214
+ it { expect(result[0]["url"]).to eq "git://github.com/user/my-repo.git" }
215
+ it { expect(result[0]["desc"]).to eq "This is my repository" }
216
+ end
217
+
218
+ end # get repositories?q=new
219
+
220
+ end # with query
221
+
222
+ end # post by query params
223
+
224
+ end # post repositories
225
+
226
+ end # add new-repo
227
+
228
+ end # add my-repo
229
+
230
+ end # repositories_controller
231
+
232
+ end # SocialSnippet::Registry::WebAPI::Versions::WebAPIv0
@@ -0,0 +1,49 @@
1
+ require "spec_helper"
2
+
3
+ module ::SocialSnippet::Registry::WebAPI::Helpers
4
+
5
+ describe UrlHelper do
6
+
7
+ include UrlHelper
8
+
9
+ context "with .git" do
10
+
11
+ context "https" do
12
+ subject { normalize_url("https://github.com/user/repo.git") }
13
+ it { should eq "git://github.com/user/repo.git" }
14
+ end
15
+
16
+ context "http" do
17
+ subject { normalize_url("http://github.com/user/repo.git") }
18
+ it { should eq "git://github.com/user/repo.git" }
19
+ end
20
+
21
+ context "git" do
22
+ subject { normalize_url("git://github.com/user/repo.git") }
23
+ it { should eq "git://github.com/user/repo.git" }
24
+ end
25
+
26
+ end # without .git
27
+
28
+ context "without .git" do
29
+
30
+ context "https" do
31
+ subject { normalize_url("https://github.com/user/repo") }
32
+ it { should eq "git://github.com/user/repo.git" }
33
+ end
34
+
35
+ context "http" do
36
+ subject { normalize_url("http://github.com/user/repo") }
37
+ it { should eq "git://github.com/user/repo.git" }
38
+ end
39
+
40
+ context "git" do
41
+ subject { normalize_url("git://github.com/user/repo") }
42
+ it { should eq "git://github.com/user/repo.git" }
43
+ end
44
+
45
+ end # without .git
46
+
47
+ end # url_helper
48
+
49
+ end # ::SocialSnippet::Registry::WebAPI::Helpers
@@ -0,0 +1,72 @@
1
+ require "spec_helper"
2
+
3
+ describe Repository do
4
+
5
+ describe "#to_object" do
6
+
7
+ context "create model" do
8
+
9
+ let(:model) do
10
+ Repository.new(
11
+ :name => "my-repo",
12
+ :desc => "thisisdesc",
13
+ :url => "git://url/to/git/repo",
14
+ )
15
+ end
16
+
17
+ context "call to_object" do
18
+ let(:result) { model.to_object }
19
+ it { expect(result[:name]).to eq "my-repo" }
20
+ it { expect(result[:desc]).to eq "thisisdesc" }
21
+ it { expect(result[:url]).to eq "git://url/to/git/repo" }
22
+ end # call to_object
23
+
24
+ end # create model
25
+
26
+ end # to_object
27
+
28
+ describe "#update_by_snippet_json" do
29
+
30
+ context "create model" do
31
+
32
+ let(:model) do
33
+ Repository.new(
34
+ :name => "my-repo",
35
+ :desc => "thisisdesc",
36
+ :url => "git://url/to/git/repo",
37
+ )
38
+ end
39
+
40
+ context "create repo" do
41
+
42
+ let(:json_obj) do
43
+ {
44
+ "name" => "new-repo",
45
+ "desc" => "this is new desc",
46
+ "dependencies" => {
47
+ "my-repo" => "1.0.0",
48
+ },
49
+ }
50
+ end
51
+
52
+ context "call update_by" do
53
+
54
+ before { model.update_by_snippet_json(json_obj) }
55
+
56
+ context "call to_object" do
57
+ let(:result) { model.to_object }
58
+ it { expect(result[:name]).to eq "my-repo" }
59
+ it { expect(result[:desc]).to eq "this is new desc" }
60
+ it { expect(result[:dependencies]).to include "my-repo" }
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
67
+ end # create model
68
+
69
+ end # update_by_real_repo
70
+
71
+ end # Repository
72
+
metadata ADDED
@@ -0,0 +1,256 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: social_snippet-registry_core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hiroyuki Sano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: padrino
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0.12'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thin
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mongoid
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-parser
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rack-tracker
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: slim
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: dalli
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: version_sorter
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: octokit
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: omniauth-github
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ! '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description:
182
+ email:
183
+ - sh19910711@gmail.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - .components
189
+ - .gitignore
190
+ - .travis.yml
191
+ - Gemfile
192
+ - LICENSE.txt
193
+ - README.md
194
+ - Rakefile
195
+ - config.ru
196
+ - config/apps.rb
197
+ - config/boot.rb
198
+ - config/database.rb
199
+ - lib/social_snippet/registry/webapi.rb
200
+ - lib/social_snippet/registry/webapi/controllers/v0/repositories_controller.rb
201
+ - lib/social_snippet/registry/webapi/controllers/v0/token_controller.rb
202
+ - lib/social_snippet/registry/webapi/controllers/v0/user_controller.rb
203
+ - lib/social_snippet/registry/webapi/helpers/repository_helper.rb
204
+ - lib/social_snippet/registry/webapi/helpers/url_helper.rb
205
+ - lib/social_snippet/registry/webapi/models/repository.rb
206
+ - lib/social_snippet/registry/webapi/models/user_account.rb
207
+ - lib/social_snippet/registry/webapi/webapi_base.rb
208
+ - lib/social_snippet/registry/webapi/webapi_v0.rb
209
+ - lib/social_snippet/registry_core.rb
210
+ - lib/social_snippet/registry_core/common_helpers.rb
211
+ - lib/social_snippet/registry_core/config_helpers.rb
212
+ - lib/social_snippet/registry_core/fetcher.rb
213
+ - lib/social_snippet/registry_core/fetcher/fetcher_base.rb
214
+ - lib/social_snippet/registry_core/fetcher/github_fetcher.rb
215
+ - lib/social_snippet/registry_core/version.rb
216
+ - lib/social_snippet/registry_core/version_helpers.rb
217
+ - social_snippet-registry_core.gemspec
218
+ - spec/spec_helper.rb
219
+ - spec/spec_helpers/database_cleaner_helper.rb
220
+ - spec/spec_helpers/factory_girl_helper.rb
221
+ - spec/spec_helpers/rack_test_helper.rb
222
+ - spec/webapi/controllers/v0/repositories_controller_spec.rb
223
+ - spec/webapi/helpers/url_helper_spec.rb
224
+ - spec/webapi/models/repository_spec.rb
225
+ homepage: https://sspm.herokuapp.com
226
+ licenses:
227
+ - MIT
228
+ metadata: {}
229
+ post_install_message:
230
+ rdoc_options: []
231
+ require_paths:
232
+ - lib
233
+ required_ruby_version: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - ! '>='
236
+ - !ruby/object:Gem::Version
237
+ version: '1.9'
238
+ required_rubygems_version: !ruby/object:Gem::Requirement
239
+ requirements:
240
+ - - ! '>='
241
+ - !ruby/object:Gem::Version
242
+ version: '0'
243
+ requirements: []
244
+ rubyforge_project:
245
+ rubygems_version: 2.4.5
246
+ signing_key:
247
+ specification_version: 4
248
+ summary: The server-side core classes for social-snippet-registry
249
+ test_files:
250
+ - spec/spec_helper.rb
251
+ - spec/spec_helpers/database_cleaner_helper.rb
252
+ - spec/spec_helpers/factory_girl_helper.rb
253
+ - spec/spec_helpers/rack_test_helper.rb
254
+ - spec/webapi/controllers/v0/repositories_controller_spec.rb
255
+ - spec/webapi/helpers/url_helper_spec.rb
256
+ - spec/webapi/models/repository_spec.rb