summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-08-30 18:16:47 -0400
committerRobert Speicher <rspeicher@gmail.com>2015-08-30 18:16:47 -0400
commitfda96b4b8ee82eb19ad4e0d061143813b64b4e2b (patch)
tree0f532e77b158eb110add4523e8c01235cd3a1197
parent534bbdd00416f0ea602af79a36372accee77e820 (diff)
downloadgitlab-ci-fda96b4b8ee82eb19ad4e0d061143813b64b4e2b.tar.gz
Update any_instance usages
-rw-r--r--spec/controllers/projects_controller_spec.rb8
-rw-r--r--spec/features/runners_spec.rb2
-rw-r--r--spec/models/user_spec.rb10
-rw-r--r--spec/requests/api/projects_spec.rb10
-rw-r--r--spec/services/create_project_service_spec.rb2
-rw-r--r--spec/support/login_helpers.rb2
-rw-r--r--spec/support/stub_gitlab_calls.rb6
7 files changed, 20 insertions, 20 deletions
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb
index 0069a78..326ec9a 100644
--- a/spec/controllers/projects_controller_spec.rb
+++ b/spec/controllers/projects_controller_spec.rb
@@ -61,8 +61,8 @@ describe ProjectsController do
it "creates project" do
allow(controller).to receive(:reset_cache) { true }
allow(controller).to receive(:current_user) { user }
- Network.any_instance.stub(:enable_ci).and_return(true)
- Network.any_instance.stub(:project_hooks).and_return(true)
+ allow_any_instance_of(Network).to receive(:enable_ci).and_return(true)
+ allow_any_instance_of(Network).to receive(:project_hooks).and_return(true)
post :create, { project: JSON.dump(project_dump.to_h) }.with_indifferent_access
@@ -73,7 +73,7 @@ describe ProjectsController do
it "shows error" do
allow(controller).to receive(:reset_cache) { true }
allow(controller).to receive(:current_user) { user }
- User.any_instance.stub(:can_manage_project?).and_return(false)
+ allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
post :create, { project: JSON.dump(project_dump.to_h) }.with_indifferent_access
@@ -97,7 +97,7 @@ describe ProjectsController do
it "searches projects" do
allow(controller).to receive(:reset_cache) { true }
allow(controller).to receive(:current_user) { user }
- Network.any_instance.should_receive(:projects).with(hash_including(search: 'str'), :authorized)
+ expect_any_instance_of(Network).to receive(:projects).with(hash_including(search: 'str'), :authorized)
xhr :get, :gitlab, { search: "str", format: "js" }.with_indifferent_access
diff --git a/spec/features/runners_spec.rb b/spec/features/runners_spec.rb
index c41dc5b..d023af5 100644
--- a/spec/features/runners_spec.rb
+++ b/spec/features/runners_spec.rb
@@ -12,7 +12,7 @@ describe "Runners" do
stub_js_gitlab_calls
# all projects should be authorized for user
- Network.any_instance.stub(:projects).and_return([
+ allow_any_instance_of(Network).to receive(:projects).and_return([
OpenStruct.new({id: @project.gitlab_id}),
OpenStruct.new({id: @project2.gitlab_id})
])
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 73a7a7d..5c1a26f 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -60,17 +60,17 @@ describe User do
FactoryGirl.create :project, gitlab_id: 2
gitlab_project = OpenStruct.new({id: 1})
gitlab_project1 = OpenStruct.new({id: 2})
- User.any_instance.stub(:gitlab_projects).and_return([gitlab_project, gitlab_project1])
+ allow_any_instance_of(User).to receive(:gitlab_projects).and_return([gitlab_project, gitlab_project1])
end
it "returns projects" do
- User.any_instance.stub(:can_manage_project?).and_return(true)
+ allow_any_instance_of(User).to receive(:can_manage_project?).and_return(true)
user.authorized_projects.count.should == 2
end
it "empty list if user miss manage permission" do
- User.any_instance.stub(:can_manage_project?).and_return(false)
+ allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
user.authorized_projects.count.should == 0
end
@@ -82,8 +82,8 @@ describe User do
project1 = FactoryGirl.create :project, gitlab_id: 2
gitlab_project = OpenStruct.new({id: 1})
gitlab_project1 = OpenStruct.new({id: 2})
- User.any_instance.stub(:gitlab_projects).and_return([gitlab_project, gitlab_project1])
- User.any_instance.stub(:can_manage_project?).and_return(true)
+ allow_any_instance_of(User).to receive(:gitlab_projects).and_return([gitlab_project, gitlab_project1])
+ allow_any_instance_of(User).to receive(:can_manage_project?).and_return(true)
user = User.new({})
runner = FactoryGirl.create :specific_runner
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 014a9ef..c165aec 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -68,7 +68,7 @@ describe API::API do
end
it "non-manager is not authorized" do
- User.any_instance.stub(:can_manage_project?).and_return(false)
+ allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
post api("/projects/#{project.id}/webhooks"), options
response.status.should == 401
end
@@ -134,7 +134,7 @@ describe API::API do
end
it "non-manager is not authorized" do
- User.any_instance.stub(:can_manage_project?).and_return(false)
+ allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
put api("/projects/#{project.id}"), options
response.status.should == 401
end
@@ -151,7 +151,7 @@ describe API::API do
end
it "non-manager is not authorized" do
- User.any_instance.stub(:can_manage_project?).and_return(false)
+ allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
delete api("/projects/#{project.id}"), options
response.status.should == 401
end
@@ -218,7 +218,7 @@ describe API::API do
end
it "non-manager is not authorized" do
- User.any_instance.stub(:can_manage_project?).and_return(false)
+ allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
post api("/projects/#{project.id}/runners/#{runner.id}"), options
response.status.should == 401
end
@@ -242,7 +242,7 @@ describe API::API do
end
it "non-manager is not authorized" do
- User.any_instance.stub(:can_manage_project?).and_return(false)
+ allow_any_instance_of(User).to receive(:can_manage_project?).and_return(false)
post api("/projects/#{project.id}/runners/#{runner.id}"), options
response.status.should == 401
end
diff --git a/spec/services/create_project_service_spec.rb b/spec/services/create_project_service_spec.rb
index 3161496..d112583 100644
--- a/spec/services/create_project_service_spec.rb
+++ b/spec/services/create_project_service_spec.rb
@@ -5,7 +5,7 @@ describe CreateProjectService do
let(:current_user) { double.as_null_object }
let(:project_dump) { YAML.load File.read(Rails.root.join('spec/support/gitlab_stubs/raw_project.yml')) }
- before { Network.any_instance.stub(enable_ci: true) }
+ before { allow_any_instance_of(Network).to receive_messages(enable_ci: true) }
describe :execute do
context 'valid params' do
diff --git a/spec/support/login_helpers.rb b/spec/support/login_helpers.rb
index ebd9693..fde02b4 100644
--- a/spec/support/login_helpers.rb
+++ b/spec/support/login_helpers.rb
@@ -17,6 +17,6 @@ module LoginHelpers
end
def skip_admin_auth
- ApplicationController.any_instance.stub(authenticate_admin!: true)
+ allow_any_instance_of(ApplicationController).to receive_messages(authenticate_admin!: true)
end
end
diff --git a/spec/support/stub_gitlab_calls.rb b/spec/support/stub_gitlab_calls.rb
index 931ef96..7760f9c 100644
--- a/spec/support/stub_gitlab_calls.rb
+++ b/spec/support/stub_gitlab_calls.rb
@@ -10,7 +10,7 @@ module StubGitlabCalls
end
def stub_js_gitlab_calls
- Network.any_instance.stub(:projects) { project_hash_array }
+ allow_any_instance_of(Network).to receive(:projects) { project_hash_array }
end
private
@@ -42,12 +42,12 @@ module StubGitlabCalls
def stub_project_8
data = File.read(Rails.root.join('spec/support/gitlab_stubs/project_8.json'))
- Network.any_instance.stub(:project).and_return(JSON.parse(data))
+ allow_any_instance_of(Network).to receive(:project).and_return(JSON.parse(data))
end
def stub_project_8_hooks
data = File.read(Rails.root.join('spec/support/gitlab_stubs/project_8_hooks.json'))
- Network.any_instance.stub(:project_hooks).and_return(JSON.parse(data))
+ allow_any_instance_of(Network).to receive(:project_hooks).and_return(JSON.parse(data))
end
def stub_projects