aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetteri Räty <petsku@petteriraty.eu>2011-07-21 19:01:40 +0300
committerPetteri Räty <petsku@petteriraty.eu>2011-07-21 19:01:40 +0300
commitb86ea29abd7ed47c435dd48654a8c2d42d97db72 (patch)
tree47b371fe1386efbccc3af94317b38a035ce85f06
parentAdd #command command to MeetBot - shows documentation for other commands (diff)
parentUse custom change in hobo to solve problem with db:reset task (diff)
downloadcouncil-webapp-b86ea29abd7ed47c435dd48654a8c2d42d97db72.tar.gz
council-webapp-b86ea29abd7ed47c435dd48654a8c2d42d97db72.tar.bz2
council-webapp-b86ea29abd7ed47c435dd48654a8c2d42d97db72.zip
Merge remote-tracking branch 'github/seed'
-rw-r--r--site/Gemfile2
-rw-r--r--site/Gemfile.lock7
-rw-r--r--site/db/seed.yml42
-rw-r--r--site/db/seeds.rb48
-rw-r--r--site/features/support/factories.rb2
-rw-r--r--site/spec/factories.rb2
-rw-r--r--site/spec/spec_helper.rb1
7 files changed, 98 insertions, 6 deletions
diff --git a/site/Gemfile b/site/Gemfile
index bba1887..67dc50a 100644
--- a/site/Gemfile
+++ b/site/Gemfile
@@ -18,7 +18,7 @@ group :development, :test do
gem 'database_cleaner'
gem 'launchy'
gem 'show_me_the_cookies'
- gem 'factory_girl'
+ gem 'factory_girl_rails'
gem 'fuubar-cucumber'
end
diff --git a/site/Gemfile.lock b/site/Gemfile.lock
index 5127cbf..277f060 100644
--- a/site/Gemfile.lock
+++ b/site/Gemfile.lock
@@ -1,6 +1,6 @@
GIT
remote: git://github.com/ahenobarbi/hobo.git
- revision: b33a9a69a2e1ce09b98c00ecee6c51bd1459fee5
+ revision: c9c13eb614a3c4a699a59d02e4757c2cdd682988
branch: rails3
specs:
dryml (1.3.0)
@@ -94,6 +94,9 @@ GEM
erubis (2.6.6)
abstract (>= 1.0.0)
factory_girl (1.3.3)
+ factory_girl_rails (1.0.1)
+ factory_girl (~> 1.3)
+ railties (>= 3.0.0)
faraday (0.6.1)
addressable (~> 2.2.4)
multipart-post (~> 1.1.0)
@@ -222,7 +225,7 @@ DEPENDENCIES
delayed_job
devise
email_spec
- factory_girl
+ factory_girl_rails
fuubar-cucumber
hobo (>= 1.3.0.pre28)!
hobo_devise (>= 0.0.2)
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..a6393c8
--- /dev/null
+++ b/site/db/seeds.rb
@@ -0,0 +1,48 @@
+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)
+
+[Agenda, AgendaItem, Participation, Proxy, User, Vote, VotingOption].each do |model|
+ # Refresh table_exists cache for all models
+ model.table_exists?(true)
+end
+
+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)
diff --git a/site/features/support/factories.rb b/site/features/support/factories.rb
deleted file mode 100644
index 300fee7..0000000
--- a/site/features/support/factories.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-require File.expand_path("../../../spec/factories.rb", __FILE__)
-require File.expand_path("../../../spec/support/users_factory.rb", __FILE__)
diff --git a/site/spec/factories.rb b/site/spec/factories.rb
index dbf841e..01a69f7 100644
--- a/site/spec/factories.rb
+++ b/site/spec/factories.rb
@@ -31,3 +31,5 @@ Factory.define :proxy do |p|;
p.proxy {users_factory(:user)}
p.agenda {Factory(:agenda)}
end
+
+require File.expand_path("../support/users_factory.rb", __FILE__)
diff --git a/site/spec/spec_helper.rb b/site/spec/spec_helper.rb
index 770b158..c13e1c5 100644
--- a/site/spec/spec_helper.rb
+++ b/site/spec/spec_helper.rb
@@ -1,7 +1,6 @@
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
-require 'factories.rb'
environment_path = File.expand_path(File.join(::Rails.root.to_s, 'config', 'environment'))
require(environment_path)