diff --git a/app/assets/stylesheets/_base.css.scss b/app/assets/stylesheets/_base.css.scss index 9b354abab..e33b11075 100644 --- a/app/assets/stylesheets/_base.css.scss +++ b/app/assets/stylesheets/_base.css.scss @@ -54,6 +54,10 @@ table tr td .btn { margin: 0 20px; } +td.wide { + width: 20%; +} + .btn { font-size: 16px; font-family: 'AmbleLight'; diff --git a/app/models/event.rb b/app/models/event.rb index c740579d2..b9f215df8 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -17,7 +17,7 @@ class Event < ActiveRecord::Base has_many :organizers, through: :organizer_rsvps, source: :user, source_type: 'User' has_many :legacy_organizers, through: :organizer_rsvps, source: :user, source_type: 'MeetupUser' - has_many :event_sessions + has_many :event_sessions, dependent: :destroy accepts_nested_attributes_for :event_sessions, allow_destroy: true validates :event_sessions, length: { minimum: 1 } diff --git a/app/models/user.rb b/app/models/user.rb index e5d3690e5..35e249fdc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -8,7 +8,7 @@ class User < ActiveRecord::Base has_many :rsvps, conditions: { user_type: 'User' } has_many :events, through: :rsvps - has_one :profile + has_one :profile, dependent: :destroy attr_accessible :first_name, :last_name, :email, :password, :password_confirmation, :remember_me, :time_zone diff --git a/app/views/volunteers/index.html.erb b/app/views/volunteers/index.html.erb index 6ea8dbd37..cd8d73875 100644 --- a/app/views/volunteers/index.html.erb +++ b/app/views/volunteers/index.html.erb @@ -16,7 +16,7 @@ <%= rsvp.subject_experience %> <%= rsvp.teaching_experience %> <%= rsvp.formatted_preference %> - + <%= form_for([@event, rsvp], method: :put, url: event_volunteer_path(@event, rsvp.id), remote: true) do %> <%= label_tag do %> <%= radio_button_tag(:volunteer_assignment_id, VolunteerAssignment::UNASSIGNED, rsvp.volunteer_assignment_id == VolunteerAssignment::UNASSIGNED) %> Unassigned diff --git a/db/seeds.rb b/db/seeds.rb index d9b4b0fd1..26b129662 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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 diff --git a/db/seeds/admin_user.rb b/db/seeds/admin_user.rb new file mode 100644 index 000000000..acffaefda --- /dev/null +++ b/db/seeds/admin_user.rb @@ -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 \ No newline at end of file diff --git a/db/seeds/seed_event.rb b/db/seeds/seed_event.rb new file mode 100644 index 000000000..e14c53493 --- /dev/null +++ b/db/seeds/seed_event.rb @@ -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: <
Workshop Description + +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. + +

Location and Sponsors

+ +The location of this workshop is located in the Cloud. That is where it is located. + +

Transportation and Parking

+ +You can park in this workshop if you are able to fly an airship into the cloud. Otherwise, parking is restricted. + +

Food and Drinks

+ +Food will be provided by you, if you bring it in a knapsack. + +

Childcare

+ +Childcare will not be provided. + +

Afterparty

+ +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 \ No newline at end of file diff --git a/spec/requests/event_organizer_dashboard_request_spec.rb b/spec/requests/event_organizer_dashboard_request_spec.rb index 9431b772b..0d8c49142 100644 --- a/spec/requests/event_organizer_dashboard_request_spec.rb +++ b/spec/requests/event_organizer_dashboard_request_spec.rb @@ -22,7 +22,7 @@ it "lets the user manage volunteers" do visit organize_event_path(@event) click_link "Manage Volunteers" - page.should have_content("Volunteer Assignment") + page.should have_content("Assign Volunteer") end it "lets the user check in volunteers", js: true do diff --git a/spec/seeds/seeds_spec.rb b/spec/seeds/seeds_spec.rb new file mode 100644 index 000000000..2fad1aa46 --- /dev/null +++ b/spec/seeds/seeds_spec.rb @@ -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 \ No newline at end of file