Permalink
Browse files

More WIP

  • Loading branch information...
1 parent 8ec156a commit 41ecbf24b4790459d13856ff26c2792e10f18572 @seancribbs seancribbs committed Sep 13, 2012
Showing with 85 additions and 27 deletions.
  1. +33 −0 lib/giddyup/contexts.rb
  2. +2 −13 lib/giddyup/records.rb
  3. +28 −5 lib/giddyup/resources.rb
  4. +5 −9 lib/giddyup/serializers.rb
  5. +17 −0 scorecards.json
View
@@ -0,0 +1,33 @@
+module GiddyUp
+ # Context that creates a test result
+ class CreateTestResult
+ attr_reader :test_result, :scorecard, :test, :platform, :log
+ attr_accessor :status, :author
+
+ def initialize
+ @test_result = TestResult.new
+ end
+
+ def id
+ @test_result.save!(:validate => false) if @test_result.new_record?
+ @test_result.id
+ end
+
+ def create_test_result(data)
+ self.test = data.delete('test')
+ self.platform = data.delete('platform')
+ self.scorecard = data.delete('version')
+ self.log = data.delete['log']
+ end
+
+ def scorecard=(
+
+ def attributes
+ {
+ :test => test,
+ :platform => platform,
+ :scorecard => scorecard
+ }
+ end
+ end
+end
View
@@ -10,28 +10,17 @@ class Test < ActiveRecord::Base
end
class TestResult < ActiveRecord::Base
- # result boolean -- did it pass or not
+ # status boolean -- did it pass or not
# author string -- who ran it
# test_id
# platform_id
# scorecard_id
- default_scope joins(:test, :platform, :backend).
- order('test.name ASC, platform.position ASC, backend.name ASC')
+ default_scope includes(:test, :platform)
belongs_to :test
belongs_to :platform
- belongs_to :backend
belongs_to :scorecard
end
-class Backend < ActiveRecord::Base
- # name string -- 'bitcask' or 'leveldb'
- default_scope order(:name)
-
- def shortname
- name[0..1].upcase
- end
-end
-
class Project < ActiveRecord::Base
# name string -- 'riak' or 'riak_ee' or 'riak_cs'
has_many :scorecards
View
@@ -1,3 +1,4 @@
+require 'stringio'
module GiddyUp
# Base class for resources
class Resource < Webmachine::Resource
@@ -19,15 +20,16 @@ class TestResultResource < Resource
# We open a transaction on initialization so we can grab the next
# id in create_path.
def initialize
- ActiveRecord::Base.connection.begin_db_transaction
+ TestResult.connection.begin_db_transaction
end
def finish_request
if response.code < 400
- ActiveRecord::Base.connection.commit_db_transaction
+ TestResult.connection.commit_db_transaction
else
- ActiveRecord::Base.connection.rollback_db_transaction
+ TestResult.connection.rollback_db_transaction
end
+ TestResult.clear_active_connections!
end
def content_types_accepted
@@ -38,12 +40,33 @@ def content_types_accepted
def resource_exists?; false; end
def post_is_create?; true; end
def create_path
- next_id = ActiveRecord::Base.connection.serial_sequence TestResult.TestResult.sequence_name
- URI.join(base_uri,
+ @context = CreateTestResult.new
+ URI.join(request.base_uri, "/test_results/#{@context.id}")
end
def allowed_methods
['POST']
end
+
+ def accept_json
+ begin
+ data = MultiJson.load(request.body.to_s)
+ rescue
+ raise Webmachine::MalformedRequest, "Invalid JSON body"
+ end
+ @context.create_test_result(data)
+ end
+
+ def accept_multipart
+ begin
+ parser = Rack::Multipart::Parser.new('CONTENT_TYPE' => request.content_type,
+ 'CONTENT_LENGTH' => request.content_length,
+ 'rack.input' => StringIO.new(request.body.to_s))
+ data = parser.parse
+ rescue
+ raise Webmachine::MalformedRequest, "Invalid multipart body"
+ end
+ @context.create_test_result(data)
+ end
end
end
View
@@ -1,5 +1,5 @@
class TestResultSerializer < ActiveModel::Serializer
- attributes :id, :result, :author, :log_url, :test, :platform, :backend, :backend_shortname
+ attributes :id, :result, :author, :log_url, :test, :platform, :tags
def test
test_result.test.name
@@ -8,14 +8,6 @@ def test
def platform
test_result.platform.name
end
-
- def backend
- test_result.backend.name
- end
-
- def backend_shortname
- test_result.backend.shortname
- end
end
class ScorecardSerializer < ActiveModel::Serializer
@@ -26,4 +18,8 @@ class ScorecardSerializer < ActiveModel::Serializer
def project
scorecard.project.name
end
+
+ def include_test_results?
+ scope == :single
+ end
end
View
@@ -0,0 +1,17 @@
+{
+ "scorecards":[
+ {"id": 1,
+ "name":"riak-1.2.1-7-deadbeef 2012-09-12",
+ "project":"riak",
+ "test_results": [1, 2, 3, 4, 5, 6]
+ }
+ ],
+ "test_results":[
+ {"id":1,
+ "test":"verify_build_cluster",
+ "platform":"ubuntu1204-64",
+ "status":true,
+ "log_url":"http://basho-giddyup.s3.amazonaws.com/1.txt"
+ }
+ ]
+}

0 comments on commit 41ecbf2

Please sign in to comment.