init commit
This commit is contained in:
parent
93efff9452
commit
9ba1224867
307 changed files with 11053 additions and 0 deletions
42
spec/models/issue_spec.rb
Normal file
42
spec/models/issue_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Issue do
|
||||
describe "Associations" do
|
||||
it { should belong_to(:project) }
|
||||
it { should belong_to(:author) }
|
||||
it { should belong_to(:assignee) }
|
||||
end
|
||||
|
||||
describe "Validation" do
|
||||
it { should validate_presence_of(:title) }
|
||||
it { should validate_presence_of(:author_id) }
|
||||
it { should validate_presence_of(:project_id) }
|
||||
it { should validate_presence_of(:assignee_id) }
|
||||
end
|
||||
|
||||
describe "Scope" do
|
||||
it { Issue.should respond_to :closed }
|
||||
it { Issue.should respond_to :opened }
|
||||
end
|
||||
|
||||
it { Factory.create(:issue,
|
||||
:author => Factory(:user),
|
||||
:assignee => Factory(:user),
|
||||
:project => Factory.create(:project)).should be_valid }
|
||||
|
||||
end
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: issues
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# title :string(255)
|
||||
# content :text
|
||||
# assignee_id :integer
|
||||
# author_id :integer
|
||||
# project_id :integer
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# closed :boolean default(FALSE), not null
|
||||
#
|
||||
|
32
spec/models/key_spec.rb
Normal file
32
spec/models/key_spec.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Key do
|
||||
describe "Associations" do
|
||||
it { should belong_to(:user) }
|
||||
end
|
||||
|
||||
describe "Validation" do
|
||||
it { should validate_presence_of(:title) }
|
||||
it { should validate_presence_of(:key) }
|
||||
end
|
||||
|
||||
describe "Methods" do
|
||||
it { should respond_to :projects }
|
||||
end
|
||||
|
||||
it { Factory.create(:key,
|
||||
:user => Factory(:user)).should be_valid }
|
||||
end
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: keys
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# user_id :integer not null
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# key :text
|
||||
# title :string(255)
|
||||
# identifier :string(255)
|
||||
#
|
||||
|
78
spec/models/note_spec.rb
Normal file
78
spec/models/note_spec.rb
Normal file
|
@ -0,0 +1,78 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Note do
|
||||
describe "Associations" do
|
||||
it { should belong_to(:project) }
|
||||
end
|
||||
|
||||
describe "Validation" do
|
||||
it { should validate_presence_of(:note) }
|
||||
it { should validate_presence_of(:project) }
|
||||
end
|
||||
|
||||
it { Factory.create(:note,
|
||||
:project => Factory.create(:project)).should be_valid }
|
||||
|
||||
describe :authorization do
|
||||
before do
|
||||
@p1 = Factory :project
|
||||
@p2 = Factory :project, :code => "alien", :path => "legit_1"
|
||||
@u1 = Factory :user
|
||||
@u2 = Factory :user
|
||||
@u3 = Factory :user
|
||||
@abilities = Six.new
|
||||
@abilities << Ability
|
||||
end
|
||||
|
||||
describe :read do
|
||||
before do
|
||||
@p1.users_projects.create(:user => @u1, :read => false)
|
||||
@p1.users_projects.create(:user => @u2, :read => true)
|
||||
@p2.users_projects.create(:user => @u3, :read => true)
|
||||
end
|
||||
|
||||
it { @abilities.allowed?(@u1, :read_note, @p1).should be_false }
|
||||
it { @abilities.allowed?(@u2, :read_note, @p1).should be_true }
|
||||
it { @abilities.allowed?(@u3, :read_note, @p1).should be_false }
|
||||
end
|
||||
|
||||
describe :write do
|
||||
before do
|
||||
@p1.users_projects.create(:user => @u1, :write => false)
|
||||
@p1.users_projects.create(:user => @u2, :write => true)
|
||||
@p2.users_projects.create(:user => @u3, :write => true)
|
||||
end
|
||||
|
||||
it { @abilities.allowed?(@u1, :write_note, @p1).should be_false }
|
||||
it { @abilities.allowed?(@u2, :write_note, @p1).should be_true }
|
||||
it { @abilities.allowed?(@u3, :write_note, @p1).should be_false }
|
||||
end
|
||||
|
||||
describe :admin do
|
||||
before do
|
||||
@p1.users_projects.create(:user => @u1, :admin => false)
|
||||
@p1.users_projects.create(:user => @u2, :admin => true)
|
||||
@p2.users_projects.create(:user => @u3, :admin => true)
|
||||
end
|
||||
|
||||
it { @abilities.allowed?(@u1, :admin_note, @p1).should be_false }
|
||||
it { @abilities.allowed?(@u2, :admin_note, @p1).should be_true }
|
||||
it { @abilities.allowed?(@u3, :admin_note, @p1).should be_false }
|
||||
end
|
||||
end
|
||||
end
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: notes
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# note :string(255)
|
||||
# noteable_id :string(255)
|
||||
# noteable_type :string(255)
|
||||
# author_id :integer
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# project_id :integer
|
||||
# attachment :string(255)
|
||||
#
|
||||
|
57
spec/models/project_security_spec.rb
Normal file
57
spec/models/project_security_spec.rb
Normal file
|
@ -0,0 +1,57 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Project do
|
||||
describe :authorization do
|
||||
before do
|
||||
@p1 = Factory :project
|
||||
@u1 = Factory :user
|
||||
@u2 = Factory :user
|
||||
@abilities = Six.new
|
||||
@abilities << Ability
|
||||
end
|
||||
|
||||
describe :read do
|
||||
before do
|
||||
@p1.users_projects.create(:project => @p1, :user => @u1, :read => false)
|
||||
@p1.users_projects.create(:project => @p1, :user => @u2, :read => true)
|
||||
end
|
||||
|
||||
it { @abilities.allowed?(@u1, :read_project, @p1).should be_false }
|
||||
it { @abilities.allowed?(@u2, :read_project, @p1).should be_true }
|
||||
end
|
||||
|
||||
describe :write do
|
||||
before do
|
||||
@p1.users_projects.create(:project => @p1, :user => @u1, :write => false)
|
||||
@p1.users_projects.create(:project => @p1, :user => @u2, :write => true)
|
||||
end
|
||||
|
||||
it { @abilities.allowed?(@u1, :write_project, @p1).should be_false }
|
||||
it { @abilities.allowed?(@u2, :write_project, @p1).should be_true }
|
||||
end
|
||||
|
||||
describe :admin do
|
||||
before do
|
||||
@p1.users_projects.create(:project => @p1, :user => @u1, :admin => false)
|
||||
@p1.users_projects.create(:project => @p1, :user => @u2, :admin => true)
|
||||
end
|
||||
|
||||
it { @abilities.allowed?(@u1, :admin_project, @p1).should be_false }
|
||||
it { @abilities.allowed?(@u2, :admin_project, @p1).should be_true }
|
||||
end
|
||||
end
|
||||
end
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: projects
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# name :string(255)
|
||||
# path :string(255)
|
||||
# description :text
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# private_flag :boolean default(TRUE), not null
|
||||
# code :string(255)
|
||||
#
|
||||
|
126
spec/models/project_spec.rb
Normal file
126
spec/models/project_spec.rb
Normal file
|
@ -0,0 +1,126 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Project do
|
||||
describe "Associations" do
|
||||
it { should have_many(:users) }
|
||||
it { should have_many(:users_projects) }
|
||||
end
|
||||
|
||||
describe "Validation" do
|
||||
it { should validate_presence_of(:name) }
|
||||
it { should validate_presence_of(:path) }
|
||||
end
|
||||
|
||||
describe "Respond to" do
|
||||
it { should respond_to(:readers) }
|
||||
it { should respond_to(:writers) }
|
||||
it { should respond_to(:gitosis_writers) }
|
||||
it { should respond_to(:admins) }
|
||||
it { should respond_to(:add_access) }
|
||||
it { should respond_to(:reset_access) }
|
||||
it { should respond_to(:update_gitosis_project) }
|
||||
it { should respond_to(:destroy_gitosis_project) }
|
||||
it { should respond_to(:public?) }
|
||||
it { should respond_to(:private?) }
|
||||
it { should respond_to(:url_to_repo) }
|
||||
it { should respond_to(:path_to_repo) }
|
||||
it { should respond_to(:valid_repo?) }
|
||||
it { should respond_to(:repo_exists?) }
|
||||
it { should respond_to(:repo) }
|
||||
it { should respond_to(:tags) }
|
||||
it { should respond_to(:commit) }
|
||||
end
|
||||
|
||||
it "should return valid url to repo" do
|
||||
project = Project.new(:path => "somewhere")
|
||||
project.url_to_repo.should == "git@localhost:somewhere.git"
|
||||
end
|
||||
|
||||
it "should return path to repo" do
|
||||
project = Project.new(:path => "somewhere")
|
||||
project.path_to_repo.should == "/tmp/somewhere"
|
||||
end
|
||||
|
||||
describe :valid_repo? do
|
||||
it "should be valid repo" do
|
||||
project = Factory :project
|
||||
project.valid_repo?.should be_true
|
||||
end
|
||||
|
||||
it "should be invalid repo" do
|
||||
project = Project.new(:name => "ok_name", :path => "/INVALID_PATH/", :code => "NEOK")
|
||||
project.valid_repo?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "Git methods" do
|
||||
let(:project) { Factory :project }
|
||||
|
||||
describe :repo do
|
||||
it "should return valid repo" do
|
||||
project.repo.should be_kind_of(Grit::Repo)
|
||||
end
|
||||
|
||||
it "should return nil" do
|
||||
lambda { Project.new(:path => "invalid").repo }.should raise_error(Grit::NoSuchPathError)
|
||||
end
|
||||
|
||||
it "should return nil" do
|
||||
lambda { Project.new.repo }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
describe :commit do
|
||||
it "should return first head commit if without params" do
|
||||
project.commit.id.should == project.repo.commits.first.id
|
||||
end
|
||||
|
||||
it "should return valid commit" do
|
||||
project.commit(ValidCommit::ID).should be_valid_commit
|
||||
end
|
||||
|
||||
it "should return nil" do
|
||||
project.commit("+123_4532530XYZ").should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe :tree do
|
||||
before do
|
||||
@commit = project.commit(ValidCommit::ID)
|
||||
end
|
||||
|
||||
it "should raise error w/o arguments" do
|
||||
lambda { project.tree }.should raise_error
|
||||
end
|
||||
|
||||
it "should return root tree for commit" do
|
||||
tree = project.tree(@commit)
|
||||
tree.contents.size.should == ValidCommit::FILES_COUNT
|
||||
tree.contents.map(&:name).should == ValidCommit::FILES
|
||||
end
|
||||
|
||||
it "should return root tree for commit with correct path" do
|
||||
tree = project.tree(@commit, ValidCommit::C_FILE_PATH)
|
||||
tree.contents.map(&:name).should == ValidCommit::C_FILES
|
||||
end
|
||||
|
||||
it "should return root tree for commit with incorrect path" do
|
||||
project.tree(@commit, "invalid_path").should be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: projects
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# name :string(255)
|
||||
# path :string(255)
|
||||
# description :text
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# private_flag :boolean default(TRUE), not null
|
||||
# code :string(255)
|
||||
#
|
||||
|
42
spec/models/user_spec.rb
Normal file
42
spec/models/user_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe User do
|
||||
describe "Associations" do
|
||||
it { should have_many(:projects) }
|
||||
it { should have_many(:users_projects) }
|
||||
it { should have_many(:issues) }
|
||||
it { should have_many(:assigned_issues) }
|
||||
end
|
||||
|
||||
describe "Respond to" do
|
||||
it { should respond_to(:is_admin?) }
|
||||
it { should respond_to(:identifier) }
|
||||
it { should respond_to(:name) }
|
||||
end
|
||||
|
||||
it "should return valid identifier" do
|
||||
user = User.new(:email => "test@mail.com")
|
||||
user.identifier.should == "test_mail.com"
|
||||
end
|
||||
end
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: users
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# email :string(255) default(""), not null
|
||||
# encrypted_password :string(128) default(""), not null
|
||||
# reset_password_token :string(255)
|
||||
# reset_password_sent_at :datetime
|
||||
# remember_created_at :datetime
|
||||
# sign_in_count :integer default(0)
|
||||
# current_sign_in_at :datetime
|
||||
# last_sign_in_at :datetime
|
||||
# current_sign_in_ip :string(255)
|
||||
# last_sign_in_ip :string(255)
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# name :string(255)
|
||||
# admin :boolean default(FALSE), not null
|
||||
#
|
||||
|
32
spec/models/users_project_spec.rb
Normal file
32
spec/models/users_project_spec.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe UsersProject do
|
||||
describe "Associations" do
|
||||
it { should belong_to(:project) }
|
||||
it { should belong_to(:user) }
|
||||
end
|
||||
|
||||
describe "Validation" do
|
||||
it { should validate_presence_of(:user_id) }
|
||||
it { should validate_presence_of(:project_id) }
|
||||
end
|
||||
|
||||
describe "Delegate methods" do
|
||||
it { should respond_to(:user_name) }
|
||||
it { should respond_to(:user_email) }
|
||||
end
|
||||
end
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: users_projects
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# user_id :integer not null
|
||||
# project_id :integer not null
|
||||
# read :boolean default(FALSE)
|
||||
# write :boolean default(FALSE)
|
||||
# admin :boolean default(FALSE)
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
#
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue