diff --git a/plugins/custom_forms/lib/custom_forms_plugin/form.rb b/plugins/custom_forms/lib/custom_forms_plugin/form.rb index 8225c7d..0eed935 100644 --- a/plugins/custom_forms/lib/custom_forms_plugin/form.rb +++ b/plugins/custom_forms/lib/custom_forms_plugin/form.rb @@ -43,6 +43,10 @@ class CustomFormsPlugin::Form < Noosfero::Plugin::ActiveRecord (begining.present? && Time.now < begining) || (ending.present? && Time.now > ending) end + def will_open? + begining.present? && Time.now < begining + end + def accessible_to(target) return true if access.nil? || target == profile return false if target.nil? diff --git a/plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb b/plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb index f5f0d69..237ca95 100644 --- a/plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb +++ b/plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb @@ -35,7 +35,23 @@ class CustomFormsPluginProfileControllerTest < ActionController::TestCase get :show, :profile => profile.identifier, :id => form.id - assert_tag :tag => 'h2', :content => 'Sorry, you can\'t fill this form right now' assert_tag :tag => 'input', :attributes => {:disabled => 'disabled'} end + + should 'show expired message' do + form = CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software', :begining => Time.now + 1.day) + form.fields << CustomFormsPlugin::TextField.create(:name => 'Field Name', :form => form, :default_value => "First Field") + + get :show, :profile => profile.identifier, :id => form.id + + assert_tag :tag => 'h2', :content => 'Sorry, you can\'t fill this form yet' + + form.begining = Time.now - 2.days + form.ending = Time.now - 1.days + form.save + + get :show, :profile => profile.identifier, :id => form.id + + assert_tag :tag => 'h2', :content => 'Sorry, you can\'t fill this form anymore' + end end diff --git a/plugins/custom_forms/test/unit/custom_forms_plugin/form_test.rb b/plugins/custom_forms/test/unit/custom_forms_plugin/form_test.rb index bee84c0..f44f1ca 100644 --- a/plugins/custom_forms/test/unit/custom_forms_plugin/form_test.rb +++ b/plugins/custom_forms/test/unit/custom_forms_plugin/form_test.rb @@ -89,6 +89,22 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase assert !form.expired? end + should 'define if form will still open' do + form = CustomFormsPlugin::Form.new + assert !form.will_open? + + form.begining = Time.now + 1.day + assert form.will_open? + + form.begining = Time.now - 1.day + assert !form.will_open? + + form.begining = Time.now - 2.day + form.ending = Time.now - 1.day + assert form.expired? + assert !form.will_open? + end + should 'validates format of access' do form = CustomFormsPlugin::Form.new form.valid? diff --git a/plugins/custom_forms/views/custom_forms_plugin_profile/show.html.erb b/plugins/custom_forms/views/custom_forms_plugin_profile/show.html.erb index 1bd7174..8d99864 100644 --- a/plugins/custom_forms/views/custom_forms_plugin_profile/show.html.erb +++ b/plugins/custom_forms/views/custom_forms_plugin_profile/show.html.erb @@ -3,7 +3,11 @@ <% if @submission.id.nil? %> <% if @form.expired? %> -
<%= @form.description %>
<% if @form.expired? %> -