paranoid_fu 0.4.0 → 0.4.1
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/CHANGELOG +5 -1
- data/lib/paranoid_fu/associations.rb +14 -0
- data/test/app/models/category.rb +13 -0
- data/test/app/models/non_paranoid_android.rb +2 -0
- data/test/app/models/order.rb +4 -0
- data/test/app/models/tag.rb +4 -0
- data/test/app/models/tagging.rb +5 -0
- data/test/app/models/widget.rb +11 -0
- data/test/debug.log +2851 -0
- data/test/paranoid_test.rb +9 -45
- data/test/test_helper.rb +9 -3
- metadata +8 -1
data/test/paranoid_test.rb
CHANGED
@@ -1,51 +1,7 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
|
-
class Tagging < ActiveRecord::Base
|
4
|
-
belongs_to :tag
|
5
|
-
belongs_to :widget
|
6
|
-
paranoid_fu
|
7
|
-
end
|
8
|
-
|
9
|
-
class Widget < ActiveRecord::Base
|
10
|
-
paranoid_fu
|
11
|
-
has_many :categories, :dependent => :destroy
|
12
|
-
has_and_belongs_to_many :habtm_categories, :class_name => 'Category'
|
13
|
-
has_one :category
|
14
|
-
belongs_to :parent_category, :class_name => 'Category'
|
15
|
-
has_many :taggings
|
16
|
-
has_many :tags, :through => :taggings, :without_deleted => true
|
17
|
-
has_many :any_tags, :through => :taggings, :class_name => 'Tag', :source => :tag
|
18
|
-
end
|
19
|
-
|
20
|
-
class Category < ActiveRecord::Base
|
21
|
-
paranoid_fu
|
22
|
-
belongs_to :widget, :without_deleted => true
|
23
|
-
belongs_to :any_widget, :class_name => 'Widget', :foreign_key => 'widget_id'
|
24
|
-
|
25
|
-
def self.search(name, options = {})
|
26
|
-
without_deleted.all options.merge(:conditions => ['LOWER(title) LIKE ?', "%#{name.to_s.downcase}%"])
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.search_with_deleted(name, options = {})
|
30
|
-
all options.merge(:conditions => ['LOWER(title) LIKE ?', "%#{name.to_s.downcase}%"])
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class Tag < ActiveRecord::Base
|
35
|
-
has_many :taggings
|
36
|
-
has_many :widgets, :through => :taggings
|
37
|
-
end
|
38
|
-
|
39
|
-
class Order < ActiveRecord::Base
|
40
|
-
belongs_to :item, :polymorphic => true, :without_deleted => true
|
41
|
-
belongs_to :any_item, :polymorphic => true, :foreign_key => 'item_id', :foreign_type => 'item_type'
|
42
|
-
end
|
43
|
-
|
44
|
-
class NonParanoidAndroid < ActiveRecord::Base
|
45
|
-
end
|
46
|
-
|
47
3
|
class ParanoidTest < ActiveSupport::TestCase
|
48
|
-
fixtures :
|
4
|
+
fixtures :categories, :widgets, :categories_widgets, :tags, :taggings, :orders
|
49
5
|
|
50
6
|
def test_without_deleted_scope
|
51
7
|
assert_equal [1, 2], Widget.all.ids
|
@@ -313,6 +269,14 @@ class ParanoidTest < ActiveSupport::TestCase
|
|
313
269
|
o = Order.find(:first, :include => :any_item)
|
314
270
|
assert_equal orders(:order_1), o
|
315
271
|
assert_equal widgets(:widget_2), o.instance_variable_get(:@any_item)
|
272
|
+
|
273
|
+
assert_equal 1, widgets(:widget_1).non_deleted_habtm_categories.size
|
274
|
+
assert_equal [categories(:category_1)], widgets(:widget_1).non_deleted_habtm_categories
|
275
|
+
w = Widget.find(1, :include => :non_deleted_habtm_categories, :conditions => {'categories.title' => 'category 1'})
|
276
|
+
assert_equal [categories(:category_1)], w.non_deleted_habtm_categories
|
277
|
+
assert_raises(ActiveRecord::RecordNotFound) do
|
278
|
+
Widget.find(1, :include => :non_deleted_habtm_categories, :conditions => {'categories.title' => 'category 2'})
|
279
|
+
end
|
316
280
|
end
|
317
281
|
end
|
318
282
|
|
data/test/test_helper.rb
CHANGED
@@ -9,9 +9,10 @@ else
|
|
9
9
|
# load activerecord and plugin manually
|
10
10
|
gem 'activerecord', "=#{ENV['RAILS']}"
|
11
11
|
require 'active_record'
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
ActiveRecord.load_all!
|
13
|
+
require 'active_record/associations'
|
14
|
+
Dir["#{File.join(File.dirname(__FILE__), '..', 'lib')}/**/*.rb"].each do |path|
|
15
|
+
require path
|
15
16
|
end
|
16
17
|
require File.join(File.dirname(__FILE__), '..', 'init.rb')
|
17
18
|
end
|
@@ -23,6 +24,11 @@ ActiveRecord::Base.configurations.update config
|
|
23
24
|
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
24
25
|
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite3'])
|
25
26
|
|
27
|
+
models_dir = File.join(File.dirname(__FILE__), 'app/models')
|
28
|
+
Dir["#{models_dir}/**/*.rb"].each do |path|
|
29
|
+
model = path[models_dir.size+1..-4]
|
30
|
+
autoload model.classify.to_sym, "#{models_dir}/#{model}"
|
31
|
+
end
|
26
32
|
load(File.dirname(__FILE__) + "/schema.rb")
|
27
33
|
|
28
34
|
class ActiveSupport::TestCase #:nodoc:
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paranoid_fu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergio Cambra
|
@@ -38,6 +38,13 @@ files:
|
|
38
38
|
- test/paranoid_test.rb
|
39
39
|
- test/schema.rb
|
40
40
|
- test/test_helper.rb
|
41
|
+
- test/debug.log
|
42
|
+
- test/app/models/category.rb
|
43
|
+
- test/app/models/non_paranoid_android.rb
|
44
|
+
- test/app/models/order.rb
|
45
|
+
- test/app/models/tagging.rb
|
46
|
+
- test/app/models/tag.rb
|
47
|
+
- test/app/models/widget.rb
|
41
48
|
- README
|
42
49
|
- MIT-LICENSE
|
43
50
|
- CHANGELOG
|