Permalink
Browse files

Make lifecycle_tests pass

  • Loading branch information...
1 parent 627ffcb commit f52d1494c6135641403e90e022cfcf18f6f250ae Rafael Mendonça França committed Nov 27, 2012
Showing with 102 additions and 23 deletions.
  1. +4 −0 test/fixtures/developers.yml
  2. +2 −0 test/fixtures/minimalistics.yml
  3. +41 −0 test/fixtures/topics.yml
  4. +44 −16 test/helper.rb
  5. +2 −7 test/lifecycle_test.rb
  6. +9 −0 test/models/topic.rb
@@ -0,0 +1,4 @@
+david:
+ id: 1
+ name: David
+ salary: 80000
@@ -0,0 +1,2 @@
+first:
+ id: 1
View
@@ -0,0 +1,41 @@
+first:
+ id: 1
+ title: The First Topic
+ author_name: David
+ author_email_address: david@loudthinking.com
+ written_on: 2003-07-16t15:28:11.2233+01:00
+ last_read: 2004-04-15
+ bonus_time: 2005-01-30t15:28:00.00+01:00
+ content: Have a nice day
+ approved: false
+ replies_count: 1
+
+second:
+ id: 2
+ title: The Second Topic of the day
+ author_name: Mary
+ written_on: 2004-07-15t15:28:00.0099+01:00
+ content: Have a nice day
+ approved: true
+ replies_count: 0
+ parent_id: 1
+ type: Reply
+
+third:
+ id: 3
+ title: The Third Topic of the day
+ author_name: Carl
+ written_on: 2012-08-12t20:24:22.129346+00:00
+ content: I'm a troll
+ approved: true
+ replies_count: 1
+
+fourth:
+ id: 4
+ title: The Fourth Topic of the day
+ author_name: Carl
+ written_on: 2006-07-15t15:28:00.0099+01:00
+ content: Why not?
+ approved: true
+ type: Reply
+ parent_id: 3
View
@@ -1,27 +1,52 @@
-require 'bundler/setup'
-require 'active_record-observers'
-require 'minitest/spec'
require 'minitest/autorun'
require 'active_record'
-ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
+require 'rails/observers/activerecord/active_record'
+
+FIXTURES_ROOT = File.expand_path(File.dirname(__FILE__)) + "/fixtures"
+
+class ActiveSupport::TestCase
+ include ActiveRecord::TestFixtures
+
+ self.fixture_path = FIXTURES_ROOT
+ self.use_instantiated_fixtures = false
+ self.use_transactional_fixtures = true
+end
+
+ActiveRecord::Base.configurations = { "test" => { adapter: 'sqlite3', database: ':memory:' } }
+ActiveRecord::Base.establish_connection(:test)
ActiveRecord::Schema.verbose = false
ActiveRecord::Schema.define do
- create_table :posts do |t|
- t.string :title
- t.string :category
+ create_table :topics do |t|
+ t.string :title
+ t.string :author_name
+ t.string :author_email_address
+ t.datetime :written_on
+ t.time :bonus_time
+ t.date :last_read
+ t.text :content
+ t.text :important
+ t.boolean :approved, :default => true
+ t.integer :replies_count, :default => 0
+ t.integer :parent_id
+ t.string :parent_title
+ t.string :type
+ t.string :group
+ t.timestamps
end
create_table :comments do |t|
t.string :title
- t.references :post
end
-end
-class Post < ActiveRecord::Base
- attr_accessible :id, :title, :category
- has_many :comments
+ create_table :minimalistics do |t|
+ end
+
+ create_table :developers do |t|
+ t.string :name
+ t.integer :salary
+ end
end
class Comment < ActiveRecord::Base
@@ -30,9 +55,12 @@ def self.lol
end
end
-require 'active_support/testing/deprecation'
-ActiveSupport::Deprecation.debug = true
+class Developer < ActiveRecord::Base
+end
+
+class Minimalistic < ActiveRecord::Base
+end
-class MiniTest::Spec
- include ActiveSupport::Testing::Deprecation
+ActiveSupport::Deprecation.silence do
+ require 'active_record/test_case'
end
View
@@ -1,9 +1,6 @@
-require 'cases/helper'
+require 'helper'
+
require 'models/topic'
-require 'models/developer'
-require 'models/reply'
-require 'models/minimalistic'
-require 'models/comment'
class SpecialDeveloper < Developer; end
@@ -31,7 +28,6 @@ def after_save(developer)
end
end
include Implementation
-
end
class TopicaAuditor < ActiveRecord::Observer
@@ -252,5 +248,4 @@ def test_observer_is_called_once
assert_equal [developer, special_developer], observer.calls
end
-
end
View
@@ -0,0 +1,9 @@
+class Topic < ActiveRecord::Base
+ has_many :replies, dependent: :destroy, foreign_key: "parent_id"
+end
+
+class Reply < Topic
+ scope :base, -> { scoped }
+
+ belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true
+end

0 comments on commit f52d149

Please sign in to comment.