added notes

This commit is contained in:
albert
2010-02-24 15:40:55 -05:00
parent 7bb935256b
commit 55700efeb1
17 changed files with 462 additions and 27 deletions

12
test/factories/note.rb Normal file
View File

@@ -0,0 +1,12 @@
Factory.define(:note) do |f|
f.creator {|x| x.association(:user)}
f.post {|x| x.association(:post)}
f.x 0
f.y 0
f.width 0
f.height 0
f.is_active true
f.body {Faker::Lorem.sentences.join}
f.updater_id {|x| x.creator_id}
f.updater_ip_addr "127.0.0.1"
end

View File

@@ -89,6 +89,7 @@ class ArtistTest < ActiveSupport::TestCase
should "revert to prior versions" do
user = Factory.create(:user)
reverter = Factory.create(:user)
artist = nil
assert_difference("ArtistVersion.count") do
artist = Factory.create(:artist, :other_names => "yyy")
@@ -103,7 +104,7 @@ class ArtistTest < ActiveSupport::TestCase
first_version = ArtistVersion.first
assert_equal("yyy", first_version.other_names)
artist.revert_to!(first_version)
artist.revert_to!(first_version, reverter.id, "127.0.0.1")
artist.reload
assert_equal("yyy", artist.other_names)
end

72
test/unit/note_test.rb Normal file
View File

@@ -0,0 +1,72 @@
require File.dirname(__FILE__) + '/../test_helper'
class NoteTest < ActiveSupport::TestCase
context "A note" do
setup do
MEMCACHE.flush_all
end
should "create versions" do
note = nil
assert_difference("NoteVersion.count") do
note = Factory.create(:note)
end
version = NoteVersion.last
assert_equal(note.body, version.body)
assert_difference("NoteVersion.count") do
note.update_attributes(:updater_id => note.creator_id, :updater_ip_addr => "127.0.0.1", :body => "fafafa")
end
version = NoteVersion.last
assert_equal("fafafa", version.body)
end
should "allow undoing any change from a user" do
vandal = Factory.create(:user)
reverter = Factory.create(:user)
note = Factory.create(:note, :x => 100, :y => 100)
note.update_attributes(:x => 2000, :y => 2000, :updater_id => vandal.id, :updater_ip_addr => "127.0.0.1")
note.reload
assert_equal(2000, note.x)
assert_equal(2000, note.y)
Note.undo_changes_by_user(vandal.id, reverter.id, "127.0.0.1")
note.reload
assert_equal(100, note.x)
assert_equal(100, note.y)
end
should "not validate if the post is note locked" do
post = Factory.create(:post, :is_note_locked => true)
note = Factory.build(:note, :post => post)
assert_difference("Note.count", 0) do
note.save
end
assert(note.errors.any?)
end
should "update the post when saved" do
post = Factory.create(:post)
assert_nil(post.last_noted_at)
note = Factory.create(:note, :post => post)
post.reload
assert_not_nil(post.last_noted_at)
end
should "know when the post is note locked" do
post = Factory.create(:post, :is_note_locked => true)
note = Factory.build(:note, :post => post)
assert(note.is_locked?)
end
should "return hits when searched" do
notes = []
notes << Factory.create(:note, :body => "aaa bbb ccc")
notes << Factory.create(:note, :body => "bbb ccc ddd", :is_active => false)
notes << Factory.create(:note, :body => "eee")
results = Note.build_relation(:query => "bbb").all
assert_equal(2, results.size)
results = Note.build_relation(:query => "bbb", :status => "Active").all
assert_equal(1, results.size)
assert_equal(notes[0].id, results[0].id)
end
end
end

View File

@@ -0,0 +1,8 @@
require 'test_helper'
class NoteVersionTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end

View File

@@ -39,6 +39,7 @@ class PostTest < ActiveSupport::TestCase
should "be created on any save" do
@user = Factory.create(:user)
@post = Factory.create(:post)
@reverter = Factory.create(:user)
assert_equal(1, @post.versions.size)
@post.rating = "e"
@@ -49,7 +50,7 @@ class PostTest < ActiveSupport::TestCase
assert_equal(@user.id, @post.versions.last.updater_id)
assert_equal("125.0.0.0", @post.versions.last.updater_ip_addr)
@post.revert_to!(PostVersion.first)
@post.revert_to!(PostVersion.first, @reverter.id, "127.0.0.1")
assert_equal("tag1 tag2", @post.tag_string)
assert_equal("q", @post.rating)
end

View File

@@ -10,7 +10,7 @@ class RelatedTagCalculatorTest < ActiveSupport::TestCase
tag = Tag.find_by_name("aaa")
calculator = RelatedTagCalculator.new
assert_equal({"bbb" => 3, "ccc" => 2, "ddd" => 1}, calculator.calculate_from_sample("aaa"))
assert_equal({"bbb" => 3, "ccc" => 2, "ddd" => 1}, calculator.calculate_from_sample("aaa", 10))
end
should "calculate related tags for a tag" do
@@ -21,9 +21,9 @@ class RelatedTagCalculatorTest < ActiveSupport::TestCase
tag = Tag.find_by_name("aaa")
calculator = RelatedTagCalculator.new
assert_equal({"ccc" => 2}, calculator.calculate_from_sample("aaa", Tag.categories.artist))
assert_equal({"ccc" => 2}, calculator.calculate_from_sample("aaa", 10, Tag.categories.artist))
calculator = RelatedTagCalculator.new
assert_equal({"ddd" => 1}, calculator.calculate_from_sample("aaa", Tag.categories.copyright))
assert_equal({"ddd" => 1}, calculator.calculate_from_sample("aaa", 10, Tag.categories.copyright))
end
should "convert a hash into string format" do
@@ -34,7 +34,7 @@ class RelatedTagCalculatorTest < ActiveSupport::TestCase
tag = Tag.find_by_name("aaa")
calculator = RelatedTagCalculator.new
counts = calculator.calculate_from_sample("aaa")
counts = calculator.calculate_from_sample("aaa", 10)
assert_equal("bbb 3 ccc 2 ddd 1", calculator.convert_hash_to_string(counts))
end
end

View File

@@ -21,6 +21,7 @@ class WikiPageTest < ActiveSupport::TestCase
should "create versions" do
wp = nil
user = Factory.create(:user)
reverter = Factory.create(:user)
assert_difference("WikiPageVersion.count") do
wp = Factory.create(:wiki_page, :title => "xxx")
@@ -34,7 +35,7 @@ class WikiPageTest < ActiveSupport::TestCase
end
version = WikiPageVersion.first
wp.revert_to!(version)
wp.revert_to!(version, reverter.id, "127.0.0.1")
assert_equal("xxx", wp.title)
end