improve the coverage by adding more specs
did
committed Feb 17, 2015
commit 421cca7c6e45f59ae54124ccbee058609933cc53
Showing 19
changed files with
215 additions
and 87 deletions
locomotive/steam.rb b/lib/locomotive/steam.rb
+0
-1
| @@ | @@ -6,7 +6,6 @@ require 'active_support/deprecation' |
| require 'active_support/core_ext' | |
| require_relative 'steam/core_ext' | |
| - | require_relative 'steam/exceptions' |
| require_relative 'steam/configuration' | |
| require_relative 'steam/monkey_patches' | |
| require_relative 'steam/decorators' | |
locomotive/steam/exceptions.rb b/lib/locomotive/steam/exceptions.rb
+0
-62
| @@ | @@ -1,62 +0,0 @@ |
| - | module Locomotive |
| - | module Steam |
| - | |
| - | class DefaultException < ::Exception |
| - | |
| - | def initialize(message = nil, parent_exception = nil) |
| - | self.log_backtrace(parent_exception) if parent_exception |
| - | |
| - | super(message) |
| - | end |
| - | |
| - | protected |
| - | |
| - | def log_backtrace(parent_exception) |
| - | full_error_message = "#{parent_exception.message}\n\t" |
| - | full_error_message += parent_exception.backtrace.join("\n\t") |
| - | full_error_message += "\n\n" |
| - | Locomotive::Common::Logger.fatal full_error_message |
| - | end |
| - | |
| - | end |
| - | |
| - | class RendererException < DefaultException |
| - | |
| - | attr_accessor :name, :template, :liquid_context |
| - | |
| - | def initialize(exception, name, template, liquid_context) |
| - | self.name, self.template, self.liquid_context = name, template, liquid_context |
| - | |
| - | self.log_page_into_backtrace(exception) |
| - | |
| - | super(exception.message) |
| - | |
| - | self.set_backtrace(exception.backtrace) |
| - | end |
| - | |
| - | def log_page_into_backtrace(exception) |
| - | line = self.template.line_offset |
| - | line += (exception.respond_to?(:line) ? exception.line || 0 : 0) + 1 |
| - | |
| - | message = "#{self.template.filepath}:#{line}:in `#{self.name}'" |
| - | |
| - | Locomotive::Common::Logger.fatal "[ERROR] #{exception.message} - #{message}\n".red |
| - | |
| - | exception.backtrace.unshift message |
| - | end |
| - | |
| - | end |
| - | |
| - | class MounterException < DefaultException |
| - | end |
| - | |
| - | class GeneratorException < DefaultException |
| - | |
| - | def log_backtrace(parent_exception) |
| - | # Logger not initialized at this step |
| - | end |
| - | |
| - | end |
| - | |
| - | end |
| - | end |
locomotive/steam/middlewares/dynamic_assets.rb b/lib/locomotive/steam/middlewares/dynamic_assets.rb
+1
-0
| @@ | @@ -42,6 +42,7 @@ module Locomotive::Steam |
| else | |
| message = "[Important] YUICompressor requires java to be installed. The JAVA_HOME variable should also be set.\n" | |
| Locomotive::Common::Logger.warn message.red | |
| + | false |
| end | |
| end | |
locomotive/steam/middlewares/entry_submission.rb b/lib/locomotive/steam/middlewares/entry_submission.rb
+1
-1
| @@ | @@ -125,7 +125,7 @@ module Locomotive::Steam |
| if entry = services.entry_submission.submit(slug, attributes) | |
| entry | |
| else | |
| - | raise "Unknown content type '#{slug}'" |
| + | raise %{Unknown content type "#{slug}"} |
| end | |
| end | |
locomotive/steam/middlewares/renderer.rb b/lib/locomotive/steam/middlewares/renderer.rb
+0
-2
| @@ | @@ -31,8 +31,6 @@ module Locomotive::Steam |
| document.render(liquid_context) | |
| end | |
| - | # == TEST == |
| - | |
| def liquid_context | |
| ::Liquid::Context.new(liquid_assigns, {}, liquid_registers, true) | |
| end | |
locomotive/steam/repositories/filesystem/models/concerns/validation.rb b/lib/locomotive/steam/repositories/filesystem/models/concerns/validation.rb
+1
-0
| @@ | @@ -1,3 +1,4 @@ |
| + | |
| require 'forwardable' | |
| module Locomotive | |
spec/fixtures/default/app/views/pages/events.fr.liquid
+4
-0
| @@ | @@ -0,0 +1,4 @@ |
| + | --- |
| + | title: Evenements |
| + | slug: evenements |
| + | --- |
spec/fixtures/default/app/views/pages/events.liquid.haml
+23
-1
| @@ | @@ -18,6 +18,28 @@ position: 5 |
| {{ event.place }}, {{ event.city }}, {{ event.state }} | |
| {% endfor %} | |
| + | #sidebar.unit.size1of3 |
| + | |
| + | {% model_form 'messages', id: 'contactform' %} |
| + | %p |
| + | %label{ :for => 'name' } Name |
| + | %input{ :type => 'text', :id => 'name', :name => 'content[name]', :placeholder => 'First and last name', :tabindex => '1', required: 'required', value: '{{ message.name }}' } |
| + | %span {{ message.errors.name }} |
| + | |
| + | %p |
| + | %label{ :for => 'email' } Email |
| + | %input{ :type => 'text', :id => 'email', :name => 'content[email]', :placeholder => 'example@domain.com', :tabindex => '2', required: 'required', value: '{{ message.email }}' } |
| + | %span {{ message.errors.email }} |
| + | |
| + | %p |
| + | %label{ :for => 'comment' } Your Message |
| + | %textarea{ :id => 'comment', :name => 'content[message]', :tabindex => '3', required: 'required' } {{ message.message }} |
| + | %span {{ message.errors.message }} |
| + | |
| + | %p.action |
| + | %input{ :name => 'submit', :type => 'submit', :tabindex => '4', :value => 'Send Message' } |
| + | {% endmodel_form %} |
| + | |
| #sidebar.unit.size1of3 | |
| {% editable_long_text 'sidebar' %} | |
| @@ | @@ -39,4 +61,4 @@ position: 5 |
| {% assign another_song = contents.songs.last %} | |
| %strong {% link_to another_song, with: a-song-template %} | |
| - | {% endblock %} |
| \ No newline at end of file | |
| + | {% endblock %} |
spec/fixtures/default/app/views/pages/songs/song-number-1.liquid.haml
+4
-0
| @@ | @@ -0,0 +1,4 @@ |
| + | --- |
| + | title: Song #1 |
| + | --- |
| + | another version |
spec/integration/server/assets_spec.rb
+10
-2
| @@ | @@ -8,6 +8,14 @@ describe Locomotive::Steam::Server do |
| run_server | |
| end | |
| + | describe 'no favicon' do |
| + | |
| + | subject { get '/favicon.ico'; last_response.body } |
| + | |
| + | it { is_expected.to include('') } |
| + | |
| + | end |
| + | |
| describe 'theme assets' do | |
| subject { get '/all'; last_response.body } | |
| @@ | @@ -18,7 +26,7 @@ describe Locomotive::Steam::Server do |
| end | |
| - | describe 'Static assets' do |
| + | describe 'static assets' do |
| it 'renders an image' do | |
| get '/images/nav_on.png' | |
| @@ | @@ -27,7 +35,7 @@ describe Locomotive::Steam::Server do |
| end | |
| - | describe 'Dynamic assets (SCSS + Coffeescript)' do |
| + | describe 'dynamic assets (SCSS + Coffeescript)' do |
| it 'renders a stylesheet' do | |
| get '/stylesheets/application.css' | |
spec/integration/server/basic_spec.rb
+3
-3
| @@ | @@ -54,12 +54,12 @@ describe Locomotive::Steam::Server do |
| it 'shows a content type template' do | |
| get '/songs/song-number-1' | |
| - | expect(last_response.body).to include 'Song #1' |
| + | expect(last_response.body).to include 'another version' |
| end | |
| it 'renders a page under a templatized one' do | |
| - | get '/songs/song-number-1/band' |
| - | expect(last_response.body).to include 'Song #1' |
| + | get '/songs/song-number-2/band' |
| + | expect(last_response.body).to include 'Song #2' |
| expect(last_response.body).to include 'Leader: Eddie' | |
| end | |
spec/integration/server/contact_form_spec.rb
+82
-11
| @@ | @@ -13,20 +13,29 @@ describe 'ContactForm' do |
| expect(last_response.body).to include '/entry_submissions/messages.json' | |
| end | |
| - | describe '#submit' do |
| + | describe 'submit a new entry (old version)' do |
| + | let(:url) { '/entry_submissions/messages' } |
| let(:params) { { | |
| 'entry' => { 'name' => 'John', 'email' => 'j@doe.net', 'message' => 'Bla bla' }, | |
| 'success_callback' => '/events', | |
| 'error_callback' => '/contact' } } | |
| - | let(:response) { post_contact_form(params, false) } |
| + | let(:response) { post_contact_form(url, params, false) } |
| let(:status) { response.status } | |
| describe 'with json request' do | |
| - | let(:response) { post_contact_form(params, true) } |
| + | let(:response) { post_contact_form(url, params, true) } |
| let(:entry) { JSON.parse(response.body) } | |
| + | context 'unknown content type' do |
| + | |
| + | let(:url) { '/entry_submissions/foo' } |
| + | |
| + | it { expect { response }.to raise_error('Unknown content type "foo"') } |
| + | |
| + | end |
| + | |
| context 'when not valid' do | |
| let(:params) { {} } | |
| @@ | @@ -73,11 +82,21 @@ describe 'ContactForm' do |
| expect(response.body.to_s).to include "can't not be blank" | |
| end | |
| + | context 'redirects outside the site' do |
| + | |
| + | let(:params) { { 'error_callback' => 'http://www.locomotivecms.com' } } |
| + | |
| + | it 'returns a success status' do |
| + | expect(response.status).to eq 301 |
| + | end |
| + | |
| + | end |
| + | |
| end | |
| context 'when valid' do | |
| - | let(:response) { post_contact_form(params, false, true) } |
| + | let(:response) { post_contact_form(url, params, false, true) } |
| it 'returns a success status' do | |
| expect(response.status).to eq 200 | |
| @@ | @@ -93,14 +112,66 @@ describe 'ContactForm' do |
| end | |
| - | def post_contact_form(params, json = false, follow_redirect = false) |
| - | url = '/entry_submissions/messages' |
| - | url += '.json' if json |
| - | params = params.symbolize_keys if json |
| - | post url, params |
| - | if follow_redirect |
| - | follow_redirect! |
| + | describe 'submit a new entry (new version)' do |
| + | |
| + | let(:url) { '/events' } |
| + | let(:params) { { |
| + | 'content_type_slug' => 'messages', |
| + | 'entry' => { 'name' => 'John', 'email' => 'j@doe.net', 'message' => 'Bla bla' } } } |
| + | let(:response) { post_contact_form(url, params) } |
| + | let(:status) { response.status } |
| + | |
| + | context 'when not valid' do |
| + | |
| + | let(:params) { { 'content_type_slug' => 'messages' } } |
| + | |
| + | it 'returns a success status' do |
| + | expect(response.status).to eq 200 |
| + | end |
| + | |
| + | it 'displays errors' do |
| + | expect(response.body.to_s).to include "can't not be blank" |
| + | end |
| + | |
| end | |
| + | |
| + | context 'when valid' do |
| + | |
| + | let(:response) { post_contact_form(url, params, false, true) } |
| + | |
| + | it 'returns a success status' do |
| + | expect(response.status).to eq 200 |
| + | end |
| + | |
| + | it 'displays a success message' do |
| + | expect(response.body.to_s).to include 'Thank you John' |
| + | end |
| + | |
| + | end |
| + | |
| + | context 'in a different locale' do |
| + | |
| + | let(:url) { '/fr/evenements' } |
| + | let(:response) { post_contact_form(url, params, false, true) } |
| + | |
| + | it 'returns a success status' do |
| + | expect(response.status).to eq 200 |
| + | end |
| + | |
| + | end |
| + | |
| + | end |
| + | |
| + | def post_contact_form(url, params, json = false, follow_redirect = false) |
| + | if json |
| + | url += '.json' |
| + | params = params.symbolize_keys |
| + | end |
| + | |
| + | post url, params |
| + | |
| + | follow_redirect! if follow_redirect |
| + | |
| last_response | |
| end | |
spec/integration/server/liquid_spec.rb
+3
-3
| @@ | @@ -9,7 +9,7 @@ describe Locomotive::Steam::Server do |
| end | |
| it 'converts {{ page.templatized? }} => true on templatized page' do | |
| - | get '/songs/song-number-1' |
| + | get '/songs/song-number-2' |
| expect(last_response.body).to include "templatized='true'" | |
| end | |
| @@ | @@ -24,12 +24,12 @@ describe Locomotive::Steam::Server do |
| end | |
| it "provides an access to page's content_type collection" do | |
| - | get '/songs/song-number-1' |
| + | get '/songs/song-number-2' |
| expect(last_response.body).to include "content_type_size='8'" | |
| end | |
| it 'provides count alias on collections' do | |
| - | get '/songs/song-number-1' |
| + | get '/songs/song-number-2' |
| expect(last_response.body).to include "content_type_count='8'" | |
| end | |
spec/unit/core_ext/string_spec.rb
+10
-0
| @@ | @@ -2,6 +2,16 @@ require 'spec_helper' |
| describe String do | |
| + | describe '#permalink!' do |
| + | |
| + | let(:string) { 'foo bar' } |
| + | |
| + | before { string.permalink! } |
| + | |
| + | it { expect(string).to eq 'foo-bar' } |
| + | |
| + | end |
| + | |
| describe '#to_bool' do | |
| subject { string.to_bool } | |
spec/unit/middlewares/dynamic_assets_spec.rb
+25
-0
| @@ | @@ -0,0 +1,25 @@ |
| + | require 'spec_helper' |
| + | |
| + | require 'sprockets' |
| + | require_relative '../../../lib/locomotive/steam/middlewares/dynamic_assets' |
| + | |
| + | describe Locomotive::Steam::Middlewares::DynamicAssets do |
| + | |
| + | let(:app) { ->(env) { [200, env, 'app'] }} |
| + | let(:options) { { root: File.dirname(__FILE__), minify: true } } |
| + | |
| + | let(:middleware) { Locomotive::Steam::Middlewares::DynamicAssets.new(app, options) } |
| + | |
| + | describe 'java not installed' do |
| + | |
| + | let(:sprockets) { instance_double('Sprockets') } |
| + | |
| + | before { allow(middleware).to receive(:is_java_installed?).and_return(false) } |
| + | |
| + | subject { middleware.send(:install_yui_compressor, sprockets, options) } |
| + | |
| + | it { is_expected.to eq(false) } |
| + | |
| + | end |
| + | |
| + | end |
spec/unit/middlewares/renderer_spec.rb
+32
-0
| @@ | @@ -0,0 +1,32 @@ |
| + | require 'spec_helper' |
| + | |
| + | require_relative '../../../lib/locomotive/steam/middlewares/threadsafe' |
| + | require_relative '../../../lib/locomotive/steam/middlewares/helpers' |
| + | require_relative '../../../lib/locomotive/steam/middlewares/renderer' |
| + | |
| + | describe Locomotive::Steam::Middlewares::Renderer do |
| + | |
| + | let(:app) { ->(env) { [200, env, 'app'] }} |
| + | |
| + | let :middleware do |
| + | Locomotive::Steam::Middlewares::Renderer.new(app) |
| + | end |
| + | |
| + | describe 'missing 404 page' do |
| + | |
| + | subject do |
| + | middleware.call env_for('http://www.example.com', { 'steam.page' => nil }) |
| + | end |
| + | |
| + | specify 'return 200' do |
| + | code, headers, response = subject |
| + | expect(code).to eq(404) |
| + | expect(response).to eq(['Missing 404 page']) |
| + | end |
| + | |
| + | end |
| + | |
| + | def env_for(url, opts={}) |
| + | Rack::MockRequest.env_for(url, opts) |
| + | end |
| + | end |
spec/unit/repositories/filesystem/models/content_entry_spec.rb
+8
-0
| @@ | @@ -27,6 +27,14 @@ describe Locomotive::Steam::Repositories::Filesystem::Models::ContentEntry do |
| end | |
| + | describe 'adding a custom error message' do |
| + | |
| + | before { content_entry.errors.add(:title, 'is mandatory') } |
| + | |
| + | it { expect(content_entry.errors[:title]).to eq(['is mandatory']) } |
| + | |
| + | end |
| + | |
| end | |
| describe '#_label' do | |
spec/unit/repositories/filesystem/models/page_spec.rb
+7
-0
| @@ | @@ -33,4 +33,11 @@ describe Locomotive::Steam::Repositories::Filesystem::Models::Page do |
| end | |
| + | describe '#valid?' do |
| + | |
| + | subject { page.valid? } |
| + | it { is_expected.to eq true } |
| + | |
| + | end |
| + | |
| end | |
spec/unit/repositories/filesystem/yaml_loaders/page_spec.rb
+1
-1
| @@ | @@ -12,7 +12,7 @@ describe Locomotive::Steam::Repositories::Filesystem::YAMLLoaders::Page do |
| subject { loader.list_of_attributes.sort { |a, b| a[:_fullpath] <=> b[:_fullpath] } } | |
| it 'tests various stuff' do | |
| - | expect(subject.size).to eq 20 |
| + | expect(subject.size).to eq 21 |
| expect(subject.first[:title]).to eq({ en: 'Page not found' }) | |
| end | |