Permalink
Browse files

re-join Model and Record and fix failing specs in spec/. yes. that me…

…ans, green, motherfucker, do you speak it.
  • Loading branch information...
1 parent c44c889 commit ecc4cdb455fcb0ecea95b48d13cf0039c91f4a91 Sven Fuchs committed Nov 1, 2011
Showing with 2,123 additions and 1,242 deletions.
  1. +0 −1 .rspec
  2. +3 −5 Gemfile
  3. +24 −30 Gemfile.lock
  4. +1 −1 app/assets/javascripts/app/models/job.js
  5. +7 −0 app/controllers/queues_controller.rb
  6. +1 −1 app/controllers/requests_controller.rb
  7. +1 −1 app/controllers/service_hooks_controller.rb
  8. +3 −2 config/routes.rb
  9. +1 −1 db/migrate/20110801161819_create_requests_commits_and_tasks.rb
  10. +12 −2 lib/tasks/ci.rake
  11. +0 −2 lib/tasks/testing.rake
  12. +7 −8 lib/travis.rb
  13. +5 −2 lib/travis/consumer/job.rb
  14. +4 −4 lib/travis/github_api.rb
  15. +80 −11 lib/travis/model/build.rb
  16. +1 −2 lib/travis/{record → model}/build/denormalize.rb
  17. 0 lib/travis/{record → model}/build/matrix.rb
  18. +29 −0 lib/travis/model/build/messages.rb
  19. +92 −96 lib/travis/model/build/notifications.rb
  20. +44 −0 lib/travis/model/build/states.rb
  21. 0 lib/travis/{record → model}/commit.rb
  22. +19 −46 lib/travis/model/job.rb
  23. +4 −27 lib/travis/model/job/configure.rb
  24. +38 −0 lib/travis/model/job/configure/states.rb
  25. +52 −0 lib/travis/model/job/states.rb
  26. +15 −17 lib/travis/model/job/tagging.rb
  27. +13 −38 lib/travis/model/job/test.rb
  28. +42 −0 lib/travis/model/job/test/states.rb
  29. +1 −1 lib/travis/{record → model}/repository.rb
  30. +37 −0 lib/travis/model/repository/service_hook.rb
  31. +37 −38 lib/travis/model/request.rb
  32. +24 −28 lib/travis/model/request/branches.rb
  33. +5 −0 lib/travis/model/request/payload.rb
  34. +22 −26 lib/travis/model/request/payload/github.rb
  35. +26 −0 lib/travis/model/request/states.rb
  36. 0 lib/travis/model/service_hook.rb
  37. 0 lib/travis/{record → model}/token.rb
  38. +1 −0 lib/travis/{record → model}/user.rb
  39. +1 −1 lib/travis/notifications/email.rb
  40. +1 −1 lib/travis/notifications/irc.rb
  41. +1 −1 lib/travis/notifications/pusher.rb
  42. +1 −1 lib/travis/notifications/webhook.rb
  43. +1 −1 lib/travis/notifications/webhook/views/v1/webhook/build.rabl
  44. +1 −1 lib/travis/notifications/worker.rb
  45. +0 −138 lib/travis/record/build.rb
  46. +0 −49 lib/travis/record/job.rb
  47. +0 −9 lib/travis/record/job/configure.rb
  48. +0 −4 lib/travis/record/job/test.rb
  49. +0 −36 lib/travis/record/repository/service_hook.rb
  50. +0 −39 lib/travis/record/request.rb
  51. +9 −23 spec/controllers/jobs_controller_spec.rb
  52. +27 −0 spec/controllers/queues_controller_spec.rb
  53. +1 −1 spec/controllers/repositories_controller_spec.rb
  54. +0 −1 spec/controllers/requests_controller_spec.rb
  55. +0 −13 spec/controllers/tasks_controller_spec.rb
  56. +1 −1 spec/fixtures/github/api/v2/json/organizations/travis-ci/public_members.json
  57. +1 −1 spec/fixtures/github/api/v2/json/repos/show/svenfuchs.json
  58. +1 −1 spec/fixtures/github/api/v2/json/repos/show/svenfuchs/gem-release.json
  59. +1 −1 spec/fixtures/github/api/v2/json/repos/show/svenfuchs/minimal.json
  60. +1 −1 spec/fixtures/github/api/v2/json/repos/show/travis-ci/travis-ci.json
  61. +1 −1 spec/fixtures/github/api/v2/json/user/show/LTe.json
  62. +1 −1 spec/fixtures/github/api/v2/json/user/show/svenfuchs.json
  63. +902 −0 spec/fixtures/github/users/svenfuchs/repos.json
  64. +1 −1 spec/integration/build_process_spec.rb
  65. +3 −2 spec/spec_helper.rb
  66. +2 −1 spec/support/github_api.rb
  67. +2 −1 spec/support/integration.rb
  68. +4 −5 spec/support/matchers.rb
  69. +4 −2 spec_fast/lib/github_spec.rb
  70. +2 −2 spec_fast/support/matchers.rb
  71. +11 −10 spec_fast/support/webmock.rb
  72. +7 −4 spec_fast/travis/mailer/helper/build_spec.rb
  73. +1 −0 spec_fast/travis/{record → model}/build/denormalize_spec.rb
  74. 0 spec_fast/travis/{record → model}/build/matrix_spec.rb
  75. +11 −13 spec_fast/travis/model/build/notifications_spec.rb
  76. +79 −0 spec_fast/travis/model/build/states_spec.rb
  77. +109 −58 spec_fast/travis/model/build_spec.rb
  78. +16 −13 spec_fast/travis/model/job/{configure_spec.rb → configure/states_spec.rb}
  79. +6 −6 spec_fast/travis/model/job/tagging_spec.rb
  80. +23 −20 spec_fast/travis/model/job/{test_spec.rb → test/states_spec.rb}
  81. 0 spec_fast/travis/{record → model}/job_spec.rb
  82. 0 spec_fast/travis/{record → model}/repository/service_hook_spec.rb
  83. 0 spec_fast/travis/{record → model}/repository_spec.rb
  84. +2 −2 spec_fast/travis/model/request/branches_spec.rb
  85. +2 −2 spec_fast/travis/model/request/payload/github_spec.rb
  86. +178 −0 spec_fast/travis/model/request/states_spec.rb
  87. +41 −172 spec_fast/travis/model/request_spec.rb
  88. 0 spec_fast/travis/{record → model}/token_spec.rb
  89. 0 spec_fast/travis/{record → model}/user_spec.rb
  90. +10 −10 spec_fast/travis/notifications/irc_spec.rb
  91. +3 −3 spec_fast/travis/notifications/pusher_spec.rb
  92. +3 −3 spec_fast/travis/notifications/webhook_spec.rb
  93. +0 −133 spec_fast/travis/record/build_spec.rb
  94. +0 −63 spec_fast/travis/record/request_spec.rb
View
1 .rspec
@@ -1,4 +1,3 @@
--colour
--tty
---drb
--format documentation
View
@@ -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'
View
@@ -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:
@@ -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)
@@ -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)
@@ -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)
@@ -4,6 +4,6 @@ Travis.Job = Travis.Record.extend({
});
Travis.Job.reopenClass({
- resource: 'jobs'
+ resource: 'queues'
});
@@ -0,0 +1,7 @@
+class QueuesController < ApplicationController
+ def index
+ respond_to do |format|
+ format.json { render :json => jobs }
+ end
+ end
+end
@@ -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
@@ -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
View
@@ -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'
@@ -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"
View
@@ -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
View
@@ -14,7 +14,6 @@ class Rake::Task
end
namespace :test do
-
Rake::Task[:units].abandon
Rake::Task[:functionals].abandon
Rake::Task[:integration].abandon
@@ -33,5 +32,4 @@ namespace :test do
t.libs << "test"
t.test_files = Dir.glob("test/integration/**/*_test.rb")
end
-
end
View
@@ -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'
@@ -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
View
@@ -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'
View
@@ -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
Oops, something went wrong.

0 comments on commit ecc4cdb

Please sign in to comment.