Rename Changeset changes assoc. to file_changes

Avoid naming collision with
`ActiveRecord::AttributeMethods::Dirty#changes`.

Signed-off-by: Alex Coles <alex@alexbcoles.com>
This commit is contained in:
Alex Coles
2015-06-15 11:14:03 +02:00
parent ab21c544f6
commit a8e92e251f
7 changed files with 12 additions and 12 deletions
+3 -3
View File
@@ -53,17 +53,17 @@ module RepositoriesHelper
end
def render_changeset_changes
changes = @changeset.changes.limit(1000).order('path').map { |change|
changes = @changeset.file_changes.limit(1000).order('path').map { |change|
case change.action
when 'A'
# Detects moved/copied files
if !change.from_path.blank?
action = @changeset.changes.detect { |c| c.action == 'D' && c.path == change.from_path }
action = @changeset.file_changes.detect { |c| c.action == 'D' && c.path == change.from_path }
change.action = action ? 'R' : 'C'
end
change
when 'D'
@changeset.changes.detect { |c| c.from_path == change.path } ? nil : change
@changeset.file_changes.detect { |c| c.from_path == change.path } ? nil : change
else
change
end
+1 -1
View File
@@ -30,7 +30,7 @@
class Changeset < ActiveRecord::Base
belongs_to :repository
belongs_to :user
has_many :changes, dependent: :delete_all
has_many :file_changes, class_name: 'Change', dependent: :delete_all
has_and_belongs_to_many :work_packages
acts_as_journalized
+1 -1
View File
@@ -51,7 +51,7 @@ class Repository < ActiveRecord::Base
validates_length_of :password, maximum: 255, allow_nil: true
validate :validate_enabled_scm, on: :create
def changes
def file_changes
Change.where(changeset_id: changesets).joins(:changeset)
end
+1 -1
View File
@@ -69,7 +69,7 @@ See doc/COPYRIGHT.rdoc for more details.
<li class="change change-R"><%= l(:label_renamed) %></li>
<li class="change change-D"><%= l(:label_deleted) %></li>
</ul>
<p><%= link_to(l(:label_view_diff), :action => 'diff', :project_id => @project, :path => nil, :rev => @changeset.identifier) if @changeset.changes.any? %></p>
<p><%= link_to(l(:label_view_diff), :action => 'diff', :project_id => @project, :path => nil, :rev => @changeset.identifier) if @changeset.file_changes.any? %></p>
<div class="changeset-changes">
<%= render_changeset_changes %>
</div>
+1 -1
View File
@@ -159,7 +159,7 @@ user_count.times do |count|
change = Change.create(action: Faker::Lorem.characters(1),
path: Faker::Internet.url)
changeset.changes << change
changeset.file_changes << change
end
repository.changesets << changeset
+3 -3
View File
@@ -69,7 +69,7 @@ describe Repository::Git, type: :model do
@repository.reload
assert_equal 22, @repository.changesets.count
assert_equal 34, @repository.changes.count
assert_equal 34, @repository.file_changes.count
commit = @repository.changesets.reorder('committed_on ASC').first
assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
@@ -80,8 +80,8 @@ describe Repository::Git, type: :model do
assert_equal '2007-12-14'.to_date, commit.commit_date
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', commit.revision
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', commit.scmid
assert_equal 3, commit.changes.count
change = commit.changes.sort_by(&:path).first
assert_equal 3, commit.file_changes.count
change = commit.file_changes.sort_by(&:path).first
assert_equal 'README', change.path
assert_equal 'A', change.action
end
@@ -46,7 +46,7 @@ describe Repository::Subversion, type: :model do
@repository.reload
assert_equal 12, @repository.changesets.count
assert_equal 21, @repository.changes.count
assert_equal 21, @repository.file_changes.count
assert_equal 'Initial import.', @repository.changesets.find_by(revision: '1').comments
end
@@ -99,7 +99,7 @@ describe Repository::Subversion, type: :model do
@repository.reload
assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision'
assert_equal 2, @repository.changes.count, 'Expected to see 2 changes, dir add and file add'
assert_equal 2, @repository.file_changes.count, 'Expected to see 2 changes, dir add and file add'
entries = @repository.entries('')
assert_not_nil entries, 'Expect to find entries'