once-ler 0.0.16 → 0.1.0

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: 951a2d0bc2021d055676679c236ee9f6979c7a6a
4
- data.tar.gz: e2eecf83edbb67e80610d15c59e5465510b2c2a8
3
+ metadata.gz: ed16df6da817425b161a3d9b887c094ca5eac560
4
+ data.tar.gz: acb176d0ec4def0482486a1da7cf1dd9189f5dfa
5
5
  SHA512:
6
- metadata.gz: deec33b613d9fb1b2f140473e4c10daa37f312a0b75c9a36e87dc66d209d0ab4873447cc38cf4141f2784b10422f6347e2ef6f7630961653c1cc1b9829f15c61
7
- data.tar.gz: fb0391864d777e3c91dd4996a86bbcd4c3f0f5d61cca71471ce67deffb43d11393b98964798faa2b009ef901b071c28121619772cbc841f109671664267b8c66
6
+ metadata.gz: 90ddd7d85c492c37b65fb5bfe5a01c1fd6e6a74013eec09a0e92cc9098d0348ef161ff1c7d6065e382c931bdc089d67a0088b39fbbb0ac345402ef5823f52376
7
+ data.tar.gz: 498383c10083fd113abb5df9843517ef3f633689604c2dc01af8793832b1d3724353ec7765036e29f1031178dc77eb4c6452948dcf8692380e4c50eb0361ed45
@@ -2,10 +2,6 @@ require "active_record"
2
2
 
3
3
  if ActiveRecord::VERSION::STRING >= "4.1."
4
4
  require "onceler/extensions/active_record_4_1"
5
- elsif ActiveRecord::VERSION::STRING >= "4.0."
6
- require "onceler/extensions/active_record_4_0"
7
- elsif ActiveRecord::VERSION::STRING >= "3.2."
8
- require "onceler/extensions/active_record_3_2"
9
5
  else
10
- require "onceler/extensions/active_record_3_0"
6
+ require "onceler/extensions/active_record_4_0"
11
7
  end
@@ -1,3 +1,5 @@
1
+ require "set"
2
+
1
3
  module Onceler
2
4
  module Recordable
3
5
  def self.extended(instance)
@@ -70,8 +72,8 @@ module Onceler
70
72
  # if a nested once block updates an inherited object's associations,
71
73
  # we want to know about it
72
74
  def __associations_equal?(obj1, obj2)
73
- cache1 = obj1.association_cache
74
- cache2 = obj2.association_cache
75
+ cache1 = obj1.instance_variable_get(:@association_cache)
76
+ cache2 = obj2.instance_variable_get(:@association_cache)
75
77
  cache1.size == cache2.size &&
76
78
  cache1.all? { |k, v| cache2.key?(k) && __values_equal?(v.target, cache2[k].target) }
77
79
  end
@@ -86,19 +88,53 @@ module Onceler
86
88
  rescue TypeError
87
89
  data.each do |hash|
88
90
  hash.each do |key, val|
89
- begin
90
- Marshal.dump(val)
91
- rescue TypeError
92
- raise TypeError.new("Unable to dump #{key} in #{self.class.metadata[:location]}: #{$!}")
93
- end
91
+ find_dump_error(key, val)
94
92
  end
95
93
  end
94
+ raise # find_dump_error should have re-raised, but just in case...
95
+ ensure
96
+ __visited_dump_vars.clear
96
97
  end
97
98
  @__comparison_cache = nil
98
99
  data
99
100
  end
100
101
  end
101
102
 
103
+ def __visited_dump_vars
104
+ @__visited_dump_vars ||= Set.new
105
+ end
106
+
107
+ def find_dump_error(key, val, prefix = "")
108
+ return if __visited_dump_vars.include?(val)
109
+ __visited_dump_vars << val
110
+
111
+ Marshal.dump(val)
112
+ rescue TypeError
113
+
114
+ # see if anything inside val can't be dumped...
115
+ sub_prefix = "#{prefix}#{key} (#<#{val.class}>) => "
116
+
117
+ # instance var?
118
+ val.instance_variables.each do |k|
119
+ v = val.instance_variable_get(k)
120
+ find_dump_error(k, v, sub_prefix)
121
+ end
122
+
123
+ # hash key/value?
124
+ val.each_pair do |k, v|
125
+ find_dump_error("hash key #{k}", k, sub_prefix)
126
+ find_dump_error("[#{k.inspect}]", v, sub_prefix)
127
+ end if val.respond_to?(:each_pair)
128
+
129
+ # array element?
130
+ val.each_with_index do |v, i|
131
+ find_dump_error("[#{i}]", v, sub_prefix)
132
+ end if val.respond_to?(:each_with_index)
133
+
134
+ # guess it's val proper
135
+ raise TypeError.new("Unable to dump #{prefix}#{key} (#<#{val.class}>) in #{self.class.metadata[:location]}: #{$!}")
136
+ end
137
+
102
138
  def copy_from(other)
103
139
  # need two copies of things for __mutated? checks (see above)
104
140
  @__inherited_cache = Marshal.load(other.__data(:inherit)).inject(&:merge)
@@ -1,7 +1,2 @@
1
1
  require "active_record"
2
- if ActiveRecord::VERSION::MAJOR >= 4
3
- require "onceler/transactions/active_record_4"
4
- else
5
- require "onceler/transactions/active_record_3"
6
- end
7
-
2
+ require "onceler/transactions/active_record_4"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: once-ler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Jensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-23 00:00:00.000000000 Z
11
+ date: 2017-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.1'
19
+ version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.1'
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '2.14'
33
+ version: '3.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '2.14'
40
+ version: '3.0'
41
41
  description: once-ler supercharges your let's and before's with the performance of
42
42
  before(:all)
43
43
  email: jon@instructure.com
@@ -52,15 +52,12 @@ files:
52
52
  - lib/onceler/basic_helpers.rb
53
53
  - lib/onceler/configuration.rb
54
54
  - lib/onceler/extensions/active_record.rb
55
- - lib/onceler/extensions/active_record_3_0.rb
56
- - lib/onceler/extensions/active_record_3_2.rb
57
55
  - lib/onceler/extensions/active_record_4_0.rb
58
56
  - lib/onceler/extensions/active_record_4_1.rb
59
57
  - lib/onceler/extensions/database_cleaner.rb
60
58
  - lib/onceler/recordable.rb
61
59
  - lib/onceler/recorder.rb
62
60
  - lib/onceler/transactions.rb
63
- - lib/onceler/transactions/active_record_3.rb
64
61
  - lib/onceler/transactions/active_record_4.rb
65
62
  homepage: http://github.com/instructure/onceler
66
63
  licenses: []
@@ -81,9 +78,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
78
  version: 1.3.5
82
79
  requirements: []
83
80
  rubyforge_project:
84
- rubygems_version: 2.2.2
81
+ rubygems_version: 2.5.1
85
82
  signing_key:
86
83
  specification_version: 4
87
84
  summary: rspec supercharger
88
85
  test_files: []
89
- has_rdoc:
@@ -1,53 +0,0 @@
1
- require "onceler/transactions"
2
-
3
- # monkey-patch these to use savepoints (if necessary)
4
-
5
- module ActiveRecord::TestFixtures
6
- include Onceler::Transactions
7
-
8
- def setup_fixtures
9
- return unless defined?(ActiveRecord) && !ActiveRecord::Base.configurations.blank?
10
-
11
- if pre_loaded_fixtures && !use_transactional_fixtures
12
- raise RuntimeError, 'pre_loaded_fixtures requires use_transactional_fixtures'
13
- end
14
-
15
- @fixture_cache = {}
16
- @@already_loaded_fixtures ||= {}
17
-
18
- # Load fixtures once and begin transaction.
19
- if run_in_transaction?
20
- if @@already_loaded_fixtures[self.class]
21
- @loaded_fixtures = @@already_loaded_fixtures[self.class]
22
- else
23
- load_fixtures
24
- @@already_loaded_fixtures[self.class] = @loaded_fixtures
25
- end
26
- ### ONCELER'd
27
- begin_transaction(ActiveRecord::Base.connection)
28
- # Load fixtures for every test.
29
- else
30
- Fixtures.reset_cache
31
- @@already_loaded_fixtures[self.class] = nil
32
- load_fixtures
33
- end
34
-
35
- # Instantiate fixtures for every test if requested.
36
- instantiate_fixtures if use_instantiated_fixtures
37
- end
38
-
39
- def teardown_fixtures
40
- return unless defined?(ActiveRecord) && !ActiveRecord::Base.configurations.blank?
41
-
42
- unless run_in_transaction?
43
- ActiveRecord::Fixtures.reset_cache
44
- end
45
-
46
- # Rollback changes if a transaction is active.
47
- if run_in_transaction? && ActiveRecord::Base.connection.open_transactions != 0
48
- ### ONCELER'd
49
- rollback_transaction(ActiveRecord::Base.connection)
50
- end
51
- ActiveRecord::Base.clear_active_connections!
52
- end
53
- end
@@ -1,63 +0,0 @@
1
- require "onceler/transactions"
2
-
3
- # monkey-patch these to use savepoints (if necessary)
4
-
5
- module ActiveRecord::TestFixtures
6
- include ::Onceler::Transactions
7
-
8
- def setup_fixtures
9
- return unless !ActiveRecord::Base.configurations.blank?
10
-
11
- if pre_loaded_fixtures && !use_transactional_fixtures
12
- raise RuntimeError, 'pre_loaded_fixtures requires use_transactional_fixtures'
13
- end
14
-
15
- @fixture_cache = {}
16
- @fixture_connections = []
17
- @@already_loaded_fixtures ||= {}
18
-
19
- # Load fixtures once and begin transaction.
20
- if run_in_transaction?
21
- if @@already_loaded_fixtures[self.class]
22
- @loaded_fixtures = @@already_loaded_fixtures[self.class]
23
- else
24
- @loaded_fixtures = load_fixtures
25
- @@already_loaded_fixtures[self.class] = @loaded_fixtures
26
- end
27
- @fixture_connections = enlist_fixture_connections
28
- @fixture_connections.each do |connection|
29
- ### ONCELER'd
30
- begin_transaction(connection)
31
- end
32
- # Load fixtures for every test.
33
- else
34
- ActiveRecord::Fixtures.reset_cache
35
- @@already_loaded_fixtures[self.class] = nil
36
- @loaded_fixtures = load_fixtures
37
- end
38
-
39
- # Instantiate fixtures for every test if requested.
40
- instantiate_fixtures if use_instantiated_fixtures
41
- end
42
-
43
- def teardown_fixtures
44
- return unless defined?(ActiveRecord) && !ActiveRecord::Base.configurations.blank?
45
-
46
- unless run_in_transaction?
47
- ActiveRecord::Fixtures.reset_cache
48
- end
49
-
50
- # Rollback changes if a transaction is active.
51
- if run_in_transaction?
52
- @fixture_connections.each do |connection|
53
- if connection.open_transactions != 0
54
- ### ONCELER'd
55
- rollback_transaction(connection)
56
- end
57
- end
58
- @fixture_connections.clear
59
- end
60
- ActiveRecord::Base.clear_active_connections!
61
- end
62
- end
63
-
@@ -1,23 +0,0 @@
1
- module Onceler
2
- module Transactions
3
- def begin_transaction(conn)
4
- if conn.open_transactions == 0
5
- conn.transaction_joinable = false
6
- conn.begin_db_transaction
7
- else
8
- conn.create_savepoint
9
- end
10
- conn.increment_open_transactions
11
- end
12
-
13
- def rollback_transaction(conn)
14
- conn.decrement_open_transactions
15
- if conn.open_transactions == 0
16
- conn.rollback_db_transaction
17
- else
18
- conn.rollback_to_savepoint
19
- end
20
- end
21
- end
22
- end
23
-