fixed spec and SQL query

This commit is contained in:
James Lopez 2016-10-17 14:57:23 +02:00
parent 470e39d64f
commit 847d2796cf
2 changed files with 30 additions and 12 deletions

View File

@ -9,26 +9,28 @@ module Gitlab
end
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)
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
def metric_attributes
[issue_metrics_table[:first_associated_with_milestone_at],
issue_metrics_table[:first_added_to_board_at]]
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

View File

@ -14,8 +14,24 @@ describe Gitlab::CycleAnalytics::Events do
describe '#issue' do
let!(:context) { create(:issue, project: project) }
xit 'does something' do
expect(subject.issue_events).to eq([context])
it 'has an issue diff' do
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