Commit afbdbb0c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Rspec fixes

parent dccd8b6e
......@@ -28,7 +28,7 @@
:javascript
$(function() {
var availableTags = #{@project.ref_names.to_json};
var availableTags = #{@project.repository.ref_names.to_json};
$("#from, #to").autocomplete({
source: availableTags,
......
......@@ -4,7 +4,7 @@ class ProjectBrowseCommits < Spinach::FeatureSteps
include SharedPaths
Then 'I see project commits' do
commit = @project.commit
commit = @project.repository.commit
page.should have_content(@project.name)
page.should have_content(commit.message)
page.should have_content(commit.id.to_s[0..5])
......@@ -15,7 +15,7 @@ class ProjectBrowseCommits < Spinach::FeatureSteps
end
Then 'I see commits atom feed' do
commit = CommitDecorator.decorate(@project.commit)
commit = CommitDecorator.decorate(@project.repository.commit)
page.response_headers['Content-Type'].should have_content("application/atom+xml")
page.body.should have_selector("title", :text => "Recent commits to #{@project.name}")
page.body.should have_selector("author email", :text => commit.author_email)
......
......@@ -13,7 +13,7 @@ module Gitlab
# Example Request:
# GET /projects/:id/notes
get ":id/notes" do
@notes = user_project.common_notes
@notes = user_project.notes.common
present paginate(@notes), with: Entities::Note
end
......@@ -25,7 +25,7 @@ module Gitlab
# Example Request:
# GET /projects/:id/notes/:note_id
get ":id/notes/:note_id" do
@note = user_project.common_notes.find(params[:note_id])
@note = user_project.notes.common.find(params[:note_id])
present @note, with: Entities::Note
end
......
......@@ -257,7 +257,7 @@ module Gitlab
per_page = params[:per_page] || 20
ref = params[:ref_name] || user_project.try(:default_branch) || 'master'
commits = user_project.commits(ref, nil, per_page, page * per_page)
commits = user_project.repository.commits(ref, nil, per_page, page * per_page)
present CommitDecorator.decorate(commits), with: Entities::RepoCommit
end
......@@ -375,10 +375,10 @@ module Gitlab
ref = params[:sha]
commit = user_project.commit ref
commit = user_project.repository.commit ref
not_found! "Commit" unless commit
tree = Tree.new commit.tree, user_project, ref, params[:filepath]
tree = Tree.new commit.tree, ref, params[:filepath]
not_found! "File" unless tree.try(:tree)
content_type tree.mime_type
......
......@@ -3,12 +3,12 @@ require 'spec_helper'
describe CommitController do
let(:project) { create(:project) }
let(:user) { create(:user) }
let(:commit) { project.last_commit_for("master") }
let(:commit) { project.repository.last_commit_for("master") }
before do
sign_in(user)
project.add_access(user, :read, :admin)
project.team << [user, :master]
end
describe "#show" do
......
......@@ -7,7 +7,7 @@ describe CommitsController do
before do
sign_in(user)
project.add_access(user, :read, :admin)
project.team << [user, :master]
end
describe "GET show" do
......
......@@ -7,7 +7,7 @@ describe MergeRequestsController do
before do
sign_in(user)
project.add_access(user, :read, :admin)
project.team << [user, :master]
MergeRequestsController.any_instance.stub(validates_merge_request: true)
end
......
......@@ -7,7 +7,7 @@ describe TreeController do
before do
sign_in(user)
project.add_access(user, :read, :admin)
project.team << [user, :master]
project.stub(:branches).and_return(['master', 'foo/bar/baz'])
project.stub(:tags).and_return(['v1.0.0', 'v2.0.0'])
......
......@@ -4,7 +4,7 @@ describe GitlabMarkdownHelper do
let!(:project) { create(:project) }
let(:user) { create(:user, username: 'gfm') }
let(:commit) { CommitDecorator.decorate(project.commit) }
let(:commit) { CommitDecorator.decorate(project.repository.commit) }
let(:issue) { create(:issue, project: project) }
let(:merge_request) { create(:merge_request, project: project) }
let(:snippet) { create(:snippet, project: project) }
......@@ -85,7 +85,7 @@ describe GitlabMarkdownHelper do
let(:expected) { project_team_member_path(project, member) }
before do
project.add_access(user, :admin)
project.team << [user, :master]
end
it "should link using a simple name" do
......@@ -314,7 +314,7 @@ describe GitlabMarkdownHelper do
end
it "should handle references in lists" do
project.add_access(user, :admin)
project.team << [user, :master]
actual = "\n* dark: ##{issue.id}\n* light by @#{member.user.username}"
......
require 'spec_helper'
describe Project, "Repository" do
let(:project) { create(:project) }
describe "#empty_repo?" do
it "should return true if the repo doesn't exist" do
project.stub(repo_exists?: false, has_commits?: true)
project.should be_empty_repo
end
it "should return true if the repo has commits" do
project.stub(repo_exists?: true, has_commits?: false)
project.should be_empty_repo
end
it "should return false if the repo exists and has commits" do
project.stub(repo_exists?: true, has_commits?: true)
project.should_not be_empty_repo
end
end
describe "#discover_default_branch" do
let(:master) { 'master' }
let(:stable) { 'stable' }
it "returns 'master' when master exists" do
project.should_receive(:branch_names).at_least(:once).and_return([stable, master])
project.discover_default_branch.should == 'master'
end
it "returns non-master when master exists but default branch is set to something else" do
project.default_branch = 'stable'
project.should_receive(:branch_names).at_least(:once).and_return([stable, master])
project.discover_default_branch.should == 'stable'
end
it "returns a non-master branch when only one exists" do
project.should_receive(:branch_names).at_least(:once).and_return([stable])
project.discover_default_branch.should == 'stable'
end
it "returns nil when no branch exists" do
project.should_receive(:branch_names).at_least(:once).and_return([])
project.discover_default_branch.should be_nil
end
end
describe "#root_ref" do
it "returns default_branch when set" do
project.default_branch = 'stable'
project.root_ref.should == 'stable'
end
it "returns 'master' when default_branch is nil" do
project.default_branch = nil
project.root_ref.should == 'master'
end
end
describe "#root_ref?" do
it "returns true when branch is root_ref" do
project.default_branch = 'stable'
project.root_ref?('stable').should be_true
end
it "returns false when branch is not root_ref" do
project.default_branch = nil
project.root_ref?('stable').should be_false
end
end
describe :repo do
it "should return valid repo" do
project.repo.should be_kind_of(Grit::Repo)
end
it "should return nil" do
lambda { Project.new(path: "invalid").repo }.should raise_error(Grit::NoSuchPathError)
end
it "should return nil" do
lambda { Project.new.repo }.should raise_error(TypeError)
end
end
describe :commit do
it "should return first head commit if without params" do
project.commit.id.should == project.repo.commits.first.id
end
it "should return valid commit" do
project.commit(ValidCommit::ID).should be_valid_commit
end
it "should return nil" do
project.commit("+123_4532530XYZ").should be_nil
end
end
describe :tree do
before do
@commit = project.commit(ValidCommit::ID)
end
it "should raise error w/o arguments" do
lambda { project.tree }.should raise_error
end
it "should return root tree for commit" do
tree = project.tree(@commit)
tree.contents.size.should == ValidCommit::FILES_COUNT
tree.contents.map(&:name).should == ValidCommit::FILES
end
it "should return root tree for commit with correct path" do
tree = project.tree(@commit, ValidCommit::C_FILE_PATH)
tree.contents.map(&:name).should == ValidCommit::C_FILES
end
it "should return root tree for commit with incorrect path" do
project.tree(@commit, "invalid_path").should be_nil
end
end
describe "fresh commits" do
let(:project) { create(:project) }
it { project.fresh_commits(3).count.should == 3 }
it { project.fresh_commits.first.id.should == "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a" }
it { project.fresh_commits.last.id.should == "f403da73f5e62794a0447aca879360494b08f678" }
end
describe "commits_between" do
let(:project) { create(:project) }
subject do
commits = project.commits_between("3a4b4fb4cde7809f033822a171b9feae19d41fff",
"8470d70da67355c9c009e4401746b1d5410af2e3")
commits.map { |c| c.id }
end
it { should have(3).elements }
it { should include("f0f14c8eaba69ebddd766498a9d0b0e79becd633") }
it { should_not include("bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a") }
end
describe :valid_repo? do
it "should be valid repo" do
project = create(:project)
project.valid_repo?.should be_true
end
it "should be invalid repo" do
project = Project.new(name: "ok_name", path: "/INVALID_PATH/", path: "NEOK")
project.valid_repo?.should be_false
end
end
end
......@@ -84,7 +84,6 @@ describe Project do
it { should respond_to(:satellite) }
it { should respond_to(:update_repository) }
it { should respond_to(:destroy_repository) }
it { should respond_to(:archive_repo) }
# Authority Role
it { should respond_to(:reset_access) }
......@@ -94,14 +93,6 @@ describe Project do
it { should respond_to(:dev_access_for?) }
it { should respond_to(:master_access_for?) }
# Team Role
it { should respond_to(:team_member_by_name_or_email) }
it { should respond_to(:team_member_by_id) }
it { should respond_to(:add_user_to_team) }
it { should respond_to(:add_users_to_team) }
it { should respond_to(:add_user_id_to_team) }
it { should respond_to(:add_users_ids_to_team) }
# Project Push Role
it { should respond_to(:observe_push) }
it { should respond_to(:update_merge_requests) }
......@@ -253,4 +244,33 @@ describe Project do
it { @project.to_param.should == "gitlab-ci" }
end
end
describe "#empty_repo?" do
let(:project) { create(:project) }
it "should return true if the repo doesn't exist" do
project.stub(repo_exists?: false, has_commits?: true)
project.should be_empty_repo
end
it "should return true if the repo has commits" do
project.stub(repo_exists?: true, has_commits?: false)
project.should be_empty_repo
end
it "should return false if the repo exists and has commits" do
project.stub(repo_exists?: true, has_commits?: true)
project.should_not be_empty_repo
end
end
describe :repository do
it "should return valid repo" do
project.repository.should be_kind_of(Repository)
end
it "should return nil" do
Project.new(path: "invalid").repository.should be_nil
end
end
end
describe Repository do
let(:project) { create(:project) }
let(:repository) { project.repository }
describe "Respond to" do
subject { repository }
it { should respond_to(:repo) }
it { should respond_to(:tree) }
it { should respond_to(:root_ref) }
......@@ -11,4 +16,88 @@ describe Repository do
it { should respond_to(:commits_since) }
it { should respond_to(:commits_between) }
end
describe "#discover_default_branch" do
let(:master) { 'master' }
let(:stable) { 'stable' }
it "returns 'master' when master exists" do
repository.should_receive(:branch_names).at_least(:once).and_return([stable, master])
repository.discover_default_branch.should == 'master'
end
it "returns non-master when master exists but default branch is set to something else" do
repository.default_branch = 'stable'
repository.should_receive(:branch_names).at_least(:once).and_return([stable, master])
repository.discover_default_branch.should == 'stable'
end
it "returns a non-master branch when only one exists" do
repository.should_receive(:branch_names).at_least(:once).and_return([stable])
repository.discover_default_branch.should == 'stable'
end
it "returns nil when no branch exists" do
repository.should_receive(:branch_names).at_least(:once).and_return([])
repository.discover_default_branch.should be_nil
end
end
describe :commit do
it "should return first head commit if without params" do
repository.commit.id.should == repository.repo.commits.first.id
end
it "should return valid commit" do
repository.commit(ValidCommit::ID).should be_valid_commit
end
it "should return nil" do
repository.commit("+123_4532530XYZ").should be_nil
end
end
describe :tree do
before do
@commit = repository.commit(ValidCommit::ID)
end
it "should raise error w/o arguments" do
lambda { repository.tree }.should raise_error
end
it "should return root tree for commit" do
tree = repository.tree(@commit)
tree.contents.size.should == ValidCommit::FILES_COUNT
tree.contents.map(&:name).should == ValidCommit::FILES
end
it "should return root tree for commit with correct path" do
tree = repository.tree(@commit, ValidCommit::C_FILE_PATH)
tree.contents.map(&:name).should == ValidCommit::C_FILES
end
it "should return root tree for commit with incorrect path" do
repository.tree(@commit, "invalid_path").should be_nil
end
end
describe "fresh commits" do
it { repository.fresh_commits(3).count.should == 3 }
it { repository.fresh_commits.first.id.should == "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a" }
it { repository.fresh_commits.last.id.should == "f403da73f5e62794a0447aca879360494b08f678" }
end
describe "commits_between" do
subject do
commits = repository.commits_between("3a4b4fb4cde7809f033822a171b9feae19d41fff",
"8470d70da67355c9c009e4401746b1d5410af2e3")
commits.map { |c| c.id }
end
it { should have(3).elements }
it { should include("f0f14c8eaba69ebddd766498a9d0b0e79becd633") }
it { should_not include("bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a") }
end
end
......@@ -6,7 +6,7 @@ describe Gitlab::API do
let(:user) { create(:user) }
let!(:project) { create(:project, namespace: user.namespace ) }
let!(:issue) { create(:issue, author: user, assignee: user, project: project) }
before { project.add_access(user, :read) }
before { project.team << [user, :reporter] }
describe "GET /issues" do
context "when unauthenticated" do
......
......@@ -6,7 +6,7 @@ describe Gitlab::API do
let(:user) { create(:user ) }
let!(:project) { create(:project, namespace: user.namespace ) }
let!(:merge_request) { create(:merge_request, author: user, assignee: user, project: project, title: "Test") }
before { project.add_access(user, :read) }
before { project.team << [user, :reporters] }
describe "GET /projects/:id/merge_requests" do
context "when unauthenticated" do
......
......@@ -7,7 +7,7 @@ describe Gitlab::API do
let!(:project) { create(:project, namespace: user.namespace ) }
let!(:milestone) { create(:milestone, project: project) }
before { project.add_access(user, :read) }
before { project.team << [user, :developer] }
describe "GET /projects/:id/milestones" do
it "should return project milestones" do
......
......@@ -10,7 +10,7 @@ describe Gitlab::API do
let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) }
let!(:snippet_note) { create(:note, noteable: snippet, project: project, author: user) }
let!(:wall_note) { create(:note, project: project, author: user) }
before { project.add_access(user, :read) }
before { project.team << [user, :reporter] }
describe "GET /projects/:id/notes" do
context "when unauthenticated" do
......
......@@ -11,7 +11,7 @@ describe Gitlab::API do
let!(:snippet) { create(:snippet, author: user, project: project, title: 'example') }
let!(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) }
let!(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) }
before { project.add_access(user, :read) }
before { project.team << [user, :reporter] }
describe "GET /projects" do
context "when unauthenticated" do
......@@ -226,14 +226,14 @@ describe Gitlab::API do
describe "GET /projects/:id/repository/commits" do
context "authorized user" do
before { project.add_access(user2, :read) }
before { project.team << [user2, :reporter] }
it "should return project commits" do
get api("/projects/#{project.id}/repository/commits", user)
response.status.should == 200
json_response.should be_an Array
json_response.first['id'].should == project.commit.id
json_response.first['id'].should == project.repository.commit.id
end
end
......
......@@ -6,7 +6,7 @@ describe "Issues Feed" do
let!(:project) { create(:project, namespace: user.namespace) }
let!(:issue) { create(:issue, author: user, project: project) }
before { project.add_access(user, :read, :write) }
before { project.team << [user, :developer] }
context "when authenticated" do
it "should render atom feed" do
......
......@@ -6,7 +6,7 @@ describe "Gitlab Flavored Markdown" do
let(:merge_request) { create(:merge_request, project: project) }
let(:fred) do
u = create(:user, name: "fred")
project.add_access(u, :admin)
project.team << [u, :master]
u
end
......@@ -33,11 +33,11 @@ describe "Gitlab Flavored Markdown" do
project.repo.gc_auto
end
let(:commit) { project.commits(@branch_name).first }
let(:commit) { project.repository.commits(@branch_name).first }
before do
login_as :user
project.add_access(@user, :read, :write)
project.team << [@user, :developer]
end
describe "for commits" do
......
......@@ -5,7 +5,7 @@ describe "Projects", "DeployKeys" do
before do
login_as :user
project.add_access(@user, :read, :write, :admin)
project.team << [@user, :master]
end
describe "GET /keys" do
......
......@@ -4,7 +4,7 @@ describe "Search" do
before do
login_as :user
@project = create(:project)
@project.add_access(@user, :read)
@project.team << [@user, :reporter]
visit search_path
fill_in "search", with: @project.name[0..3]
click_button "Search"
......
......@@ -5,7 +5,7 @@ describe "Snippets" do
before do
login_as :user
project.add_access(@user, :read, :write)
project.team << [@user, :developer]
end
describe "GET /snippets" do
......@@ -26,7 +26,7 @@ describe "Snippets" do
before do
# admin access to remove snippet
@user.users_projects.destroy_all
project.add_access(@user, :read, :write, :admin)
project.team << [@user, :master]
visit edit_project_snippet_path(project, @snippet)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment