summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-10-24 15:24:56 +0100
committerJames Lopez <james@jameslopez.es>2016-11-17 08:22:55 +0100
commitd4726112656df24ff7721865a96237d5168466f7 (patch)
tree93a5912a8b3ecb44d10cd9fa3841a910aa5b62ba
parent3cdc9af78ebb71e2b91046e9dea8695aa04f6713 (diff)
downloadgitlab-ce-d4726112656df24ff7721865a96237d5168466f7.tar.gz
added cycle analytics events controller and started integration spec
-rw-r--r--app/controllers/projects/cycle_analytics/events_controller.rb34
-rw-r--r--config/routes/project.rb6
-rw-r--r--spec/requests/projects/cycle_analytics_events_spec.rb24
3 files changed, 64 insertions, 0 deletions
diff --git a/app/controllers/projects/cycle_analytics/events_controller.rb b/app/controllers/projects/cycle_analytics/events_controller.rb
new file mode 100644
index 00000000000..fe0135874b9
--- /dev/null
+++ b/app/controllers/projects/cycle_analytics/events_controller.rb
@@ -0,0 +1,34 @@
+class Projects::CycleAnalytics::EventsController < Projects::ApplicationController
+ #before_action :authorize_read_cycle_analytics!
+
+ def issues
+ respond_to do |format|
+ format.html
+ format.json { render json: events.issue_events }
+ end
+ end
+
+ private
+
+ # TODO refactor this
+ def start_date
+ case events_params[:start_date]
+ when '30' then
+ 30.days.ago
+ when '90' then
+ 90.days.ago
+ else
+ 90.days.ago
+ end
+ end
+
+ def events
+ @events ||= Gitlab::CycleAnalytics::Events.new(project: project, from: start_date)
+ end
+
+ def events_params
+ return {} unless params[:events].present?
+
+ { start_date: params[:events][:start_date] }
+ end
+end \ No newline at end of file
diff --git a/config/routes/project.rb b/config/routes/project.rb
index 9cf8465dca8..ed595c777f5 100644
--- a/config/routes/project.rb
+++ b/config/routes/project.rb
@@ -153,6 +153,12 @@ resources :namespaces, path: '/', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only:
resource :cycle_analytics, only: [:show]
+ namespace :cycle_analytics do
+ scope :events, controller: '/projects/cycle_analytics/events' do
+ get :issues
+ end
+ end
+
resources :builds, only: [:index, :show], constraints: { id: /\d+/ } do
collection do
post :cancel_all
diff --git a/spec/requests/projects/cycle_analytics_events_spec.rb b/spec/requests/projects/cycle_analytics_events_spec.rb
new file mode 100644
index 00000000000..064434c127e
--- /dev/null
+++ b/spec/requests/projects/cycle_analytics_events_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe 'cycle analytics events' do
+ let(:user) { create(:user) }
+ let(:project) { create(:project) }
+
+ describe 'GET /:namespace/:project/cycle_analytics/events/issues' do
+ before do
+ project.team << [user, :developer]
+
+ login_as(user)
+ end
+
+ it 'lists the issue events' do
+ get namespace_project_cycle_analytics_issues_path(project.namespace, project, format: :json)
+
+ expect(json_response).to eq ([])
+ end
+ end
+
+ def json_response
+ JSON.parse(response.body)
+ end
+end