@@ -17,9 +17,13 | |||
|
17 | 17 | |
|
18 | 18 | class Repository < ActiveRecord::Base |
|
19 | 19 | belongs_to :project |
|
20 |
has_many :changesets |
|
|
20 | has_many :changesets, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC" | |
|
21 | 21 | has_many :changes, :through => :changesets |
|
22 | 22 | |
|
23 | # Raw SQL to delete changesets and changes in the database | |
|
24 | # has_many :changesets, :dependent => :destroy is too slow for big repositories | |
|
25 | before_destroy :clear_changesets | |
|
26 | ||
|
23 | 27 | # Checks if the SCM is enabled when creating a repository |
|
24 | 28 | validate_on_create { |r| r.errors.add(:type, :activerecord_error_invalid) unless Setting.enabled_scm.include?(r.class.name.demodulize) } |
|
25 | 29 | |
@@ -127,4 +131,9 class Repository < ActiveRecord::Base | |||
|
127 | 131 | root_url.strip! |
|
128 | 132 | true |
|
129 | 133 | end |
|
134 | ||
|
135 | def clear_changesets | |
|
136 | connection.delete("DELETE FROM changes WHERE changes.changeset_id IN (SELECT changesets.id FROM changesets WHERE changesets.repository_id = #{id})") | |
|
137 | connection.delete("DELETE FROM changesets WHERE changesets.repository_id = #{id}") | |
|
138 | end | |
|
130 | 139 | end |
@@ -45,6 +45,16 class RepositoryTest < Test::Unit::TestCase | |||
|
45 | 45 | assert_equal repository, project.repository |
|
46 | 46 | end |
|
47 | 47 | |
|
48 | def test_destroy | |
|
49 | changesets = Changeset.count(:all, :conditions => "repository_id = 10") | |
|
50 | changes = Change.count(:all, :conditions => "repository_id = 10", :include => :changeset) | |
|
51 | assert_difference 'Changeset.count', -changesets do | |
|
52 | assert_difference 'Change.count', -changes do | |
|
53 | Repository.find(10).destroy | |
|
54 | end | |
|
55 | end | |
|
56 | end | |
|
57 | ||
|
48 | 58 | def test_should_not_create_with_disabled_scm |
|
49 | 59 | # disable Subversion |
|
50 | 60 | Setting.enabled_scm = ['Darcs', 'Git'] |
General Comments 0
You need to be logged in to leave comments.
Login now