Commit 8da05a4ff7cd9cd84e74bd8a017baf59135ee39d

Authored by Dmitriy Zaporozhets
2 parents b03ee466 1dda0848

Merge pull request #1323 from tsigo/factory_girl

FactoryGirl and spec cleanup
Gemfile
... ... @@ -107,6 +107,7 @@ group :development, :test do
107 107 gem "awesome_print"
108 108 gem "database_cleaner"
109 109 gem "launchy"
  110 + gem 'factory_girl_rails'
110 111 end
111 112  
112 113 group :test do
... ...
Gemfile.lock
... ... @@ -166,6 +166,11 @@ GEM
166 166 eventmachine (0.12.10)
167 167 execjs (1.4.0)
168 168 multi_json (~> 1.0)
  169 + factory_girl (4.0.0)
  170 + activesupport (>= 3.0.0)
  171 + factory_girl_rails (4.0.0)
  172 + factory_girl (~> 4.0.0)
  173 + railties (>= 3.0.0)
169 174 ffaker (1.14.0)
170 175 ffi (1.0.11)
171 176 foreman (0.47.0)
... ... @@ -388,6 +393,7 @@ DEPENDENCIES
388 393 devise (~> 2.1.0)
389 394 draper
390 395 email_spec
  396 + factory_girl_rails
391 397 ffaker
392 398 foreman
393 399 git
... ...
db/fixtures/test/001_repo.rb
1   -# create tmp dir if not exist
2   -tmp_dir = File.join(Rails.root, "tmp")
3   -Dir.mkdir(tmp_dir) unless File.exists?(tmp_dir)
4   -
5   -# Create dir for test repo
6   -repo_dir = File.join(Rails.root, "tmp", "tests")
7   -Dir.mkdir(repo_dir) unless File.exists?(repo_dir)
8   -
9   -`cp spec/seed_project.tar.gz tmp/tests/`
10   -Dir.chdir(repo_dir)
11   -`tar -xf seed_project.tar.gz`
12   -3.times do |i|
13   -`cp -r gitlabhq/ gitlabhq_#{i}/`
14   -puts "Unpacked seed repo - tmp/tests/gitlabhq_#{i}"
  1 +require 'fileutils'
  2 +
  3 +print "Unpacking seed repository..."
  4 +
  5 +SEED_REPO = 'seed_project.tar.gz'
  6 +REPO_PATH = File.join(Rails.root, 'tmp', 'repositories')
  7 +
  8 +# Make whatever directories we need to make
  9 +FileUtils.mkdir_p(REPO_PATH)
  10 +
  11 +# Copy the archive to the repo path
  12 +FileUtils.cp(File.join(Rails.root, 'spec', SEED_REPO), REPO_PATH)
  13 +
  14 +# chdir to the repo path
  15 +FileUtils.cd(REPO_PATH) do
  16 + # Extract the archive
  17 + `tar -xf #{SEED_REPO}`
  18 +
  19 + # Remove the copy
  20 + FileUtils.rm(SEED_REPO)
15 21 end
  22 +
  23 +puts ' done.'
... ...
db/pkey.example
... ... @@ -1,3 +0,0 @@
1   -AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4
2   -596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4
3   -soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=
features/step_definitions/dashboard_steps.rb
... ... @@ -106,13 +106,9 @@ Given /^I have assigned issues$/ do
106 106 end
107 107  
108 108 Given /^I have authored merge requests$/ do
109   - project1 = Factory :project,
110   - :path => "gitlabhq_1",
111   - :code => "gitlabhq_1"
  109 + project1 = Factory :project
112 110  
113   - project2 = Factory :project,
114   - :path => "gitlabhq_2",
115   - :code => "gitlabhq_2"
  111 + project2 = Factory :project
116 112  
117 113 project1.add_access(@user, :read, :write)
118 114 project2.add_access(@user, :read, :write)
... ...
features/support/env.rb
... ... @@ -8,9 +8,8 @@ require 'webmock/cucumber'
8 8  
9 9 WebMock.allow_net_connect!
10 10  
11   -require Rails.root.join 'spec/factories'
12   -require Rails.root.join 'spec/support/monkeypatch'
13 11 require Rails.root.join 'spec/support/gitolite_stub'
  12 +require Rails.root.join 'spec/support/stubbed_repository'
14 13 require Rails.root.join 'spec/support/login_helpers'
15 14 require Rails.root.join 'spec/support/valid_commit'
16 15  
... ... @@ -53,6 +52,8 @@ require 'cucumber/rspec/doubles'
53 52  
54 53 include GitoliteStub
55 54  
56   -Before do
  55 +Before do
57 56 stub_gitolite!
58 57 end
  58 +
  59 +World(FactoryGirl::Syntax::Methods)
... ...
spec/factories.rb
1   -require File.join(Rails.root, 'spec', 'factory')
2   -
3   -Factory.add(:project, Project) do |obj|
4   - obj.name = Faker::Internet.user_name
5   - obj.path = 'gitlabhq'
6   - obj.owner = Factory(:user)
7   - obj.code = 'LGT'
8   -end
9   -
10   -Factory.add(:project_without_owner, Project) do |obj|
11   - obj.name = Faker::Internet.user_name
12   - obj.path = 'gitlabhq'
13   - obj.code = 'LGT'
14   -end
15   -
16   -Factory.add(:public_project, Project) do |obj|
17   - obj.name = Faker::Internet.user_name
18   - obj.path = 'gitlabhq'
19   - obj.private_flag = false
20   - obj.owner = Factory(:user)
21   - obj.code = 'LGT'
22   -end
23   -
24   -Factory.add(:user, User) do |obj|
25   - obj.email = Faker::Internet.email
26   - obj.password = "123456"
27   - obj.name = Faker::Name.name
28   - obj.password_confirmation = "123456"
29   -end
30   -
31   -Factory.add(:admin, User) do |obj|
32   - obj.email = Faker::Internet.email
33   - obj.password = "123456"
34   - obj.name = Faker::Name.name
35   - obj.password_confirmation = "123456"
36   - obj.admin = true
37   -end
38   -
39   -Factory.add(:issue, Issue) do |obj|
40   - obj.title = Faker::Lorem.sentence
41   - obj.author = Factory :user
42   - obj.assignee = Factory :user
43   -end
44   -
45   -Factory.add(:merge_request, MergeRequest) do |obj|
46   - obj.title = Faker::Lorem.sentence
47   - obj.author = Factory :user
48   - obj.assignee = Factory :user
49   - obj.source_branch = "master"
50   - obj.target_branch = "stable"
51   - obj.closed = false
52   -end
53   -
54   -Factory.add(:snippet, Snippet) do |obj|
55   - obj.title = Faker::Lorem.sentence
56   - obj.file_name = Faker::Lorem.sentence
57   - obj.content = Faker::Lorem.sentences
58   -end
59   -
60   -Factory.add(:note, Note) do |obj|
61   - obj.note = Faker::Lorem.sentence
62   -end
63   -
64   -Factory.add(:key, Key) do |obj|
65   - obj.title = "Example key"
66   - obj.key = File.read(File.join(Rails.root, "db", "pkey.example"))
67   -end
68   -
69   -Factory.add(:project_hook, ProjectHook) do |obj|
70   - obj.url = Faker::Internet.uri("http")
71   -end
72   -
73   -Factory.add(:system_hook, SystemHook) do |obj|
74   - obj.url = Faker::Internet.uri("http")
75   -end
76   -
77   -Factory.add(:wiki, Wiki) do |obj|
78   - obj.title = Faker::Lorem.sentence
79   - obj.content = Faker::Lorem.sentence
80   - obj.user = Factory(:user)
81   - obj.project = Factory(:project)
82   -end
83   -
84   -Factory.add(:event, Event) do |obj|
85   - obj.title = Faker::Lorem.sentence
86   - obj.project = Factory(:project)
87   -end
88   -
89   -Factory.add(:milestone, Milestone) do |obj|
90   - obj.title = Faker::Lorem.sentence
91   - obj.due_date = Date.today + 1.month
92   -end
93   -
94   -Factory.add(:users_project, UsersProject) do |obj|
95   - obj.user = Factory :user
96   - obj.project = Factory :project
  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 do
  79 + """
  80 + AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4
  81 + 596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4
  82 + soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=
  83 + """
  84 + end
  85 +
  86 + factory :deploy_key do
  87 + project
  88 + end
  89 +
  90 + factory :personal_key do
  91 + user
  92 + end
  93 + end
  94 +
  95 + factory :milestone do
  96 + title
  97 + project
  98 + end
  99 +
  100 + factory :system_hook do
  101 + url
  102 + end
  103 +
  104 + factory :project_hook do
  105 + url
  106 + end
  107 +
  108 + factory :wiki do
  109 + title
  110 + content
  111 + user
  112 + end
  113 +
  114 + factory :snippet do
  115 + project
  116 + author
  117 + title
  118 + content
  119 + file_name { Faker::Lorem.sentence }
  120 + end
97 121 end
... ...
spec/factories_spec.rb 0 → 100644
... ... @@ -0,0 +1,91 @@
  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 +
  53 + it "builds a valid deploy key instance" do
  54 + build(:deploy_key).should be_valid
  55 + end
  56 +
  57 + it "builds a valid personal key instance" do
  58 + build(:personal_key).should be_valid
  59 + end
  60 + end
  61 +
  62 + describe 'Milestone' do
  63 + it "builds a valid instance" do
  64 + build(:milestone).should be_valid
  65 + end
  66 + end
  67 +
  68 + describe 'SystemHook' do
  69 + it "builds a valid instance" do
  70 + build(:system_hook).should be_valid
  71 + end
  72 + end
  73 +
  74 + describe 'ProjectHook' do
  75 + it "builds a valid instance" do
  76 + build(:project_hook).should be_valid
  77 + end
  78 + end
  79 +
  80 + describe 'Wiki' do
  81 + it "builds a valid instance" do
  82 + build(:wiki).should be_valid
  83 + end
  84 + end
  85 +
  86 + describe 'Snippet' do
  87 + it "builds a valid instance" do
  88 + build(:snippet).should be_valid
  89 + end
  90 + end
  91 +end
... ...
spec/factory.rb
... ... @@ -1,29 +0,0 @@
1   -class Factory
2   - @factories = {}
3   -
4   - class << self
5   - def add(name, klass, &block)
6   - @factories[name] = [klass, block]
7   - end
8   -
9   - def create(name, opts = {})
10   - new(name, opts).tap(&:save!)
11   - end
12   -
13   - def new(name, opts = {})
14   - factory= @factories[name]
15   - factory[0].new.tap do |obj|
16   - factory[1].call(obj)
17   - end.tap do |obj|
18   - opts.each do |k, opt|
19   - obj.send("#{k}=", opt)
20   - end
21   - end
22   - end
23   - end
24   -end
25   -
26   -def Factory(name, opts={})
27   - Factory.create name, opts
28   -end
29   -
spec/helpers/gitlab_flavored_markdown_spec.rb
... ... @@ -2,7 +2,7 @@ require &quot;spec_helper&quot;
2 2  
3 3 describe GitlabMarkdownHelper do
4 4 before do
5   - @project = Project.find_by_path("gitlabhq") || Factory(:project)
  5 + @project = Factory(:project)
6 6 @commit = @project.repo.commits.first.parents.first
7 7 @commit = CommitDecorator.decorate(Commit.new(@commit))
8 8 @other_project = Factory :project, path: "OtherPath", code: "OtherCode"
... ... @@ -157,7 +157,7 @@ describe GitlabMarkdownHelper do
157 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 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 161 gfm("_Please_ *stop* 'helping' and all the other b*$#%' you do.").should == "_Please_ *stop* 'helping' and all the other b*$#%' you do."
162 162 end
163 163  
... ...
spec/models/issue_spec.rb
... ... @@ -19,11 +19,7 @@ describe Issue do
19 19 it { Issue.should respond_to :opened }
20 20 end
21 21  
22   - subject { Factory.create(:issue,
23   - author: Factory(:user),
24   - assignee: Factory(:user),
25   - project: Factory.create(:project)) }
26   - it { should be_valid }
  22 + subject { Factory.create(:issue) }
27 23  
28 24 describe '#is_being_reassigned?' do
29 25 it 'returns true if the issue assignee has changed' do
... ... @@ -41,11 +37,7 @@ describe Issue do
41 37 subject.is_being_closed?.should be_true
42 38 end
43 39 it 'returns false if the closed attribute has changed and is now false' do
44   - issue = Factory.create(:issue,
45   - closed: true,
46   - author: Factory(:user),
47   - assignee: Factory(:user),
48   - project: Factory.create(:project))
  40 + issue = Factory.create(:closed_issue)
49 41 issue.closed = false
50 42 issue.is_being_closed?.should be_false
51 43 end
... ... @@ -57,11 +49,7 @@ describe Issue do
57 49  
58 50 describe '#is_being_reopened?' do
59 51 it 'returns true if the closed attribute has changed and is now false' do
60   - issue = Factory.create(:issue,
61   - closed: true,
62   - author: Factory(:user),
63   - assignee: Factory(:user),
64   - project: Factory.create(:project))
  52 + issue = Factory.create(:closed_issue)
65 53 issue.closed = false
66 54 issue.is_being_reopened?.should be_true
67 55 end
... ... @@ -75,40 +63,33 @@ describe Issue do
75 63 end
76 64  
77 65 describe "plus 1" do
78   - let(:project) { Factory(:project) }
79   - subject {
80   - Factory.create(:issue,
81   - author: Factory(:user),
82   - assignee: Factory(:user),
83   - project: project)
84   - }
  66 + subject { Factory.create(:issue) }
85 67  
86 68 it "with no notes has a 0/0 score" do
87 69 subject.upvotes.should == 0
88 70 end
89 71  
90 72 it "should recognize non-+1 notes" do
91   - subject.notes << Factory(:note, note: "No +1 here", project: Factory(:project, path: 'plusone', code: 'plusone'))
  73 + subject.notes << Factory(:note, note: "No +1 here")
92 74 subject.should have(1).note
93 75 subject.notes.first.upvote?.should be_false
94 76 subject.upvotes.should == 0
95 77 end
96 78  
97 79 it "should recognize a single +1 note" do
98   - subject.notes << Factory(:note, note: "+1 This is awesome", project: Factory(:project, path: 'plusone', code: 'plusone'))
  80 + subject.notes << Factory(:note, note: "+1 This is awesome")
99 81 subject.upvotes.should == 1
100 82 end
101 83  
102 84 it "should recognize a multiple +1 notes" do
103   - subject.notes << Factory(:note, note: "+1 This is awesome", project: Factory(:project, path: 'plusone', code: 'plusone'))
104   - subject.notes << Factory(:note, note: "+1 I want this", project: Factory(:project, path: 'plustwo', code: 'plustwo'))
  85 + subject.notes << Factory(:note, note: "+1 This is awesome")
  86 + subject.notes << Factory(:note, note: "+1 I want this")
105 87 subject.upvotes.should == 2
106 88 end
107 89 end
108 90  
109 91 describe ".search" do
110   - let!(:issue) { Factory.create(:issue, title: "Searchable issue",
111   - project: Factory.create(:project)) }
  92 + let!(:issue) { Factory.create(:issue, title: "Searchable issue") }
112 93  
113 94 it "matches by title" do
114 95 Issue.search('able').all.should == [issue]
... ...
spec/models/key_spec.rb
... ... @@ -17,20 +17,15 @@ describe Key do
17 17 context "validation of uniqueness" do
18 18  
19 19 context "as a deploy key" do
20   - let(:project) { Factory.create(:project, path: 'alpha', code: 'alpha') }
21   - let(:another_project) { Factory.create(:project, path: 'beta', code: 'beta') }
22   -
23   - before do
24   - deploy_key = Factory.create(:key, project: project)
25   - end
  20 + let!(:deploy_key) { create(:deploy_key) }
26 21  
27 22 it "does not accept the same key twice for a project" do
28   - key = Factory.new(:key, project: project)
  23 + key = build(:key, project: deploy_key.project)
29 24 key.should_not be_valid
30 25 end
31 26  
32 27 it "does accept the same key for another project" do
33   - key = Factory.new(:key, project: another_project)
  28 + key = build(:key, project_id: 0)
34 29 key.should be_valid
35 30 end
36 31 end
... ... @@ -39,12 +34,12 @@ describe Key do
39 34 let(:user) { Factory.create(:user) }
40 35  
41 36 it "accepts the key once" do
42   - Factory.new(:key, user: user).should be_valid
  37 + build(:key, user: user).should be_valid
43 38 end
44 39  
45 40 it "does not accepts the key twice" do
46   - Factory.create(:key, user: user)
47   - Factory.new(:key, user: user).should_not be_valid
  41 + create(:key, user: user)
  42 + build(:key, user: user).should_not be_valid
48 43 end
49 44 end
50 45 end
... ...
spec/models/merge_request_spec.rb
... ... @@ -20,46 +20,34 @@ describe MergeRequest do
20 20 it { MergeRequest.should respond_to :opened }
21 21 end
22 22  
23   - it { Factory.create(:merge_request,
24   - author: Factory(:user),
25   - assignee: Factory(:user),
26   - project: Factory.create(:project)).should be_valid }
27   -
28 23 describe "plus 1" do
29   - let(:project) { Factory(:project) }
30   - subject {
31   - Factory.create(:merge_request,
32   - author: Factory(:user),
33   - assignee: Factory(:user),
34   - project: project)
35   - }
  24 + subject { Factory.create(:merge_request) }
36 25  
37 26 it "with no notes has a 0/0 score" do
38 27 subject.upvotes.should == 0
39 28 end
40 29  
41 30 it "should recognize non-+1 notes" do
42   - subject.notes << Factory(:note, note: "No +1 here", project: Factory(:project, path: 'plusone', code: 'plusone'))
  31 + subject.notes << Factory(:note, note: "No +1 here")
43 32 subject.should have(1).note
44 33 subject.notes.first.upvote?.should be_false
45 34 subject.upvotes.should == 0
46 35 end
47 36  
48 37 it "should recognize a single +1 note" do
49   - subject.notes << Factory(:note, note: "+1 This is awesome", project: Factory(:project, path: 'plusone', code: 'plusone'))
  38 + subject.notes << Factory(:note, note: "+1 This is awesome")
50 39 subject.upvotes.should == 1
51 40 end
52 41  
53 42 it "should recognize a multiple +1 notes" do
54   - subject.notes << Factory(:note, note: "+1 This is awesome", project: Factory(:project, path: 'plusone', code: 'plusone'))
55   - subject.notes << Factory(:note, note: "+1 I want this", project: Factory(:project, path: 'plustwo', code: 'plustwo'))
  43 + subject.notes << Factory(:note, note: "+1 This is awesome")
  44 + subject.notes << Factory(:note, note: "+1 I want this")
56 45 subject.upvotes.should == 2
57 46 end
58 47 end
59 48  
60 49 describe ".search" do
61   - let!(:issue) { Factory.create(:issue, title: "Searchable issue",
62   - project: Factory.create(:project)) }
  50 + let!(:issue) { Factory.create(:issue, title: "Searchable issue") }
63 51  
64 52 it "matches by title" do
65 53 Issue.search('able').all.should == [issue]
... ...
spec/models/milestone_spec.rb
... ... @@ -25,11 +25,8 @@ describe Milestone do
25 25 it { should validate_presence_of(:project_id) }
26 26 end
27 27  
28   - let(:project) { Factory :project }
29   - let(:milestone) { Factory :milestone, project: project }
30   - let(:issue) { Factory :issue, project: project }
31   -
32   - it { milestone.should be_valid }
  28 + let(:milestone) { Factory :milestone }
  29 + let(:issue) { Factory :issue }
33 30  
34 31 describe "#percent_complete" do
35 32 it "should not count open issues" do
... ...
spec/models/note_spec.rb
1 1 require 'spec_helper'
2 2  
3 3 describe Note do
4   - let(:project) { Factory :project }
5   - let!(:commit) { project.commit }
6   -
7 4 describe "Associations" do
8 5 it { should belong_to(:project) }
9 6 end
... ... @@ -13,8 +10,6 @@ describe Note do
13 10 it { should validate_presence_of(:project) }
14 11 end
15 12  
16   - it { Factory.create(:note,
17   - project: project).should be_valid }
18 13 describe "Scopes" do
19 14 it "should have a today named scope that returns ..." do
20 15 Note.today.where_values.should == ["created_at >= '#{Date.today}'"]
... ... @@ -25,26 +20,27 @@ describe Note do
25 20 let(:project) { Factory(:project) }
26 21  
27 22 it "recognizes a neutral note" do
28   - note = Factory(:note, project: project, note: "This is not a +1 note")
  23 + note = Factory(:note, note: "This is not a +1 note")
29 24 note.should_not be_upvote
30 25 end
31 26  
32 27 it "recognizes a +1 note" do
33   - note = Factory(:note, project: project, note: "+1 for this")
  28 + note = Factory(:note, note: "+1 for this")
34 29 note.should be_upvote
35 30 end
36 31  
37 32 it "recognizes a -1 note as no vote" do
38   - note = Factory(:note, project: project, note: "-1 for this")
  33 + note = Factory(:note, note: "-1 for this")
39 34 note.should_not be_upvote
40 35 end
41 36 end
42 37  
43   - describe "Commit notes" do
  38 + let(:project) { create(:project) }
  39 + let(:commit) { project.commit }
44 40  
  41 + describe "Commit notes" do
45 42 before do
46 43 @note = Factory :note,
47   - project: project,
48 44 noteable_id: commit.id,
49 45 noteable_type: "Commit"
50 46 end
... ... @@ -58,7 +54,6 @@ describe Note do
58 54 describe "Pre-line commit notes" do
59 55 before do
60 56 @note = Factory :note,
61   - project: project,
62 57 noteable_id: commit.id,
63 58 noteable_type: "Commit",
64 59 line_code: "0_16_1"
... ... @@ -91,8 +86,8 @@ describe Note do
91 86  
92 87 describe :authorization do
93 88 before do
94   - @p1 = project
95   - @p2 = Factory :project, code: "alien", path: "gitlabhq_1"
  89 + @p1 = create(:project)
  90 + @p2 = Factory :project
96 91 @u1 = Factory :user
97 92 @u2 = Factory :user
98 93 @u3 = Factory :user
... ...
spec/models/project_spec.rb
... ... @@ -85,7 +85,7 @@ describe Project do
85 85  
86 86 it "should return path to repo" do
87 87 project = Project.new(path: "somewhere")
88   - project.path_to_repo.should == File.join(Rails.root, "tmp", "tests", "somewhere")
  88 + project.path_to_repo.should == File.join(Rails.root, "tmp", "repositories", "somewhere")
89 89 end
90 90  
91 91 it "returns the full web URL for this repo" do
... ...
spec/models/system_hook_spec.rb
... ... @@ -10,13 +10,12 @@ describe SystemHook do
10 10 end
11 11  
12 12 it "project_create hook" do
13   - user = Factory :user
14 13 with_resque do
15   - project = Factory :project_without_owner, owner: user
  14 + project = Factory :project
16 15 end
17 16 WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once
18 17 end
19   -
  18 +
20 19 it "project_destroy hook" do
21 20 project = Factory :project
22 21 with_resque do
... ... @@ -31,7 +30,7 @@ describe SystemHook do
31 30 end
32 31 WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once
33 32 end
34   -
  33 +
35 34 it "user_destroy hook" do
36 35 user = Factory :user
37 36 with_resque do
... ... @@ -39,7 +38,7 @@ describe SystemHook do
39 38 end
40 39 WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once
41 40 end
42   -
  41 +
43 42 it "project_create hook" do
44 43 user = Factory :user
45 44 project = Factory :project
... ... @@ -48,7 +47,7 @@ describe SystemHook do
48 47 end
49 48 WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
50 49 end
51   -
  50 +
52 51 it "project_destroy hook" do
53 52 user = Factory :user
54 53 project = Factory :project
... ...
spec/models/user_spec.rb
... ... @@ -3,11 +3,12 @@ require &#39;spec_helper&#39;
3 3 describe User do
4 4 describe "Associations" do
5 5 it { should have_many(:projects) }
6   - it { should have_many(:users_projects) }
7   - it { should have_many(:issues) }
8   - it { should have_many(:assigned_issues) }
9   - it { should have_many(:merge_requests) }
10   - it { should have_many(:assigned_merge_requests) }
  6 + it { should have_many(:users_projects).dependent(:destroy) }
  7 + it { should have_many(:issues).dependent(:destroy) }
  8 + it { should have_many(:assigned_issues).dependent(:destroy) }
  9 + it { should have_many(:merge_requests).dependent(:destroy) }
  10 + it { should have_many(:assigned_merge_requests).dependent(:destroy) }
  11 + it { should have_many(:notes).dependent(:destroy) }
11 12 end
12 13  
13 14 describe "Respond to" do
... ... @@ -49,21 +50,6 @@ describe User do
49 50 user = Factory(:user)
50 51 user.authentication_token.should_not == ""
51 52 end
52   -
53   - describe "dependent" do
54   - before do
55   - @user = Factory :user
56   - @note = Factory :note,
57   - author: @user,
58   - project: Factory(:project)
59   - end
60   -
61   - it "should destroy all notes with user" do
62   - Note.find_by_id(@note.id).should_not be_nil
63   - @user.destroy
64   - Note.find_by_id(@note.id).should be_nil
65   - end
66   - end
67 53 end
68 54 # == Schema Information
69 55 #
... ...
spec/requests/admin/admin_projects_spec.rb
... ... @@ -87,7 +87,7 @@ describe &quot;Admin::Projects&quot; do
87 87 visit new_admin_project_path
88 88 fill_in 'project_name', with: 'NewProject'
89 89 fill_in 'project_code', with: 'NPR'
90   - fill_in 'project_path', with: 'gitlabhq_1'
  90 + fill_in 'project_path', with: 'newproject'
91 91 expect { click_button "Create project" }.to change { Project.count }.by(1)
92 92 @project = Project.last
93 93 end
... ...
spec/requests/atom/dashboard_issues_spec.rb
... ... @@ -6,13 +6,9 @@ describe &quot;User Issues Dashboard&quot; do
6 6  
7 7 login_as :user
8 8  
9   - @project1 = Factory :project,
10   - path: "gitlabhq_0",
11   - code: "TEST1"
  9 + @project1 = Factory :project
12 10  
13   - @project2 = Factory :project,
14   - path: "gitlabhq_1",
15   - code: "TEST2"
  11 + @project2 = Factory :project
16 12  
17 13 @project1.add_access(@user, :read, :write)
18 14 @project2.add_access(@user, :read, :write)
... ...
spec/spec_helper.rb
... ... @@ -10,7 +10,6 @@ require &#39;rspec/rails&#39;
10 10 require 'capybara/rails'
11 11 require 'capybara/rspec'
12 12 require 'webmock/rspec'
13   -require 'factories'
14 13 require 'email_spec'
15 14 require 'headless'
16 15  
... ... @@ -28,6 +27,7 @@ RSpec.configure do |config|
28 27  
29 28 config.include LoginHelpers, type: :request
30 29 config.include GitoliteStub
  30 + config.include FactoryGirl::Syntax::Methods
31 31  
32 32 # If you're not using ActiveRecord, or you'd prefer not to run each of your
33 33 # examples within a transaction, remove the following line or assign false
... ...
spec/support/monkeypatch.rb
... ... @@ -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
spec/support/stubbed_repository.rb 0 → 100644
... ... @@ -0,0 +1,31 @@
  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 + def path_to_repo
  5 + if new_record? || path == 'newproject'
  6 + # There are a couple Project specs and features that expect the Project's
  7 + # path to be in the returned path, so let's patronize them.
  8 + File.join(Rails.root, 'tmp', 'repositories', path)
  9 + else
  10 + # For everything else, just give it the path to one of our real seeded
  11 + # repos.
  12 + File.join(Rails.root, 'tmp', 'repositories', 'gitlabhq')
  13 + end
  14 + end
  15 +
  16 + def satellite
  17 + FakeSatellite.new
  18 + end
  19 +
  20 + class FakeSatellite
  21 + def exists?
  22 + true
  23 + end
  24 +
  25 + def create
  26 + true
  27 + end
  28 + end
  29 +end
  30 +
  31 +Project.send(:include, StubbedRepository)
... ...