acts_as_better_tree 1.1.2 → 1.1.3
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.
- checksums.yaml +4 -4
- data/Gemfile +6 -3
- data/Gemfile.lock +23 -13
- data/lib/acts_as_better_tree/version.rb +1 -1
- data/lib/acts_as_better_tree.rb +2 -2
- data/spec/acts_as_better_tree_spec.rb +43 -1
- data/spec/factories/categories.rb +3 -3
- data/spec/spec_helper.rb +6 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b7f71a6d2b5c286601e25437f287c4e1103d10255303100863d11d12f0d227e
|
4
|
+
data.tar.gz: c2d906d6f8e20c09a3d53d226d04b831bfd60cadd0427fdaacff42c0abd40ad4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3eada0c8397efc08bacc7be7c41f03c7e321f6cea8594571110c9d781216bbcf13cc1a33606ce1f17c1059b53d1eb55119ae69566dad2a304fe1a319e7d9364
|
7
|
+
data.tar.gz: 2eeadc73f674efcd38b88c7ee942b81a795811b98377da5a2f1327dec33280f573ea38f196586957430a7081ea47bc3750194241714fd7ed6d5d24dd5390e882
|
data/Gemfile
CHANGED
@@ -2,7 +2,10 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in acts_as_better_tree.gemspec
|
4
4
|
gemspec
|
5
|
-
|
5
|
+
|
6
|
+
gem 'rspec', '~> 3.12'
|
6
7
|
gem 'rails', ">= 3.2.5"
|
7
|
-
gem
|
8
|
-
gem
|
8
|
+
gem 'factory_bot', '~> 6.4'
|
9
|
+
gem 'csv'
|
10
|
+
gem 'observer'
|
11
|
+
gem 'sqlite3', '~> 2.1'
|
data/Gemfile.lock
CHANGED
@@ -86,11 +86,11 @@ GEM
|
|
86
86
|
crass (1.0.6)
|
87
87
|
csv (3.3.3)
|
88
88
|
date (3.4.1)
|
89
|
-
diff-lcs (1.1
|
89
|
+
diff-lcs (1.6.1)
|
90
90
|
drb (2.2.1)
|
91
91
|
erubi (1.13.1)
|
92
|
-
|
93
|
-
activesupport (>=
|
92
|
+
factory_bot (6.5.1)
|
93
|
+
activesupport (>= 6.1.0)
|
94
94
|
globalid (1.2.1)
|
95
95
|
activesupport (>= 6.1)
|
96
96
|
i18n (1.14.7)
|
@@ -126,6 +126,7 @@ GEM
|
|
126
126
|
nokogiri (1.18.7)
|
127
127
|
mini_portile2 (~> 2.8.2)
|
128
128
|
racc (~> 1.4)
|
129
|
+
observer (0.1.2)
|
129
130
|
pp (0.6.2)
|
130
131
|
prettyprint
|
131
132
|
prettyprint (0.2.0)
|
@@ -175,15 +176,22 @@ GEM
|
|
175
176
|
psych (>= 4.0.0)
|
176
177
|
reline (0.6.1)
|
177
178
|
io-console (~> 0.5)
|
178
|
-
rspec (
|
179
|
-
rspec-core (~>
|
180
|
-
rspec-expectations (~>
|
181
|
-
rspec-mocks (~>
|
182
|
-
rspec-core (
|
183
|
-
|
184
|
-
|
185
|
-
|
179
|
+
rspec (3.13.0)
|
180
|
+
rspec-core (~> 3.13.0)
|
181
|
+
rspec-expectations (~> 3.13.0)
|
182
|
+
rspec-mocks (~> 3.13.0)
|
183
|
+
rspec-core (3.13.3)
|
184
|
+
rspec-support (~> 3.13.0)
|
185
|
+
rspec-expectations (3.13.3)
|
186
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
187
|
+
rspec-support (~> 3.13.0)
|
188
|
+
rspec-mocks (3.13.2)
|
189
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
190
|
+
rspec-support (~> 3.13.0)
|
191
|
+
rspec-support (3.13.2)
|
186
192
|
securerandom (0.4.1)
|
193
|
+
sqlite3 (2.6.0)
|
194
|
+
mini_portile2 (~> 2.8.0)
|
187
195
|
stringio (3.1.6)
|
188
196
|
thor (1.3.2)
|
189
197
|
timeout (0.4.3)
|
@@ -203,9 +211,11 @@ PLATFORMS
|
|
203
211
|
DEPENDENCIES
|
204
212
|
acts_as_better_tree!
|
205
213
|
csv
|
206
|
-
|
214
|
+
factory_bot (~> 6.4)
|
215
|
+
observer
|
207
216
|
rails (>= 3.2.5)
|
208
|
-
rspec
|
217
|
+
rspec (~> 3.12)
|
218
|
+
sqlite3 (~> 2.1)
|
209
219
|
|
210
220
|
BUNDLED WITH
|
211
221
|
2.6.5
|
data/lib/acts_as_better_tree.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "acts_as_better_tree/version"
|
2
|
+
require "csv"
|
2
3
|
module ActiveRecord
|
3
4
|
module Acts
|
4
5
|
module BetterTree
|
@@ -28,8 +29,7 @@ module ActiveRecord
|
|
28
29
|
belongs_to :root,
|
29
30
|
class_name: name,
|
30
31
|
foreign_key: :root_id,
|
31
|
-
optional: true
|
32
|
-
dependent: :destroy
|
32
|
+
optional: true
|
33
33
|
scope :roots, -> {order(configuration[:order]).where(:parent_id => nil)}
|
34
34
|
after_create :assign_csv_ids
|
35
35
|
after_validation :update_csv_ids, :on => :update
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
ActiveRecord::Base
|
3
|
+
ActiveRecord::Base.establish_connection(
|
4
|
+
adapter: 'sqlite3',
|
5
|
+
database: ':memory:'
|
6
|
+
)
|
4
7
|
$stdout = StringIO.new
|
5
8
|
|
6
9
|
def setup_db
|
@@ -72,4 +75,43 @@ describe "ActsAsBetterTree" do
|
|
72
75
|
it "should return a csv string of all nodes" do
|
73
76
|
Category.to_csv.should eql "Animals,Cats,Lions\nAnimals,Cats,Tiger\nAnimals,Cats,House Cat\nAnimals,Cats,Panther\nAnimals,Cats,Bobcats\n"
|
74
77
|
end
|
78
|
+
|
79
|
+
context "when there are multiple category roots" do
|
80
|
+
before do
|
81
|
+
baseball = Category.create(name: "baseball")
|
82
|
+
basketball = Category.create(name: "basketball")
|
83
|
+
football = Category.create(name: "football")
|
84
|
+
Category.create(name: "minor", :parent => baseball)
|
85
|
+
Category.create(name: "major", :parent => baseball)
|
86
|
+
Category.create(name: "minor", :parent => basketball)
|
87
|
+
Category.create(name: "major", :parent => basketball)
|
88
|
+
Category.create(name: "minor", :parent => football)
|
89
|
+
Category.create(name: "major", :parent => football)
|
90
|
+
|
91
|
+
end
|
92
|
+
context "and the category root is deleted" do
|
93
|
+
it "should also remove its children" do
|
94
|
+
category = Category.find_by_name("football")
|
95
|
+
category.children.count.should eql 2
|
96
|
+
category.destroy
|
97
|
+
|
98
|
+
Category.find_by_name("football").should eql nil
|
99
|
+
Category.find_by_name("basketball").children.should_not eql nil
|
100
|
+
Category.find_by_name("baseball").children.should_not eql nil
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "and a non category root is deleted" do
|
105
|
+
it "should remove only its children" do
|
106
|
+
category = Category.find_by_name("football")
|
107
|
+
minor = category.children.find_by_name("minor")
|
108
|
+
minor.children.create(:name => "topps")
|
109
|
+
|
110
|
+
minor.destroy
|
111
|
+
category.children.find_by_name("minor").should eql nil
|
112
|
+
Category.find_by_name("basketball").children.should_not eql nil
|
113
|
+
Category.find_by_name("baseball").children.should_not eql nil
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
75
117
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
|
1
|
+
FactoryBot.define do
|
2
2
|
factory :animals, class: Category do
|
3
|
-
name "animals"
|
3
|
+
name { "animals" }
|
4
4
|
end
|
5
5
|
|
6
6
|
factory :cats, class: Category do
|
7
|
-
name "cats"
|
7
|
+
name { "cats" }
|
8
8
|
association :parent, factory: :animals, strategy: :build
|
9
9
|
end
|
10
10
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
require 'active_record'
|
3
|
-
require '
|
3
|
+
require 'factory_bot'
|
4
4
|
require 'acts_as_better_tree'
|
5
5
|
|
6
6
|
# Requires supporting files with custom matchers and macros, etc,
|
@@ -8,5 +8,10 @@ require 'acts_as_better_tree'
|
|
8
8
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
9
|
|
10
10
|
RSpec.configure do |config|
|
11
|
+
config.include FactoryBot::Syntax::Methods
|
11
12
|
|
13
|
+
# Explicitly enable the should syntax
|
14
|
+
config.expect_with :rspec do |c|
|
15
|
+
c.syntax = [:should, :expect]
|
16
|
+
end
|
12
17
|
end
|