mongo_mapper-paranoia 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -cfs
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mongo_mapper-paranoia.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec'
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+
7
+ task :release => :spec
8
+
9
+ desc "Run Specs"
10
+ RSpec::Core::RakeTask.new(:spec) do |spec|
11
+ spec.pattern = "spec/**/*_spec.rb"
12
+ spec.verbose = true
13
+ spec.rspec_opts = ['--color']
14
+ end
@@ -0,0 +1 @@
1
+ require 'mongo_mapper/paranoia'
@@ -0,0 +1,41 @@
1
+ require 'active_support/core_ext/object'
2
+ require 'mongo_mapper'
3
+ require 'mongo_mapper/plugins'
4
+
5
+ require 'mongo_mapper/paranoia/version'
6
+ require 'mongo_mapper/paranoia/acts_as_paranoid'
7
+
8
+ module MongoMapper
9
+ module Plugins
10
+ module Paranoia
11
+ extend ActiveSupport::Concern
12
+
13
+ included do
14
+ key :deleted_at, Time, :index => true
15
+ end
16
+
17
+ module ClassMethods; end
18
+
19
+ module InstanceMethods
20
+ # Destroys the instance
21
+ # @see ActiveModel::Callbacks
22
+ def destroy
23
+ run_callbacks(:destroy) do
24
+ update_attribute(:deleted_at, Time.now)
25
+ end
26
+ end
27
+ alias :delete :destroy
28
+
29
+ # @return [true, false] Whether or not the deleted_at attribute is set
30
+ def destroyed?
31
+ self.deleted_at.present?
32
+ end
33
+ alias :deleted? :destroyed?
34
+ end
35
+
36
+ end
37
+ end
38
+ end
39
+
40
+ MongoMapper::Document.plugin(MongoMapper::Plugins::Paranoia::ActsAsParanoid)
41
+ MongoMapper::EmbeddedDocument.plugin(MongoMapper::Plugins::Paranoia::ActsAsParanoid)
@@ -0,0 +1,22 @@
1
+ require 'mongo_mapper/paranoia'
2
+
3
+ module MongoMapper
4
+ module Plugins
5
+ module Paranoia
6
+ module ActsAsParanoid
7
+ extend ActiveSupport::Concern
8
+
9
+ module ClassMethods
10
+ # Includes the MongoMapper::Plugins::Paranoia MongoMapper Plugin
11
+ # @see MongoMapper::Plugins::Paranoia
12
+ def acts_as_paranoid
13
+ self.send(:include, ::MongoMapper::Plugins::Paranoia)
14
+ end
15
+ end
16
+
17
+ module InstanceMethods; end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ module MongoMapper
2
+ module Paranoia
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "mongo_mapper/paranoia/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mongo_mapper-paranoia"
7
+ s.version = MongoMapper::Paranoia::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Scott Gonyea"]
10
+ s.email = ["me@sgonyea.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Mongo Mapper ActsAsParanoid Plugin}
13
+ s.description = %q{Mongo Mapper ActsAsParanoid Plugin, modeled after Ryan Bigg's plugin}
14
+
15
+ s.add_dependency 'mongo_mapper'
16
+ s.add_dependency 'activesupport'
17
+ s.add_dependency 'i18n'
18
+
19
+ s.add_development_dependency 'rspec', '~>2.6.0'
20
+ s.add_development_dependency 'bson_ext', '~>1.3.1'
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.require_paths = ["lib"]
26
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path("../../spec_helper", File.dirname(__FILE__))
2
+
3
+ describe MongoMapper::Plugins::Paranoia::ActsAsParanoid do
4
+ class ParanoidBySugar
5
+ include MongoMapper::Document
6
+ acts_as_paranoid
7
+ end
8
+
9
+ context 'MongoMapper::Plugins::Paranoia Mixin' do
10
+ it 'should be present in the ancestors' do
11
+ ParanoidBySugar.ancestors.should include(MongoMapper::Plugins::Paranoia::InstanceMethods)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,72 @@
1
+ require File.expand_path("../spec_helper", File.dirname(__FILE__))
2
+
3
+ describe MongoMapper::Plugins::Paranoia do
4
+ class ParanoidByInclude
5
+ include MongoMapper::Document
6
+ include MongoMapper::Plugins::Paranoia
7
+ end
8
+
9
+ context 'The plugin should mix in methods and keys' do
10
+ before(:each) do
11
+ @paranoid = ParanoidByInclude.new
12
+ end
13
+
14
+ describe '#deleted_at' do
15
+ it 'should be included via the plugin interface' do
16
+ @paranoid.should respond_to(:deleted_at)
17
+ end
18
+ end
19
+
20
+ describe '#destroy, #delete' do
21
+ it 'should be included via the plugin interface' do
22
+ @paranoid.should respond_to(:destroy)
23
+ @paranoid.should respond_to(:delete)
24
+ end
25
+ end
26
+
27
+ describe '#destroyed?, #deleted?' do
28
+ it 'should be included via the plugin interface' do
29
+ @paranoid.should respond_to(:destroyed?)
30
+ @paranoid.should respond_to(:deleted?)
31
+ end
32
+ end
33
+ end
34
+
35
+ context 'When destroying instances' do
36
+ before(:each) do
37
+ @paranoid = ParanoidByInclude.create!
38
+ end
39
+
40
+ context 'Instance Methods' do
41
+ describe '#destroy' do
42
+ it 'should set the deleted_at timestamp' do
43
+ @paranoid.deleted_at.should be_nil
44
+ @paranoid.destroy
45
+
46
+ @paranoid.deleted_at.should be_present
47
+ @paranoid.deleted_at.should be_a(Time)
48
+ end
49
+ end
50
+
51
+ describe '#destroyed?' do
52
+ it 'should be true if the object has been destroyed' do
53
+ @paranoid.destroyed?.should be_false
54
+ @paranoid.destroy
55
+
56
+ @paranoid.destroyed?.should be_true
57
+ end
58
+ end
59
+ end
60
+
61
+ context 'Persistence' do
62
+ it 'should still be destroyed, when queried from the server' do
63
+ pid = @paranoid.id
64
+ @paranoid.destroy
65
+
66
+ persistanoid = ParanoidByInclude.find(pid)
67
+ persistanoid.destroyed?.should be_true
68
+ persistanoid.deleted_at.should be_present
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,9 @@
1
+ require 'bundler/setup'
2
+
3
+ Bundler.require :development
4
+ Bundler.require :default
5
+
6
+ MongoMapper.connection = ::Mongo::ReplSetConnection.new(["localhost", 27017])
7
+ MongoMapper.database = 'mongo_mapper-paranoia-test'
8
+
9
+ Dir[ Bundler.root.join("spec/support/**/*.rb") ].each{|f| require f}
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongo_mapper-paranoia
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Scott Gonyea
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-10 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mongo_mapper
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: activesupport
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: i18n
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 2.6.0
57
+ type: :development
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: bson_ext
61
+ prerelease: false
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 1.3.1
68
+ type: :development
69
+ version_requirements: *id005
70
+ description: Mongo Mapper ActsAsParanoid Plugin, modeled after Ryan Bigg's plugin
71
+ email:
72
+ - me@sgonyea.com
73
+ executables: []
74
+
75
+ extensions: []
76
+
77
+ extra_rdoc_files: []
78
+
79
+ files:
80
+ - .gitignore
81
+ - .rspec
82
+ - Gemfile
83
+ - Rakefile
84
+ - lib/mongo_mapper-paranoia.rb
85
+ - lib/mongo_mapper/paranoia.rb
86
+ - lib/mongo_mapper/paranoia/acts_as_paranoid.rb
87
+ - lib/mongo_mapper/paranoia/version.rb
88
+ - mongo_mapper-paranoia.gemspec
89
+ - spec/mongo_mapper/paranoia/acts_as_paranoid_spec.rb
90
+ - spec/mongo_mapper/paranoia_spec.rb
91
+ - spec/spec_helper.rb
92
+ homepage: ""
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options: []
97
+
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: "0"
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: "0"
112
+ requirements: []
113
+
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.5
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: Mongo Mapper ActsAsParanoid Plugin
119
+ test_files:
120
+ - spec/mongo_mapper/paranoia/acts_as_paranoid_spec.rb
121
+ - spec/mongo_mapper/paranoia_spec.rb
122
+ - spec/spec_helper.rb