Changeset 34

Show
Ignore:
Timestamp:
10/27/07 14:59:54 (13 months ago)
Author:
jweiss
Message:

A stage can list all available tasks, based on #11

Location:
trunk
Files:
1 added
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/app/controllers/stages_controller.rb

    r1 r34  
    2222  def edit 
    2323    @stage = current_project.stages.find(params[:id]) 
     24  end 
     25   
     26  # GET /projects/1/stages/1/tasks 
     27  # GET /projects/1/stages/1/tasks.xml 
     28  def tasks 
     29    @stage = current_project.stages.find(params[:id]) 
     30    @tasks = @stage.list_tasks 
     31     
     32    respond_to do |format| 
     33      format.html # tasks.rhtml 
     34      format.xml  { render :xml => @tasks.to_xml } 
     35    end 
    2436  end 
    2537 
  • trunk/app/models/stage.rb

    r1 r34  
    117117  end 
    118118   
     119  # returns a lists of all availabe tasks for this stage 
     120  def list_tasks 
     121    d = Deployment.new 
     122    d.stage = self 
     123    deployer = Webistrano::Deployer.new(d) 
     124    deployer.list_tasks.collect { |t| [t.fully_qualified_name, t.description] } 
     125  end 
     126   
    119127  protected 
    120128  def add_deployment_problem(key, desc) 
  • trunk/app/views/stages/show.rhtml

    r26 r34  
    88   <p><%= link_to 'Rollback to previous', new_project_stage_deployment_path(current_project, @stage) + '?task=deploy:rollback', :class => 'arrow_link' %></p> 
    99   <p><%= link_to 'Setup', new_project_stage_deployment_path(current_project, @stage) + '?task=deploy:setup', :class => 'arrow_link' %></p> 
     10   <p><%= link_to 'List all available tasks', tasks_project_stage_path(current_project, @stage), :class => 'arrow_link' %></p> 
    1011</div> 
    1112 
  • trunk/config/routes.rb

    r9 r34  
    2323    projects.resources :project_configurations 
    2424     
    25     projects.resources :stages, :member => {:capfile => :get, :recipes => :any} do |stages| 
     25    projects.resources :stages, :member => {:capfile => :get, :recipes => :any, :tasks => :get} do |stages| 
    2626      stages.resources :stage_configurations 
    2727      stages.resources :roles 
  • trunk/lib/webistrano/deployer.rb

    r31 r34  
    2222     
    2323      @deployment = deployment 
    24       @logger = Webistrano::Logger.new(deployment) 
    25       @logger.level = Webistrano::Logger::TRACE 
    26       validate 
     24       
     25      if(@deployment.task && !@deployment.new_record?) 
     26        # a read deployment 
     27        @logger = Webistrano::Logger.new(deployment) 
     28        @logger.level = Webistrano::Logger::TRACE 
     29        validate 
     30      else 
     31        # a fake deployment in order to access tasks 
     32        @logger = Capistrano::Logger.new 
     33      end 
    2734    end 
    2835   
     
    5663        set_webistrano_logger(config) 
    5764         
    58         set_pre_vars(config) 
    59         load_recipes(config) 
    60  
    61         set_stage_configuration(config) 
    62         set_stage_roles(config) 
    63         set_project_and_stage_names(config) 
    64         load_project_template_tasks(config) 
    65         load_stage_custom_recipes(config) 
     65        set_up_config(config) 
    6666         
    6767        exchange_real_revision(config) unless (config.fetch(:scm).to_s == 'git') # git cannot do a local query by default 
     
    8686      config = Webistrano::Configuration.new 
    8787      config.logger = logger 
     88      config 
     89    end 
     90     
     91    def set_up_config(config) 
     92      set_pre_vars(config) 
     93      load_recipes(config) 
     94 
     95      set_stage_configuration(config) 
     96      set_stage_roles(config) 
     97      set_project_and_stage_names(config) 
     98      load_project_template_tasks(config) 
     99      load_stage_custom_recipes(config) 
    88100      config 
    89101    end 
     
    213225      end 
    214226    end 
     227     
     228    # returns a list of all tasks defined for this deployer 
     229    def list_tasks 
     230      config = instantiate_configuration 
     231      config.load 'deploy' 
     232       
     233      set_up_config(config) 
     234       
     235      config.task_list(:all) 
     236    end 
    215237   
    216238  end 
  • trunk/test/functional/stages_controller_test.rb

    r1 r34  
    1313    @response   = ActionController::TestResponse.new 
    1414     
    15     @project = create_new_project 
     15    @project = create_new_project(:template => 'mongrel_rails') 
    1616    @stage = create_new_stage(:project => @project) 
    1717    @user = login 
     
    101101    assert_match "foobar here", @response.body 
    102102  end 
     103   
     104  def test_should_show_stage_tasks 
     105    get :tasks, :id => @stage.id, :project_id => @project.id 
     106    assert_response :success 
     107    assert_match /webistrano:mongrel:start/, @response.body 
     108  end 
     109   
    103110end 
  • trunk/test/unit/webistrano_deployer_test.rb

    r31 r34  
    674674  end 
    675675   
     676  def test_list_tasks 
     677    d = Deployment.new 
     678    d.stage = @stage 
     679    deployer = Webistrano::Deployer.new(d) 
     680     
     681    assert_not_nil deployer.list_tasks 
     682    assert_equal 23, deployer.list_tasks.size 
     683    assert_equal 23, @stage.list_tasks.size 
     684    deployer.list_tasks.each{|t| assert t.is_a?(Capistrano::TaskDefinition) } 
     685     
     686    # add a stage recipe 
     687    recipe_body = <<-EOS 
     688      namespace :foo do 
     689        task :bar do 
     690          run 'foobar' 
     691        end 
     692      end 
     693    EOS 
     694    recipe = create_new_recipe(:name => 'A new recipe', :body => recipe_body) 
     695    @stage.recipes << recipe 
     696         
     697    assert_equal 24, deployer.list_tasks.size 
     698    assert_equal 24, @stage.list_tasks.size 
     699    assert_equal 1, deployer.list_tasks.delete_if{|t| t.fully_qualified_name != 'foo:bar'}.size 
     700    assert_equal 1, @stage.list_tasks.delete_if{|t| t[0] != 'foo:bar'}.size 
     701  end 
     702   
    676703   
    677704  protected