Commit c9c1f76e002d899dd6765c4c1630697cc5068f27
1 parent
4805c64f
Exists in
master
and in
4 other branches
All specs and features currently passing with FactoryGirl
Showing
8 changed files
with
262 additions
and
31 deletions
Show diff stats
features/support/env.rb
@@ -8,8 +8,8 @@ require 'webmock/cucumber' | @@ -8,8 +8,8 @@ require 'webmock/cucumber' | ||
8 | 8 | ||
9 | WebMock.allow_net_connect! | 9 | WebMock.allow_net_connect! |
10 | 10 | ||
11 | -require Rails.root.join 'spec/support/monkeypatch' | ||
12 | require Rails.root.join 'spec/support/gitolite_stub' | 11 | require Rails.root.join 'spec/support/gitolite_stub' |
12 | +require Rails.root.join 'spec/support/stubbed_repository' | ||
13 | require Rails.root.join 'spec/support/login_helpers' | 13 | require Rails.root.join 'spec/support/login_helpers' |
14 | require Rails.root.join 'spec/support/valid_commit' | 14 | require Rails.root.join 'spec/support/valid_commit' |
15 | 15 | ||
@@ -52,6 +52,8 @@ require 'cucumber/rspec/doubles' | @@ -52,6 +52,8 @@ require 'cucumber/rspec/doubles' | ||
52 | 52 | ||
53 | include GitoliteStub | 53 | include GitoliteStub |
54 | 54 | ||
55 | -Before do | 55 | +Before do |
56 | stub_gitolite! | 56 | stub_gitolite! |
57 | end | 57 | end |
58 | + | ||
59 | +World(FactoryGirl::Syntax::Methods) |
@@ -0,0 +1,107 @@ | @@ -0,0 +1,107 @@ | ||
1 | +# Backwards compatibility with the old method | ||
2 | +def Factory(type, *args) | ||
3 | + FactoryGirl.create(type, *args) | ||
4 | +end | ||
5 | + | ||
6 | +module Factory | ||
7 | + def self.create(type, *args) | ||
8 | + FactoryGirl.create(type, *args) | ||
9 | + end | ||
10 | + | ||
11 | + def self.new(type, *args) | ||
12 | + FactoryGirl.build(type, *args) | ||
13 | + end | ||
14 | +end | ||
15 | + | ||
16 | +FactoryGirl.define do | ||
17 | + sequence :sentence, aliases: [:title, :content] do | ||
18 | + Faker::Lorem.sentence | ||
19 | + end | ||
20 | + | ||
21 | + sequence(:url) { Faker::Internet.uri('http') } | ||
22 | + | ||
23 | + factory :user, aliases: [:author, :assignee, :owner] do | ||
24 | + email { Faker::Internet.email } | ||
25 | + name { Faker::Name.name } | ||
26 | + password "123456" | ||
27 | + password_confirmation "123456" | ||
28 | + | ||
29 | + trait :admin do | ||
30 | + admin true | ||
31 | + end | ||
32 | + | ||
33 | + factory :admin, traits: [:admin] | ||
34 | + end | ||
35 | + | ||
36 | + factory :project do | ||
37 | + sequence(:name) { |n| "project#{n}" } | ||
38 | + path { name } | ||
39 | + code { name } | ||
40 | + owner | ||
41 | + end | ||
42 | + | ||
43 | + factory :users_project do | ||
44 | + user | ||
45 | + project | ||
46 | + end | ||
47 | + | ||
48 | + factory :issue do | ||
49 | + title | ||
50 | + author | ||
51 | + project | ||
52 | + | ||
53 | + trait :closed do | ||
54 | + closed true | ||
55 | + end | ||
56 | + | ||
57 | + factory :closed_issue, traits: [:closed] | ||
58 | + end | ||
59 | + | ||
60 | + factory :merge_request do | ||
61 | + title | ||
62 | + author | ||
63 | + project | ||
64 | + source_branch "master" | ||
65 | + target_branch "stable" | ||
66 | + end | ||
67 | + | ||
68 | + factory :note do | ||
69 | + project | ||
70 | + note "Note" | ||
71 | + end | ||
72 | + | ||
73 | + factory :event do | ||
74 | + end | ||
75 | + | ||
76 | + factory :key do | ||
77 | + title | ||
78 | + key { File.read(File.join(Rails.root, "db", "pkey.example")) } | ||
79 | + end | ||
80 | + | ||
81 | + factory :milestone do | ||
82 | + title | ||
83 | + project | ||
84 | + end | ||
85 | + | ||
86 | + factory :system_hook do | ||
87 | + url | ||
88 | + end | ||
89 | + | ||
90 | + factory :project_hook do | ||
91 | + url | ||
92 | + end | ||
93 | + | ||
94 | + factory :wiki do | ||
95 | + title | ||
96 | + content | ||
97 | + user | ||
98 | + end | ||
99 | + | ||
100 | + factory :snippet do | ||
101 | + project | ||
102 | + author | ||
103 | + title | ||
104 | + content | ||
105 | + file_name { Faker::Lorem.sentence } | ||
106 | + end | ||
107 | +end |
@@ -0,0 +1,83 @@ | @@ -0,0 +1,83 @@ | ||
1 | +require 'spec_helper' | ||
2 | + | ||
3 | +describe "Factories" do | ||
4 | + describe 'User' do | ||
5 | + it "builds a valid instance" do | ||
6 | + build(:user).should be_valid | ||
7 | + end | ||
8 | + | ||
9 | + it "builds a valid admin instance" do | ||
10 | + build(:admin).should be_valid | ||
11 | + end | ||
12 | + end | ||
13 | + | ||
14 | + describe 'Project' do | ||
15 | + it "builds a valid instance" do | ||
16 | + build(:project).should be_valid | ||
17 | + end | ||
18 | + end | ||
19 | + | ||
20 | + describe 'Issue' do | ||
21 | + it "builds a valid instance" do | ||
22 | + build(:issue).should be_valid | ||
23 | + end | ||
24 | + | ||
25 | + it "builds a valid closed instance" do | ||
26 | + build(:closed_issue).should be_valid | ||
27 | + end | ||
28 | + end | ||
29 | + | ||
30 | + describe 'MergeRequest' do | ||
31 | + it "builds a valid instance" do | ||
32 | + build(:merge_request).should be_valid | ||
33 | + end | ||
34 | + end | ||
35 | + | ||
36 | + describe 'Note' do | ||
37 | + it "builds a valid instance" do | ||
38 | + build(:note).should be_valid | ||
39 | + end | ||
40 | + end | ||
41 | + | ||
42 | + describe 'Event' do | ||
43 | + it "builds a valid instance" do | ||
44 | + build(:event).should be_valid | ||
45 | + end | ||
46 | + end | ||
47 | + | ||
48 | + describe 'Key' do | ||
49 | + it "builds a valid instance" do | ||
50 | + build(:key).should be_valid | ||
51 | + end | ||
52 | + end | ||
53 | + | ||
54 | + describe 'Milestone' do | ||
55 | + it "builds a valid instance" do | ||
56 | + build(:milestone).should be_valid | ||
57 | + end | ||
58 | + end | ||
59 | + | ||
60 | + describe 'SystemHook' do | ||
61 | + it "builds a valid instance" do | ||
62 | + build(:system_hook).should be_valid | ||
63 | + end | ||
64 | + end | ||
65 | + | ||
66 | + describe 'ProjectHook' do | ||
67 | + it "builds a valid instance" do | ||
68 | + build(:project_hook).should be_valid | ||
69 | + end | ||
70 | + end | ||
71 | + | ||
72 | + describe 'Wiki' do | ||
73 | + it "builds a valid instance" do | ||
74 | + build(:wiki).should be_valid | ||
75 | + end | ||
76 | + end | ||
77 | + | ||
78 | + describe 'Snippet' do | ||
79 | + it "builds a valid instance" do | ||
80 | + build(:snippet).should be_valid | ||
81 | + end | ||
82 | + end | ||
83 | +end |
spec/helpers/gitlab_flavored_markdown_spec.rb
@@ -2,7 +2,7 @@ require "spec_helper" | @@ -2,7 +2,7 @@ require "spec_helper" | ||
2 | 2 | ||
3 | describe GitlabMarkdownHelper do | 3 | describe GitlabMarkdownHelper do |
4 | before do | 4 | before do |
5 | - @project = Project.find_by_path("gitlabhq") || Factory(:project) | 5 | + @project = Factory(:project) |
6 | @commit = @project.repo.commits.first.parents.first | 6 | @commit = @project.repo.commits.first.parents.first |
7 | @commit = CommitDecorator.decorate(Commit.new(@commit)) | 7 | @commit = CommitDecorator.decorate(Commit.new(@commit)) |
8 | @other_project = Factory :project, path: "OtherPath", code: "OtherCode" | 8 | @other_project = Factory :project, path: "OtherPath", code: "OtherCode" |
@@ -157,7 +157,7 @@ describe GitlabMarkdownHelper do | @@ -157,7 +157,7 @@ describe GitlabMarkdownHelper do | ||
157 | 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 "}" | 157 | 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 "}" |
158 | end | 158 | end |
159 | 159 | ||
160 | - it "should not trip over other stuff", focus: true do | 160 | + it "should not trip over other stuff" do |
161 | gfm("_Please_ *stop* 'helping' and all the other b*$#%' you do.").should == "_Please_ *stop* 'helping' and all the other b*$#%' you do." | 161 | gfm("_Please_ *stop* 'helping' and all the other b*$#%' you do.").should == "_Please_ *stop* 'helping' and all the other b*$#%' you do." |
162 | end | 162 | end |
163 | 163 |
spec/models/system_hook_spec.rb
@@ -10,13 +10,12 @@ describe SystemHook do | @@ -10,13 +10,12 @@ describe SystemHook do | ||
10 | end | 10 | end |
11 | 11 | ||
12 | it "project_create hook" do | 12 | it "project_create hook" do |
13 | - user = Factory :user | ||
14 | with_resque do | 13 | with_resque do |
15 | - project = Factory :project_without_owner, owner: user | 14 | + project = Factory :project |
16 | end | 15 | end |
17 | WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once | 16 | WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once |
18 | end | 17 | end |
19 | - | 18 | + |
20 | it "project_destroy hook" do | 19 | it "project_destroy hook" do |
21 | project = Factory :project | 20 | project = Factory :project |
22 | with_resque do | 21 | with_resque do |
@@ -31,7 +30,7 @@ describe SystemHook do | @@ -31,7 +30,7 @@ describe SystemHook do | ||
31 | end | 30 | end |
32 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once | 31 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once |
33 | end | 32 | end |
34 | - | 33 | + |
35 | it "user_destroy hook" do | 34 | it "user_destroy hook" do |
36 | user = Factory :user | 35 | user = Factory :user |
37 | with_resque do | 36 | with_resque do |
@@ -39,7 +38,7 @@ describe SystemHook do | @@ -39,7 +38,7 @@ describe SystemHook do | ||
39 | end | 38 | end |
40 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once | 39 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once |
41 | end | 40 | end |
42 | - | 41 | + |
43 | it "project_create hook" do | 42 | it "project_create hook" do |
44 | user = Factory :user | 43 | user = Factory :user |
45 | project = Factory :project | 44 | project = Factory :project |
@@ -48,7 +47,7 @@ describe SystemHook do | @@ -48,7 +47,7 @@ describe SystemHook do | ||
48 | end | 47 | end |
49 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once | 48 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once |
50 | end | 49 | end |
51 | - | 50 | + |
52 | it "project_destroy hook" do | 51 | it "project_destroy hook" do |
53 | user = Factory :user | 52 | user = Factory :user |
54 | project = Factory :project | 53 | project = Factory :project |
spec/spec_helper.rb
@@ -27,6 +27,7 @@ RSpec.configure do |config| | @@ -27,6 +27,7 @@ RSpec.configure do |config| | ||
27 | 27 | ||
28 | config.include LoginHelpers, type: :request | 28 | config.include LoginHelpers, type: :request |
29 | config.include GitoliteStub | 29 | config.include GitoliteStub |
30 | + config.include FactoryGirl::Syntax::Methods | ||
30 | 31 | ||
31 | # If you're not using ActiveRecord, or you'd prefer not to run each of your | 32 | # If you're not using ActiveRecord, or you'd prefer not to run each of your |
32 | # examples within a transaction, remove the following line or assign false | 33 | # examples within a transaction, remove the following line or assign false |
spec/support/monkeypatch.rb
@@ -1,21 +0,0 @@ | @@ -1,21 +0,0 @@ | ||
1 | -# Stubbing Project <-> git host path | ||
2 | -# create project using Factory only | ||
3 | -class Project | ||
4 | - def path_to_repo | ||
5 | - File.join(Rails.root, "tmp", "tests", path) | ||
6 | - end | ||
7 | - | ||
8 | - def satellite | ||
9 | - @satellite ||= FakeSatellite.new | ||
10 | - end | ||
11 | -end | ||
12 | - | ||
13 | -class FakeSatellite | ||
14 | - def exists? | ||
15 | - true | ||
16 | - end | ||
17 | - | ||
18 | - def create | ||
19 | - true | ||
20 | - end | ||
21 | -end |
@@ -0,0 +1,60 @@ | @@ -0,0 +1,60 @@ | ||
1 | +# Stubs out all Git repository access done by models so that specs can run | ||
2 | +# against fake repositories without Grit complaining that they don't exist. | ||
3 | +module StubbedRepository | ||
4 | + extend ActiveSupport::Concern | ||
5 | + | ||
6 | + included do | ||
7 | + # If a class defines the method we want to stub directly, rather than | ||
8 | + # inheriting it from a module (as is the case in UsersProject), that method | ||
9 | + # will overwrite our stub, so use alias_method to ensure it's our stub | ||
10 | + # getting called. | ||
11 | + | ||
12 | + alias_method :update_repository, :fake_update_repository | ||
13 | + alias_method :destroy_repository, :fake_destroy_repository | ||
14 | + alias_method :repository_delete_key, :fake_repository_delete_key | ||
15 | + alias_method :path_to_repo, :fake_path_to_repo | ||
16 | + alias_method :satellite, :fake_satellite | ||
17 | + end | ||
18 | + | ||
19 | + def fake_update_repository | ||
20 | + true | ||
21 | + end | ||
22 | + | ||
23 | + def fake_destroy_repository | ||
24 | + true | ||
25 | + end | ||
26 | + | ||
27 | + def fake_repository_delete_key | ||
28 | + true | ||
29 | + end | ||
30 | + | ||
31 | + def fake_path_to_repo | ||
32 | + if new_record? | ||
33 | + # There are a couple Project specs that expect the Project's path to be | ||
34 | + # in the returned path, so let's patronize them. | ||
35 | + File.join(Rails.root, 'tmp', 'tests', path) | ||
36 | + else | ||
37 | + # For everything else, just give it the path to one of our real seeded | ||
38 | + # repos. | ||
39 | + File.join(Rails.root, 'tmp', 'tests', 'gitlabhq_1') | ||
40 | + end | ||
41 | + end | ||
42 | + | ||
43 | + def fake_satellite | ||
44 | + FakeSatellite.new | ||
45 | + end | ||
46 | + | ||
47 | + class FakeSatellite | ||
48 | + def exists? | ||
49 | + true | ||
50 | + end | ||
51 | + | ||
52 | + def create | ||
53 | + true | ||
54 | + end | ||
55 | + end | ||
56 | +end | ||
57 | + | ||
58 | +[Project, Key, ProtectedBranch, UsersProject].each do |c| | ||
59 | + c.send(:include, StubbedRepository) | ||
60 | +end |