<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>features/revert.feature</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -35,3 +35,6 @@
       %span= status_diff(version)
   %span.clear
   = updated_stamp(version.instance)
+  - form_tag(edit_admin_page_path(:id =&gt; version.versionable_id), :method =&gt; :get) do
+    = hidden_field_tag(:version, version.number)
+    = submit_tag(&quot;Revert to Version #{version.number}&quot;, :name =&gt; nil)</diff>
      <filename>app/views/admin/pages/_diff.html.haml</filename>
    </modified>
    <modified>
      <diff>@@ -28,6 +28,13 @@ Given /^I have a (.*) page with a draft$/ do |status|
   @page.reload
 end
 
+Given /^I have a page with more than one version$/ do
+  Given &quot;I have a published page with a draft&quot;
+  @page.status = Status[:published]
+  @page.title = @page.title += &quot; Version 2&quot;
+  @page.save
+end
+
 When /^I edit the page$/ do
   visit admin_pages_path
   click_link @page.title
@@ -39,11 +46,27 @@ When /^I save it as (?:a )?(draft|published)$/ do |status|
   click_button &quot;Save&quot;
 end
 
+When /^I click the revert button$/ do
+  click_button &quot;Revert to Version 1&quot;
+end
+
+When /^I edit a previous version$/ do
+  visit edit_admin_page_path(:id =&gt; @page.id, :version =&gt; 1)
+end
+
+Then /^I should be taken to the edit page$/ do
+  request.params.should == {&quot;format&quot;=&gt;&quot;html&quot;, &quot;action&quot;=&gt;&quot;edit&quot;, &quot;id&quot;=&gt;&quot;520095529&quot;, &quot;version&quot;=&gt;&quot;1&quot;, &quot;controller&quot;=&gt;&quot;admin/pages&quot;}
+  response.should have_selector('h1', :content =&gt; &quot;Edit Page&quot;)
+end
+
+Then /^the older content should be loaded$/ do
+  field_labeled(&quot;Page Title&quot;).value.should_not == @page.current.title
+end
+
 Then /^the content I am editing should be the draft$/ do
   field_labeled(&quot;Page Title&quot;).value.should =~ /.+ Draft/
 end
 
-
 Then /^the page should be saved$/ do
   @page.current.title.should == &quot;Edited&quot;
 end
@@ -56,10 +79,10 @@ Then /^change the live version$/ do
   @page.reload.title.should == &quot;Edited&quot;
 end
 
-Given /^I have a page with more than one version$/ do
-  Given &quot;I have a published page with a draft&quot;
-  @page.status = Status[:published]
-  @page.save
+When /^I view a previous version$/ do
+  visit admin_versions_path
+  click_link &quot;Version 1&quot;
+  @current_version = 1
 end
 
 When /^I view a version$/ do</diff>
      <filename>features/step_definitions/versioning_steps.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 module Chronicle::PageExtensions
   def self.included(base)
     base.class_eval do
-      simply_versioned :exclude =&gt; :parent_id
+      simply_versioned :exclude =&gt; [:parent_id, :lock_version]
       alias_method_chain :update, :parts_draft_versioning
       alias_method_chain :update_without_callbacks, :draft_versioning
       alias_method_chain :part, :versioned_association</diff>
      <filename>lib/chronicle/page_extensions.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,15 +1,23 @@
 module Chronicle::ResourceControllerExtensions
   def self.included(base)
     base.class_eval do
-      alias_method_chain :load_model, :current_version
+      alias_method_chain :load_model, :version
     end
   end
   
-  def load_model_with_current_version
-    model = load_model_without_current_version
+  def load_model_with_version
+    model = load_model_without_version
     unless %w(remove destroy).include?(action_name) ||
       (action_name == &quot;update&quot; &amp;&amp; params[&quot;page&quot;] &amp;&amp; params[&quot;page&quot;][&quot;status_id&quot;].to_i &gt;= Status[:published].id)
-        self.model = model.respond_to?(:current) ? model.current : model
+        self.model = case
+        when params[:version] &amp;&amp; version = model.versions.get_version(params[:version].to_i)
+          flash[:notice] = &quot;Loaded version #{version.number}. Click save to revert to this content.&quot;
+          version.instance
+        when model.respond_to?(:current)
+          model.current
+        else
+          model
+        end
     end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/chronicle/resource_controller_extensions.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,15 +10,26 @@ describe Admin::PagesController do
   describe &quot;editing a page&quot; do
     integrate_views
     
+    before(:each) do
+      @page = pages(:first)
+      @page.save # version 1
+      @page.title = &quot;Draft of First&quot;
+      @page.status = Status[:draft]
+      @page.save # version 2
+    end
+    
     it &quot;should load the current version for editing&quot; do
-      page = pages(:first)
-      page.title = &quot;Draft of First&quot;
-      page.status = Status[:draft]
-      page.save
+      get :edit, :id =&gt; @page.id
       
-      get :edit, :id =&gt; page.id
+      assigns[:page].title.should == @page.current.title
+      assigns[:page].lock_version.should == @page.current.lock_version
+    end
+    
+    it &quot;should load a specified version for editing&quot; do
+      get :edit, :id =&gt; @page.id, :version =&gt; 1
       
-      assigns[:page].title.should == page.current.title
+      assigns[:page].title.should == @page.versions.first_version.instance.title
+      assigns[:page].lock_version.should == @page.current.lock_version
     end
     
     it &quot;should have the version diff popup&quot; do
@@ -68,9 +79,6 @@ describe Admin::PagesController do
     before :each do
       @page = pages(:first)
       @page.update_attributes(:title =&gt; &quot;current&quot;, :status_id =&gt; Status[:draft].id)
-      # suppose the live page's lock_version gets ahead for some reason
-      @page.send(:update_with_lock, [@page.class.locking_column])
-      @page.reload.lock_version.should &gt; @page.current.lock_version
     end
     
     it &quot;should load the live version of the page&quot; do
@@ -84,7 +92,6 @@ describe Admin::PagesController do
     end
   end
   
-  
   def params_for_page(page)
     {&quot;slug&quot;=&gt;page.slug, &quot;class_name&quot;=&gt;page.class_name, &quot;title&quot;=&gt;page.title, &quot;breadcrumb&quot;=&gt;page.breadcrumb, &quot;lock_version&quot;=&gt;page.lock_version, &quot;parts_attributes&quot;=&gt;[{&quot;name&quot;=&gt;&quot;body&quot;, &quot;filter_id&quot;=&gt;&quot;&quot;, &quot;content&quot;=&gt;&quot;test&quot;}], &quot;status_id&quot;=&gt;page.status_id, &quot;layout_id&quot;=&gt;page.layout_id, &quot;parent_id&quot;=&gt;page.parent_id}
   end</diff>
      <filename>spec/controllers/admin/pages_controller_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>340f712891bd12ae90ca5d8719c1137ab54a6b87</id>
    </parent>
  </parents>
  <author>
    <name>Jason Garber</name>
    <email>jg@jasongarber.com</email>
  </author>
  <url>http://github.com/jgarber/radiant-chronicle-extension/commit/ae1c43550622c7dbd14084db0ffba05b0605d390</url>
  <id>ae1c43550622c7dbd14084db0ffba05b0605d390</id>
  <committed-date>2009-09-07T12:46:13-07:00</committed-date>
  <authored-date>2009-09-07T12:46:13-07:00</authored-date>
  <message>Add rollback for pages.</message>
  <tree>faa5225331b33985c5074365c36ce50513293a0e</tree>
  <committer>
    <name>Jason Garber</name>
    <email>jg@jasongarber.com</email>
  </committer>
</commit>
