Module: Itriagetestrail::Projects

Included in:
TestRailInterface
Defined in:
lib/itriagetestrail/testrail_objects/projects.rb

Instance Method Summary collapse

Instance Method Details

#project_by_id(id) ⇒ Object

return the project object for a given project id



24
25
26
27
28
29
30
# File 'lib/itriagetestrail/testrail_objects/projects.rb', line 24

def project_by_id(id)
  res = -1
  projects.each do |project|
    res = project if project['id'] == id.to_i
  end
  res
end

#project_by_name(name) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/itriagetestrail/testrail_objects/projects.rb', line 15

def project_by_name(name)
  res = -1
  projects.each do |project|
    res = project if project['name'] == name
  end
  res
end

#projectsObject

populate projects instance variable with all projects objects in the testrail site



11
12
13
# File 'lib/itriagetestrail/testrail_objects/projects.rb', line 11

def projects
  @projects ||= @client.send_get('get_projects')
end

#set_projectObject

set the project_id by a requested project from config/environment variable



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/itriagetestrail/testrail_objects/projects.rb', line 33

def set_project
  requested_id = @testrail_config[:projectId]
  case requested_id
  when nil, ''
    # a project id was not provided, fetch it from TestRail by project name
    res = project_by_name(@testrail_config[:projectName])
    if res == -1
      @execute = false
      return
    end
    @project_id = res['id']
    @suite_mode = res['suite_mode']
  else
    # use the requested project id
    @project_id = requested_id
    @suite_mode = project_by_id(@project_id)['suite_mode']
  end
end