puffer_pages 0.1.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rspec +3 -1
- data/.rvmrc +1 -1
- data/.travis.yml +13 -5
- data/CHANGELOG.md +130 -7
- data/Gemfile +10 -1
- data/README.md +18 -20
- data/Rakefile +1 -1
- data/app/assets/javascripts/puffer/codemirror.js +4237 -2223
- data/app/assets/javascripts/puffer/codemirror/css.js +359 -18
- data/app/assets/javascripts/puffer/codemirror/htmlmixed.js +15 -14
- data/app/assets/javascripts/puffer/codemirror/javascript.js +91 -29
- data/app/assets/javascripts/puffer/codemirror/liquid.js +185 -0
- data/app/assets/javascripts/puffer/codemirror/xml.js +99 -27
- data/app/assets/javascripts/puffer/codemirror/yaml.js +95 -0
- data/app/assets/javascripts/puffer/liquid.js +28 -12
- data/app/assets/javascripts/puffer/matchbrackets.js +63 -0
- data/app/assets/javascripts/puffer/multiplex.js +95 -0
- data/app/assets/javascripts/puffer/puffer_pages.js +140 -44
- data/app/assets/stylesheets/puffer/codemirror.css +203 -67
- data/app/assets/stylesheets/puffer/codemirror/ambiance-mobile.css +6 -0
- data/app/assets/stylesheets/puffer/codemirror/ambiance.css +76 -0
- data/app/assets/stylesheets/puffer/codemirror/blackboard.css +25 -0
- data/app/assets/stylesheets/puffer/codemirror/cobalt.css +4 -4
- data/app/assets/stylesheets/puffer/codemirror/eclipse.css +1 -1
- data/app/assets/stylesheets/puffer/codemirror/elegant.css +2 -2
- data/app/assets/stylesheets/puffer/codemirror/erlang-dark.css +21 -0
- data/app/assets/stylesheets/puffer/codemirror/lesser-dark.css +44 -0
- data/app/assets/stylesheets/puffer/codemirror/monokai.css +4 -4
- data/app/assets/stylesheets/puffer/codemirror/neat.css +3 -3
- data/app/assets/stylesheets/puffer/codemirror/night.css +4 -4
- data/app/assets/stylesheets/puffer/codemirror/rubyblue.css +5 -5
- data/app/assets/stylesheets/puffer/codemirror/solarized.css +207 -0
- data/app/assets/stylesheets/puffer/codemirror/twilight.css +26 -0
- data/app/assets/stylesheets/puffer/codemirror/vibrant-ink.css +27 -0
- data/app/assets/stylesheets/puffer/codemirror/xq-dark.css +46 -0
- data/app/assets/stylesheets/puffer/puffer_pages.css +64 -35
- data/app/components/codemirror/form.html.erb +22 -6
- data/app/components/codemirror_component.rb +1 -8
- data/app/components/handlers/form.html.erb +8 -0
- data/app/components/handlers_component.rb +8 -0
- data/app/components/page_parts/_page_part.html.erb +6 -0
- data/app/components/page_parts/form.html.erb +8 -27
- data/app/components/page_parts_component.rb +1 -3
- data/app/components/render/_tree_page.html.erb +3 -2
- data/app/controllers/admin/layouts_controller.rb +1 -1
- data/app/controllers/admin/origins_controller.rb +3 -0
- data/app/controllers/admin/pages_controller.rb +1 -1
- data/app/controllers/admin/snippets_controller.rb +1 -1
- data/app/controllers/pages_controller.rb +3 -3
- data/app/helpers/puffer_pages_helper.rb +3 -3
- data/app/models/puffer_pages/layout.rb +2 -7
- data/app/models/puffer_pages/origin.rb +2 -0
- data/app/models/puffer_pages/page.rb +1 -117
- data/app/models/puffer_pages/page_part.rb +2 -22
- data/app/models/puffer_pages/snippet.rb +2 -5
- data/config/routes.rb +3 -0
- data/db/migrate/20120812100913_create_origins.rb +16 -0
- data/db/migrate/20120924120226_migrate_to_uuid.rb +126 -0
- data/db/migrate/20130110144030_add_handler_to_page_parts.rb +9 -0
- data/db/migrate/20130118064524_add_locales_to_pages.rb +9 -0
- data/gemfiles/Gemfile.rails-3-1 +7 -0
- data/gemfiles/Gemfile.rails-3-2 +7 -0
- data/gemfiles/Gemfile.rails-head +7 -0
- data/lib/puffer_pages.rb +43 -7
- data/lib/puffer_pages/backends.rb +16 -0
- data/{app/controllers/puffer_pages → lib/puffer_pages/backends/controllers}/layouts_base.rb +2 -5
- data/lib/puffer_pages/backends/controllers/origins_base.rb +43 -0
- data/lib/puffer_pages/backends/controllers/pages_base.rb +52 -0
- data/{app/controllers/puffer_pages → lib/puffer_pages/backends/controllers}/snippets_base.rb +2 -5
- data/lib/puffer_pages/backends/models/layout.rb +34 -0
- data/lib/puffer_pages/backends/models/mixins/importable.rb +42 -0
- data/lib/puffer_pages/backends/models/mixins/localable.rb +65 -0
- data/lib/puffer_pages/backends/models/mixins/renderable.rb +153 -0
- data/lib/puffer_pages/backends/models/mixins/translatable.rb +52 -0
- data/lib/puffer_pages/backends/models/origin.rb +59 -0
- data/lib/puffer_pages/backends/models/page.rb +221 -0
- data/lib/puffer_pages/backends/models/page_part.rb +71 -0
- data/lib/puffer_pages/backends/models/snippet.rb +34 -0
- data/lib/puffer_pages/engine.rb +13 -2
- data/lib/puffer_pages/extensions/context.rb +31 -0
- data/lib/puffer_pages/extensions/core.rb +1 -8
- data/lib/puffer_pages/extensions/pagenator.rb +69 -0
- data/lib/puffer_pages/extensions/renderer.rb +31 -0
- data/lib/puffer_pages/globalize/migrator.rb +23 -0
- data/lib/puffer_pages/handlers.rb +29 -0
- data/lib/puffer_pages/handlers/base.rb +21 -0
- data/lib/puffer_pages/handlers/yaml.rb +20 -0
- data/lib/puffer_pages/helpers.rb +14 -0
- data/lib/puffer_pages/liquid/backend.rb +16 -0
- data/lib/puffer_pages/liquid/file_system.rb +36 -12
- data/lib/puffer_pages/liquid/page_drop.rb +26 -23
- data/lib/puffer_pages/liquid/tags/array.rb +39 -0
- data/lib/puffer_pages/liquid/tags/{javascripts.rb → assets.rb} +13 -4
- data/lib/puffer_pages/liquid/tags/helper.rb +15 -0
- data/lib/puffer_pages/liquid/tags/include.rb +32 -0
- data/lib/puffer_pages/liquid/tags/javascript.rb +15 -0
- data/lib/puffer_pages/liquid/tags/partials.rb +22 -0
- data/lib/puffer_pages/liquid/tags/render.rb +28 -0
- data/lib/puffer_pages/liquid/tags/scope.rb +31 -0
- data/lib/puffer_pages/liquid/tags/super.rb +36 -0
- data/lib/puffer_pages/liquid/tags/translate.rb +56 -0
- data/lib/puffer_pages/liquid/tags/url.rb +53 -0
- data/lib/puffer_pages/liquid/tags/yield.rb +3 -1
- data/lib/puffer_pages/log_subscriber.rb +29 -0
- data/lib/puffer_pages/migrations.rb +31 -0
- data/lib/puffer_pages/renderer.rb +25 -0
- data/lib/puffer_pages/rspec/matchers.rb +27 -0
- data/lib/puffer_pages/rspec/matchers/render_page.rb +90 -0
- data/lib/puffer_pages/version.rb +1 -1
- data/puffer_pages.gemspec +18 -18
- data/spec/controllers/pages_controller_spec.rb +44 -0
- data/spec/controllers/puffer_pages_controller_spec.rb +194 -0
- data/spec/data/broken.json +8 -0
- data/spec/data/import.json +55 -0
- data/spec/data/localized.json +106 -0
- data/spec/data/unlocalized.json +82 -0
- data/spec/dummy/.rvmrc +1 -0
- data/spec/dummy/app/controllers/application_controller.rb +6 -0
- data/spec/dummy/app/views/layouts/sample.en.erb +1 -0
- data/spec/dummy/app/views/layouts/sample.ru.erb +1 -0
- data/spec/dummy/app/views/shared/_first.html.erb +1 -0
- data/spec/dummy/config/application.rb +21 -2
- data/spec/dummy/config/boot.rb +0 -2
- data/spec/dummy/config/database.yml +7 -1
- data/spec/dummy/config/environments/development.rb +11 -2
- data/spec/dummy/config/environments/pg_test.rb +6 -6
- data/spec/dummy/config/environments/production.rb +19 -3
- data/spec/dummy/config/environments/test.rb +6 -6
- data/spec/dummy/config/initializers/inflections.rb +5 -0
- data/spec/dummy/config/initializers/puffer_pages.rb +4 -0
- data/spec/dummy/config/initializers/secret_token.rb +1 -1
- data/spec/dummy/config/initializers/wrap_parameters.rb +5 -3
- data/spec/dummy/config/routes.rb +2 -1
- data/spec/dummy/db/migrate/{20090422092419_create_pages.rb → 20130118071511_create_pages.rb} +1 -0
- data/spec/dummy/db/migrate/{20090504132337_create_page_parts.rb → 20130118071512_create_page_parts.rb} +1 -0
- data/spec/dummy/db/migrate/{20090506102004_create_layouts.rb → 20130118071513_create_layouts.rb} +1 -0
- data/spec/dummy/db/migrate/{20090510121824_create_snippets.rb → 20130118071514_create_snippets.rb} +1 -0
- data/spec/dummy/db/migrate/20130118071515_create_origins.rb +17 -0
- data/spec/dummy/db/migrate/20130118071516_migrate_to_uuid.rb +127 -0
- data/spec/dummy/db/migrate/20130118071517_add_handler_to_page_parts.rb +10 -0
- data/spec/dummy/db/migrate/20130118071518_add_locales_to_pages.rb +10 -0
- data/spec/dummy/db/migrate/20130118071519_add_translations.rb +9 -0
- data/spec/dummy/db/schema.rb +65 -17
- data/spec/fabricators/articles_fabricator.rb +2 -2
- data/spec/fabricators/layouts_fabricator.rb +24 -3
- data/spec/fabricators/origin_fabricator.rb +5 -0
- data/spec/fabricators/page_parts_fabricator.rb +17 -2
- data/spec/fabricators/pages_fabricator.rb +20 -5
- data/spec/fabricators/snippets_fabricator.rb +14 -3
- data/spec/lib/handlers/base_spec.rb +10 -0
- data/spec/lib/handlers/yaml_spec.rb +34 -0
- data/spec/lib/handlers_spec.rb +36 -0
- data/spec/lib/liquid/backend_spec.rb +20 -0
- data/spec/lib/liquid/interpolation_spec.rb +25 -0
- data/spec/lib/liquid/tags/include_spec.rb +38 -0
- data/spec/lib/liquid/tags/partials_spec.rb +39 -0
- data/spec/lib/liquid/tags/scope_spec.rb +18 -0
- data/spec/lib/liquid/tags/translate_spec.rb +107 -0
- data/spec/lib/liquid/tags_spec.rb +81 -0
- data/spec/lib/page_drop_spec.rb +65 -0
- data/spec/lib/pagenator_spec.rb +176 -0
- data/spec/lib/rspec/matchers/render_page_spec.rb +107 -0
- data/spec/models/puffer_pages/layout_spec.rb +15 -0
- data/spec/models/puffer_pages/localable_spec.rb +62 -0
- data/spec/models/puffer_pages/origin_spec.rb +112 -0
- data/spec/models/puffer_pages/page_part_spec.rb +14 -0
- data/spec/models/puffer_pages/page_spec.rb +307 -0
- data/spec/models/puffer_pages/renderable_spec.rb +84 -0
- data/spec/models/puffer_pages/snippet_spec.rb +15 -0
- data/spec/requests/origins_requests_spec.rb +37 -0
- data/spec/spec_helper.rb +7 -6
- metadata +349 -87
- data/Gemfile.lock +0 -176
- data/app/assets/javascripts/puffer/overlay.js +0 -51
- data/app/controllers/puffer_pages/pages_base.rb +0 -38
- data/app/models/layout.rb +0 -2
- data/app/models/page.rb +0 -2
- data/app/models/page_part.rb +0 -2
- data/app/models/snippet.rb +0 -2
- data/app/views/layouts/puffer_pages_layout.html.erb +0 -2
- data/config/puffer_routes.rb +0 -3
- data/gemfiles/Gemfile-rails-3.1 +0 -5
- data/gemfiles/Gemfile-rails-3.1.lock +0 -173
- data/gemfiles/Gemfile-rails-3.2 +0 -5
- data/gemfiles/Gemfile-rails-3.2.lock +0 -171
- data/lib/puffer_pages/extensions/controller.rb +0 -30
- data/lib/puffer_pages/extensions/mapper.rb +0 -23
- data/lib/puffer_pages/liquid/tags/page_attribute.rb +0 -39
- data/lib/puffer_pages/liquid/tags/stylesheets.rb +0 -38
- data/spec/controllers/articles_controller_spec.rb +0 -65
- data/spec/dummy/app/controllers/articles_controller.rb +0 -9
- data/spec/integration/navigation_spec.rb +0 -9
- data/spec/lib/drops_spec.rb +0 -55
- data/spec/lib/tags_spec.rb +0 -98
- data/spec/models/page_spec.rb +0 -235
- data/spec/puffer_pages_spec.rb +0 -7
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe PufferPages::PagePart do
|
5
|
+
it { should be_a(PufferPages::Backends::Mixins::Renderable) }
|
6
|
+
|
7
|
+
describe "validations" do
|
8
|
+
it { should validate_presence_of(:name) }
|
9
|
+
|
10
|
+
describe do
|
11
|
+
it { should validate_uniqueness_of(:name) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,307 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe PufferPages::Page do
|
5
|
+
it { should be_a(PufferPages::Backends::Mixins::Renderable) }
|
6
|
+
|
7
|
+
describe '.normalize_path' do
|
8
|
+
specify{PufferPages::Page.normalize_path(nil).should == nil}
|
9
|
+
specify{PufferPages::Page.normalize_path('').should == nil}
|
10
|
+
specify{PufferPages::Page.normalize_path('/').should == nil}
|
11
|
+
specify{PufferPages::Page.normalize_path('hello').should == 'hello'}
|
12
|
+
specify{PufferPages::Page.normalize_path('hello/world').should == 'hello/world'}
|
13
|
+
specify{PufferPages::Page.normalize_path('/hello///world//').should == 'hello/world'}
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'attributes' do
|
17
|
+
|
18
|
+
before { @root = Fabricate :page, :layout_name => 'foo_layout' }
|
19
|
+
|
20
|
+
it 'has nil slug location if root' do
|
21
|
+
@root.slug.should == nil
|
22
|
+
@root.location.should == nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'generates proper location' do
|
26
|
+
@foo = Fabricate :page, :slug => 'foo', :parent => @root
|
27
|
+
@bar = Fabricate :page, :slug => 'bar', :parent => @foo
|
28
|
+
@baz = Fabricate :page, :slug => 'baz', :parent => @bar
|
29
|
+
@foo.location.should == 'foo'
|
30
|
+
@bar.location.should == 'foo/bar'
|
31
|
+
@baz.location.should == 'foo/bar/baz'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'checks slug uniqueness' do
|
35
|
+
@foo = Fabricate :page, :slug => 'foo', :parent => @root
|
36
|
+
@bar = Fabricate :page, :slug => 'foo', :parent => @foo
|
37
|
+
@baz = Fabricate.build :page, :slug => 'foo', :parent => @root
|
38
|
+
@foo.should be_valid
|
39
|
+
@bar.should be_valid
|
40
|
+
@baz.should_not be_valid
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'updates descendants locations' do
|
44
|
+
@foo = Fabricate :page, :slug => 'foo', :parent => @root
|
45
|
+
@bar = Fabricate :page, :slug => 'bar', :parent => @foo
|
46
|
+
@baz = Fabricate :page, :slug => 'baz', :parent => @bar
|
47
|
+
|
48
|
+
@foo.update_attributes :slug => 'moo'
|
49
|
+
|
50
|
+
@foo.reload.location.should == 'moo'
|
51
|
+
@bar.reload.location.should == 'moo/bar'
|
52
|
+
@baz.reload.location.should == 'moo/bar/baz'
|
53
|
+
|
54
|
+
@bar.update_attributes :slug => 'fuu'
|
55
|
+
|
56
|
+
@foo.reload.location.should == 'moo'
|
57
|
+
@bar.reload.location.should == 'moo/fuu'
|
58
|
+
@baz.reload.location.should == 'moo/fuu/baz'
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'page parts' do
|
64
|
+
|
65
|
+
before :each do
|
66
|
+
@root = Fabricate :page, :layout_name => 'foo_layout'
|
67
|
+
@body = @root.page_parts.create :name => "body"
|
68
|
+
@foo = Fabricate :page, :slug => 'foo', :parent => @root
|
69
|
+
|
70
|
+
@bar = Fabricate :page, :slug => 'bar', :parent => @foo,
|
71
|
+
:page_parts => [Fabricate(:page_part, :name => PufferPages.primary_page_part_name, :body => '4')]
|
72
|
+
|
73
|
+
@baz = Fabricate :page, :slug => 'baz',
|
74
|
+
:parent => @bar, :page_parts => [
|
75
|
+
Fabricate(:page_part, :name => 'sidebar', :body => '5'),
|
76
|
+
Fabricate(:page_part, :name => 'additional', :body => '3')
|
77
|
+
]
|
78
|
+
@foo.page_parts = [Fabricate(:page_part, :name => 'sidebar', :body => '2')]
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'layout' do
|
84
|
+
|
85
|
+
before :each do
|
86
|
+
@layout = Fabricate :layout, :name => 'bar_layout'
|
87
|
+
@root = Fabricate :page, :layout_name => 'foo_layout'
|
88
|
+
@foo = Fabricate :page, :slug => 'foo', :parent => @root
|
89
|
+
@bar = Fabricate :page, :slug => 'bar', :parent => @foo, :layout_name => 'bar_layout'
|
90
|
+
@baz = Fabricate :page, :slug => 'baz', :parent => @bar
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should receive proper layout name' do
|
94
|
+
@root.inherited_layout_name.should == 'foo_layout'
|
95
|
+
@foo.inherited_layout_name.should == 'foo_layout'
|
96
|
+
@bar.inherited_layout_name.should == 'bar_layout'
|
97
|
+
@baz.inherited_layout_name.should == 'bar_layout'
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should return proper layout for render' do
|
101
|
+
@root.layout_for_render.should == 'layouts/foo_layout'
|
102
|
+
@foo.layout_for_render.should == 'layouts/foo_layout'
|
103
|
+
@bar.layout_for_render.should == nil
|
104
|
+
@baz.layout_for_render.should == nil
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
describe 'rendering' do
|
110
|
+
context 'when localization is off' do
|
111
|
+
before { PufferPages.stub(:localize).and_return(false) }
|
112
|
+
|
113
|
+
let!(:main_part) { Fabricate :main }
|
114
|
+
let!(:sidebar_part) { Fabricate :sidebar }
|
115
|
+
let!(:page) { Fabricate :root, page_parts: [main_part, sidebar_part] }
|
116
|
+
|
117
|
+
context "default locale is English" do
|
118
|
+
before { I18n.stub(:default_locale).and_return(:en) }
|
119
|
+
|
120
|
+
it 'should render content_for blocks if rails layout used' do
|
121
|
+
result = page.render 'self' => PufferPages::Liquid::PageDrop.new(page)
|
122
|
+
result.should == "PagePart: `body`, Page: ``<% content_for :'sidebar' do %>PagePart: `sidebar`, Page: ``<% end %>"
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should render layout' do
|
126
|
+
@layout = Fabricate :application, body: "{% include 'body' %} {% include 'sidebar' %}"
|
127
|
+
result = page.render 'self' => PufferPages::Liquid::PageDrop.new(page)
|
128
|
+
result.should == "PagePart: `body`, Page: `` PagePart: `sidebar`, Page: ``"
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should receive proper content type' do
|
132
|
+
page.content_type.should == 'text/html'
|
133
|
+
child_page = Fabricate :page, :slug => 'style.css', :parent => page
|
134
|
+
child_page.content_type.should == 'text/css'
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
if PufferPages.localize
|
140
|
+
context 'when localization is on' do
|
141
|
+
before { I18n.stub(:default_locale).and_return(:en) }
|
142
|
+
before { PufferPages.stub(:localize).and_return(true) }
|
143
|
+
|
144
|
+
let!(:main_part) { Fabricate :main, body_translations: { en: 'En-body', ru: 'Ru-body' } }
|
145
|
+
let!(:sidebar_part) { Fabricate :sidebar, body_translations: { en: 'En-sidebar' } }
|
146
|
+
let!(:page) { Fabricate :root, page_parts: [main_part, sidebar_part] }
|
147
|
+
|
148
|
+
context 'and current language is English' do
|
149
|
+
before { I18n.stub(:locale).and_return(:en) }
|
150
|
+
|
151
|
+
it 'should render content_for blocks if rails layout used' do
|
152
|
+
result = page.render self: page
|
153
|
+
result.should == "En-body<% content_for :'sidebar' do %>En-sidebar<% end %>"
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'should render layout' do
|
157
|
+
@layout = Fabricate :application, body: "{% include 'body' %} {% include 'sidebar' %}"
|
158
|
+
result = page.render self: page
|
159
|
+
result.should == "En-body En-sidebar"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'and current language is Russian' do
|
164
|
+
before { I18n.stub(:locale).and_return(:ru) }
|
165
|
+
|
166
|
+
it 'should render content_for blocks if rails layout used and fallback to the default locale for missing parts' do
|
167
|
+
result = page.render self: page
|
168
|
+
result.should == "Ru-body<% content_for :'sidebar' do %>En-sidebar<% end %>"
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'should render layout and fallback to the default locale for missing parts' do
|
172
|
+
@layout = Fabricate :application, body: "{% include 'body' %} {% include 'sidebar' %}"
|
173
|
+
result = page.render self: page
|
174
|
+
result.should == "Ru-body En-sidebar"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
describe 'find_page' do
|
182
|
+
|
183
|
+
def single_section_page_path
|
184
|
+
PufferPages.single_section_page_path = true
|
185
|
+
yield
|
186
|
+
PufferPages.single_section_page_path = false
|
187
|
+
end
|
188
|
+
|
189
|
+
before :each do
|
190
|
+
@root = Fabricate :page, :layout_name => 'foo_layout'
|
191
|
+
@foo = Fabricate :page, :slug => 'foo', :parent => @root
|
192
|
+
@bar = Fabricate :page, :slug => 'bar', :parent => @foo
|
193
|
+
@baz = Fabricate :page, :slug => 'baz', :parent => @bar, :status => 'draft'
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'root page' do
|
197
|
+
PufferPages::Page.find_page(nil).should == @root
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'not root page' do
|
201
|
+
PufferPages::Page.find_page('foo/bar').should == @bar
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'not existent page' do
|
205
|
+
expect {PufferPages::Page.find_page('foo/baz') }.to raise_error(ActiveRecord::RecordNotFound)
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'draft page' do
|
209
|
+
expect {PufferPages::Page.find_page('foo/bar/baz') }.to raise_error(PufferPages::DraftPage)
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'single section root page' do
|
213
|
+
single_section_page_path do
|
214
|
+
PufferPages::Page.find_page(nil).should == @root
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'single section not root page' do
|
219
|
+
single_section_page_path do
|
220
|
+
PufferPages::Page.find_page('foo').should == @foo
|
221
|
+
PufferPages::Page.find_page('bar').should == @bar
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
end
|
226
|
+
|
227
|
+
describe 'find_view_page' do
|
228
|
+
|
229
|
+
before :each do
|
230
|
+
@root = Fabricate :page, :layout_name => 'foo_layout'
|
231
|
+
@foo = Fabricate :page, :slug => 'foo', :parent => @root
|
232
|
+
@bar = Fabricate :page, :slug => '%', :parent => @foo
|
233
|
+
@quux = Fabricate :page, :slug => 'quux', :parent => @bar
|
234
|
+
@qux = Fabricate :page, :slug => '%', :parent => @bar # Created before @baz and after @quux
|
235
|
+
@baz = Fabricate :page, :slug => 'baz', :parent => @bar
|
236
|
+
@bazjs = Fabricate :page, :slug => 'baz.js', :parent => @bar
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'root page' do
|
240
|
+
PufferPages::Page.find_view_page('/').should == @root
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'not root page' do
|
244
|
+
PufferPages::Page.find_view_page('/foo').should == @foo
|
245
|
+
PufferPages::Page.find_view_page('/foo/bar').should == @bar
|
246
|
+
PufferPages::Page.find_view_page('/foo/baz').should == @bar
|
247
|
+
PufferPages::Page.find_view_page('/foo/bar/baz').should == @baz
|
248
|
+
PufferPages::Page.find_view_page('/foo/moo/baz').should == @baz
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'not existent page' do
|
252
|
+
expect {PufferPages::Page.find_view_page('/bar')}.to raise_error(PufferPages::LayoutMissed)
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'draft page' do
|
256
|
+
@bar.update_attributes(:status => 'draft')
|
257
|
+
expect {PufferPages::Page.find_view_page('/foo/bar')}.to raise_error(PufferPages::LayoutMissed)
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should choose the last created (with the most right tree location) page from those fitting the requested path and format" do
|
261
|
+
PufferPages::Page.find_view_page('/foo/moo/baz', :formats => [:html]).should == @baz
|
262
|
+
end
|
263
|
+
it "should use %-ending locations for html requests with the same priority as locations without % end
|
264
|
+
(so in this case the priority is regulated only by tree location)" do
|
265
|
+
PufferPages::Page.find_view_page('/foo/moo/quux', :formats => [:html]).should == @qux
|
266
|
+
end
|
267
|
+
specify {PufferPages::Page.find_view_page('/foo/moo/baz', :formats => [:html, :js]).should == @baz}
|
268
|
+
specify {PufferPages::Page.find_view_page('/foo/moo/baz', :formats => [:js]).should == @bazjs}
|
269
|
+
specify {PufferPages::Page.find_view_page('/foo/moo/baz', :formats => [:js, :html]).should == @bazjs}
|
270
|
+
specify {PufferPages::Page.find_view_page('/foo/moo/baz', :formats => [:xml, :html]).should == @baz}
|
271
|
+
specify {PufferPages::Page.find_view_page('/foo/moo/baz', :formats => [:xml, :js]).should == @bazjs}
|
272
|
+
it "should not use %-ending locations for formats other than html, thus generating an error if format is different" do
|
273
|
+
expect {PufferPages::Page.find_view_page('/foo/moo/baz', :formats => [:xml])}.to raise_error(PufferPages::LayoutMissed)
|
274
|
+
end
|
275
|
+
|
276
|
+
end
|
277
|
+
|
278
|
+
context 'renderable attributes' do
|
279
|
+
let!(:page) { Fabricate(:root, :name => "{{ page.body }}", :page_parts => [Fabricate(:main)] ) }
|
280
|
+
|
281
|
+
specify { page.render.should == "PagePart: `body`, Page: ``"}
|
282
|
+
end
|
283
|
+
|
284
|
+
context 'i18n translations' do
|
285
|
+
let(:translations) { { en: YAML.dump(hello: 'Hello', additional: 'Test'), de: YAML.dump(hello: 'Hallo') } }
|
286
|
+
let(:translations_update) { { en: YAML.dump(hello: 'Bye'), de: YAML.dump(hello: 'Chao') } }
|
287
|
+
|
288
|
+
let!(:root) { Fabricate :root, locales: translations }
|
289
|
+
let!(:first) { Fabricate :root, slug: 'first', parent: root, locales: translations_update }
|
290
|
+
|
291
|
+
describe '#page_translations' do
|
292
|
+
specify do
|
293
|
+
root.page_translations.should == {
|
294
|
+
en: { hello: 'Hello', additional: 'Test' },
|
295
|
+
de: { hello: 'Hallo' }
|
296
|
+
}
|
297
|
+
end
|
298
|
+
specify do
|
299
|
+
first.page_translations.should == {
|
300
|
+
en: { hello: 'Bye', additional: 'Test' },
|
301
|
+
de: { hello: 'Chao' }
|
302
|
+
}
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe PufferPages::Backends::Mixins::Renderable do
|
5
|
+
let(:klass) do
|
6
|
+
Class.new do
|
7
|
+
include PufferPages::Backends::Mixins::Renderable
|
8
|
+
end
|
9
|
+
end
|
10
|
+
subject { klass.new }
|
11
|
+
|
12
|
+
def merge *args
|
13
|
+
subject.send(:merge_context, *args)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#normalize_render_options" do
|
17
|
+
let(:string) { 'Hello ^^' }
|
18
|
+
let(:object) { Object.new }
|
19
|
+
let(:hash) { { a: 1 } }
|
20
|
+
let(:another_hash) { { b: 2 } }
|
21
|
+
let(:context) { ::Liquid::Context.new }
|
22
|
+
|
23
|
+
def normalize *args
|
24
|
+
subject.send(:normalize_render_options, *args)
|
25
|
+
end
|
26
|
+
|
27
|
+
specify { normalize(string, context, hash).should == [string, merge(context, hash)] }
|
28
|
+
specify { normalize(object, context, hash).should == [object, merge(context, hash)] }
|
29
|
+
specify { normalize(context, hash).should == [nil, merge(context, hash)] }
|
30
|
+
specify { normalize(string, hash, another_hash).should == [string, merge(hash, another_hash)] }
|
31
|
+
specify { normalize(hash, another_hash).should == [nil, merge(hash, another_hash)] }
|
32
|
+
specify { normalize(string, context).should == [string, merge(context, {})] }
|
33
|
+
specify { normalize(string, hash).should == [string, merge(hash, {})] }
|
34
|
+
specify { normalize(context).should == [nil, context] }
|
35
|
+
specify { normalize(hash).should == [nil, merge(hash, {})] }
|
36
|
+
specify { expect { normalize(string, context, hash, 42).should }.to raise_error ArgumentError }
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#merge_context" do
|
40
|
+
let(:hash) { { a: 1 } }
|
41
|
+
let(:another_hash) { { registers: { b: 2 }, environment: { c: 3 } } }
|
42
|
+
let(:context) { ::Liquid::Context.new }
|
43
|
+
|
44
|
+
specify { merge(hash, {}).should == { drops: { 'a' => 1 }, environment: {}, registers: {} } }
|
45
|
+
specify { merge(another_hash, {}).should == { drops: {}, environment: { c: 3 }, registers: { b: 2 } } }
|
46
|
+
specify { merge(hash, another_hash).should == { drops: { 'a' => 1 }, environment: { c: 3 }, registers: { b: 2 } } }
|
47
|
+
specify { merge(context, {}).should == context }
|
48
|
+
specify { merge(context, hash)['a'].should == 1 }
|
49
|
+
specify { merge(context, hash).registers.should == {} }
|
50
|
+
specify { merge(context, another_hash).registers.should == { b: 2 } }
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#normalize_context_options" do
|
54
|
+
let(:hash1) { { a: 1 } }
|
55
|
+
let(:hash2) { { b: 2 } }
|
56
|
+
let(:hash3) { { c: 3 } }
|
57
|
+
|
58
|
+
def normalize *args
|
59
|
+
subject.send(:normalize_context_options, *args)
|
60
|
+
end
|
61
|
+
|
62
|
+
specify { normalize(foo: hash1).should == { drops: { 'foo' => hash1 }, environment: {}, registers: {} } }
|
63
|
+
specify { normalize(drops: { 'a' => 1 }, environment: hash2, registers: hash3).should ==
|
64
|
+
{ drops: { 'a' => 1 }, environment: hash2, registers: hash3 } }
|
65
|
+
specify { normalize(environment: hash1, foo: hash2).should ==
|
66
|
+
{ drops: { 'environment' => hash1, 'foo' => hash2 }, environment: {}, registers: {} } }
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#render_template" do
|
70
|
+
def render *args
|
71
|
+
subject.send(:render_template, *args)
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'with hash context' do
|
75
|
+
specify { render("{{ hello }}", hello: 'Hello').should == 'Hello' }
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'with object context' do
|
79
|
+
let(:liquid_context) { ::Liquid::Context.new('hello' => 'Hello') }
|
80
|
+
|
81
|
+
specify { render("{{ hello }}", liquid_context).should == 'Hello' }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe PufferPages::Snippet do
|
5
|
+
describe "validations" do
|
6
|
+
it { should validate_presence_of(:name) }
|
7
|
+
it { should validate_uniqueness_of(:name) }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#find_snippet" do
|
11
|
+
let!(:snippet) { Fabricate :snippet, :name => 'main' }
|
12
|
+
|
13
|
+
specify { PufferPages::Snippet.find_snippet('main').should == snippet}
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Origins controller" do
|
4
|
+
let(:token) { "token" }
|
5
|
+
|
6
|
+
describe "#import" do
|
7
|
+
let(:json) { File.new('spec/data/import.json').read }
|
8
|
+
let(:origin) { Fabricate :origin }
|
9
|
+
|
10
|
+
before { FakeWeb.register_uri :get, origin.uri, :body => json, :content_length => json.length }
|
11
|
+
before { get "/admin/origins/#{origin.id}/import" }
|
12
|
+
|
13
|
+
specify { PufferPages::Layout.count.should == 2 }
|
14
|
+
specify { PufferPages::Page.count.should == 1 }
|
15
|
+
specify { PufferPages::Snippet.count.should == 1 }
|
16
|
+
specify { PufferPages::PagePart.count.should == 2 }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#export" do
|
20
|
+
context "with a valid token" do
|
21
|
+
before { get "/admin/origins/export", :token => "token" }
|
22
|
+
|
23
|
+
subject { ActiveSupport::JSON.decode response.body }
|
24
|
+
|
25
|
+
%w(layouts pages snippets).each do |key|
|
26
|
+
it { should have_key(key) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "with an invalid token" do
|
31
|
+
before { get "/admin/origins/export", :token => "bad" }
|
32
|
+
|
33
|
+
specify { response.body.should be_blank }
|
34
|
+
specify { response.status.should == 401 }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|