locomotivecms 3.0.0.pre.beta.1 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -3
- data/app/api/locomotive/api.rb +1 -0
- data/app/api/locomotive/api/entities/page_entity.rb +1 -1
- data/app/api/locomotive/api/entities/site_entity.rb +9 -1
- data/app/api/locomotive/api/exception_rescuers.rb +3 -5
- data/app/api/locomotive/api/forms/page_form.rb +1 -1
- data/app/api/locomotive/api/forms/site_form.rb +1 -2
- data/app/api/locomotive/api/helpers/authentication_helper.rb +6 -1
- data/app/api/locomotive/api/helpers/locales_helper.rb +15 -0
- data/app/api/locomotive/api/helpers/params_helper.rb +13 -0
- data/app/api/locomotive/api/middlewares/locale_middleware.rb +6 -1
- data/app/api/locomotive/api/resources/content_entry_resource.rb +2 -0
- data/app/api/locomotive/api/resources/content_type_resource.rb +2 -2
- data/app/api/locomotive/api/resources/current_site_resource.rb +2 -1
- data/app/api/locomotive/api/resources/membership_resource.rb +0 -4
- data/app/api/locomotive/api/resources/page_resource.rb +6 -1
- data/app/api/locomotive/api/resources/site_resource.rb +4 -2
- data/app/assets/javascripts/locomotive.js +1 -0
- data/app/assets/javascripts/locomotive/utils/nprogress.js.coffee +3 -1
- data/app/assets/javascripts/locomotive/views/editable_elements/index_view.js.coffee +10 -3
- data/app/assets/javascripts/locomotive/views/inputs/markdown_view.js.coffee +82 -0
- data/app/assets/javascripts/locomotive/views/inputs/rte/file_view.js.coffee +1 -1
- data/app/assets/javascripts/locomotive/views/inputs/rte/link_view.js.coffee +1 -1
- data/app/assets/javascripts/locomotive/views/inputs/rte_view.js.coffee.erb +1 -1
- data/app/assets/javascripts/locomotive/views/inputs/text_view.js.coffee +4 -1
- data/app/assets/javascripts/locomotive/views/pages/list_view.js.coffee +3 -0
- data/app/assets/javascripts/locomotive/views/shared/form_view.js.coffee +22 -1
- data/app/assets/javascripts/locomotive/views/shared/header_view.js.coffee +2 -2
- data/app/assets/stylesheets/locomotive/application.scss +2 -0
- data/app/assets/stylesheets/locomotive/base/_form.scss +2 -0
- data/app/assets/stylesheets/locomotive/base/form/_api_key.scss +0 -1
- data/app/assets/stylesheets/locomotive/base/form/_array_input.scss +2 -0
- data/app/assets/stylesheets/locomotive/base/form/_base.scss +13 -2
- data/app/assets/stylesheets/locomotive/base/form/_color_input.scss +12 -0
- data/app/assets/stylesheets/locomotive/base/form/_markdown.scss +292 -0
- data/app/assets/stylesheets/locomotive/base/form/_popover.scss +22 -0
- data/app/assets/stylesheets/locomotive/base/form/_rte.scss +2 -1
- data/app/assets/stylesheets/locomotive/components/_activity_feed.scss +1 -0
- data/app/assets/stylesheets/locomotive/components/_dashboard.scss +29 -0
- data/app/assets/stylesheets/locomotive/components/_live_editing.scss +13 -1
- data/app/assets/stylesheets/locomotive/components/_main.scss +1 -1
- data/app/assets/stylesheets/locomotive/components/_transitions.scss +24 -3
- data/app/assets/stylesheets/locomotive/components/sidebar/_base.scss +1 -0
- data/app/assets/stylesheets/locomotive/globals/_bootstrap.scss +2 -2
- data/app/assets/stylesheets/locomotive/globals/_variables.scss +4 -3
- data/app/assets/stylesheets/locomotive/layouts/_live_editing.scss +4 -0
- data/app/controllers/locomotive/concerns/locale_helpers_controller.rb +1 -0
- data/app/controllers/locomotive/content_entries_controller.rb +10 -2
- data/app/controllers/locomotive/pages_controller.rb +2 -1
- data/app/controllers/locomotive/passwords_controller.rb +17 -1
- data/app/helpers/locomotive/base_helper.rb +19 -0
- data/app/helpers/locomotive/content_types_helper.rb +2 -1
- data/app/helpers/locomotive/custom_fields_helper.rb +14 -1
- data/app/helpers/locomotive/dashboard_helper.rb +12 -0
- data/app/helpers/locomotive/editable_elements_helper.rb +9 -4
- data/app/helpers/locomotive/pages_helper.rb +1 -14
- data/app/helpers/locomotive/shared/pages_helper.rb +17 -0
- data/app/helpers/locomotive/translations_helper.rb +0 -14
- data/app/inputs/locomotive/color_input.rb +18 -0
- data/app/inputs/locomotive/markdown_input.rb +19 -0
- data/app/models/locomotive/account.rb +2 -1
- data/app/models/locomotive/concerns/content_entry/file_size.rb +27 -0
- data/app/models/locomotive/concerns/content_type/group_by.rb +3 -1
- data/app/models/locomotive/concerns/page/layout.rb +63 -19
- data/app/models/locomotive/concerns/shared/site_scope.rb +37 -0
- data/app/models/locomotive/concerns/site/cache.rb +32 -0
- data/app/models/locomotive/concerns/theme_asset/plain_text.rb +85 -0
- data/app/models/locomotive/content_entry.rb +7 -7
- data/app/models/locomotive/content_type.rb +12 -6
- data/app/models/locomotive/page.rb +12 -14
- data/app/models/locomotive/site.rb +9 -3
- data/app/models/locomotive/snippet.rb +6 -4
- data/app/models/locomotive/theme_asset.rb +8 -73
- data/app/models/locomotive/translation.rb +6 -5
- data/app/policies/locomotive/site_policy.rb +2 -2
- data/app/services/locomotive/content_entry_service.rb +7 -6
- data/app/services/locomotive/site_service.rb +1 -0
- data/app/views/locomotive/content_entries/_entry.html.slim +1 -0
- data/app/views/locomotive/content_entries/edit.html.slim +1 -1
- data/app/views/locomotive/content_entries/new.html.slim +1 -1
- data/app/views/locomotive/current_site/_membership.html.slim +1 -0
- data/app/views/locomotive/current_site/edit.html.slim +1 -1
- data/app/views/locomotive/current_site/form/_access_points.html.slim +1 -1
- data/app/views/locomotive/current_site/form/_advanced.html.slim +2 -0
- data/app/views/locomotive/dashboard/_activity.html.slim +26 -0
- data/app/views/locomotive/dashboard/_url.html.slim +9 -0
- data/app/views/locomotive/dashboard/show.html.slim +3 -21
- data/app/views/locomotive/devise_mailer/reset_password_instructions.html.slim +1 -1
- data/app/views/locomotive/editable_elements/_edit.html.slim +8 -1
- data/app/views/locomotive/editable_elements/_form.html.slim +1 -1
- data/app/views/locomotive/editable_elements/index_without_preview.html.slim +24 -17
- data/app/views/locomotive/layouts/application.html.slim +6 -4
- data/app/views/locomotive/layouts/live_editing.html.slim +9 -0
- data/app/views/locomotive/layouts/not_logged_in.html.slim +1 -1
- data/app/views/locomotive/layouts/without_site.html.slim +2 -0
- data/app/views/locomotive/memberships/edit.html.slim +1 -1
- data/app/views/locomotive/memberships/new.html.slim +1 -1
- data/app/views/locomotive/my_account/edit.html.slim +7 -5
- data/app/views/locomotive/pages/_header.html.slim +7 -0
- data/app/views/locomotive/pages/edit.html.slim +2 -4
- data/app/views/locomotive/pages/form/_main.html.slim +4 -1
- data/app/views/locomotive/pages/form/_tabs.html.slim +4 -3
- data/app/views/locomotive/public_submission_accounts/_account.html.slim +1 -1
- data/app/views/locomotive/public_submission_accounts/edit.html.slim +1 -1
- data/app/views/locomotive/shared/_header.html.slim +25 -22
- data/app/views/locomotive/shared/_locale_picker_link.html.slim +3 -0
- data/app/views/locomotive/shared/_main_app_header.html.slim +1 -1
- data/app/views/locomotive/shared/_sidebar.html.slim +15 -11
- data/app/views/locomotive/shared/rte/_markdown_toolbar.html.slim +42 -0
- data/config/locales/admin_ui.en.yml +9 -4
- data/config/locales/default.en.yml +4 -0
- data/config/locales/devise.en.yml +1 -0
- data/config/locales/simple_form.en.yml +6 -2
- data/lib/locomotive/action_controller/responder.rb +5 -0
- data/lib/locomotive/engine.rb +5 -0
- data/lib/locomotive/middlewares/site.rb +39 -21
- data/lib/locomotive/simple_form.rb +3 -31
- data/lib/locomotive/steam/middlewares/cache.rb +62 -0
- data/lib/locomotive/steam/middlewares/page_editing.rb +9 -3
- data/lib/locomotive/steam/services/api_entry_submission_service.rb +6 -3
- data/lib/locomotive/steam/services/liquid_parser_with_cache_service.rb +74 -0
- data/lib/locomotive/steam_adaptor.rb +7 -1
- data/lib/locomotive/version.rb +1 -1
- data/lib/tasks/development.rake +4 -0
- data/lib/tasks/locomotive.rake +14 -0
- data/spec/lib/locomotive/steam/services/api_entry_submission_service_spec.rb +10 -1
- data/spec/lib/locomotive/steam/services/liquid_parser_with_cache_service_spec.rb +53 -0
- data/spec/models/locomotive/concerns/content_entry/file_size_spec.rb +40 -0
- data/spec/models/locomotive/concerns/page/layout_spec.rb +122 -17
- data/spec/models/locomotive/concerns/site/cache_spec.rb +60 -0
- data/spec/models/locomotive/content_entry_spec.rb +7 -0
- data/spec/models/locomotive/content_type_spec.rb +18 -11
- data/spec/models/locomotive/page_spec.rb +32 -8
- data/spec/models/locomotive/snippet_spec.rb +13 -4
- data/spec/models/locomotive/theme_asset_spec.rb +10 -3
- data/spec/models/locomotive/translation_spec.rb +28 -0
- data/spec/requests/locomotive/steam/cache_spec.rb +83 -0
- data/spec/requests/site_spec.rb +24 -0
- data/spec/support/capybara.rb +5 -13
- data/spec/support/factories.rb +9 -0
- data/spec/support/features/session_helpers.rb +19 -3
- data/spec/support/features/site_helpers.rb +27 -0
- data/spec/support/shared_examples/site_scope_examples.rb +27 -0
- data/vendor/assets/images/locomotive/bootstrap-colorpicker/alpha-horizontal.png +0 -0
- data/vendor/assets/images/locomotive/bootstrap-colorpicker/alpha.png +0 -0
- data/vendor/assets/images/locomotive/bootstrap-colorpicker/hue-horizontal.png +0 -0
- data/vendor/assets/images/locomotive/bootstrap-colorpicker/hue.png +0 -0
- data/vendor/assets/images/locomotive/bootstrap-colorpicker/saturation.png +0 -0
- data/vendor/assets/javascripts/locomotive/bootstrap-colorpicker.js +1 -0
- data/vendor/assets/javascripts/locomotive/datepicker_i18n.js.erb +6 -6
- data/vendor/assets/javascripts/locomotive/kramed.min.js +11 -0
- data/vendor/assets/stylesheets/locomotive/bootstrap-colorpicker.scss +9 -0
- metadata +59 -44
- data/app/controllers/locomotive/api/accounts_controller.rb +0 -60
- data/app/controllers/locomotive/api/base_controller.rb +0 -35
- data/app/controllers/locomotive/api/content_assets_controller.rb +0 -51
- data/app/controllers/locomotive/api/content_entries_controller.rb +0 -71
- data/app/controllers/locomotive/api/content_types_controller.rb +0 -52
- data/app/controllers/locomotive/api/current_site_controller.rb +0 -34
- data/app/controllers/locomotive/api/memberships_controller.rb +0 -52
- data/app/controllers/locomotive/api/my_account_controller.rb +0 -46
- data/app/controllers/locomotive/api/pages_controller.rb +0 -53
- data/app/controllers/locomotive/api/sites_controller.rb +0 -58
- data/app/controllers/locomotive/api/snippets_controller.rb +0 -52
- data/app/controllers/locomotive/api/theme_assets_controller.rb +0 -51
- data/app/controllers/locomotive/api/tokens_controller.rb +0 -36
- data/app/controllers/locomotive/api/translations_controller.rb +0 -51
- data/app/controllers/locomotive/api/version_controller.rb +0 -11
- data/spec/models/locomotive/editable_control_spec.rb +0 -79
- data/spec/models/locomotive/editable_file_spec.rb +0 -94
- data/spec/models/locomotive/editable_text_spec.rb +0 -219
- data/vendor/assets/images/select2-spinner.gif +0 -0
- data/vendor/assets/images/select2.png +0 -0
- data/vendor/assets/images/select2x2.png +0 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Locomotive::Concerns::Site::Cache do
|
4
|
+
|
5
|
+
let(:enabled) { false }
|
6
|
+
let(:site) { build(:site, cache_enabled: enabled) }
|
7
|
+
|
8
|
+
describe '#last_modified_at' do
|
9
|
+
|
10
|
+
subject { site.last_modified_at }
|
11
|
+
|
12
|
+
it { is_expected.to eq nil }
|
13
|
+
|
14
|
+
context 'only updated_at is defined' do
|
15
|
+
|
16
|
+
let(:site) { build(:site, updated_at: DateTime.parse('2015/10/16 00:00:00')) }
|
17
|
+
it { is_expected.to eq DateTime.parse('2015/10/16 00:00:00') }
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'template_version or content_version are defined' do
|
22
|
+
|
23
|
+
let(:site) { build(:site, updated_at: DateTime.parse('2015/10/16 00:00:00'), template_version: DateTime.parse('2007/06/29 00:00:00'), content_version: DateTime.parse('2009/09/10 00:00:00')) }
|
24
|
+
it { is_expected.to eq DateTime.parse('2009/09/10 00:00:00') }
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#cache_enabled?' do
|
31
|
+
|
32
|
+
subject { site.cache_enabled? }
|
33
|
+
|
34
|
+
it { expect(subject).to eq false }
|
35
|
+
|
36
|
+
context 'cache enabled' do
|
37
|
+
|
38
|
+
let(:enabled) { true }
|
39
|
+
it { expect(subject).to eq true }
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#save' do
|
46
|
+
|
47
|
+
let(:date) { Time.zone.local(2015, 4, 1, 12, 0, 0) }
|
48
|
+
|
49
|
+
before { site.save }
|
50
|
+
|
51
|
+
it 'bumps content_version' do
|
52
|
+
site.name = 'New name'
|
53
|
+
Timecop.freeze(date) do
|
54
|
+
expect { site.save! }.to change { site.content_version }.to date
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -388,6 +388,13 @@ describe Locomotive::ContentEntry do
|
|
388
388
|
|
389
389
|
end
|
390
390
|
|
391
|
+
it_should_behave_like 'model scoped by a site' do
|
392
|
+
|
393
|
+
let(:model) { build_content_entry }
|
394
|
+
let(:attribute) { :content_version }
|
395
|
+
|
396
|
+
end
|
397
|
+
|
391
398
|
def localize_content_type(content_type)
|
392
399
|
content_type.entries_custom_fields.first.localized = true
|
393
400
|
content_type.save
|
@@ -9,7 +9,7 @@ describe Locomotive::ContentType do
|
|
9
9
|
context 'when validating' do
|
10
10
|
|
11
11
|
it 'haves a valid factory' do
|
12
|
-
content_type =
|
12
|
+
content_type = build(:content_type)
|
13
13
|
content_type.entries_custom_fields.build label: 'anything', type: 'string'
|
14
14
|
expect(content_type).to be_valid
|
15
15
|
end
|
@@ -18,36 +18,36 @@ describe Locomotive::ContentType do
|
|
18
18
|
|
19
19
|
%w{site name}.each do |field|
|
20
20
|
it "requires the presence of #{field}" do
|
21
|
-
content_type =
|
21
|
+
content_type = build(:content_type, field.to_sym => nil)
|
22
22
|
expect(content_type).to_not be_valid
|
23
23
|
expect(content_type.errors[field.to_sym]).to eq(["can't be blank"])
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'requires the presence of slug' do
|
28
|
-
content_type =
|
28
|
+
content_type = build(:content_type, name: nil, slug: nil)
|
29
29
|
expect(content_type).to_not be_valid
|
30
30
|
expect(content_type.errors[:slug]).to eq(["can't be blank"])
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'is not valid if slug is not unique' do
|
34
|
-
content_type =
|
34
|
+
content_type = build(:content_type)
|
35
35
|
content_type.entries_custom_fields.build label: 'anything', type: 'string'
|
36
36
|
content_type.save
|
37
|
-
content_type =
|
37
|
+
content_type = build(:content_type, site: content_type.site, slug: content_type.slug)
|
38
38
|
expect(content_type).to_not be_valid
|
39
39
|
expect(content_type.errors[:slug]).to eq(["is already taken"])
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'is not valid if there is not at least one field' do
|
43
|
-
content_type =
|
43
|
+
content_type = build(:content_type)
|
44
44
|
expect(content_type).to_not be_valid
|
45
45
|
expect(content_type.errors[:entries_custom_fields]).to eq({ base: ['At least, one custom field is required'] })
|
46
46
|
end
|
47
47
|
|
48
48
|
%w(created_at updated_at).each do |name|
|
49
49
|
it "does not allow #{name} as name" do
|
50
|
-
content_type =
|
50
|
+
content_type = build(:content_type)
|
51
51
|
field = content_type.entries_custom_fields.build label: 'anything', type: 'string', name: name
|
52
52
|
expect(field.valid?).to eq(false)
|
53
53
|
expect(field.errors[:name]).to eq(['is reserved'])
|
@@ -55,13 +55,13 @@ describe Locomotive::ContentType do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'sets a slug from the name before the validation' do
|
58
|
-
content_type =
|
58
|
+
content_type = build(:content_type, name: 'my content Type')
|
59
59
|
content_type.valid?
|
60
60
|
expect(content_type.slug).to match(/slug_of_content_type_/)
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'make sure the slug is correctly set before the validation' do
|
64
|
-
content_type =
|
64
|
+
content_type = build(:content_type, slug: 'my content-type')
|
65
65
|
content_type.valid?
|
66
66
|
expect(content_type.slug).to eq('my_content_type')
|
67
67
|
end
|
@@ -177,7 +177,7 @@ describe Locomotive::ContentType do
|
|
177
177
|
describe 'custom fields' do
|
178
178
|
|
179
179
|
before(:each) do
|
180
|
-
site =
|
180
|
+
site = build(:site)
|
181
181
|
allow(Locomotive::Site).to receive(:find).and_return(site)
|
182
182
|
|
183
183
|
@content_type = build_content_type(site: site)
|
@@ -361,8 +361,15 @@ describe Locomotive::ContentType do
|
|
361
361
|
|
362
362
|
end
|
363
363
|
|
364
|
+
it_should_behave_like 'model scoped by a site' do
|
365
|
+
|
366
|
+
let(:model) { build_content_type(slug: 'my_project') }
|
367
|
+
let(:attribute) { :content_version }
|
368
|
+
|
369
|
+
end
|
370
|
+
|
364
371
|
def build_content_type(options = {}, &block)
|
365
|
-
|
372
|
+
build(:content_type, options).tap do |content_type|
|
366
373
|
content_type.entries_custom_fields.build label: 'Name', type: 'string'
|
367
374
|
content_type.entries_custom_fields.build label: 'Description', type: 'text'
|
368
375
|
content_type.entries_custom_fields.build label: 'Active', type: 'boolean'
|
@@ -15,12 +15,16 @@ describe Locomotive::Page do
|
|
15
15
|
|
16
16
|
describe 'validation' do
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
it 'requires the presence of a site' do
|
19
|
+
page = build(:page, site: nil)
|
20
|
+
expect(page).to_not be_valid
|
21
|
+
expect(page.errors[:site]).to eq(["can't be blank"])
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'requires the presence of a title' do
|
25
|
+
page = build(:page, title: nil, site: build(:site))
|
26
|
+
expect(page).to_not be_valid
|
27
|
+
expect(page.errors[:title]).to eq(["can't be blank"])
|
24
28
|
end
|
25
29
|
|
26
30
|
it 'requires the presence of the slug' do
|
@@ -121,9 +125,9 @@ describe Locomotive::Page do
|
|
121
125
|
expect(page.slug).to eq('convention_valid_ite_dot_html')
|
122
126
|
end
|
123
127
|
|
124
|
-
it 'has
|
128
|
+
it 'has cache enabled' do
|
125
129
|
page = build(:page, site: nil)
|
126
|
-
expect(page.
|
130
|
+
expect(page.cache_enabled?).to eq(true)
|
127
131
|
end
|
128
132
|
|
129
133
|
end
|
@@ -427,6 +431,26 @@ describe Locomotive::Page do
|
|
427
431
|
|
428
432
|
end
|
429
433
|
|
434
|
+
it_should_behave_like 'model scoped by a site' do
|
435
|
+
|
436
|
+
let(:model) { create(:page) }
|
437
|
+
let(:attribute) { :content_version }
|
438
|
+
|
439
|
+
describe 'the raw_template has been modified' do
|
440
|
+
|
441
|
+
let(:date) { Time.zone.local(2015, 4, 1, 12, 0, 0) }
|
442
|
+
|
443
|
+
it 'updates the template_version attribute of the site' do
|
444
|
+
model.raw_template = 'new one'
|
445
|
+
Timecop.freeze(date) do
|
446
|
+
expect { model.save! }.to change { site.template_version }.to date
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
450
|
+
end
|
451
|
+
|
452
|
+
end
|
453
|
+
|
430
454
|
class Foo
|
431
455
|
end
|
432
456
|
|
@@ -2,18 +2,27 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Locomotive::Snippet do
|
4
4
|
|
5
|
+
let(:snippet) { build(:snippet) }
|
6
|
+
|
5
7
|
it 'has a valid factory' do
|
6
|
-
expect(
|
8
|
+
expect(snippet).to be_valid
|
7
9
|
end
|
8
10
|
|
9
11
|
# Validations ##
|
10
12
|
|
11
13
|
%w{site name template}.each do |field|
|
12
14
|
it "validates presence of #{field}" do
|
13
|
-
|
14
|
-
expect(
|
15
|
-
expect(
|
15
|
+
snippet.send(:"#{field}=", nil)
|
16
|
+
expect(snippet).to_not be_valid
|
17
|
+
expect(snippet.errors[field.to_sym].first).to eq("can't be blank")
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
21
|
+
it_should_behave_like 'model scoped by a site' do
|
22
|
+
|
23
|
+
let(:model) { snippet }
|
24
|
+
let(:attribute) { :template_version }
|
25
|
+
|
26
|
+
end
|
27
|
+
|
19
28
|
end
|
@@ -4,9 +4,9 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe Locomotive::ThemeAsset do
|
6
6
|
|
7
|
-
let(:site)
|
8
|
-
|
9
|
-
let(:asset)
|
7
|
+
let(:site) { build(:site, domains: %w{www.acme.com}) }
|
8
|
+
let(:source) { nil }
|
9
|
+
let(:asset) { build(:theme_asset, site: site, source: source, updated_at: DateTime.parse('2007/06/29 21:10:00')) }
|
10
10
|
|
11
11
|
describe 'attaching a file' do
|
12
12
|
|
@@ -165,4 +165,11 @@ describe Locomotive::ThemeAsset do
|
|
165
165
|
|
166
166
|
end
|
167
167
|
|
168
|
+
it_should_behave_like 'model scoped by a site' do
|
169
|
+
|
170
|
+
let(:model) { build(:theme_asset, source: FixturedAsset.open('5k.png')) }
|
171
|
+
let(:attribute) { :template_version }
|
172
|
+
|
173
|
+
end
|
174
|
+
|
168
175
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Locomotive::Translation do
|
4
|
+
|
5
|
+
let(:translation) { build(:translation) }
|
6
|
+
|
7
|
+
it 'has a valid factory' do
|
8
|
+
expect(translation).to be_valid
|
9
|
+
end
|
10
|
+
|
11
|
+
# Validations ##
|
12
|
+
|
13
|
+
%w{site key}.each do |field|
|
14
|
+
it "validates presence of #{field}" do
|
15
|
+
translation.send(:"#{field}=", nil)
|
16
|
+
expect(translation).to_not be_valid
|
17
|
+
expect(translation.errors[field.to_sym].first).to eq("can't be blank")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it_should_behave_like 'model scoped by a site' do
|
22
|
+
|
23
|
+
let(:model) { translation }
|
24
|
+
let(:attribute) { :content_version }
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Locomotive::Middlewares::Site' do
|
4
|
+
|
5
|
+
let(:site_cache) { false }
|
6
|
+
let(:page_cache) { false }
|
7
|
+
let(:site) { instance_double('CacheSite', _id: '0001', cache_enabled: site_cache, last_modified_at: DateTime.parse('2007/06/29 00:00:00')) }
|
8
|
+
let(:page) { instance_double('CachedPage', _id: '0042', cache_enabled: page_cache) }
|
9
|
+
let(:app) { ->(env) { [200, env, 'app'] } }
|
10
|
+
let(:middleware) { Locomotive::Steam::Middlewares::Cache.new(app) }
|
11
|
+
let(:steam_env) { { 'REQUEST_METHOD' => 'GET', 'steam.site' => site, 'steam.page' => page, 'steam.live_editing' => false, 'PATH_INFO' => 'foo', 'QUERY_STRING' => 'a=1&c=3' } }
|
12
|
+
|
13
|
+
describe '#call' do
|
14
|
+
|
15
|
+
subject { middleware.call(env_for('foo', steam_env)) }
|
16
|
+
|
17
|
+
it { expect(subject.first).to eq 200 }
|
18
|
+
|
19
|
+
context 'cache enabled' do
|
20
|
+
|
21
|
+
before(:each) { Rails.cache.clear }
|
22
|
+
|
23
|
+
let(:site_cache) { true }
|
24
|
+
let(:page_cache) { true }
|
25
|
+
|
26
|
+
it { expect(subject.first).to eq 200 }
|
27
|
+
|
28
|
+
it 'does not go to the next middleware' do
|
29
|
+
middleware.call(env_for('foo', steam_env)) # warm up the cache
|
30
|
+
expect(middleware.app).not_to receive(:call)
|
31
|
+
expect(subject.first).to eq 200
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#cache_key' do
|
39
|
+
|
40
|
+
subject { middleware.send(:cache_key, steam_env) }
|
41
|
+
|
42
|
+
it { expect(subject).to eq '559d95fa56a4a72adec091412f5542df' }
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#cacheable?' do
|
47
|
+
|
48
|
+
subject { middleware.send(:cacheable?, steam_env) }
|
49
|
+
|
50
|
+
let(:live_editing) { true }
|
51
|
+
it { expect(subject).to eq false }
|
52
|
+
|
53
|
+
context 'live editing off' do
|
54
|
+
|
55
|
+
let(:live_editing) { false }
|
56
|
+
it { expect(subject).to eq false }
|
57
|
+
|
58
|
+
context 'cache enabled for site' do
|
59
|
+
|
60
|
+
let(:site_cache) { true }
|
61
|
+
it { expect(subject).to eq false }
|
62
|
+
|
63
|
+
context 'cache enabled for page' do
|
64
|
+
|
65
|
+
let(:page_cache) { true }
|
66
|
+
it { expect(subject).to eq true }
|
67
|
+
|
68
|
+
context 'POST method' do
|
69
|
+
|
70
|
+
let(:steam_env) { { 'REQUEST_METHOD' => 'POST', 'steam.site' => site, 'steam.page' => page, 'steam.live_editing' => false, 'PATH_INFO' => 'foo' } }
|
71
|
+
it { expect(subject).to eq false }
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
data/spec/requests/site_spec.rb
CHANGED
@@ -15,6 +15,30 @@ describe 'Locomotive::Middlewares::Site' do
|
|
15
15
|
|
16
16
|
end
|
17
17
|
|
18
|
+
describe 'requesting the back-office assets' do
|
19
|
+
|
20
|
+
before { site }
|
21
|
+
before { allow(middleware).to receive(:default_host).and_return('steve.me') }
|
22
|
+
|
23
|
+
let(:url) { 'http://steve.me/assets/foo.png' }
|
24
|
+
it { is_expected.to eq(nil) }
|
25
|
+
|
26
|
+
context 'localhost' do
|
27
|
+
|
28
|
+
let(:url) { 'http://localhost/assets/foo.png' }
|
29
|
+
it { is_expected.to eq(nil) }
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
context '0.0.0.0' do
|
34
|
+
|
35
|
+
let(:url) { 'http://0.0.0.0/assets/foo.png' }
|
36
|
+
it { is_expected.to eq(nil) }
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
18
42
|
describe 'the requested site is also the default host' do
|
19
43
|
|
20
44
|
before { site }
|
data/spec/support/capybara.rb
CHANGED
@@ -1,25 +1,17 @@
|
|
1
|
-
def ensure_host_resolution(app_host)
|
2
|
-
hosts = Resolv::Hosts.new
|
3
|
-
app_host_name = URI.parse(app_host).host
|
4
|
-
begin
|
5
|
-
hosts.getaddress(app_host_name)
|
6
|
-
rescue Resolv::ResolvError
|
7
|
-
raise "Unable to resolve ip address for #{app_host_name}. Please consider adding an entry to '/etc/hosts' that associates #{app_host_name} with '127.0.0.1'."
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
1
|
Capybara.configure do |config|
|
12
2
|
config.default_selector = :css
|
13
3
|
config.server_port = 9886
|
14
|
-
config.app_host = 'http://
|
15
|
-
|
16
|
-
ensure_host_resolution(config.app_host)
|
4
|
+
config.app_host = 'http://localhost:9886'
|
17
5
|
end
|
18
6
|
|
19
7
|
Capybara.default_wait_time = 5
|
20
8
|
|
21
9
|
Capybara.javascript_driver = :poltergeist
|
22
10
|
|
11
|
+
Capybara.register_driver :poltergeist do |app|
|
12
|
+
Capybara::Poltergeist::Driver.new(app, timeout: 60)
|
13
|
+
end
|
14
|
+
|
23
15
|
# Stop endless errors like
|
24
16
|
# ~/.rvm/gems/ruby-1.9.2-p0@global/gems/rack-1.2.1/lib/rack/utils.rb:16:
|
25
17
|
# warning: regexp match /.../n against to UTF-8 string
|