diff --git a/spec/controllers/prompts_controller_spec.rb b/spec/controllers/prompts_controller_spec.rb index 2074ddc..056073b 100644 --- a/spec/controllers/prompts_controller_spec.rb +++ b/spec/controllers/prompts_controller_spec.rb @@ -7,13 +7,9 @@ describe PromptsController do end # before(:each) do - @aoi_clone = Factory.create(:user) - sign_in_as(@user = Factory(:email_confirmed_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) + @question = Factory.create(:aoi_question) + sign_in_as(@aoi_clone = @question.site) + @prompt = @question.prompts.first @visitor = @aoi_clone.visitors.find_or_create_by_identifier("test_visitor_identifier") @appearance = @aoi_clone.record_appearance(@visitor, @prompt) diff --git a/spec/models/choice_spec.rb b/spec/models/choice_spec.rb index f6a64d6..1f92e81 100644 --- a/spec/models/choice_spec.rb +++ b/spec/models/choice_spec.rb @@ -8,12 +8,14 @@ describe Choice do it {should validate_presence_of :question} before(:each) do - @aoi_clone = Factory.create(:user, :email => "pius@alum.mit.edu", :password => "password", :password_confirmation => "password", :id => 8) - @johndoe = Factory.create(:visitor, :identifier => 'johndoe', :site => @aoi_clone) - @question = Question.create(:name => 'which do you like better?', :site => @aoi_clone, :creator => @johndoe) + @aoi_clone = Factory.create(:email_confirmed_user) + @visitor= Factory.create(:visitor, :site => @aoi_clone) + @question = Question.create(:name => 'which do you like better?', + :site => @aoi_clone, + :creator => @visitor) @valid_attributes = { - :creator => @johndoe, + :creator => @visitor, :question => @question, :data => 'hi there' } @@ -23,11 +25,11 @@ describe Choice do Choice.create!(@valid_attributes) end - it "should generate prompts after creation" do - prev_choices = @question.choices.size - @question.prompts.should_not be_empty - proc {choice1 = Choice.create!(@valid_attributes.merge(:data => '1234'))}.should change(@question.prompts, :count).by(prev_choices*2) - @question.prompts.should_not be_empty + it "should generate prompts after two choices are created" do + proc { + choice1 = Choice.create!(@valid_attributes.merge(:data => '1234')) + choice2 = Choice.create!(@valid_attributes.merge(:data => '1234')) + }.should change(@question.prompts, :count).by(2) end it "should deactivate a choice" do @@ -37,10 +39,13 @@ describe Choice do end it "should update a question's counter cache on creation" do - @question.choices.size.should == 2 - choice1 = Choice.create!(@valid_attributes.merge(:data => '1234')) + @question.choices_count.should == 0 + @question.choices.size.should == 0 + Choice.create!(@valid_attributes.merge(:data => '1234')) @question.reload - @question.choices.size.should == 3 + @question.choices_count.should == 1 + @question.choices.size.should == 1 + end it "should update a question's counter cache on activation" do diff --git a/spec/models/prompt_spec.rb b/spec/models/prompt_spec.rb index 569ea06..a8dd846 100644 --- a/spec/models/prompt_spec.rb +++ b/spec/models/prompt_spec.rb @@ -5,22 +5,4 @@ describe Prompt do it {should belong_to :left_choice} it {should belong_to :right_choice} - before(:each) do - @aoi_clone = Factory.create(:user, :email => "pius@alum.mit.edu", :password => "password", :password_confirmation => "password", :id => 8) - @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) - @valid_attributes = { - :left_choice => @lc, - :right_choice => @rc, - :question => @question - - } - end - - it "should create a new instance given valid attributes" do - - end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index a37d203..ec89bbe 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -5,14 +5,9 @@ describe User do 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) + @question = Factory.create(:aoi_question) + @prompt = @question.prompts.first - @visitor = @aoi_clone.visitors.find_or_create_by_identifier("test_visitor_identifier") - @appearance = @aoi_clone.record_appearance(@visitor, @prompt) end @@ -28,10 +23,12 @@ describe User do 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 + q.choices.size.should eql 1 end it "should be able to record a visitor's vote" do + @visitor = @aoi_clone.visitors.find_or_create_by_identifier("test_visitor_identifier") + @appearance = @aoi_clone.record_appearance(@visitor, @prompt) v = @aoi_clone.record_vote("johnnydoe", @appearance.lookup, @prompt, 0, 304) prompt_votes = @prompt.votes(true) prompt_votes.should_not be_empty @@ -47,6 +44,8 @@ describe User do end it "should be able to record a visitor's skip" do + @visitor = @aoi_clone.visitors.find_or_create_by_identifier("test_visitor_identifier") + @appearance = @aoi_clone.record_appearance(@visitor, @prompt) s = @aoi_clone.record_skip("johnnydoe", @appearance.lookup, @prompt, 340) end diff --git a/spec/models/visitor_spec.rb b/spec/models/visitor_spec.rb index 297a806..15e74a2 100644 --- a/spec/models/visitor_spec.rb +++ b/spec/models/visitor_spec.rb @@ -9,12 +9,13 @@ describe Visitor do 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) + @question = Factory.create(:aoi_question) + @aoi_clone = @question.site + @johndoe = @question.creator + + @prompt = @question.prompts.first + @lc = @prompt.left_choice + @rc = @prompt.right_choice @visitor = @aoi_clone.visitors.find_or_create_by_identifier("test_visitor_identifier") @appearance = @aoi_clone.record_appearance(@visitor, @prompt) @@ -23,16 +24,15 @@ describe Visitor do :identifier => "value for identifier", :tracking => "value for tracking" } - @v = Visitor.create!(@valid_attributes) - end it "should create a new instance given valid attributes" do + @visitor = Visitor.create!(@valid_attributes) end it "should be able to determine ownership of a question" do - @v.owns?(Question.new).should be_false + @visitor.owns?(Question.new).should be_false ownedquestion = Factory.create(:question, :site => @aoi_clone, :creator=> @johndoe) @johndoe.owns?(ownedquestion).should be_true @@ -41,20 +41,20 @@ describe Visitor do 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 + v = @visitor.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! @appearance.lookup, @prompt, 304 + v = @visitor.skip! @appearance.lookup, @prompt, 304 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 + vote = @visitor.vote_for! @appearance.lookup, @prompt, 0, 340 @lc.reload @rc.reload @@ -69,7 +69,7 @@ describe Visitor do prev_loser_losses = @rc.losses prev_loser_wins = @rc.wins - vote = @v.vote_for! @appearance.lookup, @prompt, 0, 340 + vote = @visitor.vote_for! @appearance.lookup, @prompt, 0, 340 @lc.reload @rc.reload -- libgit2 0.21.2