acts_as_soft_delete_by_field 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -18,6 +18,12 @@ The model object needs to have a datetime field, that on
18
18
  delete will be set to the current time. By default, this field should
19
19
  be :deleted_at, but you can also specify your own field.
20
20
 
21
+ Installation
22
+ ------------
23
+ Add this to your Gemfile:
24
+
25
+ gem "acts_as_soft_delete_by_field"
26
+
21
27
  Usage
22
28
  -----
23
29
 
@@ -105,7 +111,7 @@ it is used.
105
111
  class ThingTest < ActiveSupport::TestCase
106
112
 
107
113
  def test_soft_delete
108
- assert_soft_delete_working_for(Thing.first)
114
+ assert_soft_delete_by_field_working_for(Thing.first)
109
115
  end
110
116
 
111
117
  end
data/Rakefile CHANGED
@@ -21,3 +21,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
21
21
  rdoc.rdoc_files.include('README')
22
22
  rdoc.rdoc_files.include('lib/**/*.rb')
23
23
  end
24
+
25
+ require 'standalone_migrations'
26
+ StandaloneMigrations::Tasks.load_tasks
@@ -13,6 +13,7 @@
13
13
  module ActsAsSoftDeleteByFieldAssertions
14
14
 
15
15
  def assert_soft_delete_by_field_working_for(item)
16
+ assert_soft_delete_enabled_for_class(item)
16
17
  # Using clones, as otherwise other assertions affected
17
18
  @starting_number = item.class.count
18
19
  assert_before_soft_delete_all_correct_for(item)
@@ -28,6 +29,13 @@ module ActsAsSoftDeleteByFieldAssertions
28
29
  assert_before_soft_delete(item.clone)
29
30
  assert_after_soft_delete(item.clone)
30
31
  end
32
+
33
+ def assert_soft_delete_enabled_for_class(item)
34
+ assert(
35
+ item.class.ancestors.include?(ActiveRecord::Acts::SoftDeleteByField::InstanceMethods),
36
+ "#{item.class} should have acts_as_soft_delete_by_field defined"
37
+ )
38
+ end
31
39
 
32
40
  def assert_soft_deleted(item)
33
41
  assert_equal(true, item.reload.is_deleted?, error_messages_for(item, "Not deleted: #{item.inspect}"))
@@ -237,4 +245,5 @@ EOF
237
245
 
238
246
  end
239
247
 
248
+ require 'active_support'
240
249
  ActiveSupport::TestCase.send(:include, ActsAsSoftDeleteByFieldAssertions)
@@ -10,16 +10,27 @@ module ActiveRecord #:nodoc:
10
10
  module ClassMethods
11
11
 
12
12
  def soft_delete_by_field_name
13
- @soft_delete_by_field_name
13
+ @soft_delete_by_field_name || parents_soft_delete_by_field_name || DEFAULT_FIELD_NAME
14
14
  end
15
15
 
16
- def acts_as_soft_delete_by_field(field_name = nil)
17
- attr_accessor :reasons_not_to_delete
18
- field_name ||= DEFAULT_FIELD_NAME
16
+ def soft_delete_by_field_name=(field_name)
19
17
  @soft_delete_by_field_name = field_name.to_sym
18
+ end
19
+
20
+ def acts_as_soft_delete_by_field(field_name = DEFAULT_FIELD_NAME)
21
+ attr_accessor :reasons_not_to_delete
22
+ self.soft_delete_by_field_name = field_name
20
23
  send :include, SoftDeleteByField::InstanceMethods
21
- scope :extant, where(["#{(self.class.name.tableize + ".") if self.class.kind_of?(SoftDeleteByField)}#{field_name} IS NULL"])
22
- scope :deleted, where(["#{(self.class.name.tableize + ".") if self.class.kind_of?(SoftDeleteByField)}#{field_name} IS NOT NULL"])
24
+ scope :extant, where(arel_table[soft_delete_by_field_name].eq(nil))
25
+ scope :deleted, where(arel_table[soft_delete_by_field_name].not_eq(nil))
26
+ end
27
+
28
+ def soft_delete_class_table_name
29
+ (self.class.name.tableize + ".") if self.class.kind_of?(SoftDeleteByField)
30
+ end
31
+
32
+ def parents_soft_delete_by_field_name
33
+ superclass.soft_delete_by_field_name if superclass.respond_to? :soft_delete_by_field_name
23
34
  end
24
35
 
25
36
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_soft_delete_by_field
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
4
+ hash: 17
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 2
10
- version: 1.0.2
9
+ - 3
10
+ version: 1.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rob Nichols
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-05 00:00:00 +01:00
19
- default_executable:
18
+ date: 2013-06-18 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: activerecord
@@ -34,6 +33,36 @@ dependencies:
34
33
  version: 3.0.0
35
34
  type: :runtime
36
35
  version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: sqlite3
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: standalone_migrations
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 9
59
+ segments:
60
+ - 2
61
+ - 1
62
+ - 1
63
+ version: 2.1.1
64
+ type: :development
65
+ version_requirements: *id003
37
66
  description: "Acts as Soft Delete by Field: Provides soft deletion for ActiveRecord models using a field to flag the datetime of deletion"
38
67
  email: rob@nicholshayes.co.uk
39
68
  executables: []
@@ -48,7 +77,6 @@ files:
48
77
  - lib/acts_as_soft_delete_by_field_assertions.rb
49
78
  - lib/acts_as_soft_delete_by_field.rb
50
79
  - lib/soft_delete_by_field.rb
51
- has_rdoc: true
52
80
  homepage: https://github.com/reggieb/acts_as_soft_delete_by_field
53
81
  licenses: []
54
82
 
@@ -78,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
106
  requirements: []
79
107
 
80
108
  rubyforge_project:
81
- rubygems_version: 1.3.7
109
+ rubygems_version: 1.8.15
82
110
  signing_key:
83
111
  specification_version: 3
84
112
  summary: Provides soft deletion for ActiveRecord models