diff options
author | Valery Sizov <vsv2711@gmail.com> | 2014-12-31 16:07:48 +0300 |
---|---|---|
committer | Valery Sizov <valery@gitlab.com> | 2015-01-10 20:51:43 +0300 |
commit | a9f7fd2c1a7052247333b89f6a22a883b480370d (patch) | |
tree | a7321e528f9ac10f0e8f8f591dca6a4c83f09b9a /spec | |
parent | d02a22ba21f91d2aa4f9cf716dc3aefcf7e7495e (diff) |
Github Importer
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/github_imports_controller_spec.rb | 64 | ||||
-rw-r--r-- | spec/helpers/projects_helper_spec.rb | 9 | ||||
-rw-r--r-- | spec/lib/gitlab/github/project_creator.rb | 25 |
3 files changed, 98 insertions, 0 deletions
diff --git a/spec/controllers/github_imports_controller_spec.rb b/spec/controllers/github_imports_controller_spec.rb new file mode 100644 index 00000000000..f1d2df8411a --- /dev/null +++ b/spec/controllers/github_imports_controller_spec.rb @@ -0,0 +1,64 @@ +require 'spec_helper' + +describe GithubImportsController do + let(:user) { create(:user, github_access_token: 'asd123') } + + before do + sign_in(user) + end + + describe "GET callback" do + it "updates access token" do + token = "asdasd12345" + Gitlab::Github::Client.any_instance.stub_chain(:client, :auth_code, :get_token, :token).and_return(token) + + get :callback + + user.reload.github_access_token.should == token + controller.should redirect_to(status_github_import_url) + end + end + + describe "GET status" do + before do + @repo = OpenStruct.new(login: 'vim', full_name: 'asd/vim') + end + + it "assigns variables" do + @project = create(:project, import_type: 'github', creator_id: user.id) + controller.stub_chain(:octo_client, :repos).and_return([@repo]) + controller.stub_chain(:octo_client, :orgs).and_return([]) + + get :status + + expect(assigns(:already_added_projects)).to eq([@project]) + expect(assigns(:repos)).to eq([@repo]) + end + + it "does not show already added project" do + @project = create(:project, import_type: 'github', creator_id: user.id, import_source: 'asd/vim') + controller.stub_chain(:octo_client, :repos).and_return([@repo]) + controller.stub_chain(:octo_client, :orgs).and_return([]) + + get :status + + expect(assigns(:already_added_projects)).to eq([@project]) + expect(assigns(:repos)).to eq([]) + end + end + + describe "POST create" do + before do + @repo = OpenStruct.new(login: 'vim', full_name: 'asd/vim', owner: OpenStruct.new(login: "john")) + end + + it "takes already existing namespace" do + namespace = create(:namespace, name: "john", owner: user) + Gitlab::Github::ProjectCreator.should_receive(:new).with(@repo, namespace, user). + and_return(double(execute: true)) + controller.stub_chain(:octo_client, :repo).and_return(@repo) + + post :create, format: :js + end + end +end diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 114058e3095..2146b0b1383 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -20,4 +20,13 @@ describe ProjectsHelper do "<option value=\"gitlab\">GitLab</option>" end end + + describe "#project_status_css_class" do + it "returns appropriate class" do + project_status_css_class("started").should == "active" + project_status_css_class("failed").should == "danger" + project_status_css_class("finished").should == "success" + end + + end end diff --git a/spec/lib/gitlab/github/project_creator.rb b/spec/lib/gitlab/github/project_creator.rb new file mode 100644 index 00000000000..0bade5619a5 --- /dev/null +++ b/spec/lib/gitlab/github/project_creator.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe Gitlab::Github::ProjectCreator do + let(:user) { create(:user, github_access_token: "asdffg") } + let(:repo) { OpenStruct.new( + login: 'vim', + name: 'vim', + private: true, + full_name: 'asd/vim', + clone_url: "https://gitlab.com/asd/vim.git", + owner: OpenStruct.new(login: "john")) + } + let(:namespace){ create(:namespace) } + + it 'creates project' do + Project.any_instance.stub(:add_import_job) + + project_creator = Gitlab::Github::ProjectCreator.new(repo, namespace, user) + project_creator.execute + project = Project.last + + project.import_url.should == "https://asdffg@gitlab.com/asd/vim.git" + project.visibility_level.should == Gitlab::VisibilityLevel::PRIVATE + end +end |