railsthemes 1.0.4 → 1.1.pre

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/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ railsthemes.log
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
  gem 'thor'
6
6
  gem 'rest-client'
7
+ gem 'launchy'
7
8
 
8
9
  group :development do
9
10
  gem 'gem-release'
@@ -16,6 +17,6 @@ group :test do
16
17
  gem 'rspec'
17
18
  gem 'rr'
18
19
  gem 'autotest'
19
- gem 'fakefs', :require => 'fakefs/safe', :git => 'https://github.com/defunkt/fakefs'
20
+ gem 'fakefs', :require => 'fakefs/safe', :git => 'https://github.com/RailsThemes/fakefs.git'
20
21
  gem 'fakeweb'
21
22
  end
data/bin/railsthemes CHANGED
@@ -10,12 +10,22 @@ class Installer < Thor
10
10
  :type => :boolean
11
11
  method_option :no_doc_popup,
12
12
  :desc => "Do not pop up documentation on successful install.",
13
- :aliases => "--no-doc-popup",
13
+ :type => :boolean
14
+ method_option :verbose,
15
+ :desc => "Print more output on installation.",
16
+ :type => :boolean
17
+ # do not rename to :debug, conflicts with Thor built-in functionality
18
+ method_option :debugging,
19
+ :desc => "Print gratuitous output on installation (for debugging).",
14
20
  :type => :boolean
15
21
 
16
22
  def install code_or_file
23
+ # might be better to pass in the options directly if we get more options
17
24
  installer = Railsthemes::Installer.new
18
25
  installer.doc_popup = !options[:no_doc_popup]
26
+ installer.verbose if options[:verbose]
27
+ installer.debug if options[:debugging]
28
+
19
29
  if options[:file]
20
30
  file = code_or_file
21
31
  abort 'Please specify a file to install from' unless file
@@ -6,20 +6,24 @@ require 'tmpdir'
6
6
  require 'bundler'
7
7
  require 'net/http'
8
8
  require 'rest-client'
9
+ require 'launchy'
9
10
 
10
11
  module Railsthemes
11
12
  class Installer
12
13
  def initialize logger = nil
13
14
  @logger = logger
14
- @server = 'https://railsthemes.com'
15
- if File.exist?('railsthemes_server')
16
- @server = File.read('railsthemes_server').gsub("\n", '')
17
- end
18
15
  @logger ||= Logger.new(STDOUT)
16
+
19
17
  # just print out basic information, not all of the extra logger stuff
20
18
  @logger.formatter = proc do |severity, datetime, progname, msg|
21
19
  "#{msg}\n"
22
20
  end
21
+
22
+ @server = 'https://railsthemes.com'
23
+ if File.exist?('railsthemes_server')
24
+ @server = File.read('railsthemes_server').gsub("\n", '')
25
+ end
26
+
23
27
  @doc_popup = true
24
28
  end
25
29
 
@@ -27,36 +31,56 @@ module Railsthemes
27
31
  @doc_popup = doc_popup
28
32
  end
29
33
 
34
+ def verbose
35
+ @logger.level = Logger::INFO
36
+ @logger.info 'In verbose mode.'
37
+ end
38
+
39
+ def debug
40
+ @logger.level = Logger::DEBUG
41
+ @logger.debug 'In debug mode.'
42
+ end
43
+
30
44
  def ensure_in_rails_root
31
45
  unless File.directory?('app') && File.directory?('public')
32
46
  Safe.log_and_abort 'Must be in the Rails root directory to use this gem.'
33
47
  end
34
48
  end
35
49
 
36
- def install_from_file_system source_filepath
50
+ def install_from_file_system original_source_filepath
51
+ source_filepath = original_source_filepath.gsub(/\\/, '/')
37
52
  if File.directory?(source_filepath)
38
53
  ensure_in_rails_root
39
54
 
40
- @logger.info 'Installing...'
55
+ @logger.warn 'Installing...'
41
56
 
42
57
  # this file causes issues when HAML is also present, and we overwrite
43
58
  # it in the ERB case, so safe to delete here
59
+ @logger.debug 'removing file app/views/layouts/application.html.erb'
44
60
  Utils.remove_file('app/views/layouts/application.html.erb')
45
61
 
62
+ @logger.debug "source_filepath: #{source_filepath}"
46
63
  Dir["#{source_filepath}/base/**/*"].each do |src|
64
+ @logger.debug "src: #{src}"
47
65
  dest = src.sub("#{source_filepath}/base/", '')
66
+ @logger.debug "dest: #{dest}"
48
67
  if File.directory?(src)
68
+ @logger.debug "mkdir -p #{dest}"
49
69
  FileUtils.mkdir_p(dest)
50
70
  else
51
- unless dest =~ /railsthemes_.*_overrides\.*/ && File.exists?(dest)
71
+ unless (dest =~ /railsthemes_.*_overrides\.*/ && File.exists?(dest)) ||
72
+ src =~ /\/\./ # remove any pesky hidden files that crept into the archive
73
+ @logger.debug "cp #{src} #{dest}"
52
74
  FileUtils.cp(src, dest)
53
75
  end
54
76
  end
55
77
  end
78
+
56
79
  gem_names = gemspecs(Utils.read_file('Gemfile.lock')).map(&:name) - ['haml', 'sass']
57
80
  install_gems_from(source_filepath, gem_names)
58
81
 
59
- @logger.info 'Done installing.'
82
+ @logger.warn 'Done installing.'
83
+
60
84
  post_copying_changes
61
85
  print_post_installation_instructions
62
86
  popup_documentation if @doc_popup
@@ -75,25 +99,29 @@ module Railsthemes
75
99
 
76
100
  def popup_documentation
77
101
  style_guide = Dir['doc/*Usage_And_Style_Guide.html'].first
78
- Safe.system_call("open #{style_guide}") if style_guide
102
+ @logger.debug("style_guide: #{style_guide}")
103
+ Launchy.open(style_guide) if style_guide
79
104
  end
80
105
 
81
106
  def install_gems_from source_filepath, gem_names
107
+ return unless File.directory?("#{source_filepath}/gems")
108
+ @logger.debug "gem_names: #{gem_names * ' '}"
82
109
  gems_that_we_can_install = Dir.entries("#{source_filepath}/gems").reject{|x| x == '.' || x == '..'}
110
+ @logger.debug "gems_that_we_can_install: #{gems_that_we_can_install * ' '}"
83
111
  (gem_names & gems_that_we_can_install).each do |gem_name|
84
- FileUtils.cp_r(File.join(source_filepath, 'gems', gem_name, '.'), '.')
112
+ src = File.join(source_filepath, 'gems', gem_name, '.')
113
+ @logger.debug("copying gems from #{src}")
114
+ FileUtils.cp_r(src, '.')
85
115
  end
86
116
  end
87
117
 
88
118
  def install_from_archive filepath
89
- @logger.info "Extracting..."
119
+ @logger.warn "Extracting..."
90
120
  with_tempdir do |tempdir|
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
96
- @logger.info "Finished extracting."
121
+ io = Tar.ungzip(File.open(filepath, 'rb'))
122
+ Tar.untar(io, tempdir)
123
+
124
+ @logger.warn "Finished extracting."
97
125
  install_from_file_system tempdir
98
126
  end
99
127
  end
@@ -103,16 +131,51 @@ module Railsthemes
103
131
  if vcs_is_unclean_message
104
132
  Safe.log_and_abort vcs_is_unclean_message
105
133
  else
106
- if File.exists?('Gemfile.lock') && Gem::Version.new('3.1') <= rails_version
107
- install_from_server code
134
+ version_is_bad_message = check_installer_version
135
+ if version_is_bad_message
136
+ Safe.log_and_abort version_is_bad_message
137
+ else
138
+ if File.exists?('Gemfile.lock') && Gem::Version.new('3.1') <= rails_version
139
+ install_from_server code
140
+ else
141
+ ask_to_install_unsupported code
142
+ end
143
+ end
144
+ end
145
+ end
146
+
147
+ def check_installer_version
148
+ begin
149
+ response = Utils.get_url(@server + '/installer/version')
150
+ rescue SocketError => e
151
+ Safe.log_and_abort 'We could not reach the RailsThemes server to download the theme. Please check your internet connection and try again.'
152
+ rescue Exception => e
153
+ @logger.info e.message
154
+ @logger.info e.backtrace * "\n"
155
+ end
156
+
157
+ if response && response.code.to_s == '200'
158
+ server_recommended_version_string = response.body
159
+ server_recommended_version = Gem::Version.new(server_recommended_version_string)
160
+ local_installer_version = Gem::Version.new(Railsthemes::VERSION)
161
+
162
+ if server_recommended_version > local_installer_version
163
+ <<-EOS
164
+ Your version is older than the recommended version.
165
+ Your version: #{Railsthemes::VERSION}
166
+ Recommended version: #{server_recommended_version_string}
167
+ EOS
108
168
  else
109
- ask_to_install_unsupported code
169
+ @logger.debug "server recommended version: #{server_recommended_version_string}"
170
+ nil
110
171
  end
172
+ else
173
+ 'There was an issue checking your installer version.'
111
174
  end
112
175
  end
113
176
 
114
177
  def install_from_server code
115
- @logger.info "Downloading theme from server..."
178
+ @logger.warn "Downloading theme from server..."
116
179
  with_tempdir do |tempdir|
117
180
  archive = File.join(tempdir, 'archive.tar.gz')
118
181
  if File.exists?('Gemfile.lock')
@@ -122,7 +185,7 @@ module Railsthemes
122
185
  dl_url = get_download_url "#{@server}/download?code=#{code}&config=#{config}"
123
186
  if dl_url
124
187
  Utils.download_file_to dl_url, archive
125
- @logger.info "Finished downloading."
188
+ @logger.warn "Finished downloading."
126
189
  install_from_archive archive
127
190
  else
128
191
  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.")
@@ -131,22 +194,22 @@ module Railsthemes
131
194
  end
132
195
 
133
196
  def ask_to_install_unsupported code
134
- @logger.info "WARNING\n"
197
+ @logger.warn "WARNING\n"
135
198
 
136
199
  if File.exists?('Gemfile.lock')
137
- @logger.info <<-EOS
200
+ @logger.warn <<-EOS
138
201
  Your Gemfile.lock file indicates that you are using a version of Rails that
139
202
  is not officially supported by RailsThemes.
140
203
  EOS
141
204
  else
142
- @logger.info <<-EOS
205
+ @logger.warn <<-EOS
143
206
  We could not find a Gemfile.lock file in this directory. This could indicate
144
207
  that you are not in a Rails application, or that you are not using Bundler
145
208
  (which probably means that you are using a version of Rails that is not
146
209
  officially supported by RailsThemes.)
147
210
  EOS
148
211
  end
149
- @logger.info <<-EOS
212
+ @logger.warn <<-EOS
150
213
  While Rails applications that are less than version 3.1 are not officially
151
214
  supported, you can try installing anyway, or can stop. If you cancel the
152
215
  install before downloading, we can refund your purchase. If you install,
@@ -165,29 +228,18 @@ but which may be more complicated.
165
228
  def get_download_url server_request_url
166
229
  response = nil
167
230
  begin
168
- url = URI.parse(server_request_url)
169
- http = Net::HTTP.new url.host, url.port
170
- if server_request_url =~ /^https/
171
- http.use_ssl = true
172
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
173
- end
174
- path = server_request_url.gsub(%r{https?://[^/]+}, '')
175
- response = http.request_get(path)
231
+ response = Utils.get_url server_request_url
176
232
  rescue SocketError => e
177
233
  Safe.log_and_abort 'We could not reach the RailsThemes server to download the theme. Please check your internet connection and try again.'
178
234
  rescue Exception => e
179
- #@logger.info e.message
180
- #@logger.info e.backtrace
235
+ @logger.info e.message
236
+ @logger.info e.backtrace
181
237
  end
182
238
 
183
- if response
184
- if response.code.to_s == '200'
185
- return response.body
186
- else
187
- #@logger.info response
188
- #@logger.info "Got a #{response.code} error while trying to download."
189
- return nil
190
- end
239
+ if response && response.code.to_s == '200'
240
+ response.body
241
+ else
242
+ nil
191
243
  end
192
244
  end
193
245
 
@@ -208,9 +260,7 @@ but which may be more complicated.
208
260
  gemfile_contents ||= Utils.read_file('Gemfile.lock')
209
261
  specs = gemspecs(gemfile_contents)
210
262
  rails = specs.select{ |x| x.name == 'rails' }.first
211
- if rails && rails.version
212
- rails.version
213
- end
263
+ rails.version if rails && rails.version
214
264
  end
215
265
 
216
266
  def send_gemfile code
@@ -233,29 +283,29 @@ but which may be more complicated.
233
283
  end
234
284
 
235
285
  def generate_tempdir_name
236
- File.join(Dir.tmpdir, DateTime.now.strftime("railsthemes-%Y%m%d-%H%M%S-#{rand(100000000)}"))
286
+ tempdir = File.join(Dir.tmpdir, DateTime.now.strftime("railsthemes-%Y%m%d-%H%M%S-#{rand(100000000)}"))
287
+ @logger.debug "tempdir: #{tempdir}"
288
+ tempdir
237
289
  end
238
290
 
239
291
  def archive? filepath
240
292
  filepath =~ /\.tar\.gz$/
241
293
  end
242
294
 
243
- def untar_string filepath, newdirpath
244
- "tar -zxf #{filepath} -C #{newdirpath}"
245
- end
246
-
247
-
248
295
  # this happens after a successful copy so that we set up the environment correctly
249
296
  # for people to view the theme correctly
250
297
  def post_copying_changes
298
+ @logger.info "Removing public/index.html"
251
299
  Utils.remove_file File.join('public', 'index.html')
252
300
  create_railsthemes_demo_pages
253
301
  end
254
302
 
255
303
  def create_railsthemes_demo_pages
256
- @logger.info 'Creating RailsThemes demo pages...'
304
+ @logger.warn 'Creating RailsThemes demo pages...'
257
305
 
306
+ @logger.debug "mkdir -p app/controllers"
258
307
  FileUtils.mkdir_p(File.join('app', 'controllers'))
308
+ @logger.debug "writing to app/controllers/railsthemes_controller.rb"
259
309
  File.open(File.join('app', 'controllers', 'railsthemes_controller.rb'), 'w') do |f|
260
310
  f.write <<-EOS
261
311
  class RailsthemesController < ApplicationController
@@ -293,7 +343,7 @@ end
293
343
  end
294
344
  end
295
345
 
296
- @logger.info 'Done creating RailsThemes demo pages.'
346
+ @logger.warn 'Done creating RailsThemes demo pages.'
297
347
  end
298
348
 
299
349
  def check_vcs_status
@@ -316,7 +366,7 @@ end
316
366
 
317
367
  def print_post_installation_instructions
318
368
  number = 0
319
- @logger.info <<-EOS
369
+ @logger.warn <<-EOS
320
370
 
321
371
  Yay! Your theme is installed!
322
372
 
@@ -0,0 +1,17 @@
1
+ module OS
2
+ def OS.windows?
3
+ (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
4
+ end
5
+
6
+ def OS.mac?
7
+ (/darwin/ =~ RUBY_PLATFORM) != nil
8
+ end
9
+
10
+ def OS.unix?
11
+ !OS.windows?
12
+ end
13
+
14
+ def OS.linux?
15
+ OS.unix? and not OS.mac?
16
+ end
17
+ end
@@ -0,0 +1,89 @@
1
+ # lifted from https://gist.github.com/1335041
2
+ require 'rubygems'
3
+ require 'rubygems/package'
4
+ require 'zlib'
5
+ require 'fileutils'
6
+
7
+ module Railsthemes
8
+ class Tar
9
+ # Creates a tar file in memory recursively
10
+ # from the given path.
11
+ #
12
+ # Returns a StringIO whose underlying String
13
+ # is the contents of the tar file.
14
+ def self.tar(path)
15
+ tarfile = StringIO.new("")
16
+ Gem::Package::TarWriter.new(tarfile) do |tar|
17
+ Dir[File.join(path, "**/*")].each do |file|
18
+ mode = File.stat(file).mode
19
+ relative_file = file.sub /^#{Regexp::escape path}\/?/, ''
20
+
21
+ if File.directory?(file)
22
+ tar.mkdir relative_file, mode
23
+ else
24
+ tar.add_file relative_file, mode do |tf|
25
+ File.open(file, "rb") { |f| tf.write f.read }
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ tarfile.rewind
32
+ tarfile
33
+ end
34
+
35
+ # gzips the underlying string in the given StringIO,
36
+ # returning a new StringIO representing the
37
+ # compressed file.
38
+ def self.gzip(tarfile)
39
+ gz = StringIO.new("")
40
+ z = Zlib::GzipWriter.new(gz)
41
+ z.write tarfile.string
42
+ z.close # this is necessary!
43
+
44
+ # z was closed to write the gzip footer, so
45
+ # now we need a new StringIO
46
+ StringIO.new gz.string
47
+ end
48
+
49
+ # un-gzips the given IO, returning the
50
+ # decompressed version as a StringIO
51
+ def self.ungzip(tarfile)
52
+ z = Zlib::GzipReader.new(tarfile)
53
+ unzipped = StringIO.new(z.read)
54
+ z.close
55
+ unzipped
56
+ end
57
+
58
+ # untars the given IO into the specified
59
+ # directory
60
+ def self.untar(io, destination)
61
+ Gem::Package::TarReader.new io do |tar|
62
+ tar.each do |tarfile|
63
+ destination_file = File.join destination, tarfile.full_name
64
+
65
+ if tarfile.directory?
66
+ FileUtils.mkdir_p destination_file
67
+ else
68
+ destination_directory = File.dirname(destination_file)
69
+ FileUtils.mkdir_p destination_directory unless File.directory?(destination_directory)
70
+ File.open destination_file, "wb" do |f|
71
+ f.print tarfile.read
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+
81
+ ### Usage Example: ###
82
+ #
83
+ # include Util::Tar
84
+ #
85
+ # io = tar("./Desktop") # io is a TAR of files
86
+ # gz = gzip(io) # gz is a TGZ
87
+ #
88
+ # io = ungzip(gz) # io is a TAR
89
+ # untar(io, "./untarred") # files are untarred
@@ -1,9 +1,12 @@
1
1
  require 'fileutils'
2
2
  require 'open-uri'
3
+ require 'railsthemes/os'
3
4
 
4
5
  # a bunch of things that should never be called in testing due to side effects
5
6
  module Railsthemes
6
7
  class Utils
8
+ @@https_seen_before = false
9
+
7
10
  # remove file only if it exists
8
11
  def self.remove_file filepath
9
12
  if File.exists?(filepath)
@@ -30,5 +33,23 @@ module Railsthemes
30
33
  end
31
34
  end
32
35
  end
36
+
37
+ def self.get_url server_request_url
38
+ url = URI.parse(server_request_url)
39
+ http = Net::HTTP.new url.host, url.port
40
+ if server_request_url =~ /^https/
41
+ if ::OS.windows?
42
+ unless @@https_seen_before
43
+ Railsthemes::WinCacerts.fetch
44
+ @@https_seen_before = true
45
+ end
46
+ http.ca_file = 'C:/RailsInstaller/cacert.pem'
47
+ end
48
+ http.use_ssl = true
49
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
50
+ end
51
+ path = server_request_url.gsub(%r{https?://[^/]+}, '')
52
+ http.request_get(path)
53
+ end
33
54
  end
34
55
  end
@@ -1,5 +1,5 @@
1
1
  module Railsthemes
2
2
  unless defined?(Railsthemes::VERSION)
3
- VERSION = "1.0.4"
3
+ VERSION = "1.1.pre"
4
4
  end
5
5
  end
@@ -0,0 +1,26 @@
1
+ # This is required on Windows to get around an issue where SSL certificates
2
+ # are not loaded properly on default
3
+ #
4
+ # originally from https://raw.github.com/gist/867550/win_fetch_cacerts.rb, from
5
+ # https://gist.github.com/867550
6
+
7
+ require 'net/http'
8
+
9
+ module Railsthemes
10
+ class WinCacerts
11
+ def self.fetch
12
+ # create a path to the file "C:\RailsInstaller\cacert.pem"
13
+ cacert_file = File.join(%w{c: RailsInstaller cacert.pem})
14
+
15
+ Net::HTTP.start("curl.haxx.se") do |http|
16
+ resp = http.get("/ca/cacert.pem")
17
+ if resp.code == "200"
18
+ open(cacert_file, "wb") { |file| file.write(resp.body) }
19
+ ENV['SSL_CERT_FILE'] = 'C:\RailsInstaller\cacert.pem'
20
+ else
21
+ Railsthemes::Safe.log_and_abort "A cacert.pem bundle could not be downloaded."
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
data/lib/railsthemes.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require 'railsthemes/version'
2
2
  require 'railsthemes/safe'
3
3
  require 'railsthemes/utils'
4
+ require 'railsthemes/tar'
4
5
  require 'railsthemes/installer'
6
+ require 'railsthemes/win_cacerts'
5
7
 
6
8
  module Railsthemes
7
9
  end
Binary file
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'railsthemes'
3
+ require 'railsthemes/os'
3
4
 
4
5
  describe Railsthemes::Installer do
5
6
  def using_gems *gems
@@ -16,11 +17,25 @@ describe Railsthemes::Installer do
16
17
  "\nGEM\n remote: https://rubygems.org/"
17
18
  end
18
19
 
20
+ LOGFILE_NAME = 'railsthemes.log'
21
+
22
+ before :all do
23
+ File.delete(LOGFILE_NAME) if File.exists?(LOGFILE_NAME)
24
+ end
25
+
19
26
  before do
20
- @logger = Logger.new(File.join Dir.tmpdir, 'railsthemes.log')
27
+ @logger = Logger.new(LOGFILE_NAME)
28
+ @logger.info "#{self.example.description}"
21
29
  @installer = Railsthemes::Installer.new @logger
22
30
  stub(@installer).ensure_in_rails_root
23
- stub(@installer).generate_tempdir_name { '/tmp' }
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 }
24
39
  FileUtils.touch('Gemfile.lock')
25
40
  end
26
41
 
@@ -30,12 +45,43 @@ describe Railsthemes::Installer do
30
45
  FileUtils.mkdir_p('filepath/base')
31
46
  FileUtils.touch('filepath/base/a')
32
47
  FileUtils.touch('filepath/base/b')
33
- FileUtils.mkdir_p('filepath/gems')
34
48
  mock(@installer).post_copying_changes
35
49
 
36
50
  @installer.install_from_file_system('filepath')
37
- File.exists?('a').should be_true
38
- File.exists?('b').should be_true
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')
39
85
  end
40
86
  end
41
87
 
@@ -56,13 +102,13 @@ describe Railsthemes::Installer do
56
102
  end
57
103
 
58
104
  @installer.install_from_file_system('filepath')
59
- File.exists?(@filename).should be_true
105
+ File.should exist(@filename)
60
106
  File.read(@filename).should =~ /existing override/
61
107
  end
62
108
 
63
109
  it 'should create override files when they do not already exist' do
64
110
  @installer.install_from_file_system('filepath')
65
- File.exists?(@filename).should be_true
111
+ File.should exist(@filename)
66
112
  File.read(@filename).should == ''
67
113
  end
68
114
  end
@@ -114,27 +160,22 @@ describe Railsthemes::Installer do
114
160
 
115
161
  describe :install_gems_from do
116
162
  it 'should install the gems that we specify that match' do
117
- FakeFS::FileSystem.clone('spec/fixtures')
163
+ FakeFS::FileSystem.clone('spec/fixtures/blank-assets')
164
+ # we only know about formtastic and simple_form in the gems directory
118
165
  @installer.install_gems_from("spec/fixtures/blank-assets", ['formtastic', 'kaminari'])
119
- File.exist?(File.join('app', 'assets', 'stylesheets', 'formtastic.css.scss')).should be_true
120
- File.exist?(File.join('app', 'assets', 'stylesheets', 'kaminari.css.scss')).should be_false
121
- File.exist?(File.join('app', 'assets', 'stylesheets', 'simple_form.css.scss')).should be_false
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')
122
169
  end
123
170
  end
124
171
 
125
172
  describe :install_from_archive do
126
- it 'should extract the archive correctly' do
127
- mock(@installer).install_from_file_system '/tmp'
128
- mock(@installer).untar_string('filepath', anything) { 'untar string' }
129
- mock(Railsthemes::Safe).system_call('untar string')
130
- @installer.install_from_archive 'filepath'
131
- end
132
- end
133
-
134
- describe :untar_string do
135
- it 'should return correct value for *.tar.gz file' do
136
- result = @installer.untar_string 'file.tar.gz', 'newdirpath'
137
- result.should == 'tar -zxf file.tar.gz -C newdirpath'
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
138
179
  end
139
180
  end
140
181
 
@@ -158,7 +199,7 @@ describe Railsthemes::Installer do
158
199
  'app/views/layouts/_interior_sidebar.html.erb',
159
200
  'app/views/layouts/application.html.erb',
160
201
  'app/views/layouts/homepage.html.erb'].each do |filename|
161
- File.exist?(filename).should be_true, "#{filename} was not present"
202
+ File.should exist(filename), "#{filename} was not present"
162
203
  end
163
204
  File.open('app/assets/stylesheets/style.css.erb').each do |line|
164
205
  line.should match /style.css.erb/
@@ -168,6 +209,7 @@ describe Railsthemes::Installer do
168
209
  before do
169
210
  stub(@installer).post_copying_changes
170
211
  FakeFS::FileSystem.clone('spec/fixtures')
212
+ # should add some gems to the gemfile here and test gem installation
171
213
  end
172
214
 
173
215
  it 'should extract correctly from directory' do
@@ -176,9 +218,11 @@ describe Railsthemes::Installer do
176
218
  verify_end_to_end_operation
177
219
  end
178
220
 
179
- # TODO need to use a pure ruby solution to get this to mock in the file system right
221
+ # does not work on Windows, NotImplementedError in tar module
180
222
  it 'should extract correctly from archive' do
181
- pending 'needs pure ruby untar solution'
223
+ filename = 'spec/fixtures/blank-assets.tar.gz'
224
+ @installer.install_from_file_system filename
225
+ verify_end_to_end_operation
182
226
  end
183
227
  end
184
228
 
@@ -226,28 +270,84 @@ describe Railsthemes::Installer do
226
270
  @installer.download_from_code 'thecode'
227
271
  end
228
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
+
229
280
  it 'should ask the user if they still want to install when a Gemfile.lock is not present' do
230
281
  File.unlink('Gemfile.lock')
231
- mock(@installer).check_vcs_status { nil }
282
+ mock(@installer).check_vcs_status
283
+ mock(@installer).check_installer_version
232
284
  mock(@installer).ask_to_install_unsupported 'thecode'
233
285
  @installer.download_from_code 'thecode'
234
286
  end
235
287
 
236
288
  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 }
289
+ mock(@installer).check_vcs_status
290
+ mock(@installer).check_installer_version
238
291
  mock(@installer).rails_version { Gem::Version.new('3.0.9') }
239
292
  mock(@installer).ask_to_install_unsupported 'thecode'
240
293
  @installer.download_from_code 'thecode'
241
294
  end
242
295
 
243
296
  it 'should install from the server otherwise' do
244
- mock(@installer).check_vcs_status { nil }
297
+ mock(@installer).check_vcs_status
298
+ mock(@installer).check_installer_version
245
299
  mock(@installer).rails_version { Gem::Version.new('3.1.0') }
246
300
  mock(@installer).install_from_server 'thecode'
247
301
  @installer.download_from_code 'thecode'
248
302
  end
249
303
  end
250
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
342
+ end
343
+
344
+ it 'should return an error message on any HTTP errors' do
345
+ FakeWeb.register_uri :get, /\/installer\/version$/,
346
+ :body => '', :status => ['401', 'Unauthorized']
347
+ @installer.check_installer_version.should_not be_nil
348
+ end
349
+ end
350
+
251
351
  describe '#install_from_server' do
252
352
  context 'when a gemfile.lock is present' do
253
353
  before do
@@ -259,8 +359,8 @@ describe Railsthemes::Installer do
259
359
  /download\?code=panozzaj@gmail.com:code&config=haml,scss/,
260
360
  :body => 'auth_url'
261
361
  mock(@installer).get_primary_configuration('') { 'haml,scss' }
262
- mock(Railsthemes::Utils).download_file_to('auth_url', '/tmp/archive.tar.gz')
263
- mock(@installer).install_from_archive '/tmp/archive.tar.gz'
362
+ mock(Railsthemes::Utils).download_file_to('auth_url', "#{@tempdir}/archive.tar.gz")
363
+ mock(@installer).install_from_archive "#{@tempdir}/archive.tar.gz"
264
364
  @installer.install_from_server 'panozzaj@gmail.com:code'
265
365
  end
266
366
 
@@ -414,4 +514,19 @@ end
414
514
  @installer.rails_version(gemfile).should be_nil
415
515
  end
416
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
417
532
  end
data/spec/spec_helper.rb CHANGED
@@ -11,11 +11,11 @@ RSpec.configure do |config|
11
11
  # RSpec automatically cleans stuff out of backtraces;
12
12
  # sometimes this is annoying when trying to debug something e.g. a gem
13
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)/
14
+ ## /\/lib\d*\/ruby\//,
15
+ ## /bin\//,
16
+ ## /gems/,
17
+ ## /spec\/spec_helper\.rb/,
18
+ ## /lib\/rspec\/(core|expectations|matchers|mocks)/
19
19
  #]
20
20
  end
21
21
 
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: 31
5
- prerelease:
4
+ hash: 961915928
5
+ prerelease: 4
6
6
  segments:
7
7
  - 1
8
- - 0
9
- - 4
10
- version: 1.0.4
8
+ - 1
9
+ - pre
10
+ version: 1.1.pre
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-06-11 00:00:00 Z
18
+ date: 2012-06-18 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: thor
@@ -66,10 +66,14 @@ files:
66
66
  - bin/railsthemes
67
67
  - lib/railsthemes.rb
68
68
  - lib/railsthemes/installer.rb
69
+ - lib/railsthemes/os.rb
69
70
  - lib/railsthemes/safe.rb
71
+ - lib/railsthemes/tar.rb
70
72
  - lib/railsthemes/utils.rb
71
73
  - lib/railsthemes/version.rb
74
+ - lib/railsthemes/win_cacerts.rb
72
75
  - railsthemes.gemspec
76
+ - spec/fixtures/blank-assets.tar.gz
73
77
  - spec/fixtures/blank-assets/base/app/assets/images/bg/sprite.png
74
78
  - spec/fixtures/blank-assets/base/app/assets/images/image1.png
75
79
  - spec/fixtures/blank-assets/base/app/assets/javascripts/jquery.dataTables.js
@@ -102,12 +106,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
106
  required_rubygems_version: !ruby/object:Gem::Requirement
103
107
  none: false
104
108
  requirements:
105
- - - ">="
109
+ - - ">"
106
110
  - !ruby/object:Gem::Version
107
- hash: 3
111
+ hash: 25
108
112
  segments:
109
- - 0
110
- version: "0"
113
+ - 1
114
+ - 3
115
+ - 1
116
+ version: 1.3.1
111
117
  requirements: []
112
118
 
113
119
  rubyforge_project:
@@ -116,6 +122,7 @@ signing_key:
116
122
  specification_version: 3
117
123
  summary: Installs gems from railsthemes.com
118
124
  test_files:
125
+ - spec/fixtures/blank-assets.tar.gz
119
126
  - spec/fixtures/blank-assets/base/app/assets/images/bg/sprite.png
120
127
  - spec/fixtures/blank-assets/base/app/assets/images/image1.png
121
128
  - spec/fixtures/blank-assets/base/app/assets/javascripts/jquery.dataTables.js