landable 1.13.1 → 1.13.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.rubocop.yml +281 -0
- data/.travis.yml +0 -1
- data/CHANGELOG.md +5 -1
- data/Gemfile +3 -4
- data/README.md +2 -0
- data/Rakefile +6 -3
- data/app/controllers/concerns/landable/variables_concern.rb +9 -9
- data/app/controllers/landable/api/access_tokens_controller.rb +7 -8
- data/app/controllers/landable/api/assets_controller.rb +29 -26
- data/app/controllers/landable/api/audits_controller.rb +6 -5
- data/app/controllers/landable/api/configurations_controller.rb +1 -1
- data/app/controllers/landable/api/directories_controller.rb +2 -2
- data/app/controllers/landable/api/page_revisions_controller.rb +2 -4
- data/app/controllers/landable/api/pages_controller.rb +39 -40
- data/app/controllers/landable/api/template_revisions_controller.rb +1 -2
- data/app/controllers/landable/api/templates_controller.rb +15 -14
- data/app/controllers/landable/api/themes_controller.rb +15 -14
- data/app/controllers/landable/api_controller.rb +10 -11
- data/app/controllers/landable/public/pages_controller.rb +2 -2
- data/app/controllers/landable/public/preview/page_revisions_controller.rb +2 -2
- data/app/controllers/landable/public/preview/pages_controller.rb +1 -1
- data/app/controllers/landable/public/sitemap_controller.rb +2 -2
- data/app/decorators/landable/page_decorator.rb +3 -3
- data/app/helpers/landable/pages_helper.rb +2 -2
- data/app/helpers/landable/traffic_helper.rb +2 -4
- data/app/models/concerns/landable/has_assets.rb +6 -9
- data/app/models/concerns/landable/has_templates.rb +6 -7
- data/app/models/concerns/landable/librarian.rb +5 -5
- data/app/models/concerns/landable/table_name.rb +2 -2
- data/app/models/landable/access_token.rb +1 -1
- data/app/models/landable/asset.rb +8 -8
- data/app/models/landable/asset_search_engine.rb +7 -8
- data/app/models/landable/author.rb +2 -1
- data/app/models/landable/category.rb +1 -3
- data/app/models/landable/directory.rb +2 -2
- data/app/models/landable/page.rb +44 -50
- data/app/models/landable/page_revision.rb +27 -41
- data/app/models/landable/page_search_engine.rb +5 -6
- data/app/models/landable/search_engine.rb +2 -2
- data/app/models/landable/template.rb +9 -11
- data/app/models/landable/template_revision.rb +4 -14
- data/app/models/landable/theme.rb +1 -1
- data/app/models/landable/traffic/attribution.rb +3 -1
- data/app/models/landable/traffic/page_view.rb +1 -1
- data/app/models/landable/traffic/user_agent.rb +1 -1
- data/app/models/landable/traffic/visit.rb +1 -1
- data/app/responders/landable/api_responder.rb +5 -3
- data/app/responders/landable/page_render_responder.rb +1 -1
- data/app/serializers/landable/asset_serializer.rb +1 -1
- data/app/serializers/landable/audit_serializer.rb +2 -3
- data/app/serializers/landable/directory_serializer.rb +2 -2
- data/app/serializers/landable/page_revision_serializer.rb +0 -1
- data/app/serializers/landable/page_serializer.rb +5 -5
- data/app/serializers/landable/template_serializer.rb +2 -2
- data/app/services/landable/authentication_service.rb +1 -1
- data/app/services/landable/registration_service.rb +3 -2
- data/app/services/landable/render_service.rb +16 -18
- data/app/services/landable/screenshot_service.rb +3 -4
- data/app/services/landable/tidy_service.rb +32 -37
- data/app/validators/path_validator.rb +1 -3
- data/app/validators/url_validator.rb +4 -7
- data/config/routes.rb +3 -6
- data/db/migrate/20130510221424_create_landable_schema.rb +45 -56
- data/db/migrate/20130909182713_landable_pages__add_updated_by.rb +2 -2
- data/db/migrate/20130909182715_landable_page_revisions__break_out_snapshot.rb +9 -12
- data/db/migrate/20131002220041_file_based_themes.rb +3 -3
- data/db/migrate/20131008164204_create_head_tag_on_page.rb +4 -4
- data/db/migrate/20131008193544_drop_status_codes_model.rb +1 -2
- data/db/migrate/20131028145652_add_traffic_schema.rb +5 -5
- data/db/migrate/20131101213623_add_dnt_column_to_visits.rb +1 -1
- data/db/migrate/20131106185946_add_index_on_page_revisions_path.rb +1 -1
- data/db/migrate/20131106193021_page_revisisons__path_status_code_index.rb +1 -1
- data/db/migrate/20131121150902_add_attribution_id_to_unique_index.rb +2 -2
- data/db/migrate/20131216214027_drop_browser_screenshot_tables.rb +3 -3
- data/db/migrate/20140128170659_file_backed_templates.rb +1 -1
- data/db/migrate/20140205193757_fix_status_codes.rb +3 -3
- data/db/migrate/20140220170324_add_slug_to_categories.rb +1 -1
- data/db/migrate/20140224205516_rename_traffic_schema.rb +7 -9
- data/db/migrate/20140509190128_create_template_revisions.rb +13 -15
- data/db/migrate/20140509192856_create_audits.rb +3 -3
- data/db/migrate/20140602213937_path_response_time_view.rb +20 -19
- data/features/step_definitions/asset_steps.rb +10 -12
- data/features/step_definitions/core_api_steps.rb +29 -27
- data/features/step_definitions/factory_steps.rb +16 -16
- data/features/step_definitions/html_steps.rb +1 -1
- data/features/step_definitions/liquid_steps.rb +8 -8
- data/features/step_definitions/theme_steps.rb +4 -4
- data/features/support/env.rb +5 -5
- data/landable.gemspec +2 -2
- data/lib/generators/landable/landable_generator.rb +2 -2
- data/lib/generators/templates/landable.rb +1 -1
- data/lib/landable.rb +7 -7
- data/lib/landable/configuration.rb +10 -19
- data/lib/landable/engine.rb +19 -19
- data/lib/landable/error.rb +1 -3
- data/lib/landable/layout.rb +6 -6
- data/lib/landable/liquid/asset_tags.rb +3 -5
- data/lib/landable/liquid/drops.rb +3 -8
- data/lib/landable/liquid/filters.rb +1 -3
- data/lib/landable/liquid/tags.rb +10 -10
- data/lib/landable/migration.rb +30 -30
- data/lib/landable/mime_types.rb +1 -1
- data/lib/landable/partial.rb +2 -2
- data/lib/landable/seeds.rb +3 -4
- data/lib/landable/traffic.rb +4 -8
- data/lib/landable/traffic/tracker.rb +48 -43
- data/lib/landable/traffic/user_tracker.rb +15 -10
- data/lib/landable/version.rb +1 -1
- data/lib/schema_moves.rb +15 -16
- data/lib/tasks/landable/cucumber.rake +46 -47
- data/lib/tasks/landable/data.rake +13 -14
- data/lib/tasks/landable/pgtap.rake +12 -18
- data/lib/tasks/landable/seed.rake +4 -4
- data/spec/concerns/landable/has_assets_spec.rb +15 -19
- data/spec/concerns/landable/has_templates_spec.rb +10 -13
- data/spec/concerns/landable/librarian.rb +4 -4
- data/spec/concerns/landable/table_name_spec.rb +3 -5
- data/spec/concerns/landable/traffic/table_name_spec.rb +2 -4
- data/spec/controllers/concerns/landable/variables_concern_spec.rb +11 -10
- data/spec/controllers/landable/api/assets_controller_spec.rb +15 -14
- data/spec/controllers/landable/api/audits_controller_spec.rb +104 -102
- data/spec/controllers/landable/api/categories_controller_spec.rb +36 -34
- data/spec/controllers/landable/api/configuration_controller_spec.rb +14 -12
- data/spec/controllers/landable/api/directories_controller_spec.rb +52 -50
- data/spec/controllers/landable/api/page_revisions_controller_spec.rb +20 -18
- data/spec/controllers/landable/api/pages_controller_spec.rb +204 -203
- data/spec/controllers/landable/api/template_revisions_controller_spec.rb +20 -18
- data/spec/controllers/landable/api/templates_controller_spec.rb +39 -37
- data/spec/controllers/landable/api_controller_spec.rb +24 -26
- data/spec/controllers/public/preview/page_revisions_controller_spec.rb +36 -34
- data/spec/controllers/public/preview/pages_controller_spec.rb +32 -30
- data/spec/controllers/public/sitemap_controller_spec.rb +19 -17
- data/spec/decorators/page_decorator_spec.rb +9 -9
- data/spec/dummy/app/helpers/application_helper.rb +1 -1
- data/spec/dummy/config/application.rb +5 -6
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/config/initializers/landable.rb +7 -6
- data/spec/factories/asset.rb +1 -1
- data/spec/factories/audit.rb +1 -1
- data/spec/factories/authors.rb +1 -1
- data/spec/factories/category.rb +1 -1
- data/spec/factories/pages.rb +4 -4
- data/spec/factories/template.rb +3 -3
- data/spec/factories/theme.rb +2 -2
- data/spec/helpers/pages_helper_spec.rb +5 -5
- data/spec/lib/landable/configuration_spec.rb +2 -4
- data/spec/lib/landable/event_publisher_spec.rb +1 -3
- data/spec/lib/landable/layout_spec.rb +4 -4
- data/spec/lib/landable/liquid_spec.rb +12 -14
- data/spec/lib/landable/migration_spec.rb +4 -4
- data/spec/lib/landable/partial_spec.rb +18 -18
- data/spec/lib/landable/tracking_spec.rb +27 -29
- data/spec/lib/landable/traffic_spec.rb +29 -33
- data/spec/models/landable/access_token_spec.rb +1 -1
- data/spec/models/landable/asset_spec.rb +9 -11
- data/spec/models/landable/directory_spec.rb +7 -7
- data/spec/models/landable/page/errors_spec.rb +1 -3
- data/spec/models/landable/page_revision_spec.rb +23 -24
- data/spec/models/landable/page_spec.rb +41 -42
- data/spec/models/landable/template_revision_spec.rb +3 -3
- data/spec/models/landable/template_spec.rb +11 -11
- data/spec/models/landable/theme_spec.rb +2 -2
- data/spec/models/landable/traffic/referer_spec.rb +3 -3
- data/spec/responders/page_render_responder_spec.rb +0 -2
- data/spec/routing/public_page_route_spec.rb +4 -5
- data/spec/services/landable/authentication_service_spec.rb +7 -7
- data/spec/services/landable/render_service_spec.rb +8 -8
- data/spec/services/landable/screenshot_service_spec.rb +3 -3
- data/spec/services/landable/tidy_service_spec.rb +20 -20
- data/spec/spec_helper.rb +3 -3
- data/spec/support/behaviors.rb +4 -4
- data/spec/support/helpers.rb +1 -1
- metadata +86 -35
- checksums.yaml +0 -7
@@ -1,44 +1,46 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
module Landable
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
36
|
+
it 'returns all categories' do
|
37
|
+
Landable::Category.delete_all
|
38
|
+
create_list :category, 5
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
4
|
-
|
5
|
-
|
3
|
+
module Landable
|
4
|
+
module Api
|
5
|
+
describe ConfigurationsController, json: true do
|
6
|
+
routes { Landable::Engine.routes }
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
describe '#show' do
|
9
|
+
include_examples 'Authenticated API controller', :make_request
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def make_request
|
12
|
+
get :show
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
4
|
-
|
5
|
-
|
3
|
+
module Landable
|
4
|
+
module Api
|
5
|
+
describe PageRevisionsController, json: true do
|
6
|
+
routes { Landable::Engine.routes }
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
describe '#index' do
|
9
|
+
include_examples 'Authenticated API controller', :make_request
|
9
10
|
|
10
|
-
|
11
|
+
let(:page) { create :page }
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def make_request(page_id = page.id)
|
14
|
+
get :index, page_id: page_id
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
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
|
4
|
-
|
5
|
-
|
3
|
+
module Landable
|
4
|
+
module Api
|
5
|
+
describe PagesController, json: true do
|
6
|
+
routes { Landable::Engine.routes }
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
describe '#create' do
|
9
|
+
include_examples 'Authenticated API controller', :make_request
|
9
10
|
|
10
|
-
|
11
|
-
|
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
|
-
|
29
|
-
|
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
|
-
|
34
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
54
|
-
|
54
|
+
describe '#index' do
|
55
|
+
include_examples 'Authenticated API controller', :make_request
|
55
56
|
|
56
|
-
|
57
|
-
|
57
|
+
let(:pages) { @pages ||= create_list(:page, 5) }
|
58
|
+
before(:each) { pages }
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
def make_request(params = {})
|
61
|
+
get :index, params
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
69
|
-
|
69
|
+
it 'filters pages according to requested ids' do
|
70
|
+
filtered_for_pages = pages[0..2]
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
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
|
-
|
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
|
-
|
105
|
-
|
106
|
-
|
105
|
+
describe '#show' do
|
106
|
+
include_examples 'Authenticated API controller', :make_request
|
107
|
+
let(:page) { @page || create(:page) }
|
107
108
|
|
108
|
-
|
109
|
-
|
110
|
-
|
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
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
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
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
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
|
-
|
136
|
-
|
137
|
-
{ page: { body: 'Different body content' } }
|
138
|
-
end
|
132
|
+
describe '#update' do
|
133
|
+
include_examples 'Authenticated API controller', :make_request
|
139
134
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
135
|
+
let(:page) { @page || create(:page) }
|
136
|
+
let(:default_params) do
|
137
|
+
{ page: { body: 'Different body content' } }
|
138
|
+
end
|
144
139
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
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
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
-
|
158
|
-
|
159
|
-
|
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
|
-
|
164
|
-
|
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
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
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
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
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
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
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
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
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
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
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
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
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
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
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
|
-
|
222
|
-
|
223
|
-
|
221
|
+
describe '#preview', json: false do
|
222
|
+
include_examples 'Authenticated API controller', :make_request
|
223
|
+
render_views
|
224
224
|
|
225
|
-
|
225
|
+
let(:theme) { create :theme, body: '<html><head>{% head_content %}</head><body>Theme content; page content: {{body}}</body></html>' }
|
226
226
|
|
227
|
-
|
228
|
-
|
229
|
-
|
227
|
+
before do
|
228
|
+
request.env['HTTP_ACCEPT'] = 'text/html'
|
229
|
+
end
|
230
230
|
|
231
|
-
|
232
|
-
|
233
|
-
|
231
|
+
def make_request(attributes = attributes_for(:page, theme_id: theme.id))
|
232
|
+
post :preview, page: attributes
|
233
|
+
end
|
234
234
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
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
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
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
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
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
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
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
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
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
|