Merge pull request #1355 from tsigo/gfm_spec_cleanup

GFM spec redesign
This commit is contained in:
Dmitriy Zaporozhets 2012-09-02 11:57:33 -07:00
commit f9711cd81a
6 changed files with 337 additions and 241 deletions

View file

@ -1,6 +1,15 @@
class CommitDecorator < ApplicationDecorator
decorates :commit
# Returns a string describing the commit for use in a link title
#
# Example
#
# "Commit: Alex Denisov - Project git clone panel"
def link_title
"Commit: #{author_name} - #{title}"
end
# Returns the commits title.
#
# Usually, the commit title is the first line of the commit message.

View file

@ -1,6 +1,7 @@
class Commit
include ActiveModel::Conversion
include Gitlab::Encode
include StaticModel
extend ActiveModel::Naming
attr_accessor :commit
@ -22,8 +23,7 @@ class Commit
:to_patch,
to: :commit
class << self
class << self
def find_or_first(repo, commit_id = nil, root_ref)
commit = if commit_id
repo.commit(commit_id)
@ -85,7 +85,7 @@ class Commit
first = project.commit(to.try(:strip))
last = project.commit(from.try(:strip))
result = {
result = {
commits: [],
diffs: [],
commit: nil
@ -105,10 +105,6 @@ class Commit
end
end
def persisted?
false
end
def initialize(raw_commit, head = nil)
@commit = raw_commit
@head = head
@ -155,7 +151,7 @@ class Commit
prev_commit.try :id
end
def parents_count
def parents_count
parents && parents.count || 0
end
end

35
app/roles/static_model.rb Normal file
View file

@ -0,0 +1,35 @@
# Provides an ActiveRecord-like interface to a model whose data is not persisted to a database.
module StaticModel
extend ActiveSupport::Concern
module ClassMethods
# Used by ActiveRecord's polymorphic association to set object_id
def primary_key
'id'
end
# Used by ActiveRecord's polymorphic association to set object_type
def base_class
self
end
end
# Used by AR for fetching attributes
#
# Pass it along if we respond to it.
def [](key)
send(key) if respond_to?(key)
end
def to_param
id
end
def persisted?
false
end
def destroyed?
false
end
end