mongoid-suicide 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b6474a3a366a898095e3cad8cb9df45fde308f0c
4
+ data.tar.gz: e7c938d51b77ad34e3e0e5abb061abd868fb508b
5
+ SHA512:
6
+ metadata.gz: 51c67b87aad6fa1f0b4d9a7dc46452d7569ae8aca083470d343f5df58371ebcf4416b06b0ea890a73a87b0278eabf38b9c7e2d7e6564e76f081e1bf845d61a10
7
+ data.tar.gz: 019475f3ebfa270ccebbec2a68296e6529e83c4cfa7543ad73ef2f6976da7e92d5676d2d55ecc5b54035ff58a92a51254a21241b6e634ff8c02fce6baaef0f83
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --tty
2
+ --colour
3
+ --format <%= ENV["CI"] ? 'progress' : 'documentation'%>
@@ -0,0 +1 @@
1
+ mongoid-suicide
@@ -0,0 +1 @@
1
+ ruby-2.2.0
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mongoid-suicide.gemspec
4
+ gemspec
5
+
6
+ gem 'mongoid'
7
+
8
+ group :test do
9
+ gem 'rspec', '~> 3.1.0'
10
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Anton Maminov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # Mongoid::Suicide
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'mongoid-suicide'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install mongoid-suicide
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/mongoid-suicide/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,37 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "bundler"
4
+ Bundler.setup
5
+
6
+ require "rake"
7
+ require "rspec/core/rake_task"
8
+
9
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
10
+ require "mongoid/suicide/version"
11
+
12
+ task :gem => :build
13
+ task :build do
14
+ system "gem build mongoid-suicide.gemspec"
15
+ end
16
+
17
+ task :install => :build do
18
+ system "gem install mongoid-suicide-#{Mongoid::VERSION}.gem"
19
+ end
20
+
21
+ task :release => :build do
22
+ system "git tag -a v#{Mongoid::Suicide::VERSION} -m 'Tagging #{Mongoid::Suicide::VERSION}'"
23
+ system "git push --tags"
24
+ system "gem push mongoid-#{Mongoid::Suicide::VERSION}.gem"
25
+ system "rm mongoid-#{Mongoid::Suicide::VERSION}.gem"
26
+ end
27
+
28
+ RSpec::Core::RakeTask.new("spec") do |spec|
29
+ spec.pattern = "spec/**/*_spec.rb"
30
+ end
31
+
32
+ RSpec::Core::RakeTask.new('spec:progress') do |spec|
33
+ spec.rspec_opts = %w(--format progress)
34
+ spec.pattern = "spec/**/*_spec.rb"
35
+ end
36
+
37
+ task :default => :spec
@@ -0,0 +1 @@
1
+ require "mongoid/suicide"
@@ -0,0 +1,293 @@
1
+ require 'mongoid'
2
+ require "mongoid/suicide/version"
3
+
4
+ module Mongoid
5
+
6
+ # This module allows remove fields.
7
+ module Suicide
8
+ extend ActiveSupport::Concern
9
+
10
+ module ClassMethods
11
+ # Removes the field from the Document.
12
+ # A getter and setter will be removed.
13
+ #
14
+ # @example Remove the field
15
+ # Model.remove_field :score
16
+ #
17
+ # @param [ Symbol ] name The name of the field.
18
+ #
19
+ # @return [ Field ] The removed field
20
+ def remove_field(name)
21
+ name = name.to_s
22
+ if fields[name]
23
+ aliased = fields[name].options[:as]
24
+
25
+ remove_accessors(name, name)
26
+ remove_accessors(name, aliased) if aliased
27
+ remove_dirty_methods(name, name)
28
+ remove_dirty_methods(name, aliased) if aliased
29
+
30
+ remove_defaults(name)
31
+
32
+ remove_field_in_descendants(name)
33
+ remove_validations_for(name)
34
+
35
+ aliased_fields.delete(aliased.to_s) if aliased
36
+ fields.delete(name)
37
+ end
38
+ end
39
+
40
+ # Remove the field accessors.
41
+ #
42
+ # @example Remove the accessors.
43
+ # Person.remove_accessors(:name, "name")
44
+ # person.name #=> undefined
45
+ # person.name = "" #=> undefined
46
+ # person.name? #=> undefined
47
+ # person.name_before_type_cast #=> undefined
48
+ # person.name_translations #=> undefined
49
+ # person.name_translations = "" #=> undefined
50
+ # person.name_t #=> undefined
51
+ # person.name_t = "" #=> undefined
52
+ #
53
+ # @param [ Symbol ] name The name of the field.
54
+ # @param [ Symbol ] meth The name of the accessor.
55
+ def remove_accessors(name, meth)
56
+ field = fields[name]
57
+
58
+ remove_field_getter(meth)
59
+ remove_field_getter_before_typecast(meth)
60
+ remove_field_setter(meth)
61
+ remove_field_check(meth)
62
+
63
+ if field.options[:localize]
64
+ remove_translations_getter(meth)
65
+ remove_translations_setter(meth)
66
+ localized_fields.delete(name)
67
+ end
68
+ end
69
+
70
+ # Removes the dirty change methods.
71
+ #
72
+ # @example Remove the accessors.
73
+ # Person.remove_dirty_change_accessor(:name, "name")
74
+ # person.name_change #=> undefined
75
+ # person.name_changed? #=> undefined
76
+ # person.name_will_change! #=> undefined
77
+ # person.name_changed_from_default? #=> undefined
78
+ # person.name_was #=> undefined
79
+ # person.reset_name! #=> undefined
80
+ # person.reset_name_to_default! #=> undefined
81
+ #
82
+ # @param [ Symbol ] name The attribute name.
83
+ # @param [ String ] meth The name of the accessor.
84
+ def remove_dirty_methods(name, meth)
85
+ remove_dirty_change_accessor(meth)
86
+ remove_dirty_change_check(meth)
87
+ remove_dirty_change_flag(meth)
88
+ remove_dirty_default_change_check(meth)
89
+ remove_dirty_previous_value_accessor(meth)
90
+ remove_dirty_reset(meth)
91
+ remove_dirty_reset_to_default(meth)
92
+ end
93
+
94
+ # Removes the field from descendants.
95
+ #
96
+ # @param [ String ] name The name of the field
97
+ def remove_field_in_descendants(name)
98
+ descendants.each { |descendant| descendant.remove_field(name) }
99
+ end
100
+
101
+ # Removes validations for the field.
102
+ #
103
+ # @example Remove validations.
104
+ # Model.remove_validations_for("name")
105
+ #
106
+ # @param [ String ] name The attribute name.
107
+ def remove_validations_for(name)
108
+ name = name.to_sym
109
+ a_name = [name]
110
+
111
+ _validators.reject!{ |key, _| key == name }
112
+ remove_validate_callbacks a_name
113
+ end
114
+
115
+ # Removes validate callbacks for the field.
116
+ #
117
+ # @example Remove validate callbacks.
118
+ # Model.remove_validate_callbacks([:name])
119
+ #
120
+ # @param [ Array<Symbol> ] a_name The attribute name.
121
+ def remove_validate_callbacks(a_name)
122
+ chain = _validate_callbacks.dup.reject do |callback|
123
+ f = callback.raw_filter
124
+ f.respond_to?(:attributes) && f.attributes == a_name
125
+ end
126
+ reset_callbacks(:validate)
127
+ chain.each do |callback|
128
+ set_callback 'validate', callback.raw_filter
129
+ end
130
+ end
131
+
132
+ # Remove the getter method for the provided field.
133
+ #
134
+ # @example Remove the getter.
135
+ # Model.remove_field_getter("name")
136
+ #
137
+ # @param [ String ] meth The name of the method.
138
+ def remove_field_getter(meth)
139
+ generated_methods.module_eval do
140
+ undef_method(meth) if method_defined?(meth)
141
+ end
142
+ end
143
+
144
+ # Remove the getter_before_type_cast method for the provided field.
145
+ #
146
+ # @example Remove the getter_before_type_cast.
147
+ # Model.remove_field_getter_before_type_cast("name")
148
+ #
149
+ # @param [ String ] meth The name of the method.
150
+ def remove_field_getter_before_typecast(meth)
151
+ generated_methods.module_eval do
152
+ undef_method("#{meth}_before_type_cast") if method_defined?("#{meth}_before_type_cast")
153
+ end
154
+ end
155
+
156
+ # Remove the setter method for the provided field.
157
+ #
158
+ # @example Remove the setter.
159
+ # Model.remove_field_setter("name")
160
+ #
161
+ # @param [ String ] meth The name of the method.
162
+ def remove_field_setter(meth)
163
+ generated_methods.module_eval do
164
+ undef_method("#{meth}=") if method_defined?("#{meth}=")
165
+ end
166
+ end
167
+
168
+ # Remove the check method for the provided field.
169
+ #
170
+ # @example Remove the check.
171
+ # Model.remove_field_check("name")
172
+ #
173
+ # @param [ String ] meth The name of the method.
174
+ def remove_field_check(meth)
175
+ generated_methods.module_eval do
176
+ undef_method("#{meth}?") if method_defined?("#{meth}?")
177
+ end
178
+ end
179
+
180
+ # Remove the translation getter method for the provided field.
181
+ #
182
+ # @example Remove the translation getter.
183
+ # Model.remove_translations_getter("name")
184
+ #
185
+ # @param [ String ] meth The name of the method.
186
+ def remove_translations_getter(meth)
187
+ generated_methods.module_eval do
188
+ undef_method("#{meth}_translations") if method_defined?("#{meth}_translations")
189
+ undef_method("#{meth}_t") if method_defined?("#{meth}_t")
190
+ end
191
+ end
192
+
193
+ # Remove the translation setter method for the provided field.
194
+ #
195
+ # @example Remove the translation setter.
196
+ # Model.remove_translations_setter("name")
197
+ #
198
+ # @param [ String ] meth The name of the method.
199
+ def remove_translations_setter(meth)
200
+ generated_methods.module_eval do
201
+ undef_method("#{meth}_translations=") if method_defined?("#{meth}_translations=")
202
+ undef_method("#{meth}_t=") if method_defined?("#{meth}_t=")
203
+ end
204
+ end
205
+
206
+ # Removes the dirty change accessor.
207
+ #
208
+ # @example Remove the accessor.
209
+ # Model.remove_dirty_change_accessor("name")
210
+ #
211
+ # @param [ String ] meth The name of the accessor.
212
+ def remove_dirty_change_accessor(meth)
213
+ generated_methods.module_eval do
214
+ undef_method("#{meth}_change") if method_defined?("#{meth}_change")
215
+ end
216
+ end
217
+
218
+ # Removes the dirty change check.
219
+ #
220
+ # @example Remove the check.
221
+ # Model.remove_dirty_change_check("name")
222
+ #
223
+ # @param [ String ] meth The name of the accessor.
224
+ def remove_dirty_change_check(meth)
225
+ generated_methods.module_eval do
226
+ undef_method("#{meth}_changed?") if method_defined?("#{meth}_changed?")
227
+ end
228
+ end
229
+
230
+ # Removes the dirty change flag.
231
+ #
232
+ # @example Remove the flag.
233
+ # Model.remove_dirty_change_flag("name")
234
+ #
235
+ # @param [ String ] meth The name of the accessor.
236
+ def remove_dirty_change_flag(meth)
237
+ generated_methods.module_eval do
238
+ undef_method("#{meth}_will_change!") if method_defined?("#{meth}_will_change!")
239
+ end
240
+ end
241
+
242
+ # Removes the dirty default change check.
243
+ #
244
+ # @example Remove the check.
245
+ # Model.remove_dirty_default_change_check("name")
246
+ #
247
+ # @param [ String ] meth The name of the accessor.
248
+ def remove_dirty_default_change_check(meth)
249
+ generated_methods.module_eval do
250
+ undef_method("#{meth}_changed_from_default?") if method_defined?("#{meth}_changed_from_default?")
251
+ end
252
+ end
253
+
254
+ # Removes the dirty change previous value accessor.
255
+ #
256
+ # @example Remove the accessor.
257
+ # Model.remove_dirty_previous_value_accessor("name")
258
+ #
259
+ # @param [ String ] meth The name of the accessor.
260
+ def remove_dirty_previous_value_accessor(meth)
261
+ generated_methods.module_eval do
262
+ undef_method("#{meth}_was") if method_defined?("#{meth}_was")
263
+ end
264
+ end
265
+
266
+ # Removes the dirty change reset.
267
+ #
268
+ # @example Remove the reset.
269
+ # Model.remove_dirty_reset("name")
270
+ #
271
+ # @param [ String ] meth The name of the accessor.
272
+ def remove_dirty_reset(meth)
273
+ generated_methods.module_eval do
274
+ undef_method("reset_#{meth}!") if method_defined?("reset_#{meth}!")
275
+ end
276
+ end
277
+
278
+ # Removes the dirty change reset to default.
279
+ #
280
+ # @example Remove the reset.
281
+ # Model.remove_dirty_reset_to_default("name")
282
+ #
283
+ # @param [ String ] meth The name of the accessor.
284
+ def remove_dirty_reset_to_default(meth)
285
+ generated_methods.module_eval do
286
+ undef_method("reset_#{meth}_to_default!") if method_defined?("reset_#{meth}_to_default!")
287
+ end
288
+ end
289
+ end
290
+ end
291
+ end
292
+
293
+ # Mongoid::Document.send :include, Mongoid::Suicide
@@ -0,0 +1,5 @@
1
+ module Mongoid
2
+ module Suicide
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mongoid/suicide/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mongoid-suicide"
8
+ spec.version = Mongoid::Suicide::VERSION
9
+ spec.authors = ["Anton Maminov"]
10
+ spec.email = ["anton.linux@gmail.com"]
11
+ spec.summary = %q{Hacks to support Mongoid remove field}
12
+ spec.description = %q{Hacks to support Mongoid remove field. Including associations and validations}
13
+ spec.homepage = "https://github.com/mamantoha/mongoid-suicide"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "mongoid", ['> 4.0', '< 5.0']
24
+ end
@@ -0,0 +1,7 @@
1
+ class Person
2
+ include Mongoid::Document
3
+ include Mongoid::Suicide
4
+
5
+ field :username, type: String
6
+ field :age, type: Integer, default: "100"
7
+ end
@@ -0,0 +1,308 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mongoid::Suicide do
4
+ describe "#remove_field" do
5
+ context "remove accessors" do
6
+
7
+ before do
8
+ Person.field(:remove_testing, type: String)
9
+ end
10
+
11
+ let(:person) do
12
+ Person.new
13
+ end
14
+
15
+ before(:each) do
16
+ Person.remove_field(:remove_testing)
17
+ end
18
+
19
+ it "removes field getter" do
20
+ expect {
21
+ person.remove_testing
22
+ }.to raise_error(NoMethodError)
23
+ end
24
+
25
+ it "removes field setter" do
26
+ expect {
27
+ person.remove_testing = 'test'
28
+ }.to raise_error(NoMethodError)
29
+ end
30
+
31
+ it "removes field _before_type_cast getter" do
32
+ expect {
33
+ person.remove_testing_before_type_cast
34
+ }.to raise_error(NoMethodError)
35
+ end
36
+
37
+ it "removes field check method" do
38
+ expect {
39
+ person.remove_testing?
40
+ }.to raise_error(NoMethodError)
41
+ end
42
+
43
+ it "removes field from fields" do
44
+ expect(Person.fields).to_not include("remove_testing")
45
+ end
46
+ end
47
+
48
+ context "remove accessors for aliasing field" do
49
+
50
+ before do
51
+ Person.field(:remove_testing, type: String, as: :rt)
52
+ end
53
+
54
+ let(:person) do
55
+ Person.new
56
+ end
57
+
58
+ before(:each) do
59
+ Person.remove_field(:remove_testing)
60
+ end
61
+
62
+ it "removes field getter" do
63
+ expect {
64
+ person.rt
65
+ }.to raise_error(NoMethodError)
66
+ end
67
+
68
+ it "removes field setter" do
69
+ expect {
70
+ person.rt = 'test'
71
+ }.to raise_error(NoMethodError)
72
+ end
73
+
74
+ it "removes field _before_type_cast getter" do
75
+ expect {
76
+ person.rt_before_type_cast
77
+ }.to raise_error(NoMethodError)
78
+ end
79
+
80
+ it "removes field check method" do
81
+ expect {
82
+ person.rt?
83
+ }.to raise_error(NoMethodError)
84
+ end
85
+
86
+ it "removes field from aliased_fields" do
87
+ expect(Person.aliased_fields).to_not include("rt")
88
+ end
89
+
90
+ end
91
+
92
+ context "remove translations" do
93
+
94
+ before do
95
+ Person.field(:remove_testing, type: String, localize: true)
96
+ end
97
+
98
+ let(:person) do
99
+ Person.new
100
+ end
101
+
102
+ before(:each) do
103
+ Person.remove_field(:remove_testing)
104
+ end
105
+
106
+ it "removes field translation getter" do
107
+ expect {
108
+ person.remove_testing_translations
109
+ }.to raise_error(NoMethodError)
110
+ end
111
+
112
+ it "removes field translation setter" do
113
+ expect {
114
+ person.remove_testing_translations = { de: 'test' }
115
+ }.to raise_error(NoMethodError)
116
+ end
117
+
118
+ it "removes field translation getter alias" do
119
+ expect {
120
+ person.remove_testing_t
121
+ }.to raise_error(NoMethodError)
122
+ end
123
+
124
+ it "removes field translation setter alias" do
125
+ expect {
126
+ person.remove_testing_t = { de: 'test' }
127
+ }.to raise_error(NoMethodError)
128
+ end
129
+
130
+ it "localized_fields should not have removed field" do
131
+ expect(person.localized_fields).to_not include('remove_testing')
132
+ end
133
+
134
+ end
135
+
136
+ context "remove translations for aliasing field" do
137
+
138
+ before do
139
+ Person.field(:remove_testing, type: String, localize: true, as: :rt)
140
+ end
141
+
142
+ let(:person) do
143
+ Person.new
144
+ end
145
+
146
+ before(:each) do
147
+ Person.remove_field(:remove_testing)
148
+ end
149
+
150
+ it "removes field translation getter" do
151
+ expect {
152
+ person.rt_translations
153
+ }.to raise_error(NoMethodError)
154
+ end
155
+
156
+ it "removes field translation setter" do
157
+ expect {
158
+ person.rt_translations = { de: 'test' }
159
+ }.to raise_error(NoMethodError)
160
+ end
161
+
162
+ it "removes field translation getter alias" do
163
+ expect {
164
+ person.rt_t
165
+ }.to raise_error(NoMethodError)
166
+ end
167
+
168
+ it "removes field translation setter alias" do
169
+ expect {
170
+ person.rt_t = { de: 'test' }
171
+ }.to raise_error(NoMethodError)
172
+ end
173
+
174
+ end
175
+
176
+ context "remove dirty change methods" do
177
+
178
+ before do
179
+ Person.field(:remove_testing, type: String)
180
+ end
181
+
182
+ let(:person) do
183
+ Person.new
184
+ end
185
+
186
+ before(:each) do
187
+ Person.remove_field(:remove_testing)
188
+ end
189
+
190
+ it "removes the dirty change accessor" do
191
+ expect {
192
+ person.remove_testing_change
193
+ }.to raise_error(NoMethodError)
194
+ end
195
+
196
+ it "removes the dirty change check" do
197
+ expect {
198
+ person.remove_testing_changed?
199
+ }.to raise_error(NoMethodError)
200
+ end
201
+
202
+ it "removes the dirty change flag" do
203
+ expect {
204
+ person.remove_testing_will_change!
205
+ }.to raise_error(NoMethodError)
206
+ end
207
+
208
+ it "removes the dirty default change check" do
209
+ expect {
210
+ person.remove_testing_changed_from_default?
211
+ }.to raise_error(NoMethodError)
212
+ end
213
+
214
+ it "removes the dirty change previous value accessor" do
215
+ expect {
216
+ person.remove_testing_was
217
+ }.to raise_error(NoMethodError)
218
+ end
219
+
220
+ it "removes the dirty change reset" do
221
+ expect {
222
+ person.reset_remove_testing!
223
+ }.to raise_error(NoMethodError)
224
+ end
225
+
226
+ it "removes the dirty change reset to default" do
227
+ expect {
228
+ person.reset_remove_testing_to_default!
229
+ }.to raise_error(NoMethodError)
230
+ end
231
+
232
+ end
233
+
234
+ context "remove dirty change methods for aliasing field" do
235
+
236
+ before do
237
+ Person.field(:remove_testing, type: String, as: :rt)
238
+ end
239
+
240
+ let(:person) do
241
+ Person.new
242
+ end
243
+
244
+ before(:each) do
245
+ Person.remove_field(:remove_testing)
246
+ end
247
+
248
+ it "removes the dirty change accessor" do
249
+ expect {
250
+ person.rt_change
251
+ }.to raise_error(NoMethodError)
252
+ end
253
+
254
+ it "removes the dirty change check" do
255
+ expect {
256
+ person.rt_changed?
257
+ }.to raise_error(NoMethodError)
258
+ end
259
+
260
+ it "removes the dirty change flag" do
261
+ expect {
262
+ person.rt_will_change!
263
+ }.to raise_error(NoMethodError)
264
+ end
265
+
266
+ it "removes the dirty default change check" do
267
+ expect {
268
+ person.rt_changed_from_default?
269
+ }.to raise_error(NoMethodError)
270
+ end
271
+
272
+ it "removes the dirty change previous value accessor" do
273
+ expect {
274
+ person.rt_was
275
+ }.to raise_error(NoMethodError)
276
+ end
277
+
278
+ it "removes the dirty change reset" do
279
+ expect {
280
+ person.reset_rt!
281
+ }.to raise_error(NoMethodError)
282
+ end
283
+
284
+ it "removes the dirty change reset to default" do
285
+ expect {
286
+ person.reset_rt_to_default!
287
+ }.to raise_error(NoMethodError)
288
+ end
289
+
290
+ end
291
+
292
+ context "remove validators" do
293
+ before do
294
+ Person.field(:remove_testing, type: String)
295
+ Person.validates(:remove_testing, uniqueness: true)
296
+ end
297
+
298
+ before(:each) do
299
+ Person.remove_field(:remove_testing)
300
+ end
301
+
302
+ it "validators should not have removed field" do
303
+ expect(Person._validators).to_not include(:remove_testing)
304
+ end
305
+ end
306
+ end
307
+
308
+ end
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
+
4
+ MODELS = File.join(File.dirname(__FILE__), "app/models")
5
+ $LOAD_PATH.unshift(MODELS)
6
+
7
+ require 'mongoid'
8
+ require 'mongoid-suicide'
9
+ require 'rspec'
10
+
11
+ # Moped.logger.level = Logger::DEBUG
12
+ # Mongoid.logger.level = Logger::DEBUG
13
+
14
+ # Autoload every model for the test suite that sits in spec/app/models.
15
+ Dir[ File.join(MODELS, "*.rb") ].sort.each do |file|
16
+ name = File.basename(file, ".rb")
17
+ autoload name.camelize.to_sym, name
18
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid-suicide
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Anton Maminov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mongoid
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '5.0'
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">"
56
+ - !ruby/object:Gem::Version
57
+ version: '4.0'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '5.0'
61
+ description: Hacks to support Mongoid remove field. Including associations and validations
62
+ email:
63
+ - anton.linux@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - ".rspec"
70
+ - ".ruby-gemset"
71
+ - ".ruby-version"
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - lib/mongoid-suicide.rb
77
+ - lib/mongoid/suicide.rb
78
+ - lib/mongoid/suicide/version.rb
79
+ - mongoid-suicide.gemspec
80
+ - spec/app/models/person.rb
81
+ - spec/mongoid_suicide_spec.rb
82
+ - spec/spec_helper.rb
83
+ homepage: https://github.com/mamantoha/mongoid-suicide
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.4.5
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Hacks to support Mongoid remove field
107
+ test_files:
108
+ - spec/app/models/person.rb
109
+ - spec/mongoid_suicide_spec.rb
110
+ - spec/spec_helper.rb