public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Petteri Räty" <betelgeuse@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/council-webapp:master commit in: site/db/
Date: Thu, 21 Jul 2011 16:06:32 +0000 (UTC)	[thread overview]
Message-ID: <c531d629ebe56626b5263a96417701093dabf652.betelgeuse@gentoo> (raw)

commit:     c531d629ebe56626b5263a96417701093dabf652
Author:     Joachim Filip Ignacy Bartosik <jbartosik <AT> gmail <DOT> com>
AuthorDate: Tue Jul 12 11:51:52 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Wed Jul 13 16:12:09 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/council-webapp.git;a=commit;h=c531d629

Seed database for demos

---
 site/db/seed.yml |   42 ++++++++++++++++++++++++++++++++++++++++++
 site/db/seeds.rb |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 88 insertions(+), 0 deletions(-)

diff --git a/site/db/seed.yml b/site/db/seed.yml
new file mode 100644
index 0000000..df649e8
--- /dev/null
+++ b/site/db/seed.yml
@@ -0,0 +1,42 @@
+-
+  state: open
+  agenda_items:
+    -
+      title:  What shall we do with drunken sailor
+      body:   Earl-aye in the morning?
+      voting_options:
+                      - Shave his belly with a rusty razor
+                      - "Put him in the long boat till he's sober"
+                      - Put him in the scuppers with a hose-pipe on him
+                      - "Put him in bed with the captain's daughter"
+    -
+      title:  Some proposal
+      body:   Description of some proposal
+      voting_options:
+                      - Accept
+                      - Reject
+-
+  state: old
+  agenda_items:
+    -
+      title:  Accepted item
+      body:   Some item that was acepted on previous meeting
+      voting_options:
+                      - Accept
+                      - Reject
+    -
+      title:  Rejected item
+      body:   Some item that was rejected on previous meeting
+      voting_options:
+                      - Accept
+                      - Reject
+-
+  agenda_items:
+    -
+      title:  Pending idea
+      body:   Some idea that was neither added to agenda nor rejected.
+      rejected: false
+    -
+      title:    Rejected idea
+      body:     Some idea that council rejected to discuss on.
+      rejected: true

diff --git a/site/db/seeds.rb b/site/db/seeds.rb
new file mode 100644
index 0000000..f276aa6
--- /dev/null
+++ b/site/db/seeds.rb
@@ -0,0 +1,46 @@
+require File.expand_path("../../spec/factories.rb", __FILE__)
+require File.expand_path("../../spec/support/users_factory.rb", __FILE__)
+
+def vote(user, item, option_description)
+  option = VotingOption.agenda_item_is(item).description_is(option_description).first
+  Factory(:vote, :voting_option => option, :user => user, :council_vote => true)
+end
+
+def make_votes(council, item_title, accepting_votes)
+  item = AgendaItem.find_by_title(item_title)
+  council.inject(0) do |counter, user|
+    if counter < accepting_votes
+      vote(user, item, "Accept")
+    else
+      vote(user, item, "Reject")
+    end
+    counter += 1
+  end
+end
+
+yml_seed_path = File.expand_path("../seed.yml", __FILE__)
+yml_seed_file = File.open(yml_seed_path)
+seed = YAML::load(yml_seed_file)
+
+seed.each do |agenda_desc|
+  state = agenda_desc['state']
+  agenda = state.nil? ? nil : Factory(:agenda, :state => state)
+
+  agenda_desc['agenda_items']._?.each do |item_desc|
+    rejected = item_desc['rejected']
+    rejected = rejected.nil? ? false : rejected
+    item = Factory(:agenda_item, :title => item_desc['title'],
+                            :body => item_desc['body'],
+                            :rejected => rejected,
+                            :agenda => agenda)
+
+    item_desc['voting_options']._?.each do |option_desc|
+      Factory(:voting_option, :description => option_desc, :agenda_item => item)
+    end
+  end
+end
+
+council = users_factory([:council] * 7)
+
+make_votes(council, "Accepted item", 5)
+make_votes(council, "Rejected item", 3)



                 reply	other threads:[~2011-07-21 16:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c531d629ebe56626b5263a96417701093dabf652.betelgeuse@gentoo \
    --to=betelgeuse@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox