pivotal-jelly 0.1.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.markdown +112 -0
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/generators/jelly/jelly_generator.rb +2 -0
- data/generators/jelly/templates/javascripts/ajax_with_jelly.js +6 -4
- data/jelly.gemspec +73 -0
- data/lib/{jelly_controller.rb → jelly/jelly_controller.rb} +3 -3
- data/lib/{jelly_helper.rb → jelly/jelly_helper.rb} +4 -6
- data/lib/jelly.rb +16 -0
- data/spec/controllers/jelly_controller_spec.rb +13 -15
- data/spec/helpers/jelly_helper_spec.rb +5 -4
- data/spec/rails_root/app/controllers/application_controller.rb +10 -0
- data/spec/rails_root/app/helpers/application_helper.rb +3 -0
- data/spec/rails_root/config/boot.rb +110 -0
- data/spec/rails_root/config/environment.rb +41 -0
- data/spec/rails_root/config/environments/development.rb +17 -0
- data/spec/rails_root/config/environments/production.rb +28 -0
- data/spec/rails_root/config/environments/test.rb +28 -0
- data/spec/rails_root/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails_root/config/initializers/inflections.rb +10 -0
- data/spec/rails_root/config/initializers/mime_types.rb +5 -0
- data/spec/rails_root/config/initializers/new_rails_defaults.rb +19 -0
- data/spec/rails_root/config/initializers/session_store.rb +15 -0
- data/spec/rails_root/config/routes.rb +43 -0
- data/spec/rails_root/test/performance/browsing_test.rb +9 -0
- data/spec/rails_root/test/test_helper.rb +38 -0
- data/spec/spec_helper.rb +4 -1
- metadata +33 -15
- data/init.rb +0 -7
- data/spec/fixtures/pages/bears.js +0 -0
- data/spec/fixtures/pages/lions.js +0 -0
- data/spec/fixtures/pages/tigers.js +0 -0
- data/spec/javascript/jelly_spec.js +0 -61
data/.gitignore
CHANGED
data/README.markdown
CHANGED
@@ -0,0 +1,112 @@
|
|
1
|
+
Jelly
|
2
|
+
=====
|
3
|
+
|
4
|
+
INSTALLATION
|
5
|
+
------------
|
6
|
+
|
7
|
+
If you haven't already, add GitHub to your gem sources:
|
8
|
+
|
9
|
+
gem sources -a http://gems.github.com
|
10
|
+
|
11
|
+
Then run:
|
12
|
+
|
13
|
+
sudo gem install pivotal-jelly
|
14
|
+
|
15
|
+
|
16
|
+
GETTING STARTED
|
17
|
+
---------------
|
18
|
+
|
19
|
+
In your `environment.rb` in the `Rails::Initializer.run` block, be sure to require jelly:
|
20
|
+
|
21
|
+
config.gem "jelly"
|
22
|
+
|
23
|
+
Then install the required JavaScript files by running this command in your Rails project:
|
24
|
+
|
25
|
+
script/generate jelly
|
26
|
+
|
27
|
+
Then, in your layout, add the following:
|
28
|
+
|
29
|
+
<%= javascript_include_tag :jelly, *application_jelly_files %>
|
30
|
+
<%= spread_jelly %>
|
31
|
+
|
32
|
+
This will include the required JavaScripts for jelly and activate the current page. The `:jelly` javascript expansion
|
33
|
+
includes jQuery. If you already have jQuery included in the page, use the `:only_jelly` expansion instead.
|
34
|
+
|
35
|
+
EXAMPLE USAGE
|
36
|
+
-------------
|
37
|
+
|
38
|
+
Assuming you have controller named `fun` with an action called `index` and that you have a layout called `fun.html.erb`
|
39
|
+
that is already setup as described above. In your fun index view (`index.html.erb`), put:
|
40
|
+
|
41
|
+
<h1>Your page's 'index' function did not run. Jelly is not configured correctly.</h1>
|
42
|
+
<span class="all">Your page's 'all' function did not run. Jelly is not configured correctly.</span>
|
43
|
+
|
44
|
+
Then, in `public/javascripts/pages/fun.js`, put:
|
45
|
+
|
46
|
+
Jelly.add("Fun", {
|
47
|
+
all: function() {
|
48
|
+
$('span.all').text("I am displayed on every action in this controller.");
|
49
|
+
},
|
50
|
+
index: function() {
|
51
|
+
$('h1').text("Welcome to the index page.");
|
52
|
+
}
|
53
|
+
});
|
54
|
+
|
55
|
+
Now goto `/fun/index` and see Jelly in action!
|
56
|
+
|
57
|
+
AJAX CALLBACKS WITH JELLY
|
58
|
+
-------------------------
|
59
|
+
|
60
|
+
You can trigger callbacks on the page object from Rails with the `jelly_callback` method.
|
61
|
+
Adding to the `index.html.erb` file from above:
|
62
|
+
|
63
|
+
<a href="#" id="jelly_ajax_link">Click me for Jelly Ajax Action</a>
|
64
|
+
<span id="jelly_callback_element">This gets filled in by the Jelly Ajax callback</span>
|
65
|
+
|
66
|
+
And update your controller:
|
67
|
+
|
68
|
+
class FunController < ApplicationController
|
69
|
+
def index
|
70
|
+
end
|
71
|
+
|
72
|
+
def ajax_action
|
73
|
+
jelly_callback do
|
74
|
+
[
|
75
|
+
render(:partial => 'fun_partial'),
|
76
|
+
"second_parameter"
|
77
|
+
]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
Update your page object in `fun.js`:
|
83
|
+
|
84
|
+
Jelly.add("Fun", {
|
85
|
+
all: function() {
|
86
|
+
$('title').text("Hello! Isn't this fun?");
|
87
|
+
},
|
88
|
+
index: function() {
|
89
|
+
$('h1').text("Welcome to the index page.");
|
90
|
+
$("#jelly_ajax_link").click(function() {
|
91
|
+
$.ajaxWithJelly({
|
92
|
+
type: "GET",
|
93
|
+
url: "/fun/ajax_action"
|
94
|
+
});
|
95
|
+
});
|
96
|
+
},
|
97
|
+
on_ajax_action: function(html, second_parameter) {
|
98
|
+
$('#jelly_callback_element').html(html);
|
99
|
+
}
|
100
|
+
});
|
101
|
+
|
102
|
+
And finally, make the partial `_fun_partial.html.erb` and just put "Hello from the server!" in it, then visit your page
|
103
|
+
and watch the ajax callbacks in action.
|
104
|
+
|
105
|
+
The `jelly_callback` method takes an optional parameter for the name of the callback, and the provided block can return
|
106
|
+
either one parameter, or an array of parameters.
|
107
|
+
|
108
|
+
DEVELOPMENT
|
109
|
+
-----------
|
110
|
+
|
111
|
+
To run ruby tests, run `rake spec`.
|
112
|
+
To run JavaScript tests, open `jelly/spec/jasmine_runner.html` in a web browser.
|
data/Rakefile
CHANGED
@@ -27,12 +27,12 @@ begin
|
|
27
27
|
Jeweler::Tasks.new do |gemspec|
|
28
28
|
gemspec.name = "jelly"
|
29
29
|
gemspec.summary = "a sweet unobtrusive javascript framework for jQuery and Rails"
|
30
|
-
gemspec.description = "Jelly provides a set of tools and conventions for creating rich ajax/javascript
|
31
|
-
web applications with jQuery and Ruby on Rails."
|
30
|
+
gemspec.description = "Jelly provides a set of tools and conventions for creating rich ajax/javascript web applications with jQuery and Ruby on Rails."
|
32
31
|
gemspec.email = "opensource@pivotallabs.com"
|
33
32
|
gemspec.homepage = "http://github.com/pivotal/jelly"
|
34
|
-
gemspec.description = "TODO"
|
35
33
|
gemspec.authors = ["Pivotal Labs, Inc"]
|
34
|
+
gemspec.files.exclude 'spec/**/*'
|
35
|
+
gemspec.add_dependency('rails', '>= 2.3.0')
|
36
36
|
end
|
37
37
|
rescue LoadError
|
38
38
|
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
@@ -3,8 +3,10 @@ class JellyGenerator < Rails::Generator::Base
|
|
3
3
|
record do |m|
|
4
4
|
m.file 'javascripts/jelly.js', "public/javascripts/jelly.js"
|
5
5
|
m.file 'javascripts/ajax_with_jelly.js', "public/javascripts/ajax_with_jelly.js"
|
6
|
+
m.directory('public/javascripts/jquery')
|
6
7
|
m.file 'javascripts/jquery/jquery-1.3.2.js', "public/javascripts/jquery/jquery-1.3.2.js"
|
7
8
|
m.file 'javascripts/jquery/jquery.protify-0.3.js', "public/javascripts/jquery/jquery.protify-0.3.js"
|
9
|
+
m.directory('public/javascripts/pages')
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
@@ -5,13 +5,15 @@
|
|
5
5
|
|
6
6
|
$.ajaxWithJelly.params = function(otherParams) {
|
7
7
|
otherParams = otherParams || {};
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
|
9
|
+
if (otherParams.type && otherParams.type != "GET") {
|
10
|
+
otherParams['data'] = $.extend(otherParams['data'], {
|
11
|
+
authenticity_token: window._token
|
12
|
+
});
|
13
|
+
}
|
11
14
|
return $.extend({
|
12
15
|
dataType: 'json',
|
13
16
|
cache: false,
|
14
|
-
type: 'POST',
|
15
17
|
success : $.ajaxWithJelly.onSuccess
|
16
18
|
}, otherParams);
|
17
19
|
};
|
data/jelly.gemspec
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{jelly}
|
5
|
+
s.version = "0.3.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Pivotal Labs, Inc"]
|
9
|
+
s.date = %q{2009-08-13}
|
10
|
+
s.description = %q{Jelly provides a set of tools and conventions for creating rich ajax/javascript web applications with jQuery and Ruby on Rails.}
|
11
|
+
s.email = %q{opensource@pivotallabs.com}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"README.markdown"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".gitignore",
|
17
|
+
"MIT-LICENSE",
|
18
|
+
"README.markdown",
|
19
|
+
"Rakefile",
|
20
|
+
"VERSION",
|
21
|
+
"generators/jelly/USAGE",
|
22
|
+
"generators/jelly/jelly_generator.rb",
|
23
|
+
"generators/jelly/templates/javascripts/ajax_with_jelly.js",
|
24
|
+
"generators/jelly/templates/javascripts/jelly.js",
|
25
|
+
"generators/jelly/templates/javascripts/jquery/jquery-1.3.2.js",
|
26
|
+
"generators/jelly/templates/javascripts/jquery/jquery.protify-0.3.js",
|
27
|
+
"install.rb",
|
28
|
+
"jelly.gemspec",
|
29
|
+
"lib/jelly.rb",
|
30
|
+
"lib/jelly/jelly_controller.rb",
|
31
|
+
"lib/jelly/jelly_helper.rb",
|
32
|
+
"tasks/jelly_tasks.rake",
|
33
|
+
"uninstall.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/pivotal/jelly}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.3}
|
39
|
+
s.summary = %q{a sweet unobtrusive javascript framework for jQuery and Rails}
|
40
|
+
s.test_files = [
|
41
|
+
"spec/controllers/jelly_controller_spec.rb",
|
42
|
+
"spec/helpers/jelly_helper_spec.rb",
|
43
|
+
"spec/rails_root/app/controllers/application_controller.rb",
|
44
|
+
"spec/rails_root/app/helpers/application_helper.rb",
|
45
|
+
"spec/rails_root/config/boot.rb",
|
46
|
+
"spec/rails_root/config/environment.rb",
|
47
|
+
"spec/rails_root/config/environments/development.rb",
|
48
|
+
"spec/rails_root/config/environments/production.rb",
|
49
|
+
"spec/rails_root/config/environments/test.rb",
|
50
|
+
"spec/rails_root/config/initializers/backtrace_silencers.rb",
|
51
|
+
"spec/rails_root/config/initializers/inflections.rb",
|
52
|
+
"spec/rails_root/config/initializers/mime_types.rb",
|
53
|
+
"spec/rails_root/config/initializers/new_rails_defaults.rb",
|
54
|
+
"spec/rails_root/config/initializers/session_store.rb",
|
55
|
+
"spec/rails_root/config/routes.rb",
|
56
|
+
"spec/rails_root/test/performance/browsing_test.rb",
|
57
|
+
"spec/rails_root/test/test_helper.rb",
|
58
|
+
"spec/spec_helper.rb"
|
59
|
+
]
|
60
|
+
|
61
|
+
if s.respond_to? :specification_version then
|
62
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
63
|
+
s.specification_version = 3
|
64
|
+
|
65
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
66
|
+
s.add_runtime_dependency(%q<rails>, [">= 2.3.0"])
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<rails>, [">= 2.3.0"])
|
69
|
+
end
|
70
|
+
else
|
71
|
+
s.add_dependency(%q<rails>, [">= 2.3.0"])
|
72
|
+
end
|
73
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module JellyController
|
2
2
|
protected
|
3
3
|
|
4
|
-
def
|
5
|
-
render :inline =>
|
4
|
+
def jelly_callback(callback_base_name = @action_name, options = {}, &block)
|
5
|
+
render :inline => jelly_callback_erb("on_#{callback_base_name}", options, block)
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
8
|
+
def jelly_callback_erb(callback_name, options, block)
|
9
9
|
@callback_name = callback_name
|
10
10
|
@options = options
|
11
11
|
@block = block
|
@@ -1,14 +1,12 @@
|
|
1
1
|
module JellyHelper
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
Dir["#{jelly_files_path}/pages/**/*.js"].map do |path|
|
7
|
-
path.gsub("#{jelly_files_path}/", "").gsub(/\.js$/, "")
|
3
|
+
def application_jelly_files(jelly_files_path_from_javascripts = '', rails_root = RAILS_ROOT)
|
4
|
+
Dir["#{rails_root}/public/javascripts/#{jelly_files_path_from_javascripts}/pages/**/*.js"].map do |path|
|
5
|
+
path.gsub("#{rails_root}/public/javascripts/", "").gsub(/\.js$/, "")
|
8
6
|
end
|
9
7
|
end
|
10
8
|
|
11
|
-
def
|
9
|
+
def spread_jelly
|
12
10
|
javascript_tag <<-JS
|
13
11
|
window._token = '#{form_authenticity_token}'
|
14
12
|
Jelly.activatePage('#{controller.controller_path.camelcase}', '#{controller.action_name}');
|
data/lib/jelly.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
raise "Jelly must be used in a Rails environment." unless defined?(ActionController)
|
2
|
+
|
3
|
+
require 'jelly/jelly_controller'
|
4
|
+
require 'jelly/jelly_helper'
|
5
|
+
|
6
|
+
ActionController::Base.class_eval do
|
7
|
+
include JellyController
|
8
|
+
end
|
9
|
+
|
10
|
+
ActionView::Base.class_eval do
|
11
|
+
include JellyHelper
|
12
|
+
end
|
13
|
+
|
14
|
+
ActionView::Helpers::AssetTagHelper.register_javascript_expansion :jelly => ["jquery/jquery-1.3.2", "jquery/jquery.protify-0.3",
|
15
|
+
"ajax_with_jelly", "jelly"]
|
16
|
+
ActionView::Helpers::AssetTagHelper.register_javascript_expansion :only_jelly => ["jquery/jquery.protify-0.3", "jelly", "ajax_with_jelly"]
|
@@ -2,27 +2,27 @@ require File.dirname(__FILE__) + '/../spec_helper.rb'
|
|
2
2
|
|
3
3
|
describe ApplicationController do
|
4
4
|
|
5
|
-
describe "#
|
5
|
+
describe "#jelly_callback" do
|
6
6
|
before do
|
7
7
|
@controller.stub!(:render)
|
8
8
|
end
|
9
9
|
|
10
10
|
it "have the method included" do
|
11
|
-
@controller.respond_to?(:
|
11
|
+
@controller.respond_to?(:jelly_callback).should be_true
|
12
12
|
end
|
13
13
|
|
14
|
-
it "should render inline the return of
|
14
|
+
it "should render inline the return of jelly_callback_erb" do
|
15
15
|
block = lambda{'foo yo'}
|
16
16
|
mock_erb = "whatever"
|
17
|
-
@controller.should_receive(:
|
17
|
+
@controller.should_receive(:jelly_callback_erb).with("on_foo", {}, block).and_return(mock_erb)
|
18
18
|
@controller.should_receive(:render).with(:inline => mock_erb)
|
19
|
-
@controller.send(:
|
19
|
+
@controller.send(:jelly_callback, "foo", &block)
|
20
20
|
end
|
21
21
|
|
22
|
-
describe "#
|
22
|
+
describe "#jelly_callback_erb" do
|
23
23
|
context "with options" do
|
24
24
|
it "should work with a block" do
|
25
|
-
erb = @controller.send(:
|
25
|
+
erb = @controller.send(:jelly_callback_erb, 'foo', {'bar' => 'baz'}, lambda{'grape'})
|
26
26
|
JSON.parse(ERB.new(erb).result(@controller.send(:binding))).should == {
|
27
27
|
'method' => 'foo',
|
28
28
|
'arguments' => ['grape'],
|
@@ -31,7 +31,7 @@ describe ApplicationController do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should work without a block" do
|
34
|
-
erb = @controller.send(:
|
34
|
+
erb = @controller.send(:jelly_callback_erb, 'foo', {'bar' => 'baz'}, nil)
|
35
35
|
JSON.parse(ERB.new(erb).result(@controller.send(:binding))).should == {
|
36
36
|
'method' => 'foo',
|
37
37
|
'arguments' => [],
|
@@ -40,7 +40,7 @@ describe ApplicationController do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should work if options are passed with symbol keys" do
|
43
|
-
erb = @controller.send(:
|
43
|
+
erb = @controller.send(:jelly_callback_erb, 'foo', {:bar => 'baz'}, nil)
|
44
44
|
JSON.parse(ERB.new(erb).result(@controller.send(:binding))).should == {
|
45
45
|
'method' => 'foo',
|
46
46
|
'arguments' => [],
|
@@ -51,7 +51,7 @@ describe ApplicationController do
|
|
51
51
|
|
52
52
|
context "without options" do
|
53
53
|
it "should work with a block" do
|
54
|
-
erb = @controller.send(:
|
54
|
+
erb = @controller.send(:jelly_callback_erb, 'foo', {}, lambda{'grape'})
|
55
55
|
JSON.parse(ERB.new(erb).result(@controller.send(:binding))).should == {
|
56
56
|
'method' => 'foo',
|
57
57
|
'arguments' => ['grape']
|
@@ -59,7 +59,7 @@ describe ApplicationController do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should work with a block of more than one thing" do
|
62
|
-
erb = @controller.send(:
|
62
|
+
erb = @controller.send(:jelly_callback_erb, 'foo', {}, lambda{['grape','tangerine']})
|
63
63
|
JSON.parse(ERB.new(erb).result(@controller.send(:binding))).should == {
|
64
64
|
'method' => 'foo',
|
65
65
|
'arguments' => ['grape','tangerine']
|
@@ -67,7 +67,7 @@ describe ApplicationController do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should work without a block" do
|
70
|
-
erb = @controller.send(:
|
70
|
+
erb = @controller.send(:jelly_callback_erb, 'foo', {}, nil)
|
71
71
|
JSON.parse(ERB.new(erb).result(@controller.send(:binding))).should == {
|
72
72
|
'method' => 'foo',
|
73
73
|
'arguments' => []
|
@@ -77,7 +77,7 @@ describe ApplicationController do
|
|
77
77
|
|
78
78
|
it "should escape html in the arguments" do
|
79
79
|
block = lambda{'<div class="foo"></div>'}
|
80
|
-
erb = @controller.send(:
|
80
|
+
erb = @controller.send(:jelly_callback_erb, 'foo', {}, block)
|
81
81
|
JSON.parse(ERB.new(erb).result(@controller.send(:binding))).should == {
|
82
82
|
'method' => 'foo',
|
83
83
|
'arguments' => ['<div class="foo"></div>']
|
@@ -85,6 +85,4 @@ describe ApplicationController do
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
end
|
88
|
-
|
89
|
-
|
90
88
|
end
|
@@ -7,17 +7,18 @@ describe "JellyHelper" do
|
|
7
7
|
stub_controller = mock(Object, :controller_path => 'my_fun_controller', :action_name => 'super_good_action')
|
8
8
|
helper.should_receive(:controller).any_number_of_times.and_return(stub_controller)
|
9
9
|
helper.should_receive(:form_authenticity_token).and_return('areallysecuretoken')
|
10
|
-
output = helper.
|
10
|
+
output = helper.spread_jelly
|
11
11
|
output.should include('<script type="text/javascript">')
|
12
12
|
output.should include("Jelly.activatePage('MyFunController', 'super_good_action');")
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
describe "#
|
16
|
+
describe "#application_jelly_files" do
|
17
17
|
it "returns the javascript files in the given path" do
|
18
|
-
|
18
|
+
my_rails_root = File.join(File.dirname(__FILE__), '/../fixtures')
|
19
|
+
files = helper.application_jelly_files("foo", my_rails_root)
|
19
20
|
files.should_not be_empty
|
20
|
-
files.should =~ ['pages/lions', 'pages/tigers', 'pages/bears']
|
21
|
+
files.should =~ ['foo/pages/lions', 'foo/pages/tigers', 'foo/pages/bears']
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Filters added to this controller apply to all controllers in the application.
|
2
|
+
# Likewise, all the methods added will be available for all controllers.
|
3
|
+
|
4
|
+
class ApplicationController < ActionController::Base
|
5
|
+
helper :all # include all helpers, all the time
|
6
|
+
protect_from_forgery # See ActionController::RequestForgeryProtection for details
|
7
|
+
|
8
|
+
# Scrub sensitive parameters from your log
|
9
|
+
# filter_parameter_logging :password
|
10
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# Don't change this file!
|
2
|
+
# Configure your app in config/environment.rb and config/environments/*.rb
|
3
|
+
|
4
|
+
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
class << self
|
8
|
+
def boot!
|
9
|
+
unless booted?
|
10
|
+
preinitialize
|
11
|
+
pick_boot.run
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def booted?
|
16
|
+
defined? Rails::Initializer
|
17
|
+
end
|
18
|
+
|
19
|
+
def pick_boot
|
20
|
+
(vendor_rails? ? VendorBoot : GemBoot).new
|
21
|
+
end
|
22
|
+
|
23
|
+
def vendor_rails?
|
24
|
+
File.exist?("#{RAILS_ROOT}/vendor/rails")
|
25
|
+
end
|
26
|
+
|
27
|
+
def preinitialize
|
28
|
+
load(preinitializer_path) if File.exist?(preinitializer_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def preinitializer_path
|
32
|
+
"#{RAILS_ROOT}/config/preinitializer.rb"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Boot
|
37
|
+
def run
|
38
|
+
load_initializer
|
39
|
+
Rails::Initializer.run(:set_load_path)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class VendorBoot < Boot
|
44
|
+
def load_initializer
|
45
|
+
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
|
46
|
+
Rails::Initializer.run(:install_gem_spec_stubs)
|
47
|
+
Rails::GemDependency.add_frozen_gem_path
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class GemBoot < Boot
|
52
|
+
def load_initializer
|
53
|
+
self.class.load_rubygems
|
54
|
+
load_rails_gem
|
55
|
+
require 'initializer'
|
56
|
+
end
|
57
|
+
|
58
|
+
def load_rails_gem
|
59
|
+
if version = self.class.gem_version
|
60
|
+
gem 'rails', version
|
61
|
+
else
|
62
|
+
gem 'rails'
|
63
|
+
end
|
64
|
+
rescue Gem::LoadError => load_error
|
65
|
+
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
|
66
|
+
exit 1
|
67
|
+
end
|
68
|
+
|
69
|
+
class << self
|
70
|
+
def rubygems_version
|
71
|
+
Gem::RubyGemsVersion rescue nil
|
72
|
+
end
|
73
|
+
|
74
|
+
def gem_version
|
75
|
+
if defined? RAILS_GEM_VERSION
|
76
|
+
RAILS_GEM_VERSION
|
77
|
+
elsif ENV.include?('RAILS_GEM_VERSION')
|
78
|
+
ENV['RAILS_GEM_VERSION']
|
79
|
+
else
|
80
|
+
parse_gem_version(read_environment_rb)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def load_rubygems
|
85
|
+
require 'rubygems'
|
86
|
+
min_version = '1.3.1'
|
87
|
+
unless rubygems_version >= min_version
|
88
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
|
89
|
+
exit 1
|
90
|
+
end
|
91
|
+
|
92
|
+
rescue LoadError
|
93
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
|
94
|
+
exit 1
|
95
|
+
end
|
96
|
+
|
97
|
+
def parse_gem_version(text)
|
98
|
+
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
def read_environment_rb
|
103
|
+
File.read("#{RAILS_ROOT}/config/environment.rb")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# All that for this:
|
110
|
+
Rails.boot!
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file
|
2
|
+
|
3
|
+
# Specifies gem version of Rails to use when vendor/rails is not present
|
4
|
+
RAILS_GEM_VERSION = '2.3.3' unless defined? RAILS_GEM_VERSION
|
5
|
+
|
6
|
+
# Bootstrap the Rails environment, frameworks, and default configuration
|
7
|
+
require File.join(File.dirname(__FILE__), 'boot')
|
8
|
+
|
9
|
+
Rails::Initializer.run do |config|
|
10
|
+
# Settings in config/environments/* take precedence over those specified here.
|
11
|
+
# Application configuration should go into files in config/initializers
|
12
|
+
# -- all .rb files in that directory are automatically loaded.
|
13
|
+
|
14
|
+
# Add additional load paths for your own custom dirs
|
15
|
+
# config.load_paths += %W( #{RAILS_ROOT}/extras )
|
16
|
+
|
17
|
+
# Specify gems that this application depends on and have them installed with rake gems:install
|
18
|
+
# config.gem "bj"
|
19
|
+
# config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
|
20
|
+
# config.gem "sqlite3-ruby", :lib => "sqlite3"
|
21
|
+
# config.gem "aws-s3", :lib => "aws/s3"
|
22
|
+
|
23
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
24
|
+
# :all can be used as a placeholder for all plugins not explicitly named
|
25
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
26
|
+
|
27
|
+
# Skip frameworks you're not going to use. To use Rails without a database,
|
28
|
+
# you must remove the Active Record framework.
|
29
|
+
# config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
|
30
|
+
|
31
|
+
# Activate observers that should always be running
|
32
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
33
|
+
|
34
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
35
|
+
# Run "rake -D time" for a list of tasks for finding time zone names.
|
36
|
+
config.time_zone = 'UTC'
|
37
|
+
|
38
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
39
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
|
40
|
+
# config.i18n.default_locale = :de
|
41
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
2
|
+
|
3
|
+
# In the development environment your application's code is reloaded on
|
4
|
+
# every request. This slows down response time but is perfect for development
|
5
|
+
# since you don't have to restart the webserver when you make code changes.
|
6
|
+
config.cache_classes = false
|
7
|
+
|
8
|
+
# Log error messages when you accidentally call methods on nil.
|
9
|
+
config.whiny_nils = true
|
10
|
+
|
11
|
+
# Show full error reports and disable caching
|
12
|
+
config.action_controller.consider_all_requests_local = true
|
13
|
+
config.action_view.debug_rjs = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
2
|
+
|
3
|
+
# The production environment is meant for finished, "live" apps.
|
4
|
+
# Code is not reloaded between requests
|
5
|
+
config.cache_classes = true
|
6
|
+
|
7
|
+
# Full error reports are disabled and caching is turned on
|
8
|
+
config.action_controller.consider_all_requests_local = false
|
9
|
+
config.action_controller.perform_caching = true
|
10
|
+
config.action_view.cache_template_loading = true
|
11
|
+
|
12
|
+
# See everything in the log (default is :info)
|
13
|
+
# config.log_level = :debug
|
14
|
+
|
15
|
+
# Use a different logger for distributed setups
|
16
|
+
# config.logger = SyslogLogger.new
|
17
|
+
|
18
|
+
# Use a different cache store in production
|
19
|
+
# config.cache_store = :mem_cache_store
|
20
|
+
|
21
|
+
# Enable serving of images, stylesheets, and javascripts from an asset server
|
22
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
23
|
+
|
24
|
+
# Disable delivery errors, bad email addresses will be ignored
|
25
|
+
# config.action_mailer.raise_delivery_errors = false
|
26
|
+
|
27
|
+
# Enable threaded mode
|
28
|
+
# config.threadsafe!
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
2
|
+
|
3
|
+
# The test environment is used exclusively to run your application's
|
4
|
+
# test suite. You never need to work with it otherwise. Remember that
|
5
|
+
# your test database is "scratch space" for the test suite and is wiped
|
6
|
+
# and recreated between test runs. Don't rely on the data there!
|
7
|
+
config.cache_classes = true
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.action_controller.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
config.action_view.cache_template_loading = true
|
16
|
+
|
17
|
+
# Disable request forgery protection in test environment
|
18
|
+
config.action_controller.allow_forgery_protection = false
|
19
|
+
|
20
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
21
|
+
# The :test delivery method accumulates sent emails in the
|
22
|
+
# ActionMailer::Base.deliveries array.
|
23
|
+
config.action_mailer.delivery_method = :test
|
24
|
+
|
25
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
26
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
27
|
+
# like if you have constraints or database-specific column types
|
28
|
+
# config.active_record.schema_format = :sql
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying do debug a problem that might steem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format
|
4
|
+
# (all these examples are active by default):
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
8
|
+
# inflect.irregular 'person', 'people'
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
10
|
+
# end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# These settings change the behavior of Rails 2 apps and will be defaults
|
4
|
+
# for Rails 3. You can remove this initializer when Rails 3 is released.
|
5
|
+
|
6
|
+
if defined?(ActiveRecord)
|
7
|
+
# Include Active Record class name as root for JSON serialized output.
|
8
|
+
ActiveRecord::Base.include_root_in_json = true
|
9
|
+
|
10
|
+
# Store the full class name (including module namespace) in STI type column.
|
11
|
+
ActiveRecord::Base.store_full_sti_class = true
|
12
|
+
end
|
13
|
+
|
14
|
+
# Use ISO 8601 format for JSON serialized times and dates.
|
15
|
+
ActiveSupport.use_standard_json_time_format = true
|
16
|
+
|
17
|
+
# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
|
18
|
+
# if you're including raw json in an HTML page.
|
19
|
+
ActiveSupport.escape_html_entities_in_json = false
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying cookie session data integrity.
|
4
|
+
# If you change this key, all old sessions will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
ActionController::Base.session = {
|
8
|
+
:key => '_rails_root_session',
|
9
|
+
:secret => '7bc680488f32703dcc8d4f0b02f629e0a913e3877e67408c83dc7d83d06532806585afbe4d27aa0c91c4341cc0a09e143b50b586da9dfc842de3474a5af40a6b'
|
10
|
+
}
|
11
|
+
|
12
|
+
# Use the database for sessions instead of the cookie-based default,
|
13
|
+
# which shouldn't be used to store highly confidential information
|
14
|
+
# (create the session table with "rake db:sessions:create")
|
15
|
+
# ActionController::Base.session_store = :active_record_store
|
@@ -0,0 +1,43 @@
|
|
1
|
+
ActionController::Routing::Routes.draw do |map|
|
2
|
+
# The priority is based upon order of creation: first created -> highest priority.
|
3
|
+
|
4
|
+
# Sample of regular route:
|
5
|
+
# map.connect 'products/:id', :controller => 'catalog', :action => 'view'
|
6
|
+
# Keep in mind you can assign values other than :controller and :action
|
7
|
+
|
8
|
+
# Sample of named route:
|
9
|
+
# map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
|
10
|
+
# This route can be invoked with purchase_url(:id => product.id)
|
11
|
+
|
12
|
+
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
13
|
+
# map.resources :products
|
14
|
+
|
15
|
+
# Sample resource route with options:
|
16
|
+
# map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
|
17
|
+
|
18
|
+
# Sample resource route with sub-resources:
|
19
|
+
# map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
|
20
|
+
|
21
|
+
# Sample resource route with more complex sub-resources
|
22
|
+
# map.resources :products do |products|
|
23
|
+
# products.resources :comments
|
24
|
+
# products.resources :sales, :collection => { :recent => :get }
|
25
|
+
# end
|
26
|
+
|
27
|
+
# Sample resource route within a namespace:
|
28
|
+
# map.namespace :admin do |admin|
|
29
|
+
# # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
|
30
|
+
# admin.resources :products
|
31
|
+
# end
|
32
|
+
|
33
|
+
# You can have the root of your site routed with map.root -- just remember to delete public/index.html.
|
34
|
+
# map.root :controller => "welcome"
|
35
|
+
|
36
|
+
# See how all your routes lay out with "rake routes"
|
37
|
+
|
38
|
+
# Install the default routes as the lowest priority.
|
39
|
+
# Note: These default routes make all actions in every controller accessible via GET requests. You should
|
40
|
+
# consider removing or commenting them out if you're using named routes and resources.
|
41
|
+
map.connect ':controller/:action/:id'
|
42
|
+
map.connect ':controller/:action/:id.:format'
|
43
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
3
|
+
require 'test_help'
|
4
|
+
|
5
|
+
class ActiveSupport::TestCase
|
6
|
+
# Transactional fixtures accelerate your tests by wrapping each test method
|
7
|
+
# in a transaction that's rolled back on completion. This ensures that the
|
8
|
+
# test database remains unchanged so your fixtures don't have to be reloaded
|
9
|
+
# between every test method. Fewer database queries means faster tests.
|
10
|
+
#
|
11
|
+
# Read Mike Clark's excellent walkthrough at
|
12
|
+
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
|
13
|
+
#
|
14
|
+
# Every Active Record database supports transactions except MyISAM tables
|
15
|
+
# in MySQL. Turn off transactional fixtures in this case; however, if you
|
16
|
+
# don't care one way or the other, switching from MyISAM to InnoDB tables
|
17
|
+
# is recommended.
|
18
|
+
#
|
19
|
+
# The only drawback to using transactional fixtures is when you actually
|
20
|
+
# need to test transactions. Since your test is bracketed by a transaction,
|
21
|
+
# any transactions started in your code will be automatically rolled back.
|
22
|
+
self.use_transactional_fixtures = true
|
23
|
+
|
24
|
+
# Instantiated fixtures are slow, but give you @david where otherwise you
|
25
|
+
# would need people(:david). If you don't want to migrate your existing
|
26
|
+
# test cases which use the @david style and don't mind the speed hit (each
|
27
|
+
# instantiated fixtures translates to a database query per test method),
|
28
|
+
# then set this back to true.
|
29
|
+
self.use_instantiated_fixtures = false
|
30
|
+
|
31
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
32
|
+
#
|
33
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
34
|
+
# -- they do not yet inherit this setting
|
35
|
+
fixtures :all
|
36
|
+
|
37
|
+
# Add more helper methods to be used by all tests here...
|
38
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
|
2
2
|
# from the project root directory.
|
3
3
|
ENV["RAILS_ENV"] ||= 'test'
|
4
|
-
ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '
|
4
|
+
ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/rails_root'
|
5
5
|
require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb'))
|
6
|
+
require 'rubygems'
|
6
7
|
require 'spec'
|
7
8
|
require 'spec/rails'
|
8
9
|
|
10
|
+
require File.dirname(__FILE__) + "/../lib/jelly"
|
11
|
+
|
9
12
|
Spec::Runner.configure do |configuration|
|
10
13
|
end
|
11
14
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pivotal-jelly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pivotal Labs, Inc
|
@@ -9,11 +9,20 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-13 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.3.0
|
24
|
+
version:
|
25
|
+
description: Jelly provides a set of tools and conventions for creating rich ajax/javascript web applications with jQuery and Ruby on Rails.
|
17
26
|
email: opensource@pivotallabs.com
|
18
27
|
executables: []
|
19
28
|
|
@@ -33,17 +42,11 @@ files:
|
|
33
42
|
- generators/jelly/templates/javascripts/jelly.js
|
34
43
|
- generators/jelly/templates/javascripts/jquery/jquery-1.3.2.js
|
35
44
|
- generators/jelly/templates/javascripts/jquery/jquery.protify-0.3.js
|
36
|
-
- init.rb
|
37
45
|
- install.rb
|
38
|
-
-
|
39
|
-
- lib/
|
40
|
-
-
|
41
|
-
-
|
42
|
-
- spec/fixtures/pages/lions.js
|
43
|
-
- spec/fixtures/pages/tigers.js
|
44
|
-
- spec/helpers/jelly_helper_spec.rb
|
45
|
-
- spec/javascript/jelly_spec.js
|
46
|
-
- spec/spec_helper.rb
|
46
|
+
- jelly.gemspec
|
47
|
+
- lib/jelly.rb
|
48
|
+
- lib/jelly/jelly_controller.rb
|
49
|
+
- lib/jelly/jelly_helper.rb
|
47
50
|
- tasks/jelly_tasks.rake
|
48
51
|
- uninstall.rb
|
49
52
|
has_rdoc: false
|
@@ -76,4 +79,19 @@ summary: a sweet unobtrusive javascript framework for jQuery and Rails
|
|
76
79
|
test_files:
|
77
80
|
- spec/controllers/jelly_controller_spec.rb
|
78
81
|
- spec/helpers/jelly_helper_spec.rb
|
82
|
+
- spec/rails_root/app/controllers/application_controller.rb
|
83
|
+
- spec/rails_root/app/helpers/application_helper.rb
|
84
|
+
- spec/rails_root/config/boot.rb
|
85
|
+
- spec/rails_root/config/environment.rb
|
86
|
+
- spec/rails_root/config/environments/development.rb
|
87
|
+
- spec/rails_root/config/environments/production.rb
|
88
|
+
- spec/rails_root/config/environments/test.rb
|
89
|
+
- spec/rails_root/config/initializers/backtrace_silencers.rb
|
90
|
+
- spec/rails_root/config/initializers/inflections.rb
|
91
|
+
- spec/rails_root/config/initializers/mime_types.rb
|
92
|
+
- spec/rails_root/config/initializers/new_rails_defaults.rb
|
93
|
+
- spec/rails_root/config/initializers/session_store.rb
|
94
|
+
- spec/rails_root/config/routes.rb
|
95
|
+
- spec/rails_root/test/performance/browsing_test.rb
|
96
|
+
- spec/rails_root/test/test_helper.rb
|
79
97
|
- spec/spec_helper.rb
|
data/init.rb
DELETED
File without changes
|
File without changes
|
File without changes
|
@@ -1,61 +0,0 @@
|
|
1
|
-
Jelly.add("MyPage", {
|
2
|
-
on_my_method : function(){}
|
3
|
-
});
|
4
|
-
var page = Jelly.all["MyPage"];
|
5
|
-
|
6
|
-
var My = {};
|
7
|
-
My.Class = {on_my_method: function() {console.debug("foo bar")}};
|
8
|
-
|
9
|
-
describe("ajax_with_json_callback", function(){
|
10
|
-
beforeEach(function(){
|
11
|
-
new Mom();
|
12
|
-
});
|
13
|
-
|
14
|
-
describe("Initializer", function(){
|
15
|
-
beforeEach(function(){
|
16
|
-
spyOn($, 'ajax');
|
17
|
-
});
|
18
|
-
it("should set up params and call ajax", function(){
|
19
|
-
var our_token = "authenticity token";
|
20
|
-
window._token = our_token;
|
21
|
-
$.ajaxWithJelly({foo : 'bar', data: {bar : 'baz'}});
|
22
|
-
expect($.ajax).wasCalled();
|
23
|
-
var ajaxParams = ($.ajax).mostRecentCall.args[0];
|
24
|
-
expect(ajaxParams['dataType']).toEqual('json');
|
25
|
-
expect(ajaxParams['cache']).toBeFalsy();
|
26
|
-
expect(ajaxParams['success']).toEqual($.ajaxWithJelly.onSuccess);
|
27
|
-
expect(ajaxParams['foo']).toEqual('bar');
|
28
|
-
expect(ajaxParams['data']['authenticity_token']).toEqual(our_token);
|
29
|
-
expect(ajaxParams['data']['bar']).toEqual('baz');
|
30
|
-
expect(ajaxParams['type']).toEqual('POST');
|
31
|
-
});
|
32
|
-
|
33
|
-
it("should allow override of type", function(){
|
34
|
-
$.ajaxWithJelly({type : 'DELETE'});
|
35
|
-
expect($.ajax).wasCalled();
|
36
|
-
var ajaxParams = ($.ajax).mostRecentCall.args[0];
|
37
|
-
expect(ajaxParams['type']).toEqual('DELETE');
|
38
|
-
});
|
39
|
-
});
|
40
|
-
|
41
|
-
it("should call page.mymethod", function(){
|
42
|
-
spyOn(page, 'on_my_method');
|
43
|
-
$.ajaxWithJelly.onSuccess({
|
44
|
-
"arguments":["arg1", "arg2"],
|
45
|
-
"method":"on_my_method"
|
46
|
-
});
|
47
|
-
expect(page.on_my_method).wasCalled();
|
48
|
-
expect(page.on_my_method).wasCalledWith('arg1', 'arg2');
|
49
|
-
});
|
50
|
-
|
51
|
-
it("should call My.Class.mymethod", function(){
|
52
|
-
spyOn(My.Class, 'on_my_method');
|
53
|
-
$.ajaxWithJelly.onSuccess({
|
54
|
-
"arguments":["arg1", "arg2"],
|
55
|
-
"method":"on_my_method",
|
56
|
-
"on":"My.Class"
|
57
|
-
});
|
58
|
-
expect(My.Class.on_my_method).wasCalled();
|
59
|
-
expect(My.Class.on_my_method).wasCalledWith('arg1', 'arg2');
|
60
|
-
});
|
61
|
-
});
|