Sha256: e1a438313e21d8fb3f60137afe15ffbc048903d7de7b9903d29ab865790d5dd4
Contents?: true
Size: 1.13 KB
Versions: 14
Compression:
Stored size: 1.13 KB
Contents
require 'spec_helper' def assert_lineage(e, m) expect(m.parent).to eq(e) expect(m.self_and_ancestors).to eq([m, e]) # make sure reloading doesn't affect the self_and_ancestors: m.reload expect(m.self_and_ancestors).to eq([m, e]) end describe CuisineType do it "finds self and parents when children << is used" do e = CuisineType.new(:name => "e") m = CuisineType.new(:name => "m") e.children << m e.save assert_lineage(e, m) end it "finds self and parents properly if the constructor is used" do e = CuisineType.create(:name => "e") m = CuisineType.create(:name => "m", :parent => e) assert_lineage(e, m) end it "sets the table_name of the hierarchy class properly" do expect(CuisineTypeHierarchy.table_name).to eq(ActiveRecord::Base.table_name_prefix + "cuisine_type_hierarchies" + ActiveRecord::Base.table_name_suffix) end it 'fixes self_and_ancestors properly on reparenting' do a = CuisineType.create! :name => 'a' b = CuisineType.create! :name => 'b' expect(b.self_and_ancestors.to_a).to eq([b]) a.children << b expect(b.self_and_ancestors.to_a).to eq([b, a]) end end
Version data entries
14 entries across 14 versions & 1 rubygems