railsthemes 1.1.pre → 1.1.pre.2

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 (33) hide show
  1. data/Gemfile +2 -2
  2. data/bin/railsthemes +27 -12
  3. data/cacert.pem +3331 -0
  4. data/lib/railsthemes/email_installer.rb +73 -0
  5. data/lib/railsthemes/ensurer.rb +152 -0
  6. data/lib/railsthemes/installer.rb +116 -345
  7. data/lib/railsthemes/logging.rb +35 -0
  8. data/lib/railsthemes/theme_installer.rb +126 -0
  9. data/lib/railsthemes/utils.rb +116 -24
  10. data/lib/railsthemes/version.rb +1 -1
  11. data/lib/railsthemes.rb +22 -1
  12. data/railsthemes.gemspec +2 -0
  13. data/spec/fixtures/blank-assets/{base/app/assets/images/bg/sprite.png → email/app/assets/stylesheets/email.css} +0 -0
  14. data/spec/fixtures/blank-assets/{base/app/assets/images/image1.png → erb-css/base/app/assets/images/bg/sprite.png} +0 -0
  15. data/spec/fixtures/blank-assets/{base/app/assets/javascripts/jquery.dataTables.js → erb-css/base/app/assets/images/image1.png} +0 -0
  16. data/spec/fixtures/blank-assets/{base/app/assets/javascripts/scripts.js.erb → erb-css/base/app/assets/javascripts/jquery.dataTables.js} +0 -0
  17. data/spec/fixtures/blank-assets/{base/app/views/layouts/_interior_sidebar.html.erb → erb-css/base/app/assets/javascripts/scripts.js.erb} +0 -0
  18. data/spec/fixtures/blank-assets/{base → erb-css/base}/app/assets/stylesheets/style.css.erb +0 -0
  19. data/spec/fixtures/blank-assets/{base/app/views/layouts/application.html.erb → erb-css/base/app/views/layouts/_interior_sidebar.html.erb} +0 -0
  20. data/spec/fixtures/blank-assets/{base/app/views/layouts/homepage.html.erb → erb-css/base/app/views/layouts/application.html.erb} +0 -0
  21. data/spec/fixtures/blank-assets/{gems/formtastic/app/assets/stylesheets/formtastic.css.scss → erb-css/base/app/views/layouts/homepage.html.erb} +0 -0
  22. data/spec/fixtures/blank-assets/{gems/simple_form/app/assets/stylesheets/simple_form.css.scss → erb-css/gems/formtastic/app/assets/stylesheets/formtastic.css.scss} +0 -0
  23. data/spec/fixtures/blank-assets/erb-css/gems/simple_form/app/assets/stylesheets/simple_form.css.scss +0 -0
  24. data/spec/fixtures/{blank-assets.tar.gz → blank-assets-archived/email.tar.gz} +0 -0
  25. data/spec/fixtures/blank-assets-archived/erb-css.tar.gz +0 -0
  26. data/spec/lib/railsthemes/email_installer_spec.rb +8 -0
  27. data/spec/lib/railsthemes/ensurer_spec.rb +215 -0
  28. data/spec/lib/railsthemes/installer_spec.rb +100 -456
  29. data/spec/lib/railsthemes/theme_installer_spec.rb +206 -0
  30. data/spec/lib/railsthemes/utils_spec.rb +62 -0
  31. data/spec/spec_helper.rb +49 -0
  32. metadata +71 -26
  33. data/lib/railsthemes/win_cacerts.rb +0 -26
@@ -1,532 +1,176 @@
1
1
  require 'spec_helper'
2
2
  require 'railsthemes'
3
- require 'railsthemes/os'
3
+ require 'json'
4
4
 
5
5
  describe Railsthemes::Installer do
6
- def using_gems *gems
7
- "GEM\nremote: https://rubygems.org/\nspecs:\n" +
8
- gems.map{|gem| " #{gem}"}.join("\n") +
9
- "\nGEM\n remote: https://rubygems.org/"
10
- end
11
-
12
- def using_gem_specs specs = {}
13
- lines = []
14
- specs.each { |name, version| lines << " #{name} (#{version})"}
15
- "GEM\nremote: https://rubygems.org/\nspecs:\n" +
16
- lines.join("\n") +
17
- "\nGEM\n remote: https://rubygems.org/"
18
- end
19
-
20
- LOGFILE_NAME = 'railsthemes.log'
21
-
22
- before :all do
23
- File.delete(LOGFILE_NAME) if File.exists?(LOGFILE_NAME)
24
- end
25
-
26
6
  before do
27
- @logger = Logger.new(LOGFILE_NAME)
28
- @logger.info "#{self.example.description}"
29
- @installer = Railsthemes::Installer.new @logger
30
- stub(@installer).ensure_in_rails_root
31
- FakeWeb.register_uri(:get, "http://curl.haxx.se/ca/cacert.pem", :body => "CAs")
32
- @tempdir = ''
33
- if OS.windows?
34
- @tempdir = File.join('C:', 'Users', 'Admin', 'AppData', 'Local', 'Temp')
35
- else
36
- @tempdir = 'tmp'
37
- end
38
- stub(@installer).generate_tempdir_name { @tempdir }
39
- FileUtils.touch('Gemfile.lock')
7
+ setup_logger
8
+ @installer = Railsthemes::Installer.new
9
+ @tempdir = stub_tempdir
10
+
11
+ stub(Railsthemes::Ensurer).ensure_clean_install_possible
40
12
  end
41
13
 
42
14
  describe :install_from_file_system do
43
- context 'when the filepath is a directory' do
44
- it 'should copy the files from that directory into the Rails app' do
45
- FileUtils.mkdir_p('filepath/base')
46
- FileUtils.touch('filepath/base/a')
47
- FileUtils.touch('filepath/base/b')
48
- mock(@installer).post_copying_changes
49
-
50
- @installer.install_from_file_system('filepath')
51
- File.should exist('a')
52
- File.should exist('b')
53
- end
54
-
55
- it 'should handle directories that have spaces' do
56
- FileUtils.mkdir_p('file path/base')
57
- FileUtils.touch('file path/base/a')
58
- FileUtils.touch('file path/base/b')
59
- mock(@installer).post_copying_changes
60
-
61
- @installer.install_from_file_system('file path')
62
- File.should exist('a')
63
- File.should exist('b')
64
- end
65
-
66
- it 'should handle windows style paths' do
67
- FileUtils.mkdir_p('fp1/fp2/base')
68
- FileUtils.touch('fp1/fp2/base/a')
69
- FileUtils.touch('fp1/fp2/base/b')
70
- FileUtils.mkdir_p('fp1/fp2/gems')
71
- mock(@installer).post_copying_changes
72
-
73
- @installer.install_from_file_system('fp1\fp2')
74
- File.should exist('a')
75
- File.should exist('b')
76
- end
77
-
78
- it 'should not copy system files' do
79
- FileUtils.mkdir_p('filepath/base')
80
- FileUtils.touch('filepath/base/.DS_Store')
81
- mock(@installer).post_copying_changes
82
-
83
- @installer.install_from_file_system('filepath')
84
- File.should_not exist('.DS_Store')
85
- end
15
+ before do
16
+ FakeFS::FileSystem.clone('spec/fixtures')
17
+ stub(Railsthemes::Utils).get_primary_configuration { ['erb', 'css'] }
86
18
  end
87
19
 
88
- describe 'override file behavior' do
20
+ describe 'installing theme' do
89
21
  before do
90
- FileUtils.mkdir_p('filepath/gems')
91
- FileUtils.mkdir_p('filepath/base/app/assets/stylesheets')
92
- FileUtils.mkdir_p("app/assets/stylesheets")
93
- @filename = 'app/assets/stylesheets/railsthemes_THEME_overrides.anything'
94
- FileUtils.touch("filepath/base/#{@filename}")
95
- mock(@installer).post_copying_changes
96
- stub(@installer).popup_documentation
22
+ stub(@installer.email_installer).install_from_file_system(anything)
97
23
  end
98
24
 
99
- it 'should not overwrite override files when they already exist' do
100
- File.open(@filename, 'w') do |f|
101
- f.write "existing override"
102
- end
103
-
104
- @installer.install_from_file_system('filepath')
105
- File.should exist(@filename)
106
- File.read(@filename).should =~ /existing override/
25
+ it 'should install the right theme version' do
26
+ mock(@installer.theme_installer).install_from_file_system('spec/fixtures/blank-assets/erb-css')
27
+ @installer.install_from_file_system 'spec/fixtures/blank-assets'
107
28
  end
108
29
 
109
- it 'should create override files when they do not already exist' do
110
- @installer.install_from_file_system('filepath')
111
- File.should exist(@filename)
112
- File.read(@filename).should == ''
30
+ it 'should install the right theme version if it is an archive in that directory' do
31
+ mock(@installer.theme_installer).install_from_file_system('spec/fixtures/blank-assets-archived/erb-css')
32
+ stub(@installer.email_installer).install_from_file_system(anything)
33
+ @installer.install_from_file_system 'spec/fixtures/blank-assets-archived'
113
34
  end
114
35
  end
115
36
 
116
-
117
- context 'when the filepath is an archive file' do
118
- it 'should extract the archive file to a temp directory if the archive exists' do
119
- archive = 'tarfile.tar.gz'
120
- FileUtils.touch archive
121
- mock(@installer).install_from_archive archive
122
- @installer.install_from_file_system archive
37
+ describe 'installing email theme' do
38
+ before do
39
+ stub(@installer.theme_installer).install_from_file_system(anything)
123
40
  end
124
41
 
125
- it 'should print an error message and exit if the archive cannot be found' do
126
- mock(Railsthemes::Safe).log_and_abort(/Cannot find/)
127
- @installer.install_from_file_system 'tarfile.tar.gz'
42
+ it 'should install the email theme if present' do
43
+ mock(@installer.email_installer).install_from_file_system('spec/fixtures/blank-assets/email')
44
+ @installer.install_from_file_system 'spec/fixtures/blank-assets'
128
45
  end
129
- end
130
46
 
131
- context 'otherwise' do
132
- it 'should print usage and report an error reading the file' do
133
- mock(@installer).print_usage_and_abort(/either/)
134
- @installer.install_from_file_system("does not exist")
47
+ it 'should install the archived email theme if present' do
48
+ mock(@installer.email_installer).install_from_file_system('spec/fixtures/blank-assets-archived/email')
49
+ @installer.install_from_file_system 'spec/fixtures/blank-assets-archived'
135
50
  end
136
51
  end
52
+ end
137
53
 
138
- describe 'popping up the documentation on a successful install' do
54
+ # should probably move documentation stuff to another class
55
+ describe 'popping up the documentation' do
56
+ context 'when installing from the file system' do
139
57
  before do
140
- # set up files for copying
141
- FileUtils.mkdir_p('filepath/base')
142
- FileUtils.touch('filepath/base/a')
143
- FileUtils.touch('filepath/base/b')
144
- FileUtils.mkdir_p('filepath/gems')
145
- mock(@installer).post_copying_changes
58
+ FakeFS::FileSystem.clone('spec/fixtures')
59
+ stub(@installer.theme_installer).install_from_file_system(anything)
60
+ stub(@installer.email_installer).install_from_file_system(anything)
146
61
  end
147
62
 
148
63
  it 'should not pop it up when the user specified not to pop it up' do
149
64
  @installer.doc_popup = false
150
65
  dont_allow(@installer).popup_documentation
151
- @installer.install_from_file_system 'filepath'
66
+ @installer.install_from_file_system 'spec/fixtures/blank-assets'
152
67
  end
153
68
 
154
69
  it 'should pop it up when the user did not specify to not pop it up' do
155
70
  mock(@installer).popup_documentation
156
- @installer.install_from_file_system 'filepath'
71
+ @installer.install_from_file_system 'spec/fixtures/blank-assets'
157
72
  end
158
73
  end
159
74
  end
160
75
 
161
- describe :install_gems_from do
162
- it 'should install the gems that we specify that match' do
163
- FakeFS::FileSystem.clone('spec/fixtures/blank-assets')
164
- # we only know about formtastic and simple_form in the gems directory
165
- @installer.install_gems_from("spec/fixtures/blank-assets", ['formtastic', 'kaminari'])
166
- File.should exist('app/assets/stylesheets/formtastic.css.scss')
167
- File.should_not exist('app/assets/stylesheets/kaminari.css.scss')
168
- File.should_not exist('app/assets/stylesheets/simple_form.css.scss')
169
- end
170
- end
171
-
172
- describe :install_from_archive do
173
- # does not work on Windows, NotImplementedError in tar module
174
- it 'should extract and then install from that extracted directory' do
175
- filename = 'spec/fixtures/blank-assets.tar.gz'
176
- FakeFS::FileSystem.clone(filename)
177
- mock(@installer).install_from_file_system @tempdir
178
- @installer.install_from_archive filename
179
- end
180
- end
181
-
182
- describe :archive? do
183
- it 'should be true for tar.gz file' do
184
- @installer.archive?('test/a/b/c/d.tar.gz').should be_true
76
+ describe 'popup_documentation' do
77
+ it 'should not open if the style guide does not exist' do
78
+ dont_allow(Launchy).open(anything)
79
+ @installer.popup_documentation
185
80
  end
186
81
 
187
- it 'should be false for other extensions' do
188
- @installer.archive?('test/a/b/c.tar/d.zip').should be_false
82
+ it 'should open the style guide correctly if it exists' do
83
+ FileUtils.mkdir_p('doc')
84
+ filename = 'doc/Theme_Envy_Usage_And_Style_Guide.html'
85
+ FileUtils.touch(filename)
86
+ mock(Launchy).open(filename)
87
+ @installer.popup_documentation
189
88
  end
190
89
  end
191
90
 
192
- describe 'end to end operation' do
193
- def verify_end_to_end_operation
194
- ['app/assets/images/image1.png',
195
- 'app/assets/images/bg/sprite.png',
196
- 'app/assets/javascripts/jquery.dataTables.js',
197
- 'app/assets/javascripts/scripts.js.erb',
198
- 'app/assets/stylesheets/style.css.erb',
199
- 'app/views/layouts/_interior_sidebar.html.erb',
200
- 'app/views/layouts/application.html.erb',
201
- 'app/views/layouts/homepage.html.erb'].each do |filename|
202
- File.should exist(filename), "#{filename} was not present"
203
- end
204
- File.open('app/assets/stylesheets/style.css.erb').each do |line|
205
- line.should match /style.css.erb/
206
- end
91
+ describe '#download_from_hash' do
92
+ it 'should download and install main theme when theme specified' do
93
+ mock(Railsthemes::Utils).download(:url => 'theme_url', :save_to => "dir/erb-css.tar.gz")
94
+ @installer.download_from_hash({'theme' => 'theme_url'}, 'dir')
207
95
  end
208
96
 
209
- before do
210
- stub(@installer).post_copying_changes
211
- FakeFS::FileSystem.clone('spec/fixtures')
212
- # should add some gems to the gemfile here and test gem installation
213
- end
214
-
215
- it 'should extract correctly from directory' do
216
- filename = 'spec/fixtures/blank-assets'
217
- @installer.install_from_file_system filename
218
- verify_end_to_end_operation
219
- end
220
-
221
- # does not work on Windows, NotImplementedError in tar module
222
- it 'should extract correctly from archive' do
223
- filename = 'spec/fixtures/blank-assets.tar.gz'
224
- @installer.install_from_file_system filename
225
- verify_end_to_end_operation
97
+ it 'should download and install email theme when email specified' do
98
+ mock(Railsthemes::Utils).download(:url => 'email_url', :save_to => "dir/email.tar.gz")
99
+ @installer.download_from_hash({'email' => 'email_url'}, 'dir')
226
100
  end
227
101
  end
228
102
 
229
- describe :send_gemfile do
103
+ describe '#install_from_code' do
230
104
  before do
231
- File.open('Gemfile.lock', 'w') do |file|
232
- file.puts "GEM\n remote: https://rubygems.org/"
233
- end
105
+ mock(@installer).send_gemfile('code')
234
106
  end
235
107
 
236
- it 'should hit the server with the Gemfile and return the results, arrayified' do
237
- FakeFS.deactivate! # has an issue with generating tmpfiles otherwise
238
- params = { :code => 'panozzaj@gmail.com:code', :gemfile_lock => File.new('Gemfile.lock', 'rb') }
239
- FakeWeb.register_uri :post, 'https://railsthemes.com/gemfiles/parse',
240
- :body => 'haml,scss', :parameters => params
241
- @installer.send_gemfile('panozzaj@gmail.com:code')
108
+ it 'should download and install when the code is recognized' do
109
+ mock(@installer).get_download_hash('code') { :hash }
110
+ mock(@installer).download_from_hash(:hash, @tempdir)
111
+ mock(@installer).install_from_file_system(@tempdir)
112
+ @installer.install_from_code 'code'
242
113
  end
243
114
 
244
- it 'should return a blank array when there are issues' do
245
- FakeFS.deactivate! # has an issue with generating tmpfiles otherwise
246
- FakeWeb.register_uri :post, 'https://railsthemes.com/gemfiles/parse',
247
- :body => '', :parameters => :any, :status => ['401', 'Unauthorized']
248
- @installer.send_gemfile('panozzaj@gmail.com:code')
115
+ it 'should print an error message when the code is not recognized' do
116
+ mock(@installer).get_download_hash('code') { nil }
117
+ dont_allow(@installer).download_from_hash(:hash, @tempdir)
118
+ dont_allow(@installer).install_from_file_system(@tempdir)
119
+ mock(Railsthemes::Safe).log_and_abort(/didn't recognize/)
120
+ @installer.install_from_code 'code'
249
121
  end
250
122
  end
251
123
 
252
- describe :ask_to_install_unsupported do
253
- it 'should abort if the user does not want to continue' do
254
- mock(Railsthemes::Safe).yes?(/wish to install/) { false }
255
- mock(Railsthemes::Safe).log_and_abort('Halting.')
256
- @installer.ask_to_install_unsupported 'code'
257
- end
258
-
259
- it 'should continue if the user wants to continue' do
260
- mock(Railsthemes::Safe).yes?(/wish to install/) { true }
261
- mock(@installer).install_from_server('code')
262
- @installer.ask_to_install_unsupported 'code'
263
- end
264
- end
265
-
266
- describe :download_from_code do
267
- it 'should abort if the VCS is not clean' do
268
- mock(@installer).check_vcs_status { 'msg' }
269
- mock(Railsthemes::Safe).log_and_abort('msg')
270
- @installer.download_from_code 'thecode'
271
- end
272
-
273
- it 'should abort if the installer version is not up-to-date' do
274
- mock(@installer).check_vcs_status
275
- mock(@installer).check_installer_version { 'msg' }
276
- mock(Railsthemes::Safe).log_and_abort('msg')
277
- @installer.download_from_code 'thecode'
278
- end
279
-
280
- it 'should ask the user if they still want to install when a Gemfile.lock is not present' do
281
- File.unlink('Gemfile.lock')
282
- mock(@installer).check_vcs_status
283
- mock(@installer).check_installer_version
284
- mock(@installer).ask_to_install_unsupported 'thecode'
285
- @installer.download_from_code 'thecode'
286
- end
287
-
288
- it 'should ask the user if they still want to install when the rails version is < 3.1' do
289
- mock(@installer).check_vcs_status
290
- mock(@installer).check_installer_version
291
- mock(@installer).rails_version { Gem::Version.new('3.0.9') }
292
- mock(@installer).ask_to_install_unsupported 'thecode'
293
- @installer.download_from_code 'thecode'
294
- end
295
-
296
- it 'should install from the server otherwise' do
297
- mock(@installer).check_vcs_status
298
- mock(@installer).check_installer_version
299
- mock(@installer).rails_version { Gem::Version.new('3.1.0') }
300
- mock(@installer).install_from_server 'thecode'
301
- @installer.download_from_code 'thecode'
302
- end
303
- end
304
-
305
- def with_installer_version version, &block
306
- old_version = Railsthemes::VERSION
307
- Railsthemes.send(:remove_const, 'VERSION')
308
- Railsthemes.const_set('VERSION', version)
309
-
310
- block.call
311
-
312
- Railsthemes.send(:remove_const, 'VERSION')
313
- Railsthemes.const_set('VERSION', old_version)
314
- end
315
-
316
- describe '#check_installer_version' do
317
- it 'should return message if the current installer version is < server recommendation' do
318
- FakeWeb.register_uri :get, /\/installer\/version$/, :body => '1.0.4'
319
- with_installer_version '1.0.3' do
320
- result = @installer.check_installer_version
321
- result.should_not be_nil
322
- result.should match(/Your version is older than the recommended version/)
323
- result.should match(/Your version: 1\.0\.3/)
324
- result.should match(/Recommended version: 1\.0\.4/)
325
- end
326
- end
327
-
328
- it 'should return nothing if the current installer version is = server recommendation' do
329
- FakeWeb.register_uri :get, /\/installer\/version$/, :body => '1.0.4'
330
- with_installer_version '1.0.4' do
331
- result = @installer.check_installer_version
332
- result.should be_nil
333
- end
334
- end
335
-
336
- it 'should return nothing if the current installer version is > server recommendation' do
337
- FakeWeb.register_uri :get, /\/installer\/version$/, :body => '1.0.4'
338
- with_installer_version '1.0.5' do
339
- result = @installer.check_installer_version
340
- result.should be_nil
341
- end
124
+ describe '#get_download_hash' do
125
+ it 'should download the file correctly when valid configuration' do
126
+ FakeWeb.register_uri :get,
127
+ /download\?code=panozzaj@gmail.com:code&config=haml,scss&v=2/,
128
+ :body => { 'theme' => 'auth_url' }.to_json
129
+ mock(Railsthemes::Utils).get_primary_configuration { ['haml', 'scss'] }
130
+ result = @installer.get_download_hash 'panozzaj@gmail.com:code'
131
+ result.should == { 'theme' => 'auth_url' }
342
132
  end
343
133
 
344
- it 'should return an error message on any HTTP errors' do
345
- FakeWeb.register_uri :get, /\/installer\/version$/,
134
+ it 'should fail with an error message on any error message' do
135
+ FakeWeb.register_uri :get,
136
+ 'https://railsthemes.com/download?code=panozzaj@gmail.com:code&config=',
346
137
  :body => '', :status => ['401', 'Unauthorized']
347
- @installer.check_installer_version.should_not be_nil
348
- end
349
- end
350
-
351
- describe '#install_from_server' do
352
- context 'when a gemfile.lock is present' do
353
- before do
354
- mock(@installer).send_gemfile('panozzaj@gmail.com:code')
355
- end
356
-
357
- it 'should download the file correctly when valid configuration' do
358
- FakeWeb.register_uri :get,
359
- /download\?code=panozzaj@gmail.com:code&config=haml,scss/,
360
- :body => 'auth_url'
361
- mock(@installer).get_primary_configuration('') { 'haml,scss' }
362
- mock(Railsthemes::Utils).download_file_to('auth_url', "#{@tempdir}/archive.tar.gz")
363
- mock(@installer).install_from_archive "#{@tempdir}/archive.tar.gz"
364
- @installer.install_from_server 'panozzaj@gmail.com:code'
365
- end
366
-
367
- it 'should fail with an error message on any error message' do
368
- FakeWeb.register_uri :get,
369
- 'https://railsthemes.com/download?code=panozzaj@gmail.com:code&config=',
370
- :body => '', :status => ['401', 'Unauthorized']
371
- mock(@installer).get_primary_configuration('') { '' }
372
- mock(Railsthemes::Safe).log_and_abort(/didn't recognize/)
373
- @installer.install_from_server 'panozzaj@gmail.com:code'
374
- end
375
- end
376
- end
377
-
378
- describe '#get_primary_configuration' do
379
- it 'should give erb,css when there is no Gemfile' do
380
- @installer.get_primary_configuration('').should == 'erb,css'
381
- end
382
-
383
- it 'should give haml,scss when haml and sass are in the Gemfile' do
384
- gemfile = using_gems 'haml', 'sass'
385
- @installer.get_primary_configuration(gemfile).should == 'haml,scss'
386
- end
387
-
388
- it 'should give haml,css when sass is not in the Gemfile but haml is' do
389
- gemfile = using_gems 'haml'
390
- @installer.get_primary_configuration(gemfile).should == 'haml,css'
391
- end
392
-
393
- it 'should give erb,scss when haml is not in the gemfile but sass is' do
394
- gemfile = using_gems 'sass'
395
- @installer.get_primary_configuration(gemfile).should == 'erb,scss'
396
- end
397
-
398
- it 'should give erb,css when haml and sass are not in the gemfile' do
399
- gemfile = using_gems
400
- @installer.get_primary_configuration(gemfile).should == 'erb,css'
138
+ mock(Railsthemes::Utils).get_primary_configuration { [] }
139
+ mock(Railsthemes::Safe).log_and_abort(/didn't recognize/)
140
+ @installer.install_from_code 'panozzaj@gmail.com:code'
401
141
  end
402
142
  end
403
143
 
404
- describe :check_vcs_status do
405
- context 'when Git used' do
406
- before do
407
- Dir.mkdir('.git')
408
- end
409
-
410
- it 'should return false, issues when the vcs is unclean' do
411
- mock(Railsthemes::Safe).system_call('git status -s') { '# modified: installer_spec.rb' }
412
- result = @installer.check_vcs_status
413
- result.should match /Git reports/
414
- result.should match /# modified: installer_spec\.rb/
415
- result.should match /roll back or commit/
416
- end
417
-
418
- it 'should do nothing significant when the vcs is clean' do
419
- mock(Railsthemes::Safe).system_call('git status -s') { '' }
420
- @installer.check_vcs_status.should be_nil
421
- end
422
- end
423
-
424
- context 'when Mercurial used' do
425
- before do
426
- Dir.mkdir('.hg')
427
- end
428
-
429
- it 'should exit when the vcs is unclean' do
430
- mock(Railsthemes::Safe).system_call('hg status') { '? test.txt' }
431
- result = @installer.check_vcs_status
432
- result.should_not be_nil
433
- result.should match /Mercurial reports/
434
- result.should match /\? test\.txt/
435
- result.should match /roll back or commit/
436
- end
437
-
438
- it 'should do nothing significant when the vcs is clean' do
439
- mock(Railsthemes::Safe).system_call('hg status') { '' }
440
- @installer.check_vcs_status.should be_nil
144
+ describe :send_gemfile do
145
+ context 'without Gemfile.lock present' do
146
+ it 'should not hit the server and should return nil' do
147
+ result = @installer.send_gemfile('panozzaj@gmail.com:code')
148
+ result.should be_nil
441
149
  end
442
150
  end
443
151
 
444
- context 'when Subversion used' do
152
+ context 'with Gemfile.lock present' do
445
153
  before do
446
- Dir.mkdir('.svn')
154
+ File.open('Gemfile.lock', 'w') do |file|
155
+ file.puts "GEM\n remote: https://rubygems.org/"
156
+ end
447
157
  end
448
158
 
449
- it 'should exit when the vcs is unclean' do
450
- mock(Railsthemes::Safe).system_call('svn status') { 'M something.txt' }
451
- result = @installer.check_vcs_status
452
- result.should match /Subversion reports/
453
- result.should match /M something\.txt/
454
- result.should match /roll back or commit/
159
+ it 'should hit the server with the Gemfile and return the results, arrayified' do
160
+ FakeFS.deactivate! # has an issue with generating tmpfiles otherwise
161
+ params = { :code => 'panozzaj@gmail.com:code', :gemfile_lock => File.new('Gemfile.lock', 'rb') }
162
+ FakeWeb.register_uri :post, 'https://railsthemes.com/gemfiles/parse',
163
+ :body => 'haml,scss', :parameters => params
164
+ @installer.send_gemfile('panozzaj@gmail.com:code')
455
165
  end
456
166
 
457
- it 'should do nothing significant when the vcs is clean' do
458
- mock(Railsthemes::Safe).system_call('svn status') { '' }
459
- @installer.check_vcs_status.should be_nil
167
+ it 'should return a blank array when there are issues' do
168
+ FakeFS.deactivate! # has an issue with generating tmpfiles otherwise
169
+ FakeWeb.register_uri :post, 'https://railsthemes.com/gemfiles/parse',
170
+ :body => '', :parameters => :any, :status => ['401', 'Unauthorized']
171
+ @installer.send_gemfile('panozzaj@gmail.com:code')
460
172
  end
461
173
  end
462
174
  end
463
175
 
464
- describe '#create_railsthemes_demo_pages' do
465
- before do
466
- FileUtils.mkdir('config')
467
- File.open(File.join('config', 'routes.rb'), 'w') do |f|
468
- f.write <<-EOS
469
- RailsApp::Application.routes.draw do
470
- # This is a legacy wild controller route that's not recommended for RESTful applications.
471
- # Note: This route will make all actions in every controller accessible via GET requests.
472
- # match ':controller(/:action(/:id(.:format)))'
473
- end
474
- EOS
475
- end
476
- end
477
-
478
- it 'should create a RailsThemes controller' do
479
- @installer.create_railsthemes_demo_pages
480
- controller = File.join('app', 'controllers', 'railsthemes_controller.rb')
481
- lines = File.read(controller).split("\n")
482
- lines.count.should == 11
483
- lines.first.should match /class RailsthemesController < ApplicationController/
484
- end
485
-
486
- it 'should insert lines into the routes file' do
487
- @installer.create_railsthemes_demo_pages
488
- routes_file = File.join('config', 'routes.rb')
489
- lines = File.read(routes_file).split("\n")
490
- lines.grep(/match 'railsthemes\/landing' => 'railsthemes#landing'/).count.should == 1
491
- lines.grep(/match 'railsthemes\/inner' => 'railsthemes#inner'/).count.should == 1
492
- lines.grep(/match 'railsthemes\/jquery_ui' => 'railsthemes#jquery_ui'/).count.should == 1
493
- end
494
-
495
- it 'should not insert lines into the routes file when run more than once' do
496
- @installer.create_railsthemes_demo_pages
497
- @installer.create_railsthemes_demo_pages
498
- routes_file = File.join('config', 'routes.rb')
499
- lines = File.read(routes_file).split("\n")
500
- lines.grep(/match 'railsthemes\/landing' => 'railsthemes#landing'/).count.should == 1
501
- lines.grep(/match 'railsthemes\/inner' => 'railsthemes#inner'/).count.should == 1
502
- lines.grep(/match 'railsthemes\/jquery_ui' => 'railsthemes#jquery_ui'/).count.should == 1
503
- end
504
- end
505
-
506
- describe '#rails_version' do
507
- it 'should return the right version' do
508
- gemfile = using_gem_specs :rails => '3.0.1'
509
- @installer.rails_version(gemfile).version.should == '3.0.1'
510
- end
511
-
512
- it 'should return nil if there is no rails present' do
513
- gemfile = using_gem_specs
514
- @installer.rails_version(gemfile).should be_nil
515
- end
516
- end
517
-
518
- describe 'popup_documentation' do
519
- it 'should not open if the style guide does not exist' do
520
- dont_allow(Launchy).open(anything)
521
- @installer.popup_documentation
522
- end
523
-
524
- it 'should open the style guide correctly if it exists' do
525
- FileUtils.mkdir_p('doc')
526
- filename = 'doc/Theme_Envy_Usage_And_Style_Guide.html'
527
- FileUtils.touch(filename)
528
- mock(Launchy).open(filename)
529
- @installer.popup_documentation
530
- end
531
- end
532
176
  end