Rspec models Milestone, Commit, UsersProject

This commit is contained in:
Dmitriy Zaporozhets 2013-01-03 19:11:14 +02:00
parent 2095780f24
commit e6c0673ef1
5 changed files with 157 additions and 1 deletions

View file

@ -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

View file

@ -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

View file

@ -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