Skip to content

Commit

Permalink
Merge branch 'phyllisstein-faster-restart'
Browse files Browse the repository at this point in the history
  • Loading branch information
mordaroso committed Aug 11, 2014
2 parents 7e81a16 + 95d8c81 commit 27ce3fa
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,6 +2,7 @@ pkg/*
*.gem
.bundle
Gemfile.lock
.ruby-version
.rvmrc

## MAC OS
Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.rdoc
@@ -1,3 +1,11 @@
== 0.6.0, (Aug 1, 2014)

Features:
- Faster restart for newer Passenger versions with passenger-config restart-app $PWD [by phyllisstein]

Fixes:
- Corrects small typo in cli_stop. [by phyllisstein]

== 0.5.0, (May 31, 2012)

Changes:
Expand Down Expand Up @@ -43,4 +51,4 @@ Changes:

Features:
- Add touching
- Activate Passenger standalone by default
- Activate Passenger standalone by default
6 changes: 3 additions & 3 deletions Gemfile
Expand Up @@ -6,10 +6,10 @@ gemspec
gem 'rake'
require 'rbconfig'

if Config::CONFIG['target_os'] =~ /darwin/i
if RbConfig::CONFIG['target_os'] =~ /darwin/i
gem 'rb-fsevent', '>= 0.3.2'
gem 'growl', '~> 1.0.3'
elsif Config::CONFIG['target_os'] =~ /linux/i
elsif RbConfig::CONFIG['target_os'] =~ /linux/i
gem 'rb-inotify', '>= 0.5.1'
gem 'libnotify', '~> 0.1.3'
end
end
5 changes: 3 additions & 2 deletions guard-passenger.gemspec
Expand Up @@ -17,8 +17,9 @@ Gem::Specification.new do |s|

s.add_dependency 'guard', '>= 1.1.0.beta '

s.add_development_dependency 'bundler', '~> 1.1.3'
s.add_development_dependency 'rspec', '~> 2.10.0'
s.add_development_dependency 'bundler', '~> 1.1'
s.add_development_dependency 'rspec', '~> 2.11.0'
s.add_development_dependency 'rspec-mocks', '~> 2.11.0'
s.add_development_dependency 'guard-rspec', '~> 0.7.3'
s.add_development_dependency 'guard-bundler', '~> 0.1.3'

Expand Down
19 changes: 9 additions & 10 deletions lib/guard/passenger/runner.rb
@@ -1,10 +1,16 @@
module Guard
class Passenger
module Runner
class << self
PASSENGER_VERSION = Gem.latest_spec_for('passenger').version

class << self
def restart_passenger
succeed = system("touch tmp/restart.txt")
if PASSENGER_VERSION >= Gem::Version.new('4.0.31')
succeed = system("passenger-config restart-app #{ Dir.getwd }")
else
succeed = system("touch tmp/restart.txt")
end

if succeed
UI.info "Passenger successfully restarted."
else
Expand All @@ -27,7 +33,6 @@ def start_passenger(cli, sudo = '')
else
UI.error "Passenger standalone is not installed. You need at least Passenger version >= 3.0.0.\nPlease run 'gem install passenger' or add it to your Gemfile."
throw :task_has_failed
false
end
end

Expand All @@ -43,14 +48,8 @@ def stop_passenger(cli, sudo = '')
end

def passenger_standalone_installed?
begin
gem "passenger", ">=3.0.0"
rescue Gem::LoadError
return false
end
true
PASSENGER_VERSION >= Gem::Version.new('3')
end

end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/guard/passenger/version.rb
@@ -1,5 +1,5 @@
module Guard
module PassengerVersion
VERSION = '0.5.0'
VERSION = '0.6.0'
end
end
end
83 changes: 66 additions & 17 deletions spec/guard/passenger/runner_spec.rb
Expand Up @@ -57,13 +57,13 @@
end

describe '#passenger_standalone_installed?' do
it 'should not have passenger >= 3 installed' do
subject.should_receive(:gem).with("passenger", ">=3.0.0").and_raise(Gem::LoadError)
it 'should not have passenger < 3 installed' do
stub_const 'Guard::Passenger::Runner::PASSENGER_VERSION', Gem::Version.new('1')
subject.passenger_standalone_installed?.should be_false
end

it 'should have passenger >= 3 installed' do
subject.should_receive(:gem).with("passenger", ">=3.0.0").and_return(true)
stub_const 'Guard::Passenger::Runner::PASSENGER_VERSION', Gem::Version.new('4')
subject.passenger_standalone_installed?.should be_true
end
end
Expand Down Expand Up @@ -100,15 +100,43 @@
end

describe '#restart_passenger' do
it 'should call "touch tmp/restart.txt"' do
it 'should call "touch tmp/restart.txt" for Passenger < 4.0.31' do
stub_const 'Guard::Passenger::Runner::PASSENGER_VERSION', Gem::Version.new('3')

subject.should_receive(:system).with('touch tmp/restart.txt')
expect {
quietly { subject.restart_passenger }
}.to throw_symbol(:task_has_failed)
end

it 'should call "passenger-config restart-app" for Passenger >= 4.0.31' do
stub_const 'Guard::Passenger::Runner::PASSENGER_VERSION', Gem::Version.new('5')

subject.should_receive(:system).with("passenger-config restart-app #{ Dir.getwd }")
expect {
quietly { subject.restart_passenger }
}.to throw_symbol(:task_has_failed)
end

context "restart succeed" do
before(:each) { subject.should_receive(:system).with('touch tmp/restart.txt').and_return(true) }
context 'for Passenger < 4.0.31' do
before(:each) { stub_const 'Guard::Passenger::Runner::PASSENGER_VERSION', Gem::Version.new('3') }
before(:each) { subject.should_receive(:system).with('touch tmp/restart.txt').and_return(true) }

it 'should display a message' do
Guard::UI.should_receive(:info).with("Passenger successfully restarted.")
subject.restart_passenger
end

it 'should return true if restart succeeds' do
subject.restart_passenger.should be_true
end
end
end

context 'for Passenger >= 4.0.31' do
before(:each) { stub_const 'Guard::Passenger::Runner::PASSENGER_VERSION', Gem::Version.new('5') }
before(:each) { subject.should_receive(:system).with("passenger-config restart-app #{ Dir.getwd }").and_return(true) }

it 'should display a message' do
Guard::UI.should_receive(:info).with("Passenger successfully restarted.")
Expand All @@ -120,20 +148,41 @@
end
end

context "restart succeed" do
before(:each) { subject.should_receive(:system).with('touch tmp/restart.txt').and_return(false) }

it 'should display a message' do
Guard::UI.should_receive(:error).with("Passenger failed to restart!")
expect {
quietly { subject.restart_passenger }
}.to throw_symbol(:task_has_failed)
context "restart failed" do
context 'for Passenger < 4.0.31' do
before(:each) { stub_const 'Guard::Passenger::Runner::PASSENGER_VERSION', Gem::Version.new('3') }
before(:each) { subject.should_receive(:system).with('touch tmp/restart.txt').and_return(false) }

it 'should display a message' do
Guard::UI.should_receive(:error).with("Passenger failed to restart!")
expect {
quietly { subject.restart_passenger }
}.to throw_symbol(:task_has_failed)
end

it 'should return false if restart fails' do
expect {
quietly { subject.restart_passenger.should be_false }
}.to throw_symbol(:task_has_failed)
end
end

it 'should return false if restart fails' do
expect {
quietly { subject.restart_passenger.should be_false }
}.to throw_symbol(:task_has_failed)
context 'for Passenger >= 4.0.31' do
before(:each) { stub_const 'Guard::Passenger::Runner::PASSENGER_VERSION', Gem::Version.new('5') }
before(:each) { subject.should_receive(:system).with("passenger-config restart-app #{ Dir.getwd }").and_return(false) }

it 'should display a message' do
Guard::UI.should_receive(:error).with("Passenger failed to restart!")
expect {
quietly { subject.restart_passenger }
}.to throw_symbol(:task_has_failed)
end

it 'should return false if restart fails' do
expect {
quietly { subject.restart_passenger.should be_false }
}.to throw_symbol(:task_has_failed)
end
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
@@ -1,6 +1,7 @@
require 'rubygems'
require 'guard/passenger'
require 'rspec'
require 'rspec/mocks'

ENV["GUARD_ENV"] = 'test'

Expand All @@ -24,4 +25,4 @@ def quietly(&block)
ensure
$stdout.reopen(orig_stdout)
end
end
end

0 comments on commit 27ce3fa

Please sign in to comment.