landable 1.13.1 → 1.13.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. data/.rubocop.yml +281 -0
  2. data/.travis.yml +0 -1
  3. data/CHANGELOG.md +5 -1
  4. data/Gemfile +3 -4
  5. data/README.md +2 -0
  6. data/Rakefile +6 -3
  7. data/app/controllers/concerns/landable/variables_concern.rb +9 -9
  8. data/app/controllers/landable/api/access_tokens_controller.rb +7 -8
  9. data/app/controllers/landable/api/assets_controller.rb +29 -26
  10. data/app/controllers/landable/api/audits_controller.rb +6 -5
  11. data/app/controllers/landable/api/configurations_controller.rb +1 -1
  12. data/app/controllers/landable/api/directories_controller.rb +2 -2
  13. data/app/controllers/landable/api/page_revisions_controller.rb +2 -4
  14. data/app/controllers/landable/api/pages_controller.rb +39 -40
  15. data/app/controllers/landable/api/template_revisions_controller.rb +1 -2
  16. data/app/controllers/landable/api/templates_controller.rb +15 -14
  17. data/app/controllers/landable/api/themes_controller.rb +15 -14
  18. data/app/controllers/landable/api_controller.rb +10 -11
  19. data/app/controllers/landable/public/pages_controller.rb +2 -2
  20. data/app/controllers/landable/public/preview/page_revisions_controller.rb +2 -2
  21. data/app/controllers/landable/public/preview/pages_controller.rb +1 -1
  22. data/app/controllers/landable/public/sitemap_controller.rb +2 -2
  23. data/app/decorators/landable/page_decorator.rb +3 -3
  24. data/app/helpers/landable/pages_helper.rb +2 -2
  25. data/app/helpers/landable/traffic_helper.rb +2 -4
  26. data/app/models/concerns/landable/has_assets.rb +6 -9
  27. data/app/models/concerns/landable/has_templates.rb +6 -7
  28. data/app/models/concerns/landable/librarian.rb +5 -5
  29. data/app/models/concerns/landable/table_name.rb +2 -2
  30. data/app/models/landable/access_token.rb +1 -1
  31. data/app/models/landable/asset.rb +8 -8
  32. data/app/models/landable/asset_search_engine.rb +7 -8
  33. data/app/models/landable/author.rb +2 -1
  34. data/app/models/landable/category.rb +1 -3
  35. data/app/models/landable/directory.rb +2 -2
  36. data/app/models/landable/page.rb +44 -50
  37. data/app/models/landable/page_revision.rb +27 -41
  38. data/app/models/landable/page_search_engine.rb +5 -6
  39. data/app/models/landable/search_engine.rb +2 -2
  40. data/app/models/landable/template.rb +9 -11
  41. data/app/models/landable/template_revision.rb +4 -14
  42. data/app/models/landable/theme.rb +1 -1
  43. data/app/models/landable/traffic/attribution.rb +3 -1
  44. data/app/models/landable/traffic/page_view.rb +1 -1
  45. data/app/models/landable/traffic/user_agent.rb +1 -1
  46. data/app/models/landable/traffic/visit.rb +1 -1
  47. data/app/responders/landable/api_responder.rb +5 -3
  48. data/app/responders/landable/page_render_responder.rb +1 -1
  49. data/app/serializers/landable/asset_serializer.rb +1 -1
  50. data/app/serializers/landable/audit_serializer.rb +2 -3
  51. data/app/serializers/landable/directory_serializer.rb +2 -2
  52. data/app/serializers/landable/page_revision_serializer.rb +0 -1
  53. data/app/serializers/landable/page_serializer.rb +5 -5
  54. data/app/serializers/landable/template_serializer.rb +2 -2
  55. data/app/services/landable/authentication_service.rb +1 -1
  56. data/app/services/landable/registration_service.rb +3 -2
  57. data/app/services/landable/render_service.rb +16 -18
  58. data/app/services/landable/screenshot_service.rb +3 -4
  59. data/app/services/landable/tidy_service.rb +32 -37
  60. data/app/validators/path_validator.rb +1 -3
  61. data/app/validators/url_validator.rb +4 -7
  62. data/config/routes.rb +3 -6
  63. data/db/migrate/20130510221424_create_landable_schema.rb +45 -56
  64. data/db/migrate/20130909182713_landable_pages__add_updated_by.rb +2 -2
  65. data/db/migrate/20130909182715_landable_page_revisions__break_out_snapshot.rb +9 -12
  66. data/db/migrate/20131002220041_file_based_themes.rb +3 -3
  67. data/db/migrate/20131008164204_create_head_tag_on_page.rb +4 -4
  68. data/db/migrate/20131008193544_drop_status_codes_model.rb +1 -2
  69. data/db/migrate/20131028145652_add_traffic_schema.rb +5 -5
  70. data/db/migrate/20131101213623_add_dnt_column_to_visits.rb +1 -1
  71. data/db/migrate/20131106185946_add_index_on_page_revisions_path.rb +1 -1
  72. data/db/migrate/20131106193021_page_revisisons__path_status_code_index.rb +1 -1
  73. data/db/migrate/20131121150902_add_attribution_id_to_unique_index.rb +2 -2
  74. data/db/migrate/20131216214027_drop_browser_screenshot_tables.rb +3 -3
  75. data/db/migrate/20140128170659_file_backed_templates.rb +1 -1
  76. data/db/migrate/20140205193757_fix_status_codes.rb +3 -3
  77. data/db/migrate/20140220170324_add_slug_to_categories.rb +1 -1
  78. data/db/migrate/20140224205516_rename_traffic_schema.rb +7 -9
  79. data/db/migrate/20140509190128_create_template_revisions.rb +13 -15
  80. data/db/migrate/20140509192856_create_audits.rb +3 -3
  81. data/db/migrate/20140602213937_path_response_time_view.rb +20 -19
  82. data/features/step_definitions/asset_steps.rb +10 -12
  83. data/features/step_definitions/core_api_steps.rb +29 -27
  84. data/features/step_definitions/factory_steps.rb +16 -16
  85. data/features/step_definitions/html_steps.rb +1 -1
  86. data/features/step_definitions/liquid_steps.rb +8 -8
  87. data/features/step_definitions/theme_steps.rb +4 -4
  88. data/features/support/env.rb +5 -5
  89. data/landable.gemspec +2 -2
  90. data/lib/generators/landable/landable_generator.rb +2 -2
  91. data/lib/generators/templates/landable.rb +1 -1
  92. data/lib/landable.rb +7 -7
  93. data/lib/landable/configuration.rb +10 -19
  94. data/lib/landable/engine.rb +19 -19
  95. data/lib/landable/error.rb +1 -3
  96. data/lib/landable/layout.rb +6 -6
  97. data/lib/landable/liquid/asset_tags.rb +3 -5
  98. data/lib/landable/liquid/drops.rb +3 -8
  99. data/lib/landable/liquid/filters.rb +1 -3
  100. data/lib/landable/liquid/tags.rb +10 -10
  101. data/lib/landable/migration.rb +30 -30
  102. data/lib/landable/mime_types.rb +1 -1
  103. data/lib/landable/partial.rb +2 -2
  104. data/lib/landable/seeds.rb +3 -4
  105. data/lib/landable/traffic.rb +4 -8
  106. data/lib/landable/traffic/tracker.rb +48 -43
  107. data/lib/landable/traffic/user_tracker.rb +15 -10
  108. data/lib/landable/version.rb +1 -1
  109. data/lib/schema_moves.rb +15 -16
  110. data/lib/tasks/landable/cucumber.rake +46 -47
  111. data/lib/tasks/landable/data.rake +13 -14
  112. data/lib/tasks/landable/pgtap.rake +12 -18
  113. data/lib/tasks/landable/seed.rake +4 -4
  114. data/spec/concerns/landable/has_assets_spec.rb +15 -19
  115. data/spec/concerns/landable/has_templates_spec.rb +10 -13
  116. data/spec/concerns/landable/librarian.rb +4 -4
  117. data/spec/concerns/landable/table_name_spec.rb +3 -5
  118. data/spec/concerns/landable/traffic/table_name_spec.rb +2 -4
  119. data/spec/controllers/concerns/landable/variables_concern_spec.rb +11 -10
  120. data/spec/controllers/landable/api/assets_controller_spec.rb +15 -14
  121. data/spec/controllers/landable/api/audits_controller_spec.rb +104 -102
  122. data/spec/controllers/landable/api/categories_controller_spec.rb +36 -34
  123. data/spec/controllers/landable/api/configuration_controller_spec.rb +14 -12
  124. data/spec/controllers/landable/api/directories_controller_spec.rb +52 -50
  125. data/spec/controllers/landable/api/page_revisions_controller_spec.rb +20 -18
  126. data/spec/controllers/landable/api/pages_controller_spec.rb +204 -203
  127. data/spec/controllers/landable/api/template_revisions_controller_spec.rb +20 -18
  128. data/spec/controllers/landable/api/templates_controller_spec.rb +39 -37
  129. data/spec/controllers/landable/api_controller_spec.rb +24 -26
  130. data/spec/controllers/public/preview/page_revisions_controller_spec.rb +36 -34
  131. data/spec/controllers/public/preview/pages_controller_spec.rb +32 -30
  132. data/spec/controllers/public/sitemap_controller_spec.rb +19 -17
  133. data/spec/decorators/page_decorator_spec.rb +9 -9
  134. data/spec/dummy/app/helpers/application_helper.rb +1 -1
  135. data/spec/dummy/config/application.rb +5 -6
  136. data/spec/dummy/config/boot.rb +1 -1
  137. data/spec/dummy/config/environments/test.rb +1 -1
  138. data/spec/dummy/config/initializers/landable.rb +7 -6
  139. data/spec/factories/asset.rb +1 -1
  140. data/spec/factories/audit.rb +1 -1
  141. data/spec/factories/authors.rb +1 -1
  142. data/spec/factories/category.rb +1 -1
  143. data/spec/factories/pages.rb +4 -4
  144. data/spec/factories/template.rb +3 -3
  145. data/spec/factories/theme.rb +2 -2
  146. data/spec/helpers/pages_helper_spec.rb +5 -5
  147. data/spec/lib/landable/configuration_spec.rb +2 -4
  148. data/spec/lib/landable/event_publisher_spec.rb +1 -3
  149. data/spec/lib/landable/layout_spec.rb +4 -4
  150. data/spec/lib/landable/liquid_spec.rb +12 -14
  151. data/spec/lib/landable/migration_spec.rb +4 -4
  152. data/spec/lib/landable/partial_spec.rb +18 -18
  153. data/spec/lib/landable/tracking_spec.rb +27 -29
  154. data/spec/lib/landable/traffic_spec.rb +29 -33
  155. data/spec/models/landable/access_token_spec.rb +1 -1
  156. data/spec/models/landable/asset_spec.rb +9 -11
  157. data/spec/models/landable/directory_spec.rb +7 -7
  158. data/spec/models/landable/page/errors_spec.rb +1 -3
  159. data/spec/models/landable/page_revision_spec.rb +23 -24
  160. data/spec/models/landable/page_spec.rb +41 -42
  161. data/spec/models/landable/template_revision_spec.rb +3 -3
  162. data/spec/models/landable/template_spec.rb +11 -11
  163. data/spec/models/landable/theme_spec.rb +2 -2
  164. data/spec/models/landable/traffic/referer_spec.rb +3 -3
  165. data/spec/responders/page_render_responder_spec.rb +0 -2
  166. data/spec/routing/public_page_route_spec.rb +4 -5
  167. data/spec/services/landable/authentication_service_spec.rb +7 -7
  168. data/spec/services/landable/render_service_spec.rb +8 -8
  169. data/spec/services/landable/screenshot_service_spec.rb +3 -3
  170. data/spec/services/landable/tidy_service_spec.rb +20 -20
  171. data/spec/spec_helper.rb +3 -3
  172. data/spec/support/behaviors.rb +4 -4
  173. data/spec/support/helpers.rb +1 -1
  174. metadata +86 -35
  175. checksums.yaml +0 -7
@@ -1,44 +1,46 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Landable::Api
4
- describe CategoriesController, json: true do
5
- routes { Landable::Engine.routes }
6
-
7
- describe '#show' do
8
- include_examples 'Authenticated API controller', :make_request
9
-
10
- let(:category) { create :category }
11
-
12
- def make_request(id = category.id)
13
- get :show, id: id
3
+ module Landable
4
+ module Api
5
+ describe CategoriesController, json: true do
6
+ routes { Landable::Engine.routes }
7
+
8
+ describe '#show' do
9
+ include_examples 'Authenticated API controller', :make_request
10
+
11
+ let(:category) { create :category }
12
+
13
+ def make_request(id = category.id)
14
+ get :show, id: id
15
+ end
16
+
17
+ it 'returns the selected category' do
18
+ make_request
19
+ response.status.should eq 200
20
+ last_json['category']['id'].should eq category.id
21
+ end
22
+
23
+ it '404s on page not found' do
24
+ make_request random_uuid
25
+ response.status.should eq 404
26
+ end
14
27
  end
15
28
 
16
- it 'returns the selected category' do
17
- make_request
18
- response.status.should == 200
19
- last_json['category']['id'].should == category.id
20
- end
29
+ describe '#index' do
30
+ include_examples 'Authenticated API controller', :make_request
21
31
 
22
- it '404s on page not found' do
23
- make_request random_uuid
24
- response.status.should == 404
25
- end
26
- end
27
-
28
- describe '#index' do
29
- include_examples 'Authenticated API controller', :make_request
30
-
31
- def make_request
32
- get :index
33
- end
32
+ def make_request
33
+ get :index
34
+ end
34
35
 
35
- it 'returns all categories' do
36
- Landable::Category.delete_all
37
- create_list :category, 5
36
+ it 'returns all categories' do
37
+ Landable::Category.delete_all
38
+ create_list :category, 5
38
39
 
39
- make_request
40
- response.status.should == 200
41
- last_json['categories'].size.should == 5
40
+ make_request
41
+ response.status.should eq 200
42
+ last_json['categories'].size.should eq 5
43
+ end
42
44
  end
43
45
  end
44
46
  end
@@ -1,20 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Landable::Api
4
- describe ConfigurationsController, json: true do
5
- routes { Landable::Engine.routes }
3
+ module Landable
4
+ module Api
5
+ describe ConfigurationsController, json: true do
6
+ routes { Landable::Engine.routes }
6
7
 
7
- describe '#show' do
8
- include_examples 'Authenticated API controller', :make_request
8
+ describe '#show' do
9
+ include_examples 'Authenticated API controller', :make_request
9
10
 
10
- def make_request
11
- get :show
12
- end
11
+ def make_request
12
+ get :show
13
+ end
13
14
 
14
- it 'renders the page as JSON' do
15
- make_request
16
- # defined in Landable Dummy Initalizer
17
- last_json['configurations'][0]['audit_flags'].should == %w(loans apr)
15
+ it 'renders the page as JSON' do
16
+ make_request
17
+ # defined in Landable Dummy Initalizer
18
+ last_json['configurations'][0]['audit_flags'].should eq %w(loans apr)
19
+ end
18
20
  end
19
21
  end
20
22
  end
@@ -1,55 +1,57 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Landable::Api
4
- describe DirectoriesController, json: true do
5
- routes { Landable::Engine.routes }
6
-
7
- describe '#index' do
8
- include_examples 'Authenticated API controller', :make_request
9
-
10
- def make_request(ids = nil)
11
- get :index, ids: ids
12
- end
13
-
14
- def dirs
15
- last_json['directories']
16
- end
17
-
18
- def dir(path)
19
- dirs.find { |dir| dir['id'] == path }
20
- end
21
-
22
- def subdirs(path)
23
- dir(path)['subdirectory_ids']
24
- end
25
-
26
- def pages(path)
27
- dir(path)['page_ids']
28
- end
29
-
30
- it 'defaults to the root path' do
31
- pages = ['/a', '/b/c', '/b/d'].map { |path| create :page, path: path }
32
- make_request
33
- response.status.should == 200
34
-
35
- dirs.length.should == 1
36
- dirs.first['id'].should == '/'
37
-
38
- subdirs('/').length.should == 1
39
- pages('/').length.should == 1
40
- end
41
-
42
- it 'returns multiple directory listings' do
43
- pages = ['/a', '/b/c', '/b/d', '/c/e', '/c/f/g'].map { |path| create :page, path: path }
44
- make_request ['/b', '/c']
45
- response.status.should == 200
46
- dirs.length.should == 2
47
-
48
- pages('/b').length.should == 2
49
- pages('/c').length.should == 1
50
-
51
- subdirs('/b').length.should == 0
52
- subdirs('/c').length.should == 1
3
+ module Landable
4
+ module Api
5
+ describe DirectoriesController, json: true do
6
+ routes { Landable::Engine.routes }
7
+
8
+ describe '#index' do
9
+ include_examples 'Authenticated API controller', :make_request
10
+
11
+ def make_request(ids = nil)
12
+ get :index, ids: ids
13
+ end
14
+
15
+ def dirs
16
+ last_json['directories']
17
+ end
18
+
19
+ def dir(path)
20
+ dirs.find { |dir| dir['id'] == path }
21
+ end
22
+
23
+ def subdirs(path)
24
+ dir(path)['subdirectory_ids']
25
+ end
26
+
27
+ def pages(path)
28
+ dir(path)['page_ids']
29
+ end
30
+
31
+ it 'defaults to the root path' do
32
+ ['/a', '/b/c', '/b/d'].map { |path| create :page, path: path }
33
+ make_request
34
+ response.status.should eq 200
35
+
36
+ dirs.length.should eq 1
37
+ dirs.first['id'].should eq '/'
38
+
39
+ subdirs('/').length.should eq 1
40
+ pages('/').length.should eq 1
41
+ end
42
+
43
+ it 'returns multiple directory listings' do
44
+ ['/a', '/b/c', '/b/d', '/c/e', '/c/f/g'].map { |path| create :page, path: path }
45
+ make_request ['/b', '/c']
46
+ response.status.should eq 200
47
+ dirs.length.should eq 2
48
+
49
+ pages('/b').length.should eq 2
50
+ pages('/c').length.should eq 1
51
+
52
+ subdirs('/b').length.should eq 0
53
+ subdirs('/c').length.should eq 1
54
+ end
53
55
  end
54
56
  end
55
57
  end
@@ -1,28 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Landable::Api
4
- describe PageRevisionsController, json: true do
5
- routes { Landable::Engine.routes }
3
+ module Landable
4
+ module Api
5
+ describe PageRevisionsController, json: true do
6
+ routes { Landable::Engine.routes }
6
7
 
7
- describe '#index' do
8
- include_examples 'Authenticated API controller', :make_request
8
+ describe '#index' do
9
+ include_examples 'Authenticated API controller', :make_request
9
10
 
10
- let(:page) { create :page }
11
+ let(:page) { create :page }
11
12
 
12
- def make_request(page_id = page.id)
13
- get :index, page_id: page_id
14
- end
13
+ def make_request(page_id = page.id)
14
+ get :index, page_id: page_id
15
+ end
15
16
 
16
- it "returns all of a page's revisions" do
17
- page.publish! author: current_author
18
- make_request
19
- response.status.should == 200
20
- last_json['page_revisions'].length.should == 1
21
- end
17
+ it "returns all of a page's revisions" do
18
+ page.publish! author: current_author
19
+ make_request
20
+ response.status.should eq 200
21
+ last_json['page_revisions'].length.should eq 1
22
+ end
22
23
 
23
- it "404s on page not found" do
24
- make_request random_uuid
25
- response.status.should == 404
24
+ it '404s on page not found' do
25
+ make_request random_uuid
26
+ response.status.should eq 404
27
+ end
26
28
  end
27
29
  end
28
30
  end
@@ -1,270 +1,271 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Landable::Api
4
- describe PagesController, json: true do
5
- routes { Landable::Engine.routes }
3
+ module Landable
4
+ module Api
5
+ describe PagesController, json: true do
6
+ routes { Landable::Engine.routes }
6
7
 
7
- describe '#create' do
8
- include_examples 'Authenticated API controller', :make_request
8
+ describe '#create' do
9
+ include_examples 'Authenticated API controller', :make_request
9
10
 
10
- let(:default_params) do
11
- { page: attributes_for(:page) }
12
- end
13
-
14
- let(:page) do
15
- Landable::Page.where(path: default_params[:page][:path]).first
16
- end
17
-
18
- def make_request(params = {})
19
- post :create, default_params.deep_merge(page: params)
20
- end
21
-
22
- context 'success' do
23
- it 'returns 201 Created' do
24
- make_request
25
- response.status.should == 201
11
+ let(:default_params) do
12
+ { page: attributes_for(:page) }
26
13
  end
27
14
 
28
- it 'returns header Location with the page URL' do
29
- make_request
30
- response.headers['Location'].should == page_url(page)
15
+ let(:page) do
16
+ Landable::Page.where(path: default_params[:page][:path]).first
31
17
  end
32
18
 
33
- it 'renders the page as JSON' do
34
- make_request
35
- path, body = default_params[:page].values_at(:path, :body)
36
- last_json['page'].should include('path' => path, 'body' => body)
19
+ def make_request(params = {})
20
+ post :create, default_params.deep_merge(page: params)
37
21
  end
38
- end
39
22
 
40
- context 'invalid' do
41
- it 'returns 422 Unprocessable Entity' do
42
- make_request path: nil
43
- response.status.should == 422
23
+ context 'success' do
24
+ it 'returns 201 Created' do
25
+ make_request
26
+ response.status.should eq 201
27
+ end
28
+
29
+ it 'returns header Location with the page URL' do
30
+ make_request
31
+ response.headers['Location'].should eq page_url(page)
32
+ end
33
+
34
+ it 'renders the page as JSON' do
35
+ make_request
36
+ path, body = default_params[:page].values_at(:path, :body)
37
+ last_json['page'].should include('path' => path, 'body' => body)
38
+ end
44
39
  end
45
40
 
46
- it 'includes the errors in the JSON response' do
47
- make_request status_code: 302, redirect_url: nil
48
- last_json['errors'].should have_key('redirect_url')
41
+ context 'invalid' do
42
+ it 'returns 422 Unprocessable Entity' do
43
+ make_request path: nil
44
+ response.status.should eq 422
45
+ end
46
+
47
+ it 'includes the errors in the JSON response' do
48
+ make_request status_code: 302, redirect_url: nil
49
+ last_json['errors'].should have_key('redirect_url')
50
+ end
49
51
  end
50
52
  end
51
- end
52
53
 
53
- describe '#index' do
54
- include_examples 'Authenticated API controller', :make_request
54
+ describe '#index' do
55
+ include_examples 'Authenticated API controller', :make_request
55
56
 
56
- let(:pages) { @pages ||= create_list(:page, 5) }
57
- before(:each) { pages }
57
+ let(:pages) { @pages ||= create_list(:page, 5) }
58
+ before(:each) { pages }
58
59
 
59
- def make_request(params = {})
60
- get :index, params
61
- end
60
+ def make_request(params = {})
61
+ get :index, params
62
+ end
62
63
 
63
- it 'renders pages as json' do
64
- make_request
65
- last_json['pages'].collect { |p| p['id'] }.sort.should == pages.map(&:id).sort
66
- end
64
+ it 'renders pages as json' do
65
+ make_request
66
+ last_json['pages'].collect { |p| p['id'] }.sort.should eq pages.map(&:id).sort
67
+ end
67
68
 
68
- it 'filters pages according to requested ids' do
69
- filtered_for_pages = pages[0..2]
69
+ it 'filters pages according to requested ids' do
70
+ filtered_for_pages = pages[0..2]
70
71
 
71
- make_request ids: filtered_for_pages.map(&:id)
72
- last_json['pages'].collect { |p| p['id'] }.sort.should == filtered_for_pages.map(&:id).sort
73
- end
72
+ make_request ids: filtered_for_pages.map(&:id)
73
+ last_json['pages'].collect { |p| p['id'] }.sort.should eq filtered_for_pages.map(&:id).sort
74
+ end
74
75
 
75
- describe 'search' do
76
- describe 'by path' do
77
- before(:each) do
78
- ['/foo', '/foo/bar', '/foo/bar/baz', '/bar'].each do |path|
79
- create :page, path: path
76
+ describe 'search' do
77
+ describe 'by path' do
78
+ before(:each) do
79
+ ['/foo', '/foo/bar', '/foo/bar/baz', '/bar'].each do |path|
80
+ create :page, path: path
81
+ end
80
82
  end
81
- end
82
83
 
83
- it 'filters by starting path fragment' do
84
- make_request search: {path: '/foo/ba'}
85
- last_json['pages'].collect { |p| p['path'] }.should == ['/foo/bar', '/foo/bar/baz']
86
- end
84
+ it 'filters by starting path fragment' do
85
+ make_request search: { path: '/foo/ba' }
86
+ last_json['pages'].collect { |p| p['path'] }.should eq ['/foo/bar', '/foo/bar/baz']
87
+ end
87
88
 
88
- it 'matches all paths with the search term in them' do
89
- make_request search: {path: 'ba'}
90
- last_json['pages'].collect { |p| p['path'] }.should == ['/bar', '/foo/bar', '/foo/bar/baz']
89
+ it 'matches all paths with the search term in them' do
90
+ make_request search: { path: 'ba' }
91
+ last_json['pages'].collect { |p| p['path'] }.should eq ['/bar', '/foo/bar', '/foo/bar/baz']
92
+ end
91
93
  end
92
94
  end
93
- end
94
95
 
95
- it 'only include 100 results, and include the total result count as meta data' do
96
- create_list :page, (100 - pages.size)
97
- make_request search: {path: '/'}
96
+ it 'only include 100 results, and include the total result count as meta data' do
97
+ create_list :page, (100 - pages.size)
98
+ make_request search: { path: '/' }
98
99
 
99
- last_json['pages'].size.should == 100
100
- last_json['meta']['search']['total_results'].should == 100
100
+ last_json['pages'].size.should eq 100
101
+ last_json['meta']['search']['total_results'].should eq 100
102
+ end
101
103
  end
102
- end
103
104
 
104
- describe '#show' do
105
- include_examples 'Authenticated API controller', :make_request
106
- let(:page) { @page || create(:page) }
105
+ describe '#show' do
106
+ include_examples 'Authenticated API controller', :make_request
107
+ let(:page) { @page || create(:page) }
107
108
 
108
- def make_request(id = page.id)
109
- get :show, id: id
110
- end
111
-
112
- it 'renders the page as JSON' do
113
- make_request
114
- last_json['page']['body'].should == page.body
115
- end
109
+ def make_request(id = page.id)
110
+ get :show, id: id
111
+ end
116
112
 
117
- it 'includes an empty meta_tags hash instead of a null' do
118
- page.update_attributes meta_tags: nil
119
- make_request
120
- last_json['page']['meta_tags'].should == {}
121
- end
113
+ it 'renders the page as JSON' do
114
+ make_request
115
+ last_json['page']['body'].should eq page.body
116
+ end
122
117
 
118
+ it 'includes an empty meta_tags hash instead of a null' do
119
+ page.update_attributes meta_tags: nil
120
+ make_request
121
+ last_json['page']['meta_tags'].should eq({})
122
+ end
123
123
 
124
- context 'no such page' do
125
- it 'returns 404' do
126
- make_request random_uuid
127
- response.status.should == 404
124
+ context 'no such page' do
125
+ it 'returns 404' do
126
+ make_request random_uuid
127
+ response.status.should eq 404
128
+ end
128
129
  end
129
130
  end
130
- end
131
-
132
- describe '#update' do
133
- include_examples 'Authenticated API controller', :make_request
134
131
 
135
- let(:page) { @page || create(:page) }
136
- let(:default_params) do
137
- { page: { body: 'Different body content' } }
138
- end
132
+ describe '#update' do
133
+ include_examples 'Authenticated API controller', :make_request
139
134
 
140
- def make_request(changes = {})
141
- id = changes.delete(:id) || page.id
142
- patch :update, default_params.deep_merge(id: id, page: changes)
143
- end
135
+ let(:page) { @page || create(:page) }
136
+ let(:default_params) do
137
+ { page: { body: 'Different body content' } }
138
+ end
144
139
 
145
- it 'saves the changes' do
146
- make_request body: 'updated body!'
147
- response.status.should == 200
148
- page.reload.body.should == 'updated body!'
149
- page.reload.updated_by_author.should == current_author
150
- end
140
+ def make_request(changes = {})
141
+ id = changes.delete(:id) || page.id
142
+ patch :update, default_params.deep_merge(id: id, page: changes)
143
+ end
151
144
 
152
- it 'renders the page as JSON' do
153
- make_request body: 'also updated'
154
- last_json['page']['body'].should == 'also updated'
155
- end
145
+ it 'saves the changes' do
146
+ make_request body: 'updated body!'
147
+ response.status.should eq 200
148
+ page.reload.body.should eq 'updated body!'
149
+ page.reload.updated_by_author.should eq current_author
150
+ end
156
151
 
157
- context 'invalid' do
158
- it 'returns 422 Unprocessable Entity' do
159
- make_request path: nil
160
- response.status.should == 422
152
+ it 'renders the page as JSON' do
153
+ make_request body: 'also updated'
154
+ last_json['page']['body'].should eq 'also updated'
161
155
  end
162
156
 
163
- it 'includes the errors in the JSON response' do
164
- make_request status_code: 302, redirect_url: nil
157
+ context 'invalid' do
158
+ it 'returns 422 Unprocessable Entity' do
159
+ make_request path: nil
160
+ response.status.should eq 422
161
+ end
162
+
163
+ it 'includes the errors in the JSON response' do
164
+ make_request status_code: 302, redirect_url: nil
165
+ end
165
166
  end
166
- end
167
167
 
168
- context 'no such page' do
169
- it 'returns 404' do
170
- make_request id: random_uuid
171
- response.status.should == 404
168
+ context 'no such page' do
169
+ it 'returns 404' do
170
+ make_request id: random_uuid
171
+ response.status.should eq 404
172
+ end
172
173
  end
173
- end
174
174
 
175
- context 'stale page' do
176
- it 'throws error when stale body update' do
177
- page.save!
178
- page1 = Landable::Page.first
179
- page2 = Landable::Page.first
175
+ context 'stale page' do
176
+ it 'throws error when stale body update' do
177
+ page.save!
178
+ page1 = Landable::Page.first
179
+ page2 = Landable::Page.first
180
180
 
181
- page1.body = "duh"
182
- expect{ page1.save! }.to_not raise_error
183
- page2.body = "something"
184
- expect{ page2.save! }.to raise_error(ActiveRecord::StaleObjectError)
185
- end
181
+ page1.body = 'duh'
182
+ expect { page1.save! }.to_not raise_error
183
+ page2.body = 'something'
184
+ expect { page2.save! }.to raise_error(ActiveRecord::StaleObjectError)
185
+ end
186
186
 
187
- it 'throws error when stale meta_tags update' do
188
- page.save!
189
- page1 = Landable::Page.first
190
- page2 = Landable::Page.first
187
+ it 'throws error when stale meta_tags update' do
188
+ page.save!
189
+ page1 = Landable::Page.first
190
+ page2 = Landable::Page.first
191
191
 
192
- page1.meta_tags = "duh"
193
- expect{ page1.save! }.to_not raise_error
194
- page2.meta_tags = "something"
195
- expect{ page2.save! }.to raise_error(ActiveRecord::StaleObjectError)
196
- end
192
+ page1.meta_tags = 'duh'
193
+ expect { page1.save! }.to_not raise_error
194
+ page2.meta_tags = 'something'
195
+ expect { page2.save! }.to raise_error(ActiveRecord::StaleObjectError)
196
+ end
197
197
 
198
- it 'throws error when stale path update' do
199
- page.save!
200
- page1 = Landable::Page.first
201
- page2 = Landable::Page.first
198
+ it 'throws error when stale path update' do
199
+ page.save!
200
+ page1 = Landable::Page.first
201
+ page2 = Landable::Page.first
202
202
 
203
- page1.body = "duh"
204
- expect{ page1.save! }.to_not raise_error
205
- page2.body = "something"
206
- expect{ page2.save! }.to raise_error(ActiveRecord::StaleObjectError)
207
- end
203
+ page1.body = 'duh'
204
+ expect { page1.save! }.to_not raise_error
205
+ page2.body = 'something'
206
+ expect { page2.save! }.to raise_error(ActiveRecord::StaleObjectError)
207
+ end
208
208
 
209
- it 'throws error when stale multi-column update' do
210
- page.save!
211
- page1 = Landable::Page.first
212
- page2 = Landable::Page.first
213
- page1.body = "duh"
214
- expect{ page1.save! }.to_not raise_error
215
- page2.body = "something"
216
- expect{ page2.save! }.to raise_error(ActiveRecord::StaleObjectError)
209
+ it 'throws error when stale multi-column update' do
210
+ page.save!
211
+ page1 = Landable::Page.first
212
+ page2 = Landable::Page.first
213
+ page1.body = 'duh'
214
+ expect { page1.save! }.to_not raise_error
215
+ page2.body = 'something'
216
+ expect { page2.save! }.to raise_error(ActiveRecord::StaleObjectError)
217
+ end
217
218
  end
218
219
  end
219
- end
220
220
 
221
- describe '#preview', json: false do
222
- include_examples 'Authenticated API controller', :make_request
223
- render_views
221
+ describe '#preview', json: false do
222
+ include_examples 'Authenticated API controller', :make_request
223
+ render_views
224
224
 
225
- let(:theme) { create :theme, body: '<html><head>{% head_content %}</head><body>Theme content; page content: {{body}}</body></html>' }
225
+ let(:theme) { create :theme, body: '<html><head>{% head_content %}</head><body>Theme content; page content: {{body}}</body></html>' }
226
226
 
227
- before do
228
- request.env['HTTP_ACCEPT'] = 'text/html'
229
- end
227
+ before do
228
+ request.env['HTTP_ACCEPT'] = 'text/html'
229
+ end
230
230
 
231
- def make_request(attributes = attributes_for(:page, theme_id: theme.id))
232
- post :preview, page: attributes
233
- end
231
+ def make_request(attributes = attributes_for(:page, theme_id: theme.id))
232
+ post :preview, page: attributes
233
+ end
234
234
 
235
- it 'renders JSON' do
236
- request.env['HTTP_ACCEPT'] = 'application/json'
237
- make_request
238
- response.status.should == 200
239
- last_json['page']['preview'].should be_present
240
- end
235
+ it 'renders JSON' do
236
+ request.env['HTTP_ACCEPT'] = 'application/json'
237
+ make_request
238
+ response.status.should eq 200
239
+ last_json['page']['preview'].should be_present
240
+ end
241
241
 
242
- it 'renders the layout without content if the body is not present' do
243
- request.env['HTTP_ACCEPT'] = 'application/json'
244
- make_request attributes_for(:page, body: nil, theme_id: theme.id)
245
- response.status.should == 200
246
- last_json['page']['preview'].should include('Theme content')
247
- end
242
+ it 'renders the layout without content if the body is not present' do
243
+ request.env['HTTP_ACCEPT'] = 'application/json'
244
+ make_request attributes_for(:page, body: nil, theme_id: theme.id)
245
+ response.status.should eq 200
246
+ last_json['page']['preview'].should include('Theme content')
247
+ end
248
248
 
249
- it 'renders without a layout if no theme is present' do
250
- request.env['HTTP_ACCEPT'] = 'application/json'
251
- make_request attributes_for(:page, body: 'raw content', theme_id: nil)
252
- response.status.should == 200
253
- last_json['page']['preview'].should include('raw content')
254
- end
249
+ it 'renders without a layout if no theme is present' do
250
+ request.env['HTTP_ACCEPT'] = 'application/json'
251
+ make_request attributes_for(:page, body: 'raw content', theme_id: nil)
252
+ response.status.should eq 200
253
+ last_json['page']['preview'].should include('raw content')
254
+ end
255
255
 
256
- it 'renders 30x pages with a link to the real thing' do
257
- request.env['HTTP_ACCEPT'] = 'application/json'
258
- make_request attributes_for(:page, :redirect, body: 'still here', theme_id: theme.id)
259
- response.status.should == 200
260
- last_json['page']['preview'].should include('301')
261
- end
256
+ it 'renders 30x pages with a link to the real thing' do
257
+ request.env['HTTP_ACCEPT'] = 'application/json'
258
+ make_request attributes_for(:page, :redirect, body: 'still here', theme_id: theme.id)
259
+ response.status.should eq 200
260
+ last_json['page']['preview'].should include('301')
261
+ end
262
262
 
263
- it 'renders 404 pages as if they were 200s' do
264
- request.env['HTTP_ACCEPT'] = 'application/json'
265
- make_request attributes_for(:page, :gone, body: 'still here', theme_id: theme.id)
266
- response.status.should == 200
267
- last_json['page']['preview'].should match(/still here/)
263
+ it 'renders 404 pages as if they were 200s' do
264
+ request.env['HTTP_ACCEPT'] = 'application/json'
265
+ make_request attributes_for(:page, :gone, body: 'still here', theme_id: theme.id)
266
+ response.status.should eq 200
267
+ last_json['page']['preview'].should match(/still here/)
268
+ end
268
269
  end
269
270
  end
270
271
  end