trellis 0.0.6 → 0.0.7

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.
@@ -65,7 +65,7 @@ module TestComponents
65
65
  page_contribution :script, %[alert('hello just once');], :scope => :class
66
66
 
67
67
  page_contribution(:dom) {
68
- at("body")['class'] = 'new_class'
68
+ at_css("body")['class'] = 'new_class'
69
69
  }
70
70
 
71
71
  render do |tag|
@@ -78,14 +78,14 @@ module TestComponents
78
78
  end
79
79
 
80
80
  class PageWithSimpleComponent < Trellis::Page
81
- template do html { body { text %[<trellis:simple_component/>] }} end
81
+ template do thtml { body { text %[<trellis:simple_component/>] }} end
82
82
  end
83
83
 
84
84
  class PageWithStatefulComponent < Trellis::Page
85
85
  route '/counters'
86
86
 
87
87
  template do
88
- html {
88
+ thtml {
89
89
  body {
90
90
  text %[
91
91
  <trellis:counter tid="one" />
@@ -101,7 +101,7 @@ module TestComponents
101
101
 
102
102
  class PageWithContributions < Trellis::Page
103
103
  template do
104
- html {
104
+ thtml {
105
105
  head {
106
106
  title "counters"
107
107
  }
@@ -1,45 +1,38 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
3
  require "rack"
4
+ require "rack/test"
4
5
  require_fixtures 'application_spec_applications'
5
6
 
6
7
  describe Trellis::Page, " when sending an event to a page" do
7
- before(:each) do
8
- @application = TestApp::MyApp.new
9
- @request = Rack::MockRequest.new(@application)
8
+ include Rack::Test::Methods
9
+
10
+ def app
11
+ TestApp::MyApp.new
10
12
  end
11
13
 
12
14
  it "should redirect to the receiving page if the event handler returns self" do
13
- response = @request.get("/home/events/event1")
14
- response.status.should be(302)
15
- response.headers['Location'].should == '/home'
15
+ get "/home/events/event1"
16
+ redirect = last_response.headers['Location']
17
+ redirect.should eql('/home')
16
18
  end
17
19
 
18
20
  it "should return a response as a string if the event handler returns a String" do
19
- response = @request.get("/home/events/event2")
20
- response.body.should == "just some text"
21
+ get "/home/events/event2"
22
+ last_response.body.should == "just some text"
21
23
  end
22
24
 
23
25
  it "should redirect to the injected page as a response if the event handler returns an injected page" do
24
- response = @request.get("/home/events/event3")
25
- response.status.should be(302)
26
- response.headers['Location'].should == '/other'
26
+ get "/home/events/event3"
27
+ redirect = last_response.headers['Location']
28
+ redirect.should eql('/other')
27
29
  end
28
30
 
29
31
  it "should be able to pass a value as the last element or the URL" do
30
- response = @request.get("/home/events/event4/quo%20vadis")
31
- response.body.should == "the value is quo vadis"
32
- end
33
-
34
- it "should invoke the before_load method if provided by the page" do
35
- response = @request.get("/before_load")
36
- response.body.should == "<html><body>8675309</body></html>"
37
- end
38
-
39
- it "should invoke the after_load method if provided by the page" do
40
- response = @request.get("/after_load")
41
- response.body.should == "<html><body>chunky bacon!</body></html>"
32
+ get "/home/events/event4/quo%20vadis"
33
+ last_response.body.should == "the value is quo vadis"
42
34
  end
35
+
43
36
  end
44
37
 
45
38
  describe Trellis::Page, " when calling inject_dependent_pages on an instance of Page" do
@@ -59,35 +52,115 @@ describe Trellis::Page, " when created with a custom route" do
59
52
  end
60
53
  end
61
54
 
55
+ describe Trellis::Page, " when provided with a #get method" do
56
+ include Rack::Test::Methods
57
+
58
+ def app
59
+ TestApp::MyApp.new
60
+ end
61
+
62
+ it "should redirect to the page returned" do
63
+ get "/page_with_get_redirect"
64
+ redirect = last_response.headers['Location']
65
+ redirect.should eql('/other')
66
+ end
67
+
68
+ it "should return a response as a string if the ==get== methood returns a String" do
69
+ get "/page_with_get_plain_text"
70
+ last_response.body.should == "some content"
71
+ end
72
+
73
+ it "should render the result of the ==get== method if it is the same page" do
74
+ get "/page_with_get_same"
75
+ last_response.body.should include("<p>Vera, what has become of you?</p>")
76
+ end
77
+ end
78
+
62
79
  describe Trellis::Page, " when given a template" do
63
- before(:each) do
64
- @application = TestApp::MyApp.new
65
- @request = Rack::MockRequest.new(@application)
80
+ include Rack::Test::Methods
81
+
82
+ def app
83
+ TestApp::MyApp.new
66
84
  end
67
85
 
68
86
  it "should rendered it correctly if it is in HAML format" do
69
- response = @request.get("/haml_page")
70
- response.body.should == "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n <head>\n <meta content=\"text/html; charset=UTF-8\" http-equiv=\"Content-Type\" />\n <title>\n This is a HAML page\n </title>\n </head>\n <body>\n <h1>\n Page Title\n </h1>\n <p>\n HAML rocks!\n </p>\n </body>\n</html>\n"
87
+ get "/haml_page"
88
+ last_response.body.should include(%[<title>\n This is a HAML page\n </title>\n </head>\n <body>\n <h1>\n Page Title\n </h1>\n <p>\n HAML rocks!\n </p>])
71
89
  end
72
90
 
73
91
  it "should rendered it correctly if it is in Textile format" do
74
- response = @request.get("/textile_page")
75
- response.body.should == "<p>A <strong>simple</strong> example.</p>"
92
+ get "/textile_page"
93
+ last_response.body.should == "<?xml version=\"1.0\"?>\n<p>A <strong>simple</strong> example.</p>\n"
76
94
  end
77
95
 
78
96
  it "should rendered it correctly if it is in Markdown format" do
79
- response = @request.get("/mark_down_page")
80
- response.body.should == "<html><body><h1>This is the Title</h1>\n\n<h2>This is the SubTitle</h2>\n\n<p>This is some text</p></body></html>"
97
+ get "/mark_down_page"
98
+ last_response.body.should include(%[body><h1>This is the Title</h1>\n\n<h2>This is the SubTitle</h2>\n\n<p><strong>This is some text</strong>])
81
99
  end
82
100
 
83
101
  it "should rendered it correctly if it is in ERuby format" do
84
- response = @request.get("/e_ruby_page")
85
- response.body.should == "<html><body><ul><li>Hey</li><li>bud</li><li>let's</li><li>party!</li></ul></body></html>"
102
+ get "/e_ruby_page"
103
+ last_response.body.should include("<li>Hey</li>")
104
+ last_response.body.should include("<li>bud</li>")
105
+ last_response.body.should include("<li>let's</li>")
106
+ last_response.body.should include("<li>party!</li>")
86
107
  end
87
108
 
88
109
  it "should rendered it correctly if it is in HTML format" do
89
- response = @request.get("/html_page")
90
- response.body.should == "<html><body><h1>This is just HTML</h1></body></html>"
110
+ get "/html_page"
111
+ last_response.body.should include("<h1>This is just HTML</h1>")
112
+ end
113
+ end
114
+
115
+ describe Trellis::Page do
116
+ include Rack::Test::Methods
117
+
118
+ before do
119
+ @application = TestApp::MyApp.new
120
+ end
121
+
122
+ def app
123
+ @application
124
+ end
125
+
126
+ it "should have access to application constants in ERuby format" do
127
+ get "/constant_access_page"
128
+ last_response.body.should include("<p>it's just us, chickens!</p>")
129
+ end
130
+
131
+ it "should have access to application methods in ERuby format" do
132
+ get "/method_access_page"
133
+ last_response.body.should include("<p>helloooo, la la la</p>")
134
+ end
135
+
136
+ it "should invoke the before_load method if provided by the page" do
137
+ get "/before_load"
138
+ last_response.body.should include("8675309")
139
+ end
140
+
141
+ it "should invoke the after_load method if provided by the page" do
142
+ get "/after_load"
143
+ last_response.body.should include("chunky bacon!")
144
+ end
145
+
146
+ it "should invoke the before_render method if provided by the page" do
147
+ get "/before_render"
148
+ last_response.body.should include("8675309")
149
+ end
150
+
151
+ it "should invoke the after_render method if provided by the page" do
152
+ env = Hash.new
153
+ env["rack.session"] = Hash.new
154
+ get "/after_render", {}, env
155
+ env["rack.session"][:my_field].should include("changed in after_render method")
156
+ end
157
+
158
+ it "should redirect if giving an explicit redirect" do
159
+ get '/explicit_redirect'
160
+ redirect = last_response.headers['Location']
161
+ redirect.should eql('/hello/Ford%20Prefect')
162
+ get redirect
163
+ last_response.body.should include("<h2>Hello</h2>\n \n Ford%20Prefect")
91
164
  end
92
165
  end
93
166
 
@@ -9,7 +9,7 @@ describe Trellis::Renderer do
9
9
  page = TestApp::Home.new
10
10
  renderer = Trellis::Renderer.new(page)
11
11
  result = renderer.render
12
- result.should == "<html><body><h1>Hello World!</h1></body></html>"
12
+ result.should == "<?xml version=\"1.0\"?>\n<html>\n <body>\n <h1>Hello World!</h1>\n </body>\n</html>\n"
13
13
  end
14
14
 
15
15
  it "should have access to page instance variables" do
@@ -17,14 +17,14 @@ describe Trellis::Renderer do
17
17
  page.value = "chunky bacon"
18
18
  renderer = Trellis::Renderer.new(page)
19
19
  result = renderer.render
20
- result.should == "<html><body>chunky bacon</body></html>"
20
+ result.should include("<body>\n chunky bacon\n </body>")
21
21
  end
22
22
 
23
23
  it "should have access to the page name" do
24
24
  page = TestApp::AnotherSamplePage.new
25
25
  renderer = Trellis::Renderer.new(page)
26
26
  result = renderer.render
27
- result.should == "<html><body>TestApp::AnotherSamplePage</body></html>"
27
+ result.should include("<body>\n TestApp::AnotherSamplePage\n </body>")
28
28
  end
29
29
 
30
30
  end
@@ -1,5 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
+ require_fixtures 'application_spec_applications'
4
+
3
5
  describe Trellis::Router, " when constructed" do
4
6
 
5
7
  it "with a page parameter should route to that page " do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trellis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Sam-Bodden
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-09 00:00:00 -07:00
12
+ date: 2009-12-06 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency