Permalink
Browse files

Move tests over to scorecard in client-side, and only send them if ri…

…ak_test is asking for them to be filtered.
  • Loading branch information...
1 parent 640a813 commit fe4d09318b4bf1d75845baee6d194864cab3dca3 @seancribbs seancribbs committed Oct 29, 2012
View
@@ -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)
@@ -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)
@@ -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({
@@ -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({
@@ -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);
@@ -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({
@@ -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){
@@ -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;
@@ -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>
View
@@ -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
View
@@ -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
View
@@ -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
@@ -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
@@ -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

0 comments on commit fe4d093

Please sign in to comment.