Commit b43c864d authored by Andreas Brandl's avatar Andreas Brandl

Simplify specs a little

parent 7ccb3cf8
...@@ -8,29 +8,24 @@ describe Gitlab::BackgroundMigration::FixProjectsWithoutProjectFeature, :migrati ...@@ -8,29 +8,24 @@ describe Gitlab::BackgroundMigration::FixProjectsWithoutProjectFeature, :migrati
let(:project_features) { table(:project_features) } let(:project_features) { table(:project_features) }
let(:namespace) { namespaces.create(name: 'foo', path: 'foo') } let(:namespace) { namespaces.create(name: 'foo', path: 'foo') }
let!(:project) { projects.create!(namespace_id: namespace.id) }
let!(:projects_without_feature) do
[
projects.create!(namespace_id: namespace.id, visibility_level: 0),
projects.create!(namespace_id: namespace.id, visibility_level: 20)
]
end
let(:public_project_without_feature) { projects_without_feature.last } let!(:project) { projects.create!(namespace_id: namespace.id) }
let(:private_project_without_feature) { projects_without_feature.first } let(:private_project_without_feature) { projects.create!(namespace_id: namespace.id, visibility_level: 0) }
let(:public_project_without_feature) { projects.create!(namespace_id: namespace.id, visibility_level: 20) }
let!(:projects_without_feature) { [private_project_without_feature, public_project_without_feature] }
before do before do
project_features.create({ project_id: project.id, pages_access_level: 20 }) project_features.create({ project_id: project.id, pages_access_level: 20 })
end end
subject { described_class.new.perform(*project_range) } subject { described_class.new.perform(Project.minimum(:id), Project.maximum(:id)) }
def project_feature_records def project_feature_records
ActiveRecord::Base.connection.select_all('SELECT project_id FROM project_features ORDER BY project_id').map { |e| e['project_id'] } project_features.order(:project_id).pluck(:project_id)
end end
def project_range def features(project)
ActiveRecord::Base.connection.select_one('SELECT MIN(id), MAX(id) FROM projects').values project_features.find_by(project_id: project.id)&.attributes
end end
it 'creates a ProjectFeature for projects without it' do it 'creates a ProjectFeature for projects without it' do
...@@ -40,10 +35,7 @@ describe Gitlab::BackgroundMigration::FixProjectsWithoutProjectFeature, :migrati ...@@ -40,10 +35,7 @@ describe Gitlab::BackgroundMigration::FixProjectsWithoutProjectFeature, :migrati
it 'creates ProjectFeature records with default values for a public project' do it 'creates ProjectFeature records with default values for a public project' do
subject subject
project_id = public_project_without_feature.id expect(features(public_project_without_feature)).to include(
record = ActiveRecord::Base.connection.select_one("SELECT * FROM project_features WHERE id=#{project_id}")
expect(record.except('id', 'project_id', 'created_at', 'updated_at')).to eq(
{ {
"merge_requests_access_level" => 20, "merge_requests_access_level" => 20,
"issues_access_level" => 20, "issues_access_level" => 20,
...@@ -60,21 +52,7 @@ describe Gitlab::BackgroundMigration::FixProjectsWithoutProjectFeature, :migrati ...@@ -60,21 +52,7 @@ describe Gitlab::BackgroundMigration::FixProjectsWithoutProjectFeature, :migrati
it 'creates ProjectFeature records with default values for a private project' do it 'creates ProjectFeature records with default values for a private project' do
subject subject
project_id = private_project_without_feature.id expect(features(private_project_without_feature)).to include("pages_access_level" => 10)
record = ActiveRecord::Base.connection.select_one("SELECT * FROM project_features WHERE id=#{project_id}")
expect(record.except('id', 'project_id', 'created_at', 'updated_at')).to eq(
{
"merge_requests_access_level" => 20,
"issues_access_level" => 20,
"wiki_access_level" => 20,
"snippets_access_level" => 20,
"builds_access_level" => 20,
"repository_access_level" => 20,
"pages_access_level" => 10,
"forking_access_level" => 20
}
)
end end
context 'when access control to pages is forced' do context 'when access control to pages is forced' do
...@@ -85,29 +63,13 @@ describe Gitlab::BackgroundMigration::FixProjectsWithoutProjectFeature, :migrati ...@@ -85,29 +63,13 @@ describe Gitlab::BackgroundMigration::FixProjectsWithoutProjectFeature, :migrati
it 'creates ProjectFeature records with default values for a public project' do it 'creates ProjectFeature records with default values for a public project' do
subject subject
project_id = public_project_without_feature.id expect(features(public_project_without_feature)).to include("pages_access_level" => 10)
record = ActiveRecord::Base.connection.select_one("SELECT * FROM project_features WHERE id=#{project_id}")
expect(record.except('id', 'project_id', 'created_at', 'updated_at')).to eq(
{
"merge_requests_access_level" => 20,
"issues_access_level" => 20,
"wiki_access_level" => 20,
"snippets_access_level" => 20,
"builds_access_level" => 20,
"repository_access_level" => 20,
"pages_access_level" => 10,
"forking_access_level" => 20
}
)
end end
end end
it 'sets created_at/updated_at timestamps' do it 'sets created_at/updated_at timestamps' do
subject subject
offenders = ActiveRecord::Base.connection.select_all('SELECT 1 FROM project_features WHERE created_at IS NULL or updated_at IS NULL') expect(project_features.where('created_at IS NULL OR updated_at IS NULL')).to be_empty
expect(offenders).to be_empty
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment