Set default formats in the database now that rails handles enums
Because rails now reads the defaults from the database correctly it no longer works to set them conditionally in after_initialise as they have already been set.
This commit is contained in:
parent
a9a9ae2cbb
commit
8fa9763281
8 changed files with 24 additions and 42 deletions
|
@ -5,7 +5,6 @@ class DiaryComment < ActiveRecord::Base
|
|||
validates_presence_of :body
|
||||
validates_associated :diary_entry
|
||||
|
||||
after_initialize :set_defaults
|
||||
after_save :spam_check
|
||||
|
||||
def body
|
||||
|
@ -23,10 +22,6 @@ class DiaryComment < ActiveRecord::Base
|
|||
|
||||
private
|
||||
|
||||
def set_defaults
|
||||
self.body_format = "markdown" unless self.attribute_present?(:body_format)
|
||||
end
|
||||
|
||||
def spam_check
|
||||
user.spam_check
|
||||
end
|
||||
|
|
|
@ -16,7 +16,6 @@ class DiaryEntry < ActiveRecord::Base
|
|||
:greater_than_or_equal_to => -180, :less_than_or_equal_to => 180
|
||||
validates_associated :language
|
||||
|
||||
after_initialize :set_defaults
|
||||
after_save :spam_check
|
||||
|
||||
def body
|
||||
|
@ -25,10 +24,6 @@ class DiaryEntry < ActiveRecord::Base
|
|||
|
||||
private
|
||||
|
||||
def set_defaults
|
||||
self.body_format = "markdown" unless self.attribute_present?(:body_format)
|
||||
end
|
||||
|
||||
def spam_check
|
||||
user.spam_check
|
||||
end
|
||||
|
|
|
@ -9,8 +9,6 @@ class Message < ActiveRecord::Base
|
|||
validates_inclusion_of :message_read, :in => [ true, false ]
|
||||
validates_as_utf8 :title
|
||||
|
||||
after_initialize :set_defaults
|
||||
|
||||
def self.from_mail(mail, from, to)
|
||||
if mail.multipart?
|
||||
if mail.text_part
|
||||
|
@ -47,10 +45,4 @@ class Message < ActiveRecord::Base
|
|||
md5 << body
|
||||
md5.hexdigest
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_defaults
|
||||
self.body_format = "markdown" unless self.attribute_present?(:body_format)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,19 +14,9 @@ class Redaction < ActiveRecord::Base
|
|||
has_many :old_ways
|
||||
has_many :old_relations
|
||||
|
||||
after_initialize :set_defaults
|
||||
|
||||
# this method overrides the AR default to provide the rich
|
||||
# text object for the description field.
|
||||
def description
|
||||
RichText.new(read_attribute(:description_format), read_attribute(:description))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# set the default format to be markdown, in the absence of
|
||||
# any other setting.
|
||||
def set_defaults
|
||||
self.description_format = "markdown" unless self.attribute_present?(:description_format)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -243,7 +243,6 @@ private
|
|||
|
||||
def set_defaults
|
||||
self.creation_time = Time.now.getutc unless self.attribute_present?(:creation_time)
|
||||
self.description_format = "markdown" unless self.attribute_present?(:description_format)
|
||||
end
|
||||
|
||||
def encrypt_password
|
||||
|
|
|
@ -4,8 +4,6 @@ class UserBlock < ActiveRecord::Base
|
|||
belongs_to :user, :class_name => "User", :foreign_key => :user_id
|
||||
belongs_to :creator, :class_name => "User", :foreign_key => :creator_id
|
||||
belongs_to :revoker, :class_name => "User", :foreign_key => :revoker_id
|
||||
|
||||
after_initialize :set_defaults
|
||||
|
||||
PERIODS = USER_BLOCK_PERIODS
|
||||
|
||||
|
@ -41,12 +39,6 @@ class UserBlock < ActiveRecord::Base
|
|||
|
||||
private
|
||||
|
||||
##
|
||||
# set default values for new records.
|
||||
def set_defaults
|
||||
self.reason_format = "markdown" unless self.attribute_present?(:reason_format)
|
||||
end
|
||||
|
||||
##
|
||||
# validate that only moderators are allowed to change the
|
||||
# block. this should be caught and dealt with in the controller,
|
||||
|
|
17
db/migrate/20150110152606_change_default_formats.rb
Normal file
17
db/migrate/20150110152606_change_default_formats.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
class ChangeDefaultFormats < ActiveRecord::Migration
|
||||
def up
|
||||
change_column_default :diary_entries, :body_format, "markdown"
|
||||
change_column_default :diary_comments, :body_format, "markdown"
|
||||
change_column_default :messages, :body_format, "markdown"
|
||||
change_column_default :users, :description_format, "markdown"
|
||||
change_column_default :user_blocks, :reason_format, "markdown"
|
||||
end
|
||||
|
||||
def down
|
||||
change_column_default :diary_entries, :body_format, "html"
|
||||
change_column_default :diary_comments, :body_format, "html"
|
||||
change_column_default :messages, :body_format, "html"
|
||||
change_column_default :users, :description_format, "html"
|
||||
change_column_default :user_blocks, :reason_format, "html"
|
||||
end
|
||||
end
|
|
@ -485,7 +485,7 @@ CREATE TABLE diary_comments (
|
|||
created_at timestamp without time zone NOT NULL,
|
||||
updated_at timestamp without time zone NOT NULL,
|
||||
visible boolean DEFAULT true NOT NULL,
|
||||
body_format format_enum DEFAULT 'html'::format_enum NOT NULL
|
||||
body_format format_enum DEFAULT 'markdown'::format_enum NOT NULL
|
||||
);
|
||||
|
||||
|
||||
|
@ -523,7 +523,7 @@ CREATE TABLE diary_entries (
|
|||
longitude double precision,
|
||||
language_code character varying DEFAULT 'en'::character varying NOT NULL,
|
||||
visible boolean DEFAULT true NOT NULL,
|
||||
body_format format_enum DEFAULT 'html'::format_enum NOT NULL
|
||||
body_format format_enum DEFAULT 'markdown'::format_enum NOT NULL
|
||||
);
|
||||
|
||||
|
||||
|
@ -684,7 +684,7 @@ CREATE TABLE messages (
|
|||
to_user_id bigint NOT NULL,
|
||||
to_user_visible boolean DEFAULT true NOT NULL,
|
||||
from_user_visible boolean DEFAULT true NOT NULL,
|
||||
body_format format_enum DEFAULT 'html'::format_enum NOT NULL
|
||||
body_format format_enum DEFAULT 'markdown'::format_enum NOT NULL
|
||||
);
|
||||
|
||||
|
||||
|
@ -983,7 +983,7 @@ CREATE TABLE user_blocks (
|
|||
revoker_id bigint,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone,
|
||||
reason_format format_enum DEFAULT 'html'::format_enum NOT NULL
|
||||
reason_format format_enum DEFAULT 'markdown'::format_enum NOT NULL
|
||||
);
|
||||
|
||||
|
||||
|
@ -1110,7 +1110,7 @@ CREATE TABLE users (
|
|||
openid_url character varying,
|
||||
preferred_editor character varying,
|
||||
terms_seen boolean DEFAULT false NOT NULL,
|
||||
description_format format_enum DEFAULT 'html'::format_enum NOT NULL,
|
||||
description_format format_enum DEFAULT 'markdown'::format_enum NOT NULL,
|
||||
image_fingerprint character varying,
|
||||
changesets_count integer DEFAULT 0 NOT NULL,
|
||||
traces_count integer DEFAULT 0 NOT NULL,
|
||||
|
@ -2541,6 +2541,8 @@ INSERT INTO schema_migrations (version) VALUES ('20140507110937');
|
|||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20140519141742');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20150110152606');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('21');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('22');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue