requires_approval 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d604fa067efbb88cdf1f0f23b6b4e5bf9c78c6c3
4
+ data.tar.gz: b31e28f39559b72140db9b4d192004e1e000dcdf
5
+ SHA512:
6
+ metadata.gz: e097e37c17729cb4ebec30e49c6a4e339c9fb3c2a15c51c3562b642032ff09e985c5c7d7c9184a1250f73f94ccebeabf68ecb6bfc6301d81ac7c8728172ec466
7
+ data.tar.gz: 35ab14aaded4103085529559b4328120b244e280263fbf655ea379e2aa9c1234ea0f8a636eb22ffd9a207c421bfe1f187ffa85591ef6f50a22ed11035ce17d89
data/Gemfile.lock CHANGED
@@ -1,14 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- requires_approval (1.0.7)
4
+ requires_approval (1.0.8)
5
+ activerecord
5
6
  requires_approval
6
7
 
7
8
  GEM
8
9
  remote: http://rubygems.org/
9
10
  specs:
10
- archive-tar-minitar (0.5.2)
11
- columnize (0.3.6)
11
+ activemodel (3.2.14)
12
+ activesupport (= 3.2.14)
13
+ builder (~> 3.0.0)
14
+ activerecord (3.2.14)
15
+ activemodel (= 3.2.14)
16
+ activesupport (= 3.2.14)
17
+ arel (~> 3.0.2)
18
+ tzinfo (~> 0.3.29)
19
+ activesupport (3.2.14)
20
+ i18n (~> 0.6, >= 0.6.4)
21
+ multi_json (~> 1.0)
22
+ arel (3.0.2)
23
+ builder (3.0.4)
12
24
  diff-lcs (1.1.3)
13
25
  ffi (1.1.5)
14
26
  git (1.2.5)
@@ -23,14 +35,13 @@ GEM
23
35
  guard-spork (1.1.0)
24
36
  guard (>= 1.1)
25
37
  spork (>= 0.8.4)
38
+ i18n (0.6.5)
26
39
  jeweler (1.8.4)
27
40
  bundler (~> 1.0)
28
41
  git (>= 1.2.5)
29
42
  rake
30
43
  rdoc
31
44
  json (1.7.5)
32
- linecache19 (0.5.12)
33
- ruby_core_source (>= 0.1.4)
34
45
  listen (0.4.7)
35
46
  rb-fchange (~> 0.0.5)
36
47
  rb-fsevent (~> 0.9.1)
@@ -38,6 +49,7 @@ GEM
38
49
  metaclass (0.0.1)
39
50
  mocha (0.12.3)
40
51
  metaclass (~> 0.0.1)
52
+ multi_json (1.8.0)
41
53
  rake (0.9.2.2)
42
54
  rb-fchange (0.0.5)
43
55
  ffi
@@ -54,19 +66,10 @@ GEM
54
66
  rspec-expectations (2.11.2)
55
67
  diff-lcs (~> 1.1.3)
56
68
  rspec-mocks (2.11.2)
57
- ruby-debug-base19 (0.11.25)
58
- columnize (>= 0.3.1)
59
- linecache19 (>= 0.5.11)
60
- ruby_core_source (>= 0.1.4)
61
- ruby-debug19 (0.11.6)
62
- columnize (>= 0.3.1)
63
- linecache19 (>= 0.5.11)
64
- ruby-debug-base19 (>= 0.11.19)
65
- ruby_core_source (0.1.5)
66
- archive-tar-minitar (>= 0.5.2)
67
69
  spork (0.9.2)
68
70
  sqlite3 (1.3.6)
69
71
  thor (0.16.0)
72
+ tzinfo (0.3.37)
70
73
  yard (0.8.2.1)
71
74
 
72
75
  PLATFORMS
@@ -82,6 +85,5 @@ DEPENDENCIES
82
85
  rdoc
83
86
  requires_approval!
84
87
  rspec
85
- ruby-debug19
86
88
  sqlite3
87
89
  yard
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.7
1
+ 1.0.8
@@ -16,10 +16,10 @@ module RequiresApproval
16
16
 
17
17
  # # approve a list of attributes
18
18
  def approve_attributes(*attributes)
19
-
19
+
20
20
  return true unless self.has_pending_changes?
21
21
 
22
- # validate an normalize our attributes
22
+ # validate an normalize our attributes
23
23
  attributes = self.check_attributes_for_approval(attributes)
24
24
 
25
25
  # make sure that all attributes are provided if we have never
@@ -28,7 +28,7 @@ module RequiresApproval
28
28
 
29
29
  if fields_not_being_approved.present? && self.never_approved?
30
30
  raise PartialApprovalForNewObject.new(
31
- "You must approve #{self.fields_requiring_approval.join(", ")} " +
31
+ "You must approve #{self.fields_requiring_approval.join(", ")} " +
32
32
  "for a new #{self.class.name}"
33
33
  )
34
34
  end
@@ -39,14 +39,14 @@ module RequiresApproval
39
39
 
40
40
  if self.save
41
41
  # if we have approved all requested changes, make our latest
42
- # unapproved version approved -
42
+ # unapproved version approved -
43
43
  # this is ALWAYS true for a new record even though its pending_changes
44
44
  # hash is forced to have values
45
45
  if self.is_first_version? || self.no_pending_changes?
46
46
  self.latest_unapproved_version.update_attribute(:is_approved, true)
47
47
  else
48
- # makes our latest_unapproved_version approved and
49
- # creates another unapproved version with any remaining
48
+ # makes our latest_unapproved_version approved and
49
+ # creates another unapproved version with any remaining
50
50
  # attributes
51
51
  self.create_approval_version_record
52
52
  end
@@ -80,14 +80,25 @@ module RequiresApproval
80
80
  else
81
81
  self.latest_unapproved_version.save
82
82
  end
83
-
83
+
84
84
  self.reload
85
85
  true
86
86
  end
87
87
 
88
+ def reload(*args)
89
+ if instance_variable_defined?(:@has_approved_version)
90
+ remove_instance_variable(:@has_approved_version)
91
+ end
92
+ super(*args)
93
+ end
94
+
88
95
  # have any of our versions ever been approved?
89
96
  def has_approved_version?
90
- self.versions.where(:is_approved => true).count > 0
97
+ unless instance_variable_defined?(:@has_approved_version)
98
+ @has_approved_version = (self.versions.where(:is_approved => true).count > 0)
99
+ end
100
+
101
+ @has_approved_version
91
102
  end
92
103
 
93
104
  # have we already approved all outstanding changes?
@@ -108,21 +119,21 @@ module RequiresApproval
108
119
  # the changes users have requested since the last approval
109
120
  def pending_changes
110
121
  return {} if self.latest_unapproved_version.blank?
111
-
122
+
112
123
  ret = {}
113
124
  # check each field requiring approval
114
125
  self.fields_requiring_approval.each do |field|
115
-
126
+
116
127
  # if it is the same in the unapproved as in the parent table
117
128
  # we skip it
118
- if self.is_first_version? ||
129
+ if self.is_first_version? ||
119
130
  self.send(field) != self.latest_unapproved_version.send(field)
120
-
131
+
121
132
  # otherwise we get the change set
122
133
  ret[field] = {
123
- # our first version is always nil, regardless of the
134
+ # our first version is always nil, regardless of the
124
135
  # defaults in that table
125
- "was" => self.is_first_version? ? nil : self.send(field),
136
+ "was" => self.is_first_version? ? nil : self.send(field),
126
137
  "became" => self.latest_unapproved_version.send(field)
127
138
  }
128
139
  end
@@ -160,7 +171,7 @@ module RequiresApproval
160
171
  self.latest_unapproved_version.update_attributes(
161
172
  self.attributes_requiring_approval.merge(:is_approved => true)
162
173
  )
163
- # reload so this unapproved version is out of our cache and will not
174
+ # reload so this unapproved version is out of our cache and will not
164
175
  # get its foreign key unassigned
165
176
  self.latest_unapproved_version(true)
166
177
 
@@ -181,7 +192,7 @@ module RequiresApproval
181
192
  !self.has_approved_version?
182
193
  end
183
194
 
184
- # ActiveRecord-style attribute hash for the
195
+ # ActiveRecord-style attribute hash for the
185
196
  # requested changes
186
197
  def pending_attributes
187
198
  ret = {}
@@ -209,7 +220,7 @@ module RequiresApproval
209
220
  # adds our versions table
210
221
  self.drop_versions_table
211
222
  self.create_versions_table
212
-
223
+
213
224
  end
214
225
 
215
226
  def requires_approval_for(*attrs)
@@ -228,10 +239,10 @@ module RequiresApproval
228
239
  :latest_unapproved_version_with_nil_check,
229
240
  :on => :create
230
241
  )
231
-
242
+
232
243
  # create the versions class
233
244
  self.create_versions_class
234
- self.has_many :versions,
245
+ self.has_many :versions,
235
246
  :class_name => self.versions_class.name,
236
247
  :foreign_key => self.versions_foreign_key
237
248
 
@@ -275,9 +286,9 @@ module RequiresApproval
275
286
  # create a class
276
287
  def create_versions_class
277
288
  versions_table_name = self.versions_table_name
278
-
289
+
279
290
  self.const_set self.versions_class_name, Class.new(ActiveRecord::Base)
280
-
291
+
281
292
  self.versions_class.class_eval do
282
293
  self.table_name = versions_table_name
283
294
  end
@@ -321,13 +332,13 @@ module RequiresApproval
321
332
  define_method("#{f}=") do |val|
322
333
  # type cast our val so "0" changes to 'false'
323
334
  type_casted_val = self.column_for_attribute(f).type_cast(val)
324
-
335
+
325
336
  # if we have a latest_unapproved version already, let it handle
326
- # updates - if not, only create one if the type casted value is
337
+ # updates - if not, only create one if the type casted value is
327
338
  # not the same as what is in the parent value
328
- if self.latest_unapproved_version.present? ||
339
+ if self.latest_unapproved_version.present? ||
329
340
  type_casted_val != self.send(f)
330
-
341
+
331
342
  self.send("#{f}_will_change!")
332
343
  self.latest_unapproved_version_with_nil_check.send("#{f}=", val)
333
344
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "requires_approval"
8
- s.version = "1.0.7"
8
+ s.version = "1.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dan Langevin"]
12
- s.date = "2013-04-03"
12
+ s.date = "2013-10-19"
13
13
  s.description = "Gem to handle versioning and things that require approval"
14
14
  s.email = "dan.langevin@lifebooker.com"
15
15
  s.extra_rdoc_files = [
@@ -40,14 +40,15 @@ Gem::Specification.new do |s|
40
40
  s.homepage = "http://github.com/LifebookerInc/requires_approval"
41
41
  s.licenses = ["MIT"]
42
42
  s.require_paths = ["lib"]
43
- s.rubygems_version = "1.8.17"
43
+ s.rubygems_version = "2.0.3"
44
44
  s.summary = "Gem to handle versioning and things that require approval"
45
45
 
46
46
  if s.respond_to? :specification_version then
47
- s.specification_version = 3
47
+ s.specification_version = 4
48
48
 
49
49
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
50
  s.add_runtime_dependency(%q<requires_approval>, [">= 0"])
51
+ s.add_runtime_dependency(%q<activerecord>, [">= 0"])
51
52
  s.add_development_dependency(%q<bundler>, [">= 0"])
52
53
  s.add_development_dependency(%q<guard-rspec>, [">= 0"])
53
54
  s.add_development_dependency(%q<guard-bundler>, [">= 0"])
@@ -56,11 +57,11 @@ Gem::Specification.new do |s|
56
57
  s.add_development_dependency(%q<mocha>, [">= 0"])
57
58
  s.add_development_dependency(%q<rdoc>, [">= 0"])
58
59
  s.add_development_dependency(%q<rspec>, [">= 0"])
59
- s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
60
60
  s.add_development_dependency(%q<sqlite3>, [">= 0"])
61
61
  s.add_development_dependency(%q<yard>, [">= 0"])
62
62
  else
63
63
  s.add_dependency(%q<requires_approval>, [">= 0"])
64
+ s.add_dependency(%q<activerecord>, [">= 0"])
64
65
  s.add_dependency(%q<bundler>, [">= 0"])
65
66
  s.add_dependency(%q<guard-rspec>, [">= 0"])
66
67
  s.add_dependency(%q<guard-bundler>, [">= 0"])
@@ -69,12 +70,12 @@ Gem::Specification.new do |s|
69
70
  s.add_dependency(%q<mocha>, [">= 0"])
70
71
  s.add_dependency(%q<rdoc>, [">= 0"])
71
72
  s.add_dependency(%q<rspec>, [">= 0"])
72
- s.add_dependency(%q<ruby-debug19>, [">= 0"])
73
73
  s.add_dependency(%q<sqlite3>, [">= 0"])
74
74
  s.add_dependency(%q<yard>, [">= 0"])
75
75
  end
76
76
  else
77
77
  s.add_dependency(%q<requires_approval>, [">= 0"])
78
+ s.add_dependency(%q<activerecord>, [">= 0"])
78
79
  s.add_dependency(%q<bundler>, [">= 0"])
79
80
  s.add_dependency(%q<guard-rspec>, [">= 0"])
80
81
  s.add_dependency(%q<guard-bundler>, [">= 0"])
@@ -83,7 +84,6 @@ Gem::Specification.new do |s|
83
84
  s.add_dependency(%q<mocha>, [">= 0"])
84
85
  s.add_dependency(%q<rdoc>, [">= 0"])
85
86
  s.add_dependency(%q<rspec>, [">= 0"])
86
- s.add_dependency(%q<ruby-debug19>, [">= 0"])
87
87
  s.add_dependency(%q<sqlite3>, [">= 0"])
88
88
  s.add_dependency(%q<yard>, [">= 0"])
89
89
  end
data/spec/spec_helper.rb CHANGED
@@ -13,9 +13,6 @@ Spork.prefork do
13
13
  require 'rspec'
14
14
  require 'requires_approval'
15
15
 
16
- require 'ruby-debug'
17
- Debugger.start
18
-
19
16
  # Requires supporting files with custom matchers and macros, etc,
20
17
  # in ./support/ and its subdirectories.
21
18
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
metadata CHANGED
@@ -1,148 +1,183 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: requires_approval
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
5
- prerelease:
4
+ version: 1.0.8
6
5
  platform: ruby
7
6
  authors:
8
7
  - Dan Langevin
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-03 00:00:00.000000000 Z
11
+ date: 2013-10-19 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: requires_approval
16
- requirement: &70165360482200 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70165360482200
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
25
41
  - !ruby/object:Gem::Dependency
26
42
  name: bundler
27
- requirement: &70165360478060 !ruby/object:Gem::Requirement
28
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
29
44
  requirements:
30
- - - ! '>='
45
+ - - '>='
31
46
  - !ruby/object:Gem::Version
32
47
  version: '0'
33
48
  type: :development
34
49
  prerelease: false
35
- version_requirements: *70165360478060
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
36
55
  - !ruby/object:Gem::Dependency
37
56
  name: guard-rspec
38
- requirement: &70165360473460 !ruby/object:Gem::Requirement
39
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
40
58
  requirements:
41
- - - ! '>='
59
+ - - '>='
42
60
  - !ruby/object:Gem::Version
43
61
  version: '0'
44
62
  type: :development
45
63
  prerelease: false
46
- version_requirements: *70165360473460
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
47
69
  - !ruby/object:Gem::Dependency
48
70
  name: guard-bundler
49
- requirement: &70165360457860 !ruby/object:Gem::Requirement
50
- none: false
71
+ requirement: !ruby/object:Gem::Requirement
51
72
  requirements:
52
- - - ! '>='
73
+ - - '>='
53
74
  - !ruby/object:Gem::Version
54
75
  version: '0'
55
76
  type: :development
56
77
  prerelease: false
57
- version_requirements: *70165360457860
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
58
83
  - !ruby/object:Gem::Dependency
59
84
  name: guard-spork
60
- requirement: &70165360455700 !ruby/object:Gem::Requirement
61
- none: false
85
+ requirement: !ruby/object:Gem::Requirement
62
86
  requirements:
63
- - - ! '>='
87
+ - - '>='
64
88
  - !ruby/object:Gem::Version
65
89
  version: '0'
66
90
  type: :development
67
91
  prerelease: false
68
- version_requirements: *70165360455700
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: jeweler
71
- requirement: &70165360453640 !ruby/object:Gem::Requirement
72
- none: false
99
+ requirement: !ruby/object:Gem::Requirement
73
100
  requirements:
74
101
  - - ~>
75
102
  - !ruby/object:Gem::Version
76
103
  version: 1.8.3
77
104
  type: :development
78
105
  prerelease: false
79
- version_requirements: *70165360453640
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 1.8.3
80
111
  - !ruby/object:Gem::Dependency
81
112
  name: mocha
82
- requirement: &70165360449700 !ruby/object:Gem::Requirement
83
- none: false
113
+ requirement: !ruby/object:Gem::Requirement
84
114
  requirements:
85
- - - ! '>='
115
+ - - '>='
86
116
  - !ruby/object:Gem::Version
87
117
  version: '0'
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *70165360449700
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
91
125
  - !ruby/object:Gem::Dependency
92
126
  name: rdoc
93
- requirement: &70165360447740 !ruby/object:Gem::Requirement
94
- none: false
127
+ requirement: !ruby/object:Gem::Requirement
95
128
  requirements:
96
- - - ! '>='
129
+ - - '>='
97
130
  - !ruby/object:Gem::Version
98
131
  version: '0'
99
132
  type: :development
100
133
  prerelease: false
101
- version_requirements: *70165360447740
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
102
139
  - !ruby/object:Gem::Dependency
103
140
  name: rspec
104
- requirement: &70165360444980 !ruby/object:Gem::Requirement
105
- none: false
141
+ requirement: !ruby/object:Gem::Requirement
106
142
  requirements:
107
- - - ! '>='
143
+ - - '>='
108
144
  - !ruby/object:Gem::Version
109
145
  version: '0'
110
146
  type: :development
111
147
  prerelease: false
112
- version_requirements: *70165360444980
113
- - !ruby/object:Gem::Dependency
114
- name: ruby-debug19
115
- requirement: &70165360443640 !ruby/object:Gem::Requirement
116
- none: false
148
+ version_requirements: !ruby/object:Gem::Requirement
117
149
  requirements:
118
- - - ! '>='
150
+ - - '>='
119
151
  - !ruby/object:Gem::Version
120
152
  version: '0'
121
- type: :development
122
- prerelease: false
123
- version_requirements: *70165360443640
124
153
  - !ruby/object:Gem::Dependency
125
154
  name: sqlite3
126
- requirement: &70165360440240 !ruby/object:Gem::Requirement
127
- none: false
155
+ requirement: !ruby/object:Gem::Requirement
128
156
  requirements:
129
- - - ! '>='
157
+ - - '>='
130
158
  - !ruby/object:Gem::Version
131
159
  version: '0'
132
160
  type: :development
133
161
  prerelease: false
134
- version_requirements: *70165360440240
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
135
167
  - !ruby/object:Gem::Dependency
136
168
  name: yard
137
- requirement: &70165360438500 !ruby/object:Gem::Requirement
138
- none: false
169
+ requirement: !ruby/object:Gem::Requirement
139
170
  requirements:
140
- - - ! '>='
171
+ - - '>='
141
172
  - !ruby/object:Gem::Version
142
173
  version: '0'
143
174
  type: :development
144
175
  prerelease: false
145
- version_requirements: *70165360438500
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
146
181
  description: Gem to handle versioning and things that require approval
147
182
  email: dan.langevin@lifebooker.com
148
183
  executables: []
@@ -173,29 +208,25 @@ files:
173
208
  homepage: http://github.com/LifebookerInc/requires_approval
174
209
  licenses:
175
210
  - MIT
211
+ metadata: {}
176
212
  post_install_message:
177
213
  rdoc_options: []
178
214
  require_paths:
179
215
  - lib
180
216
  required_ruby_version: !ruby/object:Gem::Requirement
181
- none: false
182
217
  requirements:
183
- - - ! '>='
218
+ - - '>='
184
219
  - !ruby/object:Gem::Version
185
220
  version: '0'
186
- segments:
187
- - 0
188
- hash: -2528865283922867578
189
221
  required_rubygems_version: !ruby/object:Gem::Requirement
190
- none: false
191
222
  requirements:
192
- - - ! '>='
223
+ - - '>='
193
224
  - !ruby/object:Gem::Version
194
225
  version: '0'
195
226
  requirements: []
196
227
  rubyforge_project:
197
- rubygems_version: 1.8.17
228
+ rubygems_version: 2.0.3
198
229
  signing_key:
199
- specification_version: 3
230
+ specification_version: 4
200
231
  summary: Gem to handle versioning and things that require approval
201
232
  test_files: []