Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Guru name validation and more 'bootstrappy' Guru form

  • Loading branch information...
commit a3314bda7e2fc1b8b261d07d5c22f35aa4f2ea8d 1 parent c902e76
@qertoip authored
View
17 app/frontends/web/app/assets/stylesheets/application.scss
@@ -11,3 +11,20 @@
*/
@import "bootstrap";
+
+/* Rails scaffold style compatibility */
+.error_explanation {
+ @extend .alert-message;
+ @extend .block-message;
+ @extend .error;
+}
+
+.field_with_errors, .formError {
+ // pulled from div.clearfix.error
+ @include formFieldState(#b94a48, #ee5f5b, lighten(#ee5f5b, 30%));
+}
+
+.formError {
+ color: #b94a48;
+ display: inline;
+}
View
7 app/frontends/web/app/helpers/application_helper.rb
@@ -5,4 +5,11 @@ def vm
@vm || @rm # if view model is not set fallback to response model
end
+ def errors(attribute)
+ return '' unless vm.errors && !vm.errors.blank?
+ content_tag( 'span', class: 'help-inline' ) do
+ vm.errors[attribute].join( '; ' )
+ end
+ end
+
end
View
26 app/frontends/web/app/views/gurus/_form.html.haml
@@ -1,7 +1,21 @@
-= f.label :name, 'Name'
-= f.text_field :name, class: 'span5'
-= f.label :homepage, 'Official site'
-= f.text_field :homepage, class: 'span5'
-= f.label :description, 'Description'
-~ f.text_area :description, class: 'span5'
+.control-group{ class: ( vm.errors ? 'error' : '' ) }
+ %label.control-label{ for: 'guru_name' }
+ Name
+ .controls
+ %input.span5{ type: 'text', id: 'guru_name', name: 'guru[name]', value: vm.guru.name }
+ = errors(:name)
+
+.control-group
+ %label.control-label{ for: 'guru_homepage' }
+ Official site
+ .controls
+ %input.span5{ type: 'text', id: 'guru_homepage', name: 'guru[homepage]', value: vm.guru.homepage }
+ = errors(:homepage)
+
+.control-group
+ %label.control-label{ for: 'guru_description' }
+ Description
+ .controls
+ %textarea.span5{ id: 'guru_description', name: 'guru[description]', value: vm.guru.description }
+ = errors(:description)
View
15 app/frontends/web/app/views/gurus/edit.html.haml
@@ -1,8 +1,13 @@
-- @title = 'Edit guru'
+= form_for( vm.guru, as: 'guru', url: guru_path( vm.guru ), :html => { class: 'form-horizontal' } ) do |f|
-= form_for( vm.guru, as: 'guru', url: guru_path( vm.guru ), :html => { class: 'well' } ) do |f|
+ %fieldset
+ %legend
+ = vm.guru.name
- = render 'form', f: f
+ = render 'form', f: f
- %p
- = f.submit( 'Update', class: 'btn' )
+ .form-actions
+ %button{ class: 'btn btn-primary', type: 'submit' }
+ Save changes
+ %button{ class: 'btn', type: 'button', onclick: 'history.go(-1)' }
+ Cancel
View
16 app/frontends/web/app/views/gurus/new.html.haml
@@ -1,8 +1,14 @@
-- @title = 'New guru'
-= form_for( vm.guru, as: 'guru', url: gurus_path, :html => { class: 'well' } ) do |f|
+= form_for( vm.guru, as: 'guru', url: gurus_path, :html => { class: 'form-horizontal' } ) do |f|
- = render 'form', f: f
+ %fieldset
+ %legend
+ New Guru
- %p
- = f.submit( 'Create', class: 'btn' )
+ = render 'form', f: f
+
+ .form-actions
+ %button{ class: 'btn btn-primary', type: 'submit' }
+ Create
+ %button{ class: 'btn', type: 'button', onclick: 'history.go(-1)' }
+ Cancel
View
3  test/app/use_cases/gurus/destroy_guru_test.rb
@@ -12,6 +12,9 @@ class DestroyGuruTest < GuruWatch::TestCase
guru = Guru.create_valid!
response = DestroyGuru.new(id: guru.id).exec
assert(response.ok?)
+ assert_raises(RubyPersistenceAPI::ObjectNotFound) do
+ db[Guru].find(guru.id)
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.