From 04af3d351fe1bf194ded9492d2f3b7ef9a3acec7 Mon Sep 17 00:00:00 2001 From: Anton Podviaznikov Date: Sun, 27 Nov 2011 21:21:11 +0100 Subject: [PATCH] updating tests --- lib/massive.git.coffee | 3 +-- lib/objects/git.entity.coffee | 2 +- lib/objects/git.object.coffee | 5 +---- lib/objects/repo.coffee | 19 +++++++------------ lib/objects/tree.coffee | 3 +-- lib/objects/utils.coffee | 7 +++---- lib/validators/input.validators.coffee | 1 - 7 files changed, 14 insertions(+), 26 deletions(-) diff --git a/lib/massive.git.coffee b/lib/massive.git.coffee index fcc16e4..a50b320 100644 --- a/lib/massive.git.coffee +++ b/lib/massive.git.coffee @@ -266,8 +266,7 @@ MassiveGit = exports.MassiveGit = class MassiveGit entries = tree.entries treeEntries = [] for blob in blobs - blobId = blob.id() - name = entry.name for entry in entries when entry.id == blobId + name = entry.name for entry in entries when entry.id == blob.id() treeEntries.push new TreeEntry name, blob callback err, treeEntries diff --git a/lib/objects/git.entity.coffee b/lib/objects/git.entity.coffee index b2eb66a..40f9f91 100644 --- a/lib/objects/git.entity.coffee +++ b/lib/objects/git.entity.coffee @@ -31,7 +31,7 @@ GitEntity = exports.GitEntity = class GitEntity # Method for building link. buildLink: (bucket, key, tag) -> utils.buildLink bucket, key, tag - # Method that check whether two `GitEntities` are the same. + # Method checks whether two `GitEntities` are the same. equals: (gitEntity) => @id() == gitEntity.id() and _.isEqual(@links(), gitEntity.links()) and _.isEqual(@attributes(), gitEntity.attributes()) diff --git a/lib/objects/git.object.coffee b/lib/objects/git.object.coffee index d52d29f..13d91d5 100644 --- a/lib/objects/git.object.coffee +++ b/lib/objects/git.object.coffee @@ -1,10 +1,7 @@ crypto = require "crypto" GitEntity = require("./git.entity").GitEntity -sha1 = (data) -> - shasum = crypto.createHash "sha1" - shasum.update data - shasum.digest "hex" +sha1 = (data) -> crypto.createHash("sha1").update(data).digest("hex") # GitObject # ------------ diff --git a/lib/objects/repo.coffee b/lib/objects/repo.coffee index 100ed1e..6d884b4 100644 --- a/lib/objects/repo.coffee +++ b/lib/objects/repo.coffee @@ -5,11 +5,10 @@ GitEntity = require("./git.entity").GitEntity # Class representing repository. # `id` - unique repository id. Id calculated from `owner`, `type` and `name` of the repository. # `author` - repository's author. -# `type` - type of the repository. Metainformation. +# `type` - type of the repository. Meta information. # `public` - flag that indicated whether repo is public or private. Default to `true`. # `commit` - last commit for this repository. Can be `null` if repository wasn't commited previously. # `forkedFrom` - id of the repository from which this was cloned. Default to `null`. -# todo (anton) repo type can be stored as secondary index. Repo = exports.Repo = class Repo extends GitEntity constructor: (@name, @author, @type, @public = true, @commit, @forkedFrom = null) -> @@ -24,11 +23,9 @@ Repo = exports.Repo = class Repo extends GitEntity # Method for getting plain `attributes` of the GitObject. attributes: => - # TODO (Anton) why we have `attributes` key here - attributes = - name : @name - type : @type - public: @public + name : @name + type : @type + public: @public # Method for getting `index`es of the GitObject. index: => @@ -36,13 +33,11 @@ Repo = exports.Repo = class Repo extends GitEntity type : @type public: @public - # Method for getting `links` that connect this GitObject with another GitObjects, users or repositories. + # Method for getting `links` that connect this GitObject with other Git Objects, users or repositories. links: => links = [] links.push @buildLink "users", @author, "author" - if(@forkedFrom) - links.push @buildLink "repositories", @forkedFrom, "forked_from" - if(@commit) - links.push @buildLink "objects", @commit, "commit" + links.push @buildLink "repositories", @forkedFrom, "forked_from" if @forkedFrom + links.push @buildLink "objects", @commit, "commit" if @commit links diff --git a/lib/objects/tree.coffee b/lib/objects/tree.coffee index 7ba5798..24a6349 100644 --- a/lib/objects/tree.coffee +++ b/lib/objects/tree.coffee @@ -1,7 +1,6 @@ _ = require "underscore" GitObject = require("./git.object").GitObject - # Tree # --------- # Tree is one of the 4 core Git Objects. Tree stores `entries` which are links to blobs and other trees. @@ -24,7 +23,7 @@ Tree = exports.Tree = class Tree extends GitObject # Method for getting plain `attributes` of the GitObject. attributes: => attributes = super() - # todo (anton) we need to store entities also here. Since they cannot be fully repopulated from links (mode and name of entry). + # @NOTE (anton) we need to store entities also here. Since they cannot be fully repopulated from links (mode and name of entry). # However for now it's not clear do we need these 'full' entities... attributes.entries = @entries attributes diff --git a/lib/objects/utils.coffee b/lib/objects/utils.coffee index 88183f5..e9488d2 100644 --- a/lib/objects/utils.coffee +++ b/lib/objects/utils.coffee @@ -4,8 +4,8 @@ utils = exports # Method for finding appropriate link `key` by `tag` name. # Return `null` if link wasn't found. utils.getLink = (links, tagName) -> - link =_.detect links, (link) -> tagName == link.tag - if(link) + link = _.detect links, (link) -> tagName == link.tag + if link return link.key else return null @@ -16,8 +16,7 @@ utils.getLinks = (links, tagName) -> _.map filtered, (link) -> link.key # Utility method for building link. -utils.buildLink = (bucket, key, tag) -> { bucket : bucket, key : key, tag : tag } +utils.buildLink = (bucket, key, tag) -> {bucket: bucket, key: key, tag: tag} # Utility method for merging two arrays into one. utils.mergeArrays = (first, second) -> Array::push.apply first, second - diff --git a/lib/validators/input.validators.coffee b/lib/validators/input.validators.coffee index 3c2071a..ed470d4 100644 --- a/lib/validators/input.validators.coffee +++ b/lib/validators/input.validators.coffee @@ -7,7 +7,6 @@ class ValidationResult isValid: => !@errorMessage? - # Validate user's data. `username` and `email` are both mandatory. exports.validateUser = (username, email) -> # sanitize input params before further validation