Skip to content

Commit e6c0673

Browse files
committed
Rspec models Milestone, Commit, UsersProject
1 parent 2095780 commit e6c0673

File tree

5 files changed

+157
-1
lines changed

5 files changed

+157
-1
lines changed

app/models/commit.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Commit
1111
attr_accessor :commit, :head, :refs
1212

1313
delegate :message, :authored_date, :committed_date, :parents, :sha,
14-
:date, :committer, :author, :message, :diffs, :tree, :id,
14+
:date, :committer, :author, :diffs, :tree, :id,
1515
:to_patch, to: :commit
1616

1717
class << self

app/models/users_project.rb

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class UsersProject < ActiveRecord::Base
3535

3636
delegate :name, :email, to: :user, prefix: true
3737

38+
scope :guests, where(project_access: GUEST)
39+
scope :reporters, where(project_access: REPORTER)
40+
scope :developers, where(project_access: DEVELOPER)
41+
scope :masters, where(project_access: MASTER)
3842
scope :in_project, ->(project) { where(project_id: project.id) }
3943

4044
class << self

spec/models/commit_spec.rb

+61
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,65 @@
3434
end
3535
end
3636
end
37+
38+
describe "Commit info" do
39+
before do
40+
@committer = double(
41+
42+
name: 'Mike Smith'
43+
)
44+
45+
@author = double(
46+
47+
name: 'John Smith'
48+
)
49+
50+
@raw_commit = double(
51+
id: "bcf03b5de6abcf03b5de6c",
52+
author: @author,
53+
committer: @committer,
54+
committed_date: Date.yesterday,
55+
message: 'Refactoring specs'
56+
)
57+
58+
@commit = Commit.new(@raw_commit)
59+
end
60+
61+
it { @commit.short_id.should == "bcf03b5de6a" }
62+
it { @commit.safe_message.should == @raw_commit.message }
63+
it { @commit.created_at.should == @raw_commit.committed_date }
64+
it { @commit.author_email.should == @author.email }
65+
it { @commit.author_name.should == @author.name }
66+
it { @commit.committer_name.should == @committer.name }
67+
it { @commit.committer_email.should == @committer.email }
68+
it { @commit.different_committer?.should be_true }
69+
end
70+
71+
describe "Class methods" do
72+
subject { Commit }
73+
74+
it { should respond_to(:find_or_first) }
75+
it { should respond_to(:fresh_commits) }
76+
it { should respond_to(:commits_with_refs) }
77+
it { should respond_to(:commits_since) }
78+
it { should respond_to(:commits_between) }
79+
it { should respond_to(:commits) }
80+
it { should respond_to(:compare) }
81+
end
82+
83+
describe "delegation" do
84+
subject { commit }
85+
86+
it { should respond_to(:message) }
87+
it { should respond_to(:authored_date) }
88+
it { should respond_to(:committed_date) }
89+
it { should respond_to(:parents) }
90+
it { should respond_to(:date) }
91+
it { should respond_to(:committer) }
92+
it { should respond_to(:author) }
93+
it { should respond_to(:diffs) }
94+
it { should respond_to(:tree) }
95+
it { should respond_to(:id) }
96+
it { should respond_to(:to_patch) }
97+
end
3798
end

spec/models/milestone_spec.rb

+50
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,54 @@
6363
milestone.expires_at.should be_present
6464
end
6565
end
66+
67+
describe :expired? do
68+
context "expired" do
69+
before do
70+
milestone.stub(due_date: Date.today.prev_year)
71+
end
72+
73+
it { milestone.expired?.should be_true }
74+
end
75+
76+
context "not expired" do
77+
before do
78+
milestone.stub(due_date: Date.today.next_year)
79+
end
80+
81+
it { milestone.expired?.should be_false }
82+
end
83+
end
84+
85+
describe :percent_complete do
86+
before do
87+
milestone.stub(
88+
closed_items_count: 3,
89+
total_items_count: 4
90+
)
91+
end
92+
93+
it { milestone.percent_complete.should == 75 }
94+
end
95+
96+
describe :items_count do
97+
before do
98+
milestone.issues << create(:issue)
99+
milestone.issues << create(:issue, closed: true)
100+
milestone.merge_requests << create(:merge_request)
101+
end
102+
103+
it { milestone.closed_items_count.should == 1 }
104+
it { milestone.open_items_count.should == 2 }
105+
it { milestone.total_items_count.should == 3 }
106+
it { milestone.is_empty?.should be_false }
107+
end
108+
109+
describe :can_be_closed? do
110+
it { milestone.can_be_closed?.should be_true }
111+
end
112+
113+
describe :open? do
114+
it { milestone.open?.should be_true }
115+
end
66116
end

spec/models/users_project_spec.rb

+41
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,45 @@
6969
it { @project_1.users.should_not include(@user_2) }
7070
end
7171
end
72+
73+
describe :add_users_into_projects do
74+
before do
75+
@project_1 = create :project
76+
@project_2 = create :project
77+
78+
@user_1 = create :user
79+
@user_2 = create :user
80+
81+
UsersProject.add_users_into_projects(
82+
[@project_1.id, @project_2.id],
83+
[@user_1.id, @user_2.id],
84+
UsersProject::MASTER
85+
)
86+
end
87+
88+
it { @project_1.users.should include(@user_1) }
89+
it { @project_1.users.should include(@user_2) }
90+
91+
92+
it { @project_2.users.should include(@user_1) }
93+
it { @project_2.users.should include(@user_2) }
94+
end
95+
96+
describe :truncate_teams do
97+
before do
98+
@project_1 = create :project
99+
@project_2 = create :project
100+
101+
@user_1 = create :user
102+
@user_2 = create :user
103+
104+
@project_1.add_access @user_1, :write
105+
@project_2.add_access @user_2, :read
106+
107+
UsersProject.truncate_teams([@project_1.id, @project_2.id])
108+
end
109+
110+
it { @project_1.users.should be_empty }
111+
it { @project_2.users.should be_empty }
112+
end
72113
end

0 commit comments

Comments
 (0)