You have the concept down. The test would look like this:

it "updates its cumulative score when a comment gets a score" do
      comment_1 = @link.comments.first
      comment_1.vote_up
       
      comment_2 = FactoryGirl.create(:comment, link:@link)
      2.times { comment_2.vote_up }
  
      @link.score.should == 5
    end

To get this to pass you need to add the following code:

In comment.rb:

after_save :update_link_score # after a comment is saved call update_link_score
after_initialize { score ||= 0 }    # sets the score to 0 if it's nil. This will prevent the "NoMethodError" you got

def vote_up
  self.score += 1
  self.save
end

protected
def update_link_score
  if self.link.present?        # if the comment is associated with a link
    self.link.update_score # call the update_score method in link.rb
  end
end

In link.rb:

after_initialize { self.score ||= 0 } 

def update_score
  updated_score = self.comments.sum(:score) # the updated score will be the sum of the comments score column
  self.update_attribute(:score, updated_score)  # actually update & save the link score.
end