diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index 54b6d85d..25a97a0a 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -93,6 +93,8 @@ linters: - "app/views/admin/sponsors/index.html.haml" - "app/views/admin/sponsorship_levels/_form.html.haml" - "app/views/admin/sponsorship_levels/index.html.haml" + - "app/views/admin/surveys/index.html.haml" + - "app/views/admin/surveys/show.html.haml" - "app/views/admin/targets/_form.html.haml" - "app/views/admin/targets/index.html.haml" - "app/views/admin/tickets/_form.html.haml" @@ -161,6 +163,9 @@ linters: - "app/views/schedules/events.html.haml" - "app/views/schedules/show.html.haml" - "app/views/schedules/show.xml.haml" + - "app/views/surveys/*" + - "app/views/admin/surveys/*" + - "app/views/admin/survey_questions/*.html.haml" - "app/views/shared/_changelog_actions.haml" - "app/views/shared/_dynamic_association.html.haml" - "app/views/shared/_media_item.html.haml" @@ -210,6 +215,8 @@ linters: - "app/views/admin/splashpages/_form.html.haml" - "app/views/admin/sponsors/_form.html.haml" - "app/views/admin/sponsorship_levels/_form.html.haml" + - "app/views/admin/survey_questions/*" + - "app/views/admin/surveys/*" - "app/views/admin/tickets/_form.html.haml" - "app/views/admin/tracks/_form.html.haml" - "app/views/admin/users/_form.html.haml" @@ -447,3 +454,5 @@ linters: - "app/views/conferences/_gallery.html.haml" - "app/views/layouts/_navigation.html.haml" - "app/views/schedules/events.html.haml" + - "app/views/admin/survey_questions/*" + - "app/views/admin/surveys/*" diff --git a/app/controllers/admin/survey_questions_controller.rb b/app/controllers/admin/survey_questions_controller.rb index 2fb836c3..0ce9a6b6 100644 --- a/app/controllers/admin/survey_questions_controller.rb +++ b/app/controllers/admin/survey_questions_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class SurveyQuestionsController < Admin::BaseController load_and_authorize_resource :conference, find_by: :short_title diff --git a/app/controllers/admin/surveys_controller.rb b/app/controllers/admin/surveys_controller.rb index 81929d7a..ccc2243d 100644 --- a/app/controllers/admin/surveys_controller.rb +++ b/app/controllers/admin/surveys_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class SurveysController < Admin::BaseController load_and_authorize_resource :conference, find_by: :short_title @@ -17,7 +19,7 @@ module Admin if @survey.save redirect_to new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), notice: 'Successfully created survey' else - redirect_to new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), error: 'Could not create survey.' + @survey.errors.full_messates.to_sentence + redirect_to new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), error: 'Could not create survey.' + @survey.errors.full_messages.to_sentence end end diff --git a/app/controllers/surveys_controller.rb b/app/controllers/surveys_controller.rb index 303b9f25..5c0af57e 100644 --- a/app/controllers/surveys_controller.rb +++ b/app/controllers/surveys_controller.rb @@ -1,6 +1,10 @@ +# frozen_string_literal: true + class SurveysController < ApplicationController load_resource :conference, find_by: :short_title - load_and_authorize_resource + load_and_authorize_resource except: :reply + load_resource only: :reply + skip_authorization_check only: :reply def index @surveys = @conference.surveys.select(&:active?) @@ -11,6 +15,11 @@ class SurveysController < ApplicationController end def reply + unless can? :reply, @survey + redirect_to conference_survey_path(@conference, @survey), alert: 'This survey is currently closed' + return + end + survey_submission = params[:survey_submission] @survey.survey_questions.each do |survey_question| @@ -22,7 +31,13 @@ class SurveysController < ApplicationController else survey_question.survey_replies.create!(text: reply_text, user: current_user) end - @survey.survey_submissions.create!(user: current_user) unless @survey.survey_submissions.find_by(user: current_user) + + user_survey_submission = @survey.survey_submissions.find_by(user: current_user) + if user_survey_submission + user_survey_submission.update_attributes(updated_at: Time.current) + else + @survey.survey_submissions.create!(user: current_user) + end end redirect_to :back diff --git a/app/models/ability.rb b/app/models/ability.rb index ce7fe202..65615b4b 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -55,6 +55,8 @@ class Ability can [:show, :events], Schedule do |schedule| schedule.program.schedule_public end + + can [:index, :show], Survey, surveyable_type: 'Conference' end end @@ -104,8 +106,18 @@ class Ability # can manage the commercials of their own events can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id) - # can view and reply a survey - can [:show, :reply], Survey, surveyable_type: 'Conference', surveyable_id: user.registrations.pluck(:conference_id) + # can view and reply to a survey + can [:index, :show, :reply], Survey, surveyable_type: 'Conference' + can [:index, :show, :reply], Survey, surveyable_type: 'Registration', surveyable_id: user.registrations.pluck(:conference_id) + + # TODO: this needs to check for more, eg. + # if survey target is after_conference, check whether or not the conference is over + # if not, do not allow replies. + + # do not allow replies before the start_date or after the end_date of survey + cannot :reply, Survey do |survey| + survey.start_date > Time.current || survey.end_date < Time.current + end can [:destroy], Openid diff --git a/app/models/conference.rb b/app/models/conference.rb index adffe619..c33417e0 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -1235,4 +1235,3 @@ class Conference < ApplicationRecord result end end -# rubocop:enable Metrics/ClassLength diff --git a/app/models/event.rb b/app/models/event.rb index d6a163dd..3ed8b030 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -268,6 +268,18 @@ class Event < ApplicationRecord event_schedules.find_by(schedule_id: selected_schedule_id).try(:start_time) end + ## + # Returns true or false, if the event is already over or not + # + # ====Returns + # * +true+ -> If the event is over + # * +false+ -> If the event is not over yet + def ended? + event_schedule = event_schedules.find_by(schedule_id: selected_schedule_id) + return false unless event_schedule + event_schedule.end_time < Time.current + end + def conference program.conference end diff --git a/app/models/survey.rb b/app/models/survey.rb index 14975b55..e89aad41 100644 --- a/app/models/survey.rb +++ b/app/models/survey.rb @@ -1,12 +1,15 @@ +# frozen_string_literal: true + class Survey < ActiveRecord::Base belongs_to :surveyable, polymorphic: true - has_many :survey_questions - has_many :survey_submissions + has_many :survey_questions, dependent: :destroy + has_many :survey_submissions, dependent: :destroy enum target: [:after_conference, :during_registration] validates :title, presence: true def active? + return false unless start_date && end_date now = Time.now.in_time_zone(surveyable.timezone) now >= start_date && now <= end_date end diff --git a/app/models/survey_question.rb b/app/models/survey_question.rb index e7c3a019..7f3f7750 100644 --- a/app/models/survey_question.rb +++ b/app/models/survey_question.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + class SurveyQuestion < ActiveRecord::Base belongs_to :survey - has_many :survey_replies + has_many :survey_replies, dependent: :destroy # Order of this list should not be changed without proper action! enum kind: [:boolean, :choice, :string, :text, :datetime, :numeric] @@ -23,15 +25,15 @@ class SurveyQuestion < ActiveRecord::Base end def possible_answers=(value) - self[:possible_answers] = choice? ? value : nil + self[:possible_answers] = value if choice? end def min_choices=(value) - self[:min_choices] = choice? ? value : nil + self[:min_choices] = value if choice? end def max_choices=(value) - self[:max_choices] = choice? ? value : nil + self[:max_choices] = value if choice? end private diff --git a/app/models/survey_reply.rb b/app/models/survey_reply.rb index 1abca384..bfba843b 100644 --- a/app/models/survey_reply.rb +++ b/app/models/survey_reply.rb @@ -1,7 +1,10 @@ +# frozen_string_literal: true + class SurveyReply < ActiveRecord::Base belongs_to :user belongs_to :survey_question serialize :text + validates :user_id, :survey_question_id, presence: true validates :survey_question_id, uniqueness: { scope: :user_id } end diff --git a/app/models/survey_submission.rb b/app/models/survey_submission.rb index 997f6947..f31198d4 100644 --- a/app/models/survey_submission.rb +++ b/app/models/survey_submission.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class SurveySubmission < ActiveRecord::Base belongs_to :user belongs_to :survey diff --git a/app/views/admin/events/_datatable_row.haml b/app/views/admin/events/_datatable_row.haml index d4448a50..93f43d77 100644 --- a/app/views/admin/events/_datatable_row.haml +++ b/app/views/admin/events/_datatable_row.haml @@ -61,3 +61,8 @@ = link_to "#{event.comments_count}", admin_conference_program_event_path(conference_id, event), anchor: 'comments-div' + %td.text-center + = link_to new_admin_conference_survey_path(@conference.short_title, + survey: { surveyable_type: 'Event', surveyable_id: event.id }), + class: 'btn btn-success' do + .fa.fa-plus diff --git a/app/views/admin/survey_questions/_form.html.haml b/app/views/admin/survey_questions/_form.html.haml index 7cd7bbdb..2538c17c 100644 --- a/app/views/admin/survey_questions/_form.html.haml +++ b/app/views/admin/survey_questions/_form.html.haml @@ -17,7 +17,7 @@ .col-md-12 = f.input :title = f.input :mandatory - %div.survey-possible-answers{ class: @survey_question.choice? ? '' : 'hidden'} + .survey-possible-answers{ class: @survey_question.choice? ? '' : 'hidden' } = f.input :possible_answers, hint: 'Comma separated', input_html: { rows: 3 } .row .col-md-6 @@ -38,16 +38,16 @@ %label Preview: .panel.panel-default - .panel-body{id: 'survey_question_preview'} - %p{id: 'title', style: 'word-wrap: break-word'} + .panel-body{ id: 'survey_question_preview' } + %p{ id: 'title', style: 'word-wrap: break-word' } = @survey_question.title.blank? ? 'What is your answer?' : @survey_question.title - %div.kinds.boolean{ class: @survey_question.boolean? ? '' : 'hidden'} - %input{type: 'radio', name: 'radio'} Yes + .kinds.boolean{ class: @survey_question.boolean? ? '' : 'hidden' } + %input{ type: 'radio', name: 'radio' } Yes %br - %input{type: 'radio', name: 'radio'} No + %input{ type: 'radio', name: 'radio' } No - %div.kinds.choice{ id: '', class: @survey_question.choice? ? '' : 'hidden'} + .kinds.choice{ class: @survey_question.choice? ? '' : 'hidden' } - if @survey_question.possible_answers.blank? - if @survey_question.single_choice? %input{ type: 'radio', name: 'radio' } Choice 1 @@ -72,21 +72,21 @@ = option %br - %div.kinds.string{ class: @survey_question.string? ? '' : 'hidden'} + .kinds.string{ class: @survey_question.string? ? '' : 'hidden' } %input.form-control - %div.kinds.text{ class: @survey_question.text? ? '' : 'hidden'} + .kinds.text{ class: @survey_question.text? ? '' : 'hidden' } %textarea.form-control{ rows: 4 } - %div.kinds.datetime{ class: @survey_question.datetime? ? '' : 'hidden'} - .form-group{class: 'datetimepicker'} + .kinds.datetime{ class: @survey_question.datetime? ? '' : 'hidden' } + .form-group{ class: 'datetimepicker' } .input-group .input-group-addon %span.fa.fa-calendar - %input.form-control{readonly: 'readonly'} + %input.form-control{ readonly: 'readonly' } + .kinds.numeric{ class: @survey_question.numeric? ? '' : 'hidden' } - %div.kinds.numeric{ class: @survey_question.numeric? ? '' : 'hidden'} %input.form-control{ type: 'number' } = f.submit 'Save', class: 'btn btn-primary' diff --git a/app/views/admin/surveys/_survey_question.html.haml b/app/views/admin/surveys/_survey_question.html.haml index dcf81d40..bb7a54d3 100644 --- a/app/views/admin/surveys/_survey_question.html.haml +++ b/app/views/admin/surveys/_survey_question.html.haml @@ -1,31 +1,11 @@ .panel.panel-default .panel-heading - %span.badge - = question_index - = survey_question.title - - - if survey_question.multiple_choice? - ( Select - - if survey_question.min_choices != survey_question.max_choices - a minimum of - = survey_question.min_choices - - if survey_question.min_choices != survey_question.max_choices - and a maximum of - = survey_question.max_choices - choices ) - - if survey_question.mandatory - %span.fa.fa-asterisk.text-danger - - if can? :edit, @survey - %p.pull-right - = link_to edit_admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question) do - %span.fa.fa-edit - = link_to admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question), method: :delete, data: { confirm: 'Are you sure you want to delete this question?' } do - %span.fa.fa-times + = render partial: 'admin/surveys/survey_question_title', locals: { survey_question: survey_question, question_index: question_index } .panel-body - if survey_question.boolean? %input{ type: 'hidden', name: "survey_submission[#{survey_question.id}][]" } %label - %input{ type: 'radio', name: "survey_submission[#{survey_question.id}][]", value: 'Yes', checked: survey_reply.text == 'Yes' } + %input{ type: 'radio', name: "survey_submission[#{survey_question.id}][]", value: 'Yes', checked: survey_reply.text == 'Yes',required: survey_question.mandatory } Yes %br %label @@ -39,24 +19,24 @@ - possible_answers.each.with_index(1) do |answer, answer_index| - if survey_question.single_choice? %label - %input{ type: 'radio', name: "survey_submission[#{survey_question.id}][]", value: answer, checked: (survey_reply.text.include? answer if survey_reply.text) } + %input{ type: 'radio', name: "survey_submission[#{survey_question.id}][]", value: answer, checked: (survey_reply.text == answer if survey_reply.text), required: survey_question.mandatory } = answer %br - else %label - = check_box_tag "survey_submission[#{survey_question.id}][]", answer, (survey_reply.text.include? answer if survey_reply.text), id: dom_id(survey_reply) + = check_box_tag "survey_submission[#{survey_question.id}][]", answer, (survey_reply.text.include? answer if survey_reply.text), id: dom_id(survey_reply), required: survey_question.mandatory = answer %br - elsif survey_question.string? - %input.form-control{ name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text } + %input.form-control{ name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text, required: survey_question.mandatory } - elsif survey_question.text? - = text_area_tag "survey_submission[#{survey_question.id}][]", survey_reply.text, rows: 4, class: 'form-control' + = text_area_tag "survey_submission[#{survey_question.id}][]", survey_reply.text, rows: 4, class: 'form-control', required: survey_question.mandatory - elsif survey_question.datetime? .form-group{ class: 'datetimepicker' } .input-group .input-group-addon %span.fa.fa-calendar - %input.form-control{ readonly: 'readonly', name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text } + %input.form-control{ readonly: 'readonly', name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text, required: survey_question.mandatory } - elsif survey_question.numeric? - %input.form-control{ type: 'number', name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text } + %input.form-control{ type: 'number', name: "survey_submission[#{survey_question.id}][]", value: survey_reply.text, required: survey_question.mandatory } diff --git a/app/views/admin/surveys/_survey_question_body.html.haml b/app/views/admin/surveys/_survey_question_body.html.haml new file mode 100644 index 00000000..e69de29b diff --git a/app/views/admin/surveys/_survey_question_title.html.haml b/app/views/admin/surveys/_survey_question_title.html.haml new file mode 100644 index 00000000..4fd0f421 --- /dev/null +++ b/app/views/admin/surveys/_survey_question_title.html.haml @@ -0,0 +1,22 @@ +%span.badge + = question_index += survey_question.title + +- if survey_question.multiple_choice? + ( Select + - if survey_question.min_choices != survey_question.max_choices + a minimum of + = survey_question.min_choices + - if survey_question.min_choices != survey_question.max_choices + and a maximum of + = survey_question.max_choices + choices ) +- if survey_question.mandatory + %span.fa.fa-asterisk.text-danger +- if can? :edit, @survey + %p.pull-right + = "(#{survey_question.survey_replies.count} replies)" + = link_to edit_admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question) do + %span.fa.fa-edit + = link_to admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question), method: :delete, data: { confirm: 'Are you sure you want to delete this question?' } do + %span.fa.fa-times diff --git a/app/views/admin/surveys/_survey_replies.html.haml b/app/views/admin/surveys/_survey_replies.html.haml new file mode 100644 index 00000000..8ce5d809 --- /dev/null +++ b/app/views/admin/surveys/_survey_replies.html.haml @@ -0,0 +1,16 @@ +- @survey.survey_questions.each.with_index(1) do |survey_question, question_index| + .panel.panel-default + .panel-heading{ type: 'button', 'data-toggle': 'collapse', 'data-target': "#question-#{survey_question.id}", 'aria-expanded': 'true', 'aria-controls': 'collapse' } + = render partial: 'survey_question_title', locals: { survey_question: survey_question, question_index: question_index } + + .panel-body.collapse{ id: "question-#{survey_question.id}" } + - if survey_question.survey_replies.any? + %table.table + %thead + %th User Email + %th Reply + %tbody + - survey_question.survey_replies.reload.each do |reply| + %tr + %td= reply.user.email + %td= reply.text diff --git a/app/views/admin/surveys/_survey_stats.html.haml b/app/views/admin/surveys/_survey_stats.html.haml new file mode 100644 index 00000000..b9336f4a --- /dev/null +++ b/app/views/admin/surveys/_survey_stats.html.haml @@ -0,0 +1,13 @@ += javascript_include_tag "//www.google.com/jsapi", "chartkick" += javascript_include_tag 'chartkick' + += bar_chart @survey.survey_questions.map{ |q| [q.title, q.survey_replies.count] } + +- @survey.survey_questions.each.with_index(1) do |survey_question, question_index| + .panel.panel-default + .panel-heading + = render partial: 'survey_question_title', locals: { survey_question: survey_question, question_index: question_index } + .panel-body + - question_replies = survey_question.survey_replies + - if question_replies.any? + = pie_chart question_replies.group(:text).count, library: { legend: 'bottom', plotOptions: { pie: { dataLabels: { enabled: false }, showInLegend: true } } } diff --git a/app/views/admin/surveys/index.html.haml b/app/views/admin/surveys/index.html.haml index 2c561e83..ff3e9b0b 100644 --- a/app/views/admin/surveys/index.html.haml +++ b/app/views/admin/surveys/index.html.haml @@ -14,6 +14,8 @@ %table.table.table-hover.datatable#surveys %thead %th Title + %th # of questions + %th # of submissions %th When %th Start Date %th End Date @@ -23,6 +25,10 @@ %tr %td = link_to survey.title, admin_conference_survey_path(@conference.short_title, survey) + %td + = survey.survey_questions.length + %td + = survey.survey_submissions.length %td = survey.target %td diff --git a/app/views/admin/surveys/show.html.haml b/app/views/admin/surveys/show.html.haml index 8a49b463..27f8b2c8 100644 --- a/app/views/admin/surveys/show.html.haml +++ b/app/views/admin/surveys/show.html.haml @@ -11,10 +11,24 @@ = @survey.end_date .row .col-md-12 - = semantic_form_for 'survey_submission', url: '#' do |f| - - @survey.survey_questions.each.with_index(1) do |survey_question, question_index| - .row - .col-md-12 - - survey_reply = survey_question.survey_replies.new(survey_question_id: survey_question.id, user_id: current_user.id) - = render partial: 'survey_question', locals: { survey_question: survey_question, question_index: question_index, survey_reply: survey_reply } - = link_to 'Add Question', new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), class: 'btn btn-success pull-right' + .tabbable + %ul.nav.nav-tabs + %li.active + = link_to 'Questions' , '#questions-content', 'data-toggle' => 'tab' + %li + = link_to 'Replies' , '#replies-content', 'data-toggle' => 'tab' + %li + = link_to 'Stats' , '#stats-content', 'data-toggle' => 'tab' + .tab-content + .tab-pane.active#questions-content + = semantic_form_for 'survey_submission', url: '#' do |f| + - @survey.survey_questions.each.with_index(1) do |survey_question, question_index| + .row + .col-md-12 + - survey_reply = survey_question.survey_replies.new(survey_question_id: survey_question.id, user_id: current_user.id) + = render partial: 'survey_question', locals: { survey_question: survey_question, question_index: question_index, survey_reply: survey_reply } + = link_to 'Add Question', new_admin_conference_survey_survey_question_path(@conference.short_title, @survey), class: 'btn btn-success pull-right' + .tab-pane#replies-content + = render partial: 'survey_replies' + .tab-pane#stats-content + = render partial: 'survey_stats' diff --git a/app/views/surveys/show.html.haml b/app/views/surveys/show.html.haml index 5d7b85eb..2efe7a65 100644 --- a/app/views/surveys/show.html.haml +++ b/app/views/surveys/show.html.haml @@ -10,15 +10,19 @@ = @survey.start_date to = @survey.end_date - + - unless @survey.active? + %label + %i.fa.fa-exclamation-circle + This survey does not accept replies at this monent. .row .col-md-12 = semantic_form_for @survey_submission, url: reply_conference_survey_path(@conference.short_title, @survey) do |f| - @survey.survey_questions.each.with_index(1) do |survey_question, question_index| .row .col-md-10.col-md-offset-1 - - survey_reply = survey_question.survey_replies.find_by(user: current_user) || SurveyReply.new(survey_question_id: survey_question.id, user_id: current_user.id) + - survey_reply = survey_question.survey_replies.find_by(user: current_user) || SurveyReply.new(survey_question_id: survey_question.id, user: current_user) = render partial: 'admin/surveys/survey_question', locals: { survey_question: survey_question, question_index: question_index, survey_reply: survey_reply } + .row .col-md-10.col-md-offset-1 - = f.submit 'Submit', class: 'btn btn-primary pull-right' + = f.submit 'Submit', class: 'btn btn-primary pull-right', disabled: !(can? :reply, @survey) diff --git a/db/migrate/20160627122446_create_surveys.rb b/db/migrate/20160627122446_create_surveys.rb index 8a57053c..ca7f52ea 100644 --- a/db/migrate/20160627122446_create_surveys.rb +++ b/db/migrate/20160627122446_create_surveys.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateSurveys < ActiveRecord::Migration def change create_table :surveys do |t| diff --git a/db/migrate/20160628093634_create_survey_questions.rb b/db/migrate/20160628093634_create_survey_questions.rb index 233a7f4d..63020a7d 100644 --- a/db/migrate/20160628093634_create_survey_questions.rb +++ b/db/migrate/20160628093634_create_survey_questions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateSurveyQuestions < ActiveRecord::Migration def change create_table :survey_questions do |t| diff --git a/db/migrate/20160629145954_add_target_to_surveys.rb b/db/migrate/20160629145954_add_target_to_surveys.rb index 16c10b8d..385ea38a 100644 --- a/db/migrate/20160629145954_add_target_to_surveys.rb +++ b/db/migrate/20160629145954_add_target_to_surveys.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddTargetToSurveys < ActiveRecord::Migration def change add_column :surveys, :target, :integer, default: 0 diff --git a/db/migrate/20160630094850_create_survey_replies.rb b/db/migrate/20160630094850_create_survey_replies.rb index 3b8917de..8e8d43a2 100644 --- a/db/migrate/20160630094850_create_survey_replies.rb +++ b/db/migrate/20160630094850_create_survey_replies.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateSurveyReplies < ActiveRecord::Migration def change create_table :survey_replies do |t| diff --git a/db/migrate/20160630130731_create_survey_submissions.rb b/db/migrate/20160630130731_create_survey_submissions.rb index bcab5271..a64c4e5d 100644 --- a/db/migrate/20160630130731_create_survey_submissions.rb +++ b/db/migrate/20160630130731_create_survey_submissions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateSurveySubmissions < ActiveRecord::Migration def change create_table :survey_submissions do |t| diff --git a/lib/tasks/demo_data_for_development.rake b/lib/tasks/demo_data_for_development.rake index e65fa80e..13b7fdfb 100644 --- a/lib/tasks/demo_data_for_development.rake +++ b/lib/tasks/demo_data_for_development.rake @@ -7,8 +7,8 @@ namespace :data do task surveys: :environment do conference = create(:full_conference, start_date: Date.current, end_date: Date.current + 1.day) survey_after_conference_active = create(:survey, surveyable: conference, target: :after_conference, title: 'Survey about the conference', start_date: conference.start_date - 1.day, end_date: conference.end_date + 5.days, description: 'Survey about the conference. You can already see it.') - survey_after_conference_inactive = create(:survey, surveyable: conference, target: :after_conference, title: 'Survey about the conference', start_date: conference.start_date + 1.day, end_date: conference.end_date + 5.days, description: 'Survey abou the conference. Not available yet!') - survey_on_registration = create(:survey, surveyable: conference, target: :during_registration, title: 'Survey during registation', start_date: conference.registration_period.start_date, end_date: conference.registration_period.end_date, description: 'Survey during registration.') + # survey_after_conference_inactive = create(:survey, surveyable: conference, target: :after_conference, title: 'Survey about the conference', start_date: conference.start_date + 1.day, end_date: conference.end_date + 5.days, description: 'Survey abou the conference. Not available yet!') + # survey_on_registration = create(:survey, surveyable: conference, target: :during_registration, title: 'Survey during registation', start_date: conference.registration_period.start_date, end_date: conference.registration_period.end_date, description: 'Survey during registration.') create(:boolean_non_mandatory, survey: survey_after_conference_active) create(:boolean_mandatory, survey: survey_after_conference_active) diff --git a/spec/controllers/surveys_controller_spec.rb b/spec/controllers/surveys_controller_spec.rb index 0b08bc75..fb62de8e 100644 --- a/spec/controllers/surveys_controller_spec.rb +++ b/spec/controllers/surveys_controller_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe SurveysController do diff --git a/spec/factories/survey_questions.rb b/spec/factories/survey_questions.rb index b3e2240f..7e8bda5c 100644 --- a/spec/factories/survey_questions.rb +++ b/spec/factories/survey_questions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryGirl.define do factory :survey_question do survey diff --git a/spec/factories/survey_replies.rb b/spec/factories/survey_replies.rb index 54ce3744..46114e51 100644 --- a/spec/factories/survey_replies.rb +++ b/spec/factories/survey_replies.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryGirl.define do factory :survey_reply do user diff --git a/spec/factories/survey_submissions.rb b/spec/factories/survey_submissions.rb index ad4a2dd4..26aec771 100644 --- a/spec/factories/survey_submissions.rb +++ b/spec/factories/survey_submissions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryGirl.define do factory :survey_submission do user diff --git a/spec/factories/surveys.rb b/spec/factories/surveys.rb index b4303b84..2d1b785f 100644 --- a/spec/factories/surveys.rb +++ b/spec/factories/surveys.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryGirl.define do factory :survey do title 'This is my survey' diff --git a/spec/models/survey_question_spec.rb b/spec/models/survey_question_spec.rb index 7151a889..0f86950d 100644 --- a/spec/models/survey_question_spec.rb +++ b/spec/models/survey_question_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe SurveyQuestion do @@ -7,7 +9,7 @@ describe SurveyQuestion do let(:single_choice_question) { create(:choice_mandatory_1_reply) } let(:multiple_choice_question) { create(:choice_mandatory_2_replies) } - let(:boolean_question) { create(:boolean_question, min_choices: 3)} + let(:boolean_question) { create(:boolean_question, min_choices: 3) } describe 'association' do it { is_expected.to belong_to(:survey) } @@ -88,7 +90,7 @@ describe SurveyQuestion do end end - fields = ['min_choices', 'max_choices', 'possible_answers'] + fields = %w[min_choices max_choices possible_answers] (SurveyQuestion.kinds.keys - ['choice']).each do |kind| fields.each do |field| it_behaves_like 'is nil', kind, field diff --git a/spec/models/survey_reply_spec.rb b/spec/models/survey_reply_spec.rb index 0c340c83..358fa134 100644 --- a/spec/models/survey_reply_spec.rb +++ b/spec/models/survey_reply_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe SurveyReply do diff --git a/spec/models/survey_spec.rb b/spec/models/survey_spec.rb index caed4264..12a87c67 100644 --- a/spec/models/survey_spec.rb +++ b/spec/models/survey_spec.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + require 'spec_helper' describe Survey do subject { create(:survey) } let(:survey_active) { create(:conference_survey, start_date: Date.current - 1.day, end_date: Date.current + 1.day) } - let(:survey_inactive) { create(:conference_survey, start_date: Date.current - 2.day, end_date: Date.current - 1.day) } + let(:survey_inactive) { create(:conference_survey, start_date: Date.current - 2.days, end_date: Date.current - 1.day) } describe 'association' do it { is_expected.to have_many(:survey_questions) } @@ -17,12 +19,8 @@ describe Survey do describe '#active?' do it { expect(survey_active.active?).to eq true } it { expect(survey_inactive.active?).to eq false } - it 'returns false, if start_date is not set' do - expect(create(:survey, start_date: nil, end_date: Date.current + 1.day).active?).to eq false - end - - it 'returns false, if end_date is not set' do - expect(create(:survey, start_date: Date.current + 1.day, end_date: nil).active?).to eq false + it 'returns true, if both start_date and end_date are not set' do + expect(create(:survey, start_date: nil, end_date: nil, surveyable: create(:conference)).active?).to eq true end end end diff --git a/spec/models/survey_submission_spec.rb b/spec/models/survey_submission_spec.rb index fdf3ca4f..e24f644c 100644 --- a/spec/models/survey_submission_spec.rb +++ b/spec/models/survey_submission_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe SurveySubmission do