Class: RTrail::Section

Inherits:
Entity
  • Object
show all
Includes:
Methods::Delete, Methods::Get, Methods::Update
Defined in:
lib/rtrail/section.rb

Instance Attribute Summary

Attributes inherited from Entity

#data

Instance Method Summary collapse

Methods included from Methods::Delete

#delete

Methods included from Methods::Update

#update

Methods included from Methods::Get

included

Methods inherited from Entity

#add_entity, basename, client, #client, client=, #get_entities, #initialize, #method_missing

Methods included from Helpers

included, #is_id?, #path_with_params

Constructor Details

This class inherits a constructor from RTrail::Entity

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RTrail::Entity

Instance Method Details

#add_case(fields = {}) ⇒ Object

Add a new Case to the Section Requires :title, :custom_steps_separated, :custom_expected :custom_steps_separated => [ => ‘Action’, ‘expected’ => ‘Expectation’, … ]



45
46
47
# File 'lib/rtrail/section.rb', line 45

def add_case(fields={})
  return add_entity(Case, data.id, fields)
end

#add_subsection(fields = {}) ⇒ Object

Add a Section within this Section



50
51
52
53
54
55
56
57
# File 'lib/rtrail/section.rb', line 50

def add_subsection(fields={})
  _suite = suite
  subsection_data = fields.merge({
    :suite_id => _suite.id,
    :parent_id => data.id
  })
  return add_entity(Section, _suite.project_id, subsection_data)
end

#case(case_title_or_id) ⇒ Object

Return the Case matching a title or ID



34
35
36
37
38
39
40
# File 'lib/rtrail/section.rb', line 34

def case(case_title_or_id)
  if is_id?(case_title_or_id)
    return Case.get(case_title_or_id)
  else
    return case_by_title(case_title_or_id)
  end
end

#case_by_title(case_title) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/rtrail/section.rb', line 22

def case_by_title(case_title)
  kase = cases.find do |c|
    c.title == case_title
  end
  if kase.nil?
    raise RTrail::NotFound.new(
      "Case '#{case_title}' not found in Section '#{data.name}'")
  end
  return kase
end

#casesObject

Return the Cases in this Section



18
19
20
# File 'lib/rtrail/section.rb', line 18

def cases
  return suite.cases(data.id)
end

#subsection(subsection_name_or_id) ⇒ Object

Return the Subsection with the given name or ID



79
80
81
82
83
84
85
# File 'lib/rtrail/section.rb', line 79

def subsection(subsection_name_or_id)
  if is_id?(subsection_name_or_id)
    return Section.get(subsection_name_or_id)
  else
    return subsection_by_name(subsection_name_or_id)
  end
end

#subsection_by_name(subsection_name) ⇒ Object

Return the subsection with the given name



67
68
69
70
71
72
73
74
75
76
# File 'lib/rtrail/section.rb', line 67

def subsection_by_name(subsection_name)
  subsect = subsections.find do |s|
    s.name == subsection_name
  end
  if subsect.nil?
    raise RTrail::NotFound.new(
      "Sub-Section '#{subsection_name}' not found within Section '#{data.name}'")
  end
  return subsect
end

#subsectionsObject

Return all Subsections in this Section



60
61
62
63
64
# File 'lib/rtrail/section.rb', line 60

def subsections
  return suite.sections.select do |sect|
    sect.parent_id == data.id
  end
end

#suiteObject

Return the Suite this Section is in



13
14
15
# File 'lib/rtrail/section.rb', line 13

def suite
  return Suite.get(data.suite_id)
end