Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
require File.dirname(__FILE__) + '/../test_helper'

def default_options(options = {})
  {
    :user_id    => 3829,
    :featured_by=> 2,
    :corkd_take => "Rules",
    :start_date => Date.today + 14,
    :end_date   => Date.today + 21
  }.merge(options)
end

context "A generic Featured User object" do
  specify "should return the correct user for today" do
    FeaturedUser.current.should.not.be.nil
  end

  specify "should return the correct user for another day" do
    FeaturedUser.featured_on(Date.today + 1).should.not.be.nil
  end
  
  specify "should return nil for a blank range" do
    FeaturedUser.featured_on(Date.today + 14).should.be.nil
  end
  
  specify "should get a list of days / users for a given month" do
    days_users = FeaturedUser.featured_for_month(Time.now.month, Time.now.year)
    # days_users.should.include? "simplebits"
    # days_users.index("simplebits").should.be Today.now.day
  end
  
end

context "A featured user creation attempt should fail" do
  setup do
    @featured_user = FeaturedUser.new(default_options)
  end
  
  specify "without a user_id" do
    @featured_user.user_id = nil
    @featured_user.should.not.validate
  end
  
  specify "without a featuring person" do
    @featured_user.featured_by = nil
    @featured_user.should.not.validate
  end
  
  specify "without a cork'd take" do
    @featured_user.corkd_take = nil
    @featured_user.should.not.validate
  end

  specify "without a start date" do
    @featured_user.start_date = nil
    @featured_user.should.not.validate
  end
  
  specify "without an end date" do
    @featured_user.end_date = nil
    @featured_user.should.not.validate
  end
  
  specify "with conflicting dates" do
    @featured_user.start_date = Time.now - 1.week
    @featured_user.should.not.validate
  end
  
  specify "with dates that are within another ranges dates" do
    @featured_user.start_date = Time.now - 1.week + 300
    @featured_user.end_date = Time.now + 1.week - 300
    @featured_user.should.not.validate
  end

  specify "with reversed dates" do
    @featured_user.start_date = Time.now + 2.weeks
    @featured_user.end_date = Time.now + 1.week
    @featured_user.should.not.validate
  end
end

context "A featured user creation attempt should succede" do
  setup do
    @featured_user = FeaturedUser.new(default_options)
  end
  
  specify "with everything as it should be" do
    @featured_user.should.validate
  end
end