Sha256: 33e0e348ca9817c174fe10901ebc5cdd6f06158fb46c84051c752460336eb06d

Contents?: true

Size: 994 Bytes

Versions: 15

Compression:

Stored size: 994 Bytes

Contents

puts "Running effective_polls seeds"

Effective::Poll.all.each { |poll| poll.destroy! }

Effective::Ballot.delete_all

def build_effective_poll
  poll = Effective::Poll.new(
    title: 'Effective Poll',
    start_at: (Time.zone.now + 1.day).beginning_of_day,
    end_at: (Time.zone.now + 1.day).end_of_day,
    audience: 'All Users',
    audience_class_name: 'User'
  )

  build_poll_question(poll, Effective::PollQuestion::CATEGORIES)

  poll.save!
  poll
end

def build_poll_question(poll, category)
  questions = Array(category).map.with_index do |category, index|
    question = poll.poll_questions.build(title: "#{category} Question ##{index+1}", category: category)

    if question.poll_question_option?
      question.poll_question_options.build(title: 'Option A')
      question.poll_question_options.build(title: 'Option B')
      question.poll_question_options.build(title: 'Option C')
    end
  end

  questions.length == 1 ? questions.first : questions
end

build_effective_poll()

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
effective_polls-0.7.2 db/seeds.rb
effective_polls-0.7.1 db/seeds.rb
effective_polls-0.7.0 db/seeds.rb
effective_polls-0.6.2 db/seeds.rb
effective_polls-0.6.1 db/seeds.rb
effective_polls-0.6.0 db/seeds.rb
effective_polls-0.5.6 db/seeds.rb
effective_polls-0.5.5 db/seeds.rb
effective_polls-0.5.4 db/seeds.rb
effective_polls-0.5.3 db/seeds.rb
effective_polls-0.5.2 db/seeds.rb
effective_polls-0.5.1 db/seeds.rb
effective_polls-0.5.0 db/seeds.rb
effective_polls-0.4.1 db/seeds.rb
effective_polls-0.4.0 db/seeds.rb