summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/commit.rb2
-rw-r--r--app/models/users_project.rb4
-rw-r--r--spec/models/commit_spec.rb61
-rw-r--r--spec/models/milestone_spec.rb50
-rw-r--r--spec/models/users_project_spec.rb41
5 files changed, 157 insertions, 1 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index f11b7fe0202..07c5fbd7183 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -11,7 +11,7 @@ class Commit
attr_accessor :commit, :head, :refs
delegate :message, :authored_date, :committed_date, :parents, :sha,
- :date, :committer, :author, :message, :diffs, :tree, :id,
+ :date, :committer, :author, :diffs, :tree, :id,
:to_patch, to: :commit
class << self
diff --git a/app/models/users_project.rb b/app/models/users_project.rb
index ce7ac8ac61d..f8e0078400f 100644
--- a/app/models/users_project.rb
+++ b/app/models/users_project.rb
@@ -35,6 +35,10 @@ class UsersProject < ActiveRecord::Base
delegate :name, :email, to: :user, prefix: true
+ scope :guests, where(project_access: GUEST)
+ scope :reporters, where(project_access: REPORTER)
+ scope :developers, where(project_access: DEVELOPER)
+ scope :masters, where(project_access: MASTER)
scope :in_project, ->(project) { where(project_id: project.id) }
class << self
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index e4bc1936839..e760c501bd7 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -34,4 +34,65 @@ describe Commit do
end
end
end
+
+ describe "Commit info" do
+ before do
+ @committer = double(
+ email: 'mike@smith.com',
+ name: 'Mike Smith'
+ )
+
+ @author = double(
+ email: 'john@smith.com',
+ name: 'John Smith'
+ )
+
+ @raw_commit = double(
+ id: "bcf03b5de6abcf03b5de6c",
+ author: @author,
+ committer: @committer,
+ committed_date: Date.yesterday,
+ message: 'Refactoring specs'
+ )
+
+ @commit = Commit.new(@raw_commit)
+ end
+
+ it { @commit.short_id.should == "bcf03b5de6a" }
+ it { @commit.safe_message.should == @raw_commit.message }
+ it { @commit.created_at.should == @raw_commit.committed_date }
+ it { @commit.author_email.should == @author.email }
+ it { @commit.author_name.should == @author.name }
+ it { @commit.committer_name.should == @committer.name }
+ it { @commit.committer_email.should == @committer.email }
+ it { @commit.different_committer?.should be_true }
+ end
+
+ describe "Class methods" do
+ subject { Commit }
+
+ it { should respond_to(:find_or_first) }
+ it { should respond_to(:fresh_commits) }
+ it { should respond_to(:commits_with_refs) }
+ it { should respond_to(:commits_since) }
+ it { should respond_to(:commits_between) }
+ it { should respond_to(:commits) }
+ it { should respond_to(:compare) }
+ end
+
+ describe "delegation" do
+ subject { commit }
+
+ it { should respond_to(:message) }
+ it { should respond_to(:authored_date) }
+ it { should respond_to(:committed_date) }
+ it { should respond_to(:parents) }
+ it { should respond_to(:date) }
+ it { should respond_to(:committer) }
+ it { should respond_to(:author) }
+ it { should respond_to(:diffs) }
+ it { should respond_to(:tree) }
+ it { should respond_to(:id) }
+ it { should respond_to(:to_patch) }
+ end
end
diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb
index f661814787e..2ea2c56a6f7 100644
--- a/spec/models/milestone_spec.rb
+++ b/spec/models/milestone_spec.rb
@@ -63,4 +63,54 @@ describe Milestone do
milestone.expires_at.should be_present
end
end
+
+ describe :expired? do
+ context "expired" do
+ before do
+ milestone.stub(due_date: Date.today.prev_year)
+ end
+
+ it { milestone.expired?.should be_true }
+ end
+
+ context "not expired" do
+ before do
+ milestone.stub(due_date: Date.today.next_year)
+ end
+
+ it { milestone.expired?.should be_false }
+ end
+ end
+
+ describe :percent_complete do
+ before do
+ milestone.stub(
+ closed_items_count: 3,
+ total_items_count: 4
+ )
+ end
+
+ it { milestone.percent_complete.should == 75 }
+ end
+
+ describe :items_count do
+ before do
+ milestone.issues << create(:issue)
+ milestone.issues << create(:issue, closed: true)
+ milestone.merge_requests << create(:merge_request)
+ end
+
+ it { milestone.closed_items_count.should == 1 }
+ it { milestone.open_items_count.should == 2 }
+ it { milestone.total_items_count.should == 3 }
+ it { milestone.is_empty?.should be_false }
+ end
+
+ describe :can_be_closed? do
+ it { milestone.can_be_closed?.should be_true }
+ end
+
+ describe :open? do
+ it { milestone.open?.should be_true }
+ end
end
diff --git a/spec/models/users_project_spec.rb b/spec/models/users_project_spec.rb
index a9a1857eb69..f85e21ff3f1 100644
--- a/spec/models/users_project_spec.rb
+++ b/spec/models/users_project_spec.rb
@@ -69,4 +69,45 @@ describe UsersProject do
it { @project_1.users.should_not include(@user_2) }
end
end
+
+ describe :add_users_into_projects do
+ before do
+ @project_1 = create :project
+ @project_2 = create :project
+
+ @user_1 = create :user
+ @user_2 = create :user
+
+ UsersProject.add_users_into_projects(
+ [@project_1.id, @project_2.id],
+ [@user_1.id, @user_2.id],
+ UsersProject::MASTER
+ )
+ end
+
+ it { @project_1.users.should include(@user_1) }
+ it { @project_1.users.should include(@user_2) }
+
+
+ it { @project_2.users.should include(@user_1) }
+ it { @project_2.users.should include(@user_2) }
+ end
+
+ describe :truncate_teams do
+ before do
+ @project_1 = create :project
+ @project_2 = create :project
+
+ @user_1 = create :user
+ @user_2 = create :user
+
+ @project_1.add_access @user_1, :write
+ @project_2.add_access @user_2, :read
+
+ UsersProject.truncate_teams([@project_1.id, @project_2.id])
+ end
+
+ it { @project_1.users.should be_empty }
+ it { @project_2.users.should be_empty }
+ end
end