acts_as_sweepable 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,5 @@
1
+ = Version 0.1.4
2
+ * use_delete - use delete_all instead of destroy_all
1
3
  = Version 0.1.3
2
4
  * Spec fix, changing hash keys to symbols
3
5
  = Version 0.1.2
data/Rakefile CHANGED
@@ -2,12 +2,12 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('acts_as_sweepable', '0.1.3') do |p|
5
+ Echoe.new('acts_as_sweepable', '0.1.4') do |p|
6
6
  p.description = "Adds a class method called sweep to ActiveRecord - used to remove old elements"
7
7
  p.url = "https://github.com/mensfeld/Acts-as-Sweepable"
8
8
  p.author = "Maciej Mensfeld"
9
9
  p.email = "maciej@mensfeld.pl"
10
10
  p.ignore_pattern = ["tmp/*", "script/*"]
11
- p.development_dependencies = ["rspec >=2.0.0", "active_record"]
11
+ p.development_dependencies = ["rspec >=2.0.0", 'mocha', "active_record"]
12
12
  end
13
13
 
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "acts_as_sweepable"
5
- s.version = "0.1.3"
5
+ s.version = "0.1.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Maciej Mensfeld"]
9
- s.date = "2012-01-28"
9
+ s.date = "2012-06-16"
10
10
  s.description = "Adds a class method called sweep to ActiveRecord - used to remove old elements"
11
11
  s.email = "maciej@mensfeld.pl"
12
12
  s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.md", "lib/acts_as_sweepable.rb"]
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Acts_as_sweepable", "--main", "README.md"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = "acts_as_sweepable"
18
- s.rubygems_version = "1.8.15"
18
+ s.rubygems_version = "1.8.10"
19
19
  s.summary = "Adds a class method called sweep to ActiveRecord - used to remove old elements"
20
20
 
21
21
  if s.respond_to? :specification_version then
@@ -23,13 +23,16 @@ Gem::Specification.new do |s|
23
23
 
24
24
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
25
  s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
26
+ s.add_development_dependency(%q<mocha>, [">= 0"])
26
27
  s.add_development_dependency(%q<active_record>, [">= 0"])
27
28
  else
28
29
  s.add_dependency(%q<rspec>, [">= 2.0.0"])
30
+ s.add_dependency(%q<mocha>, [">= 0"])
29
31
  s.add_dependency(%q<active_record>, [">= 0"])
30
32
  end
31
33
  else
32
34
  s.add_dependency(%q<rspec>, [">= 2.0.0"])
35
+ s.add_dependency(%q<mocha>, [">= 0"])
33
36
  s.add_dependency(%q<active_record>, [">= 0"])
34
37
  end
35
38
  end
@@ -17,6 +17,7 @@ module Acts
17
17
  time_ago = options.delete(:time)
18
18
  conditions = options.delete(:conditions)
19
19
  created_or_updated = options.delete(:created_or_updated)
20
+ delete = options.delete(:use_delete) || false
20
21
  created_or_updated = true if created_or_updated.nil?
21
22
 
22
23
  time = case time_ago
@@ -40,7 +41,12 @@ module Acts
40
41
  # Run on each block of code
41
42
  els.each {|el| yield el } if block_given?
42
43
 
43
- self.destroy_all "#{statement} #{conditions}"
44
+ if delete
45
+ self.delete_all "#{statement} #{conditions}"
46
+ else
47
+ self.destroy_all "#{statement} #{conditions}"
48
+ end
49
+
44
50
  end
45
51
  end
46
52
 
@@ -71,6 +71,7 @@ describe CoolElement do
71
71
 
72
72
  context "When we sweep smthg" do
73
73
  it "should be able to perform on each" do
74
+ subject.expects(:destroy_all)
74
75
  2.times { |i| subject.create(:created_at => 10.days.ago, :name => i.to_s) }
75
76
  saved = []
76
77
  subject.sweep(:time => '1d') do |el|
@@ -81,4 +82,12 @@ describe CoolElement do
81
82
  end
82
83
  end
83
84
 
85
+ context 'when we want to delete instead of destroying' do
86
+ it 'should use it instead of destroy' do
87
+ 2.times { |i| subject.create(:created_at => 10.days.ago, :name => i.to_s) }
88
+ subject.expects(:delete_all)
89
+ subject.sweep(:time => '1d', :use_delete => true)
90
+ end
91
+ end
92
+
84
93
  end
data/spec/spec_helper.rb CHANGED
@@ -5,6 +5,11 @@ require 'rubygems'
5
5
  require 'sqlite3'
6
6
  require 'active_record'
7
7
  require 'acts_as_sweepable'
8
+ require 'mocha'
9
+
10
+ RSpec.configure do |config|
11
+ config.mock_with :mocha
12
+ end
8
13
 
9
14
  ActiveRecord::Base.establish_connection(
10
15
  :adapter => "sqlite3",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_sweepable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-28 00:00:00.000000000Z
12
+ date: 2012-06-16 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &23459120 !ruby/object:Gem::Requirement
16
+ requirement: &16911420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,21 @@ dependencies:
21
21
  version: 2.0.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *23459120
24
+ version_requirements: *16911420
25
+ - !ruby/object:Gem::Dependency
26
+ name: mocha
27
+ requirement: &16910580 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *16910580
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: active_record
27
- requirement: &23458460 !ruby/object:Gem::Requirement
38
+ requirement: &16906940 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,7 +43,7 @@ dependencies:
32
43
  version: '0'
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *23458460
46
+ version_requirements: *16906940
36
47
  description: Adds a class method called sweep to ActiveRecord - used to remove old
37
48
  elements
38
49
  email: maciej@mensfeld.pl
@@ -80,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
91
  version: '1.2'
81
92
  requirements: []
82
93
  rubyforge_project: acts_as_sweepable
83
- rubygems_version: 1.8.15
94
+ rubygems_version: 1.8.10
84
95
  signing_key:
85
96
  specification_version: 3
86
97
  summary: Adds a class method called sweep to ActiveRecord - used to remove old elements