From 7f5321fde55e6f50b31e7a30fbb66f2fd314eba4 Mon Sep 17 00:00:00 2001 From: adamjacobbecker Date: Thu, 26 Sep 2013 11:46:09 -0400 Subject: [PATCH] specz --- Gemfile | 3 ++ Gemfile.lock | 7 +++++ lib/formbuilder/entry_renderer.rb | 4 +-- spec/factories/formbuilder_forms.rb | 1 - spec/features/form_renderer_spec.rb | 31 +++++++++++++++++++++ spec/lib/formbuilder/entry_renderer_spec.rb | 27 +++++++++++++++++- spec/lib/formbuilder/form_renderer_spec.rb | 2 +- 7 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 spec/features/form_renderer_spec.rb diff --git a/Gemfile b/Gemfile index d4857fd..6ad3d09 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 6a39c21..8ee54c2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,9 @@ +GIT + remote: git://github.com/jonleighton/spring.git + revision: 38214cfd773daaa3345604743f795271824dcf49 + specs: + spring (0.0.10) + PATH remote: . specs: @@ -186,5 +192,6 @@ DEPENDENCIES guard-rspec launchy rspec-rails + spring! terminal-notifier-guard thin diff --git a/lib/formbuilder/entry_renderer.rb b/lib/formbuilder/entry_renderer.rb index 2747f19..515d5ca 100644 --- a/lib/formbuilder/entry_renderer.rb +++ b/lib/formbuilder/entry_renderer.rb @@ -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 @@ -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 diff --git a/spec/factories/formbuilder_forms.rb b/spec/factories/formbuilder_forms.rb index 72624e2..3a95b60 100644 --- a/spec/factories/formbuilder_forms.rb +++ b/spec/factories/formbuilder_forms.rb @@ -1,6 +1,5 @@ FactoryGirl.define do factory :form, class: Formbuilder::Form do - end factory :kitchen_sink_form, parent: :form do diff --git a/spec/features/form_renderer_spec.rb b/spec/features/form_renderer_spec.rb new file mode 100644 index 0000000..5195b75 --- /dev/null +++ b/spec/features/form_renderer_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/lib/formbuilder/entry_renderer_spec.rb b/spec/lib/formbuilder/entry_renderer_spec.rb index d29af7a..b0564ef 100644 --- a/spec/lib/formbuilder/entry_renderer_spec.rb +++ b/spec/lib/formbuilder/entry_renderer_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/lib/formbuilder/form_renderer_spec.rb b/spec/lib/formbuilder/form_renderer_spec.rb index a98ac1e..0db3574 100644 --- a/spec/lib/formbuilder/form_renderer_spec.rb +++ b/spec/lib/formbuilder/form_renderer_spec.rb @@ -2,6 +2,6 @@ describe Formbuilder::FormRenderer do - pending + # Intentionally blank, this gets tested w/ a feature spec end \ No newline at end of file