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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc74272fc7fc3915abb380329b5e94c5c5e1a0443eac3622cf822c6108c4a210
4
- data.tar.gz: 35fe1dc2025071cff6d0aa42a006a56eaeede88cf5ad4a4a44c4986c6b6923f6
3
+ metadata.gz: 4b7f71a6d2b5c286601e25437f287c4e1103d10255303100863d11d12f0d227e
4
+ data.tar.gz: c2d906d6f8e20c09a3d53d226d04b831bfd60cadd0427fdaacff42c0abd40ad4
5
5
  SHA512:
6
- metadata.gz: ea0b0db48776dcaf23d73d305beb17e43384f3c85b8faf77c099a2ed829487326154aa7bda9f17094e528f2f3da233f8f07f9c3aa9ecf8556afc2a7a232b77a4
7
- data.tar.gz: be207899c3706d392db8d6d4beb7ecec0577eb62874213c4480b59171791eb5cda45cea897424a91e28465aec16cfcdf93ced39d80ba1851a419f502e7810c24
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
- gem 'rspec'
5
+
6
+ gem 'rspec', '~> 3.12'
6
7
  gem 'rails', ">= 3.2.5"
7
- gem "factory_girl"
8
- gem "csv"
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.3)
89
+ diff-lcs (1.6.1)
90
90
  drb (2.2.1)
91
91
  erubi (1.13.1)
92
- factory_girl (3.6.1)
93
- activesupport (>= 3.0.0)
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 (2.11.0)
179
- rspec-core (~> 2.11.0)
180
- rspec-expectations (~> 2.11.0)
181
- rspec-mocks (~> 2.11.0)
182
- rspec-core (2.11.1)
183
- rspec-expectations (2.11.2)
184
- diff-lcs (~> 1.1.3)
185
- rspec-mocks (2.11.1)
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
- factory_girl
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
@@ -1,3 +1,3 @@
1
1
  module ActsAsBetterTree
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
@@ -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::establish_connection(:adapter => "sqlite3", :dbfile => ":memory:", :database => "gemtest")
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
- FactoryGirl.define do
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 'factory_girl'
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_better_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Isaac Sloan