• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

calagator / calagator / 22330793633

24 Feb 2026 12:18AM UTC coverage: 95.503% (-1.8%) from 97.337%
22330793633

Pull #752

github

web-flow
Merge 000aa5232 into 19da19ae2
Pull Request #752: Rails 7.2 Compatibility

443 of 532 branches covered (83.27%)

432 of 494 new or added lines in 51 files covered. (87.45%)

1 existing line in 1 file now uncovered.

1975 of 2068 relevant lines covered (95.5%)

1808.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.29
/app/controllers/paper_trail_manager/changes_controller.rb
1
# frozen_string_literal: true
2

3
# Allow the parent class of ChangesController to be configured in the host app
4
PaperTrailManager::ChangesController = Class.new(PaperTrailManager.base_controller.constantize)
18✔
5

6
class PaperTrailManager
18✔
7
  class ChangesController
18✔
8
    # Default number of changes to list on a pagenated index page.
9
    PER_PAGE = 50
18✔
10

11
    helper PaperTrailManager.route_helpers if PaperTrailManager.route_helpers
18!
12
    helper PaperTrailManager::ChangesHelper
18✔
13
    layout PaperTrailManager.layout if PaperTrailManager.layout
18!
14

15
    # List changes
16
    def index
18✔
17
      unless change_index_allowed?
54!
NEW
18
        flash[:error] = "You do not have permission to list changes."
×
NEW
19
        return(redirect_to root_url)
×
20
      end
21

22
      @versions = PaperTrail::Version.order("created_at DESC, id DESC")
54✔
23
      @versions = @versions.where(item_type: params[:type]) if params[:type]
54!
24
      @versions = @versions.where(item_id: params[:id]) if params[:id]
54!
25

26
      # Ensure pagination parameters have sensible values
27
      @page = params[:page].to_i
54✔
28
      @page = nil if @page.zero?
54!
29

30
      @per_page = params[:per_page].to_i
54✔
31
      @per_page = nil if @per_page.zero?
54!
32

33
      @versions = if defined?(WillPaginate)
54✔
34
        @versions.paginate(page: @page, per_page: @per_page)
54✔
35
      else
×
NEW
36
        @versions.page(@page).per(@per_page)
×
37
      end
38

39
      respond_to do |format|
54✔
40
        format.html # index.html.erb
54✔
41
        format.atom # index.atom.builder
54✔
42
        format.json { render json: @versions }
54✔
43
      end
44
    end
45

46
    # Show a change
47
    def show
18✔
48
      begin
NEW
49
        @version = PaperTrail::Version.find(params[:id])
×
50
      rescue ActiveRecord::RecordNotFound
NEW
51
        flash[:error] = "No such version."
×
NEW
52
        return(redirect_to action: :index)
×
53
      end
54

NEW
55
      unless change_show_allowed?(@version)
×
NEW
56
        flash[:error] = "You do not have permission to show that change."
×
NEW
57
        return(redirect_to action: :index)
×
58
      end
59

NEW
60
      respond_to do |format|
×
NEW
61
        format.html # show.html.erb
×
NEW
62
        format.json { render json: @version }
×
63
      end
64
    end
65

66
    # Rollback a change
67
    def update
18✔
68
      begin
NEW
69
        @version = PaperTrail::Version.find(params[:id])
×
70
      rescue ActiveRecord::RecordNotFound
NEW
71
        flash[:error] = "No such version."
×
NEW
72
        return(redirect_to(changes_path))
×
73
      end
74

NEW
75
      unless change_revert_allowed?(@version)
×
NEW
76
        flash[:error] = "You do not have permission to revert this change."
×
NEW
77
        return(redirect_to changes_path)
×
78
      end
79

NEW
80
      if @version.event == "create"
×
NEW
81
        @record = @version.item_type.constantize.find(@version.item_id)
×
NEW
82
        @result = @record.destroy
×
83
      else
×
NEW
84
        @record = @version.reify
×
NEW
85
        @result = @record.save
×
86
      end
87

NEW
88
      if @result
×
NEW
89
        if @version.event == "create"
×
NEW
90
          flash[:notice] = "Rolled back newly-created record by destroying it."
×
NEW
91
          redirect_to changes_path
×
92
        else
×
NEW
93
          flash[:notice] = "Rolled back changes to this record."
×
NEW
94
          redirect_to change_item_url(@version)
×
95
        end
96
      else
×
NEW
97
        flash[:error] = "Couldn't rollback. Sorry."
×
NEW
98
        redirect_to changes_path
×
99
      end
100
    end
101

102
    protected
18✔
103

104
    # Return the URL for the item represented by the +version+, e.g. a Company record instance referenced by a version.
105
    def change_item_url(version)
18✔
106
      version_type = version.item_type.underscore.split("/").last
54✔
107
      send("#{version_type}_url", version.item_id)
54✔
108
    rescue NoMethodError
NEW
109
      nil
×
110
    end
111
    helper_method :change_item_url
18✔
112

113
    # Allow index?
114
    def change_index_allowed?
18✔
115
      PaperTrailManager.allow_index?(self)
54✔
116
    end
117
    helper_method :change_index_allowed?
18✔
118

119
    # Allow show?
120
    def change_show_allowed?(version)
18✔
121
      PaperTrailManager.allow_show?(self, version)
54✔
122
    end
123
    helper_method :change_show_allowed?
18✔
124

125
    # Allow revert?
126
    def change_revert_allowed?(version)
18✔
127
      PaperTrailManager.allow_revert?(self, version)
36✔
128
    end
129
    helper_method :change_revert_allowed?
18✔
130
  end
131
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc