prevent_destroy 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.bundle/config ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_DISABLE_SHARED_GEMS: "1"
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'activerecord', '>= 3.0.2'
4
+
5
+ group :development do
6
+ gem 'bundler', '~> 1.0.5'
7
+ gem 'jeweler', '~> 1.5.1'
8
+ gem 'rcov', '>= 0.9.9'
9
+ gem 'rspec', '~> 2.1.0'
10
+ gem 'sqlite3', '>= 0.1.1'
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,48 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.0.2)
5
+ activesupport (= 3.0.2)
6
+ builder (~> 2.1.2)
7
+ i18n (~> 0.4.1)
8
+ activerecord (3.0.2)
9
+ activemodel (= 3.0.2)
10
+ activesupport (= 3.0.2)
11
+ arel (~> 2.0.2)
12
+ tzinfo (~> 0.3.23)
13
+ activesupport (3.0.2)
14
+ arel (2.0.2)
15
+ builder (2.1.2)
16
+ diff-lcs (1.1.2)
17
+ ffi (0.6.3)
18
+ rake (>= 0.8.7)
19
+ git (1.2.5)
20
+ i18n (0.4.2)
21
+ jeweler (1.5.1)
22
+ bundler (~> 1.0.0)
23
+ git (>= 1.2.5)
24
+ rake
25
+ rake (0.8.7)
26
+ rcov (0.9.9)
27
+ rspec (2.1.0)
28
+ rspec-core (~> 2.1.0)
29
+ rspec-expectations (~> 2.1.0)
30
+ rspec-mocks (~> 2.1.0)
31
+ rspec-core (2.1.0)
32
+ rspec-expectations (2.1.0)
33
+ diff-lcs (~> 1.1.2)
34
+ rspec-mocks (2.1.0)
35
+ sqlite3 (0.1.1)
36
+ ffi (>= 0.6.3)
37
+ tzinfo (0.3.23)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ activerecord (>= 3.0.2)
44
+ bundler (~> 1.0.5)
45
+ jeweler (~> 1.5.1)
46
+ rcov (>= 0.9.9)
47
+ rspec (~> 2.1.0)
48
+ sqlite3 (>= 0.1.1)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Marc Tauber
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = prevent_destroy
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to prevent_destroy
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Marc Tauber. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "prevent_destroy"
16
+ gem.homepage = "http://github.com/sauberia/prevent_destroy"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Prevents a record being destroyed that has associated records through a has many association}
19
+ gem.description = %Q{Prevents a record being destroyed that has associated records through a has many association}
20
+ gem.email = "marc@marctauber.com"
21
+ gem.authors = ["Marc Tauber"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
+ spec.pattern = 'spec/**/*_spec.rb'
37
+ spec.rcov = true
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "prevent_destroy #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ ActiveRecord::Base.send :include, PreventDestroy
@@ -0,0 +1,25 @@
1
+ module PreventDestroy
2
+
3
+ def self.included(base)
4
+ base.send :extend, ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+
9
+ def prevent_destroy_if_has_children *args
10
+
11
+ define_method(:children_to_check) { args }
12
+
13
+ before_destroy do |record|
14
+ found = []
15
+ if record.children_to_check.any?
16
+ record.children_to_check.each { |search| found << search.to_s.underscore.humanize.downcase if record.send(search).any? }
17
+ end
18
+ if found.any?
19
+ record.errors.add_to_base("The #{self.class.name.underscore.humanize.downcase} cannot be deleted as it contains #{found.to_sentence}")
20
+ false
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{prevent_destroy}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Marc Tauber"]
12
+ s.date = %q{2010-11-16}
13
+ s.description = %q{Prevents a record being destroyed that has associated records through a has many association}
14
+ s.email = %q{marc@marctauber.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".bundle/config",
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "init.rb",
30
+ "lib/prevent_destroy.rb",
31
+ "prevent_destroy.gemspec",
32
+ "spec/prevent_destroy_spec.rb",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/sauberia/prevent_destroy}
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{Prevents a record being destroyed that has associated records through a has many association}
40
+ s.test_files = [
41
+ "spec/prevent_destroy_spec.rb",
42
+ "spec/spec_helper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<activerecord>, [">= 3.0.2"])
51
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.5"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
53
+ s.add_development_dependency(%q<rcov>, [">= 0.9.9"])
54
+ s.add_development_dependency(%q<rspec>, ["~> 2.1.0"])
55
+ s.add_development_dependency(%q<sqlite3>, [">= 0.1.1"])
56
+ else
57
+ s.add_dependency(%q<activerecord>, [">= 3.0.2"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0.5"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
60
+ s.add_dependency(%q<rcov>, [">= 0.9.9"])
61
+ s.add_dependency(%q<rspec>, ["~> 2.1.0"])
62
+ s.add_dependency(%q<sqlite3>, [">= 0.1.1"])
63
+ end
64
+ else
65
+ s.add_dependency(%q<activerecord>, [">= 3.0.2"])
66
+ s.add_dependency(%q<bundler>, ["~> 1.0.5"])
67
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
68
+ s.add_dependency(%q<rcov>, [">= 0.9.9"])
69
+ s.add_dependency(%q<rspec>, ["~> 2.1.0"])
70
+ s.add_dependency(%q<sqlite3>, [">= 0.1.1"])
71
+ end
72
+ end
73
+
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe 'Parent with children' do
4
+
5
+ before(:each) do
6
+ @parent = Parent.create!
7
+ @parent.children << Child.new
8
+ @parent.save!
9
+ end
10
+
11
+ it 'should be prevented from being destroyed' do
12
+ @parent.destroy
13
+ Parent.all.length.should == 1
14
+ end
15
+
16
+ it 'should add appropriate error to base' do
17
+ @parent.destroy
18
+ @parent.errors.full_messages.should include 'The parent cannot be deleted as it contains children'
19
+ end
20
+
21
+ end
@@ -0,0 +1,37 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'active_record'
5
+ require 'active_support/core_ext/logger' rescue nil # rails3
6
+ require 'prevent_destroy'
7
+ require File.join(File.dirname(__FILE__), '../init')
8
+
9
+ # Requires supporting files with custom matchers and macros, etc,
10
+ # in ./support/ and its subdirectories.
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
12
+
13
+ RSpec.configure do |config|
14
+
15
+ end
16
+
17
+
18
+ ActiveRecord::Base.establish_connection({ :adapter => 'sqlite3', :database => ':memory:' })
19
+ ActiveRecord::Base.logger = Logger.new("#{File.dirname(__FILE__)}/active_record.log")
20
+
21
+
22
+ ActiveRecord::Schema.define(:version => 1) do
23
+ create_table :parents do |t|
24
+ end
25
+ create_table :children do |t|
26
+ t.references :parent
27
+ end
28
+ end
29
+
30
+ class Parent < ActiveRecord::Base
31
+ has_many :children, :dependent => :destroy
32
+ prevent_destroy_if_has_children :children
33
+ end
34
+
35
+ class Child < ActiveRecord::Base
36
+ belongs_to :parent
37
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prevent_destroy
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 0
9
+ version: 0.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Marc Tauber
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-16 00:00:00 +00:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activerecord
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 3
29
+ - 0
30
+ - 2
31
+ version: 3.0.2
32
+ type: :runtime
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: bundler
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 0
45
+ - 5
46
+ version: 1.0.5
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: jeweler
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 1
59
+ - 5
60
+ - 1
61
+ version: 1.5.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: rcov
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ - 9
75
+ - 9
76
+ version: 0.9.9
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: rspec
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 2
89
+ - 1
90
+ - 0
91
+ version: 2.1.0
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: sqlite3
97
+ requirement: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ segments:
103
+ - 0
104
+ - 1
105
+ - 1
106
+ version: 0.1.1
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: *id006
110
+ description: Prevents a record being destroyed that has associated records through a has many association
111
+ email: marc@marctauber.com
112
+ executables: []
113
+
114
+ extensions: []
115
+
116
+ extra_rdoc_files:
117
+ - LICENSE.txt
118
+ - README.rdoc
119
+ files:
120
+ - .bundle/config
121
+ - .document
122
+ - .rspec
123
+ - Gemfile
124
+ - Gemfile.lock
125
+ - LICENSE.txt
126
+ - README.rdoc
127
+ - Rakefile
128
+ - VERSION
129
+ - init.rb
130
+ - lib/prevent_destroy.rb
131
+ - prevent_destroy.gemspec
132
+ - spec/prevent_destroy_spec.rb
133
+ - spec/spec_helper.rb
134
+ has_rdoc: true
135
+ homepage: http://github.com/sauberia/prevent_destroy
136
+ licenses:
137
+ - MIT
138
+ post_install_message:
139
+ rdoc_options: []
140
+
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ hash: -1000703533
149
+ segments:
150
+ - 0
151
+ version: "0"
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ segments:
158
+ - 0
159
+ version: "0"
160
+ requirements: []
161
+
162
+ rubyforge_project:
163
+ rubygems_version: 1.3.7
164
+ signing_key:
165
+ specification_version: 3
166
+ summary: Prevents a record being destroyed that has associated records through a has many association
167
+ test_files:
168
+ - spec/prevent_destroy_spec.rb
169
+ - spec/spec_helper.rb