pancake 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. data/LICENSE +20 -0
  2. data/README.textile +95 -0
  3. data/Rakefile +56 -0
  4. data/TODO +17 -0
  5. data/bin/jeweler +19 -0
  6. data/bin/pancake-gen +17 -0
  7. data/bin/rubyforge +19 -0
  8. data/lib/pancake/bootloaders.rb +180 -0
  9. data/lib/pancake/configuration.rb +145 -0
  10. data/lib/pancake/constants.rb +5 -0
  11. data/lib/pancake/core_ext/class.rb +44 -0
  12. data/lib/pancake/core_ext/object.rb +22 -0
  13. data/lib/pancake/core_ext/symbol.rb +15 -0
  14. data/lib/pancake/defaults/configuration.rb +22 -0
  15. data/lib/pancake/defaults/middlewares.rb +1 -0
  16. data/lib/pancake/errors.rb +61 -0
  17. data/lib/pancake/generators/base.rb +12 -0
  18. data/lib/pancake/generators/micro_generator.rb +17 -0
  19. data/lib/pancake/generators/short_generator.rb +17 -0
  20. data/lib/pancake/generators/stack_generator.rb +17 -0
  21. data/lib/pancake/generators/templates/common/dotgitignore +22 -0
  22. data/lib/pancake/generators/templates/common/dothtaccess +17 -0
  23. data/lib/pancake/generators/templates/micro/%stack_name%/%stack_name%.rb.tt +8 -0
  24. data/lib/pancake/generators/templates/micro/%stack_name%/config.ru.tt +12 -0
  25. data/lib/pancake/generators/templates/micro/%stack_name%/pancake.init.tt +1 -0
  26. data/lib/pancake/generators/templates/micro/%stack_name%/public/.empty_directory +0 -0
  27. data/lib/pancake/generators/templates/micro/%stack_name%/tmp/.empty_directory +0 -0
  28. data/lib/pancake/generators/templates/micro/%stack_name%/views/root.html.haml +1 -0
  29. data/lib/pancake/generators/templates/short/%stack_name%/LICENSE.tt +20 -0
  30. data/lib/pancake/generators/templates/short/%stack_name%/README.tt +7 -0
  31. data/lib/pancake/generators/templates/short/%stack_name%/Rakefile.tt +50 -0
  32. data/lib/pancake/generators/templates/short/%stack_name%/VERSION.tt +1 -0
  33. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/%stack_name%.rb.tt +6 -0
  34. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/config.ru.tt +10 -0
  35. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/mounts/.empty_directory +0 -0
  36. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/public/.empty_directory +0 -0
  37. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/tmp/.empty_directory +0 -0
  38. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/views/root.html.haml +2 -0
  39. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%.rb.tt +5 -0
  40. data/lib/pancake/generators/templates/short/%stack_name%/pancake.init.tt +1 -0
  41. data/lib/pancake/generators/templates/short/%stack_name%/spec/%stack_name%_spec.rb.tt +7 -0
  42. data/lib/pancake/generators/templates/short/%stack_name%/spec/spec_helper.rb.tt +9 -0
  43. data/lib/pancake/generators/templates/stack/%stack_name%/LICENSE.tt +20 -0
  44. data/lib/pancake/generators/templates/stack/%stack_name%/README.tt +7 -0
  45. data/lib/pancake/generators/templates/stack/%stack_name%/Rakefile.tt +50 -0
  46. data/lib/pancake/generators/templates/stack/%stack_name%/VERSION.tt +1 -0
  47. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/config/environments/development.rb.tt +18 -0
  48. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/config/environments/production.rb.tt +18 -0
  49. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/config/router.rb.tt +6 -0
  50. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/config.ru.tt +12 -0
  51. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/gems/cache/.empty_directory +0 -0
  52. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/mounts/.empty_directory +0 -0
  53. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/public/.empty_directory +0 -0
  54. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/tmp/.empty_directory +0 -0
  55. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%.rb.tt +3 -0
  56. data/lib/pancake/generators/templates/stack/%stack_name%/pancake.init.tt +1 -0
  57. data/lib/pancake/generators/templates/stack/%stack_name%/spec/%stack_name%_spec.rb.tt +7 -0
  58. data/lib/pancake/generators/templates/stack/%stack_name%/spec/spec_helper.rb.tt +9 -0
  59. data/lib/pancake/generators.rb +8 -0
  60. data/lib/pancake/hooks/inheritable_inner_classes.rb +60 -0
  61. data/lib/pancake/hooks/on_inherit.rb +34 -0
  62. data/lib/pancake/logger.rb +200 -0
  63. data/lib/pancake/master.rb +123 -0
  64. data/lib/pancake/middleware.rb +347 -0
  65. data/lib/pancake/middlewares/logger.rb +16 -0
  66. data/lib/pancake/middlewares/static.rb +38 -0
  67. data/lib/pancake/mime_types.rb +265 -0
  68. data/lib/pancake/mixins/publish/action_options.rb +104 -0
  69. data/lib/pancake/mixins/publish.rb +125 -0
  70. data/lib/pancake/mixins/render/render.rb +168 -0
  71. data/lib/pancake/mixins/render/template.rb +23 -0
  72. data/lib/pancake/mixins/render/view_context.rb +21 -0
  73. data/lib/pancake/mixins/render.rb +109 -0
  74. data/lib/pancake/mixins/request_helper.rb +100 -0
  75. data/lib/pancake/mixins/stack_helper.rb +46 -0
  76. data/lib/pancake/mixins/url.rb +10 -0
  77. data/lib/pancake/paths.rb +218 -0
  78. data/lib/pancake/router.rb +99 -0
  79. data/lib/pancake/stack/app.rb +10 -0
  80. data/lib/pancake/stack/bootloader.rb +79 -0
  81. data/lib/pancake/stack/configuration.rb +44 -0
  82. data/lib/pancake/stack/middleware.rb +0 -0
  83. data/lib/pancake/stack/router.rb +21 -0
  84. data/lib/pancake/stack/stack.rb +66 -0
  85. data/lib/pancake/stacks/short/bootloaders.rb +13 -0
  86. data/lib/pancake/stacks/short/controller.rb +116 -0
  87. data/lib/pancake/stacks/short/default/views/base.html.haml +5 -0
  88. data/lib/pancake/stacks/short/stack.rb +187 -0
  89. data/lib/pancake/stacks/short.rb +3 -0
  90. data/lib/pancake.rb +58 -0
  91. data/spec/helpers/helpers.rb +20 -0
  92. data/spec/helpers/matchers.rb +25 -0
  93. data/spec/pancake/bootloaders_spec.rb +109 -0
  94. data/spec/pancake/configuration_spec.rb +177 -0
  95. data/spec/pancake/constants_spec.rb +7 -0
  96. data/spec/pancake/defaults/configuration_spec.rb +58 -0
  97. data/spec/pancake/fixtures/foo_stack/pancake.init +0 -0
  98. data/spec/pancake/fixtures/middlewares/other_public/two.html +1 -0
  99. data/spec/pancake/fixtures/middlewares/public/foo#bar.html +1 -0
  100. data/spec/pancake/fixtures/middlewares/public/one.html +1 -0
  101. data/spec/pancake/fixtures/paths/controllers/controller1.rb +0 -0
  102. data/spec/pancake/fixtures/paths/controllers/controller2.rb +0 -0
  103. data/spec/pancake/fixtures/paths/controllers/controller3.rb +0 -0
  104. data/spec/pancake/fixtures/paths/models/model1.rb +0 -0
  105. data/spec/pancake/fixtures/paths/models/model2.rb +0 -0
  106. data/spec/pancake/fixtures/paths/models/model3.rb +0 -0
  107. data/spec/pancake/fixtures/paths/stack/controllers/controller1.rb +0 -0
  108. data/spec/pancake/fixtures/paths/stack/models/model3.rb +0 -0
  109. data/spec/pancake/fixtures/paths/stack/views/view1.erb +0 -0
  110. data/spec/pancake/fixtures/paths/stack/views/view1.rb +0 -0
  111. data/spec/pancake/fixtures/paths/stack/views/view2.erb +0 -0
  112. data/spec/pancake/fixtures/paths/stack/views/view2.haml +0 -0
  113. data/spec/pancake/fixtures/render_templates/context_template.html.erb +2 -0
  114. data/spec/pancake/fixtures/render_templates/erb_template.html.erb +1 -0
  115. data/spec/pancake/fixtures/render_templates/erb_template.json.erb +1 -0
  116. data/spec/pancake/fixtures/render_templates/haml_template.html.haml +1 -0
  117. data/spec/pancake/fixtures/render_templates/haml_template.xml.haml +1 -0
  118. data/spec/pancake/fixtures/render_templates/templates/context.erb +2 -0
  119. data/spec/pancake/fixtures/render_templates/view_context/capture_erb.erb +5 -0
  120. data/spec/pancake/fixtures/render_templates/view_context/capture_haml.haml +4 -0
  121. data/spec/pancake/fixtures/render_templates/view_context/concat_erb.erb +2 -0
  122. data/spec/pancake/fixtures/render_templates/view_context/concat_haml.haml +2 -0
  123. data/spec/pancake/fixtures/render_templates/view_context/context.erb +3 -0
  124. data/spec/pancake/fixtures/render_templates/view_context/context2.erb +3 -0
  125. data/spec/pancake/fixtures/render_templates/view_context/helper_methods.erb +3 -0
  126. data/spec/pancake/fixtures/render_templates/view_context/inherited_erb_from_haml.erb +5 -0
  127. data/spec/pancake/fixtures/render_templates/view_context/inherited_erb_level_0.erb +5 -0
  128. data/spec/pancake/fixtures/render_templates/view_context/inherited_erb_level_1.erb +5 -0
  129. data/spec/pancake/fixtures/render_templates/view_context/inherited_haml_from_erb.haml +4 -0
  130. data/spec/pancake/fixtures/render_templates/view_context/inherited_haml_level_0.haml +4 -0
  131. data/spec/pancake/fixtures/render_templates/view_context/inherited_haml_level_1.haml +4 -0
  132. data/spec/pancake/fixtures/render_templates/view_context/nested_content_level_0.haml +6 -0
  133. data/spec/pancake/fixtures/render_templates/view_context/nested_content_level_1.haml +4 -0
  134. data/spec/pancake/fixtures/render_templates/view_context/nested_inner.erb +1 -0
  135. data/spec/pancake/fixtures/render_templates/view_context/nested_outer.erb +3 -0
  136. data/spec/pancake/fixtures/render_templates/view_context/super_erb_from_erb_0.erb +5 -0
  137. data/spec/pancake/fixtures/render_templates/view_context/super_erb_from_erb_1.erb +6 -0
  138. data/spec/pancake/fixtures/render_templates/view_context/super_erb_from_haml_0.erb +5 -0
  139. data/spec/pancake/fixtures/render_templates/view_context/super_erb_from_haml_1.erb +6 -0
  140. data/spec/pancake/fixtures/render_templates/view_context/super_haml_from_erb_0.haml +4 -0
  141. data/spec/pancake/fixtures/render_templates/view_context/super_haml_from_erb_1.haml +5 -0
  142. data/spec/pancake/fixtures/render_templates/view_context/super_haml_from_haml_0.haml +5 -0
  143. data/spec/pancake/fixtures/render_templates/view_context/super_haml_from_haml_1.haml +5 -0
  144. data/spec/pancake/fixtures/stacks/short/foobar/other_root/views/base.html.haml +4 -0
  145. data/spec/pancake/fixtures/stacks/short/foobar/views/basic.html.haml +1 -0
  146. data/spec/pancake/fixtures/stacks/short/foobar/views/inherited_from_base.html.haml +5 -0
  147. data/spec/pancake/hooks/on_inherit_spec.rb +65 -0
  148. data/spec/pancake/inheritance_spec.rb +100 -0
  149. data/spec/pancake/middleware_spec.rb +401 -0
  150. data/spec/pancake/middlewares/logger_spec.rb +29 -0
  151. data/spec/pancake/middlewares/static_spec.rb +83 -0
  152. data/spec/pancake/mime_types_spec.rb +234 -0
  153. data/spec/pancake/mixins/publish_spec.rb +94 -0
  154. data/spec/pancake/mixins/render/template_spec.rb +69 -0
  155. data/spec/pancake/mixins/render/view_context_spec.rb +248 -0
  156. data/spec/pancake/mixins/render_spec.rb +56 -0
  157. data/spec/pancake/mixins/request_helper_spec.rb +27 -0
  158. data/spec/pancake/mixins/stack_helper_spec.rb +46 -0
  159. data/spec/pancake/pancake_spec.rb +90 -0
  160. data/spec/pancake/paths_spec.rb +210 -0
  161. data/spec/pancake/stack/app_spec.rb +28 -0
  162. data/spec/pancake/stack/bootloader_spec.rb +41 -0
  163. data/spec/pancake/stack/middleware_spec.rb +0 -0
  164. data/spec/pancake/stack/router_spec.rb +282 -0
  165. data/spec/pancake/stack/stack_configuration_spec.rb +101 -0
  166. data/spec/pancake/stack/stack_spec.rb +60 -0
  167. data/spec/pancake/stacks/short/controller_spec.rb +322 -0
  168. data/spec/pancake/stacks/short/middlewares_spec.rb +22 -0
  169. data/spec/pancake/stacks/short/router_spec.rb +136 -0
  170. data/spec/pancake/stacks/short/stack_spec.rb +64 -0
  171. data/spec/spec_helper.rb +23 -0
  172. metadata +294 -0
@@ -0,0 +1,234 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), "..", "spec_helper")
2
+
3
+ describe Pancake::MimeTypes do
4
+ before do
5
+ Pancake::MimeTypes.reset!
6
+ end
7
+
8
+ it "should have many types" do
9
+ Pancake::MimeTypes.types.should be_an(Array)
10
+ end
11
+
12
+ it "should have a type for each mime type defined in Rack::Mime::MIME_TYPES" do
13
+ Rack::Mime::MIME_TYPES.each do |ext, type|
14
+ ext =~ /\.(.*)$/
15
+ t = Pancake::MimeTypes.type_by_extension($1)
16
+ t.should_not be_nil
17
+ t.should be_an_instance_of(Pancake::MimeTypes::Type)
18
+ t.type_strings.should include(type)
19
+ end
20
+ end
21
+
22
+ it "should find the type from an extension" do
23
+ t = Pancake::MimeTypes.type_by_extension("html")
24
+ t.should_not be_nil
25
+ t.type_strings.should include("text/html")
26
+ end
27
+
28
+ it "should allow me to add a new mime type" do
29
+ t = Pancake::MimeTypes::Type.new("foo", "text/foobar")
30
+ type = Pancake::MimeTypes.type_by_extension("foo")
31
+ type.should_not be_nil
32
+ type.type_strings.should have(1).item
33
+ type.type_strings.should include("text/foobar")
34
+ end
35
+
36
+ describe Pancake::MimeTypes::Type do
37
+ include Pancake::MimeTypes
38
+
39
+ before do
40
+ @type = Pancake::MimeTypes::Type.new("html", "text/html")
41
+ end
42
+
43
+ it "should have one extension" do
44
+ @type.extension.should == "html"
45
+ end
46
+
47
+ it "should tell me the type strings" do
48
+ @type.type_strings.should include("text/html")
49
+ end
50
+
51
+ it "should allow me to add type strings" do
52
+ @type.type_strings << "text/foo_html"
53
+ @type.type_strings.should include("text/foo_html")
54
+ end
55
+
56
+ it "should not add duplicate type strings" do
57
+ @type.type_strings.should have(1).item
58
+ @type.type_strings << "text/html"
59
+ @type.type_strings.should have(2).items
60
+ @type.type_strings.should include("text/html")
61
+ end
62
+
63
+ it "should add non duplicate tpe strying" do
64
+ @type.type_strings.should have(1).item
65
+ @type.type_strings << "text/foo_html"
66
+ @type.type_strings.should have(2).items
67
+ @type.type_strings.should include("text/foo_html")
68
+ end
69
+ end
70
+
71
+ describe "grouping types" do
72
+ it "should allow me to create a group of mime types" do
73
+ Pancake::MimeTypes.group(:html).should be_an(Enumerable)
74
+ end
75
+
76
+ it "should allow me to add mime types to the group" do
77
+ Pancake::MimeTypes.group_as(:foo, "html", "xhtml")
78
+ r = Pancake::MimeTypes.group(:foo)
79
+ r.should have(2).items
80
+ r.should include(Pancake::MimeTypes.type_by_extension("html"))
81
+ r.should include(Pancake::MimeTypes.type_by_extension("xhtml"))
82
+ end
83
+
84
+ it "should allow me to add to a group without creating duplicates" do
85
+ t = Pancake::MimeTypes::Type.new("foo", "foo/bar")
86
+ Pancake::MimeTypes.group_as(:bar, "xhtml", "html")
87
+ Pancake::MimeTypes.group(:bar).should have(2).items
88
+ Pancake::MimeTypes.group(:bar).should_not include(t)
89
+ Pancake::MimeTypes.group_as(:bar, "html", "foo", "xhtml")
90
+ Pancake::MimeTypes.group(:bar).should have(3).items
91
+ Pancake::MimeTypes.group(:bar).should include(t)
92
+ end
93
+
94
+ it "should allow me to look up a mime type via a string or symbol identifier" do
95
+ Pancake::MimeTypes.group(:html).should eql(Pancake::MimeTypes.group("html"))
96
+ end
97
+
98
+ it "should be empty empty when accessing a non existant mime type" do
99
+ r = Pancake::MimeTypes.group(:not_a_mime)
100
+ r.should_not be_nil
101
+ r.should be_empty
102
+ r.should respond_to(:each)
103
+ end
104
+
105
+ it "should populate the group with the types when first acessing when a type with that extension exists" do
106
+ r = Pancake::MimeTypes.group(:xml)
107
+ r.should_not be_empty
108
+ r.each do |t|
109
+ t.should be_an_instance_of(Pancake::MimeTypes::Type)
110
+ end
111
+ end
112
+ end
113
+
114
+ describe "prepared groups" do
115
+ it "should prepare the html group" do
116
+ g = Pancake::MimeTypes.group(:html)
117
+ g.should have(3).items
118
+ ["html", "htm", "xhtml"].each do |ext|
119
+ t = Pancake::MimeTypes.type_by_extension(ext)
120
+ g.should include(t)
121
+ end
122
+ end
123
+
124
+ it "should parepare the text group" do
125
+ g = Pancake::MimeTypes.group(:text)
126
+ g.should have(2).items
127
+ ["text", "txt"].each do |ext|
128
+ t = Pancake::MimeTypes.type_by_extension(ext)
129
+ g.should include(t)
130
+ end
131
+ end
132
+
133
+ it "should prepare the svg group" do
134
+ g = Pancake::MimeTypes.group(:svg)
135
+ g.should have(2).items
136
+ ["svg", "svgz"].each do |ext|
137
+ t = Pancake::MimeTypes.type_by_extension(ext)
138
+ g.should include(t)
139
+ end
140
+ end
141
+
142
+
143
+ it "should add the text/xml to the xml format" do
144
+ t = Pancake::MimeTypes.type_by_extension("xml")
145
+ t.type_strings.should include("text/xml", "application/xml")
146
+ end
147
+ end
148
+
149
+ describe "format from accept type" do
150
+ it "should return the first matching type" do
151
+ accept_type = "text/plain"
152
+ group, at, r = Pancake::MimeTypes.negotiate_accept_type(accept_type, :text)
153
+ group.should == :text
154
+ at.should == accept_type
155
+ r.should_not be_nil
156
+ r.type_strings.should include("text/plain")
157
+ end
158
+
159
+ it "should return the first type if the matching type is */*" do
160
+ accept_type = "*/*;application/xml"
161
+ group, at, r = Pancake::MimeTypes.negotiate_accept_type(accept_type, :text, :xml, :html)
162
+ at.should == "text/plain"
163
+ group.should == :text
164
+ r.should_not be_nil
165
+ r.type_strings.should include("text/plain")
166
+ end
167
+
168
+ it "should use */* if avaiable" do
169
+ # safari uses application/xml first
170
+ accept_type = "application/xml,*/*"
171
+ group, at, r = Pancake::MimeTypes.negotiate_accept_type(accept_type, :html, :xml)
172
+ at.should == "text/html"
173
+ group.should == :html
174
+ r.should_not be_nil
175
+ end
176
+
177
+ it "should return nil if there is no matching class" do
178
+ accept_type = "text/xml"
179
+ group, r = Pancake::MimeTypes.negotiate_accept_type(accept_type, :text, :html)
180
+ r.should be_nil
181
+ group.should be_nil
182
+ end
183
+
184
+ it "should return a type when it is not in the first position" do
185
+ accept_type = "text/xml, text/html,text/plain;"
186
+ group, at, r = Pancake::MimeTypes.negotiate_accept_type(accept_type, :svg, :text)
187
+ group.should == :text
188
+ r.should_not be_nil
189
+ r.type_strings.should include("text/plain")
190
+ r.extension.should == "text"
191
+ end
192
+
193
+ it "should recognize the type from a quality value" do
194
+ accept_type = "text/plain;q=0.5,text/html;q=0.8"
195
+ group, at, r = Pancake::MimeTypes.negotiate_accept_type(accept_type, :text, :html)
196
+ group.should == :html
197
+ r.should_not be_nil
198
+ r.type_strings.should include("text/html")
199
+ r.extension.should == "html"
200
+ end
201
+ end
202
+
203
+ describe "mime from extension" do
204
+ it "should recognize the mime type from the extension" do
205
+ group, at, r = Pancake::MimeTypes.negotiate_by_extension("text", :html, :text)
206
+ group.should == :text
207
+ at.should == "text/plain"
208
+ r.should == Pancake::MimeTypes.type_by_extension("text")
209
+ end
210
+
211
+ it "should recognize grouped mimes by extension" do
212
+ Pancake::MimeTypes.group_as(:foo, "text", "txt", "html")
213
+ group, at, r = Pancake::MimeTypes.negotiate_by_extension("txt", :foo)
214
+ group.should == :foo
215
+ at.should == "text/plain"
216
+ r.extension.should == "txt"
217
+ group, at, r = Pancake::MimeTypes.negotiate_by_extension("text", :foo)
218
+ r.extension.should == "text"
219
+ group, at, r = Pancake::MimeTypes.negotiate_by_extension("html", :foo)
220
+ r.extension.should == "html"
221
+ at.should == "text/html"
222
+ end
223
+
224
+ it "should not negotiate by extension when there the extension is not part of the accepted types" do
225
+ Pancake::MimeTypes.group_as(:bar, "text")
226
+ group, at, r = Pancake::MimeTypes.negotiate_by_extension("svg", :bar)
227
+ group.should be_nil
228
+ at.should be_nil
229
+ r.should be_nil
230
+ end
231
+
232
+ end
233
+ end
234
+
@@ -0,0 +1,94 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe "Pancake::Controller publish declaration" do
4
+ before(:each) do
5
+ class ::PancakeTest
6
+ extend Pancake::Mixins::Publish
7
+
8
+ provides :html
9
+
10
+ publish
11
+ def simple_publish; end
12
+
13
+ publish :id => as(:integer)
14
+ def integer_test; end
15
+
16
+ publish :start => as(:date)
17
+ def date_test; end
18
+
19
+ publish :page => as(:integer, 12)
20
+ def default_test; end
21
+
22
+ publish :provides => [:xml, :json]
23
+ def provides_test; end
24
+
25
+ publish :only_provides => :xml
26
+ def only_provides_test; end
27
+
28
+ publish :name => as(:string, :opt)
29
+ def optional_test; end
30
+
31
+ publish :provides => [:json, :txt],
32
+ :id => as(:integer, :req),
33
+ :name => as(:string, "Campion"),
34
+ :melon => as(:integer, 50),
35
+ :jam => as(:string, :opt),
36
+ :squeeze => as(:string, :req)
37
+ def complex_test; end
38
+ end
39
+ end
40
+
41
+ after do
42
+ clear_constants "PancakeTest"
43
+ end
44
+
45
+ it "should publish an action" do
46
+ PancakeTest.actions['simple_publish'].is_a?(Pancake::Mixins::Publish::ActionOptions).should == true
47
+ end
48
+
49
+ it "should coerce a parameter into an integer" do
50
+ params, missing = PancakeTest.__send__(:validate_and_coerce_params, 'integer_test', 'id' => "30")
51
+ params['id'].should == 30
52
+ end
53
+
54
+ it "should coerce a parameter into a date" do
55
+ date = Date.parse("2009/07/05")
56
+ params, missing = PancakeTest.__send__(:validate_and_coerce_params, 'date_test', 'start' => "2009/07/05")
57
+ params['start'].should == date
58
+ end
59
+
60
+ it "should flag required params that are missing" do
61
+ params, missing = PancakeTest.__send__(:validate_and_coerce_params, 'integer_test', {})
62
+ missing.include?(['id', :integer]).should == true
63
+ end
64
+
65
+ it "should allow parameters to be optional" do
66
+ params, missing = PancakeTest.__send__(:validate_and_coerce_params, 'optional_test', {})
67
+ missing.empty?.should == true
68
+ end
69
+
70
+ it "should return a default value for a parameter" do
71
+ params, missing = PancakeTest.__send__(:validate_and_coerce_params, 'default_test', {})
72
+ params['page'].should == 12
73
+ end
74
+
75
+ it "should append formats to the list allowed for an action" do
76
+ PancakeTest.actions['provides_test'].formats.should == [:html, :xml, :json]
77
+ end
78
+
79
+ it "should replace the list of formats allowed for an action" do
80
+ PancakeTest.actions['only_provides_test'].formats.should == [:xml]
81
+ end
82
+
83
+ it "should allow complex declarations" do
84
+ input = {'id' => "30", 'name' => "Purslane"}
85
+ params, missing = PancakeTest.__send__(:validate_and_coerce_params, 'complex_test', input)
86
+ params['id'].should == 30
87
+ params['name'].should == "Purslane"
88
+ params['melon'].should == 50
89
+ params['jame'].should be_nil
90
+ missing.include?(['squeeze', :string]).should == true
91
+
92
+ PancakeTest.actions['complex_test'].formats.should == [:html, :json, :txt]
93
+ end
94
+ end
@@ -0,0 +1,69 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "..", "spec_helper")
2
+
3
+ describe Pancake::Mixins::Render::Template do
4
+ before do
5
+ $captures = []
6
+ @templates_path = File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "fixtures", "render_templates", "templates")
7
+ class ::FooBar
8
+ include Pancake::Mixins::Render
9
+ end
10
+ end
11
+ after do
12
+ clear_constants :FooBar, :BarFoo
13
+ end
14
+
15
+ describe "Creation" do
16
+ it "should create a template with a name and a path" do
17
+ result = FooBar::Template.new(:context, File.join(@templates_path, "context.erb"))
18
+ result.should_not be_nil
19
+ end
20
+
21
+ it "should raise an error when creating a template without a name" do
22
+ lambda do
23
+ FooBar::Template.new(nil, File.join(@templates_path, "context.erb"))
24
+ end.should raise_error(Pancake::Mixins::Render::Template::UnamedTemplate)
25
+ end
26
+
27
+ it "should raise an error when createing a template withouth a valid file name" do
28
+ lambda do
29
+ FooBar::Template.new(:foo, "/not/a/real/file.erb")
30
+ end.should raise_error(Pancake::Mixins::Render::Template::NotFound)
31
+ end
32
+
33
+ it "should raise an error when it cannot create a rendering object for the file" do
34
+ lambda do
35
+ FooBar::Template.new(:foo, "/not/registed")
36
+ end.should raise_error
37
+ end
38
+
39
+ describe "accessing information" do
40
+ before do
41
+ @template = FooBar::Template.new(:context, File.join(@templates_path, "context.erb"))
42
+ end
43
+
44
+ it "should provide access to it's name" do
45
+ @template.name.should == :context
46
+ end
47
+
48
+ it "should provide access to it's path" do
49
+ @template.path.should == File.join(@templates_path, "context.erb")
50
+ end
51
+
52
+ it "should render the template" do
53
+ @template.render.should match(/in context/m)
54
+ end
55
+
56
+ describe "contexts" do
57
+ before do
58
+ @context = mock("context")
59
+ end
60
+
61
+ it "should render with the given context" do
62
+ @template.render(@context)
63
+ $captures.first.should == @context
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,248 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "..", "spec_helper")
2
+
3
+ describe Pancake::Mixins::Render::ViewContext do
4
+
5
+ before do
6
+ $captures = []
7
+ class ::FooBar
8
+ include Pancake::Mixins::Render
9
+ attr_accessor :params, :data
10
+
11
+ def _template_name_for(name, opts)
12
+ "#{name}"
13
+ end
14
+ push_paths :views, "", "**/*"
15
+
16
+ roots << File.join(File.expand_path(File.dirname(__FILE__)),"..","..", "fixtures", "render_templates", "view_context")
17
+ end
18
+ end
19
+
20
+ after do
21
+ clear_constants :FooBar, :BarFoo
22
+ end
23
+
24
+ it "should setup the spec correctly" do
25
+ %w(helper_methods.erb context.erb).each do |f|
26
+ File.exists?(File.join(FooBar.roots.first, f)).should be_true
27
+ end
28
+ end
29
+
30
+ describe "view contexts" do
31
+
32
+ it "should inherit from Pancake::Mixins::Render::ViewContext" do
33
+ FooBar::ViewContext.should inherit_from(Pancake::Mixins::Render::ViewContext)
34
+ end
35
+
36
+ #it "should allow me to setup the view context before the view is run" do
37
+ # FooBar.class_eval do
38
+ # def view_context_before_render(context)
39
+ # super
40
+ # $captures << :here
41
+ # end
42
+ # end
43
+ # $captures.should be_blank
44
+ # FooBar.new.render(:context)
45
+ # $captures.should include(:here)
46
+ #end
47
+
48
+ #it "should execute the before render block in the instance" do
49
+ # FooBar.class_eval do
50
+ # def view_context_before_render(context)
51
+ # super
52
+ # $captures << data
53
+ # end
54
+ # end
55
+ # foobar = FooBar.new
56
+ # foobar.data = {:some => :data}
57
+ # foobar.render(:context)
58
+ # $captures.should include(:some => :data)
59
+ # $captures.clear
60
+ # FooBar.new.render(:context)
61
+ # $captures.should_not include(:some => :data)
62
+ #end
63
+ end
64
+
65
+ describe "inheriting classes" do
66
+ before do
67
+ FooBar::ViewContext.class_eval do
68
+ def some_helper
69
+ $captures << :some_helper
70
+ end
71
+ end
72
+
73
+ class ::BarFoo < FooBar
74
+ end
75
+
76
+ end
77
+
78
+ it "should inherit the view context when inheriting the outer class" do
79
+ BarFoo::ViewContext.should inherit_from(FooBar::ViewContext)
80
+ end
81
+ end
82
+
83
+ describe "delegation" do
84
+ before do
85
+ @renderer = mock("renderer", :null_object => true)
86
+ end
87
+
88
+ it "should provide access to the object the view context is rendering for" do
89
+ context = FooBar::ViewContext.new(@renderer)
90
+ context._view_context_for.should == @renderer
91
+ end
92
+
93
+ it "should grab the template from the view context when rendering" do
94
+ context = FooBar::ViewContext.new(@renderer)
95
+ @renderer.should_receive(:template).with(:foo).and_return(@renderer)
96
+ context.render(:foo, :some => :opts)
97
+ end
98
+ end
99
+
100
+ describe "capturing" do
101
+ before do
102
+ end
103
+
104
+ it "should render the haml template with a capture" do
105
+ result = FooBar.new.render(:capture_haml)
106
+ result.should_not include("captured haml")
107
+
108
+ context = $captures.first
109
+ context.should_not be_nil
110
+ context.instance_variable_get("@captured_haml").should include("captured haml")
111
+ end
112
+
113
+ it "should capture in erb" do
114
+ result = FooBar.new.render(:capture_erb)
115
+ result.should_not include("captured erb")
116
+ context = $captures.first
117
+ context.should_not be_nil
118
+ context.instance_variable_get("@captured_erb").should include("captured erb")
119
+ end
120
+
121
+ it "should concat in haml" do
122
+ result = FooBar.new.render(:concat_haml)
123
+ result.should include("concatenated")
124
+ end
125
+
126
+ it "should concat in erb" do
127
+ result = FooBar.new.render(:concat_erb)
128
+ result.should include("concatenated")
129
+ end
130
+ end
131
+
132
+ describe "content_block" do
133
+ before do
134
+ @foo = FooBar.new
135
+ end
136
+
137
+ it "should include the default text" do
138
+ result = @foo.render(:inherited_haml_level_0)
139
+ result.should include("inherited haml level 0")
140
+ result.should include("default content block content")
141
+ end
142
+
143
+ it "should inherit the content block from a parent template" do
144
+ result = @foo.render(:inherited_haml_level_1)
145
+ result.should include("inherited haml level 0")
146
+ result.should include("inherited haml level 1 content")
147
+ end
148
+
149
+ it "should inherit the default text in erb" do
150
+ result = @foo.render(:inherited_erb_level_0)
151
+ result.should include("inherited erb level 0")
152
+ result.should include("default content block content")
153
+ end
154
+
155
+ it "should inherit the content block from a parent template in erb" do
156
+ result = @foo.render(:inherited_erb_level_1)
157
+ result.should include("inherited erb level 0")
158
+ result.should include("inherited erb level 1 content")
159
+ end
160
+
161
+ it "should inherit erb from haml" do
162
+ result = @foo.render(:inherited_erb_from_haml)
163
+ result.should include("inherited haml level 0")
164
+ result.should include("inherited erb content")
165
+ end
166
+
167
+ it "should inherit haml from erb" do
168
+ result = @foo.render(:inherited_haml_from_erb)
169
+ result.should include("inherited erb level 0")
170
+ result.should include("inherited haml content")
171
+ end
172
+
173
+ end
174
+
175
+ describe "super blocks" do
176
+ before do
177
+ @foo = FooBar.new
178
+ end
179
+
180
+ it "should render the super text" do
181
+ result = @foo.render(:super_haml_from_haml_0)
182
+ result.should include("default content block content")
183
+ end
184
+
185
+ it "should render the super text and the new text" do
186
+ result = @foo.render(:super_haml_from_haml_1)
187
+ result.should include("default content block content")
188
+ result.should include("new content with super")
189
+ end
190
+
191
+ it "should render the super text in erb templates" do
192
+ result = @foo.render(:super_erb_from_erb_0)
193
+ result.should include("default content block content")
194
+ end
195
+
196
+ it "should render the super text and the new text in erb" do
197
+ result = @foo.render(:super_erb_from_erb_1)
198
+ result.should include("new content with super")
199
+ result.should include("default content block content")
200
+ end
201
+
202
+ it "should inherit haml from erb" do
203
+ result = @foo.render(:super_haml_from_erb_0)
204
+ result.should include("default content block content")
205
+ end
206
+
207
+ it "should inherit haml from erb with with additional contnet" do
208
+ result = @foo.render(:super_haml_from_erb_1)
209
+ result.should include("new content from haml")
210
+ result.should include("default content block content")
211
+ end
212
+
213
+ it "should inherit erb from haml" do
214
+ result = @foo.render(:super_erb_from_haml_0)
215
+ result.should include("default content block content")
216
+ end
217
+
218
+ it "should inherit erb from haml" do
219
+ result = @foo.render(:super_erb_from_haml_1)
220
+ result.should include("new content from erb")
221
+ result.should include("default content block content")
222
+ end
223
+ end
224
+
225
+ describe "multiple context blocks" do
226
+ before do
227
+ @foo = FooBar.new
228
+ end
229
+
230
+ it "should allow nested default captures" do
231
+ result = @foo.render(:nested_content_level_0)
232
+ result.should include("level 0 content")
233
+ result.should include("nested foo content")
234
+ result.should include("nested bar content")
235
+ end
236
+
237
+ it "should allow inherited nested content to overwrite a given block" do
238
+ result = @foo.render(:nested_content_level_1)
239
+ result.should include("level 0 content")
240
+ result.should include("nested foo content")
241
+ result.should include("nested new bar content")
242
+ end
243
+ end
244
+ end
245
+
246
+
247
+
248
+
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Pancake::Mixins::Render do
4
+ before do
5
+ class ::RenderSpecClass
6
+ include Pancake::Mixins::Render
7
+
8
+ # setup the renderer
9
+ roots << File.expand_path(File.join(File.dirname(__FILE__), "..", "fixtures", "render_templates"))
10
+ push_paths :views, "/", "**/*"
11
+
12
+ def params
13
+ @params ||= {}
14
+ end
15
+
16
+ def string
17
+ render :text => "A String"
18
+ end
19
+
20
+ def the_current_context
21
+ "the current context"
22
+ end
23
+ end
24
+
25
+ @render = RenderSpecClass.new
26
+ end
27
+ after do
28
+ clear_constants "RenderSpecClass"
29
+ end
30
+
31
+ it "should allow me to render a string" do
32
+ @render.string.should == "A String"
33
+ end
34
+
35
+ it "should render a haml" do
36
+ @render.render(:haml_template).chomp.should == "IN HAML"
37
+ end
38
+
39
+ it "should render erb" do
40
+ @render.render(:erb_template).should == "IN ERB"
41
+ end
42
+
43
+ it "should render an xml format" do
44
+ @render.render(:haml_template, :format => :xml).chomp.should == "IN HAML XML"
45
+ end
46
+
47
+ it "should render an erb template for json" do
48
+ @render.render(:erb_template, :format => :json).chomp.should == "IN ERB JSON"
49
+ end
50
+
51
+ it "should render with the rendering controller as the current context" do
52
+ @render.render(:context_template)
53
+ $captures.first.should be_a_kind_of(Pancake::Mixins::Render::ViewContext)
54
+ end
55
+
56
+ end