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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 156f34d8f9c1f130ba86b2098d2867fff9d53167
4
- data.tar.gz: abff9315dd010abfcc006b93ec6533964fb4964d
3
+ metadata.gz: ce0dcb3f38b7a78dfabe5d75cf5376385cfaaeac
4
+ data.tar.gz: 78652cb4a461fc982c07e524d06a30571ee7cee7
5
5
  SHA512:
6
- metadata.gz: b35e2189d626e521ac419f03b04dd0aa24d4891b1fd5060d346d83a5c87d97ef727d7fd5fd4a145cd63f0bd6f8671b50b2e089fec2989e05b899e61516cf40e6
7
- data.tar.gz: 3fe88512f796388583c763447a79d6e1a09ab21aa732f7f514c8b2406059bf81df5553aeb10503ffaab8c0cb183c4845676bcf8029f03163ffb2ce2cd43cff62
6
+ metadata.gz: 61e257b23bf0b7309f6cbf88ca2593bdf454f18ba270c27fd6951af2396bb663422006eaebedd78a807250e4bb60ddde072fdf76daa1ae60e9cb63ca5019bce6
7
+ data.tar.gz: 8a47558d1ee198d94d450d237e454014e5bc727f83b8fb8a14eea325e2f2797d877e2f35dc70ffbaaf7fb4498f78ea8a42607f4b7edb40bf16ae22151a829207
data/.travis.yml CHANGED
@@ -2,7 +2,6 @@ language: ruby
2
2
  rvm:
3
3
  - 2.3.1
4
4
  - 2.2.5
5
- - 2.1.9
6
5
  gemfile:
7
6
  - gemfiles/4.1.gemfile
8
7
  - gemfiles/4.2.gemfile
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.5.1 (August 4, 2017)
2
+
3
+ * Allow use of 'optional' option for belongs_to (Yuji Yaginuma)
4
+
1
5
  # 0.5.0 (May 14, 2016)
2
6
 
3
7
  * Add Rails 5.0 support
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.1.0"
23
+ gem.add_development_dependency 'rspec', "~> 3.6.0"
24
24
  end
data/gemfiles/5.0.gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "activerecord", "~> 5.0.0.rc1"
3
+ gem "activerecord", "~> 5.0.0"
4
4
 
5
5
  gemspec :path=>"../"
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
- belongs_to :parent, common_options.merge(inverse_of: :children)
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
@@ -1,3 +1,3 @@
1
1
  module Edge
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
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 include(usa)
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.around :disable_transactions => nil do |example|
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.0
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: 2016-05-14 00:00:00.000000000 Z
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.1.0
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.1.0
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.5.1
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