@@ -17,9 +17,13 | |||||
17 |
|
17 | |||
18 | class Repository < ActiveRecord::Base |
|
18 | class Repository < ActiveRecord::Base | |
19 | belongs_to :project |
|
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 | has_many :changes, :through => :changesets |
|
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 | # Checks if the SCM is enabled when creating a repository |
|
27 | # Checks if the SCM is enabled when creating a repository | |
24 | validate_on_create { |r| r.errors.add(:type, :activerecord_error_invalid) unless Setting.enabled_scm.include?(r.class.name.demodulize) } |
|
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 | root_url.strip! |
|
131 | root_url.strip! | |
128 | true |
|
132 | true | |
129 | end |
|
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 | end |
|
139 | end |
@@ -45,6 +45,16 class RepositoryTest < Test::Unit::TestCase | |||||
45 | assert_equal repository, project.repository |
|
45 | assert_equal repository, project.repository | |
46 | end |
|
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 | def test_should_not_create_with_disabled_scm |
|
58 | def test_should_not_create_with_disabled_scm | |
49 | # disable Subversion |
|
59 | # disable Subversion | |
50 | Setting.enabled_scm = ['Darcs', 'Git'] |
|
60 | Setting.enabled_scm = ['Darcs', 'Git'] |
General Comments 0
You need to be logged in to leave comments.
Login now