diff options
author | Valery Sizov <valery@gitlab.com> | 2015-01-27 15:37:19 -0800 |
---|---|---|
committer | Valery Sizov <valery@gitlab.com> | 2015-02-05 12:50:34 -0800 |
commit | 5194214e3a2f97accf0c8119b4cb39fd4fcef5db (patch) | |
tree | 7320257c4470abadd90a0f17fd92f408143b6bb1 /spec/controllers | |
parent | 0a9cab4ee65f2b42c56989698c401cab60d68b53 (diff) | |
download | gitlab-ce-5194214e3a2f97accf0c8119b4cb39fd4fcef5db.tar.gz |
GitLab integration. Importer
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/importers/githubs_controller_spec.rb (renamed from spec/controllers/github_imports_controller_spec.rb) | 4 | ||||
-rw-r--r-- | spec/controllers/importers/gitlabs_controller_spec.rb | 68 |
2 files changed, 70 insertions, 2 deletions
diff --git a/spec/controllers/github_imports_controller_spec.rb b/spec/controllers/importers/githubs_controller_spec.rb index 26e7854fea3..e21b5f8a470 100644 --- a/spec/controllers/github_imports_controller_spec.rb +++ b/spec/controllers/importers/githubs_controller_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe GithubImportsController do +describe Importers::GithubsController do let(:user) { create(:user, github_access_token: 'asd123') } before do @@ -16,7 +16,7 @@ describe GithubImportsController do get :callback user.reload.github_access_token.should == token - controller.should redirect_to(status_github_import_url) + controller.should redirect_to(status_importers_github_url) end end diff --git a/spec/controllers/importers/gitlabs_controller_spec.rb b/spec/controllers/importers/gitlabs_controller_spec.rb new file mode 100644 index 00000000000..af42d14ded3 --- /dev/null +++ b/spec/controllers/importers/gitlabs_controller_spec.rb @@ -0,0 +1,68 @@ +require 'spec_helper' + +describe Importers::GitlabsController do + let(:user) { create(:user, gitlab_access_token: 'asd123') } + + before do + sign_in(user) + end + + describe "GET callback" do + it "updates access token" do + token = "asdasd12345" + Gitlab::GitlabImport::Client.any_instance.stub_chain(:client, :auth_code, :get_token, :token).and_return(token) + Gitlab.config.omniauth.providers << OpenStruct.new(app_id: "asd123", app_secret: "asd123", name: "gitlab") + + get :callback + + user.reload.gitlab_access_token.should == token + controller.should redirect_to(status_importers_gitlab_url) + end + end + + describe "GET status" do + before do + @repo = OpenStruct.new(path: 'vim', path_with_namespace: 'asd/vim') + end + + it "assigns variables" do + @project = create(:project, import_type: 'gitlab', creator_id: user.id) + controller.stub_chain(:client, :projects).and_return([@repo]) + + 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: 'gitlab', creator_id: user.id, import_source: 'asd/vim') + controller.stub_chain(:client, :projects).and_return([@repo]) + + get :status + + expect(assigns(:already_added_projects)).to eq([@project]) + expect(assigns(:repos)).to eq([]) + end + end + + describe "POST create" do + before do + @repo = { + path: 'vim', + path_with_namespace: 'asd/vim', + owner: {name: "john"}, + namespace: {path: "john"} + }.with_indifferent_access + end + + it "takes already existing namespace" do + namespace = create(:namespace, name: "john", owner: user) + Gitlab::GitlabImport::ProjectCreator.should_receive(:new).with(@repo, namespace, user). + and_return(double(execute: true)) + controller.stub_chain(:client, :project).and_return(@repo) + + post :create, format: :js + end + end +end |