holygrail 0.5.1 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +3 -1
- data/README.md +8 -6
- data/holygrail.gemspec +1 -1
- data/lib/holygrail.rb +93 -58
- data/public/javascripts/jquery.js +4376 -0
- data/rails/init.rb +4 -1
- data/specs.watchr +1 -1
- data/test/{holygrail_test.rb → functional_test.rb} +3 -12
- data/test/integration_test.rb +118 -0
- data/test/test_helper.rb +21 -0
- metadata +5 -3
data/rails/init.rb
CHANGED
@@ -2,5 +2,8 @@ require 'pathname'
|
|
2
2
|
require Pathname(__FILE__).dirname.parent + 'lib/holygrail'
|
3
3
|
|
4
4
|
class ActionController::TestCase
|
5
|
-
include
|
5
|
+
include HolyGrail::Extensions
|
6
|
+
end
|
7
|
+
class ActionController::IntegrationTest
|
8
|
+
include HolyGrail::Extensions
|
6
9
|
end
|
data/specs.watchr
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# Rules
|
6
6
|
# --------------------------------------------------
|
7
7
|
watch( '^test.*/.*_test\.rb' ) {|m| ruby m[0] }
|
8
|
-
watch( '^lib/(.*)\.rb' ) {
|
8
|
+
watch( '^lib/(.*)\.rb' ) { ruby tests }
|
9
9
|
watch( '^rails/init\.rb' ) { ruby tests }
|
10
10
|
watch( '^test/test_helper\.rb' ) { ruby tests }
|
11
11
|
|
@@ -1,17 +1,7 @@
|
|
1
1
|
require 'test/test_helper'
|
2
2
|
|
3
|
-
class
|
4
|
-
def self.root
|
5
|
-
Pathname(__FILE__).dirname.parent.expand_path
|
6
|
-
end
|
7
|
-
end
|
3
|
+
class FunctionalsController < ActionController::Base
|
8
4
|
|
9
|
-
ActionController::Routing::Routes.draw do |map|
|
10
|
-
map.connect '/foo', :controller => 'holy_grails', :action => 'foo'
|
11
|
-
map.connect '/bar', :controller => 'holy_grails', :action => 'bar'
|
12
|
-
end
|
13
|
-
|
14
|
-
class HolyGrailsController < ActionController::Base
|
15
5
|
def foo
|
16
6
|
render :text => <<-HTML
|
17
7
|
<html>
|
@@ -41,7 +31,8 @@ class HolyGrailsController < ActionController::Base
|
|
41
31
|
end
|
42
32
|
end
|
43
33
|
|
44
|
-
class
|
34
|
+
class FunctionalsControllerTest < ActionController::TestCase
|
35
|
+
|
45
36
|
test "api" do
|
46
37
|
assert_respond_to self, :execute_javascript
|
47
38
|
assert_respond_to self, :js
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class IntegrationController < ActionController::Base
|
4
|
+
|
5
|
+
PERFORM_XHR_FUNCTION = <<-JS
|
6
|
+
function perform_xhr(method, url, data) {
|
7
|
+
var xhr = new XMLHttpRequest()
|
8
|
+
xhr.open(method, url, false) //false == synchronous
|
9
|
+
xhr.onreadystatechange = function() {
|
10
|
+
if (this.readyState != 4) { return }
|
11
|
+
document.body.innerHTML = this.responseText
|
12
|
+
}
|
13
|
+
xhr.send(data) //POST request sends data here
|
14
|
+
}
|
15
|
+
JS
|
16
|
+
|
17
|
+
def baz
|
18
|
+
render :text => <<-HTML
|
19
|
+
<html>
|
20
|
+
<head>
|
21
|
+
<script>#{PERFORM_XHR_FUNCTION}</script>
|
22
|
+
</head>
|
23
|
+
<body></body>
|
24
|
+
</html>
|
25
|
+
HTML
|
26
|
+
end
|
27
|
+
|
28
|
+
def boo
|
29
|
+
render :text => <<-HTML
|
30
|
+
<html>
|
31
|
+
<head>
|
32
|
+
<script>#{PERFORM_XHR_FUNCTION}</script>
|
33
|
+
<script>
|
34
|
+
window.onload = function() {
|
35
|
+
perform_xhr("GET", "xhr")
|
36
|
+
}
|
37
|
+
</script>
|
38
|
+
</head>
|
39
|
+
<body></body>
|
40
|
+
</html>
|
41
|
+
HTML
|
42
|
+
end
|
43
|
+
|
44
|
+
def moo
|
45
|
+
render :text => <<-HTML
|
46
|
+
<html>
|
47
|
+
<head>
|
48
|
+
<script type="text/javascript" src="javascripts/jquery.js"></script>
|
49
|
+
</head>
|
50
|
+
<body></body>
|
51
|
+
</html>
|
52
|
+
HTML
|
53
|
+
end
|
54
|
+
|
55
|
+
def xhr
|
56
|
+
render :text => "xhr response"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class IntegrationControllerTest < ActionController::IntegrationTest
|
61
|
+
|
62
|
+
test "api" do
|
63
|
+
assert_respond_to self, :execute_javascript
|
64
|
+
assert_respond_to self, :js
|
65
|
+
end
|
66
|
+
|
67
|
+
## xhr
|
68
|
+
|
69
|
+
test "xhr calls controller" do
|
70
|
+
get '/baz'
|
71
|
+
|
72
|
+
assert_equal "", js(<<-JS).gsub("\n",'').strip
|
73
|
+
document.body.innerHTML
|
74
|
+
JS
|
75
|
+
assert_equal "xhr response", js(<<-JS)
|
76
|
+
perform_xhr("GET", "xhr")
|
77
|
+
document.body.innerHTML
|
78
|
+
JS
|
79
|
+
end
|
80
|
+
|
81
|
+
test "xhr identifes properly" do
|
82
|
+
get '/baz'
|
83
|
+
assert_nil request.headers['X-Requested-With']
|
84
|
+
|
85
|
+
js(<<-JS)
|
86
|
+
perform_xhr("GET", "xhr")
|
87
|
+
JS
|
88
|
+
assert_equal 'XMLHttpRequest', request.headers['X-Requested-With']
|
89
|
+
end
|
90
|
+
|
91
|
+
test "xhr is mocked early" do
|
92
|
+
get '/boo' #triggers ajax call on load
|
93
|
+
assert_equal "xhr response", js(<<-JS)
|
94
|
+
document.body.innerHTML
|
95
|
+
JS
|
96
|
+
end
|
97
|
+
|
98
|
+
test "xhr with post data" do
|
99
|
+
get '/baz'
|
100
|
+
js(<<-JS)
|
101
|
+
perform_xhr("GET", "xhr", "animove")
|
102
|
+
JS
|
103
|
+
assert_equal 'animove', request.body.read
|
104
|
+
end
|
105
|
+
|
106
|
+
test "xhr with jquery" do
|
107
|
+
get '/moo' #loads jquery.js
|
108
|
+
js(<<-JS)
|
109
|
+
$.get("/xhr", function(data, textStatus, xhr){
|
110
|
+
document.body.innerHTML = data
|
111
|
+
})
|
112
|
+
JS
|
113
|
+
assert_equal "xhr response", js(<<-JS).strip
|
114
|
+
document.body.innerHTML
|
115
|
+
JS
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
data/test/test_helper.rb
CHANGED
@@ -1,8 +1,29 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'action_controller'
|
3
|
+
require 'action_controller/integration'
|
3
4
|
|
4
5
|
begin require 'ruby-debug'; rescue LoadError; end
|
5
6
|
begin require 'redgreen'; rescue LoadError; end
|
6
7
|
begin require 'phocus'; rescue LoadError; end
|
7
8
|
|
8
9
|
require 'rails/init'
|
10
|
+
|
11
|
+
class Rails
|
12
|
+
def self.root
|
13
|
+
Pathname(__FILE__).dirname.parent.expand_path
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
ActionController::Routing::Routes.draw do |map|
|
18
|
+
map.connect '/foo', :controller => 'functionals', :action => 'foo'
|
19
|
+
map.connect '/bar', :controller => 'functionals', :action => 'bar'
|
20
|
+
map.connect '/baz', :controller => 'integration', :action => 'baz'
|
21
|
+
map.connect '/boo', :controller => 'integration', :action => 'boo'
|
22
|
+
map.connect '/moo', :controller => 'integration', :action => 'moo'
|
23
|
+
map.connect '/xhr', :controller => 'integration', :action => 'xhr'
|
24
|
+
end
|
25
|
+
|
26
|
+
ActionController::Base.session = {
|
27
|
+
:key => "_myapp_session",
|
28
|
+
:secret => "some secret phrase" * 5
|
29
|
+
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: holygrail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: "0.6"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mynyml
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-04-01 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -51,9 +51,11 @@ files:
|
|
51
51
|
- lib/holygrail.rb
|
52
52
|
- public/javascripts/application.js
|
53
53
|
- public/javascripts/foo.js
|
54
|
+
- public/javascripts/jquery.js
|
54
55
|
- rails/init.rb
|
55
56
|
- specs.watchr
|
56
|
-
- test/
|
57
|
+
- test/functional_test.rb
|
58
|
+
- test/integration_test.rb
|
57
59
|
- test/test_helper.rb
|
58
60
|
has_rdoc: true
|
59
61
|
homepage: http://github.com/mynyml/holygrail
|