record_collection 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69468333eb7b36ccfe4e161a27349d8c0c88eb97
4
- data.tar.gz: f11c4e74135a921ff668565f2806bd1e21dbd21e
3
+ metadata.gz: 2d78564aff4c9d3493bf4e5c3cfe0adcd45dc1dd
4
+ data.tar.gz: 9caf058b010b857cdc2130e78f104eac76a8bf43
5
5
  SHA512:
6
- metadata.gz: 6efdd0029314ff4867e3c894b7bb634fedcdbb23dfc1d8bdcd29531fe429820236ae0d68357074ef6d37770de8ae952f8d7d4266edece99ba9f6a94e4c9e18e6
7
- data.tar.gz: a5cff88bcf12c8e0739cac8f94b61981afe9383ff1f5119f519d2d43822041e2c562611b158bea30f8fc43854ae9a0a3d8aa97207e01aac3c49bc3a3228c1397
6
+ metadata.gz: da13c3bd14acad5192abacdf8cfe328a95c09611e01a2811d615cf89d5c420c78ed63f00a4da523f5031ba1ce6c750ba8e17e5c8d37891f5fe6b90b902adecc7
7
+ data.tar.gz: 330143a4fb2164d75ec1fad8f2d8292e213a418464ffd7991691ded829ae6630f3ba5476b6c80a982a91b6c9918ff981e3a8444f1551501c57a66b80dcdde818
@@ -24,6 +24,14 @@ module RecordCollection
24
24
  end
25
25
  end
26
26
 
27
+ def after_record_update(&blk)
28
+ if blk
29
+ @after_record_update = blk
30
+ else
31
+ @after_record_update
32
+ end
33
+ end
34
+
27
35
  alias_method :old_validates, :validates
28
36
  def validates(attr, options)
29
37
  # Collection nil attributes mean they do not play a role for the collection.
@@ -66,7 +74,12 @@ module RecordCollection
66
74
  end
67
75
 
68
76
  def update_collection_attributes!
69
- each { |r| r.update changed_attributes }
77
+ after_blk = self.class.after_record_update
78
+ each do |record|
79
+ record.update changed_attributes
80
+ after_blk.call(record) if after_blk
81
+ end
82
+ self
70
83
  end
71
84
 
72
85
  def changed_attributes
@@ -1,3 +1,3 @@
1
1
  module RecordCollection
2
- VERSION = "0.4.5"
2
+ VERSION = "0.4.6"
3
3
  end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ class AfterRecordUpdateCollection < RecordCollection::Base
3
+ attribute :section
4
+ after_record_update{|record| record.update(admin: true) }
5
+ end
6
+ RSpec.describe AfterRecordUpdateCollection do
7
+ subject { described_class.new }
8
+ it "executes on the record" do
9
+ employee = Employee.create section: 'SE1', admin: false
10
+ described_class.new([employee]).update({})
11
+ employee.reload
12
+ employee.admin.should be true
13
+ end
14
+ end
data/spec/spec_helper.rb CHANGED
@@ -20,6 +20,10 @@ RSpec.configure do |config|
20
20
  config.mock_with :rspec
21
21
  config.include Dummy::Application.routes.url_helpers, type: :feature
22
22
 
23
+ config.before :each do
24
+ Employee.delete_all
25
+ end
26
+
23
27
  config.expect_with :rspec do |c|
24
28
  c.syntax = [:should, :expect]
25
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: record_collection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin ter Kuile
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-08 00:00:00.000000000 Z
11
+ date: 2015-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -307,6 +307,7 @@ files:
307
307
  - lib/record_collection/rails/routes.rb
308
308
  - lib/record_collection/version.rb
309
309
  - record_collection.gemspec
310
+ - spec/base/after_record_update_spec.rb
310
311
  - spec/base/delegation_spec.rb
311
312
  - spec/base/finding_records_spec.rb
312
313
  - spec/base/validations_spec.rb
@@ -404,6 +405,7 @@ signing_key:
404
405
  specification_version: 4
405
406
  summary: Manage collections of records in Ruby on Rails
406
407
  test_files:
408
+ - spec/base/after_record_update_spec.rb
407
409
  - spec/base/delegation_spec.rb
408
410
  - spec/base/finding_records_spec.rb
409
411
  - spec/base/validations_spec.rb