diff options
author | Valery Sizov <valery@gitlab.com> | 2015-02-03 04:01:07 +0300 |
---|---|---|
committer | Valery Sizov <valery@gitlab.com> | 2015-02-05 23:50:34 +0300 |
commit | 33349dd54928a0b074b4ae3ebfabf214799fc085 (patch) | |
tree | 593a14d0f6df812410349f353e252e3a58d8cacd /spec/controllers/import | |
parent | 713bc152bde5396bb95a1555907bcd9a2847839d (diff) |
GitLab.com integration: refactoring
Diffstat (limited to 'spec/controllers/import')
-rw-r--r-- | spec/controllers/import/github_controller_spec.rb | 65 | ||||
-rw-r--r-- | spec/controllers/import/gitlab_controller_spec.rb | 68 |
2 files changed, 133 insertions, 0 deletions
diff --git a/spec/controllers/import/github_controller_spec.rb b/spec/controllers/import/github_controller_spec.rb new file mode 100644 index 00000000000..ef93ff6f92f --- /dev/null +++ b/spec/controllers/import/github_controller_spec.rb @@ -0,0 +1,65 @@ +require 'spec_helper' + +describe Import::GithubController 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) + Gitlab.config.omniauth.providers << OpenStruct.new(app_id: "asd123", app_secret: "asd123", name: "github") + + get :callback + + user.reload.github_access_token.should == token + controller.should redirect_to(status_import_github_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/controllers/import/gitlab_controller_spec.rb b/spec/controllers/import/gitlab_controller_spec.rb new file mode 100644 index 00000000000..36995091c69 --- /dev/null +++ b/spec/controllers/import/gitlab_controller_spec.rb @@ -0,0 +1,68 @@ +require 'spec_helper' + +describe Import::GitlabController 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_import_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 |