Commit e6de02cb7bb87308a18738d9a14bfae5f5c2337b

Authored by Andrew Kane
1 parent 4d9e570d

Added test for last option with date column - #155

Showing 1 changed file with 18 additions and 2 deletions   Show diff stats
test/test_helper.rb
... ... @@ -225,6 +225,18 @@ module TestDatabase
225 225 assert_equal expected, User.group_by_year(:created_at, last: 3).count
226 226 end
227 227  
  228 + def test_last_date
  229 + Time.zone = pt
  230 + create_user Date.today.to_s
  231 + expected = {
  232 + Date.parse("#{this_year}-#{this_month - 1}-01") => 0,
  233 + Date.parse("#{this_year}-#{this_month}-01") => 1
  234 + }
  235 + assert_equal expected, User.group_by_month(:created_on, last: 2).count
  236 + ensure
  237 + Time.zone = nil
  238 + end
  239 +
228 240 def test_last_hour_of_day
229 241 error = assert_raises(ArgumentError) { User.group_by_hour_of_day(:created_at, last: 3).count }
230 242 assert_equal "Cannot use last option with hour_of_day", error.message
... ... @@ -1165,11 +1177,15 @@ module TestGroupdate
1165 1177 end
1166 1178  
1167 1179 def this_quarters_month
1168   - Time.now.utc.beginning_of_quarter.month
  1180 + Time.now.beginning_of_quarter.month
1169 1181 end
1170 1182  
1171 1183 def this_year
1172   - Time.now.utc.year
  1184 + Time.now.year
  1185 + end
  1186 +
  1187 + def this_month
  1188 + Time.now.month
1173 1189 end
1174 1190  
1175 1191 def utc
... ...