copyable 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f42c56201c71a8dae13510b60503300a1f8bfd27
4
- data.tar.gz: c4efc57da93c3b9f0a3ff7134dc00bbb84fbba2d
3
+ metadata.gz: 4e51f2b73f6b3f642d8b9174567c245c2f875b6a
4
+ data.tar.gz: c56647390d32496da7fbe0f971d9e86d2299b070
5
5
  SHA512:
6
- metadata.gz: 69a4aa712cf34f9cba8f598dee4b970bf482ab9b6b71558b14fd5fd0c9a9dfcf7dcb2644543db4ec21c71cc118af0bde080eda5b6f15ab78ba1baecc5d3d5f93
7
- data.tar.gz: a64545cc78dea5befe38066e86cdda5a6486bfd5115d77fcda21810802674ce8e7f40a61e9c8637bef8efcc0aa8dcab0d6a041e617b2df40bd1fa96cf9c661bc
6
+ metadata.gz: 236d9f5a60f236f49d99b2a8f47586ea2678bbd1c2a97c86d2e0dd7eaabf4dafe90065f8e09b9fd32b6f8c9c75188e4ee27c4977c9e3ffd198a85124ed1c13c5
7
+ data.tar.gz: b59f9f190720c3dbc37646795017d52953078f7bf8d7a2726fef9aa891e29c67579e911d021029b9b2def2f9898f4a5f05b163644bbba2e7fcdea506b50bcb6d
@@ -1,4 +1,4 @@
1
- Copyright (c) 2016 Dennis Chan
1
+ Copyright (c) 2017 District Management Group
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -267,4 +267,4 @@ So the recommended approach is to use `after_copy` to tweak the columns of the c
267
267
 
268
268
  ## About
269
269
 
270
- Copyable was developed at [the District Management Council](http://dmcouncil.org).
270
+ Copyable was developed at [District Management Group](https://dmgroupK12.com).
@@ -16,6 +16,9 @@ module Copyable
16
16
 
17
17
  def self.disable_all_callbacks(klass)
18
18
  klass.class_eval do
19
+ # Don't do it if it was already done
20
+ return if self.method_defined? :__disabled__run_callbacks
21
+
19
22
  alias_method :__disabled__run_callbacks, :run_callbacks
20
23
  # We are violently duck-punching ActiveRecord because ActiveRecord
21
24
  # gives us no way to turn off callbacks. My apologies to the
@@ -32,7 +35,11 @@ module Copyable
32
35
 
33
36
  def self.reenable_all_callbacks(klass)
34
37
  klass.class_eval do
38
+ # Only do it if the disabled callbacks are defined
39
+ return unless self.method_defined? :__disabled__run_callbacks
40
+
35
41
  alias_method :run_callbacks, :__disabled__run_callbacks
42
+ remove_method :__disabled__run_callbacks
36
43
  end
37
44
  end
38
45
 
@@ -1,3 +1,3 @@
1
1
  module Copyable
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -12,18 +12,6 @@ end
12
12
 
13
13
 
14
14
 
15
- #*******************************************************************************
16
- # For testing observers.
17
- #
18
-
19
- class CopyableCar < ActiveRecord::Base
20
- validates :make, presence: true
21
- validates :model, presence: true
22
- validates :year, presence: true
23
- end
24
-
25
-
26
-
27
15
  #*******************************************************************************
28
16
  # For testing callbacks.
29
17
  #
@@ -7,24 +7,19 @@ describe Copyable::ModelHooks do
7
7
 
8
8
  describe '.disable!' do
9
9
  before(:each) do
10
- puts "Dennis before!"
11
10
  Copyable::ModelHooks.disable!(CopyableTree)
12
11
  end
13
12
  after(:each) do
14
- puts "Dennis after"
15
13
  Copyable::ModelHooks.reenable!(CopyableTree)
16
14
  end
17
15
  it 'should prevent callbacks from executing' do
18
- puts "Dennis 1"
19
16
  expect {
20
- tree = CopyableTree.create!(kind: 'magnolia')
17
+ CopyableTree.create!(kind: 'magnolia')
21
18
  }.to_not raise_error
22
- puts "Dennis 2"
23
19
  end
24
20
  it 'should not prevent model actions from executing' do
25
- puts "Dennis 4"
26
21
  expect(CopyableTree.count).to eq(0)
27
- tree = CopyableTree.create!(kind: 'magnolia')
22
+ CopyableTree.create!(kind: 'magnolia')
28
23
  expect(CopyableTree.count).to eq(1)
29
24
  end
30
25
  end
@@ -34,33 +29,65 @@ describe Copyable::ModelHooks do
34
29
  Copyable::ModelHooks.disable!(CopyableTree)
35
30
  Copyable::ModelHooks.reenable!(CopyableTree)
36
31
  expect {
37
- tree = CopyableTree.create!(kind: 'magnolia')
32
+ CopyableTree.create!(kind: 'magnolia')
38
33
  }.to raise_error(RuntimeError, "callback2 called")
39
34
  end
40
35
  end
41
36
  end
42
37
 
43
- context 'observers' do
38
+ context 'validations' do
44
39
 
45
40
  # Note: the relevant model and observer class is defined in helper/test_models.rb
46
41
 
47
42
  describe '.disable!' do
48
43
  before(:each) do
49
- Copyable::ModelHooks.disable!(CopyableCar)
44
+ Copyable::ModelHooks.disable!(CopyableCoin)
50
45
  end
51
46
  after(:each) do
52
- Copyable::ModelHooks.reenable!(CopyableCar)
47
+ Copyable::ModelHooks.reenable!(CopyableCoin)
53
48
  end
54
- it 'should prevent observers from executing' do
49
+ it 'should prevent validations from executing' do
55
50
  expect {
56
- car = CopyableCar.create!(make: 'Ferrari', model: 'California', year: 2009)
51
+ CopyableCoin.create!(year: -10)
57
52
  }.to_not raise_error
58
53
  end
59
54
  it 'should not prevent model actions from executing' do
60
- expect(CopyableCar.count).to eq(0)
61
- car = CopyableCar.create!(make: 'Ferrari', model: 'California', year: 2009)
62
- expect(CopyableCar.count).to eq(1)
55
+ expect(CopyableCoin.count).to eq(0)
56
+ CopyableCoin.create!(year: -10)
57
+ expect(CopyableCoin.count).to eq(1)
63
58
  end
64
59
  end
60
+
61
+ describe '.reenable!' do
62
+ it 'should allow validations to execute again' do
63
+ Copyable::ModelHooks.disable!(CopyableCoin)
64
+ Copyable::ModelHooks.reenable!(CopyableCoin)
65
+ expect {
66
+ CopyableCoin.create!(year: -10)
67
+ }.to raise_error(ActiveRecord::RecordInvalid)
68
+ end
69
+ end
70
+ end
71
+
72
+ describe 'nested disables and enables' do
73
+ it 'should allow callbacks to execute again' do
74
+ Copyable::ModelHooks.disable!(CopyableTree)
75
+ expect { CopyableTree.create!(kind: 'magnolia') }.to_not raise_error
76
+
77
+ Copyable::ModelHooks.disable!(CopyableCoin)
78
+ expect { CopyableCoin.create!(year: -10) }.to_not raise_error
79
+
80
+ Copyable::ModelHooks.disable!(CopyableTree)
81
+ expect { CopyableTree.create!(kind: 'magnolia') }.to_not raise_error
82
+
83
+ Copyable::ModelHooks.reenable!(CopyableCoin)
84
+ expect { CopyableCoin.create!(year: -10) }.to raise_error(ActiveRecord::RecordInvalid)
85
+
86
+ Copyable::ModelHooks.reenable!(CopyableTree)
87
+ expect { CopyableTree.create!(kind: 'magnolia') }.to raise_error(RuntimeError)
88
+
89
+ Copyable::ModelHooks.reenable!(CopyableTree)
90
+ expect { CopyableTree.create!(kind: 'magnolia') }.to raise_error(RuntimeError)
91
+ end
65
92
  end
66
93
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: copyable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wyatt Greene
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-21 00:00:00.000000000 Z
12
+ date: 2018-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -174,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  version: '0'
175
175
  requirements: []
176
176
  rubyforge_project:
177
- rubygems_version: 2.4.8
177
+ rubygems_version: 2.6.12
178
178
  signing_key:
179
179
  specification_version: 4
180
180
  summary: ActiveRecord copier