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.
Files changed (197) hide show
  1. data/.gitignore +5 -0
  2. data/.rspec +3 -1
  3. data/.rvmrc +1 -1
  4. data/.travis.yml +13 -5
  5. data/CHANGELOG.md +130 -7
  6. data/Gemfile +10 -1
  7. data/README.md +18 -20
  8. data/Rakefile +1 -1
  9. data/app/assets/javascripts/puffer/codemirror.js +4237 -2223
  10. data/app/assets/javascripts/puffer/codemirror/css.js +359 -18
  11. data/app/assets/javascripts/puffer/codemirror/htmlmixed.js +15 -14
  12. data/app/assets/javascripts/puffer/codemirror/javascript.js +91 -29
  13. data/app/assets/javascripts/puffer/codemirror/liquid.js +185 -0
  14. data/app/assets/javascripts/puffer/codemirror/xml.js +99 -27
  15. data/app/assets/javascripts/puffer/codemirror/yaml.js +95 -0
  16. data/app/assets/javascripts/puffer/liquid.js +28 -12
  17. data/app/assets/javascripts/puffer/matchbrackets.js +63 -0
  18. data/app/assets/javascripts/puffer/multiplex.js +95 -0
  19. data/app/assets/javascripts/puffer/puffer_pages.js +140 -44
  20. data/app/assets/stylesheets/puffer/codemirror.css +203 -67
  21. data/app/assets/stylesheets/puffer/codemirror/ambiance-mobile.css +6 -0
  22. data/app/assets/stylesheets/puffer/codemirror/ambiance.css +76 -0
  23. data/app/assets/stylesheets/puffer/codemirror/blackboard.css +25 -0
  24. data/app/assets/stylesheets/puffer/codemirror/cobalt.css +4 -4
  25. data/app/assets/stylesheets/puffer/codemirror/eclipse.css +1 -1
  26. data/app/assets/stylesheets/puffer/codemirror/elegant.css +2 -2
  27. data/app/assets/stylesheets/puffer/codemirror/erlang-dark.css +21 -0
  28. data/app/assets/stylesheets/puffer/codemirror/lesser-dark.css +44 -0
  29. data/app/assets/stylesheets/puffer/codemirror/monokai.css +4 -4
  30. data/app/assets/stylesheets/puffer/codemirror/neat.css +3 -3
  31. data/app/assets/stylesheets/puffer/codemirror/night.css +4 -4
  32. data/app/assets/stylesheets/puffer/codemirror/rubyblue.css +5 -5
  33. data/app/assets/stylesheets/puffer/codemirror/solarized.css +207 -0
  34. data/app/assets/stylesheets/puffer/codemirror/twilight.css +26 -0
  35. data/app/assets/stylesheets/puffer/codemirror/vibrant-ink.css +27 -0
  36. data/app/assets/stylesheets/puffer/codemirror/xq-dark.css +46 -0
  37. data/app/assets/stylesheets/puffer/puffer_pages.css +64 -35
  38. data/app/components/codemirror/form.html.erb +22 -6
  39. data/app/components/codemirror_component.rb +1 -8
  40. data/app/components/handlers/form.html.erb +8 -0
  41. data/app/components/handlers_component.rb +8 -0
  42. data/app/components/page_parts/_page_part.html.erb +6 -0
  43. data/app/components/page_parts/form.html.erb +8 -27
  44. data/app/components/page_parts_component.rb +1 -3
  45. data/app/components/render/_tree_page.html.erb +3 -2
  46. data/app/controllers/admin/layouts_controller.rb +1 -1
  47. data/app/controllers/admin/origins_controller.rb +3 -0
  48. data/app/controllers/admin/pages_controller.rb +1 -1
  49. data/app/controllers/admin/snippets_controller.rb +1 -1
  50. data/app/controllers/pages_controller.rb +3 -3
  51. data/app/helpers/puffer_pages_helper.rb +3 -3
  52. data/app/models/puffer_pages/layout.rb +2 -7
  53. data/app/models/puffer_pages/origin.rb +2 -0
  54. data/app/models/puffer_pages/page.rb +1 -117
  55. data/app/models/puffer_pages/page_part.rb +2 -22
  56. data/app/models/puffer_pages/snippet.rb +2 -5
  57. data/config/routes.rb +3 -0
  58. data/db/migrate/20120812100913_create_origins.rb +16 -0
  59. data/db/migrate/20120924120226_migrate_to_uuid.rb +126 -0
  60. data/db/migrate/20130110144030_add_handler_to_page_parts.rb +9 -0
  61. data/db/migrate/20130118064524_add_locales_to_pages.rb +9 -0
  62. data/gemfiles/Gemfile.rails-3-1 +7 -0
  63. data/gemfiles/Gemfile.rails-3-2 +7 -0
  64. data/gemfiles/Gemfile.rails-head +7 -0
  65. data/lib/puffer_pages.rb +43 -7
  66. data/lib/puffer_pages/backends.rb +16 -0
  67. data/{app/controllers/puffer_pages → lib/puffer_pages/backends/controllers}/layouts_base.rb +2 -5
  68. data/lib/puffer_pages/backends/controllers/origins_base.rb +43 -0
  69. data/lib/puffer_pages/backends/controllers/pages_base.rb +52 -0
  70. data/{app/controllers/puffer_pages → lib/puffer_pages/backends/controllers}/snippets_base.rb +2 -5
  71. data/lib/puffer_pages/backends/models/layout.rb +34 -0
  72. data/lib/puffer_pages/backends/models/mixins/importable.rb +42 -0
  73. data/lib/puffer_pages/backends/models/mixins/localable.rb +65 -0
  74. data/lib/puffer_pages/backends/models/mixins/renderable.rb +153 -0
  75. data/lib/puffer_pages/backends/models/mixins/translatable.rb +52 -0
  76. data/lib/puffer_pages/backends/models/origin.rb +59 -0
  77. data/lib/puffer_pages/backends/models/page.rb +221 -0
  78. data/lib/puffer_pages/backends/models/page_part.rb +71 -0
  79. data/lib/puffer_pages/backends/models/snippet.rb +34 -0
  80. data/lib/puffer_pages/engine.rb +13 -2
  81. data/lib/puffer_pages/extensions/context.rb +31 -0
  82. data/lib/puffer_pages/extensions/core.rb +1 -8
  83. data/lib/puffer_pages/extensions/pagenator.rb +69 -0
  84. data/lib/puffer_pages/extensions/renderer.rb +31 -0
  85. data/lib/puffer_pages/globalize/migrator.rb +23 -0
  86. data/lib/puffer_pages/handlers.rb +29 -0
  87. data/lib/puffer_pages/handlers/base.rb +21 -0
  88. data/lib/puffer_pages/handlers/yaml.rb +20 -0
  89. data/lib/puffer_pages/helpers.rb +14 -0
  90. data/lib/puffer_pages/liquid/backend.rb +16 -0
  91. data/lib/puffer_pages/liquid/file_system.rb +36 -12
  92. data/lib/puffer_pages/liquid/page_drop.rb +26 -23
  93. data/lib/puffer_pages/liquid/tags/array.rb +39 -0
  94. data/lib/puffer_pages/liquid/tags/{javascripts.rb → assets.rb} +13 -4
  95. data/lib/puffer_pages/liquid/tags/helper.rb +15 -0
  96. data/lib/puffer_pages/liquid/tags/include.rb +32 -0
  97. data/lib/puffer_pages/liquid/tags/javascript.rb +15 -0
  98. data/lib/puffer_pages/liquid/tags/partials.rb +22 -0
  99. data/lib/puffer_pages/liquid/tags/render.rb +28 -0
  100. data/lib/puffer_pages/liquid/tags/scope.rb +31 -0
  101. data/lib/puffer_pages/liquid/tags/super.rb +36 -0
  102. data/lib/puffer_pages/liquid/tags/translate.rb +56 -0
  103. data/lib/puffer_pages/liquid/tags/url.rb +53 -0
  104. data/lib/puffer_pages/liquid/tags/yield.rb +3 -1
  105. data/lib/puffer_pages/log_subscriber.rb +29 -0
  106. data/lib/puffer_pages/migrations.rb +31 -0
  107. data/lib/puffer_pages/renderer.rb +25 -0
  108. data/lib/puffer_pages/rspec/matchers.rb +27 -0
  109. data/lib/puffer_pages/rspec/matchers/render_page.rb +90 -0
  110. data/lib/puffer_pages/version.rb +1 -1
  111. data/puffer_pages.gemspec +18 -18
  112. data/spec/controllers/pages_controller_spec.rb +44 -0
  113. data/spec/controllers/puffer_pages_controller_spec.rb +194 -0
  114. data/spec/data/broken.json +8 -0
  115. data/spec/data/import.json +55 -0
  116. data/spec/data/localized.json +106 -0
  117. data/spec/data/unlocalized.json +82 -0
  118. data/spec/dummy/.rvmrc +1 -0
  119. data/spec/dummy/app/controllers/application_controller.rb +6 -0
  120. data/spec/dummy/app/views/layouts/sample.en.erb +1 -0
  121. data/spec/dummy/app/views/layouts/sample.ru.erb +1 -0
  122. data/spec/dummy/app/views/shared/_first.html.erb +1 -0
  123. data/spec/dummy/config/application.rb +21 -2
  124. data/spec/dummy/config/boot.rb +0 -2
  125. data/spec/dummy/config/database.yml +7 -1
  126. data/spec/dummy/config/environments/development.rb +11 -2
  127. data/spec/dummy/config/environments/pg_test.rb +6 -6
  128. data/spec/dummy/config/environments/production.rb +19 -3
  129. data/spec/dummy/config/environments/test.rb +6 -6
  130. data/spec/dummy/config/initializers/inflections.rb +5 -0
  131. data/spec/dummy/config/initializers/puffer_pages.rb +4 -0
  132. data/spec/dummy/config/initializers/secret_token.rb +1 -1
  133. data/spec/dummy/config/initializers/wrap_parameters.rb +5 -3
  134. data/spec/dummy/config/routes.rb +2 -1
  135. data/spec/dummy/db/migrate/{20090422092419_create_pages.rb → 20130118071511_create_pages.rb} +1 -0
  136. data/spec/dummy/db/migrate/{20090504132337_create_page_parts.rb → 20130118071512_create_page_parts.rb} +1 -0
  137. data/spec/dummy/db/migrate/{20090506102004_create_layouts.rb → 20130118071513_create_layouts.rb} +1 -0
  138. data/spec/dummy/db/migrate/{20090510121824_create_snippets.rb → 20130118071514_create_snippets.rb} +1 -0
  139. data/spec/dummy/db/migrate/20130118071515_create_origins.rb +17 -0
  140. data/spec/dummy/db/migrate/20130118071516_migrate_to_uuid.rb +127 -0
  141. data/spec/dummy/db/migrate/20130118071517_add_handler_to_page_parts.rb +10 -0
  142. data/spec/dummy/db/migrate/20130118071518_add_locales_to_pages.rb +10 -0
  143. data/spec/dummy/db/migrate/20130118071519_add_translations.rb +9 -0
  144. data/spec/dummy/db/schema.rb +65 -17
  145. data/spec/fabricators/articles_fabricator.rb +2 -2
  146. data/spec/fabricators/layouts_fabricator.rb +24 -3
  147. data/spec/fabricators/origin_fabricator.rb +5 -0
  148. data/spec/fabricators/page_parts_fabricator.rb +17 -2
  149. data/spec/fabricators/pages_fabricator.rb +20 -5
  150. data/spec/fabricators/snippets_fabricator.rb +14 -3
  151. data/spec/lib/handlers/base_spec.rb +10 -0
  152. data/spec/lib/handlers/yaml_spec.rb +34 -0
  153. data/spec/lib/handlers_spec.rb +36 -0
  154. data/spec/lib/liquid/backend_spec.rb +20 -0
  155. data/spec/lib/liquid/interpolation_spec.rb +25 -0
  156. data/spec/lib/liquid/tags/include_spec.rb +38 -0
  157. data/spec/lib/liquid/tags/partials_spec.rb +39 -0
  158. data/spec/lib/liquid/tags/scope_spec.rb +18 -0
  159. data/spec/lib/liquid/tags/translate_spec.rb +107 -0
  160. data/spec/lib/liquid/tags_spec.rb +81 -0
  161. data/spec/lib/page_drop_spec.rb +65 -0
  162. data/spec/lib/pagenator_spec.rb +176 -0
  163. data/spec/lib/rspec/matchers/render_page_spec.rb +107 -0
  164. data/spec/models/puffer_pages/layout_spec.rb +15 -0
  165. data/spec/models/puffer_pages/localable_spec.rb +62 -0
  166. data/spec/models/puffer_pages/origin_spec.rb +112 -0
  167. data/spec/models/puffer_pages/page_part_spec.rb +14 -0
  168. data/spec/models/puffer_pages/page_spec.rb +307 -0
  169. data/spec/models/puffer_pages/renderable_spec.rb +84 -0
  170. data/spec/models/puffer_pages/snippet_spec.rb +15 -0
  171. data/spec/requests/origins_requests_spec.rb +37 -0
  172. data/spec/spec_helper.rb +7 -6
  173. metadata +349 -87
  174. data/Gemfile.lock +0 -176
  175. data/app/assets/javascripts/puffer/overlay.js +0 -51
  176. data/app/controllers/puffer_pages/pages_base.rb +0 -38
  177. data/app/models/layout.rb +0 -2
  178. data/app/models/page.rb +0 -2
  179. data/app/models/page_part.rb +0 -2
  180. data/app/models/snippet.rb +0 -2
  181. data/app/views/layouts/puffer_pages_layout.html.erb +0 -2
  182. data/config/puffer_routes.rb +0 -3
  183. data/gemfiles/Gemfile-rails-3.1 +0 -5
  184. data/gemfiles/Gemfile-rails-3.1.lock +0 -173
  185. data/gemfiles/Gemfile-rails-3.2 +0 -5
  186. data/gemfiles/Gemfile-rails-3.2.lock +0 -171
  187. data/lib/puffer_pages/extensions/controller.rb +0 -30
  188. data/lib/puffer_pages/extensions/mapper.rb +0 -23
  189. data/lib/puffer_pages/liquid/tags/page_attribute.rb +0 -39
  190. data/lib/puffer_pages/liquid/tags/stylesheets.rb +0 -38
  191. data/spec/controllers/articles_controller_spec.rb +0 -65
  192. data/spec/dummy/app/controllers/articles_controller.rb +0 -9
  193. data/spec/integration/navigation_spec.rb +0 -9
  194. data/spec/lib/drops_spec.rb +0 -55
  195. data/spec/lib/tags_spec.rb +0 -98
  196. data/spec/models/page_spec.rb +0 -235
  197. data/spec/puffer_pages_spec.rb +0 -7
@@ -0,0 +1,176 @@
1
+ require 'spec_helper'
2
+
3
+ describe PufferPages::Extensions::Pagenator do
4
+ context 'controller' do
5
+ include RSpec::Rails::ControllerExampleGroup
6
+ let!(:foo_layout){Fabricate :foo_layout}
7
+ let!(:root){Fabricate :foo_root}
8
+ let!(:anonymous){Fabricate :page, :slug => 'anonymous', :name => 'foo', :parent => root}
9
+ let!(:foo){Fabricate :page, :slug => 'foo', :parent => root}
10
+ let!(:bar){Fabricate :page, :slug => 'bar', :parent => foo}
11
+
12
+ let!(:bar_layout){Fabricate :bar_layout}
13
+ let!(:root2){Fabricate :foo_root, :layout_name => 'bar_layout'}
14
+
15
+ let!(:named){Fabricate :page, :slug => 'named', :name => 'foo', :parent => root}
16
+ let!(:named2){Fabricate :page, :slug => 'named', :name => 'bar', :parent => root2}
17
+
18
+ context do
19
+ controller do
20
+ puffer_pages
21
+ def index; end
22
+ end
23
+
24
+ specify do
25
+ get :index
26
+ response.body.should == 'foo_layout anonymous'
27
+ end
28
+ end
29
+
30
+ context do
31
+ controller do
32
+ puffer_pages :only => :index
33
+ def index; end
34
+ end
35
+
36
+ specify do
37
+ get :index
38
+ response.body.should == 'foo_layout anonymous'
39
+ end
40
+ end
41
+
42
+ context do
43
+ controller do
44
+ puffer_pages :except => :show
45
+ def index; end
46
+ end
47
+
48
+ specify do
49
+ get :index
50
+ response.body.should == 'foo_layout anonymous'
51
+ end
52
+ end
53
+
54
+ context do
55
+ controller do
56
+ puffer_pages :only => [:show]
57
+ def index; end
58
+ end
59
+
60
+ specify{expect{get :index}.to raise_error}
61
+ end
62
+
63
+ context do
64
+ controller do
65
+ puffer_pages :except => [:index]
66
+ def index; end
67
+ end
68
+
69
+ specify{expect{get :index}.to raise_error}
70
+ end
71
+
72
+ context do
73
+ controller do
74
+ puffer_pages
75
+ def index
76
+ render 'foo'
77
+ end
78
+ end
79
+
80
+ specify do
81
+ get :index
82
+ response.body.should == 'foo_layout foo'
83
+ end
84
+ end
85
+
86
+ context do
87
+ controller do
88
+ puffer_pages
89
+ def index
90
+ render PufferPages::Page.where(:slug => 'foo').first
91
+ end
92
+ end
93
+
94
+ specify do
95
+ get :index
96
+ response.body.should == 'foo_layout foo'
97
+ end
98
+ end
99
+
100
+ context do
101
+ controller do
102
+ puffer_pages
103
+ def index
104
+ render 'foo/bar'
105
+ end
106
+ end
107
+
108
+ specify do
109
+ get :index
110
+ response.body.should == 'foo_layout bar'
111
+ end
112
+ end
113
+
114
+ context do
115
+ controller do
116
+ puffer_pages
117
+ def index
118
+ render 'foo/bar'
119
+ end
120
+ end
121
+
122
+ specify do
123
+ get :index
124
+ response.body.should == 'foo_layout bar'
125
+ end
126
+ end
127
+
128
+ context do
129
+ controller do
130
+ puffer_pages :scope => {:name => 'foo'}
131
+ def index
132
+ render 'named'
133
+ end
134
+ end
135
+
136
+ specify do
137
+ get :index
138
+ response.body.should == 'foo_layout named'
139
+ end
140
+ end
141
+
142
+ context do
143
+ controller do
144
+ puffer_pages :scope => lambda {|conroller|
145
+ {:name => 'bar'}
146
+ }
147
+ def index
148
+ render 'named'
149
+ end
150
+ end
151
+
152
+ specify do
153
+ get :index
154
+ response.body.should == 'bar_layout named'
155
+ end
156
+ end
157
+
158
+ context do
159
+ controller do
160
+ puffer_pages :scope => :puffer_scope
161
+ def index
162
+ render 'named'
163
+ end
164
+
165
+ def puffer_scope
166
+ {:name => 'bar'}
167
+ end
168
+ end
169
+
170
+ specify do
171
+ get :index
172
+ response.body.should == 'bar_layout named'
173
+ end
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Specs' do
4
+ describe '#render_page' do
5
+ include RSpec::Rails::ControllerExampleGroup
6
+
7
+ let!(:layout) { Fabricate :application }
8
+ let!(:root) { Fabricate :root }
9
+ let!(:first) { Fabricate :page, slug: 'first', parent: root }
10
+ let!(:second) { Fabricate :page, slug: 'second', parent: first }
11
+
12
+ context 'no page specified' do
13
+ context do
14
+ controller do
15
+ def index
16
+ @page = PufferPages::Page.root
17
+ render puffer_page: @page
18
+ end
19
+ end
20
+
21
+ it { should render_page }
22
+ specify do
23
+ get :index
24
+ response.should render_page
25
+ end
26
+ end
27
+
28
+ context do
29
+ controller do
30
+ def index
31
+ render nothing: true
32
+ end
33
+ end
34
+
35
+ it { should_not render_page }
36
+ specify do
37
+ get :index
38
+ response.should_not render_page
39
+ end
40
+ end
41
+ end
42
+
43
+ context 'with page instance' do
44
+ controller do
45
+ def index
46
+ @page = PufferPages::Page.root
47
+ render puffer_page: @page
48
+ end
49
+
50
+ def show
51
+ @page = PufferPages::Page.find_page 'first'
52
+ render puffer_page: @page
53
+ end
54
+ end
55
+
56
+ it { should render_page root }
57
+ it { should_not render_page first }
58
+ it { should_not render_page second }
59
+ specify do
60
+ get :index
61
+ response.should render_page root
62
+ end
63
+ specify do
64
+ get :index
65
+ response.should_not render_page first
66
+ end
67
+ specify do
68
+ get :index
69
+ response.should_not render_page second
70
+ end
71
+ specify do
72
+ get :show, id: 42
73
+ response.should_not render_page root
74
+ end
75
+ specify do
76
+ get :show, id: 42
77
+ response.should render_page first
78
+ end
79
+ specify do
80
+ get :show, id: 42
81
+ response.should_not render_page second
82
+ end
83
+ end
84
+
85
+ context 'with drops' do
86
+ controller do
87
+ def index
88
+ page = PufferPages::Page.root
89
+ @count = 42
90
+ @string = 'hello'
91
+ @object = Object.new
92
+ render puffer_page: page
93
+ end
94
+ end
95
+
96
+ it { should render_page }
97
+ it { should render_page.with_drops }
98
+ it { should render_page.with_drops('count') }
99
+ it { should render_page.with_drops('string' => 'hello') }
100
+ it { should render_page.with_drops('string', 'count' => 42) }
101
+ it { should render_page.with_drops { |drops| drops.keys.include?('string') } }
102
+ it { should render_page.with_drops { |drops| drops['count'] > 40 } }
103
+ it { should render_page.with_drops('count') { |drops| !drops.key?('object') } }
104
+ it { should_not render_page.with_drops('object') }
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe PufferPages::Layout 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_layout" do
11
+ let!(:layout) { Fabricate :layout, :name => 'main' }
12
+
13
+ specify { PufferPages::Layout.find_layout('main').should == layout}
14
+ end
15
+ end
@@ -0,0 +1,62 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe PufferPages::Backends::Mixins::Localable do
5
+ let(:locales_class) { PufferPages::Backends::Mixins::Localable::Locales }
6
+
7
+ context do
8
+ let!(:page) { Fabricate.build :root }
9
+ specify { page.locales.should == {} }
10
+ specify { page.locales.should be_a locales_class }
11
+ end
12
+
13
+ context do
14
+ let!(:page) { Fabricate :root }
15
+ specify { page.locales.should == {} }
16
+ specify { page.reload.locales.should == {} }
17
+ specify { page.locales.should be_a locales_class }
18
+ specify { page.reload.locales.should be_a locales_class }
19
+ end
20
+
21
+ context do
22
+ let!(:page) { Fabricate :root, locales: { en: 'hello: world' } }
23
+ specify { page.locales.should == { 'en' => 'hello: world' } }
24
+ specify { page.reload.locales.should == { 'en' => 'hello: world' } }
25
+ specify { page.locales.should be_a locales_class }
26
+ specify { page.reload.locales.should be_a locales_class }
27
+ end
28
+
29
+ context do
30
+ let!(:page) { Fabricate.build :root, locales: { en: 'Hello' } }
31
+ specify { page.should be_invalid }
32
+ specify { page.tap { |page| page.valid? }.errors[:locales].first.should == page.locales.error }
33
+ end
34
+ end
35
+
36
+ describe PufferPages::Backends::Mixins::Localable::Locales do
37
+ let(:valid) {
38
+ described_class.new(
39
+ en: YAML.dump(hello: 'World', bye: 'Hell'),
40
+ de: YAML.dump('key' => 'value')
41
+ )
42
+ }
43
+ let(:invalid) {
44
+ described_class.new(
45
+ en: YAML.dump('hello')
46
+ )
47
+ }
48
+ describe '#translations' do
49
+ specify { valid.translations.should == { en: { hello: 'World', bye: 'Hell' }, de: { key: 'value' } } }
50
+ specify { expect { invalid.translations }.to raise_exception SyntaxError }
51
+ end
52
+
53
+ describe '#valid?' do
54
+ specify { valid.should be_valid }
55
+ specify { invalid.should_not be_valid }
56
+ end
57
+
58
+ describe '#valid?' do
59
+ specify { valid.error.should be_false }
60
+ specify { invalid.error.should =~ /Locale should be a hash/ }
61
+ end
62
+ end
@@ -0,0 +1,112 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe PufferPages::Origin do
5
+ let!(:origin) { Fabricate :origin }
6
+
7
+ describe "validations" do
8
+ it { should validate_presence_of(:name) }
9
+ it { should validate_presence_of(:host) }
10
+ it { should validate_presence_of(:token) }
11
+ it { should validate_uniqueness_of(:name) }
12
+ end
13
+
14
+ describe ".export_json" do
15
+ let!(:layout) { Fabricate :application }
16
+ let!(:snippet) { Fabricate :snippet }
17
+ let!(:page) { Fabricate :root, page_parts: [Fabricate(:main)] }
18
+
19
+ let(:json) { described_class.export_json }
20
+
21
+ describe "root level keys" do
22
+ subject { ActiveSupport::JSON.decode json }
23
+
24
+ %w(layouts pages snippets).each do |key|
25
+ it { should have_key(key) }
26
+ end
27
+ end
28
+
29
+ describe "exported page parts" do
30
+ subject { ActiveSupport::JSON.decode(json)["pages"].first }
31
+ it { should have_key("page_parts") }
32
+ specify { subject["page_parts"].should have(1).items }
33
+ end
34
+ end
35
+
36
+ describe "#uri" do
37
+ {
38
+ "http://localhost#{PufferPages.export_path}" => { host: 'localhost' },
39
+ "http://ya.ru#{PufferPages.export_path}" => { host: 'ya.ru' },
40
+ "http://localhost:3000#{PufferPages.export_path}" => { host: 'localhost:3000' },
41
+ "https://localhost:3000#{PufferPages.export_path}" => { host: 'https://localhost:3000' },
42
+ "https://localhost:3000#{PufferPages.export_path}" => { host: 'https://localhost:3000', token: 'token2' },
43
+ "http://localhost:3000/export/path" => { host: 'http://localhost:3000', token: 'token2', path: 'export/path' }
44
+ }.each_with_index do |(uri, attributes), index|
45
+ specify {
46
+ origin = Fabricate :origin, attributes
47
+ origin.uri.to_s.should == [uri, { token: origin.token }.to_query].join(??)
48
+ }
49
+ end
50
+ end
51
+
52
+ context "import" do
53
+ let(:json) { File.read('spec/data/import.json') }
54
+
55
+ describe "#import_json" do
56
+ specify { expect { origin.import_json(json) }.to change(PufferPages::Layout, :count).from(0).to(2) }
57
+ specify { expect { origin.import_json(json) }.to change(PufferPages::Page, :count).from(0).to(1) }
58
+ specify { expect { origin.import_json(json) }.to change(PufferPages::PagePart, :count).from(0).to(2) }
59
+ specify { expect { origin.import_json(json) }.to change(PufferPages::Snippet, :count).from(0).to(1) }
60
+ end
61
+
62
+ describe "#import!" do
63
+ before { FakeWeb.register_uri(:get, origin.uri, body: json, content_length: json.length) }
64
+
65
+ specify { expect { origin.import! }.to change(PufferPages::Layout, :count).from(0).to(2) }
66
+ specify { expect { origin.import! }.to change(PufferPages::Page, :count).from(0).to(1) }
67
+ specify { expect { origin.import! }.to change(PufferPages::PagePart, :count).from(0).to(2) }
68
+ specify { expect { origin.import! }.to change(PufferPages::Snippet, :count).from(0).to(1) }
69
+ end
70
+ end
71
+
72
+ context "import error" do
73
+ let(:json) { File.read('spec/data/broken.json') }
74
+
75
+ specify { expect { origin.import_json json }.to raise_exception ActiveRecord::UnknownAttributeError }
76
+ end
77
+
78
+ context "import-export integrity" do
79
+ before { Timecop.freeze Time.parse('2013/12/23 23:23') }
80
+ after { Timecop.return }
81
+
82
+ let!(:layout) { Fabricate :application }
83
+ let!(:snippet) { Fabricate :snippet }
84
+ let!(:root) { Fabricate :root, page_parts: [Fabricate(:main), Fabricate(:sidebar)] }
85
+ let!(:first) { Fabricate :page, slug: 'first', parent: root, page_parts: [Fabricate(:main)] }
86
+ let!(:second) { Fabricate :page, slug: 'second', parent: first, page_parts: [Fabricate(:sidebar)] }
87
+
88
+ let(:json) do
89
+ PufferPages.localize ?
90
+ File.read('spec/data/localized.json') :
91
+ File.read('spec/data/unlocalized.json')
92
+ end
93
+
94
+ # TODO: make this work will be perfect
95
+ # specify do
96
+ # ActiveSupport::JSON.decode(described_class.export_json).should ==
97
+ # ActiveSupport::JSON.decode(json)
98
+ # end
99
+
100
+ specify do
101
+ origin.import_json json
102
+
103
+ old_dump = ActiveSupport::JSON.decode(json)
104
+ new_dump = ActiveSupport::JSON.decode(described_class.export_json)
105
+ new_dump.each do |(table, rows)|
106
+ rows.each_with_index do |attributes, index|
107
+ attributes.should == old_dump[table][index]
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end