acts_as_approvable 0.1.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/.gitignore +4 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +5 -0
  4. data/Appraisals +22 -0
  5. data/CHANGELOG +76 -0
  6. data/Gemfile +3 -0
  7. data/Gemfile.lock +84 -0
  8. data/MIT-LICENSE +2 -2
  9. data/README.md +146 -0
  10. data/Rakefile +90 -7
  11. data/TODO.md +30 -0
  12. data/VERSION +1 -0
  13. data/acts_as_approvable.gemspec +40 -0
  14. data/features/create_approval.feature +36 -0
  15. data/features/destroy_approval.feature +19 -0
  16. data/features/reset_approval.feature +13 -0
  17. data/features/step_definitions/cucumber_steps.rb +132 -0
  18. data/features/support/env.rb +14 -0
  19. data/features/support/large.txt +29943 -0
  20. data/features/support/second_large.txt +31798 -0
  21. data/features/update_approval.feature +48 -0
  22. data/gemfiles/Gemfile.ci +14 -0
  23. data/gemfiles/Gemfile.ci.lock +98 -0
  24. data/gemfiles/mysql2.gemfile +7 -0
  25. data/gemfiles/mysql2.gemfile.lock +86 -0
  26. data/gemfiles/rails2.gemfile +8 -0
  27. data/gemfiles/rails2.gemfile.lock +86 -0
  28. data/gemfiles/rails30.gemfile +9 -0
  29. data/gemfiles/rails30.gemfile.lock +124 -0
  30. data/gemfiles/rails31.gemfile +9 -0
  31. data/gemfiles/rails31.gemfile.lock +135 -0
  32. data/gemfiles/sqlite.gemfile +7 -0
  33. data/generators/acts_as_approvable/USAGE +3 -0
  34. data/generators/acts_as_approvable/acts_as_approvable_generator.rb +81 -0
  35. data/generators/acts_as_approvable/templates/approvals.js +71 -0
  36. data/generators/acts_as_approvable/templates/approvals_controller.rb +91 -0
  37. data/generators/acts_as_approvable/templates/create_approvals.rb +27 -0
  38. data/generators/acts_as_approvable/templates/initializer.rb +3 -0
  39. data/generators/acts_as_approvable/templates/jquery.form.js +101 -0
  40. data/generators/acts_as_approvable/templates/views/erb/_owner_select.html.erb +4 -0
  41. data/generators/acts_as_approvable/templates/views/erb/_table.html.erb +26 -0
  42. data/generators/acts_as_approvable/templates/views/erb/index.html.erb +17 -0
  43. data/generators/acts_as_approvable/templates/views/haml/_owner_select.html.haml +3 -0
  44. data/generators/acts_as_approvable/templates/views/haml/_table.html.haml +19 -0
  45. data/generators/acts_as_approvable/templates/views/haml/index.html.haml +15 -0
  46. data/init.rb +1 -0
  47. data/lib/acts_as_approvable.rb +96 -2
  48. data/lib/acts_as_approvable/approval.rb +205 -11
  49. data/lib/acts_as_approvable/error.rb +34 -0
  50. data/lib/acts_as_approvable/model.rb +60 -0
  51. data/lib/acts_as_approvable/model/class_methods.rb +63 -0
  52. data/lib/acts_as_approvable/model/create_instance_methods.rb +88 -0
  53. data/lib/acts_as_approvable/model/destroy_instance_methods.rb +38 -0
  54. data/lib/acts_as_approvable/model/instance_methods.rb +107 -0
  55. data/lib/acts_as_approvable/model/update_instance_methods.rb +61 -0
  56. data/lib/acts_as_approvable/ownership.rb +141 -0
  57. data/lib/acts_as_approvable/railtie.rb +7 -0
  58. data/lib/acts_as_approvable/version.rb +1 -8
  59. data/lib/generators/acts_as_approvable/USAGE +1 -0
  60. data/lib/generators/acts_as_approvable/acts_as_approvable_generator.rb +68 -0
  61. data/lib/generators/acts_as_approvable/base.rb +30 -0
  62. data/lib/generators/acts_as_approvable/templates/approvals.js +71 -0
  63. data/lib/generators/acts_as_approvable/templates/approvals_controller.rb +91 -0
  64. data/lib/generators/acts_as_approvable/templates/create_approvals.rb +27 -0
  65. data/lib/generators/acts_as_approvable/templates/jquery.form.js +101 -0
  66. data/lib/generators/erb/acts_as_approvable_generator.rb +33 -0
  67. data/lib/generators/erb/templates/_owner_select.html.erb +4 -0
  68. data/lib/generators/erb/templates/_table.html.erb +26 -0
  69. data/lib/generators/erb/templates/index.html.erb +17 -0
  70. data/lib/generators/haml/acts_as_approvable_generator.rb +33 -0
  71. data/lib/generators/haml/templates/_owner_select.html.haml +3 -0
  72. data/lib/generators/haml/templates/_table.html.haml +19 -0
  73. data/lib/generators/haml/templates/index.html.haml +15 -0
  74. data/lib/tasks/acts_as_approvable.rake +4 -0
  75. data/rails/init.rb +1 -0
  76. data/spec/acts_as_approvable/approval_spec.rb +614 -0
  77. data/spec/acts_as_approvable/model/class_methods_spec.rb +219 -0
  78. data/spec/acts_as_approvable/model/create_instance_methods_spec.rb +169 -0
  79. data/spec/acts_as_approvable/model/destroy_instance_methods_spec.rb +71 -0
  80. data/spec/acts_as_approvable/model/instance_methods_spec.rb +328 -0
  81. data/spec/acts_as_approvable/model/update_instance_methods_spec.rb +111 -0
  82. data/spec/acts_as_approvable/model_spec.rb +113 -0
  83. data/spec/acts_as_approvable/ownership/class_methods_spec.rb +134 -0
  84. data/spec/acts_as_approvable/ownership/instance_methods_spec.rb +32 -0
  85. data/spec/acts_as_approvable/ownership_spec.rb +52 -0
  86. data/spec/acts_as_approvable_spec.rb +31 -0
  87. data/spec/spec_helper.rb +51 -0
  88. data/spec/support/database.rb +49 -0
  89. data/spec/support/database.yml +12 -0
  90. data/spec/support/matchers.rb +87 -0
  91. data/spec/support/models.rb +67 -0
  92. data/spec/support/schema.rb +54 -0
  93. metadata +375 -58
  94. data/README.rdoc +0 -38
  95. data/lib/acts_as_approvable/approver.rb +0 -76
  96. data/lib/generators/acts_as_approvable/install_generator.rb +0 -28
  97. data/lib/generators/acts_as_approvable/templates/install.rb +0 -16
@@ -0,0 +1,4 @@
1
+ debug.log
2
+ spec/*.db
3
+ coverage/
4
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format doc
2
+ --color
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ gemfile: gemfiles/Gemfile.ci
@@ -0,0 +1,22 @@
1
+ appraise 'rails2' do
2
+ gem 'activerecord', '~> 2.3'
3
+ gem 'sqlite3'
4
+ end
5
+
6
+ if RUBY_VERSION =~ /^1\.9/
7
+ appraise 'rails30' do
8
+ gem 'activerecord', '~> 3.0.0'
9
+ gem 'railties', '~> 3.0.0'
10
+ gem 'sqlite3'
11
+ end
12
+
13
+ appraise 'rails31' do
14
+ gem 'activerecord', '~> 3.1.0'
15
+ gem 'railties', '~> 3.1.0'
16
+ gem 'sqlite3'
17
+ end
18
+ end
19
+
20
+ appraise 'mysql2' do
21
+ gem 'mysql2', '~> 0.2.18'
22
+ end
@@ -0,0 +1,76 @@
1
+ == 0.7.0
2
+
3
+ * Support approvals for record deletions.
4
+ * Only check `#stale?` if the approval is for an update.
5
+ * Configuration option for disabling the stale check.
6
+
7
+ == 0.6.9
8
+
9
+ * Fix generator templates using `select` instead of `select_tag`
10
+ * `reset!` to push a create approval back to a valid pending state
11
+ * Refactor Ownership setup to use a source class instead of monkey-patching
12
+ to override owner retrieval methods. Fixes an issue with rails development
13
+ mode.
14
+ * General cleanup
15
+
16
+ == 0.6.8.1
17
+
18
+ * Bad gem push...
19
+
20
+ == 0.6.8
21
+
22
+ * Fixed issue where approval state would be checked if the local state field
23
+ was present but not the value being checked.
24
+ * Reorganized `ActsAsApprovable::Model` into seperate files.
25
+ * `.acts_as_approvable` is the only method that should be available until
26
+ called. Moved other class methods into a module that is included on
27
+ configuration.
28
+ * Moved from Test::Unit to RSpec
29
+ * Renamed `can_save?` to `able_to_save?`
30
+ * Specify larger field size for original and object columns (16MB)
31
+
32
+ == 0.6.6
33
+
34
+ * `#pending_changes?` should not be true if there are no pending update
35
+ approvals.
36
+
37
+ == 0.6.5
38
+
39
+ * Copy javascripts if `--scripts` is passed to the generator. AJAXifies the
40
+ views.
41
+
42
+ == 0.6.4
43
+
44
+ * around_filters cannot render content
45
+
46
+ == 0.6.3.3
47
+
48
+ * Don't call #state on nil objects
49
+
50
+ == 0.6.3.2
51
+
52
+ * Fix the Rails 2 initializer
53
+
54
+ == 0.6.3.1
55
+
56
+ * Update rails 2 generator with previous fix
57
+ * Fix test helper
58
+
59
+ == 0.6.3
60
+
61
+ * Correct state parameter validation for negative numbers
62
+
63
+ == 0.6.2
64
+
65
+ * Rename main file to match gem name
66
+
67
+ == 0.6.1
68
+
69
+ * Change gem name to 'acts-as-approvable'
70
+
71
+ == 0.6
72
+
73
+ * Convert to a gem
74
+ * Support for Rails 3.x
75
+ * Validate state parameter is an integer before using
76
+ * Correct spelling of `current_user` in controller templates
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,84 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ acts_as_approvable (0.7.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ activerecord (2.3.14)
10
+ activesupport (= 2.3.14)
11
+ activesupport (2.3.14)
12
+ appraisal (0.4.1)
13
+ bundler
14
+ rake
15
+ binding_of_caller (0.6.7)
16
+ builder (3.0.0)
17
+ coderay (1.0.5)
18
+ cucumber (1.1.9)
19
+ builder (>= 2.1.2)
20
+ diff-lcs (>= 1.1.2)
21
+ gherkin (~> 2.9.0)
22
+ json (>= 1.4.6)
23
+ term-ansicolor (>= 1.0.6)
24
+ diff-lcs (1.1.3)
25
+ gherkin (2.9.0)
26
+ json (>= 1.4.6)
27
+ json (1.6.5)
28
+ method_source (0.7.1)
29
+ multi_json (1.1.0)
30
+ plymouth (0.3.2)
31
+ pry-exception_explorer (>= 0.1.7)
32
+ pry (0.9.8.4)
33
+ coderay (~> 1.0.5)
34
+ method_source (~> 0.7.1)
35
+ slop (>= 2.4.4, < 3)
36
+ pry-exception_explorer (0.1.9)
37
+ pry-stack_explorer (>= 0.3.9)
38
+ pry-nav (0.1.0)
39
+ pry (~> 0.9.8.1)
40
+ pry-stack_explorer (0.4.1)
41
+ binding_of_caller (~> 0.6.2)
42
+ pry (~> 0.9.8.2)
43
+ pry-syntax-hacks (0.0.6)
44
+ pry (>= 0.9.8)
45
+ rake (0.9.2.2)
46
+ redcarpet (2.1.0)
47
+ rspec (2.8.0)
48
+ rspec-core (~> 2.8.0)
49
+ rspec-expectations (~> 2.8.0)
50
+ rspec-mocks (~> 2.8.0)
51
+ rspec-core (2.8.0)
52
+ rspec-expectations (2.8.0)
53
+ diff-lcs (~> 1.1.2)
54
+ rspec-mocks (2.8.0)
55
+ shoulda (2.11.3)
56
+ simplecov (0.6.1)
57
+ multi_json (~> 1.0)
58
+ simplecov-html (~> 0.5.3)
59
+ simplecov-html (0.5.3)
60
+ slop (2.4.4)
61
+ term-ansicolor (1.0.7)
62
+ timecop (0.3.5)
63
+ yard (0.7.5)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ activerecord (>= 2.3)
70
+ acts_as_approvable!
71
+ appraisal (~> 0.4.1)
72
+ cucumber (~> 1.1.0)
73
+ plymouth
74
+ pry (~> 0.9.8.1)
75
+ pry-nav (~> 0.1.0)
76
+ pry-stack_explorer
77
+ pry-syntax-hacks
78
+ rake (~> 0.9.2)
79
+ redcarpet (~> 2.1.0)
80
+ rspec (~> 2.8.0)
81
+ shoulda (~> 2.0)
82
+ simplecov
83
+ timecop (~> 0.3.5)
84
+ yard
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Jay Hayes
1
+ Copyright (c) 2012 James Logsdon
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
19
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,146 @@
1
+ # Acts as Approvable [![Build Status](https://secure.travis-ci.org/jlogsdon/acts_as_approvable.png)](http://travis-ci.org/jlogsdon/acts_as_approvable?branch=master)
2
+
3
+ This plugin provides a workflow for approving new records and changes to existing
4
+ records.
5
+
6
+ Installation
7
+ ============
8
+
9
+ Rails 3
10
+ -------
11
+
12
+ Add the gem to your Gemfile:
13
+
14
+ gem 'acts-as-approvable'
15
+
16
+ Then run the generator:
17
+
18
+ rails g acts_as_approvable
19
+
20
+ Rails 2
21
+ -------
22
+
23
+ Add the gem to `config/environment.rb`
24
+
25
+ config.gem 'acts-as-approvable'
26
+
27
+ Then run `rake gems:install`. After the gem is installed, run the generator:
28
+
29
+ $ script/generate acts_as_approvable
30
+
31
+ Generator Options
32
+ =================
33
+
34
+ These options are also available by passing `--help` as an option to the generator.
35
+
36
+ --base BASE Base class for ApprovableController.
37
+ --haml* Generate HAML views instead of ERB.
38
+ --owner [User] Enable and, optionally, set the model for approval ownerships.
39
+ --scripts Copy javascripts for ApprovalsController and its views.
40
+
41
+ \* This option is not available in Rails 3. You should configure your template engine in `config/application.rb`
42
+
43
+ API Documentation
44
+ =================
45
+
46
+ API Documentation is [available online](http://rubydoc.info/gems/acts-as-approvable/frames).
47
+
48
+ Configuration
49
+ =============
50
+
51
+ The generator creates an initializor at `config/initializers/acts_as_approvable.rb`. A sample
52
+ initializer might look like this:
53
+
54
+ ```ruby
55
+ ActsAsApprovable.view_language = 'haml'
56
+ ActsAsApprovable::Ownership.configure
57
+ ```
58
+
59
+ The `Ownership` functionality expects a `User` model in your project by default, but by providing
60
+ an `:owner` option you can change the expected model to whatever you wish. `.configure` also
61
+ accepts a block which it applies to the `Approval` model, allowing you to override methods as
62
+ you see fit.
63
+
64
+ For example, to only allow Users with the "admin" role to 'own' an Approval, change your initializer
65
+ to something like this:
66
+
67
+ ```ruby
68
+ ActsAsApprovable.view_language = 'haml'
69
+ ActsAsApprovable::Ownership.configure(:source => ApprovalSources)
70
+ ```
71
+
72
+ The `ApprovalSources` class should be created by you if you wish to override how available owners
73
+ are selected or the option arrays for `select_tag` are created. Below is an example:
74
+
75
+ ```ruby
76
+ class ApprovalSources
77
+ def self.available_owners
78
+ User.all(:conditions => ['role', 'admin'])
79
+ end
80
+
81
+ def self.option_for_owner(owner)
82
+ # default is [owner.to_str, owner.id]
83
+ [owner.email, owner.id]
84
+ end
85
+ end
86
+ ```
87
+
88
+ Examples
89
+ ========
90
+
91
+ Require approval for new Users, but not modifications...
92
+
93
+ ```ruby
94
+ class User < ActiveRecord::Base
95
+ acts_as_approvable :on => :create, :state_field => :state
96
+
97
+ # Let the user know they've been approved (ApprovalMailer is your creation)
98
+ def after_approve(approval)
99
+ ApprovalMailer.deliver_user_approved(self.email)
100
+ end
101
+
102
+ # Let the user know they were rejected
103
+ def after_reject(approval)
104
+ ApprovalMailer.deliver_user_rejected(self.email, approval.reason)
105
+ end
106
+ end
107
+ ```
108
+
109
+ Require approval when a Game's title or description is changed, but not when view or installation count is changed...
110
+
111
+ ```ruby
112
+ class Game < ActiveRecord::Base
113
+ acts_as_approvable :on => :update, :ignore => [:views, :installs]
114
+ end
115
+ ```
116
+
117
+ Require approval for all changes, except the standard ignored fields (`created_at`, `updated_at` and `:state_field`)...
118
+
119
+ ```ruby
120
+ class Advertisement < ActiveRecord::Base
121
+ acts_as_approvable :state_field => :state
122
+ end
123
+ ```
124
+
125
+ Options
126
+ =======
127
+
128
+ The following options may be used to configure the workflow on a per-model
129
+ basis:
130
+
131
+ * `:on` The type of events (`:create`, `:update` or `:destroy`) to require approval on.
132
+ * `:ignore` A list of fields to ignore for `:update` approvals.
133
+ * `:only` A list of fields that should be approved. All other fields are
134
+ ignored. If set, the `:ignore` option is... ignored.
135
+ * `:state_field` A local model field to save the `:create` approvals state. Useful
136
+ for selecting approved models without joining the approvals table.
137
+
138
+ The fields `:created_at`, `:updated_at` and whatever is set for the `:state_field`
139
+ are automatically ignored.
140
+
141
+ Contributors
142
+ ============
143
+
144
+ * [James Logsdon](http://github.com/jlogsdon) (Lead developer)
145
+ * [Hwan-Joon Choi](http://github.com/hc5duke) (Performance enhancements, bug fixes)
146
+ * [Neal Wiggins](http://github.com/nwigginsTJ) (Enumeration of states)
data/Rakefile CHANGED
@@ -1,10 +1,93 @@
1
- # encoding: UTF-8
2
1
  require 'rubygems'
3
- begin
4
- require 'bundler/setup'
5
- rescue LoadError
6
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
2
+ require 'bundler/setup'
3
+ require 'rake/testtask'
4
+ require 'rspec/core/rake_task'
5
+ require 'cucumber'
6
+ require 'cucumber/rake/task'
7
+ require 'yard'
8
+ require 'appraisal'
9
+
10
+ desc 'Default: run unit tests.'
11
+ task :default => :test
12
+
13
+ desc 'Start a pry session with a database connection open'
14
+ task :pry do |t|
15
+ $LOAD_PATH << './lib'
16
+ require 'pry'
17
+ require './spec/spec_helper'
18
+
19
+ Support::Database.setup_log(STDOUT)
20
+ Support::Database.load_schema
21
+
22
+ #ActsAsApprovable::Ownership.configure
23
+ Pry.start(TOPLEVEL_BINDING)
24
+ end
25
+
26
+ desc 'Copy templates from Rails 3 generators to the Rails 2 generators'
27
+ task :copy do |t|
28
+ ['erb', 'haml'].each do |lang|
29
+ Dir["lib/generators/#{lang}/templates/*"].each do |file|
30
+ FileUtils.cp(file, "generators/acts_as_approvable/templates/views/#{lang}/#{File.basename(file)}")
31
+ end
32
+ end
33
+ Dir["lib/generators/acts_as_approvable/templates/*"].each do |file|
34
+ FileUtils.cp(file, "generators/acts_as_approvable/templates/#{File.basename(file)}")
35
+ end
36
+ end
37
+
38
+ desc 'Test the acts_as_approvable plugin.'
39
+ RSpec::Core::RakeTask.new(:test)
40
+
41
+ if RUBY_VERSION =~ /^1\.8/
42
+ begin
43
+ require 'rcov/rcovtask'
44
+ Rcov::RcovTask.new do |t|
45
+ t.libs << 'test' << 'lib'
46
+ t.rcov_opts << '--exclude' << '"Library/Ruby/*"' << '--sort' << 'coverage'
47
+ t.pattern = 'test/*_test.rb'
48
+ t.output_dir = 'coverage/'
49
+ t.verbose = true
50
+ end
51
+ rescue LoadError
52
+ end
53
+ elsif RUBY_VERSION =~ /^1\.9/
54
+ namespace :test do
55
+ task :coverage do
56
+ ENV['COVERAGE'] = 'true'
57
+ Rake::Task['test'].invoke
58
+ end
59
+ end
7
60
  end
8
61
 
9
- require 'rake'
10
- task :default => :spec
62
+ namespace :test do
63
+ desc 'Setup appraisals and install gems for the gambit run'
64
+ task :setup do
65
+ start = Time.now
66
+ Kernel.system('rbenv each -v bundle install')
67
+ Kernel.system('rbenv each -v bundle exec rake appraisal:install')
68
+ elapsed = Time.now - start
69
+
70
+ puts "\nRan everything in #{elapsed} seconds"
71
+ end
72
+
73
+ desc 'Run all specs and features across all installed rubies'
74
+ task :gambit do
75
+ start = Time.now
76
+ Kernel.system('rbenv each -v bundle exec rake appraisal test')
77
+ Kernel.system('rbenv each -v bundle exec rake appraisal features')
78
+ elapsed = Time.now - start
79
+
80
+ puts "\nRan everything in #{elapsed} seconds"
81
+ end
82
+ end
83
+
84
+ Cucumber::Rake::Task.new(:features) do |t|
85
+ t.cucumber_opts = "features --format pretty"
86
+ end
87
+
88
+ desc 'Generate documentation for the acts_as_approvable plugin.'
89
+ YARD::Rake::YardocTask.new do |t|
90
+ yard_dir = (ENV['YARD_DIR'] || 'yardoc')
91
+ t.files = ['lib/**/*.rb', 'README.md']
92
+ t.options = ['-r', 'README.md', '-o', yard_dir, '--markup', 'markdown']
93
+ end