paper_trail_manager 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 237613f3cbd029dce20a9cf59e754551550f712d
4
- data.tar.gz: 60b579fcda4d97494c48513714c5290f4f24d1bc
3
+ metadata.gz: 2549171549b22c9328db417189798ea21871029c
4
+ data.tar.gz: 150cc4d55fbf5db0818687c333c6df8d463226af
5
5
  SHA512:
6
- metadata.gz: da1ad13d7385129624206e5ba3d2083d79ea092523b308ccf26df020add6c3e3f4961b89705433bd9ead44716f940d1786f8ec63352f4e6a389f51c9b215bb48
7
- data.tar.gz: 6997cda79358bf04d28edc830fade6f9829da2d99f24896e09581e3cf50687b28c698636df63bf312dc627eeff8af7779e1baf8acc4d9f0b39ac05369fc814d5
6
+ metadata.gz: fea549305c1d60b72b0ee0cb7638967f5618789b8ee4fe709c200706a118ed4e5d6a7a63dfb30228313008ac41e61cbbd083fd663f03610108b73b409c257775
7
+ data.tar.gz: 2b3e7b426fd66283adabdfee001ce2415eec56537fdbc8c249509fb3428c893f2b736db4a3ad5e10e1739c70094aba8e0678b9042026fa13f00cdb2dd863a5d8
data/.travis.yml CHANGED
@@ -4,8 +4,12 @@ rvm:
4
4
  - 2.0
5
5
  - 2.1
6
6
  gemfile:
7
- - gemfiles/rails_3.2.gemfile
8
- - gemfiles/rails_4.0.gemfile
9
- - gemfiles/rails_4.1.gemfile
10
- - gemfiles/rails_4.2.gemfile
7
+ - gemfiles/rails_3.2_will_paginate.gemfile
8
+ - gemfiles/rails_4.0_will_paginate.gemfile
9
+ - gemfiles/rails_4.1_will_paginate.gemfile
10
+ - gemfiles/rails_4.2_will_paginate.gemfile
11
+ - gemfiles/rails_3.2_kaminari.gemfile
12
+ - gemfiles/rails_4.0_kaminari.gemfile
13
+ - gemfiles/rails_4.1_kaminari.gemfile
14
+ - gemfiles/rails_4.2_kaminari.gemfile
11
15
  cache: bundler
data/Appraisals CHANGED
@@ -1,15 +1,39 @@
1
- appraise "rails-3.2" do
2
- gem "rails", "3.2.21"
1
+ appraise "rails-3.2-will-paginate" do
2
+ gem "rails", "~> 3.2.21"
3
+ gem "will_paginate", "~> 3.0"
3
4
  end
4
5
 
5
- appraise "rails-4.0" do
6
- gem "rails", "4.0.9"
6
+ appraise "rails-4.0-will-paginate" do
7
+ gem "rails", "~> 4.0.13"
8
+ gem "will_paginate", "~> 3.0"
7
9
  end
8
10
 
9
- appraise "rails-4.1" do
10
- gem "rails", "4.1.9"
11
+ appraise "rails-4.1-will-paginate" do
12
+ gem "rails", "~> 4.1.11"
13
+ gem "will_paginate", "~> 3.0"
11
14
  end
12
15
 
13
- appraise "rails-4.2" do
14
- gem "rails", "4.2.0"
16
+ appraise "rails-4.2-will-paginate" do
17
+ gem "rails", "~> 4.2.2"
18
+ gem "will_paginate", "~> 3.0"
19
+ end
20
+
21
+ appraise "rails-3.2-kaminari" do
22
+ gem "rails", "~> 3.2.21"
23
+ gem "kaminari", "~> 0.16"
24
+ end
25
+
26
+ appraise "rails-4.0-kaminari" do
27
+ gem "rails", "~> 4.0.13"
28
+ gem "kaminari", "~> 0.16"
29
+ end
30
+
31
+ appraise "rails-4.1-kaminari" do
32
+ gem "rails", "~> 4.1.11"
33
+ gem "kaminari", "~> 0.16"
34
+ end
35
+
36
+ appraise "rails-4.2-kaminari" do
37
+ gem "rails", "~> 4.2.2"
38
+ gem "kaminari", "~> 0.16"
15
39
  end
data/CHANGES.md CHANGED
@@ -1,6 +1,11 @@
1
1
  Changes to `paper_trail_manager`
2
2
  ================================
3
3
 
4
+ * 0.5.0
5
+ * Added support for pagination with [Kaminari](https://github.com/amatsuda/kaminari) in addition to [will_paginate](https://github.com/mislav/will_paginate).
6
+ * **[!]** Removed direct dependency on will_paginate. You must now include either `will_paginate` or `kaminari` in your Gemfile.
7
+ * Fixed a bug with route generation when paper_trail_manager is used within another Rails engine.
8
+
4
9
  * 0.4.0
5
10
  * Allow configuration of ChangesController's parent class, route helpers, and layout
6
11
 
data/Gemfile CHANGED
@@ -3,4 +3,3 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in paper_trail_manager.gemspec
4
4
  gemspec
5
5
 
6
- gem "byebug"
data/README.md CHANGED
@@ -11,8 +11,15 @@ This software has been in use for a year at http://calagator.org and http://epdx
11
11
  If you have a Ruby on Rails 3 or 4 application where you're using the `paper_trail` gem to track changes to your records, you can make use of this like:
12
12
 
13
13
  Add the following line to your `Gemfile`:
14
+
14
15
  gem 'paper_trail_manager'
15
16
 
17
+ PaperTrailManager will use your existing paging library ([will_paginate](https://github.com/mislav/will_paginate) or [Kaminari](https://github.com/amatsuda/kaminari)). If you don't currently use one in your app, add one of the following lines to your `Gemfile`:
18
+
19
+ gem 'kaminari'
20
+ #or
21
+ gem 'will_paginate'
22
+
16
23
  Install the libary:
17
24
 
18
25
  bundle install
@@ -63,15 +70,24 @@ Setup:
63
70
 
64
71
  Running tests:
65
72
 
66
- * Run `rake` to run the tests. Note that the first time tests are run, gems will need to be downloaded for each individual version of Rails this app is tested against, which may take a while.
73
+ * Run `appraisal rake` to run the tests against all supported gem combinations. Note that the first time tests are run, gems will need to be downloaded for each individual version of Rails this app is tested against, which may take a while.
67
74
 
68
75
  Adding support for new Rails versions:
69
76
 
70
- * Run `./rails_test/generate_test_directory VERSION` where `VERSION` is the Rails version you want to add support for, e.g.: `./rails_test/generate_test_directory 3.2.8`
71
- * Run `rake test:rails-VERSION`, e.g. `rake test:rails-3.2.8` to install dependencies and run the tests.
72
- * Rerun the previous command to run tests for that specific version.
73
- * Edit the files in `rails_test/common` which will be copied into the individual Rails apps, e.g. the tests run against individual Rails versions are stored in `rails_test/common/spec`.
74
- * Edit the `./rails_test/generate_test_directory` file to modify files, e.g. setup routes.
77
+ * This repo uses the [Appraisal](https://github.com/thoughtbot/appraisal) gem, to add a new rails version modify the Appraisals file
78
+ - Add both a 'will_paginate' and a 'kaminari' version like so:
79
+ ```
80
+ appraise "rails-5.0-will-paginate" do
81
+ gem "rails", "5.0.0"
82
+ gem "will_paginate", "~> 3.0"
83
+ end
84
+ appraise "rails-5.0-will-kaminari" do
85
+ gem "rails", "5.0.0"
86
+ gem "kaminari", "~> 0.16"
87
+ end
88
+ ```
89
+ * Run `appraisal generate`
90
+ * Run `appraisal install`
75
91
  * Fix whatever breaks.
76
92
  * Please contribute your fixes with a Github pull request.
77
93
 
@@ -28,7 +28,11 @@ class PaperTrailManager::ChangesController
28
28
  @page = (v = params[:page].to_i; v == 0 ? nil : v)
29
29
  @per_page = (v = params[:per_page].to_i; v == 0 ? PER_PAGE : v)
30
30
 
31
- @versions = @versions.paginate(:page => @page, :per_page => @per_page)
31
+ if defined?(WillPaginate)
32
+ @versions = @versions.paginate(:page => @page, :per_page => @per_page)
33
+ else
34
+ @versions = @versions.page(@page).per(@per_page)
35
+ end
32
36
 
33
37
  respond_to do |format|
34
38
  format.html # index.html.erb
@@ -63,12 +67,12 @@ class PaperTrailManager::ChangesController
63
67
  @version = PaperTrail::Version.find(params[:id])
64
68
  rescue ActiveRecord::RecordNotFound
65
69
  flash[:error] = "No such version."
66
- return(redirect_to(:action => :index))
70
+ return(redirect_to(changes_path))
67
71
  end
68
72
 
69
73
  unless change_revert_allowed?(@version)
70
74
  flash[:error] = "You do not have permission to revert this change."
71
- return(redirect_to :action => :index)
75
+ return(redirect_to changes_path)
72
76
  end
73
77
 
74
78
  if @version.event == "create"
@@ -82,14 +86,14 @@ class PaperTrailManager::ChangesController
82
86
  if @result
83
87
  if @version.event == "create"
84
88
  flash[:notice] = "Rolled back newly-created record by destroying it."
85
- redirect_to :action => :index
89
+ redirect_to changes_path
86
90
  else
87
91
  flash[:notice] = "Rolled back changes to this record."
88
92
  redirect_to change_item_url(@version)
89
93
  end
90
94
  else
91
95
  flash[:error] = "Couldn't rollback. Sorry."
92
- redirect_to :action => :index
96
+ redirect_to changes_path
93
97
  end
94
98
  end
95
99
 
@@ -97,7 +101,8 @@ protected
97
101
 
98
102
  # Return the URL for the item represented by the +version+, e.g. a Company record instance referenced by a version.
99
103
  def change_item_url(version)
100
- return send("#{version.item_type.downcase}_url", version.item_id)
104
+ version_type = version.item_type.underscore.split('/').last
105
+ return send("#{version_type}_url", version.item_id)
101
106
  rescue NoMethodError
102
107
  return nil
103
108
  end
@@ -11,7 +11,7 @@
11
11
  <tfoot>
12
12
  <tr>
13
13
  <td colspan='2'>
14
- <%= will_paginate @versions %>
14
+ <%= paginate @versions %>
15
15
  </td>
16
16
  </tr>
17
17
  </tfoot>
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "4.0.9"
5
+ gem "rails", "~> 3.2.21"
6
+ gem "kaminari", "~> 0.16"
6
7
 
7
8
  gemspec :path => "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 3.2.21"
6
+ gem "will_paginate", "~> 3.0"
7
+
8
+ gemspec :path => "../"
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "4.1.9"
5
+ gem "rails", "~> 4.0.13"
6
+ gem "kaminari", "~> 0.16"
6
7
 
7
8
  gemspec :path => "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.0.13"
6
+ gem "will_paginate", "~> 3.0"
7
+
8
+ gemspec :path => "../"
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "4.2.0"
5
+ gem "rails", "~> 4.1.11"
6
+ gem "kaminari", "~> 0.16"
6
7
 
7
8
  gemspec :path => "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.1.11"
6
+ gem "will_paginate", "~> 3.0"
7
+
8
+ gemspec :path => "../"
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "3.2.21"
5
+ gem "rails", "~> 4.2.2"
6
+ gem "kaminari", "~> 0.16"
6
7
 
7
8
  gemspec :path => "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.2.2"
6
+ gem "will_paginate", "~> 3.0"
7
+
8
+ gemspec :path => "../"
@@ -1,8 +1,23 @@
1
1
  require 'rails'
2
2
  require 'paper_trail'
3
- require 'will_paginate'
3
+
4
+ begin
5
+ require 'will_paginate'
6
+ rescue LoadError
7
+ begin
8
+ require 'kaminari'
9
+ rescue LoadError
10
+ raise LoadError.new('will_paginate or kaminari must be in Gemfile or load_path')
11
+ end
12
+ end
4
13
 
5
14
  class PaperTrailManager < Rails::Engine
15
+ initializer "paper_trail_manager.pagination" do
16
+ if defined?(WillPaginate)
17
+ ::ActionView::Base.send(:alias_method, :paginate, :will_paginate)
18
+ end
19
+ end
20
+
6
21
  @@whodunnit_name_method = :name
7
22
  cattr_accessor :whodunnit_class, :whodunnit_name_method, :route_helpers, :layout, :base_controller
8
23
 
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "paper_trail_manager"
7
- spec.version = "0.4.0"
7
+ spec.version = "0.5.0"
8
8
  spec.authors = ["Igal Koshevoy", "Reid Beels"]
9
9
  spec.authors = ["mail@reidbeels.com"]
10
10
  spec.summary = "A user interface for `paper_trail` versioning data in Ruby on Rails 3 applications."
@@ -19,7 +19,6 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_dependency "rails", [">= 3.0", "< 5.0"]
21
21
  spec.add_dependency "paper_trail", "~> 3.0"
22
- spec.add_dependency "will_paginate", "~> 3.0"
23
22
 
24
23
  spec.add_development_dependency "rake", "~> 10.4"
25
24
  spec.add_development_dependency "sqlite3", "~> 1.3"
@@ -69,37 +69,6 @@ describe PaperTrailManager, :versioning => true do
69
69
  versions.map(&:id).should == versions.sort_by { |o| [o.created_at, o.id] }.reverse.map(&:id)
70
70
  end
71
71
  end
72
-
73
- context "and getting paginated page" do
74
- let(:page) { 2 }
75
- let(:per_page) { 3 }
76
-
77
- before { get changes_path(:page => page, :per_page => per_page) }
78
-
79
- it "should set :page parameter" do
80
- assigns[:page].should == page
81
- end
82
-
83
- it "should set :per_page parameter" do
84
- assigns[:per_page].should == per_page
85
- end
86
-
87
- it "should retrieve only items for page" do
88
- versions.size.should == per_page
89
- end
90
- end
91
-
92
- context "and getting invalid pagination" do
93
- before { get changes_path(:page => "Shanghai", :per_page => "Alice") }
94
-
95
- it "should set default :page parameter" do
96
- assigns[:page].should be_nil
97
- end
98
-
99
- it "should set default :per_page parameter" do
100
- assigns[:per_page].should == PaperTrailManager::ChangesController::PER_PAGE
101
- end
102
- end
103
72
  end
104
73
 
105
74
  # TODO
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require "rails_helper"
2
2
  require "rspec/its"
3
- require "byebug"
4
3
 
5
4
  # This file was generated by the `rails generate rspec:install` command. Conventionally, all
6
5
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paper_trail_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mail@reidbeels.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-14 00:00:00.000000000 Z
11
+ date: 2015-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -44,20 +44,6 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '3.0'
47
- - !ruby/object:Gem::Dependency
48
- name: will_paginate
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '3.0'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '3.0'
61
47
  - !ruby/object:Gem::Dependency
62
48
  name: rake
63
49
  requirement: !ruby/object:Gem::Requirement
@@ -177,10 +163,14 @@ files:
177
163
  - app/views/paper_trail_manager/changes/index.atom.builder
178
164
  - app/views/paper_trail_manager/changes/index.html.erb
179
165
  - app/views/paper_trail_manager/changes/show.html.erb
180
- - gemfiles/rails_3.2.gemfile
181
- - gemfiles/rails_4.0.gemfile
182
- - gemfiles/rails_4.1.gemfile
183
- - gemfiles/rails_4.2.gemfile
166
+ - gemfiles/rails_3.2_kaminari.gemfile
167
+ - gemfiles/rails_3.2_will_paginate.gemfile
168
+ - gemfiles/rails_4.0_kaminari.gemfile
169
+ - gemfiles/rails_4.0_will_paginate.gemfile
170
+ - gemfiles/rails_4.1_kaminari.gemfile
171
+ - gemfiles/rails_4.1_will_paginate.gemfile
172
+ - gemfiles/rails_4.2_kaminari.gemfile
173
+ - gemfiles/rails_4.2_will_paginate.gemfile
184
174
  - lib/paper_trail_manager.rb
185
175
  - paper_trail_manager.gemspec
186
176
  - spec/controllers/entities_controller_spec.rb