railsthemes 1.0.3 → 1.0.4
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/Gemfile +3 -1
- data/Guardfile +19 -0
- data/README.md +7 -3
- data/bin/railsthemes +11 -3
- data/lib/railsthemes/installer.rb +149 -52
- data/lib/railsthemes/safe.rb +7 -0
- data/lib/railsthemes/utils.rb +4 -0
- data/lib/railsthemes/version.rb +1 -1
- data/spec/lib/railsthemes/installer_spec.rb +181 -23
- data/spec/spec_helper.rb +10 -0
- metadata +5 -4
data/Gemfile
CHANGED
@@ -7,6 +7,8 @@ gem 'rest-client'
|
|
7
7
|
|
8
8
|
group :development do
|
9
9
|
gem 'gem-release'
|
10
|
+
gem 'guard'
|
11
|
+
gem 'guard-rspec'
|
10
12
|
end
|
11
13
|
|
12
14
|
# development gems
|
@@ -14,6 +16,6 @@ group :test do
|
|
14
16
|
gem 'rspec'
|
15
17
|
gem 'rr'
|
16
18
|
gem 'autotest'
|
17
|
-
gem 'fakefs', :require => 'fakefs/safe'
|
19
|
+
gem 'fakefs', :require => 'fakefs/safe', :git => 'https://github.com/defunkt/fakefs'
|
18
20
|
gem 'fakeweb'
|
19
21
|
end
|
data/Guardfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :version => 2 do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
watch('config/routes.rb') { "spec/routing" }
|
15
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
+
# Capybara request specs
|
17
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
18
|
+
end
|
19
|
+
|
data/README.md
CHANGED
@@ -20,16 +20,20 @@ This has been tested with Ruby 1.8.7, and should work with higher versions. 1.8.
|
|
20
20
|
|
21
21
|
Not sure if this will work for Windows users due to invoking tar on the command-line instead of using native Ruby. This is something that we can change going forward, just a matter of time.
|
22
22
|
|
23
|
-
##
|
23
|
+
## Committer notes
|
24
24
|
|
25
|
-
To cut a release,
|
25
|
+
To cut a release, use the gem-release gem:
|
26
26
|
|
27
27
|
installer> gem bump --version patch
|
28
28
|
|
29
|
-
|
29
|
+
Inspect the commit created. This is the last chance before pushing to the repo.
|
30
30
|
|
31
31
|
installer> gem tag
|
32
32
|
|
33
|
+
Inspect the tag created, if you wish.
|
34
|
+
|
35
|
+
installer> gem release
|
36
|
+
|
33
37
|
Changing patch to minor or major as useful. For more thorough documentation, see [gem-release](https://github.com/svenfuchs/gem-release).
|
34
38
|
|
35
39
|
## Contributing
|
data/bin/railsthemes
CHANGED
@@ -5,18 +5,26 @@ require "railsthemes"
|
|
5
5
|
|
6
6
|
class Installer < Thor
|
7
7
|
desc "install CODE", "Install from RailsThemes.com using your download code"
|
8
|
-
method_option :file,
|
8
|
+
method_option :file,
|
9
|
+
:desc => "Use local filename instead of downloading.",
|
10
|
+
:type => :boolean
|
11
|
+
method_option :no_doc_popup,
|
12
|
+
:desc => "Do not pop up documentation on successful install.",
|
13
|
+
:aliases => "--no-doc-popup",
|
14
|
+
:type => :boolean
|
9
15
|
|
10
16
|
def install code_or_file
|
17
|
+
installer = Railsthemes::Installer.new
|
18
|
+
installer.doc_popup = !options[:no_doc_popup]
|
11
19
|
if options[:file]
|
12
20
|
file = code_or_file
|
13
21
|
abort 'Please specify a file to install from' unless file
|
14
22
|
puts "Installing from file: #{file}."
|
15
|
-
|
23
|
+
installer.install_from_file_system file
|
16
24
|
else
|
17
25
|
code = code_or_file
|
18
26
|
abort 'Please specify a code to install from' unless code
|
19
|
-
|
27
|
+
installer.download_from_code code
|
20
28
|
end
|
21
29
|
end
|
22
30
|
|
@@ -20,6 +20,11 @@ module Railsthemes
|
|
20
20
|
@logger.formatter = proc do |severity, datetime, progname, msg|
|
21
21
|
"#{msg}\n"
|
22
22
|
end
|
23
|
+
@doc_popup = true
|
24
|
+
end
|
25
|
+
|
26
|
+
def doc_popup= doc_popup
|
27
|
+
@doc_popup = doc_popup
|
23
28
|
end
|
24
29
|
|
25
30
|
def ensure_in_rails_root
|
@@ -33,13 +38,28 @@ module Railsthemes
|
|
33
38
|
ensure_in_rails_root
|
34
39
|
|
35
40
|
@logger.info 'Installing...'
|
36
|
-
|
37
|
-
|
38
|
-
|
41
|
+
|
42
|
+
# this file causes issues when HAML is also present, and we overwrite
|
43
|
+
# it in the ERB case, so safe to delete here
|
44
|
+
Utils.remove_file('app/views/layouts/application.html.erb')
|
45
|
+
|
46
|
+
Dir["#{source_filepath}/base/**/*"].each do |src|
|
47
|
+
dest = src.sub("#{source_filepath}/base/", '')
|
48
|
+
if File.directory?(src)
|
49
|
+
FileUtils.mkdir_p(dest)
|
50
|
+
else
|
51
|
+
unless dest =~ /railsthemes_.*_overrides\.*/ && File.exists?(dest)
|
52
|
+
FileUtils.cp(src, dest)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
gem_names = gemspecs(Utils.read_file('Gemfile.lock')).map(&:name) - ['haml', 'sass']
|
57
|
+
install_gems_from(source_filepath, gem_names)
|
39
58
|
|
40
59
|
@logger.info 'Done installing.'
|
41
60
|
post_copying_changes
|
42
61
|
print_post_installation_instructions
|
62
|
+
popup_documentation if @doc_popup
|
43
63
|
elsif archive?(source_filepath)
|
44
64
|
if File.exists?(source_filepath)
|
45
65
|
install_from_archive source_filepath
|
@@ -53,6 +73,11 @@ module Railsthemes
|
|
53
73
|
end
|
54
74
|
end
|
55
75
|
|
76
|
+
def popup_documentation
|
77
|
+
style_guide = Dir['doc/*Usage_And_Style_Guide.html'].first
|
78
|
+
Safe.system_call("open #{style_guide}") if style_guide
|
79
|
+
end
|
80
|
+
|
56
81
|
def install_gems_from source_filepath, gem_names
|
57
82
|
gems_that_we_can_install = Dir.entries("#{source_filepath}/gems").reject{|x| x == '.' || x == '..'}
|
58
83
|
(gem_names & gems_that_we_can_install).each do |gem_name|
|
@@ -64,30 +89,76 @@ module Railsthemes
|
|
64
89
|
@logger.info "Extracting..."
|
65
90
|
with_tempdir do |tempdir|
|
66
91
|
Safe.system_call untar_string(filepath, tempdir)
|
92
|
+
# remove any pesky hidden files that crept into the archivej
|
93
|
+
Dir["#{tempdir}/**/.*"].reject {|x| x =~ /\/\.\.?$/}.each do |file|
|
94
|
+
File.unlink(file)
|
95
|
+
end
|
67
96
|
@logger.info "Finished extracting."
|
68
97
|
install_from_file_system tempdir
|
69
98
|
end
|
70
99
|
end
|
71
100
|
|
72
101
|
def download_from_code code
|
73
|
-
check_vcs_status
|
74
|
-
if
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
102
|
+
vcs_is_unclean_message = check_vcs_status
|
103
|
+
if vcs_is_unclean_message
|
104
|
+
Safe.log_and_abort vcs_is_unclean_message
|
105
|
+
else
|
106
|
+
if File.exists?('Gemfile.lock') && Gem::Version.new('3.1') <= rails_version
|
107
|
+
install_from_server code
|
108
|
+
else
|
109
|
+
ask_to_install_unsupported code
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def install_from_server code
|
115
|
+
@logger.info "Downloading theme from server..."
|
116
|
+
with_tempdir do |tempdir|
|
117
|
+
archive = File.join(tempdir, 'archive.tar.gz')
|
118
|
+
if File.exists?('Gemfile.lock')
|
119
|
+
send_gemfile code # first time hitting the server
|
120
|
+
end
|
121
|
+
config = get_primary_configuration(Utils.read_file('Gemfile.lock'))
|
122
|
+
dl_url = get_download_url "#{@server}/download?code=#{code}&config=#{config}"
|
123
|
+
if dl_url
|
124
|
+
Utils.download_file_to dl_url, archive
|
125
|
+
@logger.info "Finished downloading."
|
126
|
+
install_from_archive archive
|
127
|
+
else
|
128
|
+
Safe.log_and_abort("We didn't recognize the code you gave to download the theme (#{code}). It should look something like your@email.com:ABCDEF.")
|
88
129
|
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def ask_to_install_unsupported code
|
134
|
+
@logger.info "WARNING\n"
|
135
|
+
|
136
|
+
if File.exists?('Gemfile.lock')
|
137
|
+
@logger.info <<-EOS
|
138
|
+
Your Gemfile.lock file indicates that you are using a version of Rails that
|
139
|
+
is not officially supported by RailsThemes.
|
140
|
+
EOS
|
141
|
+
else
|
142
|
+
@logger.info <<-EOS
|
143
|
+
We could not find a Gemfile.lock file in this directory. This could indicate
|
144
|
+
that you are not in a Rails application, or that you are not using Bundler
|
145
|
+
(which probably means that you are using a version of Rails that is not
|
146
|
+
officially supported by RailsThemes.)
|
147
|
+
EOS
|
148
|
+
end
|
149
|
+
@logger.info <<-EOS
|
150
|
+
While Rails applications that are less than version 3.1 are not officially
|
151
|
+
supported, you can try installing anyway, or can stop. If you cancel the
|
152
|
+
install before downloading, we can refund your purchase. If you install,
|
153
|
+
we cannot guarantee that RailsThemes will work for your app. You may have
|
154
|
+
to do some custom changes, which might be as easy as copying files,
|
155
|
+
but which may be more complicated.
|
156
|
+
EOS
|
157
|
+
|
158
|
+
if Safe.yes? 'Do you still wish to install the theme? [y/N]'
|
159
|
+
install_from_server code
|
89
160
|
else
|
90
|
-
Safe.log_and_abort
|
161
|
+
Safe.log_and_abort 'Halting.'
|
91
162
|
end
|
92
163
|
end
|
93
164
|
|
@@ -102,44 +173,52 @@ module Railsthemes
|
|
102
173
|
end
|
103
174
|
path = server_request_url.gsub(%r{https?://[^/]+}, '')
|
104
175
|
response = http.request_get(path)
|
176
|
+
rescue SocketError => e
|
177
|
+
Safe.log_and_abort 'We could not reach the RailsThemes server to download the theme. Please check your internet connection and try again.'
|
105
178
|
rescue Exception => e
|
106
|
-
|
107
|
-
|
179
|
+
#@logger.info e.message
|
180
|
+
#@logger.info e.backtrace
|
108
181
|
end
|
109
182
|
|
110
183
|
if response
|
111
184
|
if response.code.to_s == '200'
|
112
185
|
return response.body
|
113
186
|
else
|
114
|
-
|
115
|
-
|
187
|
+
#@logger.info response
|
188
|
+
#@logger.info "Got a #{response.code} error while trying to download."
|
116
189
|
return nil
|
117
190
|
end
|
118
191
|
end
|
119
192
|
end
|
120
193
|
|
121
|
-
def
|
122
|
-
|
194
|
+
def gemspecs gemfile_contents = nil
|
195
|
+
gemfile_contents ||= Utils.read_file('Gemfile.lock')
|
196
|
+
return [] if gemfile_contents.strip == ''
|
197
|
+
lockfile = Bundler::LockfileParser.new(gemfile_contents)
|
198
|
+
lockfile.specs
|
123
199
|
end
|
124
200
|
|
125
|
-
def
|
126
|
-
|
127
|
-
|
128
|
-
|
201
|
+
def get_primary_configuration gemfile_contents
|
202
|
+
gem_names = gemspecs(gemfile_contents).map(&:name)
|
203
|
+
(gem_names.include?('haml') ? 'haml' : 'erb') + ',' +
|
204
|
+
(gem_names.include?('sass') ? 'scss' : 'css')
|
129
205
|
end
|
130
206
|
|
131
|
-
def
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
207
|
+
def rails_version gemfile_contents = nil
|
208
|
+
gemfile_contents ||= Utils.read_file('Gemfile.lock')
|
209
|
+
specs = gemspecs(gemfile_contents)
|
210
|
+
rails = specs.select{ |x| x.name == 'rails' }.first
|
211
|
+
if rails && rails.version
|
212
|
+
rails.version
|
213
|
+
end
|
137
214
|
end
|
138
215
|
|
139
216
|
def send_gemfile code
|
140
217
|
begin
|
141
218
|
response = RestClient.post("#{@server}/gemfiles/parse",
|
142
219
|
:code => code, :gemfile_lock => File.new('Gemfile.lock', 'rb'))
|
220
|
+
rescue SocketError => e
|
221
|
+
Safe.log_and_abort 'We could not reach the RailsThemes server to start your download. Please check your internet connection and try again.'
|
143
222
|
rescue Exception => e
|
144
223
|
@logger.info e.message
|
145
224
|
@logger.info e.backtrace
|
@@ -170,11 +249,12 @@ module Railsthemes
|
|
170
249
|
# for people to view the theme correctly
|
171
250
|
def post_copying_changes
|
172
251
|
Utils.remove_file File.join('public', 'index.html')
|
173
|
-
|
174
|
-
create_railsthemes_controller
|
252
|
+
create_railsthemes_demo_pages
|
175
253
|
end
|
176
254
|
|
177
|
-
def
|
255
|
+
def create_railsthemes_demo_pages
|
256
|
+
@logger.info 'Creating RailsThemes demo pages...'
|
257
|
+
|
178
258
|
FileUtils.mkdir_p(File.join('app', 'controllers'))
|
179
259
|
File.open(File.join('app', 'controllers', 'railsthemes_controller.rb'), 'w') do |f|
|
180
260
|
f.write <<-EOS
|
@@ -193,19 +273,27 @@ end
|
|
193
273
|
end
|
194
274
|
|
195
275
|
lines = []
|
196
|
-
if File.exists?('config
|
197
|
-
lines =
|
276
|
+
if File.exists?(File.join('config', 'routes.rb'))
|
277
|
+
lines = Utils.read_file('config/routes.rb').split("\n")
|
198
278
|
last = lines.pop
|
199
|
-
lines
|
200
|
-
|
201
|
-
|
279
|
+
if lines.grep(/railsthemes#landing/).empty?
|
280
|
+
lines << " match 'railsthemes/landing' => 'railsthemes#landing'"
|
281
|
+
end
|
282
|
+
if lines.grep(/railsthemes#inner/).empty?
|
283
|
+
lines << " match 'railsthemes/inner' => 'railsthemes#inner'"
|
284
|
+
end
|
285
|
+
if lines.grep(/railsthemes#jquery_ui/).empty?
|
286
|
+
lines << " match 'railsthemes/jquery_ui' => 'railsthemes#jquery_ui'"
|
287
|
+
end
|
202
288
|
lines << last
|
203
|
-
File.open('config
|
289
|
+
File.open(File.join('config', 'routes.rb'), 'w') do |f|
|
204
290
|
lines.each do |line|
|
205
291
|
f.puts line
|
206
292
|
end
|
207
293
|
end
|
208
294
|
end
|
295
|
+
|
296
|
+
@logger.info 'Done creating RailsThemes demo pages.'
|
209
297
|
end
|
210
298
|
|
211
299
|
def check_vcs_status
|
@@ -222,27 +310,36 @@ end
|
|
222
310
|
result = Safe.system_call('svn status')
|
223
311
|
end
|
224
312
|
unless result.size == 0
|
225
|
-
|
313
|
+
return "\n#{variety} reports that you have the following pending changes:\n#{result}\nPlease roll back or commit the changes before proceeding to ensure that you can roll back after installing if you want."
|
226
314
|
end
|
227
315
|
end
|
228
316
|
|
229
317
|
def print_post_installation_instructions
|
318
|
+
number = 0
|
230
319
|
@logger.info <<-EOS
|
231
320
|
|
232
321
|
Yay! Your theme is installed!
|
233
322
|
|
234
323
|
=============================
|
235
324
|
|
325
|
+
Documentation and help
|
326
|
+
|
327
|
+
Theme documentation is located in the doc folder.
|
328
|
+
|
329
|
+
There are some help articles for your perusal at http://support.railsthemes.com.
|
330
|
+
|
331
|
+
|
236
332
|
What now?
|
237
|
-
1)
|
238
|
-
|
239
|
-
|
240
|
-
3)
|
241
|
-
be finnicky.)
|
242
|
-
4) Check out the samples at:
|
333
|
+
1) Make sure that you have the jquery-rails gem installed. All of the current
|
334
|
+
themes require this in your Gemfile so we can use jQuery UI.
|
335
|
+
2) Start or restart your development server.
|
336
|
+
3) Check out the local theme samples at:
|
243
337
|
http://localhost:3000/railsthemes/landing
|
244
338
|
http://localhost:3000/railsthemes/inner
|
245
|
-
|
339
|
+
http://localhost:3000/railsthemes/jquery_ui
|
340
|
+
4) Ensure your new application layout file contains everything that you wanted
|
341
|
+
from the old one.
|
342
|
+
5) Let us know how it went: @railsthemes or support@railsthemes.com.
|
246
343
|
EOS
|
247
344
|
end
|
248
345
|
|
data/lib/railsthemes/safe.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
require 'fileutils'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
require 'thor'
|
2
5
|
|
3
6
|
# a bunch of things that should never be called in testing due to side effects
|
4
7
|
module Railsthemes
|
@@ -10,5 +13,9 @@ module Railsthemes
|
|
10
13
|
def self.log_and_abort s
|
11
14
|
abort s
|
12
15
|
end
|
16
|
+
|
17
|
+
def self.yes? question, color = nil
|
18
|
+
Thor::Shell::Basic.new.yes? question, color
|
19
|
+
end
|
13
20
|
end
|
14
21
|
end
|
data/lib/railsthemes/utils.rb
CHANGED
@@ -17,6 +17,10 @@ module Railsthemes
|
|
17
17
|
FileUtils.cp src, dest
|
18
18
|
end
|
19
19
|
|
20
|
+
def self.read_file filepath
|
21
|
+
File.exists?(filepath) ? File.read(filepath) : ''
|
22
|
+
end
|
23
|
+
|
20
24
|
# would be nice to put download status in the output (speed, progress, etc.)
|
21
25
|
def self.download_file_to url, save_to
|
22
26
|
File.open(save_to, "wb") do |saved_file|
|
data/lib/railsthemes/version.rb
CHANGED
@@ -8,6 +8,14 @@ describe Railsthemes::Installer do
|
|
8
8
|
"\nGEM\n remote: https://rubygems.org/"
|
9
9
|
end
|
10
10
|
|
11
|
+
def using_gem_specs specs = {}
|
12
|
+
lines = []
|
13
|
+
specs.each { |name, version| lines << " #{name} (#{version})"}
|
14
|
+
"GEM\nremote: https://rubygems.org/\nspecs:\n" +
|
15
|
+
lines.join("\n") +
|
16
|
+
"\nGEM\n remote: https://rubygems.org/"
|
17
|
+
end
|
18
|
+
|
11
19
|
before do
|
12
20
|
@logger = Logger.new(File.join Dir.tmpdir, 'railsthemes.log')
|
13
21
|
@installer = Railsthemes::Installer.new @logger
|
@@ -31,6 +39,35 @@ describe Railsthemes::Installer do
|
|
31
39
|
end
|
32
40
|
end
|
33
41
|
|
42
|
+
describe 'override file behavior' do
|
43
|
+
before do
|
44
|
+
FileUtils.mkdir_p('filepath/gems')
|
45
|
+
FileUtils.mkdir_p('filepath/base/app/assets/stylesheets')
|
46
|
+
FileUtils.mkdir_p("app/assets/stylesheets")
|
47
|
+
@filename = 'app/assets/stylesheets/railsthemes_THEME_overrides.anything'
|
48
|
+
FileUtils.touch("filepath/base/#{@filename}")
|
49
|
+
mock(@installer).post_copying_changes
|
50
|
+
stub(@installer).popup_documentation
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should not overwrite override files when they already exist' do
|
54
|
+
File.open(@filename, 'w') do |f|
|
55
|
+
f.write "existing override"
|
56
|
+
end
|
57
|
+
|
58
|
+
@installer.install_from_file_system('filepath')
|
59
|
+
File.exists?(@filename).should be_true
|
60
|
+
File.read(@filename).should =~ /existing override/
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should create override files when they do not already exist' do
|
64
|
+
@installer.install_from_file_system('filepath')
|
65
|
+
File.exists?(@filename).should be_true
|
66
|
+
File.read(@filename).should == ''
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
34
71
|
context 'when the filepath is an archive file' do
|
35
72
|
it 'should extract the archive file to a temp directory if the archive exists' do
|
36
73
|
archive = 'tarfile.tar.gz'
|
@@ -51,6 +88,28 @@ describe Railsthemes::Installer do
|
|
51
88
|
@installer.install_from_file_system("does not exist")
|
52
89
|
end
|
53
90
|
end
|
91
|
+
|
92
|
+
describe 'popping up the documentation on a successful install' do
|
93
|
+
before do
|
94
|
+
# set up files for copying
|
95
|
+
FileUtils.mkdir_p('filepath/base')
|
96
|
+
FileUtils.touch('filepath/base/a')
|
97
|
+
FileUtils.touch('filepath/base/b')
|
98
|
+
FileUtils.mkdir_p('filepath/gems')
|
99
|
+
mock(@installer).post_copying_changes
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should not pop it up when the user specified not to pop it up' do
|
103
|
+
@installer.doc_popup = false
|
104
|
+
dont_allow(@installer).popup_documentation
|
105
|
+
@installer.install_from_file_system 'filepath'
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should pop it up when the user did not specify to not pop it up' do
|
109
|
+
mock(@installer).popup_documentation
|
110
|
+
@installer.install_from_file_system 'filepath'
|
111
|
+
end
|
112
|
+
end
|
54
113
|
end
|
55
114
|
|
56
115
|
describe :install_gems_from do
|
@@ -146,18 +205,52 @@ describe Railsthemes::Installer do
|
|
146
205
|
end
|
147
206
|
end
|
148
207
|
|
208
|
+
describe :ask_to_install_unsupported do
|
209
|
+
it 'should abort if the user does not want to continue' do
|
210
|
+
mock(Railsthemes::Safe).yes?(/wish to install/) { false }
|
211
|
+
mock(Railsthemes::Safe).log_and_abort('Halting.')
|
212
|
+
@installer.ask_to_install_unsupported 'code'
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'should continue if the user wants to continue' do
|
216
|
+
mock(Railsthemes::Safe).yes?(/wish to install/) { true }
|
217
|
+
mock(@installer).install_from_server('code')
|
218
|
+
@installer.ask_to_install_unsupported 'code'
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
149
222
|
describe :download_from_code do
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
223
|
+
it 'should abort if the VCS is not clean' do
|
224
|
+
mock(@installer).check_vcs_status { 'msg' }
|
225
|
+
mock(Railsthemes::Safe).log_and_abort('msg')
|
226
|
+
@installer.download_from_code 'thecode'
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'should ask the user if they still want to install when a Gemfile.lock is not present' do
|
230
|
+
File.unlink('Gemfile.lock')
|
231
|
+
mock(@installer).check_vcs_status { nil }
|
232
|
+
mock(@installer).ask_to_install_unsupported 'thecode'
|
233
|
+
@installer.download_from_code 'thecode'
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'should ask the user if they still want to install when the rails version is < 3.1' do
|
237
|
+
mock(@installer).check_vcs_status { nil }
|
238
|
+
mock(@installer).rails_version { Gem::Version.new('3.0.9') }
|
239
|
+
mock(@installer).ask_to_install_unsupported 'thecode'
|
240
|
+
@installer.download_from_code 'thecode'
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'should install from the server otherwise' do
|
244
|
+
mock(@installer).check_vcs_status { nil }
|
245
|
+
mock(@installer).rails_version { Gem::Version.new('3.1.0') }
|
246
|
+
mock(@installer).install_from_server 'thecode'
|
247
|
+
@installer.download_from_code 'thecode'
|
156
248
|
end
|
249
|
+
end
|
157
250
|
|
251
|
+
describe '#install_from_server' do
|
158
252
|
context 'when a gemfile.lock is present' do
|
159
253
|
before do
|
160
|
-
mock(@installer).check_vcs_status
|
161
254
|
mock(@installer).send_gemfile('panozzaj@gmail.com:code')
|
162
255
|
end
|
163
256
|
|
@@ -168,7 +261,7 @@ describe Railsthemes::Installer do
|
|
168
261
|
mock(@installer).get_primary_configuration('') { 'haml,scss' }
|
169
262
|
mock(Railsthemes::Utils).download_file_to('auth_url', '/tmp/archive.tar.gz')
|
170
263
|
mock(@installer).install_from_archive '/tmp/archive.tar.gz'
|
171
|
-
@installer.
|
264
|
+
@installer.install_from_server 'panozzaj@gmail.com:code'
|
172
265
|
end
|
173
266
|
|
174
267
|
it 'should fail with an error message on any error message' do
|
@@ -176,13 +269,17 @@ describe Railsthemes::Installer do
|
|
176
269
|
'https://railsthemes.com/download?code=panozzaj@gmail.com:code&config=',
|
177
270
|
:body => '', :status => ['401', 'Unauthorized']
|
178
271
|
mock(@installer).get_primary_configuration('') { '' }
|
179
|
-
mock(Railsthemes::Safe).log_and_abort(/didn't
|
180
|
-
@installer.
|
272
|
+
mock(Railsthemes::Safe).log_and_abort(/didn't recognize/)
|
273
|
+
@installer.install_from_server 'panozzaj@gmail.com:code'
|
181
274
|
end
|
182
275
|
end
|
183
276
|
end
|
184
277
|
|
185
278
|
describe '#get_primary_configuration' do
|
279
|
+
it 'should give erb,css when there is no Gemfile' do
|
280
|
+
@installer.get_primary_configuration('').should == 'erb,css'
|
281
|
+
end
|
282
|
+
|
186
283
|
it 'should give haml,scss when haml and sass are in the Gemfile' do
|
187
284
|
gemfile = using_gems 'haml', 'sass'
|
188
285
|
@installer.get_primary_configuration(gemfile).should == 'haml,scss'
|
@@ -205,55 +302,116 @@ describe Railsthemes::Installer do
|
|
205
302
|
end
|
206
303
|
|
207
304
|
describe :check_vcs_status do
|
208
|
-
context 'when
|
305
|
+
context 'when Git used' do
|
209
306
|
before do
|
210
307
|
Dir.mkdir('.git')
|
211
308
|
end
|
212
309
|
|
213
|
-
it 'should
|
310
|
+
it 'should return false, issues when the vcs is unclean' do
|
214
311
|
mock(Railsthemes::Safe).system_call('git status -s') { '# modified: installer_spec.rb' }
|
215
|
-
|
216
|
-
|
312
|
+
result = @installer.check_vcs_status
|
313
|
+
result.should match /Git reports/
|
314
|
+
result.should match /# modified: installer_spec\.rb/
|
315
|
+
result.should match /roll back or commit/
|
217
316
|
end
|
218
317
|
|
219
318
|
it 'should do nothing significant when the vcs is clean' do
|
220
319
|
mock(Railsthemes::Safe).system_call('git status -s') { '' }
|
221
|
-
@installer.check_vcs_status
|
320
|
+
@installer.check_vcs_status.should be_nil
|
222
321
|
end
|
223
322
|
end
|
224
323
|
|
225
|
-
context 'when
|
324
|
+
context 'when Mercurial used' do
|
226
325
|
before do
|
227
326
|
Dir.mkdir('.hg')
|
228
327
|
end
|
229
328
|
|
230
329
|
it 'should exit when the vcs is unclean' do
|
231
330
|
mock(Railsthemes::Safe).system_call('hg status') { '? test.txt' }
|
232
|
-
|
233
|
-
|
331
|
+
result = @installer.check_vcs_status
|
332
|
+
result.should_not be_nil
|
333
|
+
result.should match /Mercurial reports/
|
334
|
+
result.should match /\? test\.txt/
|
335
|
+
result.should match /roll back or commit/
|
234
336
|
end
|
235
337
|
|
236
338
|
it 'should do nothing significant when the vcs is clean' do
|
237
339
|
mock(Railsthemes::Safe).system_call('hg status') { '' }
|
238
|
-
@installer.check_vcs_status
|
340
|
+
@installer.check_vcs_status.should be_nil
|
239
341
|
end
|
240
342
|
end
|
241
343
|
|
242
|
-
context 'when
|
344
|
+
context 'when Subversion used' do
|
243
345
|
before do
|
244
346
|
Dir.mkdir('.svn')
|
245
347
|
end
|
246
348
|
|
247
349
|
it 'should exit when the vcs is unclean' do
|
248
350
|
mock(Railsthemes::Safe).system_call('svn status') { 'M something.txt' }
|
249
|
-
|
250
|
-
|
351
|
+
result = @installer.check_vcs_status
|
352
|
+
result.should match /Subversion reports/
|
353
|
+
result.should match /M something\.txt/
|
354
|
+
result.should match /roll back or commit/
|
251
355
|
end
|
252
356
|
|
253
357
|
it 'should do nothing significant when the vcs is clean' do
|
254
358
|
mock(Railsthemes::Safe).system_call('svn status') { '' }
|
255
|
-
@installer.check_vcs_status
|
359
|
+
@installer.check_vcs_status.should be_nil
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
364
|
+
describe '#create_railsthemes_demo_pages' do
|
365
|
+
before do
|
366
|
+
FileUtils.mkdir('config')
|
367
|
+
File.open(File.join('config', 'routes.rb'), 'w') do |f|
|
368
|
+
f.write <<-EOS
|
369
|
+
RailsApp::Application.routes.draw do
|
370
|
+
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
371
|
+
# Note: This route will make all actions in every controller accessible via GET requests.
|
372
|
+
# match ':controller(/:action(/:id(.:format)))'
|
373
|
+
end
|
374
|
+
EOS
|
256
375
|
end
|
257
376
|
end
|
377
|
+
|
378
|
+
it 'should create a RailsThemes controller' do
|
379
|
+
@installer.create_railsthemes_demo_pages
|
380
|
+
controller = File.join('app', 'controllers', 'railsthemes_controller.rb')
|
381
|
+
lines = File.read(controller).split("\n")
|
382
|
+
lines.count.should == 11
|
383
|
+
lines.first.should match /class RailsthemesController < ApplicationController/
|
384
|
+
end
|
385
|
+
|
386
|
+
it 'should insert lines into the routes file' do
|
387
|
+
@installer.create_railsthemes_demo_pages
|
388
|
+
routes_file = File.join('config', 'routes.rb')
|
389
|
+
lines = File.read(routes_file).split("\n")
|
390
|
+
lines.grep(/match 'railsthemes\/landing' => 'railsthemes#landing'/).count.should == 1
|
391
|
+
lines.grep(/match 'railsthemes\/inner' => 'railsthemes#inner'/).count.should == 1
|
392
|
+
lines.grep(/match 'railsthemes\/jquery_ui' => 'railsthemes#jquery_ui'/).count.should == 1
|
393
|
+
end
|
394
|
+
|
395
|
+
it 'should not insert lines into the routes file when run more than once' do
|
396
|
+
@installer.create_railsthemes_demo_pages
|
397
|
+
@installer.create_railsthemes_demo_pages
|
398
|
+
routes_file = File.join('config', 'routes.rb')
|
399
|
+
lines = File.read(routes_file).split("\n")
|
400
|
+
lines.grep(/match 'railsthemes\/landing' => 'railsthemes#landing'/).count.should == 1
|
401
|
+
lines.grep(/match 'railsthemes\/inner' => 'railsthemes#inner'/).count.should == 1
|
402
|
+
lines.grep(/match 'railsthemes\/jquery_ui' => 'railsthemes#jquery_ui'/).count.should == 1
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
describe '#rails_version' do
|
407
|
+
it 'should return the right version' do
|
408
|
+
gemfile = using_gem_specs :rails => '3.0.1'
|
409
|
+
@installer.rails_version(gemfile).version.should == '3.0.1'
|
410
|
+
end
|
411
|
+
|
412
|
+
it 'should return nil if there is no rails present' do
|
413
|
+
gemfile = using_gem_specs
|
414
|
+
@installer.rails_version(gemfile).should be_nil
|
415
|
+
end
|
258
416
|
end
|
259
417
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,6 +7,16 @@ require 'fakeweb'
|
|
7
7
|
RSpec.configure do |config|
|
8
8
|
config.mock_with :rr
|
9
9
|
config.include FakeFS::SpecHelpers
|
10
|
+
|
11
|
+
# RSpec automatically cleans stuff out of backtraces;
|
12
|
+
# sometimes this is annoying when trying to debug something e.g. a gem
|
13
|
+
#config.backtrace_clean_patterns = [
|
14
|
+
# /\/lib\d*\/ruby\//,
|
15
|
+
# /bin\//,
|
16
|
+
# /gems/,
|
17
|
+
# /spec\/spec_helper\.rb/,
|
18
|
+
# /lib\/rspec\/(core|expectations|matchers|mocks)/
|
19
|
+
#]
|
10
20
|
end
|
11
21
|
|
12
22
|
FakeWeb.allow_net_connect = false
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: railsthemes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 4
|
10
|
+
version: 1.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Railsthemes
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-06-11 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: thor
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- .rspec
|
60
60
|
- .rvmrc
|
61
61
|
- Gemfile
|
62
|
+
- Guardfile
|
62
63
|
- LICENSE
|
63
64
|
- README.md
|
64
65
|
- Rakefile
|