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.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -3
  3. data/app/api/locomotive/api.rb +1 -0
  4. data/app/api/locomotive/api/entities/page_entity.rb +1 -1
  5. data/app/api/locomotive/api/entities/site_entity.rb +9 -1
  6. data/app/api/locomotive/api/exception_rescuers.rb +3 -5
  7. data/app/api/locomotive/api/forms/page_form.rb +1 -1
  8. data/app/api/locomotive/api/forms/site_form.rb +1 -2
  9. data/app/api/locomotive/api/helpers/authentication_helper.rb +6 -1
  10. data/app/api/locomotive/api/helpers/locales_helper.rb +15 -0
  11. data/app/api/locomotive/api/helpers/params_helper.rb +13 -0
  12. data/app/api/locomotive/api/middlewares/locale_middleware.rb +6 -1
  13. data/app/api/locomotive/api/resources/content_entry_resource.rb +2 -0
  14. data/app/api/locomotive/api/resources/content_type_resource.rb +2 -2
  15. data/app/api/locomotive/api/resources/current_site_resource.rb +2 -1
  16. data/app/api/locomotive/api/resources/membership_resource.rb +0 -4
  17. data/app/api/locomotive/api/resources/page_resource.rb +6 -1
  18. data/app/api/locomotive/api/resources/site_resource.rb +4 -2
  19. data/app/assets/javascripts/locomotive.js +1 -0
  20. data/app/assets/javascripts/locomotive/utils/nprogress.js.coffee +3 -1
  21. data/app/assets/javascripts/locomotive/views/editable_elements/index_view.js.coffee +10 -3
  22. data/app/assets/javascripts/locomotive/views/inputs/markdown_view.js.coffee +82 -0
  23. data/app/assets/javascripts/locomotive/views/inputs/rte/file_view.js.coffee +1 -1
  24. data/app/assets/javascripts/locomotive/views/inputs/rte/link_view.js.coffee +1 -1
  25. data/app/assets/javascripts/locomotive/views/inputs/rte_view.js.coffee.erb +1 -1
  26. data/app/assets/javascripts/locomotive/views/inputs/text_view.js.coffee +4 -1
  27. data/app/assets/javascripts/locomotive/views/pages/list_view.js.coffee +3 -0
  28. data/app/assets/javascripts/locomotive/views/shared/form_view.js.coffee +22 -1
  29. data/app/assets/javascripts/locomotive/views/shared/header_view.js.coffee +2 -2
  30. data/app/assets/stylesheets/locomotive/application.scss +2 -0
  31. data/app/assets/stylesheets/locomotive/base/_form.scss +2 -0
  32. data/app/assets/stylesheets/locomotive/base/form/_api_key.scss +0 -1
  33. data/app/assets/stylesheets/locomotive/base/form/_array_input.scss +2 -0
  34. data/app/assets/stylesheets/locomotive/base/form/_base.scss +13 -2
  35. data/app/assets/stylesheets/locomotive/base/form/_color_input.scss +12 -0
  36. data/app/assets/stylesheets/locomotive/base/form/_markdown.scss +292 -0
  37. data/app/assets/stylesheets/locomotive/base/form/_popover.scss +22 -0
  38. data/app/assets/stylesheets/locomotive/base/form/_rte.scss +2 -1
  39. data/app/assets/stylesheets/locomotive/components/_activity_feed.scss +1 -0
  40. data/app/assets/stylesheets/locomotive/components/_dashboard.scss +29 -0
  41. data/app/assets/stylesheets/locomotive/components/_live_editing.scss +13 -1
  42. data/app/assets/stylesheets/locomotive/components/_main.scss +1 -1
  43. data/app/assets/stylesheets/locomotive/components/_transitions.scss +24 -3
  44. data/app/assets/stylesheets/locomotive/components/sidebar/_base.scss +1 -0
  45. data/app/assets/stylesheets/locomotive/globals/_bootstrap.scss +2 -2
  46. data/app/assets/stylesheets/locomotive/globals/_variables.scss +4 -3
  47. data/app/assets/stylesheets/locomotive/layouts/_live_editing.scss +4 -0
  48. data/app/controllers/locomotive/concerns/locale_helpers_controller.rb +1 -0
  49. data/app/controllers/locomotive/content_entries_controller.rb +10 -2
  50. data/app/controllers/locomotive/pages_controller.rb +2 -1
  51. data/app/controllers/locomotive/passwords_controller.rb +17 -1
  52. data/app/helpers/locomotive/base_helper.rb +19 -0
  53. data/app/helpers/locomotive/content_types_helper.rb +2 -1
  54. data/app/helpers/locomotive/custom_fields_helper.rb +14 -1
  55. data/app/helpers/locomotive/dashboard_helper.rb +12 -0
  56. data/app/helpers/locomotive/editable_elements_helper.rb +9 -4
  57. data/app/helpers/locomotive/pages_helper.rb +1 -14
  58. data/app/helpers/locomotive/shared/pages_helper.rb +17 -0
  59. data/app/helpers/locomotive/translations_helper.rb +0 -14
  60. data/app/inputs/locomotive/color_input.rb +18 -0
  61. data/app/inputs/locomotive/markdown_input.rb +19 -0
  62. data/app/models/locomotive/account.rb +2 -1
  63. data/app/models/locomotive/concerns/content_entry/file_size.rb +27 -0
  64. data/app/models/locomotive/concerns/content_type/group_by.rb +3 -1
  65. data/app/models/locomotive/concerns/page/layout.rb +63 -19
  66. data/app/models/locomotive/concerns/shared/site_scope.rb +37 -0
  67. data/app/models/locomotive/concerns/site/cache.rb +32 -0
  68. data/app/models/locomotive/concerns/theme_asset/plain_text.rb +85 -0
  69. data/app/models/locomotive/content_entry.rb +7 -7
  70. data/app/models/locomotive/content_type.rb +12 -6
  71. data/app/models/locomotive/page.rb +12 -14
  72. data/app/models/locomotive/site.rb +9 -3
  73. data/app/models/locomotive/snippet.rb +6 -4
  74. data/app/models/locomotive/theme_asset.rb +8 -73
  75. data/app/models/locomotive/translation.rb +6 -5
  76. data/app/policies/locomotive/site_policy.rb +2 -2
  77. data/app/services/locomotive/content_entry_service.rb +7 -6
  78. data/app/services/locomotive/site_service.rb +1 -0
  79. data/app/views/locomotive/content_entries/_entry.html.slim +1 -0
  80. data/app/views/locomotive/content_entries/edit.html.slim +1 -1
  81. data/app/views/locomotive/content_entries/new.html.slim +1 -1
  82. data/app/views/locomotive/current_site/_membership.html.slim +1 -0
  83. data/app/views/locomotive/current_site/edit.html.slim +1 -1
  84. data/app/views/locomotive/current_site/form/_access_points.html.slim +1 -1
  85. data/app/views/locomotive/current_site/form/_advanced.html.slim +2 -0
  86. data/app/views/locomotive/dashboard/_activity.html.slim +26 -0
  87. data/app/views/locomotive/dashboard/_url.html.slim +9 -0
  88. data/app/views/locomotive/dashboard/show.html.slim +3 -21
  89. data/app/views/locomotive/devise_mailer/reset_password_instructions.html.slim +1 -1
  90. data/app/views/locomotive/editable_elements/_edit.html.slim +8 -1
  91. data/app/views/locomotive/editable_elements/_form.html.slim +1 -1
  92. data/app/views/locomotive/editable_elements/index_without_preview.html.slim +24 -17
  93. data/app/views/locomotive/layouts/application.html.slim +6 -4
  94. data/app/views/locomotive/layouts/live_editing.html.slim +9 -0
  95. data/app/views/locomotive/layouts/not_logged_in.html.slim +1 -1
  96. data/app/views/locomotive/layouts/without_site.html.slim +2 -0
  97. data/app/views/locomotive/memberships/edit.html.slim +1 -1
  98. data/app/views/locomotive/memberships/new.html.slim +1 -1
  99. data/app/views/locomotive/my_account/edit.html.slim +7 -5
  100. data/app/views/locomotive/pages/_header.html.slim +7 -0
  101. data/app/views/locomotive/pages/edit.html.slim +2 -4
  102. data/app/views/locomotive/pages/form/_main.html.slim +4 -1
  103. data/app/views/locomotive/pages/form/_tabs.html.slim +4 -3
  104. data/app/views/locomotive/public_submission_accounts/_account.html.slim +1 -1
  105. data/app/views/locomotive/public_submission_accounts/edit.html.slim +1 -1
  106. data/app/views/locomotive/shared/_header.html.slim +25 -22
  107. data/app/views/locomotive/shared/_locale_picker_link.html.slim +3 -0
  108. data/app/views/locomotive/shared/_main_app_header.html.slim +1 -1
  109. data/app/views/locomotive/shared/_sidebar.html.slim +15 -11
  110. data/app/views/locomotive/shared/rte/_markdown_toolbar.html.slim +42 -0
  111. data/config/locales/admin_ui.en.yml +9 -4
  112. data/config/locales/default.en.yml +4 -0
  113. data/config/locales/devise.en.yml +1 -0
  114. data/config/locales/simple_form.en.yml +6 -2
  115. data/lib/locomotive/action_controller/responder.rb +5 -0
  116. data/lib/locomotive/engine.rb +5 -0
  117. data/lib/locomotive/middlewares/site.rb +39 -21
  118. data/lib/locomotive/simple_form.rb +3 -31
  119. data/lib/locomotive/steam/middlewares/cache.rb +62 -0
  120. data/lib/locomotive/steam/middlewares/page_editing.rb +9 -3
  121. data/lib/locomotive/steam/services/api_entry_submission_service.rb +6 -3
  122. data/lib/locomotive/steam/services/liquid_parser_with_cache_service.rb +74 -0
  123. data/lib/locomotive/steam_adaptor.rb +7 -1
  124. data/lib/locomotive/version.rb +1 -1
  125. data/lib/tasks/development.rake +4 -0
  126. data/lib/tasks/locomotive.rake +14 -0
  127. data/spec/lib/locomotive/steam/services/api_entry_submission_service_spec.rb +10 -1
  128. data/spec/lib/locomotive/steam/services/liquid_parser_with_cache_service_spec.rb +53 -0
  129. data/spec/models/locomotive/concerns/content_entry/file_size_spec.rb +40 -0
  130. data/spec/models/locomotive/concerns/page/layout_spec.rb +122 -17
  131. data/spec/models/locomotive/concerns/site/cache_spec.rb +60 -0
  132. data/spec/models/locomotive/content_entry_spec.rb +7 -0
  133. data/spec/models/locomotive/content_type_spec.rb +18 -11
  134. data/spec/models/locomotive/page_spec.rb +32 -8
  135. data/spec/models/locomotive/snippet_spec.rb +13 -4
  136. data/spec/models/locomotive/theme_asset_spec.rb +10 -3
  137. data/spec/models/locomotive/translation_spec.rb +28 -0
  138. data/spec/requests/locomotive/steam/cache_spec.rb +83 -0
  139. data/spec/requests/site_spec.rb +24 -0
  140. data/spec/support/capybara.rb +5 -13
  141. data/spec/support/factories.rb +9 -0
  142. data/spec/support/features/session_helpers.rb +19 -3
  143. data/spec/support/features/site_helpers.rb +27 -0
  144. data/spec/support/shared_examples/site_scope_examples.rb +27 -0
  145. data/vendor/assets/images/locomotive/bootstrap-colorpicker/alpha-horizontal.png +0 -0
  146. data/vendor/assets/images/locomotive/bootstrap-colorpicker/alpha.png +0 -0
  147. data/vendor/assets/images/locomotive/bootstrap-colorpicker/hue-horizontal.png +0 -0
  148. data/vendor/assets/images/locomotive/bootstrap-colorpicker/hue.png +0 -0
  149. data/vendor/assets/images/locomotive/bootstrap-colorpicker/saturation.png +0 -0
  150. data/vendor/assets/javascripts/locomotive/bootstrap-colorpicker.js +1 -0
  151. data/vendor/assets/javascripts/locomotive/datepicker_i18n.js.erb +6 -6
  152. data/vendor/assets/javascripts/locomotive/kramed.min.js +11 -0
  153. data/vendor/assets/stylesheets/locomotive/bootstrap-colorpicker.scss +9 -0
  154. metadata +59 -44
  155. data/app/controllers/locomotive/api/accounts_controller.rb +0 -60
  156. data/app/controllers/locomotive/api/base_controller.rb +0 -35
  157. data/app/controllers/locomotive/api/content_assets_controller.rb +0 -51
  158. data/app/controllers/locomotive/api/content_entries_controller.rb +0 -71
  159. data/app/controllers/locomotive/api/content_types_controller.rb +0 -52
  160. data/app/controllers/locomotive/api/current_site_controller.rb +0 -34
  161. data/app/controllers/locomotive/api/memberships_controller.rb +0 -52
  162. data/app/controllers/locomotive/api/my_account_controller.rb +0 -46
  163. data/app/controllers/locomotive/api/pages_controller.rb +0 -53
  164. data/app/controllers/locomotive/api/sites_controller.rb +0 -58
  165. data/app/controllers/locomotive/api/snippets_controller.rb +0 -52
  166. data/app/controllers/locomotive/api/theme_assets_controller.rb +0 -51
  167. data/app/controllers/locomotive/api/tokens_controller.rb +0 -36
  168. data/app/controllers/locomotive/api/translations_controller.rb +0 -51
  169. data/app/controllers/locomotive/api/version_controller.rb +0 -11
  170. data/spec/models/locomotive/editable_control_spec.rb +0 -79
  171. data/spec/models/locomotive/editable_file_spec.rb +0 -94
  172. data/spec/models/locomotive/editable_text_spec.rb +0 -219
  173. data/vendor/assets/images/select2-spinner.gif +0 -0
  174. data/vendor/assets/images/select2.png +0 -0
  175. 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 = FactoryGirl.build(: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 = FactoryGirl.build(:content_type, field.to_sym => nil)
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 = FactoryGirl.build(:content_type, name: nil, slug: nil)
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 = FactoryGirl.build(: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 = FactoryGirl.build(:content_type, site: content_type.site, slug: content_type.slug)
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 = FactoryGirl.build(: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 = FactoryGirl.build(: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 = FactoryGirl.build(:content_type, name: 'my 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 = FactoryGirl.build(:content_type, slug: 'my 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 = FactoryGirl.build(: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
- FactoryGirl.build(:content_type, options).tap do |content_type|
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
- %w{site title}.each do |field|
19
- it "requires the presence of the #{field}" do
20
- page = build(:page, field.to_sym => nil)
21
- expect(page).to_not be_valid
22
- expect(page.errors[field.to_sym]).to eq(["can't be blank"])
23
- end
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 no cache strategy' do
128
+ it 'has cache enabled' do
125
129
  page = build(:page, site: nil)
126
- expect(page.with_cache?).to eq(false)
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(FactoryGirl.build(:snippet)).to be_valid
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
- template = FactoryGirl.build(:snippet, field.to_sym => nil)
14
- expect(template).to_not be_valid
15
- expect(template.errors[field.to_sym]).to eq(["can't be blank"])
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) { FactoryGirl.build(:site, domains: %w{www.acme.com}) }
8
-
9
- let(:asset) { FactoryGirl.build(:theme_asset, site: site, updated_at: DateTime.parse('2007/06/29 21:10:00')) }
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
@@ -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 }
@@ -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://test.example.com:9886'
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