diff options
author | Rémy Coutable <remy@rymai.me> | 2017-08-04 19:14:04 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-09-06 13:20:11 +0200 |
commit | 2ce686b5cfd8d252c569515a6827fcda53289f86 (patch) | |
tree | 3553cbed7a4a49b134617fb17a4ab540bf6313fb | |
parent | d1b60cbc67dc14b21820ef3f823a8e1ea851697d (diff) | |
download | gitlab-ce-36009-user-default-project-creator-in-factories.tar.gz |
Experiment to make user/author use project.creator in factories36009-user-default-project-creator-in-factories
Signed-off-by: Rémy Coutable <remy@rymai.me>
-rw-r--r-- | spec/factories/commits.rb | 2 | ||||
-rw-r--r-- | spec/factories/deployments.rb | 3 | ||||
-rw-r--r-- | spec/factories/events.rb | 2 | ||||
-rw-r--r-- | spec/factories/issues.rb | 2 | ||||
-rw-r--r-- | spec/factories/merge_requests.rb | 2 | ||||
-rw-r--r-- | spec/factories/notes.rb | 2 | ||||
-rw-r--r-- | spec/factories/notification_settings.rb | 2 | ||||
-rw-r--r-- | spec/factories/project_wikis.rb | 2 | ||||
-rw-r--r-- | spec/factories/sent_notifications.rb | 2 | ||||
-rw-r--r-- | spec/factories/snippets.rb | 1 | ||||
-rw-r--r-- | spec/factories/subscriptions.rb | 2 | ||||
-rw-r--r-- | spec/factories/timelogs.rb | 2 | ||||
-rw-r--r-- | spec/factories/todos.rb | 4 | ||||
-rw-r--r-- | spec/models/abuse_report_spec.rb | 8 |
14 files changed, 21 insertions, 15 deletions
diff --git a/spec/factories/commits.rb b/spec/factories/commits.rb index f4f12a095fc..2afc1f029aa 100644 --- a/spec/factories/commits.rb +++ b/spec/factories/commits.rb @@ -10,7 +10,7 @@ FactoryGirl.define do end after(:build) do |commit| - allow(commit).to receive(:author).and_return build(:author) + allow(commit).to receive(:author).and_return build_stubbed(:author) end trait :without_author do diff --git a/spec/factories/deployments.rb b/spec/factories/deployments.rb index e5abfd67d60..c65c904a7d8 100644 --- a/spec/factories/deployments.rb +++ b/spec/factories/deployments.rb @@ -3,13 +3,14 @@ FactoryGirl.define do sha '97de212e80737a608d939f648d959671fb0a0142' ref 'master' tag false - user + user nil project nil deployable factory: :ci_build environment factory: :environment after(:build) do |deployment, evaluator| deployment.project ||= deployment.environment.project + deployment.user ||= deployment.project.creator unless deployment.project.repository_exists? allow(deployment.project.repository).to receive(:fetch_ref) diff --git a/spec/factories/events.rb b/spec/factories/events.rb index ad9f7e2caef..9579271b560 100644 --- a/spec/factories/events.rb +++ b/spec/factories/events.rb @@ -1,7 +1,7 @@ FactoryGirl.define do factory :event do project - author factory: :user + author(factory: :user) { project.creator } action Event::JOINED trait(:created) { action Event::CREATED } diff --git a/spec/factories/issues.rb b/spec/factories/issues.rb index 7c3b80198f9..44a19b1d4da 100644 --- a/spec/factories/issues.rb +++ b/spec/factories/issues.rb @@ -1,8 +1,8 @@ FactoryGirl.define do factory :issue do title { generate(:title) } - author project + author { project.creator } trait :confidential do confidential true diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb index cbec716d6ea..56b4c22db90 100644 --- a/spec/factories/merge_requests.rb +++ b/spec/factories/merge_requests.rb @@ -1,9 +1,9 @@ FactoryGirl.define do factory :merge_request do title { generate(:title) } - author association :source_project, :repository, factory: :project target_project { source_project } + author { source_project.creator } # $ git log --pretty=oneline feature..master # 5937ac0a7beb003549fc5fd26fc247adbce4a52e Add submodule from gitlab.com diff --git a/spec/factories/notes.rb b/spec/factories/notes.rb index f0d05504b7e..46d6d2384a3 100644 --- a/spec/factories/notes.rb +++ b/spec/factories/notes.rb @@ -6,7 +6,7 @@ FactoryGirl.define do factory :note do project note { generate(:title) } - author + author { project.creator } on_issue factory :note_on_commit, traits: [:on_commit] diff --git a/spec/factories/notification_settings.rb b/spec/factories/notification_settings.rb index e9171528d86..dc864347ba2 100644 --- a/spec/factories/notification_settings.rb +++ b/spec/factories/notification_settings.rb @@ -1,7 +1,7 @@ FactoryGirl.define do factory :notification_setting do source factory: :project - user + user { source&.creator || source&.owner } level 3 end end diff --git a/spec/factories/project_wikis.rb b/spec/factories/project_wikis.rb index 38fcab7466d..e8c4e182654 100644 --- a/spec/factories/project_wikis.rb +++ b/spec/factories/project_wikis.rb @@ -3,7 +3,7 @@ FactoryGirl.define do skip_create project - user factory: :user + user { project.creator } initialize_with { new(project, user) } end end diff --git a/spec/factories/sent_notifications.rb b/spec/factories/sent_notifications.rb index c2febf5b438..90238ed15af 100644 --- a/spec/factories/sent_notifications.rb +++ b/spec/factories/sent_notifications.rb @@ -1,7 +1,7 @@ FactoryGirl.define do factory :sent_notification do project - recipient factory: :user + recipient { project.creator } noteable { create(:issue, project: project) } reply_key { SentNotification.reply_key } end diff --git a/spec/factories/snippets.rb b/spec/factories/snippets.rb index 075bccd7f94..f60d4dbd91b 100644 --- a/spec/factories/snippets.rb +++ b/spec/factories/snippets.rb @@ -21,6 +21,7 @@ FactoryGirl.define do factory :project_snippet, parent: :snippet, class: :ProjectSnippet do project + author { projet.creator } end factory :personal_snippet, parent: :snippet, class: :PersonalSnippet do diff --git a/spec/factories/subscriptions.rb b/spec/factories/subscriptions.rb index 1ae7fc9f384..bcccb85e497 100644 --- a/spec/factories/subscriptions.rb +++ b/spec/factories/subscriptions.rb @@ -1,7 +1,7 @@ FactoryGirl.define do factory :subscription do - user project + user { project.creator } subscribable factory: :issue end end diff --git a/spec/factories/timelogs.rb b/spec/factories/timelogs.rb index 6f1545418eb..ed38fbaa0d4 100644 --- a/spec/factories/timelogs.rb +++ b/spec/factories/timelogs.rb @@ -3,7 +3,7 @@ FactoryGirl.define do factory :timelog do time_spent 3600 - user issue + user { issue.project.creator } end end diff --git a/spec/factories/todos.rb b/spec/factories/todos.rb index 4975befbfe3..df9fa4d6593 100644 --- a/spec/factories/todos.rb +++ b/spec/factories/todos.rb @@ -1,8 +1,8 @@ FactoryGirl.define do factory :todo do project - author - user + author { project.creator } + user { project.creator } target factory: :issue action { Todo::ASSIGNED } diff --git a/spec/models/abuse_report_spec.rb b/spec/models/abuse_report_spec.rb index d4da30b1641..92dc33ceffd 100644 --- a/spec/models/abuse_report_spec.rb +++ b/spec/models/abuse_report_spec.rb @@ -1,12 +1,14 @@ require 'rails_helper' RSpec.describe AbuseReport do - subject { create(:abuse_report) } + subject { build_stubbed(:abuse_report) } let(:user) { create(:admin) } it { expect(subject).to be_valid } describe 'associations' do + subject { create(:abuse_report) } + it { is_expected.to belong_to(:reporter).class_name('User') } it { is_expected.to belong_to(:user) } @@ -19,10 +21,12 @@ RSpec.describe AbuseReport do it { is_expected.to validate_presence_of(:reporter) } it { is_expected.to validate_presence_of(:user) } it { is_expected.to validate_presence_of(:message) } - it { is_expected.to validate_uniqueness_of(:user_id).with_message('has already been reported') } + it { expect(create(:abuse_report)).to validate_uniqueness_of(:user_id).with_message('has already been reported') } end describe '#remove_user' do + subject { create(:abuse_report) } + it 'blocks the user' do expect { subject.remove_user(deleted_by: user) }.to change { subject.user.blocked? }.to(true) end |