Skip to content

Commit

Permalink
some ProjectInstance#execute tests & fix for very stupid bug
Browse files Browse the repository at this point in the history
also make commits on project info page links
  • Loading branch information
comboy committed Feb 19, 2012
1 parent 36ffd6e commit 10e8f9b
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 6 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -28,4 +28,5 @@ gem 'httparty'

group :development, :test do
gem 'factory_girl_rails'
gem 'ZenTest'
end
8 changes: 8 additions & 0 deletions Gemfile.lock
@@ -1,6 +1,7 @@
GEM
remote: http://rubygems.org/
specs:
ZenTest (4.6.2)
abstract (1.0.0)
actionmailer (3.0.11)
actionpack (= 3.0.11)
Expand Down Expand Up @@ -45,12 +46,15 @@ GEM
crack (= 0.1.8)
i18n (0.5.0)
json (1.6.5)
juggernaut (2.1.1)
redis
mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.17.2)
open4 (1.3.0)
pg (0.10.1)
polyglot (0.3.3)
rack (1.2.5)
Expand All @@ -75,6 +79,7 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
redis (2.2.2)
sqlite3-ruby (1.3.2)
thor (0.14.6)
treetop (1.4.10)
Expand All @@ -87,11 +92,14 @@ PLATFORMS
ruby

DEPENDENCIES
ZenTest
factory_girl_rails
git
gravtastic
haml
httparty
juggernaut
open4
pg
rails (= 3.0.11)
sqlite3-ruby
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/commits_controller.rb
@@ -1,12 +1,12 @@
class CommitsController < ApplicationController

within_project

def index
must_be_in_project
@commits = @project.commits.order('committed_at DESC').paginate(:page => params[:page], :per_page => 10)
end

def show
@commit = Commit.find params[:id]
@project = @commit.project
end
end
2 changes: 1 addition & 1 deletion app/views/projects/show.html.haml
Expand Up @@ -20,7 +20,7 @@
%td{:style => 'width: 20px;'}
= image_tag commit.author.gravatar_url :size => 15
%td
= commit.short_description
= link_to commit.short_description, commit_path(commit)
%td
= commit.build_state
- if i == 0
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -45,6 +45,7 @@
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
resources :commits

# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
Expand Down
1 change: 1 addition & 0 deletions db/schema.rb
@@ -1,3 +1,4 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
Expand Down
4 changes: 2 additions & 2 deletions lib/moci/project_handler/base.rb
Expand Up @@ -31,11 +31,11 @@ def working_directory
end

def execute(command, output='')
@project_instance.execute(command, output='')
@project_instance.execute(command, output)
end

def execute!(command, output='')
@project_instance.execute!(command, output='')
@project_instance.execute!(command, output)
end

end
Expand Down
6 changes: 5 additions & 1 deletion test/factories/project_instance.rb
@@ -1,6 +1,10 @@
FactoryGirl.define do
factory :project_instance do
project
working_directory ""
working_directory "#{Rails.root}/tmp/test_run/#{$instance_dir = $instance_dir.to_i + 1}"
after_create do |o|
# cleaned up in test_helper
FileUtils.mkdir_p o.working_directory
end
end
end
3 changes: 3 additions & 0 deletions test/test_helper.rb
@@ -1,6 +1,9 @@
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'fileutils'

FileUtils.rm_rf("#{Rails.root}/tmp/test_run") if File.exists? Rails.root

class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
Expand Down
25 changes: 25 additions & 0 deletions test/unit/project_instance_test.rb
Expand Up @@ -17,5 +17,30 @@ class ProjectInstanceTest < ActiveSupport::TestCase
assert_nil instance.locked_by
end

test "collecting output from execution" do
instance = Factory.create :project_instance
output = ''
assert instance.execute "echo 'this is test'", output
lines = output.split("\n")
assert lines[0].starts_with? '$' # first line is command being executed
assert_equal lines[1], '' # second separating line
assert_equal lines[2], 'this is test'
end

test "collecting execution status" do
instance = Factory.create :project_instance
assert instance.execute("exit 0")
assert !instance.execute("exit 1")
end

test "execute!" do
instance = Factory.create :project_instance
instance.execute!("exit 0")
assert_raise RuntimeError do
instance.execute!("exit 1")
end
end


end

0 comments on commit 10e8f9b

Please sign in to comment.