Commit 76c6aeb9 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge CI factories and CI spec/support with GitLab

parent 3d6fed54
...@@ -8,7 +8,7 @@ module Ci ...@@ -8,7 +8,7 @@ module Ci
rescue_from Ci::Network::UnauthorizedError, with: :invalid_token rescue_from Ci::Network::UnauthorizedError, with: :invalid_token
before_filter :default_headers before_filter :default_headers
before_filter :check_config #before_filter :check_config
protect_from_forgery protect_from_forgery
......
This diff is collapsed.
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :user do
end
end
if ENV['SIMPLECOV']
require 'simplecov'
SimpleCov.start
end
if ENV['COVERALLS']
require 'coveralls'
Coveralls.wear!('rails')
end
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'sidekiq/testing/inline'
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
Capybara.default_wait_time = 10
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
require 'webmock/rspec'
WebMock.disable_net_connect!(allow_localhost: true)
RSpec.configure do |config|
config.include LoginHelpers, type: :feature
config.include StubGitlabCalls
config.include StubGitlabData
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = false
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
end
module ApiHelpers
# Public: Prepend a request path with the path to the API
#
# path - Path to append
# user - User object - If provided, automatically appends private_token query
# string for authenticated requests
#
# Examples
#
# >> api('/issues')
# => "/api/v2/issues"
#
# >> api('/issues', User.last)
# => "/api/v2/issues?private_token=..."
#
# >> api('/issues?foo=bar', User.last)
# => "/api/v2/issues?foo=bar&private_token=..."
#
# Returns the relative path to the requested API resource
def api(path, user = nil)
"/api/#{API::API.version}#{path}" +
# Normalize query string
(path.index('?') ? '' : '?') +
# Append private_token if given a User object
(user.respond_to?(:private_token) ?
"&private_token=#{user.private_token}" : "")
end
def json_response
JSON.parse(response.body)
end
end
# RSpec.configure do |config|
# config.around(:each) do |example|
# DatabaseCleaner.strategy = :transaction
# DatabaseCleaner.clean_with(:truncation)
# DatabaseCleaner.cleaning do
# example.run
# end
# end
# config.around(:each, js: true) do |example|
# DatabaseCleaner.strategy = :truncation
# DatabaseCleaner.clean_with(:truncation)
# DatabaseCleaner.cleaning do
# example.run
# end
# end
# end
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, :js => true) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
module LoginHelpers
def login_as(role)
raise 'Only :user allowed' unless role == :user
stub_gitlab_calls
login_with(:user)
end
# Internal: Login as the specified user
#
# user - User instance to login with
def login_with(user)
visit callback_user_sessions_path(code: "some_auth_code_here")
end
def logout
click_link "Logout" rescue nil
end
def skip_admin_auth
ApplicationController.any_instance.stub(authenticate_admin!: true)
end
end
module OAuth2
class Client
def get_token(params, access_token_opts = {}, access_token_class = AccessToken)
OpenStruct.new(token: "some_token")
end
end
end
\ No newline at end of file
require "spec_helper" require "spec_helper"
describe CommitsController do describe Ci::CommitsController do
before do before do
@project = FactoryGirl.create :project @project = FactoryGirl.create :ci_project
end end
describe "GET /status" do describe "GET /status" do
it "returns status of commit" do it "returns status of commit" do
commit = FactoryGirl.create :commit, project: @project commit = FactoryGirl.create :ci_commit, project: @project
get :status, id: commit.sha, ref_id: commit.ref, project_id: @project.id get :status, id: commit.sha, ref_id: commit.ref, project_id: @project.id
expect(response).to be_success expect(response).to be_success
...@@ -16,7 +16,7 @@ describe CommitsController do ...@@ -16,7 +16,7 @@ describe CommitsController do
end end
it "returns not_found status" do it "returns not_found status" do
commit = FactoryGirl.create :commit, project: @project commit = FactoryGirl.create :ci_commit, project: @project
get :status, id: commit.sha, ref_id: "deploy", project_id: @project.id get :status, id: commit.sha, ref_id: "deploy", project_id: @project.id
expect(response).to be_success expect(response).to be_success
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
# Read about factories at https://github.com/thoughtbot/factory_girl # Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :build do factory :ci_build, class: Ci::Build do
started_at 'Di 29. Okt 09:51:28 CET 2013' started_at 'Di 29. Okt 09:51:28 CET 2013'
finished_at 'Di 29. Okt 09:53:28 CET 2013' finished_at 'Di 29. Okt 09:53:28 CET 2013'
commands 'ls -a' commands 'ls -a'
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
# Read about factories at https://github.com/thoughtbot/factory_girl # Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :commit do factory :ci_commit, class: Ci::Commit do
ref 'master' ref 'master'
before_sha '76de212e80737a608d939f648d959671fb0a0142' before_sha '76de212e80737a608d939f648d959671fb0a0142'
sha '97de212e80737a608d939f648d959671fb0a0142' sha '97de212e80737a608d939f648d959671fb0a0142'
...@@ -51,21 +51,21 @@ FactoryGirl.define do ...@@ -51,21 +51,21 @@ FactoryGirl.define do
} }
end end
factory :commit_without_jobs do factory :ci_commit_without_jobs do
after(:create) do |commit, evaluator| after(:create) do |commit, evaluator|
commit.push_data[:ci_yaml_file] = YAML.dump({}) commit.push_data[:ci_yaml_file] = YAML.dump({})
commit.save commit.save
end end
end end
factory :commit_with_one_job do factory :ci_commit_with_one_job do
after(:create) do |commit, evaluator| after(:create) do |commit, evaluator|
commit.push_data[:ci_yaml_file] = YAML.dump({rspec: { script: "ls" }}) commit.push_data[:ci_yaml_file] = YAML.dump({rspec: { script: "ls" }})
commit.save commit.save
end end
end end
factory :commit_with_two_jobs do factory :ci_commit_with_two_jobs do
after(:create) do |commit, evaluator| after(:create) do |commit, evaluator|
commit.push_data[:ci_yaml_file] = YAML.dump({rspec: { script: "ls" }, spinach: { script: "ls" }}) commit.push_data[:ci_yaml_file] = YAML.dump({rspec: { script: "ls" }, spinach: { script: "ls" }})
commit.save commit.save
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# #
FactoryGirl.define do FactoryGirl.define do
factory :event, class: Event do factory :ci_event, class: Ci::Event do
sequence :description do |n| sequence :description do |n|
"updated project settings#{n}" "updated project settings#{n}"
end end
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
# Read about factories at https://github.com/thoughtbot/factory_girl # Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :project_without_token, class: Project do factory :ci_project_without_token, class: Ci::Project do
sequence :name do |n| sequence :name do |n|
"GitLab / gitlab-shell#{n}" "GitLab / gitlab-shell#{n}"
end end
...@@ -45,11 +45,11 @@ FactoryGirl.define do ...@@ -45,11 +45,11 @@ FactoryGirl.define do
sequence :gitlab_id sequence :gitlab_id
factory :project do factory :ci_project do
token 'iPWx6WM4lhHNedGfBpPJNP' token 'iPWx6WM4lhHNedGfBpPJNP'
end end
factory :public_project do factory :ci_public_project do
public true public true
end end
end end
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# Read about factories at https://github.com/thoughtbot/factory_girl # Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :runner_project do factory :ci_runner_project, class: Ci::RunnerProject do
runner_id 1 runner_id 1
project_id 1 project_id 1
end end
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
# Read about factories at https://github.com/thoughtbot/factory_girl # Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :runner do factory :ci_runner, class: Ci::Runner do
sequence :description do |n| sequence :description do |n|
"My runner#{n}" "My runner#{n}"
end end
......
# Read about factories at https://github.com/thoughtbot/factory_girl # Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :trigger_without_token, class: Trigger do factory :ci_trigger_without_token, class: Ci::Trigger do
factory :trigger do factory :trigger do
token 'token' token 'token'
end end
......
FactoryGirl.define do FactoryGirl.define do
factory :web_hook do factory :ci_web_hook, class: Ci::WebHook do
sequence(:url) { Faker::Internet.uri('http') } sequence(:url) { Faker::Internet.uri('http') }
project project
end end
......
...@@ -29,6 +29,9 @@ RSpec.configure do |config| ...@@ -29,6 +29,9 @@ RSpec.configure do |config|
config.include LoginHelpers, type: :request config.include LoginHelpers, type: :request
config.include StubConfiguration config.include StubConfiguration
config.include TestEnv config.include TestEnv
config.include StubGitlabCalls
config.include StubGitlabData
config.infer_spec_type_from_file_location! config.infer_spec_type_from_file_location!
config.raise_errors_for_deprecations! config.raise_errors_for_deprecations!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment