fixed unit tests, tweaked attr_accessible rules
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
class Artist < ActiveRecord::Base
|
class Artist < ActiveRecord::Base
|
||||||
attr_accessor :updater_id, :updater_ip_addr
|
attr_accessor :updater_id, :updater_ip_addr
|
||||||
|
before_create :initialize_creator
|
||||||
before_save :normalize_name
|
before_save :normalize_name
|
||||||
after_save :create_version
|
after_save :create_version
|
||||||
after_save :commit_url_string
|
after_save :commit_url_string
|
||||||
@@ -11,7 +12,7 @@ class Artist < ActiveRecord::Base
|
|||||||
has_one :wiki_page, :foreign_key => "title", :primary_key => "name"
|
has_one :wiki_page, :foreign_key => "title", :primary_key => "name"
|
||||||
has_one :tag_alias, :foreign_key => "antecedent_name", :primary_key => "name"
|
has_one :tag_alias, :foreign_key => "antecedent_name", :primary_key => "name"
|
||||||
accepts_nested_attributes_for :wiki_page
|
accepts_nested_attributes_for :wiki_page
|
||||||
attr_accessible :name, :url_string, :other_names, :group_name, :wiki_page_attributes
|
attr_accessible :name, :url_string, :other_names, :group_name, :wiki_page_attributes, :updater_id, :updater_ip_addr
|
||||||
|
|
||||||
module UrlMethods
|
module UrlMethods
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
@@ -152,5 +153,11 @@ class Artist < ActiveRecord::Base
|
|||||||
include UpdaterMethods
|
include UpdaterMethods
|
||||||
extend SearchMethods
|
extend SearchMethods
|
||||||
include VersionMethods
|
include VersionMethods
|
||||||
|
|
||||||
|
def initialize_creator
|
||||||
|
if creator.nil?
|
||||||
|
self.creator_id = updater_id
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,15 @@ class Pool < ActiveRecord::Base
|
|||||||
attr_accessible :name, :description, :post_ids, :is_public, :is_active
|
attr_accessible :name, :description, :post_ids, :is_public, :is_active
|
||||||
|
|
||||||
def self.create_anonymous(creator, creator_ip_addr)
|
def self.create_anonymous(creator, creator_ip_addr)
|
||||||
pool = Pool.create(:name => "TEMP:#{Time.now.to_f}.#{rand(1_000_000)}", :creator => creator, :updater_id => creator.id, :updater_ip_addr => creator_ip_addr)
|
Pool.new do |pool|
|
||||||
pool.update_attribute(:name, "anonymous:#{pool.id}")
|
pool.name = "TEMP:#{Time.now.to_f}.#{rand(1_000_000)}"
|
||||||
pool
|
pool.creator = creator
|
||||||
|
pool.updater_id = creator.id
|
||||||
|
pool.updater_ip_addr = creator_ip_addr
|
||||||
|
pool.save
|
||||||
|
pool.name = "anonymous:#{pool.id}"
|
||||||
|
pool.save
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def revert_to!(version)
|
def revert_to!(version)
|
||||||
@@ -63,7 +69,7 @@ class Pool < ActiveRecord::Base
|
|||||||
|
|
||||||
def create_version
|
def create_version
|
||||||
last_version = versions.last
|
last_version = versions.last
|
||||||
|
|
||||||
if last_version && updater_ip_addr == last_version.updater_ip_addr && updater_id == last_version.updater_id
|
if last_version && updater_ip_addr == last_version.updater_ip_addr && updater_id == last_version.updater_id
|
||||||
last_version.update_attribute(:post_ids, post_ids)
|
last_version.update_attribute(:post_ids, post_ids)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class Post < ActiveRecord::Base
|
|||||||
has_one :upload, :dependent => :destroy
|
has_one :upload, :dependent => :destroy
|
||||||
has_many :versions, :class_name => "PostVersion", :dependent => :destroy
|
has_many :versions, :class_name => "PostVersion", :dependent => :destroy
|
||||||
has_many :votes, :class_name => "PostVote", :dependent => :destroy
|
has_many :votes, :class_name => "PostVote", :dependent => :destroy
|
||||||
attr_accessible :source, :rating, :tag_string, :old_tag_string
|
attr_accessible :source, :rating, :tag_string, :old_tag_string, :updater_id, :updater_ip_addr
|
||||||
|
|
||||||
module FileMethods
|
module FileMethods
|
||||||
def delete_files
|
def delete_files
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
class WikiPage < ActiveRecord::Base
|
class WikiPage < ActiveRecord::Base
|
||||||
attr_accessor :updater_id, :updater_ip_addr
|
attr_accessor :updater_id, :updater_ip_addr
|
||||||
before_save :normalize_title
|
before_save :normalize_title
|
||||||
|
before_create :initialize_creator
|
||||||
after_save :create_version
|
after_save :create_version
|
||||||
belongs_to :creator, :class_name => "User"
|
belongs_to :creator, :class_name => "User"
|
||||||
belongs_to :updater, :class_name => "User"
|
belongs_to :updater, :class_name => "User"
|
||||||
validates_uniqueness_of :title, :case_sensitive => false
|
validates_uniqueness_of :title, :case_sensitive => false
|
||||||
validates_presence_of :body, :updater_id, :updater_ip_addr
|
validates_presence_of :body, :updater_id, :updater_ip_addr
|
||||||
attr_protected :text_search_index, :is_locked, :version
|
attr_accessible :title, :body, :updater_id, :updater_ip_addr
|
||||||
scope :titled, lambda {|title| where(["title = ?", title.downcase.tr(" ", "_")])}
|
scope :titled, lambda {|title| where(["title = ?", title.downcase.tr(" ", "_")])}
|
||||||
has_one :tag, :foreign_key => "name", :primary_key => "title"
|
has_one :tag, :foreign_key => "name", :primary_key => "title"
|
||||||
has_one :artist, :foreign_key => "name", :primary_key => "title"
|
has_one :artist, :foreign_key => "name", :primary_key => "title"
|
||||||
@@ -58,4 +59,10 @@ class WikiPage < ActiveRecord::Base
|
|||||||
:is_locked => is_locked
|
:is_locked => is_locked
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def initialize_creator
|
||||||
|
if creator.nil?
|
||||||
|
self.creator_id = updater_id
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -27,11 +27,10 @@ class ArtistTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
should "make sure old urls are deleted" do
|
should "make sure old urls are deleted" do
|
||||||
artist = Factory.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg")
|
artist = Factory.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg")
|
||||||
artist.update_attributes(
|
artist.updater_id = artist.creator_id
|
||||||
:updater_id => artist.creator_id,
|
artist.updater_ip_addr = "127.0.0.1"
|
||||||
:updater_ip_addr => "127.0.0.1",
|
artist.url_string = "http://not.rembrandt.com/test.jpg"
|
||||||
:url_string => "http://not.rembrandt.com/test.jpg"
|
artist.save
|
||||||
)
|
|
||||||
artist.reload
|
artist.reload
|
||||||
assert_equal(["http://not.rembrandt.com/test.jpg"], artist.artist_urls.map(&:to_s).sort)
|
assert_equal(["http://not.rembrandt.com/test.jpg"], artist.artist_urls.map(&:to_s).sort)
|
||||||
end
|
end
|
||||||
@@ -80,11 +79,11 @@ class ArtistTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
should "have an associated wiki" do
|
should "have an associated wiki" do
|
||||||
user = Factory.create(:user)
|
user = Factory.create(:user)
|
||||||
artist = Factory.create(:artist, :name => "max", :wiki_page_attributes => {:body => "this is max", :creator_id => user.id, :updater_id => user.id, :updater_ip_addr => "127.0.0.1"})
|
artist = Factory.create(:artist, :name => "max", :wiki_page_attributes => {:body => "this is max", :updater_id => user.id, :updater_ip_addr => "127.0.0.1"})
|
||||||
assert_not_nil(artist.wiki_page)
|
assert_not_nil(artist.wiki_page)
|
||||||
assert_equal("this is max", artist.wiki_page.body)
|
assert_equal("this is max", artist.wiki_page.body)
|
||||||
|
|
||||||
artist.update_attributes(:wiki_page_attributes => {:id => artist.wiki_page.id, :body => "this is hoge mark ii", :updater_id => user.id, :updater_ip_addr => "127.0.0.1"})
|
artist.update_attributes(:wiki_page_attributes => {:id => artist.wiki_page.id, :body => "this is hoge mark ii", :creator_id => user.id, :updater_id => user.id, :updater_ip_addr => "127.0.0.1"})
|
||||||
assert_equal("this is hoge mark ii", artist.wiki_page(true).body)
|
assert_equal("this is hoge mark ii", artist.wiki_page(true).body)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -96,11 +95,10 @@ class ArtistTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
assert_difference("ArtistVersion.count") do
|
assert_difference("ArtistVersion.count") do
|
||||||
artist.update_attributes(
|
artist.updater_id = user.id
|
||||||
:updater_id => user.id,
|
artist.updater_ip_addr = "127.0.0.1"
|
||||||
:updater_ip_addr => "127.0.0.1",
|
artist.other_names = "xxx"
|
||||||
:other_names => "xxx"
|
artist.save
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
first_version = ArtistVersion.first
|
first_version = ArtistVersion.first
|
||||||
|
|||||||
@@ -2,13 +2,23 @@ require File.dirname(__FILE__) + '/../test_helper'
|
|||||||
|
|
||||||
class PoolTest < ActiveSupport::TestCase
|
class PoolTest < ActiveSupport::TestCase
|
||||||
context "A pool" do
|
context "A pool" do
|
||||||
|
setup do
|
||||||
|
MEMCACHE.flush_all
|
||||||
|
end
|
||||||
|
|
||||||
should "create versions for each distinct user" do
|
should "create versions for each distinct user" do
|
||||||
pool = Factory.create(:pool)
|
pool = Factory.create(:pool)
|
||||||
user = Factory.create(:user)
|
user = Factory.create(:user)
|
||||||
assert_equal(1, pool.versions(true).size)
|
assert_equal(1, pool.versions(true).size)
|
||||||
pool.update_attributes(:post_ids => "1", :updater_id => user.id, :updater_ip_addr => "128.0.0.1")
|
pool.post_ids = "1"
|
||||||
|
pool.updater_id = user.id
|
||||||
|
pool.updater_ip_addr = "128.0.0.1"
|
||||||
|
pool.save
|
||||||
assert_equal(2, pool.versions(true).size)
|
assert_equal(2, pool.versions(true).size)
|
||||||
pool.update_attributes(:post_ids => "1 2", :updater_id => user.id, :updater_ip_addr => "128.0.0.1")
|
pool.post_ids = "1 2"
|
||||||
|
pool.updater_id = user.id
|
||||||
|
pool.updater_ip_addr = "128.0.0.1"
|
||||||
|
pool.save
|
||||||
assert_equal(2, pool.versions(true).size)
|
assert_equal(2, pool.versions(true).size)
|
||||||
pool.revert_to!(PoolVersion.first)
|
pool.revert_to!(PoolVersion.first)
|
||||||
assert_equal("", pool.post_ids)
|
assert_equal("", pool.post_ids)
|
||||||
@@ -59,7 +69,6 @@ class PoolTest < ActiveSupport::TestCase
|
|||||||
user = Factory.create(:user)
|
user = Factory.create(:user)
|
||||||
pool = Pool.create_anonymous(user, "127.0.0.1")
|
pool = Pool.create_anonymous(user, "127.0.0.1")
|
||||||
assert_match(/^anonymous:\d+$/, pool.name)
|
assert_match(/^anonymous:\d+$/, pool.name)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -27,7 +27,10 @@ class WikiPageTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
assert_difference("WikiPageVersion.count") do
|
assert_difference("WikiPageVersion.count") do
|
||||||
wp.update_attributes(:title => "yyy", :updater_id => user.id, :updater_ip_addr => "127.0.0.1")
|
wp.title = "yyy"
|
||||||
|
wp.updater_id = user.id
|
||||||
|
wp.updater_ip_addr = "127.0.0.1"
|
||||||
|
wp.save
|
||||||
end
|
end
|
||||||
|
|
||||||
version = WikiPageVersion.first
|
version = WikiPageVersion.first
|
||||||
|
|||||||
Reference in New Issue
Block a user