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
rescue_from Ci::Network::UnauthorizedError, with: :invalid_token
before_filter :default_headers
before_filter :check_config
#before_filter :check_config
protect_from_forgery
......
......@@ -24,17 +24,6 @@ ActiveRecord::Schema.define(version: 20150826001931) do
t.datetime "updated_at"
end
create_table "appearances", force: true do |t|
t.string "title"
t.text "description"
t.string "logo"
t.integer "updated_by"
t.datetime "created_at"
t.datetime "updated_at"
t.string "dark_logo"
t.string "light_logo"
end
create_table "application_settings", force: true do |t|
t.integer "default_projects_limit"
t.boolean "signup_enabled"
......@@ -46,11 +35,10 @@ ActiveRecord::Schema.define(version: 20150826001931) do
t.string "home_page_url"
t.integer "default_branch_protection", default: 2
t.boolean "twitter_sharing_enabled", default: true
t.text "help_text"
t.text "restricted_visibility_levels"
t.boolean "version_check_enabled", default: true
t.integer "max_attachment_size", default: 10, null: false
t.integer "default_project_visibility"
t.boolean "version_check_enabled", default: true
t.integer "default_snippet_visibility"
t.text "restricted_signup_domains"
t.boolean "user_oauth_applications", default: true
......@@ -318,28 +306,6 @@ ActiveRecord::Schema.define(version: 20150826001931) do
add_index "forked_project_links", ["forked_to_project_id"], name: "index_forked_project_links_on_forked_to_project_id", unique: true, using: :btree
create_table "git_hooks", force: true do |t|
t.string "force_push_regex"
t.string "delete_branch_regex"
t.string "commit_message_regex"
t.boolean "deny_delete_tag"
t.integer "project_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "author_email_regex"
t.boolean "member_check", default: false, null: false
t.string "file_name_regex"
t.boolean "is_sample", default: false
t.integer "max_file_size", default: 0
end
create_table "historical_data", force: true do |t|
t.date "date", null: false
t.integer "active_user_count"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "identities", force: true do |t|
t.string "extern_uid"
t.string "provider"
......@@ -411,21 +377,6 @@ ActiveRecord::Schema.define(version: 20150826001931) do
add_index "labels", ["project_id"], name: "index_labels_on_project_id", using: :btree
create_table "ldap_group_links", force: true do |t|
t.string "cn", null: false
t.integer "group_access", null: false
t.integer "group_id", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.string "provider"
end
create_table "licenses", force: true do |t|
t.text "data", null: false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "members", force: true do |t|
t.integer "access_level", null: false
t.integer "source_id", null: false
......@@ -515,11 +466,10 @@ ActiveRecord::Schema.define(version: 20150826001931) do
t.string "type"
t.string "description", default: "", null: false
t.string "avatar"
t.boolean "membership_lock", default: false
end
add_index "namespaces", ["created_at", "id"], name: "index_namespaces_on_created_at_and_id", using: :btree
add_index "namespaces", ["name"], name: "index_namespaces_on_name", using: :btree
add_index "namespaces", ["name"], name: "index_namespaces_on_name", unique: true, using: :btree
add_index "namespaces", ["owner_id"], name: "index_namespaces_on_owner_id", using: :btree
add_index "namespaces", ["path"], name: "index_namespaces_on_path", unique: true, using: :btree
add_index "namespaces", ["type"], name: "index_namespaces_on_type", using: :btree
......@@ -593,14 +543,6 @@ ActiveRecord::Schema.define(version: 20150826001931) do
add_index "oauth_applications", ["owner_id", "owner_type"], name: "index_oauth_applications_on_owner_id_and_owner_type", using: :btree
add_index "oauth_applications", ["uid"], name: "index_oauth_applications_on_uid", unique: true, using: :btree
create_table "project_group_links", force: true do |t|
t.integer "project_id", null: false
t.integer "group_id", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "group_access", default: 30, null: false
end
create_table "project_import_data", force: true do |t|
t.integer "project_id"
t.text "data"
......@@ -631,9 +573,6 @@ ActiveRecord::Schema.define(version: 20150826001931) do
t.integer "star_count", default: 0, null: false
t.string "import_type"
t.string "import_source"
t.text "merge_requests_template"
t.boolean "merge_requests_rebase_enabled", default: false
t.boolean "merge_requests_rebase_default", default: true
t.integer "commit_count", default: 0
end
......@@ -734,12 +673,6 @@ ActiveRecord::Schema.define(version: 20150826001931) do
add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree
create_table "test", id: false, force: true do |t|
t.integer "col"
end
add_index "test", ["col"], name: "index_name", unique: true, using: :btree
create_table "users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
......@@ -783,14 +716,13 @@ ActiveRecord::Schema.define(version: 20150826001931) do
t.string "notification_email"
t.boolean "hide_no_password", default: false
t.boolean "password_automatically_set", default: false
t.datetime "admin_email_unsubscribed_at"
t.string "location"
t.string "public_email", default: "", null: false
t.string "encrypted_otp_secret"
t.string "encrypted_otp_secret_iv"
t.string "encrypted_otp_secret_salt"
t.boolean "otp_required_for_login", default: false, null: false
t.text "otp_backup_codes"
t.string "public_email", default: "", null: false
t.integer "dashboard", default: 0
t.integer "project_view", default: 0
end
......
# 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"
describe CommitsController do
describe Ci::CommitsController do
before do
@project = FactoryGirl.create :project
@project = FactoryGirl.create :ci_project
end
describe "GET /status" 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
expect(response).to be_success
......@@ -16,7 +16,7 @@ describe CommitsController do
end
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
expect(response).to be_success
......
......@@ -26,7 +26,7 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :build do
factory :ci_build, class: Ci::Build do
started_at 'Di 29. Okt 09:51:28 CET 2013'
finished_at 'Di 29. Okt 09:53:28 CET 2013'
commands 'ls -a'
......
......@@ -17,7 +17,7 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :commit do
factory :ci_commit, class: Ci::Commit do
ref 'master'
before_sha '76de212e80737a608d939f648d959671fb0a0142'
sha '97de212e80737a608d939f648d959671fb0a0142'
......@@ -51,21 +51,21 @@ FactoryGirl.define do
}
end
factory :commit_without_jobs do
factory :ci_commit_without_jobs do
after(:create) do |commit, evaluator|
commit.push_data[:ci_yaml_file] = YAML.dump({})
commit.save
end
end
factory :commit_with_one_job do
factory :ci_commit_with_one_job do
after(:create) do |commit, evaluator|
commit.push_data[:ci_yaml_file] = YAML.dump({rspec: { script: "ls" }})
commit.save
end
end
factory :commit_with_two_jobs do
factory :ci_commit_with_two_jobs do
after(:create) do |commit, evaluator|
commit.push_data[:ci_yaml_file] = YAML.dump({rspec: { script: "ls" }, spinach: { script: "ls" }})
commit.save
......
......@@ -12,7 +12,7 @@
#
FactoryGirl.define do
factory :event, class: Event do
factory :ci_event, class: Ci::Event do
sequence :description do |n|
"updated project settings#{n}"
end
......
......@@ -28,7 +28,7 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :project_without_token, class: Project do
factory :ci_project_without_token, class: Ci::Project do
sequence :name do |n|
"GitLab / gitlab-shell#{n}"
end
......@@ -45,11 +45,11 @@ FactoryGirl.define do
sequence :gitlab_id
factory :project do
factory :ci_project do
token 'iPWx6WM4lhHNedGfBpPJNP'
end
factory :public_project do
factory :ci_public_project do
public true
end
end
......
......@@ -12,7 +12,7 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :runner_project do
factory :ci_runner_project, class: Ci::RunnerProject do
runner_id 1
project_id 1
end
......
......@@ -20,7 +20,7 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :runner do
factory :ci_runner, class: Ci::Runner do
sequence :description do |n|
"My runner#{n}"
end
......
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :trigger_without_token, class: Trigger do
factory :ci_trigger_without_token, class: Ci::Trigger do
factory :trigger do
token 'token'
end
......
FactoryGirl.define do
factory :web_hook do
factory :ci_web_hook, class: Ci::WebHook do
sequence(:url) { Faker::Internet.uri('http') }
project
end
......
......@@ -29,6 +29,9 @@ RSpec.configure do |config|
config.include LoginHelpers, type: :request
config.include StubConfiguration
config.include TestEnv
config.include StubGitlabCalls
config.include StubGitlabData
config.infer_spec_type_from_file_location!
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