spontaneous 0.2.0.beta4 → 0.2.0.beta5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -0
- data/Gemfile +11 -6
- data/Readme.markdown +136 -69
- data/application/css/core.css.scss +27 -7
- data/application/css/editing.css.scss +4 -26
- data/application/css/schema_error.css.scss +22 -0
- data/application/js/content.js +11 -3
- data/application/js/edit_panel.js +1 -4
- data/application/js/field/file.js +17 -0
- data/application/js/field/image.js +30 -21
- data/application/js/field/string.js +4 -1
- data/application/js/field_preview.js +21 -16
- data/application/js/publish.js +6 -6
- data/application/js/types.js +5 -13
- data/application/js/views.js +2 -2
- data/application/js/views/box_view.js +3 -2
- data/application/js/views/page_piece_view.js +1 -1
- data/application/js/views/piece_view.js +1 -1
- data/application/views/schema_modification_error.html.erb +13 -3
- data/db/migrations/20131104101935_site_must_publish_all.rb +14 -0
- data/lib/spontaneous.rb +0 -1
- data/lib/spontaneous/box_style.rb +15 -9
- data/lib/spontaneous/capistrano/deploy.rb +13 -1
- data/lib/spontaneous/change.rb +11 -13
- data/lib/spontaneous/cli.rb +5 -2
- data/lib/spontaneous/cli/assets.rb +7 -1
- data/lib/spontaneous/cli/console.rb +7 -1
- data/lib/spontaneous/cli/content.rb +35 -0
- data/lib/spontaneous/cli/fields.rb +3 -2
- data/lib/spontaneous/cli/generate.rb +5 -2
- data/lib/spontaneous/cli/server.rb +12 -8
- data/lib/spontaneous/cli/site.rb +12 -12
- data/lib/spontaneous/cli/user.rb +28 -14
- data/lib/spontaneous/collections/box_set.rb +4 -4
- data/lib/spontaneous/collections/field_set.rb +4 -4
- data/lib/spontaneous/collections/prototype_set.rb +12 -4
- data/lib/spontaneous/data_mapper.rb +11 -7
- data/lib/spontaneous/data_mapper/content_model.rb +8 -0
- data/lib/spontaneous/data_mapper/content_model/associations.rb +1 -1
- data/lib/spontaneous/data_mapper/dataset.rb +14 -2
- data/lib/spontaneous/data_mapper/scope.rb +33 -13
- data/lib/spontaneous/facet.rb +4 -0
- data/lib/spontaneous/field.rb +12 -12
- data/lib/spontaneous/field/base.rb +27 -22
- data/lib/spontaneous/field/boolean.rb +4 -4
- data/lib/spontaneous/field/date.rb +2 -2
- data/lib/spontaneous/field/file.rb +24 -18
- data/lib/spontaneous/field/html.rb +1 -1
- data/lib/spontaneous/field/image.rb +6 -19
- data/lib/spontaneous/field/location.rb +1 -1
- data/lib/spontaneous/field/long_string.rb +3 -3
- data/lib/spontaneous/field/markdown.rb +3 -3
- data/lib/spontaneous/field/select.rb +2 -2
- data/lib/spontaneous/field/string.rb +2 -2
- data/lib/spontaneous/field/tags.rb +2 -2
- data/lib/spontaneous/field/update.rb +21 -20
- data/lib/spontaneous/field/webvideo.rb +6 -6
- data/lib/spontaneous/field/webvideo/fallback.rb +2 -2
- data/lib/spontaneous/field/webvideo/vimeo.rb +7 -7
- data/lib/spontaneous/generators/site.rb +2 -2
- data/lib/spontaneous/generators/site/Gemfile.tt +5 -1
- data/lib/spontaneous/layout.rb +2 -2
- data/lib/spontaneous/media.rb +1 -0
- data/lib/spontaneous/media/file.rb +6 -5
- data/lib/spontaneous/media/image/attributes.rb +4 -0
- data/lib/spontaneous/media/image/renderable.rb +4 -4
- data/lib/spontaneous/media/store.rb +22 -0
- data/lib/spontaneous/{storage → media/store}/backend.rb +1 -1
- data/lib/spontaneous/{storage → media/store}/cloud.rb +1 -1
- data/lib/spontaneous/{storage → media/store}/local.rb +1 -1
- data/lib/spontaneous/media/temp_file.rb +1 -1
- data/lib/spontaneous/model.rb +10 -7
- data/lib/spontaneous/model/action.rb +7 -0
- data/lib/spontaneous/model/action/clean.rb +87 -0
- data/lib/spontaneous/model/box/allowed_types.rb +15 -1
- data/lib/spontaneous/model/core.rb +10 -0
- data/lib/spontaneous/model/core/aliases.rb +1 -1
- data/lib/spontaneous/model/core/content_groups.rb +1 -1
- data/lib/spontaneous/model/core/fields.rb +1 -1
- data/lib/spontaneous/model/core/modifications.rb +2 -2
- data/lib/spontaneous/model/core/page_search.rb +4 -0
- data/lib/spontaneous/model/core/publishing.rb +4 -17
- data/lib/spontaneous/model/core/render.rb +4 -4
- data/lib/spontaneous/model/core/styles.rb +2 -2
- data/lib/spontaneous/model/core/visibility.rb +6 -2
- data/lib/spontaneous/model/page.rb +6 -2
- data/lib/spontaneous/model/page/controllers.rb +55 -17
- data/lib/spontaneous/model/page/formats.rb +12 -7
- data/lib/spontaneous/model/page/layouts.rb +2 -2
- data/lib/spontaneous/model/page/locks.rb +4 -1
- data/lib/spontaneous/model/page/page_tree.rb +40 -6
- data/lib/spontaneous/output.rb +14 -52
- data/lib/spontaneous/output/context.rb +11 -39
- data/lib/spontaneous/output/context/navigation.rb +31 -0
- data/lib/spontaneous/output/format.rb +15 -19
- data/lib/spontaneous/output/renderable.rb +99 -0
- data/lib/spontaneous/output/store.rb +24 -0
- data/lib/spontaneous/output/store/backend.rb +52 -0
- data/lib/spontaneous/output/store/file.rb +77 -0
- data/lib/spontaneous/output/store/moneta.rb +117 -0
- data/lib/spontaneous/output/store/revision.rb +34 -0
- data/lib/spontaneous/output/store/store.rb +15 -0
- data/lib/spontaneous/output/store/transaction.rb +44 -0
- data/lib/spontaneous/output/template/engine.rb +17 -7
- data/lib/spontaneous/output/template/renderer.rb +66 -40
- data/lib/spontaneous/page_lock.rb +5 -7
- data/lib/spontaneous/page_piece.rb +2 -2
- data/lib/spontaneous/permissions/user.rb +14 -7
- data/lib/spontaneous/plugins/application/features.rb +8 -4
- data/lib/spontaneous/plugins/application/state.rb +12 -6
- data/lib/spontaneous/prototypes/box_prototype.rb +9 -10
- data/lib/spontaneous/prototypes/field_prototype.rb +66 -15
- data/lib/spontaneous/publishing/immediate.rb +30 -26
- data/lib/spontaneous/rack.rb +12 -7
- data/lib/spontaneous/rack/back.rb +43 -37
- data/lib/spontaneous/rack/back/base.rb +4 -4
- data/lib/spontaneous/rack/back/changes.rb +2 -2
- data/lib/spontaneous/rack/back/file.rb +16 -24
- data/lib/spontaneous/rack/back/map.rb +5 -5
- data/lib/spontaneous/rack/back/preview.rb +3 -4
- data/lib/spontaneous/rack/back/schema.rb +1 -1
- data/lib/spontaneous/rack/back/site.rb +6 -7
- data/lib/spontaneous/rack/front.rb +19 -16
- data/lib/spontaneous/rack/middleware/authenticate.rb +3 -3
- data/lib/spontaneous/rack/middleware/reloader.rb +3 -2
- data/lib/spontaneous/rack/middleware/scope.rb +25 -19
- data/lib/spontaneous/rack/page_controller.rb +164 -13
- data/lib/spontaneous/rack/public.rb +23 -62
- data/lib/spontaneous/rack/static.rb +2 -3
- data/lib/spontaneous/schema.rb +27 -8
- data/lib/spontaneous/schema/schema_modification.rb +9 -1
- data/lib/spontaneous/schema/uid.rb +2 -2
- data/lib/spontaneous/schema/uid_map.rb +3 -2
- data/lib/spontaneous/search/database.rb +2 -2
- data/lib/spontaneous/search/field.rb +5 -3
- data/lib/spontaneous/search/index.rb +12 -7
- data/lib/spontaneous/search/results.rb +5 -3
- data/lib/spontaneous/server.rb +2 -2
- data/lib/spontaneous/site.rb +10 -3
- data/lib/spontaneous/site/features.rb +26 -6
- data/lib/spontaneous/site/helpers.rb +9 -12
- data/lib/spontaneous/site/level.rb +7 -9
- data/lib/spontaneous/site/map.rb +9 -11
- data/lib/spontaneous/site/paths.rb +5 -5
- data/lib/spontaneous/site/publishing.rb +83 -80
- data/lib/spontaneous/site/schema.rb +1 -7
- data/lib/spontaneous/site/search.rb +8 -18
- data/lib/spontaneous/site/selectors.rb +60 -54
- data/lib/spontaneous/site/state.rb +36 -30
- data/lib/spontaneous/site/storage.rb +10 -16
- data/lib/spontaneous/state.rb +8 -0
- data/lib/spontaneous/style.rb +32 -33
- data/lib/spontaneous/version.rb +1 -1
- data/spontaneous.gemspec +22 -21
- data/test/fixtures/public/templates/layouts/default.html.cut +1 -1
- data/test/fixtures/public/templates/layouts/default.pdf.cut +1 -1
- data/test/fixtures/public/templates/layouts/default.rss.cut +1 -1
- data/test/fixtures/search/config/indexes.rb +1 -1
- data/test/fixtures/serialisation/class_hash.yaml.erb +13 -1
- data/test/fixtures/serialisation/root_hash.yaml.erb +10 -0
- data/test/functional/test_application.rb +20 -24
- data/test/functional/test_back.rb +26 -27
- data/test/functional/test_cli.rb +146 -0
- data/test/functional/test_front.rb +287 -216
- data/test/functional/test_user_manager.rb +1 -1
- data/test/test_helper.rb +15 -11
- data/test/unit/test_alias.rb +32 -25
- data/test/unit/test_asset_bundler.rb +1 -1
- data/test/unit/test_assets.rb +34 -33
- data/test/unit/test_authentication.rb +1 -1
- data/test/unit/test_boxes.rb +16 -2
- data/test/unit/test_changesets.rb +23 -11
- data/test/unit/test_content.rb +15 -0
- data/test/unit/test_context.rb +139 -0
- data/test/unit/test_controllers.rb +374 -0
- data/test/{experimental → unit}/test_crypt.rb +0 -0
- data/test/unit/test_datamapper.rb +260 -237
- data/test/unit/test_datamapper_content.rb +42 -12
- data/test/{experimental → unit}/test_features.rb +85 -3
- data/test/unit/test_fields.rb +117 -42
- data/test/unit/test_formats.rb +11 -1
- data/test/unit/test_generators.rb +2 -2
- data/test/unit/test_helpers.rb +7 -8
- data/test/unit/test_images.rb +39 -2
- data/test/unit/test_layouts.rb +14 -12
- data/test/unit/test_media.rb +32 -23
- data/test/unit/test_output_store.rb +342 -0
- data/test/unit/test_page.rb +8 -1
- data/test/unit/test_permissions.rb +11 -7
- data/test/unit/test_plugins.rb +3 -3
- data/test/unit/test_prototype_set.rb +8 -1
- data/test/unit/test_publishing.rb +67 -54
- data/test/unit/test_render.rb +91 -38
- data/test/unit/test_revisions.rb +4 -4
- data/test/unit/test_schema.rb +109 -84
- data/test/unit/test_search.rb +42 -42
- data/test/unit/test_serialisation.rb +3 -2
- data/test/unit/test_site.rb +39 -27
- data/test/unit/test_storage.rb +9 -6
- data/test/unit/test_styles.rb +25 -32
- data/test/unit/test_templates.rb +8 -4
- metadata +89 -54
- data/lib/spontaneous/model/page/request.rb +0 -105
- data/lib/spontaneous/storage.rb +0 -22
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'foreman/engine/cli'
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
require File.expand_path('../../test_helper', __FILE__)
|
6
|
+
|
7
|
+
|
8
|
+
describe "CLI" do
|
9
|
+
let(:cli) { Spontaneous::Cli }
|
10
|
+
let(:root) { cli::Root }
|
11
|
+
|
12
|
+
describe "Console" do
|
13
|
+
let(:cmd) { cli::Console }
|
14
|
+
it "maps 'spot console' to Console#open" do
|
15
|
+
cmd.any_instance.expects(:open_console)
|
16
|
+
root.start(["console"])
|
17
|
+
end
|
18
|
+
it "maps 'spot c' to Console#open" do
|
19
|
+
cmd.any_instance.expects(:open_console)
|
20
|
+
root.start(["c"])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "Server" do
|
25
|
+
let(:cmd) { cli::Server }
|
26
|
+
|
27
|
+
def expect_subcommand_launch
|
28
|
+
foreman = mock()
|
29
|
+
foreman.expects(:register).with("front", regexp_matches(/spot server front/))
|
30
|
+
foreman.expects(:register).with("back", regexp_matches(/spot server back/))
|
31
|
+
foreman.expects(:register).with("tasks", regexp_matches(/spot server tasks/))
|
32
|
+
foreman.expects(:start)
|
33
|
+
::Foreman::Engine::CLI.expects(:new).returns(foreman)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "maps 'spot server' to Server#start" do
|
37
|
+
cmd.any_instance.expects(:start)
|
38
|
+
root.start(["server"])
|
39
|
+
end
|
40
|
+
|
41
|
+
it "'spot server' launches front & back" do
|
42
|
+
expect_subcommand_launch
|
43
|
+
root.start(["server"])
|
44
|
+
end
|
45
|
+
|
46
|
+
it "'spot s' launches front & back" do
|
47
|
+
expect_subcommand_launch
|
48
|
+
root.start(["s"])
|
49
|
+
end
|
50
|
+
|
51
|
+
it "maps 'spot server back' to Server#back" do
|
52
|
+
silence_logger do
|
53
|
+
cmd.any_instance.expects(:start_server).with(:back)
|
54
|
+
root.start(["server", "back"])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "maps 'spot s back' to Server#back" do
|
59
|
+
silence_logger do
|
60
|
+
cmd.any_instance.expects(:start_server).with(:back)
|
61
|
+
root.start(["s", "back"])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "maps 'spot server front' to Server#front" do
|
66
|
+
silence_logger do
|
67
|
+
cmd.any_instance.expects(:start_server).with(:front)
|
68
|
+
root.start(["server", "front"])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "maps 'spot s front' to Server#front" do
|
73
|
+
silence_logger do
|
74
|
+
cmd.any_instance.expects(:start_server).with(:front)
|
75
|
+
root.start(["s", "front"])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it "maps 'spot server tasks' to Server#tasks" do
|
80
|
+
silence_logger do
|
81
|
+
cmd.any_instance.expects(:start_simultaneous)
|
82
|
+
root.start(["server", "tasks"])
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it "maps 'spot s tasks' to Server#tasks" do
|
87
|
+
silence_logger do
|
88
|
+
cmd.any_instance.expects(:start_simultaneous)
|
89
|
+
root.start(["s", "tasks"])
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "User" do
|
95
|
+
let(:cmd) { cli::User }
|
96
|
+
it "maps 'spot user' to User#add" do
|
97
|
+
cmd.any_instance.expects(:add_user)
|
98
|
+
root.start(["user"])
|
99
|
+
end
|
100
|
+
|
101
|
+
it "maps 'spot user add' to User#add" do
|
102
|
+
cmd.any_instance.expects(:add_user)
|
103
|
+
root.start(["user", "add"])
|
104
|
+
end
|
105
|
+
|
106
|
+
it "maps 'spot user list' to User#list" do
|
107
|
+
cmd.any_instance.expects(:list_users)
|
108
|
+
root.start(["user", "list"])
|
109
|
+
end
|
110
|
+
|
111
|
+
it "maps 'spot user authenticate' to User#authenticate" do
|
112
|
+
cmd.any_instance.expects(:authenticate_user).with("garry", "fishingrod")
|
113
|
+
root.start(["user", "authenticate", "garry", "fishingrod"])
|
114
|
+
end
|
115
|
+
end
|
116
|
+
describe "Generate" do
|
117
|
+
let(:cmd) { cli::Generate }
|
118
|
+
let(:generator) { ::Spontaneous::Generators::Site }
|
119
|
+
it "maps 'generate site' to Generate#site" do
|
120
|
+
generator.expects(:start).with([])
|
121
|
+
root.start(["generate", "site"])
|
122
|
+
end
|
123
|
+
|
124
|
+
it "maps 'generate example.com' to Generate#site" do
|
125
|
+
generator.expects(:start).with(['example.com'])
|
126
|
+
root.start(["generate", "example.com"])
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "Assets" do
|
132
|
+
let(:cmd) { cli::Assets }
|
133
|
+
it "maps 'spot assets compile' to Assets#compile" do
|
134
|
+
cmd.any_instance.expects(:compile_assets)
|
135
|
+
root.start(["assets", "compile", "--destination=/tmp/destination"])
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "Content" do
|
140
|
+
let(:cmd) { cli::Content }
|
141
|
+
it "maps 'spot content clean' to Content#clean" do
|
142
|
+
cmd.any_instance.expects(:clean_content)
|
143
|
+
root.start(["content", "clean"])
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -8,6 +8,8 @@ describe "Front" do
|
|
8
8
|
include RackTestMethods
|
9
9
|
|
10
10
|
start do
|
11
|
+
@warn_level = $VERBOSE
|
12
|
+
$VERBOSE = nil
|
11
13
|
site_root = Dir.mktmpdir
|
12
14
|
FileUtils.cp_r(File.expand_path("../../fixtures/public/templates", __FILE__), site_root)
|
13
15
|
Spontaneous::Output.write_compiled_scripts = true
|
@@ -15,13 +17,21 @@ describe "Front" do
|
|
15
17
|
|
16
18
|
site = setup_site(site_root)
|
17
19
|
let(:site) { site }
|
18
|
-
S::Site.background_mode = :immediate
|
19
20
|
S::State.delete
|
20
21
|
|
21
|
-
|
22
|
+
site.background_mode = :immediate
|
23
|
+
site.output_store :Memory
|
22
24
|
::Content.delete
|
23
25
|
|
26
|
+
class ::Page
|
27
|
+
controller do
|
28
|
+
set :show_exceptions, false
|
29
|
+
set :raise_errors, true
|
30
|
+
set :dump_errors, true
|
31
|
+
end
|
32
|
+
end
|
24
33
|
class ::SitePage < ::Page
|
34
|
+
add_output :pdf
|
25
35
|
layout :default
|
26
36
|
layout :dynamic
|
27
37
|
box :pages
|
@@ -32,65 +42,99 @@ describe "Front" do
|
|
32
42
|
class ::StaticPage < ::Page
|
33
43
|
layout :default
|
34
44
|
end
|
35
|
-
class ::SubPage < SitePage; end
|
36
45
|
|
46
|
+
class ::DynamicRequestParams < ::Page
|
47
|
+
layout(:html) { "{{ params[:horse] }}*{{ equine }}" }
|
48
|
+
end
|
49
|
+
|
50
|
+
class ::DynamicRenderParams < ::Page
|
51
|
+
add_output :mobile
|
52
|
+
add_output :session
|
53
|
+
add_output :params
|
54
|
+
layout(:html) { "{{ teeth }}${ path }.${ __format }" }
|
55
|
+
layout(:mobile) { "${ path }.${ __format }" }
|
56
|
+
layout(:session) { %[{{session['user_id']}}/{{params['wendy']}}/{{request.env["SERVER_NAME"]}}] }
|
57
|
+
layout(:params) { "{{ something }}"}
|
58
|
+
end
|
59
|
+
|
60
|
+
class ::CommentablePage < ::Page
|
61
|
+
attr_accessor :status
|
62
|
+
|
63
|
+
add_output :xml
|
64
|
+
add_output :post
|
65
|
+
layout(:html) { "${path}.${ __format }" }
|
66
|
+
layout(:post) { "{{results.join(',')}}" }
|
67
|
+
layout(:xml) { "${ path}.${ __format }" }
|
68
|
+
box :pages
|
69
|
+
end
|
70
|
+
|
71
|
+
class ::FeedPage < ::Page
|
72
|
+
outputs :rss, [:html, {:mimetype => "application/xhtml+xml"}], [:pdf, {:private => true}]
|
73
|
+
layout { "${ path }.${ __format }" }
|
74
|
+
end
|
37
75
|
|
38
76
|
root = ::SitePage.create
|
39
77
|
about = ::SitePage.create(:slug => "about", :uid => "about")
|
40
|
-
|
78
|
+
feed = ::FeedPage.create(:slug => "feed", :uid => "feed")
|
41
79
|
news = ::SitePage.create(:slug => "news", :uid => "news")
|
42
|
-
dynamic = ::SitePage.create(:slug => "dynamic", :uid => "dynamic")
|
43
80
|
static = ::StaticPage.create(:slug => "static", :uid => "static")
|
44
|
-
|
81
|
+
dynamic_request_params = ::DynamicRequestParams.create(slug: "dynamic-request-params", uid: "dynamic_request_params")
|
82
|
+
dynamic_render_params = ::DynamicRenderParams.create(slug: "dynamic-render-params", uid: "dynamic_render_params")
|
83
|
+
commentable = ::CommentablePage.create(slug:"commentable", uid: "commentable")
|
45
84
|
root.pages << about
|
85
|
+
root.pages << feed
|
46
86
|
root.pages << news
|
47
|
-
root.pages <<
|
87
|
+
root.pages << dynamic_request_params
|
88
|
+
root.pages << dynamic_render_params
|
48
89
|
root.pages << static
|
49
|
-
|
90
|
+
root.pages << commentable
|
50
91
|
root.save
|
51
92
|
|
52
93
|
let(:root_id) { root.id }
|
53
94
|
let(:about_id) { about.id }
|
54
|
-
let(:
|
95
|
+
let(:feed_id) { feed.id }
|
55
96
|
let(:news_id) { news.id }
|
56
|
-
let(:
|
97
|
+
let(:dynamic_request_params_id) { dynamic_request_params.id }
|
98
|
+
let(:dynamic_render_params_id) { dynamic_render_params.id }
|
57
99
|
let(:static_id) { static.id }
|
100
|
+
let(:commentable_id) { commentable.id }
|
58
101
|
|
59
102
|
Content.delete_revision(1) rescue nil
|
60
103
|
|
61
104
|
Spontaneous.logger.silent! {
|
62
|
-
|
105
|
+
site.publish_all
|
63
106
|
}
|
64
107
|
end
|
65
108
|
|
66
109
|
finish do
|
67
|
-
|
68
|
-
|
69
|
-
|
110
|
+
[:SitePage, :StaticPage, :DynamicRequestParams, :DynamicRenderParams, :CommentablePage, :FeedPage].each do |const|
|
111
|
+
Object.send(:remove_const, const) rescue nil
|
112
|
+
end
|
113
|
+
if defined?(Content)
|
114
|
+
Content.delete
|
115
|
+
Content.delete_revision(1)
|
116
|
+
end
|
70
117
|
S::State.delete
|
71
|
-
Content.delete_revision(1)
|
72
118
|
teardown_site(true)
|
73
119
|
Spontaneous::Output.write_compiled_scripts = false
|
120
|
+
$VERBOSE = @warn_level
|
74
121
|
end
|
75
122
|
|
76
123
|
let(:root) { Content[root_id] }
|
77
124
|
let(:about) { Content[about_id] }
|
78
|
-
let(:
|
125
|
+
let(:feed) { Content[feed_id] }
|
79
126
|
let(:news) { Content[news_id] }
|
80
|
-
let(:
|
127
|
+
let(:dynamic_request_params) { Content[dynamic_request_params_id] }
|
128
|
+
let(:dynamic_render_params) { Content[dynamic_render_params_id] }
|
81
129
|
let(:static) { Content[static_id] }
|
130
|
+
let(:commentable) { Content[commentable_id] }
|
82
131
|
|
83
132
|
def app
|
84
|
-
Spontaneous::Rack::Front.application
|
133
|
+
@app ||= Spontaneous::Rack::Front.application(site)
|
85
134
|
end
|
86
135
|
|
87
|
-
|
88
|
-
|
89
|
-
SitePage.instance_variable_set(:@request_blocks, {})
|
90
|
-
[root, about, subpage, news, static].each do |page|
|
91
|
-
page.layout = :default
|
92
|
-
end
|
93
|
-
dynamic.layout = :dynamic
|
136
|
+
def renderer
|
137
|
+
@renderer ||= Spontaneous::Output::Template::PublishRenderer.new(site, true)
|
94
138
|
end
|
95
139
|
|
96
140
|
def session
|
@@ -103,10 +147,6 @@ describe "Front" do
|
|
103
147
|
|
104
148
|
describe "Public pages" do
|
105
149
|
|
106
|
-
after do
|
107
|
-
about.class.outputs :html
|
108
|
-
end
|
109
|
-
|
110
150
|
it "return a 404 if asked for a non-existant page" do
|
111
151
|
get '/not-bloody-likely'
|
112
152
|
assert last_response.status == 404
|
@@ -133,7 +173,6 @@ describe "Front" do
|
|
133
173
|
end
|
134
174
|
|
135
175
|
it "honor the format of the request" do
|
136
|
-
about.class.outputs :html, :pdf
|
137
176
|
get '/about.pdf'
|
138
177
|
assert last_response.ok?
|
139
178
|
last_response.body.must_equal "/about.pdf\n"
|
@@ -141,19 +180,17 @@ describe "Front" do
|
|
141
180
|
end
|
142
181
|
|
143
182
|
it "provide the default format of the page if none is explicitly given" do
|
144
|
-
|
145
|
-
get '/about'
|
183
|
+
get '/feed'
|
146
184
|
assert last_response.ok?
|
147
185
|
last_response.content_type.must_equal ::Rack::Mime.mime_type('.rss') + ";charset=utf-8"
|
148
|
-
last_response.body.must_equal "/
|
186
|
+
last_response.body.must_equal "/feed.rss"
|
149
187
|
end
|
150
188
|
|
151
189
|
it "return a custom content type if one is defined" do
|
152
|
-
|
153
|
-
get '/about'
|
190
|
+
get '/feed.html'
|
154
191
|
assert last_response.ok?
|
155
192
|
last_response.content_type.must_equal "application/xhtml+xml;charset=utf-8"
|
156
|
-
last_response.body.must_equal "/
|
193
|
+
last_response.body.must_equal "/feed.html"
|
157
194
|
end
|
158
195
|
|
159
196
|
|
@@ -163,21 +200,19 @@ describe "Front" do
|
|
163
200
|
end
|
164
201
|
|
165
202
|
it "raise a 404 when accessing a private format" do
|
166
|
-
|
167
|
-
get '/about.rss'
|
203
|
+
get '/feed.pdf'
|
168
204
|
assert last_response.status == 404
|
169
205
|
end
|
170
206
|
|
171
207
|
describe "Dynamic pages" do
|
172
208
|
before do
|
209
|
+
Content::Page.stubs(:path).with("/").returns(root)
|
173
210
|
Content::Page.stubs(:path).with("/about").returns(about)
|
174
211
|
Content::Page.stubs(:path).with("/static").returns(static)
|
175
212
|
Content::Page.stubs(:path).with("/news").returns(news)
|
176
213
|
end
|
177
214
|
|
178
215
|
after do
|
179
|
-
about.layout = :default
|
180
|
-
SitePage.instance_variable_set(:@request_blocks, {})
|
181
216
|
end
|
182
217
|
|
183
218
|
it "default to static behaviour" do
|
@@ -185,139 +220,176 @@ describe "Front" do
|
|
185
220
|
page = SitePage.new
|
186
221
|
refute page.dynamic?
|
187
222
|
end
|
223
|
+
|
188
224
|
it "correctly show a dynamic behaviour" do
|
189
|
-
|
190
|
-
show "/static"
|
225
|
+
DynamicRenderParams.controller do
|
226
|
+
get { show "/static" }
|
191
227
|
end
|
192
|
-
assert
|
193
|
-
page =
|
228
|
+
assert DynamicRenderParams.dynamic?
|
229
|
+
page = DynamicRenderParams.new
|
194
230
|
assert page.dynamic?
|
195
231
|
end
|
196
232
|
|
197
233
|
it "render an alternate page if passed a page" do
|
198
|
-
|
199
|
-
|
234
|
+
DynamicRenderParams.controller do
|
235
|
+
get { render site['/static'] }
|
200
236
|
end
|
201
|
-
get '/
|
237
|
+
get '/dynamic-render-params'
|
202
238
|
assert last_response.ok?
|
203
239
|
last_response.body.must_equal "/static.html\n"
|
204
240
|
end
|
205
241
|
|
206
242
|
it "render an alternate page if passed a path" do
|
207
|
-
|
208
|
-
|
209
|
-
show "/static"
|
243
|
+
DynamicRenderParams.controller do
|
244
|
+
get { render "/static" }
|
210
245
|
end
|
211
|
-
get '/
|
246
|
+
get '/dynamic-render-params'
|
212
247
|
assert last_response.ok?
|
213
248
|
last_response.body.must_equal "/static.html\n"
|
214
249
|
end
|
215
250
|
|
216
251
|
it "render an alternate page if passed a uid with a #" do
|
217
|
-
|
218
|
-
|
219
|
-
show "static"
|
252
|
+
DynamicRenderParams.controller do
|
253
|
+
get { render "static" }
|
220
254
|
end
|
221
|
-
get '/
|
255
|
+
get '/dynamic-render-params'
|
222
256
|
assert last_response.ok?
|
223
257
|
last_response.body.must_equal "/static.html\n"
|
224
258
|
end
|
225
259
|
|
226
260
|
it "render an alternate page if passed a uid" do
|
227
|
-
|
228
|
-
|
229
|
-
show "static"
|
261
|
+
DynamicRenderParams.controller do
|
262
|
+
get { render "static" }
|
230
263
|
end
|
231
|
-
get '/
|
264
|
+
get '/dynamic-render-params'
|
232
265
|
assert last_response.ok?
|
233
266
|
last_response.body.must_equal "/static.html\n"
|
234
267
|
end
|
235
268
|
|
236
269
|
it "return not found of #request_show returns an invalid uid or path" do
|
237
|
-
|
238
|
-
|
239
|
-
show "caterpillars"
|
270
|
+
DynamicRenderParams.controller do
|
271
|
+
get { render "caterpillars" }
|
240
272
|
end
|
241
|
-
get '/
|
273
|
+
get '/dynamic-render-params'
|
242
274
|
assert last_response.status == 404
|
243
275
|
end
|
244
276
|
|
245
277
|
it "return the right status code" do
|
246
|
-
|
247
|
-
|
278
|
+
DynamicRenderParams.controller do
|
279
|
+
get { render "static", 403 }
|
248
280
|
end
|
249
|
-
get '/
|
250
|
-
assert last_response.status ==
|
281
|
+
get '/dynamic-render-params'
|
282
|
+
assert last_response.status == 403
|
251
283
|
last_response.body.must_equal "/static.html\n"
|
252
284
|
end
|
253
285
|
|
254
286
|
it "allow handing POST requests" do
|
255
|
-
|
256
|
-
|
287
|
+
DynamicRenderParams.controller do
|
288
|
+
post { render "static" }
|
257
289
|
end
|
258
|
-
post '/
|
290
|
+
post '/dynamic-render-params'
|
259
291
|
assert last_response.status == 200, "Expected status 200 but recieved #{last_response.status}"
|
260
292
|
last_response.body.must_equal "/static.html\n"
|
261
293
|
end
|
262
294
|
|
263
295
|
it "allow returning of any status code without altering content" do
|
264
|
-
|
265
|
-
|
296
|
+
DynamicRenderParams.controller do
|
297
|
+
get { render 403 }
|
266
298
|
end
|
267
|
-
get '/
|
268
|
-
assert last_response.status ==
|
269
|
-
last_response.body.must_equal "/
|
299
|
+
get '/dynamic-render-params'
|
300
|
+
assert last_response.status == 403
|
301
|
+
last_response.body.must_equal "/dynamic-render-params.html"
|
270
302
|
end
|
271
303
|
|
272
304
|
it "allow altering of headers" do
|
273
|
-
|
274
|
-
|
305
|
+
DynamicRenderParams.controller do
|
306
|
+
get do
|
307
|
+
headers["X-Works"] = "Yes"
|
308
|
+
render
|
309
|
+
end
|
275
310
|
end
|
276
|
-
get '/
|
311
|
+
get '/dynamic-render-params'
|
277
312
|
assert last_response.status == 200
|
278
|
-
last_response.body.must_equal "/
|
313
|
+
last_response.body.must_equal "/dynamic-render-params.html"
|
279
314
|
last_response.headers["X-Works"].must_equal "Yes"
|
280
315
|
end
|
281
316
|
|
282
317
|
it "allow passing of template params & a page to the render call" do
|
283
|
-
|
284
|
-
|
318
|
+
DynamicRenderParams.controller do
|
319
|
+
get { render page, :teeth => "blue" }
|
320
|
+
end
|
321
|
+
get '/dynamic-render-params'
|
322
|
+
assert last_response.status == 200
|
323
|
+
last_response.body.must_equal "blue/dynamic-render-params.html"
|
324
|
+
end
|
325
|
+
|
326
|
+
it "allows setting status code and passing parameters to the show call" do
|
327
|
+
DynamicRenderParams.controller do
|
328
|
+
get { render "$dynamic_render_params", 401, :teeth => "white" }
|
285
329
|
end
|
286
|
-
|
287
|
-
|
330
|
+
get '/dynamic-render-params'
|
331
|
+
assert last_response.status == 401
|
332
|
+
last_response.body.must_equal "white/dynamic-render-params.html"
|
333
|
+
end
|
334
|
+
|
335
|
+
it "allows passing parameters to the render call" do
|
336
|
+
DynamicRenderParams.controller do
|
337
|
+
get { render "$dynamic_render_params", :teeth => "white" }
|
288
338
|
end
|
289
|
-
get '/
|
339
|
+
get '/dynamic-render-params'
|
290
340
|
assert last_response.status == 200
|
291
|
-
last_response.body.must_equal "white"
|
292
|
-
SitePage.instance_variable_set(:@layout_procs, nil)
|
341
|
+
last_response.body.must_equal "white/dynamic-render-params.html"
|
293
342
|
end
|
294
343
|
|
295
344
|
it "give access to the request params within the controller" do
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
345
|
+
DynamicRequestParams.controller do
|
346
|
+
post do
|
347
|
+
value = params[:horse]
|
348
|
+
render page, :equine => value
|
349
|
+
end
|
300
350
|
end
|
301
|
-
post '/
|
351
|
+
post '/dynamic-request-params', :horse => "dancing"
|
302
352
|
assert last_response.status == 200
|
303
353
|
last_response.body.must_equal "dancing*dancing"
|
304
|
-
SitePage.instance_variable_set(:@layout_procs, nil)
|
305
354
|
end
|
306
355
|
|
307
356
|
it "allows for dynamically setting the output" do
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
output :mobile
|
357
|
+
DynamicRenderParams.controller do
|
358
|
+
get do
|
359
|
+
if request.user_agent =~ /iPhone/
|
360
|
+
output :mobile
|
361
|
+
end
|
362
|
+
render teeth: "clean"
|
315
363
|
end
|
316
364
|
end
|
317
|
-
get "/
|
318
|
-
last_response.
|
319
|
-
|
320
|
-
|
365
|
+
get "/dynamic-render-params", {}, { "HTTP_USER_AGENT" => "Desktop" }
|
366
|
+
assert last_response.status == 200, "Expected status 200 but got #{last_response.status}"
|
367
|
+
last_response.body.must_equal "clean/dynamic-render-params.html"
|
368
|
+
get "/dynamic-render-params", {}, { "HTTP_USER_AGENT" => "iPhone" }
|
369
|
+
last_response.body.must_equal "/dynamic-render-params.mobile"
|
370
|
+
end
|
371
|
+
|
372
|
+
it "inherits any request handlers from superclasses" do
|
373
|
+
# request block inheritance is done at type creation & is not dynamic
|
374
|
+
# so we need to create a new class that will inherit the newly minted
|
375
|
+
# :get request handler
|
376
|
+
DynamicRenderParams.controller do
|
377
|
+
get { render "about" }
|
378
|
+
end
|
379
|
+
|
380
|
+
class ::TempPage < DynamicRenderParams; end
|
381
|
+
|
382
|
+
temp = ::TempPage.create(:slug => "temp", :uid => "temp")
|
383
|
+
root.pages << temp
|
384
|
+
root.save
|
385
|
+
site.model.stubs(:path).with("/temp").returns(temp)
|
386
|
+
|
387
|
+
get "/temp"
|
388
|
+
last_response.status.must_equal 200
|
389
|
+
last_response.body.must_equal "/about.html\n"
|
390
|
+
|
391
|
+
temp.destroy
|
392
|
+
Object.send(:remove_const, "TempPage")
|
321
393
|
end
|
322
394
|
|
323
395
|
# should "handle anything that responds to #render(format)" do
|
@@ -336,55 +408,57 @@ describe "Front" do
|
|
336
408
|
end
|
337
409
|
|
338
410
|
it "respond appropriatly to redirects to path" do
|
339
|
-
|
340
|
-
|
411
|
+
DynamicRenderParams.controller do
|
412
|
+
get do
|
413
|
+
redirect "/news"
|
414
|
+
end
|
341
415
|
end
|
342
|
-
get '/
|
416
|
+
get '/dynamic-render-params'
|
343
417
|
assert last_response.status == 302
|
344
418
|
last_response.headers["Location"].must_equal "http://example.org/news"
|
345
419
|
end
|
346
420
|
|
347
421
|
it "respond appropriately to redirects to a Page instance" do
|
348
|
-
|
349
|
-
redirect Page.path("/news")
|
422
|
+
DynamicRenderParams.controller do
|
423
|
+
get { redirect Page.path("/news") }
|
350
424
|
end
|
351
|
-
get '/
|
425
|
+
get '/dynamic-render-params'
|
352
426
|
assert last_response.status == 302
|
353
427
|
last_response.headers["Location"].must_equal "http://example.org/news"
|
354
428
|
end
|
355
429
|
|
356
430
|
it "respond appropriately to redirects to a UID" do
|
357
|
-
|
358
|
-
redirect "news"
|
431
|
+
DynamicRenderParams.controller do
|
432
|
+
get { redirect "news" }
|
359
433
|
end
|
360
|
-
get '/
|
434
|
+
get '/dynamic-render-params'
|
361
435
|
assert last_response.status == 302
|
362
436
|
last_response.headers["Location"].must_equal "http://example.org/news"
|
363
437
|
end
|
364
438
|
|
365
439
|
it "recognise a :temporary redirect" do
|
366
|
-
|
367
|
-
redirect "/news", :temporary
|
440
|
+
DynamicRenderParams.controller do
|
441
|
+
get { redirect "/news", :temporary }
|
368
442
|
end
|
369
|
-
get '/
|
443
|
+
get '/dynamic-render-params'
|
370
444
|
assert last_response.status == 302
|
371
445
|
last_response.headers["Location"].must_equal "http://example.org/news"
|
372
446
|
end
|
373
447
|
|
374
448
|
it "recognise a :permanent redirect" do
|
375
|
-
|
376
|
-
redirect "/news", :permanent
|
449
|
+
DynamicRenderParams.controller do
|
450
|
+
get { redirect "/news", :permanent }
|
377
451
|
end
|
378
|
-
get '/
|
452
|
+
get '/dynamic-render-params'
|
379
453
|
assert last_response.status == 301
|
380
454
|
last_response.headers["Location"].must_equal "http://example.org/news"
|
381
455
|
end
|
382
456
|
|
383
457
|
it "correctly apply numeric status codes" do
|
384
|
-
|
385
|
-
redirect "/news", 307
|
458
|
+
DynamicRenderParams.controller do
|
459
|
+
get { redirect "/news", 307 }
|
386
460
|
end
|
387
|
-
get '/
|
461
|
+
get '/dynamic-render-params'
|
388
462
|
last_response.headers["Location"].must_equal "http://example.org/news"
|
389
463
|
assert last_response.status == 307
|
390
464
|
end
|
@@ -404,55 +478,60 @@ describe "Front" do
|
|
404
478
|
end
|
405
479
|
|
406
480
|
it "have access to the params, request & session object" do
|
407
|
-
|
408
|
-
|
409
|
-
|
481
|
+
DynamicRenderParams.controller do
|
482
|
+
get { render }
|
483
|
+
end
|
484
|
+
get '/dynamic-render-params.session', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 }
|
485
|
+
assert last_response.ok?, "Expected status 200 but got #{last_response.status}"
|
486
|
+
last_response.body.must_equal "42/peter/example.org"
|
410
487
|
end
|
411
488
|
|
489
|
+
# Disabled for the moment while I think about the implications of the
|
490
|
+
# template store & if there isn't a better way to optimise the render
|
491
|
+
# by using a LRU cache of the compiled classes or something like that.
|
412
492
|
describe "caching" do
|
413
|
-
it "use pre-rendered versions of the templates" do
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
end
|
420
|
-
|
421
|
-
it "cache templates as ruby files" do
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
end
|
437
|
-
|
438
|
-
it "not cache templates if caching turned off" do
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
end
|
493
|
+
# it "use pre-rendered versions of the templates" do
|
494
|
+
# dummy_content = 'cached-version/#{session[\'user_id\']}'
|
495
|
+
# dummy_template = File.join(site.revision_root, "current/dynamic/dynamic.html.cut")
|
496
|
+
# File.open(dummy_template, 'w') { |f| f.write(dummy_content) }
|
497
|
+
# get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 }
|
498
|
+
# last_response.body.must_equal "cached-version/42"
|
499
|
+
# end
|
500
|
+
|
501
|
+
# it "cache templates as ruby files" do
|
502
|
+
# dummy_content = 'cached-version/#{session[\'user_id\']}'
|
503
|
+
# dummy_template = File.join(site.revision_root, "current/dynamic/index.html.cut")
|
504
|
+
# # Spontaneous::Output.renderer.write_compiled_scripts = true
|
505
|
+
# File.open(dummy_template, 'w') { |f| f.write(dummy_content) }
|
506
|
+
# FileUtils.rm(@cache_file) if File.exists?(@cache_file)
|
507
|
+
# refute File.exists?(@cache_file)
|
508
|
+
# get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 }
|
509
|
+
|
510
|
+
# assert File.exists?(@cache_file)
|
511
|
+
# File.open(@cache_file, 'w') { |f| f.write('@__buf << %Q`@cache_filed-version/#{params[\'wendy\']}`;')}
|
512
|
+
# # Force compiled file to have a later timestamp
|
513
|
+
# File.utime(Time.now, Time.now + 1, @cache_file)
|
514
|
+
# get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 }
|
515
|
+
# last_response.body.must_equal "@cache_filed-version/peter"
|
516
|
+
# end
|
517
|
+
|
518
|
+
# it "not cache templates if caching turned off" do
|
519
|
+
# Spontaneous::Output.cache_templates = false
|
520
|
+
# refute File.exists?(@cache_file)
|
521
|
+
# get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 }
|
522
|
+
# refute File.exists?(@cache_file)
|
523
|
+
# end
|
444
524
|
end
|
445
525
|
end
|
446
526
|
|
447
527
|
describe "Model controllers" do
|
448
528
|
before do
|
449
|
-
SitePage.instance_variable_set(:@request_blocks, {})
|
450
529
|
class ::TestController < Spontaneous::Rack::PageController
|
451
530
|
get '/' do
|
452
531
|
"Magic"
|
453
532
|
end
|
454
533
|
end
|
455
|
-
|
534
|
+
CommentablePage.controller :comments do
|
456
535
|
get '/' do
|
457
536
|
"Success"
|
458
537
|
end
|
@@ -465,7 +544,7 @@ describe "Front" do
|
|
465
544
|
end
|
466
545
|
end
|
467
546
|
|
468
|
-
|
547
|
+
CommentablePage.controller :status do
|
469
548
|
get '/:status' do
|
470
549
|
page.status = params[:status]
|
471
550
|
page
|
@@ -477,7 +556,7 @@ describe "Front" do
|
|
477
556
|
end
|
478
557
|
end
|
479
558
|
|
480
|
-
|
559
|
+
CommentablePage.controller :search do
|
481
560
|
get '/render/:query' do
|
482
561
|
render({ results: %w(a b c)})
|
483
562
|
end
|
@@ -487,149 +566,141 @@ describe "Front" do
|
|
487
566
|
end
|
488
567
|
|
489
568
|
get '/renderoutput/:query' do
|
490
|
-
render page, :
|
569
|
+
render page, :post, { results: %w(a b c)}
|
491
570
|
end
|
492
571
|
end
|
493
572
|
|
494
|
-
|
573
|
+
CommentablePage.controller :test, ::TestController
|
495
574
|
|
496
|
-
|
575
|
+
CommentablePage.controller :test2, ::TestController do
|
497
576
|
get "/block" do
|
498
577
|
"Block"
|
499
578
|
end
|
500
579
|
end
|
501
580
|
|
581
|
+
class ::SubPage < CommentablePage; end
|
582
|
+
@subpage = ::SubPage.create(:slug => "now", :uid => "now")
|
583
|
+
commentable.pages << @subpage
|
584
|
+
|
585
|
+
@subpage.reload
|
586
|
+
|
502
587
|
Content.stubs(:path).with("/").returns(root)
|
503
|
-
Content.stubs(:path).with("/
|
504
|
-
Content.stubs(:path).with("/
|
588
|
+
Content.stubs(:path).with("/commentable").returns(commentable)
|
589
|
+
Content.stubs(:path).with("/commentable/now").returns(@subpage)
|
590
|
+
@renderer = Spontaneous::Output.published_renderer(site)
|
505
591
|
end
|
506
592
|
|
507
593
|
after do
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
594
|
+
Object.send(:remove_const, :SubPage) rescue nil
|
595
|
+
CommentablePage.instance_variable_set(:@request_blocks, {})
|
596
|
+
CommentablePage.send(:remove_const, :StatusController) rescue nil
|
597
|
+
CommentablePage.send(:remove_const, :TestController) rescue nil
|
598
|
+
CommentablePage.send(:remove_const, :Test2Controller) rescue nil
|
512
599
|
Object.send(:remove_const, :TestController) rescue nil
|
513
|
-
about.class.outputs :html
|
514
600
|
end
|
515
601
|
|
516
602
|
it "not be used unless necessary" do
|
517
|
-
get "/
|
603
|
+
get "/commentable"
|
518
604
|
assert last_response.ok?
|
519
|
-
last_response.body.must_equal
|
605
|
+
last_response.body.must_equal commentable.render_using(@renderer).read
|
520
606
|
end
|
521
607
|
|
522
|
-
it "work on
|
523
|
-
get "/@comments"
|
608
|
+
it "work on sub classes" do
|
609
|
+
get "/commentable/now/@comments"
|
524
610
|
assert last_response.ok?
|
525
611
|
last_response.body.must_equal "Success"
|
526
612
|
end
|
527
613
|
|
528
614
|
|
529
615
|
it "be recognised" do
|
530
|
-
get "/
|
616
|
+
get "/commentable/@comments"
|
531
617
|
assert last_response.ok?
|
532
618
|
last_response.body.must_equal "Success"
|
533
619
|
end
|
534
620
|
|
535
621
|
it "render the page correctly if action returns page object" do
|
536
|
-
get "/
|
622
|
+
get "/commentable/@comments/page"
|
537
623
|
assert last_response.ok?
|
538
|
-
last_response.body.must_equal
|
624
|
+
last_response.body.must_equal commentable.render_using(@renderer).read
|
539
625
|
end
|
540
626
|
|
541
627
|
it "return 404 if trying unknown namespace" do
|
542
|
-
get "/
|
628
|
+
get "/commentable/@missing/action"
|
543
629
|
assert last_response.status == 404
|
544
630
|
end
|
545
631
|
|
546
632
|
it "respond to multiple namespaces" do
|
547
|
-
get "/
|
633
|
+
get "/commentable/@status/good"
|
548
634
|
assert last_response.ok?
|
549
|
-
last_response.body.must_equal
|
550
|
-
|
635
|
+
last_response.body.must_equal commentable.render_using(@renderer).read
|
636
|
+
commentable.status.must_equal "good"
|
551
637
|
end
|
552
638
|
|
553
639
|
it "accept POST requests" do
|
554
|
-
post "/
|
640
|
+
post "/commentable/@status/good"
|
555
641
|
assert last_response.ok?
|
556
|
-
last_response.body.must_equal
|
557
|
-
|
642
|
+
last_response.body.must_equal commentable.render_using(@renderer).read
|
643
|
+
commentable.status.must_equal "good"
|
558
644
|
end
|
559
645
|
|
560
646
|
it "return 404 unless post request has an action" do
|
561
|
-
Page.expects(:path).with("/
|
562
|
-
post "/
|
647
|
+
Page.expects(:path).with("/commentable").never
|
648
|
+
post "/commentable"
|
563
649
|
assert last_response.status == 404
|
564
650
|
end
|
565
651
|
|
566
652
|
it "return 404 for post requests to unknown actions" do
|
567
|
-
post "/
|
653
|
+
post "/commentable/@status/missing/action"
|
568
654
|
assert last_response.status == 404
|
569
655
|
end
|
570
656
|
|
571
657
|
# probably the wrong place to test this -- should be in units -- but what the heck
|
572
658
|
it "be able to generate urls for actions" do
|
573
|
-
|
659
|
+
commentable.action_url(:status, "/good").must_equal "/commentable/@status/good"
|
574
660
|
end
|
575
661
|
|
576
662
|
it "be able to generate urls for actions with no path" do
|
577
|
-
|
663
|
+
commentable.action_url(:status).must_equal "/commentable/@status"
|
578
664
|
end
|
579
665
|
|
580
666
|
it "pass the output onto the page if the action returns it to the render call" do
|
581
|
-
|
582
|
-
about.class.layout do
|
583
|
-
"${path}.${__format}"
|
584
|
-
end
|
585
|
-
get "/about/@comments/page.xml"
|
667
|
+
get "/commentable/@comments/page.xml"
|
586
668
|
assert last_response.ok?
|
587
|
-
last_response.body.must_equal "/
|
669
|
+
last_response.body.must_equal "/commentable.xml"
|
588
670
|
end
|
589
671
|
|
590
672
|
it "use the format within the action if required" do
|
591
|
-
|
592
|
-
|
593
|
-
assert last_response.ok?
|
673
|
+
get "/commentable/@comments/format.xml"
|
674
|
+
assert last_response.ok?, "Expected status 200 but got #{last_response.status}"
|
594
675
|
last_response.body.must_equal "xml"
|
595
676
|
end
|
596
677
|
|
597
678
|
it "be inherited by subclasses" do
|
598
|
-
get "/
|
679
|
+
get "/commentable/now/@comments"
|
599
680
|
assert last_response.ok?
|
600
681
|
last_response.body.must_equal "Success"
|
601
682
|
end
|
602
683
|
|
603
684
|
it "allow definition of controller using class" do
|
604
|
-
get "/
|
685
|
+
get "/commentable/@test"
|
605
686
|
assert last_response.ok?
|
606
687
|
last_response.body.must_equal "Magic"
|
607
688
|
end
|
608
689
|
|
609
690
|
it "allow definition of controller using class and extend it using block" do
|
610
|
-
get "/
|
691
|
+
get "/commentable/@test2/block"
|
611
692
|
assert last_response.ok?
|
612
693
|
last_response.body.must_equal "Block"
|
613
694
|
end
|
614
695
|
|
615
696
|
it "allows passing parameters to the page render" do
|
616
|
-
|
617
|
-
about.class.layout do
|
618
|
-
"{{results.join(',')}}"
|
619
|
-
end
|
620
|
-
|
621
|
-
get "/about/@search/render/query.xml"
|
697
|
+
get "/commentable/@search/render/query.post"
|
622
698
|
assert last_response.ok?, "Expected 200 OK but got #{last_response.status}"
|
623
699
|
last_response.body.must_equal "a,b,c"
|
624
700
|
end
|
625
701
|
|
626
702
|
it "allows passing an output to the page render" do
|
627
|
-
|
628
|
-
about.class.layout do
|
629
|
-
"{{results.join(',')}}"
|
630
|
-
end
|
631
|
-
|
632
|
-
get "/about/@search/renderoutput/query"
|
703
|
+
get "/commentable/@search/renderoutput/query"
|
633
704
|
assert last_response.ok?, "Expected 200 OK but got #{last_response.status}"
|
634
705
|
last_response.body.must_equal "a,b,c"
|
635
706
|
end
|
@@ -642,7 +713,7 @@ describe "Front" do
|
|
642
713
|
end
|
643
714
|
end
|
644
715
|
|
645
|
-
|
716
|
+
CommentablePage.controller :drummer do
|
646
717
|
get '/' do
|
647
718
|
"Success"
|
648
719
|
end
|
@@ -654,8 +725,8 @@ describe "Front" do
|
|
654
725
|
end
|
655
726
|
|
656
727
|
it "affect all controller actions" do
|
657
|
-
get "/
|
658
|
-
assert last_response.ok
|
728
|
+
get "/commentable/@drummer/nothing"
|
729
|
+
assert last_response.ok?, "Expected 200 got #{last_response.status}"
|
659
730
|
last_response.body.must_equal "Something"
|
660
731
|
end
|
661
732
|
end
|
@@ -703,4 +774,4 @@ describe "Front" do
|
|
703
774
|
end
|
704
775
|
end
|
705
776
|
end
|
706
|
-
end
|
777
|
+
end
|