Commit a36f7203940155c17693487adff6749c7f332e0e

Authored by Dhruv Kapadia
1 parent 578ad0c7

Modifying specs to deal with removing 2 choices on creation assumption

spec/controllers/prompts_controller_spec.rb
... ... @@ -7,13 +7,9 @@ describe PromptsController do
7 7 end
8 8 #
9 9 before(:each) do
10   - @aoi_clone = Factory.create(:user)
11   - sign_in_as(@user = Factory(:email_confirmed_user))
12   - @johndoe = Factory.create(:visitor, :identifier => 'johndoe', :site => @aoi_clone)
13   - @question = Factory.create(:question, :name => 'which do you like better?', :site => @aoi_clone, :creator => @aoi_clone.default_visitor)
14   - @lc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'hello gorgeous')
15   - @rc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'goodbye gorgeous')
16   - @prompt = Factory.create(:prompt, :question => @question, :tracking => 'sample', :left_choice => @lc, :right_choice => @rc)
  10 + @question = Factory.create(:aoi_question)
  11 + sign_in_as(@aoi_clone = @question.site)
  12 + @prompt = @question.prompts.first
17 13  
18 14 @visitor = @aoi_clone.visitors.find_or_create_by_identifier("test_visitor_identifier")
19 15 @appearance = @aoi_clone.record_appearance(@visitor, @prompt)
... ...
spec/models/choice_spec.rb
... ... @@ -8,12 +8,14 @@ describe Choice do
8 8 it {should validate_presence_of :question}
9 9  
10 10 before(:each) do
11   - @aoi_clone = Factory.create(:user, :email => "pius@alum.mit.edu", :password => "password", :password_confirmation => "password", :id => 8)
12   - @johndoe = Factory.create(:visitor, :identifier => 'johndoe', :site => @aoi_clone)
13   - @question = Question.create(:name => 'which do you like better?', :site => @aoi_clone, :creator => @johndoe)
  11 + @aoi_clone = Factory.create(:email_confirmed_user)
  12 + @visitor= Factory.create(:visitor, :site => @aoi_clone)
  13 + @question = Question.create(:name => 'which do you like better?',
  14 + :site => @aoi_clone,
  15 + :creator => @visitor)
14 16  
15 17 @valid_attributes = {
16   - :creator => @johndoe,
  18 + :creator => @visitor,
17 19 :question => @question,
18 20 :data => 'hi there'
19 21 }
... ... @@ -23,11 +25,11 @@ describe Choice do
23 25 Choice.create!(@valid_attributes)
24 26 end
25 27  
26   - it "should generate prompts after creation" do
27   - prev_choices = @question.choices.size
28   - @question.prompts.should_not be_empty
29   - proc {choice1 = Choice.create!(@valid_attributes.merge(:data => '1234'))}.should change(@question.prompts, :count).by(prev_choices*2)
30   - @question.prompts.should_not be_empty
  28 + it "should generate prompts after two choices are created" do
  29 + proc {
  30 + choice1 = Choice.create!(@valid_attributes.merge(:data => '1234'))
  31 + choice2 = Choice.create!(@valid_attributes.merge(:data => '1234'))
  32 + }.should change(@question.prompts, :count).by(2)
31 33 end
32 34  
33 35 it "should deactivate a choice" do
... ... @@ -37,10 +39,13 @@ describe Choice do
37 39 end
38 40  
39 41 it "should update a question's counter cache on creation" do
40   - @question.choices.size.should == 2
41   - choice1 = Choice.create!(@valid_attributes.merge(:data => '1234'))
  42 + @question.choices_count.should == 0
  43 + @question.choices.size.should == 0
  44 + Choice.create!(@valid_attributes.merge(:data => '1234'))
42 45 @question.reload
43   - @question.choices.size.should == 3
  46 + @question.choices_count.should == 1
  47 + @question.choices.size.should == 1
  48 +
44 49 end
45 50  
46 51 it "should update a question's counter cache on activation" do
... ...
spec/models/prompt_spec.rb
... ... @@ -5,22 +5,4 @@ describe Prompt do
5 5 it {should belong_to :left_choice}
6 6 it {should belong_to :right_choice}
7 7  
8   - before(:each) do
9   - @aoi_clone = Factory.create(:user, :email => "pius@alum.mit.edu", :password => "password", :password_confirmation => "password", :id => 8)
10   - @johndoe = Factory.create(:visitor, :identifier => 'johndoe', :site => @aoi_clone)
11   - @question = Factory.create(:question, :name => 'which do you like better?', :site => @aoi_clone, :creator => @aoi_clone.default_visitor)
12   - @lc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'hello gorgeous')
13   - @rc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'goodbye gorgeous')
14   - @prompt = Factory.create(:prompt, :question => @question, :tracking => 'sample', :left_choice => @lc, :right_choice => @rc)
15   - @valid_attributes = {
16   - :left_choice => @lc,
17   - :right_choice => @rc,
18   - :question => @question
19   -
20   - }
21   - end
22   -
23   - it "should create a new instance given valid attributes" do
24   -
25   - end
26 8 end
... ...
spec/models/user_spec.rb
... ... @@ -5,14 +5,9 @@ describe User do
5 5  
6 6 before(:each) do
7 7 @aoi_clone = Factory.create(:user)
8   - @johndoe = Factory.create(:visitor, :identifier => 'johndoe', :site => @aoi_clone)
9   - @question = Factory.create(:question, :name => 'which do you like better?', :site => @aoi_clone, :creator => @aoi_clone.default_visitor)
10   - @lc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'hello gorgeous')
11   - @rc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'goodbye gorgeous')
12   - @prompt = Factory.create(:prompt, :question => @question, :tracking => 'sample', :left_choice => @lc, :right_choice => @rc)
  8 + @question = Factory.create(:aoi_question)
  9 + @prompt = @question.prompts.first
13 10  
14   - @visitor = @aoi_clone.visitors.find_or_create_by_identifier("test_visitor_identifier")
15   - @appearance = @aoi_clone.record_appearance(@visitor, @prompt)
16 11 end
17 12  
18 13  
... ... @@ -28,10 +23,12 @@ describe User do
28 23 c = @aoi_clone.create_choice("foobarbaz", q, {:data => 'foobarbaz'})
29 24 q.should_not be_nil
30 25 q.choices.should_not be_empty
31   - q.choices.size.should eql 3
  26 + q.choices.size.should eql 1
32 27 end
33 28  
34 29 it "should be able to record a visitor's vote" do
  30 + @visitor = @aoi_clone.visitors.find_or_create_by_identifier("test_visitor_identifier")
  31 + @appearance = @aoi_clone.record_appearance(@visitor, @prompt)
35 32 v = @aoi_clone.record_vote("johnnydoe", @appearance.lookup, @prompt, 0, 304)
36 33 prompt_votes = @prompt.votes(true)
37 34 prompt_votes.should_not be_empty
... ... @@ -47,6 +44,8 @@ describe User do
47 44 end
48 45  
49 46 it "should be able to record a visitor's skip" do
  47 + @visitor = @aoi_clone.visitors.find_or_create_by_identifier("test_visitor_identifier")
  48 + @appearance = @aoi_clone.record_appearance(@visitor, @prompt)
50 49 s = @aoi_clone.record_skip("johnnydoe", @appearance.lookup, @prompt, 340)
51 50 end
52 51  
... ...
spec/models/visitor_spec.rb
... ... @@ -9,12 +9,13 @@ describe Visitor do
9 9 it {should have_many :clicks}
10 10  
11 11 before(:each) do
12   - @aoi_clone = Factory.create(:user)
13   - @johndoe = Factory.create(:visitor, :identifier => 'johndoe', :site => @aoi_clone)
14   - @question = Factory.create(:question, :name => 'which do you like better?', :site => @aoi_clone, :creator => @aoi_clone.default_visitor)
15   - @lc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'hello gorgeous')
16   - @rc = Factory.create(:choice, :question => @question, :creator => @johndoe, :data => 'goodbye gorgeous')
17   - @prompt = Factory.create(:prompt, :question => @question, :tracking => 'sample', :left_choice => @lc, :right_choice => @rc)
  12 + @question = Factory.create(:aoi_question)
  13 + @aoi_clone = @question.site
  14 + @johndoe = @question.creator
  15 +
  16 + @prompt = @question.prompts.first
  17 + @lc = @prompt.left_choice
  18 + @rc = @prompt.right_choice
18 19  
19 20 @visitor = @aoi_clone.visitors.find_or_create_by_identifier("test_visitor_identifier")
20 21 @appearance = @aoi_clone.record_appearance(@visitor, @prompt)
... ... @@ -23,16 +24,15 @@ describe Visitor do
23 24 :identifier => "value for identifier",
24 25 :tracking => "value for tracking"
25 26 }
26   - @v = Visitor.create!(@valid_attributes)
27   -
28 27 end
29 28  
30 29 it "should create a new instance given valid attributes" do
  30 + @visitor = Visitor.create!(@valid_attributes)
31 31  
32 32 end
33 33  
34 34 it "should be able to determine ownership of a question" do
35   - @v.owns?(Question.new).should be_false
  35 + @visitor.owns?(Question.new).should be_false
36 36  
37 37 ownedquestion = Factory.create(:question, :site => @aoi_clone, :creator=> @johndoe)
38 38 @johndoe.owns?(ownedquestion).should be_true
... ... @@ -41,20 +41,20 @@ describe Visitor do
41 41 it "should be able to vote for a prompt" do
42 42 #@prompt = @question.prompts.first
43 43 @prompt.should_not be_nil
44   - v = @v.vote_for! @appearance.lookup, @prompt, 0, 340
  44 + v = @visitor.vote_for! @appearance.lookup, @prompt, 0, 340
45 45 end
46 46  
47 47 it "should be able to skip a prompt" do
48 48 #@prompt = @question.prompts.first
49 49 @prompt.should_not be_nil
50   - v = @v.skip! @appearance.lookup, @prompt, 304
  50 + v = @visitor.skip! @appearance.lookup, @prompt, 304
51 51 end
52 52  
53 53 it "should accurately update score counts after vote" do
54 54 prev_winner_score = @lc.score
55 55 prev_loser_score = @rc.score
56 56  
57   - vote = @v.vote_for! @appearance.lookup, @prompt, 0, 340
  57 + vote = @visitor.vote_for! @appearance.lookup, @prompt, 0, 340
58 58  
59 59 @lc.reload
60 60 @rc.reload
... ... @@ -69,7 +69,7 @@ describe Visitor do
69 69 prev_loser_losses = @rc.losses
70 70 prev_loser_wins = @rc.wins
71 71  
72   - vote = @v.vote_for! @appearance.lookup, @prompt, 0, 340
  72 + vote = @visitor.vote_for! @appearance.lookup, @prompt, 0, 340
73 73  
74 74 @lc.reload
75 75 @rc.reload
... ...