controlled_versioning 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjRhOWQ1Y2VjZTQ5YzI2NmJlZmUyNWQxMGFkMjU2NDYyMzUzZmVlYQ==
4
+ NzdiMmM3ZTU3MWI2YTQ4MjgxYWE5Y2E4ODRiYmRmM2U5NGNkZDg4OA==
5
5
  data.tar.gz: !binary |-
6
- MWFkNjNmMjA1M2VhOWQwMzFmNThmN2UxNDBmYWJlZGU2YTQ4YmNkMA==
6
+ ZTI3OTQ4MThkZWNmNTg5ZmNhOWE1NjAyZjdiNzg0MzliZmEwYmUxMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YmEyODNiMWNhY2JjYzZhZjNkZTU5ZjU5OTk4ZTdhM2NiZTI1YjZjNTJjYzNi
10
- MDdkNTQ4ZGVlY2VlMjE0NzhhMjMxOGY5YjU2ZjliMTZhNWM5Y2ZiNjcwMTUy
11
- MGUyODUyNGEyOGZhM2NiN2U4N2I4MjUyMTQzMmYyYTFjMGM5ZDc=
9
+ ZDRiYTI2NWU3OWY4YTgxNzljZTQ1NWM4YThjNDRmMGVkZTdhMGRkOGJjZjU5
10
+ NGM3Mzg3ZWIyN2RlNTBjMDY5MTMzNDFlZGZhYjEwMDZhNDUyMThlYmVmZGQ1
11
+ ZDg1YzE0NDg0NGJkYzNkMzZjZWExNjllZjBmMjc4MjNjYzAxYzA=
12
12
  data.tar.gz: !binary |-
13
- ODUxMmQwYTFjNzdmYzliMWYzZjk5ZDBjNDNlMTBjMzljMTIwYjcwZTcwZmQ2
14
- MGY5ZWY3NjRmMTIzYzUwNmYxMjFjYWU1YWUxYTJmZTVmYzNlYWYxMTUwNWYx
15
- MjgwNzdmMGM1OGI1ZDNlZjhlMzVhZmMyMWFhZmQ2NDRjN2ZhZmE=
13
+ MTA5YmE1NzRjMjQ3N2IxYTMzODVhZjNiNjFlYmI1OTgwMGQ0ZDM0Y2EwOGMy
14
+ Y2JkZjRhNGY0YmIyYmY2YWU3NWU2NGE2NDFhMGZkYzE2MTRiNzg4ZDFiN2I5
15
+ NGU0ZmY0NzM4NzRjNmVkNTEyMjU3NzJjODgwNThlZTExZWE2Njk=
@@ -13,11 +13,19 @@ module ControlledVersioning
13
13
  if pending?
14
14
  Revision::Publisher.new(self).accept_revision unless initial?
15
15
  update_attributes(pending: false, accepted: true)
16
+ versionable.try(:when_accepting_anything)
17
+ versionable.try(:when_accepting_an_initial_version) if initial?
18
+ versionable.try(:when_accepting_a_revision) unless initial?
16
19
  end
17
20
  end
18
21
 
19
22
  def decline
20
- update_attributes(pending: false, declined: true) if pending?
23
+ if pending?
24
+ update_attributes(pending: false, declined: true)
25
+ versionable.try(:when_declining_anything)
26
+ versionable.try(:when_declining_an_initial_version) if initial?
27
+ versionable.try(:when_declining_a_revision) unless initial?
28
+ end
21
29
  end
22
30
 
23
31
  def revisions
@@ -0,0 +1,4 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ no_revisions_made: "We didn't find any changes. Please make sure you've revised at least one attribute."
@@ -10,14 +10,9 @@ class Revision::Factory < Revision
10
10
 
11
11
  def build
12
12
  versionable.assign_attributes(suggested_attributes)
13
- if versionable.invalid?
14
- versionable.errors
15
- elsif !Revision::Auditor.new(versionable).changes_original?
16
- versionable.errors[:base] << I18n.t("errors.messages.no_revisions_made")
17
- versionable.errors
18
- else
19
- build_parent
20
- end
13
+ versionable.valid?
14
+ validate_presence_of_changes
15
+ versionable.errors.present? ? versionable : build_parent
21
16
  end
22
17
 
23
18
  def build_associations
@@ -27,6 +22,12 @@ class Revision::Factory < Revision
27
22
  end
28
23
 
29
24
  private
25
+ def validate_presence_of_changes
26
+ unless Revision::Auditor.new(versionable).changes_original?
27
+ versionable.errors[:base] << I18n.t("errors.messages.no_revisions_made")
28
+ end
29
+ end
30
+
30
31
  def build_parent
31
32
  self.version = versionable.versions.build
32
33
  version.notes = versionable_notes
@@ -1,3 +1,3 @@
1
1
  module ControlledVersioning
2
- VERSION_NUMBER = "0.9.2"
2
+ VERSION_NUMBER = "0.10.0"
3
3
  end
@@ -0,0 +1,31 @@
1
+ class HandlerResource < ActiveRecord::Base
2
+ acts_as_versionable
3
+
4
+ def when_accepting_anything
5
+ increment(:accept_count)
6
+ save
7
+ end
8
+
9
+ def when_accepting_an_initial_version
10
+ update_attribute(:accepted, true)
11
+ end
12
+
13
+ def when_accepting_a_revision
14
+ increment(:accepted_revisions_count)
15
+ save
16
+ end
17
+
18
+ def when_declining_anything
19
+ increment(:decline_count)
20
+ save
21
+ end
22
+
23
+ def when_declining_an_initial_version
24
+ update_attribute(:declined, true)
25
+ end
26
+
27
+ def when_declining_a_revision
28
+ increment(:declined_revisions_count)
29
+ save
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ class CreateHandlerResources < ActiveRecord::Migration
2
+ def change
3
+ create_table :handler_resources do |t|
4
+ t.boolean :r_boolean
5
+ t.date :r_date
6
+ t.datetime :r_datetime
7
+ t.decimal :r_decimal
8
+ t.float :r_float
9
+ t.integer :r_integer
10
+ t.string :r_string
11
+ t.text :r_text
12
+ t.time :r_time
13
+
14
+ t.integer :accept_count, null: false, default: 0
15
+ t.integer :decline_count, null: false, default: 0
16
+ t.integer :accepted_revisions_count, null: false, default: 0
17
+ t.integer :declined_revisions_count, null: false, default: 0
18
+
19
+ t.boolean :accepted, null: false, default: false
20
+ t.boolean :declined, null: false, default: false
21
+
22
+ t.timestamps
23
+ end
24
+ end
25
+ end
@@ -88,6 +88,26 @@ ActiveRecord::Schema.define(version: 20140206204920) do
88
88
  t.datetime "updated_at"
89
89
  end
90
90
 
91
+ create_table "handler_resources", force: true do |t|
92
+ t.boolean "r_boolean"
93
+ t.date "r_date"
94
+ t.datetime "r_datetime"
95
+ t.decimal "r_decimal"
96
+ t.float "r_float"
97
+ t.integer "r_integer"
98
+ t.string "r_string"
99
+ t.text "r_text"
100
+ t.time "r_time"
101
+ t.integer "accept_count", default: 0, null: false
102
+ t.integer "decline_count", default: 0, null: false
103
+ t.integer "accepted_revisions_count", default: 0, null: false
104
+ t.integer "declined_revisions_count", default: 0, null: false
105
+ t.boolean "accepted", default: false, null: false
106
+ t.boolean "declined", default: false, null: false
107
+ t.datetime "created_at"
108
+ t.datetime "updated_at"
109
+ end
110
+
91
111
  create_table "nonversionable_resources", force: true do |t|
92
112
  t.boolean "r_boolean"
93
113
  t.date "r_date"
@@ -0,0 +1,16 @@
1
+ FactoryGirl.define do
2
+ factory :handler_resource do
3
+ r_boolean true
4
+ r_date Date.today
5
+ r_datetime DateTime.now
6
+ r_decimal 3.14
7
+ r_float 3.14
8
+ r_integer 3
9
+ r_string "my string"
10
+ r_text "my text"
11
+ r_time Time.now
12
+
13
+ initialize_with { HandlerResource.create_with_version(attributes) }
14
+
15
+ end
16
+ end
@@ -73,9 +73,9 @@ describe ControlledVersioning::Version do
73
73
  changed_child = version.revisions.children.first
74
74
  changed_attribute = changed_child.attributes.first
75
75
  expect(changed_child.new?).to be_true
76
- expect(changed_attribute.name).to eq "r_float"
76
+ expect(changed_attribute.name).to eq "r_float" || "parent_id"
77
77
  expect(changed_attribute.old_value).to be_nil
78
- expect(changed_attribute.new_value).to eq "3.14"
78
+ expect(changed_attribute.new_value).to eq "3.14" || @resource.id
79
79
  end
80
80
 
81
81
  it 'marked children' do
@@ -88,6 +88,56 @@ describe ControlledVersioning::Version do
88
88
  end
89
89
  end
90
90
 
91
+ context 'allows for custom handling of' do
92
+ before :each do
93
+ @resource = create(:handler_resource)
94
+ @revision_one = @resource.submit_revision(r_string: "first revision")
95
+ @revision_two = @resource.submit_revision(r_string: "second revisions")
96
+ end
97
+
98
+ context 'acceptances of' do
99
+ before :each do
100
+ @resource.initial_version.accept
101
+ @revision_one.accept
102
+ @revision_two.accept
103
+ @resource.reload
104
+ end
105
+
106
+ it 'any kind' do
107
+ expect(@resource.accept_count).to eq 3
108
+ end
109
+
110
+ it 'initial versions' do
111
+ expect(@resource.accepted).to be_true
112
+ end
113
+
114
+ it 'revisions' do
115
+ expect(@resource.accepted_revisions_count).to eq 2
116
+ end
117
+ end
118
+
119
+ context 'declines of' do
120
+ before :each do
121
+ @resource.initial_version.decline
122
+ @revision_one.decline
123
+ @revision_two.decline
124
+ @resource.reload
125
+ end
126
+
127
+ it 'any kind' do
128
+ expect(@resource.decline_count).to eq 3
129
+ end
130
+
131
+ it 'initial versions' do
132
+ expect(@resource.declined).to be_true
133
+ end
134
+
135
+ it 'revisions' do
136
+ expect(@resource.declined_revisions_count).to eq 2
137
+ end
138
+ end
139
+ end
140
+
91
141
  context 'has a scope that' do
92
142
  before :each do
93
143
  @resource = create(:versionable_resource)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: controlled_versioning
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - timothythehuman
@@ -128,6 +128,7 @@ files:
128
128
  - app/models/controlled_versioning/version_attribute.rb
129
129
  - app/models/controlled_versioning/version_child.rb
130
130
  - app/views/layouts/controlled_versioning/application.html.erb
131
+ - config/locales/controlled_versioning.en.yml
131
132
  - db/migrate/20140206204853_create_controlled_versioning_versions.rb
132
133
  - db/migrate/20140206204910_create_controlled_versioning_version_attributes.rb
133
134
  - db/migrate/20140206204920_create_controlled_versioning_version_children.rb
@@ -156,6 +157,7 @@ files:
156
157
  - spec/dummy/app/helpers/application_helper.rb
157
158
  - spec/dummy/app/models/child_resource.rb
158
159
  - spec/dummy/app/models/grand_child_resource.rb
160
+ - spec/dummy/app/models/handler_resource.rb
159
161
  - spec/dummy/app/models/nonversionable_resource.rb
160
162
  - spec/dummy/app/models/parent_resource.rb
161
163
  - spec/dummy/app/models/partially_exclusive_versionable_resource.rb
@@ -191,6 +193,7 @@ files:
191
193
  - spec/dummy/db/migrate/20140117222840_create_parent_resources.rb
192
194
  - spec/dummy/db/migrate/20140117222841_create_child_resources.rb
193
195
  - spec/dummy/db/migrate/20140117222842_create_grand_child_resources.rb
196
+ - spec/dummy/db/migrate/20140118222842_create_handler_resources.rb
194
197
  - spec/dummy/db/schema.rb
195
198
  - spec/dummy/public/404.html
196
199
  - spec/dummy/public/422.html
@@ -198,6 +201,7 @@ files:
198
201
  - spec/dummy/public/favicon.ico
199
202
  - spec/factories/child_resources.rb
200
203
  - spec/factories/grand_child_resources.rb
204
+ - spec/factories/handler_resources.rb
201
205
  - spec/factories/parent_resources.rb
202
206
  - spec/factories/partially_exclusive_versionable_resources.rb
203
207
  - spec/factories/partially_inclusive_versionable_resources.rb
@@ -231,62 +235,65 @@ specification_version: 4
231
235
  summary: Adds model versioning to a Rails app, with the ability to approve and declined
232
236
  revisions.
233
237
  test_files:
238
+ - spec/factories/parent_resources.rb
239
+ - spec/factories/versionable_resources.rb
240
+ - spec/factories/grand_child_resources.rb
241
+ - spec/factories/handler_resources.rb
242
+ - spec/factories/partially_inclusive_versionable_resources.rb
243
+ - spec/factories/child_resources.rb
244
+ - spec/factories/partially_exclusive_versionable_resources.rb
245
+ - spec/factories/unversionable_resources.rb
246
+ - spec/factories/users.rb
247
+ - spec/spec_helper.rb
248
+ - spec/models/controlled_versioning/version_spec.rb
249
+ - spec/controlled_versioning_spec.rb
234
250
  - spec/dummy/Rakefile
235
- - spec/dummy/README.rdoc
236
- - spec/dummy/db/migrate/20140117222815_create_partially_exclusive_versionable_resources.rb
237
- - spec/dummy/db/migrate/20140117222800_create_users.rb
238
- - spec/dummy/db/migrate/20140117222840_create_parent_resources.rb
251
+ - spec/dummy/public/favicon.ico
252
+ - spec/dummy/public/422.html
253
+ - spec/dummy/public/500.html
254
+ - spec/dummy/public/404.html
255
+ - spec/dummy/bin/rake
256
+ - spec/dummy/bin/rails
257
+ - spec/dummy/bin/bundle
258
+ - spec/dummy/db/schema.rb
239
259
  - spec/dummy/db/migrate/20140117222808_create_versionable_resources.rb
260
+ - spec/dummy/db/migrate/20140117222840_create_parent_resources.rb
261
+ - spec/dummy/db/migrate/20140117222800_create_users.rb
262
+ - spec/dummy/db/migrate/20140117222842_create_grand_child_resources.rb
263
+ - spec/dummy/db/migrate/20140117222815_create_partially_exclusive_versionable_resources.rb
240
264
  - spec/dummy/db/migrate/20140117222828_create_nonversionable_resources.rb
241
- - spec/dummy/db/migrate/20140117222814_create_partially_inclusive_versionable_resources.rb
242
265
  - spec/dummy/db/migrate/20140117222841_create_child_resources.rb
243
- - spec/dummy/db/migrate/20140117222842_create_grand_child_resources.rb
244
- - spec/dummy/db/schema.rb
245
- - spec/dummy/bin/bundle
246
- - spec/dummy/bin/rake
247
- - spec/dummy/bin/rails
248
- - spec/dummy/public/500.html
249
- - spec/dummy/public/422.html
250
- - spec/dummy/public/favicon.ico
251
- - spec/dummy/public/404.html
252
- - spec/dummy/app/views/layouts/application.html.erb
253
- - spec/dummy/app/assets/stylesheets/application.css
254
- - spec/dummy/app/assets/javascripts/application.js
255
- - spec/dummy/app/controllers/application_controller.rb
256
- - spec/dummy/app/helpers/application_helper.rb
257
- - spec/dummy/app/models/user.rb
258
- - spec/dummy/app/models/parent_resource.rb
259
- - spec/dummy/app/models/partially_exclusive_versionable_resource.rb
260
- - spec/dummy/app/models/child_resource.rb
261
- - spec/dummy/app/models/nonversionable_resource.rb
262
- - spec/dummy/app/models/grand_child_resource.rb
263
- - spec/dummy/app/models/versionable_resource.rb
264
- - spec/dummy/app/models/partially_inclusive_versionable_resource.rb
266
+ - spec/dummy/db/migrate/20140117222814_create_partially_inclusive_versionable_resources.rb
267
+ - spec/dummy/db/migrate/20140118222842_create_handler_resources.rb
265
268
  - spec/dummy/config.ru
266
269
  - spec/dummy/config/boot.rb
267
- - spec/dummy/config/environments/development.rb
268
- - spec/dummy/config/environments/production.rb
269
- - spec/dummy/config/environments/test.rb
270
+ - spec/dummy/config/initializers/wrap_parameters.rb
270
271
  - spec/dummy/config/initializers/inflections.rb
272
+ - spec/dummy/config/initializers/session_store.rb
271
273
  - spec/dummy/config/initializers/backtrace_silencers.rb
274
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
272
275
  - spec/dummy/config/initializers/secret_token.rb
273
- - spec/dummy/config/initializers/wrap_parameters.rb
274
276
  - spec/dummy/config/initializers/mime_types.rb
275
- - spec/dummy/config/initializers/filter_parameter_logging.rb
276
- - spec/dummy/config/initializers/session_store.rb
277
- - spec/dummy/config/routes.rb
278
- - spec/dummy/config/application.rb
279
277
  - spec/dummy/config/locales/en.yml
278
+ - spec/dummy/config/application.rb
280
279
  - spec/dummy/config/environment.rb
280
+ - spec/dummy/config/routes.rb
281
+ - spec/dummy/config/environments/development.rb
282
+ - spec/dummy/config/environments/test.rb
283
+ - spec/dummy/config/environments/production.rb
281
284
  - spec/dummy/config/database.yml
282
- - spec/spec_helper.rb
283
- - spec/factories/child_resources.rb
284
- - spec/factories/grand_child_resources.rb
285
- - spec/factories/partially_inclusive_versionable_resources.rb
286
- - spec/factories/unversionable_resources.rb
287
- - spec/factories/users.rb
288
- - spec/factories/partially_exclusive_versionable_resources.rb
289
- - spec/factories/parent_resources.rb
290
- - spec/factories/versionable_resources.rb
291
- - spec/controlled_versioning_spec.rb
292
- - spec/models/controlled_versioning/version_spec.rb
285
+ - spec/dummy/app/controllers/application_controller.rb
286
+ - spec/dummy/app/models/versionable_resource.rb
287
+ - spec/dummy/app/models/user.rb
288
+ - spec/dummy/app/models/parent_resource.rb
289
+ - spec/dummy/app/models/partially_exclusive_versionable_resource.rb
290
+ - spec/dummy/app/models/child_resource.rb
291
+ - spec/dummy/app/models/nonversionable_resource.rb
292
+ - spec/dummy/app/models/handler_resource.rb
293
+ - spec/dummy/app/models/grand_child_resource.rb
294
+ - spec/dummy/app/models/partially_inclusive_versionable_resource.rb
295
+ - spec/dummy/app/views/layouts/application.html.erb
296
+ - spec/dummy/app/helpers/application_helper.rb
297
+ - spec/dummy/app/assets/javascripts/application.js
298
+ - spec/dummy/app/assets/stylesheets/application.css
299
+ - spec/dummy/README.rdoc