Skip to content

Commit

Permalink
specz
Browse files Browse the repository at this point in the history
  • Loading branch information
ajb committed Sep 26, 2013
1 parent dc090ae commit 7f5321f
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ gemspec
# Explicitly require carrierwave
gem 'carrierwave', require: 'carrierwave'

# Bundle spring from github
gem 'spring', github: 'jonleighton/spring'

# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
Expand Down
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
GIT
remote: git://github.com/jonleighton/spring.git
revision: 38214cfd773daaa3345604743f795271824dcf49
specs:
spring (0.0.10)

PATH
remote: .
specs:
Expand Down Expand Up @@ -186,5 +192,6 @@ DEPENDENCIES
guard-rspec
launchy
rspec-rails
spring!
terminal-notifier-guard
thin
4 changes: 2 additions & 2 deletions lib/formbuilder/entry_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(entry, form, opts = {})
end

def fields
return_fields = @form.response_fields.reject { |rf| !rf.field_class.input_field? }
return_fields = @form.response_fields.reject { |rf| !rf.input_field }
return_fields.reject! { |rf| rf.blind? } unless @options[:show_blind]
return_fields
end
Expand Down Expand Up @@ -41,7 +41,7 @@ def no_value

def field_value(rf)
value = @entry.response_value(rf)
rf.field_class.render_entry(rf, value, entry: @entry)
rf.render_entry(value, entry: @entry)
end
end
end
1 change: 0 additions & 1 deletion spec/factories/formbuilder_forms.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
FactoryGirl.define do
factory :form, class: Formbuilder::Form do

end

factory :kitchen_sink_form, parent: :form do
Expand Down
31 changes: 31 additions & 0 deletions spec/features/form_renderer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'spec_helper'
include SubmittingAnEntrySpecHelper

describe 'Rendering a form properly' do

subject { page }
let!(:form) { FactoryGirl.create(:form) }
let!(:entry) { e = Entry.new(form: form); e.save(validate: false); e }

context 'with a text field' do

before do
form.response_fields.create(label: "Text", type: "Formbuilder::ResponseFieldText", sort_order: 0)
visit form_path(form.id, entry.id)
end

it 'should render the field and its label' do
# label
# required?
# description
end

it 'should render errors'

it 'should render length validations'

it 'should render min/max validations'

end

end
27 changes: 26 additions & 1 deletion spec/lib/formbuilder/entry_renderer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@

describe Formbuilder::EntryRenderer do

pending
TEXT_FIELD_PARAMS = { label: "Text", type: "Formbuilder::ResponseFieldText", sort_order: 0 }

let(:form) { FactoryGirl.create(:form) }
let(:entry) { e = Entry.new(form: form); e.save(validate: false); e }

it 'should display a label for blind fields' do
form.response_fields.create TEXT_FIELD_PARAMS.merge(blind: true)
Formbuilder::EntryRenderer.new(entry, form, show_blind: true).to_html.should match('Blind')
end

it 'should only display blind fields when instructed to' do
form.response_fields.create TEXT_FIELD_PARAMS.merge(blind: true)
Formbuilder::EntryRenderer.new(entry, form).to_html.should_not match('Blind')
end

it 'should display a label for admin only fields' do
form.response_fields.create TEXT_FIELD_PARAMS.merge(admin_only: true)
Formbuilder::EntryRenderer.new(entry, form).to_html.should match('Admin Only')
end

it 'should display placeholder text if there is no response' do
form.response_fields.create TEXT_FIELD_PARAMS
Formbuilder::EntryRenderer.new(entry, form).to_html.should match('No response')
end

it 'should display the response'

end
2 changes: 1 addition & 1 deletion spec/lib/formbuilder/form_renderer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

describe Formbuilder::FormRenderer do

pending
# Intentionally blank, this gets tested w/ a feature spec

end

0 comments on commit 7f5321f

Please sign in to comment.