dependent_restrict 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/dependent_restrict.gemspec +1 -1
- data/lib/dependent_restrict.rb +4 -1
- data/lib/dependent_restrict/version.rb +1 -1
- data/spec/dependent_restrict_spec.rb +35 -8
- data/spec/schema.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/support/coverage_loader.rb +5 -26
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 419625dae9ead42079c955404a75b04bdff01f69
|
4
|
+
data.tar.gz: eee3360dd08cd3d2ed0d6723ceb9618e9b36b15f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db2746a76da5913fa2c93c0efa8c9f99c9cd5318a4e991dcb2d1be3f8246723389fbe7f231cc0a06eabe1b85626cc47682799b81e63d10ac8f6ab4548b374276
|
7
|
+
data.tar.gz: 7c82199bafdae295cc3015ce60bc437694b1617dc1332149719411664d484ca42b364a54ccf3da28f192611d2bbcfed36278ca2a06071182e1868a92b8a2fac5
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Change Log
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
|
+
This changelog adheres to [Keep a CHANGELOG](http://keepachangelog.com/).
|
5
|
+
|
6
|
+
## Unreleased
|
7
|
+
|
8
|
+
## 0.2.4
|
9
|
+
### Added
|
10
|
+
- Support has and belongs to many in rails 4+
|
11
|
+
- Enforce minimum coverage in tests
|
12
|
+
- [TT-1392] Changelog file
|
13
|
+
|
14
|
+
## 0.2.3
|
15
|
+
### Added
|
16
|
+
- Support rails 5
|
17
|
+
- Improve testing of ruby/rails versions
|
data/dependent_restrict.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency 'bundler'
|
25
25
|
spec.add_development_dependency 'rake'
|
26
26
|
spec.add_development_dependency 'rspec'
|
27
|
-
spec.add_development_dependency '
|
27
|
+
spec.add_development_dependency 'coverage-kit'
|
28
28
|
spec.add_development_dependency 'simplecov-rcov'
|
29
29
|
spec.add_development_dependency 'coveralls'
|
30
30
|
spec.add_development_dependency 'sqlite3'
|
data/lib/dependent_restrict.rb
CHANGED
@@ -52,7 +52,6 @@ module DependentRestrict
|
|
52
52
|
options = args.extract_options! || {}
|
53
53
|
if VALID_DEPENDENTS.include?(options[:dependent].try(:to_sym))
|
54
54
|
reflection = if active_record_4?
|
55
|
-
raise ArgumentError, "dependent_restrict doesn't work with has_and_belongs_to_many. Use equivalent rails 4.1 has_many :through" if ActiveRecord::Reflection.respond_to? :create
|
56
55
|
association_id, scope = *args
|
57
56
|
restrict_create_reflection(:has_and_belongs_to_many, association_id, scope || {}, options, self)
|
58
57
|
else
|
@@ -101,6 +100,10 @@ module DependentRestrict
|
|
101
100
|
|
102
101
|
def restrict_create_reflection(*args)
|
103
102
|
if ActiveRecord::Reflection.respond_to? :create
|
103
|
+
if args[0] == :has_and_belongs_to_many
|
104
|
+
args[0] = :has_many
|
105
|
+
args[3][:through] = [self.table_name, args[1].to_s].sort.join('_')
|
106
|
+
end
|
104
107
|
ActiveRecord::Reflection.create *args
|
105
108
|
else
|
106
109
|
create_reflection(*args)
|
@@ -18,33 +18,35 @@ describe DependentRestrict do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
class Category < ActiveRecord::Base
|
21
|
+
has_and_belongs_to_many :products
|
22
|
+
|
21
23
|
def to_s
|
22
24
|
"Category #{id}"
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
|
-
class
|
28
|
+
class CategoriesProduct < ActiveRecord::Base
|
27
29
|
belongs_to :product
|
28
30
|
belongs_to :category
|
29
31
|
end
|
30
32
|
|
31
33
|
class Product < ActiveRecord::Base
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
has_and_belongs_to_many :categories
|
35
|
+
|
36
|
+
def to_s
|
37
|
+
"Product #{id}"
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
41
|
end
|
40
42
|
|
41
43
|
after do
|
42
|
-
[OrderInvoice, Order, Category,
|
44
|
+
[OrderInvoice, Order, Category, CategoriesProduct, Product].each(&:delete_all)
|
43
45
|
classes_to_remove = %w(
|
44
46
|
OrderInvoice
|
45
47
|
Order
|
46
48
|
Category
|
47
|
-
|
49
|
+
CategoriesProduct
|
48
50
|
Product
|
49
51
|
CategoryOrdersAssociationExtension
|
50
52
|
)
|
@@ -87,6 +89,12 @@ describe DependentRestrict do
|
|
87
89
|
end
|
88
90
|
|
89
91
|
has_many :order_invoices, :through => :orders, :dependent => :restrict_with_exception
|
92
|
+
|
93
|
+
has_and_belongs_to_many :products, dependent: :restrict_with_exception
|
94
|
+
end
|
95
|
+
|
96
|
+
class Product < ActiveRecord::Base
|
97
|
+
has_and_belongs_to_many :categories
|
90
98
|
end
|
91
99
|
end
|
92
100
|
|
@@ -95,7 +103,26 @@ describe DependentRestrict do
|
|
95
103
|
end
|
96
104
|
|
97
105
|
it 'should create the reflections on Category' do
|
98
|
-
expect(Category.reflect_on_all_associations.map(&:name)).to eq [:orders, :order_invoices]
|
106
|
+
expect(Category.reflect_on_all_associations.map(&:name)).to eq [:products, :orders, :order_invoices]
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should restrict has_and_belongs_to_many relationships' do
|
110
|
+
product = Product.create!
|
111
|
+
category = Category.create!
|
112
|
+
category.products = [product]
|
113
|
+
|
114
|
+
expect { category.reload.destroy }.to raise_error(
|
115
|
+
ActiveRecord::DetailedDeleteRestrictionError,
|
116
|
+
'Cannot delete record because dependent products exists'
|
117
|
+
)
|
118
|
+
begin
|
119
|
+
category.destroy
|
120
|
+
rescue ActiveRecord::DetailedDeleteRestrictionError => e
|
121
|
+
expect(e.detailed_message).to eq "Cannot delete record because dependent products exists\n\n\nThese include:\n1: Product 1"
|
122
|
+
end
|
123
|
+
|
124
|
+
Product.destroy_all
|
125
|
+
expect { category.reload.destroy }.to_not raise_error
|
99
126
|
end
|
100
127
|
|
101
128
|
it 'should restrict has_many relationships' do
|
data/spec/schema.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,26 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
require 'coveralls'
|
7
|
-
Coveralls.wear!
|
8
|
-
|
9
|
-
SimpleCov.formatters = [
|
10
|
-
SimpleCov::Formatter::RcovFormatter,
|
11
|
-
Coveralls::SimpleCov::Formatter
|
12
|
-
]
|
13
|
-
SimpleCov.start do
|
14
|
-
add_filter '/vendor/'
|
15
|
-
add_filter '/spec/'
|
16
|
-
add_group 'lib', 'lib'
|
17
|
-
end
|
18
|
-
SimpleCov.at_exit do
|
19
|
-
SimpleCov.result.format!
|
20
|
-
percent = SimpleCov.result.covered_percent
|
21
|
-
unless percent >= MINIMUM_COVERAGE
|
22
|
-
puts "Coverage must be above #{MINIMUM_COVERAGE}%. It is #{"%.2f" % percent}%"
|
23
|
-
Kernel.exit(1)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
1
|
+
require 'simplecov-rcov'
|
2
|
+
require 'coveralls'
|
3
|
+
require 'coverage/kit'
|
4
|
+
minimum_coverage = ActiveRecord::VERSION::MAJOR >= 4 ? 92.2 : 86.6
|
5
|
+
Coverage::Kit.setup(minimum_coverage: minimum_coverage)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dependent_restrict
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Noack
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -73,7 +73,7 @@ dependencies:
|
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
76
|
+
name: coverage-kit
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - ">="
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- ".gitignore"
|
154
154
|
- ".rspec"
|
155
155
|
- ".travis.yml"
|
156
|
+
- CHANGELOG.md
|
156
157
|
- Gemfile
|
157
158
|
- LICENSE
|
158
159
|
- README.md
|
@@ -188,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
189
|
version: '0'
|
189
190
|
requirements: []
|
190
191
|
rubyforge_project:
|
191
|
-
rubygems_version: 2.
|
192
|
+
rubygems_version: 2.5.2
|
192
193
|
signing_key:
|
193
194
|
specification_version: 4
|
194
195
|
summary: Add dependent restrict and improves functionality to ActiveRecord 2/3/4.x.
|