jnewland / resource_this

Not scaffolding. Resourcing. Creates extremely customizable resource controllers with one line of code.

This URL has Read+Write access

resource_this / test / test_helper.rb
100644 81 lines (66 sloc) 1.82 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
$LOAD_PATH.unshift 'lib/'
 
require 'rubygems'
require 'multi_rails_init'
require 'action_controller/test_process'
require 'test/unit'
require 'resource_this'
 
begin
  require 'redgreen'
rescue LoadError
  nil
end
 
RAILS_ROOT = '.' unless defined? RAILS_ROOT
RAILS_ENV = 'test' unless defined? RAILS_ENV
 
ActiveRecord::Base.logger = Logger.new(STDOUT) if ENV['DEBUG']
ActionController::Base.logger = Logger.new(STDOUT) if ENV['DEBUG']
 
ActionController::Base.send :include, ResourceThis
 
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
 
ActiveRecord::Schema.define(:version => 1) do
  create_table :posts do |t|
    t.column :title, :string
    t.column :body, :text
    t.column :created_at, :datetime
    t.column :updated_at, :datetime
  end
  create_table :comments do |t|
    t.column :body, :text
    t.column :post_id, :integer
    t.column :created_at, :datetime
    t.column :updated_at, :datetime
  end
  create_table :widgets do |t|
    t.column :title, :string
    t.column :body, :text
    t.column :created_at, :datetime
    t.column :updated_at, :datetime
  end
end
 
class Post < ActiveRecord::Base
  has_many :comments
  validates_length_of :title, :within => 2..100
  def validate
  end
end
 
class Comment < ActiveRecord::Base
  belongs_to :post
  def validate
  end
  validates_associated :post
end
 
class Widget < ActiveRecord::Base
  def validate
  end
end
 
class PostsController < ActionController::Base
  resource_this
end
 
class WidgetsController < ActionController::Base
  resource_this
end
 
module Admin; end
 
class Admin::PostsController < ActionController::Base
  resource_this :path_prefix => "admin_"
end
 
class CommentsController < ActionController::Base
  resource_this :nested => [:posts]
end