zombie_record 0.4.0 → 1.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: 8fffbb5b3d7304492d0999ef54eb7db4fc783cb5
4
- data.tar.gz: 121cc7d9627e7450500d076f025b501b52f31687
3
+ metadata.gz: c54fbb089be314efff0a17095023ff80ac9c68fe
4
+ data.tar.gz: a515209fd43f48a0f360eb60382d8ad8c00fdc10
5
5
  SHA512:
6
- metadata.gz: e45075a3ee932ef550c34120d0be0d92d601e7839a16e06d418e949e4fba0673738a7f8e830e6d4be35aaca08f3ea5aa6bd95d66db594a22fd09258d794222a1
7
- data.tar.gz: 38833db59a21a4bba05c96ba4d31fb34aefea3cd4d85912b9e5cbc1a3a71fa2dd3bb5d8c6217f82aa39d764a0b03f5c6144daf34d0f03bac67ad773d4b730dd3
6
+ metadata.gz: bd0b9759920d3fda72aef62f1e0ccde2ad618209922dc3fae568bd35310832e43d510871691a9f667b82491154a5e39b25d63859b464a21ae1173319aab9a685
7
+ data.tar.gz: 99901a30dc8e1d48c9066d05699529dbde1869c3e1e156c6368e8f43f9eebb3330a5ef447cf6a7f51fe7c04ee93b85f6817803558e826fd09c2ae5f10be99800
data/.travis.yml CHANGED
@@ -1,3 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
+ gemfile:
5
+ - gemfiles/rails4.0.gemfile
6
+ - gemfiles/rails4.1.gemfile
7
+ bundler_args: ""
8
+ script: "bundle exec rake spec"
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ###### Unreleased
2
+
3
+ ###### v1.1.0
4
+
5
+ * Add compatibility with Rails 4.1.
6
+
7
+ ###### v1.0.0
8
+
9
+ * Remove compatibility with Rails 3, instead adding compatibility with
10
+ Rails 4.0.
11
+
1
12
  ###### v0.4.0
2
13
 
3
14
  * Allow accessing associated records on deleted objects, even if they themselves
data/Gemfile CHANGED
@@ -2,5 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in zombie_record.gemspec
4
4
  gemspec
5
-
6
- gem "byebug"
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Allows restoring your Active Records from the dead!
4
4
 
5
+ [![Build Status](https://travis-ci.org/zendesk/zombie_record.svg?branch=master)](https://travis-ci.org/zendesk/zombie_record)
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -42,6 +44,10 @@ book.restore!
42
44
  Book.find(42) # returns the Book record.
43
45
  ```
44
46
 
47
+ ## Compatibility
48
+
49
+ Zombie Record only works with Active Record 4. For Active Record 3 compatibility, check out the activerecord-3 branch of this gem.
50
+
45
51
  ## Contributing
46
52
 
47
53
  1. Fork it
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require "wwtd/tasks"
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
5
6
 
6
- task :default => :spec
7
+ task :default => "wwtd:local"
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: "../"
4
+
5
+ gem "activerecord", "~> 4.0.12"
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ zombie_record (1.0.0)
5
+ activerecord (~> 4.0)
6
+ mysql2
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (4.0.12)
12
+ activesupport (= 4.0.12)
13
+ builder (~> 3.1.0)
14
+ activerecord (4.0.12)
15
+ activemodel (= 4.0.12)
16
+ activerecord-deprecated_finders (~> 1.0.2)
17
+ activesupport (= 4.0.12)
18
+ arel (~> 4.0.0)
19
+ activerecord-deprecated_finders (1.0.3)
20
+ activesupport (4.0.12)
21
+ i18n (~> 0.6, >= 0.6.9)
22
+ minitest (~> 4.2)
23
+ multi_json (~> 1.3)
24
+ thread_safe (~> 0.1)
25
+ tzinfo (~> 0.3.37)
26
+ arel (4.0.2)
27
+ builder (3.1.4)
28
+ byebug (3.5.1)
29
+ columnize (~> 0.8)
30
+ debugger-linecache (~> 1.2)
31
+ slop (~> 3.6)
32
+ columnize (0.8.9)
33
+ debugger-linecache (1.2.0)
34
+ diff-lcs (1.2.5)
35
+ i18n (0.6.11)
36
+ minitest (4.7.5)
37
+ multi_json (1.10.1)
38
+ mysql2 (0.3.17)
39
+ rake (10.3.2)
40
+ rspec (2.14.1)
41
+ rspec-core (~> 2.14.0)
42
+ rspec-expectations (~> 2.14.0)
43
+ rspec-mocks (~> 2.14.0)
44
+ rspec-core (2.14.8)
45
+ rspec-expectations (2.14.5)
46
+ diff-lcs (>= 1.1.3, < 2.0)
47
+ rspec-mocks (2.14.6)
48
+ slop (3.6.0)
49
+ thread_safe (0.3.4)
50
+ timecop (0.7.1)
51
+ tzinfo (0.3.42)
52
+ wwtd (0.5.5)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ activerecord (~> 4.0.12)
59
+ bundler (~> 1.3)
60
+ byebug
61
+ rake
62
+ rspec (~> 2.14.1)
63
+ timecop (~> 0.7.0)
64
+ wwtd (>= 0.5.3)
65
+ zombie_record!
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: "../"
4
+
5
+ gem "activerecord", "~> 4.1.8"
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ zombie_record (1.0.0)
5
+ activerecord (~> 4.0)
6
+ mysql2
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (4.1.8)
12
+ activesupport (= 4.1.8)
13
+ builder (~> 3.1)
14
+ activerecord (4.1.8)
15
+ activemodel (= 4.1.8)
16
+ activesupport (= 4.1.8)
17
+ arel (~> 5.0.0)
18
+ activesupport (4.1.8)
19
+ i18n (~> 0.6, >= 0.6.9)
20
+ json (~> 1.7, >= 1.7.7)
21
+ minitest (~> 5.1)
22
+ thread_safe (~> 0.1)
23
+ tzinfo (~> 1.1)
24
+ arel (5.0.1.20140414130214)
25
+ builder (3.2.2)
26
+ byebug (3.5.1)
27
+ columnize (~> 0.8)
28
+ debugger-linecache (~> 1.2)
29
+ slop (~> 3.6)
30
+ columnize (0.8.9)
31
+ debugger-linecache (1.2.0)
32
+ diff-lcs (1.2.5)
33
+ i18n (0.6.11)
34
+ json (1.8.1)
35
+ minitest (5.4.3)
36
+ mysql2 (0.3.17)
37
+ rake (10.3.2)
38
+ rspec (2.14.1)
39
+ rspec-core (~> 2.14.0)
40
+ rspec-expectations (~> 2.14.0)
41
+ rspec-mocks (~> 2.14.0)
42
+ rspec-core (2.14.8)
43
+ rspec-expectations (2.14.5)
44
+ diff-lcs (>= 1.1.3, < 2.0)
45
+ rspec-mocks (2.14.6)
46
+ slop (3.6.0)
47
+ thread_safe (0.3.4)
48
+ timecop (0.7.1)
49
+ tzinfo (1.2.2)
50
+ thread_safe (~> 0.1)
51
+ wwtd (0.5.5)
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ activerecord (~> 4.1.8)
58
+ bundler (~> 1.3)
59
+ byebug
60
+ rake
61
+ rspec (~> 2.14.1)
62
+ timecop (~> 0.7.0)
63
+ wwtd (>= 0.5.3)
64
+ zombie_record!
@@ -8,26 +8,6 @@ module ZombieRecord
8
8
  define_callbacks :restore
9
9
  end
10
10
 
11
- # Override Rails' #destroy for soft-delete functionality
12
- # When changing to Rails 4, override #destroy_row with a one-liner instead.
13
- def destroy
14
- run_callbacks :destroy do
15
- destroy_associations
16
-
17
- if persisted?
18
- time = current_time_from_proper_timezone
19
- update_column(:deleted_at, time)
20
-
21
- if self.class.column_names.include?("updated_at")
22
- update_column(:updated_at, time)
23
- end
24
- end
25
-
26
- @destroyed = true
27
- freeze
28
- end
29
- end
30
-
31
11
  # Restores a destroyed record.
32
12
  #
33
13
  # Returns nothing.
@@ -71,6 +51,16 @@ module ZombieRecord
71
51
 
72
52
  private
73
53
 
54
+ # Override Rails' #destroy_row for soft-delete functionality
55
+ def destroy_row
56
+ time = current_time_from_proper_timezone
57
+ update_column(:deleted_at, time)
58
+
59
+ if self.class.column_names.include?("updated_at")
60
+ update_column(:updated_at, time)
61
+ end
62
+ end
63
+
74
64
  def restore_associated_records!
75
65
  self.class.reflect_on_all_associations.each do |association|
76
66
  # Only restore associations that are automatically destroyed alongside
@@ -186,9 +176,15 @@ module ZombieRecord
186
176
  #
187
177
  # Returns an ActiveRecord::Relation.
188
178
  def with_deleted
189
- scoped.
190
- tap {|relation| relation.default_scoped = false }.
191
- extending(WithDeletedAssociationsWrapper)
179
+ if ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 0
180
+ all.
181
+ tap {|relation| relation.default_scoped = false }.
182
+ extending(WithDeletedAssociationsWrapper)
183
+ else
184
+ all.
185
+ unscope(where: :deleted_at).
186
+ extending(WithDeletedAssociationsWrapper)
187
+ end
192
188
  end
193
189
  end
194
190
  end
@@ -1,3 +1,3 @@
1
1
  module ZombieRecord
2
- VERSION = "0.4.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -9,7 +9,7 @@ describe ZombieRecord::Restorable do
9
9
  book.destroy
10
10
  book = Book.with_deleted.first
11
11
 
12
- book.cover.should == cover.reload
12
+ book.cover.should_not be_nil
13
13
  end
14
14
 
15
15
  it "allows accessing deleted belongs_to associations" do
@@ -18,11 +18,13 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "activerecord", "~> 3.2.15"
21
+ spec.add_dependency "activerecord", "~> 4.0"
22
22
  spec.add_dependency "mysql2"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "byebug"
25
26
  spec.add_development_dependency "rake"
26
- spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "rspec", "~> 2.14.1"
27
28
  spec.add_development_dependency "timecop", "~> 0.7.0"
29
+ spec.add_development_dependency "wwtd", ">= 0.5.3"
28
30
  end
metadata CHANGED
@@ -1,99 +1,127 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zombie_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Schierbeck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-26 00:00:00.000000000 Z
11
+ date: 2014-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 3.2.15
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.2.15
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mysql2
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '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
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: byebug
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rspec
70
+ name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 2.14.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 2.14.1
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: timecop
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - "~>"
101
+ - - ~>
88
102
  - !ruby/object:Gem::Version
89
103
  version: 0.7.0
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - "~>"
108
+ - - ~>
95
109
  - !ruby/object:Gem::Version
96
110
  version: 0.7.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: wwtd
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.5.3
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: 0.5.3
97
125
  description: Allows restoring your Active Records from the dead!
98
126
  email:
99
127
  - dasch@zendesk.com
@@ -101,14 +129,18 @@ executables: []
101
129
  extensions: []
102
130
  extra_rdoc_files: []
103
131
  files:
104
- - ".gitignore"
105
- - ".rspec"
106
- - ".travis.yml"
132
+ - .gitignore
133
+ - .rspec
134
+ - .travis.yml
107
135
  - CHANGELOG.md
108
136
  - Gemfile
109
137
  - LICENSE.txt
110
138
  - README.md
111
139
  - Rakefile
140
+ - gemfiles/rails4.0.gemfile
141
+ - gemfiles/rails4.0.gemfile.lock
142
+ - gemfiles/rails4.1.gemfile
143
+ - gemfiles/rails4.1.gemfile.lock
112
144
  - lib/zombie_record.rb
113
145
  - lib/zombie_record/restorable.rb
114
146
  - lib/zombie_record/version.rb
@@ -125,21 +157,20 @@ require_paths:
125
157
  - lib
126
158
  required_ruby_version: !ruby/object:Gem::Requirement
127
159
  requirements:
128
- - - ">="
160
+ - - '>='
129
161
  - !ruby/object:Gem::Version
130
162
  version: '0'
131
163
  required_rubygems_version: !ruby/object:Gem::Requirement
132
164
  requirements:
133
- - - ">="
165
+ - - '>='
134
166
  - !ruby/object:Gem::Version
135
167
  version: '0'
136
168
  requirements: []
137
169
  rubyforge_project:
138
- rubygems_version: 2.2.2
170
+ rubygems_version: 2.1.11
139
171
  signing_key:
140
172
  specification_version: 4
141
173
  summary: Allows restoring your Active Records from the dead!
142
174
  test_files:
143
175
  - spec/restorable_spec.rb
144
176
  - spec/spec_helper.rb
145
- has_rdoc: