summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorRiyad Preukschas <riyad@informatik.uni-bremen.de>2012-12-23 01:03:57 +0100
committerRiyad Preukschas <riyad@informatik.uni-bremen.de>2012-12-23 01:03:57 +0100
commitdb2c15369c365340aeaf4e431e8838714b40396b (patch)
tree26ca045a337132370b67cc8f2ed4010e3087dfa5 /spec/models
parentb47173da6a0fea0982d009f91e2c4d042f9b5c37 (diff)
parent68c43d59f09a66cca0da1b9a50c11421d52eac9a (diff)
downloadgitlab-ce-db2c15369c365340aeaf4e431e8838714b40396b.tar.gz
Merge branch 'master' into discussions
Conflicts: app/assets/stylesheets/main.scss app/models/project.rb app/views/notes/_common_form.html.haml app/views/notes/_per_line_form.html.haml lib/gitlab/markdown.rb spec/models/note_spec.rb
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/event_spec.rb2
-rw-r--r--spec/models/merge_request_spec.rb2
-rw-r--r--spec/models/note_spec.rb6
-rw-r--r--spec/models/project_hooks_spec.rb2
-rw-r--r--spec/models/project_security_spec.rb93
-rw-r--r--spec/models/project_spec.rb103
-rw-r--r--spec/models/system_hook_spec.rb4
-rw-r--r--spec/models/user_spec.rb5
-rw-r--r--spec/models/users_project_spec.rb1
9 files changed, 105 insertions, 113 deletions
diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb
index 49cb49db375..82b46b68b64 100644
--- a/spec/models/event_spec.rb
+++ b/spec/models/event_spec.rb
@@ -59,7 +59,7 @@ describe Event do
end
it { @event.push?.should be_true }
- it { @event.allowed?.should be_true }
+ it { @event.proper?.should be_true }
it { @event.new_branch?.should be_true }
it { @event.tag?.should be_false }
it { @event.branch_name.should == "master" }
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index d70647f668d..a0849401254 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -42,7 +42,7 @@ describe MergeRequest do
before do
merge_request.stub(:commits) { [merge_request.project.commit] }
- create(:note, noteable: merge_request.commits.first)
+ create(:note, commit_id: merge_request.commits.first.id, noteable_type: 'Commit')
create(:note, noteable: merge_request)
end
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 4c1afd8a3b4..34683e4196a 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -80,13 +80,13 @@ describe Note do
let!(:commit) { note.noteable }
it "should be accessible through #noteable" do
- note.noteable_id.should == commit.id
+ note.commit_id.should == commit.id
note.noteable.should be_a(Commit)
note.noteable.should == commit
end
it "should save a valid note" do
- note.noteable_id.should == commit.id
+ note.commit_id.should == commit.id
note.noteable == commit
end
@@ -104,7 +104,7 @@ describe Note do
let!(:commit) { note.noteable }
it "should save a valid note" do
- note.noteable_id.should == commit.id
+ note.commit_id.should == commit.id
note.noteable.id.should == commit.id
end
diff --git a/spec/models/project_hooks_spec.rb b/spec/models/project_hooks_spec.rb
index 7c8f05b17a3..df6a3831e30 100644
--- a/spec/models/project_hooks_spec.rb
+++ b/spec/models/project_hooks_spec.rb
@@ -108,7 +108,7 @@ describe Project, "Hooks" do
it { should include(id: @commit.id) }
it { should include(message: @commit.safe_message) }
it { should include(timestamp: @commit.date.xmlschema) }
- it { should include(url: "#{Gitlab.config.url}/#{project.code}/commits/#{@commit.id}") }
+ it { should include(url: "#{Gitlab.config.gitlab.url}/#{project.code}/commit/#{@commit.id}") }
context "with a author" do
subject { @data[:commits].first[:author] }
diff --git a/spec/models/project_security_spec.rb b/spec/models/project_security_spec.rb
index 60f8d45c9c8..92c6bce08f6 100644
--- a/spec/models/project_security_spec.rb
+++ b/spec/models/project_security_spec.rb
@@ -4,38 +4,109 @@ describe Project do
describe :authorization do
before do
@p1 = create(:project)
+
@u1 = create(:user)
@u2 = create(:user)
+ @u3 = create(:user)
+ @u4 = @p1.chief
+
@abilities = Six.new
@abilities << Ability
end
- describe "read access" do
+ let(:guest_actions) { Ability.project_guest_rules }
+ let(:report_actions) { Ability.project_report_rules }
+ let(:dev_actions) { Ability.project_dev_rules }
+ let(:master_actions) { Ability.project_master_rules }
+ let(:admin_actions) { Ability.project_admin_rules }
+
+ describe "Non member rules" do
+ it "should deny for non-project users any actions" do
+ admin_actions.each do |action|
+ @abilities.allowed?(@u1, action, @p1).should be_false
+ end
+ end
+ end
+
+ describe "Guest Rules" do
+ before do
+ @p1.users_projects.create(project: @p1, user: @u2, project_access: UsersProject::GUEST)
+ end
+
+ it "should allow for project user any guest actions" do
+ guest_actions.each do |action|
+ @abilities.allowed?(@u2, action, @p1).should be_true
+ end
+ end
+ end
+
+ describe "Report Rules" do
before do
@p1.users_projects.create(project: @p1, user: @u2, project_access: UsersProject::REPORTER)
end
- it { @abilities.allowed?(@u1, :read_project, @p1).should be_false }
- it { @abilities.allowed?(@u2, :read_project, @p1).should be_true }
+ it "should allow for project user any report actions" do
+ report_actions.each do |action|
+ @abilities.allowed?(@u2, action, @p1).should be_true
+ end
+ end
end
- describe "write access" do
+ describe "Developer Rules" do
+ before do
+ @p1.users_projects.create(project: @p1, user: @u2, project_access: UsersProject::REPORTER)
+ @p1.users_projects.create(project: @p1, user: @u3, project_access: UsersProject::DEVELOPER)
+ end
+
+ it "should deny for developer master-specific actions" do
+ [dev_actions - report_actions].each do |action|
+ @abilities.allowed?(@u2, action, @p1).should be_false
+ end
+ end
+
+ it "should allow for project user any dev actions" do
+ dev_actions.each do |action|
+ @abilities.allowed?(@u3, action, @p1).should be_true
+ end
+ end
+ end
+
+ describe "Master Rules" do
before do
@p1.users_projects.create(project: @p1, user: @u2, project_access: UsersProject::DEVELOPER)
+ @p1.users_projects.create(project: @p1, user: @u3, project_access: UsersProject::MASTER)
end
- it { @abilities.allowed?(@u1, :write_project, @p1).should be_false }
- it { @abilities.allowed?(@u2, :write_project, @p1).should be_true }
+ it "should deny for developer master-specific actions" do
+ [master_actions - dev_actions].each do |action|
+ @abilities.allowed?(@u2, action, @p1).should be_false
+ end
+ end
+
+ it "should allow for project user any master actions" do
+ master_actions.each do |action|
+ @abilities.allowed?(@u3, action, @p1).should be_true
+ end
+ end
end
- describe "admin access" do
+ describe "Admin Rules" do
before do
- @p1.users_projects.create(project: @p1, user: @u1, project_access: UsersProject::DEVELOPER)
- @p1.users_projects.create(project: @p1, user: @u2, project_access: UsersProject::MASTER)
+ @p1.users_projects.create(project: @p1, user: @u2, project_access: UsersProject::DEVELOPER)
+ @p1.users_projects.create(project: @p1, user: @u3, project_access: UsersProject::MASTER)
end
- it { @abilities.allowed?(@u1, :admin_project, @p1).should be_false }
- it { @abilities.allowed?(@u2, :admin_project, @p1).should be_true }
+ it "should deny for masters admin-specific actions" do
+ [admin_actions - master_actions].each do |action|
+ @abilities.allowed?(@u2, action, @p1).should be_false
+ end
+ end
+
+ it "should allow for project owner any admin actions" do
+ admin_actions.each do |action|
+ @abilities.allowed?(@u4, action, @p1).should be_true
+ end
+ end
end
end
end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index db0d30727b4..83a76976098 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -129,6 +129,13 @@ describe Project do
it { should respond_to(:execute_hooks) }
it { should respond_to(:post_receive_data) }
it { should respond_to(:trigger_post_receive) }
+
+ # Namespaced Project Role
+ it { should respond_to(:transfer) }
+ it { should respond_to(:name_with_namespace) }
+ it { should respond_to(:namespace_owner) }
+ it { should respond_to(:chief) }
+ it { should respond_to(:path_with_namespace) }
end
describe 'modules' do
@@ -136,11 +143,12 @@ describe Project do
it { should include_module(PushObserver) }
it { should include_module(Authority) }
it { should include_module(Team) }
+ it { should include_module(NamespacedProject) }
end
it "should return valid url to repo" do
project = Project.new(path: "somewhere")
- project.url_to_repo.should == Gitlab.config.ssh_path + "somewhere.git"
+ project.url_to_repo.should == Gitlab.config.gitolite.ssh_path_prefix + "somewhere.git"
end
it "should return path to repo" do
@@ -150,19 +158,7 @@ describe Project do
it "returns the full web URL for this repo" do
project = Project.new(path: "somewhere")
- project.web_url.should == "#{Gitlab.config.url}/somewhere"
- end
-
- describe :valid_repo? do
- it "should be valid repo" do
- project = create(:project)
- project.valid_repo?.should be_true
- end
-
- it "should be invalid repo" do
- project = Project.new(name: "ok_name", path: "/INVALID_PATH/", path: "NEOK")
- project.valid_repo?.should be_false
- end
+ project.web_url.should == "#{Gitlab.config.gitlab.url}/somewhere"
end
describe "last_activity methods" do
@@ -188,85 +184,6 @@ describe Project do
end
end
- describe "fresh commits" do
- let(:project) { create(:project) }
-
- it { project.fresh_commits(3).count.should == 3 }
- it { project.fresh_commits.first.id.should == "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a" }
- it { project.fresh_commits.last.id.should == "f403da73f5e62794a0447aca879360494b08f678" }
- end
-
- describe "commits_between" do
- let(:project) { create(:project) }
-
- subject do
- commits = project.commits_between("3a4b4fb4cde7809f033822a171b9feae19d41fff",
- "8470d70da67355c9c009e4401746b1d5410af2e3")
- commits.map { |c| c.id }
- end
-
- it { should have(3).elements }
- it { should include("f0f14c8eaba69ebddd766498a9d0b0e79becd633") }
- it { should_not include("bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a") }
- end
-
- describe "Git methods" do
- let(:project) { create(: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
-
describe :update_merge_requests do
let(:project) { create(:project) }
diff --git a/spec/models/system_hook_spec.rb b/spec/models/system_hook_spec.rb
index 9d03b56cd8f..7ae483a4003 100644
--- a/spec/models/system_hook_spec.rb
+++ b/spec/models/system_hook_spec.rb
@@ -56,7 +56,7 @@ describe SystemHook do
user = create(:user)
project = create(:project)
with_resque do
- project.users << user
+ project.add_access(user, :admin)
end
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
end
@@ -64,7 +64,7 @@ describe SystemHook do
it "project_destroy hook" do
user = create(:user)
project = create(:project)
- project.users << user
+ project.add_access(user, :admin)
with_resque do
project.users_projects.clear
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 279e315b693..d09484f8fe0 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -41,7 +41,6 @@ describe User do
it { should have_many(:users_projects).dependent(:destroy) }
it { should have_many(:projects) }
it { should have_many(:groups) }
- it { should have_many(:my_own_projects).class_name('Project') }
it { should have_many(:keys).dependent(:destroy) }
it { should have_many(:events).class_name('Event').dependent(:destroy) }
it { should have_many(:recent_events).class_name('Event') }
@@ -67,6 +66,10 @@ describe User do
it { should ensure_length_of(:bio).is_within(0..255) }
end
+ describe 'modules' do
+ it { should include_module(Account) }
+ end
+
describe "Respond to" do
it { should respond_to(:is_admin?) }
it { should respond_to(:identifier) }
diff --git a/spec/models/users_project_spec.rb b/spec/models/users_project_spec.rb
index 1f896324f18..a9a1857eb69 100644
--- a/spec/models/users_project_spec.rb
+++ b/spec/models/users_project_spec.rb
@@ -29,6 +29,7 @@ describe UsersProject do
it { should validate_uniqueness_of(:user_id).scoped_to(:project_id).with_message(/already exists/) }
it { should validate_presence_of(:project) }
+ it { should ensure_inclusion_of(:project_access).in_array(UsersProject.access_roles.values) }
end
describe "Delegate methods" do