To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / b6 / b65ec8c82f61d464c9e0e9afaf52479ff0abd80c.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (1.71 KB)

1 1296:038ba2d95de8 Chris
require 'spec_helper'
2
3
describe "Helper" do
4
  include CollectiveIdea::Acts::NestedSet::Helper
5
6
  before(:all) do
7
    self.class.fixtures :categories
8
  end
9
10
  describe "nested_set_options" do
11
    it "test_nested_set_options" do
12
      expected = [
13
        [" Top Level", 1],
14
        ["- Child 1", 2],
15
        ['- Child 2', 3],
16
        ['-- Child 2.1', 4],
17
        ['- Child 3', 5],
18
        [" Top Level 2", 6]
19
      ]
20
      actual = nested_set_options(Category) do |c|
21
        "#{'-' * c.level} #{c.name}"
22
      end
23
      actual.should == expected
24
    end
25
26
    it "test_nested_set_options_with_mover" do
27
      expected = [
28
        [" Top Level", 1],
29
        ["- Child 1", 2],
30
        ['- Child 3', 5],
31
        [" Top Level 2", 6]
32
      ]
33
      actual = nested_set_options(Category, categories(:child_2)) do |c|
34
        "#{'-' * c.level} #{c.name}"
35
      end
36
      actual.should == expected
37
    end
38
39
    it "test_nested_set_options_with_array_as_argument_without_mover" do
40
      expected = [
41
        [" Top Level", 1],
42
        ["- Child 1", 2],
43
        ['- Child 2', 3],
44
        ['-- Child 2.1', 4],
45
        ['- Child 3', 5],
46
        [" Top Level 2", 6]
47
      ]
48
      actual = nested_set_options(Category.all) do |c|
49
        "#{'-' * c.level} #{c.name}"
50
      end
51
      actual.should == expected
52
    end
53
54
    it "test_nested_set_options_with_array_as_argument_with_mover" do
55
      expected = [
56
        [" Top Level", 1],
57
        ["- Child 1", 2],
58
        ['- Child 3', 5],
59
        [" Top Level 2", 6]
60
      ]
61
      actual = nested_set_options(Category.all, categories(:child_2)) do |c|
62
        "#{'-' * c.level} #{c.name}"
63
      end
64
      actual.should == expected
65
    end
66
  end
67
end