Changeset 121
- Timestamp:
- 07/04/08 16:52:18 (2 months ago)
- 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 1 1 2 2 SVN 3 4 * Add Recipe versioning with version_fu. Provided by Mathias Meyer 3 5 4 6 * Update to Capistrano 2.4.0 trunk/app/controllers/deployments_controller.rb
r109 r121 65 65 respond_to do |format| 66 66 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 68 74 end 69 75 end trunk/app/controllers/recipes_controller.rb
r87 r121 16 16 # GET /recipes/1.xml 17 17 def show 18 @recipe = Recipe.find(params[:id])19 18 find_recipe_with_version 19 20 20 respond_to do |format| 21 21 format.html # show.rhtml … … 31 31 # GET /recipes/1;edit 32 32 def edit 33 @recipe = Recipe.find(params[:id])33 find_recipe_with_version 34 34 end 35 35 … … 37 37 # POST /recipes.xml 38 38 def create 39 @recipe = Recipe.new( params[:recipe])39 @recipe = Recipe.new((params[:recipe] || {}).merge(:user_id => current_user.id)) 40 40 41 41 respond_to do |format| … … 57 57 58 58 respond_to do |format| 59 if @recipe.update_attributes( params[:recipe])59 if @recipe.update_attributes((params[:recipe] || {}).merge(:user_id => current_user.id)) 60 60 flash[:notice] = 'Recipe was successfully updated.' 61 61 format.html { redirect_to recipe_url(@recipe) } … … 92 92 end 93 93 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 94 104 end trunk/app/controllers/sessions_controller.rb
r120 r121 2 2 class SessionsController < ApplicationController 3 3 4 skip_before_filter :login_required 4 skip_before_filter :login_required, :except => :version 5 5 6 6 # render new.rhtml trunk/app/helpers/recipes_helper.rb
r87 r121 3 3 Syntax::Convertors::HTML.for_syntax("ruby").convert(code) 4 4 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 5 15 end trunk/app/models/recipe.rb
r114 r121 5 5 validates_presence_of :name, :body 6 6 validates_length_of :name, :maximum => 250 7 8 attr_accessor :user_id 7 9 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 9 15 10 16 def validate trunk/app/views/recipes/show.html.erb
r87 r121 21 21 <%=h @recipe.stages.count %> 22 22 </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> 23 29 <% if current_user.admin? %> 24 30 <br /> trunk/config/environment.rb
r115 r121 77 77 # Include your application configuration below 78 78 79 WEBISTRANO_VERSION = '1. 3'79 WEBISTRANO_VERSION = '1.4' 80 80 81 81 ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(:log => '%Y-%m-%d %H:%M') trunk/config/routes.rb
r105 r121 26 26 stages.resources :stage_configurations 27 27 stages.resources :roles 28 stages.resources :deployments 28 stages.resources :deployments, :collection => {:latest => :get} 29 29 end 30 30 end trunk/db/schema.rb
r116 r121 10 10 # It's strongly recommended to check this file into your version control system. 11 11 12 ActiveRecord::Schema.define(:version => 200806 13212046) do12 ActiveRecord::Schema.define(:version => 20080621203016) do 13 13 14 14 create_table "configuration_parameters", :force => true do |t| … … 54 54 t.text "description" 55 55 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" 56 67 t.datetime "created_at" 57 68 t.datetime "updated_at" trunk/test/functional/deployments_controller_test.rb
r109 r121 118 118 assert_equal "deploy:default", assigns(:deployment).task 119 119 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 120 128 end trunk/test/functional/recipes_controller_test.rb
r87 r121 126 126 assert_select_rjs :replace_html, "preview" 127 127 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 128 137 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 129 154 end trunk/test/functional/sessions_controller_test.rb
r105 r121 76 76 77 77 def test_should_render_the_version_xml 78 login_as :quentin 78 79 get :version 79 80 assert_select "application" do |element|
