hassox-pancake 0.1.6

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 (125) hide show
  1. data/LICENSE +20 -0
  2. data/README.textile +95 -0
  3. data/Rakefile +56 -0
  4. data/TODO +18 -0
  5. data/bin/jeweler +19 -0
  6. data/bin/pancake-gen +17 -0
  7. data/bin/rubyforge +19 -0
  8. data/lib/pancake.rb +48 -0
  9. data/lib/pancake/bootloaders.rb +180 -0
  10. data/lib/pancake/configuration.rb +140 -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/errors.rb +61 -0
  15. data/lib/pancake/generators.rb +8 -0
  16. data/lib/pancake/generators/base.rb +12 -0
  17. data/lib/pancake/generators/flat_generator.rb +17 -0
  18. data/lib/pancake/generators/short_generator.rb +17 -0
  19. data/lib/pancake/generators/stack_generator.rb +17 -0
  20. data/lib/pancake/generators/templates/common/dotgitignore +22 -0
  21. data/lib/pancake/generators/templates/common/dothtaccess +17 -0
  22. data/lib/pancake/generators/templates/flat/%stack_name%/%stack_name%.rb.tt +8 -0
  23. data/lib/pancake/generators/templates/flat/%stack_name%/.gitignore +21 -0
  24. data/lib/pancake/generators/templates/flat/%stack_name%/config.ru.tt +12 -0
  25. data/lib/pancake/generators/templates/flat/%stack_name%/pancake.init.tt +1 -0
  26. data/lib/pancake/generators/templates/flat/%stack_name%/public/.empty_directory +0 -0
  27. data/lib/pancake/generators/templates/flat/%stack_name%/tmp/.empty_directory +0 -0
  28. data/lib/pancake/generators/templates/short/%stack_name%/.gitignore +21 -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 +48 -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%.rb.tt +5 -0
  34. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/%stack_name%.rb.tt +6 -0
  35. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/config.ru.tt +12 -0
  36. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/gems/cache/.empty_directory +0 -0
  37. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/mounts/.empty_directory +0 -0
  38. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/public/.empty_directory +0 -0
  39. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/tmp/.empty_directory +0 -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%/.gitignore +21 -0
  44. data/lib/pancake/generators/templates/stack/%stack_name%/LICENSE.tt +20 -0
  45. data/lib/pancake/generators/templates/stack/%stack_name%/README.tt +7 -0
  46. data/lib/pancake/generators/templates/stack/%stack_name%/Rakefile.tt +48 -0
  47. data/lib/pancake/generators/templates/stack/%stack_name%/VERSION.tt +1 -0
  48. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%.rb.tt +3 -0
  49. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/config.ru.tt +12 -0
  50. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/config/environments/development.rb.tt +18 -0
  51. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/config/environments/production.rb.tt +18 -0
  52. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/config/router.rb.tt +6 -0
  53. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/gems/cache/.empty_directory +0 -0
  54. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/mounts/.empty_directory +0 -0
  55. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/public/.empty_directory +0 -0
  56. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/tmp/.empty_directory +0 -0
  57. data/lib/pancake/generators/templates/stack/%stack_name%/pancake.init.tt +1 -0
  58. data/lib/pancake/generators/templates/stack/%stack_name%/spec/%stack_name%_spec.rb.tt +7 -0
  59. data/lib/pancake/generators/templates/stack/%stack_name%/spec/spec_helper.rb.tt +9 -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/master.rb +87 -0
  63. data/lib/pancake/middleware.rb +354 -0
  64. data/lib/pancake/mime_types.rb +265 -0
  65. data/lib/pancake/mixins/publish.rb +125 -0
  66. data/lib/pancake/mixins/publish/action_options.rb +104 -0
  67. data/lib/pancake/mixins/render.rb +61 -0
  68. data/lib/pancake/mixins/request_helper.rb +92 -0
  69. data/lib/pancake/mixins/stack_helper.rb +44 -0
  70. data/lib/pancake/mixins/url.rb +10 -0
  71. data/lib/pancake/more/controller.rb +4 -0
  72. data/lib/pancake/more/controller/base.rb +34 -0
  73. data/lib/pancake/paths.rb +218 -0
  74. data/lib/pancake/router.rb +99 -0
  75. data/lib/pancake/stack/app.rb +10 -0
  76. data/lib/pancake/stack/bootloader.rb +79 -0
  77. data/lib/pancake/stack/configuration.rb +44 -0
  78. data/lib/pancake/stack/middleware.rb +0 -0
  79. data/lib/pancake/stack/router.rb +18 -0
  80. data/lib/pancake/stack/stack.rb +57 -0
  81. data/lib/pancake/stacks/short.rb +2 -0
  82. data/lib/pancake/stacks/short/controller.rb +105 -0
  83. data/lib/pancake/stacks/short/stack.rb +194 -0
  84. data/spec/helpers/helpers.rb +20 -0
  85. data/spec/helpers/matchers.rb +25 -0
  86. data/spec/pancake/bootloaders_spec.rb +109 -0
  87. data/spec/pancake/configuration_spec.rb +177 -0
  88. data/spec/pancake/fixtures/foo_stack/pancake.init +0 -0
  89. data/spec/pancake/fixtures/paths/controllers/controller1.rb +0 -0
  90. data/spec/pancake/fixtures/paths/controllers/controller2.rb +0 -0
  91. data/spec/pancake/fixtures/paths/controllers/controller3.rb +0 -0
  92. data/spec/pancake/fixtures/paths/models/model1.rb +0 -0
  93. data/spec/pancake/fixtures/paths/models/model2.rb +0 -0
  94. data/spec/pancake/fixtures/paths/models/model3.rb +0 -0
  95. data/spec/pancake/fixtures/paths/stack/controllers/controller1.rb +0 -0
  96. data/spec/pancake/fixtures/paths/stack/models/model3.rb +0 -0
  97. data/spec/pancake/fixtures/paths/stack/views/view1.erb +0 -0
  98. data/spec/pancake/fixtures/paths/stack/views/view1.rb +0 -0
  99. data/spec/pancake/fixtures/paths/stack/views/view2.erb +0 -0
  100. data/spec/pancake/fixtures/paths/stack/views/view2.haml +0 -0
  101. data/spec/pancake/fixtures/render_templates/context_template.html.erb +1 -0
  102. data/spec/pancake/fixtures/render_templates/erb_template.html.erb +1 -0
  103. data/spec/pancake/fixtures/render_templates/erb_template.json.erb +1 -0
  104. data/spec/pancake/fixtures/render_templates/haml_template.html.haml +1 -0
  105. data/spec/pancake/fixtures/render_templates/haml_template.xml.haml +1 -0
  106. data/spec/pancake/hooks/on_inherit_spec.rb +65 -0
  107. data/spec/pancake/inheritance_spec.rb +100 -0
  108. data/spec/pancake/middleware_spec.rb +401 -0
  109. data/spec/pancake/mime_types_spec.rb +234 -0
  110. data/spec/pancake/mixins/publish_spec.rb +94 -0
  111. data/spec/pancake/mixins/render_spec.rb +55 -0
  112. data/spec/pancake/mixins/stack_helper_spec.rb +46 -0
  113. data/spec/pancake/pancake_spec.rb +31 -0
  114. data/spec/pancake/paths_spec.rb +210 -0
  115. data/spec/pancake/stack/app_spec.rb +28 -0
  116. data/spec/pancake/stack/bootloader_spec.rb +41 -0
  117. data/spec/pancake/stack/middleware_spec.rb +0 -0
  118. data/spec/pancake/stack/router_spec.rb +266 -0
  119. data/spec/pancake/stack/stack_configuration_spec.rb +101 -0
  120. data/spec/pancake/stack/stack_spec.rb +55 -0
  121. data/spec/pancake/stacks/short/controller_spec.rb +287 -0
  122. data/spec/pancake/stacks/short/router_spec.rb +132 -0
  123. data/spec/pancake/stacks/short/stack_spec.rb +40 -0
  124. data/spec/spec_helper.rb +21 -0
  125. metadata +238 -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,55 @@
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).chomp.should == "the current context"
53
+ end
54
+
55
+ end
@@ -0,0 +1,46 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), "..","..","spec_helper")
2
+
3
+ describe Pancake::Mixins::StackHelper do
4
+ before do
5
+ class ::FooStack < Pancake::Stack
6
+ class Bar
7
+ include Pancake::Mixins::StackHelper
8
+ end
9
+ end
10
+ end
11
+
12
+ after do
13
+ clear_constants :FooStack, :BarStack, :FooBar
14
+ end
15
+
16
+ it "should provide access to the stack helper to the Bar class" do
17
+ FooStack::Bar.stack_class.should == FooStack
18
+ end
19
+
20
+ it "should track the class for a newly namespaced stack" do
21
+ class ::BarStack < FooStack
22
+ class Bar < ::FooStack::Bar
23
+ end
24
+ end
25
+
26
+ BarStack::Bar.stack_class.should == BarStack
27
+ end
28
+
29
+ it "should raise an exception when including it into a class that is not of a stack" do
30
+ lambda do
31
+ class ::FooBar
32
+ include Pancake::Mixins::StackHelper
33
+ end
34
+ end.should raise_error
35
+ end
36
+
37
+ it "should remember the stack it was initially mixed into if it's inherited to a non namespaced class" do
38
+ class ::FooBar < FooStack::Bar; end
39
+ FooBar.stack_class.should == FooStack
40
+ end
41
+
42
+ it "should provide access to the stack helper from an instance of the Bar class" do
43
+ FooStack::Bar.new.stack_class.should == FooStack
44
+ end
45
+
46
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "pancake" do
4
+
5
+ it "should get the correct root directory for a file" do
6
+ Pancake.get_root(__FILE__).should == File.expand_path(File.dirname(__FILE__))
7
+ end
8
+
9
+ describe "stack labels" do
10
+ before(:each) do
11
+ @orig_lables = Pancake.stack_labels
12
+ end
13
+
14
+ after(:each) do
15
+ Pancake.stack_labels = @orig_labels
16
+ end
17
+
18
+ it "should allow me to set a stack type on panckae" do
19
+ Pancake.stack_labels = [:foo, :bar]
20
+ Pancake.stack_labels.should == [:foo, :bar]
21
+ end
22
+
23
+ it "should provide me with stack label of [:production] by default" do
24
+ Pancake.stack_labels = nil
25
+ Pancake.stack_labels.should == [:production]
26
+ Pancake.stack_labels = []
27
+ Pancake.stack_labels.should == [:production]
28
+ end
29
+ end
30
+
31
+ end