diff options
author | Vincent Bonmalais <vb.kouno@gmail.com> | 2012-11-06 07:31:55 +0400 |
---|---|---|
committer | Vincent Bonmalais <vb.kouno@gmail.com> | 2012-11-13 15:27:45 +0400 |
commit | 80fb38de7abdfacbf5ad2e0150b934c1392721f0 (patch) | |
tree | 302ee55b21e8206ab44cef819a583803b9bb0c6f /spec | |
parent | d52f06f38013540a9798686aa37c4dad120c3d74 (diff) |
Remove backward compatibility of factories.
Diffstat (limited to 'spec')
42 files changed, 221 insertions, 239 deletions
diff --git a/spec/factories.rb b/spec/factories.rb index 0258f8920e9..7b2a2efab23 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -1,21 +1,3 @@ -# 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 - def self.attributes(type, *args) - FactoryGirl.attributes_for(type, *args) - end -end - FactoryGirl.define do sequence :sentence, aliases: [:title, :content] do Faker::Lorem.sentence diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index 874864a3894..b6b1769fc80 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -4,8 +4,8 @@ describe Notify do include EmailSpec::Helpers include EmailSpec::Matchers - let(:recipient) { Factory.create(:user, email: 'recipient@example.com') } - let(:project) { Factory.create(:project) } + let(:recipient) { create(:user, email: 'recipient@example.com') } + let(:project) { create(:project) } shared_examples 'a multiple recipients email' do it 'is sent to the given recipient' do @@ -15,7 +15,7 @@ describe Notify do describe 'for new users, the email' do let(:example_site_path) { root_path } - let(:new_user) { Factory.create(:user, email: 'newguy@example.com') } + let(:new_user) { create(:user, email: 'newguy@example.com') } subject { Notify.new_user_email(new_user.id, new_user.password) } @@ -42,8 +42,8 @@ describe Notify do context 'for a project' do describe 'items that are assignable, the email' do - let(:assignee) { Factory.create(:user, email: 'assignee@example.com') } - let(:previous_assignee) { Factory.create(:user, name: 'Previous Assignee') } + let(:assignee) { create(:user, email: 'assignee@example.com') } + let(:previous_assignee) { create(:user, name: 'Previous Assignee') } shared_examples 'an assignee email' do it 'is sent to the assignee' do @@ -52,7 +52,7 @@ describe Notify do end context 'for issues' do - let(:issue) { Factory.create(:issue, assignee: assignee, project: project ) } + let(:issue) { create(:issue, assignee: assignee, project: project ) } describe 'that are new' do subject { Notify.new_issue_email(issue.id) } @@ -93,10 +93,10 @@ describe Notify do end describe 'status changed' do - let(:current_user) { Factory.create :user, email: "current@email.com" } + let(:current_user) { create(:user, email: "current@email.com") } let(:status) { 'closed' } subject { Notify.issue_status_changed_email(recipient.id, issue.id, status, current_user) } - + it 'has the correct subject' do should have_subject /changed issue ##{issue.id} \| #{issue.title}/i end @@ -117,7 +117,7 @@ describe Notify do end context 'for merge requests' do - let(:merge_request) { Factory.create(:merge_request, assignee: assignee, project: project) } + let(:merge_request) { create(:merge_request, assignee: assignee, project: project) } describe 'that are new' do subject { Notify.new_merge_request_email(merge_request.id) } @@ -169,13 +169,13 @@ describe Notify do end describe 'project access changed' do - let(:project) { Factory.create(:project, - path: "Fuu", - code: "Fuu") } - let(:user) { Factory.create :user } - let(:users_project) { Factory.create(:users_project, - project: project, - user: user) } + let(:project) { create(:project, + path: "Fuu", + code: "Fuu") } + let(:user) { create(:user) } + let(:users_project) { create(:users_project, + project: project, + user: user) } subject { Notify.project_access_granted_email(users_project.id) } it 'has the correct subject' do should have_subject /access to project was granted/ @@ -189,8 +189,8 @@ describe Notify do end context 'items that are noteable, the email for a note' do - let(:note_author) { Factory.create(:user, name: 'author_name') } - let(:note) { Factory.create(:note, project: project, author: note_author) } + let(:note_author) { create(:user, name: 'author_name') } + let(:note) { create(:note, project: project, author: note_author) } before :each do Note.stub(:find).with(note.id).and_return(note) @@ -251,7 +251,7 @@ describe Notify do end describe 'on a merge request' do - let(:merge_request) { Factory.create(:merge_request, project: project) } + let(:merge_request) { create(:merge_request, project: project) } let(:note_on_merge_request_path) { project_merge_request_path(project, merge_request, anchor: "note_#{note.id}") } before(:each) { note.stub(:noteable).and_return(merge_request) } @@ -269,7 +269,7 @@ describe Notify do end describe 'on an issue' do - let(:issue) { Factory.create(:issue, project: project) } + let(:issue) { create(:issue, project: project) } let(:note_on_issue_path) { project_issue_path(project, issue, anchor: "note_#{note.id}") } before(:each) { note.stub(:noteable).and_return(issue) } diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index 77b49246c46..d68ebb8614b 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -32,7 +32,7 @@ describe Event do describe "Push event" do before do - project = Factory :project + project = create(:project) @user = project.owner data = { diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 7c98b9ea58d..4e999aad661 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -38,11 +38,11 @@ describe Issue do it { should include_module(Votes) } end - subject { Factory.create(:issue) } + subject { create(:issue) } describe '#is_being_reassigned?' do it 'returns true if the issue assignee has changed' do - subject.assignee = Factory(:user) + subject.assignee = create(:user) subject.is_being_reassigned?.should be_true end it 'returns false if the issue assignee has not changed' do @@ -56,7 +56,7 @@ describe Issue do subject.is_being_closed?.should be_true end it 'returns false if the closed attribute has changed and is now false' do - issue = Factory.create(:closed_issue) + issue = create(:closed_issue) issue.closed = false issue.is_being_closed?.should be_false end @@ -68,7 +68,7 @@ describe Issue do describe '#is_being_reopened?' do it 'returns true if the closed attribute has changed and is now false' do - issue = Factory.create(:closed_issue) + issue = create(:closed_issue) issue.closed = false issue.is_being_reopened?.should be_true end diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb index d3231af88bc..80dfff08397 100644 --- a/spec/models/key_spec.rb +++ b/spec/models/key_spec.rb @@ -53,7 +53,7 @@ describe Key do end context "as a personal key" do - let(:user) { Factory.create(:user) } + let(:user) { create(:user) } it "accepts the key once" do build(:key, user: user).should be_valid @@ -67,7 +67,7 @@ describe Key do end context "validate it is a fingerprintable key" do - let(:user) { Factory.create(:user) } + let(:user) { create(:user) } it "accepts the fingerprintable key" do build(:key, user: user).should be_valid diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index be40c561adb..3267f6f685f 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -37,12 +37,12 @@ describe MergeRequest do end describe "#mr_and_commit_notes" do - let!(:merge_request) { Factory.create(:merge_request) } + let!(:merge_request) { create(:merge_request) } before do merge_request.stub(:commits) { [merge_request.project.commit] } - Factory.create(:note, noteable: merge_request.commits.first) - Factory.create(:note, noteable: merge_request) + create(:note, noteable: merge_request.commits.first) + create(:note, noteable: merge_request) end it "should include notes for commits" do @@ -51,11 +51,11 @@ describe MergeRequest do end end - subject { Factory.create(:merge_request) } + subject { create(:merge_request) } describe '#is_being_reassigned?' do it 'returns true if the merge_request assignee has changed' do - subject.assignee = Factory(:user) + subject.assignee = create(:user) subject.is_being_reassigned?.should be_true end it 'returns false if the merge request assignee has not changed' do @@ -69,7 +69,7 @@ describe MergeRequest do subject.is_being_closed?.should be_true end it 'returns false if the closed attribute has changed and is now false' do - merge_request = Factory.create(:closed_merge_request) + merge_request = create(:closed_merge_request) merge_request.closed = false merge_request.is_being_closed?.should be_false end @@ -81,7 +81,7 @@ describe MergeRequest do describe '#is_being_reopened?' do it 'returns true if the closed attribute has changed and is now false' do - merge_request = Factory.create(:closed_merge_request) + merge_request = create(:closed_merge_request) merge_request.closed = false merge_request.is_being_reopened?.should be_true end diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb index 1aba20c651d..0e5cf7dd665 100644 --- a/spec/models/milestone_spec.rb +++ b/spec/models/milestone_spec.rb @@ -30,8 +30,8 @@ describe Milestone do it { should ensure_inclusion_of(:closed).in_array([true, false]) } end - let(:milestone) { Factory :milestone } - let(:issue) { Factory :issue } + let(:milestone) { create(:milestone) } + let(:issue) { create(:issue) } describe "#percent_complete" do it "should not count open issues" do diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 514b6202b74..d739053748f 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -40,10 +40,10 @@ describe Note do end describe "Voting score" do - let(:project) { Factory(:project) } + let(:project) { create(:project) } it "recognizes a neutral note" do - note = Factory(:note, note: "This is not a +1 note") + note = create(:note, note: "This is not a +1 note") note.should_not be_upvote note.should_not be_downvote end @@ -55,7 +55,7 @@ describe Note do end it "recognizes a +1 note" do - note = Factory(:note, note: "+1 for this") + note = create(:note, note: "+1 for this") note.should be_upvote end @@ -65,7 +65,7 @@ describe Note do end it "recognizes a -1 note" do - note = Factory(:note, note: "-1 for this") + note = create(:note, note: "-1 for this") note.should be_downvote end @@ -80,9 +80,9 @@ describe Note do describe "Commit notes" do before do - @note = Factory :note, - noteable_id: commit.id, - noteable_type: "Commit" + @note = create(:note, + noteable_id: commit.id, + noteable_type: "Commit") end it "should be accessible through #noteable" do @@ -103,10 +103,10 @@ describe Note do describe "Pre-line commit notes" do before do - @note = Factory :note, - noteable_id: commit.id, - noteable_type: "Commit", - line_code: "0_16_1" + @note = create(:note, + noteable_id: commit.id, + noteable_type: "Commit", + line_code: "0_16_1") end it "should save a valid note" do @@ -120,9 +120,9 @@ describe Note do end describe '#create_status_change_note' do - let(:project) { Factory.create(:project) } - let(:thing) { Factory.create(:issue, project: project) } - let(:author) { Factory(:user) } + let(:project) { create(:project) } + let(:thing) { create(:issue, project: project) } + let(:author) { create(:user) } let(:status) { 'new_status' } subject { Note.create_status_change_note(thing, author, status) } @@ -141,10 +141,10 @@ describe Note do describe :authorization do before do @p1 = create(:project) - @p2 = Factory :project - @u1 = Factory :user - @u2 = Factory :user - @u3 = Factory :user + @p2 = create(:project) + @u1 = create(:user) + @u2 = create(:user) + @u3 = create(:user) @abilities = Six.new @abilities << Ability end diff --git a/spec/models/project_hooks_spec.rb b/spec/models/project_hooks_spec.rb index 129e3d61030..ee441ec4ec5 100644 --- a/spec/models/project_hooks_spec.rb +++ b/spec/models/project_hooks_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper' describe Project, "Hooks" do - let(:project) { Factory :project } - before do - @key = Factory :key, user: project.owner + let(:project) { create(:project) } + before do + @key = create(:key, user: project.owner) @user = @key.user @key_id = @key.identifier end - describe "Post Receive Event" do - it "should create push event" do + describe "Post Receive Event" do + it "should create push event" do oldrev, newrev, ref = '00000000000000000000000000000000', 'newrev', 'refs/heads/master' project.observe_push(oldrev, newrev, ref, @user) event = Event.last @@ -32,8 +32,8 @@ describe Project, "Hooks" do context "with web hooks" do before do - @project_hook = Factory(:project_hook) - @project_hook_2 = Factory(:project_hook) + @project_hook = create(:project_hook) + @project_hook_2 = create(:project_hook) project.hooks << [@project_hook, @project_hook_2] end @@ -47,7 +47,7 @@ describe Project, "Hooks" do context "does not execute web hooks" do before do - @project_hook = Factory(:project_hook) + @project_hook = create(:project_hook) project.hooks << [@project_hook] end diff --git a/spec/models/project_security_spec.rb b/spec/models/project_security_spec.rb index baf6d4b68ea..60f8d45c9c8 100644 --- a/spec/models/project_security_spec.rb +++ b/spec/models/project_security_spec.rb @@ -3,9 +3,9 @@ require 'spec_helper' describe Project do describe :authorization do before do - @p1 = Factory :project - @u1 = Factory :user - @u2 = Factory :user + @p1 = create(:project) + @u1 = create(:user) + @u2 = create(:user) @abilities = Six.new @abilities << Ability end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 6fe46446262..1cf4f586192 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -157,7 +157,7 @@ describe Project do describe :valid_repo? do it "should be valid repo" do - project = Factory :project + project = create(:project) project.valid_repo?.should be_true end @@ -168,7 +168,7 @@ describe Project do end describe "last_activity methods" do - let(:project) { Factory :project } + let(:project) { create(:project) } let(:last_event) { double(created_at: Time.now) } describe "last_activity" do @@ -191,7 +191,7 @@ describe Project do end describe "fresh commits" do - let(:project) { Factory :project } + let(:project) { create(:project) } it { project.fresh_commits(3).count.should == 3 } it { project.fresh_commits.first.id.should == "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a" } @@ -199,7 +199,7 @@ describe Project do end describe "commits_between" do - let(:project) { Factory :project } + let(:project) { create(:project) } subject do commits = project.commits_between("3a4b4fb4cde7809f033822a171b9feae19d41fff", @@ -213,7 +213,7 @@ describe Project do end describe "Git methods" do - let(:project) { Factory :project } + let(:project) { create(:project) } describe :repo do it "should return valid repo" do @@ -270,14 +270,14 @@ describe Project do end describe :update_merge_requests do - let(:project) { Factory :project } + let(:project) { create(:project) } before do - @merge_request = Factory :merge_request, - project: project, - merged: false, - closed: false - @key = Factory :key, user_id: project.owner.id + @merge_request = create(:merge_request, + project: project, + merged: false, + closed: false) + @key = create(:key, user_id: project.owner.id) end it "should close merge request if last commit from source branch was pushed to target branch" do diff --git a/spec/models/system_hook_spec.rb b/spec/models/system_hook_spec.rb index b5d338a8c55..5f9239119b0 100644 --- a/spec/models/system_hook_spec.rb +++ b/spec/models/system_hook_spec.rb @@ -17,19 +17,19 @@ describe SystemHook do before(:each) { ActiveRecord::Base.observers.enable(:all) } before(:each) do - @system_hook = Factory :system_hook + @system_hook = create(:system_hook) WebMock.stub_request(:post, @system_hook.url) end it "project_create hook" do with_resque do - project = Factory :project + project = create(:project) end WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once end it "project_destroy hook" do - project = Factory :project + project = create(:project) with_resque do project.destroy end @@ -38,13 +38,13 @@ describe SystemHook do it "user_create hook" do with_resque do - Factory :user + create(:user) end WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once end it "user_destroy hook" do - user = Factory :user + user = create(:user) with_resque do user.destroy end @@ -52,8 +52,8 @@ describe SystemHook do end it "project_create hook" do - user = Factory :user - project = Factory :project + user = create(:user) + project = create(:project) with_resque do project.users << user end @@ -61,8 +61,8 @@ describe SystemHook do end it "project_destroy hook" do - user = Factory :user - project = Factory :project + user = create(:user) + project = create(:project) project.users << user with_resque do project.users_projects.clear diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 5f41fb05ed1..b9654d7002c 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -108,7 +108,7 @@ describe User do describe 'authentication token' do it "should have authentication token" do - user = Factory(:user) + user = create(:user) user.authentication_token.should_not be_blank end end diff --git a/spec/models/web_hook_spec.rb b/spec/models/web_hook_spec.rb index d71fec811f0..8f8decb81c6 100644 --- a/spec/models/web_hook_spec.rb +++ b/spec/models/web_hook_spec.rb @@ -39,8 +39,8 @@ describe ProjectHook do describe "execute" do before(:each) do - @project_hook = Factory :project_hook - @project = Factory :project + @project_hook = create(:project_hook) + @project = create(:project) @project.hooks << [@project_hook] @data = { before: 'oldrev', after: 'newrev', ref: 'ref'} diff --git a/spec/observers/activity_observer_spec.rb b/spec/observers/activity_observer_spec.rb index 0db4a9985be..0eec41f44e9 100644 --- a/spec/observers/activity_observer_spec.rb +++ b/spec/observers/activity_observer_spec.rb @@ -1,17 +1,17 @@ require 'spec_helper' describe ActivityObserver do - let(:project) { Factory :project } + let(:project) { create(:project) } def self.it_should_be_valid_event it { @event.should_not be_nil } it { @event.project.should == project } end - describe "Merge Request created" do + describe "Merge Request created" do before do MergeRequest.observers.enable :activity_observer do - @merge_request = Factory :merge_request, project: project + @merge_request = create(:merge_request, project: project) @event = Event.last end end @@ -21,10 +21,10 @@ describe ActivityObserver do it { @event.target.should == @merge_request } end - describe "Issue created" do + describe "Issue created" do before do Issue.observers.enable :activity_observer do - @issue = Factory :issue, project: project + @issue = create(:issue, project: project) @event = Event.last end end @@ -34,10 +34,10 @@ describe ActivityObserver do it { @event.target.should == @issue } end - #describe "Issue commented" do - #before do - #@issue = Factory :issue, project: project - #@note = Factory :note, noteable: @issue, project: project + #describe "Issue commented" do + #before do + #@issue = create(:issue, project: project) + #@note = create(:note, noteable: @issue, project: project) #@event = Event.last #end diff --git a/spec/observers/issue_observer_spec.rb b/spec/observers/issue_observer_spec.rb index b5943f2c539..509c1d02b49 100644 --- a/spec/observers/issue_observer_spec.rb +++ b/spec/observers/issue_observer_spec.rb @@ -16,7 +16,7 @@ describe IssueObserver do subject.should_receive(:after_create) Issue.observers.enable :issue_observer do - Factory.create(:issue, project: Factory.create(:project)) + create(:issue, project: create(:project)) end end @@ -43,7 +43,7 @@ describe IssueObserver do end it 'is called when an issue is changed' do - changed = Factory.create(:issue, project: Factory.create(:project)) + changed = create(:issue, project: create(:project)) subject.should_receive(:after_update) Issue.observers.enable :issue_observer do diff --git a/spec/observers/merge_request_observer_spec.rb b/spec/observers/merge_request_observer_spec.rb index a9ba79271e3..6b15be96630 100644 --- a/spec/observers/merge_request_observer_spec.rb +++ b/spec/observers/merge_request_observer_spec.rb @@ -16,7 +16,7 @@ describe MergeRequestObserver do subject.should_receive(:after_create) MergeRequest.observers.enable :merge_request_observer do - Factory.create(:merge_request, project: Factory.create(:project)) + create(:merge_request, project: create(:project)) end end @@ -43,7 +43,7 @@ describe MergeRequestObserver do end it 'is called when a merge request is changed' do - changed = Factory.create(:merge_request, project: Factory.create(:project)) + changed = create(:merge_request, project: create(:project)) subject.should_receive(:after_update) MergeRequest.observers.enable :merge_request_observer do diff --git a/spec/observers/note_observer_spec.rb b/spec/observers/note_observer_spec.rb index 203a58a4950..7dfa9f772e9 100644 --- a/spec/observers/note_observer_spec.rb +++ b/spec/observers/note_observer_spec.rb @@ -13,7 +13,7 @@ describe NoteObserver do subject.should_receive :after_create Note.observers.enable :note_observer do - Factory.create(:note) + create(:note) end end diff --git a/spec/observers/user_observer_spec.rb b/spec/observers/user_observer_spec.rb index 0420a250c8a..08254f44026 100644 --- a/spec/observers/user_observer_spec.rb +++ b/spec/observers/user_observer_spec.rb @@ -4,7 +4,7 @@ describe UserObserver do subject { UserObserver.instance } it 'calls #after_create when new users are created' do - new_user = Factory.new(:user) + new_user = build(:user) subject.should_receive(:after_create).with(new_user) User.observers.enable :user_observer do diff --git a/spec/observers/users_project_observer_spec.rb b/spec/observers/users_project_observer_spec.rb index a8e0834bc99..cbe42248033 100644 --- a/spec/observers/users_project_observer_spec.rb +++ b/spec/observers/users_project_observer_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' describe UsersProjectObserver do - let(:user) { Factory.create :user } - let(:project) { Factory.create(:project, - code: "Fuu", - path: "Fuu" ) } - let(:users_project) { Factory.create(:users_project, - project: project, - user: user )} + let(:user) { create(:user) } + let(:project) { create(:project, + code: "Fuu", + path: "Fuu" ) } + let(:users_project) { create(:users_project, + project: project, + user: user )} subject { UsersProjectObserver.instance } describe "#after_commit" do diff --git a/spec/requests/admin/admin_hooks_spec.rb b/spec/requests/admin/admin_hooks_spec.rb index 2f026aabab8..3f35b2fd37d 100644 --- a/spec/requests/admin/admin_hooks_spec.rb +++ b/spec/requests/admin/admin_hooks_spec.rb @@ -2,12 +2,12 @@ require 'spec_helper' describe "Admin::Hooks" do before do - @project = Factory :project, - name: "LeGiT", - code: "LGT" + @project = create(:project, + name: "LeGiT", + code: "LGT") login_as :admin - @system_hook = Factory :system_hook + @system_hook = create(:system_hook) end diff --git a/spec/requests/admin/admin_projects_spec.rb b/spec/requests/admin/admin_projects_spec.rb index 61e66eec08b..43e39d7cbcd 100644 --- a/spec/requests/admin/admin_projects_spec.rb +++ b/spec/requests/admin/admin_projects_spec.rb @@ -2,9 +2,9 @@ require 'spec_helper' describe "Admin::Projects" do before do - @project = Factory :project, - name: "LeGiT", - code: "LGT" + @project = create(:project, + name: "LeGiT", + code: "LGT") login_as :admin end @@ -104,7 +104,7 @@ describe "Admin::Projects" do describe "Add new team member" do before do - @new_user = Factory :user + @new_user = create(:user) visit admin_project_path(@project) end diff --git a/spec/requests/admin/admin_users_spec.rb b/spec/requests/admin/admin_users_spec.rb index 68358bf0a0f..9f43f07a476 100644 --- a/spec/requests/admin/admin_users_spec.rb +++ b/spec/requests/admin/admin_users_spec.rb @@ -76,7 +76,7 @@ describe "Admin::Users" do describe "GET /admin/users/:id/edit" do before do - @simple_user = Factory :user + @simple_user = create(:user) visit admin_users_path click_link "edit_user_#{@simple_user.id}" end @@ -107,13 +107,13 @@ describe "Admin::Users" do end end - describe "Add new project" do - before do - @new_project = Factory :project + describe "Add new project" do + before do + @new_project = create(:project) visit admin_user_path(@user) end - it "should create new user" do + it "should create new user" do select @new_project.name, from: "project_ids" expect { click_button "Add" }.to change { UsersProject.count }.by(1) page.should have_content @new_project.name diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb index 442e9c730dc..6ea7e9b5579 100644 --- a/spec/requests/api/issues_spec.rb +++ b/spec/requests/api/issues_spec.rb @@ -3,9 +3,9 @@ require 'spec_helper' describe Gitlab::API do include ApiHelpers - let(:user) { Factory :user } - let!(:project) { Factory :project, owner: user } - let!(:issue) { Factory :issue, author: user, assignee: user, project: project } + let(:user) { create(:user) } + let!(:project) { create(:project, owner: user) } + let!(:issue) { create(:issue, author: user, assignee: user, project: project) } before { project.add_access(user, :read) } describe "GET /issues" do diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index e1c7949f70c..e83f24671ed 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -1,11 +1,11 @@ require "spec_helper" -describe Gitlab::API do +describe Gitlab::API do include ApiHelpers - - let(:user) { Factory :user } - let!(:project) { Factory :project, owner: user } - let!(:merge_request) { Factory :merge_request, author: user, assignee: user, project: project, title: "Test" } + + let(:user) { create(:user ) } + let!(:project) { create(:project, owner: user) } + let!(:merge_request) { create(:merge_request, author: user, assignee: user, project: project, title: "Test") } before { project.add_access(user, :read) } describe "GET /projects/:id/merge_requests" do @@ -39,7 +39,7 @@ describe Gitlab::API do post api("/projects/#{project.code}/merge_requests", user), title: 'Test merge_request', source_branch: "stable", target_branch: "master", author: user response.status.should == 201 - json_response['title'].should == 'Test merge_request' + json_response['title'].should == 'Test merge_request' end end @@ -47,7 +47,7 @@ describe Gitlab::API do it "should return merge_request" do put api("/projects/#{project.code}/merge_request/#{merge_request.id}", user), title: "New title" response.status.should == 200 - json_response['title'].should == 'New title' + json_response['title'].should == 'New title' end end @@ -55,7 +55,7 @@ describe Gitlab::API do it "should return comment" do post api("/projects/#{project.code}/merge_request/#{merge_request.id}/comments", user), note: "My comment" response.status.should == 201 - json_response['note'].should == 'My comment' + json_response['note'].should == 'My comment' end end diff --git a/spec/requests/api/milestones_spec.rb b/spec/requests/api/milestones_spec.rb index cf5f65f068c..860825ab2db 100644 --- a/spec/requests/api/milestones_spec.rb +++ b/spec/requests/api/milestones_spec.rb @@ -3,9 +3,9 @@ require 'spec_helper' describe Gitlab::API do include ApiHelpers - let(:user) { Factory :user } - let!(:project) { Factory :project, owner: user } - let!(:milestone) { Factory :milestone, project: project } + let(:user) { create(:user) } + let!(:project) { create(:project, owner: user) } + let!(:milestone) { create(:milestone, project: project) } before { project.add_access(user, :read) } diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 5f9a587d57a..d24ce43d3f2 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -3,14 +3,14 @@ require 'spec_helper' describe Gitlab::API do include ApiHelpers - let(:user) { Factory :user } - let(:user2) { Factory.create(:user) } - let(:user3) { Factory.create(:user) } - let!(:hook) { Factory :project_hook, project: project, url: "http://example.com" } - let!(:project) { Factory :project, owner: user } - let!(:snippet) { Factory :snippet, author: user, project: project, title: 'example' } - let!(:users_project) { Factory :users_project, user: user, project: project, project_access: UsersProject::MASTER } - let!(:users_project2) { Factory :users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER } + let(:user) { create(:user) } + let(:user2) { create(:user) } + let(:user3) { create(:user) } + let!(:hook) { create(:project_hook, project: project, url: "http://example.com") } + let!(:project) { create(:project, owner: user ) } + let!(:snippet) { create(:snippet, author: user, project: project, title: 'example') } + let!(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) } + let!(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) } before { project.add_access(user, :read) } describe "GET /projects" do @@ -52,7 +52,7 @@ describe Gitlab::API do end it "should assign attributes to project" do - project = Factory.attributes(:project, { + project = attributes_for(:project, { path: 'path', code: 'code', description: Faker::Lorem.sentence, diff --git a/spec/requests/api/session_spec.rb b/spec/requests/api/session_spec.rb index f251f3921ac..afae8be8cbc 100644 --- a/spec/requests/api/session_spec.rb +++ b/spec/requests/api/session_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Gitlab::API do include ApiHelpers - let(:user) { Factory :user } + let(:user) { create(:user) } describe "POST /session" do context "when valid password" do diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index 4c2e6adaf7f..4cfb4884e7c 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -3,9 +3,9 @@ require 'spec_helper' describe Gitlab::API do include ApiHelpers - let(:user) { Factory :user } - let(:admin) { Factory :admin } - let(:key) { Factory :key, user: user } + let(:user) { create(:user) } + let(:admin) { create(:admin) } + let(:key) { create(:key, user: user) } describe "GET /users" do context "when unauthenticated" do @@ -43,12 +43,12 @@ describe Gitlab::API do it "should create user" do expect { - post api("/users", admin), Factory.attributes(:user, projects_limit: 3) + post api("/users", admin), attributes_for(:user, projects_limit: 3) }.to change { User.count }.by(1) end it "shouldn't available for non admin users" do - post api("/users", user), Factory.attributes(:user) + post api("/users", user), attributes_for(:user) response.status.should == 403 end end @@ -103,7 +103,7 @@ describe Gitlab::API do end it "should create ssh key" do - key_attrs = Factory.attributes :key + key_attrs = attributes_for :key expect { post api("/user/keys", user), key_attrs }.to change{ user.keys.count }.by(1) diff --git a/spec/requests/atom/dashboard_issues_spec.rb b/spec/requests/atom/dashboard_issues_spec.rb index 8d1111fc770..8ce64cd4c14 100644 --- a/spec/requests/atom/dashboard_issues_spec.rb +++ b/spec/requests/atom/dashboard_issues_spec.rb @@ -2,11 +2,11 @@ require 'spec_helper' describe "Dashboard Issues Feed" do describe "GET /issues" do - let!(:user) { Factory :user } - let!(:project1) { Factory :project } - let!(:project2) { Factory :project } - let!(:issue1) { Factory :issue, author: user, assignee: user, project: project1 } - let!(:issue2) { Factory :issue, author: user, assignee: user, project: project2 } + let!(:user) { create(:user) } + let!(:project1) { create(:project) } + let!(:project2) { create(:project) } + let!(:issue1) { create(:issue, author: user, assignee: user, project: project1) } + let!(:issue2) { create(:issue, author: user, assignee: user, project: project2) } describe "atom feed" do it "should render atom feed via private token" do diff --git a/spec/requests/atom/dashboard_spec.rb b/spec/requests/atom/dashboard_spec.rb index c160d24ac20..6257ad5c895 100644 --- a/spec/requests/atom/dashboard_spec.rb +++ b/spec/requests/atom/dashboard_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe "Dashboard Feed" do describe "GET /" do - let!(:user) { Factory :user } + let!(:user) { create(:user) } context "projects atom feed via private token" do it "should render projects atom feed" do diff --git a/spec/requests/atom/issues_spec.rb b/spec/requests/atom/issues_spec.rb index c8671979870..29f88f3f1c3 100644 --- a/spec/requests/atom/issues_spec.rb +++ b/spec/requests/atom/issues_spec.rb @@ -2,9 +2,9 @@ require 'spec_helper' describe "Issues Feed" do describe "GET /issues" do - let!(:user) { Factory :user } - let!(:project) { Factory :project, owner: user } - let!(:issue) { Factory :issue, author: user, project: project } + let!(:user) { create(:user) } + let!(:project) { create(:project, owner: user) } + let!(:issue) { create(:issue, author: user, project: project) } before { project.add_access(user, :read, :write) } diff --git a/spec/requests/gitlab_flavored_markdown_spec.rb b/spec/requests/gitlab_flavored_markdown_spec.rb index 014f99ebb0e..aedd435e617 100644 --- a/spec/requests/gitlab_flavored_markdown_spec.rb +++ b/spec/requests/gitlab_flavored_markdown_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' describe "Gitlab Flavored Markdown" do - let(:project) { Factory :project } - let(:issue) { Factory :issue, project: project } - let(:merge_request) { Factory :merge_request, project: project } + let(:project) { create(:project) } + let(:issue) { create(:issue, project: project) } + let(:merge_request) { create(:merge_request, project: project) } let(:fred) do - u = Factory :user, name: "fred" + u = create(:user, name: "fred") project.users << u u end @@ -84,16 +84,16 @@ describe "Gitlab Flavored Markdown" do describe "for issues" do before do - @other_issue = Factory :issue, + @other_issue = create(:issue, + author: @user, + assignee: @user, + project: project) + @issue = create(:issue, author: @user, assignee: @user, - project: project - @issue = Factory :issue, - author: @user, - assignee: @user, - project: project, - title: "fix ##{@other_issue.id}", - description: "ask @#{fred.name} for details" + project: project, + title: "fix ##{@other_issue.id}", + description: "ask @#{fred.name} for details") end it "should render subject in issues#index" do @@ -118,9 +118,9 @@ describe "Gitlab Flavored Markdown" do describe "for merge requests" do before do - @merge_request = Factory :merge_request, - project: project, - title: "fix ##{issue.id}" + @merge_request = create(:merge_request, + project: project, + title: "fix ##{issue.id}") end it "should render title in merge_requests#index" do @@ -139,10 +139,10 @@ describe "Gitlab Flavored Markdown" do describe "for milestones" do before do - @milestone = Factory :milestone, - project: project, - title: "fix ##{issue.id}", - description: "ask @#{fred.name} for details" + @milestone = create(:milestone, + project: project, + title: "fix ##{issue.id}", + description: "ask @#{fred.name} for details") end it "should render title in milestones#index" do diff --git a/spec/requests/issues_spec.rb b/spec/requests/issues_spec.rb index 15ee5d174a0..c95409d3a5f 100644 --- a/spec/requests/issues_spec.rb +++ b/spec/requests/issues_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' describe "Issues" do - let(:project) { Factory :project } + let(:project) { create(:project) } before do login_as :user - @user2 = Factory :user + @user2 = create(:user) project.add_access(@user, :read, :write) project.add_access(@user2, :read, :write) @@ -13,10 +13,10 @@ describe "Issues" do describe "Edit issue", js: true do before do - @issue = Factory :issue, - author: @user, - assignee: @user, - project: project + @issue = create(:issue, + author: @user, + assignee: @user, + project: project) visit project_issues_path(project) click_link "Edit" end @@ -46,11 +46,11 @@ describe "Issues" do describe "Search issue", js: true do before do ['foobar', 'foobar2', 'gitlab'].each do |title| - @issue = Factory :issue, - author: @user, - assignee: @user, - project: project, - title: title + @issue = create(:issue, + author: @user, + assignee: @user, + project: project, + title: title) @issue.save end end @@ -93,15 +93,15 @@ describe "Issues" do describe "Filter issue" do before do ['foobar', 'barbaz', 'gitlab'].each do |title| - @issue = Factory :issue, - author: @user, - assignee: @user, - project: project, - title: title + @issue = create(:issue, + author: @user, + assignee: @user, + project: project, + title: title) end @issue = Issue.first - @issue.milestone = Factory(:milestone, project: project) + @issue.milestone = create(:milestone, project: project) @issue.assignee = nil @issue.save end diff --git a/spec/requests/projects_deploy_keys_spec.rb b/spec/requests/projects_deploy_keys_spec.rb index df1be79d2f5..35323f556f9 100644 --- a/spec/requests/projects_deploy_keys_spec.rb +++ b/spec/requests/projects_deploy_keys_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe "Projects", "DeployKeys" do - let(:project) { Factory :project } + let(:project) { create(:project) } before do login_as :user @@ -10,7 +10,7 @@ describe "Projects", "DeployKeys" do describe "GET /keys" do before do - @key = Factory :key, project: project + @key = create(:key, project: project) visit project_deploy_keys_path(project) end @@ -57,7 +57,7 @@ describe "Projects", "DeployKeys" do describe "Show page" do before do - @key = Factory :key, project: project + @key = create(:key, project: project) visit project_deploy_key_path(project, @key) end diff --git a/spec/requests/projects_spec.rb b/spec/requests/projects_spec.rb index 92e89a162af..c44bea89f96 100644 --- a/spec/requests/projects_spec.rb +++ b/spec/requests/projects_spec.rb @@ -6,7 +6,7 @@ describe "Projects" do describe 'GET /project/new' do it "should work autocomplete", :js => true do visit new_project_path - + fill_in 'project_name', with: 'Awesome' find("#project_path").value.should == 'awesome' find("#project_code").value.should == 'awesome' @@ -15,7 +15,7 @@ describe "Projects" do describe "GET /projects/show" do before do - @project = Factory :project, owner: @user + @project = create(:project, owner: @user) @project.add_access(@user, :read) visit project_path(@project) @@ -28,7 +28,7 @@ describe "Projects" do describe "GET /projects/:id/edit" do before do - @project = Factory :project + @project = create(:project) @project.add_access(@user, :admin, :read) visit edit_project_path(@project) @@ -47,7 +47,7 @@ describe "Projects" do describe "PUT /projects/:id" do before do - @project = Factory :project, owner: @user + @project = create(:project, owner: @user) @project.add_access(@user, :admin, :read) visit edit_project_path(@project) @@ -69,7 +69,7 @@ describe "Projects" do describe "DELETE /projects/:id" do before do - @project = Factory :project + @project = create(:project) @project.add_access(@user, :read, :admin) visit edit_project_path(@project) end diff --git a/spec/requests/search_spec.rb b/spec/requests/search_spec.rb index 537c4d0c64c..17cc0d39946 100644 --- a/spec/requests/search_spec.rb +++ b/spec/requests/search_spec.rb @@ -3,14 +3,14 @@ require 'spec_helper' describe "Search" do before do login_as :user - @project = Factory :project + @project = create(:project) @project.add_access(@user, :read) visit search_path fill_in "search", with: @project.name[0..3] click_button "Search" end - it "should show project in search results" do + it "should show project in search results" do page.should have_content @project.name end end diff --git a/spec/requests/security/profile_access_spec.rb b/spec/requests/security/profile_access_spec.rb index 69c1c29cf12..8562b8e78af 100644 --- a/spec/requests/security/profile_access_spec.rb +++ b/spec/requests/security/profile_access_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe "Users Security" do describe "Project" do before do - @u1 = Factory :user + @u1 = create(:user) end describe "GET /login" do diff --git a/spec/requests/snippets_spec.rb b/spec/requests/snippets_spec.rb index 6b993660507..9ef217ba62c 100644 --- a/spec/requests/snippets_spec.rb +++ b/spec/requests/snippets_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe "Snippets" do - let(:project) { Factory :project } + let(:project) { create(:project) } before do login_as :user @@ -10,9 +10,9 @@ describe "Snippets" do describe "GET /snippets" do before do - @snippet = Factory :snippet, - author: @user, - project: project + @snippet = create(:snippet, + author: @user, + project: project) visit project_snippets_path(project) end @@ -68,9 +68,9 @@ describe "Snippets" do describe "Edit snippet" do before do - @snippet = Factory :snippet, - author: @user, - project: project + @snippet = create(:snippet, + author: @user, + project: project) visit project_snippet_path(project, @snippet) click_link "Edit" end diff --git a/spec/support/login_helpers.rb b/spec/support/login_helpers.rb index 769034e2286..4579c971d47 100644 --- a/spec/support/login_helpers.rb +++ b/spec/support/login_helpers.rb @@ -3,7 +3,7 @@ module LoginHelpers # # role - User role (e.g., :admin, :user) def login_as(role) - @user = Factory(role) + @user = create(role) login_with(@user) end diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index 809453c4a3b..29d16ecbac7 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -59,9 +59,9 @@ module UrlAccess def emulate_user(user) user = case user - when :user then Factory(:user) + when :user then create(:user) when :visitor then nil - when :admin then Factory(:admin) + when :admin then create(:admin) else user end login_with(user) if user diff --git a/spec/workers/post_receive_spec.rb b/spec/workers/post_receive_spec.rb index 6f4bcca2bf2..22e3e0d0fe5 100644 --- a/spec/workers/post_receive_spec.rb +++ b/spec/workers/post_receive_spec.rb @@ -9,8 +9,8 @@ describe PostReceive do end context "web hook" do - let(:project) { Factory.create(:project) } - let(:key) { Factory.create(:key, user: project.owner) } + let(:project) { create(:project) } + let(:key) { create(:key, user: project.owner) } let(:key_id) { key.identifier } it "fetches the correct project" do |