paranoia 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,8 +9,7 @@ module Paranoia
9
9
 
10
10
  def destroy
11
11
  _run_destroy_callbacks
12
- self[:deleted_at] ||= Time.now
13
- self.save
12
+ self.update_attribute(:deleted_at, Time.now) if !deleted? && persisted?
14
13
  end
15
14
  alias :delete :destroy
16
15
 
@@ -1,3 +1,3 @@
1
1
  module Paranoia
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -17,6 +17,8 @@ Gem::Specification.new do |s|
17
17
  s.add_dependency "activerecord", ">= 3.0.0"
18
18
 
19
19
  s.add_development_dependency "bundler", ">= 1.0.0"
20
+ s.add_development_dependency "sqlite3"
21
+ s.add_development_dependency "rake", "0.8.7"
20
22
 
21
23
  s.files = `git ls-files`.split("\n")
22
24
  s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
@@ -1,6 +1,6 @@
1
1
  require 'test/unit'
2
2
  require 'active_record'
3
- require 'lib/paranoia'
3
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/paranoia")
4
4
 
5
5
  DB_FILE = 'tmp/test_db'
6
6
 
@@ -8,8 +8,9 @@ FileUtils.mkdir_p File.dirname(DB_FILE)
8
8
  FileUtils.rm_f DB_FILE
9
9
 
10
10
  ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => DB_FILE
11
- ActiveRecord::Base.connection.execute 'CREATE TABLE paranoid_models (id INTEGER NOT NULL PRIMARY KEY)'
12
- ActiveRecord::Base.connection.execute 'CREATE TABLE plain_models (id INTEGER NOT NULL PRIMARY KEY)'
11
+ ActiveRecord::Base.connection.execute 'CREATE TABLE paranoid_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME)'
12
+ ActiveRecord::Base.connection.execute 'CREATE TABLE featureful_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME, name VARCHAR(32))'
13
+ ActiveRecord::Base.connection.execute 'CREATE TABLE plain_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME)'
13
14
 
14
15
  class ParanoiaTest < Test::Unit::TestCase
15
16
  def test_plain_model_class_is_not_paranoid
@@ -28,6 +29,50 @@ class ParanoiaTest < Test::Unit::TestCase
28
29
  assert_equal true, ParanoidModel.new.paranoid?
29
30
  end
30
31
 
32
+ def test_delete_behavior_for_plain_models
33
+ model = PlainModel.new
34
+ assert_equal 0, model.class.count
35
+ model.save!
36
+ assert_equal 1, model.class.count
37
+ model.delete
38
+
39
+ assert_equal true, model.deleted_at.nil?
40
+
41
+ assert_equal 0, model.class.count
42
+ assert_equal 0, model.class.unscoped.count
43
+ end
44
+
45
+ def test_delete_behavior_for_paranoid_models
46
+ model = ParanoidModel.new
47
+ assert_equal 0, model.class.count
48
+ model.save!
49
+ assert_equal 1, model.class.count
50
+ model.delete
51
+
52
+ assert_equal false, model.deleted_at.nil?
53
+
54
+ assert_equal 0, model.class.count
55
+ assert_equal 1, model.class.unscoped.count
56
+
57
+ end
58
+
59
+ def test_delete_behavior_for_featureful_paranoid_models
60
+ model = get_featureful_model
61
+ assert_equal 0, model.class.count
62
+ model.save!
63
+ assert_equal 1, model.class.count
64
+ model.delete
65
+
66
+ assert_equal false, model.deleted_at.nil?
67
+
68
+ assert_equal 0, model.class.count
69
+ assert_equal 1, model.class.unscoped.count
70
+ end
71
+
72
+ private
73
+ def get_featureful_model
74
+ FeaturefulModel.new(:name => "not empty")
75
+ end
31
76
  end
32
77
 
33
78
  # Helper classes
@@ -36,5 +81,10 @@ class ParanoidModel < ActiveRecord::Base
36
81
  acts_as_paranoid
37
82
  end
38
83
 
84
+ class FeaturefulModel < ActiveRecord::Base
85
+ acts_as_paranoid
86
+ validates :name, :presence => true, :uniqueness => true
87
+ end
88
+
39
89
  class PlainModel < ActiveRecord::Base
40
90
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: paranoia
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.1
5
+ version: 1.0.2
6
6
  platform: ruby
7
7
  authors: []
8
8
 
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-12 00:00:00 +10:00
13
+ date: 2011-05-25 00:00:00 +10:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -35,6 +35,28 @@ dependencies:
35
35
  version: 1.0.0
36
36
  type: :development
37
37
  version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: sqlite3
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: rake
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - "="
56
+ - !ruby/object:Gem::Version
57
+ version: 0.8.7
58
+ type: :development
59
+ version_requirements: *id004
38
60
  description: acts_as_paranoid, without the clusterfuck
39
61
  email: []
40
62