Skip to content

Commit

Permalink
Move tests over to scorecard in client-side, and only send them if ri…
Browse files Browse the repository at this point in the history
…ak_test is asking for them to be filtered.
  • Loading branch information
seancribbs committed Oct 29, 2012
1 parent 640a813 commit fe4d093
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 32 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Expand Up @@ -17,8 +17,8 @@ GIT
GEM
remote: http://rubygems.org/
specs:
active_model_serializers (0.5.2)
activemodel (~> 3.0)
active_model_serializers (0.6.0)
activemodel (>= 3.0)
activemodel (3.2.8)
activesupport (= 3.2.8)
builder (~> 3.0.0)
Expand All @@ -31,7 +31,7 @@ GEM
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
builder (3.0.3)
builder (3.0.4)
daemons (1.1.9)
eventmachine (1.0.0)
excon (0.16.2)
Expand Down
34 changes: 17 additions & 17 deletions assets/javascripts/app/models.js
Expand Up @@ -12,27 +12,21 @@ DS.attr.transforms.hash = {
GiddyUp.Project = DS.Model.extend({
primaryKey: 'name',
name: DS.attr('string'),
tests: DS.hasMany('GiddyUp.Test', { embedded: true }),
scorecards: DS.hasMany('GiddyUp.Scorecard', { key: 'scorecard_ids' }),
platforms: function(){
return this.get('tests').getEach('platform').sort().uniq();
}.property('tests').cacheable(),
testNames: function(){
return this.get('tests').getEach('name').sort().uniq();
}.property('tests').cacheable()
scorecards: DS.hasMany('GiddyUp.Scorecard', { key: 'scorecard_ids' })
});

GiddyUp.Scorecard = DS.Model.extend({
name: DS.attr('string'),
project: DS.belongsTo('GiddyUp.Project', {key: 'project'}),
project: DS.belongsTo('GiddyUp.Project', { key: 'project' }),
test_results: DS.hasMany('GiddyUp.TestResult', { key: 'test_result_ids' }),
tests: DS.hasMany('GiddyUp.Test', { embedded: true }),
cells: function(){
if(!this.get('project.isLoaded')){
return [];
}
var scorecard = this;
var platforms = this.get('project.platforms');
var testNames = this.get('project.testNames');
var platforms = this.get('platforms');
var testNames = this.get('testNames');
return testNames.map(function(name){
return platforms.map(function(platform){
return GiddyUp.ScorecardCell.create({
Expand All @@ -42,7 +36,13 @@ GiddyUp.Scorecard = DS.Model.extend({
});
});
})
}.property('project.isLoaded')
}.property('project.isLoaded'),
platforms: function(){
return this.get('tests').getEach('platform').sort().uniq();
}.property('tests').cacheable(),
testNames: function(){
return this.get('tests').getEach('name').sort().uniq();
}.property('tests').cacheable()
});

GiddyUp.TestResult = DS.Model.extend({
Expand All @@ -54,7 +54,7 @@ GiddyUp.TestResult = DS.Model.extend({
return null;
}

tests = this.get('scorecard.project.tests');
tests = this.get('scorecard.tests');

if(tests) {
return tests.findProperty('id', id);
Expand Down Expand Up @@ -86,8 +86,8 @@ GiddyUp.TestResult = DS.Model.extend({
GiddyUp.Test = DS.Model.extend({
name: DS.attr('string'),
tags: DS.attr('hash'),
platform: function(){ return this.get('tags').platform; }.property('tags'),
backend: function(){ return this.get('tags').backend; }.property('tags')
platform: function(){ return this.get('tags.platform'); }.property('tags'),
backend: function(){ return this.get('tags.backend'); }.property('tags')
});

GiddyUp.Log = DS.Model.extend({
Expand All @@ -111,7 +111,7 @@ GiddyUp.ScorecardCell = Ember.Object.extend({
var platform = this.get('platform');
var scorecard = this.get('scorecard');
var cell = this;
var tests = scorecard.get('project.tests').filter(function(test){
var tests = scorecard.get('tests').filter(function(test){
return test.get('name') === name && test.get('platform') === platform;
});
return tests.map(function(test){
Expand Down Expand Up @@ -154,7 +154,7 @@ GiddyUp.ScorecardSubcellRouterProxy = Ember.Object.extend({
var name = this.get('test.name');
var backend = this.get('test.backend');
var platform = this.get('test.platform');
var tests = this.get('scorecard.project.tests');
var tests = this.get('scorecard.tests');

var selectedTest;
var selectedResults;
Expand Down
2 changes: 1 addition & 1 deletion assets/javascripts/app/templates/scorecard.hbs
Expand Up @@ -3,7 +3,7 @@
<thead>
<tr>
<th>&nbsp;</th>
{{#each platform in controller.content.project.platforms}}
{{#each platform in controller.content.platforms}}
<th>{{platform}}</th>
{{/each}}
</tr>
Expand Down
2 changes: 1 addition & 1 deletion lib/giddyup/hstore.rb
Expand Up @@ -116,7 +116,7 @@ def hstore(*args)

class PostgreSQLColumn < Column
# Does the type casting from hstore columns using String#from_hstore or Hash#from_hstore.
def type_cast_code_with_hstore(var_name)r
def type_cast_code_with_hstore(var_name)
type == :hstore ? "HstoreSerializer.load(#{var_name})" : type_cast_code_without_hstore(var_name)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/giddyup/records.rb
Expand Up @@ -53,7 +53,7 @@ def content
class Project < ActiveRecord::Base
# name string -- 'riak' or 'riak_ee' or 'riak_cs'
validates_uniqueness_of :name
default_scope includes(:tests, :scorecards)
default_scope includes(:scorecards)
has_many :scorecards
has_and_belongs_to_many :tests
end
Expand Down
17 changes: 10 additions & 7 deletions lib/giddyup/resources.rb
Expand Up @@ -159,19 +159,22 @@ def to_json

class ProjectResource < Resource
def resource_exists?
query = Project.where(:name => request.path_info[:name])
if version = request.query.delete('version')
query = Test.for_version(version, query)
end
scope = Project.where(:name => request.path_info[:name])
if !request.query.empty?
query = query.where(['tests.tags::hstore @> ?', HstoreSerializer.dump(request.query)])
query = request.query.dup
scope = scope.includes(:tests)
if version = query.delete('version')
scope = Test.for_version(version, scope)
end
scope = scope.where(['tests.tags::hstore @> ?', HstoreSerializer.dump(query)])
end
@project = query.first
@project = scope.first
@project.present?
end

def to_json
ProjectSerializer.new(@project, {:scope => :single}).to_json
options = request.query.empty? ? {} : {:scope => :filtered}
ProjectSerializer.new(@project, options).to_json
end
end

Expand Down
8 changes: 6 additions & 2 deletions lib/giddyup/serializers.rb
@@ -1,6 +1,10 @@
class ProjectSerializer < ActiveModel::Serializer
attributes :name, :scorecard_ids
has_many :tests

def include_tests?
scope == :filtered
end
end

class LogSerializer < ActiveModel::Serializer
Expand All @@ -12,8 +16,8 @@ class TestResultSerializer < ActiveModel::Serializer
end

class ScorecardSerializer < ActiveModel::Serializer
attributes :id, :name, :project, :test_result_ids, :tests

attributes :id, :name, :project, :test_result_ids
has_many :tests
def project
# We key the project off the name
scorecard.project.name
Expand Down

0 comments on commit fe4d093

Please sign in to comment.