PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/spec/requests/projects/cycle_analytics_events_spec.rb

https://gitlab.com/artofhuman/gitlab-ce
Ruby | 134 lines | 94 code | 40 blank | 0 comment | 0 complexity | d9c1e0f34c3a0347a53702633d14138e MD5 | raw file
  1. require 'spec_helper'
  2. describe 'cycle analytics events' do
  3. let(:user) { create(:user) }
  4. let(:project) { create(:project, :repository, public_builds: false) }
  5. let(:issue) { create(:issue, project: project, created_at: 2.days.ago) }
  6. describe 'GET /:namespace/:project/cycle_analytics/events/issues' do
  7. before do
  8. project.add_developer(user)
  9. 3.times do |count|
  10. Timecop.freeze(Time.now + count.days) do
  11. create_cycle
  12. end
  13. end
  14. deploy_master(user, project)
  15. login_as(user)
  16. end
  17. it 'lists the issue events' do
  18. get project_cycle_analytics_issue_path(project, format: :json)
  19. first_issue_iid = project.issues.sort_by_attribute(:created_desc).pluck(:iid).first.to_s
  20. expect(json_response['events']).not_to be_empty
  21. expect(json_response['events'].first['iid']).to eq(first_issue_iid)
  22. end
  23. it 'lists the plan events' do
  24. get project_cycle_analytics_plan_path(project, format: :json)
  25. first_mr_short_sha = project.merge_requests.sort_by_attribute(:created_asc).first.commits.first.short_id
  26. expect(json_response['events']).not_to be_empty
  27. expect(json_response['events'].first['short_sha']).to eq(first_mr_short_sha)
  28. end
  29. it 'lists the code events' do
  30. get project_cycle_analytics_code_path(project, format: :json)
  31. expect(json_response['events']).not_to be_empty
  32. first_mr_iid = project.merge_requests.sort_by_attribute(:created_desc).pluck(:iid).first.to_s
  33. expect(json_response['events'].first['iid']).to eq(first_mr_iid)
  34. end
  35. it 'lists the test events' do
  36. get project_cycle_analytics_test_path(project, format: :json)
  37. expect(json_response['events']).not_to be_empty
  38. expect(json_response['events'].first['date']).not_to be_empty
  39. end
  40. it 'lists the review events' do
  41. get project_cycle_analytics_review_path(project, format: :json)
  42. first_mr_iid = project.merge_requests.sort_by_attribute(:created_desc).pluck(:iid).first.to_s
  43. expect(json_response['events']).not_to be_empty
  44. expect(json_response['events'].first['iid']).to eq(first_mr_iid)
  45. end
  46. it 'lists the staging events' do
  47. get project_cycle_analytics_staging_path(project, format: :json)
  48. expect(json_response['events']).not_to be_empty
  49. expect(json_response['events'].first['date']).not_to be_empty
  50. end
  51. it 'lists the production events' do
  52. get project_cycle_analytics_production_path(project, format: :json)
  53. first_issue_iid = project.issues.sort_by_attribute(:created_desc).pluck(:iid).first.to_s
  54. expect(json_response['events']).not_to be_empty
  55. expect(json_response['events'].first['iid']).to eq(first_issue_iid)
  56. end
  57. context 'specific branch' do
  58. it 'lists the test events' do
  59. branch = project.merge_requests.first.source_branch
  60. get project_cycle_analytics_test_path(project, format: :json, branch: branch)
  61. expect(json_response['events']).not_to be_empty
  62. expect(json_response['events'].first['date']).not_to be_empty
  63. end
  64. end
  65. context 'with private project and builds' do
  66. before do
  67. project.members.last.update(access_level: Gitlab::Access::GUEST)
  68. end
  69. it 'does not list the test events' do
  70. get project_cycle_analytics_test_path(project, format: :json)
  71. expect(response).to have_gitlab_http_status(:not_found)
  72. end
  73. it 'does not list the staging events' do
  74. get project_cycle_analytics_staging_path(project, format: :json)
  75. expect(response).to have_gitlab_http_status(:not_found)
  76. end
  77. it 'lists the issue events' do
  78. get project_cycle_analytics_issue_path(project, format: :json)
  79. expect(response).to have_gitlab_http_status(:ok)
  80. end
  81. end
  82. end
  83. def create_cycle
  84. milestone = create(:milestone, project: project)
  85. issue.update(milestone: milestone)
  86. mr = create_merge_request_closing_issue(user, project, issue, commit_message: "References #{issue.to_reference}")
  87. pipeline = create(:ci_empty_pipeline, status: 'created', project: project, ref: mr.source_branch, sha: mr.source_branch_sha, head_pipeline_of: mr)
  88. pipeline.run
  89. create(:ci_build, pipeline: pipeline, status: :success, author: user)
  90. create(:ci_build, pipeline: pipeline, status: :success, author: user)
  91. merge_merge_requests_closing_issue(user, project, issue)
  92. ProcessCommitWorker.new.perform(project.id, user.id, mr.commits.last.to_hash)
  93. end
  94. end