Commit 6d005f2618e111d22f4bccf9b3b2bfd95a425cd0

Authored by Andrew Kane
2 parents 63162161 3fed5ff9

Merge pull request #98 from codesnik/fix_tests

Make some tests work properly now and in future
Showing 1 changed file with 16 additions and 12 deletions   Show diff stats
test/test_helper.rb
... ... @@ -688,22 +688,22 @@ module TestGroupdate
688 688 end
689 689  
690 690 def test_last
691   - create_user "2012-05-01 00:00:00 UTC"
692   - create_user "2014-05-01 00:00:00 UTC"
  691 + create_user "#{this_year - 3}-01-01 00:00:00 UTC"
  692 + create_user "#{this_year - 1}-01-01 00:00:00 UTC"
693 693 expected = {
694   - utc.parse("2013-01-01 00:00:00 UTC") => 0,
695   - utc.parse("2014-01-01 00:00:00 UTC") => 1,
696   - utc.parse("2015-01-01 00:00:00 UTC") => 0
  694 + utc.parse("#{this_year - 2}-01-01 00:00:00 UTC") => 0,
  695 + utc.parse("#{this_year - 1}-01-01 00:00:00 UTC") => 1,
  696 + utc.parse("#{this_year }-01-01 00:00:00 UTC") => 0
697 697 }
698 698 assert_equal expected, User.group_by_year(:created_at, last: 3).count
699 699 end
700 700  
701 701 def test_current
702   - create_user "2012-05-01 00:00:00 UTC"
703   - create_user "2014-05-01 00:00:00 UTC"
  702 + create_user "#{this_year - 3}-01-01 00:00:00 UTC"
  703 + create_user "#{this_year - 1}-01-01 00:00:00 UTC"
704 704 expected = {
705   - utc.parse("2013-01-01 00:00:00 UTC") => 0,
706   - utc.parse("2014-01-01 00:00:00 UTC") => 1
  705 + utc.parse("#{this_year - 2}-01-01 00:00:00 UTC") => 0,
  706 + utc.parse("#{this_year - 1}-01-01 00:00:00 UTC") => 1
707 707 }
708 708 assert_equal expected, User.group_by_year(:created_at, last: 2, current: false).count
709 709 end
... ... @@ -801,10 +801,10 @@ module TestGroupdate
801 801 # default value
802 802  
803 803 def test_default_value
804   - create_user "2015-05-01 00:00:00 UTC"
  804 + create_user "#{this_year }-01-01 00:00:00 UTC"
805 805 expected = {
806   - utc.parse("2014-01-01 00:00:00 UTC") => nil,
807   - utc.parse("2015-01-01 00:00:00 UTC") => 1
  806 + utc.parse("#{this_year - 1}-01-01 00:00:00 UTC") => nil,
  807 + utc.parse("#{this_year }-01-01 00:00:00 UTC") => 1
808 808 }
809 809 assert_equal expected, User.group_by_year(:created_at, last: 2, default_value: nil).count
810 810 end
... ... @@ -884,6 +884,10 @@ module TestGroupdate
884 884 User.create! :name => "Andrew", :score => score, :created_at => utc.parse(created_at)
885 885 end
886 886  
  887 + def this_year
  888 + Time.now.utc.year
  889 + end
  890 +
887 891 def utc
888 892 ActiveSupport::TimeZone["UTC"]
889 893 end
... ...