require 'rubygems' require 'mosquito' require File.dirname(__FILE__) + '/../linkr' ActiveRecord::Base.configurations = {:x => 'x'} # pretend AR is configured Linkr.create include Linkr::Models class TestVote < Camping::UnitTest fixtures :linkr_links, :linkr_votes def test_vote user = 'mosquito' link = Link.find :first assert_equal 0, Vote.find_all_by_user(user).size Vote.for user, link, :up assert_equal 1, Vote.find_all_by_user(user).size end def test_score user = 'mosquito' link = Link.find :first assert_equal 1, link.score Vote.for user, link, :up link.reload assert_equal 2, link.score Vote.for user, link, :down link.reload assert_equal 1, link.score end # julianday sqlite function doesn't seem to be working under :memory: mode # def test_sorting # assert_equal [1, 2, 3], Link.find_all_by_score.collect { |l| l.id } # end def test_find_tags link = Link.find :first link.tags = 'cool none links' link.update assert Link.find_tags.include?('cool') assert Link.find_tags.include?('links') end def test_link_description_saved_as_comment link = Link.new :user => 'mosquito', :url => 'http://somesite.com', :title => 'Coolish', :description => 'This is cool!' assert link.save link.reload assert_equal 'This is cool!', link.comments.first.body assert_equal 'mosquito', link.comments.first.user end def test_link_with_no_description link = Link.new :user => 'mosquito', :url => 'http://somesite.com', :title => 'Coolish' assert link.save link.reload assert_equal 0, link.comments.size end end