the entry_submission_service should only allow submitting an entry if the related content type has the public_submission_enabled property set to true

did committed Sep 13, 2015
commit f5c23e0fc77eb052ea780154dafc508db461048f
Showing 4 changed files with 12 additions and 4 deletions
locomotive/steam/middlewares/entry_submission.rb b/lib/locomotive/steam/middlewares/entry_submission.rb +1 -1
@@ @@ -123,7 +123,7 @@ module Locomotive::Steam
if entry = services.entry_submission.submit(slug, entry_attributes)
entry
else
- raise %{Unknown content type "#{slug}"}
+ raise %{Unknown content type "#{slug}" or public_submission_enabled property not true}
end
end
locomotive/steam/services/entry_submission_service.rb b/lib/locomotive/steam/services/entry_submission_service.rb +1 -1
@@ @@ -10,7 +10,7 @@ module Locomotive
def submit(slug, attributes = {})
type = get_type(slug)
- return nil if type.nil?
+ return nil if type.nil? || type.public_submission_enabled == false
clean_attributes(attributes)
spec/integration/server/contact_form_spec.rb +1 -1
@@ @@ -32,7 +32,7 @@ describe 'ContactForm' do
let(:url) { '/entry_submissions/foo' }
- it { expect { response }.to raise_error('Unknown content type "foo"') }
+ it { expect { response }.to raise_error('Unknown content type "foo" or public_submission_enabled property not true') }
end
spec/unit/services/entry_submission_service_spec.rb +9 -1
@@ @@ -91,7 +91,8 @@ describe Locomotive::Steam::EntrySubmissionService do
let(:unique_fields) { {} }
let(:first_validation) { false }
let(:errors) { [:title] }
- let(:type) { instance_double('Comments') }
+ let(:enabled) { true }
+ let(:type) { instance_double('Comments', public_submission_enabled: enabled) }
let(:entry) { instance_double('Entry', title: 'Hello world', content_type: type, valid?: first_validation, errors: errors, attributes: { title: 'Hello world' }, localized_attributes: []) }
let(:slug) { 'comments' }
@@ @@ -101,6 +102,13 @@ describe Locomotive::Steam::EntrySubmissionService do
allow(entry_repository).to receive(:build).with(attributes).and_return(entry)
end
+ context 'public submission disabled' do
+
+ let(:enabled) { false }
+ it { is_expected.to eq nil }
+
+ end
+
context 'valid' do
before { expect(entry_repository).to receive(:create) }