edge 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/CHANGELOG.md +4 -0
- data/edge.gemspec +1 -1
- data/gemfiles/5.0.gemfile +1 -1
- data/lib/edge/forest.rb +5 -2
- data/lib/edge/version.rb +1 -1
- data/spec/forest_spec.rb +24 -1
- data/spec/spec_helper.rb +8 -26
- metadata +11 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce0dcb3f38b7a78dfabe5d75cf5376385cfaaeac
|
4
|
+
data.tar.gz: 78652cb4a461fc982c07e524d06a30571ee7cee7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61e257b23bf0b7309f6cbf88ca2593bdf454f18ba270c27fd6951af2396bb663422006eaebedd78a807250e4bb60ddde072fdf76daa1ae60e9cb63ca5019bce6
|
7
|
+
data.tar.gz: 8a47558d1ee198d94d450d237e454014e5bc727f83b8fb8a14eea325e2f2797d877e2f35dc70ffbaaf7fb4498f78ea8a42607f4b7edb40bf16ae22151a829207
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/edge.gemspec
CHANGED
@@ -20,5 +20,5 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.add_development_dependency 'pg'
|
21
21
|
gem.add_development_dependency 'pry'
|
22
22
|
gem.add_development_dependency 'rake'
|
23
|
-
gem.add_development_dependency 'rspec', "~> 3.
|
23
|
+
gem.add_development_dependency 'rspec', "~> 3.6.0"
|
24
24
|
end
|
data/gemfiles/5.0.gemfile
CHANGED
data/lib/edge/forest.rb
CHANGED
@@ -7,8 +7,9 @@ module Edge
|
|
7
7
|
# * dependent - passed to children has_many (default: none)
|
8
8
|
# * foreign_key - column name to use for parent foreign_key (default: parent_id)
|
9
9
|
# * order - how to order children (default: none)
|
10
|
+
# * optional - passed to belongs_to (default: none)
|
10
11
|
def acts_as_forest(options={})
|
11
|
-
options.assert_valid_keys :foreign_key, :order, :dependent
|
12
|
+
options.assert_valid_keys :foreign_key, :order, :dependent, :optional
|
12
13
|
|
13
14
|
class_attribute :forest_foreign_key
|
14
15
|
self.forest_foreign_key = options[:foreign_key] || "parent_id"
|
@@ -23,7 +24,9 @@ module Edge
|
|
23
24
|
|
24
25
|
dependent_options = options[:dependent] ? { dependent: options[:dependent] } : {}
|
25
26
|
|
26
|
-
|
27
|
+
optional_options = (ActiveRecord::VERSION::MAJOR >= 5 && options[:optional]) ? { optional: options[:optional] } : {}
|
28
|
+
|
29
|
+
belongs_to :parent, common_options.merge(inverse_of: :children).merge(optional_options)
|
27
30
|
|
28
31
|
if forest_order
|
29
32
|
has_many :children, -> { order(forest_order) }, common_options.merge(inverse_of: :parent).merge(dependent_options)
|
data/lib/edge/version.rb
CHANGED
data/spec/forest_spec.rb
CHANGED
@@ -164,7 +164,8 @@ describe "Edge::Forest" do
|
|
164
164
|
|
165
165
|
it "works when scoped" do
|
166
166
|
forest = Location.where(:name => "USA").find_forest
|
167
|
-
expect(forest).to
|
167
|
+
expect(forest).to match_array([usa])
|
168
|
+
expect(forest.first.children).to match_array([illinois, indiana])
|
168
169
|
end
|
169
170
|
|
170
171
|
it "preloads children in proper order" do
|
@@ -257,4 +258,26 @@ describe "Edge::Forest" do
|
|
257
258
|
end
|
258
259
|
|
259
260
|
end
|
261
|
+
|
262
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
263
|
+
describe "optional option" do
|
264
|
+
before do
|
265
|
+
@original_value = ActiveRecord::Base.belongs_to_required_by_default
|
266
|
+
ActiveRecord::Base.belongs_to_required_by_default = true
|
267
|
+
end
|
268
|
+
|
269
|
+
after do
|
270
|
+
ActiveRecord::Base.belongs_to_required_by_default = @original_value
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'parent can be nil' do
|
274
|
+
class Location4 < ActiveRecord::Base
|
275
|
+
self.table_name = "locations"
|
276
|
+
acts_as_forest optional: true
|
277
|
+
end
|
278
|
+
|
279
|
+
expect(Location4.new(name: "Iceland").valid?).to eq true
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
260
283
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,36 +6,18 @@ require 'rspec'
|
|
6
6
|
database_config = YAML.load_file(File.expand_path("../database.yml", __FILE__))
|
7
7
|
ActiveRecord::Base.establish_connection database_config["test"]
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
# class HstoreRecord < ActiveRecord::Base
|
12
|
-
# serialize :properties, Surus::Hstore::Serializer.new
|
13
|
-
# end
|
14
|
-
|
15
|
-
# class TextArrayRecord < ActiveRecord::Base
|
16
|
-
# serialize :texts, Surus::Array::TextSerializer.new
|
17
|
-
# end
|
18
|
-
|
19
|
-
# class IntegerArrayRecord < ActiveRecord::Base
|
20
|
-
# serialize :integers, Surus::Array::IntegerSerializer.new
|
21
|
-
# end
|
22
|
-
|
23
|
-
# class FloatArrayRecord < ActiveRecord::Base
|
24
|
-
# serialize :floats, Surus::Array::FloatSerializer.new
|
25
|
-
# end
|
26
|
-
|
27
|
-
# class DecimalArrayRecord < ActiveRecord::Base
|
28
|
-
# serialize :decimals, Surus::Array::DecimalSerializer.new
|
29
|
-
# end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
9
|
RSpec.configure do |config|
|
34
|
-
config.
|
10
|
+
config.before(:all) do |example|
|
11
|
+
ActiveRecord::Base.connection.execute <<-SQL
|
12
|
+
truncate body_parts;
|
13
|
+
truncate locations;
|
14
|
+
SQL
|
15
|
+
end
|
16
|
+
|
17
|
+
config.around do |example|
|
35
18
|
ActiveRecord::Base.transaction do
|
36
19
|
example.call
|
37
20
|
raise ActiveRecord::Rollback
|
38
21
|
end
|
39
22
|
end
|
40
23
|
end
|
41
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: edge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jack Christensen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 3.
|
75
|
+
version: 3.6.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 3.
|
82
|
+
version: 3.6.0
|
83
83
|
description: Graph functionality for ActiveRecord
|
84
84
|
email:
|
85
85
|
- jack@jackchristensen.com
|
@@ -131,9 +131,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
133
|
rubyforge_project:
|
134
|
-
rubygems_version: 2.
|
134
|
+
rubygems_version: 2.6.11
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
137
|
summary: Graph functionality for ActiveRecord. Provides tree/forest modeling structure
|
138
138
|
that can load entire trees in a single query.
|
139
|
-
test_files:
|
139
|
+
test_files:
|
140
|
+
- spec/database.yml
|
141
|
+
- spec/database.yml.travis
|
142
|
+
- spec/database_structure.sql
|
143
|
+
- spec/forest_spec.rb
|
144
|
+
- spec/spec_helper.rb
|