honkster-jelly 0.8.14 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/.bundle/config +3 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +10 -0
  4. data/Gemfile.lock +123 -0
  5. data/Rakefile +5 -5
  6. data/VERSION.yml +2 -2
  7. data/generators/jelly/templates/javascripts/ajax_with_jelly.js +1 -2
  8. data/jelly.gemspec +53 -46
  9. data/lib/jelly/jelly_controller.rb +1 -1
  10. data/spec/rails_root/.gitignore +4 -0
  11. data/spec/rails_root/lib/tasks/.gitkeep +0 -0
  12. data/spec/rails_root/public/stylesheets/.gitkeep +0 -0
  13. data/spec/rails_root/vendor/plugins/.gitkeep +0 -0
  14. metadata +106 -66
  15. data/.gitignore +0 -3
  16. data/spec/jelly/common_spec.rb +0 -56
  17. data/spec/jelly/jelly_controller_spec.rb +0 -327
  18. data/spec/jelly/jelly_helper_spec.rb +0 -88
  19. data/spec/rails_root/app/controllers/application_controller.rb +0 -10
  20. data/spec/rails_root/app/helpers/application_helper.rb +0 -3
  21. data/spec/rails_root/config/boot.rb +0 -110
  22. data/spec/rails_root/config/environment.rb +0 -41
  23. data/spec/rails_root/config/environments/development.rb +0 -17
  24. data/spec/rails_root/config/environments/production.rb +0 -28
  25. data/spec/rails_root/config/environments/test.rb +0 -28
  26. data/spec/rails_root/config/initializers/backtrace_silencers.rb +0 -7
  27. data/spec/rails_root/config/initializers/inflections.rb +0 -10
  28. data/spec/rails_root/config/initializers/mime_types.rb +0 -5
  29. data/spec/rails_root/config/initializers/new_rails_defaults.rb +0 -19
  30. data/spec/rails_root/config/initializers/session_store.rb +0 -15
  31. data/spec/rails_root/config/routes.rb +0 -43
  32. data/spec/rails_root/test/performance/browsing_test.rb +0 -9
  33. data/spec/rails_root/test/test_helper.rb +0 -38
  34. data/spec/spec_helper.rb +0 -42
  35. data/spec/spec_suite.rb +0 -3
data/.gitignore DELETED
@@ -1,3 +0,0 @@
1
- .idea
2
- *.svn
3
- pkg
@@ -1,56 +0,0 @@
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
@@ -1,327 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
2
-
3
- describe ApplicationController, :type => :controller do
4
-
5
- describe "#jelly_callback" do
6
- attr_reader :template
7
- before do
8
- stub(@controller).render do |params|
9
- @template = ActionView::Base.new(@controller.class.view_paths, {}, @controller)
10
- template.send(:_evaluate_assigns_and_ivars)
11
- response.body = ERB.new(params[:inline]).result(template.send(:binding))
12
- end
13
- end
14
-
15
- it "have the method included" do
16
- @controller.respond_to?(:jelly_callback).should be_true
17
- end
18
-
19
- describe "Arguments block" do
20
- describe "self" do
21
- it "runs with the binding of the ERB template" do
22
- self_in_block = nil
23
- @controller.send(:jelly_callback, 'foo', :format => :json) do
24
- self_in_block = self
25
- 12345
26
- end
27
- self_in_block.should == template
28
- end
29
- end
30
-
31
- context "when an Array is returned from the block" do
32
- it "sets the arguments to be an Array around the Hash" do
33
- @controller.send(:jelly_callback, 'foo', :format => :json) do
34
- ["foo", "bar"]
35
- end
36
- callback = JSON.parse(response.body)
37
- callback["method"].should == "on_foo"
38
- callback["arguments"].should == ["foo", "bar"]
39
- end
40
- end
41
-
42
- context "when a non-array is returned in the block" do
43
- context "when the argument is a Hash" do
44
- it "sets the arguments to be an Array around the Hash" do
45
- @controller.send(:jelly_callback, 'foo', :format => :json) do
46
- {"foo" => "bar"}
47
- end
48
- callback = JSON.parse(response.body)
49
- callback["method"].should == "on_foo"
50
- callback["arguments"].should == [{"foo" => "bar"}]
51
- end
52
- end
53
-
54
- context "when the argument is a String" do
55
- it "sets the arguments to be an Array around the argument" do
56
- @controller.send(:jelly_callback, 'foo', :format => :json) do
57
- "foobar"
58
- end
59
- callback = JSON.parse(response.body)
60
- callback["method"].should == "on_foo"
61
- callback["arguments"].should == ["foobar"]
62
- end
63
- end
64
-
65
- context "when the argument is a Number" do
66
- it "sets the arguments to be an Array around the argument" do
67
- @controller.send(:jelly_callback, 'foo', :format => :json) do
68
- 12345
69
- end
70
- callback = JSON.parse(response.body)
71
- callback["method"].should == "on_foo"
72
- callback["arguments"].should == [12345]
73
- end
74
- end
75
- end
76
- end
77
-
78
- context "when given a format" do
79
- describe "json" do
80
- it "responds with a json hash, even if the request is not xhr" do
81
- stub(request).xhr? {false}
82
-
83
- @controller.send(:jelly_callback, 'foo', {'format' => :json, 'bar' => 'baz'}) do
84
- "grape"
85
- end
86
- callback = JSON.parse(response.body)
87
- callback["method"].should == "on_foo"
88
- callback["arguments"].should == ["grape"]
89
- callback["bar"].should == "baz"
90
- end
91
- end
92
-
93
- describe "jsonp" do
94
- it "responds with a jsonp callback based on the callback param" do
95
- @controller.params[:callback] = "Jelly.notifyObservers"
96
-
97
- @controller.send(:jelly_callback, 'foo', {'format' => :jsonp, 'bar' => 'baz'}) do
98
- "grape"
99
- end
100
- json = Regexp.new('Jelly\.notifyObservers\((.*)\);').match(response.body)[1]
101
- callback = JSON.parse(json)
102
- callback["method"].should == "on_foo"
103
- callback["arguments"].should == ["grape"]
104
- callback["bar"].should == "baz"
105
- end
106
- end
107
-
108
- describe "iframe" do
109
- it "responds with a the json in a textarea tag" do
110
- @controller.send(:jelly_callback, 'foo', {'format' => :iframe, 'bar' => 'baz'}) do
111
- "grape"
112
- end
113
- body = response.body
114
- body.should =~ /^<textarea>/
115
- body.should =~ /<\/textarea>$/
116
- doc = Nokogiri::HTML(body)
117
-
118
- callback = JSON.parse(doc.at("textarea").inner_html)
119
- callback["method"].should == "on_foo"
120
- callback["arguments"].should == ["grape"]
121
- callback["bar"].should == "baz"
122
- end
123
- end
124
- end
125
-
126
- context "when there is a callback param" do
127
- before do
128
- @controller.params[:callback] = "Jelly.notifyObservers"
129
- end
130
-
131
- context "when the request is XHR" do
132
- before do
133
- stub(request).xhr? {true}
134
- end
135
-
136
- it "responds with a call to the given callback method with the json as an argument" do
137
- @controller.send(:jelly_callback, 'foo', {'bar' => 'baz'}) do
138
- "grape"
139
- end
140
- json = Regexp.new('Jelly\.notifyObservers\((.*)\);').match(response.body)[1]
141
- callback = JSON.parse(json)
142
- callback["method"].should == "on_foo"
143
- callback["arguments"].should == ["grape"]
144
- callback["bar"].should == "baz"
145
- end
146
- end
147
-
148
- context "when the request is not XHR" do
149
- before do
150
- stub(request).xhr? {false}
151
- end
152
-
153
- it "responds with a call to the given callback method with the json as an argument" do
154
- @controller.send(:jelly_callback, 'foo', {'bar' => 'baz'}) do
155
- "grape"
156
- end
157
- json = Regexp.new('Jelly\.notifyObservers\((.*)\);').match(response.body)[1]
158
- callback = JSON.parse(json)
159
- callback["method"].should == "on_foo"
160
- callback["arguments"].should == ["grape"]
161
- callback["bar"].should == "baz"
162
- end
163
- end
164
- end
165
-
166
- context "when there is not a callback param" do
167
- context "when the request is XHR" do
168
- before do
169
- stub(request).xhr? {true}
170
- end
171
-
172
- it "responds with a json hash" do
173
- @controller.send(:jelly_callback, 'foo', {'bar' => 'baz'}) do
174
- "grape"
175
- end
176
- callback = JSON.parse(response.body)
177
- callback["method"].should == "on_foo"
178
- callback["arguments"].should == ["grape"]
179
- callback["bar"].should == "baz"
180
- end
181
-
182
- end
183
-
184
- context "when the request is not XHR" do
185
- before do
186
- stub(request).xhr? {false}
187
- end
188
-
189
- context "when there is not a callback param" do
190
- 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
191
- @controller.send(:jelly_callback, 'foo', {'bar' => 'baz'}) do
192
- "grape"
193
- end
194
- body = response.body
195
- body.should =~ /^<textarea>/
196
- body.should =~ /<\/textarea>$/
197
- doc = Nokogiri::HTML(body)
198
-
199
- callback = JSON.parse(doc.at("textarea").inner_html)
200
- callback["method"].should == "on_foo"
201
- callback["arguments"].should == ["grape"]
202
- callback["bar"].should == "baz"
203
- end
204
- end
205
- end
206
- end
207
- end
208
-
209
- describe "#raw_jelly_callback" do
210
- attr_reader :response
211
- before do
212
- @response = Struct.new(:body).new
213
- stub(@controller).render do |params|
214
- response.body = ERB.new(params[:inline]).result(@controller.send(:binding))
215
- end
216
- end
217
-
218
- it "have the method included" do
219
- @controller.respond_to?(:raw_jelly_callback).should be_true
220
- end
221
-
222
- context "when given a format" do
223
- describe "json" do
224
- it "responds with a json hash, even if the request is not xhr" do
225
- stub(request).xhr? {false}
226
-
227
- @controller.send(:raw_jelly_callback, :format => :json) do
228
- jelly_notify_hash("foo", "grape").merge('bar' => 'baz')
229
- end
230
- callback = JSON.parse(response.body)
231
- callback["method"].should == "foo"
232
- callback["arguments"].should == ["grape"]
233
- callback["bar"].should == "baz"
234
- end
235
- end
236
-
237
- describe "jsonp" do
238
- it "responds with a jsonp callback based on the callback param" do
239
- @controller.params[:callback] = "Jelly.notifyObservers"
240
-
241
- @controller.send(:raw_jelly_callback, :format => :jsonp) do
242
- jelly_notify_hash("foo", "grape").merge('bar' => 'baz')
243
- end
244
- json = Regexp.new('Jelly\.notifyObservers\((.*)\);').match(response.body)[1]
245
- callback = JSON.parse(json)
246
- callback["method"].should == "foo"
247
- callback["arguments"].should == ["grape"]
248
- callback["bar"].should == "baz"
249
- end
250
- end
251
-
252
- describe "iframe" do
253
- it "responds with a the json in a textarea tag" do
254
- @controller.send(:raw_jelly_callback, :format => :iframe) do
255
- jelly_notify_hash("foo", "grape").merge('bar' => 'baz')
256
- end
257
- body = response.body
258
- body.should =~ /^<textarea>/
259
- body.should =~ /<\/textarea>$/
260
- doc = Nokogiri::HTML(body)
261
-
262
- callback = JSON.parse(doc.at("textarea").inner_html)
263
- callback["method"].should == "foo"
264
- callback["arguments"].should == ["grape"]
265
- callback["bar"].should == "baz"
266
- end
267
- end
268
- end
269
-
270
- context "when the request is XHR" do
271
- before do
272
- stub(request).xhr? {true}
273
- end
274
-
275
- it "responds with a json hash" do
276
- @controller.send(:raw_jelly_callback) do
277
- jelly_notify_hash("foo", "grape").merge('bar' => 'baz')
278
- end
279
- callback = JSON.parse(response.body)
280
- callback["method"].should == "foo"
281
- callback["arguments"].should == ["grape"]
282
- callback["bar"].should == "baz"
283
- end
284
-
285
- end
286
-
287
- context "when the request is not XHR" do
288
- before do
289
- stub(request).xhr? {false}
290
- end
291
-
292
- context "when there is a callback param" do
293
- before do
294
- @controller.params[:callback] = "Jelly.notifyObservers"
295
- end
296
-
297
- it "responds with a call to the given callback method with the json as an argument" do
298
- @controller.send(:raw_jelly_callback) do
299
- jelly_notify_hash("foo", "grape").merge('bar' => 'baz')
300
- end
301
- json = Regexp.new('Jelly\.notifyObservers\((.*)\);').match(response.body)[1]
302
- callback = JSON.parse(json)
303
- callback["method"].should == "foo"
304
- callback["arguments"].should == ["grape"]
305
- callback["bar"].should == "baz"
306
- end
307
- end
308
-
309
- context "when there is not a callback param" do
310
- 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
311
- @controller.send(:raw_jelly_callback) do
312
- jelly_notify_hash("foo", "grape").merge('bar' => 'baz')
313
- end
314
- body = response.body
315
- body.should =~ /^<textarea>/
316
- body.should =~ /<\/textarea>$/
317
- doc = Nokogiri::HTML(body)
318
-
319
- callback = JSON.parse(doc.at("textarea").inner_html)
320
- callback["method"].should == "foo"
321
- callback["arguments"].should == ["grape"]
322
- callback["bar"].should == "baz"
323
- end
324
- end
325
- end
326
- end
327
- end
@@ -1,88 +0,0 @@
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
- assigns[: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 $(document).ready block" do
71
- helper.attach_javascript_component("MyComponent", 'arg1', 'arg2', 'arg3')
72
- expected_args = ['arg1','arg2','arg3'].to_json
73
- assigns[: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("$(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