acts-as-approvable 0.6.7 → 0.6.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/.gitignore +2 -5
  2. data/.rspec +2 -0
  3. data/.travis.yml +5 -0
  4. data/Appraisals +14 -10
  5. data/CHANGELOG +16 -0
  6. data/Gemfile.lock +60 -20
  7. data/README.md +1 -2
  8. data/Rakefile +44 -16
  9. data/VERSION +1 -1
  10. data/acts-as-approvable.gemspec +21 -11
  11. data/features/create_approval.feature +26 -0
  12. data/features/step_definitions/cucumber_steps.rb +86 -0
  13. data/features/support/env.rb +14 -0
  14. data/features/support/large.txt +29943 -0
  15. data/features/support/second_large.txt +31798 -0
  16. data/features/update_approval.feature +34 -0
  17. data/gemfiles/Gemfile.ci +14 -0
  18. data/gemfiles/Gemfile.ci.lock +98 -0
  19. data/gemfiles/mysql2.gemfile +7 -0
  20. data/gemfiles/mysql2.gemfile.lock +92 -0
  21. data/gemfiles/rails2.gemfile +1 -0
  22. data/gemfiles/rails2.gemfile.lock +59 -17
  23. data/gemfiles/rails30.gemfile +1 -0
  24. data/gemfiles/rails30.gemfile.lock +54 -14
  25. data/gemfiles/rails31.gemfile +1 -0
  26. data/gemfiles/rails31.gemfile.lock +54 -14
  27. data/gemfiles/sqlite.gemfile +7 -0
  28. data/generators/acts_as_approvable/templates/create_approvals.rb +8 -7
  29. data/lib/acts-as-approvable.rb +2 -3
  30. data/lib/acts_as_approvable/approval.rb +3 -2
  31. data/lib/acts_as_approvable/model.rb +55 -0
  32. data/lib/acts_as_approvable/model/class_methods.rb +63 -0
  33. data/lib/acts_as_approvable/model/create_instance_methods.rb +83 -0
  34. data/lib/acts_as_approvable/model/instance_methods.rb +89 -0
  35. data/lib/acts_as_approvable/model/update_instance_methods.rb +61 -0
  36. data/lib/acts_as_approvable/railtie.rb +1 -1
  37. data/lib/generators/acts_as_approvable/templates/create_approvals.rb +8 -7
  38. data/spec/acts_as_approvable/approval_spec.rb +475 -0
  39. data/spec/acts_as_approvable/model/class_methods_spec.rb +219 -0
  40. data/spec/acts_as_approvable/model/create_instance_methods_spec.rb +149 -0
  41. data/spec/acts_as_approvable/model/instance_methods_spec.rb +328 -0
  42. data/spec/acts_as_approvable/model/update_instance_methods_spec.rb +111 -0
  43. data/spec/acts_as_approvable/model_spec.rb +90 -0
  44. data/spec/acts_as_approvable/ownership/class_methods_spec.rb +101 -0
  45. data/spec/acts_as_approvable/ownership/instance_methods_spec.rb +32 -0
  46. data/spec/acts_as_approvable/ownership_spec.rb +51 -0
  47. data/spec/acts_as_approvable_spec.rb +29 -0
  48. data/spec/spec_helper.rb +51 -0
  49. data/spec/support/database.rb +46 -0
  50. data/spec/support/database.yml +12 -0
  51. data/spec/support/matchers.rb +87 -0
  52. data/spec/support/models.rb +60 -0
  53. data/{test → spec/support}/schema.rb +15 -9
  54. metadata +156 -53
  55. data/gemfiles/rails32.gemfile +0 -8
  56. data/gemfiles/rails32.gemfile.lock +0 -99
  57. data/lib/acts_as_approvable/acts_as_approvable.rb +0 -291
  58. data/test/acts_as_approvable_model_test.rb +0 -459
  59. data/test/acts_as_approvable_ownership_test.rb +0 -132
  60. data/test/acts_as_approvable_schema_test.rb +0 -13
  61. data/test/acts_as_approvable_test.rb +0 -8
  62. data/test/database.yml +0 -7
  63. data/test/support.rb +0 -19
  64. data/test/test_helper.rb +0 -62
@@ -1,132 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ActsAsApprovableOwnershipTest < Test::Unit::TestCase
4
- load_schema
5
-
6
- def teardown
7
- truncate
8
- end
9
-
10
- context 'with default configuration' do
11
- setup do
12
- # Reset from test below
13
- ActsAsApprovable::Ownership.configure do
14
- def self.available_owners
15
- owner_class.all
16
- end
17
- end
18
- end
19
-
20
- should 'respond to .owner_class' do
21
- assert_respond_to Approval, :owner_class
22
- end
23
-
24
- should 'respond to .available_owners' do
25
- assert_respond_to Approval, :available_owners
26
- end
27
-
28
- should 'respond to .options_for_available_owners' do
29
- assert_respond_to Approval, :options_for_available_owners
30
- end
31
-
32
- should 'respond to .assigned_owners' do
33
- assert_respond_to Approval, :assigned_owners
34
- end
35
-
36
- should 'respond to .options_for_assigned_owners' do
37
- assert_respond_to Approval, :options_for_assigned_owners
38
- end
39
-
40
- context 'and some objects' do
41
- setup do
42
- @employee = Employee.create
43
- @approval = @employee.approval
44
-
45
- @user1, @user2 = User.without_approval { |m| [m.create, m.create] }
46
- end
47
-
48
- context '#assign' do
49
- should 'raise an error when the record is not assignable' do
50
- assert_raise(ActsAsApprovable::Error::InvalidOwner) { @approval.assign(@employee) }
51
- end
52
-
53
- should 'allow assignment of a valid record' do
54
- assert_nothing_raised { @approval.assign(@user1) }
55
- assert_equal @approval.owner, @user1
56
- end
57
- end
58
-
59
- context '#unassign' do
60
- setup do
61
- @approval.owner = @user1
62
- @approval.unassign
63
- end
64
-
65
- should 'nullify the owner' do
66
- assert @approval.owner.nil?
67
- end
68
- end
69
-
70
- context '.available_owners' do
71
- should 'contain all available owners' do
72
- assert_equal [@user1, @user2], Approval.available_owners
73
- end
74
- end
75
-
76
- context '.options_for_available_owners' do
77
- should 'format all available owners for a #options_for_select' do
78
- assert_equal Approval.options_for_available_owners, [
79
- [@user1.to_str, @user1.id],
80
- [@user2.to_str, @user2.id]
81
- ]
82
- end
83
-
84
- should 'insert a prompt if requested' do
85
- assert_equal ['(none)', nil], Approval.options_for_available_owners(true).first
86
- end
87
- end
88
-
89
- context 'with some assigned owners' do
90
- setup do
91
- @user3 = User.without_approval { |m| m.create }
92
-
93
- @approval.assign(@user1)
94
- Employee.create.approval.assign(@user3)
95
- end
96
-
97
- context '.assigned_owners' do
98
- should 'contain all assigned owners' do
99
- assert_equal [@user1, @user3], Approval.assigned_owners
100
- end
101
- end
102
-
103
- context '.options_for_assigned_owners' do
104
- should 'format all assigned owners for #options_for_select' do
105
- assert_equal Approval.options_for_assigned_owners, [
106
- [@user1.to_str, @user1.id],
107
- [@user3.to_str, @user3.id]
108
- ]
109
- end
110
-
111
- should 'insert a prompt if requested' do
112
- assert_equal ['All Users', nil], Approval.options_for_assigned_owners(true).first
113
- end
114
- end
115
- end
116
- end
117
- end
118
-
119
- context 'given a block' do
120
- setup do
121
- ActsAsApprovable::Ownership.configure do
122
- def self.available_owners
123
- [1, 2, 3]
124
- end
125
- end
126
- end
127
-
128
- should 'allow overriding methods' do
129
- assert_equal [1, 2, 3], Approval.available_owners
130
- end
131
- end
132
- end
@@ -1,13 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ActsAsApprovableSchemaTest < Test::Unit::TestCase
4
- def setup
5
- load_schema
6
- end
7
-
8
- def test_schema_has_loaded_correctly
9
- assert_equal [], User.all
10
- assert_equal [], Project.all
11
- assert_equal [], Approval.all
12
- end
13
- end
@@ -1,8 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ActsAsApprovableTest < Test::Unit::TestCase
4
- should 'set VERSION contanst to file contents' do
5
- contents = File.read(File.expand_path(File.join(File.dirname(__FILE__), '..', 'VERSION'))).chomp
6
- assert_equal ActsAsApprovable::VERSION, contents
7
- end
8
- end
data/test/database.yml DELETED
@@ -1,7 +0,0 @@
1
- sqlite:
2
- :adapter: sqlite
3
- :database: test/acts_as_approvable_plugin.sqlite.db
4
-
5
- sqlite3:
6
- :adapter: sqlite3
7
- :database: test/acts_as_approvable_plugin.sqlite3.db
data/test/support.rb DELETED
@@ -1,19 +0,0 @@
1
- class User < ActiveRecord::Base
2
- acts_as_approvable :on => :create, :state_field => :state
3
-
4
- def to_str
5
- login || "user-#{id}"
6
- end
7
- end
8
-
9
- class Project < ActiveRecord::Base
10
- acts_as_approvable :on => :update, :ignore => :title
11
- end
12
-
13
- class Game < ActiveRecord::Base
14
- acts_as_approvable :on => :update, :only => :title
15
- end
16
-
17
- class Employee < ActiveRecord::Base
18
- acts_as_approvable
19
- end
data/test/test_helper.rb DELETED
@@ -1,62 +0,0 @@
1
- if RUBY_VERSION =~ /^1\.9/
2
- require 'simplecov'
3
- SimpleCov.start do
4
- add_filter '/test/'
5
- end if ENV['COVERAGE']
6
- end
7
-
8
- ENV['RAILS_ENV'] = 'test'
9
- ENV['RAILS_ROOT'] ||= File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..'))
10
-
11
- require 'rubygems'
12
- require 'test/unit'
13
- require 'mocha'
14
- require 'shoulda'
15
- require 'active_record'
16
-
17
- require File.dirname(__FILE__) + '/../lib/acts-as-approvable'
18
- require './test/support'
19
-
20
- logfile = File.dirname(__FILE__) + '/debug.log'
21
- LOGGER = ActiveRecord::Base.logger = if defined?(ActiveSupport::BufferedLogger)
22
- ActiveSupport::BufferedLogger.new(logfile)
23
- else
24
- Logger.new(logfile)
25
- end
26
-
27
- def load_schema
28
- config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
29
-
30
- db_adapter = ENV['DB']
31
-
32
- db_adapter ||=
33
- begin
34
- require 'sqlite'
35
- 'sqlite'
36
- rescue MissingSourceFile
37
- begin
38
- require 'sqlite3'
39
- 'sqlite3'
40
- rescue MissingSourceFile
41
- end
42
- end
43
-
44
- if db_adapter.nil?
45
- raise 'No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3.'
46
- end
47
-
48
- ActiveRecord::Base.establish_connection(config[db_adapter])
49
- ActiveRecord::Migration.suppress_messages do
50
- load(File.dirname(__FILE__) + '/schema.rb')
51
- end
52
-
53
- ar_classes.each { |klass| klass.reset_column_information }
54
- end
55
-
56
- def ar_classes
57
- ActiveRecord::Base.send(ActiveRecord::Base.respond_to?(:descendants) ? :descendants : :subclasses)
58
- end
59
-
60
- def truncate
61
- ar_classes.each { |klass| klass.delete_all }
62
- end