Peritor Open Source
  • Home
  • Webistrano
  • Login
  • Settings
  • Register
  • Help/Guide
  • About Trac
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Navigation

  • ← Previous Changeset
  • Next Changeset →

Changeset 121

Show
Ignore:
Timestamp:
07/04/08 16:52:18 (2 months ago)
Author:
jweiss
Message:

Add Recipe versioning with version_fu. Provided by Mathias Meyer

Files:
  • trunk/CHANGELOG.txt (modified) (1 diff)
  • trunk/app/controllers/deployments_controller.rb (modified) (1 diff)
  • trunk/app/controllers/recipes_controller.rb (modified) (5 diffs)
  • trunk/app/controllers/sessions_controller.rb (modified) (1 diff)
  • trunk/app/helpers/recipes_helper.rb (modified) (1 diff)
  • trunk/app/models/recipe.rb (modified) (1 diff)
  • trunk/app/views/recipes/show.html.erb (modified) (1 diff)
  • trunk/config/environment.rb (modified) (1 diff)
  • trunk/config/routes.rb (modified) (1 diff)
  • trunk/db/migrate/20080621203016_create_recipe_versions.rb (added)
  • trunk/db/migrate/20080621205235_add_recipe_version.rb (added)
  • trunk/db/schema.rb (modified) (2 diffs)
  • trunk/test/functional/deployments_controller_test.rb (modified) (1 diff)
  • trunk/test/functional/recipes_controller_test.rb (modified) (1 diff)
  • trunk/test/functional/sessions_controller_test.rb (modified) (1 diff)

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/CHANGELOG.txt

    r119 r121  
    11 
    22SVN 
     3 
     4* Add Recipe versioning with version_fu. Provided by Mathias Meyer 
    35 
    46* Update to Capistrano 2.4.0 
  • trunk/app/controllers/deployments_controller.rb

    r109 r121  
    6565    respond_to do |format| 
    6666      format.html { render :action => "show"} 
    67       format.xml  { render :xml => @deployment.to_xml } 
     67      format.xml do 
     68        if @deployment 
     69          render :xml => @deployment.to_xml 
     70        else 
     71          render :status => 404, :nothing => true 
     72        end 
     73      end 
    6874    end 
    6975  end 
  • trunk/app/controllers/recipes_controller.rb

    r87 r121  
    1616  # GET /recipes/1.xml 
    1717  def show 
    18     @recipe = Recipe.find(params[:id]) 
    19  
     18    find_recipe_with_version 
     19     
    2020    respond_to do |format| 
    2121      format.html # show.rhtml 
    …… 
    3131  # GET /recipes/1;edit 
    3232  def edit 
    33     @recipe = Recipe.find(params[:id]) 
     33    find_recipe_with_version 
    3434  end 
    3535 
    …… 
    3737  # POST /recipes.xml 
    3838  def create 
    39     @recipe = Recipe.new(params[:recipe]) 
     39    @recipe = Recipe.new((params[:recipe] || {}).merge(:user_id => current_user.id)) 
    4040 
    4141    respond_to do |format| 
    …… 
    5757 
    5858    respond_to do |format| 
    59       if @recipe.update_attributes(params[:recipe]) 
     59      if @recipe.update_attributes((params[:recipe] || {}).merge(:user_id => current_user.id)) 
    6060        flash[:notice] = 'Recipe was successfully updated.' 
    6161        format.html { redirect_to recipe_url(@recipe) } 
    …… 
    9292    end 
    9393  end 
     94   
     95  private 
     96  def find_recipe_with_version 
     97    @recipe = Recipe.find(params[:id]) 
     98     
     99    unless params[:version].blank? 
     100      recipe_version = @recipe.find_version(params[:version]) 
     101      @recipe.attributes = @recipe.find_version(params[:version]).attributes if recipe_version 
     102    end 
     103  end 
    94104end 
  • trunk/app/controllers/sessions_controller.rb

    r120 r121  
    22class SessionsController < ApplicationController 
    33   
    4   skip_before_filter :login_required 
     4  skip_before_filter :login_required, :except => :version 
    55   
    66  # render new.rhtml 
  • trunk/app/helpers/recipes_helper.rb

    r87 r121  
    33    Syntax::Convertors::HTML.for_syntax("ruby").convert(code) 
    44  end 
     5   
     6  def all_recipe_versions 
     7    versions = @recipe.versions.collect{|v| [v.version.to_s, v.version.to_s]}.reverse 
     8    versions[0] = ["Latest", ""] 
     9    versions 
     10  end 
     11   
     12  def not_latest_version 
     13    !params[:version].blank? && params[:version].to_i < @recipe.versions.latest.version 
     14  end 
    515end 
  • trunk/app/models/recipe.rb

    r114 r121  
    55  validates_presence_of :name, :body 
    66  validates_length_of :name, :maximum => 250 
     7 
     8  attr_accessor :user_id 
    79   
    8   attr_accessible :name, :body, :description 
     10  attr_accessible :name, :body, :description, :user_id 
     11   
     12  version_fu do 
     13    belongs_to :user, :class_name => "::User" 
     14  end 
    915   
    1016  def validate 
  • trunk/app/views/recipes/show.html.erb

    r87 r121  
    2121                  <%=h @recipe.stages.count %> 
    2222                </p> 
     23                <p> 
     24                  <b>Versions:</b> 
     25                  <%= select_tag "version", options_for_select(all_recipe_versions, params[:version]), :id => "recipe_version" %> 
     26                  <%= link_to_function "Show", "location.href='#{recipe_path(@recipe)}?version=' + $F('recipe_version')", :class => "arrow_link" %> 
     27                  <%= link_to "Rollback", edit_recipe_path(@recipe, :version => params[:version]), :class => "arrow_link" if not_latest_version and current_user.admin? %> 
     28    </p> 
    2329                <% if current_user.admin? %> 
    2430                <br /> 
  • trunk/config/environment.rb

    r115 r121  
    7777# Include your application configuration below 
    7878 
    79 WEBISTRANO_VERSION = '1.3' 
     79WEBISTRANO_VERSION = '1.4' 
    8080 
    8181ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(:log => '%Y-%m-%d %H:%M') 
  • trunk/config/routes.rb

    r105 r121  
    2626      stages.resources :stage_configurations 
    2727      stages.resources :roles 
    28       stages.resources :deployments 
     28      stages.resources :deployments, :collection => {:latest => :get} 
    2929    end 
    3030  end 
  • trunk/db/schema.rb

    r116 r121  
    1010# It's strongly recommended to check this file into your version control system. 
    1111 
    12 ActiveRecord::Schema.define(:version => 20080613212046) do 
     12ActiveRecord::Schema.define(:version => 20080621203016) do 
    1313 
    1414  create_table "configuration_parameters", :force => true do |t| 
    …… 
    5454    t.text     "description" 
    5555    t.string   "template" 
     56    t.datetime "created_at" 
     57    t.datetime "updated_at" 
     58  end 
     59 
     60  create_table "recipe_versions", :force => true do |t| 
     61    t.integer  "recipe_id",   :limit => 11 
     62    t.integer  "version",     :limit => 11 
     63    t.integer  "user_id",     :limit => 11 
     64    t.string   "name" 
     65    t.text     "body" 
     66    t.text     "description" 
    5667    t.datetime "created_at" 
    5768    t.datetime "updated_at" 
  • trunk/test/functional/deployments_controller_test.rb

    r109 r121  
    118118    assert_equal "deploy:default", assigns(:deployment).task 
    119119  end 
     120   
     121  def test_latest_with_no_deployment 
     122    Deployment.delete_all 
     123    host_down = create_new_host 
     124    down_role = create_new_role(:stage => @stage, :name => 'foo', :host => host_down) 
     125    get :latest, :project_id => @project.id, :stage_id => @stage.id, :format => "xml" 
     126    assert_response 404 
     127  end 
    120128end 
  • trunk/test/functional/recipes_controller_test.rb

    r87 r121  
    126126    assert_select_rjs :replace_html, "preview" 
    127127  end 
     128 
     129  def test_show_with_version_should_show_the_specified_version 
     130    @user = admin_login 
     131     
     132    @recipe.update_attributes!(:body => "do_something :else") 
     133    @recipe.update_attributes!(:body => "do_something :other_than => :else") 
     134    get :show, :id => @recipe.id, :version => 2 
     135    assert_equal "do_something :else", assigns["recipe"].body 
     136  end 
    128137   
     138  def test_edit_with_version_should_load_the_specified_version 
     139    @user = admin_login 
     140    @recipe.update_attributes!(:body => "do_something :else") 
     141    @recipe.update_attributes!(:body => "do_something :other_than => :else") 
     142    get :edit, :id => @recipe.id, :version => 2 
     143    assert_equal "do_something :else", assigns["recipe"].body 
     144  end 
     145   
     146  def test_show_should_ignore_illegal_versions 
     147    @user = admin_login 
     148     
     149    @recipe.update_attributes!(:body => "do_something :else") 
     150    @recipe.update_attributes!(:body => "do_something :other_than => :else") 
     151    get :show, :id => @recipe.id, :version => @recipe.version + 1 
     152    assert_equal "do_something :other_than => :else", assigns["recipe"].body 
     153  end 
    129154end 
  • trunk/test/functional/sessions_controller_test.rb

    r105 r121  
    7676 
    7777  def test_should_render_the_version_xml 
     78    login_as :quentin 
    7879    get :version 
    7980    assert_select "application" do |element| 
Download in other formats: Unified Diff  Zip Archive  


© 2007 - 2008 Peritor Wissensmanagement GmbH | Impressum | Legal

Powered by Trac 0.10.4 | Edgewall Software