From c531d629ebe56626b5263a96417701093dabf652 Mon Sep 17 00:00:00 2001 From: Joachim Filip Ignacy Bartosik Date: Tue, 12 Jul 2011 13:51:52 +0200 Subject: Seed database for demos --- site/db/seed.yml | 42 ++++++++++++++++++++++++++++++++++++++++++ site/db/seeds.rb | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 site/db/seed.yml create mode 100644 site/db/seeds.rb 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) -- cgit v1.2.3-65-gdbad From b08d41fcf32e33f32d131863349765d8fe80e043 Mon Sep 17 00:00:00 2001 From: Joachim Filip Ignacy Bartosik Date: Sat, 16 Jul 2011 13:01:34 +0200 Subject: Use factory_girl_rails, don't require factories manually --- site/Gemfile | 2 +- site/Gemfile.lock | 5 ++++- site/db/seeds.rb | 3 --- site/features/support/factories.rb | 2 -- site/spec/factories.rb | 2 ++ site/spec/spec_helper.rb | 1 - 6 files changed, 7 insertions(+), 8 deletions(-) delete mode 100644 site/features/support/factories.rb 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..d2a4c5a 100644 --- a/site/Gemfile.lock +++ b/site/Gemfile.lock @@ -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/seeds.rb b/site/db/seeds.rb index f276aa6..40e1a11 100644 --- a/site/db/seeds.rb +++ b/site/db/seeds.rb @@ -1,6 +1,3 @@ -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) 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) -- cgit v1.2.3-65-gdbad From 70e7a3efbae388ca189ecc8c1b10619201f41d01 Mon Sep 17 00:00:00 2001 From: Joachim Filip Ignacy Bartosik Date: Mon, 18 Jul 2011 23:26:18 +0200 Subject: Use custom change in hobo to solve problem with db:reset task --- site/Gemfile.lock | 2 +- site/db/seeds.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/site/Gemfile.lock b/site/Gemfile.lock index d2a4c5a..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) diff --git a/site/db/seeds.rb b/site/db/seeds.rb index 40e1a11..a6393c8 100644 --- a/site/db/seeds.rb +++ b/site/db/seeds.rb @@ -19,6 +19,11 @@ 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) -- cgit v1.2.3-65-gdbad