Top Level Namespace

Defined Under Namespace

Modules: ADSL, Kernel Classes: ADSLRailsTestApplication, Array, FalseClass, Fixnum, Module, NilClass, Object, Sexp, String, Symbol, Time, TrueClass

Instance Method Summary collapse

Instance Method Details

#initialize_test_contextObject



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
# File 'lib/adsl/extract/rails/rails_test_helper.rb', line 11

def initialize_test_context
  Object.lookup_or_create_class('::Asd', ActiveRecord::Base).class_exec do
    has_many :blahs, :class_name => 'Mod::Blah'
    has_many :kmes, :through => :blahs, :source => :kme12, :dependent => :destroy
  end
  
  Object.lookup_or_create_class('::Kme', Asd).class_exec do
    belongs_to :blah, :class_name => 'Mod::Blah', :dependent => :delete
  end
  
  Object.lookup_or_create_class('::Mod::Blah', ActiveRecord::Base).class_exec do
    belongs_to :asd
    has_one :kme12, :class_name => 'Kme', :dependent => :delete
  end

  Object.lookup_or_create_class('::ApplicationController', ActionController::Base).class_exec do
    def respond_to
      # allow for empty render statements, for testing purposes only
      if block_given?
        super
      else
        render :nothing => true
      end
    end

    def render(options = {}, extra_options = nil, &block)
      options ||= {}
      options[:nothing] = true
      super
    end

    # no templates exist and we do not care
    rescue_from ActionView::MissingTemplate do; end
  end

  Object.lookup_or_create_class('::AsdsController', ApplicationController).class_exec do
    def index;   respond_to; end
    def show;    respond_to; end
    def new;     respond_to; end

    def create
      a = Asd.new
      a.save!
      respond_to
    end

    def edit;    respond_to; end
    def update;  respond_to; end
    def destroy; respond_to; end
    def nothing; respond_to; end

    before_filter :before,  :only => :before_filter_action
    before_filter :before2, :only => :before_filter_action
    after_filter  :after,   :only => :after_filter_action

    before_filter :before_nothing, :only => :nothing
    after_filter  :after_nothing,  :only => :nothing

    def before_filter_action; respond_to; end
    def after_filter_action;  respond_to; end
    
    def before; end
    def before2; end
    def after; end

    def before_nothing; end
    def after_nothing; end
  end
end