From 68a8ec22049352afeec8850bd79304bbfb8ab79d Mon Sep 17 00:00:00 2001 From: Stella Rouzi Date: Thu, 12 Oct 2017 16:18:48 +0300 Subject: [PATCH] Add task to populate demo data for surveys --- lib/tasks/data_demo.rake | 2 +- lib/tasks/demo_data_for_development.rake | 38 +++++----- spec/factories/survey_questions.rb | 92 ++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 19 deletions(-) diff --git a/lib/tasks/data_demo.rake b/lib/tasks/data_demo.rake index dd5c17ea..4683a3c4 100644 --- a/lib/tasks/data_demo.rake +++ b/lib/tasks/data_demo.rake @@ -2,9 +2,9 @@ namespace :data do desc 'Create demo data using our factories' + task demo: :environment do include FactoryGirl::Syntax::Methods - conference = create(:full_conference, title: 'Open Source Event Manager Demo', short_title: 'osemdemo' ,description: "This is a [Open Source Event Manager](http://osem.io/) demo instance. You can log in as **admin** with the password **password123** or just you just [sign up](/accounts/sign_up) with your own user. We hope you enjoy checking out all the functionality, if you have questions don't hesitate to [contact us](http://osem.io/#contact)!\r\n\r\n## Data will be destroyed every thirty minutes or whenever someone updates the [OSEM source code on github](https://github.com/openSUSE/osem/commits/master).") conference.contact.update_attributes(email: 'osemdemo@osem.io', sponsor_email: 'osemdemo@osem.io') create(:admin, email: 'admin@osem.io', username: 'admin', password: 'password123', password_confirmation: 'password123') diff --git a/lib/tasks/demo_data_for_development.rake b/lib/tasks/demo_data_for_development.rake index dac1967d..e65fa80e 100644 --- a/lib/tasks/demo_data_for_development.rake +++ b/lib/tasks/demo_data_for_development.rake @@ -2,29 +2,31 @@ namespace :data do desc 'Create demo data for our local development' + include FactoryGirl::Syntax::Methods - task survey: :environment do - include FactoryGirl::Syntax::Methods + 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.') - conference = Conference.find_by(short_title: 'conf_with_survey') || create(:full_conference, short_title: 'conf_with_survey', start_date: Date.today) - # active survey - survey_after_conference_active = create(:survey, surveyable: conference, target: 0, title: 'Survey about the conference', start_date: conference.start_date - 1.day, end_date: conference.end_date + 5.days ) - # inactive survey (will be available in 1 day) - survey_after_conference_active = create(:survey, surveyable: conference, target: 0, title: 'Survey about the conference', start_date: conference.start_date + 1.day, end_date: conference.end_date + 5.days ) - survey_on_registration = create(:survey, surveyable: conference, target: 1, title: 'Survey during registation', start_date: conference.registration_period.start_date, end_date: conference.registration_period.end_date ) - # boolean - create(:survey_question, survey: survey_after_conference, title: 'Did you like this conference?', kind: 0) - # single choice - create(:survey_question, survey: survey_after_conference, title: 'Which keynote did you like best?', kind: 1, min_choices: 1, max_choices: 1, possible_answers: 'Yes, No') - # string - create(:survey_question, survey: survey_after_conference, title: 'What did you like the most about this conference?', kind: 2) - # text - create(:survey_question, survey: survey_after_conference, title: 'Anything else you would like to share with us?', kind: 3) + create(:boolean_non_mandatory, survey: survey_after_conference_active) + create(:boolean_mandatory, survey: survey_after_conference_active) + create(:choice_mandatory_1_reply, survey: survey_after_conference_active) + create(:choice_non_mandatory_1_reply, survey: survey_after_conference_active) + create(:choice_mandatory_2_replies, survey: survey_after_conference_active) + create(:choice_non_mandatory_2_replies, survey: survey_after_conference_active) + create(:string_mandatory, survey: survey_after_conference_active) + create(:string_non_mandatory, survey: survey_after_conference_active) + create(:text_mandatory, survey: survey_after_conference_active) + create(:text_non_mandatory, survey: survey_after_conference_active) + create(:datetime_mandatory, survey: survey_after_conference_active) + create(:datetime_non_mandatory, survey: survey_after_conference_active) + create(:numeric_mandatory, survey: survey_after_conference_active) + create(:numeric_non_mandatory, survey: survey_after_conference_active) end task test: :environment do - include FactoryGirl::Syntax::Methods - def generate_program conference program = conference.program user1 = create(:user) diff --git a/spec/factories/survey_questions.rb b/spec/factories/survey_questions.rb index 20db184b..0f7cd271 100644 --- a/spec/factories/survey_questions.rb +++ b/spec/factories/survey_questions.rb @@ -2,5 +2,97 @@ FactoryGirl.define do factory :survey_question do survey title 'What about this question?' + + factory :boolean_non_mandatory do + title 'Have you attended the conference before? (Non mandatory)' + kind :boolean + end + + factory :boolean_mandatory do + title 'Did you attend the info talk about the conference? (Mandatory)' + kind :boolean + mandatory true + end + + # radio buttons + factory :choice_mandatory_1_reply do + title 'Choice question with only 1 answer (Mandatory)?' + kind :choice + min_choices 1 + max_choices 1 + possible_answers 'A, B, C' + mandatory true + end + + factory :choice_non_mandatory_1_reply do + title 'Choice question with only 1 answer (Non mandatory)' + kind :choice + min_choices 1 + max_choices 1 + possible_answers 'A, B, C' + end + + # checkboxes + factory :choice_mandatory_2_replies do + title 'Choice question with 2 replies (Mandatory)?' + kind :choice + min_choices 2 + max_choices 2 + possible_answers 'A, B, C' + mandatory true + end + + # checkboxes + factory :choice_non_mandatory_2_replies do + title 'Choice question with 2 replies (Non mandatory)?' + kind :choice + min_choices 2 + max_choices 2 + possible_answers 'A, B, C' + end + + factory :string_mandatory do + title 'String question (Mandatory)?' + kind :string + mandatory true + end + + factory :string_non_mandatory do + title 'String question (Non mandatory)?' + kind :string + end + + factory :text_mandatory do + title 'Text question (Mandatory)?' + kind :text + mandatory true + end + + factory :text_non_mandatory do + title 'Text question (Non mandatory)?' + kind :text + end + + factory :datetime_mandatory do + title 'Datetime question (Mandatory)?' + kind :datetime + mandatory true + end + + factory :datetime_non_mandatory do + title 'Datetime question (Non mandatory)?' + kind :datetime + end + + factory :numeric_mandatory do + title 'Numeric question (Mandatory)?' + kind :numeric + mandatory true + end + + factory :numeric_non_mandatory do + title 'Numeric question (Non mandatory)?' + kind :numeric + end end end