Module: Lcms::Engine::Test::ResourceHelpers

Defined in:
lib/lcms/engine/test/resource_helpers.rb

Instance Method Summary collapse

Instance Method Details

#build_or_return_resources_chain(curr) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/lcms/engine/test/resource_helpers.rb', line 62

def build_or_return_resources_chain(curr)
  dir = []
  parent = nil
  ::Lcms::Engine::Resource.hierarchy.each_with_index do |type, idx|
    next unless curr[idx]

    dir.push curr[idx]
    res = ::Lcms::Engine::Resource.find_by(short_title: curr[idx]) ||
          FactoryBot.create(:resource,
                            title: "Test Resource #{dir.join('|')}",
                            short_title: curr[idx],
                            curriculum_type: type,
                            parent: parent,
                            metadata: ::Lcms::Engine::Resource.(dir))
    parent = res
  end
  parent
end

#build_resources_chain(curr) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/lcms/engine/test/resource_helpers.rb', line 45

def build_resources_chain(curr)
  dir = []
  parent = nil
  ::Lcms::Engine::Resource.hierarchy.each_with_index do |type, idx|
    next unless curr[idx]

    dir.push curr[idx]
    res = create(:resource,
                 title: "Test Resource #{dir.join('|')}",
                 short_title: curr[idx],
                 curriculum_type: type,
                 parent: parent,
                 metadata: ::Lcms::Engine::Resource.(dir))
    parent = res
  end
end

#resources_sample_collectionObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/lcms/engine/test/resource_helpers.rb', line 7

def resources_sample_collection
  # ELA G2 => 2 lessons
  2.times do |i|
    pos = i + 1
    dir = ['ela', 'grade 2', 'module 1', 'unit 1', "lesson #{pos}"]
    create(:resource,
           title: "Test Resource ELA G2 L#{pos}",
           metadata: ::Lcms::Engine::Resource.(dir))
  end

  # ELA G6 => 6 lessons
  6.times do |i|
    pos = i + 1
    dir = ['ela', 'grade 6', 'module 1', 'unit 1', "lesson #{pos}"]
    create(:resource,
           title: "Test Resource ELA G6 L#{pos}",
           metadata: ::Lcms::Engine::Resource.(dir))
  end

  # Math G4 => 4 lessons
  4.times do |i|
    pos = i + 1
    dir = ['math', 'grade 4', 'module 1', 'unit 1', "lesson #{pos}"]
    create(:resource,
           title: "Test Resource Math G4 L#{pos}",
           metadata: ::Lcms::Engine::Resource.(dir))
  end

  # Math G7 => 7 lessons
  7.times do |i|
    pos = i + 1
    dir = ['math', 'grade 7', 'module 1', 'unit 1', "lesson #{pos}"]
    create(:resource,
           title: "Test Resource Math G7 L#{pos}",
           metadata: ::Lcms::Engine::Resource.(dir))
  end
end