Add task to populate demo data for surveys

This commit is contained in:
Stella Rouzi 2017-10-12 16:18:48 +03:00
parent 9f3c0eff5d
commit 68a8ec2204
3 changed files with 113 additions and 19 deletions

View file

@ -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')

View file

@ -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)