##// END OF EJS Templates
Renamed #changes association to #filechanges (clash with AR::Base.changes that triggers errors with Rails 3.2.5)....
Jean-Philippe Lang -
r9576:2cbf9c9cc481
parent child
Show More
@@ -46,17 +46,17 module RepositoriesHelper
46 end
46 end
47
47
48 def render_changeset_changes
48 def render_changeset_changes
49 changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change|
49 changes = @changeset.filechanges.find(:all, :limit => 1000, :order => 'path').collect do |change|
50 case change.action
50 case change.action
51 when 'A'
51 when 'A'
52 # Detects moved/copied files
52 # Detects moved/copied files
53 if !change.from_path.blank?
53 if !change.from_path.blank?
54 change.action =
54 change.action =
55 @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
55 @changeset.filechanges.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
56 end
56 end
57 change
57 change
58 when 'D'
58 when 'D'
59 @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change
59 @changeset.filechanges.detect {|c| c.from_path == change.path} ? nil : change
60 else
60 else
61 change
61 change
62 end
62 end
@@ -20,7 +20,7 require 'iconv'
20 class Changeset < ActiveRecord::Base
20 class Changeset < ActiveRecord::Base
21 belongs_to :repository
21 belongs_to :repository
22 belongs_to :user
22 belongs_to :user
23 has_many :changes, :dependent => :delete_all
23 has_many :filechanges, :class_name => 'Change', :dependent => :delete_all
24 has_and_belongs_to_many :issues
24 has_and_belongs_to_many :issues
25 has_and_belongs_to_many :parents,
25 has_and_belongs_to_many :parents,
26 :class_name => "Changeset",
26 :class_name => "Changeset",
@@ -22,7 +22,7 class Repository < ActiveRecord::Base
22
22
23 belongs_to :project
23 belongs_to :project
24 has_many :changesets, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC"
24 has_many :changesets, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC"
25 has_many :changes, :through => :changesets
25 has_many :filechanges, :class_name => 'Change', :through => :changesets
26
26
27 serialize :extra_info
27 serialize :extra_info
28
28
@@ -228,7 +228,7 class Repository < ActiveRecord::Base
228 :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
228 :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
229 :limit => limit)
229 :limit => limit)
230 else
230 else
231 changes.find(
231 filechanges.find(
232 :all,
232 :all,
233 :include => {:changeset => :user},
233 :include => {:changeset => :user},
234 :conditions => ["path = ?", path.with_leading_slash],
234 :conditions => ["path = ?", path.with_leading_slash],
@@ -54,7 +54,7 class Repository::Cvs < Repository
54 if entries
54 if entries
55 entries.each() do |entry|
55 entries.each() do |entry|
56 if ( ! entry.lastrev.nil? ) && ( ! entry.lastrev.revision.nil? )
56 if ( ! entry.lastrev.nil? ) && ( ! entry.lastrev.revision.nil? )
57 change=changes.find_by_revision_and_path(
57 change = filechanges.find_by_revision_and_path(
58 entry.lastrev.revision,
58 entry.lastrev.revision,
59 scm.with_leading_slash(entry.path) )
59 scm.with_leading_slash(entry.path) )
60 if change
60 if change
@@ -94,7 +94,7 class Repository::Cvs < Repository
94 if rev_to.to_i > 0
94 if rev_to.to_i > 0
95 changeset_to = changesets.find_by_revision(rev_to)
95 changeset_to = changesets.find_by_revision(rev_to)
96 end
96 end
97 changeset_from.changes.each() do |change_from|
97 changeset_from.filechanges.each() do |change_from|
98 revision_from = nil
98 revision_from = nil
99 revision_to = nil
99 revision_to = nil
100 if path.nil? || (change_from.path.starts_with? scm.with_leading_slash(path))
100 if path.nil? || (change_from.path.starts_with? scm.with_leading_slash(path))
@@ -102,7 +102,7 class Repository::Cvs < Repository
102 end
102 end
103 if revision_from
103 if revision_from
104 if changeset_to
104 if changeset_to
105 changeset_to.changes.each() do |change_to|
105 changeset_to.filechanges.each() do |change_to|
106 revision_to = change_to.revision if change_to.path == change_from.path
106 revision_to = change_to.revision if change_to.path == change_from.path
107 end
107 end
108 end
108 end
@@ -133,7 +133,7 class Repository::Cvs < Repository
133 # only add the change to the database, if it doen't exists. the cvs log
133 # only add the change to the database, if it doen't exists. the cvs log
134 # is not exclusive at all.
134 # is not exclusive at all.
135 tmp_time = revision.time.clone
135 tmp_time = revision.time.clone
136 unless changes.find_by_path_and_revision(
136 unless filechanges.find_by_path_and_revision(
137 scm.with_leading_slash(revision.paths[0][:path]),
137 scm.with_leading_slash(revision.paths[0][:path]),
138 revision.paths[0][:revision]
138 revision.paths[0][:revision]
139 )
139 )
@@ -79,7 +79,7 class Repository::Darcs < Repository
79 return nil if patch_from.nil?
79 return nil if patch_from.nil?
80 patch_to = changesets.find_by_revision(rev_to) if rev_to
80 patch_to = changesets.find_by_revision(rev_to) if rev_to
81 if path.blank?
81 if path.blank?
82 path = patch_from.changes.collect{|change| change.path}.join(' ')
82 path = patch_from.filechanges.collect{|change| change.path}.join(' ')
83 end
83 end
84 patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil) : nil
84 patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil) : nil
85 end
85 end
@@ -83,7 +83,7
83 :id => @project,
83 :id => @project,
84 :repository_id => @repository.identifier_param,
84 :repository_id => @repository.identifier_param,
85 :path => "",
85 :path => "",
86 :rev => @changeset.identifier) if @changeset.changes.any? %></p>
86 :rev => @changeset.identifier) if @changeset.filechanges.any? %></p>
87
87
88 <div class="changeset-changes">
88 <div class="changeset-changes">
89 <%= render_changeset_changes %>
89 <%= render_changeset_changes %>
@@ -67,7 +67,7 class RepositoryBazaarTest < ActiveSupport::TestCase
67 @project.reload
67 @project.reload
68
68
69 assert_equal NUM_REV, @repository.changesets.count
69 assert_equal NUM_REV, @repository.changesets.count
70 assert_equal 9, @repository.changes.count
70 assert_equal 9, @repository.filechanges.count
71 assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments
71 assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments
72 end
72 end
73
73
@@ -102,7 +102,7 class RepositoryCvsTest < ActiveSupport::TestCase
102 @project.reload
102 @project.reload
103
103
104 assert_equal CHANGESETS_NUM, @repository.changesets.count
104 assert_equal CHANGESETS_NUM, @repository.changesets.count
105 assert_equal 16, @repository.changes.count
105 assert_equal 16, @repository.filechanges.count
106 assert_not_nil @repository.changesets.find_by_comments('Two files changed')
106 assert_not_nil @repository.changesets.find_by_comments('Two files changed')
107
107
108 r2 = @repository.changesets.find_by_revision('2')
108 r2 = @repository.changesets.find_by_revision('2')
@@ -68,7 +68,7 class RepositoryDarcsTest < ActiveSupport::TestCase
68 @project.reload
68 @project.reload
69
69
70 assert_equal NUM_REV, @repository.changesets.count
70 assert_equal NUM_REV, @repository.changesets.count
71 assert_equal 13, @repository.changes.count
71 assert_equal 13, @repository.filechanges.count
72 assert_equal "Initial commit.", @repository.changesets.find_by_revision('1').comments
72 assert_equal "Initial commit.", @repository.changesets.find_by_revision('1').comments
73 end
73 end
74
74
@@ -62,11 +62,11 class RepositoryFilesystemTest < ActiveSupport::TestCase
62 if File.directory?(REPOSITORY_PATH)
62 if File.directory?(REPOSITORY_PATH)
63 def test_fetch_changesets
63 def test_fetch_changesets
64 assert_equal 0, @repository.changesets.count
64 assert_equal 0, @repository.changesets.count
65 assert_equal 0, @repository.changes.count
65 assert_equal 0, @repository.filechanges.count
66 @repository.fetch_changesets
66 @repository.fetch_changesets
67 @project.reload
67 @project.reload
68 assert_equal 0, @repository.changesets.count
68 assert_equal 0, @repository.changesets.count
69 assert_equal 0, @repository.changes.count
69 assert_equal 0, @repository.filechanges.count
70 end
70 end
71
71
72 def test_entries
72 def test_entries
@@ -105,7 +105,7 class RepositoryGitTest < ActiveSupport::TestCase
105 @project.reload
105 @project.reload
106
106
107 assert_equal NUM_REV, @repository.changesets.count
107 assert_equal NUM_REV, @repository.changesets.count
108 assert_equal 39, @repository.changes.count
108 assert_equal 39, @repository.filechanges.count
109
109
110 commit = @repository.changesets.find_by_revision("7234cb2750b63f47bff735edc50a1c0a433c2518")
110 commit = @repository.changesets.find_by_revision("7234cb2750b63f47bff735edc50a1c0a433c2518")
111 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
111 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
@@ -115,8 +115,8 class RepositoryGitTest < ActiveSupport::TestCase
115 # TODO: add a commit with commit time <> author time to the test repository
115 # TODO: add a commit with commit time <> author time to the test repository
116 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
116 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
117 assert_equal "2007-12-14".to_date, commit.commit_date
117 assert_equal "2007-12-14".to_date, commit.commit_date
118 assert_equal 3, commit.changes.count
118 assert_equal 3, commit.filechanges.count
119 change = commit.changes.sort_by(&:path).first
119 change = commit.filechanges.sort_by(&:path).first
120 assert_equal "README", change.path
120 assert_equal "README", change.path
121 assert_equal nil, change.from_path
121 assert_equal nil, change.from_path
122 assert_equal "A", change.action
122 assert_equal "A", change.action
@@ -86,7 +86,7 class RepositoryMercurialTest < ActiveSupport::TestCase
86 @repository.fetch_changesets
86 @repository.fetch_changesets
87 @project.reload
87 @project.reload
88 assert_equal NUM_REV, @repository.changesets.count
88 assert_equal NUM_REV, @repository.changesets.count
89 assert_equal 46, @repository.changes.count
89 assert_equal 46, @repository.filechanges.count
90 assert_equal "Initial import.\nThe repository contains 3 files.",
90 assert_equal "Initial import.\nThe repository contains 3 files.",
91 @repository.changesets.find_by_revision('0').comments
91 @repository.changesets.find_by_revision('0').comments
92 end
92 end
@@ -214,7 +214,7 class RepositoryMercurialTest < ActiveSupport::TestCase
214
214
215 cs1 = @repository.changesets.find_by_revision('13')
215 cs1 = @repository.changesets.find_by_revision('13')
216 assert_not_nil cs1
216 assert_not_nil cs1
217 c1 = cs1.changes.sort_by(&:path)
217 c1 = cs1.filechanges.sort_by(&:path)
218 assert_equal 2, c1.size
218 assert_equal 2, c1.size
219
219
220 assert_equal 'A', c1[0].action
220 assert_equal 'A', c1[0].action
@@ -227,7 +227,7 class RepositoryMercurialTest < ActiveSupport::TestCase
227 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
227 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
228
228
229 cs2 = @repository.changesets.find_by_revision('15')
229 cs2 = @repository.changesets.find_by_revision('15')
230 c2 = cs2.changes
230 c2 = cs2.filechanges
231 assert_equal 1, c2.size
231 assert_equal 1, c2.size
232
232
233 assert_equal 'A', c2[0].action
233 assert_equal 'A', c2[0].action
@@ -236,7 +236,7 class RepositoryMercurialTest < ActiveSupport::TestCase
236 assert_equal '933ca60293d7', c2[0].from_revision
236 assert_equal '933ca60293d7', c2[0].from_revision
237
237
238 cs3 = @repository.changesets.find_by_revision('19')
238 cs3 = @repository.changesets.find_by_revision('19')
239 c3 = cs3.changes
239 c3 = cs3.filechanges
240 assert_equal 1, c3.size
240 assert_equal 1, c3.size
241 assert_equal 'A', c3[0].action
241 assert_equal 'A', c3[0].action
242 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
242 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
@@ -36,7 +36,7 class RepositorySubversionTest < ActiveSupport::TestCase
36 @project.reload
36 @project.reload
37
37
38 assert_equal NUM_REV, @repository.changesets.count
38 assert_equal NUM_REV, @repository.changesets.count
39 assert_equal 20, @repository.changes.count
39 assert_equal 20, @repository.filechanges.count
40 assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
40 assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
41 end
41 end
42
42
@@ -99,7 +99,7 class RepositorySubversionTest < ActiveSupport::TestCase
99 @project.reload
99 @project.reload
100
100
101 assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision'
101 assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision'
102 assert_equal 2, @repository.changes.count, 'Expected to see 2 changes, dir add and file add'
102 assert_equal 2, @repository.filechanges.count, 'Expected to see 2 changes, dir add and file add'
103
103
104 entries = @repository.entries('')
104 entries = @repository.entries('')
105 assert_not_nil entries, 'Expect to find entries'
105 assert_not_nil entries, 'Expect to find entries'
@@ -98,8 +98,10 class RepositoryTest < ActiveSupport::TestCase
98 end
98 end
99
99
100 def test_destroy
100 def test_destroy
101 changesets = Changeset.where("repository_id = 10").all.count
101 repository = Repository.find(10)
102 changes = Changeset.joins([:changes]).where("repository_id = 10").all.count
102 changesets = repository.changesets.count
103 changes = repository.filechanges.count
104
103 assert_difference 'Changeset.count', -changesets do
105 assert_difference 'Changeset.count', -changesets do
104 assert_difference 'Change.count', -changes do
106 assert_difference 'Change.count', -changes do
105 Repository.find(10).destroy
107 Repository.find(10).destroy
General Comments 0
You need to be logged in to leave comments. Login now