user_spec.rb
2.01 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
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe User do
it {should have_many :visitors}
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)
end
it "should be able to create a question as a site" do
q = @aoi_clone.create_question("foobarbaz", {:name => 'foo'})
q.should_not be_nil
q.site.should_not be_nil
q.site.should eql @aoi_clone
end
it "should be able to create a choice for a question " do
q = @aoi_clone.create_question("foobarbaz", {:name => 'foo'}) #replace with a factory
c = @aoi_clone.create_choice("foobarbaz", q, {:data => 'foobarbaz'})
q.should_not be_nil
q.choices.should_not be_empty
q.choices.size.should eql 3
end
it "should be able to record a visitor's vote" do
v = @aoi_clone.record_vote("johnnydoe", @appearance.lookup, @prompt, 0, 304)
prompt_votes = @prompt.votes(true)
prompt_votes.should_not be_empty
prompt_votes.size.should eql 1
choices = @prompt.choices
#@question.prompts(true).size.should == 2
choices.should_not be_empty
choice_votes = choices[0].votes(true)
choice_votes.should_not be_empty
choice_votes.size.should eql 1
end
it "should be able to record a visitor's skip" do
s = @aoi_clone.record_skip("johnnydoe", @prompt)
end
end