visitor_spec.rb
2.64 KB
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
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Visitor do
it {should belong_to :site}
it {should have_many :questions}
it {should have_many :votes}
it {should have_many :skips}
it {should have_many :clicks}
before(:each) do
@aoi_clone = Factory.create(:user)
@johndoe = Factory.create(:visitor, :identifier => 'johndoe', :site => @aoi_clone)
@question = Factory.create(:question, :name => 'which do you like better?', :site => @aoi_clone, :creator => @aoi_clone.default_visitor)
@lc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'hello gorgeous')
@rc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'goodbye gorgeous')
@prompt = Factory.create(:prompt, :question => @question, :tracking => 'sample', :left_choice => @lc, :right_choice => @rc)
@visitor = @aoi_clone.visitors.find_or_create_by_identifier("test_visitor_identifier")
@appearance = @aoi_clone.record_appearance(@visitor, @prompt)
@valid_attributes = {
:site => @aoi_clone,
:identifier => "value for identifier",
:tracking => "value for tracking"
}
@v = Visitor.create!(@valid_attributes)
end
it "should create a new instance given valid attributes" do
end
it "should be able to determine ownership of a question" do
@v.owns?(Question.new).should be_false
ownedquestion = Factory.create(:question, :site => @aoi_clone, :creator=> @johndoe)
@johndoe.owns?(ownedquestion).should be_true
end
it "should be able to vote for a prompt" do
#@prompt = @question.prompts.first
@prompt.should_not be_nil
v = @v.vote_for! @appearance.lookup, @prompt, 0, 340
end
it "should be able to skip a prompt" do
#@prompt = @question.prompts.first
@prompt.should_not be_nil
v = @v.skip! @prompt
end
it "should accurately update score counts after vote" do
prev_winner_score = @lc.score
prev_loser_score = @rc.score
vote = @v.vote_for! @appearance.lookup, @prompt, 0, 340
@lc.reload
@rc.reload
@lc.score.should > prev_winner_score
@rc.score.should < prev_loser_score
end
it "should accurately update win and loss totals after vote" do
prev_winner_wins = @lc.wins
prev_winner_losses = @lc.losses
prev_loser_losses = @rc.losses
prev_loser_wins = @rc.wins
vote = @v.vote_for! @appearance.lookup, @prompt, 0, 340
@lc.reload
@rc.reload
@lc.wins.should == prev_winner_wins + 1
@lc.losses.should == prev_winner_losses
@rc.losses.should == prev_loser_losses + 1
@rc.wins.should == prev_winner_wins
end
end