// ==========================================================================
// Project:   TestRunner.Target
// Copyright: ©2009 My Company, Inc.
// ==========================================================================
/*globals TestRunner */

/** @class

  Describes a single target in the current project.  A target can have a name,
  a type and one or more tests that are loaded on demand.

  @extends SC.Record
  @author Charles Jolley
*/
TestRunner.Target = SC.Record.extend(
/** @scope TestRunner.Target.prototype */ {
  
  /** Load the tests for the target. */
  tests: function() {
    this.refreshTests();
    return this._tests;
  }.property().cacheable(),
  
  /**
    Loads the targets from the server.  When the targets have loaded, adds 
    them to the store and then sets the local content.
  */
  refreshTests: function() {
    if (!this._tests) this._tests = [] ;
    SC.Request.getUrl(this.get('link_tests'))
      .notify(this, 'testsDidRefresh').set('isJSON', YES).send();
  },
  
  testsDidRefresh: function(request) {
    var json = request.get('response'), len = json.length, idx;
    for(idx=0;idx<len;idx++) json[idx].guid = json[idx].url ; // patch
    var tests = SC.Store.updateRecords(json, SC.Store, TestRunner.Test);
    tests = tests.sort(function(a,b) { 
      a = a.get('filename'); 
      b = b.get('filename');
      return (a<b) ? -1 : (a>b) ? 1 : 0;
    });

    this.propertyWillChange('tests');
    this._tests = tests ;
    this.propertyDidChange('tests');
  }

}) ;

@@ -528,251 +528,295 @@
 / %7B%0A
-  %0A  /** Load the tests for the target. */%0A  tests: function() %7B%0A    this.refreshTests();%0A    return this._tests;%0A  %7D.property().cacheable(),%0A  %0A  /**%0A    Loads the targets from the server.  When the targets have loaded, adds 
+%0A  primaryKey: %22name%22,%0A  %0A  /**%0A    The target name.  This is the primary key%0A    %0A    @property%0A  */%0A  name: SC.Record.attr(String),%0A  %0A  /**%0A    The kind of target.  Usually is one of %22app%22 or %22framework%22.%0A    %0A    @property%0A  */%0A  kind: SC.Record.attr(String),%0A%0A  /**
 %0A    
-them
+Link
  to the 
 stor
@@ -815,743 +815,846 @@
 the 
-store and then sets the local content.%0A  */%0A  refreshTests: function() %7B%0A    if (!this._tests) this._tests = %5B%5D ;%0A    SC.Request.getUrl(this.get('link_tests'))%0A      .notify(this, 'testsDidRefresh').set('isJSON', YES).send();%0A  %7D,
+document index json%0A%0A    @property%0A  */%0A  docsUrl: SC.Record.attr(String, %7B key: %22link_docs%22 %7D),%0A  %0A  /**%0A    Link to the test index json%0A    %0A    @property%0A  */%0A  testsUrl: SC.Record.attr(String, %7B key: %22link_tests%22 %7D),%0A  %0A  /**%0A    Link to the target itself.  This is only useful for applications.%0A    %0A    @property
 %0A  
+*/
 %0A  
-testsDidRefresh: function(request) %7B
+rootUrl: SC.Record.attr(String, %7B key: %22link_root%22 %7D),%0A  
 %0A  
+%0A
   
-var json = request.get('response'), len = json.length, idx;%0A    for(idx=0;idx%3Clen;idx++) json%5Bidx%5D.guid = json%5Bidx%5D.url ; // patch%0A    var tests = SC.Store.updateRecords(json, SC.Store, 
+/**%0A    The parent target, if there is one.  This is a reference to the primary%0A    key.%0A    %0A    @property%0A  */%0A  parent: SC.Record.hasOne(%22
 TestRun
-n
 er.T
-est);%0A    tests = tests.sort(function(a,b) %7B %0A      a = a.get('filename'); %0A      b = b
+arget%22),%0A  %0A  /**%0A    The display name for the target.  Computed by taking the last part of the%0A    target name.%0A  */%0A  displayName: function() %7B%0A    var name = this
 .get('
-file
 name')
-;%0A      return (a%3Cb) ? -1 : (a%3Eb) ? 1 : 0;%0A    %7D);%0A%0A    this.propertyWillChange('tests');%0A    this._tests = tests ;%0A    this.propertyDidChange('tests');
+.split('/');%0A    name = name%5Bname.length-1%5D %7C%7C '(none)';%0A    return name.titleize();%0A  %7D.property('name').cacheable()
 %0A  
-%7D%0A
 %0A%7D) 

Update unit test Target model.