paranoia 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6d1586094e7835b1d718602ae37b0c333a45a553
4
+ data.tar.gz: 3df4961b93e213a09baf0eb4db5c0df0a40bb5cf
5
+ SHA512:
6
+ metadata.gz: 6c803ff4e4a54f80fd99fbd10ee8ae18b9db6a3c85ac12ba7d8da0199fa639fcb812190310735ed36fa2c4c3ddcb7684f57b6a579cd58bb4be6b513e7fa25a87
7
+ data.tar.gz: e0df9dc5dacce1342a164a03d9bd462b2d4c2e3acf231a85dbe2297a0d38fd49ea8a8fa39bdec98c89c79e4130e1bb3a7385c2d111ed8d37c4b99c32a6d9854d
data/.gitignore CHANGED
@@ -3,3 +3,4 @@ pkg/*
3
3
  .bundle
4
4
  tmp
5
5
  .rvmrc
6
+ Gemfile.lock
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :gemcutter
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in paranoia.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -12,52 +12,32 @@ Put this in your Gemfile:
12
12
  gem 'paranoia'
13
13
  ```
14
14
 
15
- Then run `bundle`. Done.
16
-
17
- Updating is as simple as `bundle update paranoia`.
18
-
19
- #### Rails 3
20
-
21
- In your _Gemfile_:
22
-
23
- ```ruby
24
- gem 'paranoia'
25
- ```
26
-
27
15
  Then run:
28
16
 
29
17
  ```shell
30
18
  bundle install
31
19
  ```
32
20
 
33
- #### Rails 2:
34
-
35
- In your _config/environment.rb_:
21
+ Updating is as simple as `bundle update paranoia`.
36
22
 
37
- ```ruby
38
- config.gem 'paranoia'
39
- ```
23
+ #### Run your migrations for the desired models
40
24
 
41
- Then run:
25
+ Run:
42
26
 
43
27
  ```shell
44
- rake gems:install
28
+ rails generate migration AddDeletedAtToClients deleted_at:datetime
45
29
  ```
46
30
 
47
- #### Run your migrations for the desired models
31
+ and now you have a migration
48
32
 
49
33
  ```ruby
50
- class AddDeletedAtToClient < ActiveRecord::Migration
51
- def self.up
34
+ class AddDeletedAtToClients < ActiveRecord::Migration
35
+ def change
52
36
  add_column :clients, :deleted_at, :datetime
53
37
  end
54
-
55
- def self.down
56
- remove_column :clients, :deleted_at
57
- end
58
38
  end
59
39
  ```
60
-
40
+
61
41
  ### Usage
62
42
 
63
43
  #### In your model:
@@ -90,16 +70,12 @@ end
90
70
 
91
71
  You can replace the older acts_as_paranoid methods as follows:
92
72
 
93
- ```ruby
94
- find_with_deleted(:all) # => with_deleted
95
- find_with_deleted(:first) # => with_deleted.first
96
- find_with_deleted(id) # => with_deleted.find(id)
97
-
98
- find_only_deleted(:all) # => only_deleted
99
- find_only_deleted(:first) # => only_deleted.first
100
- find_only_deleted(id) # => only_deleted.find(id)
101
- ```
73
+ | Old Syntax | New Syntax |
74
+ |:-------------------------- |:------------------------------ |
75
+ |`find_with_deleted(:all)` | `Client.with_deleted` |
76
+ |`find_with_deleted(:first)` | `Client.with_deleted.first` |
77
+ |`find_with_deleted(id)` | `Client.with_deleted.find(id)` |
102
78
 
103
79
  ## License
104
80
 
105
- This gem is released under the MIT license.
81
+ This gem is released under the MIT license.
data/lib/paranoia.rb CHANGED
@@ -7,21 +7,21 @@ module Paranoia
7
7
  def paranoid? ; true ; end
8
8
 
9
9
  def only_deleted
10
- scoped.tap { |x| x.default_scoped = false }.where("#{self.table_name}.deleted_at is not null")
10
+ all.tap { |x| x.default_scoped = false }.where("#{self.table_name}.deleted_at is not null")
11
11
  end
12
12
 
13
13
  def with_deleted
14
- scoped.tap { |x| x.default_scoped = false }
14
+ all.tap { |x| x.default_scoped = false }
15
15
  end
16
16
  end
17
17
 
18
18
  def destroy
19
- _run_destroy_callbacks { delete }
19
+ run_callbacks(:destroy) { delete }
20
20
  end
21
21
 
22
22
  def delete
23
- update_attribute_or_column(:deleted_at, Time.now) if !deleted? && persisted?
24
- freeze
23
+ return if new_record? or destroyed?
24
+ update_attribute_or_column :deleted_at, Time.now
25
25
  end
26
26
 
27
27
  def restore!
@@ -43,10 +43,10 @@ end
43
43
 
44
44
  class ActiveRecord::Base
45
45
  def self.acts_as_paranoid
46
- alias_method :destroy!, :destroy
47
- alias_method :delete!, :delete
46
+ alias :destroy! :destroy
47
+ alias :delete! :delete
48
48
  include Paranoia
49
- default_scope :conditions => { :deleted_at => nil }
49
+ default_scope { where(:deleted_at => nil) }
50
50
  end
51
51
 
52
52
  def self.paranoid? ; false ; end
@@ -1,3 +1,3 @@
1
1
  module Paranoia
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
data/paranoia.gemspec CHANGED
@@ -14,11 +14,12 @@ Gem::Specification.new do |s|
14
14
  s.required_rubygems_version = ">= 1.3.6"
15
15
  s.rubyforge_project = "paranoia"
16
16
 
17
- s.add_dependency "activerecord", ">= 3.0.0"
17
+ s.add_dependency "activerecord", "~> 3.2"
18
18
 
19
19
  s.add_development_dependency "bundler", ">= 1.0.0"
20
20
  s.add_development_dependency "sqlite3"
21
21
  s.add_development_dependency "rake", "0.8.7"
22
+ s.add_development_dependency "pry"
22
23
 
23
24
  s.files = `git ls-files`.split("\n")
24
25
  s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
@@ -54,7 +54,6 @@ class ParanoiaTest < Test::Unit::TestCase
54
54
  model.destroy
55
55
 
56
56
  assert_equal true, model.deleted_at.nil?
57
- assert model.frozen?
58
57
 
59
58
  assert_equal 0, model.class.count
60
59
  assert_equal 0, model.class.unscoped.count
@@ -68,7 +67,6 @@ class ParanoiaTest < Test::Unit::TestCase
68
67
  model.destroy
69
68
 
70
69
  assert_equal false, model.deleted_at.nil?
71
- assert model.frozen?
72
70
 
73
71
  assert_equal 0, model.class.count
74
72
  assert_equal 1, model.class.unscoped.count
@@ -105,7 +103,8 @@ class ParanoiaTest < Test::Unit::TestCase
105
103
  # Regression test for #24
106
104
  def test_chaining_for_paranoid_models
107
105
  scope = FeaturefulModel.where(:name => "foo").only_deleted
108
- assert_equal "foo", scope.where_values_hash[:name]
106
+
107
+ assert_equal "foo", scope.where_values_hash["name"]
109
108
  assert_equal 2, scope.where_values.count
110
109
  end
111
110
 
@@ -185,6 +184,7 @@ class ParanoiaTest < Test::Unit::TestCase
185
184
 
186
185
  model = ParanoidModel.only_deleted.find(id)
187
186
  model.restore!
187
+ model.reload
188
188
 
189
189
  assert_equal false, model.destroyed?
190
190
  end
@@ -194,7 +194,7 @@ class ParanoiaTest < Test::Unit::TestCase
194
194
  model.save
195
195
  model.destroy!
196
196
 
197
- assert_equal false, ParanoidModel.unscoped.exists?(model.id)
197
+ assert_equal false, !!ParanoidModel.unscoped.exists?(model.id)
198
198
  end
199
199
 
200
200
  def test_real_delete
@@ -202,7 +202,7 @@ class ParanoiaTest < Test::Unit::TestCase
202
202
  model.save
203
203
  model.delete!
204
204
 
205
- assert_equal false, ParanoidModel.unscoped.exists?(model.id)
205
+ assert_equal false, !!ParanoidModel.unscoped.exists?(model.id)
206
206
  end
207
207
 
208
208
  private
metadata CHANGED
@@ -1,68 +1,60 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paranoia
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
5
- prerelease:
4
+ version: 1.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - radarlistener@gmail.com
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-11-22 00:00:00.000000000 Z
11
+ date: 2013-07-08 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ~>
20
18
  - !ruby/object:Gem::Version
21
- version: 3.0.0
19
+ version: '3.2'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ~>
28
25
  - !ruby/object:Gem::Version
29
- version: 3.0.0
26
+ version: '3.2'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bundler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: 1.0.0
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: 1.0.0
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: sqlite3
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - '='
68
60
  - !ruby/object:Gem::Version
@@ -70,11 +62,24 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - '='
76
67
  - !ruby/object:Gem::Version
77
68
  version: 0.8.7
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
78
83
  description: Paranoia is a re-implementation of acts_as_paranoid for Rails 3, using
79
84
  much, much, much less code. You would use either plugin / gem if you wished that
80
85
  when you called destroy on an Active Record object that it didn't actually destroy
@@ -88,7 +93,6 @@ extra_rdoc_files: []
88
93
  files:
89
94
  - .gitignore
90
95
  - Gemfile
91
- - Gemfile.lock
92
96
  - LICENSE
93
97
  - README.md
94
98
  - Rakefile
@@ -98,27 +102,26 @@ files:
98
102
  - test/paranoia_test.rb
99
103
  homepage: http://rubygems.org/gems/paranoia
100
104
  licenses: []
105
+ metadata: {}
101
106
  post_install_message:
102
107
  rdoc_options: []
103
108
  require_paths:
104
109
  - lib
105
110
  required_ruby_version: !ruby/object:Gem::Requirement
106
- none: false
107
111
  requirements:
108
- - - ! '>='
112
+ - - '>='
109
113
  - !ruby/object:Gem::Version
110
114
  version: '0'
111
115
  required_rubygems_version: !ruby/object:Gem::Requirement
112
- none: false
113
116
  requirements:
114
- - - ! '>='
117
+ - - '>='
115
118
  - !ruby/object:Gem::Version
116
119
  version: 1.3.6
117
120
  requirements: []
118
121
  rubyforge_project: paranoia
119
- rubygems_version: 1.8.24
122
+ rubygems_version: 2.0.0
120
123
  signing_key:
121
- specification_version: 3
124
+ specification_version: 4
122
125
  summary: Paranoia is a re-implementation of acts_as_paranoid for Rails 3, using much,
123
126
  much, much less code.
124
127
  test_files: []
data/Gemfile.lock DELETED
@@ -1,36 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- paranoia (1.1.0)
5
- activerecord (>= 3.0.0)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activemodel (3.2.0)
11
- activesupport (= 3.2.0)
12
- builder (~> 3.0.0)
13
- activerecord (3.2.0)
14
- activemodel (= 3.2.0)
15
- activesupport (= 3.2.0)
16
- arel (~> 3.0.0)
17
- tzinfo (~> 0.3.29)
18
- activesupport (3.2.0)
19
- i18n (~> 0.6)
20
- multi_json (~> 1.0)
21
- arel (3.0.0)
22
- builder (3.0.0)
23
- i18n (0.6.0)
24
- multi_json (1.0.4)
25
- rake (0.8.7)
26
- sqlite3 (1.3.5)
27
- tzinfo (0.3.31)
28
-
29
- PLATFORMS
30
- ruby
31
-
32
- DEPENDENCIES
33
- bundler (>= 1.0.0)
34
- paranoia!
35
- rake (= 0.8.7)
36
- sqlite3