test/test_helper.rb in destroyed_at-0.2.0 vs test/test_helper.rb in destroyed_at-0.3.0

- old
+ new

@@ -25,81 +25,78 @@ :database => ':memory:' ) DatabaseCleaner.strategy = :truncation -ActiveRecord::Base.connection.execute(%{CREATE TABLE users (id INTEGER PRIMARY KEY, destroyed_at DATETIME, type STRING);}) -ActiveRecord::Base.connection.execute(%{CREATE TABLE profiles (id INTEGER PRIMARY KEY, destroyed_at DATETIME, user_id INTEGER);}) -ActiveRecord::Base.connection.execute(%{CREATE TABLE cars (id INTEGER PRIMARY KEY, user_id INTEGER);}) -ActiveRecord::Base.connection.execute(%{CREATE TABLE dinners (id INTEGER PRIMARY KEY, destroyed_at DATETIME, user_id INTEGER);}) -ActiveRecord::Base.connection.execute(%{CREATE TABLE shows (id INTEGER PRIMARY KEY, destroyed_at DATETIME, user_id INTEGER);}) -ActiveRecord::Base.connection.execute(%{CREATE TABLE fleets (id INTEGER PRIMARY KEY, destroyed_at DATETIME, user_id INTEGER, car_id INTEGER);}) +ActiveRecord::Base.connection.execute(%{CREATE TABLE authors (id INTEGER PRIMARY KEY);}) +ActiveRecord::Base.connection.execute(%{CREATE TABLE categories (id INTEGER PRIMARY KEY);}) +ActiveRecord::Base.connection.execute(%{CREATE TABLE categorizations (id INTEGER PRIMARY KEY, category_id INTEGER, post_id INTEGER);}) +ActiveRecord::Base.connection.execute(%{CREATE TABLE comments (id INTEGER PRIMARY KEY, commenter_id INTEGER, post_id INTEGER, destroyed_at DATETIME);}) +ActiveRecord::Base.connection.execute(%{CREATE TABLE commenters (id INTEGER PRIMARY KEY, destroyed_at DATETIME);}) +ActiveRecord::Base.connection.execute(%{CREATE TABLE images (id INTEGER PRIMARY KEY, post_id INTEGER);}) +ActiveRecord::Base.connection.execute(%{CREATE TABLE posts (id INTEGER PRIMARY KEY, author_id INTEGER, destroyed_at DATETIME);}) -class User < ActiveRecord::Base - include DestroyedAt - has_one :profile, :dependent => :destroy - has_one :car, :dependent => :destroy - has_many :dinners, :dependent => :destroy - has_one :show - has_many :fleets - has_many :cars, :through => :fleets, :dependent => :destroy - before_update :increment_callback_counter - validate :increment_validation_counter +class Author < ActiveRecord::Base + has_many :posts +end - attr_accessor :before_update_count, :validation_count +class Category < ActiveRecord::Base + has_many :categorizations + has_many :posts, through: :categorizations +end - private +class Categorization < ActiveRecord::Base + belongs_to :category + belongs_to :post +end - def increment_callback_counter - self.before_update_count ||= 0 - self.before_update_count = self.before_update_count + 1 - end +class Comment < ActiveRecord::Base + include DestroyedAt + belongs_to :post + belongs_to :commenter +end - def increment_validation_counter - self.validation_count ||= 0 - self.validation_count = self.validation_count + 1 - end +class Commenter < ActiveRecord::Base + include DestroyedAt + has_many :comments, dependent: :destroy + has_many :posts, through: :comments end -class Person < User - before_destroy :set_before_flag - after_destroy :set_after_flag +class Post < ActiveRecord::Base + include DestroyedAt - before_restore :set_before_flag - after_restore :set_after_flag + belongs_to :author + has_many :categories, through: :categorizations + has_many :categorizations, dependent: :destroy + has_many :comments, dependent: :destroy + has_many :commenters, through: :comments - attr_accessor :before_flag, :after_flag + before_destroy :increment_destroy_callback_counter + before_restore :increment_restore_callback_counter + before_update :increment_update_callback_counter - def set_before_flag - self.before_flag = true - end + validate :increment_validation_counter - def set_after_flag - self.after_flag = true - end -end + attr_accessor :destroy_callback_count, :restore_callback_count, :update_callback_count, :validation_count -class Profile < ActiveRecord::Base - include DestroyedAt - belongs_to :user -end + private -class Car < ActiveRecord::Base - belongs_to :user - has_many :fleets -end + def increment_restore_callback_counter + self.restore_callback_count ||= 0 + self.restore_callback_count = self.restore_callback_count + 1 + end -class Dinner < ActiveRecord::Base - include DestroyedAt - belongs_to :user -end + def increment_destroy_callback_counter + self.destroy_callback_count ||= 0 + self.destroy_callback_count = self.destroy_callback_count + 1 + end -class Show < ActiveRecord::Base - include DestroyedAt - belongs_to :user, :dependent => :destroy -end + def increment_update_callback_counter + self.update_callback_count ||= 0 + self.update_callback_count = self.update_callback_count + 1 + end -class Fleet < ActiveRecord::Base - include DestroyedAt - belongs_to :user - belongs_to :car + def increment_validation_counter + self.validation_count ||= 0 + self.validation_count = self.validation_count + 1 + end end