Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seed data & developer omni-auth strategy. #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class SessionsController < ApplicationController
skip_before_filter :verify_authenticity_token

def create
user = User.from_facebook_omniauth(env["omniauth.auth"])
session[:user_id] = user.id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Rails.application.config.middleware.use OmniAuth::Builder do
provider :developer unless Rails.env.production?
provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET']
end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Rails.application.routes.draw do
root 'pages#home'

get 'auth/:provider/callback' => 'sessions#create'
match 'auth/:provider/callback' => 'sessions#create', via: [:get, :post]
get 'auth/failure' => redirect('/')
get 'signout' => 'sessions#destroy', as: 'signout'
end
28 changes: 24 additions & 4 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
# 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)

# Start fresh and destroy the types of things we're about to create
User.destroy_all
Trip.destroy_all
Reservation.destroy_all # should be unnecessary because of Trip.destroy_all

# Create users alphabetically and define methods. e.g. `al => #<User id: 1, name: "Al" ...>`
%w(Al Berta Chief Deanne Earl Florence Gabrielle Henry Isabella Jason Kelly Marshall).each do |name|
user = User.create(name: name, provider: "developer", uid: "#{name}@example.com")
define_method(name.downcase.to_sym, ->{user})
end

chi = Trip.create(
name: "Chicago to DC",
description: "Going to the Rally via Peoria Charter",
passenger_limit: 50,
host: al)

chambana = Trip.create(
name: "Champaign to DC",
description: "Illini for Bernie. Meet at ISR",
passenger_limit: 10,
host: chief,
passengers: [henry, isabella, jason, kelly, marshall])