All specs and features currently passing with FactoryGirl
This commit is contained in:
parent
4805c64f2a
commit
c9c1f76e00
8 changed files with 262 additions and 31 deletions
|
@ -8,8 +8,8 @@ require 'webmock/cucumber'
|
||||||
|
|
||||||
WebMock.allow_net_connect!
|
WebMock.allow_net_connect!
|
||||||
|
|
||||||
require Rails.root.join 'spec/support/monkeypatch'
|
|
||||||
require Rails.root.join 'spec/support/gitolite_stub'
|
require Rails.root.join 'spec/support/gitolite_stub'
|
||||||
|
require Rails.root.join 'spec/support/stubbed_repository'
|
||||||
require Rails.root.join 'spec/support/login_helpers'
|
require Rails.root.join 'spec/support/login_helpers'
|
||||||
require Rails.root.join 'spec/support/valid_commit'
|
require Rails.root.join 'spec/support/valid_commit'
|
||||||
|
|
||||||
|
@ -52,6 +52,8 @@ require 'cucumber/rspec/doubles'
|
||||||
|
|
||||||
include GitoliteStub
|
include GitoliteStub
|
||||||
|
|
||||||
Before do
|
Before do
|
||||||
stub_gitolite!
|
stub_gitolite!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
World(FactoryGirl::Syntax::Methods)
|
||||||
|
|
107
spec/factories.rb
Normal file
107
spec/factories.rb
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
# Backwards compatibility with the old method
|
||||||
|
def Factory(type, *args)
|
||||||
|
FactoryGirl.create(type, *args)
|
||||||
|
end
|
||||||
|
|
||||||
|
module Factory
|
||||||
|
def self.create(type, *args)
|
||||||
|
FactoryGirl.create(type, *args)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.new(type, *args)
|
||||||
|
FactoryGirl.build(type, *args)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
FactoryGirl.define do
|
||||||
|
sequence :sentence, aliases: [:title, :content] do
|
||||||
|
Faker::Lorem.sentence
|
||||||
|
end
|
||||||
|
|
||||||
|
sequence(:url) { Faker::Internet.uri('http') }
|
||||||
|
|
||||||
|
factory :user, aliases: [:author, :assignee, :owner] do
|
||||||
|
email { Faker::Internet.email }
|
||||||
|
name { Faker::Name.name }
|
||||||
|
password "123456"
|
||||||
|
password_confirmation "123456"
|
||||||
|
|
||||||
|
trait :admin do
|
||||||
|
admin true
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :admin, traits: [:admin]
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :project do
|
||||||
|
sequence(:name) { |n| "project#{n}" }
|
||||||
|
path { name }
|
||||||
|
code { name }
|
||||||
|
owner
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :users_project do
|
||||||
|
user
|
||||||
|
project
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :issue do
|
||||||
|
title
|
||||||
|
author
|
||||||
|
project
|
||||||
|
|
||||||
|
trait :closed do
|
||||||
|
closed true
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :closed_issue, traits: [:closed]
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :merge_request do
|
||||||
|
title
|
||||||
|
author
|
||||||
|
project
|
||||||
|
source_branch "master"
|
||||||
|
target_branch "stable"
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :note do
|
||||||
|
project
|
||||||
|
note "Note"
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :event do
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :key do
|
||||||
|
title
|
||||||
|
key { File.read(File.join(Rails.root, "db", "pkey.example")) }
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :milestone do
|
||||||
|
title
|
||||||
|
project
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :system_hook do
|
||||||
|
url
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :project_hook do
|
||||||
|
url
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :wiki do
|
||||||
|
title
|
||||||
|
content
|
||||||
|
user
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :snippet do
|
||||||
|
project
|
||||||
|
author
|
||||||
|
title
|
||||||
|
content
|
||||||
|
file_name { Faker::Lorem.sentence }
|
||||||
|
end
|
||||||
|
end
|
83
spec/factories_spec.rb
Normal file
83
spec/factories_spec.rb
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe "Factories" do
|
||||||
|
describe 'User' do
|
||||||
|
it "builds a valid instance" do
|
||||||
|
build(:user).should be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "builds a valid admin instance" do
|
||||||
|
build(:admin).should be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'Project' do
|
||||||
|
it "builds a valid instance" do
|
||||||
|
build(:project).should be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'Issue' do
|
||||||
|
it "builds a valid instance" do
|
||||||
|
build(:issue).should be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "builds a valid closed instance" do
|
||||||
|
build(:closed_issue).should be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'MergeRequest' do
|
||||||
|
it "builds a valid instance" do
|
||||||
|
build(:merge_request).should be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'Note' do
|
||||||
|
it "builds a valid instance" do
|
||||||
|
build(:note).should be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'Event' do
|
||||||
|
it "builds a valid instance" do
|
||||||
|
build(:event).should be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'Key' do
|
||||||
|
it "builds a valid instance" do
|
||||||
|
build(:key).should be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'Milestone' do
|
||||||
|
it "builds a valid instance" do
|
||||||
|
build(:milestone).should be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'SystemHook' do
|
||||||
|
it "builds a valid instance" do
|
||||||
|
build(:system_hook).should be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'ProjectHook' do
|
||||||
|
it "builds a valid instance" do
|
||||||
|
build(:project_hook).should be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'Wiki' do
|
||||||
|
it "builds a valid instance" do
|
||||||
|
build(:wiki).should be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'Snippet' do
|
||||||
|
it "builds a valid instance" do
|
||||||
|
build(:snippet).should be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -2,7 +2,7 @@ require "spec_helper"
|
||||||
|
|
||||||
describe GitlabMarkdownHelper do
|
describe GitlabMarkdownHelper do
|
||||||
before do
|
before do
|
||||||
@project = Project.find_by_path("gitlabhq") || Factory(:project)
|
@project = Factory(:project)
|
||||||
@commit = @project.repo.commits.first.parents.first
|
@commit = @project.repo.commits.first.parents.first
|
||||||
@commit = CommitDecorator.decorate(Commit.new(@commit))
|
@commit = CommitDecorator.decorate(Commit.new(@commit))
|
||||||
@other_project = Factory :project, path: "OtherPath", code: "OtherCode"
|
@other_project = Factory :project, path: "OtherPath", code: "OtherCode"
|
||||||
|
@ -157,7 +157,7 @@ describe GitlabMarkdownHelper do
|
||||||
gfm("Let @#{user.name} fix the *mess* in #{@commit.id}").should == "Let #{link_to "@#{user.name}", project_team_member_path(@project, member), class: "gfm gfm-team_member "} fix the *mess* in #{link_to @commit.id, project_commit_path(@project, id: @commit.id), title: "Commit: #{@commit.author_name} - #{@commit.title}", class: "gfm gfm-commit "}"
|
gfm("Let @#{user.name} fix the *mess* in #{@commit.id}").should == "Let #{link_to "@#{user.name}", project_team_member_path(@project, member), class: "gfm gfm-team_member "} fix the *mess* in #{link_to @commit.id, project_commit_path(@project, id: @commit.id), title: "Commit: #{@commit.author_name} - #{@commit.title}", class: "gfm gfm-commit "}"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not trip over other stuff", focus: true do
|
it "should not trip over other stuff" do
|
||||||
gfm("_Please_ *stop* 'helping' and all the other b*$#%' you do.").should == "_Please_ *stop* 'helping' and all the other b*$#%' you do."
|
gfm("_Please_ *stop* 'helping' and all the other b*$#%' you do.").should == "_Please_ *stop* 'helping' and all the other b*$#%' you do."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,13 +10,12 @@ describe SystemHook do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "project_create hook" do
|
it "project_create hook" do
|
||||||
user = Factory :user
|
|
||||||
with_resque do
|
with_resque do
|
||||||
project = Factory :project_without_owner, owner: user
|
project = Factory :project
|
||||||
end
|
end
|
||||||
WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once
|
WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once
|
||||||
end
|
end
|
||||||
|
|
||||||
it "project_destroy hook" do
|
it "project_destroy hook" do
|
||||||
project = Factory :project
|
project = Factory :project
|
||||||
with_resque do
|
with_resque do
|
||||||
|
@ -31,7 +30,7 @@ describe SystemHook do
|
||||||
end
|
end
|
||||||
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once
|
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once
|
||||||
end
|
end
|
||||||
|
|
||||||
it "user_destroy hook" do
|
it "user_destroy hook" do
|
||||||
user = Factory :user
|
user = Factory :user
|
||||||
with_resque do
|
with_resque do
|
||||||
|
@ -39,7 +38,7 @@ describe SystemHook do
|
||||||
end
|
end
|
||||||
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once
|
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once
|
||||||
end
|
end
|
||||||
|
|
||||||
it "project_create hook" do
|
it "project_create hook" do
|
||||||
user = Factory :user
|
user = Factory :user
|
||||||
project = Factory :project
|
project = Factory :project
|
||||||
|
@ -48,7 +47,7 @@ describe SystemHook do
|
||||||
end
|
end
|
||||||
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
|
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
|
||||||
end
|
end
|
||||||
|
|
||||||
it "project_destroy hook" do
|
it "project_destroy hook" do
|
||||||
user = Factory :user
|
user = Factory :user
|
||||||
project = Factory :project
|
project = Factory :project
|
||||||
|
|
|
@ -27,6 +27,7 @@ RSpec.configure do |config|
|
||||||
|
|
||||||
config.include LoginHelpers, type: :request
|
config.include LoginHelpers, type: :request
|
||||||
config.include GitoliteStub
|
config.include GitoliteStub
|
||||||
|
config.include FactoryGirl::Syntax::Methods
|
||||||
|
|
||||||
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
# 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
|
# examples within a transaction, remove the following line or assign false
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
# Stubbing Project <-> git host path
|
|
||||||
# create project using Factory only
|
|
||||||
class Project
|
|
||||||
def path_to_repo
|
|
||||||
File.join(Rails.root, "tmp", "tests", path)
|
|
||||||
end
|
|
||||||
|
|
||||||
def satellite
|
|
||||||
@satellite ||= FakeSatellite.new
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class FakeSatellite
|
|
||||||
def exists?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
def create
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
|
60
spec/support/stubbed_repository.rb
Normal file
60
spec/support/stubbed_repository.rb
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
# Stubs out all Git repository access done by models so that specs can run
|
||||||
|
# against fake repositories without Grit complaining that they don't exist.
|
||||||
|
module StubbedRepository
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
# If a class defines the method we want to stub directly, rather than
|
||||||
|
# inheriting it from a module (as is the case in UsersProject), that method
|
||||||
|
# will overwrite our stub, so use alias_method to ensure it's our stub
|
||||||
|
# getting called.
|
||||||
|
|
||||||
|
alias_method :update_repository, :fake_update_repository
|
||||||
|
alias_method :destroy_repository, :fake_destroy_repository
|
||||||
|
alias_method :repository_delete_key, :fake_repository_delete_key
|
||||||
|
alias_method :path_to_repo, :fake_path_to_repo
|
||||||
|
alias_method :satellite, :fake_satellite
|
||||||
|
end
|
||||||
|
|
||||||
|
def fake_update_repository
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def fake_destroy_repository
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def fake_repository_delete_key
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def fake_path_to_repo
|
||||||
|
if new_record?
|
||||||
|
# There are a couple Project specs that expect the Project's path to be
|
||||||
|
# in the returned path, so let's patronize them.
|
||||||
|
File.join(Rails.root, 'tmp', 'tests', path)
|
||||||
|
else
|
||||||
|
# For everything else, just give it the path to one of our real seeded
|
||||||
|
# repos.
|
||||||
|
File.join(Rails.root, 'tmp', 'tests', 'gitlabhq_1')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def fake_satellite
|
||||||
|
FakeSatellite.new
|
||||||
|
end
|
||||||
|
|
||||||
|
class FakeSatellite
|
||||||
|
def exists?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
[Project, Key, ProtectedBranch, UsersProject].each do |c|
|
||||||
|
c.send(:include, StubbedRepository)
|
||||||
|
end
|
Loading…
Reference in a new issue