Skip to content

Instantly share code, notes, and snippets.

@tooky
Forked from radar/account_signup.rb
Created January 15, 2013 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tooky/4537009 to your computer and use it in GitHub Desktop.
Save tooky/4537009 to your computer and use it in GitHub Desktop.
class AccountSignup
def self.new(warden, acccount_params)
account = Subscribem::Account.create(account_params)
account.create_schema
UserSignup.new(warden, account, account.owner)
end
end
require_dependency "subscribem/application_controller"
module Subscribem
class AccountsController < ApplicationController
def new
@account = Subscribem::Account.new
@account.build_owner
end
def create
AccountSignUp.new(env['warden'], params[:account])
flash[:success] = "Your account has been successfully created."
redirect_to subscribem.root_url(:subdomain => account.subdomain)
end
end
end
require 'spec_helper'
describe Subscribem::AccountsController do
context "creates the account's schema" do
let!(:account) { stub_model(Subscribem::Account) }
let!(:owner) { stub_model(Subscribem::User) }
let!(:account_params) { { :account => { :name => "First Account" } } }
specify do
AccountSignUp.should_receive(:new).with(warden, account_params)
post :create, params.merge(:use_route => :subscribem)
end
end
end
class UserSignin
def self.new(warden, account, user)
warden.set_user(user.id, :scope => :user)
warden.set_user(account.id, :scope => :account)
end
end
class UserSignup
def self.new(warden, account, user)
account.users << user
UserSignIn.new(warden, account, user)
end
end
require_dependency "subscribem/application_controller"
module Subscribem
class Account::UsersController < ApplicationController
def new
@user = Subscribem::User.new
end
def create
user = Subscribem::User.create(params[:user])
UserSignUp.new(env['warden'], account, user)
flash[:success] = "You have signed up successfully."
redirect_to root_path
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment