paper_trail-globalid 0.1.3.rc → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +2 -1
- data/lib/paper_trail-globalid.rb +3 -1
- data/lib/paper_trail_globalid/paper_trail.rb +7 -13
- data/lib/paper_trail_globalid/version.rb +1 -1
- data/paper_trail_globalid.gemspec +6 -0
- data/spec/paper_trail_globalid_spec.rb +122 -0
- data/spec/spec_helper.rb +101 -0
- data/spec/support/admin.rb +4 -0
- data/spec/support/database_connection.rb +4 -0
- data/spec/support/order.rb +5 -0
- metadata +99 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 102e00cb9ac9f000210f7616d21282c4bc8cad0f
|
4
|
+
data.tar.gz: 79a1e30e95486bc103720f785322d8d9f16bb276
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f301f67094a75e64884c3f7b85db75c4b79cb3a9bd2b07b3904aee7cd7b4471d4388a56c33c25f78df9b567f1baf4a4c20d7284a7da2468326c846033ae0333
|
7
|
+
data.tar.gz: 905514bf080152ac06f8a0a407a5ec0da943be9c6fbbf44dc16e1c8424aa4ed386147e0fdb2bc4bd58538e5cf0f895a60e57046e0bcfce082582b4eee5514963
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# PaperTrailGlobalid
|
2
|
+
[![Code Climate](https://codeclimate.com/github/ankit1910/paper_trail-globalid/badges/gpa.svg)](https://codeclimate.com/github/ankit1910/paper_trail-globalid)
|
3
|
+
|
2
4
|
This gem is an extension to paper_trail gem https://github.com/airblade/paper_trail. That means you need to pre install `paper_trail` gem. This gem will add one more method `actor` to instances of `PaperTrail::Version` that will return you the `ActiveRecord` object who was responsible for change.
|
3
5
|
|
4
|
-
[![Code Climate](https://codeclimate.com/github/ankit1910/paper_trail-globalid/badges/gpa.svg)](https://codeclimate.com/github/ankit1910/paper_trail-globalid)
|
5
6
|
|
6
7
|
## Supported Rails
|
7
8
|
|
data/lib/paper_trail-globalid.rb
CHANGED
@@ -1,21 +1,15 @@
|
|
1
1
|
module PaperTrailGlobalid
|
2
2
|
module PaperTrail
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
paper_trail_store[:whodunnit] = value
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def actor
|
13
|
-
::GlobalID::Locator.locate(paper_trail_store[:whodunnit]) || whodunnit
|
3
|
+
def whodunnit=(value)
|
4
|
+
if value.is_a? ActiveRecord::Base
|
5
|
+
paper_trail_store[:whodunnit] = value.to_gid
|
6
|
+
else
|
7
|
+
paper_trail_store[:whodunnit] = value
|
14
8
|
end
|
15
9
|
end
|
16
10
|
|
17
|
-
def
|
18
|
-
|
11
|
+
def actor
|
12
|
+
::GlobalID::Locator.locate(paper_trail_store[:whodunnit]) || whodunnit
|
19
13
|
end
|
20
14
|
end
|
21
15
|
end
|
@@ -24,4 +24,10 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency 'appraisal', '~> 2.1'
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.6"
|
26
26
|
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.3.0"
|
28
|
+
spec.add_development_dependency "coveralls", "~> 0.8.2"
|
29
|
+
spec.add_development_dependency "activerecord", ">=3.2.0"
|
30
|
+
spec.add_development_dependency "activesupport", ">=3.2.0"
|
31
|
+
spec.add_development_dependency "sqlite3"
|
32
|
+
spec.add_development_dependency "byebug"
|
27
33
|
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../spec/support/order.rb'
|
3
|
+
require_relative '../spec/support/admin.rb'
|
4
|
+
|
5
|
+
|
6
|
+
describe PaperTrailGlobalid do
|
7
|
+
before(:all) do
|
8
|
+
ActiveRecord::Migration.verbose = false
|
9
|
+
ActiveRecord::Schema.define do
|
10
|
+
create_table :orders, force: true do |t|
|
11
|
+
t.string :order_number
|
12
|
+
t.integer :total
|
13
|
+
end
|
14
|
+
|
15
|
+
create_table :admins, force: true do |t|
|
16
|
+
t.string :name
|
17
|
+
end
|
18
|
+
|
19
|
+
create_table :versions do |t|
|
20
|
+
t.string :item_type, :null => false
|
21
|
+
t.integer :item_id, :null => false
|
22
|
+
t.string :event, :null => false
|
23
|
+
t.string :whodunnit
|
24
|
+
t.text :object, :limit => 1_073_741_823
|
25
|
+
t.datetime :created_at
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
after(:all) do
|
31
|
+
ActiveRecord::Schema.define do
|
32
|
+
drop_table :orders
|
33
|
+
drop_table :versions
|
34
|
+
end
|
35
|
+
ActiveRecord::Migration.verbose = true
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'paper_trail_globalid' do
|
39
|
+
before do
|
40
|
+
GlobalID.app = "App"
|
41
|
+
@admin = Admin.create(name: 'admin')
|
42
|
+
@order = Order.create!(order_number: 'ord_1', total: 100)
|
43
|
+
@version = @order.versions.last
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'paper_trail' do
|
47
|
+
describe 'class_methods' do
|
48
|
+
describe 'PaperTrail.actor' do
|
49
|
+
context 'when value for whodunnit is object of ActiveRecord' do
|
50
|
+
it 'returns object' do
|
51
|
+
PaperTrail.whodunnit=@admin
|
52
|
+
expect(PaperTrail.actor).to eq(@admin)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when value for whodunnit is not an object of ActiveRecord' do
|
57
|
+
it 'returns value itself' do
|
58
|
+
PaperTrail.whodunnit="test"
|
59
|
+
expect(PaperTrail.actor).to eq("test")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '.whodunnit' do
|
65
|
+
context 'when value for whodunnit is object of ActiveRecord' do
|
66
|
+
it 'returns global id' do
|
67
|
+
PaperTrail.whodunnit=@admin
|
68
|
+
expect(PaperTrail.paper_trail_store[:whodunnit]).to eq(@admin.to_gid)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'when value for whodunnit is not an object of ActiveRecord' do
|
73
|
+
it 'returns value itself' do
|
74
|
+
PaperTrail.whodunnit="test"
|
75
|
+
expect(PaperTrail.paper_trail_store[:whodunnit]).to eq("test")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'version_concern' do
|
83
|
+
describe 'instance_methods' do
|
84
|
+
describe '#actor' do
|
85
|
+
context 'when value for whodunnit is object of ActiveRecord' do
|
86
|
+
it 'returns object' do
|
87
|
+
@version.whodunnit = @admin
|
88
|
+
@version.save
|
89
|
+
expect(@version.actor).to eq(@admin)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'when value for whodunnit is not an object of ActiveRecord' do
|
94
|
+
it 'returns value itself' do
|
95
|
+
@version.whodunnit = "test"
|
96
|
+
@version.save
|
97
|
+
expect(@version.actor).to eq("test")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '.whodunnit' do
|
103
|
+
context 'when value for whodunnit is object of ActiveRecord' do
|
104
|
+
it 'returns global id' do
|
105
|
+
@version.whodunnit = @admin
|
106
|
+
@version.save
|
107
|
+
expect(@version.whodunnit).to eq(@admin.to_gid.to_s)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'when value for whodunnit is not an object of ActiveRecord' do
|
112
|
+
it 'returns value itself' do
|
113
|
+
@version.whodunnit = "test"
|
114
|
+
@version.save
|
115
|
+
expect(@version.whodunnit).to eq("test")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
16
|
+
# users commonly want.
|
17
|
+
#
|
18
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
|
+
require 'sqlite3'
|
20
|
+
require 'active_record'
|
21
|
+
require 'byebug'
|
22
|
+
require_relative './../lib/paper_trail-globalid.rb'
|
23
|
+
require_relative './support/database_connection.rb'
|
24
|
+
RSpec.configure do |config|
|
25
|
+
# rspec-expectations config goes here. You can use an alternate
|
26
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
27
|
+
# assertions if you prefer.
|
28
|
+
config.expect_with :rspec do |expectations|
|
29
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
30
|
+
# and `failure_message` of custom matchers include text for helper methods
|
31
|
+
# defined using `chain`, e.g.:
|
32
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
33
|
+
# # => "be bigger than 2 and smaller than 4"
|
34
|
+
# ...rather than:
|
35
|
+
# # => "be bigger than 2"
|
36
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
37
|
+
end
|
38
|
+
|
39
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
40
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
41
|
+
config.mock_with :rspec do |mocks|
|
42
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
43
|
+
# a real object. This is generally recommended, and will default to
|
44
|
+
# `true` in RSpec 4.
|
45
|
+
mocks.verify_partial_doubles = true
|
46
|
+
end
|
47
|
+
|
48
|
+
# The settings below are suggested to provide a good initial experience
|
49
|
+
# with RSpec, but feel free to customize to your heart's content.
|
50
|
+
=begin
|
51
|
+
# These two settings work together to allow you to limit a spec run
|
52
|
+
# to individual examples or groups you care about by tagging them with
|
53
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
54
|
+
# get run.
|
55
|
+
config.filter_run :focus
|
56
|
+
config.run_all_when_everything_filtered = true
|
57
|
+
|
58
|
+
# Allows RSpec to persist some state between runs in order to support
|
59
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
60
|
+
# you configure your source control system to ignore this file.
|
61
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
62
|
+
|
63
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
64
|
+
# recommended. For more details, see:
|
65
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
66
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
67
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
68
|
+
config.disable_monkey_patching!
|
69
|
+
|
70
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
71
|
+
# be too noisy due to issues in dependencies.
|
72
|
+
config.warnings = true
|
73
|
+
|
74
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
75
|
+
# file, and it's useful to allow more verbose output when running an
|
76
|
+
# individual spec file.
|
77
|
+
if config.files_to_run.one?
|
78
|
+
# Use the documentation formatter for detailed output,
|
79
|
+
# unless a formatter has already been configured
|
80
|
+
# (e.g. via a command-line flag).
|
81
|
+
config.default_formatter = 'doc'
|
82
|
+
end
|
83
|
+
|
84
|
+
# Print the 10 slowest examples and example groups at the
|
85
|
+
# end of the spec run, to help surface which specs are running
|
86
|
+
# particularly slow.
|
87
|
+
config.profile_examples = 10
|
88
|
+
|
89
|
+
# Run specs in random order to surface order dependencies. If you find an
|
90
|
+
# order dependency and want to debug it, you can fix the order by providing
|
91
|
+
# the seed, which is printed after each run.
|
92
|
+
# --seed 1234
|
93
|
+
config.order = :random
|
94
|
+
|
95
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
96
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
97
|
+
# test failures related to randomization by passing the same `--seed` value
|
98
|
+
# as the one that triggered the failure.
|
99
|
+
Kernel.srand config.seed
|
100
|
+
=end
|
101
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paper_trail-globalid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ankit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: paper_trail
|
@@ -80,6 +80,90 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.3.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.3.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coveralls
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.8.2
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.8.2
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: activerecord
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 3.2.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 3.2.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: activesupport
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 3.2.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 3.2.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: sqlite3
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: byebug
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
83
167
|
description: An extension to paper_trail, using this you can fetch actual object who
|
84
168
|
was responsible for this change
|
85
169
|
email:
|
@@ -98,6 +182,11 @@ files:
|
|
98
182
|
- lib/paper_trail_globalid/version.rb
|
99
183
|
- lib/paper_trail_globalid/version_concern.rb
|
100
184
|
- paper_trail_globalid.gemspec
|
185
|
+
- spec/paper_trail_globalid_spec.rb
|
186
|
+
- spec/spec_helper.rb
|
187
|
+
- spec/support/admin.rb
|
188
|
+
- spec/support/database_connection.rb
|
189
|
+
- spec/support/order.rb
|
101
190
|
homepage: https://github.com/ankit1910/paper_trail-globalid
|
102
191
|
licenses:
|
103
192
|
- MIT
|
@@ -113,9 +202,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
202
|
version: '0'
|
114
203
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
204
|
requirements:
|
116
|
-
- - '
|
205
|
+
- - '>='
|
117
206
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
207
|
+
version: '0'
|
119
208
|
requirements: []
|
120
209
|
rubyforge_project:
|
121
210
|
rubygems_version: 2.2.2
|
@@ -123,4 +212,9 @@ signing_key:
|
|
123
212
|
specification_version: 4
|
124
213
|
summary: An extension to paper_trail, using this you can fetch actual object who was
|
125
214
|
responsible for this change
|
126
|
-
test_files:
|
215
|
+
test_files:
|
216
|
+
- spec/paper_trail_globalid_spec.rb
|
217
|
+
- spec/spec_helper.rb
|
218
|
+
- spec/support/admin.rb
|
219
|
+
- spec/support/database_connection.rb
|
220
|
+
- spec/support/order.rb
|