Skip to content
Snippets Groups Projects
Commit fda96b4b authored by Robert Speicher's avatar Robert Speicher
Browse files

Update any_instance usages

parent 534bbdd0
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
 
Loading
Loading
@@ -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
 
Loading
Loading
@@ -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
 
Loading
Loading
Loading
Loading
@@ -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})
])
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment