Module: RailsArts

Includes:
ActionView::Helpers::JavaScriptHelper, ActionView::Helpers::PrototypeHelper, ActionView::Helpers::ScriptaculousHelper, ActionView::Helpers::TagHelper, ActionView::Helpers::UrlHelper
Defined in:
lib/rails-arts/version.rb,
lib/rails-arts/assertions.rb

Constant Summary collapse

VERSION =
"1.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#template_formatObject

needed for JavaScriptGenerator to work - rails 2.3?



137
138
139
# File 'lib/rails-arts/assertions.rb', line 137

def template_format
  @template_format
end

Instance Method Details

#assert_no_rjs(action, *args, &block) ⇒ Object



16
17
18
# File 'lib/rails-arts/assertions.rb', line 16

def assert_no_rjs(action, *args, &block)
  assert_raises(Test::Unit::AssertionFailedError) { assert_rjs(action, *args, &block) }
end

#assert_rjs(action, *args, &block) ⇒ Object



9
10
11
12
13
14
# File 'lib/rails-arts/assertions.rb', line 9

def assert_rjs(action, *args, &block)
  respond_to?("assert_rjs_#{action}") ?
    send("assert_rjs_#{action}", *args) :
    assert_response_contains(create_generator.send(action, *args, &block), 
       generic_error(action, args))
end

#assert_rjs_insert_html(*args) ⇒ Object



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
# File 'lib/rails-arts/assertions.rb', line 20

def assert_rjs_insert_html(*args)
  position = args.shift
  item_id = args.shift
  
  content = extract_matchable_content(args)
  
  unless content.blank?
    case content
      when Regexp
        assert_match Regexp.new("Element.insert\\(\"#{item_id}\",\\ \\{\\ #{position.to_s}.*#{content.source}.*"),
                     @response.body
      when String
        assert_response_contains("Element.insert(\"#{item_id}\", { #{position.to_s}: #{content} });",
               "No insert_html call found for \n" +
               "     position: '#{position}' id: '#{item_id}' \ncontent: \n" +
               "#{content}\n" +
               "in response:\n#{@response.body}")
      else
        raise "Invalid content type"
    end
  else
    assert_match Regexp.new("Element.insert\\(\"#{item_id}\",\\ \\{\\ #{position.to_s}.*\\);"), 
                 @response.body
  end
end

#assert_rjs_page(*args) ⇒ Object

To deal with [] syntax. I hate JavaScriptProxy so.. SO very much



89
90
91
92
93
# File 'lib/rails-arts/assertions.rb', line 89

def assert_rjs_page(*args)
  content = build_method_chain!(args)
  assert_match Regexp.new(Regexp.escape(content)), @response.body, 
               "Content did not include:\n #{content.to_s}"
end

#assert_rjs_replace(*args) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/rails-arts/assertions.rb', line 67

def assert_rjs_replace(*args)
  div = args.shift
  content = extract_matchable_content(args)
  
  unless content.blank?
    case content
      when Regexp
        assert_match Regexp.new("Element.replace(.*#{div}.*,.*#{content.source}.*);"),
                     @response.body
      when String
        assert_response_contains("Element.replace(\"#{div}\", #{content});", 
               "No replace call found on div: '#{div}' and content: \n#{content}\n" +
               "in response:\n#{@response.body}")
      else
        raise "Invalid content type"
    end
  else
    assert_match Regexp.new("Element.replace(.*#{div}.*,.*?);"), @response.body
  end
end

#assert_rjs_replace_html(*args) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rails-arts/assertions.rb', line 46

def assert_rjs_replace_html(*args)
  div = args.shift
  content = extract_matchable_content(args)
     
  unless content.blank?
    case content
      when Regexp
        assert_match Regexp.new("Element.update(.*#{div}.*,.*#{content.source}.*);"),
                     @response.body
      when String
        assert_response_contains("Element.update(\"#{div}\", #{content});", 
               "No replace_html call found on div: '#{div}' and content: \n#{content}\n" +
               "in response:\n#{@response.body}")
      else
        raise "Invalid content type"
    end
  else
    assert_match Regexp.new("Element.update(.*#{div}.*,.*?);"), @response.body
  end
end

#with_output_buffer(lines = [], &block) ⇒ Object

hack for rails 2.2.2



140
141
142
# File 'lib/rails-arts/assertions.rb', line 140

def with_output_buffer(lines=[], &block)
  block.call
end