honkster-jelly 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +1 -2
- data/Gemfile.lock +1 -1
- data/Rakefile +0 -16
- data/jelly.gemspec +13 -64
- data/lib/jelly/jelly_helper.rb +1 -1
- data/spec/fixtures/public/javascripts/components/component1.js +0 -0
- data/spec/fixtures/public/javascripts/foo/components/paw.js +0 -0
- data/spec/fixtures/public/javascripts/foo/components/teeth.js +0 -0
- data/spec/fixtures/public/javascripts/foo/pages/bears.js +0 -0
- data/spec/fixtures/public/javascripts/foo/pages/lions.js +0 -0
- data/spec/fixtures/public/javascripts/foo/pages/tigers.js +0 -0
- data/spec/fixtures/public/javascripts/pages/page1.js +0 -0
- data/spec/jasmine/TrivialReporter.js +129 -0
- data/spec/jasmine/jasmine-0.10.0.js +2149 -0
- data/spec/jasmine/jasmine.css +76 -0
- data/spec/jasmine/json2.js +478 -0
- data/spec/jasmine_runner.html +30 -0
- data/spec/javascript/ajax_with_jelly_spec.js +157 -0
- data/spec/javascript/jelly_spec.js +649 -0
- data/spec/javascript/spec_helper.js +7 -0
- data/spec/jelly/common_spec.rb +56 -0
- data/spec/jelly/jelly_controller_spec.rb +331 -0
- data/spec/jelly/jelly_helper_spec.rb +88 -0
- data/spec/rails_root/Gemfile +31 -0
- data/spec/rails_root/Gemfile.lock +73 -0
- data/spec/rails_root/README +256 -0
- data/spec/rails_root/Rakefile +7 -0
- data/spec/rails_root/app/controllers/application_controller.rb +3 -0
- data/spec/rails_root/app/helpers/application_helper.rb +2 -0
- data/spec/rails_root/app/views/layouts/application.html.erb +14 -0
- data/spec/rails_root/config.ru +4 -0
- data/spec/rails_root/config/application.rb +42 -0
- data/spec/rails_root/config/boot.rb +6 -0
- data/spec/rails_root/config/database.yml +22 -0
- data/spec/rails_root/config/environment.rb +5 -0
- data/spec/rails_root/config/environments/development.rb +26 -0
- data/spec/rails_root/config/environments/production.rb +49 -0
- data/spec/rails_root/config/environments/test.rb +35 -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/secret_token.rb +7 -0
- data/spec/rails_root/config/initializers/session_store.rb +8 -0
- data/spec/rails_root/config/locales/en.yml +5 -0
- data/spec/rails_root/config/routes.rb +58 -0
- data/spec/rails_root/db/seeds.rb +7 -0
- data/spec/rails_root/db/test.sqlite3 +1 -0
- data/spec/rails_root/doc/README_FOR_APP +2 -0
- data/spec/rails_root/log/development.log +0 -0
- data/spec/rails_root/log/production.log +0 -0
- data/spec/rails_root/log/server.log +0 -0
- data/spec/rails_root/log/test.log +6 -0
- data/spec/rails_root/public/404.html +26 -0
- data/spec/rails_root/public/422.html +26 -0
- data/spec/rails_root/public/500.html +26 -0
- data/spec/rails_root/public/favicon.ico +0 -0
- data/spec/rails_root/public/images/rails.png +0 -0
- data/spec/rails_root/public/index.html +239 -0
- data/spec/rails_root/public/javascripts/application.js +2 -0
- data/spec/rails_root/public/javascripts/controls.js +965 -0
- data/spec/rails_root/public/javascripts/dragdrop.js +974 -0
- data/spec/rails_root/public/javascripts/effects.js +1123 -0
- data/spec/rails_root/public/javascripts/prototype.js +6001 -0
- data/spec/rails_root/public/javascripts/rails.js +191 -0
- data/spec/rails_root/public/robots.txt +5 -0
- data/spec/rails_root/script/about +4 -0
- data/spec/rails_root/script/console +3 -0
- data/spec/rails_root/script/dbconsole +3 -0
- data/spec/rails_root/script/destroy +3 -0
- data/spec/rails_root/script/generate +3 -0
- data/spec/rails_root/script/performance/benchmarker +3 -0
- data/spec/rails_root/script/performance/profiler +3 -0
- data/spec/rails_root/script/plugin +3 -0
- data/spec/rails_root/script/rails +6 -0
- data/spec/rails_root/script/runner +3 -0
- data/spec/rails_root/script/server +3 -0
- data/spec/rails_root/test/performance/browsing_test.rb +9 -0
- data/spec/rails_root/test/test_helper.rb +13 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/spec_suite.rb +3 -0
- metadata +271 -46
- data/VERSION.yml +0 -5
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
2
|
+
|
3
|
+
describe Jelly::Common do
|
4
|
+
attr_reader :fixture
|
5
|
+
before do
|
6
|
+
@fixture = Class.new do
|
7
|
+
include Jelly::Common
|
8
|
+
end.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#jelly_notify_hash" do
|
12
|
+
it "creates a hash with a method and arguments" do
|
13
|
+
fixture.jelly_notify_hash("my_method", 1, 2, 3).should == {
|
14
|
+
"method" => "my_method",
|
15
|
+
"arguments" => [1, 2, 3]
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#jelly_method_call_hash" do
|
21
|
+
it "creates a hash with a object, method, and arguments" do
|
22
|
+
fixture.jelly_method_call_hash("MyObject", "my_method", 1, 2, 3).should == {
|
23
|
+
"on" => "MyObject",
|
24
|
+
"method" => "my_method",
|
25
|
+
"arguments" => [1, 2, 3]
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#jelly_callback_attach_hash" do
|
31
|
+
context "when passed attachments" do
|
32
|
+
it "creates a hash with the attach param being set to the given attachments" do
|
33
|
+
attachments = [
|
34
|
+
fixture.jelly_attachment_hash("Foo", 1, 2),
|
35
|
+
fixture.jelly_attachment_hash("Bar", 3),
|
36
|
+
]
|
37
|
+
fixture.jelly_notify_attach_hash(attachments).should == {
|
38
|
+
"attach" => attachments
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when not passed attachments" do
|
44
|
+
it "creates a hash with the attach param being set to #jelly_attachments" do
|
45
|
+
attachments = [
|
46
|
+
fixture.jelly_attachment_hash("Foo", 1, 2),
|
47
|
+
fixture.jelly_attachment_hash("Bar", 3),
|
48
|
+
]
|
49
|
+
stub(fixture).jelly_attachments {attachments}
|
50
|
+
fixture.jelly_notify_attach_hash.should == {
|
51
|
+
"attach" => attachments
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,331 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
2
|
+
|
3
|
+
describe ApplicationController, :type => :controller do
|
4
|
+
render_views
|
5
|
+
include ActionController::Testing
|
6
|
+
|
7
|
+
describe "#jelly_callback" do
|
8
|
+
attr_reader :template
|
9
|
+
before do
|
10
|
+
stub(@controller).render do |params|
|
11
|
+
@template = @controller.view_context
|
12
|
+
@controller.instance_variables.each do |var|
|
13
|
+
@template.instance_variable_set(var, @controller.instance_variable_get(var))
|
14
|
+
end
|
15
|
+
response.body = @template.render(params)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "have the method included" do
|
20
|
+
@controller.respond_to?(:jelly_callback).should be_true
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "Arguments block" do
|
24
|
+
describe "self" do
|
25
|
+
it "runs with the binding of the ERB template" do
|
26
|
+
self_in_block = nil
|
27
|
+
@controller.send(:jelly_callback, 'foo', :format => :json) do
|
28
|
+
self_in_block = self
|
29
|
+
12345
|
30
|
+
end
|
31
|
+
self_in_block.should == template
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when an Array is returned from the block" do
|
36
|
+
it "sets the arguments to be an Array around the Hash" do
|
37
|
+
@controller.send(:jelly_callback, 'foo', :format => :json) do
|
38
|
+
["foo", "bar"]
|
39
|
+
end
|
40
|
+
callback = JSON.parse(response.body)
|
41
|
+
callback["method"].should == "on_foo"
|
42
|
+
callback["arguments"].should == ["foo", "bar"]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when a non-array is returned in the block" do
|
47
|
+
context "when the argument is a Hash" do
|
48
|
+
it "sets the arguments to be an Array around the Hash" do
|
49
|
+
@controller.send(:jelly_callback, 'foo', :format => :json) do
|
50
|
+
{"foo" => "bar"}
|
51
|
+
end
|
52
|
+
callback = JSON.parse(response.body)
|
53
|
+
callback["method"].should == "on_foo"
|
54
|
+
callback["arguments"].should == [{"foo" => "bar"}]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when the argument is a String" do
|
59
|
+
it "sets the arguments to be an Array around the argument" do
|
60
|
+
@controller.send(:jelly_callback, 'foo', :format => :json) do
|
61
|
+
"foobar"
|
62
|
+
end
|
63
|
+
callback = JSON.parse(response.body)
|
64
|
+
callback["method"].should == "on_foo"
|
65
|
+
callback["arguments"].should == ["foobar"]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when the argument is a Number" do
|
70
|
+
it "sets the arguments to be an Array around the argument" do
|
71
|
+
@controller.send(:jelly_callback, 'foo', :format => :json) do
|
72
|
+
12345
|
73
|
+
end
|
74
|
+
callback = JSON.parse(response.body)
|
75
|
+
callback["method"].should == "on_foo"
|
76
|
+
callback["arguments"].should == [12345]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when given a format" do
|
83
|
+
describe "json" do
|
84
|
+
it "responds with a json hash, even if the request is not xhr" do
|
85
|
+
stub(request).xhr? {false}
|
86
|
+
|
87
|
+
@controller.send(:jelly_callback, 'foo', {'format' => :json, 'bar' => 'baz'}) do
|
88
|
+
"grape"
|
89
|
+
end
|
90
|
+
callback = JSON.parse(response.body)
|
91
|
+
callback["method"].should == "on_foo"
|
92
|
+
callback["arguments"].should == ["grape"]
|
93
|
+
callback["bar"].should == "baz"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "jsonp" do
|
98
|
+
it "responds with a jsonp callback based on the callback param" do
|
99
|
+
@controller.params[:callback] = "Jelly.notifyObservers"
|
100
|
+
|
101
|
+
@controller.send(:jelly_callback, 'foo', {'format' => :jsonp, 'bar' => 'baz'}) do
|
102
|
+
"grape"
|
103
|
+
end
|
104
|
+
json = Regexp.new('Jelly\.notifyObservers\((.*)\);').match(response.body)[1]
|
105
|
+
callback = JSON.parse(json)
|
106
|
+
callback["method"].should == "on_foo"
|
107
|
+
callback["arguments"].should == ["grape"]
|
108
|
+
callback["bar"].should == "baz"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "iframe" do
|
113
|
+
it "responds with a the json in a textarea tag" do
|
114
|
+
@controller.send(:jelly_callback, 'foo', {'format' => :iframe, 'bar' => 'baz'}) do
|
115
|
+
"grape"
|
116
|
+
end
|
117
|
+
body = response.body
|
118
|
+
body.should =~ /^<textarea>/
|
119
|
+
body.should =~ /<\/textarea>$/
|
120
|
+
doc = Nokogiri::HTML(body)
|
121
|
+
|
122
|
+
callback = JSON.parse(doc.at("textarea").inner_html)
|
123
|
+
callback["method"].should == "on_foo"
|
124
|
+
callback["arguments"].should == ["grape"]
|
125
|
+
callback["bar"].should == "baz"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context "when there is a callback param" do
|
131
|
+
before do
|
132
|
+
@controller.params[:callback] = "Jelly.notifyObservers"
|
133
|
+
end
|
134
|
+
|
135
|
+
context "when the request is XHR" do
|
136
|
+
before do
|
137
|
+
stub(request).xhr? {true}
|
138
|
+
end
|
139
|
+
|
140
|
+
it "responds with a call to the given callback method with the json as an argument" do
|
141
|
+
@controller.send(:jelly_callback, 'foo', {'bar' => 'baz'}) do
|
142
|
+
"grape"
|
143
|
+
end
|
144
|
+
json = Regexp.new('Jelly\.notifyObservers\((.*)\);').match(response.body)[1]
|
145
|
+
callback = JSON.parse(json)
|
146
|
+
callback["method"].should == "on_foo"
|
147
|
+
callback["arguments"].should == ["grape"]
|
148
|
+
callback["bar"].should == "baz"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context "when the request is not XHR" do
|
153
|
+
before do
|
154
|
+
stub(request).xhr? {false}
|
155
|
+
end
|
156
|
+
|
157
|
+
it "responds with a call to the given callback method with the json as an argument" do
|
158
|
+
@controller.send(:jelly_callback, 'foo', {'bar' => 'baz'}) do
|
159
|
+
"grape"
|
160
|
+
end
|
161
|
+
json = Regexp.new('Jelly\.notifyObservers\((.*)\);').match(response.body)[1]
|
162
|
+
callback = JSON.parse(json)
|
163
|
+
callback["method"].should == "on_foo"
|
164
|
+
callback["arguments"].should == ["grape"]
|
165
|
+
callback["bar"].should == "baz"
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context "when there is not a callback param" do
|
171
|
+
context "when the request is XHR" do
|
172
|
+
before do
|
173
|
+
stub(request).xhr? {true}
|
174
|
+
end
|
175
|
+
|
176
|
+
it "responds with a json hash" do
|
177
|
+
@controller.send(:jelly_callback, 'foo', {'bar' => 'baz'}) do
|
178
|
+
"grape"
|
179
|
+
end
|
180
|
+
callback = JSON.parse(response.body)
|
181
|
+
callback["method"].should == "on_foo"
|
182
|
+
callback["arguments"].should == ["grape"]
|
183
|
+
callback["bar"].should == "baz"
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
context "when the request is not XHR" do
|
189
|
+
before do
|
190
|
+
stub(request).xhr? {false}
|
191
|
+
end
|
192
|
+
|
193
|
+
context "when there is not a callback param" do
|
194
|
+
it "wraps the json response in a textarea tag to support File Uploads in an iframe target (see: http://malsup.com/jquery/form/#code-samples)" do
|
195
|
+
@controller.send(:jelly_callback, 'foo', {'bar' => 'baz'}) do
|
196
|
+
"grape"
|
197
|
+
end
|
198
|
+
body = response.body
|
199
|
+
body.should =~ /^<textarea>/
|
200
|
+
body.should =~ /<\/textarea>$/
|
201
|
+
doc = Nokogiri::HTML(body)
|
202
|
+
|
203
|
+
callback = JSON.parse(doc.at("textarea").inner_html)
|
204
|
+
callback["method"].should == "on_foo"
|
205
|
+
callback["arguments"].should == ["grape"]
|
206
|
+
callback["bar"].should == "baz"
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe "#raw_jelly_callback" do
|
214
|
+
attr_reader :response
|
215
|
+
before do
|
216
|
+
@response = Struct.new(:body).new
|
217
|
+
stub(@controller).render do |params|
|
218
|
+
response.body = ERB.new(params[:inline]).result(@controller.send(:binding))
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
it "have the method included" do
|
223
|
+
@controller.respond_to?(:raw_jelly_callback).should be_true
|
224
|
+
end
|
225
|
+
|
226
|
+
context "when given a format" do
|
227
|
+
describe "json" do
|
228
|
+
it "responds with a json hash, even if the request is not xhr" do
|
229
|
+
stub(request).xhr? {false}
|
230
|
+
|
231
|
+
@controller.send(:raw_jelly_callback, :format => :json) do
|
232
|
+
@controller.jelly_notify_hash("foo", "grape").merge('bar' => 'baz')
|
233
|
+
end
|
234
|
+
callback = JSON.parse(response.body)
|
235
|
+
callback["method"].should == "foo"
|
236
|
+
callback["arguments"].should == ["grape"]
|
237
|
+
callback["bar"].should == "baz"
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
describe "jsonp" do
|
242
|
+
it "responds with a jsonp callback based on the callback param" do
|
243
|
+
@controller.params[:callback] = "Jelly.notifyObservers"
|
244
|
+
|
245
|
+
@controller.send(:raw_jelly_callback, :format => :jsonp) do
|
246
|
+
@controller.jelly_notify_hash("foo", "grape").merge('bar' => 'baz')
|
247
|
+
end
|
248
|
+
json = Regexp.new('Jelly\.notifyObservers\((.*)\);').match(response.body)[1]
|
249
|
+
callback = JSON.parse(json)
|
250
|
+
callback["method"].should == "foo"
|
251
|
+
callback["arguments"].should == ["grape"]
|
252
|
+
callback["bar"].should == "baz"
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
describe "iframe" do
|
257
|
+
it "responds with a the json in a textarea tag" do
|
258
|
+
@controller.send(:raw_jelly_callback, :format => :iframe) do
|
259
|
+
@controller.jelly_notify_hash("foo", "grape").merge('bar' => 'baz')
|
260
|
+
end
|
261
|
+
body = response.body
|
262
|
+
body.should =~ /^<textarea>/
|
263
|
+
body.should =~ /<\/textarea>$/
|
264
|
+
doc = Nokogiri::HTML(body)
|
265
|
+
|
266
|
+
callback = JSON.parse(doc.at("textarea").inner_html)
|
267
|
+
callback["method"].should == "foo"
|
268
|
+
callback["arguments"].should == ["grape"]
|
269
|
+
callback["bar"].should == "baz"
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
context "when the request is XHR" do
|
275
|
+
before do
|
276
|
+
stub(request).xhr? {true}
|
277
|
+
end
|
278
|
+
|
279
|
+
it "responds with a json hash" do
|
280
|
+
@controller.send(:raw_jelly_callback) do
|
281
|
+
@controller.jelly_notify_hash("foo", "grape").merge('bar' => 'baz')
|
282
|
+
end
|
283
|
+
callback = JSON.parse(response.body)
|
284
|
+
callback["method"].should == "foo"
|
285
|
+
callback["arguments"].should == ["grape"]
|
286
|
+
callback["bar"].should == "baz"
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
290
|
+
|
291
|
+
context "when the request is not XHR" do
|
292
|
+
before do
|
293
|
+
stub(request).xhr? {false}
|
294
|
+
end
|
295
|
+
|
296
|
+
context "when there is a callback param" do
|
297
|
+
before do
|
298
|
+
@controller.params[:callback] = "Jelly.notifyObservers"
|
299
|
+
end
|
300
|
+
|
301
|
+
it "responds with a call to the given callback method with the json as an argument" do
|
302
|
+
@controller.send(:raw_jelly_callback) do
|
303
|
+
@controller.jelly_notify_hash("foo", "grape").merge('bar' => 'baz')
|
304
|
+
end
|
305
|
+
json = Regexp.new('Jelly\.notifyObservers\((.*)\);').match(response.body)[1]
|
306
|
+
callback = JSON.parse(json)
|
307
|
+
callback["method"].should == "foo"
|
308
|
+
callback["arguments"].should == ["grape"]
|
309
|
+
callback["bar"].should == "baz"
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
context "when there is not a callback param" do
|
314
|
+
it "wraps the json response in a textarea tag to support File Uploads in an iframe target (see: http://malsup.com/jquery/form/#code-samples)" do
|
315
|
+
@controller.send(:raw_jelly_callback) do
|
316
|
+
@controller.jelly_notify_hash("foo", "grape").merge('bar' => 'baz')
|
317
|
+
end
|
318
|
+
body = response.body
|
319
|
+
body.should =~ /^<textarea>/
|
320
|
+
body.should =~ /<\/textarea>$/
|
321
|
+
doc = Nokogiri::HTML(body)
|
322
|
+
|
323
|
+
callback = JSON.parse(doc.at("textarea").inner_html)
|
324
|
+
callback["method"].should == "foo"
|
325
|
+
callback["arguments"].should == ["grape"]
|
326
|
+
callback["bar"].should == "baz"
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
2
|
+
|
3
|
+
describe JellyHelper, :type => :helper do
|
4
|
+
|
5
|
+
def jelly_attach_arguments(html)
|
6
|
+
JSON.parse(Regexp.new('Jelly\.attach\.apply\(Jelly, (.*)\);').match(html)[1])
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#spread_jelly" do
|
10
|
+
before do
|
11
|
+
stub_controller = mock! do |controller|
|
12
|
+
controller.controller_path {'my_fun_controller'}
|
13
|
+
controller.action_name {'super_good_action'}
|
14
|
+
end
|
15
|
+
stub(helper).controller {stub_controller}
|
16
|
+
mock(helper).form_authenticity_token {'areallysecuretoken'}
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should create a javascript include tag that attaches the Jelly.Location and Jelly.Page components" do
|
20
|
+
output = helper.spread_jelly
|
21
|
+
output.should include('<script type="text/javascript">')
|
22
|
+
doc = Nokogiri::HTML(output)
|
23
|
+
argument = jelly_attach_arguments(doc.css("script")[1].inner_html)
|
24
|
+
argument.should include({'component' => "Jelly.Location", 'arguments' => []})
|
25
|
+
argument.should include({'component' => "Jelly.Page", 'arguments' => ['MyFunController', 'super_good_action']})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#application_jelly_files" do
|
30
|
+
context "when passing in a jelly path" do
|
31
|
+
it "returns the javascript files in /javascipts/:jelly_path/pages and /javascipts/:jelly_path/components" do
|
32
|
+
my_rails_root = File.join(File.dirname(__FILE__), '/../fixtures')
|
33
|
+
files = helper.application_jelly_files("foo", my_rails_root)
|
34
|
+
files.should_not be_empty
|
35
|
+
files.should =~ ['foo/components/paw', 'foo/components/teeth', 'foo/pages/lions', 'foo/pages/tigers', 'foo/pages/bears']
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when not passing in a jelly path" do
|
40
|
+
it "returns the javascript files in /javascipts/pages and /javascipts/components" do
|
41
|
+
my_rails_root = File.join(File.dirname(__FILE__), '/../fixtures')
|
42
|
+
files = helper.application_jelly_files("", my_rails_root)
|
43
|
+
files.should_not be_empty
|
44
|
+
files.should =~ ['components/component1', 'pages/page1']
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#attach_javascript_component" do
|
50
|
+
before do
|
51
|
+
def helper.form_authenticity_token
|
52
|
+
"12345"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
after do
|
57
|
+
helper.clear_jelly_attached()
|
58
|
+
end
|
59
|
+
|
60
|
+
it "fails to add multiple calls to Jelly.attach for the same component" do
|
61
|
+
helper.attach_javascript_component("MyComponent", 'arg1', 'arg2', 'arg3')
|
62
|
+
helper.attach_javascript_component("MyComponent", 'arg1', 'arg2', 'arg3')
|
63
|
+
helper.attach_javascript_component("MyComponent", 'arg1', 'arg2', 'arg5')
|
64
|
+
helper.instance_variable_get(:@jelly_attachments).should == [
|
65
|
+
{'component' => "MyComponent", 'arguments' => ['arg1', 'arg2', 'arg3']},
|
66
|
+
{'component' => "MyComponent", 'arguments' => ['arg1', 'arg2', 'arg5']},
|
67
|
+
]
|
68
|
+
end
|
69
|
+
|
70
|
+
it "adds a call to Jelly.attach in an jQuery(document).ready block" do
|
71
|
+
helper.attach_javascript_component("MyComponent", 'arg1', 'arg2', 'arg3')
|
72
|
+
expected_args = ['arg1','arg2','arg3'].to_json
|
73
|
+
helper.instance_variable_get(:@jelly_attachments).should == [
|
74
|
+
{'component' => "MyComponent", 'arguments' => ['arg1', 'arg2', 'arg3']}
|
75
|
+
]
|
76
|
+
|
77
|
+
html = helper.spread_jelly
|
78
|
+
doc = Nokogiri::HTML(html)
|
79
|
+
document_ready_tag = doc.css("script")[1]
|
80
|
+
document_ready_tag.inner_html.should include("jQuery(document).ready(function() {")
|
81
|
+
document_ready_part = document_ready_tag.inner_html.split("\n")[3]
|
82
|
+
arguments = jelly_attach_arguments(document_ready_part)
|
83
|
+
arguments.should include({'component' => "MyComponent", 'arguments' => ['arg1', 'arg2', 'arg3']})
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|