fixed unit tests, tweaked attr_accessible rules

This commit is contained in:
albert
2010-02-19 17:54:44 -05:00
parent 703eb6a1b6
commit 2f907c67b5
7 changed files with 53 additions and 23 deletions

View File

@@ -1,5 +1,6 @@
class Artist < ActiveRecord::Base
attr_accessor :updater_id, :updater_ip_addr
before_create :initialize_creator
before_save :normalize_name
after_save :create_version
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 :tag_alias, :foreign_key => "antecedent_name", :primary_key => "name"
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 ClassMethods
@@ -152,5 +153,11 @@ class Artist < ActiveRecord::Base
include UpdaterMethods
extend SearchMethods
include VersionMethods
def initialize_creator
if creator.nil?
self.creator_id = updater_id
end
end
end

View File

@@ -10,9 +10,15 @@ class Pool < ActiveRecord::Base
attr_accessible :name, :description, :post_ids, :is_public, :is_active
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.update_attribute(:name, "anonymous:#{pool.id}")
pool
Pool.new do |pool|
pool.name = "TEMP:#{Time.now.to_f}.#{rand(1_000_000)}"
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
def revert_to!(version)
@@ -63,7 +69,7 @@ class Pool < ActiveRecord::Base
def create_version
last_version = versions.last
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)
else

View File

@@ -13,7 +13,7 @@ class Post < ActiveRecord::Base
has_one :upload, :dependent => :destroy
has_many :versions, :class_name => "PostVersion", :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
def delete_files

View File

@@ -1,12 +1,13 @@
class WikiPage < ActiveRecord::Base
attr_accessor :updater_id, :updater_ip_addr
before_save :normalize_title
before_create :initialize_creator
after_save :create_version
belongs_to :creator, :class_name => "User"
belongs_to :updater, :class_name => "User"
validates_uniqueness_of :title, :case_sensitive => false
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(" ", "_")])}
has_one :tag, :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
)
end
def initialize_creator
if creator.nil?
self.creator_id = updater_id
end
end
end