diff --git a/app/models/repository.rb b/app/models/repository.rb index a9d0922ba0..7ed9d6d880 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -23,7 +23,7 @@ class Repository < ApplicationRecord MEDIA_DIR = 'media'.freeze validates :name, presence: true, uniqueness: { case_sensitive: false } - validates :remote, presence: true + validates :remote, presence: true, uniqueness: { case_sensitive: false } validate :repo_is_accessible, on: :create diff --git a/db/migrate/20231107160330_add_unique_to_repository_remote.rb b/db/migrate/20231107160330_add_unique_to_repository_remote.rb new file mode 100644 index 0000000000..82c57dec43 --- /dev/null +++ b/db/migrate/20231107160330_add_unique_to_repository_remote.rb @@ -0,0 +1,5 @@ +class AddUniqueToRepositoryRemote < ActiveRecord::Migration[7.1] + def change + add_index :repositories, :remote, unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index c7a60a2e37..71cab76545 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2023_10_26_075353) do +ActiveRecord::Schema[7.1].define(version: 2023_11_07_160330) do create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false @@ -396,6 +396,7 @@ t.index ["judge_id"], name: "index_repositories_on_judge_id" t.index ["name"], name: "index_repositories_on_name", unique: true t.index ["path"], name: "index_repositories_on_path", unique: true + t.index ["remote"], name: "index_repositories_on_remote", unique: true end create_table "repository_admins", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| diff --git a/db/seeds.rb b/db/seeds.rb index 070f80080e..a1396cd274 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -276,6 +276,9 @@ def fill_series_with_realistic_submissions(s) puts activity_repo.errors.full_messages unless activity_repo.valid? activity_repo.process_activities + # remote must be unique for the repository, and we want to clone it again + activity_repo.update!(remote: '-') + big_activity_repo = Repository.create name: 'A lot of python activities', remote: 'git@github.com:dodona-edu/example-exercises.git', judge: python_judge, allowed_courses: courses Delayed::Worker.delay_jobs = true Dir.glob("#{big_activity_repo.full_path}/*") diff --git a/test/controllers/repositories_controller_test.rb b/test/controllers/repositories_controller_test.rb index 8c80b40ba1..0bc14179a7 100644 --- a/test/controllers/repositories_controller_test.rb +++ b/test/controllers/repositories_controller_test.rb @@ -200,6 +200,8 @@ class RepositoryGitControllerTest < ActionDispatch::IntegrationTest @remote.update_json('echo/config.json', 'make echo private') do |config| config.update 'access' => 'private' end + + @second_remote = local_remote('exercises/lasagna') end def find_echo @@ -222,16 +224,16 @@ def find_echo user = users(:staff) judge = create :judge, :git_stubbed sign_in user - post repositories_path, params: { repository: { name: 'test', remote: @remote.path, judge_id: judge.id } } + post repositories_path, params: { repository: { name: 'test', remote: @second_remote.path, judge_id: judge.id } } end test 'should email during repository creation' do user = users(:staff) judge = create :judge, :git_stubbed sign_in user - @remote.update_file('echo/config.json', 'break config') { '(╯°□°)╯︵ ┻━┻' } + @second_remote.update_file('exercises/extra/echo/config.json', 'break config') { '(╯°□°)╯︵ ┻━┻' } assert_difference 'ActionMailer::Base.deliveries.size', +1 do - post repositories_path, params: { repository: { name: 'test', remote: @remote.path, judge_id: judge.id } } + post repositories_path, params: { repository: { name: 'test', remote: @second_remote.path, judge_id: judge.id } } end end