Commit e6c0673ef1108a93928c4d88ba273e12616b836b
1 parent
2095780f
Exists in
master
and in
4 other branches
Rspec models Milestone, Commit, UsersProject
Showing
5 changed files
with
157 additions
and
1 deletions
Show diff stats
app/models/commit.rb
... | ... | @@ -11,7 +11,7 @@ class Commit |
11 | 11 | attr_accessor :commit, :head, :refs |
12 | 12 | |
13 | 13 | delegate :message, :authored_date, :committed_date, :parents, :sha, |
14 | - :date, :committer, :author, :message, :diffs, :tree, :id, | |
14 | + :date, :committer, :author, :diffs, :tree, :id, | |
15 | 15 | :to_patch, to: :commit |
16 | 16 | |
17 | 17 | class << self | ... | ... |
app/models/users_project.rb
... | ... | @@ -35,6 +35,10 @@ class UsersProject < ActiveRecord::Base |
35 | 35 | |
36 | 36 | delegate :name, :email, to: :user, prefix: true |
37 | 37 | |
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) | |
38 | 42 | scope :in_project, ->(project) { where(project_id: project.id) } |
39 | 43 | |
40 | 44 | class << self | ... | ... |
spec/models/commit_spec.rb
... | ... | @@ -34,4 +34,65 @@ describe Commit do |
34 | 34 | end |
35 | 35 | end |
36 | 36 | end |
37 | + | |
38 | + describe "Commit info" do | |
39 | + before do | |
40 | + @committer = double( | |
41 | + email: 'mike@smith.com', | |
42 | + name: 'Mike Smith' | |
43 | + ) | |
44 | + | |
45 | + @author = double( | |
46 | + email: 'john@smith.com', | |
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 | |
37 | 98 | end | ... | ... |
spec/models/milestone_spec.rb
... | ... | @@ -63,4 +63,54 @@ describe Milestone do |
63 | 63 | milestone.expires_at.should be_present |
64 | 64 | end |
65 | 65 | 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 | |
66 | 116 | end | ... | ... |
spec/models/users_project_spec.rb
... | ... | @@ -69,4 +69,45 @@ describe UsersProject do |
69 | 69 | it { @project_1.users.should_not include(@user_2) } |
70 | 70 | end |
71 | 71 | 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 | |
72 | 113 | end | ... | ... |