selector_2_sql_examples.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.shared_examples 'TicketSelector2Sql' do
  4. context 'when relative time range is selected in ticket selector' do
  5. def get_condition(operator, range)
  6. {
  7. 'ticket.created_at' => {
  8. operator: operator,
  9. range: range, # minute|hour|day|month|
  10. value: '10',
  11. },
  12. }
  13. end
  14. before do
  15. freeze_time
  16. end
  17. it 'calculates proper time interval, when operator is within last relative' do
  18. condition = get_condition('within last (relative)', 'minute')
  19. _, bind_params = Ticket.selector2sql(condition)
  20. expect(bind_params).to eq([10.minutes.ago, Time.zone.now])
  21. end
  22. it 'calculates proper time interval, when operator is within next relative' do
  23. condition = get_condition('within next (relative)', 'hour')
  24. _, bind_params = Ticket.selector2sql(condition)
  25. expect(bind_params).to eq([Time.zone.now, 10.hours.from_now])
  26. end
  27. it 'calculates proper time interval, when operator is before (relative)' do
  28. condition = get_condition('before (relative)', 'day')
  29. _, bind_params = Ticket.selector2sql(condition)
  30. expect(bind_params).to eq([10.days.ago])
  31. end
  32. it 'calculates proper time interval, when operator is after (relative)' do
  33. condition = get_condition('after (relative)', 'week')
  34. _, bind_params = Ticket.selector2sql(condition)
  35. expect(bind_params).to eq([10.weeks.from_now])
  36. end
  37. it 'calculates proper time interval, when operator is till (relative)' do
  38. condition = get_condition('till (relative)', 'month')
  39. _, bind_params = Ticket.selector2sql(condition)
  40. expect(bind_params).to eq([10.months.from_now])
  41. end
  42. it 'calculates proper time interval, when operator is from (relative)' do
  43. condition = get_condition('from (relative)', 'year')
  44. _, bind_params = Ticket.selector2sql(condition)
  45. expect(bind_params).to eq([10.years.ago])
  46. end
  47. end
  48. end