summaryrefslogtreecommitdiff
path: root/spec/controllers
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-06-23 10:44:03 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-06-23 10:44:03 +0200
commitf40b99d02ee9411e5a7f9a93e3e6cf33c1d7890e (patch)
treea55ff4f3ceaa24fcb008114f62b8ac377db6a129 /spec/controllers
parent9369adb93d119ca349add2b7f80d6a9b4bbd6703 (diff)
parent4aa1fdd347d1df4001d9e1298e6dc09c0c478c2e (diff)
downloadgitlab-ce-f40b99d02ee9411e5a7f9a93e3e6cf33c1d7890e.tar.gz
Merge branch 'master' into rubocop-for-tests
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> Conflicts: spec/features/issues_spec.rb spec/models/forked_project_link_spec.rb spec/models/hooks/service_hook_spec.rb spec/models/hooks/web_hook_spec.rb spec/models/project_services/hipchat_service_spec.rb spec/requests/api/project_members_spec.rb spec/requests/api/projects_spec.rb spec/requests/api/system_hooks_spec.rb spec/services/archive_repository_service_spec.rb spec/support/matchers.rb spec/tasks/gitlab/backup_rake_spec.rb
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/autocomplete_controller_spec.rb6
-rw-r--r--spec/controllers/commit_controller_spec.rb8
-rw-r--r--spec/controllers/import/bitbucket_controller_spec.rb17
-rw-r--r--spec/controllers/import/github_controller_spec.rb19
-rw-r--r--spec/controllers/import/gitlab_controller_spec.rb17
-rw-r--r--spec/controllers/import/gitorious_controller_spec.rb9
-rw-r--r--spec/controllers/import/google_code_controller_spec.rb14
-rw-r--r--spec/controllers/import/import_spec_helper.rb33
-rw-r--r--spec/controllers/projects/merge_requests_controller_spec.rb8
9 files changed, 85 insertions, 46 deletions
diff --git a/spec/controllers/autocomplete_controller_spec.rb b/spec/controllers/autocomplete_controller_spec.rb
index 1ea1227b28b..9ad9cb41cc1 100644
--- a/spec/controllers/autocomplete_controller_spec.rb
+++ b/spec/controllers/autocomplete_controller_spec.rb
@@ -16,7 +16,7 @@ describe AutocompleteController do
let(:body) { JSON.parse(response.body) }
it { expect(body).to be_kind_of(Array) }
- it { expect(body.size).to eq(1) }
+ it { expect(body.size).to eq 1 }
it { expect(body.first["username"]).to eq user.username }
end
@@ -33,7 +33,7 @@ describe AutocompleteController do
let(:body) { JSON.parse(response.body) }
it { expect(body).to be_kind_of(Array) }
- it { expect(body.size).to eq(1) }
+ it { expect(body.size).to eq 1 }
it { expect(body.first["username"]).to eq user.username }
end
@@ -46,6 +46,6 @@ describe AutocompleteController do
let(:body) { JSON.parse(response.body) }
it { expect(body).to be_kind_of(Array) }
- it { expect(body.size).to eq(User.count) }
+ it { expect(body.size).to eq User.count }
end
end
diff --git a/spec/controllers/commit_controller_spec.rb b/spec/controllers/commit_controller_spec.rb
index 2dfc8e2821f..bb3d87f3840 100644
--- a/spec/controllers/commit_controller_spec.rb
+++ b/spec/controllers/commit_controller_spec.rb
@@ -49,10 +49,10 @@ describe Projects::CommitController do
project_id: project.to_param,
id: commit.id, format: format)
- expect(response.body).to_not include('&amp;')
- expect(response.body).to_not include('&gt;')
- expect(response.body).to_not include('&lt;')
- expect(response.body).to_not include('&quot;')
+ expect(response.body).not_to include('&amp;')
+ expect(response.body).not_to include('&gt;')
+ expect(response.body).not_to include('&lt;')
+ expect(response.body).not_to include('&quot;')
end
end
diff --git a/spec/controllers/import/bitbucket_controller_spec.rb b/spec/controllers/import/bitbucket_controller_spec.rb
index ddeeaf74fcb..d5d9310e603 100644
--- a/spec/controllers/import/bitbucket_controller_spec.rb
+++ b/spec/controllers/import/bitbucket_controller_spec.rb
@@ -1,11 +1,14 @@
require 'spec_helper'
+require_relative 'import_spec_helper'
describe Import::BitbucketController do
+ include ImportSpecHelper
+
let(:user) { create(:user, bitbucket_access_token: 'asd123', bitbucket_access_token_secret: "sekret") }
before do
sign_in(user)
- controller.stub(:bitbucket_import_enabled?).and_return(true)
+ allow(controller).to receive(:bitbucket_import_enabled?).and_return(true)
end
describe "GET callback" do
@@ -17,8 +20,9 @@ describe Import::BitbucketController do
token = "asdasd12345"
secret = "sekrettt"
access_token = double(token: token, secret: secret)
- Gitlab::BitbucketImport::Client.any_instance.stub(:get_token).and_return(access_token)
- Gitlab.config.omniauth.providers << OpenStruct.new(app_id: "asd123", app_secret: "asd123", name: "bitbucket")
+ allow_any_instance_of(Gitlab::BitbucketImport::Client).
+ to receive(:get_token).and_return(access_token)
+ stub_omniauth_provider('bitbucket')
get :callback
@@ -35,7 +39,7 @@ describe Import::BitbucketController do
it "assigns variables" do
@project = create(:project, import_type: 'bitbucket', creator_id: user.id)
- controller.stub_chain(:client, :projects).and_return([@repo])
+ stub_client(projects: [@repo])
get :status
@@ -45,7 +49,7 @@ describe Import::BitbucketController do
it "does not show already added project" do
@project = create(:project, import_type: 'bitbucket', creator_id: user.id, import_source: 'asd/vim')
- controller.stub_chain(:client, :projects).and_return([@repo])
+ stub_client(projects: [@repo])
get :status
@@ -70,8 +74,7 @@ describe Import::BitbucketController do
to receive(:new).with(bitbucket_repo, user).
and_return(double(execute: true))
- controller.stub_chain(:client, :user).and_return(bitbucket_user)
- controller.stub_chain(:client, :project).and_return(bitbucket_repo)
+ stub_client(user: bitbucket_user, project: bitbucket_repo)
end
context "when the repository owner is the Bitbucket user" do
diff --git a/spec/controllers/import/github_controller_spec.rb b/spec/controllers/import/github_controller_spec.rb
index 5f2a09280b2..0bc14059a35 100644
--- a/spec/controllers/import/github_controller_spec.rb
+++ b/spec/controllers/import/github_controller_spec.rb
@@ -1,11 +1,14 @@
require 'spec_helper'
+require_relative 'import_spec_helper'
describe Import::GithubController do
+ include ImportSpecHelper
+
let(:user) { create(:user, github_access_token: 'asd123') }
before do
sign_in(user)
- controller.stub(:github_import_enabled?).and_return(true)
+ allow(controller).to receive(:github_import_enabled?).and_return(true)
end
describe "GET callback" do
@@ -13,9 +16,7 @@ describe Import::GithubController do
token = "asdasd12345"
allow_any_instance_of(Gitlab::GithubImport::Client).
to receive(:get_token).and_return(token)
- Gitlab.config.omniauth.providers << OpenStruct.new(app_id: 'asd123',
- app_secret: 'asd123',
- name: 'github')
+ stub_omniauth_provider('github')
get :callback
@@ -33,9 +34,7 @@ describe Import::GithubController do
it "assigns variables" do
@project = create(:project, import_type: 'github', creator_id: user.id)
- controller.stub_chain(:client, :repos).and_return([@repo])
- controller.stub_chain(:client, :orgs).and_return([@org])
- controller.stub_chain(:client, :org_repos).with(@org.login).and_return([@org_repo])
+ stub_client(repos: [@repo], orgs: [@org], org_repos: [@org_repo])
get :status
@@ -45,8 +44,7 @@ describe Import::GithubController do
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(:client, :repos).and_return([@repo])
- controller.stub_chain(:client, :orgs).and_return([])
+ stub_client(repos: [@repo], orgs: [])
get :status
@@ -67,8 +65,7 @@ describe Import::GithubController do
end
before do
- controller.stub_chain(:client, :user).and_return(github_user)
- controller.stub_chain(:client, :repo).and_return(github_repo)
+ stub_client(user: github_user, repo: github_repo)
end
context "when the repository owner is the GitHub user" do
diff --git a/spec/controllers/import/gitlab_controller_spec.rb b/spec/controllers/import/gitlab_controller_spec.rb
index a0c5ce1fe5b..4bc67c86703 100644
--- a/spec/controllers/import/gitlab_controller_spec.rb
+++ b/spec/controllers/import/gitlab_controller_spec.rb
@@ -1,18 +1,22 @@
require 'spec_helper'
+require_relative 'import_spec_helper'
describe Import::GitlabController do
+ include ImportSpecHelper
+
let(:user) { create(:user, gitlab_access_token: 'asd123') }
before do
sign_in(user)
- controller.stub(:gitlab_import_enabled?).and_return(true)
+ allow(controller).to receive(:gitlab_import_enabled?).and_return(true)
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")
+ allow_any_instance_of(Gitlab::GitlabImport::Client).
+ to receive(:get_token).and_return(token)
+ stub_omniauth_provider('gitlab')
get :callback
@@ -28,7 +32,7 @@ describe Import::GitlabController do
it "assigns variables" do
@project = create(:project, import_type: 'gitlab', creator_id: user.id)
- controller.stub_chain(:client, :projects).and_return([@repo])
+ stub_client(projects: [@repo])
get :status
@@ -38,7 +42,7 @@ describe Import::GitlabController do
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])
+ stub_client(projects: [@repo])
get :status
@@ -62,8 +66,7 @@ describe Import::GitlabController do
end
before do
- controller.stub_chain(:client, :user).and_return(gitlab_user)
- controller.stub_chain(:client, :project).and_return(gitlab_repo)
+ stub_client(user: gitlab_user, project: gitlab_repo)
end
context "when the repository owner is the GitLab.com user" do
diff --git a/spec/controllers/import/gitorious_controller_spec.rb b/spec/controllers/import/gitorious_controller_spec.rb
index 07c9484bf1a..7cb1b85a46d 100644
--- a/spec/controllers/import/gitorious_controller_spec.rb
+++ b/spec/controllers/import/gitorious_controller_spec.rb
@@ -1,6 +1,9 @@
require 'spec_helper'
+require_relative 'import_spec_helper'
describe Import::GitoriousController do
+ include ImportSpecHelper
+
let(:user) { create(:user) }
before do
@@ -30,7 +33,7 @@ describe Import::GitoriousController do
it "assigns variables" do
@project = create(:project, import_type: 'gitorious', creator_id: user.id)
- controller.stub_chain(:client, :repos).and_return([@repo])
+ stub_client(repos: [@repo])
get :status
@@ -40,7 +43,7 @@ describe Import::GitoriousController do
it "does not show already added project" do
@project = create(:project, import_type: 'gitorious', creator_id: user.id, import_source: 'asd/vim')
- controller.stub_chain(:client, :repos).and_return([@repo])
+ stub_client(repos: [@repo])
get :status
@@ -59,7 +62,7 @@ describe Import::GitoriousController do
expect(Gitlab::GitoriousImport::ProjectCreator).
to receive(:new).with(@repo, namespace, user).
and_return(double(execute: true))
- controller.stub_chain(:client, :repo).and_return(@repo)
+ stub_client(repo: @repo)
post :create, format: :js
end
diff --git a/spec/controllers/import/google_code_controller_spec.rb b/spec/controllers/import/google_code_controller_spec.rb
index 78c0f5079cc..66088139a69 100644
--- a/spec/controllers/import/google_code_controller_spec.rb
+++ b/spec/controllers/import/google_code_controller_spec.rb
@@ -1,6 +1,9 @@
require 'spec_helper'
+require_relative 'import_spec_helper'
describe Import::GoogleCodeController do
+ include ImportSpecHelper
+
let(:user) { create(:user) }
let(:dump_file) { fixture_file_upload(Rails.root + 'spec/fixtures/GoogleCodeProjectHosting.json', 'application/json') }
@@ -21,13 +24,12 @@ describe Import::GoogleCodeController do
describe "GET status" do
before do
@repo = OpenStruct.new(name: 'vim')
- controller.stub_chain(:client, :valid?).and_return(true)
+ stub_client(valid?: true)
end
it "assigns variables" do
@project = create(:project, import_type: 'google_code', creator_id: user.id)
- controller.stub_chain(:client, :repos).and_return([@repo])
- controller.stub_chain(:client, :incompatible_repos).and_return([])
+ stub_client(repos: [@repo], incompatible_repos: [])
get :status
@@ -38,8 +40,7 @@ describe Import::GoogleCodeController do
it "does not show already added project" do
@project = create(:project, import_type: 'google_code', creator_id: user.id, import_source: 'vim')
- controller.stub_chain(:client, :repos).and_return([@repo])
- controller.stub_chain(:client, :incompatible_repos).and_return([])
+ stub_client(repos: [@repo], incompatible_repos: [])
get :status
@@ -48,8 +49,7 @@ describe Import::GoogleCodeController do
end
it "does not show any invalid projects" do
- controller.stub_chain(:client, :repos).and_return([])
- controller.stub_chain(:client, :incompatible_repos).and_return([@repo])
+ stub_client(repos: [], incompatible_repos: [@repo])
get :status
diff --git a/spec/controllers/import/import_spec_helper.rb b/spec/controllers/import/import_spec_helper.rb
new file mode 100644
index 00000000000..9d7648e25a7
--- /dev/null
+++ b/spec/controllers/import/import_spec_helper.rb
@@ -0,0 +1,33 @@
+require 'ostruct'
+
+# Helper methods for controller specs in the Import namespace
+#
+# Must be included manually.
+module ImportSpecHelper
+ # Stub `controller` to return a null object double with the provided messages
+ # when `client` is called
+ #
+ # Examples:
+ #
+ # stub_client(foo: %w(foo))
+ #
+ # controller.client.foo # => ["foo"]
+ # controller.client.bar.baz.foo # => ["foo"]
+ #
+ # Returns the client double
+ def stub_client(messages = {})
+ client = double('client', messages).as_null_object
+ allow(controller).to receive(:client).and_return(client)
+
+ client
+ end
+
+ def stub_omniauth_provider(name)
+ provider = OpenStruct.new(
+ name: name,
+ app_id: 'asd123',
+ app_secret: 'asd123'
+ )
+ Gitlab.config.omniauth.providers << provider
+ end
+end
diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb
index bda931666f7..b8db8591709 100644
--- a/spec/controllers/projects/merge_requests_controller_spec.rb
+++ b/spec/controllers/projects/merge_requests_controller_spec.rb
@@ -52,10 +52,10 @@ describe Projects::MergeRequestsController do
id: merge_request.iid,
format: format)
- expect(response.body).to_not include('&amp;')
- expect(response.body).to_not include('&gt;')
- expect(response.body).to_not include('&lt;')
- expect(response.body).to_not include('&quot;')
+ expect(response.body).not_to include('&amp;')
+ expect(response.body).not_to include('&gt;')
+ expect(response.body).not_to include('&lt;')
+ expect(response.body).not_to include('&quot;')
end
end