All Files
(71.98%
covered at
9.04
hits/line)
14 files in total.
257 relevant lines.
185 lines covered and
72 lines missed
Controllers
(60.77%
covered at
7.6
hits/line)
5 files in total.
181 relevant lines.
110 lines covered and
71 lines missed
Models
(98.25%
covered at
6.28
hits/line)
4 files in total.
57 relevant lines.
56 lines covered and
1 lines missed
Helpers
(100.0%
covered at
12.7
hits/line)
5 files in total.
19 relevant lines.
19 lines covered and
0 lines missed
Libraries
(100.0%
covered at
0.0
hits/line)
0 files in total.
0.0 relevant lines.
0.0 lines covered and
0.0 lines missed
File |
% covered |
Lines |
Relevant Lines |
Lines covered |
Lines missed |
Avg. Hits / Line |
Plugins
(100.0%
covered at
0.0
hits/line)
0 files in total.
0.0 relevant lines.
0.0 lines covered and
0.0 lines missed
File |
% covered |
Lines |
Relevant Lines |
Lines covered |
Lines missed |
Avg. Hits / Line |
-
1
class ApplicationController < ActionController::Base
-
1
protect_from_forgery
-
-
1
helper_method :abilities, :can?
-
-
1
protected
-
-
1
def abilities
-
145
@abilities ||= Six.new
-
end
-
-
1
def can?(object, action, subject)
-
45
abilities.allowed?(object, action, subject)
-
end
-
end
-
1
require "base64"
-
-
1
class CommitsController < ApplicationController
-
1
before_filter :project
-
-
# GET /commits
-
# GET /commits.json
-
1
def index
-
3
@repo = project.repo
-
3
@branch = params[:branch] || "master"
-
3
@commits = @repo.commits(@branch, params[:limit] || 100, params[:offset] || 0)
-
-
3
respond_to do |format|
-
3
format.html # index.html.erb
-
3
format.js
-
3
format.json { render json: @commits }
-
end
-
end
-
-
# GET /commits/1
-
# GET /commits/1.json
-
1
def show
-
1
@commit = project.repo.commits(params[:id]).first
-
-
1
respond_to do |format|
-
1
format.html # show.html.erb
-
1
format.json { render json: @commit }
-
end
-
end
-
-
1
protected
-
-
1
def project
-
8
@project ||= Project.find(params[:project_id])
-
end
-
end
-
1
class KeysController < ApplicationController
-
# GET /keys
-
# GET /keys.json
-
1
def index
-
@keys = Key.all
-
-
respond_to do |format|
-
format.html # index.html.erb
-
format.json { render json: @keys }
-
end
-
end
-
-
# GET /keys/1
-
# GET /keys/1.json
-
1
def show
-
@key = Key.find(params[:id])
-
-
respond_to do |format|
-
format.html # show.html.erb
-
format.json { render json: @key }
-
end
-
end
-
-
# GET /keys/new
-
# GET /keys/new.json
-
1
def new
-
@key = Key.new
-
-
respond_to do |format|
-
format.html # new.html.erb
-
format.json { render json: @key }
-
end
-
end
-
-
# GET /keys/1/edit
-
1
def edit
-
@key = Key.find(params[:id])
-
end
-
-
# POST /keys
-
# POST /keys.json
-
1
def create
-
@key = Key.new(params[:key])
-
-
respond_to do |format|
-
if @key.save
-
format.html { redirect_to @key, notice: 'Key was successfully created.' }
-
format.json { render json: @key, status: :created, location: @key }
-
else
-
format.html { render action: "new" }
-
format.json { render json: @key.errors, status: :unprocessable_entity }
-
end
-
end
-
end
-
-
# PUT /keys/1
-
# PUT /keys/1.json
-
1
def update
-
@key = Key.find(params[:id])
-
-
respond_to do |format|
-
if @key.update_attributes(params[:key])
-
format.html { redirect_to @key, notice: 'Key was successfully updated.' }
-
format.json { head :ok }
-
else
-
format.html { render action: "edit" }
-
format.json { render json: @key.errors, status: :unprocessable_entity }
-
end
-
end
-
end
-
-
# DELETE /keys/1
-
# DELETE /keys/1.json
-
1
def destroy
-
@key = Key.find(params[:id])
-
@key.destroy
-
-
respond_to do |format|
-
format.html { redirect_to keys_url }
-
format.json { head :ok }
-
end
-
end
-
end
-
1
class ProjectsController < ApplicationController
-
1
before_filter :authenticate_user!, :except => [:index, :show, :tree, :blob]
-
1
before_filter :project, :except => [:index, :new, :create]
-
-
# Authorize
-
1
before_filter :add_abilities
-
1
before_filter :authorize_read!, :except => [:index, :new, :create]
-
1
before_filter :authorize_admin!, :only => [:edit, :update, :destroy]
-
-
# GET /projects
-
# GET /projects.json
-
1
def index
-
43
@projects = if current_user
-
43
current_user.projects.all
-
else
-
Project.public_only.all
-
end
-
-
43
respond_to do |format|
-
43
format.html # index.html.erb
-
43
format.json { render json: @projects }
-
end
-
end
-
-
# GET /projects/1
-
# GET /projects/1.json
-
1
def show
-
17
@repo = project.repo
-
17
@commit = @repo.commits.first
-
17
@tree = @commit.tree
-
17
@tree = @tree / params[:path] if params[:path]
-
-
17
respond_to do |format|
-
17
format.html # show.html.erb
-
17
format.json { render json: project }
-
end
-
end
-
-
1
def tree
-
14
@repo = project.repo
-
14
if params[:commit_id]
-
7
@commit = @repo.commits(params[:commit_id]).first
-
else
-
7
@commit = @repo.commits.first
-
end
-
14
@tree = @commit.tree
-
14
@tree = @tree / params[:path] if params[:path]
-
-
14
respond_to do |format|
-
14
format.html # show.html.erb
-
14
format.js
-
14
format.json { render json: project }
-
end
-
end
-
-
1
def blob
-
2
@repo = project.repo
-
2
@commit = project.commit(params[:commit_id])
-
2
@tree = project.tree(@commit, params[:path])
-
-
2
if @tree.is_a?(Grit::Blob)
-
2
send_data(@tree.data, :type => @tree.mime_type, :disposition => 'inline')
-
end
-
end
-
-
# GET /projects/new
-
# GET /projects/new.json
-
1
def new
-
10
@project = Project.new
-
-
10
respond_to do |format|
-
10
format.html # new.html.erb
-
10
format.json { render json: @project }
-
end
-
end
-
-
# GET /projects/1/edit
-
1
def edit
-
end
-
-
# POST /projects
-
# POST /projects.json
-
1
def create
-
8
@project = Project.new(params[:project])
-
-
8
Project.transaction do
-
8
@project.save!
-
-
8
UsersProject.create!(:project => @project, :admin => true, :read => true,
-
:write => true, :user => current_user)
-
end
-
-
8
respond_to do |format|
-
8
if @project.valid?
-
16
format.html { redirect_to @project, notice: 'Project was successfully created.' }
-
8
format.json { render json: @project, status: :created, location: @project }
-
else
-
format.html { render action: "new" }
-
format.json { render json: @project.errors, status: :unprocessable_entity }
-
end
-
end
-
rescue StandardError => ex
-
@project.errors.add(:base, "Cant save project. Please try again later")
-
respond_to do |format|
-
format.html { render action: "new" }
-
format.json { render json: @project.errors, status: :unprocessable_entity }
-
end
-
end
-
-
# PUT /projects/1
-
# PUT /projects/1.json
-
1
def update
-
2
respond_to do |format|
-
2
if project.update_attributes(params[:project])
-
4
format.html { redirect_to project, notice: 'Project was successfully updated.' }
-
2
format.json { head :ok }
-
else
-
format.html { render action: "edit" }
-
format.json { render json: project.errors, status: :unprocessable_entity }
-
end
-
end
-
end
-
-
# DELETE /projects/1
-
# DELETE /projects/1.json
-
1
def destroy
-
project.destroy
-
-
respond_to do |format|
-
format.html { redirect_to projects_url }
-
format.json { head :ok }
-
end
-
end
-
-
1
protected
-
-
1
def add_abilities
-
100
abilities << Project
-
end
-
-
1
def project
-
125
@project ||= Project.find(params[:id])
-
end
-
-
1
def authorize_read!
-
39
head(404) unless can?(current_user, :read_project, project)
-
end
-
-
1
def authorize_admin!
-
6
head(404) unless can?(current_user, :admin_project, project)
-
end
-
end
-
1
class TeamMembersController < ApplicationController
-
1
before_filter :project
-
-
1
def show
-
@team_member = TeamMember.find(params[:id])
-
-
respond_to do |format|
-
format.html # show.html.erb
-
format.js
-
format.json { render json: @team_member }
-
end
-
end
-
-
# GET /team_members/new
-
# GET /team_members/new.json
-
1
def new
-
@team_member = project.users_projects.new
-
-
respond_to do |format|
-
format.html # new.html.erb
-
format.js
-
format.json { render json: @team_member }
-
end
-
end
-
-
# POST /team_members
-
# POST /team_members.json
-
1
def create
-
@team_member = project.users_projects.new(params[:team_member])
-
-
respond_to do |format|
-
if @team_member.save
-
format.html { redirect_to @team_member, notice: 'Team member was successfully created.' }
-
format.js
-
format.json { render json: @team_member, status: :created, location: @team_member }
-
else
-
format.html { render action: "new" }
-
format.js
-
format.json { render json: @team_member.errors, status: :unprocessable_entity }
-
end
-
end
-
end
-
-
# PUT /team_members/1
-
# PUT /team_members/1.json
-
#def update
-
#@team_member = TeamMember.find(params[:id])
-
-
#respond_to do |format|
-
#if @team_member.update_attributes(params[:team_member])
-
#format.html { redirect_to @team_member, notice: 'Team member was successfully updated.' }
-
#format.json { head :ok }
-
#else
-
#format.html { render action: "edit" }
-
#format.json { render json: @team_member.errors, status: :unprocessable_entity }
-
#end
-
#end
-
#end
-
-
# DELETE /team_members/1
-
# DELETE /team_members/1.json
-
1
def destroy
-
@team_member = UsersProject.find(params[:id])
-
@team_member.destroy
-
-
respond_to do |format|
-
format.html { redirect_to team_members_url }
-
format.json { head :ok }
-
format.js { render :nothing => true }
-
end
-
end
-
-
-
1
protected
-
-
1
def project
-
@project ||= Project.find(params[:project_id])
-
end
-
end
-
1
module ApplicationHelper
-
end
-
1
module CommitsHelper
-
1
def diff_line(line, line_new = 0, line_old = 0)
-
176
full_line = html_escape(line.gsub(/\n/, ''))
-
176
color = if line[0] == "+"
-
70
full_line = "<span class=\"old_line\"> </span><span class=\"new_line\">#{line_new}</span> " + full_line
-
70
"#DFD"
-
elsif line[0] == "-"
-
26
full_line = "<span class=\"old_line\">#{line_old}</span><span class=\"new_line\"> </span> " + full_line
-
26
"#FDD"
-
else
-
80
full_line = "<span class=\"old_line\">#{line_old}</span><span class=\"new_line\">#{line_new}</span> " + full_line
-
80
"none"
-
end
-
-
176
raw "<div style=\"white-space:pre;background:#{color};\">#{full_line}</div>"
-
end
-
-
1
def more_commits_link
-
3
offset = params[:offset] || 0
-
3
limit = params[:limit] || 100
-
3
link_to "More", project_commits_path(@project, :offset => offset.to_i + limit.to_i, :limit => limit),
-
:remote => true, :class => "button", :style => "text-align:center; width:95%; ", :id => "more-commits-link"
-
end
-
end
-
1
module ProjectsHelper
-
end
-
1
module TeamMembersHelper
-
end
-
1
class Key < ActiveRecord::Base
-
1
belongs_to :user
-
end
-
1
require "grit"
-
-
1
class Project < ActiveRecord::Base
-
1
has_many :users_projects, :dependent => :destroy
-
1
has_many :users, :through => :users_projects
-
-
1
validates_presence_of :name
-
1
validates_presence_of :path
-
-
1
before_save :valid_repo?
-
-
1
scope :public_only, where(:private_flag => false)
-
-
1
def self.allowed(user, project)
-
157
return [] unless project.instance_of?(Project)
-
-
51
rules = []
-
rules << :read_project if project.public? ||
-
51
project.readers.include?(user)
-
-
51
rules << :write_project if project.writers.include?(user)
-
51
rules << :admin_project if project.admins.include?(user)
-
51
rules
-
end
-
-
1
def add_access(user, *access)
-
27
opts = { :project => self, :user => user }
-
58
access.each { |name| opts.merge!(name => true) }
-
27
UsersProject.create(opts)
-
end
-
-
1
def writers
-
51
users_projects.includes(:user).where(:write => true).map(&:user)
-
end
-
-
1
def readers
-
51
users_projects.includes(:user).where(:read => true).map(&:user)
-
end
-
-
1
def admins
-
51
users_projects.includes(:user).where(:admin => true).map(&:user)
-
end
-
-
1
def public?
-
51
!private_flag
-
end
-
-
1
def private?
-
private_flag
-
end
-
-
1
def valid_repo?
-
58
repo
-
rescue
-
1
errors.add(:path, "Invalid repository path")
-
1
false
-
end
-
-
1
def repo
-
112
@repo ||= Grit::Repo.new(path)
-
end
-
-
1
def commit(commit_id = nil)
-
9
if commit_id
-
8
repo.commits(commit_id).first
-
else
-
1
repo.commits.first
-
end
-
end
-
-
1
def tree(fcommit, path = nil)
-
5
fcommit = commit if fcommit == :head
-
5
tree = fcommit.tree
-
5
path ? (tree / path) : tree
-
end
-
end
-
1
class User < ActiveRecord::Base
-
# Include default devise modules. Others available are:
-
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
-
1
devise :database_authenticatable, :registerable,
-
:recoverable, :rememberable, :trackable, :validatable
-
-
# Setup accessible (or protected) attributes for your model
-
1
attr_accessible :email, :password, :password_confirmation, :remember_me
-
-
1
has_many :users_projects, :dependent => :destroy
-
1
has_many :projects, :through => :users_projects
-
1
has_many :keys, :dependent => :destroy
-
end
-
1
class UsersProject < ActiveRecord::Base
-
1
belongs_to :user
-
1
belongs_to :project
-
-
1
validates_uniqueness_of :user_id, :scope => [:project_id]
-
1
validates_presence_of :user_id
-
1
validates_presence_of :project_id
-
end