diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-01-03 21:11:14 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-01-03 21:11:14 +0400 |
commit | e6c0673ef1108a93928c4d88ba273e12616b836b (patch) | |
tree | 421050c37fa8bcdecf94781473380c54bcecdda6 /spec | |
parent | 2095780f24db7c75f5a004654ae2e4052fe16bdd (diff) |
Rspec models Milestone, Commit, UsersProject
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/commit_spec.rb | 61 | ||||
-rw-r--r-- | spec/models/milestone_spec.rb | 50 | ||||
-rw-r--r-- | spec/models/users_project_spec.rb | 41 |
3 files changed, 152 insertions, 0 deletions
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 |