Skip to content
Browse files

Fix a couple of issues with installing.

  • Loading branch information...
1 parent 6464cff commit 54788605db9c03e031951e600b9a1b31f6e0b798 @panozzaj panozzaj committed
Showing with 27 additions and 9 deletions.
  1. +22 −4 lib/railsthemes/installer.rb
  2. +5 −5 spec/lib/railsthemes/installer_spec.rb
View
26 lib/railsthemes/installer.rb
@@ -11,7 +11,10 @@ module Railsthemes
class Installer
def initialize logger = nil
@logger = logger
- @server = File.exist?('railsthemes_server') ? File.read('railsthemes_server') : 'https://railsthemes.com'
+ @server = 'https://railsthemes.com'
+ if File.exist?('railsthemes_server')
+ @server = File.read('railsthemes_server').gsub("\n", '')
+ end
@logger ||= Logger.new(STDOUT)
# just print out basic information, not all of the extra logger stuff
@logger.formatter = proc do |severity, datetime, progname, msg|
@@ -91,13 +94,28 @@ def download_from_code code
def get_download_url server_request_url
response = nil
begin
- response = Net::HTTP.get_response URI.parse(server_request_url)
+ url = URI.parse(server_request_url)
+ http = Net::HTTP.new url.host, url.port
+ http = Net::HTTP.new url.host, url.port
+ if server_request_url =~ /^https/
+ http.use_ssl = true
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
+ end
+ path = server_request_url.gsub(%r{https?://[^/]+}, '')
+ response = http.request_get(path)
rescue Exception => e
#@logger.info e.message
#@logger.info e.backtrace
end
- response.body if response && response.code.to_s == '200'
+ if response
+ if response.code.to_s == '200'
+ return response.body
+ else
+ @logger.info "Got a #{response.code} error while trying to download."
+ return nil
+ end
+ end
end
def gems_used
@@ -144,7 +162,7 @@ def archive? filepath
end
def untar_string filepath, newdirpath
- "tar -zxf #{filepath}"
+ "tar -zxf #{filepath} -C #{newdirpath}"
end
View
10 spec/lib/railsthemes/installer_spec.rb
@@ -75,7 +75,7 @@ def using_gems *gems
describe :untar_string do
it 'should return correct value for *.tar.gz file' do
result = @installer.untar_string 'file.tar.gz', 'newdirpath'
- result.should == 'tar -zxf file.tar.gz'
+ result.should == 'tar -zxf file.tar.gz -C newdirpath'
end
end
@@ -183,22 +183,22 @@ def verify_end_to_end_operation
end
describe '#get_primary_configuration' do
- it 'should give haml+scss when haml and sass are in the Gemfile' do
+ it 'should give haml,scss when haml and sass are in the Gemfile' do
gemfile = using_gems 'haml', 'sass'
@installer.get_primary_configuration(gemfile).should == 'haml,scss'
end
- it 'should give haml+css when sass is not in the Gemfile' do
+ it 'should give haml,css when sass is not in the Gemfile but haml is' do
gemfile = using_gems 'haml'
@installer.get_primary_configuration(gemfile).should == 'haml,css'
end
- it 'should give erb, scss when haml is not in the gemfile' do
+ it 'should give erb,scss when haml is not in the gemfile but sass is' do
gemfile = using_gems 'sass'
@installer.get_primary_configuration(gemfile).should == 'erb,scss'
end
- it 'should give erb, scss when haml is not in the gemfile' do
+ it 'should give erb,css when haml and sass are not in the gemfile' do
gemfile = using_gems
@installer.get_primary_configuration(gemfile).should == 'erb,css'
end

0 comments on commit 5478860

Please sign in to comment.
Something went wrong with that request. Please try again.