Commit 847d2796 authored by James Lopez's avatar James Lopez

fixed spec and SQL query

parent 470e39d6
...@@ -9,26 +9,28 @@ module Gitlab ...@@ -9,26 +9,28 @@ module Gitlab
end end
def fetch_issues def fetch_issues
cte_table = Arel::Table.new("cte_table_for_issue")
# Build a `SELECT` query. We find the first of the `end_time_attrs` that isn't `NULL` (call this end_time).
# Next, we find the first of the start_time_attrs that isn't `NULL` (call this start_time).
# We compute the (end_time - start_time) interval, and give it an alias based on the current
# cycle analytics stage.
base_query = base_query_for(:issue) base_query = base_query_for(:issue)
diff_fn = subtract_datetimes_diff(base_query, issue_table[:created_at], metric_attributes) diff_fn = subtract_datetimes_diff(base_query, issue_table[:created_at], metric_attributes)
query = base_query.project(diff_fn.as('issue_diff')) query = base_query.join(user_table).on(issue_table[:author_id].eq(user_table[:id])).
project(diff_fn.as('issue_diff'), *issue_projections).
order(issue_table[:created_at].desc)
ActiveRecord::Base.connection.execute(query.to_sql) ActiveRecord::Base.connection.execute(query.to_sql).first
end end
def metric_attributes def metric_attributes
[issue_metrics_table[:first_associated_with_milestone_at], [issue_metrics_table[:first_associated_with_milestone_at],
issue_metrics_table[:first_added_to_board_at]] issue_metrics_table[:first_added_to_board_at]]
end end
def issue_projections
[issue_table[:title], issue_table[:iid], issue_table[:created_at], User.arel_table[:name]]
end
def user_table
User.arel_table
end
end end
end end
end end
...@@ -14,8 +14,24 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -14,8 +14,24 @@ describe Gitlab::CycleAnalytics::Events do
describe '#issue' do describe '#issue' do
let!(:context) { create(:issue, project: project) } let!(:context) { create(:issue, project: project) }
xit 'does something' do it 'has an issue diff' do
expect(subject.issue_events).to eq([context]) expect(subject.issue_events['issue_diff']).to eq("-00:00:00.339259")
end
it 'has a title' do
expect(subject.issue_events['title']).to eq(context.title)
end
it 'has an iid' do
expect(subject.issue_events['iid']).to eq(context.iid)
end
it 'has a created_at timestamp' do
expect(subject.issue_events['created_at']).to eq(context.created_at)
end
it "has the author's name" do
expect(subject.issue_events['name']).to eq(context.author.name)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment