Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Commit

Permalink
Made revert work.
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Jun 18, 2008
1 parent f500b65 commit d30ba95
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
24 changes: 22 additions & 2 deletions English.lproj/PassengerPref.xib
Expand Up @@ -8,7 +8,7 @@
<string key="IBDocument.HIToolboxVersion">352.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="230"/>
<integer value="6"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand Down Expand Up @@ -1366,6 +1366,26 @@ dHRwOi8vd3d3Lm1vZHJhaWxzLmNvbSBmb3IgaW5zdGFsbGF0aW9uIGluc3RydWN0aW9ucy4</string>
</object>
<int key="connectionID">375</int>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
<string key="label">target: selection</string>
<reference key="source" ref="615078570"/>
<reference key="destination" ref="467003467"/>
<object class="NSNibBindingConnector" key="connector">
<reference key="NSSource" ref="615078570"/>
<reference key="NSDestination" ref="467003467"/>
<string key="NSLabel">target: selection</string>
<string key="NSBinding">target</string>
<string key="NSKeyPath">selection</string>
<object class="NSDictionary" key="NSOptions">
<string key="NS.key.0">NSSelectorName</string>
<string key="NS.object.0">revert</string>
</object>
<int key="NSNibBindingConnectorVersion">2</int>
</object>
</object>
<int key="connectionID">377</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
Expand Down Expand Up @@ -2004,7 +2024,7 @@ dHRwOi8vd3d3Lm1vZHJhaWxzLmNvbSBmb3IgaW5zdGFsbGF0aW9uIGluc3RydWN0aW9ucy4</string>
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">375</int>
<int key="maxID">377</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand Down
17 changes: 17 additions & 0 deletions PassengerApplication.rb
Expand Up @@ -41,6 +41,8 @@ def init
@new_app = true
@dirty = @valid = false
@host, @path = '', ''

@original_values = { 'host' => @host, 'path' => @path, 'environment' => @environment, 'allow_mod_rewrite' => @allow_mod_rewrite }
self
end
end
Expand All @@ -54,6 +56,8 @@ def initWithFile(file)
@path = data.match(/DocumentRoot\s+"(.+)\/public"\n/)[1]
@environment = (data.match(/RailsEnv\s+(development|production)\n/)[1] == 'development' ? DEVELOPMENT : PRODUCTION)
@allow_mod_rewrite = (data.match(/RailsAllowModRewrite\s+(off|on)\n/)[1] == 'on')

@original_values = { 'host' => @host, 'path' => @path, 'environment' => @environment, 'allow_mod_rewrite' => @allow_mod_rewrite }
self
end
end
Expand All @@ -63,6 +67,8 @@ def initWithPath(path)
@dirty = true
@path = path
set_default_host_from_path(path)

@original_values = { 'host' => @host, 'path' => @path, 'environment' => @environment, 'allow_mod_rewrite' => @allow_mod_rewrite }
self
end
end
Expand All @@ -75,6 +81,10 @@ def dirty?
@dirty
end

def valid?
@valid
end

def apply(sender = nil)
p "apply"
@new_app ? start : restart
Expand Down Expand Up @@ -119,6 +129,13 @@ def to_hash
}
end

def revert(sender = nil)
@original_values.each do |key, value|
send "#{key}=", value
end
self.valid = self.dirty = false
end

private

def set_default_host_from_path(path)
Expand Down
27 changes: 25 additions & 2 deletions test/passenger_application_test.rb
@@ -1,6 +1,14 @@
require File.expand_path('../test_helper', __FILE__)
require 'PassengerApplication'

class Hash
def except(key)
copy = dup
copy.delete(key)
copy
end
end

describe "PassengerApplication, with a new application" do
tests PassengerApplication

Expand Down Expand Up @@ -95,8 +103,6 @@ def after_setup
end

it "should mark the application as dirty if a value has changed" do
passenger_app.stubs(:restart)

assigns(:dirty).should.be false
passenger_app.setValue_forKey('het-manfreds-blog.local', 'host')
assigns(:dirty).should.be true
Expand Down Expand Up @@ -169,4 +175,21 @@ def after_setup

PassengerApplication.startApplications [app1, app2].to_ns
end

it "should remember all the original values for the case that the user wants to revert" do
passenger_app.setValue_forKey('foo.local', 'host')
passenger_app.setValue_forKey('/some/path', 'path')
passenger_app.setValue_forKey('production', 'environment')
passenger_app.setValue_forKey(true, 'allow_mod_rewrite')

passenger_app.should.be.dirty
passenger_app.should.be.valid
passenger_app.to_hash.except('config_path').should == { 'host' => 'foo.local', 'path' => '/some/path', 'environment' => 'production', 'allow_mod_rewrite' => true }

passenger_app.revert

passenger_app.should.not.be.dirty
passenger_app.should.not.be.valid
passenger_app.to_hash.except('config_path').should == { 'host' => 'het-manfreds-blog.local', 'path' => '/Users/het-manfred/rails code/blog', 'environment' => 'development', 'allow_mod_rewrite' => false }
end
end

0 comments on commit d30ba95

Please sign in to comment.