overlay 1.1.0 → 2.0.0

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.
data/spec/github_spec.rb CHANGED
@@ -1,104 +1,262 @@
1
1
  require 'spec_helper'
2
+ require 'socket'
2
3
 
3
4
  describe Overlay::Github do
4
- before :each do
5
- # Configure the overlay
6
- Overlay.configuration.reset if Overlay.configuration
7
5
 
8
- Overlay.configure do |config|
9
- config.auth = 'test_user:test_password'
10
- config.repositories << Overlay::GithubRepo.new('saarinen', 'overlay', 'master', 'spec', 'spec')
6
+ let(:repo_config) do
7
+ Overlay::GithubRepo.new(
8
+ 'test_org',
9
+ 'test_repo',
10
+ 'test_user:test_pass',
11
+ 'spec',
12
+ 'spec'
13
+ )
14
+ end
15
+
16
+ describe "Register Github webhook" do
17
+ before :each do
18
+ # Configure the overlay
19
+ Overlay.configuration.reset if Overlay.configuration
20
+
21
+ Overlay.configure do |config|
22
+ # Configure host port as Rails::Server is not available
23
+ config.host_port = 3000
24
+ end
11
25
 
12
- # Configure host port as Rails::Server is not available
13
- #
14
- config.host_port = 3000
26
+
27
+ Overlay.configuration.repositories = Set.new [repo_config]
15
28
  end
16
- end
17
29
 
18
- describe "process overlays" do
19
- it "should configure the github_api" do
20
- Overlay::Github.stub(:register_web_hook).and_return
21
- Overlay::Github.stub(:overlay_repo).and_return
30
+ it 'should register a webhook with github' do
31
+ config = Overlay.configuration.repositories.first
32
+ allow(Overlay::Github.instance).to receive(:fork_it).with(:overlay_repo, config).and_return
33
+
34
+ stub_request(:get, /api.github.com/).
35
+ with(:headers => {'Accept'=>'application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1', 'Accept-Charset'=>'utf-8', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Github Ruby Gem 0.11.2'}).
36
+ to_return(:status => 200, :body => '[]', :headers => {})
22
37
 
23
- Overlay::Github.should_receive(:configure).once
24
- Overlay::Github.process_overlays
38
+ expect(repo_config.github_api.hooks).to receive(:create).with(
39
+ 'test_org',
40
+ 'test_repo',
41
+ name: 'web',
42
+ active: true,
43
+ config: {:url => "http://#{Socket.gethostname}:3000/overlay/github/update", :content_type => 'json'}
44
+ ).and_return
45
+
46
+ Overlay::Github.instance.process_overlays
25
47
  end
26
48
 
27
- it "should verify the user and repo config" do
28
- Overlay::Github.stub(:register_web_hook).and_return
29
- Overlay::Github.stub(:overlay_repo).and_return
49
+ it 'should use a configured endpoint' do
50
+ config = Overlay.configuration.repositories.first
51
+ config.endpoint = "https://www.test.com"
52
+
53
+ allow(Overlay::Github.instance).to receive(:fork_it).with(:overlay_repo, config).and_return
54
+
55
+ stub_request(:get, /www.test.com/).
56
+ with(:headers => {'Accept'=>'application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1', 'Accept-Charset'=>'utf-8', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Github Ruby Gem 0.11.2'}).
57
+ to_return(:status => 200, :body => '[]', :headers => {})
30
58
 
31
- Overlay.configuration.repositories << Overlay::GithubRepo.new(nil, nil, 'master', 'spec', 'spec')
59
+ expect(repo_config.github_api.hooks).to receive(:create).with(
60
+ 'test_org',
61
+ 'test_repo',
62
+ name: 'web',
63
+ active: true,
64
+ config: {:url => "http://#{Socket.gethostname}:3000/overlay/github/update", :content_type => 'json'}
65
+ ).and_return
66
+
67
+ Overlay::Github.instance.process_overlays
68
+ end
69
+ end
32
70
 
33
- expect{Overlay::Github.process_overlays}.to raise_error("Respository config missing user")
71
+ describe 'subscribe to a redis publisher' do
72
+ before :each do
73
+ # Configure the overlay
74
+ Overlay.configuration.reset if Overlay.configuration
34
75
 
35
- Overlay.configuration.reset
76
+ Overlay.configure do |config|
77
+ # Configure host port as Rails::Server is not available
78
+ config.host_port = 3000
79
+ end
36
80
 
37
- Overlay.configuration.repositories << Overlay::GithubRepo.new("test", nil, 'master', 'spec', 'spec')
81
+ config = repo_config
82
+ config.use_publisher = true
83
+ config.redis_server = 'localhost'
84
+ config.redis_port = 6734
85
+ config.registration_server = "http://www.test.com"
38
86
 
39
- expect{Overlay::Github.process_overlays}.to raise_error("Respository config missing repo")
87
+ Overlay.configuration.repositories = Set.new [config]
40
88
  end
41
89
 
42
- it "should call to add a web_hook" do
43
- Overlay::Github.stub(:overlay_repo).and_return
90
+ it 'should call publisher_subscribe' do
91
+ config = Overlay.configuration.repositories.first
92
+ allow(Overlay::Github.instance).to receive(:fork_it).with(:overlay_repo, config).and_return
44
93
 
45
- Overlay::Github.should_receive(:register_web_hook).once.and_return
46
- Overlay::Github.process_overlays
94
+ expect(Overlay::Github.instance).to receive(:publisher_subscribe).with(config).and_return
95
+
96
+ Overlay::Github.instance.process_overlays
47
97
  end
48
98
 
49
- it "should overlay the repo" do
50
- Overlay::Github.stub(:register_web_hook).and_return
99
+ it 'should send a registration request' do
100
+ config = Overlay.configuration.repositories.first
101
+ allow(Overlay::Github.instance).to receive(:fork_it).with(:overlay_repo, config).and_return
102
+ expect(Overlay::Github.instance).to receive(:fork_it).with(:subscribe_to_channel, "test_key", config).and_return
103
+
104
+ stub_request(:post, /www.test.com/).
105
+ with(headers: {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
106
+ to_return(status: 200, body: "{\"publish_key\": \"test_key\"}", headers: {})
51
107
 
52
- Overlay::Github.should_receive(:overlay_repo).once.and_return
53
- Overlay::Github.process_overlays
108
+ Overlay::Github.instance.process_overlays
54
109
  end
55
110
  end
56
111
 
57
- describe "configure github_api" do
58
- it "should call github api configure" do
59
- ::Github.should_receive(:configure).once
60
- Overlay::Github.configure
112
+ describe 'process webhook payload' do
113
+ let(:repo_config) do
114
+ Overlay::GithubRepo.new(
115
+ 'test_org',
116
+ 'test_repo',
117
+ 'test_user:test_pass',
118
+ 'lib',
119
+ 'lib'
120
+ )
61
121
  end
62
122
 
63
- it "should set a custom site address" do
64
- Overlay.configuration.site = "http://www.example.com"
65
- Overlay::Github.configure
66
- expect(::Github::Repos.new.site).to eq("http://www.example.com")
123
+ let(:payload) do
124
+ JSON.parse(
125
+ "{
126
+ \"ref\":\"refs/heads/master\",
127
+ \"after\":\"3524f66a6b374a35a5359905be8a87a3931eba17\",
128
+ \"before\":\"57f73e81329ef71a37c55c2f41b48910f9a7c790\",
129
+ \"created\":false,
130
+ \"deleted\":false,
131
+ \"forced\":false,
132
+ \"compare\":\"https://api.test.com/test_org/test_repo/compare/57f73e81329e...3524f66a6b37\",
133
+ \"commits\":[
134
+ {
135
+ \"id\":\"3524f66a6b374a35a5359905be8a87a3931eba17\",
136
+ \"distinct\":true,
137
+ \"message\":\"test webhook\",
138
+ \"timestamp\":\"2014-02-14T22:05:33+00:00\",
139
+ \"url\":\"https://api.test.com/test_org/test_repo/commit/3524f66a6b374a35a5359905be8a87a3931eba17\",
140
+ \"author\":{
141
+ \"name\":\"Steve Saarinen\",
142
+ \"email\":\"ssaarinen@whitepages.com\",
143
+ \"username\":\"saarinen\"
144
+ },
145
+ \"committer\":{
146
+ \"name\":\"Steve Saarinen\",
147
+ \"email\":\"ssaarinen@whitepages.com\",
148
+ \"username\":\"saarinen\"
149
+ },
150
+ \"added\":[
151
+
152
+ ],
153
+ \"added\":[
154
+ \"lib/test/test.rb\"
155
+ ],
156
+ \"removed\":[
157
+ \"lib/test/test.rb\"
158
+ ],
159
+ \"modified\":[
160
+ \"lib/test/test.rb\"
161
+ ]
162
+ }
163
+ ],
164
+ \"head_commit\":{
165
+ \"id\":\"3524f66a6b374a35a5359905be8a87a3931eba17\",
166
+ \"distinct\":true,
167
+ \"message\":\"test webhook\",
168
+ \"timestamp\":\"2014-02-14T22:05:33+00:00\",
169
+ \"url\":\"https://api.test.com/test_org/test_repo/commit/3524f66a6b374a35a5359905be8a87a3931eba17\",
170
+ \"author\":{
171
+ \"name\":\"Steve Saarinen\",
172
+ \"email\":\"ssaarinen@whitepages.com\",
173
+ \"username\":\"saarinen\"
174
+ },
175
+ \"committer\":{
176
+ \"name\":\"Steve Saarinen\",
177
+ \"email\":\"ssaarinen@whitepages.com\",
178
+ \"username\":\"saarinen\"
179
+ },
180
+ \"added\":[
181
+ \"lib/test/test.rb\"
182
+ ],
183
+ \"removed\":[
184
+ \"lib/test/test.rb\"
185
+ ],
186
+ \"modified\":[
187
+ \"lib/test/test.rb\"
188
+ ]
189
+ },
190
+ \"repository\":{
191
+ \"id\":1720,
192
+ \"name\":\"bing_maps\",
193
+ \"url\":\"https://www.test.com/test_org/test_repo\",
194
+ \"description\":\"Gem providing Bing Maps API integration\",
195
+ \"watchers\":0,
196
+ \"stargazers\":0,
197
+ \"forks\":0,
198
+ \"fork\":true,
199
+ \"size\":412,
200
+ \"owner\":{
201
+ \"name\":\"saarinen\",
202
+ \"email\":\"ssaarinen@whitepages.com\"
203
+ },
204
+ \"private\":false,
205
+ \"open_issues\":0,
206
+ \"has_issues\":false,
207
+ \"has_downloads\":true,
208
+ \"has_wiki\":true,
209
+ \"language\":\"Ruby\",
210
+ \"created_at\":1383860934,
211
+ \"pushed_at\":1392415533,
212
+ \"master_branch\":\"master\"
213
+ },
214
+ \"pusher\":{
215
+ \"name\":\"saarinen\",
216
+ \"email\":\"ssaarinen@whitepages.com\"
217
+ }
218
+ }"
219
+ )
67
220
  end
68
221
 
69
- it "should verify basic auth" do
70
- Overlay.configuration.auth = nil
71
- expect{Overlay::Github.configure}.to raise_error("Configuration github_overlays.basic_auth not set")
222
+ it 'should make a directory for a new file' do
223
+ allow(Overlay::Github.instance).to receive(:clone_file).and_return
224
+ allow(File).to receive(:delete).and_return
225
+ expect(FileUtils).to receive(:mkdir_p).with("#{Rails.application.root}/lib/test")
226
+
227
+ Overlay::Github.instance.process_hook(payload, repo_config)
72
228
  end
73
229
 
74
- it "should set auth" do
75
- Overlay::Github.configure
76
- expect(::Github::Repos.new.basic_auth).to eq('test_user:test_password')
230
+ it 'should remove a deleted file' do
231
+ allow(Overlay::Github.instance).to receive(:clone_file).and_return
232
+ allow(FileUtils).to receive(:mkdir_p).with("#{Rails.application.root}/lib/test")
233
+ expect(File).to receive(:delete).with("#{Rails.application.root}/lib/test/test.rb").and_return
234
+
235
+ Overlay::Github.instance.process_hook(payload, repo_config)
77
236
  end
78
- end
79
237
 
80
- describe "overlay_repo" do
81
- it "should jump directly to overlay_directory if root set" do
82
- repo_config = Overlay::GithubRepo.new('saarinen', 'overlay', 'master', 'spec', 'spec')
83
- Overlay::Github.should_receive(:overlay_directory).once.with('spec', repo_config).and_return
84
- overlay_thread = Overlay::Github.overlay_repo repo_config
85
- overlay_thread.join
238
+ it 'should clone added or modified files' do
239
+ allow(FileUtils).to receive(:mkdir_p).with("#{Rails.application.root}/lib/test")
240
+ allow(File).to receive(:delete).with("#{Rails.application.root}/lib/test/test.rb").and_return
241
+ expect(Overlay::Github.instance).to receive(:clone_file).with("lib/test/test.rb", repo_config).exactly(:twice).and_return
242
+
243
+ Overlay::Github.instance.process_hook(payload, repo_config)
86
244
  end
87
245
 
88
- it "should ignore any files in repo root"
246
+ it 'should call post_hook after hook is processed' do
247
+ allow(FileUtils).to receive(:mkdir_p).with("#{Rails.application.root}/lib/test")
248
+ allow(File).to receive(:delete).with("#{Rails.application.root}/lib/test/test.rb").and_return
249
+ allow(Overlay::Github.instance).to receive(:clone_file).with("lib/test/test.rb", repo_config).and_return
89
250
 
90
- it "should process all directories in repo root"
91
- end
251
+ hook_ran = false
92
252
 
93
- describe "overlay_directory" do
94
- it "should set path correctly based on root"
95
- it "should create path for directory"
96
- it "should call clone_files for all files in directory"
97
- it "should call overlay_directory for all directories"
98
- end
253
+ repo_config.after_process_hook do
254
+ hook_ran = true
255
+ end
99
256
 
100
- describe "clone_file" do
101
- it "should create a file for the cloned file"
102
- it "should corrctly set the file path"
257
+ Overlay::Github.instance.process_hook(payload, repo_config)
258
+
259
+ expect(hook_ran).to eq(true)
260
+ end
103
261
  end
104
262
  end
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,9 @@ require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
4
  require 'rspec/rails'
5
5
  require 'rspec/autorun'
6
6
 
7
+ require 'webmock/rspec'
8
+ WebMock.disable_net_connect!(allow_localhost: true)
9
+
7
10
  # Requires supporting ruby files with custom matchers and macros, etc,
8
11
  # in spec/support/ and its subdirectories.
9
12
  Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: overlay
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Saarinen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-12 00:00:00.000000000 Z
11
+ date: 2014-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: redis
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'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: github_api
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - '>='
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description: Overlay one or more external repositories on a running Rails application
56
84
  email:
57
85
  - saarinen@gmail.com
@@ -59,21 +87,20 @@ executables: []
59
87
  extensions: []
60
88
  extra_rdoc_files: []
61
89
  files:
62
- - app/assets/stylesheets/overlay/application.css
63
90
  - app/controllers/overlay/application_controller.rb
64
91
  - app/controllers/overlay/github_controller.rb
65
- - app/helpers/overlay/application_helper.rb
66
- - app/views/layouts/overlay/application.html.erb
67
92
  - config/routes.rb
68
93
  - lib/overlay/configuration.rb
69
94
  - lib/overlay/engine.rb
70
95
  - lib/overlay/github.rb
96
+ - lib/overlay/subscriber.rb
71
97
  - lib/overlay/version.rb
72
98
  - lib/overlay.rb
73
99
  - lib/tasks/overlay_tasks.rake
74
100
  - MIT-LICENSE
75
101
  - Rakefile
76
102
  - README.rdoc
103
+ - spec/configuration_spec.rb
77
104
  - spec/controllers/overlay/github_controller_spec.rb
78
105
  - spec/dummy/app/assets/javascripts/application.js
79
106
  - spec/dummy/app/assets/stylesheets/application.css
@@ -99,7 +126,6 @@ files:
99
126
  - spec/dummy/config/locales/en.yml
100
127
  - spec/dummy/config/routes.rb
101
128
  - spec/dummy/config.ru
102
- - spec/dummy/log/development.log
103
129
  - spec/dummy/log/test.log
104
130
  - spec/dummy/public/404.html
105
131
  - spec/dummy/public/422.html
@@ -162,6 +188,7 @@ signing_key:
162
188
  specification_version: 4
163
189
  summary: Overlay external repository on existing Rails application
164
190
  test_files:
191
+ - spec/configuration_spec.rb
165
192
  - spec/controllers/overlay/github_controller_spec.rb
166
193
  - spec/dummy/app/assets/javascripts/application.js
167
194
  - spec/dummy/app/assets/stylesheets/application.css
@@ -187,7 +214,6 @@ test_files:
187
214
  - spec/dummy/config/locales/en.yml
188
215
  - spec/dummy/config/routes.rb
189
216
  - spec/dummy/config.ru
190
- - spec/dummy/log/development.log
191
217
  - spec/dummy/log/test.log
192
218
  - spec/dummy/public/404.html
193
219
  - spec/dummy/public/422.html
@@ -1,13 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the top of the
9
- * compiled file, but it's generally better to create a new file per style scope.
10
- *
11
- *= require_self
12
- *= require_tree .
13
- */