layout pages have pre-defined attributes (is_layout, listed, published) + update the specs accordingly + rake task to help to generate the data for the specs

did committed Oct 03, 2015
commit f1cfcf068dfdee3e713c2eb48ae508e0045a4ae5
Showing 40 changed files with 90 additions and 36 deletions
Rakefile +14 -2
@@ @@ -17,9 +17,21 @@ namespace :mongodb do
namespace :test do
desc 'Seed the MongoDB database with the dump of the Sample website'
task :seed do
- path = File.join(File.expand_path(File.dirname(__FILE__)), 'spec', 'fixtures', 'mongodb')
+ root_path = File.expand_path(File.dirname(__FILE__))
+ db_path = File.join(root_path, 'spec', 'fixtures', 'mongodb')
+
+ if database = ENV['DATABASE']
+ dump_path = File.join(root_path, 'dump', database)
+
+ `rm -rf #{db_path}`
+ `mongodump --db #{database}`
+ `mv #{dump_path} #{db_path}`
+ end
+
`mongo steam_test --eval "db.dropDatabase()"`
- `mongorestore -d steam_test #{path}`
+ `mongorestore -d steam_test #{db_path}`
+
+ puts "Done! Update now the spec/support/helpers.rb file by setting the new id of the site returned by the mongodb_site_id method"
end
end
end
locomotive/steam/adapters/filesystem/yaml_loaders/page.rb b/lib/locomotive/steam/adapters/filesystem/yaml_loaders/page.rb +9 -0
@@ @@ -80,6 +80,9 @@ module Locomotive
# trick to use the template of the default locale (if available)
attributes[:template_path] = false if template.blank?
+
+ # page under layouts/ should be treated differently
+ set_layout_attributes(attributes) if fullpath.split('/').first == 'layouts'
end
end
end
@@ @@ -158,6 +161,12 @@ module Locomotive
{ block: block, slug: slug, content: { locale => content } }
end
+ def set_layout_attributes(attributes)
+ attributes[:is_layout] = true if attributes[:is_layout].nil?
+ attributes[:listed] = false
+ attributes[:published] = false
+ end
+
end
end
spec/fixtures/default/README +11 -0
@@ @@ -0,0 +1,11 @@
+ [LocomotiveCMS]
+
+ mongoid.yml: locomotive_engine_wagon_dev
+
+ > bundle exec rake development:bootstrap
+ > bundle exec rails c
+ # Locomotive::Site.first.destroy
+
+ [Steam]
+ wagon_dev deploy development -d -v spec/fixtures/default
+ bundle exec rake mongodb:test:seed
spec/fixtures/default/app/views/pages/layouts/simple.liquid +14 -0
@@ @@ -0,0 +1,14 @@
+ ---
+ title: Simple layout
+ ---
+ <html>
+ <head>
+ <title>{{ page. title }}</title>
+ </head>
+ <body>
+ {% editable_text body %}
+ <h1>Hello world</h1>
+ <p>Lorem ipsum</p>
+ {% endeditable_text %}
+ </body>
+ </html>
spec/fixtures/default/config/deploy.yml +4 -3
@@ @@ -1,7 +1,8 @@
development:
- host: sample.lvh.me:3000
- email: john@doe.net
- api_key: a9ac1e08c2c22c1b6f3da6db77a70cac4a615bd7
+ host: localhost:3000
+ handle: sample
+ email: admin@locomotivecms.com
+ api_key: d49cd50f6f0d2b163f48fc73cb249f0244c37074
staging:
host: staging.example.com
email: john@doe.net
spec/fixtures/default/config/site.yml +1 -1
@@ @@ -1,4 +1,4 @@
- name: Sample website
+ name: Sample site
subdomain: sample
locomotive_accounts.bson b/spec/fixtures/mongodb/locomotive_accounts.bson +0 -0
locomotive_accounts.metadata.json b/spec/fixtures/mongodb/locomotive_accounts.metadata.json +1 -1
@@ @@ -1 +1 @@
- { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_2_5_dev.locomotive_accounts" } ] }
\ No newline at end of file
+ { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_wagon_dev.locomotive_accounts" } ] }
\ No newline at end of file
locomotive_activities.bson b/spec/fixtures/mongodb/locomotive_activities.bson +0 -0
locomotive_activities.metadata.json b/spec/fixtures/mongodb/locomotive_activities.metadata.json +1 -0
@@ @@ -0,0 +1 @@
+ { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_wagon_dev.locomotive_activities" } ] }
\ No newline at end of file
locomotive_content_assets.bson b/spec/fixtures/mongodb/locomotive_content_assets.bson +0 -0
locomotive_content_assets.metadata.json b/spec/fixtures/mongodb/locomotive_content_assets.metadata.json +1 -1
@@ @@ -1 +1 @@
- { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_2_5_dev.locomotive_content_assets" } ] }
\ No newline at end of file
+ { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_wagon_dev.locomotive_content_assets" } ] }
\ No newline at end of file
locomotive_content_entries.bson b/spec/fixtures/mongodb/locomotive_content_entries.bson +0 -0
locomotive_content_entries.metadata.json b/spec/fixtures/mongodb/locomotive_content_entries.metadata.json +1 -1
@@ @@ -1 +1 @@
- { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_2_5_dev.locomotive_content_entries" } ] }
\ No newline at end of file
+ { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_wagon_dev.locomotive_content_entries" } ] }
\ No newline at end of file
locomotive_content_types.bson b/spec/fixtures/mongodb/locomotive_content_types.bson +0 -0
locomotive_content_types.metadata.json b/spec/fixtures/mongodb/locomotive_content_types.metadata.json +1 -1
@@ @@ -1 +1 @@
- { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_2_5_dev.locomotive_content_types" } ] }
\ No newline at end of file
+ { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_wagon_dev.locomotive_content_types" } ] }
\ No newline at end of file
locomotive_pages.bson b/spec/fixtures/mongodb/locomotive_pages.bson +0 -0
locomotive_pages.metadata.json b/spec/fixtures/mongodb/locomotive_pages.metadata.json +1 -1
@@ @@ -1 +1 @@
- { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_2_5_dev.locomotive_pages" } ] }
\ No newline at end of file
+ { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_wagon_dev.locomotive_pages" } ] }
\ No newline at end of file
locomotive_sites.bson b/spec/fixtures/mongodb/locomotive_sites.bson +0 -0
locomotive_sites.metadata.json b/spec/fixtures/mongodb/locomotive_sites.metadata.json +1 -1
@@ @@ -1 +1 @@
- { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_2_5_dev.locomotive_sites" } ] }
\ No newline at end of file
+ { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_wagon_dev.locomotive_sites" } ] }
\ No newline at end of file
locomotive_snippets.bson b/spec/fixtures/mongodb/locomotive_snippets.bson +0 -0
locomotive_snippets.metadata.json b/spec/fixtures/mongodb/locomotive_snippets.metadata.json +1 -1
@@ @@ -1 +1 @@
- { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_2_5_dev.locomotive_snippets" } ] }
\ No newline at end of file
+ { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_wagon_dev.locomotive_snippets" } ] }
\ No newline at end of file
locomotive_theme_assets.bson b/spec/fixtures/mongodb/locomotive_theme_assets.bson +0 -0
locomotive_theme_assets.metadata.json b/spec/fixtures/mongodb/locomotive_theme_assets.metadata.json +1 -1
@@ @@ -1 +1 @@
- { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_2_5_dev.locomotive_theme_assets" } ] }
\ No newline at end of file
+ { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_wagon_dev.locomotive_theme_assets" } ] }
\ No newline at end of file
locomotive_translations.bson b/spec/fixtures/mongodb/locomotive_translations.bson +0 -0
locomotive_translations.metadata.json b/spec/fixtures/mongodb/locomotive_translations.metadata.json +1 -1
@@ @@ -1 +1 @@
- { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_2_5_dev.locomotive_translations" } ] }
\ No newline at end of file
+ { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_wagon_dev.locomotive_translations" } ] }
\ No newline at end of file
sessions.bson b/spec/fixtures/mongodb/sessions.bson +0 -0
sessions.metadata.json b/spec/fixtures/mongodb/sessions.metadata.json +0 -1
@@ @@ -1 +0,0 @@
- { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "locomotive_engine_2_5_dev.sessions" } ] }
\ No newline at end of file
system.indexes.bson b/spec/fixtures/mongodb/system.indexes.bson +0 -0
spec/integration/liquid/tags/paginate_spec.rb +1 -1
@@ @@ -69,7 +69,7 @@ EOF
it_should_behave_like 'pagination' do
- let(:site_id) { BSON::ObjectId.from_string('54eb49c12475804b2b000002') }
+ let(:site_id) { mongodb_site_id }
let(:adapter) { Locomotive::Steam::MongoDBAdapter.new(database: 'steam_test', hosts: ['127.0.0.1:27017']) }
end
spec/integration/repositories/content_entry_repository_spec.rb +2 -2
@@ @@ -82,9 +82,9 @@ describe Locomotive::Steam::ContentEntryRepository do
it_should_behave_like 'a repository' do
- let(:site_id) { BSON::ObjectId.from_string('54eb49c12475804b2b000002') }
+ let(:site_id) { mongodb_site_id }
let(:adapter) { Locomotive::Steam::MongoDBAdapter.new(database: 'steam_test', hosts: ['127.0.0.1:27017']) }
- let(:entry_id) { BSON::ObjectId.from_string('54eb4bbc2475804b2b00003f') }
+ let(:entry_id) { BSON::ObjectId.from_string('5610310b87f6431588000029') }
end
spec/integration/repositories/content_type_repository_spec.rb +1 -1
@@ @@ -46,7 +46,7 @@ describe Locomotive::Steam::ContentTypeRepository do
it_should_behave_like 'a repository' do
- let(:site_id) { BSON::ObjectId.from_string('54eb49c12475804b2b000002') }
+ let(:site_id) { mongodb_site_id }
let(:adapter) { Locomotive::Steam::MongoDBAdapter.new(database: 'steam_test', hosts: ['127.0.0.1:27017']) }
end
spec/integration/repositories/page_repository_spec.rb +3 -3
@@ @@ -19,7 +19,7 @@ describe Locomotive::Steam::PageRepository do
describe '#all' do
let(:conditions) { {} }
subject { repository.all(conditions) }
- it { expect(subject.size).to eq 24 }
+ it { expect(subject.size).to eq 26 }
context 'with conditions' do
let(:conditions) { { fullpath: 'index', 'slug.ne' => '404' } }
@@ @@ -83,7 +83,7 @@ describe Locomotive::Steam::PageRepository do
describe '#children_of' do
let(:page) { repository.root }
subject { repository.children_of(page) }
- it { expect(subject.size).to eq 14 }
+ it { expect(subject.size).to eq 15 }
end
describe '#editable_element_for' do
@@ @@ -98,7 +98,7 @@ describe Locomotive::Steam::PageRepository do
it_should_behave_like 'a repository' do
- let(:site_id) { BSON::ObjectId.from_string('54eb49c12475804b2b000002') }
+ let(:site_id) { mongodb_site_id }
let(:adapter) { Locomotive::Steam::MongoDBAdapter.new(database: 'steam_test', hosts: ['127.0.0.1:27017']) }
end
spec/integration/repositories/site_repository_spec.rb +3 -3
@@ @@ -15,12 +15,12 @@ describe Locomotive::Steam::SiteRepository do
end
describe '#query' do
- subject { repository.query { where(subdomain: 'sample') }.first }
- it { expect(subject.name).to eq 'Sample website' }
+ subject { repository.query { where(handle: 'sample') }.first }
+ it { expect(subject.name).to eq 'Sample site' }
end
describe '#by_domain' do
- subject { repository.by_domain('sample.lvh.me') }
+ subject { repository.by_domain('sample.example.com') }
it { expect(subject).not_to eq nil }
end
spec/integration/repositories/snippet_repository_spec.rb +1 -1
@@ @@ -27,7 +27,7 @@ describe Locomotive::Steam::SnippetRepository do
it_should_behave_like 'a repository' do
- let(:site_id) { BSON::ObjectId.from_string('54eb49c12475804b2b000002') }
+ let(:site_id) { mongodb_site_id }
let(:adapter) { Locomotive::Steam::MongoDBAdapter.new(database: 'steam_test', hosts: ['127.0.0.1:27017']) }
end
spec/integration/repositories/theme_asset_repository_spec.rb +3 -3
@@ @@ -10,7 +10,7 @@ describe Locomotive::Steam::ThemeAssetRepository do
context 'MongoDB' do
- let(:site_id) { BSON::ObjectId.from_string('54eb49c12475804b2b000002') }
+ let(:site_id) { mongodb_site_id }
let(:adapter) { Locomotive::Steam::MongoDBAdapter.new(database: 'steam_test', hosts: ['127.0.0.1:27017']) }
describe '#all' do
@@ @@ -20,13 +20,13 @@ describe Locomotive::Steam::ThemeAssetRepository do
describe '#url_for' do
subject { repository.url_for('stylesheets/application.css') }
- it { is_expected.to eq '/sites/54eb49c12475804b2b000002/theme/stylesheets/application.css' }
+ it { is_expected.to eq "/sites/#{mongodb_site_id}/theme/stylesheets/application.css" }
end
describe '#checksums' do
subject { repository.checksums }
it { expect(subject.size).to eq 16 }
- it { expect(subject['stylesheets/application.css']).to eq 'aa017461d702a80ef8837e51e65deb4f' }
+ it { expect(subject['stylesheets/application.css']).to eq '3bacf4c2b7877e230e6990d72dae7724' }
end
end
spec/integration/repositories/translation_repository_spec.rb +1 -1
@@ @@ -27,7 +27,7 @@ describe Locomotive::Steam::TranslationRepository do
it_should_behave_like 'a repository' do
- let(:site_id) { BSON::ObjectId.from_string('54eb49c12475804b2b000002') }
+ let(:site_id) { mongodb_site_id }
let(:adapter) { Locomotive::Steam::MongoDBAdapter.new(database: 'steam_test', hosts: ['127.0.0.1:27017']) }
end
spec/support/helpers.rb +4 -0
@@ @@ -3,6 +3,10 @@ require 'locomotive/common'
module Spec
module Helpers
+ def mongodb_site_id
+ BSON::ObjectId.from_string('561030e287f6431555000006')
+ end
+
def reset!
FileUtils.rm_rf(File.expand_path('../../../site', __FILE__))
end
spec/unit/adapters/filesystem/yaml_loaders/page_spec.rb +7 -4
@@ @@ -15,11 +15,14 @@ describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::Page do
subject { loader.load(scope).sort { |a, b| a[:_fullpath] <=> b[:_fullpath] } }
it 'tests various stuff' do
- expect(subject.size).to eq 24
+ expect(subject.size).to eq 26
expect(subject.first[:title]).to eq(en: 'Page not found')
- expect(subject[14][:slug]).to eq(en: 'music', fr: 'notre-musique')
- expect(subject[15][:_fullpath]).to eq 'songs'
- expect(subject[15][:template_path]).to eq(en: false)
+ expect(subject[15][:is_layout]).to eq true
+ expect(subject[15][:listed]).to eq false
+ expect(subject[15][:published]).to eq false
+ expect(subject[16][:slug]).to eq(en: 'music', fr: 'notre-musique')
+ expect(subject[17][:_fullpath]).to eq 'songs'
+ expect(subject[17][:template_path]).to eq(en: false)
end
end
spec/unit/adapters/filesystem/yaml_loaders/site_spec.rb +1 -1
@@ @@ -12,7 +12,7 @@ describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::Site do
subject { loader.load(nil) }
- it { expect(subject.first[:name]).to eq 'Sample website' }
+ it { expect(subject.first[:name]).to eq 'Sample site' }
end