pravangi 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +51 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +55 -0
- data/Rakefile +11 -0
- data/lib/generators/pravangi/USAGE +2 -0
- data/lib/generators/pravangi/install_generator.rb +31 -0
- data/lib/generators/pravangi/templates/create_pending_approvals.rb +11 -0
- data/lib/pravangi/models/pending_approval.rb +34 -0
- data/lib/pravangi/requires_approval.rb +62 -0
- data/lib/pravangi/version.rb +3 -0
- data/lib/pravangi.rb +12 -0
- data/pravangi.gemspec +39 -0
- data/spec/lib/pravangi/requires_approval_spec.rb +5 -0
- data/spec/lib/pravangi_spec.rb +238 -0
- data/spec/spec_helper.rb +96 -0
- metadata +191 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 05996bcd1b0b07af131b72d7a2172e5943b1355b
|
4
|
+
data.tar.gz: 0418b717faa2732a08211fd370dc885577e4d6b1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 510296350eb12c18de1725e093cc95f96fa4103c1204d3c3b856415e36afab051ac3a9a516b584242321d23834e858fa148598fd50b6a0ae05fec0f25457e85b
|
7
|
+
data.tar.gz: 1a8ad67b8d426b0c62c00a7790d3c483da34adbb05d8a4c1d456ca927516f7a491511bda1c23b50e36a66966b0d57faa9db227510816621573865ff665779b50
|
data/.gitignore
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
/.config
|
19
|
+
/coverage/
|
20
|
+
/InstalledFiles
|
21
|
+
/pkg/
|
22
|
+
/spec/reports/
|
23
|
+
/test/tmp/
|
24
|
+
/test/version_tmp/
|
25
|
+
/tmp/
|
26
|
+
spec/support/db.sqlite
|
27
|
+
|
28
|
+
## Specific to RubyMotion:
|
29
|
+
.dat*
|
30
|
+
.repl_history
|
31
|
+
build/
|
32
|
+
|
33
|
+
## Documentation cache and generated files:
|
34
|
+
/.yardoc/
|
35
|
+
/_yardoc/
|
36
|
+
/doc/
|
37
|
+
/rdoc/
|
38
|
+
|
39
|
+
## Environment normalisation:
|
40
|
+
/.bundle/
|
41
|
+
/vendor/bundle
|
42
|
+
/lib/bundler/man/
|
43
|
+
|
44
|
+
# for a library or gem, you might want to ignore these files since the code is
|
45
|
+
# intended to run in multiple environments; otherwise, check them in:
|
46
|
+
# Gemfile.lock
|
47
|
+
# .ruby-version
|
48
|
+
# .ruby-gemset
|
49
|
+
|
50
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
51
|
+
.rvmrc
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Metaware Labs
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Pravangi (ਪ੍ਰਵਾਨਗੀ) [![Build Status](https://travis-ci.org/metaware/pravangi.svg?branch=master)](https://travis-ci.org/metaware/pravangi) [![Code Climate](https://codeclimate.com/github/metaware/pravangi/badges/gpa.svg)](https://codeclimate.com/github/metaware/pravangi)
|
2
|
+
|
3
|
+
ਪ੍ਰਵਾਨਗੀ (pravangi) : Let's you add an approval process on top of your models/objects. Assume you have an object which is in an `approved` state, you want any subsequent changes to this model to go into a review queue and have someone review these changes until they are actually committed to the object.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
### Rails 3 & 4
|
8
|
+
|
9
|
+
1. Add pravangi to your `Gemfile`.
|
10
|
+
|
11
|
+
`gem 'pravangi'`
|
12
|
+
|
13
|
+
2. Generate a migration which will add a `pending_approvals` table to your database.
|
14
|
+
|
15
|
+
`bundle exec rails generate pravangi:install`
|
16
|
+
|
17
|
+
3. Run the migration.
|
18
|
+
|
19
|
+
`bundle exec rake db:migrate`
|
20
|
+
|
21
|
+
4. Add `requires_approval` to the models you want to track.
|
22
|
+
|
23
|
+
## API Summary
|
24
|
+
|
25
|
+
When you declare `requires_approval` in your model, you get these methods:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
class Article < ActiveRecord::Base
|
29
|
+
requires_approval # you can pass various options here
|
30
|
+
end
|
31
|
+
|
32
|
+
# check if this object requires any approval?
|
33
|
+
article.pending_approval?
|
34
|
+
```
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.
|
38
|
+
|
39
|
+
**You get extra attention, if your PR includes specs/tests.**
|
40
|
+
|
41
|
+
1. Fork or clone the project.
|
42
|
+
2. Create your feature branch (`$ git checkout -b my-new-feature`)
|
43
|
+
3. Install the dependencies by doing: `$ bundle install` in the project directory.
|
44
|
+
4. Add your bug fixes or new feature code.
|
45
|
+
- New features should include new specs/tests.
|
46
|
+
- Bug fixes should ideally include exposing specs/tests.
|
47
|
+
5. Commit your changes (`$ git commit -am 'Add some feature'`)
|
48
|
+
6. Push to the branch (`$ git push origin my-new-feature`)
|
49
|
+
7. Open your Pull Request!
|
50
|
+
|
51
|
+
|
52
|
+
## License
|
53
|
+
Copyright (c) 2013 [Jasdeep Singh](http://jasdeep.ca) ([Metaware Labs Inc](http://metawarelabs.com/))
|
54
|
+
|
55
|
+
Licensed under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
|
4
|
+
module Pravangi
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
include ::Rails::Generators::Migration
|
7
|
+
|
8
|
+
source_root File.expand_path('../templates', __FILE__)
|
9
|
+
|
10
|
+
def create_migration_file
|
11
|
+
add_pravangi_versions_migration('create_pending_approvals')
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.next_migration_number(dirname)
|
15
|
+
::ActiveRecord::Generators::Base.next_migration_number(dirname)
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
def add_pravangi_versions_migration(template)
|
20
|
+
migration_dir = File.expand_path('db/migrate')
|
21
|
+
|
22
|
+
unless self.class.migration_exists?(migration_dir, template)
|
23
|
+
migration_template "#{template}.rb", "db/migrate/#{template}.rb"
|
24
|
+
else
|
25
|
+
warn("ALERT: Migration already exists named '#{template}'." +
|
26
|
+
" Please check your migrations directory before re-running")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class CreatePendingApprovals < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :pending_approvals do |t|
|
4
|
+
t.string :resource_type, null: false
|
5
|
+
t.integer :resource_id, null: false
|
6
|
+
t.text :object_changes
|
7
|
+
t.text :raw_object, null: false
|
8
|
+
t.timestamps null: false
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module Pravangi
|
4
|
+
class PendingApproval < ::ActiveRecord::Base
|
5
|
+
|
6
|
+
belongs_to :resource, polymorphic: true
|
7
|
+
serialize :object_changes, Hash
|
8
|
+
before_save :skip_attributes
|
9
|
+
|
10
|
+
def as_object
|
11
|
+
@object ||= YAML.load(raw_object)
|
12
|
+
end
|
13
|
+
|
14
|
+
def changed_object_attributes
|
15
|
+
self.object_changes.keys
|
16
|
+
end
|
17
|
+
|
18
|
+
def commit
|
19
|
+
resource.skip_approval = true
|
20
|
+
object_changes.each do |k,v|
|
21
|
+
resource[k] = v[1]
|
22
|
+
end
|
23
|
+
resource.save
|
24
|
+
resource.reload
|
25
|
+
end
|
26
|
+
|
27
|
+
def skip_attributes
|
28
|
+
if self.resource.class.pravangi_options[:skip_attributes]
|
29
|
+
object_changes.except(*self.resource.class.pravangi_options[:skip_attributes])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
module Pravangi
|
4
|
+
module Model
|
5
|
+
|
6
|
+
extend ::ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do |base|
|
9
|
+
base.send :extend, ClassMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
class_methods do
|
13
|
+
|
14
|
+
def requires_approval(options = {})
|
15
|
+
class_attribute :pravangi_options
|
16
|
+
self.pravangi_options = options.dup
|
17
|
+
|
18
|
+
attr_accessor :skip_approval
|
19
|
+
|
20
|
+
class_eval do
|
21
|
+
def should_track_approval?
|
22
|
+
self.send(self.class.pravangi_options[:if]) && !skip_approval
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
before_update :track_approval, if: :should_track_approval?
|
27
|
+
|
28
|
+
has_many :pending_approvals,
|
29
|
+
lambda { order('id ASC') },
|
30
|
+
class_name: 'Pravangi::PendingApproval',
|
31
|
+
as: :resource
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def pravangi_object_changes
|
37
|
+
self.changes.except(*self.class.pravangi_options[:skip_attributes])
|
38
|
+
end
|
39
|
+
|
40
|
+
def track_approval
|
41
|
+
warn('Pravangi: The record cannot be updated, because it requires approval.')
|
42
|
+
if changed?
|
43
|
+
original = self.clone
|
44
|
+
original.pending_approvals.build(
|
45
|
+
object_changes: original.pravangi_object_changes,
|
46
|
+
raw_object: original.to_yaml
|
47
|
+
).save
|
48
|
+
self.reload
|
49
|
+
|
50
|
+
skip_attributes = Array(self.class.pravangi_options[:skip_attributes])
|
51
|
+
skip_attributes.each do |attr|
|
52
|
+
self[attr] = original[attr]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def pending_approval?
|
58
|
+
pending_approvals.present?
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
data/lib/pravangi.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'pravangi/version'
|
3
|
+
require 'pravangi/requires_approval'
|
4
|
+
require 'pravangi/models/pending_approval'
|
5
|
+
require 'active_record'
|
6
|
+
|
7
|
+
module Pravangi
|
8
|
+
end
|
9
|
+
|
10
|
+
ActiveSupport.on_load(:active_record) do
|
11
|
+
include Pravangi::Model
|
12
|
+
end
|
data/pravangi.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pravangi/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pravangi"
|
8
|
+
spec.version = Pravangi::VERSION
|
9
|
+
spec.authors = ["Jasdeep Singh"]
|
10
|
+
spec.email = ["narang.jasdeep@gmail.com"]
|
11
|
+
spec.description = %q{ਪ੍ਰਵਾਨਗੀ (pravangi) : Approval}
|
12
|
+
spec.summary = %q{ਪ੍ਰਵਾਨਗੀ (pravangi) : Approval}
|
13
|
+
spec.homepage = "http://metawarelabs.com"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
spec.add_development_dependency "railties"
|
26
|
+
|
27
|
+
spec.add_dependency 'activerecord'
|
28
|
+
|
29
|
+
unless defined?(JRUBY_VERSION)
|
30
|
+
spec.add_dependency 'sqlite3'
|
31
|
+
spec.add_dependency 'mysql2'
|
32
|
+
spec.add_dependency 'pg'
|
33
|
+
else
|
34
|
+
spec.add_dependency 'activerecord-jdbcsqlite3-adapter'
|
35
|
+
spec.add_dependency 'activerecord-jdbcpostgresql-adapter'
|
36
|
+
spec.add_dependency 'activerecord-jdbcmysql-adapter'
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,238 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pravangi do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
|
7
|
+
ActiveRecord::Base.establish_connection({
|
8
|
+
adapter: :sqlite3,
|
9
|
+
database: ':memory:'
|
10
|
+
})
|
11
|
+
|
12
|
+
ActiveRecord::Schema.define do
|
13
|
+
create_table :posts do |table|
|
14
|
+
table.column :title, :string
|
15
|
+
table.column :body, :string
|
16
|
+
table.column :state, :string
|
17
|
+
table.column :created_at, :datetime
|
18
|
+
table.column :updated_at, :datetime
|
19
|
+
end
|
20
|
+
|
21
|
+
CreatePendingApprovals.new.change
|
22
|
+
end
|
23
|
+
|
24
|
+
class Post < ActiveRecord::Base
|
25
|
+
requires_approval if: :approved?, skip_attributes: :updated_at
|
26
|
+
|
27
|
+
def approved?
|
28
|
+
self.state == 'approved'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when creating a new' do
|
35
|
+
|
36
|
+
let(:post) { Post.create(title: 'metaware', state: 'approved') }
|
37
|
+
|
38
|
+
it 'record gets created without the need for approval' do
|
39
|
+
expect(post.title).to eq('metaware')
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'record there are no pending approvals required' do
|
43
|
+
expect(post.pending_approvals).to be_empty
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'existing record' do
|
49
|
+
|
50
|
+
let(:post) { Post.create(title: 'metaware', state: 'approved') }
|
51
|
+
|
52
|
+
before(:each) do
|
53
|
+
post.title = 'new metaware'
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'that requires approval' do
|
57
|
+
|
58
|
+
before(:each) do
|
59
|
+
post.save
|
60
|
+
post.reload
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should not update or change after saving' do
|
64
|
+
expect(post.title).to eq('metaware')
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should prepare a trail of pending approvals' do
|
68
|
+
expect(post.title).to eq('metaware')
|
69
|
+
expect(post.pending_approvals).to be_present
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should allow to enquire if there are pending approvals' do
|
73
|
+
expect(post.pending_approval?).to eq(true)
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'tracks object_changes' do
|
77
|
+
|
78
|
+
it 'should populate the object_changes column' do
|
79
|
+
expect(post.pending_approvals.last.object_changes).to be_present
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should verify the object_changes are stored in a Hash' do
|
83
|
+
expect(post.pending_approvals.last.object_changes).to be_a(Hash)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should be possible to find out what attributes changed' do
|
87
|
+
expect(post.pending_approvals.last.object_changes).to include('title')
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'raw_object' do
|
93
|
+
|
94
|
+
it 'should populate raw_object column' do
|
95
|
+
expect(post.pending_approvals.last.raw_object).to be_present
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'serialized' do
|
99
|
+
|
100
|
+
let(:serialized_object) { YAML.load(post.pending_approvals.last.raw_object) }
|
101
|
+
|
102
|
+
it 'should be able to serialize raw_object back to object' do
|
103
|
+
expect(serialized_object).to be_a(Post)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should have the correct (new) attributes' do
|
107
|
+
expect(serialized_object.title).to eq('new metaware')
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'multiple changes' do
|
117
|
+
|
118
|
+
before(:each) do
|
119
|
+
post.title = 'metaware 2'
|
120
|
+
post.save
|
121
|
+
post.title = 'metaware 3'
|
122
|
+
post.save
|
123
|
+
post.reload
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should recognize 2 pending approvals' do
|
127
|
+
expect(post.pending_approvals.count).to eq(2)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should recognize approvals in order' do
|
131
|
+
pending_approvals = post.pending_approvals
|
132
|
+
expect(pending_approvals.first.as_object.title).to eq('metaware 2')
|
133
|
+
expect(pending_approvals.last.as_object.title).to eq('metaware 3')
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should be able to apply all changes to bring the object to desired state' do
|
137
|
+
post.pending_approvals.each(&:commit)
|
138
|
+
post.reload
|
139
|
+
expect(post.title).to eq('metaware 3')
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'deserialized object' do
|
145
|
+
|
146
|
+
before(:each) do
|
147
|
+
post.title = 'metaware 2'
|
148
|
+
post.save
|
149
|
+
post.title = 'metaware 3'
|
150
|
+
post.save
|
151
|
+
post.reload
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should have the anticipated changes' do
|
155
|
+
first = post.pending_approvals.first.as_object
|
156
|
+
second = post.pending_approvals.last.as_object
|
157
|
+
|
158
|
+
expect(first.title).to eq('metaware 2')
|
159
|
+
expect(second.title).to eq('metaware 3')
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
context '#commit' do
|
165
|
+
|
166
|
+
before(:each) do
|
167
|
+
post.title = 'metaware 2'
|
168
|
+
post.save
|
169
|
+
post.reload
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should be able to revert the object back to the requested state' do
|
173
|
+
post.pending_approvals.last.commit
|
174
|
+
post.reload
|
175
|
+
expect(post.title).to eq('metaware 2')
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
context 'does not requires approval' do
|
181
|
+
|
182
|
+
before(:each) do
|
183
|
+
expect(post).to receive(:approved?).and_return(false)
|
184
|
+
post.save
|
185
|
+
post.reload
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'should just commit the changes' do
|
189
|
+
expect(post.title).to eq('new metaware')
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'should return false when approval is not required' do
|
193
|
+
expect(post.pending_approval?).to eq(false)
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
|
200
|
+
context 'when taking an object to satisfying if condition' do
|
201
|
+
|
202
|
+
let(:post) { Post.create(title: 'metaware', state: 'draft') }
|
203
|
+
|
204
|
+
it 'should trigger approval tracking only when the object is in a satisfying state' do
|
205
|
+
skip('the following is a failing test case, however not an immediate concern as we are doing state change as an isolated action on our objects')
|
206
|
+
# post.title = 'metaware draft'
|
207
|
+
# post.state = 'approved'
|
208
|
+
# post.save
|
209
|
+
# post.reload
|
210
|
+
# expect(post.title).to eq('metaware draft')
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
context 'skip_attributes' do
|
216
|
+
|
217
|
+
let(:post) { Post.create(title: 'metaware', state: 'approved') }
|
218
|
+
|
219
|
+
it 'should allow the capability to skip certain attributes from the approval process' do
|
220
|
+
original_updated_at = post.updated_at
|
221
|
+
post.updated_at = post.updated_at + 1.hour
|
222
|
+
post.save
|
223
|
+
post.reload
|
224
|
+
expect(post.updated_at).to eq(original_updated_at + 1.hour)
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'should not track the skipped attributes' do
|
228
|
+
post.title = 'metaware unapprovable'
|
229
|
+
post.updated_at = post.updated_at + 10.minutes
|
230
|
+
post.save
|
231
|
+
post.reload
|
232
|
+
expect(post.pending_approvals.last.object_changes).to include(:title)
|
233
|
+
expect(post.pending_approvals.last.object_changes).to_not include(:updated_at)
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,96 @@
|
|
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
|
+
|
20
|
+
require 'active_record'
|
21
|
+
require 'pravangi'
|
22
|
+
require 'generators/pravangi/templates/create_pending_approvals'
|
23
|
+
|
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
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
59
|
+
# recommended. For more details, see:
|
60
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
61
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
62
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
63
|
+
config.disable_monkey_patching!
|
64
|
+
|
65
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
66
|
+
# be too noisy due to issues in dependencies.
|
67
|
+
config.warnings = true
|
68
|
+
|
69
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
70
|
+
# file, and it's useful to allow more verbose output when running an
|
71
|
+
# individual spec file.
|
72
|
+
if config.files_to_run.one?
|
73
|
+
# Use the documentation formatter for detailed output,
|
74
|
+
# unless a formatter has already been configured
|
75
|
+
# (e.g. via a command-line flag).
|
76
|
+
config.default_formatter = 'doc'
|
77
|
+
end
|
78
|
+
|
79
|
+
# Print the 10 slowest examples and example groups at the
|
80
|
+
# end of the spec run, to help surface which specs are running
|
81
|
+
# particularly slow.
|
82
|
+
config.profile_examples = 10
|
83
|
+
|
84
|
+
# Run specs in random order to surface order dependencies. If you find an
|
85
|
+
# order dependency and want to debug it, you can fix the order by providing
|
86
|
+
# the seed, which is printed after each run.
|
87
|
+
# --seed 1234
|
88
|
+
config.order = :random
|
89
|
+
|
90
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
91
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
92
|
+
# test failures related to randomization by passing the same `--seed` value
|
93
|
+
# as the one that triggered the failure.
|
94
|
+
Kernel.srand config.seed
|
95
|
+
=end
|
96
|
+
end
|
metadata
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pravangi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jasdeep Singh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: railties
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activerecord
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sqlite3
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: mysql2
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pg
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: "ਪ੍ਰਵਾਨਗੀ (pravangi) : Approval"
|
140
|
+
email:
|
141
|
+
- narang.jasdeep@gmail.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
148
|
+
- ".travis.yml"
|
149
|
+
- Gemfile
|
150
|
+
- LICENSE
|
151
|
+
- README.md
|
152
|
+
- Rakefile
|
153
|
+
- lib/generators/pravangi/USAGE
|
154
|
+
- lib/generators/pravangi/install_generator.rb
|
155
|
+
- lib/generators/pravangi/templates/create_pending_approvals.rb
|
156
|
+
- lib/pravangi.rb
|
157
|
+
- lib/pravangi/models/pending_approval.rb
|
158
|
+
- lib/pravangi/requires_approval.rb
|
159
|
+
- lib/pravangi/version.rb
|
160
|
+
- pravangi.gemspec
|
161
|
+
- spec/lib/pravangi/requires_approval_spec.rb
|
162
|
+
- spec/lib/pravangi_spec.rb
|
163
|
+
- spec/spec_helper.rb
|
164
|
+
homepage: http://metawarelabs.com
|
165
|
+
licenses:
|
166
|
+
- MIT
|
167
|
+
metadata: {}
|
168
|
+
post_install_message:
|
169
|
+
rdoc_options: []
|
170
|
+
require_paths:
|
171
|
+
- lib
|
172
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
177
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
requirements: []
|
183
|
+
rubyforge_project:
|
184
|
+
rubygems_version: 2.4.6
|
185
|
+
signing_key:
|
186
|
+
specification_version: 4
|
187
|
+
summary: "ਪ੍ਰਵਾਨਗੀ (pravangi) : Approval"
|
188
|
+
test_files:
|
189
|
+
- spec/lib/pravangi/requires_approval_spec.rb
|
190
|
+
- spec/lib/pravangi_spec.rb
|
191
|
+
- spec/spec_helper.rb
|