forked from railsbridge/bridge_troll
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test event to things created by db:seed
- Loading branch information
1 parent
02201bb
commit d9f9e22
Showing
9 changed files
with
169 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,7 @@ | ||
# This file should contain all the record creation needed to seed the database with its default values. | ||
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). | ||
# | ||
# Examples: | ||
# | ||
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) | ||
# Mayor.create(name: 'Emanuel', city: cities.first) | ||
require Rails.root.join('db', 'seeds', 'admin_user') | ||
require Rails.root.join('db', 'seeds', 'seed_event') | ||
|
||
#this seeds the database with an admin user--for development only | ||
|
||
if Rails.env.development? then | ||
new_user=User.new( | ||
:name => 'admin', | ||
:email => 'admin@example.com', | ||
:password => 'password', | ||
:password_confirmation => 'password', | ||
:first_name => 'Admin', | ||
:last_name => 'User', | ||
) | ||
new_user.admin = true | ||
if new_user.save | ||
puts "Finished running seeds.rb. Check to see if the there is an admin user." | ||
else | ||
puts "Could not save an admin user. #{new_user.inspect}" | ||
end | ||
else | ||
puts "This seeds.rb task is intended for the development environment only." | ||
if Rails.env.development? | ||
Seeder::admin_user | ||
Seeder::seed_event | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Seeder | ||
def self.admin_user | ||
# seeds the database with an admin user | ||
admin = User.where(email: 'admin@example.com').first_or_initialize | ||
admin.update_attributes( | ||
name: 'admin', | ||
password: 'password', | ||
first_name: 'Admin', | ||
last_name: 'User', | ||
) | ||
admin.admin = true | ||
admin.save! | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
require 'faker' | ||
|
||
module Seeder | ||
def self.create_user email | ||
user = User.create!( | ||
email: email, | ||
password: 'password', | ||
first_name: Faker::Name.first_name, | ||
last_name: Faker::Name.last_name | ||
) | ||
user.confirm! | ||
user | ||
end | ||
|
||
def self.create_volunteer_rsvp options | ||
rsvp = Rsvp.create!( | ||
event: options[:event], | ||
user: options[:user], | ||
role_id: Role::VOLUNTEER, | ||
volunteer_assignment_id: options[:assignment], | ||
subject_experience: Faker::Lorem.sentence, | ||
teaching_experience: Faker::Lorem.sentence | ||
) | ||
options[:event].event_sessions.each do |session| | ||
RsvpSession.create!(rsvp: rsvp, event_session: session) | ||
end | ||
end | ||
|
||
def self.destroy_event event | ||
event.rsvps.each do |rsvp| | ||
rsvp.user.destroy | ||
end | ||
event.location.destroy if event.location.present? | ||
event.destroy | ||
end | ||
|
||
def self.seed_event | ||
old_event = Event.where(title: 'Seeded Test Event').first | ||
destroy_event(old_event) if old_event.present? | ||
|
||
location = Location.create!( | ||
name: "Sutro Tower", | ||
address_1: "Sutro Tower", | ||
city: "San Francisco", | ||
state: "CA", | ||
zip: "94131", | ||
latitude: 37.75519999999999, | ||
longitude: -122.4528, | ||
gmaps: true | ||
) | ||
|
||
event = Event.new( | ||
title: 'Seeded Test Event', | ||
time_zone: 'Pacific Time (US & Canada)', | ||
details: <<DETAILS | ||
<h2>Workshop Description</h2> | ||
This workshop is created by seeds.rb. It is to help you see what it looks like to have an event with multiple people RSVPed. | ||
<h2>Location and Sponsors</h2> | ||
The location of this workshop is located in the Cloud. That is where it is located. | ||
<h2>Transportation and Parking</h2> | ||
You can park in this workshop if you are able to fly an airship into the cloud. Otherwise, parking is restricted. | ||
<h2>Food and Drinks</h2> | ||
Food will be provided by you, if you bring it in a knapsack. | ||
<h2>Childcare</h2> | ||
Childcare will not be provided. | ||
<h2>Afterparty</h2> | ||
The afterparty will be at the Fancy Goat at 7:09 PM. | ||
DETAILS | ||
) | ||
event.event_sessions << EventSession.create(name: 'First Session', starts_at: 60.days.from_now, ends_at: 61.days.from_now) | ||
event.event_sessions << EventSession.create(name: 'Second Session', starts_at: 65.days.from_now, ends_at: 66.days.from_now) | ||
|
||
event.location = location | ||
|
||
event.save! | ||
|
||
first_session = event.event_sessions.find_by_name('First Session') | ||
second_session = event.event_sessions.find_by_name('Second Session') | ||
|
||
organizer = create_user('organizer@example.com') | ||
event.organizers << organizer | ||
|
||
teacher = create_user('teacher@example.com') | ||
create_volunteer_rsvp(event: event, user: teacher, assignment: VolunteerAssignment::TEACHER) | ||
|
||
ta = create_user('ta@example.com') | ||
create_volunteer_rsvp(event: event, user: ta, assignment: VolunteerAssignment::TA) | ||
|
||
unassigned1 = create_user('unassigned1@example.com') | ||
create_volunteer_rsvp(event: event, user: unassigned1, assignment: VolunteerAssignment::UNASSIGNED) | ||
|
||
unassigned2 = create_user('unassigned2@example.com') | ||
create_volunteer_rsvp(event: event, user: unassigned2, assignment: VolunteerAssignment::UNASSIGNED) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'spec_helper' | ||
require Rails.root.join('db', 'seeds', 'seed_event') | ||
|
||
def assert_no_rows_present | ||
rows = {} | ||
total = 0 | ||
ActiveRecord::Base.send(:subclasses).each do |sc| | ||
rows[sc.name] = sc.all.size | ||
total += sc.all.size | ||
end | ||
if total > 0 | ||
puts "Leaked the following rows: " | ||
rows.each do |klass, count| | ||
next unless count > 0 | ||
puts "#{klass}: #{count}" | ||
end | ||
total.should == 0 | ||
end | ||
end | ||
|
||
describe "#seed_event" do | ||
it "creates an event which can cleanly destroy itself" do | ||
Seeder::seed_event | ||
event = Event.last | ||
event.title.should == 'Seeded Test Event' | ||
Seeder::destroy_event(event) | ||
assert_no_rows_present | ||
end | ||
|
||
it "destroys itself when asked to create itself twice" do | ||
Seeder::seed_event | ||
Seeder::seed_event | ||
Event.count.should == 1 | ||
end | ||
end |