Merge pull request #357 from warpc/263-refactoring
[Refs #263] Big lib code cleanup * Upgrade gems; * Upgrade FactoryGirl syntax; * Move code out from vendor/plugins, redo plugins structure; * Fix all deprecations; * Great refactor for lib and initializers folders; * Add magic encodings; * Fix some specs.
This commit is contained in:
commit
5aca4a0ea9
13
Gemfile
13
Gemfile
|
@ -22,8 +22,9 @@ gem 'jbuilder'
|
|||
|
||||
# gem 'rugged', '~> 0.16.0'
|
||||
gem 'grack', :git => 'git://github.com/rdblue/grack.git', :require => 'git_http'
|
||||
gem "grit", :git => 'git://github.com/chipiga/grit.git' #, :path => '~/Sites/code/grit'
|
||||
gem "grit", :git => 'git://github.com/warpc/grit.git' #, :path => '~/Sites/code/grit'
|
||||
gem 'charlock_holmes', '~> 0.6.8' #, :git => 'git://github.com/brianmario/charlock_holmes.git', :branch => 'bundle-icu'
|
||||
gem 'diff-display', '~> 0.0.1'
|
||||
|
||||
# Wiki
|
||||
gem "gollum", "1.3.1"
|
||||
|
@ -34,7 +35,7 @@ gem 'rdiscount'
|
|||
gem 'RedCloth'
|
||||
gem 'wikicloth'
|
||||
|
||||
gem 'unicorn', '~> 4.2.0', :platforms => [:mri, :rbx]
|
||||
gem 'unicorn', '~> 4.2.1', :platforms => [:mri, :rbx]
|
||||
gem 'trinidad', '~> 1.0.2', :platforms => :jruby
|
||||
gem 'newrelic_rpm', '~> 3.3.2', :platforms => [:mri, :rbx]
|
||||
gem 'whenever', '~> 0.7.3', :require => false
|
||||
|
@ -49,8 +50,8 @@ group :assets do
|
|||
gem 'sass-rails', '~> 3.2.5'
|
||||
gem 'coffee-rails', '~> 3.2.2'
|
||||
gem 'compass-rails', '~> 1.0.1'
|
||||
gem 'uglifier', '~> 1.2.1'
|
||||
gem 'therubyracer', '~> 0.9.10', :platforms => [:mri, :rbx]
|
||||
gem 'uglifier', '~> 1.2.4'
|
||||
gem 'therubyracer', '~> 0.10.0', :platforms => [:mri, :rbx]
|
||||
gem 'therubyrhino', '~> 1.73.1', :platforms => :jruby
|
||||
end
|
||||
|
||||
|
@ -72,8 +73,8 @@ group :development do
|
|||
end
|
||||
|
||||
group :test do
|
||||
gem 'rspec-rails', '~> 2.8.1'
|
||||
gem 'factory_girl_rails', '~> 1.7.0'
|
||||
gem 'rspec-rails', '~> 2.9.0', :group => 'development'
|
||||
gem 'factory_girl_rails', '~> 3.0.0'
|
||||
gem 'rr', '~> 1.0.4'
|
||||
gem 'shoulda'
|
||||
end
|
||||
|
|
76
Gemfile.lock
76
Gemfile.lock
|
@ -1,12 +1,3 @@
|
|||
GIT
|
||||
remote: git://github.com/chipiga/grit.git
|
||||
revision: 696b0967cb7e6bac044569d898e5acef431d4f97
|
||||
specs:
|
||||
grit (2.4.1)
|
||||
diff-lcs (~> 1.1)
|
||||
mime-types (~> 1.15)
|
||||
posix-spawn (~> 0.3.6)
|
||||
|
||||
GIT
|
||||
remote: git://github.com/chipiga/redhillonrails_core.git
|
||||
revision: 5f58167c41882890c223168b0a5521d99e8d92aa
|
||||
|
@ -21,6 +12,15 @@ GIT
|
|||
specs:
|
||||
grack (0.2.0)
|
||||
|
||||
GIT
|
||||
remote: git://github.com/warpc/grit.git
|
||||
revision: 696b0967cb7e6bac044569d898e5acef431d4f97
|
||||
specs:
|
||||
grit (2.4.1)
|
||||
diff-lcs (~> 1.1)
|
||||
mime-types (~> 1.15)
|
||||
posix-spawn (~> 0.3.6)
|
||||
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
|
@ -108,6 +108,7 @@ GEM
|
|||
orm_adapter (~> 0.0.3)
|
||||
railties (~> 3.1)
|
||||
warden (~> 1.1.1)
|
||||
diff-display (0.0.1)
|
||||
diff-lcs (1.1.3)
|
||||
erubis (2.7.0)
|
||||
eventmachine (0.12.10)
|
||||
|
@ -115,10 +116,10 @@ GEM
|
|||
execjs (1.3.0)
|
||||
multi_json (~> 1.0)
|
||||
expression_parser (0.9.0)
|
||||
factory_girl (2.6.4)
|
||||
activesupport (>= 2.3.9)
|
||||
factory_girl_rails (1.7.0)
|
||||
factory_girl (~> 2.6.0)
|
||||
factory_girl (3.0.0)
|
||||
activesupport (>= 3.0.0)
|
||||
factory_girl_rails (3.0.0)
|
||||
factory_girl (~> 3.0.0)
|
||||
railties (>= 3.0.0)
|
||||
fssm (0.2.8.1)
|
||||
github-markup (0.7.1)
|
||||
|
@ -150,15 +151,15 @@ GEM
|
|||
railties (>= 3.2.0, < 5.0)
|
||||
thor (~> 0.14)
|
||||
jruby-rack (1.1.4)
|
||||
json (1.6.5)
|
||||
json (1.6.5-java)
|
||||
kgio (2.7.3)
|
||||
json (1.6.6)
|
||||
json (1.6.6-java)
|
||||
kgio (2.7.4)
|
||||
libv8 (3.3.10.4)
|
||||
mail (2.4.4)
|
||||
i18n (>= 0.4.0)
|
||||
mime-types (~> 1.16)
|
||||
treetop (~> 1.4.8)
|
||||
mailcatcher (0.5.5)
|
||||
mailcatcher (0.5.6)
|
||||
activesupport (~> 3.0)
|
||||
eventmachine (~> 0.12)
|
||||
haml (~> 3.1)
|
||||
|
@ -170,7 +171,7 @@ GEM
|
|||
meta-tags (1.2.6)
|
||||
actionpack
|
||||
mime-types (1.18)
|
||||
multi_json (1.1.0)
|
||||
multi_json (1.2.0)
|
||||
mustache (0.99.4)
|
||||
net-scp (1.0.4)
|
||||
net-ssh (>= 1.99.1)
|
||||
|
@ -188,7 +189,7 @@ GEM
|
|||
omniauth-openid (1.0.1)
|
||||
omniauth (~> 1.0)
|
||||
rack-openid (~> 1.3.1)
|
||||
orm_adapter (0.0.6)
|
||||
orm_adapter (0.0.7)
|
||||
paperclip (2.7.0)
|
||||
activerecord (>= 2.3.0)
|
||||
activesupport (>= 2.3.2)
|
||||
|
@ -235,19 +236,19 @@ GEM
|
|||
json (~> 1.4)
|
||||
redcarpet (1.17.2)
|
||||
rr (1.0.4)
|
||||
rspec (2.8.0)
|
||||
rspec-core (~> 2.8.0)
|
||||
rspec-expectations (~> 2.8.0)
|
||||
rspec-mocks (~> 2.8.0)
|
||||
rspec-core (2.8.0)
|
||||
rspec-expectations (2.8.0)
|
||||
diff-lcs (~> 1.1.2)
|
||||
rspec-mocks (2.8.0)
|
||||
rspec-rails (2.8.1)
|
||||
rspec (2.9.0)
|
||||
rspec-core (~> 2.9.0)
|
||||
rspec-expectations (~> 2.9.0)
|
||||
rspec-mocks (~> 2.9.0)
|
||||
rspec-core (2.9.0)
|
||||
rspec-expectations (2.9.0)
|
||||
diff-lcs (~> 1.1.3)
|
||||
rspec-mocks (2.9.0)
|
||||
rspec-rails (2.9.0)
|
||||
actionpack (>= 3.0)
|
||||
activesupport (>= 3.0)
|
||||
railties (>= 3.0)
|
||||
rspec (~> 2.8.0)
|
||||
rspec (~> 2.9.0)
|
||||
ruby-openid (2.1.8)
|
||||
russian (0.6.0)
|
||||
i18n (>= 0.5.0)
|
||||
|
@ -278,7 +279,7 @@ GEM
|
|||
tilt (~> 1.1, != 1.3.0)
|
||||
sqlite3 (1.3.5)
|
||||
state_machine (1.1.2)
|
||||
therubyracer (0.9.10)
|
||||
therubyracer (0.10.0)
|
||||
libv8 (~> 3.3.10)
|
||||
therubyrhino (1.73.1)
|
||||
thin (1.3.1)
|
||||
|
@ -295,10 +296,10 @@ GEM
|
|||
trinidad_jars (>= 0.3.0)
|
||||
trinidad_jars (1.0.2)
|
||||
tzinfo (0.3.32)
|
||||
uglifier (1.2.3)
|
||||
uglifier (1.2.4)
|
||||
execjs (>= 0.3.0)
|
||||
multi_json (>= 1.0.2)
|
||||
unicorn (4.2.0)
|
||||
unicorn (4.2.1)
|
||||
kgio (~> 2.6)
|
||||
rack
|
||||
raindrops (~> 0.7)
|
||||
|
@ -332,7 +333,8 @@ DEPENDENCIES
|
|||
daemons (= 1.1.6)
|
||||
delayed_job_active_record (~> 0.3.2)
|
||||
devise (~> 2.0.4)
|
||||
factory_girl_rails (~> 1.7.0)
|
||||
diff-display (~> 0.0.1)
|
||||
factory_girl_rails (~> 3.0.0)
|
||||
gollum (= 1.3.1)
|
||||
grack!
|
||||
grit!
|
||||
|
@ -355,16 +357,16 @@ DEPENDENCIES
|
|||
redcarpet (= 1.17.2)
|
||||
redhillonrails_core!
|
||||
rr (~> 1.0.4)
|
||||
rspec-rails (~> 2.8.1)
|
||||
rspec-rails (~> 2.9.0)
|
||||
russian (~> 0.6.0)
|
||||
sass-rails (~> 3.2.5)
|
||||
shotgun
|
||||
shoulda
|
||||
therubyracer (~> 0.9.10)
|
||||
therubyracer (~> 0.10.0)
|
||||
therubyrhino (~> 1.73.1)
|
||||
trinidad (~> 1.0.2)
|
||||
uglifier (~> 1.2.1)
|
||||
unicorn (~> 4.2.0)
|
||||
uglifier (~> 1.2.4)
|
||||
unicorn (~> 4.2.1)
|
||||
whenever (~> 0.7.3)
|
||||
wikicloth
|
||||
will_paginate (~> 3.0.3)
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
Rails.application.config.generators do |g|
|
||||
g.test_framework = :rspec
|
||||
end
|
|
@ -5,5 +5,14 @@
|
|||
# Mime::Type.register "text/richtext", :rtf
|
||||
# Mime::Type.register_alias "text/html", :iphone
|
||||
|
||||
Mime::Type.register "text/plain", :diff
|
||||
Mime::Type.register "text/plain", :patch
|
||||
Mime::Type.register "text/plain", 'diff'
|
||||
Mime::Type.register "text/plain", 'patch'
|
||||
|
||||
# add rpm spec as mime type for *.spec files
|
||||
[["text/x-python", ['py'], '8bit'],
|
||||
["text/x-rpm-spec", ['spec'], '8bit'],
|
||||
["text/x-csrc", ['h', 'c'], '8bit'],
|
||||
["text/x-c++src", ['cpp'], '8bit']
|
||||
].each do |type|
|
||||
MIME::Types.add MIME::Type.from_array(type)
|
||||
end
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
require './lib/rosa_presenter/rosa_presenter'
|
|
@ -1,35 +1,12 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
APP_CONFIG = YAML.load_file("#{Rails.root}/config/application.yml")[Rails.env]
|
||||
|
||||
Dir[Rails.root.join("lib/ext/**/*.rb")].each {|f| require f}
|
||||
require 'modules'
|
||||
require 'plugins'
|
||||
|
||||
# Setup Smart HTTP GRack
|
||||
require 'grack'
|
||||
config = {:project_root => File.join(APP_CONFIG['root_path'], 'git_projects'), :git_path => 'git', :upload_pack => true, :receive_pack => true}
|
||||
# Rosa::Application.config.middleware.insert_before 0, ::Grack::Handler, config
|
||||
Rosa::Application.config.middleware.insert_after ::Rails::Rack::Logger, ::Grack::Handler, config
|
||||
Rosa::Application.config.middleware.insert_before ::Grack::Handler, ::Grack::Auth
|
||||
|
||||
Grit::Git.git_timeout = 60
|
||||
# Grit.debug = true
|
||||
GAP_REPO_PATH = '/tmp/gap_repo.git'
|
||||
unless File.directory? GAP_REPO_PATH
|
||||
Grit::Repo.init_bare(GAP_REPO_PATH)
|
||||
# FileUtils.chmod "a-w", GAP_REPO_PATH
|
||||
end
|
||||
|
||||
Dir[Rails.root.join("lib/ext/**/*.rb")].each {|f| require f}
|
||||
|
||||
# add rpm spec as mime type for *.spec files
|
||||
types = [
|
||||
["text/x-python", ['py'], '8bit'],
|
||||
["text/x-rpm-spec", ['spec'], '8bit'],
|
||||
["text/x-csrc", ['h', 'c'], '8bit'],
|
||||
["text/x-c++src", ['cpp'], '8bit']
|
||||
]
|
||||
types.each do |type|
|
||||
MIME::Types.add MIME::Type.from_array(type)
|
||||
end
|
||||
|
||||
# load datatables plugin
|
||||
require Rails.root.join("lib/rails_datatables")
|
|
@ -1,3 +1,4 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class AddConfirmableToUsers < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :users, :confirmation_token, :string
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class ConfirmAllRegisteredUsers < ActiveRecord::Migration
|
||||
def up
|
||||
User.all.each { |user| user.confirm! }
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class RemoveAutoBuildList < ActiveRecord::Migration
|
||||
def self.up
|
||||
drop_table :auto_build_lists
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class DeleteCategories < ActiveRecord::Migration
|
||||
def self.up
|
||||
remove_column :projects, :category_id
|
||||
|
|
10
db/schema.rb
10
db/schema.rb
|
@ -1,4 +1,4 @@
|
|||
# encoding: UTF-8
|
||||
# -*- encoding : utf-8 -*-
|
||||
# This file is auto-generated from the current state of the database. Instead
|
||||
# of editing this file, please use the migrations feature of Active Record to
|
||||
# incrementally modify your database, and then regenerate this schema definition.
|
||||
|
@ -17,8 +17,8 @@ ActiveRecord::Schema.define(:version => 20120329182602) do
|
|||
t.integer "user_id", :null => false
|
||||
t.string "kind"
|
||||
t.text "data"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "arches", :force => true do |t|
|
||||
|
@ -351,16 +351,16 @@ ActiveRecord::Schema.define(:version => 20120329182602) do
|
|||
t.string "name"
|
||||
t.string "email", :default => "", :null => false
|
||||
t.string "encrypted_password", :limit => 128, :default => "", :null => false
|
||||
t.string "password_salt", :default => "", :null => false
|
||||
t.string "reset_password_token"
|
||||
t.datetime "remember_created_at"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.text "ssh_key"
|
||||
t.string "uname"
|
||||
t.string "role"
|
||||
t.string "language", :default => "en"
|
||||
t.integer "own_projects_count", :default => 0, :null => false
|
||||
t.datetime "reset_password_sent_at"
|
||||
t.integer "own_projects_count", :default => 0, :null => false
|
||||
t.text "professional_experience"
|
||||
t.string "site"
|
||||
t.string "company"
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
# # -*- encoding : utf-8 -*-
|
||||
module Gollum
|
||||
class Wiki
|
||||
# Public: Applies a reverse diff for a given page. If only 1 SHA is given,
|
|
@ -1,6 +1,4 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
# -*- ruby encoding: utf-8 -*-
|
||||
|
||||
module Grit
|
||||
class Blob
|
||||
|
||||
|
@ -48,3 +46,11 @@ module Grit
|
|||
|
||||
end
|
||||
end
|
||||
|
||||
Grit::Git.git_timeout = 60
|
||||
# Grit.debug = true
|
||||
GAP_REPO_PATH = '/tmp/gap_repo.git'
|
||||
unless File.directory? GAP_REPO_PATH
|
||||
Grit::Repo.init_bare(GAP_REPO_PATH)
|
||||
# FileUtils.chmod "a-w", GAP_REPO_PATH
|
||||
end
|
|
@ -6,7 +6,5 @@ module Modules
|
|||
|
||||
module Models
|
||||
extend ActiveSupport::Autoload
|
||||
|
||||
autoload :Owner
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,9 +8,6 @@ module Modules
|
|||
after_create lambda { relations.create :object_id => owner.id, :object_type => owner.class.to_s, :role => 'admin' }
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,6 @@ module Modules
|
|||
after_create :create_personal_repository
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def create_personal_repository
|
||||
pl = platforms.build
|
||||
pl.owner = self
|
||||
|
@ -32,7 +31,6 @@ module Modules
|
|||
def personal_repository
|
||||
personal_platform.repositories.first
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
end
|
||||
|
|
|
@ -18,9 +18,6 @@ module Modules
|
|||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
Dir[File.join(File.dirname(__FILE__), 'plugins', '*.rb')].each do |f|
|
||||
$:.unshift File.dirname(f)
|
||||
require f
|
||||
end
|
|
@ -1,3 +1,4 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
require Rails.root.join('lib/rails_datatables/rails_datatables')
|
||||
require_relative 'rails_datatables/rails_datatables'
|
||||
|
||||
ActionView::Base.send :include, RailsDatatables
|
|
@ -0,0 +1,17 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
module RelatedModels
|
||||
extend ActiveSupport::Autoload
|
||||
|
||||
autoload :ClassMethods
|
||||
autoload :BelongsToHelpers
|
||||
autoload :PolymorphicHelpers
|
||||
autoload :UrlHelpers
|
||||
autoload :Base
|
||||
end
|
||||
|
||||
class ActionController::Base
|
||||
#include ClassMethods
|
||||
def self.is_related_controller!
|
||||
RelatedModels::Base.is_child!(self)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
module RosaPresenter
|
||||
extend ActiveSupport::Autoload
|
||||
|
||||
autoload :Activation
|
||||
autoload :Base
|
||||
|
||||
VERSION = "0.0.1"
|
||||
end
|
||||
|
||||
ActionController::Base.send(:include, RosaPresenter::Activation)
|
|
@ -13,5 +13,3 @@ module RosaPresenter
|
|||
end
|
||||
end
|
||||
end
|
||||
ActionController::Base.send(:include, RosaPresenter::Activation)
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
require File.dirname(__FILE__) + "/lib/activation"
|
||||
require File.dirname(__FILE__) + "/lib/base"
|
||||
|
||||
module RosaPresenter
|
||||
VERSION = "0.0.1"
|
||||
end
|
|
@ -68,7 +68,7 @@ describe BuildListsController do
|
|||
|
||||
context 'crud' do
|
||||
before(:each) do
|
||||
platform = Factory(:platform_with_repos)
|
||||
platform = FactoryGirl.create(:platform_with_repos)
|
||||
@create_params = {
|
||||
:build_list => {
|
||||
:project_version => 'latest_master',
|
||||
|
@ -76,7 +76,7 @@ describe BuildListsController do
|
|||
:update_type => 'security',
|
||||
:include_repos => [platform.repositories.first.id]
|
||||
},
|
||||
:arches => [Factory(:arch).id],
|
||||
:arches => [FactoryGirl.create(:arch).id],
|
||||
:bpls => [platform.id]
|
||||
}
|
||||
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
||||
|
@ -91,24 +91,24 @@ describe BuildListsController do
|
|||
|
||||
context 'for user' do
|
||||
before(:each) do
|
||||
@build_list = Factory(:build_list_core)
|
||||
@build_list = FactoryGirl.create(:build_list_core)
|
||||
@project = @build_list.project
|
||||
@owner_user = @project.owner
|
||||
@member_user = Factory(:user)
|
||||
@member_user = FactoryGirl.create(:user)
|
||||
rel = @project.relations.build(:role => 'reader')
|
||||
rel.object = @member_user
|
||||
rel.save
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@show_params = {:project_id => @project.id, :id => @build_list.id}
|
||||
end
|
||||
|
||||
context 'for all build lists' do
|
||||
before(:each) do
|
||||
@build_list1 = Factory(:build_list_core)
|
||||
@build_list2 = Factory(:build_list_core, :project => Factory(:project, :visibility => 'hidden'))
|
||||
@build_list3 = Factory(:build_list_core, :project => Factory(:project, :owner => @user, :visibility => 'hidden'))
|
||||
@build_list4 = Factory(:build_list_core, :project => Factory(:project, :visibility => 'hidden'))
|
||||
@build_list1 = FactoryGirl.create(:build_list_core)
|
||||
@build_list2 = FactoryGirl.create(:build_list_core, :project => FactoryGirl.create(:project, :visibility => 'hidden'))
|
||||
@build_list3 = FactoryGirl.create(:build_list_core, :project => FactoryGirl.create(:project, :owner => @user, :visibility => 'hidden'))
|
||||
@build_list4 = FactoryGirl.create(:build_list_core, :project => FactoryGirl.create(:project, :visibility => 'hidden'))
|
||||
@build_list4.project.relations.create :role => 'reader', :object_id => @user.id, :object_type => 'User'
|
||||
end
|
||||
|
||||
|
@ -168,21 +168,21 @@ describe BuildListsController do
|
|||
|
||||
context 'for group' do
|
||||
before(:each) do
|
||||
@owner_group = Factory(:group)
|
||||
@owner_user = Factory(:user)
|
||||
@owner_group = FactoryGirl.create(:group)
|
||||
@owner_user = FactoryGirl.create(:user)
|
||||
@owner_group.objects.create :role => 'reader', :object_id => @owner_user.id, :object_type => 'User'
|
||||
@member_group = Factory(:group)
|
||||
@member_user = Factory(:user)
|
||||
@member_group = FactoryGirl.create(:group)
|
||||
@member_user = FactoryGirl.create(:user)
|
||||
@member_group.objects.create :role => 'reader', :object_id => @member_user.id, :object_type => 'User'
|
||||
|
||||
@group = Factory(:group)
|
||||
@user = Factory(:user)
|
||||
@group = FactoryGirl.create(:group)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@group.objects.create :role => 'reader', :object_id => @user.id, :object_type => 'User'
|
||||
|
||||
@project = Factory(:project, :owner => @owner_group)
|
||||
@project = FactoryGirl.create(:project, :owner => @owner_group)
|
||||
@project.relations.create :role => 'reader', :object_id => @member_group.id, :object_type => 'Group'
|
||||
|
||||
@build_list = Factory(:build_list_core, :project => @project)
|
||||
@build_list = FactoryGirl.create(:build_list_core, :project => @project)
|
||||
|
||||
set_session_for(@user)
|
||||
@show_params = {:project_id => @project.id, :id => @build_list.id}
|
||||
|
@ -190,10 +190,10 @@ describe BuildListsController do
|
|||
|
||||
context 'for all build lists' do
|
||||
before(:each) do
|
||||
@build_list1 = Factory(:build_list_core)
|
||||
@build_list2 = Factory(:build_list_core, :project => Factory(:project, :visibility => 'hidden'))
|
||||
@build_list3 = Factory(:build_list_core, :project => Factory(:project, :owner => @group, :visibility => 'hidden'))
|
||||
@build_list4 = Factory(:build_list_core, :project => Factory(:project, :visibility => 'hidden'))
|
||||
@build_list1 = FactoryGirl.create(:build_list_core)
|
||||
@build_list2 = FactoryGirl.create(:build_list_core, :project => FactoryGirl.create(:project, :visibility => 'hidden'))
|
||||
@build_list3 = FactoryGirl.create(:build_list_core, :project => FactoryGirl.create(:project, :owner => @group, :visibility => 'hidden'))
|
||||
@build_list4 = FactoryGirl.create(:build_list_core, :project => FactoryGirl.create(:project, :visibility => 'hidden'))
|
||||
@build_list4.project.relations.create :role => 'reader', :object_id => @group.id, :object_type => 'Group'
|
||||
end
|
||||
|
||||
|
@ -253,7 +253,7 @@ describe BuildListsController do
|
|||
end
|
||||
|
||||
context 'for admin' do
|
||||
before(:each) { set_session_for Factory(:admin) }
|
||||
before(:each) { set_session_for FactoryGirl.create(:admin) }
|
||||
|
||||
it "should be able to perform index action without exception" do
|
||||
any_instance_of(XMLRPC::Client) do |xml_rpc|
|
||||
|
@ -271,12 +271,12 @@ describe BuildListsController do
|
|||
context 'filter' do
|
||||
|
||||
before(:each) do
|
||||
set_session_for Factory(:admin)
|
||||
set_session_for FactoryGirl.create(:admin)
|
||||
|
||||
@build_list1 = Factory(:build_list_core)
|
||||
@build_list2 = Factory(:build_list_core)
|
||||
@build_list3 = Factory(:build_list_core)
|
||||
@build_list4 = Factory(:build_list_core, :created_at => (Time.now - 1.day),
|
||||
@build_list1 = FactoryGirl.create(:build_list_core)
|
||||
@build_list2 = FactoryGirl.create(:build_list_core)
|
||||
@build_list3 = FactoryGirl.create(:build_list_core)
|
||||
@build_list4 = FactoryGirl.create(:build_list_core, :created_at => (Time.now - 1.day),
|
||||
:project => @build_list3.project, :pl => @build_list3.pl,
|
||||
:arch => @build_list3.arch)
|
||||
end
|
||||
|
@ -310,7 +310,7 @@ describe BuildListsController do
|
|||
end
|
||||
|
||||
context 'callbacks' do
|
||||
let(:build_list) { Factory(:build_list_core) }
|
||||
let(:build_list) { FactoryGirl.create(:build_list_core) }
|
||||
|
||||
describe 'publish_build' do
|
||||
before { test_git_commit(build_list.project); build_list.update_attribute :commit_hash, build_list.project.git_repository.commits('master').last.id }
|
||||
|
|
|
@ -38,8 +38,8 @@ end
|
|||
describe CollaboratorsController do
|
||||
before(:each) do
|
||||
stub_rsync_methods
|
||||
@project = Factory(:project)
|
||||
@another_user = Factory(:user)
|
||||
@project = FactoryGirl.create(:project)
|
||||
@another_user = FactoryGirl.create(:user)
|
||||
@update_params = {:user => {@another_user.id => :reader}}
|
||||
end
|
||||
|
||||
|
@ -57,7 +57,7 @@ describe CollaboratorsController do
|
|||
|
||||
context 'for global admin' do
|
||||
before(:each) do
|
||||
@admin = Factory(:admin)
|
||||
@admin = FactoryGirl.create(:admin)
|
||||
set_session_for(@admin)
|
||||
end
|
||||
|
||||
|
@ -66,10 +66,10 @@ describe CollaboratorsController do
|
|||
|
||||
context 'for admin user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@user.relations
|
||||
set_session_for(@user)
|
||||
@group = Factory(:group)
|
||||
@group = FactoryGirl.create(:group)
|
||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||
end
|
||||
|
||||
|
@ -91,7 +91,7 @@ describe CollaboratorsController do
|
|||
|
||||
context 'for owner user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@project.update_attribute(:owner, @user)
|
||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||
|
@ -102,7 +102,7 @@ describe CollaboratorsController do
|
|||
|
||||
context 'for reader user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@project.update_attribute(:owner, @user)
|
||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
||||
|
@ -113,7 +113,7 @@ describe CollaboratorsController do
|
|||
|
||||
context 'for writer user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@project.update_attribute(:owner, @user)
|
||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
|
||||
|
|
|
@ -79,7 +79,7 @@ end
|
|||
describe CommentsController do
|
||||
before(:each) do
|
||||
stub_rsync_methods
|
||||
@project = Factory(:project)
|
||||
@project = FactoryGirl.create(:project)
|
||||
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.git_repository.path}) # maybe FIXME ?
|
||||
@commit = @project.git_repository.commits.first
|
||||
|
||||
|
@ -87,8 +87,8 @@ describe CommentsController do
|
|||
@update_params = {:comment => {:body => 'updated'}, :project_id => @project.id, :commit_id => @commit.id}
|
||||
|
||||
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
||||
@stranger_comment = create_comment Factory(:user)
|
||||
@user = Factory(:user)
|
||||
@stranger_comment = create_comment FactoryGirl.create(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@own_comment = create_comment @user
|
||||
set_session_for(@user)
|
||||
end
|
||||
|
|
|
@ -74,18 +74,18 @@ describe CommentsController do
|
|||
before(:each) do
|
||||
stub_rsync_methods
|
||||
|
||||
@project = Factory(:project)
|
||||
@issue = Factory(:issue, :project_id => @project.id, :creator => Factory(:user))
|
||||
@comment = Factory(:comment, :commentable => @issue, :project_id => @project.id)
|
||||
@project = FactoryGirl.create(:project)
|
||||
@issue = FactoryGirl.create(:issue, :project_id => @project.id, :creator => FactoryGirl.create(:user))
|
||||
@comment = FactoryGirl.create(:comment, :commentable => @issue, :project_id => @project.id)
|
||||
|
||||
@create_params = {:comment => {:body => 'I am a comment!'}, :project_id => @project.id, :issue_id => @issue.serial_id}
|
||||
@update_params = {:comment => {:body => 'updated'}, :project_id => @project.id, :issue_id => @issue.serial_id}
|
||||
|
||||
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
||||
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@own_comment = Factory(:comment, :commentable => @issue, :user => @user, :project_id => @project.id)
|
||||
@own_comment = FactoryGirl.create(:comment, :commentable => @issue, :user => @user, :project_id => @project.id)
|
||||
end
|
||||
|
||||
context 'for project admin user' do
|
||||
|
|
|
@ -70,8 +70,8 @@ end
|
|||
describe GroupsController do
|
||||
before(:each) do
|
||||
stub_rsync_methods
|
||||
@group = Factory(:group)
|
||||
@another_user = Factory(:user)
|
||||
@group = FactoryGirl.create(:group)
|
||||
@another_user = FactoryGirl.create(:user)
|
||||
@create_params = {:group => {:description => 'grp1', :uname => 'un_grp1'}}
|
||||
@update_params = {:group => {:description => 'grp2'}}
|
||||
end
|
||||
|
@ -95,7 +95,7 @@ describe GroupsController do
|
|||
|
||||
context 'for global admin' do
|
||||
before(:each) do
|
||||
@admin = Factory(:admin)
|
||||
@admin = FactoryGirl.create(:admin)
|
||||
set_session_for(@admin)
|
||||
end
|
||||
|
||||
|
@ -115,7 +115,7 @@ describe GroupsController do
|
|||
|
||||
context 'for group admin' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||
end
|
||||
|
@ -127,7 +127,7 @@ describe GroupsController do
|
|||
|
||||
context 'for group owner' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@group.update_attribute(:owner, @user)
|
||||
@group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||
|
@ -139,7 +139,7 @@ describe GroupsController do
|
|||
|
||||
context 'for group reader and writer user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
||||
end
|
||||
|
|
|
@ -75,12 +75,12 @@ describe IssuesController do
|
|||
before(:each) do
|
||||
stub_rsync_methods
|
||||
|
||||
@project = Factory(:project)
|
||||
@issue_user = Factory(:user)
|
||||
@project = FactoryGirl.create(:project)
|
||||
@issue_user = FactoryGirl.create(:user)
|
||||
|
||||
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
||||
|
||||
@issue = Factory(:issue, :project_id => @project.id, :user_id => @issue_user.id)
|
||||
@issue = FactoryGirl.create(:issue, :project_id => @project.id, :user_id => @issue_user.id)
|
||||
@create_params = {
|
||||
:project_id => @project.id,
|
||||
:issue => {
|
||||
|
@ -98,13 +98,13 @@ describe IssuesController do
|
|||
}
|
||||
}
|
||||
|
||||
@project_with_turned_off_issues = Factory(:project, :has_issues => false)
|
||||
@turned_of_issue = Factory(:issue, :project_id => @project_with_turned_off_issues.id, :user_id => @issue_user.id)
|
||||
@project_with_turned_off_issues = FactoryGirl.create(:project, :has_issues => false)
|
||||
@turned_of_issue = FactoryGirl.create(:issue, :project_id => @project_with_turned_off_issues.id, :user_id => @issue_user.id)
|
||||
end
|
||||
|
||||
context 'for global admin user' do
|
||||
before(:each) do
|
||||
@admin = Factory(:admin)
|
||||
@admin = FactoryGirl.create(:admin)
|
||||
set_session_for(@admin)
|
||||
end
|
||||
|
||||
|
@ -113,7 +113,7 @@ describe IssuesController do
|
|||
|
||||
context 'for project admin user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||
end
|
||||
|
@ -127,7 +127,7 @@ describe IssuesController do
|
|||
|
||||
context 'for project owner user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@project.update_attribute(:owner, @user)
|
||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||
|
@ -142,7 +142,7 @@ describe IssuesController do
|
|||
|
||||
context 'for project reader user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
||||
end
|
||||
|
@ -164,7 +164,7 @@ describe IssuesController do
|
|||
|
||||
context 'for project writer user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
|
||||
end
|
||||
|
|
|
@ -4,10 +4,10 @@ require 'spec_helper'
|
|||
describe MembersController do
|
||||
before(:each) do
|
||||
stub_rsync_methods
|
||||
@group = Factory(:group)
|
||||
@group = FactoryGirl.create(:group)
|
||||
@user = @group.owner
|
||||
set_session_for @user
|
||||
@another_user = Factory(:user)
|
||||
@another_user = FactoryGirl.create(:user)
|
||||
@add_params = {:group_id => @group.id, :user_id => @another_user.uname}
|
||||
end
|
||||
|
||||
|
|
|
@ -48,10 +48,10 @@ describe PersonalRepositoriesController do
|
|||
before(:each) do
|
||||
stub_rsync_methods
|
||||
|
||||
@repository = Factory(:personal_repository)
|
||||
@platform = Factory(:platform)
|
||||
@project = Factory(:project)
|
||||
@another_user = Factory(:user)
|
||||
@repository = FactoryGirl.create(:personal_repository)
|
||||
@platform = FactoryGirl.create(:platform)
|
||||
@project = FactoryGirl.create(:project)
|
||||
@another_user = FactoryGirl.create(:user)
|
||||
@create_params = {:repository => {:name => 'pro', :description => 'pro2'}, :platform_id => @platform.id}
|
||||
end
|
||||
|
||||
|
@ -66,7 +66,7 @@ describe PersonalRepositoriesController do
|
|||
|
||||
context 'for global admin' do
|
||||
before(:each) do
|
||||
@admin = Factory(:admin)
|
||||
@admin = FactoryGirl.create(:admin)
|
||||
@project.update_attribute(:owner, @admin)
|
||||
set_session_for(@admin)
|
||||
end
|
||||
|
@ -78,7 +78,7 @@ describe PersonalRepositoriesController do
|
|||
|
||||
pending 'for anyone except admin' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
end
|
||||
|
||||
|
@ -86,7 +86,7 @@ describe PersonalRepositoriesController do
|
|||
|
||||
context 'for owner user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
|
||||
@project.update_attribute(:owner, @user)
|
||||
|
||||
|
@ -103,7 +103,7 @@ describe PersonalRepositoriesController do
|
|||
|
||||
context 'for reader user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
||||
set_session_for(@user)
|
||||
end
|
||||
|
|
|
@ -37,9 +37,9 @@ describe PlatformsController do
|
|||
before(:each) do
|
||||
stub_rsync_methods
|
||||
|
||||
@platform = Factory(:platform)
|
||||
@personal_platform = Factory(:platform, :platform_type => 'personal')
|
||||
@user = Factory(:user)
|
||||
@platform = FactoryGirl.create(:platform)
|
||||
@personal_platform = FactoryGirl.create(:platform, :platform_type => 'personal')
|
||||
@user = FactoryGirl.create(:user)
|
||||
@create_params = {:platform => {
|
||||
:name => 'pl1',
|
||||
:description => 'pl1',
|
||||
|
@ -67,8 +67,8 @@ describe PlatformsController do
|
|||
|
||||
context 'for global admin' do
|
||||
before(:each) do
|
||||
@admin = Factory(:admin)
|
||||
@user = Factory(:user)
|
||||
@admin = FactoryGirl.create(:admin)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@admin)
|
||||
end
|
||||
|
||||
|
@ -103,7 +103,7 @@ describe PlatformsController do
|
|||
|
||||
context 'for owner user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@platform.update_attribute(:owner, @user)
|
||||
@platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||
|
@ -126,7 +126,7 @@ describe PlatformsController do
|
|||
|
||||
context 'for reader user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ describe ProductBuildListsController do
|
|||
{:product_id => product.id, :platform_id => product.platform_id}
|
||||
end
|
||||
|
||||
let(:product) { Factory(:product) }
|
||||
let(:product) { FactoryGirl.create(:product) }
|
||||
|
||||
context 'for guest' do
|
||||
it 'should not be able to perform create action' do
|
||||
|
@ -21,7 +21,7 @@ describe ProductBuildListsController do
|
|||
end
|
||||
|
||||
context 'for user' do
|
||||
before(:each) { set_session_for Factory(:user) }
|
||||
before(:each) { set_session_for FactoryGirl.create(:user) }
|
||||
|
||||
it 'should not be able to perform create action' do
|
||||
post :create, valid_attributes
|
||||
|
@ -30,7 +30,7 @@ describe ProductBuildListsController do
|
|||
end
|
||||
|
||||
context 'for admin' do
|
||||
before(:each) { set_session_for Factory(:admin) }
|
||||
before(:each) { set_session_for FactoryGirl.create(:admin) }
|
||||
|
||||
it "creates a new ProductBuildList" do
|
||||
expect {
|
||||
|
@ -46,7 +46,7 @@ describe ProductBuildListsController do
|
|||
end
|
||||
|
||||
context 'callbacks' do
|
||||
let(:product_build_list) { Factory(:product_build_list) }
|
||||
let(:product_build_list) { FactoryGirl.create(:product_build_list) }
|
||||
|
||||
def do_get
|
||||
get :status_build, :id => product_build_list.id, :status => ProductBuildList::BUILD_FAILED
|
||||
|
|
|
@ -5,9 +5,9 @@ describe ProductsController do
|
|||
before(:each) do
|
||||
stub_rsync_methods
|
||||
|
||||
@another_user = Factory(:user)
|
||||
@platform = Factory(:platform)
|
||||
@product = Factory(:product, :platform => @platform)
|
||||
@another_user = FactoryGirl.create(:user)
|
||||
@platform = FactoryGirl.create(:platform)
|
||||
@product = FactoryGirl.create(:product, :platform => @platform)
|
||||
@create_params = {:product => {:name => 'pro'}, :platform_id => @platform.id}
|
||||
@update_params = {:product => {:name => 'pro2'}, :platform_id => @platform.id}
|
||||
end
|
||||
|
@ -30,7 +30,7 @@ describe ProductsController do
|
|||
|
||||
context 'for global admin' do
|
||||
before(:each) do
|
||||
@admin = Factory(:admin)
|
||||
@admin = FactoryGirl.create(:admin)
|
||||
set_session_for(@admin)
|
||||
end
|
||||
|
||||
|
@ -60,7 +60,7 @@ describe ProductsController do
|
|||
|
||||
context 'for admin relation user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||
end
|
||||
|
@ -91,7 +91,7 @@ describe ProductsController do
|
|||
|
||||
context 'for no relation user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
end
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@ describe ProjectsController do
|
|||
before(:each) do
|
||||
stub_rsync_methods
|
||||
|
||||
@project = Factory(:project)
|
||||
@another_user = Factory(:user)
|
||||
@project = FactoryGirl.create(:project)
|
||||
@another_user = FactoryGirl.create(:user)
|
||||
@create_params = {:project => {:name => 'pro'}}
|
||||
@update_params = {:project => {:name => 'pro2'}}
|
||||
end
|
||||
|
@ -25,7 +25,7 @@ describe ProjectsController do
|
|||
|
||||
context 'for admin' do
|
||||
before(:each) do
|
||||
@admin = Factory(:admin)
|
||||
@admin = FactoryGirl.create(:admin)
|
||||
set_session_for(@admin)
|
||||
end
|
||||
|
||||
|
@ -44,7 +44,7 @@ describe ProjectsController do
|
|||
|
||||
context 'for owner user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@project.update_attribute(:owner, @user)
|
||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||
|
@ -70,7 +70,7 @@ describe ProjectsController do
|
|||
|
||||
context 'for reader user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
||||
end
|
||||
|
@ -80,7 +80,7 @@ describe ProjectsController do
|
|||
|
||||
context 'for writer user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
|
||||
end
|
||||
|
@ -91,9 +91,9 @@ describe ProjectsController do
|
|||
context 'search projects' do
|
||||
|
||||
before(:each) do
|
||||
@admin = Factory(:admin)
|
||||
@project1 = Factory(:project, :name => 'perl-debug')
|
||||
@project2 = Factory(:project, :name => 'perl')
|
||||
@admin = FactoryGirl.create(:admin)
|
||||
@project1 = FactoryGirl.create(:project, :name => 'perl-debug')
|
||||
@project2 = FactoryGirl.create(:project, :name => 'perl')
|
||||
set_session_for(@admin)
|
||||
end
|
||||
|
||||
|
|
|
@ -5,11 +5,11 @@ describe RepositoriesController do
|
|||
before(:each) do
|
||||
stub_rsync_methods
|
||||
|
||||
@repository = Factory(:repository)
|
||||
@personal_repository = Factory(:personal_repository)
|
||||
@platform = Factory(:platform)
|
||||
@project = Factory(:project)
|
||||
@another_user = Factory(:user)
|
||||
@repository = FactoryGirl.create(:repository)
|
||||
@personal_repository = FactoryGirl.create(:personal_repository)
|
||||
@platform = FactoryGirl.create(:platform)
|
||||
@project = FactoryGirl.create(:project)
|
||||
@another_user = FactoryGirl.create(:user)
|
||||
@create_params = {:repository => {:name => 'pro', :description => 'pro2'}, :platform_id => @platform.id}
|
||||
end
|
||||
|
||||
|
@ -31,7 +31,7 @@ describe RepositoriesController do
|
|||
|
||||
context 'for admin' do
|
||||
before(:each) do
|
||||
@admin = Factory(:admin)
|
||||
@admin = FactoryGirl.create(:admin)
|
||||
set_session_for(@admin)
|
||||
end
|
||||
|
||||
|
@ -54,7 +54,7 @@ describe RepositoriesController do
|
|||
|
||||
context 'for anyone except admin' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
end
|
||||
|
||||
|
@ -77,7 +77,7 @@ describe RepositoriesController do
|
|||
|
||||
context 'for owner user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@repository.platform.update_attribute(:owner, @user)
|
||||
@repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||
|
@ -88,7 +88,7 @@ describe RepositoriesController do
|
|||
|
||||
context 'for reader user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
||||
end
|
||||
|
|
|
@ -51,8 +51,8 @@ describe SubscribesController do
|
|||
before(:each) do
|
||||
stub_rsync_methods
|
||||
|
||||
@project = Factory(:project)
|
||||
@issue = Factory(:issue, :project_id => @project.id)
|
||||
@project = FactoryGirl.create(:project)
|
||||
@issue = FactoryGirl.create(:issue, :project_id => @project.id)
|
||||
|
||||
@create_params = {:issue_id => @issue.serial_id, :project_id => @project.id}
|
||||
@destroy_params = {:issue_id => @issue.serial_id, :project_id => @project.id}
|
||||
|
@ -64,7 +64,7 @@ describe SubscribesController do
|
|||
|
||||
context 'for global admin user' do
|
||||
before(:each) do
|
||||
@user = Factory(:admin)
|
||||
@user = FactoryGirl.create(:admin)
|
||||
set_session_for(@user)
|
||||
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||
@destroy_params = @destroy_params.merge({:id => @user.id})
|
||||
|
@ -87,7 +87,7 @@ describe SubscribesController do
|
|||
|
||||
context 'for simple user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
@destroy_params = @destroy_params.merge({:id => @user.id})
|
||||
end
|
||||
|
|
|
@ -5,11 +5,11 @@ describe UsersController do
|
|||
before(:each) do
|
||||
stub_rsync_methods
|
||||
|
||||
@simple_user = Factory(:user)
|
||||
@other_user = Factory(:user)
|
||||
@admin = Factory(:admin)
|
||||
@simple_user = FactoryGirl.create(:user)
|
||||
@other_user = FactoryGirl.create(:user)
|
||||
@admin = FactoryGirl.create(:admin)
|
||||
%w[user1 user2 user3].each do |uname|
|
||||
Factory(:user, :uname => uname, :email => "#{ uname }@nonexistanceserver.com")
|
||||
FactoryGirl.create(:user, :uname => uname, :email => "#{ uname }@nonexistanceserver.com")
|
||||
end
|
||||
@update_params = {:email => 'new_email@test.com'}
|
||||
end
|
||||
|
|
|
@ -1,30 +1,32 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
Factory.sequence :integer do |n|
|
||||
FactoryGirl.define do
|
||||
sequence :integer do |n|
|
||||
n
|
||||
end
|
||||
|
||||
Factory.sequence :string do |n|
|
||||
sequence :string do |n|
|
||||
"Lorem ipsum #{n}"
|
||||
end
|
||||
|
||||
Factory.sequence :uname do |n|
|
||||
sequence :uname do |n|
|
||||
"test#{n}"
|
||||
end
|
||||
|
||||
Factory.sequence :unixname do |n|
|
||||
sequence :unixname do |n|
|
||||
"test_unixname#{n}"
|
||||
end
|
||||
|
||||
Factory.sequence :email do |n|
|
||||
sequence :email do |n|
|
||||
"email#{n}@example.com"
|
||||
end
|
||||
|
||||
Factory.sequence :text do |n|
|
||||
sequence :text do |n|
|
||||
"#{n}. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
|
||||
end
|
||||
|
||||
Factory.sequence :text_file do |n|
|
||||
sequence :text_file do |n|
|
||||
stringio = StringIO.new("this is file content #{n}")
|
||||
stringio.instance_eval("def original_filename; 'stringio#{n}.txt'; end ")
|
||||
stringio
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
Factory.define(:arch) do |p|
|
||||
p.name { Factory.next(:string) }
|
||||
FactoryGirl.define do
|
||||
factory :arch do
|
||||
name { FactoryGirl.generate(:string) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
Factory.define(:build_list) do |p|
|
||||
p.association :user
|
||||
p.association :project
|
||||
p.association :pl, :factory => :platform_with_repos
|
||||
p.association :arch
|
||||
p.bpl {|bl| bl.pl}
|
||||
p.project_version "1.0"
|
||||
p.build_requires true
|
||||
p.update_type 'security'
|
||||
p.include_repos {|bl| bl.pl.repositories.map(&:id)}
|
||||
p.commit_hash '1234567890abcdef1234567890abcdef12345678'
|
||||
FactoryGirl.define do
|
||||
factory :build_list do
|
||||
association :user
|
||||
association :project
|
||||
association :pl, :factory => :platform_with_repos
|
||||
association :arch
|
||||
bpl {|bl| bl.pl}
|
||||
project_version "1.0"
|
||||
build_requires true
|
||||
update_type 'security'
|
||||
include_repos {|bl| bl.pl.repositories.map(&:id)}
|
||||
commit_hash '1234567890abcdef1234567890abcdef12345678'
|
||||
end
|
||||
|
||||
Factory.define(:build_list_core, :parent => :build_list) do |p|
|
||||
p.bs_id { Factory.next(:integer) }
|
||||
factory :build_list_core, :parent => :build_list do
|
||||
bs_id { FactoryGirl.generate(:integer) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
Factory.define(:comment) do |p|
|
||||
p.body { Factory.next(:string) }
|
||||
p.association :user, :factory => :user
|
||||
p.association :commentable, :factory => :issue
|
||||
FactoryGirl.define do
|
||||
factory :comment do
|
||||
body { FactoryGirl.generate(:string) }
|
||||
association :user, :factory => :user
|
||||
association :commentable, :factory => :issue
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
Factory.define(:group) do |g|
|
||||
g.uname { Factory.next(:uname) }
|
||||
g.description 'Description'
|
||||
g.association :owner, :factory => :user
|
||||
FactoryGirl.define do
|
||||
factory :group do
|
||||
uname { FactoryGirl.generate(:uname) }
|
||||
description 'Description'
|
||||
association :owner, :factory => :user
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
Factory.define(:issue) do |p|
|
||||
p.title { Factory.next(:string) }
|
||||
p.body { Factory.next(:string) }
|
||||
p.association :project, :factory => :project
|
||||
p.association :user, :factory => :user
|
||||
p.association :creator, :factory => :user
|
||||
p.status "open"
|
||||
FactoryGirl.define do
|
||||
factory :issue do
|
||||
title { FactoryGirl.generate(:string) }
|
||||
body { FactoryGirl.generate(:string) }
|
||||
association :project, :factory => :project
|
||||
association :user, :factory => :user
|
||||
association :creator, :factory => :user
|
||||
status "open"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
Factory.define(:platform) do |p|
|
||||
p.description { Factory.next(:string) }
|
||||
p.name { Factory.next(:unixname) }
|
||||
p.platform_type 'main'
|
||||
p.distrib_type APP_CONFIG['distr_types'].first
|
||||
p.association :owner, :factory => :user
|
||||
FactoryGirl.define do
|
||||
factory :platform do
|
||||
description { FactoryGirl.generate(:string) }
|
||||
name { FactoryGirl.generate(:unixname) }
|
||||
platform_type 'main'
|
||||
distrib_type APP_CONFIG['distr_types'].first
|
||||
association :owner, :factory => :user
|
||||
end
|
||||
|
||||
Factory.define(:platform_with_repos, :parent => :platform) do |p|
|
||||
p.repositories {|r| [r.association(:repository)]}
|
||||
factory :platform_with_repos, :parent => :platform do
|
||||
repositories {|r| [r.association(:repository)]}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
Factory.define(:private_user) do |p|
|
||||
p.login { Factory.next(:string) }
|
||||
p.password { Factory.next(:string) }
|
||||
p.association :platform, :factory => :platform
|
||||
p.association :user, :factory => :user
|
||||
FactoryGirl.define do
|
||||
factory :private_user do
|
||||
login { FactoryGirl.generate(:string) }
|
||||
password { FactoryGirl.generate(:string) }
|
||||
association :platform, :factory => :platform
|
||||
association :user, :factory => :user
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
Factory.define(:product_build_list) do |p|
|
||||
p.association :product, :factory => :product
|
||||
FactoryGirl.define do
|
||||
factory :product_build_list do
|
||||
association :product, :factory => :product
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
Factory.define(:product) do |p|
|
||||
p.name { Factory.next(:string) }
|
||||
p.association :platform, :factory => :platform
|
||||
FactoryGirl.define do
|
||||
factory :product do
|
||||
name { FactoryGirl.generate(:string) }
|
||||
association :platform, :factory => :platform
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
Factory.define(:project) do |p|
|
||||
p.description { Factory.next(:string) }
|
||||
p.name { Factory.next(:unixname) }
|
||||
p.association :owner, :factory => :user
|
||||
FactoryGirl.define do
|
||||
factory :project do
|
||||
description { FactoryGirl.generate(:string) }
|
||||
name { FactoryGirl.generate(:unixname) }
|
||||
association :owner, :factory => :user
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
FactoryGirl.define do
|
||||
factory :register_request do
|
||||
name "MyString"
|
||||
email { Factory.next(:email) }
|
||||
email { FactoryGirl.generate(:email) }
|
||||
token "MyString"
|
||||
interest "MyString"
|
||||
more "MyText"
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
Factory.define(:repository) do |p|
|
||||
p.description { Factory.next(:string) }
|
||||
p.name { Factory.next(:unixname) }
|
||||
p.association :platform, :factory => :platform
|
||||
FactoryGirl.define do
|
||||
factory :repository do
|
||||
description { FactoryGirl.generate(:string) }
|
||||
name { FactoryGirl.generate(:unixname) }
|
||||
association :platform, :factory => :platform
|
||||
end
|
||||
|
||||
Factory.define(:personal_repository, :parent => :repository) do |p|
|
||||
p.after_create {|r|
|
||||
factory :personal_repository, :parent => :repository do
|
||||
after_create {|r|
|
||||
r.platform.platform_type = 'personal'
|
||||
r.platform.visibility = 'hidden'
|
||||
r.platform.save!
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
Factory.define(:subscribe) do |p|
|
||||
p.association :subscribeable, :factory => :issue
|
||||
p.association :user, :factory => :user
|
||||
FactoryGirl.define do
|
||||
factory :subscribe do
|
||||
association :subscribeable, :factory => :issue
|
||||
association :user, :factory => :user
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
Factory.define(:user) do |u|
|
||||
u.email { Factory.next(:email) }
|
||||
u.name { Factory.next(:string) }
|
||||
u.uname { Factory.next(:uname) }
|
||||
u.password '123456'
|
||||
u.password_confirmation { |user| user.password }
|
||||
FactoryGirl.define do
|
||||
factory :user do
|
||||
email { FactoryGirl.generate(:email) }
|
||||
name { FactoryGirl.generate(:string) }
|
||||
uname { FactoryGirl.generate(:uname) }
|
||||
password '123456'
|
||||
password_confirmation {|u| u.password}
|
||||
confirmed_at { Time.current }
|
||||
end
|
||||
|
||||
Factory.define(:admin, :class => 'User') do |u|
|
||||
u.email { Factory.next(:email) }
|
||||
u.name { Factory.next(:string) }
|
||||
u.uname { Factory.next(:uname) }
|
||||
u.password '123456'
|
||||
u.password_confirmation { |user| user.password }
|
||||
u.role 'admin'
|
||||
factory :admin, :parent => :user do
|
||||
role 'admin'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,12 +8,12 @@ describe UserMailer do
|
|||
before(:each) do
|
||||
stub_rsync_methods
|
||||
|
||||
@project = Factory(:project)
|
||||
@issue_user = Factory(:user)
|
||||
@project = FactoryGirl.create(:project)
|
||||
@issue_user = FactoryGirl.create(:user)
|
||||
|
||||
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
||||
|
||||
@issue = Factory(:issue, :project_id => @project.id, :user_id => @issue_user.id, :creator => @issue_user)
|
||||
@issue = FactoryGirl.create(:issue, :project_id => @project.id, :user_id => @issue_user.id, :creator => @issue_user)
|
||||
@email = UserMailer.new_issue_notification(@issue, @issue_user).deliver
|
||||
end
|
||||
|
||||
|
@ -46,13 +46,13 @@ describe UserMailer do
|
|||
before(:each) do
|
||||
stub_rsync_methods
|
||||
|
||||
@project = Factory(:project)
|
||||
@issue_user = Factory(:user)
|
||||
@user = Factory(:user)
|
||||
@project = FactoryGirl.create(:project)
|
||||
@issue_user = FactoryGirl.create(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
|
||||
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
||||
|
||||
@issue = Factory(:issue, :project_id => @project.id, :user_id => @issue_user.id, :creator => @issue_user)
|
||||
@issue = FactoryGirl.create(:issue, :project_id => @project.id, :user_id => @issue_user.id, :creator => @issue_user)
|
||||
@email = UserMailer.issue_assign_notification(@issue, @user).deliver
|
||||
end
|
||||
|
||||
|
@ -82,14 +82,14 @@ describe UserMailer do
|
|||
before(:each) do
|
||||
stub_rsync_methods
|
||||
|
||||
@project = Factory(:project)
|
||||
@issue_user = Factory(:user)
|
||||
@user = Factory(:user)
|
||||
@project = FactoryGirl.create(:project)
|
||||
@issue_user = FactoryGirl.create(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
|
||||
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
||||
|
||||
@issue = Factory(:issue, :project_id => @project.id, :user_id => @issue_user.id, :creator => @issue_user)
|
||||
@comment = Factory(:comment, :commentable => @issue, :user_id => @user.id, :project => @project)
|
||||
@issue = FactoryGirl.create(:issue, :project_id => @project.id, :user_id => @issue_user.id, :creator => @issue_user)
|
||||
@comment = FactoryGirl.create(:comment, :commentable => @issue, :user_id => @user.id, :project => @project)
|
||||
@email = UserMailer.new_comment_notification(@comment, @issue_user).deliver
|
||||
end
|
||||
|
||||
|
|
|
@ -3,12 +3,12 @@ require 'spec_helper'
|
|||
require "cancan/matchers"
|
||||
|
||||
def admin_create
|
||||
@admin = Factory(:admin)
|
||||
@admin = FactoryGirl.create(:admin)
|
||||
@ability = Ability.new(@admin)
|
||||
end
|
||||
|
||||
def user_create
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@ability = Ability.new(@user)
|
||||
end
|
||||
|
||||
|
@ -18,11 +18,11 @@ end
|
|||
|
||||
describe CanCan do
|
||||
|
||||
let(:personal_platform) { Factory(:platform, :platform_type => 'personal') }
|
||||
let(:personal_repository) { Factory(:personal_repository) }
|
||||
let(:open_platform) { Factory(:platform, :visibility => 'open') }
|
||||
let(:hidden_platform) { Factory(:platform, :visibility => 'hidden') }
|
||||
let(:register_request) { Factory(:register_request) }
|
||||
let(:personal_platform) { FactoryGirl.create(:platform, :platform_type => 'personal') }
|
||||
let(:personal_repository) { FactoryGirl.create(:personal_repository) }
|
||||
let(:open_platform) { FactoryGirl.create(:platform, :visibility => 'open') }
|
||||
let(:hidden_platform) { FactoryGirl.create(:platform, :visibility => 'hidden') }
|
||||
let(:register_request) { FactoryGirl.create(:register_request) }
|
||||
|
||||
before(:each) do
|
||||
stub_rsync_methods
|
||||
|
@ -118,7 +118,7 @@ describe CanCan do
|
|||
end
|
||||
|
||||
it "shoud be able to read open projects" do
|
||||
@project = Factory(:project, :visibility => 'open')
|
||||
@project = FactoryGirl.create(:project, :visibility => 'open')
|
||||
@ability.should be_able_to(:read, @project)
|
||||
end
|
||||
|
||||
|
@ -132,7 +132,7 @@ describe CanCan do
|
|||
|
||||
context "private users relations" do
|
||||
before(:each) do
|
||||
@private_user = Factory(:private_user)
|
||||
@private_user = FactoryGirl.create(:private_user)
|
||||
@private_user.platform.update_attribute(:owner, @user)
|
||||
end
|
||||
|
||||
|
@ -145,8 +145,8 @@ describe CanCan do
|
|||
|
||||
context 'as project collaborator' do
|
||||
before(:each) do
|
||||
@project = Factory(:project)
|
||||
@issue = Factory(:issue, :project_id => @project.id)
|
||||
@project = FactoryGirl.create(:project)
|
||||
@issue = FactoryGirl.create(:issue, :project_id => @project.id)
|
||||
end
|
||||
|
||||
context 'with read rights' do
|
||||
|
@ -180,7 +180,7 @@ describe CanCan do
|
|||
|
||||
[:new, :create].each do |action|
|
||||
it "should be able to #{action} build_list" do
|
||||
@build_list = Factory(:build_list, :project => @project)
|
||||
@build_list = FactoryGirl.create(:build_list, :project => @project)
|
||||
@ability.should be_able_to(action, @build_list)
|
||||
end
|
||||
end
|
||||
|
@ -199,7 +199,7 @@ describe CanCan do
|
|||
|
||||
[:new, :create].each do |action|
|
||||
it "should be able to #{action} build_list" do
|
||||
@build_list = Factory(:build_list, :project => @project)
|
||||
@build_list = FactoryGirl.create(:build_list, :project => @project)
|
||||
@ability.should be_able_to(action, @build_list)
|
||||
end
|
||||
end
|
||||
|
@ -229,7 +229,7 @@ describe CanCan do
|
|||
|
||||
[:new, :create].each do |action|
|
||||
it "should be able to #{action} build_list" do
|
||||
@build_list = Factory(:build_list, :project => @project)
|
||||
@build_list = FactoryGirl.create(:build_list, :project => @project)
|
||||
@ability.should be_able_to(action, @build_list)
|
||||
end
|
||||
end
|
||||
|
@ -245,7 +245,7 @@ describe CanCan do
|
|||
|
||||
context 'platform relations' do
|
||||
before(:each) do
|
||||
@platform = Factory(:platform)
|
||||
@platform = FactoryGirl.create(:platform)
|
||||
end
|
||||
|
||||
context 'with owner rights' do
|
||||
|
@ -273,7 +273,7 @@ describe CanCan do
|
|||
|
||||
context 'repository relations' do
|
||||
before(:each) do
|
||||
@repository = Factory(:repository)
|
||||
@repository = FactoryGirl.create(:repository)
|
||||
end
|
||||
|
||||
context 'with owner rights' do
|
||||
|
@ -301,9 +301,9 @@ describe CanCan do
|
|||
|
||||
context 'build list relations' do
|
||||
before(:each) do
|
||||
@project = Factory(:project)
|
||||
@project = FactoryGirl.create(:project)
|
||||
@project.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'writer')
|
||||
@build_list = Factory(:build_list, :project => @project)
|
||||
@build_list = FactoryGirl.create(:build_list, :project => @project)
|
||||
end
|
||||
|
||||
it 'should be able to publish build list with SUCCESS status' do
|
||||
|
|
|
@ -11,7 +11,7 @@ end
|
|||
def set_comments_data_for_commit
|
||||
@ability = Ability.new(@user)
|
||||
|
||||
@project = Factory(:project, :owner => @user)
|
||||
@project = FactoryGirl.create(:project, :owner => @user)
|
||||
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.git_repository.path}) # maybe FIXME ?
|
||||
@commit = @project.git_repository.commits.first
|
||||
|
||||
|
@ -28,8 +28,8 @@ describe Comment do
|
|||
before { stub_rsync_methods }
|
||||
context 'for global admin user' do
|
||||
before(:each) do
|
||||
@user = Factory(:admin)
|
||||
@stranger = Factory(:user)
|
||||
@user = FactoryGirl.create(:admin)
|
||||
@stranger = FactoryGirl.create(:user)
|
||||
|
||||
set_comments_data_for_commit
|
||||
end
|
||||
|
@ -57,11 +57,11 @@ describe Comment do
|
|||
|
||||
context 'for project admin user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@stranger = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@stranger = FactoryGirl.create(:user)
|
||||
|
||||
set_comments_data_for_commit
|
||||
@admin = Factory(:user)
|
||||
@admin = FactoryGirl.create(:user)
|
||||
@ability = Ability.new(@admin)
|
||||
@project.relations.create!(:object_type => 'User', :object_id => @admin.id, :role => 'admin')
|
||||
ActionMailer::Base.deliveries = []
|
||||
|
@ -147,8 +147,8 @@ describe Comment do
|
|||
|
||||
context 'for project owner user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@stranger = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@stranger = FactoryGirl.create(:user)
|
||||
set_comments_data_for_commit
|
||||
@project.update_attribute(:owner, @user)
|
||||
ActionMailer::Base.deliveries = []
|
||||
|
@ -244,9 +244,9 @@ describe Comment do
|
|||
|
||||
context 'for simple user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@simple = Factory(:user)
|
||||
@stranger = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@simple = FactoryGirl.create(:user)
|
||||
@stranger = FactoryGirl.create(:user)
|
||||
set_comments_data_for_commit
|
||||
@comment = create_comment(@simple)
|
||||
@ability = Ability.new(@simple)
|
||||
|
|
|
@ -5,11 +5,11 @@ require "cancan/matchers"
|
|||
def set_commentable_data
|
||||
@ability = Ability.new(@user)
|
||||
|
||||
@project = Factory(:project)
|
||||
@issue = Factory(:issue, :project_id => @project.id, :creator => @user)
|
||||
@project = FactoryGirl.create(:project)
|
||||
@issue = FactoryGirl.create(:issue, :project_id => @project.id, :creator => @user)
|
||||
|
||||
@comment = Factory(:comment, :commentable => @issue, :user => @user, :project => @project)
|
||||
@stranger_comment = Factory(:comment, :commentable => @issue, :user => @stranger, :project => @project)
|
||||
@comment = FactoryGirl.create(:comment, :commentable => @issue, :user => @user, :project => @project)
|
||||
@stranger_comment = FactoryGirl.create(:comment, :commentable => @issue, :user => @stranger, :project => @project)
|
||||
|
||||
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
||||
end
|
||||
|
@ -18,8 +18,8 @@ describe Comment do
|
|||
before { stub_rsync_methods }
|
||||
context 'for global admin user' do
|
||||
before(:each) do
|
||||
@user = Factory(:admin)
|
||||
@stranger = Factory(:user)
|
||||
@user = FactoryGirl.create(:admin)
|
||||
@stranger = FactoryGirl.create(:user)
|
||||
|
||||
set_commentable_data
|
||||
end
|
||||
|
@ -51,8 +51,8 @@ describe Comment do
|
|||
|
||||
context 'for project admin user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@stranger = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@stranger = FactoryGirl.create(:user)
|
||||
|
||||
set_commentable_data
|
||||
|
||||
|
@ -79,8 +79,8 @@ describe Comment do
|
|||
|
||||
context 'for project owner user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@stranger = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@stranger = FactoryGirl.create(:user)
|
||||
|
||||
set_commentable_data
|
||||
|
||||
|
@ -107,8 +107,8 @@ describe Comment do
|
|||
|
||||
context 'for simple user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@stranger = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@stranger = FactoryGirl.create(:user)
|
||||
|
||||
set_commentable_data
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ require "cancan/matchers"
|
|||
describe Group do
|
||||
before(:each) do
|
||||
stub_rsync_methods
|
||||
@group = Factory(:group)
|
||||
@group = FactoryGirl.create(:group)
|
||||
@ability = Ability.new(User.new)
|
||||
end
|
||||
|
||||
|
@ -19,7 +19,7 @@ describe Group do
|
|||
|
||||
context 'for global admin' do
|
||||
before(:each) do
|
||||
@admin = Factory(:admin)
|
||||
@admin = FactoryGirl.create(:admin)
|
||||
@ability = Ability.new(@admin)
|
||||
end
|
||||
|
||||
|
@ -32,8 +32,8 @@ describe Group do
|
|||
|
||||
context 'for group admin' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@another_user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@another_user = FactoryGirl.create(:user)
|
||||
@group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||
@ability = Ability.new(@user)
|
||||
end
|
||||
|
@ -61,7 +61,7 @@ describe Group do
|
|||
|
||||
context 'for group owner' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@group.update_attribute(:owner, @user)
|
||||
@group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||
@ability = Ability.new(@user)
|
||||
|
@ -76,7 +76,7 @@ describe Group do
|
|||
|
||||
context 'for group reader and writer user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
||||
@ability = Ability.new(@user)
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ describe Platform do
|
|||
|
||||
context 'released' do
|
||||
it 'should add suffix to name when released' do
|
||||
@platform = Factory(:platform)
|
||||
@platform = FactoryGirl.create(:platform)
|
||||
old_name = @platform.name
|
||||
|
||||
@platform.released = true
|
||||
|
@ -20,7 +20,7 @@ describe Platform do
|
|||
end
|
||||
|
||||
it 'should not add suffix to name when not released' do
|
||||
@platform = Factory(:platform, :name => 'name')
|
||||
@platform = FactoryGirl.create(:platform, :name => 'name')
|
||||
@platform.name.should == 'name'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,10 +4,10 @@ require 'spec_helper'
|
|||
describe ProjectToRepository do
|
||||
before(:each) do
|
||||
stub_rsync_methods
|
||||
@platform = Factory(:platform)
|
||||
@first_repo = Factory(:repository, :platform_id => @platform.id)
|
||||
@second_repo = Factory(:repository, :platform_id => @platform.id)
|
||||
@project = Factory(:project)
|
||||
@platform = FactoryGirl.create(:platform)
|
||||
@first_repo = FactoryGirl.create(:repository, :platform_id => @platform.id)
|
||||
@second_repo = FactoryGirl.create(:repository, :platform_id => @platform.id)
|
||||
@project = FactoryGirl.create(:project)
|
||||
@first_repo.projects << @project
|
||||
@first_repo.save
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ describe Repository do
|
|||
context 'when create with same owner that platform' do
|
||||
before (:each) do
|
||||
stub_rsync_methods
|
||||
@platform = Factory(:platform)
|
||||
@platform = FactoryGirl.create(:platform)
|
||||
@params = {:name => 'tst_platform', :description => 'test platform'}
|
||||
end
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@ require "cancan/matchers"
|
|||
def set_testable_data
|
||||
@ability = Ability.new(@user)
|
||||
|
||||
@project = Factory(:project)
|
||||
@issue = Factory(:issue, :project_id => @project.id)
|
||||
@project = FactoryGirl.create(:project)
|
||||
@issue = FactoryGirl.create(:issue, :project_id => @project.id)
|
||||
|
||||
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
||||
end
|
||||
|
@ -15,8 +15,8 @@ describe Subscribe do
|
|||
before { stub_rsync_methods }
|
||||
context 'for global admin user' do
|
||||
before(:each) do
|
||||
@user = Factory(:admin)
|
||||
@stranger = Factory(:user)
|
||||
@user = FactoryGirl.create(:admin)
|
||||
@stranger = FactoryGirl.create(:user)
|
||||
|
||||
set_testable_data
|
||||
end
|
||||
|
@ -27,8 +27,8 @@ describe Subscribe do
|
|||
|
||||
context 'destroy' do
|
||||
before(:each) do
|
||||
@subscribe = Factory(:subscribe, :subscribeable => @issue, :user => @user)
|
||||
@stranger_subscribe = Factory(:subscribe, :subscribeable => @issue, :user => @stranger)
|
||||
@subscribe = FactoryGirl.create(:subscribe, :subscribeable => @issue, :user => @user)
|
||||
@stranger_subscribe = FactoryGirl.create(:subscribe, :subscribeable => @issue, :user => @stranger)
|
||||
end
|
||||
|
||||
context 'own subscribe' do
|
||||
|
@ -47,8 +47,8 @@ describe Subscribe do
|
|||
|
||||
context 'for simple user' do
|
||||
before(:each) do
|
||||
@user = Factory(:user)
|
||||
@stranger = Factory(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
@stranger = FactoryGirl.create(:user)
|
||||
|
||||
set_testable_data
|
||||
end
|
||||
|
@ -59,8 +59,8 @@ describe Subscribe do
|
|||
|
||||
context 'destroy' do
|
||||
before(:each) do
|
||||
@subscribe = Factory(:subscribe, :subscribeable => @issue, :user => @user)
|
||||
@stranger_subscribe = Factory(:subscribe, :subscribeable => @issue, :user => @stranger)
|
||||
@subscribe = FactoryGirl.create(:subscribe, :subscribeable => @issue, :user => @user)
|
||||
@stranger_subscribe = FactoryGirl.create(:subscribe, :subscribeable => @issue, :user => @stranger)
|
||||
end
|
||||
|
||||
context 'own subscribe' do
|
||||
|
|
|
@ -28,7 +28,7 @@ RSpec.configure do |config|
|
|||
end
|
||||
|
||||
def set_session_for(user=nil)
|
||||
current_user = user.is_a?(Symbol) ? Factory.create(user) : user
|
||||
current_user = user.is_a?(Symbol) ? FactoryGirl.create(user) : user
|
||||
@request.env["devise.mapping"] = :user
|
||||
sign_in current_user
|
||||
end
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
.DS_Store
|
|
@ -1,4 +0,0 @@
|
|||
== 0.0.1 2008-01-28
|
||||
|
||||
* 1 major enhancement:
|
||||
* Initial release
|
|
@ -1,21 +0,0 @@
|
|||
Copyright (c) 2008 Johan Sørensen
|
||||
Copyright (c) 2003 Marcel Molina Jr.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -1,26 +0,0 @@
|
|||
History.txt
|
||||
License.txt
|
||||
Manifest.txt
|
||||
README.txt
|
||||
Rakefile
|
||||
config/hoe.rb
|
||||
config/requirements.rb
|
||||
lib/diff-display.rb
|
||||
lib/diff-display/version.rb
|
||||
log/debug.log
|
||||
script/destroy
|
||||
script/generate
|
||||
script/txt2html
|
||||
setup.rb
|
||||
spec/diff-display_spec.rb
|
||||
spec/spec.opts
|
||||
spec/spec_helper.rb
|
||||
tasks/deployment.rake
|
||||
tasks/environment.rake
|
||||
tasks/rspec.rake
|
||||
tasks/website.rake
|
||||
website/index.html
|
||||
website/index.txt
|
||||
website/javascripts/rounded_corners_lite.inc.js
|
||||
website/stylesheets/screen.css
|
||||
website/template.rhtml
|
|
@ -1,58 +0,0 @@
|
|||
Diff::Display
|
||||
=============
|
||||
|
||||
Diff::Display::Unified renders unified diffs into various forms. The output is
|
||||
based on a callback object that's passed into the renderer
|
||||
|
||||
Rewrite of an (unreleased) library by Marcel Molina Jr., who wrote this it
|
||||
probably back in 2004 or so.
|
||||
|
||||
Usage
|
||||
======
|
||||
|
||||
irb(main):001:0> require 'diff-display'
|
||||
=> true
|
||||
irb(main):002:0> diff = <<EOS
|
||||
irb(main):003:0" diff --git a/History.txt b/History.txt
|
||||
irb(main):004:0" index 0ed7358..622c384 100644
|
||||
irb(main):005:0" --- a/History.txt
|
||||
irb(main):006:0" +++ b/History.txt
|
||||
irb(main):007:0" @@ -1,4 +1,5 @@
|
||||
irb(main):008:0" == 0.0.1 2008-01-28
|
||||
irb(main):009:0"
|
||||
irb(main):010:0" -* 1 major enhancement:
|
||||
irb(main):011:0" - * Initial release
|
||||
irb(main):012:0" +* 2 major enhancements:
|
||||
irb(main):013:0" + * The Initial release
|
||||
irb(main):014:0" + * stuff added
|
||||
irb(main):015:0" EOS
|
||||
...
|
||||
irb(main):016:0> diff_display = Diff::Display::Unified.new(diff)
|
||||
=> #<Diff::Display::Unified:0x331c9c @data=...
|
||||
# Be boring and render it back out as a diff
|
||||
irb(main):017:0> puts diff_display.render(Diff::Renderer::Diff.new)
|
||||
diff --git a/History.txt b/History.txt
|
||||
index 0ed7358..622c384 100644
|
||||
--- a/History.txt
|
||||
+++ b/History.txt
|
||||
@@ -1,4 +1,5 @@
|
||||
== 0.0.1 2008-01-28
|
||||
|
||||
-* 1 major enhancement:
|
||||
- * Initial release
|
||||
+* 2 major enhancements:
|
||||
+ * The Initial release
|
||||
+ * stuff added
|
||||
|
||||
See Diff::Renderer::Base for what methods your callback needs to implement
|
||||
|
||||
Git Repository
|
||||
===============
|
||||
|
||||
http://gitorious.org/projects/diff-display/
|
||||
|
||||
|
||||
License
|
||||
======
|
||||
|
||||
Please see License.txt
|
|
@ -1,10 +0,0 @@
|
|||
# encoding: utf-8
|
||||
|
||||
require 'rubygems'
|
||||
require 'hoe'
|
||||
require './lib/diff-display.rb'
|
||||
|
||||
Hoe.new('diff-display', Diff::Display::VERSION::STRING) do |p|
|
||||
p.rubyforge_name = 'hoe_testx'
|
||||
p.developer('Johan Sørensen', 'johan@johansorensen.com')
|
||||
end
|
|
@ -1,15 +0,0 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
$:.unshift File.dirname(__FILE__)
|
||||
|
||||
module Diff
|
||||
module Display
|
||||
end
|
||||
end
|
||||
|
||||
require "diff/display/version"
|
||||
# require "diff/display/data_structure"
|
||||
require "diff/display/unified"
|
||||
require "diff/display/unified/generator"
|
||||
|
||||
require "diff/renderer/base"
|
||||
require "diff/renderer/diff"
|
|
@ -1,20 +0,0 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
module Diff
|
||||
module Display
|
||||
class Unified
|
||||
def initialize(udiff)
|
||||
@data = Diff::Display::Unified::Generator.run(udiff)
|
||||
end
|
||||
attr_reader :data
|
||||
|
||||
def stats
|
||||
@stats ||= data.stats
|
||||
end
|
||||
|
||||
def render(renderer, out="")
|
||||
out << renderer.render(data)
|
||||
out
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,405 +0,0 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
module Diff::Display
|
||||
# Processes the diff and generates a Data object which contains the
|
||||
# resulting data structure.
|
||||
#
|
||||
# The +run+ class method is fed a diff and returns a Data object. It will
|
||||
# accept as its argument a String, an Array or a File object (or anything
|
||||
# that responds to #each):
|
||||
#
|
||||
# Diff::Display::Unified::Generator.run(diff)
|
||||
#
|
||||
class Data < Array
|
||||
def initialize
|
||||
super
|
||||
@stats = {:additions => 0, :deletions => 0}
|
||||
end
|
||||
|
||||
def stats
|
||||
each do |block|
|
||||
block.each do |line|
|
||||
case line
|
||||
when Diff::Display::AddLine
|
||||
@stats[:additions] += 1
|
||||
when Diff::Display::RemLine
|
||||
@stats[:deletions] += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
@stats
|
||||
end
|
||||
|
||||
def to_diff
|
||||
diff = ""
|
||||
each do |block|
|
||||
block.each do |line|
|
||||
line_str = line.expand_inline_changes_with(nil, nil)
|
||||
case line
|
||||
when HeaderLine
|
||||
diff << "#{line_str}\n"
|
||||
when UnModLine
|
||||
diff << " #{line_str}\n"
|
||||
when SepLine
|
||||
diff << "\n"
|
||||
when AddLine
|
||||
diff << "+#{line_str}\n"
|
||||
when RemLine
|
||||
diff << "-#{line_str}\n"
|
||||
when NonewlineLine
|
||||
diff << line_str
|
||||
end
|
||||
end
|
||||
end
|
||||
diff.chomp
|
||||
end
|
||||
|
||||
def debug
|
||||
demodularize = Proc.new {|obj| obj.class.name[/\w+$/]}
|
||||
each do |diff_block|
|
||||
print "-" * 40, ' ', demodularize.call(diff_block)
|
||||
puts
|
||||
puts diff_block.map {|line|
|
||||
# "%5d" % line.old_number +
|
||||
"%8s" % "[#{line.old_number || '.'} #{line.new_number || '.'}]" +
|
||||
" [#{demodularize.call(line)}#{'(i)' if line.inline_changes?}]" +
|
||||
line
|
||||
}.join("\n")
|
||||
puts "-" * 40, ' '
|
||||
end
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
class Line < String
|
||||
class << self
|
||||
def add(line, line_number, inline = false, offsets = [])
|
||||
AddLine.new(line, line_number, inline, offsets)
|
||||
end
|
||||
|
||||
def rem(line, line_number, inline = false, offsets = [])
|
||||
RemLine.new(line, line_number, inline, offsets)
|
||||
end
|
||||
|
||||
def unmod(line, old_number, new_number)
|
||||
UnModLine.new(line, old_number, new_number)
|
||||
end
|
||||
|
||||
def nonewline(line)
|
||||
NonewlineLine.new(line)
|
||||
end
|
||||
|
||||
def header(line)
|
||||
HeaderLine.new(line)
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(line, old_number = nil, new_number = nil)
|
||||
super(line)
|
||||
@old_number, @new_number = old_number, new_number
|
||||
@inline = false
|
||||
end
|
||||
attr_reader :old_number, :new_number
|
||||
|
||||
def identifier
|
||||
self.class.name[/\w+$/].gsub(/Line$/, "").downcase.to_sym
|
||||
end
|
||||
|
||||
def inline_changes?
|
||||
# Is set in the AddLine+RemLine subclasses
|
||||
@inline
|
||||
end
|
||||
|
||||
# returns the prefix, middle and postfix parts of a line with inline changes
|
||||
def segments
|
||||
return self.dup unless inline_changes?
|
||||
prefix, changed = self.dup.split('\\0')
|
||||
changed, postfix = changed.split('\\1')
|
||||
[prefix, changed, postfix]
|
||||
end
|
||||
|
||||
# Expand any inline changes with +prefix+ and +postfix+
|
||||
def expand_inline_changes_with(prefix, postfix)
|
||||
return self.dup unless inline_changes?
|
||||
str = self.dup
|
||||
str.sub!('\\0', prefix.to_s)
|
||||
str.sub!('\\1', postfix.to_s)
|
||||
str
|
||||
end
|
||||
|
||||
def inspect
|
||||
%Q{#<#{self.class.name} [#{old_number.inspect}-#{new_number.inspect}] "#{self}">}
|
||||
end
|
||||
end
|
||||
|
||||
class AddLine < Line
|
||||
def initialize(line, line_number, inline = false, offsets = [])
|
||||
super(line, nil, line_number)
|
||||
@inline = inline
|
||||
@offsets = offsets
|
||||
end
|
||||
attr_reader :offsets
|
||||
end
|
||||
|
||||
class RemLine < Line
|
||||
def initialize(line, line_number, inline = false, offsets = [])
|
||||
super(line, line_number, nil)
|
||||
@inline = inline
|
||||
@offsets = offsets
|
||||
end
|
||||
attr_reader :offsets
|
||||
end
|
||||
|
||||
class NonewlineLine < Line
|
||||
def initialize(line = '\\ No newline at end of file')
|
||||
super(line)
|
||||
end
|
||||
end
|
||||
|
||||
class UnModLine < Line
|
||||
def initialize(line, old_number, new_number)
|
||||
super(line, old_number, new_number)
|
||||
end
|
||||
end
|
||||
|
||||
class SepLine < Line
|
||||
def initialize(line = '...')
|
||||
super(line)
|
||||
end
|
||||
end
|
||||
|
||||
class HeaderLine < Line
|
||||
def initialize(line)
|
||||
super(line)
|
||||
end
|
||||
end
|
||||
|
||||
# This class is an array which contains Line objects. Just like Line
|
||||
# classes, several Block classes inherit from Block. If all the lines
|
||||
# in the block are added lines then it is an AddBlock. If all lines
|
||||
# in the block are removed lines then it is a RemBlock. If the lines
|
||||
# in the block are all unmodified then it is an UnMod block. If the
|
||||
# lines in the block are a mixture of added and removed lines then
|
||||
# it is a ModBlock. There are no blocks that contain a mixture of
|
||||
# modified and unmodified lines.
|
||||
class Block < Array
|
||||
class << self
|
||||
def add; AddBlock.new end
|
||||
def rem; RemBlock.new end
|
||||
def mod; ModBlock.new end
|
||||
def unmod; UnModBlock.new end
|
||||
def header; HeaderBlock.new end
|
||||
def nonewline; NonewlineBlock.new end
|
||||
end
|
||||
end
|
||||
|
||||
#:stopdoc:#
|
||||
class AddBlock < Block; end
|
||||
class RemBlock < Block; end
|
||||
class ModBlock < Block; end
|
||||
class UnModBlock < Block; end
|
||||
class SepBlock < Block; end
|
||||
class HeaderBlock < Block; end
|
||||
class NonewlineBlock < Block; end
|
||||
#:startdoc:#
|
||||
|
||||
|
||||
class Unified::Generator
|
||||
|
||||
# Extracts the line number info for a given diff section
|
||||
LINE_NUM_RE = /^@@ [+-]([0-9]+)(?:,([0-9]+))? [+-]([0-9]+)(?:,([0-9]+))? @@/
|
||||
LINE_TYPES = {'+' => :add, '-' => :rem, ' ' => :unmod, '\\' => :nonewline}
|
||||
|
||||
# Runs the generator on a diff and returns a Data object
|
||||
def self.run(udiff)
|
||||
raise ArgumentError, "Object must be enumerable" unless udiff.respond_to?(:each_line)
|
||||
generator = new
|
||||
udiff.each_line do |line|
|
||||
begin
|
||||
generator.process(line.chomp)
|
||||
rescue ArgumentError => e
|
||||
e.message =~ /^invalid byte sequence/ ? next : raise(e)
|
||||
end
|
||||
end
|
||||
generator.finish
|
||||
generator.data
|
||||
end
|
||||
|
||||
def initialize
|
||||
@buffer = []
|
||||
@line_type = nil
|
||||
@prev_line_type = nil
|
||||
@offset = [0, 0]
|
||||
@data = Data.new
|
||||
self
|
||||
end
|
||||
|
||||
# Finishes up with the generation and returns the Data object (could
|
||||
# probably use a better name...maybe just #data?)
|
||||
def data
|
||||
@data
|
||||
end
|
||||
|
||||
# This method is called once the generator is done with the unified
|
||||
# diff. It is a finalizer of sorts. By the time it is called all data
|
||||
# has been collected and processed.
|
||||
def finish
|
||||
# certain things could be set now that processing is done
|
||||
#identify_block
|
||||
end
|
||||
|
||||
def process(line)
|
||||
if is_header_line?(line)
|
||||
push Block.header
|
||||
current_block << Line.header(line)
|
||||
return
|
||||
end
|
||||
|
||||
if line =~ LINE_NUM_RE
|
||||
push Block.header
|
||||
current_block << Line.header(line)
|
||||
add_separator unless @offset[0].zero?
|
||||
@line_type = nil
|
||||
@offset = Array.new(2) { $3.to_i - 1 }
|
||||
return
|
||||
end
|
||||
|
||||
@line_type, line = LINE_TYPES[car(line)], cdr(line)
|
||||
|
||||
if @line_type == :add && @prev_line_type == :rem
|
||||
@offset[0] -= 1
|
||||
@buffer.push current_block.pop
|
||||
@buffer.push line
|
||||
process_block(:mod, false)
|
||||
return
|
||||
end
|
||||
|
||||
if LINE_TYPES.values.include?(@line_type)
|
||||
@buffer.push(line.to_s)
|
||||
process_block(@line_type, true)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
protected
|
||||
def is_header_line?(line)
|
||||
return true if ['+++ ', '--- '].include?(line[0,4])
|
||||
return true if line =~ /^(new|delete) file mode [0-9]+$/
|
||||
return true if line =~ /^diff \-\-git/
|
||||
return true if line =~ /^index \w+\.\.\w+( [0-9]+)?$/i
|
||||
false
|
||||
end
|
||||
|
||||
def process_block(diff_line_type, isnew = false)
|
||||
@data.pop unless isnew
|
||||
push Block.send(diff_line_type)
|
||||
|
||||
current_line = @buffer.pop
|
||||
return unless current_line
|
||||
|
||||
# \\ No newline at end of file
|
||||
if diff_line_type == :nonewline
|
||||
current_block << Line.nonewline('\\ No newline at end of file')
|
||||
return
|
||||
end
|
||||
|
||||
if isnew
|
||||
process_line(current_line, diff_line_type)
|
||||
else
|
||||
process_lines_with_differences(@buffer.shift, current_line)
|
||||
raise "buffer exceeded #{@buffer.inspect}" unless @buffer.empty?
|
||||
end
|
||||
end
|
||||
|
||||
def process_line(line, type, inline = false)
|
||||
case type
|
||||
when :add
|
||||
@offset[1] += 1
|
||||
current_block << Line.send(type, line, @offset[1], inline, @offset.dup)
|
||||
when :rem
|
||||
@offset[0] += 1
|
||||
current_block << Line.send(type, line, @offset[0], inline, @offset.dup)
|
||||
# when :rmod
|
||||
# @offset[0] += 1
|
||||
# @offset[1] += 1 # TODO: is that really correct?
|
||||
# current_block << Line.send(@prev_line_type, line, @offset[0])
|
||||
when :unmod
|
||||
@offset[0] += 1
|
||||
@offset[1] += 1
|
||||
current_block << Line.send(type, line, *@offset)
|
||||
end
|
||||
@prev_line_type = type
|
||||
end
|
||||
|
||||
# TODO Needs a better name...it does process a line (two in fact) but
|
||||
# its primary function is to add a Rem and an Add pair which
|
||||
# potentially have inline changes
|
||||
def process_lines_with_differences(oldline, newline)
|
||||
start, ending = get_change_extent(oldline, newline)
|
||||
|
||||
if start.zero? && ending.zero?
|
||||
process_line(oldline, :rem, false) # -
|
||||
process_line(newline, :add, false) # +
|
||||
else
|
||||
# -
|
||||
line = inline_diff(oldline, start, ending)
|
||||
process_line(line, :rem, true)
|
||||
# +
|
||||
line = inline_diff(newline, start, ending)
|
||||
process_line(line, :add, true)
|
||||
end
|
||||
end
|
||||
|
||||
# Inserts string formating characters around the section of a string
|
||||
# that differs internally from another line so that the Line class
|
||||
# can insert the desired formating
|
||||
def inline_diff(line, start, ending)
|
||||
if start != 0 || ending != 0
|
||||
last = ending + line.length
|
||||
str = line[0...start] + '\0' + line[start...last] + '\1' + line[last...line.length]
|
||||
end
|
||||
str || line
|
||||
end
|
||||
|
||||
def add_separator
|
||||
push SepBlock.new
|
||||
current_block << SepLine.new
|
||||
end
|
||||
|
||||
def car(line)
|
||||
line[0,1]
|
||||
end
|
||||
|
||||
def cdr(line)
|
||||
line[1..-1]
|
||||
end
|
||||
|
||||
# Returns the current Block object
|
||||
def current_block
|
||||
@data.last
|
||||
end
|
||||
|
||||
# Adds a Line object onto the current Block object
|
||||
def push(line)
|
||||
@data.push line
|
||||
end
|
||||
|
||||
# Determines the extent of differences between two string. Returns
|
||||
# an array containing the offset at which changes start, and then
|
||||
# negative offset at which the chnages end. If the two strings have
|
||||
# neither a common prefix nor a common suffic, [0, 0] is returned.
|
||||
def get_change_extent(str1, str2)
|
||||
start = 0
|
||||
limit = [str1.size, str2.size].sort.first
|
||||
while start < limit and str1[start, 1] == str2[start, 1]
|
||||
start += 1
|
||||
end
|
||||
ending = -1
|
||||
limit -= start
|
||||
while -ending <= limit and str1[ending, 1] == str2[ending, 1]
|
||||
ending -= 1
|
||||
end
|
||||
|
||||
return [start, ending + 1]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,12 +0,0 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
module Diff
|
||||
module Display #:nodoc:
|
||||
module VERSION #:nodoc:
|
||||
MAJOR = 0
|
||||
MINOR = 0
|
||||
TINY = 1
|
||||
|
||||
STRING = [MAJOR, MINOR, TINY].join('.')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,93 +0,0 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
module Diff
|
||||
module Renderer
|
||||
class Base
|
||||
def render(data)
|
||||
result = []
|
||||
data.each do |block|
|
||||
result << send("before_" + classify(block), block)
|
||||
result << block.map { |line| send(classify(line), line) }
|
||||
result << send("after_" + classify(block), block)
|
||||
end
|
||||
result.compact.join(new_line)
|
||||
end
|
||||
|
||||
def before_headerblock(block)
|
||||
end
|
||||
|
||||
def before_unmodblock(block)
|
||||
end
|
||||
|
||||
def before_modblock(block)
|
||||
end
|
||||
|
||||
def before_remblock(block)
|
||||
end
|
||||
|
||||
def before_addblock(block)
|
||||
end
|
||||
|
||||
def before_sepblock(block)
|
||||
end
|
||||
|
||||
def before_nonewlineblock(block)
|
||||
end
|
||||
|
||||
def headerline(line)
|
||||
line
|
||||
end
|
||||
|
||||
def unmodline(line)
|
||||
line
|
||||
end
|
||||
|
||||
def remline(line)
|
||||
line
|
||||
end
|
||||
|
||||
def addline(line)
|
||||
line
|
||||
end
|
||||
|
||||
def sepline(line)
|
||||
|
||||
end
|
||||
|
||||
def nonewlineline(line)
|
||||
line
|
||||
end
|
||||
|
||||
def after_headerblock(block)
|
||||
end
|
||||
|
||||
def after_unmodblock(block)
|
||||
end
|
||||
|
||||
def after_modblock(block)
|
||||
end
|
||||
|
||||
def after_remblock(block)
|
||||
"</div>"
|
||||
end
|
||||
|
||||
def after_addblock(block)
|
||||
"</div>"
|
||||
end
|
||||
|
||||
def after_sepblock(block)
|
||||
end
|
||||
|
||||
def after_nonewlineblock(block)
|
||||
end
|
||||
|
||||
def new_line
|
||||
""
|
||||
end
|
||||
|
||||
protected
|
||||
def classify(object)
|
||||
object.class.name[/\w+$/].downcase
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,94 +0,0 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
module Diff
|
||||
module Renderer
|
||||
class Diff < Base
|
||||
def before_addblock(block)
|
||||
%q{<tbody class="add"><tr>}
|
||||
end
|
||||
|
||||
def before_remblock(block)
|
||||
%Q{<tbody class="rem"><tr>}
|
||||
end
|
||||
|
||||
def before_modblock(block)
|
||||
%Q{<tbody class="mod"><tr>}
|
||||
end
|
||||
|
||||
def before_unmodblock(block)
|
||||
%Q{<tbody class="unmod"><tr>}
|
||||
end
|
||||
|
||||
def before_sepblock(block)
|
||||
%Q{<tbody class="sep"><tr>}
|
||||
end
|
||||
|
||||
# After blocks
|
||||
def after_addblock(block)
|
||||
"</tbody>"
|
||||
end
|
||||
|
||||
def after_remblock(block)
|
||||
"</tbody>"
|
||||
end
|
||||
|
||||
def after_modblock(block)
|
||||
"</tbody>"
|
||||
end
|
||||
|
||||
def after_unmodblock(block)
|
||||
"</tbody>"
|
||||
end
|
||||
|
||||
def after_sepblock(block)
|
||||
"</tbody>"
|
||||
end
|
||||
|
||||
# Before lines
|
||||
def addline(line)
|
||||
# adds go on the right
|
||||
%Q{<th class="line-numbers">#{line.old_number}</th>} +
|
||||
%Q{<td class="code ins"></td>} +
|
||||
%Q{<th class="line-numbers">#{line.new_number}</th>} +
|
||||
%Q{<td class="code ins"><ins>#{line}</ins></td></tr>}
|
||||
end
|
||||
|
||||
def remline(line)
|
||||
# rems go on the left (hide the right side)
|
||||
%Q{<th class="line-numbers">#{line.old_number}</th>} +
|
||||
%Q{<td class="code del"><del>#{line}</del></td>} +
|
||||
%Q{<th class="line-numbers">#{line.new_number}</th>} +
|
||||
%Q{<td class="code del hidden"><del>#{line}</del></td></tr>}
|
||||
end
|
||||
|
||||
def modline(line)
|
||||
# TODO: figure how we best display these
|
||||
# %Q{<th class="line-numbers">#{line.old_number}</th>} +
|
||||
# %Q{<td class="code changed mod">#{render_line(line)}</td>} +
|
||||
# %Q{<th class="line-numbers">#{line.new_number}</th>} +
|
||||
# %Q{<td class="code changed mod">#{render_line(line)}</td></tr>}
|
||||
end
|
||||
|
||||
def unmodline(line)
|
||||
# unmods goes on both sides
|
||||
%Q{<th class="line-numbers">#{line.old_number}</th>} +
|
||||
%Q{<td class="code unchanged unmod">#{line}</td>} +
|
||||
%Q{<th class="line-numbers">#{line.new_number}</th>} +
|
||||
%Q{<td class="code unchanged unmod">#{line}</td></tr>}
|
||||
end
|
||||
|
||||
def sepline(line)
|
||||
%Q{<th class="line-numbers line-num-cut">…</th>} +
|
||||
%Q{<td class="code cut-line"></td>} +
|
||||
%Q{<th class="line-numbers line-num-cut">…</th>} +
|
||||
%Q{<td class="code cut-line"></td></tr>}
|
||||
end
|
||||
|
||||
def nonewlineline(line)
|
||||
%Q{<th class="line-numbers line-num-cut">…</th>} +
|
||||
%Q{<td class="code mod"></td>} +
|
||||
%Q{<th class="line-numbers line-num-cut">…</th>} +
|
||||
%Q{<td class="code mod">#{line}</td></tr>}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,34 +0,0 @@
|
|||
desc 'Release the website and new gem version'
|
||||
task :deploy => [:check_version, :website, :release] do
|
||||
puts "Remember to create SVN tag:"
|
||||
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
||||
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
||||
puts "Suggested comment:"
|
||||
puts "Tagging release #{CHANGES}"
|
||||
end
|
||||
|
||||
desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
|
||||
task :local_deploy => [:website_generate, :install_gem]
|
||||
|
||||
task :check_version do
|
||||
unless ENV['VERSION']
|
||||
puts 'Must pass a VERSION=x.y.z release version'
|
||||
exit
|
||||
end
|
||||
unless ENV['VERSION'] == VERS
|
||||
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
||||
exit
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
|
||||
task :install_gem_no_doc => [:clean, :package] do
|
||||
sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
|
||||
end
|
||||
|
||||
namespace :manifest do
|
||||
desc 'Recreate Manifest.txt to include ALL files'
|
||||
task :refresh do
|
||||
`rake check_manifest | patch -p0 > Manifest.txt`
|
||||
end
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
task :ruby_env do
|
||||
RUBY_APP = if RUBY_PLATFORM =~ /java/
|
||||
"jruby"
|
||||
else
|
||||
"ruby"
|
||||
end unless defined? RUBY_APP
|
||||
end
|
|
@ -1,17 +0,0 @@
|
|||
desc 'Generate website files'
|
||||
task :website_generate => :ruby_env do
|
||||
(Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
|
||||
sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Upload website files to rubyforge'
|
||||
task :website_upload do
|
||||
host = "#{rubyforge_username}@rubyforge.org"
|
||||
remote_dir = "/var/www/gforge-projects/#{PATH}/"
|
||||
local_dir = 'website'
|
||||
sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
|
||||
end
|
||||
|
||||
desc 'Generate and upload website files'
|
||||
task :website => [:website_generate, :website_upload, :publish_docs]
|
|
@ -1,14 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
||||
|
||||
begin
|
||||
require 'rubigen'
|
||||
rescue LoadError
|
||||
require 'rubygems'
|
||||
require 'rubigen'
|
||||
end
|
||||
require 'rubigen/scripts/destroy'
|
||||
|
||||
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
||||
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
||||
RubiGen::Scripts::Destroy.new.run(ARGV)
|
|
@ -1,14 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
||||
|
||||
begin
|
||||
require 'rubigen'
|
||||
rescue LoadError
|
||||
require 'rubygems'
|
||||
require 'rubigen'
|
||||
end
|
||||
require 'rubigen/scripts/generate'
|
||||
|
||||
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
||||
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
||||
RubiGen::Scripts::Generate.new.run(ARGV)
|
|
@ -1,74 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'rubygems'
|
||||
begin
|
||||
require 'newgem'
|
||||
rescue LoadError
|
||||
puts "\n\nGenerating the website requires the newgem RubyGem"
|
||||
puts "Install: gem install newgem\n\n"
|
||||
exit(1)
|
||||
end
|
||||
require 'redcloth'
|
||||
require 'syntax/convertors/html'
|
||||
require 'erb'
|
||||
require File.dirname(__FILE__) + '/../lib/diff-display/version.rb'
|
||||
|
||||
version = Diff-display::VERSION::STRING
|
||||
download = 'http://rubyforge.org/projects/diff-display'
|
||||
|
||||
class Fixnum
|
||||
def ordinal
|
||||
# teens
|
||||
return 'th' if (10..19).include?(self % 100)
|
||||
# others
|
||||
case self % 10
|
||||
when 1: return 'st'
|
||||
when 2: return 'nd'
|
||||
when 3: return 'rd'
|
||||
else return 'th'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Time
|
||||
def pretty
|
||||
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
||||
end
|
||||
end
|
||||
|
||||
def convert_syntax(syntax, source)
|
||||
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
||||
end
|
||||
|
||||
if ARGV.length >= 1
|
||||
src, template = ARGV
|
||||
template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
|
||||
|
||||
else
|
||||
puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
|
||||
exit!
|
||||
end
|
||||
|
||||
template = ERB.new(File.open(template).read)
|
||||
|
||||
title = nil
|
||||
body = nil
|
||||
File.open(src) do |fsrc|
|
||||
title_text = fsrc.readline
|
||||
body_text = fsrc.read
|
||||
syntax_items = []
|
||||
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
|
||||
ident = syntax_items.length
|
||||
element, syntax, source = $1, $2, $3
|
||||
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
|
||||
"syntax-temp-#{ident}"
|
||||
}
|
||||
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
||||
body = RedCloth.new(body_text).to_html
|
||||
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
|
||||
end
|
||||
stat = File.stat(src)
|
||||
created = stat.ctime
|
||||
modified = stat.mtime
|
||||
|
||||
$stdout << template.result(binding)
|
File diff suppressed because it is too large
Load Diff
|
@ -1,590 +0,0 @@
|
|||
--- unified.rb (revision 620)
|
||||
+++ unified.rb (revision 644)
|
||||
@@ -1,298 +1,390 @@
|
||||
module Diff
|
||||
module Display
|
||||
module Unified
|
||||
-
|
||||
- LINE_RE = /@@ [+-]([0-9]+),([0-9]+) [+-]([0-9]+),([0-9]+) @@/
|
||||
- TABWIDTH = 4
|
||||
- SPACE = ' ' #' '
|
||||
- # By defaul don't wrap inline diffs in anything
|
||||
- INLINE_REM_OPEN = "\e[4;33m"
|
||||
- INLINE_REM_CLOSE = "\e[m"
|
||||
- INLINE_ADD_OPEN = "\e[4;35m"
|
||||
- INLINE_ADD_CLOSE = "\e[m"
|
||||
- ESCAPE_HTML = false
|
||||
-
|
||||
class Line < String
|
||||
- attr_reader :add_lineno, :rem_lineno
|
||||
- def initialize(line, type, add_lineno, rem_lineno = add_lineno)
|
||||
+ def initialize(line, line_number)
|
||||
super(line)
|
||||
- @type = type
|
||||
- @add_lineno = add_lineno
|
||||
- @rem_lineno = rem_lineno
|
||||
+ @line_number = line_number
|
||||
+ self
|
||||
end
|
||||
|
||||
+ def contains_inline_change?
|
||||
+ @inline
|
||||
+ end
|
||||
+
|
||||
def number
|
||||
- add_lineno ? add_lineno : rem_lineno
|
||||
+ @line_number
|
||||
end
|
||||
|
||||
- def type
|
||||
- @type
|
||||
+ def decorate(&block)
|
||||
+ yield self
|
||||
end
|
||||
|
||||
- class << self
|
||||
- def add(line, add_lineno)
|
||||
- AddLine.new(line, add_lineno)
|
||||
+ def inline_add_open; '' end
|
||||
+ def inline_add_close; '' end
|
||||
+ def inline_rem_open; '' end
|
||||
+ def inline_rem_close; '' end
|
||||
+
|
||||
+ protected
|
||||
+
|
||||
+ def escape
|
||||
+ self
|
||||
end
|
||||
|
||||
- def rem(line, rem_lineno)
|
||||
- RemLine.new(line, rem_lineno)
|
||||
+ def expand
|
||||
+ escape.gsub("\t", ' ' * tabwidth).gsub(/ ( +)|^ /) do |match|
|
||||
+ (space + ' ') * (match.size / 2) +
|
||||
+ space * (match.size % 2)
|
||||
+ end
|
||||
end
|
||||
|
||||
- def unmod(line, lineno)
|
||||
- UnModLine.new(line, lineno)
|
||||
+ def tabwidth
|
||||
+ 4
|
||||
end
|
||||
|
||||
- def mod(line, lineno)
|
||||
- ModLine.new(line, lineno)
|
||||
+
|
||||
+ def space
|
||||
+ ' '
|
||||
end
|
||||
+
|
||||
+ class << self
|
||||
+ def add(line, line_number, inline = false)
|
||||
+ AddLine.new(line, line_number, inline)
|
||||
+ end
|
||||
+
|
||||
+ def rem(line, line_number, inline = false)
|
||||
+ RemLine.new(line, line_number, inline)
|
||||
+ end
|
||||
+
|
||||
+ def unmod(line, line_number)
|
||||
+ UnModLine.new(line, line_number)
|
||||
+ end
|
||||
end
|
||||
end
|
||||
|
||||
class AddLine < Line
|
||||
- def initialize(line, add_lineno)
|
||||
- super(line, 'add', add_lineno, nil)
|
||||
+ def initialize(line, line_number, inline = false)
|
||||
+ line = inline ? line % [inline_add_open, inline_add_close] : line
|
||||
+ super(line, line_number)
|
||||
+ @inline = inline
|
||||
+ self
|
||||
end
|
||||
end
|
||||
|
||||
class RemLine < Line
|
||||
- def initialize(line, rem_lineno)
|
||||
- super(line, 'rem', nil, rem_lineno)
|
||||
+ def initialize(line, line_number, inline = false)
|
||||
+ line = inline ? line % [inline_rem_open, inline_rem_close] : line
|
||||
+ super(line, line_number)
|
||||
+ @inline = inline
|
||||
+ self
|
||||
end
|
||||
end
|
||||
|
||||
class UnModLine < Line
|
||||
- def initialize(line, lineno)
|
||||
- super(line, 'unmod', lineno)
|
||||
+ def initialize(line, line_number)
|
||||
+ super(line, line_number)
|
||||
end
|
||||
end
|
||||
|
||||
- class ModLine < Line
|
||||
- def initialize(line, lineno)
|
||||
- super(line, 'mod', lineno)
|
||||
+ class SepLine < Line
|
||||
+ def initialize(line = '...')
|
||||
+ super(line, nil)
|
||||
end
|
||||
end
|
||||
|
||||
+ # This class is an array which contains Line objects. Just like Line
|
||||
+ # classes, several Block classes inherit from Block. If all the lines
|
||||
+ # in the block are added lines then it is an AddBlock. If all lines
|
||||
+ # in the block are removed lines then it is a RemBlock. If the lines
|
||||
+ # in the block are all unmodified then it is an UnMod block. If the
|
||||
+ # lines in the block are a mixture of added and removed lines then
|
||||
+ # it is a ModBlock. There are no blocks that contain a mixture of
|
||||
+ # modified and unmodified lines.
|
||||
class Block < Array
|
||||
- def initialize(type)
|
||||
- super(0)
|
||||
- @type = type
|
||||
+ def initialize
|
||||
+ super
|
||||
+ @line_types = []
|
||||
end
|
||||
|
||||
def <<(line_object)
|
||||
super(line_object)
|
||||
- (@line_types ||= []).push(line_object.type)
|
||||
- @line_types.uniq!
|
||||
+ line_class = line_object.class.name[/\w+$/]
|
||||
+ @line_types.push(line_class) unless @line_types.include?(line_class)
|
||||
self
|
||||
end
|
||||
|
||||
+ def decorate(&block)
|
||||
+ yield self
|
||||
+ end
|
||||
+
|
||||
def line_types
|
||||
@line_types
|
||||
end
|
||||
|
||||
- def type
|
||||
- @type
|
||||
+ class << self
|
||||
+ def add; AddBlock.new end
|
||||
+ def rem; RemBlock.new end
|
||||
+ def mod; ModBlock.new end
|
||||
+ def unmod; UnModBlock.new end
|
||||
end
|
||||
end
|
||||
|
||||
- class Generator < Array
|
||||
+ class AddBlock < Block; end
|
||||
+ class RemBlock < Block; end
|
||||
+ class ModBlock < Block; end
|
||||
+ class UnModBlock < Block; end
|
||||
+ class SepBlock < Block; end
|
||||
|
||||
+ # This data object contains the generated diff data structure. It is an
|
||||
+ # array of Block objects which are themselves arrays of Line objects. The
|
||||
+ # Generator class returns a Data instance object after it is done
|
||||
+ # processing the diff.
|
||||
+ class Data < Array
|
||||
+ def initialize
|
||||
+ super
|
||||
+ end
|
||||
+
|
||||
+ def debug
|
||||
+ demodularize = Proc.new {|obj| obj.class.name[/\w+$/]}
|
||||
+ each do |diff_block|
|
||||
+ print "*" * 40, ' ', demodularize.call(diff_block)
|
||||
+ puts
|
||||
+ puts diff_block.map {|line|
|
||||
+ "%5d" % line.number +
|
||||
+ " [#{demodularize.call(line)}]" +
|
||||
+ line
|
||||
+ }.join("\n")
|
||||
+ puts "*" * 40, ' '
|
||||
+ end
|
||||
+ end
|
||||
+
|
||||
+ end
|
||||
+
|
||||
+ # Processes the diff and generates a Data object which contains the
|
||||
+ # resulting data structure.
|
||||
+ class Generator
|
||||
+
|
||||
+ # Extracts the line number info for a given diff section
|
||||
+ LINE_NUM_RE = /@@ [+-]([0-9]+),([0-9]+) [+-]([0-9]+),([0-9]+) @@/
|
||||
+ LINE_TYPES = {'+' => :add, '-' => :rem, ' ' => :unmod}
|
||||
+
|
||||
class << self
|
||||
- def run(udiff, options = {})
|
||||
- generator = new(options)
|
||||
- udiff.split("\n").each {|line| generator.build(line) }
|
||||
- generator.close
|
||||
- generator
|
||||
+
|
||||
+ # Runs the generator on a diff and returns a Data object without
|
||||
+ # instantiating a Generator object
|
||||
+ def run(udiff)
|
||||
+ raise ArgumentError, "Object must be enumerable" unless udiff.respond_to?(:each)
|
||||
+ generator = new
|
||||
+ udiff.each {|line| generator.process(line.chomp)}
|
||||
+ generator.render
|
||||
end
|
||||
end
|
||||
|
||||
- def initialize(options = {})
|
||||
- super(0)
|
||||
- default_options = {:inline_add_open => INLINE_ADD_OPEN,
|
||||
- :inline_add_close => INLINE_ADD_CLOSE,
|
||||
- :inline_rem_open => INLINE_REM_OPEN,
|
||||
- :inline_rem_close => INLINE_REM_CLOSE,
|
||||
- :escape_html => ESCAPE_HTML,
|
||||
- :tabwidth => TABWIDTH,
|
||||
- :space => SPACE}
|
||||
-
|
||||
- @options = default_options.merge(options)
|
||||
- @block = []
|
||||
- @ttype = nil
|
||||
- @p_block = []
|
||||
- @p_type = nil
|
||||
- @changeno = -1
|
||||
- @blockno = 0
|
||||
+ def initialize
|
||||
+ @buffer = []
|
||||
+ @prev_buffer = []
|
||||
+ @line_type = nil
|
||||
+ @prev_line_type = nil
|
||||
@offset_base = 0
|
||||
@offset_changed = 0
|
||||
+ @data = Diff::Display::Unified::Data.new
|
||||
+ self
|
||||
end
|
||||
|
||||
- def current_block
|
||||
- last
|
||||
+ # Operates on a single line from the diff and passes along the
|
||||
+ # collected data to the appropriate method for further processing. The
|
||||
+ # cycle of processing is in general:
|
||||
+ #
|
||||
+ # process --> identify_block --> process_block --> process_line
|
||||
+ #
|
||||
+ def process(line)
|
||||
+ return if ['++', '--'].include?(line[0,2])
|
||||
+
|
||||
+ if match = LINE_NUM_RE.match(line)
|
||||
+ identify_block
|
||||
+ push SepBlock.new and current_block << SepLine.new unless @offset_changed.zero?
|
||||
+ @line_type = nil
|
||||
+ @offset_base = match[1].to_i - 1
|
||||
+ @offset_changed = match[3].to_i - 1
|
||||
+ return
|
||||
+ end
|
||||
+
|
||||
+ new_line_type, line = LINE_TYPES[car(line)], cdr(line)
|
||||
+
|
||||
+ # Add line to the buffer if it's the same diff line type
|
||||
+ # as the previous line
|
||||
+ #
|
||||
+ # e.g.
|
||||
+ #
|
||||
+ # + This is a new line
|
||||
+ # + As is this one
|
||||
+ # + And yet another one...
|
||||
+ #
|
||||
+ if new_line_type.eql?(@line_type)
|
||||
+ @buffer.push(line)
|
||||
+ else
|
||||
+ # Side by side inline diff
|
||||
+ #
|
||||
+ # e.g.
|
||||
+ #
|
||||
+ # - This line just had to go
|
||||
+ # + This line is on the way in
|
||||
+ #
|
||||
+ if new_line_type.eql?(LINE_TYPES['+']) and @line_type.eql?(LINE_TYPES['-'])
|
||||
+ @prev_buffer = @buffer
|
||||
+ @prev_line_type = @line_type
|
||||
+ else
|
||||
+ identify_block
|
||||
+ end
|
||||
+ @buffer = [line]
|
||||
+ @line_type = new_line_type
|
||||
+ end
|
||||
end
|
||||
|
||||
+ # Finishes up with the generation and returns the Data object (could
|
||||
+ # probably use a better name...maybe just #data?)
|
||||
def render
|
||||
close
|
||||
- self
|
||||
+ @data
|
||||
end
|
||||
-
|
||||
- def escape(text)
|
||||
- return '' unless text
|
||||
- return text unless @options[:escape_html]
|
||||
- text.gsub('&', '&').
|
||||
- gsub('<', '<' ).
|
||||
- gsub('>', '>' ).
|
||||
- gsub('"', '"')
|
||||
- end
|
||||
|
||||
- def expand(text)
|
||||
- escape(text).gsub(/ ( +)|^ /) do |match|
|
||||
- (@options[:space] + ' ') * (match.size / 2) +
|
||||
- @options[:space] * (match.size % 2)
|
||||
- end
|
||||
- end
|
||||
+ protected
|
||||
|
||||
- def inline_diff(line, start, ending, change)
|
||||
- expand(line[0, start]) +
|
||||
- change +
|
||||
- expand(line[ending, ending.abs])
|
||||
- end
|
||||
+ def identify_block
|
||||
+ if @prev_line_type.eql?(LINE_TYPES['-']) and @line_type.eql?(LINE_TYPES['+'])
|
||||
+ process_block(:mod, {:old => @prev_buffer, :new => @buffer})
|
||||
+ else
|
||||
+ if LINE_TYPES.values.include?(@line_type)
|
||||
+ process_block(@line_type, {:new => @buffer})
|
||||
+ end
|
||||
+ end
|
||||
|
||||
- def write_line(oldline, newline)
|
||||
- start, ending = get_change_extent(oldline, newline)
|
||||
- change = ''
|
||||
- if oldline.size > start - ending
|
||||
- change = @options[:inline_rem_open] +
|
||||
- expand(oldline[start...ending]) +
|
||||
- @options[:inline_rem_close]
|
||||
+ @prev_line_type = nil
|
||||
end
|
||||
|
||||
- line = inline_diff(oldline, start, ending, change)
|
||||
- current_block << Line.rem(line, @offset_base)
|
||||
+ def process_block(diff_line_type, blocks = {:old => nil, :new => nil})
|
||||
+ push Block.send(diff_line_type)
|
||||
+ old, new = blocks[:old], blocks[:new]
|
||||
|
||||
- change = ''
|
||||
- if newline.size > start - ending
|
||||
- change = @options[:inline_add_open] +
|
||||
- expand(newline[start...ending]) +
|
||||
- @options[:inline_add_close]
|
||||
+ # Mod block
|
||||
+ if diff_line_type.eql?(:mod) and old.size & new.size == 1
|
||||
+ process_line(old.first, new.first)
|
||||
+ return
|
||||
+ end
|
||||
+
|
||||
+ if old and not old.empty?
|
||||
+ old.each do |line|
|
||||
+ @offset_base += 1
|
||||
+ current_block << Line.send(@prev_line_type, line, @offset_base)
|
||||
+ end
|
||||
+ end
|
||||
+
|
||||
+ if new and not new.empty?
|
||||
+ new.each do |line|
|
||||
+ @offset_changed += 1
|
||||
+ current_block << Line.send(@line_type, line, @offset_changed)
|
||||
+ end
|
||||
+ end
|
||||
end
|
||||
|
||||
- line = inline_diff(newline, start, ending, change)
|
||||
- current_block << Line.add(line, @offset_changed)
|
||||
- end
|
||||
+ # TODO Needs a better name...it does process a line (two in fact) but
|
||||
+ # its primary function is to add a Rem and an Add pair which
|
||||
+ # potentially have inline changes
|
||||
+ def process_line(oldline, newline)
|
||||
+ start, ending = get_change_extent(oldline, newline)
|
||||
|
||||
- def write_block(dtype, old = nil, new = nil)
|
||||
- push Block.new(dtype)
|
||||
+ # -
|
||||
+ line = inline_diff(oldline, start, ending)
|
||||
+ current_block << Line.rem(line, @offset_base += 1, true)
|
||||
|
||||
- if dtype == 'mod' and old.size == 1 and new.size == 1
|
||||
- write_line(old.first, new.first)
|
||||
- return
|
||||
+ # +
|
||||
+ line = inline_diff(newline, start, ending)
|
||||
+ current_block << Line.add(line, @offset_changed += 1, true)
|
||||
end
|
||||
|
||||
- if old and not old.empty?
|
||||
- old.each do |e|
|
||||
- current_block << Line.send(dtype, expand(e), @offset_base)
|
||||
- @offset_base += 1
|
||||
- end
|
||||
+ # Inserts string formating characters around the section of a string
|
||||
+ # that differs internally from another line so that the Line class
|
||||
+ # can insert the desired formating
|
||||
+ def inline_diff(line, start, ending)
|
||||
+ line[0, start] +
|
||||
+ '%s' + extract_change(line, start, ending) + '%s' +
|
||||
+ line[ending, ending.abs]
|
||||
end
|
||||
|
||||
- if new and not new.empty?
|
||||
- new.each do |e|
|
||||
- current_block << Line.send(dtype, expand(e), @offset_changed)
|
||||
- @offset_changed += 1
|
||||
- end
|
||||
+ def extract_change(line, start, ending)
|
||||
+ line.size > (start - ending) ? line[start...ending] : ''
|
||||
end
|
||||
- end
|
||||
|
||||
- def print_block
|
||||
- if @p_type.eql?('-') and @ttype.eql?('+')
|
||||
- write_block('mod', @p_block, @block)
|
||||
- else
|
||||
- case @ttype
|
||||
- when '+'
|
||||
- write_block('add', @block)
|
||||
- when '-'
|
||||
- write_block('rem', @block)
|
||||
- when ' '
|
||||
- write_block('unmod', @block)
|
||||
- end
|
||||
+ def car(line)
|
||||
+ line[0,1]
|
||||
end
|
||||
|
||||
- @block = @p_block = []
|
||||
- @p_type = ' '
|
||||
- @blockno += 1
|
||||
- end
|
||||
+ def cdr(line)
|
||||
+ line[1..-1]
|
||||
+ end
|
||||
|
||||
- def build(text)
|
||||
- # TODO Names of the files and their versions go here perhaps
|
||||
+ # Returns the current Block object
|
||||
+ def current_block
|
||||
+ @data.last
|
||||
+ end
|
||||
|
||||
- return if ['++', '--'].include?(text[0,2])
|
||||
+ # Adds a Line object onto the current Block object
|
||||
+ def push(line)
|
||||
+ @data.push line
|
||||
+ end
|
||||
|
||||
- if match = LINE_RE.match(text)
|
||||
- print_block
|
||||
- @changeno += 1
|
||||
- @blockno = 0
|
||||
- @offset_base = match[1].to_i - 1
|
||||
- @offset_changed = match[3].to_i - 1
|
||||
- return
|
||||
+ # This method is called once the generator is done with the unified
|
||||
+ # diff. It is a finalizer of sorts. By the time it is called all data
|
||||
+ # has been collected and processed.
|
||||
+ def close
|
||||
+ # certain things could be set now that processing is done
|
||||
+ identify_block
|
||||
end
|
||||
|
||||
- # Set ttype to first character of line
|
||||
- ttype = text[0, 1]
|
||||
- text = text[1..-1]
|
||||
- text = text.gsub("\t", ' ' * @options[:tabwidth]) if text
|
||||
- # If it's the same type of mod as the last line push this line onto the
|
||||
- # block stack
|
||||
- if ttype.eql?(@ttype)
|
||||
- @block.push(text)
|
||||
- else
|
||||
- # If we have a side by side subtraction/addition
|
||||
- if ttype == '+' and @ttype == '-'
|
||||
- @p_block = @block
|
||||
- @p_type = @ttype
|
||||
- else
|
||||
- print_block
|
||||
+ # Determines the extent of differences between two string. Returns
|
||||
+ # an array containing the offset at which changes start, and then
|
||||
+ # negative offset at which the chnages end. If the two strings have
|
||||
+ # neither a common prefix nor a common suffic, [0, 0] is returned.
|
||||
+ def get_change_extent(str1, str2)
|
||||
+ start = 0
|
||||
+ limit = [str1.size, str2.size].sort.first
|
||||
+ while start < limit and str1[start, 1] == str2[start, 1]
|
||||
+ start += 1
|
||||
end
|
||||
- @block = [text]
|
||||
- @ttype = ttype
|
||||
+ ending = -1
|
||||
+ limit -= start
|
||||
+ while -ending <= limit and str1[ending, 1] == str2[ending, 1]
|
||||
+ ending -= 1
|
||||
+ end
|
||||
+
|
||||
+ return [start, ending + 1]
|
||||
end
|
||||
- end
|
||||
+ end
|
||||
|
||||
- def debug
|
||||
- each do |diff_block|
|
||||
- print "*" * (40 - diff_block.type.size / 2), ' ', diff_block.type
|
||||
- puts
|
||||
- puts diff_block.map {|line| "#{line.number}" << line << " [#{line.type}]"}.join("\n")
|
||||
- print "Line types:"
|
||||
- puts diff_block.line_types.join(", ")
|
||||
- puts
|
||||
- end
|
||||
+ # Mostly a convinience class at this point that just overwrites various
|
||||
+ # customization methods
|
||||
+ class HTMLGenerator < Generator
|
||||
+
|
||||
+ # This and the space method now don't work/make sense now that those
|
||||
+ # methods are part of the Line class and there certainly won't be an
|
||||
+ # HTMLLine class
|
||||
+ def escape(text)
|
||||
+ text.gsub('&', '&').
|
||||
+ gsub('<', '<' ).
|
||||
+ gsub('>', '>' ).
|
||||
+ gsub('"', '"')
|
||||
end
|
||||
|
||||
- def close
|
||||
- # certain things could be set now that processing is done
|
||||
- print_block
|
||||
+ def space
|
||||
+ ' '
|
||||
end
|
||||
|
||||
- # Determines the extent of differences between two string. Returns
|
||||
- # an array containing the offset at which changes start, and then
|
||||
- # negative offset at which the chnages end. If the two strings have
|
||||
- # neither a common prefix nor a common suffic, [0, 0] is returned.
|
||||
- def get_change_extent(str1, str2)
|
||||
- start = 0
|
||||
- limit = [str1.size, str2.size].sort.first
|
||||
- while start < limit and str1[start, 1] == str2[start, 1]
|
||||
- start += 1
|
||||
- end
|
||||
- ending = -1
|
||||
- limit -= start
|
||||
- while -ending <= limit and str1[ending, 1] == str2[ending, 1]
|
||||
- ending -= 1
|
||||
- end
|
||||
+ end
|
||||
|
||||
- return [start, ending + 1]
|
||||
- end
|
||||
+ # See doc string for HTMLGenerator
|
||||
+ class ASCIIGenerator < Generator
|
||||
end
|
||||
+
|
||||
end
|
||||
end
|
||||
end
|
||||
-
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue