Skip to content

Commit

Permalink
re-join Model and Record and fix failing specs in spec/. yes. that me…
Browse files Browse the repository at this point in the history
…ans, green, motherfucker, do you speak it.
  • Loading branch information
Sven Fuchs committed Nov 1, 2011
1 parent c44c889 commit ecc4cdb
Show file tree
Hide file tree
Showing 94 changed files with 2,123 additions and 1,242 deletions.
1 change: 0 additions & 1 deletion .rspec
@@ -1,4 +1,3 @@
--colour
--tty
--drb
--format documentation
8 changes: 3 additions & 5 deletions Gemfile
Expand Up @@ -20,15 +20,13 @@ gem 'rabl', '~> 0.3.0'

# app
gem 'devise', '~> 1.4.2'
gem 'oa-oauth', '~> 0.2.6'
gem 'oa-oauth', '~> 0.3.0'
gem 'simple_states', '0.0.9'
gem 'unobtrusive_flash', '~> 0.0.2'
gem 'actionmailer_inline_css', "~> 1.3.0"
gem 'actionmailer_inline_css', '~> 1.3.0'

# apis
# current oa-oauth release depends on faraday 0.6.1, current octokit on faraday ~> 0.7.3, :git source for oa-oauth confuses heroku :(
# so we have to wait for an oa-oauth release
gem 'octokit', :git => 'git://github.com/pengwynn/octokit.git', :ref => '463e08caa4f940045f7f'
gem 'octokit', '~> 0.6.5'
gem 'pusher', '~> 0.8.1'
gem 'hoptoad_notifier', '~> 2.4.11'
gem 'newrelic_rpm', '~> 3.1.0'
Expand Down
54 changes: 24 additions & 30 deletions Gemfile.lock
@@ -1,15 +1,3 @@
GIT
remote: git://github.com/pengwynn/octokit.git
revision: 463e08caa4f940045f7f9e2003bd9dcd427b13c0
ref: 463e08caa4f940045f7f
specs:
octokit (0.6.3)
addressable (~> 2.2.6)
faraday (~> 0.6.0)
faraday_middleware (~> 0.6.0)
hashie (~> 1.0.0)
multi_json (~> 1.0.2)

GEM
remote: http://rubygems.org/
specs:
Expand Down Expand Up @@ -103,16 +91,16 @@ GEM
activesupport
fakeredis (0.2.2)
redis (~> 2.2.0)
faraday (0.6.1)
addressable (~> 2.2.4)
multipart-post (~> 1.1.0)
faraday (0.7.5)
addressable (~> 2.2.6)
multipart-post (~> 1.1.3)
rack (>= 1.1.0, < 2)
faraday_middleware (0.6.5)
faraday (~> 0.6.0)
faraday_middleware (0.7.0)
faraday (~> 0.7.3)
ffi (1.0.9)
forgery (0.5.0)
fssm (0.2.7)
hashie (1.0.0)
hashie (1.2.0)
hashr (0.0.16)
hike (1.2.1)
hoptoad_notifier (2.4.11)
Expand Down Expand Up @@ -144,22 +132,28 @@ GEM
mocha (0.10.0)
metaclass (~> 0.0.1)
multi_json (1.0.3)
multi_xml (0.2.2)
multi_xml (0.4.1)
multipart-post (1.1.3)
newrelic_rpm (3.1.2)
nokogiri (1.5.0)
oa-core (0.2.6)
oa-oauth (0.2.6)
faraday (~> 0.6.1)
oa-core (0.3.2)
oa-oauth (0.3.2)
faraday (~> 0.7.3)
multi_json (~> 1.0.0)
multi_xml (~> 0.2.2)
oa-core (= 0.2.6)
multi_xml (~> 0.4.0)
oa-core (= 0.3.2)
oauth (~> 0.4.0)
oauth2 (~> 0.4.1)
oauth2 (~> 0.5.0)
oauth (0.4.5)
oauth2 (0.4.1)
faraday (~> 0.6.1)
multi_json (>= 0.0.5)
oauth2 (0.5.1)
faraday (~> 0.7.4)
multi_json (~> 1.0.3)
octokit (0.6.5)
addressable (~> 2.2.6)
faraday (~> 0.7.4)
faraday_middleware (~> 0.7.0)
hashie (~> 1.2.0)
multi_json (~> 1.0.2)
orm_adapter (0.0.5)
pg (0.11.0)
polyglot (0.3.2)
Expand Down Expand Up @@ -329,8 +323,8 @@ DEPENDENCIES
minitest_tu_shim
mocha
newrelic_rpm (~> 3.1.0)
oa-oauth (~> 0.2.6)
octokit!
oa-oauth (~> 0.3.0)
octokit (~> 0.6.5)
pg (~> 0.11.0)
pusher (~> 0.8.1)
rabl (~> 0.3.0)
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/app/models/job.js
Expand Up @@ -4,6 +4,6 @@ Travis.Job = Travis.Record.extend({
});

Travis.Job.reopenClass({
resource: 'jobs'
resource: 'queues'
});

7 changes: 7 additions & 0 deletions app/controllers/queues_controller.rb
@@ -0,0 +1,7 @@
class QueuesController < ApplicationController
def index
respond_to do |format|
format.json { render :json => jobs }
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/requests_controller.rb
@@ -1,7 +1,7 @@
class RequestsController < ApplicationController
# also responds to POST /builds legacy route
def create
Travis::Model::Request.create(params[:payload], api_token)
Request.create_from(params[:payload], api_token)
render :nothing => true
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/service_hooks_controller.rb
Expand Up @@ -12,7 +12,7 @@ def index
end

def update
repository.service_hook.toggle(params[:active], current_user)
repository.service_hook.set(params[:active], current_user)
respond_with(repository)
end

Expand Down
5 changes: 3 additions & 2 deletions config/routes.rb
Expand Up @@ -10,8 +10,9 @@
resources :builds, :only => :show
resources :requests, :only => :create
resources :jobs, :only => [:show, :update, :log]
resources :queue, :only => :index
resources :workers, :only => :index

match 'queues', :to => 'queues#index'
match 'workers', :to => 'workers#index'

resource :profile, :only => :show do
get 'service_hooks', :to => 'service_hooks#index'
Expand Down
Expand Up @@ -99,7 +99,7 @@ def self.up
execute 'UPDATE builds SET commit_id = (SELECT commits.id FROM commits WHERE commits.commit = builds.commit LIMIT 1)'

# execute "DROP SEQUENCE shared_builds_tasks_seq" rescue nil
execute "CREATE SEQUENCE shared_builds_tasks_seq START WITH #{[Build.maximum(:id), Task.maximum(:id)].compact.max.to_i + 1} CACHE 30"
execute "CREATE SEQUENCE shared_builds_tasks_seq START WITH #{[Build.maximum(:id), (Task.maximum(:id) rescue 0)].compact.max.to_i + 1} CACHE 30"
execute "ALTER TABLE builds ALTER COLUMN id TYPE BIGINT"
execute "ALTER TABLE builds ALTER COLUMN id SET DEFAULT nextval('shared_builds_tasks_seq')"
execute "ALTER TABLE tasks ALTER COLUMN id TYPE BIGINT"
Expand Down
14 changes: 12 additions & 2 deletions lib/tasks/ci.rake
@@ -1,4 +1,14 @@
namespace :test do
desc "a little shortcut for ci testing"
task :ci => ["db:drop", "db:create", "db:test:load", "spec"]
desc 'a little shortcut for ci testing'
task :ci => ['ci_env', 'db:drop', 'db:create', 'db:test:load', 'spec_fast', 'spec']

RSpec::Core::RakeTask.new(:spec_fast) do |t|
t.rspec_opts = '-Ispec_fast'
t.pattern = "./spec_fast/**/*_spec.rb"
end
end

task :ci_env do
ENV['CI'] = 'true'
ENV['RAILS_ENV'] = 'test'
end
2 changes: 0 additions & 2 deletions lib/tasks/testing.rake
Expand Up @@ -14,7 +14,6 @@ class Rake::Task
end

namespace :test do

Rake::Task[:units].abandon
Rake::Task[:functionals].abandon
Rake::Task[:integration].abandon
Expand All @@ -33,5 +32,4 @@ namespace :test do
t.libs << "test"
t.test_files = Dir.glob("test/integration/**/*_test.rb")
end

end
15 changes: 7 additions & 8 deletions lib/travis.rb
@@ -1,17 +1,16 @@
autoload :Build, 'travis/record/build'
autoload :Commit, 'travis/record/commit'
autoload :Job, 'travis/record/job'
autoload :Repository, 'travis/record/repository'
autoload :Request, 'travis/record/request'
autoload :Token, 'travis/record/token'
autoload :User, 'travis/record/user'
autoload :Build, 'travis/model/build'
autoload :Commit, 'travis/model/commit'
autoload :Job, 'travis/model/job'
autoload :Repository, 'travis/model/repository'
autoload :Request, 'travis/model/request'
autoload :Token, 'travis/model/token'
autoload :User, 'travis/model/user'

module Travis
autoload :Config, 'travis/config'
autoload :Consumer, 'travis/consumer'
autoload :GithubApi, 'travis/github_api'
autoload :Mailer, 'travis/mailer'
autoload :Model, 'travis/model'
autoload :Notifications, 'travis/notifications'
autoload :Record, 'travis/record'
autoload :Renderer, 'travis/renderer'
Expand Down
7 changes: 5 additions & 2 deletions lib/travis/consumer/job.rb
Expand Up @@ -16,13 +16,16 @@ def handle(event, payload)

protected

def job
@job ||= ::Job.find(payload.id)
end

def handle_update
job = Travis::Model::Job.find(payload.id)
job.update_attributes(payload.to_hash)
end

def handle_log_update
Travis::Model::Job.append_log!(payload.id, payload.log)
::Job::Test.append_log!(payload.id, payload.log)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/travis/github_api.rb
Expand Up @@ -7,17 +7,17 @@ class ServiceHookError < StandardError; end
class << self
def add_service_hook(owner_name, name, oauth_token, data)
client = Octokit::Client.new(:oauth_token => oauth_token)
client.subscribe_service_hook(owner_name, name, 'Travis', data)
client.subscribe_service_hook("#{owner_name}/#{name}", 'Travis', data)
rescue Octokit::UnprocessableEntity => e
# TODO log these events
raise ServiceHookError, 'error subscribing to the GitHub push event'
rescue Octokit::Unauthorized => e
raise ServiceHookError, 'error authorizing with given GitHub OAuth token'
end

def remove_service_hook(repository, user)
client = Octokit::Client.new(:oauth_token => user.github_oauth_token)
client.unsubscribe_service_hook(repository.owner_name, repository.name, 'Travis')
def remove_service_hook(owner_name, name, oauth_token)
client = Octokit::Client.new(:oauth_token => oauth_token)
client.unsubscribe_service_hook("#{owner_name}/#{name}", 'Travis')
rescue Octokit::UnprocessableEntity => e
# TODO log this event
raise ServiceHookError, 'error unsubscribing from the GitHub push event'
Expand Down
91 changes: 80 additions & 11 deletions lib/travis/model/build.rb
@@ -1,19 +1,88 @@
require 'simple_states'
require 'active_record'
require 'core_ext/active_record/base'
require 'core_ext/hash/deep_symbolize_keys'

module Travis
class Model
class Build < Model
autoload :Notifications, 'travis/model/build/notifications'
class Build < ActiveRecord::Base
autoload :Notifications, 'travis/model/build/notifications'
autoload :Matrix, 'travis/model/build/matrix'
autoload :Messages, 'travis/model/build/messages'
autoload :Denormalize, 'travis/model/build/denormalize'
autoload :States, 'travis/model/build/states'

include Notifications, SimpleStates, Travis::Notifications
include Matrix, States, Messages

states :created, :started, :finished
PER_PAGE = 10

event :start, :to => :started
event :finish, :to => :finished, :if => :matrix_finished?
event :all, :after => [:denormalize, :notify]
belongs_to :commit
belongs_to :request
belongs_to :repository, :autosave => true
has_many :matrix, :as => :owner, :order => :id, :class_name => 'Job::Test'

delegate :state, :state=, :config, :passed?, :failed?, :matrix_finished?, :denormalize, :to => :record
validates :repository_id, :commit_id, :request_id, :presence => true

serialize :config

class << self
def recent(options = {})
was_started.descending.paged(options).includes([:commit, { :matrix => :commit }])
end

def was_started
where(:state => ['started', 'finished'])
end

def finished
where(:state => 'finished')
end

def on_branch(branches)
branches = normalize_to_array(branches)
joins(:commit).where(branches.present? ? ["commits.branch IN (?)", branches] : [])
end

def previous(build)
where("builds.repository_id = ? AND builds.id < ?", build.repository_id, build.id).finished.descending.limit(1).first
end

def last_finished_on_branch(branches)
finished.on_branch(branches).descending.first
end

def descending
order(arel_table[:id].desc)
end

def paged(options)
# TODO should use an offset when we use limit!
# offset(PER_PAGE * options[:offset]).limit(options[:page])
limit(PER_PAGE * (options[:page] || 1).to_i)
end

def next_number
maximum(floor('number')).to_i + 1
end

protected

def normalize_to_array(object)
Array(object).compact.join(',').split(',')
end
end

after_initialize do
self.config = {} if config.nil?
end

before_create do
self.number = repository.builds.next_number
expand_matrix
end

def previous_on_branch
Build.on_branch(commit.branch).previous(self)
end

def config=(config)
super(config.deep_symbolize_keys)
end
end
@@ -1,7 +1,6 @@
class Build
module Denormalize
def denormalize(*args)
event = args.first # TODO bug in simple_state? getting an error when i add this to the method signature
def denormalize(event, *args)
repository.update_attributes!(denormalize_attributes_for(event)) if denormalize?(event)
end

Expand Down
File renamed without changes.

0 comments on commit ecc4cdb

Please sign in to comment.